@uxf/wysiwyg 13.0.3 → 14.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.
Files changed (33) hide show
  1. package/hooks.js +21 -7
  2. package/package.json +8 -8
  3. package/plugins/image/create-image-plugin.js +6 -0
  4. package/plugins/image/image-upload-errors.test.d.ts +1 -0
  5. package/plugins/image/image-upload-errors.test.js +78 -0
  6. package/plugins/image/with-paste-image-url.js +24 -3
  7. package/plugins/link/floating-link-wrapper.js +111 -8
  8. package/plugins/link/hooks/use-floating-link-selectors.js +67 -7
  9. package/plugins/link/hooks/use-link-actions.js +127 -31
  10. package/plugins/link/hooks/use-link-submit-on-enter.js +58 -12
  11. package/ui/button/button-element.js +72 -48
  12. package/ui/button/insert-button-modal-content.js +183 -40
  13. package/ui/components/modal/modal-button-cancel.js +46 -44
  14. package/ui/floating-link.js +381 -46
  15. package/ui/image/image-element.js +72 -48
  16. package/ui/image/insert-image-modal-content.js +268 -45
  17. package/ui/paragraph-element.js +1 -1
  18. package/ui/paragraph-element.test.d.ts +1 -0
  19. package/ui/paragraph-element.test.js +15 -0
  20. package/ui/toolbar/buttons/button-toolbar-button.js +37 -2
  21. package/ui/toolbar/buttons/element-toolbar-button.js +53 -8
  22. package/ui/toolbar/buttons/image-toolbar-button.js +37 -2
  23. package/ui/toolbar/buttons/link-toolbar-button.js +53 -9
  24. package/ui/toolbar/buttons/list-toolbar-button.js +50 -9
  25. package/ui/toolbar/buttons/mark-toolbar-button.js +49 -9
  26. package/ui/toolbar/buttons/toolbar-button.js +59 -14
  27. package/ui/toolbar/buttons/undo-redo-button-group.js +132 -58
  28. package/ui/toolbar/buttons/video-toolbar-button.js +37 -2
  29. package/ui/toolbar/toolbar.js +162 -38
  30. package/ui/video/insert-video-modal-content.js +160 -36
  31. package/ui/video/video-element.js +83 -48
  32. package/wysiwyg-editor.js +187 -37
  33. package/wysiwyg-editor.stories.js +291 -121
package/wysiwyg-editor.js CHANGED
@@ -35,8 +35,9 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  })();
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.WysiwygEditor = void 0;
38
+ const compiler_runtime_1 = require("react/compiler-runtime");
38
39
  const classes_1 = require("@uxf/core/constants/classes");
39
- const use_is_mounted_1 = require("@uxf/core-react/hooks/use-is-mounted");
40
+ const use_is_hydrated_1 = require("@uxf/core-react/hooks/use-is-hydrated");
40
41
  const translations_1 = require("@uxf/core-react/translations");
41
42
  const loader_1 = require("@uxf/ui/loader");
42
43
  const react_1 = require("platejs/react");
@@ -50,50 +51,199 @@ const CLASS_NAME = "uxf-wysiwyg";
50
51
  * Must be rendered inside Plate component
51
52
  */
52
53
  function EditorRefHandler(props) {
54
+ const $ = (0, compiler_runtime_1.c)(2);
55
+ const { ref } = props;
53
56
  const editor = (0, hooks_1.useUxfEditorRef)();
54
- (0, react_2.useImperativeHandle)(props.ref, () => ({
55
- focus: () => {
56
- // Select the end of the document first
57
- editor.tf.select(editor.api.end([]));
58
- // Then focus the editor
59
- (0, utils_1.focusEditor)(editor);
60
- },
61
- }));
57
+ let t0;
58
+ if ($[0] !== editor) {
59
+ t0 = () => ({
60
+ focus: () => {
61
+ editor.tf.select(editor.api.end([]));
62
+ (0, utils_1.focusEditor)(editor);
63
+ }
64
+ });
65
+ $[0] = editor;
66
+ $[1] = t0;
67
+ }
68
+ else {
69
+ t0 = $[1];
70
+ }
71
+ (0, react_2.useImperativeHandle)(ref, t0);
62
72
  return null;
63
73
  }
64
74
  EditorRefHandler.displayName = "EditorRefHandler";
65
- const Editor = (props) => {
75
+ const Editor = props => {
66
76
  var _a, _b;
77
+ const $ = (0, compiler_runtime_1.c)(29);
78
+ const { ref } = props;
67
79
  const t = (0, translations_1.useUxfTranslation)();
68
- /**
69
- * `<Plate>` renders no DOM of its own, so the toolbar moving inside it leaves the markup identical
70
- * while letting it take the editor from context instead of by id.
71
- */
72
- const editor = (0, react_1.usePlateEditor)({
73
- id: props.id,
74
- plugins: props.plugins,
75
- shouldNormalizeEditor: true,
76
- value: props.initialValue,
77
- }, [props.plugins]);
78
- return (react_2.default.createElement(react_1.Plate, { editor: editor, onChange: ({ value }) => props.onChange(value) },
79
- react_2.default.createElement(toolbar_1.Toolbar, { customPluginsButtons: props.customPluginsToolbarButtons, leftElement: props.toolbarLeftElement, plateId: props.id, rightElement: props.toolbarRightElement }),
80
- react_2.default.createElement("div", { className: `${CLASS_NAME}__content` },
81
- react_2.default.createElement(react_1.PlateContent, { autoFocus: false,
82
- placeholder: t("uxf-wysiwyg:common.placeholder"),
83
- readOnly: false,
84
- spellCheck: false,
85
- ...props.editableProps,
86
- className: `${CLASS_NAME}__editable ${(_b = (_a = props.editableProps) === null || _a === void 0 ? void 0 : _a.className) !== null && _b !== void 0 ? _b : ""}` }),
87
- props.ref && react_2.default.createElement(EditorRefHandler, { ref: props.ref }))));
80
+ let t0;
81
+ if ($[0] !== props.id || $[1] !== props.initialValue || $[2] !== props.plugins) {
82
+ t0 = {
83
+ id: props.id,
84
+ plugins: props.plugins,
85
+ shouldNormalizeEditor: true,
86
+ value: props.initialValue
87
+ };
88
+ $[0] = props.id;
89
+ $[1] = props.initialValue;
90
+ $[2] = props.plugins;
91
+ $[3] = t0;
92
+ }
93
+ else {
94
+ t0 = $[3];
95
+ }
96
+ let t1;
97
+ if ($[4] !== props.plugins) {
98
+ t1 = [props.plugins];
99
+ $[4] = props.plugins;
100
+ $[5] = t1;
101
+ }
102
+ else {
103
+ t1 = $[5];
104
+ }
105
+ const editor = (0, react_1.usePlateEditor)(t0, t1);
106
+ let t2;
107
+ if ($[6] !== props) {
108
+ t2 = t3 => {
109
+ const { value } = t3;
110
+ return props.onChange(value);
111
+ };
112
+ $[6] = props;
113
+ $[7] = t2;
114
+ }
115
+ else {
116
+ t2 = $[7];
117
+ }
118
+ let t3;
119
+ if ($[8] !== props.customPluginsToolbarButtons || $[9] !== props.id || $[10] !== props.toolbarLeftElement || $[11] !== props.toolbarRightElement) {
120
+ t3 = react_2.default.createElement(toolbar_1.Toolbar, { customPluginsButtons: props.customPluginsToolbarButtons, leftElement: props.toolbarLeftElement, plateId: props.id, rightElement: props.toolbarRightElement });
121
+ $[8] = props.customPluginsToolbarButtons;
122
+ $[9] = props.id;
123
+ $[10] = props.toolbarLeftElement;
124
+ $[11] = props.toolbarRightElement;
125
+ $[12] = t3;
126
+ }
127
+ else {
128
+ t3 = $[12];
129
+ }
130
+ let t4;
131
+ if ($[13] !== t) {
132
+ t4 = t("uxf-wysiwyg:common.placeholder");
133
+ $[13] = t;
134
+ $[14] = t4;
135
+ }
136
+ else {
137
+ t4 = $[14];
138
+ }
139
+ const t5 = `${CLASS_NAME}__editable ${(_b = (_a = props.editableProps) === null || _a === void 0 ? void 0 : _a.className) !== null && _b !== void 0 ? _b : ""}`;
140
+ let t6;
141
+ if ($[15] !== props.editableProps || $[16] !== t4 || $[17] !== t5) {
142
+ t6 = react_2.default.createElement(react_1.PlateContent, { autoFocus: false,
143
+ placeholder: t4,
144
+ readOnly: false,
145
+ spellCheck: false,
146
+ ...props.editableProps,
147
+ className: t5 });
148
+ $[15] = props.editableProps;
149
+ $[16] = t4;
150
+ $[17] = t5;
151
+ $[18] = t6;
152
+ }
153
+ else {
154
+ t6 = $[18];
155
+ }
156
+ let t7;
157
+ if ($[19] !== ref) {
158
+ t7 = ref && react_2.default.createElement(EditorRefHandler, { ref: ref });
159
+ $[19] = ref;
160
+ $[20] = t7;
161
+ }
162
+ else {
163
+ t7 = $[20];
164
+ }
165
+ let t8;
166
+ if ($[21] !== t6 || $[22] !== t7) {
167
+ t8 = react_2.default.createElement("div", { className: `${CLASS_NAME}__content` },
168
+ t6,
169
+ t7);
170
+ $[21] = t6;
171
+ $[22] = t7;
172
+ $[23] = t8;
173
+ }
174
+ else {
175
+ t8 = $[23];
176
+ }
177
+ let t9;
178
+ if ($[24] !== editor || $[25] !== t2 || $[26] !== t3 || $[27] !== t8) {
179
+ t9 = react_2.default.createElement(react_1.Plate, { editor: editor, onChange: t2 },
180
+ t3,
181
+ t8);
182
+ $[24] = editor;
183
+ $[25] = t2;
184
+ $[26] = t3;
185
+ $[27] = t8;
186
+ $[28] = t9;
187
+ }
188
+ else {
189
+ t9 = $[28];
190
+ }
191
+ return t9;
88
192
  };
89
- const WysiwygEditor = (props) => {
193
+ const WysiwygEditor = props => {
90
194
  var _a, _b;
91
- const isMounted = (0, use_is_mounted_1.useIsMounted)();
92
- if (!isMounted) {
93
- return (react_2.default.createElement("div", { className: `${CLASS_NAME} ${CLASS_NAME}--${classes_1.CLASSES.IS_LOADING} ${(_a = props.className) !== null && _a !== void 0 ? _a : ""}` },
94
- react_2.default.createElement(loader_1.Loader, { className: `${CLASS_NAME}__loader` })));
195
+ const $ = (0, compiler_runtime_1.c)(16);
196
+ const { ref } = props;
197
+ const isHydrated = (0, use_is_hydrated_1.useIsHydrated)();
198
+ if (!isHydrated) {
199
+ const t0 = `${CLASS_NAME} ${CLASS_NAME}--${classes_1.CLASSES.IS_LOADING} ${(_a = props.className) !== null && _a !== void 0 ? _a : ""}`;
200
+ let t1;
201
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
202
+ t1 = react_2.default.createElement(loader_1.Loader, { className: `${CLASS_NAME}__loader` });
203
+ $[0] = t1;
204
+ }
205
+ else {
206
+ t1 = $[0];
207
+ }
208
+ let t2;
209
+ if ($[1] !== t0) {
210
+ t2 = react_2.default.createElement("div", { className: t0 }, t1);
211
+ $[1] = t0;
212
+ $[2] = t2;
213
+ }
214
+ else {
215
+ t2 = $[2];
216
+ }
217
+ return t2;
218
+ }
219
+ const t0 = `${CLASS_NAME} ${(_b = props.className) !== null && _b !== void 0 ? _b : ""}`;
220
+ let t1;
221
+ if ($[3] !== props.customPluginsToolbarButtons || $[4] !== props.editableProps || $[5] !== props.id || $[6] !== props.initialValue || $[7] !== props.onChange || $[8] !== props.plugins || $[9] !== props.toolbarLeftElement || $[10] !== props.toolbarRightElement || $[11] !== ref) {
222
+ t1 = react_2.default.createElement(Editor, { customPluginsToolbarButtons: props.customPluginsToolbarButtons, editableProps: props.editableProps, id: props.id, initialValue: props.initialValue, onChange: props.onChange, plugins: props.plugins, ref: ref, toolbarLeftElement: props.toolbarLeftElement, toolbarRightElement: props.toolbarRightElement });
223
+ $[3] = props.customPluginsToolbarButtons;
224
+ $[4] = props.editableProps;
225
+ $[5] = props.id;
226
+ $[6] = props.initialValue;
227
+ $[7] = props.onChange;
228
+ $[8] = props.plugins;
229
+ $[9] = props.toolbarLeftElement;
230
+ $[10] = props.toolbarRightElement;
231
+ $[11] = ref;
232
+ $[12] = t1;
233
+ }
234
+ else {
235
+ t1 = $[12];
236
+ }
237
+ let t2;
238
+ if ($[13] !== t0 || $[14] !== t1) {
239
+ t2 = react_2.default.createElement("div", { className: t0 }, t1);
240
+ $[13] = t0;
241
+ $[14] = t1;
242
+ $[15] = t2;
243
+ }
244
+ else {
245
+ t2 = $[15];
95
246
  }
96
- return (react_2.default.createElement("div", { className: `${CLASS_NAME} ${(_b = props.className) !== null && _b !== void 0 ? _b : ""}` },
97
- react_2.default.createElement(Editor, { customPluginsToolbarButtons: props.customPluginsToolbarButtons, editableProps: props.editableProps, id: props.id, initialValue: props.initialValue, onChange: props.onChange, plugins: props.plugins, ref: props.ref, toolbarLeftElement: props.toolbarLeftElement, toolbarRightElement: props.toolbarRightElement })));
247
+ return t2;
98
248
  };
99
249
  exports.WysiwygEditor = WysiwygEditor;