@pie-lib/editable-html 7.22.4 → 8.0.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 +34 -0
- package/lib/editor.js +127 -100
- package/lib/editor.js.map +1 -1
- package/lib/plugins/characters/custom-popover.js +73 -0
- package/lib/plugins/characters/custom-popover.js.map +1 -0
- package/lib/plugins/characters/index.js +271 -0
- package/lib/plugins/characters/index.js.map +1 -0
- package/lib/plugins/characters/utils.js +362 -0
- package/lib/plugins/characters/utils.js.map +1 -0
- package/lib/plugins/image/component.js +190 -29
- package/lib/plugins/image/component.js.map +1 -1
- package/lib/plugins/image/image-toolbar.js +4 -58
- package/lib/plugins/image/image-toolbar.js.map +1 -1
- package/lib/plugins/image/index.js +3 -1
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/index.js +19 -4
- package/lib/plugins/index.js.map +1 -1
- package/package.json +5 -5
- package/src/editor.jsx +52 -15
- package/src/plugins/characters/custom-popover.js +45 -0
- package/src/plugins/characters/index.jsx +237 -0
- package/src/plugins/characters/utils.js +444 -0
- package/src/plugins/image/component.jsx +171 -19
- package/src/plugins/image/image-toolbar.jsx +2 -32
- package/src/plugins/image/index.jsx +3 -1
- package/src/plugins/index.jsx +3 -0
package/lib/plugins/index.js
CHANGED
|
@@ -15,6 +15,8 @@ var _image = _interopRequireDefault(require("./image"));
|
|
|
15
15
|
|
|
16
16
|
var _media = _interopRequireDefault(require("./media"));
|
|
17
17
|
|
|
18
|
+
var _characters = _interopRequireDefault(require("./characters"));
|
|
19
|
+
|
|
18
20
|
var _FormatItalic = _interopRequireDefault(require("@material-ui/icons/FormatItalic"));
|
|
19
21
|
|
|
20
22
|
var _math = _interopRequireDefault(require("./math"));
|
|
@@ -41,7 +43,18 @@ var _respArea = _interopRequireDefault(require("./respArea"));
|
|
|
41
43
|
|
|
42
44
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
47
|
+
|
|
48
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
49
|
+
|
|
50
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
51
|
+
|
|
52
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
53
|
+
|
|
54
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
55
|
+
|
|
56
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
57
|
+
|
|
45
58
|
var log = (0, _debug["default"])('@pie-lib:editable-html:plugins');
|
|
46
59
|
|
|
47
60
|
function MarkHotkey(options) {
|
|
@@ -79,7 +92,7 @@ function MarkHotkey(options) {
|
|
|
79
92
|
}
|
|
80
93
|
|
|
81
94
|
var ALL_PLUGINS = ['bold', // 'code',
|
|
82
|
-
'italic', 'underline', 'strikethrough', 'bulleted-list', 'numbered-list', 'image', 'math', 'table', 'video', 'audio', 'responseArea'];
|
|
95
|
+
'italic', 'underline', 'strikethrough', 'bulleted-list', 'numbered-list', 'image', 'math', 'languageCharacters', 'table', 'video', 'audio', 'responseArea'];
|
|
83
96
|
exports.ALL_PLUGINS = ALL_PLUGINS;
|
|
84
97
|
var DEFAULT_PLUGINS = ALL_PLUGINS.filter(function (plug) {
|
|
85
98
|
return plug !== 'responseArea';
|
|
@@ -118,7 +131,9 @@ var buildPlugins = function buildPlugins(activePlugins, opts) {
|
|
|
118
131
|
type: 'underline',
|
|
119
132
|
icon: /*#__PURE__*/_react["default"].createElement(_FormatUnderlined["default"], null),
|
|
120
133
|
tag: 'u'
|
|
121
|
-
})), addIf('image', imagePlugin), addIf('video', (0, _media["default"])('video', opts.media)), addIf('audio', (0, _media["default"])('audio', opts.media)), addIf('math', mathPlugin)
|
|
134
|
+
})), addIf('image', imagePlugin), addIf('video', (0, _media["default"])('video', opts.media)), addIf('audio', (0, _media["default"])('audio', opts.media)), addIf('math', mathPlugin)].concat(_toConsumableArray(opts.languageCharacters.map(function (config) {
|
|
135
|
+
return addIf('languageCharacters', (0, _characters["default"])(config));
|
|
136
|
+
})), [addIf('bulleted-list', (0, _list["default"])({
|
|
122
137
|
key: 'l',
|
|
123
138
|
type: 'ul_list',
|
|
124
139
|
icon: /*#__PURE__*/_react["default"].createElement(_FormatListBulleted["default"], null)
|
|
@@ -128,7 +143,7 @@ var buildPlugins = function buildPlugins(activePlugins, opts) {
|
|
|
128
143
|
icon: /*#__PURE__*/_react["default"].createElement(_FormatListNumbered["default"], null)
|
|
129
144
|
})), (0, _toolbar["default"])(opts.toolbar), (0, _slateSoftBreak["default"])({
|
|
130
145
|
shift: true
|
|
131
|
-
}), addIf('responseArea', respAreaPlugin)]);
|
|
146
|
+
}), addIf('responseArea', respAreaPlugin)]));
|
|
132
147
|
};
|
|
133
148
|
|
|
134
149
|
exports.buildPlugins = buildPlugins;
|
package/lib/plugins/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/index.jsx"],"names":["log","MarkHotkey","options","type","key","icon","tag","toolbar","isMark","onToggle","change","toggleMark","renderMark","props","mark","K","children","onKeyDown","event","metaKey","preventDefault","ALL_PLUGINS","DEFAULT_PLUGINS","filter","plug","buildPlugins","activePlugins","opts","addIf","p","includes","imagePlugin","image","onDelete","mathPlugin","math","respAreaPlugin","responseArea","table","media","shift"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/index.jsx"],"names":["log","MarkHotkey","options","type","key","icon","tag","toolbar","isMark","onToggle","change","toggleMark","renderMark","props","mark","K","children","onKeyDown","event","metaKey","preventDefault","ALL_PLUGINS","DEFAULT_PLUGINS","filter","plug","buildPlugins","activePlugins","opts","addIf","p","includes","imagePlugin","image","onDelete","mathPlugin","math","respAreaPlugin","responseArea","table","media","languageCharacters","map","config","shift"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,gCAAN,CAAZ;;AAEA,SAASC,UAAT,CAAoBC,OAApB,EAA6B;AAC3B,MAAQC,IAAR,GAAiCD,OAAjC,CAAQC,IAAR;AAAA,MAAcC,GAAd,GAAiCF,OAAjC,CAAcE,GAAd;AAAA,MAAmBC,IAAnB,GAAiCH,OAAjC,CAAmBG,IAAnB;AAAA,MAAyBC,GAAzB,GAAiCJ,OAAjC,CAAyBI,GAAzB,CAD2B,CAG3B;;AACA,SAAO;AACLC,IAAAA,OAAO,EAAE;AACPC,MAAAA,MAAM,EAAE,IADD;AAEPL,MAAAA,IAAI,EAAJA,IAFO;AAGPE,MAAAA,IAAI,EAAJA,IAHO;AAIPI,MAAAA,QAAQ,EAAE,kBAAAC,MAAM,EAAI;AAClBV,QAAAA,GAAG,CAAC,uBAAD,EAA0BG,IAA1B,CAAH;AACA,eAAOO,MAAM,CAACC,UAAP,C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AAAA,IAAI,EAAE,WAAlB;AAA+BE,IAAAA,IAAI,eAAE,gCAAC,4BAAD,OAArC;AAAoDC,IAAAA,GAAG,EAAE;AAAzD,GAAD,CAAxB,CAdA,EAeLsB,KAAK,CAAC,OAAD,EAAUG,WAAV,CAfA,EAgBLH,KAAK,CAAC,OAAD,EAAU,uBAAY,OAAZ,EAAqBD,IAAI,CAACY,KAA1B,CAAV,CAhBA,EAiBLX,KAAK,CAAC,OAAD,EAAU,uBAAY,OAAZ,EAAqBD,IAAI,CAACY,KAA1B,CAAV,CAjBA,EAkBLX,KAAK,CAAC,MAAD,EAASM,UAAT,CAlBA,4BAmBFP,IAAI,CAACa,kBAAL,CAAwBC,GAAxB,CAA4B,UAAAC,MAAM;AAAA,WAAId,KAAK,CAAC,oBAAD,EAAuB,4BAAiBc,MAAjB,CAAvB,CAAT;AAAA,GAAlC,CAnBE,IAoBLd,KAAK,CAAC,eAAD,EAAkB,sBAAK;AAAExB,IAAAA,GAAG,EAAE,GAAP;AAAYD,IAAAA,IAAI,EAAE,SAAlB;AAA6BE,IAAAA,IAAI,eAAE,gCAAC,8BAAD;AAAnC,GAAL,CAAlB,CApBA,EAqBLuB,KAAK,CAAC,eAAD,EAAkB,sBAAK;AAAExB,IAAAA,GAAG,EAAE,GAAP;AAAYD,IAAAA,IAAI,EAAE,SAAlB;AAA6BE,IAAAA,IAAI,eAAE,gCAAC,8BAAD;AAAnC,GAAL,CAAlB,CArBA,EAsBL,yBAAcsB,IAAI,CAACpB,OAAnB,CAtBK,EAuBL,gCAAgB;AAAEoC,IAAAA,KAAK,EAAE;AAAT,GAAhB,CAvBK,EAwBLf,KAAK,CAAC,cAAD,EAAiBQ,cAAjB,CAxBA,GAAP;AA0BD,CAvCM","sourcesContent":["import Bold from '@material-ui/icons/FormatBold';\n// import Code from '@material-ui/icons/Code';\nimport BulletedListIcon from '@material-ui/icons/FormatListBulleted';\nimport NumberedListIcon from '@material-ui/icons/FormatListNumbered';\nimport ImagePlugin from './image';\nimport MediaPlugin from './media';\nimport CharactersPlugin from './characters';\nimport Italic from '@material-ui/icons/FormatItalic';\nimport MathPlugin from './math';\nimport React from 'react';\nimport Strikethrough from '@material-ui/icons/FormatStrikethrough';\nimport ToolbarPlugin from './toolbar';\nimport Underline from '@material-ui/icons/FormatUnderlined';\nimport compact from 'lodash/compact';\nimport SoftBreakPlugin from 'slate-soft-break';\nimport debug from 'debug';\nimport List from './list';\nimport TablePlugin from './table';\nimport RespAreaPlugin from './respArea';\n\nconst log = debug('@pie-lib:editable-html:plugins');\n\nfunction MarkHotkey(options) {\n const { type, key, icon, tag } = options;\n\n // Return our \"plugin\" object, containing the `onKeyDown` handler.\n return {\n toolbar: {\n isMark: true,\n type,\n icon,\n onToggle: change => {\n log('[onToggleMark] type: ', type);\n return change.toggleMark(type);\n }\n },\n renderMark(props) {\n if (props.mark.type === type) {\n const K = tag || type;\n return <K>{props.children}</K>;\n }\n },\n onKeyDown(event, change) {\n // Check that the key pressed matches our `key` option.\n if (!event.metaKey || event.key != key) return;\n\n // Prevent the default characters from being inserted.\n event.preventDefault();\n\n // Toggle the mark `type`.\n change.toggleMark(type);\n return true;\n }\n };\n}\n\nexport const ALL_PLUGINS = [\n 'bold',\n // 'code',\n 'italic',\n 'underline',\n 'strikethrough',\n 'bulleted-list',\n 'numbered-list',\n 'image',\n 'math',\n 'languageCharacters',\n 'table',\n 'video',\n 'audio',\n 'responseArea'\n];\n\nexport const DEFAULT_PLUGINS = ALL_PLUGINS.filter(plug => plug !== 'responseArea');\n\nexport const buildPlugins = (activePlugins, opts) => {\n log('[buildPlugins] opts: ', opts);\n\n activePlugins = activePlugins || DEFAULT_PLUGINS;\n\n const addIf = (key, p) => activePlugins.includes(key) && p;\n const imagePlugin = opts.image && opts.image.onDelete && ImagePlugin(opts.image);\n const mathPlugin = MathPlugin(opts.math);\n const respAreaPlugin =\n opts.responseArea &&\n opts.responseArea.type &&\n RespAreaPlugin(opts.responseArea, compact([mathPlugin]));\n\n return compact([\n addIf('table', TablePlugin(opts.table, compact([imagePlugin, mathPlugin, respAreaPlugin]))),\n addIf('bold', MarkHotkey({ key: 'b', type: 'bold', icon: <Bold />, tag: 'strong' })),\n // addIf('code', MarkHotkey({ key: '`', type: 'code', icon: <Code /> })),\n addIf('italic', MarkHotkey({ key: 'i', type: 'italic', icon: <Italic />, tag: 'em' })),\n addIf(\n 'strikethrough',\n MarkHotkey({\n key: '~',\n type: 'strikethrough',\n icon: <Strikethrough />,\n tag: 'del'\n })\n ),\n addIf('underline', MarkHotkey({ key: 'u', type: 'underline', icon: <Underline />, tag: 'u' })),\n addIf('image', imagePlugin),\n addIf('video', MediaPlugin('video', opts.media)),\n addIf('audio', MediaPlugin('audio', opts.media)),\n addIf('math', mathPlugin),\n ...opts.languageCharacters.map(config => addIf('languageCharacters', CharactersPlugin(config))),\n addIf('bulleted-list', List({ key: 'l', type: 'ul_list', icon: <BulletedListIcon /> })),\n addIf('numbered-list', List({ key: 'n', type: 'ol_list', icon: <NumberedListIcon /> })),\n ToolbarPlugin(opts.toolbar),\n SoftBreakPlugin({ shift: true }),\n addIf('responseArea', respAreaPlugin)\n ]);\n};\n"],"file":"index.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/editable-html",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"@material-ui/icons": "^3.0.2",
|
|
12
12
|
"@material-ui/styles": "^3.0.0-alpha.10",
|
|
13
13
|
"@pie-lib/drag": "^1.1.52",
|
|
14
|
-
"@pie-lib/math-rendering": "^2.4.
|
|
15
|
-
"@pie-lib/math-toolbar": "^1.9.
|
|
16
|
-
"@pie-lib/render-ui": "^4.12.
|
|
14
|
+
"@pie-lib/math-rendering": "^2.4.3",
|
|
15
|
+
"@pie-lib/math-toolbar": "^1.9.4",
|
|
16
|
+
"@pie-lib/render-ui": "^4.12.9",
|
|
17
17
|
"change-case": "^3.0.2",
|
|
18
18
|
"classnames": "^2.2.6",
|
|
19
19
|
"debug": "^4.1.1",
|
|
@@ -46,6 +46,6 @@
|
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "2f841d92dcda7472f18cbce517eb664dec2f6442",
|
|
50
50
|
"scripts": {}
|
|
51
51
|
}
|
package/src/editor.jsx
CHANGED
|
@@ -30,6 +30,8 @@ const defaultResponseAreaProps = {
|
|
|
30
30
|
onHandleAreaChange: () => {}
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
const defaultLanguageCharactersProps = [];
|
|
34
|
+
|
|
33
35
|
const createToolbarOpts = toolbarOpts => {
|
|
34
36
|
return {
|
|
35
37
|
...defaultToolbarOpts,
|
|
@@ -49,6 +51,7 @@ export class Editor extends React.Component {
|
|
|
49
51
|
focus: PropTypes.func.isRequired,
|
|
50
52
|
value: SlateTypes.value.isRequired,
|
|
51
53
|
imageSupport: PropTypes.object,
|
|
54
|
+
charactersLimit: PropTypes.number,
|
|
52
55
|
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
53
56
|
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
54
57
|
minHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
@@ -72,6 +75,13 @@ export class Editor extends React.Component {
|
|
|
72
75
|
respAreaToolbar: PropTypes.func,
|
|
73
76
|
onHandleAreaChange: PropTypes.func
|
|
74
77
|
}),
|
|
78
|
+
languageCharactersProps: PropTypes.arrayOf(
|
|
79
|
+
PropTypes.shape({
|
|
80
|
+
language: PropTypes.string,
|
|
81
|
+
characterIcon: PropTypes.string,
|
|
82
|
+
characters: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.string))
|
|
83
|
+
})
|
|
84
|
+
),
|
|
75
85
|
toolbarOpts: PropTypes.shape({
|
|
76
86
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
77
87
|
alignment: PropTypes.oneOf(['left', 'right']),
|
|
@@ -87,7 +97,9 @@ export class Editor extends React.Component {
|
|
|
87
97
|
new Error(`Invalid values: ${values}, values must be one of [${ALL_PLUGINS.join(',')}]`)
|
|
88
98
|
);
|
|
89
99
|
}),
|
|
90
|
-
className: PropTypes.string
|
|
100
|
+
className: PropTypes.string,
|
|
101
|
+
maxImageWidth: PropTypes.number,
|
|
102
|
+
maxImageHeight: PropTypes.number,
|
|
91
103
|
};
|
|
92
104
|
|
|
93
105
|
static defaultProps = {
|
|
@@ -96,7 +108,8 @@ export class Editor extends React.Component {
|
|
|
96
108
|
onBlur: () => {},
|
|
97
109
|
onKeyDown: () => {},
|
|
98
110
|
toolbarOpts: defaultToolbarOpts,
|
|
99
|
-
responseAreaProps: defaultResponseAreaProps
|
|
111
|
+
responseAreaProps: defaultResponseAreaProps,
|
|
112
|
+
languageCharactersProps: defaultLanguageCharactersProps
|
|
100
113
|
};
|
|
101
114
|
|
|
102
115
|
constructor(props) {
|
|
@@ -106,15 +119,19 @@ export class Editor extends React.Component {
|
|
|
106
119
|
toolbarOpts: createToolbarOpts(props.toolbarOpts)
|
|
107
120
|
};
|
|
108
121
|
|
|
122
|
+
this.onResize = () => {
|
|
123
|
+
props.onChange(this.state.value, true);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
this.handlePlugins(this.props);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
handlePlugins = props => {
|
|
109
130
|
const normalizedResponseAreaProps = {
|
|
110
131
|
...defaultResponseAreaProps,
|
|
111
132
|
...props.responseAreaProps
|
|
112
133
|
};
|
|
113
134
|
|
|
114
|
-
this.onResize = () => {
|
|
115
|
-
props.onChange(this.state.value, true);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
135
|
this.plugins = buildPlugins(props.activePlugins, {
|
|
119
136
|
math: {
|
|
120
137
|
onClick: this.onMathClick,
|
|
@@ -123,25 +140,27 @@ export class Editor extends React.Component {
|
|
|
123
140
|
},
|
|
124
141
|
image: {
|
|
125
142
|
onDelete:
|
|
126
|
-
|
|
127
|
-
|
|
143
|
+
props.imageSupport &&
|
|
144
|
+
props.imageSupport.delete &&
|
|
128
145
|
((src, done) => {
|
|
129
|
-
|
|
146
|
+
props.imageSupport.delete(src, e => {
|
|
130
147
|
done(e, this.state.value);
|
|
131
148
|
});
|
|
132
149
|
}),
|
|
133
150
|
insertImageRequested:
|
|
134
|
-
|
|
151
|
+
props.imageSupport &&
|
|
135
152
|
(getHandler => {
|
|
136
153
|
/**
|
|
137
154
|
* The handler is the object through which the outer context
|
|
138
155
|
* communicates file upload events like: fileChosen, cancel, progress
|
|
139
156
|
*/
|
|
140
157
|
const handler = getHandler(() => this.state.value);
|
|
141
|
-
|
|
158
|
+
props.imageSupport.add(handler);
|
|
142
159
|
}),
|
|
143
160
|
onFocus: this.onPluginFocus,
|
|
144
|
-
onBlur: this.onPluginBlur
|
|
161
|
+
onBlur: this.onPluginBlur,
|
|
162
|
+
maxImageWidth: this.props.maxImageWidth,
|
|
163
|
+
maxImageHeight: this.props.maxImageHeight,
|
|
145
164
|
},
|
|
146
165
|
toolbar: {
|
|
147
166
|
/**
|
|
@@ -151,7 +170,7 @@ export class Editor extends React.Component {
|
|
|
151
170
|
disableUnderline: props.disableUnderline,
|
|
152
171
|
autoWidth: props.autoWidthToolbar,
|
|
153
172
|
onDone: () => {
|
|
154
|
-
const { nonEmpty } =
|
|
173
|
+
const { nonEmpty } = props;
|
|
155
174
|
|
|
156
175
|
log('[onDone]');
|
|
157
176
|
this.setState({ toolbarInFocus: false, focusedNode: null });
|
|
@@ -192,13 +211,14 @@ export class Editor extends React.Component {
|
|
|
192
211
|
this.onPluginBlur();
|
|
193
212
|
}
|
|
194
213
|
},
|
|
214
|
+
languageCharacters: props.languageCharactersProps,
|
|
195
215
|
media: {
|
|
196
216
|
focus: this.focus,
|
|
197
217
|
createChange: () => this.state.value.change(),
|
|
198
218
|
onChange: this.onChange
|
|
199
219
|
}
|
|
200
220
|
});
|
|
201
|
-
}
|
|
221
|
+
};
|
|
202
222
|
|
|
203
223
|
componentDidMount() {
|
|
204
224
|
// onRef is needed to get the ref of the component because we export it using withStyles
|
|
@@ -232,6 +252,10 @@ export class Editor extends React.Component {
|
|
|
232
252
|
toolbarOpts: newToolbarOpts
|
|
233
253
|
});
|
|
234
254
|
}
|
|
255
|
+
|
|
256
|
+
if (!isEqual(nextProps.languageCharactersProps, this.props.languageCharactersProps)) {
|
|
257
|
+
this.handlePlugins(nextProps);
|
|
258
|
+
}
|
|
235
259
|
}
|
|
236
260
|
|
|
237
261
|
componentDidUpdate() {
|
|
@@ -440,7 +464,20 @@ export class Editor extends React.Component {
|
|
|
440
464
|
|
|
441
465
|
onChange = (change, done) => {
|
|
442
466
|
log('[onChange]');
|
|
443
|
-
|
|
467
|
+
|
|
468
|
+
const { value } = change;
|
|
469
|
+
const { charactersLimit } = this.props;
|
|
470
|
+
|
|
471
|
+
if (
|
|
472
|
+
value &&
|
|
473
|
+
value.document &&
|
|
474
|
+
value.document.text &&
|
|
475
|
+
value.document.text.length > charactersLimit
|
|
476
|
+
) {
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
this.setState({ value }, () => {
|
|
444
481
|
log('[onChange], call done()');
|
|
445
482
|
|
|
446
483
|
if (done) {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { withStyles } from '@material-ui/core/styles';
|
|
3
|
+
import Popover from '@material-ui/core/Popover';
|
|
4
|
+
import Typography from '@material-ui/core/Typography';
|
|
5
|
+
|
|
6
|
+
const styles = () => ({
|
|
7
|
+
popover: {
|
|
8
|
+
pointerEvents: 'none',
|
|
9
|
+
zIndex: 99999
|
|
10
|
+
},
|
|
11
|
+
paper: {
|
|
12
|
+
padding: 20,
|
|
13
|
+
height: 'auto',
|
|
14
|
+
width: 'auto'
|
|
15
|
+
},
|
|
16
|
+
typography: {
|
|
17
|
+
fontSize: 50,
|
|
18
|
+
textAlign: 'center'
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const CustomPopOver = withStyles(styles)(({ classes, children, ...props }) => (
|
|
23
|
+
<Popover
|
|
24
|
+
id="mouse-over-popover"
|
|
25
|
+
open
|
|
26
|
+
className={classes.popover}
|
|
27
|
+
classes={{
|
|
28
|
+
paper: classes.paper
|
|
29
|
+
}}
|
|
30
|
+
anchorOrigin={{
|
|
31
|
+
vertical: 'bottom',
|
|
32
|
+
horizontal: 'left'
|
|
33
|
+
}}
|
|
34
|
+
transformOrigin={{
|
|
35
|
+
vertical: 'top',
|
|
36
|
+
horizontal: 'left'
|
|
37
|
+
}}
|
|
38
|
+
disableRestoreFocus
|
|
39
|
+
{...props}
|
|
40
|
+
>
|
|
41
|
+
<Typography classes={{ root: classes.typography }}>{children}</Typography>
|
|
42
|
+
</Popover>
|
|
43
|
+
));
|
|
44
|
+
|
|
45
|
+
export default CustomPopOver;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import debug from 'debug';
|
|
4
|
+
import get from 'lodash/get';
|
|
5
|
+
|
|
6
|
+
import { PureToolbar } from '@pie-lib/math-toolbar';
|
|
7
|
+
|
|
8
|
+
import CustomPopOver from './custom-popover';
|
|
9
|
+
import { insertSnackBar } from '../respArea/utils';
|
|
10
|
+
import { characterIcons, spanishConfig, specialConfig } from './utils';
|
|
11
|
+
const log = debug('@pie-lib:editable-html:plugins:characters');
|
|
12
|
+
|
|
13
|
+
const removeDialogs = () => {
|
|
14
|
+
const prevDialogs = document.querySelectorAll('.insert-character-dialog');
|
|
15
|
+
|
|
16
|
+
log('[characters:removeDialogs]');
|
|
17
|
+
prevDialogs.forEach(s => s.remove());
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const removePopOvers = () => {
|
|
21
|
+
const prevPopOvers = document.querySelectorAll('#mouse-over-popover');
|
|
22
|
+
|
|
23
|
+
log('[characters:removePopOvers]');
|
|
24
|
+
prevPopOvers.forEach(s => s.remove());
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const insertDialog = ({ value, callback, opts }) => {
|
|
28
|
+
const newEl = document.createElement('div');
|
|
29
|
+
const initialBodyOverflow = document.body.style.overflow;
|
|
30
|
+
|
|
31
|
+
log('[characters:insertDialog]');
|
|
32
|
+
|
|
33
|
+
removeDialogs();
|
|
34
|
+
|
|
35
|
+
newEl.className = 'insert-character-dialog';
|
|
36
|
+
document.body.style.overflow = 'hidden';
|
|
37
|
+
|
|
38
|
+
let configToUse;
|
|
39
|
+
|
|
40
|
+
switch (true) {
|
|
41
|
+
case opts.language === 'spanish':
|
|
42
|
+
configToUse = spanishConfig;
|
|
43
|
+
break;
|
|
44
|
+
case opts.language === 'special':
|
|
45
|
+
configToUse = specialConfig;
|
|
46
|
+
break;
|
|
47
|
+
default:
|
|
48
|
+
configToUse = opts;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!configToUse.characters) {
|
|
52
|
+
insertSnackBar('No characters provided or language not recognized');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const layoutForCharacters = configToUse.characters.reduce(
|
|
57
|
+
(obj, arr) => {
|
|
58
|
+
if (arr.length >= obj.columns) {
|
|
59
|
+
obj.columns = arr.length;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return obj;
|
|
63
|
+
},
|
|
64
|
+
{ rows: configToUse.characters.length, columns: 0 }
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
let popoverEl;
|
|
68
|
+
|
|
69
|
+
const closePopOver = () => {
|
|
70
|
+
if (popoverEl) {
|
|
71
|
+
popoverEl.remove();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
removePopOvers();
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const renderPopOver = (event, el) => {
|
|
78
|
+
if (!event) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const infoStyle = { fontSize: '20px', lineHeight: '20px' };
|
|
83
|
+
|
|
84
|
+
closePopOver();
|
|
85
|
+
|
|
86
|
+
popoverEl = document.createElement('div');
|
|
87
|
+
ReactDOM.render(
|
|
88
|
+
<CustomPopOver onClose={closePopOver} anchorEl={event.currentTarget}>
|
|
89
|
+
<div>{el.label}</div>
|
|
90
|
+
|
|
91
|
+
<div style={infoStyle}>{el.description}</div>
|
|
92
|
+
|
|
93
|
+
<div style={infoStyle}>{el.unicode}</div>
|
|
94
|
+
</CustomPopOver>,
|
|
95
|
+
popoverEl
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
document.body.appendChild(newEl);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const handleClose = () => {
|
|
102
|
+
newEl.remove();
|
|
103
|
+
closePopOver();
|
|
104
|
+
document.body.style.overflow = initialBodyOverflow;
|
|
105
|
+
callback(undefined, true);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const handleChange = val => {
|
|
109
|
+
if (typeof val === 'string') {
|
|
110
|
+
callback(val);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (configToUse.autoClose) {
|
|
114
|
+
handleClose();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const el = (
|
|
119
|
+
<PureToolbar
|
|
120
|
+
autoFocus
|
|
121
|
+
noDecimal
|
|
122
|
+
hideInput
|
|
123
|
+
noLatexHandling
|
|
124
|
+
layoutForKeyPad={layoutForCharacters}
|
|
125
|
+
additionalKeys={configToUse.characters.reduce((arr, n) => {
|
|
126
|
+
arr = [
|
|
127
|
+
...arr,
|
|
128
|
+
...n.map(k => ({
|
|
129
|
+
name: get(k, 'name') || k,
|
|
130
|
+
write: get(k, 'write') || k,
|
|
131
|
+
label: get(k, 'label') || k,
|
|
132
|
+
category: 'character',
|
|
133
|
+
extraClass: 'character',
|
|
134
|
+
...(configToUse.hasPreview
|
|
135
|
+
? {
|
|
136
|
+
actions: { onMouseEnter: ev => renderPopOver(ev, k), onMouseLeave: closePopOver }
|
|
137
|
+
}
|
|
138
|
+
: {})
|
|
139
|
+
}))
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
return arr;
|
|
143
|
+
}, [])}
|
|
144
|
+
keypadMode="language"
|
|
145
|
+
onChange={handleChange}
|
|
146
|
+
onDone={handleClose}
|
|
147
|
+
/>
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
ReactDOM.render(el, newEl, () => {
|
|
151
|
+
const cursorItem = document.querySelector(`[data-key="${value.anchorKey}"]`);
|
|
152
|
+
|
|
153
|
+
if (cursorItem) {
|
|
154
|
+
const boundRect = cursorItem.getBoundingClientRect();
|
|
155
|
+
|
|
156
|
+
document.body.appendChild(newEl);
|
|
157
|
+
newEl.style.position = 'fixed';
|
|
158
|
+
newEl.style.top = `${boundRect.top - newEl.offsetHeight - 10}px`;
|
|
159
|
+
newEl.style.left = `${boundRect.left + cursorItem.offsetWidth + 10}px`;
|
|
160
|
+
newEl.style.zIndex = 99999;
|
|
161
|
+
|
|
162
|
+
let firstCallMade = false;
|
|
163
|
+
|
|
164
|
+
const listener = () => {
|
|
165
|
+
// this will be triggered right after setting it because
|
|
166
|
+
// this toolbar is added on the mousedown event
|
|
167
|
+
// so right after mouseup, the click will be triggered
|
|
168
|
+
if (firstCallMade) {
|
|
169
|
+
document.body.removeEventListener('click', listener);
|
|
170
|
+
handleClose();
|
|
171
|
+
} else {
|
|
172
|
+
firstCallMade = true;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
if (configToUse.autoClose) {
|
|
177
|
+
document.body.addEventListener('click', listener);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const CharacterIcon = ({ letter }) => (
|
|
184
|
+
<div
|
|
185
|
+
style={{
|
|
186
|
+
fontSize: '25px',
|
|
187
|
+
lineHeight: '15px'
|
|
188
|
+
}}
|
|
189
|
+
>
|
|
190
|
+
{letter}
|
|
191
|
+
</div>
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
export default function CharactersPlugin(opts) {
|
|
195
|
+
removeDialogs();
|
|
196
|
+
return {
|
|
197
|
+
name: 'math',
|
|
198
|
+
toolbar: {
|
|
199
|
+
icon: <CharacterIcon letter={opts.characterIcon || characterIcons[opts.language] || 'ñ'} />,
|
|
200
|
+
onClick: (value, onChange) => {
|
|
201
|
+
let valueToUse = value;
|
|
202
|
+
const callback = (char, focus) => {
|
|
203
|
+
if (char) {
|
|
204
|
+
const change = valueToUse
|
|
205
|
+
.change()
|
|
206
|
+
.insertTextByKey(valueToUse.anchorKey, valueToUse.anchorOffset, char);
|
|
207
|
+
|
|
208
|
+
valueToUse = change.value;
|
|
209
|
+
log('[characters:insert]: ', value);
|
|
210
|
+
onChange(change);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
log('[characters:click]');
|
|
214
|
+
|
|
215
|
+
if (focus) {
|
|
216
|
+
const editorDOM = document.querySelector(`[data-key="${valueToUse.document.key}"]`);
|
|
217
|
+
|
|
218
|
+
if (editorDOM) {
|
|
219
|
+
editorDOM.focus();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
insertDialog({ value: valueToUse, callback, opts });
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
|
|
228
|
+
pluginStyles: (node, parentNode, p) => {
|
|
229
|
+
if (p) {
|
|
230
|
+
return {
|
|
231
|
+
position: 'absolute',
|
|
232
|
+
top: 'initial'
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|