tinymce-solid 0.0.1
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/.github/ISSUE_TEMPLATE/bug-report.yml +31 -0
- package/.github/ISSUE_TEMPLATE/feature-request.yml +27 -0
- package/.github/codeql/codeql-config.yml +2 -0
- package/.github/workflows/badges.yml +30 -0
- package/.github/workflows/ci.yml +47 -0
- package/.github/workflows/codeql.yml +75 -0
- package/LICENSE +21 -0
- package/README.md +135 -0
- package/banner.svg +179 -0
- package/components.json +16 -0
- package/dist/dev.js +1431 -0
- package/dist/dev.jsx +1426 -0
- package/dist/index.d.ts +255 -0
- package/dist/index.js +716 -0
- package/dist/index.jsx +709 -0
- package/eslint.config.mjs +5 -0
- package/package.json +80 -0
- package/postcss.config.js +6 -0
- package/src/Events.ts +93 -0
- package/src/ScriptLoader2.ts +176 -0
- package/src/TinyMCE.ts +8 -0
- package/src/Utils.ts +133 -0
- package/src/components/EditorPropTypes.ts +191 -0
- package/src/components/SolidEditor.tsx +391 -0
- package/src/index.tsx +6 -0
- package/tailwind.config.js +84 -0
- package/tsconfig.json +24 -0
- package/tsup.config.ts +42 -0
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tinymce-solid",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "TinyMCE for SolidJS",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"homepage": "https://thednp.github.io/tinymce-solid",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/thednp/tinymce-solid/issues"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public",
|
|
12
|
+
"registry": "https://registry.npmjs.org/"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"solid-js": "^1.8.17",
|
|
16
|
+
"tinymce": "^7.1.1"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@kobalte/core": "^0.13.3",
|
|
20
|
+
"@kobalte/utils": "^0.9.0",
|
|
21
|
+
"@types/node": "^20.14.1",
|
|
22
|
+
"@types/prop-types": "^15.7.12",
|
|
23
|
+
"autoprefixer": "^10.4.19",
|
|
24
|
+
"class-variance-authority": "^0.7.0",
|
|
25
|
+
"clsx": "^2.1.1",
|
|
26
|
+
"postcss": "^8.4.38",
|
|
27
|
+
"prettier": "^3.3.0",
|
|
28
|
+
"prop-types": "^15.8.1",
|
|
29
|
+
"tailwind-merge": "^2.3.0",
|
|
30
|
+
"tailwindcss": "^3.4.3",
|
|
31
|
+
"tailwindcss-animate": "^1.0.7",
|
|
32
|
+
"tsup": "^8.1.0",
|
|
33
|
+
"tsup-preset-solid": "^2.2.0",
|
|
34
|
+
"typescript": "^5.4.5",
|
|
35
|
+
"typescript-eslint": "^7.12.0",
|
|
36
|
+
"vite": "^5.2.12",
|
|
37
|
+
"vite-plugin-compression2": "^1.1.1",
|
|
38
|
+
"vite-plugin-solid": "^2.10.2"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18"
|
|
42
|
+
},
|
|
43
|
+
"main": "./dist/index.js",
|
|
44
|
+
"module": "./dist/index.js",
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"browser": {},
|
|
47
|
+
"exports": {
|
|
48
|
+
"solid": {
|
|
49
|
+
"development": "./dist/dev.jsx",
|
|
50
|
+
"import": "./dist/index.jsx"
|
|
51
|
+
},
|
|
52
|
+
"development": {
|
|
53
|
+
"import": {
|
|
54
|
+
"types": "./dist/index.d.ts",
|
|
55
|
+
"default": "./dist/dev.js"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"import": {
|
|
59
|
+
"types": "./dist/index.d.ts",
|
|
60
|
+
"default": "./dist/index.js"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"typesVersions": {},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"format": "prettier -w \"src/**/*.{js,ts,json,css,tsx,jsx}\"",
|
|
66
|
+
"build": "tsup",
|
|
67
|
+
"build:all": "pnpm build && pnpm build:docs",
|
|
68
|
+
"dev": "vite serve demo",
|
|
69
|
+
"build:docs": "vite build demo --config demo/vite.config.docs.ts",
|
|
70
|
+
"copy:tiny": "cp -a './node_modules/.pnpm/tinymce@7.1.1/node_modules/tinymce' './demo/public'",
|
|
71
|
+
"serve:docs": "vite serve docs --port 3000",
|
|
72
|
+
"lint": "pnpm lint:types && pnpm lint:code",
|
|
73
|
+
"lint:code": "eslint 'src/**/*.{ts,tsx}' --max-warnings 0",
|
|
74
|
+
"lint:types": "tsc --noEmit src/**/* --jsx preserve",
|
|
75
|
+
"fix:ts": "eslint 'src/**/*.{ts,tsx}' --fix",
|
|
76
|
+
"start": "pnpm serve:docs",
|
|
77
|
+
"serve": "vite preview docs --port 3000",
|
|
78
|
+
"version": "vite version"
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/Events.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
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 {}
|
|
@@ -0,0 +1,176 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { 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
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
attrName.substr(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
|
+
};
|
|
@@ -0,0 +1,191 @@
|
|
|
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
|
+
};
|