From b1db6e90e013097f9f2e58ccc4baa7572bf7d665 Mon Sep 17 00:00:00 2001 From: Rainer Simon Date: Sat, 12 Sep 2020 09:41:03 +0200 Subject: [PATCH] Preparatory work for flexible plugin API --- src/editor/Editor.jsx | 19 ++++--------------- src/editor/index.js | 6 ++++++ src/editor/{ => widgets}/DOMWidget.jsx | 0 src/editor/widgets/index.js | 0 4 files changed, 10 insertions(+), 15 deletions(-) rename src/editor/{ => widgets}/DOMWidget.jsx (100%) create mode 100644 src/editor/widgets/index.js diff --git a/src/editor/Editor.jsx b/src/editor/Editor.jsx index c8cbf8b..b2eb942 100644 --- a/src/editor/Editor.jsx +++ b/src/editor/Editor.jsx @@ -1,7 +1,7 @@ import React from 'preact/compat'; import { useState, useRef, useEffect } from 'preact/hooks'; import Environment from '../Environment'; -import DOMWidget from './DOMWidget'; +import DOMWidget from './widgets/DOMWidget'; import setPosition from './setPosition'; import i18n from '../i18n'; @@ -139,32 +139,21 @@ const Editor = props => { } }; - const widgets = props.widget ? props.widgets.map(fn => ) : []; + const widgets = props.widgets ? props.widgets.map(fn => ) : []; return (
- {React.Children.map(props.children, child => - React.cloneElement(child, { - ...child.props, - annotation : currentAnnotation, - readOnly : props.readOnly, - onAppendBody, - onUpdateBody, - onRemoveBody, - onSaveAndClose : onOk - })) - } - {widgets.map(widget => React.cloneElement(widget, { annotation : currentAnnotation, readOnly : props.readOnly, + config: props.config, onAppendBody, onUpdateBody, onRemoveBody, - onSaveAndClose : onOk + onSaveAndClose: onOk }) )} diff --git a/src/editor/index.js b/src/editor/index.js index 4bf9280..9d69b35 100644 --- a/src/editor/index.js +++ b/src/editor/index.js @@ -3,6 +3,12 @@ import Editor from './Editor'; import CommentWidget from './widgets/comment/CommentWidget'; import TagWidget from './widgets/tag/TagWidget'; +/** Standard widgets included by default **/ +const DEFAULT_WIDGETS = { + COMMENT: CommentWidget, + TAG: TagWidget +}; + Editor.CommentWidget = CommentWidget; Editor.TagWidget = TagWidget; diff --git a/src/editor/DOMWidget.jsx b/src/editor/widgets/DOMWidget.jsx similarity index 100% rename from src/editor/DOMWidget.jsx rename to src/editor/widgets/DOMWidget.jsx diff --git a/src/editor/widgets/index.js b/src/editor/widgets/index.js new file mode 100644 index 0000000..e69de29