tinymce-solid 0.0.7 → 0.0.9
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 +8 -6
- package/dist/dev.js +45 -24
- package/dist/dev.jsx +40 -27
- package/dist/index.js +35 -14
- package/dist/index.jsx +30 -17
- package/package.json +32 -23
- package/eslint.config.mjs +0 -5
- package/src/Events.ts +0 -93
- package/src/ScriptLoader2.ts +0 -176
- package/src/TinyMCE.ts +0 -8
- package/src/Utils.ts +0 -133
- package/src/components/Editor.tsx +0 -391
- package/src/components/EditorPropTypes.ts +0 -191
- package/src/index.tsx +0 -6
- package/tsconfig.json +0 -25
- package/tsup.config.ts +0 -40
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinymce-solid",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "📝 TinyMCE Component for SolidJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,30 +20,35 @@
|
|
|
20
20
|
"registry": "https://registry.npmjs.org/"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"solid-js": "^1.
|
|
24
|
-
"tinymce": "^7.
|
|
23
|
+
"solid-js": "^1.9.3",
|
|
24
|
+
"tinymce": "^7.5.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@kobalte/core": "^0.13.
|
|
28
|
-
"@kobalte/utils": "^0.9.
|
|
29
|
-
"@
|
|
30
|
-
"@types/
|
|
27
|
+
"@kobalte/core": "^0.13.7",
|
|
28
|
+
"@kobalte/utils": "^0.9.1",
|
|
29
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
30
|
+
"@types/node": "^20.17.7",
|
|
31
|
+
"@types/prop-types": "^15.7.13",
|
|
32
|
+
"@vitest/browser": "^2.1.5",
|
|
33
|
+
"@vitest/coverage-istanbul": "^2.1.5",
|
|
34
|
+
"@vitest/ui": "^2.1.5",
|
|
31
35
|
"autoprefixer": "^10.4.20",
|
|
32
36
|
"class-variance-authority": "^0.7.0",
|
|
33
37
|
"clsx": "^2.1.1",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
38
|
+
"jsdom": "^25.0.1",
|
|
39
|
+
"playwright": "^1.49.0",
|
|
40
|
+
"postcss": "^8.4.49",
|
|
36
41
|
"prop-types": "^15.8.1",
|
|
37
|
-
"tailwind-merge": "^2.5.
|
|
38
|
-
"tailwindcss": "^3.4.
|
|
42
|
+
"tailwind-merge": "^2.5.4",
|
|
43
|
+
"tailwindcss": "^3.4.15",
|
|
39
44
|
"tailwindcss-animate": "^1.0.7",
|
|
40
|
-
"tsup": "^8.
|
|
45
|
+
"tsup": "^8.3.5",
|
|
41
46
|
"tsup-preset-solid": "^2.2.0",
|
|
42
|
-
"typescript": "^5.
|
|
43
|
-
"
|
|
44
|
-
"vite": "^
|
|
45
|
-
"vite-plugin-
|
|
46
|
-
"
|
|
47
|
+
"typescript": "^5.7.2",
|
|
48
|
+
"vite": "^5.4.11",
|
|
49
|
+
"vite-plugin-compression2": "^1.3.1",
|
|
50
|
+
"vite-plugin-solid": "^2.10.2",
|
|
51
|
+
"vitest": "^2.1.5"
|
|
47
52
|
},
|
|
48
53
|
"engines": {
|
|
49
54
|
"node": ">=18"
|
|
@@ -70,18 +75,22 @@
|
|
|
70
75
|
},
|
|
71
76
|
"typesVersions": {},
|
|
72
77
|
"scripts": {
|
|
73
|
-
"
|
|
78
|
+
"pre-test": "pnpm clean-coverage",
|
|
79
|
+
"test": "pnpm pre-test && vitest --config vitest.config.mts",
|
|
80
|
+
"test-ui": "pnpm pre-test && vitest --config vitest.config-ui.mts",
|
|
81
|
+
"clean-coverage": "rm -rf coverage .nyc_output",
|
|
82
|
+
"format": "deno fmt src",
|
|
74
83
|
"build": "tsup",
|
|
75
84
|
"build:all": "pnpm build && pnpm build:docs",
|
|
76
85
|
"dev": "vite serve demo",
|
|
77
|
-
"build:docs": "vite build demo --config demo/vite.config.docs.
|
|
78
|
-
"copy:tiny": "cp -a './node_modules/.pnpm/tinymce@7.
|
|
86
|
+
"build:docs": "vite build demo --config demo/vite.config.docs.mts",
|
|
87
|
+
"copy:tiny": "cp -a './node_modules/.pnpm/tinymce@7.5.1/node_modules/tinymce' './demo/public'",
|
|
79
88
|
"serve:docs": "vite serve docs --port 3000",
|
|
80
|
-
"badges": "npx -p dependency-version-badge update-badge solid-js tinymce typescript
|
|
89
|
+
"badges": "npx -p dependency-version-badge update-badge solid-js tinymce typescript vitest vite",
|
|
81
90
|
"lint": "pnpm lint:types && pnpm lint:code",
|
|
82
|
-
"lint:code": "
|
|
91
|
+
"lint:code": "deno lint src",
|
|
83
92
|
"lint:types": "tsc --noEmit src/**/* --jsx preserve",
|
|
84
|
-
"fix:ts": "
|
|
93
|
+
"fix:ts": "deno lint src --fix",
|
|
85
94
|
"start": "pnpm serve:docs",
|
|
86
95
|
"serve": "vite preview docs --port 3000",
|
|
87
96
|
"version": "vite version"
|
package/eslint.config.mjs
DELETED
package/src/Events.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { Editor as TinyMCEEditor, EditorEvent, Events } from "tinymce";
|
|
2
|
-
|
|
3
|
-
export type EventHandler<A> = (
|
|
4
|
-
a: EditorEvent<A>,
|
|
5
|
-
editor: TinyMCEEditor,
|
|
6
|
-
) => unknown;
|
|
7
|
-
|
|
8
|
-
type EEventHandler<K extends keyof Events.EditorEventMap> = EventHandler<
|
|
9
|
-
Events.EditorEventMap[K]
|
|
10
|
-
>;
|
|
11
|
-
|
|
12
|
-
export interface INativeEvents {
|
|
13
|
-
onBeforePaste: EEventHandler<"beforepaste">;
|
|
14
|
-
onBlur: EEventHandler<"blur">;
|
|
15
|
-
onClick: EEventHandler<"click">;
|
|
16
|
-
onCompositionEnd: EEventHandler<"compositionend">;
|
|
17
|
-
onCompositionStart: EEventHandler<"compositionstart">;
|
|
18
|
-
onCompositionUpdate: EEventHandler<"compositionupdate">;
|
|
19
|
-
onContextMenu: EEventHandler<"contextmenu">;
|
|
20
|
-
onCopy: EEventHandler<"copy">;
|
|
21
|
-
onCut: EEventHandler<"cut">;
|
|
22
|
-
onDblclick: EEventHandler<"dblclick">;
|
|
23
|
-
onDrag: EEventHandler<"drag">;
|
|
24
|
-
onDragDrop: EEventHandler<"dragdrop">;
|
|
25
|
-
onDragEnd: EEventHandler<"dragend">;
|
|
26
|
-
onDragGesture: EEventHandler<"draggesture">;
|
|
27
|
-
onDragOver: EEventHandler<"dragover">;
|
|
28
|
-
onDrop: EEventHandler<"drop">;
|
|
29
|
-
onFocus: EEventHandler<"focus">;
|
|
30
|
-
onFocusIn: EEventHandler<"focusin">;
|
|
31
|
-
onFocusOut: EEventHandler<"focusout">;
|
|
32
|
-
onInput: EEventHandler<"input">;
|
|
33
|
-
onKeyDown: EEventHandler<"keydown">;
|
|
34
|
-
onKeyPress: EEventHandler<"keypress">;
|
|
35
|
-
onKeyUp: EEventHandler<"keyup">;
|
|
36
|
-
onMouseDown: EEventHandler<"mousedown">;
|
|
37
|
-
onMouseEnter: EEventHandler<"mouseenter">;
|
|
38
|
-
onMouseLeave: EEventHandler<"mouseleave">;
|
|
39
|
-
onMouseMove: EEventHandler<"mousemove">;
|
|
40
|
-
onMouseOut: EEventHandler<"mouseout">;
|
|
41
|
-
onMouseOver: EEventHandler<"mouseover">;
|
|
42
|
-
onMouseUp: EEventHandler<"mouseup">;
|
|
43
|
-
onPaste: EEventHandler<"paste">;
|
|
44
|
-
onSelectionChange: EEventHandler<"selectionchange">;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface ITinyEvents {
|
|
48
|
-
onActivate: EEventHandler<"activate">;
|
|
49
|
-
onAddUndo: EEventHandler<"AddUndo">;
|
|
50
|
-
onBeforeAddUndo: EEventHandler<"BeforeAddUndo">;
|
|
51
|
-
onBeforeExecCommand: EEventHandler<"BeforeExecCommand">;
|
|
52
|
-
onBeforeGetContent: EEventHandler<"BeforeGetContent">;
|
|
53
|
-
onBeforeRenderUI: EventHandler<unknown>;
|
|
54
|
-
onBeforeSetContent: EEventHandler<"BeforeSetContent">;
|
|
55
|
-
onChange: EventHandler<unknown>;
|
|
56
|
-
onClearUndos: EEventHandler<"ClearUndos">;
|
|
57
|
-
onCommentChange: EventHandler<unknown>;
|
|
58
|
-
onDeactivate: EEventHandler<"deactivate">;
|
|
59
|
-
onDirty: EventHandler<unknown>;
|
|
60
|
-
onExecCommand: EEventHandler<"ExecCommand">;
|
|
61
|
-
onGetContent: EEventHandler<"GetContent">;
|
|
62
|
-
onHide: EventHandler<unknown>;
|
|
63
|
-
onInit: EEventHandler<"init">;
|
|
64
|
-
onLoadContent: EEventHandler<"LoadContent">;
|
|
65
|
-
onNodeChange: EEventHandler<"NodeChange">;
|
|
66
|
-
onPostProcess: EventHandler<unknown>;
|
|
67
|
-
onPostRender: EEventHandler<"PostRender">;
|
|
68
|
-
onPreProcess: EventHandler<unknown>;
|
|
69
|
-
onProgressState: EEventHandler<"ProgressState">;
|
|
70
|
-
onRedo: EEventHandler<"Redo">;
|
|
71
|
-
onRemove: EEventHandler<"remove">;
|
|
72
|
-
onReset: EventHandler<unknown>;
|
|
73
|
-
onSaveContent: EventHandler<unknown>;
|
|
74
|
-
onSetAttrib: EventHandler<unknown>;
|
|
75
|
-
onObjectResizeStart: EEventHandler<"ObjectResizeStart">;
|
|
76
|
-
onObjectResized: EEventHandler<"ObjectResized">;
|
|
77
|
-
onObjectSelected: EEventHandler<"ObjectSelected">;
|
|
78
|
-
onSetContent: EEventHandler<"SetContent">;
|
|
79
|
-
onShow: EventHandler<unknown>;
|
|
80
|
-
onSubmit: EventHandler<unknown>;
|
|
81
|
-
onUndo: EEventHandler<"Undo">;
|
|
82
|
-
onVisualAid: EventHandler<unknown>;
|
|
83
|
-
onSkinLoadError: EEventHandler<"SkinLoadError">;
|
|
84
|
-
onThemeLoadError: EEventHandler<"ThemeLoadError">;
|
|
85
|
-
onModelLoadError: EEventHandler<"ModelLoadError">;
|
|
86
|
-
onPluginLoadError: EEventHandler<"PluginLoadError">;
|
|
87
|
-
onIconsLoadError: EEventHandler<"IconsLoadError">;
|
|
88
|
-
onLanguageLoadError: EEventHandler<"LanguageLoadError">;
|
|
89
|
-
onScriptsLoad: () => void;
|
|
90
|
-
onScriptsLoadError: (err: unknown) => void;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface IEvents extends INativeEvents, ITinyEvents {}
|
package/src/ScriptLoader2.ts
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { uuid } from "./Utils";
|
|
2
|
-
|
|
3
|
-
export type CallbackFn = () => void;
|
|
4
|
-
|
|
5
|
-
export interface ScriptItem {
|
|
6
|
-
src: string;
|
|
7
|
-
async?: boolean;
|
|
8
|
-
defer?: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface Id {
|
|
12
|
-
id: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const injectScriptTag = (
|
|
16
|
-
doc: Document,
|
|
17
|
-
item: ScriptItem & Id,
|
|
18
|
-
handler: (id: string, err?: unknown) => void,
|
|
19
|
-
) => {
|
|
20
|
-
const scriptTag = doc.createElement("script");
|
|
21
|
-
scriptTag.referrerPolicy = "origin";
|
|
22
|
-
scriptTag.type = "application/javascript";
|
|
23
|
-
scriptTag.id = item.id;
|
|
24
|
-
scriptTag.src = item.src;
|
|
25
|
-
scriptTag.async = item.async ?? false;
|
|
26
|
-
scriptTag.defer = item.defer ?? false;
|
|
27
|
-
|
|
28
|
-
const loadHandler = () => {
|
|
29
|
-
scriptTag.removeEventListener("load", loadHandler);
|
|
30
|
-
scriptTag.removeEventListener("error", errorHandler);
|
|
31
|
-
handler(item.src);
|
|
32
|
-
};
|
|
33
|
-
const errorHandler = (err: unknown) => {
|
|
34
|
-
scriptTag.removeEventListener("load", loadHandler);
|
|
35
|
-
scriptTag.removeEventListener("error", errorHandler);
|
|
36
|
-
handler(item.src, err);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
scriptTag.addEventListener("load", loadHandler);
|
|
40
|
-
scriptTag.addEventListener("error", errorHandler);
|
|
41
|
-
|
|
42
|
-
if (doc.head) {
|
|
43
|
-
doc.head.appendChild(scriptTag);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
interface ScriptState {
|
|
48
|
-
id: string;
|
|
49
|
-
src: string;
|
|
50
|
-
done: boolean;
|
|
51
|
-
error?: unknown;
|
|
52
|
-
handlers: ((src: string, err?: unknown) => void)[];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const createDocumentScriptLoader = (doc: Document) => {
|
|
56
|
-
let lookup: Record<string, ScriptState> = {};
|
|
57
|
-
|
|
58
|
-
const scriptLoadOrErrorHandler = (src: string, err?: unknown) => {
|
|
59
|
-
const item = lookup[src];
|
|
60
|
-
item.done = true;
|
|
61
|
-
item.error = err;
|
|
62
|
-
for (const h of item.handlers) {
|
|
63
|
-
h(src, err);
|
|
64
|
-
}
|
|
65
|
-
item.handlers = [];
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const loadScripts = (
|
|
69
|
-
items: ScriptItem[],
|
|
70
|
-
success: () => void,
|
|
71
|
-
failure?: (err: unknown) => void,
|
|
72
|
-
) => {
|
|
73
|
-
const failureOrLog = (err: unknown) =>
|
|
74
|
-
failure !== undefined ? failure(err) : console.error(err);
|
|
75
|
-
if (items.length === 0) {
|
|
76
|
-
failureOrLog(new Error("At least one script must be provided"));
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
let successCount = 0;
|
|
80
|
-
let failed = false;
|
|
81
|
-
const loaded = (_src: string, err?: unknown) => {
|
|
82
|
-
if (failed) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (err) {
|
|
86
|
-
failed = true;
|
|
87
|
-
failureOrLog(err);
|
|
88
|
-
} else if (++successCount === items.length) {
|
|
89
|
-
success();
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
for (const item of items) {
|
|
93
|
-
const existing = lookup[item.src];
|
|
94
|
-
if (existing) {
|
|
95
|
-
if (existing.done) {
|
|
96
|
-
loaded(item.src, existing.error);
|
|
97
|
-
} else {
|
|
98
|
-
existing.handlers.push(loaded);
|
|
99
|
-
}
|
|
100
|
-
} else {
|
|
101
|
-
// create a new entry
|
|
102
|
-
const id = uuid("tiny-");
|
|
103
|
-
lookup[item.src] = {
|
|
104
|
-
id,
|
|
105
|
-
src: item.src,
|
|
106
|
-
done: false,
|
|
107
|
-
error: null,
|
|
108
|
-
handlers: [loaded],
|
|
109
|
-
};
|
|
110
|
-
injectScriptTag(doc, { id, ...item }, scriptLoadOrErrorHandler);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const deleteScripts = () => {
|
|
116
|
-
for (const item of Object.values(lookup)) {
|
|
117
|
-
const scriptTag = doc.getElementById(item.id);
|
|
118
|
-
if (scriptTag != null && scriptTag.tagName === "SCRIPT") {
|
|
119
|
-
scriptTag.parentNode?.removeChild(scriptTag);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
lookup = {};
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const getDocument = () => doc;
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
loadScripts,
|
|
129
|
-
deleteScripts,
|
|
130
|
-
getDocument,
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
type DocumentScriptLoader = ReturnType<typeof createDocumentScriptLoader>;
|
|
135
|
-
|
|
136
|
-
const createScriptLoader = () => {
|
|
137
|
-
const cache: DocumentScriptLoader[] = [];
|
|
138
|
-
|
|
139
|
-
const getDocumentScriptLoader = (doc: Document) => {
|
|
140
|
-
let loader = cache.find((l) => l.getDocument() === doc);
|
|
141
|
-
if (loader === undefined) {
|
|
142
|
-
loader = createDocumentScriptLoader(doc);
|
|
143
|
-
cache.push(loader);
|
|
144
|
-
}
|
|
145
|
-
return loader;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const loadList = (
|
|
149
|
-
doc: Document,
|
|
150
|
-
items: ScriptItem[],
|
|
151
|
-
delay: number,
|
|
152
|
-
success: () => void,
|
|
153
|
-
failure?: (err: unknown) => void,
|
|
154
|
-
) => {
|
|
155
|
-
const doLoad = () =>
|
|
156
|
-
getDocumentScriptLoader(doc).loadScripts(items, success, failure);
|
|
157
|
-
if (delay > 0) {
|
|
158
|
-
setTimeout(doLoad, delay);
|
|
159
|
-
} else {
|
|
160
|
-
doLoad();
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const reinitialize = () => {
|
|
165
|
-
for (let loader = cache.pop(); loader != null; loader = cache.pop()) {
|
|
166
|
-
loader.deleteScripts();
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
return {
|
|
171
|
-
loadList,
|
|
172
|
-
reinitialize,
|
|
173
|
-
};
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
export const ScriptLoader = createScriptLoader();
|
package/src/TinyMCE.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type TinyMCE as TinyMCEGlobal } from "tinymce";
|
|
2
|
-
|
|
3
|
-
const getTinymce = (view: Window): TinyMCEGlobal | null => {
|
|
4
|
-
const global = view as unknown as { tinymce: TinyMCEGlobal | null };
|
|
5
|
-
return global && global.tinymce ? global.tinymce : null;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export { getTinymce };
|
package/src/Utils.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { eventPropTypes, IEventPropTypes } from "./components/EditorPropTypes";
|
|
2
|
-
import { IAllProps } from "./components/EditorPropTypes";
|
|
3
|
-
import { Editor as TinyMCEEditor, EditorEvent } from "tinymce";
|
|
4
|
-
|
|
5
|
-
export const isFunction = (x: unknown): x is typeof Function =>
|
|
6
|
-
typeof x === "function";
|
|
7
|
-
|
|
8
|
-
const isEventProp = (name: string): name is keyof IEventPropTypes =>
|
|
9
|
-
name in eventPropTypes;
|
|
10
|
-
|
|
11
|
-
const eventAttrToEventName = <T extends string>(attrName: `on${T}`): T =>
|
|
12
|
-
String(attrName.slice(2)) as T;
|
|
13
|
-
|
|
14
|
-
type PropLookup = <K extends keyof IAllProps>(key: K) => IAllProps[K];
|
|
15
|
-
|
|
16
|
-
export const configHandlers2 = <H>(
|
|
17
|
-
handlerLookup: PropLookup,
|
|
18
|
-
on: (name: string, handler: H) => void,
|
|
19
|
-
off: (name: string, handler: H) => void,
|
|
20
|
-
adapter: <K extends keyof IEventPropTypes>(lookup: PropLookup, key: K) => H,
|
|
21
|
-
prevProps: Partial<IAllProps>,
|
|
22
|
-
props: Partial<IAllProps>,
|
|
23
|
-
boundHandlers: Record<string, H>,
|
|
24
|
-
): void => {
|
|
25
|
-
const prevEventKeys = Object.keys(prevProps).filter(isEventProp);
|
|
26
|
-
const currEventKeys = Object.keys(props).filter(isEventProp);
|
|
27
|
-
|
|
28
|
-
const removedKeys = prevEventKeys.filter((key) => props[key] === undefined);
|
|
29
|
-
const addedKeys = currEventKeys.filter((key) => prevProps[key] === undefined);
|
|
30
|
-
|
|
31
|
-
removedKeys.forEach((key) => {
|
|
32
|
-
// remove event handler
|
|
33
|
-
const eventName = eventAttrToEventName(key);
|
|
34
|
-
const wrappedHandler = boundHandlers[eventName];
|
|
35
|
-
off(eventName, wrappedHandler);
|
|
36
|
-
delete boundHandlers[eventName];
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
addedKeys.forEach((key) => {
|
|
40
|
-
const wrappedHandler = adapter(handlerLookup, key);
|
|
41
|
-
const eventName = eventAttrToEventName(key);
|
|
42
|
-
boundHandlers[eventName] = wrappedHandler;
|
|
43
|
-
on(eventName, wrappedHandler);
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const configHandlers = (
|
|
48
|
-
editor: TinyMCEEditor,
|
|
49
|
-
prevProps: Partial<IAllProps>,
|
|
50
|
-
props: Partial<IAllProps>,
|
|
51
|
-
boundHandlers: Record<string, (event: EditorEvent<unknown>) => unknown>,
|
|
52
|
-
lookup: PropLookup,
|
|
53
|
-
): void =>
|
|
54
|
-
configHandlers2(
|
|
55
|
-
lookup,
|
|
56
|
-
editor.on.bind(editor),
|
|
57
|
-
editor.off.bind(editor),
|
|
58
|
-
// @ts-expect-error: typescript cannot infer the type of the lookup function
|
|
59
|
-
(handlerLookup, key) => (e) => handlerLookup(key)?.(e, editor),
|
|
60
|
-
prevProps,
|
|
61
|
-
props,
|
|
62
|
-
boundHandlers,
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
let unique = 0;
|
|
66
|
-
|
|
67
|
-
export const uuid = (prefix: string): string => {
|
|
68
|
-
const time = Date.now();
|
|
69
|
-
const random = Math.floor(Math.random() * 1000000000);
|
|
70
|
-
|
|
71
|
-
unique++;
|
|
72
|
-
|
|
73
|
-
return prefix + "_" + random + unique + String(time);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export const isTextareaOrInput = (
|
|
77
|
-
element: Element | null,
|
|
78
|
-
): element is HTMLTextAreaElement | HTMLInputElement =>
|
|
79
|
-
element !== null &&
|
|
80
|
-
(element.tagName.toLowerCase() === "textarea" ||
|
|
81
|
-
element.tagName.toLowerCase() === "input");
|
|
82
|
-
|
|
83
|
-
const normalizePluginArray = (plugins?: string | string[]): string[] => {
|
|
84
|
-
if (typeof plugins === "undefined" || plugins === "") {
|
|
85
|
-
return [];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return Array.isArray(plugins) ? plugins : plugins.split(" ");
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export const mergePlugins = (
|
|
92
|
-
initPlugins: string | string[] | undefined,
|
|
93
|
-
inputPlugins: string | string[] | undefined,
|
|
94
|
-
): string[] =>
|
|
95
|
-
normalizePluginArray(initPlugins).concat(normalizePluginArray(inputPlugins));
|
|
96
|
-
|
|
97
|
-
export const isBeforeInputEventAvailable = () =>
|
|
98
|
-
window.InputEvent &&
|
|
99
|
-
typeof InputEvent.prototype.getTargetRanges === "function";
|
|
100
|
-
|
|
101
|
-
export const isInDoc = (elem: Node) => {
|
|
102
|
-
if (!("isConnected" in Node.prototype)) {
|
|
103
|
-
// Fallback for IE and old Edge
|
|
104
|
-
let current = elem;
|
|
105
|
-
let parent = elem.parentNode;
|
|
106
|
-
while (parent != null) {
|
|
107
|
-
current = parent;
|
|
108
|
-
parent = current.parentNode;
|
|
109
|
-
}
|
|
110
|
-
return current === elem.ownerDocument;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return elem.isConnected;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export const setMode = (
|
|
117
|
-
editor: TinyMCEEditor | undefined,
|
|
118
|
-
mode: "readonly" | "design",
|
|
119
|
-
) => {
|
|
120
|
-
if (editor !== undefined) {
|
|
121
|
-
if (
|
|
122
|
-
editor.mode != null &&
|
|
123
|
-
typeof editor.mode === "object" &&
|
|
124
|
-
typeof editor.mode.set === "function"
|
|
125
|
-
) {
|
|
126
|
-
editor.mode.set(mode);
|
|
127
|
-
} else {
|
|
128
|
-
// support TinyMCE 4
|
|
129
|
-
// @ts-expect-error: no point in explaining this to IE
|
|
130
|
-
editor.setMode(mode);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
};
|