tinymce-solid 0.0.8 → 0.0.10
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/README.md +5 -6
- package/dist/dev.js +55 -48
- package/dist/dev.jsx +41 -36
- package/dist/index.d.ts +1 -1
- package/dist/index.js +45 -38
- package/dist/index.jsx +31 -26
- package/package.json +29 -31
- package/vitest.config-ui.ts +3 -1
- package/vitest.config.ts +3 -1
- package/eslint.config.mjs +0 -5
- package/src/Events.ts +0 -93
- package/src/ScriptLoader2.ts +0 -182
- package/src/TinyMCE.ts +0 -11
- package/src/Utils.ts +0 -138
- package/src/components/Editor.tsx +0 -427
- package/src/components/EditorPropTypes.ts +0 -191
- package/src/index.tsx +0 -6
- package/test/fixtures/Editor.tsx +0 -6
- package/test/index.test.tsx +0 -227
- package/tsconfig.json +0 -25
- package/tsup.config.ts +0 -40
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
import { createEffect, createSignal, on, onCleanup, onMount } from "solid-js";
|
|
2
|
-
import { Dynamic } from "solid-js/web";
|
|
3
|
-
import { type ScriptItem, ScriptLoader } from "../ScriptLoader2";
|
|
4
|
-
import { getTinymce } from "../TinyMCE";
|
|
5
|
-
import {
|
|
6
|
-
isFunction,
|
|
7
|
-
isTextareaOrInput,
|
|
8
|
-
mergePlugins,
|
|
9
|
-
uuid,
|
|
10
|
-
configHandlers,
|
|
11
|
-
isBeforeInputEventAvailable,
|
|
12
|
-
isInDoc,
|
|
13
|
-
setMode,
|
|
14
|
-
} from "../Utils";
|
|
15
|
-
import {
|
|
16
|
-
IAllProps,
|
|
17
|
-
Version,
|
|
18
|
-
EditorOptions,
|
|
19
|
-
InitOptions,
|
|
20
|
-
OmittedInitProps,
|
|
21
|
-
// IProps,
|
|
22
|
-
} from "./EditorPropTypes";
|
|
23
|
-
import { Bookmark, Editor as TinyMCEEditor, EditorEvent } from "tinymce";
|
|
24
|
-
|
|
25
|
-
export const Editor = (props: Partial<IAllProps>) => {
|
|
26
|
-
const [id] = createSignal(props.id || uuid("solid-tinymce-editor"));
|
|
27
|
-
const initialValue = () => props.initialValue;
|
|
28
|
-
const value = () => props.value || "";
|
|
29
|
-
const skin = () => props.skin || "oxide";
|
|
30
|
-
const tagName = () => props.tagName || "div";
|
|
31
|
-
const contentCss = () => props.contentCss || "default";
|
|
32
|
-
const disabled = () => props.disabled || false;
|
|
33
|
-
const [editor, setEditor] = createSignal<TinyMCEEditor>();
|
|
34
|
-
const [currentContent, setCurrentContent] = createSignal<string>(value());
|
|
35
|
-
const [rollbackTimer, setRollbackTimer] = createSignal<number>();
|
|
36
|
-
const [valueCursor, setValueCursor] = createSignal<Bookmark>();
|
|
37
|
-
const [boundHandlers, setBoundHandlers] = createSignal<
|
|
38
|
-
Record<string, (event: EditorEvent<unknown>) => unknown>
|
|
39
|
-
>({});
|
|
40
|
-
const view = () =>
|
|
41
|
-
props?.elementRef?.ownerDocument.defaultView ??
|
|
42
|
-
/* istanbul ignore next @preserve */ window;
|
|
43
|
-
|
|
44
|
-
const getInitialValue = () => {
|
|
45
|
-
/* istanbul ignore else @preserve */
|
|
46
|
-
if (typeof initialValue() === "string") {
|
|
47
|
-
return initialValue() as string;
|
|
48
|
-
} else if (typeof value() === "string") {
|
|
49
|
-
return value();
|
|
50
|
-
} else {
|
|
51
|
-
return "";
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const getScriptSources = (): ScriptItem[] => {
|
|
55
|
-
const async = props.scriptLoading?.async;
|
|
56
|
-
const defer = props.scriptLoading?.defer;
|
|
57
|
-
/* istanbul ignore next @preserve */
|
|
58
|
-
if (props.tinymceScriptSrc !== undefined) {
|
|
59
|
-
/* istanbul ignore next @preserve */
|
|
60
|
-
if (typeof props.tinymceScriptSrc === "string") {
|
|
61
|
-
return [{ src: props.tinymceScriptSrc, async, defer }];
|
|
62
|
-
}
|
|
63
|
-
// multiple scripts can be specified which allows for hybrid mode
|
|
64
|
-
/* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
|
|
65
|
-
return (props.tinymceScriptSrc as string[] | ScriptItem[]).map((item) => {
|
|
66
|
-
if (typeof item === "string") {
|
|
67
|
-
// async does not make sense for multiple items unless
|
|
68
|
-
// they are not dependent (which will be unlikely)
|
|
69
|
-
return { src: item, async, defer };
|
|
70
|
-
} else {
|
|
71
|
-
return item;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// fallback to the cloud when the tinymceScriptSrc is not specified
|
|
77
|
-
const channel = (props.cloudChannel || "7") as Version; // `cloudChannel` is in `defaultProps`, so it's always defined.
|
|
78
|
-
const apiKey = props.apiKey ? props.apiKey : "no-api-key";
|
|
79
|
-
const cloudTinyJs = `https://cdn.tiny.cloud/1/${apiKey}/tinymce/${channel}/tinymce.min.js`;
|
|
80
|
-
return [{ src: cloudTinyJs, async, defer }];
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const bindHandlers = (prevProps: Partial<IAllProps>) => {
|
|
84
|
-
/* istanbul ignore else @preserve */
|
|
85
|
-
if (editor() !== undefined) {
|
|
86
|
-
const tinyEditor = editor()!;
|
|
87
|
-
|
|
88
|
-
// typescript chokes trying to understand the type of the lookup function
|
|
89
|
-
configHandlers(
|
|
90
|
-
tinyEditor,
|
|
91
|
-
prevProps,
|
|
92
|
-
props,
|
|
93
|
-
boundHandlers(),
|
|
94
|
-
(key) => props[key],
|
|
95
|
-
);
|
|
96
|
-
// check if we should monitor editor changes
|
|
97
|
-
const isValueControlled = (p: Partial<IAllProps>) =>
|
|
98
|
-
p.onEditorChange !== undefined || p.value !== undefined;
|
|
99
|
-
const wasControlled = isValueControlled(prevProps);
|
|
100
|
-
const nowControlled = isValueControlled(props);
|
|
101
|
-
/* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
|
|
102
|
-
if (!wasControlled && nowControlled) {
|
|
103
|
-
tinyEditor.on(changeEvents(), handleEditorChange);
|
|
104
|
-
tinyEditor.on(beforeInputEvent(), handleBeforeInput);
|
|
105
|
-
tinyEditor.on("keydown", handleBeforeInputSpecial);
|
|
106
|
-
tinyEditor.on("keyup", handleEditorChangeSpecial);
|
|
107
|
-
tinyEditor.on("NewBlock", handleEditorChange);
|
|
108
|
-
} else if (wasControlled && !nowControlled) {
|
|
109
|
-
tinyEditor.off(changeEvents(), handleEditorChange);
|
|
110
|
-
tinyEditor.off(beforeInputEvent(), handleBeforeInput);
|
|
111
|
-
tinyEditor.off("keydown", handleBeforeInputSpecial);
|
|
112
|
-
tinyEditor.off("keyup", handleEditorChangeSpecial);
|
|
113
|
-
tinyEditor.off("NewBlock", handleEditorChange);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
const successHandler = () => {
|
|
118
|
-
props.onScriptsLoad?.();
|
|
119
|
-
initialise();
|
|
120
|
-
};
|
|
121
|
-
/* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
|
|
122
|
-
const errorHandler = (err: unknown) => {
|
|
123
|
-
// console.warn(err);
|
|
124
|
-
props.onScriptsLoadError?.(err);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const initialise = (attempts = 0) => {
|
|
128
|
-
const target = props.elementRef;
|
|
129
|
-
/* istanbul ignore next @preserve */
|
|
130
|
-
if (!target) {
|
|
131
|
-
return; // Editor has been unmounted
|
|
132
|
-
}
|
|
133
|
-
/* istanbul ignore else @preserve */
|
|
134
|
-
if (!isInDoc(target)) {
|
|
135
|
-
// this is probably someone trying to help by rendering us offscreen
|
|
136
|
-
// but we can't do that because the editor iframe must be in the document
|
|
137
|
-
// in order to have state
|
|
138
|
-
if (attempts === 0) {
|
|
139
|
-
// we probably just need to wait for the current events to be processed
|
|
140
|
-
setTimeout(() => initialise(1), 1);
|
|
141
|
-
} else if (attempts < 100) {
|
|
142
|
-
// wait for ten seconds, polling every tenth of a second
|
|
143
|
-
setTimeout(() => initialise(attempts + 1), 100);
|
|
144
|
-
} else {
|
|
145
|
-
// give up, at this point it seems that more polling is unlikely to help
|
|
146
|
-
/* istanbul ignore next @preserve - this error is thrown on every HMR so we ignore it */
|
|
147
|
-
throw new Error("tinymce can only be initialised when in a document");
|
|
148
|
-
}
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const tinymce = getTinymce(view());
|
|
153
|
-
/* istanbul ignore next @preserve - this error is thrown on every HMR so we can ignore it */
|
|
154
|
-
if (!tinymce) {
|
|
155
|
-
throw new Error("tinymce should have been loaded into global scope");
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const finalInit: EditorOptions = {
|
|
159
|
-
...(props.init as Omit<InitOptions, OmittedInitProps>),
|
|
160
|
-
selector: undefined,
|
|
161
|
-
target,
|
|
162
|
-
skin: skin(),
|
|
163
|
-
content_css: contentCss(),
|
|
164
|
-
readonly: props.disabled,
|
|
165
|
-
inline: props.inline,
|
|
166
|
-
plugins: mergePlugins(props.init?.plugins, props.plugins),
|
|
167
|
-
toolbar: props.toolbar ?? props.init?.toolbar,
|
|
168
|
-
...(props.licenseKey ? { license_key: props.licenseKey } : {}),
|
|
169
|
-
setup: (editor) => {
|
|
170
|
-
setEditor(editor);
|
|
171
|
-
bindHandlers({});
|
|
172
|
-
|
|
173
|
-
// When running in inline mode the editor gets the initial value
|
|
174
|
-
// from the innerHTML of the element it is initialized on.
|
|
175
|
-
// However we don't want to take on the responsibility of sanitizing
|
|
176
|
-
// to remove XSS in the react integration so we have a chicken and egg
|
|
177
|
-
// problem... We avoid it by sneaking in a set content before the first
|
|
178
|
-
// "official" setContent and using TinyMCE to do the sanitization.
|
|
179
|
-
if (props.inline && !isTextareaOrInput(target)) {
|
|
180
|
-
editor.once("PostRender", (_evt) => {
|
|
181
|
-
editor.setContent(getInitialValue(), {
|
|
182
|
-
no_events: true,
|
|
183
|
-
event_name: _evt.type,
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/* istanbul ignore next @preserve */
|
|
189
|
-
if (props.init && isFunction(props.init.setup)) {
|
|
190
|
-
props.init.setup(editor);
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
init_instance_callback: (editor) => {
|
|
194
|
-
// check for changes that happened since tinymce.init() was called
|
|
195
|
-
const initialValue = getInitialValue();
|
|
196
|
-
let newCurrentValue = currentContent() ?? editor.getContent();
|
|
197
|
-
/* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
|
|
198
|
-
if (newCurrentValue !== initialValue) {
|
|
199
|
-
newCurrentValue = initialValue;
|
|
200
|
-
// same as resetContent in TinyMCE 5
|
|
201
|
-
editor.setContent(initialValue);
|
|
202
|
-
editor.undoManager.clear();
|
|
203
|
-
editor.undoManager.add();
|
|
204
|
-
editor.setDirty(false);
|
|
205
|
-
}
|
|
206
|
-
setCurrentContent(newCurrentValue);
|
|
207
|
-
const isDisabled = disabled() ?? false;
|
|
208
|
-
setMode(editor, isDisabled ? "readonly" : "design");
|
|
209
|
-
// ensure existing init_instance_callback is called
|
|
210
|
-
/* istanbul ignore next @preserve */
|
|
211
|
-
if (props.init && isFunction(props.init.init_instance_callback)) {
|
|
212
|
-
props.init.init_instance_callback(editor);
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
};
|
|
216
|
-
if (!props.inline) {
|
|
217
|
-
target.style.visibility = "";
|
|
218
|
-
}
|
|
219
|
-
if (isTextareaOrInput(target)) {
|
|
220
|
-
target.value = getInitialValue();
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
tinymce.init(finalInit);
|
|
224
|
-
};
|
|
225
|
-
const mountCallback = () => {
|
|
226
|
-
/* istanbul ignore else @preserve */
|
|
227
|
-
if (getTinymce(view()) !== null) {
|
|
228
|
-
initialise();
|
|
229
|
-
} else if (
|
|
230
|
-
Array.isArray(props.tinymceScriptSrc) &&
|
|
231
|
-
props.tinymceScriptSrc.length === 0
|
|
232
|
-
) {
|
|
233
|
-
props.onScriptsLoadError?.(
|
|
234
|
-
new Error(
|
|
235
|
-
"No `tinymce` global is present but the `tinymceScriptSrc` prop was an empty array.",
|
|
236
|
-
),
|
|
237
|
-
);
|
|
238
|
-
} else if (props?.elementRef?.ownerDocument) {
|
|
239
|
-
ScriptLoader.loadList(
|
|
240
|
-
props.elementRef.ownerDocument,
|
|
241
|
-
getScriptSources(),
|
|
242
|
-
props.scriptLoading?.delay ?? 0,
|
|
243
|
-
successHandler,
|
|
244
|
-
errorHandler,
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
const cleanUpCallback = () => {
|
|
249
|
-
const tinyEditor = editor()!;
|
|
250
|
-
/* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
|
|
251
|
-
if (typeof tinyEditor !== "undefined") {
|
|
252
|
-
tinyEditor.off(changeEvents(), handleEditorChange);
|
|
253
|
-
tinyEditor.off(beforeInputEvent(), handleBeforeInput);
|
|
254
|
-
tinyEditor.off("keypress", handleEditorChangeSpecial);
|
|
255
|
-
tinyEditor.off("keydown", handleBeforeInputSpecial);
|
|
256
|
-
tinyEditor.off("NewBlock", handleEditorChange);
|
|
257
|
-
Object.keys(boundHandlers()).forEach((eventName) => {
|
|
258
|
-
tinyEditor.off(eventName, boundHandlers()[eventName]);
|
|
259
|
-
});
|
|
260
|
-
setBoundHandlers({});
|
|
261
|
-
tinyEditor.destroy();
|
|
262
|
-
tinyEditor.remove();
|
|
263
|
-
setEditor();
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
createEffect(
|
|
268
|
-
on(value, () => {
|
|
269
|
-
/* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
|
|
270
|
-
if (value() !== currentContent()) {
|
|
271
|
-
setCurrentContent(value());
|
|
272
|
-
editor()?.setContent(value(), { no_events: true, event_name: "input" });
|
|
273
|
-
}
|
|
274
|
-
}),
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
createEffect(
|
|
278
|
-
on(skin, () => {
|
|
279
|
-
cleanUpCallback();
|
|
280
|
-
setTimeout(mountCallback, 1);
|
|
281
|
-
}),
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
createEffect(
|
|
285
|
-
on(disabled, () => {
|
|
286
|
-
const tinyEditor = editor();
|
|
287
|
-
if (tinyEditor?.initialized) {
|
|
288
|
-
const isDisabled = disabled() ?? false;
|
|
289
|
-
setMode(tinyEditor, isDisabled ? "readonly" : "design");
|
|
290
|
-
}
|
|
291
|
-
}),
|
|
292
|
-
);
|
|
293
|
-
|
|
294
|
-
onMount(mountCallback);
|
|
295
|
-
onCleanup(cleanUpCallback);
|
|
296
|
-
|
|
297
|
-
const changeEvents = () => {
|
|
298
|
-
const isIE = getTinymce(view())?.Env?.browser?.isIE();
|
|
299
|
-
return isIE
|
|
300
|
-
? "change keyup compositionend setcontent CommentChange"
|
|
301
|
-
: "change input compositionend setcontent CommentChange";
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
const beforeInputEvent = () => {
|
|
305
|
-
return isBeforeInputEventAvailable()
|
|
306
|
-
? "beforeinput SelectionChange"
|
|
307
|
-
: "SelectionChange";
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
const handleEditorChange = (event: EditorEvent<unknown>) => {
|
|
311
|
-
const tinyEditor = editor();
|
|
312
|
-
/* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
|
|
313
|
-
if (tinyEditor && tinyEditor.initialized && !event.isDefaultPrevented()) {
|
|
314
|
-
const newContent = tinyEditor.getContent();
|
|
315
|
-
/* istanbul ignore next @preserve */
|
|
316
|
-
if (
|
|
317
|
-
props.value !== undefined &&
|
|
318
|
-
props.value !== newContent &&
|
|
319
|
-
props.rollback !== false
|
|
320
|
-
) {
|
|
321
|
-
// start a timer and revert to the value if not applied in time
|
|
322
|
-
/* istanbul ignore next @preserve */
|
|
323
|
-
if (!rollbackTimer()) {
|
|
324
|
-
setRollbackTimer(
|
|
325
|
-
window.setTimeout(
|
|
326
|
-
rollbackChange,
|
|
327
|
-
typeof props.rollback === "number" ? props.rollback : 200,
|
|
328
|
-
),
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/* istanbul ignore next @preserve */
|
|
334
|
-
if (newContent !== currentContent()) {
|
|
335
|
-
setCurrentContent(newContent);
|
|
336
|
-
/* istanbul ignore next @preserve */
|
|
337
|
-
if (isFunction(props.onEditorChange)) {
|
|
338
|
-
props.onEditorChange(newContent, tinyEditor);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
const rollbackChange = () => {
|
|
345
|
-
/* istanbul ignore next @preserve */
|
|
346
|
-
const tinyEditor = editor();
|
|
347
|
-
const value = props.value;
|
|
348
|
-
/* istanbul ignore next @preserve */
|
|
349
|
-
if (tinyEditor && value && value !== currentContent()) {
|
|
350
|
-
tinyEditor.undoManager.ignore(() => {
|
|
351
|
-
tinyEditor.setContent(value);
|
|
352
|
-
// only restore cursor on inline editors when they are focused
|
|
353
|
-
// as otherwise it will cause a focus grab
|
|
354
|
-
/* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
|
|
355
|
-
if (valueCursor() && (!props.inline || tinyEditor.hasFocus())) {
|
|
356
|
-
try {
|
|
357
|
-
tinyEditor.selection.moveToBookmark(valueCursor()!);
|
|
358
|
-
} catch (e) {
|
|
359
|
-
/* ignore */
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
/* istanbul ignore next @preserve */
|
|
365
|
-
setRollbackTimer(undefined);
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
const handleBeforeInput = (event: EditorEvent<unknown>) => {
|
|
369
|
-
/* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
|
|
370
|
-
const tinyEditor = editor()!;
|
|
371
|
-
/* istanbul ignore next @preserve - exact same reason */
|
|
372
|
-
if (
|
|
373
|
-
props.value !== undefined &&
|
|
374
|
-
props.value === currentContent() &&
|
|
375
|
-
tinyEditor &&
|
|
376
|
-
!event.isDefaultPrevented()
|
|
377
|
-
) {
|
|
378
|
-
if (!props.inline || tinyEditor.hasFocus()) {
|
|
379
|
-
try {
|
|
380
|
-
// getBookmark throws exceptions when the editor has not been focused
|
|
381
|
-
// possibly only in inline mode but I'm not taking chances
|
|
382
|
-
// this.valueCursor = tinyEditor.selection.getBookmark(3);
|
|
383
|
-
setValueCursor(tinyEditor.selection.getBookmark(3));
|
|
384
|
-
} catch (e) {
|
|
385
|
-
/* ignore */
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
const handleEditorChangeSpecial = (evt: EditorEvent<KeyboardEvent>) => {
|
|
392
|
-
/* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
|
|
393
|
-
if (
|
|
394
|
-
evt.key === "Enter" ||
|
|
395
|
-
evt.key === "Backspace" ||
|
|
396
|
-
evt.key === "Delete"
|
|
397
|
-
) {
|
|
398
|
-
handleBeforeInput(evt);
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
const handleBeforeInputSpecial = (evt: EditorEvent<KeyboardEvent>) => {
|
|
403
|
-
/* istanbul ignore next @preserve - this should be covered but the browser mode won't register this part */
|
|
404
|
-
if (
|
|
405
|
-
evt.key === "Enter" ||
|
|
406
|
-
evt.key === "Backspace" ||
|
|
407
|
-
evt.key === "Delete"
|
|
408
|
-
) {
|
|
409
|
-
handleBeforeInput(evt);
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
return (
|
|
414
|
-
<Dynamic
|
|
415
|
-
{...props}
|
|
416
|
-
component={props.inline ? tagName() : "textarea"}
|
|
417
|
-
id={id()}
|
|
418
|
-
data-testid={props.testid}
|
|
419
|
-
tabIndex={props.tabIndex}
|
|
420
|
-
ref={props.elementRef}
|
|
421
|
-
// value={value()}
|
|
422
|
-
data-disabled={disabled()}
|
|
423
|
-
data-skin={skin()}
|
|
424
|
-
data-css={contentCss()}
|
|
425
|
-
/>
|
|
426
|
-
);
|
|
427
|
-
};
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import * as PropTypes from "prop-types";
|
|
2
|
-
import { IEvents } from "../Events";
|
|
3
|
-
import { Editor as TinyMCEEditor, TinyMCE } from "tinymce";
|
|
4
|
-
import { ScriptItem } from "../ScriptLoader2";
|
|
5
|
-
|
|
6
|
-
export type OmitStringIndexSignature<T> = {
|
|
7
|
-
[K in keyof T as string extends K ? never : K]: T[K];
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
interface DoNotUse<T extends string> {
|
|
11
|
-
__brand: T;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type OmittedInitProps =
|
|
15
|
-
| "selector"
|
|
16
|
-
| "target"
|
|
17
|
-
| "readonly"
|
|
18
|
-
| "license_key";
|
|
19
|
-
|
|
20
|
-
export type EditorOptions = Parameters<TinyMCE["init"]>[0];
|
|
21
|
-
|
|
22
|
-
export type InitOptions = Omit<
|
|
23
|
-
OmitStringIndexSignature<EditorOptions>,
|
|
24
|
-
OmittedInitProps
|
|
25
|
-
> & {
|
|
26
|
-
selector?: DoNotUse<"selector prop is handled internally by the component">;
|
|
27
|
-
target?: DoNotUse<"target prop is handled internally by the component">;
|
|
28
|
-
readonly?: DoNotUse<"readonly prop is overridden by the component, use the `disabled` prop instead">;
|
|
29
|
-
license_key?: DoNotUse<"license_key prop is overridden by the integration, use the `licenseKey` prop instead">;
|
|
30
|
-
} & { [key: string]: unknown };
|
|
31
|
-
|
|
32
|
-
export type Version =
|
|
33
|
-
`${"4" | "5" | "6" | "7"}${"" | "-dev" | "-testing" | `.${number}` | `.${number}.${number}`}`;
|
|
34
|
-
|
|
35
|
-
export interface IProps {
|
|
36
|
-
propTypes: IEditorPropTypes;
|
|
37
|
-
elementRef: HTMLDivElement | HTMLTextAreaElement;
|
|
38
|
-
apiKey: string;
|
|
39
|
-
id: string;
|
|
40
|
-
testid: string; // testing-library attribute
|
|
41
|
-
inline: boolean;
|
|
42
|
-
initialValue: string;
|
|
43
|
-
onEditorChange: (content: string, editor: TinyMCEEditor) => void;
|
|
44
|
-
value: string;
|
|
45
|
-
init: InitOptions;
|
|
46
|
-
tagName: string;
|
|
47
|
-
tabIndex: number;
|
|
48
|
-
cloudChannel: Version;
|
|
49
|
-
plugins: NonNullable<EditorOptions["plugins"]>;
|
|
50
|
-
toolbar: NonNullable<EditorOptions["toolbar"]>;
|
|
51
|
-
disabled: boolean;
|
|
52
|
-
textareaName: string;
|
|
53
|
-
tinymceScriptSrc: string | string[] | ScriptItem[];
|
|
54
|
-
rollback: number | false;
|
|
55
|
-
skin: "oxide" | "oxide-dark" | "tinymce-5" | "tinymce-5-dark";
|
|
56
|
-
contentCss:
|
|
57
|
-
| "default"
|
|
58
|
-
| "dark"
|
|
59
|
-
| "document"
|
|
60
|
-
| "tinymce-5"
|
|
61
|
-
| "tinymce-5-dark"
|
|
62
|
-
| "writer";
|
|
63
|
-
scriptLoading: {
|
|
64
|
-
async?: boolean;
|
|
65
|
-
defer?: boolean;
|
|
66
|
-
delay?: number;
|
|
67
|
-
};
|
|
68
|
-
licenseKey: string;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface IAllProps extends Partial<IProps>, Partial<IEvents> {}
|
|
72
|
-
|
|
73
|
-
export type CopyProps<T> = { [P in keyof T]: PropTypes.Requireable<unknown> };
|
|
74
|
-
|
|
75
|
-
export type IEventPropTypes = CopyProps<IEvents>;
|
|
76
|
-
|
|
77
|
-
export interface IEditorPropTypes extends IEventPropTypes, CopyProps<IProps> {}
|
|
78
|
-
|
|
79
|
-
export const eventPropTypes: IEventPropTypes = {
|
|
80
|
-
onActivate: PropTypes.func,
|
|
81
|
-
onAddUndo: PropTypes.func,
|
|
82
|
-
onBeforeAddUndo: PropTypes.func,
|
|
83
|
-
onBeforeExecCommand: PropTypes.func,
|
|
84
|
-
onBeforeGetContent: PropTypes.func,
|
|
85
|
-
onBeforeRenderUI: PropTypes.func,
|
|
86
|
-
onBeforeSetContent: PropTypes.func,
|
|
87
|
-
onBeforePaste: PropTypes.func,
|
|
88
|
-
onBlur: PropTypes.func,
|
|
89
|
-
onChange: PropTypes.func,
|
|
90
|
-
onClearUndos: PropTypes.func,
|
|
91
|
-
onClick: PropTypes.func,
|
|
92
|
-
onContextMenu: PropTypes.func,
|
|
93
|
-
onCommentChange: PropTypes.func,
|
|
94
|
-
onCompositionEnd: PropTypes.func,
|
|
95
|
-
onCompositionStart: PropTypes.func,
|
|
96
|
-
onCompositionUpdate: PropTypes.func,
|
|
97
|
-
onCopy: PropTypes.func,
|
|
98
|
-
onCut: PropTypes.func,
|
|
99
|
-
onDblclick: PropTypes.func,
|
|
100
|
-
onDeactivate: PropTypes.func,
|
|
101
|
-
onDirty: PropTypes.func,
|
|
102
|
-
onDrag: PropTypes.func,
|
|
103
|
-
onDragDrop: PropTypes.func,
|
|
104
|
-
onDragEnd: PropTypes.func,
|
|
105
|
-
onDragGesture: PropTypes.func,
|
|
106
|
-
onDragOver: PropTypes.func,
|
|
107
|
-
onDrop: PropTypes.func,
|
|
108
|
-
onExecCommand: PropTypes.func,
|
|
109
|
-
onFocus: PropTypes.func,
|
|
110
|
-
onFocusIn: PropTypes.func,
|
|
111
|
-
onFocusOut: PropTypes.func,
|
|
112
|
-
onGetContent: PropTypes.func,
|
|
113
|
-
onHide: PropTypes.func,
|
|
114
|
-
onInit: PropTypes.func,
|
|
115
|
-
onInput: PropTypes.func,
|
|
116
|
-
onKeyDown: PropTypes.func,
|
|
117
|
-
onKeyPress: PropTypes.func,
|
|
118
|
-
onKeyUp: PropTypes.func,
|
|
119
|
-
onLoadContent: PropTypes.func,
|
|
120
|
-
onMouseDown: PropTypes.func,
|
|
121
|
-
onMouseEnter: PropTypes.func,
|
|
122
|
-
onMouseLeave: PropTypes.func,
|
|
123
|
-
onMouseMove: PropTypes.func,
|
|
124
|
-
onMouseOut: PropTypes.func,
|
|
125
|
-
onMouseOver: PropTypes.func,
|
|
126
|
-
onMouseUp: PropTypes.func,
|
|
127
|
-
onNodeChange: PropTypes.func,
|
|
128
|
-
onObjectResizeStart: PropTypes.func,
|
|
129
|
-
onObjectResized: PropTypes.func,
|
|
130
|
-
onObjectSelected: PropTypes.func,
|
|
131
|
-
onPaste: PropTypes.func,
|
|
132
|
-
onPostProcess: PropTypes.func,
|
|
133
|
-
onPostRender: PropTypes.func,
|
|
134
|
-
onPreProcess: PropTypes.func,
|
|
135
|
-
onProgressState: PropTypes.func,
|
|
136
|
-
onRedo: PropTypes.func,
|
|
137
|
-
onRemove: PropTypes.func,
|
|
138
|
-
onReset: PropTypes.func,
|
|
139
|
-
onSaveContent: PropTypes.func,
|
|
140
|
-
onSelectionChange: PropTypes.func,
|
|
141
|
-
onSetAttrib: PropTypes.func,
|
|
142
|
-
onSetContent: PropTypes.func,
|
|
143
|
-
onShow: PropTypes.func,
|
|
144
|
-
onSubmit: PropTypes.func,
|
|
145
|
-
onUndo: PropTypes.func,
|
|
146
|
-
onVisualAid: PropTypes.func,
|
|
147
|
-
onSkinLoadError: PropTypes.func,
|
|
148
|
-
onThemeLoadError: PropTypes.func,
|
|
149
|
-
onModelLoadError: PropTypes.func,
|
|
150
|
-
onPluginLoadError: PropTypes.func,
|
|
151
|
-
onIconsLoadError: PropTypes.func,
|
|
152
|
-
onLanguageLoadError: PropTypes.func,
|
|
153
|
-
onScriptsLoad: PropTypes.func,
|
|
154
|
-
onScriptsLoadError: PropTypes.func,
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export const EditorPropTypes = {
|
|
158
|
-
apiKey: PropTypes.string,
|
|
159
|
-
licenseKey: PropTypes.string,
|
|
160
|
-
id: PropTypes.string,
|
|
161
|
-
inline: PropTypes.bool,
|
|
162
|
-
init: PropTypes.object,
|
|
163
|
-
initialValue: PropTypes.string,
|
|
164
|
-
onEditorChange: PropTypes.func,
|
|
165
|
-
value: PropTypes.string,
|
|
166
|
-
tagName: PropTypes.string,
|
|
167
|
-
tabIndex: PropTypes.number,
|
|
168
|
-
cloudChannel: PropTypes.string,
|
|
169
|
-
plugins: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
|
|
170
|
-
toolbar: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
|
|
171
|
-
disabled: PropTypes.bool,
|
|
172
|
-
textareaName: PropTypes.string,
|
|
173
|
-
tinymceScriptSrc: PropTypes.oneOfType([
|
|
174
|
-
PropTypes.string,
|
|
175
|
-
PropTypes.arrayOf(PropTypes.string),
|
|
176
|
-
PropTypes.arrayOf(
|
|
177
|
-
PropTypes.shape({
|
|
178
|
-
src: PropTypes.string,
|
|
179
|
-
async: PropTypes.bool,
|
|
180
|
-
defer: PropTypes.bool,
|
|
181
|
-
}),
|
|
182
|
-
),
|
|
183
|
-
]),
|
|
184
|
-
rollback: PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf([false])]),
|
|
185
|
-
scriptLoading: PropTypes.shape({
|
|
186
|
-
async: PropTypes.bool,
|
|
187
|
-
defer: PropTypes.bool,
|
|
188
|
-
delay: PropTypes.number,
|
|
189
|
-
}),
|
|
190
|
-
...eventPropTypes,
|
|
191
|
-
};
|
package/src/index.tsx
DELETED
package/test/fixtures/Editor.tsx
DELETED