@studiocms/wysiwyg 0.1.0-experimental.2 → 0.1.0-experimental.3
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/dist/wysiwyg/components/Editor.astro +24 -38
- package/dist/wysiwyg/editorPlugins/blocks/blocks.d.ts +3 -0
- package/dist/wysiwyg/editorPlugins/blocks/blocks.js +239 -0
- package/dist/wysiwyg/editorPlugins/blocks/index.d.ts +80 -0
- package/dist/wysiwyg/editorPlugins/blocks/index.js +26 -0
- package/dist/wysiwyg/editorPlugins/code/blocks.d.ts +4 -0
- package/dist/wysiwyg/editorPlugins/code/blocks.js +20 -0
- package/dist/wysiwyg/editorPlugins/code/commands.d.ts +4 -0
- package/dist/wysiwyg/editorPlugins/code/commands.js +109 -0
- package/dist/wysiwyg/editorPlugins/code/components.d.ts +4 -0
- package/dist/wysiwyg/editorPlugins/code/components.js +88 -0
- package/dist/wysiwyg/editorPlugins/code/index.d.ts +47 -0
- package/dist/wysiwyg/editorPlugins/code/index.js +28 -0
- package/dist/wysiwyg/editorPlugins/code/utils.d.ts +3 -0
- package/dist/wysiwyg/editorPlugins/code/utils.js +8 -0
- package/dist/wysiwyg/editorPlugins/countdown.d.ts +86 -0
- package/dist/wysiwyg/editorPlugins/countdown.js +163 -0
- package/dist/wysiwyg/editorPlugins/forms/blocks.d.ts +3 -0
- package/dist/wysiwyg/editorPlugins/forms/blocks.js +93 -0
- package/dist/wysiwyg/editorPlugins/forms/components.d.ts +11 -0
- package/dist/wysiwyg/editorPlugins/forms/components.js +284 -0
- package/dist/wysiwyg/editorPlugins/forms/index.d.ts +21 -0
- package/dist/wysiwyg/editorPlugins/forms/index.js +18 -0
- package/dist/wysiwyg/editorPlugins/forms/traits.d.ts +2 -0
- package/dist/wysiwyg/editorPlugins/forms/traits.js +47 -0
- package/dist/wysiwyg/editorPlugins/index.d.ts +9 -0
- package/dist/wysiwyg/editorPlugins/index.js +20 -0
- package/dist/wysiwyg/editorPlugins/rte/colorPicker.d.ts +95 -0
- package/dist/wysiwyg/editorPlugins/rte/colorPicker.js +185 -0
- package/dist/wysiwyg/editorPlugins/rte/index.d.ts +48 -0
- package/dist/wysiwyg/editorPlugins/rte/index.js +369 -0
- package/dist/wysiwyg/editorPlugins/rte/styles.css +63 -0
- package/dist/wysiwyg/editorPlugins/tabs/blocks.d.ts +3 -0
- package/dist/wysiwyg/editorPlugins/tabs/blocks.js +19 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/Tab.d.ts +10 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/Tab.js +100 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/TabContainer.d.ts +5 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/TabContainer.js +23 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/TabContent.d.ts +5 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/TabContent.js +23 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/TabContents.d.ts +4 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/TabContents.js +19 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/Tabs.d.ts +4 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/Tabs.js +169 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/index.d.ts +4 -0
- package/dist/wysiwyg/editorPlugins/tabs/components/index.js +29 -0
- package/dist/wysiwyg/editorPlugins/tabs/index.d.ts +5 -0
- package/dist/wysiwyg/editorPlugins/tabs/index.js +15 -0
- package/dist/wysiwyg/editorPlugins/tabs/options.d.ts +5 -0
- package/dist/wysiwyg/editorPlugins/tabs/options.js +80 -0
- package/dist/wysiwyg/editorPlugins/tabs/types.d.ts +81 -0
- package/dist/wysiwyg/editorPlugins/tabs/types.js +0 -0
- package/dist/wysiwyg/editorPlugins/tooltip.d.ts +68 -0
- package/dist/wysiwyg/editorPlugins/tooltip.js +318 -0
- package/dist/wysiwyg/editorPlugins/tuiImageEditor.d.ts +86 -0
- package/dist/wysiwyg/editorPlugins/tuiImageEditor.js +204 -0
- package/dist/wysiwyg/editorPlugins/typed/blocks.d.ts +4 -0
- package/dist/wysiwyg/editorPlugins/typed/blocks.js +15 -0
- package/dist/wysiwyg/editorPlugins/typed/components.d.ts +9 -0
- package/dist/wysiwyg/editorPlugins/typed/components.js +109 -0
- package/dist/wysiwyg/editorPlugins/typed/index.d.ts +35 -0
- package/dist/wysiwyg/editorPlugins/typed/index.js +18 -0
- package/dist/wysiwyg/editorPlugins/typed/traits.d.ts +3 -0
- package/dist/wysiwyg/editorPlugins/typed/traits.js +18 -0
- package/dist/wysiwyg/editorPlugins/typed/utils.d.ts +2 -0
- package/dist/wysiwyg/editorPlugins/typed/utils.js +6 -0
- package/package.json +2 -14
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Plugin } from 'grapesjs';
|
|
2
|
+
interface FontOptions {
|
|
3
|
+
fontName?: string[] | boolean;
|
|
4
|
+
fontSize?: boolean;
|
|
5
|
+
fontColor?: string[] | boolean;
|
|
6
|
+
hilite?: string[] | boolean;
|
|
7
|
+
}
|
|
8
|
+
interface BaseOptions {
|
|
9
|
+
bold?: boolean;
|
|
10
|
+
italic?: boolean;
|
|
11
|
+
underline?: boolean;
|
|
12
|
+
strikethrough?: boolean;
|
|
13
|
+
link?: boolean;
|
|
14
|
+
}
|
|
15
|
+
interface FormatOptions {
|
|
16
|
+
heading1?: boolean;
|
|
17
|
+
heading2?: boolean;
|
|
18
|
+
heading3?: boolean;
|
|
19
|
+
heading4?: boolean;
|
|
20
|
+
heading5?: boolean;
|
|
21
|
+
heading6?: boolean;
|
|
22
|
+
paragraph?: boolean;
|
|
23
|
+
quote?: boolean;
|
|
24
|
+
clearFormatting?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface ActionOptions {
|
|
27
|
+
copy?: boolean;
|
|
28
|
+
cut?: boolean;
|
|
29
|
+
paste?: boolean;
|
|
30
|
+
delete?: boolean;
|
|
31
|
+
}
|
|
32
|
+
interface RichTextEditorOptions {
|
|
33
|
+
base?: BaseOptions | boolean;
|
|
34
|
+
fonts?: FontOptions;
|
|
35
|
+
format?: FormatOptions | boolean;
|
|
36
|
+
subscriptSuperscript?: boolean;
|
|
37
|
+
indentOutdent?: boolean;
|
|
38
|
+
list?: boolean;
|
|
39
|
+
align?: boolean;
|
|
40
|
+
actions?: ActionOptions | boolean;
|
|
41
|
+
undoredo?: boolean;
|
|
42
|
+
extra?: boolean;
|
|
43
|
+
icons?: Record<string, string>;
|
|
44
|
+
darkColorPicker?: boolean;
|
|
45
|
+
maxWidth?: string;
|
|
46
|
+
}
|
|
47
|
+
declare const plugin: Plugin<RichTextEditorOptions>;
|
|
48
|
+
export default plugin;
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import ColorPicker from "./colorPicker.js";
|
|
2
|
+
const plugin = (editor, opts = {}) => {
|
|
3
|
+
const options = {
|
|
4
|
+
...{
|
|
5
|
+
// default options
|
|
6
|
+
base: {
|
|
7
|
+
bold: true,
|
|
8
|
+
italic: true,
|
|
9
|
+
underline: true,
|
|
10
|
+
strikethrough: true,
|
|
11
|
+
link: true
|
|
12
|
+
},
|
|
13
|
+
//fonts: {
|
|
14
|
+
// fontName: ['font1',...,'fontn'],
|
|
15
|
+
// fontSize: true,
|
|
16
|
+
// //An array of strings representing colors
|
|
17
|
+
// fontColor: [],
|
|
18
|
+
// //An array of strings representing colors
|
|
19
|
+
// hilite: [],
|
|
20
|
+
//}
|
|
21
|
+
fonts: {
|
|
22
|
+
fontColor: true,
|
|
23
|
+
hilite: true
|
|
24
|
+
},
|
|
25
|
+
format: {
|
|
26
|
+
heading1: true,
|
|
27
|
+
heading2: true,
|
|
28
|
+
heading3: true,
|
|
29
|
+
//heading4: false,
|
|
30
|
+
//heading5: false,
|
|
31
|
+
//heading6: false,
|
|
32
|
+
paragraph: true,
|
|
33
|
+
//quote: false,
|
|
34
|
+
clearFormatting: true
|
|
35
|
+
},
|
|
36
|
+
subscriptSuperscript: false,
|
|
37
|
+
indentOutdent: false,
|
|
38
|
+
list: false,
|
|
39
|
+
align: true,
|
|
40
|
+
//actions: {
|
|
41
|
+
// copy: true,
|
|
42
|
+
// cut: true,
|
|
43
|
+
// paste: true,
|
|
44
|
+
// delete: true,
|
|
45
|
+
//},
|
|
46
|
+
actions: false,
|
|
47
|
+
undoredo: false,
|
|
48
|
+
extra: false,
|
|
49
|
+
icons: {},
|
|
50
|
+
darkColorPicker: true
|
|
51
|
+
},
|
|
52
|
+
...opts
|
|
53
|
+
};
|
|
54
|
+
const { icons } = options;
|
|
55
|
+
const formatBlock = "formatBlock";
|
|
56
|
+
const rte = editor.RichTextEditor;
|
|
57
|
+
const fontNames = options.fonts?.fontName ? Array.isArray(options.fonts.fontName) ? options.fonts.fontName : false : false;
|
|
58
|
+
if (options.fonts) {
|
|
59
|
+
options.fonts.fontName = fontNames;
|
|
60
|
+
}
|
|
61
|
+
const fontOptionsEl = fontNames ? fontNames.map((font) => `<option>${font.toString()}</option>`).join("") : "";
|
|
62
|
+
const fontNamesEl = `<select style="height:1.8rem;color:inherit;" class="gjs-field gjs-field-select">
|
|
63
|
+
${fontOptionsEl}
|
|
64
|
+
</select>`;
|
|
65
|
+
editor.onReady(() => {
|
|
66
|
+
if (options.maxWidth) rte.getToolbarEl().firstChild.style.maxWidth = options.maxWidth;
|
|
67
|
+
if (!options.base || typeof options.base === "object") {
|
|
68
|
+
const baseOpts = options.base;
|
|
69
|
+
!baseOpts.bold && rte.remove("bold");
|
|
70
|
+
!baseOpts.italic && rte.remove("italic");
|
|
71
|
+
!baseOpts.underline && rte.remove("underline");
|
|
72
|
+
!baseOpts.strikethrough && rte.remove("strikethrough");
|
|
73
|
+
!baseOpts.link && rte.remove("link");
|
|
74
|
+
}
|
|
75
|
+
options.fonts?.fontName && rte.add("fontName", {
|
|
76
|
+
icon: fontNamesEl,
|
|
77
|
+
// Bind the 'result' on 'change' listener
|
|
78
|
+
event: "change",
|
|
79
|
+
attributes: {
|
|
80
|
+
style: "padding: 0 4px 2px;",
|
|
81
|
+
title: "Font Name"
|
|
82
|
+
},
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
result: (rte2, action) => rte2.exec("fontName", action.btn?.firstChild?.value),
|
|
85
|
+
// Callback on any input change (mousedown, keydown, etc..)
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
update: (rte2, action) => {
|
|
88
|
+
const value = rte2.doc.queryCommandValue(action.name);
|
|
89
|
+
if (value !== "false") {
|
|
90
|
+
if (action.btn?.firstChild) action.btn.firstChild.value = value;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
options.fonts?.fontSize && rte.add("fontSize", {
|
|
95
|
+
icon: `<select style="height:1.8rem;color:inherit;" class="gjs-field gjs-field-select">
|
|
96
|
+
<option value="1">xx-small</option>
|
|
97
|
+
<option value="2">x-small</option>
|
|
98
|
+
<option value="3">small</option>
|
|
99
|
+
<option value="4">medium</option>
|
|
100
|
+
<option value="5">large</option>
|
|
101
|
+
<option value="6">x-large</option>
|
|
102
|
+
<option value="7">xx-large</option>
|
|
103
|
+
</select>`,
|
|
104
|
+
// Bind the 'result' on 'change' listener
|
|
105
|
+
event: "change",
|
|
106
|
+
attributes: {
|
|
107
|
+
style: "padding: 0 4px 2px;",
|
|
108
|
+
title: "Font Size"
|
|
109
|
+
},
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
result: (rte2, action) => rte2.exec("fontSize", action.btn?.firstChild?.value),
|
|
112
|
+
// Callback on any input change (mousedown, keydown, etc..)
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
update: (rte2, action) => {
|
|
115
|
+
const value = rte2.doc.queryCommandValue(action.name);
|
|
116
|
+
if (value !== "false") {
|
|
117
|
+
action.btn.firstChild.value = value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
const pk1 = {};
|
|
122
|
+
options.fonts?.fontColor && rte.add("fontColor", {
|
|
123
|
+
icon: `${icons?.fontColor || '<b style="pointer-events:none;border-bottom:2px solid">A</b>'}
|
|
124
|
+
<div id="foreColor-picker-${// @ts-ignore
|
|
125
|
+
editor.Config.container?.replace("#", "")}"
|
|
126
|
+
class="${options.darkColorPicker ? "rte-color-picker dark" : "rte-color-picker light"}">
|
|
127
|
+
</div>`,
|
|
128
|
+
attributes: {
|
|
129
|
+
id: "rte-font-color",
|
|
130
|
+
title: "Font Color"
|
|
131
|
+
},
|
|
132
|
+
result: (rte2) => {
|
|
133
|
+
const pikerEle = `#foreColor-picker-${// @ts-ignore
|
|
134
|
+
editor.Config.container?.replace("#", "")}`;
|
|
135
|
+
if (!pk1[pikerEle])
|
|
136
|
+
pk1[pikerEle] = new ColorPicker(
|
|
137
|
+
pikerEle,
|
|
138
|
+
options.fonts?.fontColor ? Array.isArray(options.fonts.fontColor) ? options.fonts.fontColor : void 0 : void 0,
|
|
139
|
+
{
|
|
140
|
+
open: "span#rte-font-color.gjs-rte-action",
|
|
141
|
+
closeOnBlur: true
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
pk1[pikerEle].colorChosen((col) => rte2.exec("foreColor", col));
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
const pk2 = {};
|
|
148
|
+
options.fonts?.hilite && rte.add("hiliteColor", {
|
|
149
|
+
icon: `${icons?.hiliteColor || '<b style="pointer-events:none;" class="rte-hilite-btn">A</b>'}
|
|
150
|
+
<div id="hilite-picker-${// @ts-ignore
|
|
151
|
+
editor.Config.container?.replace("#", "")}"
|
|
152
|
+
class="${options.darkColorPicker ? "rte-color-picker dark" : "rte-color-picker light"}">
|
|
153
|
+
</div>`,
|
|
154
|
+
attributes: {
|
|
155
|
+
id: "rte-font-hilite",
|
|
156
|
+
title: "Font Highlight"
|
|
157
|
+
},
|
|
158
|
+
result: (rte2) => {
|
|
159
|
+
const pikerEle = `#hilite-picker-${// @ts-ignore
|
|
160
|
+
editor.Config.container?.replace("#", "")}`;
|
|
161
|
+
if (!pk2[pikerEle])
|
|
162
|
+
pk2[pikerEle] = new ColorPicker(
|
|
163
|
+
pikerEle,
|
|
164
|
+
options.fonts?.hilite ? Array.isArray(options.fonts.hilite) ? options.fonts.hilite : void 0 : void 0,
|
|
165
|
+
{
|
|
166
|
+
open: "span#rte-font-hilite.gjs-rte-action",
|
|
167
|
+
closeOnBlur: true
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
pk2[pikerEle].colorChosen((col) => rte2.exec("hiliteColor", col));
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const formatOpts = options.format;
|
|
174
|
+
options.format && formatOpts.heading1 && rte.add("heading1", {
|
|
175
|
+
icon: icons?.heading1 || "<div>H1</div>",
|
|
176
|
+
attributes: {
|
|
177
|
+
title: "Heading 1"
|
|
178
|
+
},
|
|
179
|
+
result: (rte2) => rte2.exec(formatBlock, "<h1>")
|
|
180
|
+
});
|
|
181
|
+
options.format && formatOpts.heading2 && rte.add("heading2", {
|
|
182
|
+
icon: icons?.heading2 || "<div>H2</div>",
|
|
183
|
+
attributes: {
|
|
184
|
+
title: "Heading 2"
|
|
185
|
+
},
|
|
186
|
+
result: (rte2) => rte2.exec(formatBlock, "<h2>")
|
|
187
|
+
});
|
|
188
|
+
options.format && formatOpts.heading3 && rte.add("heading3", {
|
|
189
|
+
icon: icons?.heading3 || "<div>H3</div>",
|
|
190
|
+
attributes: {
|
|
191
|
+
title: "Heading 3"
|
|
192
|
+
},
|
|
193
|
+
result: (rte2) => rte2.exec(formatBlock, "<h3>")
|
|
194
|
+
});
|
|
195
|
+
options.format && formatOpts.heading4 && rte.add("heading4", {
|
|
196
|
+
icon: icons?.heading4 || "<div>H4</div>",
|
|
197
|
+
attributes: {
|
|
198
|
+
title: "Heading 4"
|
|
199
|
+
},
|
|
200
|
+
result: (rte2) => rte2.exec(formatBlock, "<h4>")
|
|
201
|
+
});
|
|
202
|
+
options.format && formatOpts.heading5 && rte.add("heading5", {
|
|
203
|
+
icon: icons?.heading5 || "<div>H5</div>",
|
|
204
|
+
attributes: {
|
|
205
|
+
title: "Heading 5"
|
|
206
|
+
},
|
|
207
|
+
result: (rte2) => rte2.exec(formatBlock, "<h5>")
|
|
208
|
+
});
|
|
209
|
+
options.format && formatOpts.heading6 && rte.add("heading6", {
|
|
210
|
+
icon: icons?.heading6 || "<div>H6</div>",
|
|
211
|
+
attributes: {
|
|
212
|
+
title: "Heading 6"
|
|
213
|
+
},
|
|
214
|
+
result: (rte2) => rte2.exec(formatBlock, "<h6>")
|
|
215
|
+
});
|
|
216
|
+
options.format && formatOpts.paragraph && rte.add("paragraph", {
|
|
217
|
+
icon: icons?.paragraph || "¶",
|
|
218
|
+
attributes: {
|
|
219
|
+
title: "Paragraph"
|
|
220
|
+
},
|
|
221
|
+
result: (rte2) => rte2.exec(formatBlock, "<p>")
|
|
222
|
+
});
|
|
223
|
+
options.format && formatOpts.quote && rte.add("quote", {
|
|
224
|
+
icon: icons?.quote || '<i class="fa fa-quote-left"></i>',
|
|
225
|
+
attributes: {
|
|
226
|
+
title: "Quote"
|
|
227
|
+
},
|
|
228
|
+
result: (rte2) => rte2.exec(formatBlock, "<blockquote>")
|
|
229
|
+
});
|
|
230
|
+
options.format && formatOpts.clearFormatting && rte.add("clearFormatting", {
|
|
231
|
+
icon: icons?.clear || '<i class="fa fa-eraser"></i>',
|
|
232
|
+
attributes: {
|
|
233
|
+
title: "Clear Formatting"
|
|
234
|
+
},
|
|
235
|
+
result: (rte2) => rte2.exec("removeFormat")
|
|
236
|
+
});
|
|
237
|
+
options.indentOutdent && rte.add("indent", {
|
|
238
|
+
icon: icons?.indent || '<i class="fa fa-indent"></i>',
|
|
239
|
+
attributes: {
|
|
240
|
+
title: "Indent"
|
|
241
|
+
},
|
|
242
|
+
result: (rte2) => rte2.exec("indent")
|
|
243
|
+
});
|
|
244
|
+
options.indentOutdent && rte.add("outdent", {
|
|
245
|
+
icon: icons?.outdent || '<i class="fa fa-outdent"></i>',
|
|
246
|
+
attributes: {
|
|
247
|
+
title: "Outdent"
|
|
248
|
+
},
|
|
249
|
+
result: (rte2) => rte2.exec("outdent")
|
|
250
|
+
});
|
|
251
|
+
options.subscriptSuperscript && rte.add("subscript", {
|
|
252
|
+
icon: icons?.subscript || "<div>X<sub>2</sub></div>",
|
|
253
|
+
attributes: {
|
|
254
|
+
title: "Subscript"
|
|
255
|
+
},
|
|
256
|
+
result: (rte2) => rte2.exec("subscript")
|
|
257
|
+
});
|
|
258
|
+
options.subscriptSuperscript && rte.add("superscript", {
|
|
259
|
+
icon: icons?.superscript || "<div>X<sup>2</sup></div>",
|
|
260
|
+
attributes: {
|
|
261
|
+
title: "Superscript"
|
|
262
|
+
},
|
|
263
|
+
result: (rte2) => rte2.exec("superscript")
|
|
264
|
+
});
|
|
265
|
+
options.list && rte.add("olist", {
|
|
266
|
+
icon: icons?.olist || '<i class="fa fa-list-ol"></i>',
|
|
267
|
+
attributes: {
|
|
268
|
+
title: "Ordered List"
|
|
269
|
+
},
|
|
270
|
+
result: (rte2) => rte2.exec("insertOrderedList")
|
|
271
|
+
});
|
|
272
|
+
options.list && rte.add("ulist", {
|
|
273
|
+
icon: icons?.ulist || '<i class="fa fa-list-ul"></i>',
|
|
274
|
+
attributes: {
|
|
275
|
+
title: "Unordered List"
|
|
276
|
+
},
|
|
277
|
+
result: (rte2) => rte2.exec("insertUnorderedList")
|
|
278
|
+
});
|
|
279
|
+
options.align && rte.add("justifyLeft", {
|
|
280
|
+
icon: icons?.justifyLeft || '<i class="fa fa-align-left"></i>',
|
|
281
|
+
attributes: {
|
|
282
|
+
title: "Align Left"
|
|
283
|
+
},
|
|
284
|
+
result: (rte2) => rte2.exec("justifyLeft")
|
|
285
|
+
});
|
|
286
|
+
options.align && rte.add("justifyCenter", {
|
|
287
|
+
icon: icons?.justifyRight || '<i class="fa fa-align-center"></i>',
|
|
288
|
+
attributes: {
|
|
289
|
+
title: "Align Center"
|
|
290
|
+
},
|
|
291
|
+
result: (rte2) => rte2.exec("justifyCenter")
|
|
292
|
+
});
|
|
293
|
+
options.align && rte.add("justifyFull", {
|
|
294
|
+
icon: icons?.justifyFull || '<i class="fa fa-align-justify"></i>',
|
|
295
|
+
attributes: {
|
|
296
|
+
title: "Align Justify"
|
|
297
|
+
},
|
|
298
|
+
result: (rte2) => rte2.exec("justifyFull")
|
|
299
|
+
});
|
|
300
|
+
options.align && rte.add("justifyRight", {
|
|
301
|
+
icon: icons?.justifyRight || '<i class="fa fa-align-right"></i>',
|
|
302
|
+
attributes: {
|
|
303
|
+
title: "Align Right"
|
|
304
|
+
},
|
|
305
|
+
result: (rte2) => rte2.exec("justifyRight")
|
|
306
|
+
});
|
|
307
|
+
const actionOpts = options.actions;
|
|
308
|
+
options.actions && actionOpts.copy && rte.add("copy", {
|
|
309
|
+
icon: icons?.copy || '<i class="fa fa-files-o"></i>',
|
|
310
|
+
attributes: {
|
|
311
|
+
title: "Copy"
|
|
312
|
+
},
|
|
313
|
+
result: (rte2) => rte2.exec("copy")
|
|
314
|
+
});
|
|
315
|
+
options.actions && actionOpts.cut && rte.add("cut", {
|
|
316
|
+
icon: icons?.cut || '<i class="fa fa-scissors"></i>',
|
|
317
|
+
attributes: {
|
|
318
|
+
title: "Cut"
|
|
319
|
+
},
|
|
320
|
+
result: (rte2) => rte2.exec("cut")
|
|
321
|
+
});
|
|
322
|
+
options.actions && actionOpts.paste && rte.add("paste", {
|
|
323
|
+
icon: icons?.paste || '<i class="fa fa-clipboard"></i>',
|
|
324
|
+
attributes: {
|
|
325
|
+
title: "Paste"
|
|
326
|
+
},
|
|
327
|
+
result: (rte2) => rte2.exec("paste")
|
|
328
|
+
});
|
|
329
|
+
options.actions && actionOpts.delete && rte.add("delete", {
|
|
330
|
+
icon: icons?.delete || '<i class="fa fa-trash-o"></i>',
|
|
331
|
+
attributes: {
|
|
332
|
+
title: "Delete"
|
|
333
|
+
},
|
|
334
|
+
result: (rte2) => rte2.exec("delete")
|
|
335
|
+
});
|
|
336
|
+
options.extra && rte.add("code", {
|
|
337
|
+
icon: icons?.code || '<i class="fa fa-code"></i>',
|
|
338
|
+
attributes: {
|
|
339
|
+
title: "Code"
|
|
340
|
+
},
|
|
341
|
+
result: (rte2) => rte2.exec(formatBlock, "<pre>")
|
|
342
|
+
});
|
|
343
|
+
options.extra && rte.add("line", {
|
|
344
|
+
icon: icons?.line || "<b>―</b>",
|
|
345
|
+
attributes: {
|
|
346
|
+
title: "Horizontal Line"
|
|
347
|
+
},
|
|
348
|
+
result: (rte2) => rte2.exec("insertHorizontalRule")
|
|
349
|
+
});
|
|
350
|
+
options.undoredo && rte.add("undo", {
|
|
351
|
+
icon: icons?.undo || '<i class="fa fa-reply"></i>',
|
|
352
|
+
attributes: {
|
|
353
|
+
title: "Undo"
|
|
354
|
+
},
|
|
355
|
+
result: (rte2) => rte2.exec("undo")
|
|
356
|
+
});
|
|
357
|
+
options.undoredo && rte.add("redo", {
|
|
358
|
+
icon: icons?.redo || '<i class="fa fa-share"></i>',
|
|
359
|
+
attributes: {
|
|
360
|
+
title: "Redo"
|
|
361
|
+
},
|
|
362
|
+
result: (rte2) => rte2.exec("redo")
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
var rte_default = plugin;
|
|
367
|
+
export {
|
|
368
|
+
rte_default as default
|
|
369
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
.gjs-rte-toolbar {
|
|
2
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.44);
|
|
3
|
+
border-radius: 3px;
|
|
4
|
+
}
|
|
5
|
+
.gjs-rte-action {
|
|
6
|
+
font-size: 1rem;
|
|
7
|
+
border-right: none;
|
|
8
|
+
padding: 10px;
|
|
9
|
+
min-width: 35px;
|
|
10
|
+
}
|
|
11
|
+
.gjs-rte-actionbar {
|
|
12
|
+
max-width: 600px;
|
|
13
|
+
flex-wrap: wrap;
|
|
14
|
+
}
|
|
15
|
+
.rte-hilite-btn {
|
|
16
|
+
padding: 3px 6px;
|
|
17
|
+
border-radius: 3px;
|
|
18
|
+
background: rgba(210, 120, 201, 0.3);
|
|
19
|
+
}
|
|
20
|
+
.rte-color-picker {
|
|
21
|
+
display: none;
|
|
22
|
+
padding: 10px;
|
|
23
|
+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2), 0 2px 5px rgba(0, 0, 0, 0.34);
|
|
24
|
+
border-radius: 5px;
|
|
25
|
+
position: absolute;
|
|
26
|
+
top: 55px;
|
|
27
|
+
width: 250px;
|
|
28
|
+
transition: all 2s ease;
|
|
29
|
+
}
|
|
30
|
+
.rte-color-picker:before {
|
|
31
|
+
content: "";
|
|
32
|
+
position: absolute;
|
|
33
|
+
top: -20px;
|
|
34
|
+
left: 46%;
|
|
35
|
+
border-width: 10px;
|
|
36
|
+
border-style: solid;
|
|
37
|
+
}
|
|
38
|
+
.rte-color-picker.dark {
|
|
39
|
+
background: rgba(0, 0, 0, 0.8);
|
|
40
|
+
}
|
|
41
|
+
.rte-color-picker.dark:before {
|
|
42
|
+
border-color: transparent transparent rgba(0, 0, 0, 0.75) transparent;
|
|
43
|
+
}
|
|
44
|
+
.rte-color-picker.light {
|
|
45
|
+
background: rgba(255, 255, 255, 0.75);
|
|
46
|
+
}
|
|
47
|
+
.rte-color-picker.light:before {
|
|
48
|
+
border-color: transparent transparent rgba(255, 255, 255, 0.75) transparent;
|
|
49
|
+
}
|
|
50
|
+
.rte-color-picker > div {
|
|
51
|
+
width: 30px;
|
|
52
|
+
display: inline-block;
|
|
53
|
+
height: 30px;
|
|
54
|
+
margin: 5px;
|
|
55
|
+
border-radius: 100%;
|
|
56
|
+
opacity: 0.7;
|
|
57
|
+
}
|
|
58
|
+
.rte-color-picker > div:hover {
|
|
59
|
+
opacity: 1;
|
|
60
|
+
}
|
|
61
|
+
.picker-wrapper {
|
|
62
|
+
padding: 20px;
|
|
63
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function loadBlocks(editor, { tabsBlock, typeTabs }) {
|
|
2
|
+
const { Blocks } = editor;
|
|
3
|
+
if (tabsBlock) {
|
|
4
|
+
const blockConfig = {
|
|
5
|
+
media: `
|
|
6
|
+
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
7
|
+
<path d="M22 9.3c0-.8-.5-1.3-1.3-1.3H3.4C2.5 8 2 8.5 2 9.3v7.4c0 .8.5 1.3 1.3 1.3h17.4c.8 0 1.3-.5 1.3-1.3V9.3zM21 17H3V9h18v8z" fill-rule="nonzero"/><rect x="3" y="5" width="4" height="2" rx=".5"/><rect x="8" y="5" width="4" height="2" rx=".5"/><rect x="13" y="5" width="4" height="2" rx=".5"/>
|
|
8
|
+
</svg>
|
|
9
|
+
`,
|
|
10
|
+
label: "Tabs",
|
|
11
|
+
content: { type: typeTabs },
|
|
12
|
+
...tabsBlock
|
|
13
|
+
};
|
|
14
|
+
Blocks.add(typeTabs, blockConfig);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
loadBlocks as default
|
|
19
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Component, Editor } from 'grapesjs';
|
|
2
|
+
import type { TabConfig } from '../types.js';
|
|
3
|
+
export interface TabComponent extends Component {
|
|
4
|
+
tabContent?: Component;
|
|
5
|
+
__initTab(index: number): void;
|
|
6
|
+
__onRemove(): void;
|
|
7
|
+
getTabContent(): Component | undefined;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: (editor: Editor, config: TabConfig) => void;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { resolveTemplate } from "../options.js";
|
|
2
|
+
var Tab_default = (editor, config) => {
|
|
3
|
+
const { Components } = editor;
|
|
4
|
+
const prevSelectorTab = "data-prev";
|
|
5
|
+
const getPrevCntId = (comp) => comp.getAttributes()[prevSelectorTab];
|
|
6
|
+
const defaultModel = editor.DomComponents.getType("default").model;
|
|
7
|
+
Components.addType(config.typeTab, {
|
|
8
|
+
model: {
|
|
9
|
+
defaults: {
|
|
10
|
+
name: "Tab",
|
|
11
|
+
tagName: "div",
|
|
12
|
+
draggable: `[data-gjs-type="${config.typeTabContainer}"]`,
|
|
13
|
+
droppable: false,
|
|
14
|
+
attributes: { role: "tab" },
|
|
15
|
+
classes: [config.classTab],
|
|
16
|
+
traits: [
|
|
17
|
+
{
|
|
18
|
+
type: "button",
|
|
19
|
+
label: false,
|
|
20
|
+
text: "Style Active",
|
|
21
|
+
full: true,
|
|
22
|
+
command: (editor2) => {
|
|
23
|
+
const sm = editor2.StyleManager;
|
|
24
|
+
sm.select(`.${config.classTab}.${config.classTabActive}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
...config.tabProps
|
|
29
|
+
},
|
|
30
|
+
init() {
|
|
31
|
+
this.on("removed", this.__onRemove);
|
|
32
|
+
},
|
|
33
|
+
__initTab(index) {
|
|
34
|
+
if (this.tabContent) return;
|
|
35
|
+
let content = this.getTabContent();
|
|
36
|
+
if (content && getPrevCntId(content)) {
|
|
37
|
+
const id = content.getId();
|
|
38
|
+
const tabId = this.getId();
|
|
39
|
+
content.addAttributes({ id, "aria-labelledby": tabId, hidden: true });
|
|
40
|
+
content.removeAttributes(prevSelectorTab);
|
|
41
|
+
this.addAttributes({ [config.selectorTab]: id, id: tabId });
|
|
42
|
+
}
|
|
43
|
+
if (!content) {
|
|
44
|
+
const tabs = this.getTabsType();
|
|
45
|
+
const cnts = tabs.getContentsType();
|
|
46
|
+
content = cnts.append({
|
|
47
|
+
type: config.typeTabContent,
|
|
48
|
+
components: resolveTemplate(config.templateTabContent, {
|
|
49
|
+
index
|
|
50
|
+
})
|
|
51
|
+
})[0];
|
|
52
|
+
const id = content.getId();
|
|
53
|
+
const tabId = this.getId();
|
|
54
|
+
content.addAttributes({ id, "aria-labelledby": tabId, hidden: true });
|
|
55
|
+
this.addAttributes({ [config.selectorTab]: id, id: tabId });
|
|
56
|
+
this.tabContent = content;
|
|
57
|
+
}
|
|
58
|
+
this.tabContent = content;
|
|
59
|
+
},
|
|
60
|
+
__onRemove() {
|
|
61
|
+
const content = this.getTabContent();
|
|
62
|
+
if (content) {
|
|
63
|
+
content.remove();
|
|
64
|
+
}
|
|
65
|
+
this.getTabsType().trigger("rerender");
|
|
66
|
+
},
|
|
67
|
+
getTabsType() {
|
|
68
|
+
return this.closestType(config.typeTabs);
|
|
69
|
+
},
|
|
70
|
+
getTabContent() {
|
|
71
|
+
const id = this.getAttributes()[config.selectorTab];
|
|
72
|
+
const tabs = this.getTabsType();
|
|
73
|
+
if (!tabs || !id) return;
|
|
74
|
+
const contents = tabs.findContents();
|
|
75
|
+
const content = contents.filter(
|
|
76
|
+
(c) => c.getId() === id || getPrevCntId(c) === id
|
|
77
|
+
)[0];
|
|
78
|
+
return content;
|
|
79
|
+
},
|
|
80
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
81
|
+
clone(opt = {}, ...args) {
|
|
82
|
+
const fromParent = opt._inner;
|
|
83
|
+
if (fromParent) {
|
|
84
|
+
const tabCont = this.getTabContent();
|
|
85
|
+
if (tabCont) {
|
|
86
|
+
tabCont.addAttributes({ [prevSelectorTab]: tabCont.getId() });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const cloned = defaultModel.prototype.clone.apply(this, [opt, ...args]);
|
|
90
|
+
if (!fromParent) {
|
|
91
|
+
cloned.addAttributes({ [config.selectorTab]: "" });
|
|
92
|
+
}
|
|
93
|
+
return cloned;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
export {
|
|
99
|
+
Tab_default as default
|
|
100
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const role = "tablist";
|
|
2
|
+
var TabContainer_default = (editor, config) => {
|
|
3
|
+
const { Components } = editor;
|
|
4
|
+
Components.addType(config.typeTabContainer, {
|
|
5
|
+
model: {
|
|
6
|
+
defaults: {
|
|
7
|
+
name: "Tab Container",
|
|
8
|
+
draggable: `[data-gjs-type="${config.typeTabs}"]`,
|
|
9
|
+
droppable: `[data-gjs-type="${config.typeTab}"]`,
|
|
10
|
+
copyable: false,
|
|
11
|
+
removable: false,
|
|
12
|
+
highlightable: false,
|
|
13
|
+
attributes: { role },
|
|
14
|
+
classes: config.classTabContainer,
|
|
15
|
+
...config.tabContainerProps
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
TabContainer_default as default,
|
|
22
|
+
role
|
|
23
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const role = "tabpanel";
|
|
2
|
+
var TabContent_default = (editor, config) => {
|
|
3
|
+
const { Components } = editor;
|
|
4
|
+
Components.addType(config.typeTabContent, {
|
|
5
|
+
model: {
|
|
6
|
+
defaults: {
|
|
7
|
+
name: "Tab Content",
|
|
8
|
+
draggable: false,
|
|
9
|
+
copyable: false,
|
|
10
|
+
removable: false,
|
|
11
|
+
highlightable: false,
|
|
12
|
+
attributes: { role },
|
|
13
|
+
classes: config.classTabContent,
|
|
14
|
+
traits: [],
|
|
15
|
+
...config.tabContentProps
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
TabContent_default as default,
|
|
22
|
+
role
|
|
23
|
+
};
|