|
@@ -6,10 +6,6 @@ import { IS_IE11, STRINGS } from '../../config/wagtailConfig';
|
|
|
|
|
|
import Icon from '../Icon/Icon';
|
|
|
|
|
|
-import registry from './registry';
|
|
|
-
|
|
|
-export { registry };
|
|
|
-
|
|
|
export { default as Link } from './decorators/Link';
|
|
|
export { default as Document } from './decorators/Document';
|
|
|
export { default as ImageBlock } from './blocks/ImageBlock';
|
|
@@ -17,6 +13,20 @@ export { default as EmbedBlock } from './blocks/EmbedBlock';
|
|
|
|
|
|
export { default as ModalWorkflowSource } from './sources/ModalWorkflowSource';
|
|
|
|
|
|
+/**
|
|
|
+ * Registry for client-side code of Draftail plugins.
|
|
|
+ */
|
|
|
+const PLUGINS = {};
|
|
|
+
|
|
|
+const registerPlugin = (plugin) => {
|
|
|
+ PLUGINS[plugin.type] = plugin;
|
|
|
+ return PLUGINS;
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * Wraps a style/block/entity type’s icon with an icon font implementation,
|
|
|
+ * so Draftail can use icon fonts in its toolbar.
|
|
|
+ */
|
|
|
export const wrapWagtailIcon = type => {
|
|
|
const isIconFont = type.icon && typeof type.icon === 'string';
|
|
|
if (isIconFont) {
|
|
@@ -33,7 +43,7 @@ export const wrapWagtailIcon = type => {
|
|
|
* @param {string} fieldName
|
|
|
* @param {Object} options
|
|
|
*/
|
|
|
-export const initEditor = (fieldName, options) => {
|
|
|
+const initEditor = (fieldName, options) => {
|
|
|
const field = document.querySelector(`[name="${fieldName}"]`);
|
|
|
const editorWrapper = document.createElement('div');
|
|
|
field.parentNode.appendChild(editorWrapper);
|
|
@@ -47,9 +57,9 @@ export const initEditor = (fieldName, options) => {
|
|
|
let entityTypes = options.entityTypes || [];
|
|
|
|
|
|
entityTypes = entityTypes.map(wrapWagtailIcon).map((type) => {
|
|
|
- const plugin = registry.getPlugin(type.type);
|
|
|
- // Override the properties defined in the JS plugin: Python should be the source of truth.
|
|
|
+ const plugin = PLUGINS[type.type];
|
|
|
|
|
|
+ // Override the properties defined in the JS plugin: Python should be the source of truth.
|
|
|
return Object.assign({}, plugin, type);
|
|
|
});
|
|
|
|
|
@@ -68,7 +78,6 @@ export const initEditor = (fieldName, options) => {
|
|
|
enableLineBreak={{ description: STRINGS.LINE_BREAK }}
|
|
|
showUndoControl={{ description: STRINGS.UNDO }}
|
|
|
showRedoControl={{ description: STRINGS.REDO }}
|
|
|
- // If increasing above 4, we will need to add styles for the extra nesting levels.
|
|
|
maxListNesting={4}
|
|
|
// Draft.js + IE 11 presents some issues with pasting rich text. Disable rich paste there.
|
|
|
stripPastedStyles={IS_IE11}
|
|
@@ -85,3 +94,8 @@ export const initEditor = (fieldName, options) => {
|
|
|
// Bind editor instance to its field so it can be accessed imperatively elsewhere.
|
|
|
field.draftailEditor = draftailEditor;
|
|
|
};
|
|
|
+
|
|
|
+export default {
|
|
|
+ initEditor,
|
|
|
+ registerPlugin,
|
|
|
+};
|