@rg-dev/tinymce-helpers 1.0.0 → 1.0.2
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/index.d.mts +29 -0
- package/index.mjs +365 -0
- package/package.json +4 -6
package/index.d.mts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Editor, RawEditorOptions } from 'tinymce';
|
|
2
|
+
|
|
3
|
+
type RemoveIndexSignature<T> = {
|
|
4
|
+
[K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K];
|
|
5
|
+
};
|
|
6
|
+
type EditorOpts = Omit<RemoveIndexSignature<RawEditorOptions>, 'setup' | 'target' | 'selector'> & Record<string, unknown>;
|
|
7
|
+
declare class tinymceHelpers {
|
|
8
|
+
private _editor;
|
|
9
|
+
private constructor();
|
|
10
|
+
static initMce(el: HTMLElement, customOpts?: {
|
|
11
|
+
skin?: "default" | "dark" | undefined;
|
|
12
|
+
customSetup?: ((editor: Editor) => void) | undefined;
|
|
13
|
+
overrides?: ((defaultOpts: EditorOpts) => EditorOpts) | undefined;
|
|
14
|
+
}): Promise<tinymceHelpers>;
|
|
15
|
+
_initMce(el: HTMLElement, customOpts?: {
|
|
16
|
+
skin?: "default" | "dark" | undefined;
|
|
17
|
+
customSetup?: ((editor: Editor) => void) | undefined;
|
|
18
|
+
overrides?: ((defaultOpts: EditorOpts) => EditorOpts) | undefined;
|
|
19
|
+
}): Promise<this>;
|
|
20
|
+
toggleEditable(): void;
|
|
21
|
+
isEditable(): boolean;
|
|
22
|
+
setContent(content: string): void;
|
|
23
|
+
private getCustomStyles;
|
|
24
|
+
toggleTextDirection(): void;
|
|
25
|
+
get editor(): Editor;
|
|
26
|
+
destroy(): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { tinymceHelpers };
|
package/index.mjs
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
18
|
+
|
|
19
|
+
// src/client/custom-components/tinymce-helpers.ts
|
|
20
|
+
import tinymce from "tinymce";
|
|
21
|
+
import "tinymce/icons/default/icons.min.js";
|
|
22
|
+
import "tinymce/themes/silver/theme.min.js";
|
|
23
|
+
import "tinymce/models/dom/model.min.js";
|
|
24
|
+
import "tinymce/plugins/advlist";
|
|
25
|
+
import "tinymce/plugins/code";
|
|
26
|
+
import "tinymce/plugins/emoticons";
|
|
27
|
+
import "tinymce/plugins/emoticons/js/emojis";
|
|
28
|
+
import "tinymce/plugins/link";
|
|
29
|
+
import "tinymce/plugins/lists";
|
|
30
|
+
import "tinymce/plugins/table";
|
|
31
|
+
import "tinymce/plugins/directionality";
|
|
32
|
+
import "tinymce/plugins/autolink";
|
|
33
|
+
import "tinymce/plugins/searchreplace";
|
|
34
|
+
import "tinymce/plugins/save";
|
|
35
|
+
import "tinymce/plugins/visualblocks";
|
|
36
|
+
import "tinymce/plugins/fullscreen";
|
|
37
|
+
import "tinymce/plugins/visualchars";
|
|
38
|
+
import "tinymce/plugins/image";
|
|
39
|
+
import "tinymce/plugins/media";
|
|
40
|
+
import "tinymce/plugins/codesample";
|
|
41
|
+
import "tinymce/plugins/charmap";
|
|
42
|
+
import "tinymce/plugins/pagebreak";
|
|
43
|
+
import "tinymce/plugins/nonbreaking";
|
|
44
|
+
import "tinymce/plugins/anchor";
|
|
45
|
+
import "tinymce/plugins/wordcount";
|
|
46
|
+
import "tinymce/plugins/help";
|
|
47
|
+
import "tinymce/plugins/help/js/i18n/keynav/en.js";
|
|
48
|
+
import "tinymce/plugins/quickbars";
|
|
49
|
+
import "tinymce/plugins/importcss";
|
|
50
|
+
import "tinymce/plugins/preview";
|
|
51
|
+
import "tinymce/plugins/insertdatetime";
|
|
52
|
+
|
|
53
|
+
// src/client/custom-components/mce.css?raw
|
|
54
|
+
var mce_default = ':where(.mce-content-body) {\n --editor-text: #000;\n --editor-link: #000;\n --editor-border: #aaa;\n --editor-table-header-text: #6e6e6e;\n --editor-table-row-even: #fafafa;\n --editor-hr: #bbb;\n}\n\nli::marker {\n color: var(--editor-link) !important;\n}\n\n::-webkit-scrollbar {\n width: 10px;\n}\n\n::-webkit-scrollbar-track {\n background: var(--editor-table-row-even);\n}\n\n::-webkit-scrollbar-thumb {\n background: var(--editor-link);\n border-radius: 35px;\n}\n\n@media print {\n .mce-content-body {\n --editor-text: #000;\n --editor-link: #000;\n --editor-border: #000;\n --editor-table-header-text: #000;\n --editor-table-row-even: transparent;\n --editor-hr: #000;\n }\n\n .mce-content-body blockquote {\n border-inline-start: unset !important;\n background: unset !important;\n color: unset !important;\n }\n\n .mce-content-body td[data-mce-selected]::after,\n .mce-content-body th[data-mce-selected]::after {\n display: none !important;\n}\n}\n\nimg {\n max-width: 100%;\n}\n\n\n\n.mce-content-body blockquote {\n margin: 25px 0;\n display: flex;\n flex-direction: column;\n padding: 15px 20px;\n border: none !important;\n background: var(--editor-table-row-even);\n color: var(--editor-text);\n}\n\n\n\n.mce-content-body blockquote p {\n margin: 0;\n}\n\n* {\n border: 0;\n padding: 0;\n margin: 0;\n background: 0 0;\n color: inherit;\n box-sizing: border-box;\n background-repeat: no-repeat;\n background-position: 50% 50%;\n font-weight: 400;\n}\n\n:focus {\n outline: 0;\n}\n\na {\n text-decoration: none;\n cursor: pointer;\n}\n\nb,\nb *,\nstrong,\nstrong * {\n font-weight: 700;\n}\n\nol,\nul {\n list-style: none;\n}\n\npre {\n font: inherit;\n}\n\nbutton,\ninput,\ninput:not([type]),\ninput[type="button"],\ninput[type="color"],\ninput[type="date"],\ninput[type="datetime-local"],\ninput[type="datetime"],\ninput[type="email"],\ninput[type="month"],\ninput[type="number"],\ninput[type="password"],\ninput[type="reset"],\ninput[type="search"],\ninput[type="submit"],\ninput[type="tel"],\ninput[type="text"],\ninput[type="time"],\ninput[type="url"],\ninput[type="week"],\nselect,\ntextarea {\n font: inherit;\n}\n\n.mce-container textarea {\n display: inline-block !important;\n}\n\n.mce-content-body {\n font-size: 28px;\n font-family: Rubik, Helvetica, Arial, sans-serif;\n padding: 0 25px 25px;\n color: var(--editor-text);\n}\n\n.mce-content-body table {\n width: 100%;\n table-layout: fixed;\n}\n\n.mce-content-body table td,\n.mce-content-body table th {\n overflow-wrap: anywhere;\n word-break: break-word;\n \n white-space: normal;\n}\n\n.mce-content-body h1 {\n font-size: 34px;\n line-height: 1.4em;\n margin: 25px 0 15px;\n}\n\n.mce-content-body h2 {\n font-size: 30px;\n line-height: 1.4em;\n margin: 25px 0 15px;\n}\n\n.mce-content-body h3 {\n font-size: 26px;\n line-height: 1.4em;\n margin: 25px 0 15px;\n}\n\n.mce-content-body h4 {\n font-size: 22px;\n line-height: 1.4em;\n margin: 25px 0 15px;\n}\n\n.mce-content-body h5 {\n font-size: 18px;\n line-height: 1.4em;\n margin: 25px 0 15px;\n}\n\n.mce-content-body h6 {\n font-size: 14px;\n line-height: 1.4em;\n margin: 25px 0 15px;\n}\n\n.mce-content-body p {\n margin: 25px 0;\n}\n\n.mce-content-body pre {\n font-family: monospace;\n}\n\n.mce-content-body ol,\n.mce-content-body ul {\n margin-left: 15px;\n list-style-position: outside;\n margin-bottom: 20px;\n}\n\n.mce-content-body ol li,\n.mce-content-body ul li {\n margin-left: 10px;\n margin-bottom: 10px;\n color: var(--editor-text);\n}\n\n.mce-content-body ul {\n list-style-type: disc;\n}\n\n.mce-content-body ol {\n list-style-type: decimal;\n}\n\n.mce-content-body a[href] {\n color: var(--editor-link);\n text-decoration: underline;\n}\n\n.mce-content-body table caption,\n.mce-content-body table td,\n.mce-content-body table th {\n padding: 15px 7px;\n font: inherit;\n}\n\n.mce-content-body table td,\n.mce-content-body table th {\n border: 1px solid var(--editor-border);\n border-collapse: collapse;\n}\n\n.mce-content-body table th {\n font-weight: 400;\n color: var(--editor-table-header-text);\n background-position: 100% 100%;\n background-size: 2px 10px;\n background-repeat: no-repeat;\n}\n\n.mce-content-body table {\n width: 100%;\n border-spacing: 0;\n border-collapse: separate;\n border: 1px solid var(--editor-border);\n}\n\n.mce-content-body table tr:nth-child(even) {\n background: var(--editor-table-row-even);\n}\n\n.mce-content-body hr {\n border-top: 2px solid var(--editor-hr);\n}';
|
|
55
|
+
|
|
56
|
+
// src/client/custom-components/tinymce-helpers.ts
|
|
57
|
+
import { isNonEmptyString } from "@rg-dev/stdlib/lib/common-env";
|
|
58
|
+
async function defaultSkin(document = false) {
|
|
59
|
+
const contentSkin = `default`;
|
|
60
|
+
const shellSkin = "oxide";
|
|
61
|
+
await Promise.all([
|
|
62
|
+
import("tinymce/skins/ui/oxide/content.js"),
|
|
63
|
+
import("tinymce/skins/content/default/content.js"),
|
|
64
|
+
import("tinymce/skins/ui/oxide/skin.js")
|
|
65
|
+
]);
|
|
66
|
+
return {
|
|
67
|
+
css: tinymce.Resource.get(`content/${contentSkin}/content.css`) + tinymce.Resource.get(`ui/${shellSkin}/content.css`) + `
|
|
68
|
+
|
|
69
|
+
.my-custom-styles{
|
|
70
|
+
direction: rtl;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
`,
|
|
74
|
+
skin: shellSkin
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
async function darkSkin() {
|
|
78
|
+
const contentSkin = `dark`;
|
|
79
|
+
const shellSkin = "oxide-dark";
|
|
80
|
+
await Promise.all(
|
|
81
|
+
[
|
|
82
|
+
import("tinymce/skins/ui/oxide-dark/content.js"),
|
|
83
|
+
import("tinymce/skins/content/dark/content.js"),
|
|
84
|
+
import("tinymce/skins/ui/oxide-dark/skin.js")
|
|
85
|
+
]
|
|
86
|
+
);
|
|
87
|
+
return {
|
|
88
|
+
css: tinymce.Resource.get(`content/${contentSkin}/content.css`) + tinymce.Resource.get(`ui/${shellSkin}/content.css`) + `
|
|
89
|
+
|
|
90
|
+
.my-custom-styles{
|
|
91
|
+
direction: rtl;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.mce-content-body {
|
|
95
|
+
--editor-bg: #222f3e;
|
|
96
|
+
--editor-text: #e4e8ec;
|
|
97
|
+
--editor-link: #74b9ff;
|
|
98
|
+
--editor-border: #526273;
|
|
99
|
+
--editor-table-header-text: #b8c2cc;
|
|
100
|
+
--editor-table-header-bg: #2c3e50;
|
|
101
|
+
--editor-table-row-even: #263747;
|
|
102
|
+
--editor-hr: #526273;
|
|
103
|
+
}
|
|
104
|
+
`,
|
|
105
|
+
skin: shellSkin
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
var skinsTable = {
|
|
109
|
+
dark: () => darkSkin(),
|
|
110
|
+
default: () => defaultSkin()
|
|
111
|
+
};
|
|
112
|
+
var tinymceHelpers = class _tinymceHelpers {
|
|
113
|
+
constructor() {
|
|
114
|
+
__publicField(this, "_editor");
|
|
115
|
+
}
|
|
116
|
+
static async initMce(el, customOpts = Object()) {
|
|
117
|
+
return await new _tinymceHelpers()._initMce(el, customOpts);
|
|
118
|
+
}
|
|
119
|
+
async _initMce(el, customOpts = Object()) {
|
|
120
|
+
var _a, _b;
|
|
121
|
+
if (!(el instanceof HTMLElement)) {
|
|
122
|
+
throw new Error("invalid element");
|
|
123
|
+
}
|
|
124
|
+
const theSkin = await skinsTable[customOpts.skin || "default"]();
|
|
125
|
+
theSkin.css += mce_default;
|
|
126
|
+
const that = this;
|
|
127
|
+
let opts = {
|
|
128
|
+
setup(editor) {
|
|
129
|
+
var _a2;
|
|
130
|
+
editor.ui.registry.addMenuItem("create-block-below", {
|
|
131
|
+
text: "Create block below",
|
|
132
|
+
icon: "plus",
|
|
133
|
+
onAction: () => {
|
|
134
|
+
const node = editor.selection.getNode();
|
|
135
|
+
const body = editor.getBody();
|
|
136
|
+
const topBlock = editor.dom.getParent(node, (n) => n.parentNode === body) || node;
|
|
137
|
+
const newBlock = editor.dom.create("p", {}, '<br data-mce-bogus="1">');
|
|
138
|
+
editor.dom.insertAfter(newBlock, topBlock);
|
|
139
|
+
editor.selection.setCursorLocation(newBlock, 0);
|
|
140
|
+
editor.focus();
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
editor.ui.registry.addMenuItem("create-block-above", {
|
|
144
|
+
text: "Create block above",
|
|
145
|
+
icon: "plus",
|
|
146
|
+
onAction: () => {
|
|
147
|
+
var _a3;
|
|
148
|
+
const node = editor.selection.getNode();
|
|
149
|
+
const body = editor.getBody();
|
|
150
|
+
const topBlock = editor.dom.getParent(node, (n) => n.parentNode === body) || node;
|
|
151
|
+
const newBlock = editor.dom.create("p", {}, '<br data-mce-bogus="1">');
|
|
152
|
+
(_a3 = topBlock.parentNode) == null ? void 0 : _a3.insertBefore(newBlock, topBlock);
|
|
153
|
+
editor.selection.setCursorLocation(newBlock, 0);
|
|
154
|
+
editor.focus();
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
editor.ui.registry.addMenuItem(
|
|
158
|
+
"change-dir",
|
|
159
|
+
{
|
|
160
|
+
text: "Switch text direction",
|
|
161
|
+
onAction: async () => {
|
|
162
|
+
that.toggleTextDirection();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
editor.ui.registry.addMenuItem(
|
|
167
|
+
"toggleEdit",
|
|
168
|
+
{
|
|
169
|
+
text: "toggle readonly",
|
|
170
|
+
onAction: async () => {
|
|
171
|
+
that.toggleEditable();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
editor.ui.registry.addMenuItem(
|
|
176
|
+
"reset-style-button-img",
|
|
177
|
+
{
|
|
178
|
+
text: "Reset Image Style",
|
|
179
|
+
icon: "resize",
|
|
180
|
+
onAction: function() {
|
|
181
|
+
const selectedImage = editor.selection.getNode();
|
|
182
|
+
if (selectedImage.nodeName === "IMG") {
|
|
183
|
+
selectedImage.style.width = "unset";
|
|
184
|
+
selectedImage.style.height = "unset";
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
), editor.ui.registry.addMenuItem("clearTextStyle", {
|
|
189
|
+
text: "Clear formatting",
|
|
190
|
+
icon: "removeformat",
|
|
191
|
+
onAction: () => {
|
|
192
|
+
editor.execCommand("RemoveFormat");
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
editor.ui.registry.addButton(
|
|
196
|
+
"decreaseFontSize",
|
|
197
|
+
{
|
|
198
|
+
tooltip: "Decrease Font Size",
|
|
199
|
+
icon: "minus",
|
|
200
|
+
onAction: () => {
|
|
201
|
+
const currentSize = editor.queryCommandValue("FontSize");
|
|
202
|
+
let newSize = 16;
|
|
203
|
+
if (currentSize) {
|
|
204
|
+
const sizeNum = parseInt(currentSize.toString());
|
|
205
|
+
if (!isNaN(sizeNum) && sizeNum > 8) {
|
|
206
|
+
newSize = sizeNum - 2;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
editor.execCommand("FontSize", false, newSize + "px");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
editor.ui.registry.addButton(
|
|
214
|
+
"increaseFontSize",
|
|
215
|
+
{
|
|
216
|
+
tooltip: "Increase Font Size",
|
|
217
|
+
icon: "plus",
|
|
218
|
+
onAction: () => {
|
|
219
|
+
const currentSize = editor.queryCommandValue("FontSize");
|
|
220
|
+
let newSize = 16;
|
|
221
|
+
if (currentSize) {
|
|
222
|
+
const sizeNum = parseInt(currentSize.toString());
|
|
223
|
+
if (!isNaN(sizeNum)) {
|
|
224
|
+
newSize = sizeNum + 2;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
editor.execCommand("FontSize", false, newSize + "px");
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
(_a2 = customOpts.customSetup) == null ? void 0 : _a2.call(customOpts, editor);
|
|
232
|
+
},
|
|
233
|
+
newline_behavior: "linebreak",
|
|
234
|
+
id: "tinymce",
|
|
235
|
+
extended_valid_elements: "img[drawio-diagram|contenteditable|style|class|src]",
|
|
236
|
+
font_family_formats: "Rubik=Rubik, Helvetica, Arial, sans-serif; Andale Mono=andale mono,times; Arial=arial,helvetica,sans-serif; Arial Black=arial black,avant garde; Book Antiqua=book antiqua,palatino; Comic Sans MS=comic sans ms,sans-serif; Courier New=courier new,courier; Georgia=georgia,palatino; Helvetica=helvetica; Impact=impact,chicago; Symbol=symbol; Tahoma=tahoma,arial,helvetica,sans-serif; Terminal=terminal,monaco; Times New Roman=times new roman,times; Trebuchet MS=trebuchet ms,geneva; Verdana=verdana,geneva; Webdings=webdings; Wingdings=wingdings,zapf dingbats; Afacad=afacad,sans-serif; Marcellus=marcellus,serif; Poppins=poppins,sans-serif; Raleway=raleway,sans-serif;",
|
|
237
|
+
skin: theSkin.skin,
|
|
238
|
+
highlight_on_focus: false,
|
|
239
|
+
content_style: theSkin.css,
|
|
240
|
+
body_class: "my-custom-styles",
|
|
241
|
+
target: el,
|
|
242
|
+
toolbar: "undo redo | increaseFontSize decreaseFontSize bold italic underline strikethrough | fontfamily fontsize | ltr rtl alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | forecolor backcolor removeformat | charmap emoticons | fullscreen preview save print | insertfile image media template link anchor codesample",
|
|
243
|
+
toolbar_sticky: true,
|
|
244
|
+
promotion: false,
|
|
245
|
+
image_advtab: true,
|
|
246
|
+
license_key: "gpl",
|
|
247
|
+
resize: false,
|
|
248
|
+
height: "100%",
|
|
249
|
+
image_caption: true,
|
|
250
|
+
quickbars_selection_toolbar: "bold italic | quicklink blockquote quickimage quicktable",
|
|
251
|
+
noneditable_noneditable_class: "mceNonEditable",
|
|
252
|
+
toolbar_mode: "sliding",
|
|
253
|
+
browser_spellcheck: true,
|
|
254
|
+
menu: {
|
|
255
|
+
file: {
|
|
256
|
+
title: "File",
|
|
257
|
+
items: "print"
|
|
258
|
+
},
|
|
259
|
+
others_menu: {
|
|
260
|
+
title: "Others",
|
|
261
|
+
items: "change-dir toggleEdit"
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
menubar: "file edit view insert format tools table others_menu",
|
|
265
|
+
//spellchecker_active: true,
|
|
266
|
+
// spellchecker_languages: 'US English=en-US,Hebrew=he_IL',
|
|
267
|
+
// "spellchecker_rpc_url": "https://spelling.iad.tiny.cloud",
|
|
268
|
+
// "spellchecker_rpc_url": "http://10.0.0.13:7777",
|
|
269
|
+
// "spellchecker_api_key": "qagffr3pkuv17a8on1afax661irst1hbr4e6tbv888sz91jc",
|
|
270
|
+
// spellchecker_language: 'he_IL',
|
|
271
|
+
//tinymcespellchecker
|
|
272
|
+
plugins: "preview importcss searchreplace autolink directionality code visualblocks visualchars fullscreen image link media codesample table charmap pagebreak nonbreaking anchor insertdatetime advlist lists wordcount charmap quickbars emoticons",
|
|
273
|
+
// contextmenu: false,
|
|
274
|
+
contextmenu: "link image table create-block-above create-block-below reset-style-button-img clearTextStyle"
|
|
275
|
+
};
|
|
276
|
+
opts = __spreadValues(__spreadValues({}, opts), ((_a = customOpts.overrides) == null ? void 0 : _a.call(customOpts, opts)) || {});
|
|
277
|
+
if (!opts.skin) {
|
|
278
|
+
throw new Error("no skin");
|
|
279
|
+
}
|
|
280
|
+
const mce = this._editor = await tinymce.init(opts).then((x) => x[0]);
|
|
281
|
+
const all = mce.ui.registry.getAll();
|
|
282
|
+
const availableMenuItems = all.menuItems;
|
|
283
|
+
if (typeof opts.contextmenu == "string") {
|
|
284
|
+
if (!isNonEmptyString(opts.contextmenu.trim())) {
|
|
285
|
+
console.error("Context menu is missing items");
|
|
286
|
+
} else {
|
|
287
|
+
const items = opts.contextmenu.trim().split(/\s+/);
|
|
288
|
+
for (const item of items) {
|
|
289
|
+
if (!availableMenuItems[item.toLowerCase()] && !all.contextToolbars[item.toLocaleLowerCase()]) {
|
|
290
|
+
console.error(
|
|
291
|
+
`Context menu references unknown menu item "${item}"`
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (opts.menu) {
|
|
298
|
+
for (const [key, value] of Object.entries(opts.menu)) {
|
|
299
|
+
if (!isNonEmptyString((_b = value.items) == null ? void 0 : _b.trim())) {
|
|
300
|
+
console.error(`Menu "${key}" is missing items`);
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
const items = value.items.trim().split(/\s+/);
|
|
304
|
+
for (const item of items) {
|
|
305
|
+
if (!availableMenuItems[item.toLowerCase()]) {
|
|
306
|
+
console.error(
|
|
307
|
+
`Menu "${key}" references unknown menu item "${item}"`
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return this;
|
|
314
|
+
}
|
|
315
|
+
toggleEditable() {
|
|
316
|
+
const curr = this.editor.getBody().isContentEditable;
|
|
317
|
+
const toolbar = this.editor.getContainer().querySelector(".tox-toolbar-overlord");
|
|
318
|
+
if (toolbar) {
|
|
319
|
+
toolbar.style.display = curr ? "none" : "";
|
|
320
|
+
}
|
|
321
|
+
this.editor.setEditableRoot(!curr);
|
|
322
|
+
}
|
|
323
|
+
isEditable() {
|
|
324
|
+
return this.editor.getBody().isContentEditable;
|
|
325
|
+
}
|
|
326
|
+
setContent(content) {
|
|
327
|
+
this._editor.setContent(content);
|
|
328
|
+
this._editor.undoManager.clear();
|
|
329
|
+
}
|
|
330
|
+
getCustomStyles() {
|
|
331
|
+
const sheets = this._editor.getDoc().styleSheets;
|
|
332
|
+
for (let sheet of sheets) {
|
|
333
|
+
for (let rule of sheet.cssRules) {
|
|
334
|
+
if (rule.selectorText == ".my-custom-styles") {
|
|
335
|
+
return rule.style;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
toggleTextDirection() {
|
|
341
|
+
if (!this.isEditable()) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const styles = this.getCustomStyles();
|
|
345
|
+
if (!styles) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const dir = styles.direction == "rtl" ? "ltr" : "rtl";
|
|
349
|
+
const newDirection = dir;
|
|
350
|
+
styles.direction = newDirection;
|
|
351
|
+
const tds = this._editor.dom.select("td");
|
|
352
|
+
for (let td of tds) {
|
|
353
|
+
this._editor.dom.setStyle(td, "direction", dir);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
get editor() {
|
|
357
|
+
return this._editor;
|
|
358
|
+
}
|
|
359
|
+
destroy() {
|
|
360
|
+
this._editor.destroy();
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
export {
|
|
364
|
+
tinymceHelpers
|
|
365
|
+
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rg-dev/tinymce-helpers",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
8
|
"build": "tsup"
|
|
9
9
|
},
|
|
10
|
-
"types": "./
|
|
10
|
+
"types": "./index.d.mts",
|
|
11
11
|
"type": "module",
|
|
12
|
-
|
|
13
|
-
"dist"
|
|
14
|
-
],
|
|
12
|
+
|
|
15
13
|
"exports": {
|
|
16
14
|
".": {
|
|
17
|
-
"import": "./
|
|
15
|
+
"import": "./index.mjs"
|
|
18
16
|
}
|
|
19
17
|
},
|
|
20
18
|
"publishConfig": {
|