Preparatory work for flexible plugin API

This commit is contained in:
Rainer Simon 2020-09-12 09:41:03 +02:00
parent d4ab1aedb4
commit b1db6e90e0
4 changed files with 10 additions and 15 deletions

View File

@ -1,7 +1,7 @@
import React from 'preact/compat'; import React from 'preact/compat';
import { useState, useRef, useEffect } from 'preact/hooks'; import { useState, useRef, useEffect } from 'preact/hooks';
import Environment from '../Environment'; import Environment from '../Environment';
import DOMWidget from './DOMWidget'; import DOMWidget from './widgets/DOMWidget';
import setPosition from './setPosition'; import setPosition from './setPosition';
import i18n from '../i18n'; import i18n from '../i18n';
@ -139,28 +139,17 @@ const Editor = props => {
} }
}; };
const widgets = props.widget ? props.widgets.map(fn => <DOMWidget widget={fn} />) : []; const widgets = props.widgets ? props.widgets.map(fn => <DOMWidget widget={fn} />) : [];
return ( return (
<div ref={element} className="r6o-editor"> <div ref={element} className="r6o-editor">
<div className="arrow" /> <div className="arrow" />
<div className="inner"> <div className="inner">
{React.Children.map(props.children, child =>
React.cloneElement(child, {
...child.props,
annotation : currentAnnotation,
readOnly : props.readOnly,
onAppendBody,
onUpdateBody,
onRemoveBody,
onSaveAndClose : onOk
}))
}
{widgets.map(widget => {widgets.map(widget =>
React.cloneElement(widget, { React.cloneElement(widget, {
annotation : currentAnnotation, annotation : currentAnnotation,
readOnly : props.readOnly, readOnly : props.readOnly,
config: props.config,
onAppendBody, onAppendBody,
onUpdateBody, onUpdateBody,
onRemoveBody, onRemoveBody,

View File

@ -3,6 +3,12 @@ import Editor from './Editor';
import CommentWidget from './widgets/comment/CommentWidget'; import CommentWidget from './widgets/comment/CommentWidget';
import TagWidget from './widgets/tag/TagWidget'; import TagWidget from './widgets/tag/TagWidget';
/** Standard widgets included by default **/
const DEFAULT_WIDGETS = {
COMMENT: CommentWidget,
TAG: TagWidget
};
Editor.CommentWidget = CommentWidget; Editor.CommentWidget = CommentWidget;
Editor.TagWidget = TagWidget; Editor.TagWidget = TagWidget;

View File