@pie-lib/editable-html 9.0.3 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/lib/editor.js +24 -6
- package/lib/editor.js.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/image/alt-dialog.js +119 -0
- package/lib/plugins/image/alt-dialog.js.map +1 -0
- package/lib/plugins/image/component.js +3 -1
- package/lib/plugins/image/component.js.map +1 -1
- package/lib/plugins/image/image-toolbar.js +52 -4
- package/lib/plugins/image/image-toolbar.js.map +1 -1
- package/lib/plugins/image/index.js +11 -6
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/respArea/index.js.map +1 -1
- package/lib/plugins/table/index.js.map +1 -1
- package/lib/plugins/toolbar/editor-and-toolbar.js +12 -4
- package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
- package/package.json +3 -3
- package/src/editor.jsx +28 -2
- package/src/index.jsx +2 -2
- package/src/plugins/image/alt-dialog.jsx +69 -0
- package/src/plugins/image/component.jsx +2 -0
- package/src/plugins/image/image-toolbar.jsx +44 -4
- package/src/plugins/image/index.jsx +12 -5
- package/src/plugins/respArea/index.jsx +0 -1
- package/src/plugins/table/index.jsx +3 -1
- package/src/plugins/toolbar/editor-and-toolbar.jsx +26 -3
|
@@ -69,7 +69,8 @@ var EditorAndToolbar = /*#__PURE__*/function (_React$Component) {
|
|
|
69
69
|
}, {
|
|
70
70
|
key: "render",
|
|
71
71
|
value: function render() {
|
|
72
|
-
var _this = this
|
|
72
|
+
var _this = this,
|
|
73
|
+
_classNames;
|
|
73
74
|
|
|
74
75
|
var _this$props = this.props,
|
|
75
76
|
classes = _this$props.classes,
|
|
@@ -100,11 +101,12 @@ var EditorAndToolbar = /*#__PURE__*/function (_React$Component) {
|
|
|
100
101
|
|
|
101
102
|
log('[render] inFocus: ', inFocus, 'value.isFocused:', value.isFocused, 'focused node: ', focusedNode);
|
|
102
103
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
103
|
-
className: (0, _classnames["default"])(classes.
|
|
104
|
+
className: (0, _classnames["default"])((_classNames = {}, (0, _defineProperty2["default"])(_classNames, classes.noBorder, toolbarOpts && toolbarOpts.noBorder), (0, _defineProperty2["default"])(_classNames, classes.error, toolbarOpts && toolbarOpts.error), _classNames), classes.root)
|
|
104
105
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
105
|
-
className: holderNames
|
|
106
|
+
className: holderNames,
|
|
107
|
+
id: 'holder'
|
|
106
108
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
107
|
-
className: classes.children
|
|
109
|
+
className: (0, _classnames["default"])((0, _defineProperty2["default"])({}, classes.noPadding, toolbarOpts && toolbarOpts.noBorder), classes.children)
|
|
108
110
|
}, clonedChildren)), /*#__PURE__*/_react["default"].createElement(_toolbar["default"], {
|
|
109
111
|
autoWidth: autoWidth,
|
|
110
112
|
plugins: plugins,
|
|
@@ -254,6 +256,12 @@ var style = {
|
|
|
254
256
|
},
|
|
255
257
|
error: {
|
|
256
258
|
border: '2px solid red'
|
|
259
|
+
},
|
|
260
|
+
noBorder: {
|
|
261
|
+
border: 'none'
|
|
262
|
+
},
|
|
263
|
+
noPadding: {
|
|
264
|
+
padding: 0
|
|
257
265
|
}
|
|
258
266
|
};
|
|
259
267
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/toolbar/editor-and-toolbar.jsx"],"names":["log","EditorAndToolbar","IS_FIREFOX","editorRef","tmp","isUpdatingSelection","props","classes","children","value","plugins","onChange","onDone","focusedNode","autoWidth","readOnly","disableUnderline","pluginProps","toolbarOpts","onDataChange","toolbarRef","inFocus","isFocused","undefined","holderNames","editorHolder","editorInFocus","disabledUnderline","clonedChildren","React","cloneElement","ref","el","root","error","Component","PropTypes","oneOfType","arrayOf","node","isRequired","SlatePropTypes","array","func","bool","object","shape","position","oneOf","alwaysVisible","string","style","padding","border","borderRadius","cursor","wordBreak","overflow","maxHeight","overflowY","color","text","backgroundColor","background","left","right","bottom","height","content","transition","pointerEvents","transform","primary","display","backgroundSize","backgroundImage","backgroundRepeat","backgroundPosition"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,2DAAN,CAAZ;;IAEaC,gB;;;;;;;;;;;;;AAsBX;AACF;AACA;AACE,iCAAoB;AAClB,UAAIC,+BAAJ,EAAgB;AACd,aAAKC,SAAL,CAAeC,GAAf,CAAmBC,mBAAnB,GAAyC,IAAzC;AACD;AACF;;;WAED,kBAAS;AAAA;;AACP,wBAeI,KAAKC,KAfT;AAAA,UACEC,OADF,eACEA,OADF;AAAA,UAEEC,QAFF,eAEEA,QAFF;AAAA,UAGEC,KAHF,eAGEA,KAHF;AAAA,UAIEC,OAJF,eAIEA,OAJF;AAAA,UAKEC,QALF,eAKEA,QALF;AAAA,UAMEC,MANF,eAMEA,MANF;AAAA,UAOEC,WAPF,eAOEA,WAPF;AAAA,UAQEC,SARF,eAQEA,SARF;AAAA,UASEC,QATF,eASEA,QATF;AAAA,UAUEC,gBAVF,eAUEA,gBAVF;AAAA,UAWEC,WAXF,eAWEA,WAXF;AAAA,UAYEC,WAZF,eAYEA,WAZF;AAAA,UAaEC,YAbF,eAaEA,YAbF;AAAA,UAcEC,UAdF,eAcEA,UAdF;AAiBA,UAAMC,OAAO,GAAGZ,KAAK,CAACa,SAAN,IAAoBT,WAAW,KAAK,IAAhB,IAAwBA,WAAW,KAAKU,SAA5E;AACA,UAAMC,WAAW,GAAG,4BAClBjB,OAAO,CAACkB,YADU,EAElBJ,OAAO,IAAId,OAAO,CAACmB,aAFD,EAGlBX,QAAQ,IAAIR,OAAO,CAACQ,QAHF,EAIlBC,gBAAgB,IAAIT,OAAO,CAACoB,iBAJV,CAApB;AAMA,UAAIC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BAAa;AACX8C,MAAAA,OAAO,EAAE;AADE,KADI;AAIjB,gBAAY;AACVA,MAAAA,OAAO,EAAE;AADC;AAJK,GA9DP;AAuEZ1D,EAAAA,QAAQ,EAAE;AACR,iBAAa;AACXgD,MAAAA,UAAU,EAAE,aADD;AAEXW,MAAAA,cAAc,EAAE,SAFL;AAGXC,MAAAA,eAAe,EAAE,oEAHN;AAIXC,MAAAA,gBAAgB,EAAE,UAJP;AAKXC,MAAAA,kBAAkB,EAAE;AALT,KADL;AAQR,gBAAY;AACVb,MAAAA,IAAI,EAAE,GADI;AAEVC,MAAAA,KAAK,EAAE,GAFG;AAGVC,MAAAA,MAAM,EAAE,GAHE;AAIVC,MAAAA,MAAM,EAAE,KAJE;AAKVC,MAAAA,OAAO,EAAE,IALC;AAMVrB,MAAAA,QAAQ,EAAE,UANA;AAOVwB,MAAAA,SAAS,EAAE,WAPD;AAQVF,MAAAA,UAAU,EAAE,iFARF;AASVP,MAAAA,eAAe,EAAE;AATP,KARJ;AAmBR,eAAW;AACT,kBAAY;AACVS,QAAAA,SAAS,EAAE,WADD;AAEVT,QAAAA,eAAe,EAAE,OAFP;AAGVK,QAAAA,MAAM,EAAE;AAHE;AADH;AAnBH,GAvEE;AAkGZzC,EAAAA,aAAa,EAAE;AACb,gBAAY;AACV6C,MAAAA,SAAS,EAAE,WADD;AAEVT,MAAAA,eAAe,EAAEU,cAFP;AAGVL,MAAAA,MAAM,EAAE;AAHE,KADC;AAMb,eAAW;AACT,kBAAY;AACVL,QAAAA,eAAe,EAAEU;AADP;AADH;AANE,GAlGH;AA8GZtC,EAAAA,KAAK,EAAE;AACLmB,IAAAA,MAAM,EAAE;AADH;AA9GK,CAAd;;eAmHe,wBAAWF,KAAX,EAAkBlD,gBAAlB,C","sourcesContent":["import React from 'react';\nimport Toolbar from './toolbar';\nimport classNames from 'classnames';\nimport debug from 'debug';\nimport { primary } from '../../theme';\nimport { withStyles } from '@material-ui/core/styles';\nimport PropTypes from 'prop-types';\nimport SlatePropTypes from 'slate-prop-types';\nimport { IS_FIREFOX } from 'slate-dev-environment';\nimport { color } from '@pie-lib/render-ui';\n\nconst log = debug('@pie-lib:editable-html:plugins:toolbar:editor-and-toolbar');\n\nexport class EditorAndToolbar extends React.Component {\n static propTypes = {\n children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,\n value: SlatePropTypes.value.isRequired,\n plugins: PropTypes.array.isRequired,\n onChange: PropTypes.func.isRequired,\n onDone: PropTypes.func.isRequired,\n onDataChange: PropTypes.func,\n toolbarRef: PropTypes.func,\n focusedNode: SlatePropTypes.node,\n readOnly: PropTypes.bool,\n disableUnderline: PropTypes.bool,\n autoWidth: PropTypes.bool,\n classes: PropTypes.object.isRequired,\n pluginProps: PropTypes.object,\n toolbarOpts: PropTypes.shape({\n position: PropTypes.oneOf(['bottom', 'top']),\n alwaysVisible: PropTypes.bool,\n error: PropTypes.string\n })\n };\n\n /** This is an interim fix until this PR is merged in slate:\n * https://github.com/ianstormtaylor/slate/pull/2236\n */\n componentDidMount() {\n if (IS_FIREFOX) {\n this.editorRef.tmp.isUpdatingSelection = true;\n }\n }\n\n render() {\n const {\n classes,\n children,\n value,\n plugins,\n onChange,\n onDone,\n focusedNode,\n autoWidth,\n readOnly,\n disableUnderline,\n pluginProps,\n toolbarOpts,\n onDataChange,\n toolbarRef\n } = this.props;\n\n const inFocus = value.isFocused || (focusedNode !== null && focusedNode !== undefined);\n const holderNames = classNames(\n classes.editorHolder,\n inFocus && classes.editorInFocus,\n readOnly && classes.readOnly,\n disableUnderline && classes.disabledUnderline\n );\n let clonedChildren = children;\n\n if (typeof children !== 'string') {\n clonedChildren = React.cloneElement(children, {\n ref: el => (this.editorRef = el)\n });\n }\n\n log(\n '[render] inFocus: ',\n inFocus,\n 'value.isFocused:',\n value.isFocused,\n 'focused node: ',\n focusedNode\n );\n\n return (\n <div className={classNames(classes.root, toolbarOpts && toolbarOpts.error && classes.error)}>\n <div className={holderNames}>\n <div className={classes.children}>{clonedChildren}</div>\n </div>\n <Toolbar\n autoWidth={autoWidth}\n plugins={plugins}\n focusedNode={focusedNode}\n value={value}\n isFocused={inFocus}\n onChange={onChange}\n onDone={onDone}\n onDataChange={onDataChange}\n toolbarRef={toolbarRef}\n pluginProps={pluginProps}\n toolbarOpts={toolbarOpts}\n />\n </div>\n );\n }\n}\n\nconst style = {\n root: {\n position: 'relative',\n padding: '0px',\n border: '1px solid #ccc',\n borderRadius: '4px',\n cursor: 'text',\n '& [data-slate-editor=\"true\"]': {\n wordBreak: 'break-word',\n overflow: 'visible',\n maxHeight: '500px',\n // needed in order to be able to put the focus before a void element when it is the first one in the editor\n padding: '5px'\n }\n },\n children: {\n padding: '10px 16px'\n },\n editorHolder: {\n position: 'relative',\n padding: '0px',\n overflowY: 'scroll',\n color: color.text(),\n backgroundColor: color.background(),\n '&::before': {\n left: '0',\n right: '0',\n bottom: '0',\n height: '1px',\n content: '\"\"',\n position: 'absolute',\n transition: 'background-color 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',\n pointerEvents: 'none',\n backgroundColor: 'rgba(0, 0, 0, 0.42)'\n },\n '&::after': {\n left: '0',\n right: '0',\n bottom: '0',\n height: '1px',\n content: '\"\"',\n position: 'absolute',\n transform: 'scaleX(0)',\n transition:\n 'transform 200ms cubic-bezier(0.0, 0.0, 0.2, 1) 0ms, background-color 200ms linear',\n backgroundColor: 'rgba(0, 0, 0, 0.42)'\n },\n '&:focus': {\n '&::after': {\n transform: 'scaleX(1)',\n backgroundColor: primary,\n height: '2px'\n }\n },\n '&:hover': {\n '&::after': {\n transform: 'scaleX(1)',\n backgroundColor: 'black',\n height: '2px'\n }\n }\n },\n disabledUnderline: {\n '&::before': {\n display: 'none'\n },\n '&::after': {\n display: 'none'\n }\n },\n\n readOnly: {\n '&::before': {\n background: 'transparent',\n backgroundSize: '5px 1px',\n backgroundImage: 'linear-gradient(to right, rgba(0, 0, 0, 0.42) 33%, transparent 0%)',\n backgroundRepeat: 'repeat-x',\n backgroundPosition: 'left top'\n },\n '&::after': {\n left: '0',\n right: '0',\n bottom: '0',\n height: '1px',\n content: '\"\"',\n position: 'absolute',\n transform: 'scaleX(0)',\n transition: 'transform 200ms cubic-bezier(0.0, 0.0, 0.2, 1) 0ms, background-color 0ms linear',\n backgroundColor: 'rgba(0, 0, 0, 0)'\n },\n '&:hover': {\n '&::after': {\n transform: 'scaleX(0)',\n backgroundColor: 'black',\n height: '2px'\n }\n }\n },\n editorInFocus: {\n '&::after': {\n transform: 'scaleX(1)',\n backgroundColor: primary,\n height: '2px'\n },\n '&:hover': {\n '&::after': {\n backgroundColor: primary\n }\n }\n },\n error: {\n border: '2px solid red'\n }\n};\n\nexport default withStyles(style)(EditorAndToolbar);\n"],"file":"editor-and-toolbar.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/toolbar/editor-and-toolbar.jsx"],"names":["log","EditorAndToolbar","IS_FIREFOX","editorRef","tmp","isUpdatingSelection","props","classes","children","value","plugins","onChange","onDone","focusedNode","autoWidth","readOnly","disableUnderline","pluginProps","toolbarOpts","onDataChange","toolbarRef","inFocus","isFocused","undefined","holderNames","editorHolder","editorInFocus","disabledUnderline","clonedChildren","React","cloneElement","ref","el","noBorder","error","root","noPadding","Component","PropTypes","oneOfType","arrayOf","node","isRequired","SlatePropTypes","array","func","bool","object","shape","position","oneOf","alwaysVisible","string","style","padding","border","borderRadius","cursor","wordBreak","overflow","maxHeight","overflowY","color","text","backgroundColor","background","left","right","bottom","height","content","transition","pointerEvents","transform","primary","display","backgroundSize","backgroundImage","backgroundRepeat","backgroundPosition"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,2DAAN,CAAZ;;IAEaC,gB;;;;;;;;;;;;;AAsBX;AACF;AACA;AACE,iCAAoB;AAClB,UAAIC,+BAAJ,EAAgB;AACd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AE,SAFL;AAGXC,MAAAA,eAAe,EAAE,oEAHN;AAIXC,MAAAA,gBAAgB,EAAE,UAJP;AAKXC,MAAAA,kBAAkB,EAAE;AALT,KADL;AAQR,gBAAY;AACVb,MAAAA,IAAI,EAAE,GADI;AAEVC,MAAAA,KAAK,EAAE,GAFG;AAGVC,MAAAA,MAAM,EAAE,GAHE;AAIVC,MAAAA,MAAM,EAAE,KAJE;AAKVC,MAAAA,OAAO,EAAE,IALC;AAMVrB,MAAAA,QAAQ,EAAE,UANA;AAOVwB,MAAAA,SAAS,EAAE,WAPD;AAQVF,MAAAA,UAAU,EAAE,iFARF;AASVP,MAAAA,eAAe,EAAE;AATP,KARJ;AAmBR,eAAW;AACT,kBAAY;AACVS,QAAAA,SAAS,EAAE,WADD;AAEVT,QAAAA,eAAe,EAAE,OAFP;AAGVK,QAAAA,MAAM,EAAE;AAHE;AADH;AAnBH,GAvEE;AAkGZ3C,EAAAA,aAAa,EAAE;AACb,gBAAY;AACV+C,MAAAA,SAAS,EAAE,WADD;AAEVT,MAAAA,eAAe,EAAEU,cAFP;AAGVL,MAAAA,MAAM,EAAE;AAHE,KADC;AAMb,eAAW;AACT,kBAAY;AACVL,QAAAA,eAAe,EAAEU;AADP;AADH;AANE,GAlGH;AA8GZxC,EAAAA,KAAK,EAAE;AACLqB,IAAAA,MAAM,EAAE;AADH,GA9GK;AAiHZtB,EAAAA,QAAQ,EAAE;AACRsB,IAAAA,MAAM,EAAE;AADA,GAjHE;AAoHZnB,EAAAA,SAAS,EAAE;AACTkB,IAAAA,OAAO,EAAE;AADA;AApHC,CAAd;;eAyHe,wBAAWD,KAAX,EAAkBpD,gBAAlB,C","sourcesContent":["import React from 'react';\nimport Toolbar from './toolbar';\nimport classNames from 'classnames';\nimport debug from 'debug';\nimport { primary } from '../../theme';\nimport { withStyles } from '@material-ui/core/styles';\nimport PropTypes from 'prop-types';\nimport SlatePropTypes from 'slate-prop-types';\nimport { IS_FIREFOX } from 'slate-dev-environment';\nimport { color } from '@pie-lib/render-ui';\n\nconst log = debug('@pie-lib:editable-html:plugins:toolbar:editor-and-toolbar');\n\nexport class EditorAndToolbar extends React.Component {\n static propTypes = {\n children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,\n value: SlatePropTypes.value.isRequired,\n plugins: PropTypes.array.isRequired,\n onChange: PropTypes.func.isRequired,\n onDone: PropTypes.func.isRequired,\n onDataChange: PropTypes.func,\n toolbarRef: PropTypes.func,\n focusedNode: SlatePropTypes.node,\n readOnly: PropTypes.bool,\n disableUnderline: PropTypes.bool,\n autoWidth: PropTypes.bool,\n classes: PropTypes.object.isRequired,\n pluginProps: PropTypes.object,\n toolbarOpts: PropTypes.shape({\n position: PropTypes.oneOf(['bottom', 'top']),\n alwaysVisible: PropTypes.bool,\n error: PropTypes.string\n })\n };\n\n /** This is an interim fix until this PR is merged in slate:\n * https://github.com/ianstormtaylor/slate/pull/2236\n */\n componentDidMount() {\n if (IS_FIREFOX) {\n this.editorRef.tmp.isUpdatingSelection = true;\n }\n }\n\n render() {\n const {\n classes,\n children,\n value,\n plugins,\n onChange,\n onDone,\n focusedNode,\n autoWidth,\n readOnly,\n disableUnderline,\n pluginProps,\n toolbarOpts,\n onDataChange,\n toolbarRef\n } = this.props;\n\n const inFocus = value.isFocused || (focusedNode !== null && focusedNode !== undefined);\n const holderNames = classNames(\n classes.editorHolder,\n inFocus && classes.editorInFocus,\n readOnly && classes.readOnly,\n disableUnderline && classes.disabledUnderline\n );\n let clonedChildren = children;\n\n if (typeof children !== 'string') {\n clonedChildren = React.cloneElement(children, {\n ref: el => (this.editorRef = el)\n });\n }\n\n log(\n '[render] inFocus: ',\n inFocus,\n 'value.isFocused:',\n value.isFocused,\n 'focused node: ',\n focusedNode\n );\n\n return (\n <div\n className={classNames(\n {\n [classes.noBorder]: toolbarOpts && toolbarOpts.noBorder,\n [classes.error]: toolbarOpts && toolbarOpts.error\n },\n classes.root\n )}\n >\n <div className={holderNames} id={'holder'}>\n <div\n className={classNames(\n {\n [classes.noPadding]: toolbarOpts && toolbarOpts.noBorder\n },\n classes.children\n )}\n >\n {clonedChildren}\n </div>\n </div>\n <Toolbar\n autoWidth={autoWidth}\n plugins={plugins}\n focusedNode={focusedNode}\n value={value}\n isFocused={inFocus}\n onChange={onChange}\n onDone={onDone}\n onDataChange={onDataChange}\n toolbarRef={toolbarRef}\n pluginProps={pluginProps}\n toolbarOpts={toolbarOpts}\n />\n </div>\n );\n }\n}\n\nconst style = {\n root: {\n position: 'relative',\n padding: '0px',\n border: '1px solid #ccc',\n borderRadius: '4px',\n cursor: 'text',\n '& [data-slate-editor=\"true\"]': {\n wordBreak: 'break-word',\n overflow: 'visible',\n maxHeight: '500px',\n // needed in order to be able to put the focus before a void element when it is the first one in the editor\n padding: '5px'\n }\n },\n children: {\n padding: '10px 16px'\n },\n editorHolder: {\n position: 'relative',\n padding: '0px',\n overflowY: 'scroll',\n color: color.text(),\n backgroundColor: color.background(),\n '&::before': {\n left: '0',\n right: '0',\n bottom: '0',\n height: '1px',\n content: '\"\"',\n position: 'absolute',\n transition: 'background-color 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',\n pointerEvents: 'none',\n backgroundColor: 'rgba(0, 0, 0, 0.42)'\n },\n '&::after': {\n left: '0',\n right: '0',\n bottom: '0',\n height: '1px',\n content: '\"\"',\n position: 'absolute',\n transform: 'scaleX(0)',\n transition:\n 'transform 200ms cubic-bezier(0.0, 0.0, 0.2, 1) 0ms, background-color 200ms linear',\n backgroundColor: 'rgba(0, 0, 0, 0.42)'\n },\n '&:focus': {\n '&::after': {\n transform: 'scaleX(1)',\n backgroundColor: primary,\n height: '2px'\n }\n },\n '&:hover': {\n '&::after': {\n transform: 'scaleX(1)',\n backgroundColor: 'black',\n height: '2px'\n }\n }\n },\n disabledUnderline: {\n '&::before': {\n display: 'none'\n },\n '&::after': {\n display: 'none'\n }\n },\n\n readOnly: {\n '&::before': {\n background: 'transparent',\n backgroundSize: '5px 1px',\n backgroundImage: 'linear-gradient(to right, rgba(0, 0, 0, 0.42) 33%, transparent 0%)',\n backgroundRepeat: 'repeat-x',\n backgroundPosition: 'left top'\n },\n '&::after': {\n left: '0',\n right: '0',\n bottom: '0',\n height: '1px',\n content: '\"\"',\n position: 'absolute',\n transform: 'scaleX(0)',\n transition: 'transform 200ms cubic-bezier(0.0, 0.0, 0.2, 1) 0ms, background-color 0ms linear',\n backgroundColor: 'rgba(0, 0, 0, 0)'\n },\n '&:hover': {\n '&::after': {\n transform: 'scaleX(0)',\n backgroundColor: 'black',\n height: '2px'\n }\n }\n },\n editorInFocus: {\n '&::after': {\n transform: 'scaleX(1)',\n backgroundColor: primary,\n height: '2px'\n },\n '&:hover': {\n '&::after': {\n backgroundColor: primary\n }\n }\n },\n error: {\n border: '2px solid red'\n },\n noBorder: {\n border: 'none'\n },\n noPadding: {\n padding: 0\n }\n};\n\nexport default withStyles(style)(EditorAndToolbar);\n"],"file":"editor-and-toolbar.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/editable-html",
|
|
3
|
-
"version": "9.0
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@material-ui/styles": "^3.0.0-alpha.10",
|
|
13
13
|
"@pie-lib/drag": "^1.1.52",
|
|
14
14
|
"@pie-lib/math-rendering": "^2.4.5",
|
|
15
|
-
"@pie-lib/math-toolbar": "^1.10.
|
|
15
|
+
"@pie-lib/math-toolbar": "^1.10.3",
|
|
16
16
|
"@pie-lib/render-ui": "^4.13.1",
|
|
17
17
|
"change-case": "^3.0.2",
|
|
18
18
|
"classnames": "^2.2.6",
|
|
@@ -47,6 +47,6 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "5f0932d39d7f01be0f96665b8fbe45ee745c2868",
|
|
51
51
|
"scripts": {}
|
|
52
52
|
}
|
package/src/editor.jsx
CHANGED
|
@@ -33,7 +33,7 @@ const defaultResponseAreaProps = {
|
|
|
33
33
|
onHandleAreaChange: () => {}
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
const defaultLanguageCharactersProps = [
|
|
36
|
+
const defaultLanguageCharactersProps = [];
|
|
37
37
|
|
|
38
38
|
const createToolbarOpts = toolbarOpts => {
|
|
39
39
|
return {
|
|
@@ -352,7 +352,7 @@ export class Editor extends React.Component {
|
|
|
352
352
|
log('[onBlur] node: ', node);
|
|
353
353
|
|
|
354
354
|
return new Promise(resolve => {
|
|
355
|
-
this.setState({ focusedNode: node }, this.handleBlur.bind(this, resolve));
|
|
355
|
+
this.setState({ focusedNode: !node ? null : node }, this.handleBlur.bind(this, resolve));
|
|
356
356
|
this.props.onBlur(event);
|
|
357
357
|
});
|
|
358
358
|
};
|
|
@@ -639,6 +639,31 @@ export class Editor extends React.Component {
|
|
|
639
639
|
}
|
|
640
640
|
};
|
|
641
641
|
|
|
642
|
+
renderPlaceholder = props => {
|
|
643
|
+
const { editor } = props;
|
|
644
|
+
const { document } = editor.value;
|
|
645
|
+
|
|
646
|
+
if (!editor.props.placeholder || document.text !== '' || document.nodes.size !== 1) {
|
|
647
|
+
return false;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
return (
|
|
651
|
+
<span
|
|
652
|
+
contentEditable={false}
|
|
653
|
+
style={{
|
|
654
|
+
display: 'inline-block',
|
|
655
|
+
width: 'fit-content', // for centering the placeholder if text-align is set to center
|
|
656
|
+
maxWidth: '100%',
|
|
657
|
+
whiteSpace: 'nowrap',
|
|
658
|
+
opacity: '0.33',
|
|
659
|
+
pointerEvents: 'none'
|
|
660
|
+
}}
|
|
661
|
+
>
|
|
662
|
+
{editor.props.placeholder}
|
|
663
|
+
</span>
|
|
664
|
+
);
|
|
665
|
+
};
|
|
666
|
+
|
|
642
667
|
render() {
|
|
643
668
|
const {
|
|
644
669
|
disabled,
|
|
@@ -704,6 +729,7 @@ export class Editor extends React.Component {
|
|
|
704
729
|
pluginProps={pluginProps}
|
|
705
730
|
toolbarOpts={toolbarOpts}
|
|
706
731
|
placeholder={placeholder}
|
|
732
|
+
renderPlaceholder={this.renderPlaceholder}
|
|
707
733
|
onDataChange={this.changeData}
|
|
708
734
|
/>
|
|
709
735
|
</div>
|
package/src/index.jsx
CHANGED
|
@@ -95,9 +95,9 @@ export default class EditableHtml extends React.Component {
|
|
|
95
95
|
c.focus();
|
|
96
96
|
|
|
97
97
|
if (position === 'end' && lastText) {
|
|
98
|
-
c.moveFocusTo(lastText.key, lastText.text
|
|
98
|
+
c.moveFocusTo(lastText.key, lastText.text?.length).moveAnchorTo(
|
|
99
99
|
lastText.key,
|
|
100
|
-
lastText.text
|
|
100
|
+
lastText.text?.length
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import DialogContent from '@material-ui/core/DialogContent';
|
|
3
|
+
import ArrowBackIos from '@material-ui/icons/ArrowBackIos';
|
|
4
|
+
import TextField from '@material-ui/core/TextField';
|
|
5
|
+
import DialogActions from '@material-ui/core/DialogActions';
|
|
6
|
+
import Button from '@material-ui/core/Button';
|
|
7
|
+
import Dialog from '@material-ui/core/Dialog';
|
|
8
|
+
import PropTypes from "prop-types";
|
|
9
|
+
|
|
10
|
+
export class AltDialog extends React.Component {
|
|
11
|
+
static propTypes = {
|
|
12
|
+
onDone: PropTypes.func.isRequired,
|
|
13
|
+
alt: PropTypes.string
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
constructor(props) {
|
|
17
|
+
super(props);
|
|
18
|
+
|
|
19
|
+
const { alt } = props;
|
|
20
|
+
|
|
21
|
+
this.state = {
|
|
22
|
+
value: alt
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
closeDialog = () => {
|
|
27
|
+
const allDialogs = document.querySelectorAll('#text-dialog');
|
|
28
|
+
|
|
29
|
+
allDialogs.forEach(function(s) {
|
|
30
|
+
return s.remove();
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
onDone = () => {
|
|
35
|
+
const { onDone } = this.props;
|
|
36
|
+
const { value } = this.state;
|
|
37
|
+
|
|
38
|
+
onDone(value);
|
|
39
|
+
this.closeDialog();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
render() {
|
|
43
|
+
const { value } = this.state;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Dialog open disablePortal onClose={this.closeDialog} id="text-dialog" hideBackdrop>
|
|
47
|
+
<DialogContent>
|
|
48
|
+
<div style={{ display: 'flex' }}>
|
|
49
|
+
<ArrowBackIos style={{ paddingTop: '6px' }} />
|
|
50
|
+
<TextField
|
|
51
|
+
multiline
|
|
52
|
+
placeholder={'Enter an Alt Text description of this image'}
|
|
53
|
+
helperText={
|
|
54
|
+
'Users with visual limitations rely on Alt Text, since screen readers cannot otherwise describe the contents of an image.'
|
|
55
|
+
}
|
|
56
|
+
value={value}
|
|
57
|
+
onChange={event => this.setState({ value: event.target.value })}
|
|
58
|
+
/>
|
|
59
|
+
</div>
|
|
60
|
+
</DialogContent>
|
|
61
|
+
<DialogActions>
|
|
62
|
+
<Button onClick={this.onDone}>Done</Button>
|
|
63
|
+
</DialogActions>
|
|
64
|
+
</Dialog>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default AltDialog;
|
|
@@ -208,6 +208,7 @@ export class Component extends React.Component {
|
|
|
208
208
|
const deleteStatus = node.data.get('deleteStatus');
|
|
209
209
|
const alignment = node.data.get('alignment');
|
|
210
210
|
const percent = node.data.get('percent');
|
|
211
|
+
const alt = node.data.get('alt');
|
|
211
212
|
let margin;
|
|
212
213
|
let justifyContent;
|
|
213
214
|
|
|
@@ -261,6 +262,7 @@ export class Component extends React.Component {
|
|
|
261
262
|
src={src}
|
|
262
263
|
style={size}
|
|
263
264
|
onLoad={this.loadImage}
|
|
265
|
+
alt={alt}
|
|
264
266
|
/>
|
|
265
267
|
<div
|
|
266
268
|
ref={ref => {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import debug from 'debug';
|
|
4
|
+
import ReactDOM from 'react-dom';
|
|
4
5
|
import { withStyles } from '@material-ui/core/styles';
|
|
6
|
+
import classNames from 'classnames';
|
|
5
7
|
|
|
6
8
|
import { MarkButton } from '../toolbar/toolbar-buttons';
|
|
9
|
+
import AltDialog from './alt-dialog';
|
|
7
10
|
|
|
8
11
|
const log = debug('@pie-lib:editable-html:plugins:image:image-toolbar');
|
|
9
12
|
|
|
@@ -24,16 +27,36 @@ AlignmentButton.propTypes = {
|
|
|
24
27
|
export class ImageToolbar extends React.Component {
|
|
25
28
|
static propTypes = {
|
|
26
29
|
onChange: PropTypes.func.isRequired,
|
|
27
|
-
classes: PropTypes.object.isRequired
|
|
30
|
+
classes: PropTypes.object.isRequired,
|
|
31
|
+
alignment: PropTypes.string,
|
|
32
|
+
alt: PropTypes.string,
|
|
33
|
+
imageLoaded: PropTypes.bool
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
onAltTextDone = newAlt => {
|
|
37
|
+
log('[onAltTextDone]: alt:', newAlt);
|
|
38
|
+
|
|
39
|
+
this.props.onChange({ alt: newAlt });
|
|
28
40
|
};
|
|
29
41
|
|
|
30
42
|
onAlignmentClick = alignment => {
|
|
31
43
|
log('[onAlignmentClick]: alignment:', alignment);
|
|
32
|
-
this.props.onChange(alignment);
|
|
44
|
+
this.props.onChange({ alignment });
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
renderDialog = () => {
|
|
48
|
+
const { alt } = this.props;
|
|
49
|
+
const popoverEl = document.createElement('div');
|
|
50
|
+
|
|
51
|
+
const el = <AltDialog alt={alt} onDone={this.onAltTextDone} />;
|
|
52
|
+
|
|
53
|
+
ReactDOM.render(el, popoverEl);
|
|
54
|
+
|
|
55
|
+
document.body.appendChild(popoverEl);
|
|
33
56
|
};
|
|
34
57
|
|
|
35
58
|
render() {
|
|
36
|
-
const { classes, alignment } = this.props;
|
|
59
|
+
const { classes, alignment, imageLoaded } = this.props;
|
|
37
60
|
|
|
38
61
|
return (
|
|
39
62
|
<div className={classes.holder}>
|
|
@@ -52,6 +75,15 @@ export class ImageToolbar extends React.Component {
|
|
|
52
75
|
active={alignment === 'right'}
|
|
53
76
|
onClick={this.onAlignmentClick}
|
|
54
77
|
/>
|
|
78
|
+
<span
|
|
79
|
+
className={classNames({
|
|
80
|
+
[classes.disabled]: !imageLoaded,
|
|
81
|
+
[classes.altButton]: true
|
|
82
|
+
})}
|
|
83
|
+
onMouseDown={event => imageLoaded && this.renderDialog(event)}
|
|
84
|
+
>
|
|
85
|
+
Alt text
|
|
86
|
+
</span>
|
|
55
87
|
</div>
|
|
56
88
|
);
|
|
57
89
|
}
|
|
@@ -62,7 +94,15 @@ const styles = theme => ({
|
|
|
62
94
|
paddingLeft: theme.spacing.unit,
|
|
63
95
|
display: 'flex',
|
|
64
96
|
alignItems: 'center'
|
|
65
|
-
}
|
|
97
|
+
},
|
|
98
|
+
disabled: {
|
|
99
|
+
opacity: 0.5
|
|
100
|
+
},
|
|
101
|
+
altButton: {
|
|
102
|
+
borderLeft: '1px solid grey',
|
|
103
|
+
paddingLeft: 8,
|
|
104
|
+
marginLeft: 4,
|
|
105
|
+
},
|
|
66
106
|
});
|
|
67
107
|
|
|
68
108
|
export default withStyles(styles)(ImageToolbar);
|
|
@@ -30,17 +30,21 @@ export default function ImagePlugin(opts) {
|
|
|
30
30
|
supports: node => node.object === 'inline' && node.type === 'image',
|
|
31
31
|
customToolbar: (node, value, onToolbarDone) => {
|
|
32
32
|
const alignment = node.data.get('alignment');
|
|
33
|
-
const
|
|
33
|
+
const alt = node.data.get('alt');
|
|
34
|
+
const imageLoaded = node.data.get('loaded') !== false;
|
|
35
|
+
const onChange = newValues => {
|
|
34
36
|
const update = {
|
|
35
37
|
...node.data.toObject(),
|
|
36
|
-
|
|
38
|
+
...newValues
|
|
37
39
|
};
|
|
38
40
|
|
|
39
41
|
const change = value.change().setNodeByKey(node.key, { data: update });
|
|
40
42
|
onToolbarDone(change, false);
|
|
41
43
|
};
|
|
42
44
|
|
|
43
|
-
const Tb = () =>
|
|
45
|
+
const Tb = () => (
|
|
46
|
+
<ImageToolbar alt={alt} imageLoaded={imageLoaded} alignment={alignment || 'left'} onChange={onChange} />
|
|
47
|
+
);
|
|
44
48
|
return Tb;
|
|
45
49
|
},
|
|
46
50
|
showDone: true
|
|
@@ -150,7 +154,8 @@ export const serialization = {
|
|
|
150
154
|
height,
|
|
151
155
|
margin: el.style.margin,
|
|
152
156
|
justifyContent: el.style.justifyContent,
|
|
153
|
-
alignment: el.getAttribute('alignment')
|
|
157
|
+
alignment: el.getAttribute('alignment'),
|
|
158
|
+
alt: el.getAttribute('alt')
|
|
154
159
|
}
|
|
155
160
|
};
|
|
156
161
|
log('return object: ', out);
|
|
@@ -166,6 +171,7 @@ export const serialization = {
|
|
|
166
171
|
const alignment = data.get('alignment');
|
|
167
172
|
const margin = data.get('margin');
|
|
168
173
|
const justifyContent = data.get('margin');
|
|
174
|
+
const alt = data.get('alt');
|
|
169
175
|
const style = {};
|
|
170
176
|
if (width) {
|
|
171
177
|
style.width = `${width}px`;
|
|
@@ -203,7 +209,8 @@ export const serialization = {
|
|
|
203
209
|
const props = {
|
|
204
210
|
src,
|
|
205
211
|
style,
|
|
206
|
-
alignment
|
|
212
|
+
alignment,
|
|
213
|
+
alt
|
|
207
214
|
};
|
|
208
215
|
|
|
209
216
|
return <img {...props} />;
|
|
@@ -79,7 +79,9 @@ TableCell.propTypes = {
|
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
export const moveFocusToBeginningOfTable = change => {
|
|
82
|
-
const addedTable = change.value.document.findDescendant(
|
|
82
|
+
const addedTable = change.value.document.findDescendant(
|
|
83
|
+
d => !!d.data && !!d.data.get('newTable')
|
|
84
|
+
);
|
|
83
85
|
|
|
84
86
|
if (!addedTable) {
|
|
85
87
|
return;
|
|
@@ -85,9 +85,26 @@ export class EditorAndToolbar extends React.Component {
|
|
|
85
85
|
);
|
|
86
86
|
|
|
87
87
|
return (
|
|
88
|
-
<div
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
<div
|
|
89
|
+
className={classNames(
|
|
90
|
+
{
|
|
91
|
+
[classes.noBorder]: toolbarOpts && toolbarOpts.noBorder,
|
|
92
|
+
[classes.error]: toolbarOpts && toolbarOpts.error
|
|
93
|
+
},
|
|
94
|
+
classes.root
|
|
95
|
+
)}
|
|
96
|
+
>
|
|
97
|
+
<div className={holderNames} id={'holder'}>
|
|
98
|
+
<div
|
|
99
|
+
className={classNames(
|
|
100
|
+
{
|
|
101
|
+
[classes.noPadding]: toolbarOpts && toolbarOpts.noBorder
|
|
102
|
+
},
|
|
103
|
+
classes.children
|
|
104
|
+
)}
|
|
105
|
+
>
|
|
106
|
+
{clonedChildren}
|
|
107
|
+
</div>
|
|
91
108
|
</div>
|
|
92
109
|
<Toolbar
|
|
93
110
|
autoWidth={autoWidth}
|
|
@@ -219,6 +236,12 @@ const style = {
|
|
|
219
236
|
},
|
|
220
237
|
error: {
|
|
221
238
|
border: '2px solid red'
|
|
239
|
+
},
|
|
240
|
+
noBorder: {
|
|
241
|
+
border: 'none'
|
|
242
|
+
},
|
|
243
|
+
noPadding: {
|
|
244
|
+
padding: 0
|
|
222
245
|
}
|
|
223
246
|
};
|
|
224
247
|
|