@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
import '@studiocms/ui/css/colors.css';
|
|
3
3
|
import 'grapesjs/dist/css/grapes.min.css';
|
|
4
|
-
import '
|
|
4
|
+
import '../editorPlugins/rte/styles.css';
|
|
5
5
|
import '../styles/main.css';
|
|
6
6
|
import { importComponentsKeys } from 'studiocms/lib/renderer/runtime.js';
|
|
7
7
|
import type { PluginPageTypeEditorProps } from 'studiocms/types';
|
|
@@ -41,24 +41,19 @@ interface Props extends PluginPageTypeEditorProps {}
|
|
|
41
41
|
<script>
|
|
42
42
|
import { toast } from "@studiocms/ui/components/Toast/toast.js";
|
|
43
43
|
import grapesjs, { type Editor, usePlugin } from "grapesjs";
|
|
44
|
-
import "@studiocms/grapesjs-plugin";
|
|
45
|
-
import blocks from "grapesjs-blocks-basic";
|
|
46
|
-
import countdown from "grapesjs-component-countdown";
|
|
47
|
-
import exporter from "grapesjs-plugin-export";
|
|
48
|
-
import customCode from "grapesjs-custom-code";
|
|
49
|
-
import postcss from "grapesjs-parser-postcss";
|
|
50
|
-
import tooltip from "grapesjs-tooltip";
|
|
51
|
-
import tuiImage from "grapesjs-tui-image-editor";
|
|
52
|
-
import typed from "grapesjs-typed";
|
|
53
|
-
import styleBg from "grapesjs-style-bg";
|
|
54
|
-
import forms from "grapesjs-plugin-forms";
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
import rte from "grapesjs-rte-extensions";
|
|
57
|
-
// @ts-ignore
|
|
58
|
-
import tabs from "grapesjs-tabs";
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
import touch from "grapesjs-touch";
|
|
61
44
|
import { parse } from "../../utils.js";
|
|
45
|
+
import {
|
|
46
|
+
blocks,
|
|
47
|
+
customCode,
|
|
48
|
+
countdown,
|
|
49
|
+
forms,
|
|
50
|
+
rte,
|
|
51
|
+
tabs,
|
|
52
|
+
tooltip,
|
|
53
|
+
tuiImageEditor,
|
|
54
|
+
typed
|
|
55
|
+
} from '../editorPlugins/index.js';
|
|
56
|
+
import "@studiocms/grapesjs-plugin";
|
|
62
57
|
|
|
63
58
|
/**
|
|
64
59
|
* Represents an array of Astro component blocks, where each block contains metadata
|
|
@@ -199,21 +194,19 @@ interface Props extends PluginPageTypeEditorProps {}
|
|
|
199
194
|
panels: { defaults: [] },
|
|
200
195
|
plugins: [
|
|
201
196
|
usePlugin(getPlugin(componentKeys)),
|
|
202
|
-
usePlugin(
|
|
203
|
-
usePlugin(
|
|
204
|
-
|
|
197
|
+
usePlugin(inlineStorage),
|
|
198
|
+
usePlugin(blocks, {
|
|
199
|
+
flexGrid: true
|
|
205
200
|
}),
|
|
206
|
-
usePlugin(
|
|
207
|
-
|
|
208
|
-
category:
|
|
209
|
-
content: {
|
|
210
|
-
type: "typed",
|
|
211
|
-
"type-speed": 40,
|
|
212
|
-
strings: ["Text row one", "Text row two", "Text row three"],
|
|
213
|
-
},
|
|
201
|
+
usePlugin(tabs, {
|
|
202
|
+
tabsBlock: {
|
|
203
|
+
category: 'Extra'
|
|
214
204
|
},
|
|
215
205
|
}),
|
|
216
|
-
usePlugin(
|
|
206
|
+
usePlugin(countdown),
|
|
207
|
+
usePlugin(customCode),
|
|
208
|
+
usePlugin(tooltip),
|
|
209
|
+
usePlugin(tuiImageEditor, {
|
|
217
210
|
script: [
|
|
218
211
|
"https://uicdn.toast.com/tui.code-snippet/v1.5.2/tui-code-snippet.min.js",
|
|
219
212
|
"https://uicdn.toast.com/tui-color-picker/v2.2.7/tui-color-picker.min.js",
|
|
@@ -224,17 +217,10 @@ interface Props extends PluginPageTypeEditorProps {}
|
|
|
224
217
|
"https://uicdn.toast.com/tui-image-editor/v3.15.2/tui-image-editor.min.css",
|
|
225
218
|
],
|
|
226
219
|
}),
|
|
227
|
-
usePlugin(countdown),
|
|
228
|
-
usePlugin(exporter),
|
|
229
|
-
usePlugin(customCode),
|
|
230
|
-
usePlugin(postcss),
|
|
231
|
-
usePlugin(tooltip),
|
|
232
220
|
usePlugin(typed),
|
|
233
|
-
usePlugin(styleBg),
|
|
234
|
-
usePlugin(inlineStorage),
|
|
235
221
|
usePlugin(forms),
|
|
236
222
|
usePlugin(rte),
|
|
237
|
-
|
|
223
|
+
'@studiocms/grapesjs-plugin',
|
|
238
224
|
],
|
|
239
225
|
blockManager: {
|
|
240
226
|
blocks: convertComponentBlocks(rawBlocks),
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
function blocks_default(editor, opts) {
|
|
2
|
+
const bm = editor.BlockManager;
|
|
3
|
+
const { category, blocks, stylePrefix, flexGrid, rowHeight, addBasicStyle } = opts;
|
|
4
|
+
const clsRow = `${stylePrefix}row`;
|
|
5
|
+
const clsCell = `${stylePrefix}cell`;
|
|
6
|
+
const styleRow = flexGrid ? `
|
|
7
|
+
.${clsRow} {
|
|
8
|
+
display: flex;
|
|
9
|
+
justify-content: flex-start;
|
|
10
|
+
align-items: stretch;
|
|
11
|
+
flex-wrap: nowrap;
|
|
12
|
+
padding: 10px;
|
|
13
|
+
}
|
|
14
|
+
@media (max-width: 768px) {
|
|
15
|
+
.${clsRow} {
|
|
16
|
+
flex-wrap: wrap;
|
|
17
|
+
}
|
|
18
|
+
}` : `
|
|
19
|
+
.${clsRow} {
|
|
20
|
+
display: table;
|
|
21
|
+
padding: 10px;
|
|
22
|
+
width: 100%;
|
|
23
|
+
}
|
|
24
|
+
@media (max-width: 768px) {
|
|
25
|
+
.${stylePrefix}cell, .${stylePrefix}cell30, .${stylePrefix}cell70 {
|
|
26
|
+
width: 100%;
|
|
27
|
+
display: block;
|
|
28
|
+
}
|
|
29
|
+
}`;
|
|
30
|
+
const styleClm = flexGrid ? `
|
|
31
|
+
.${clsCell} {
|
|
32
|
+
min-height: ${rowHeight}px;
|
|
33
|
+
flex-grow: 1;
|
|
34
|
+
flex-basis: 100%;
|
|
35
|
+
}` : `
|
|
36
|
+
.${clsCell} {
|
|
37
|
+
width: 8%;
|
|
38
|
+
display: table-cell;
|
|
39
|
+
height: ${rowHeight}px;
|
|
40
|
+
}`;
|
|
41
|
+
const styleClm30 = `
|
|
42
|
+
.${stylePrefix}cell30 {
|
|
43
|
+
width: 30%;
|
|
44
|
+
}`;
|
|
45
|
+
const styleClm70 = `
|
|
46
|
+
.${stylePrefix}cell70 {
|
|
47
|
+
width: 70%;
|
|
48
|
+
}`;
|
|
49
|
+
const step = 0.2;
|
|
50
|
+
const minDim = 1;
|
|
51
|
+
const currentUnit = 1;
|
|
52
|
+
const resizerBtm = {
|
|
53
|
+
tl: 0,
|
|
54
|
+
tc: 0,
|
|
55
|
+
tr: 0,
|
|
56
|
+
cl: 0,
|
|
57
|
+
cr: 0,
|
|
58
|
+
bl: 0,
|
|
59
|
+
br: 0,
|
|
60
|
+
minDim
|
|
61
|
+
};
|
|
62
|
+
const resizerRight = {
|
|
63
|
+
...resizerBtm,
|
|
64
|
+
cr: 1,
|
|
65
|
+
bc: 0,
|
|
66
|
+
currentUnit,
|
|
67
|
+
minDim,
|
|
68
|
+
step
|
|
69
|
+
};
|
|
70
|
+
if (flexGrid) {
|
|
71
|
+
resizerRight.keyWidth = "flex-basis";
|
|
72
|
+
}
|
|
73
|
+
const rowAttr = {
|
|
74
|
+
class: clsRow,
|
|
75
|
+
"data-gjs-droppable": `.${clsCell}`,
|
|
76
|
+
"data-gjs-resizable": resizerBtm,
|
|
77
|
+
"data-gjs-name": "Row"
|
|
78
|
+
};
|
|
79
|
+
const colAttr = {
|
|
80
|
+
class: clsCell,
|
|
81
|
+
"data-gjs-draggable": `.${clsRow}`,
|
|
82
|
+
"data-gjs-resizable": resizerRight,
|
|
83
|
+
"data-gjs-name": "Cell"
|
|
84
|
+
};
|
|
85
|
+
if (flexGrid) {
|
|
86
|
+
colAttr["data-gjs-unstylable"] = ["width"];
|
|
87
|
+
colAttr["data-gjs-stylable-require"] = ["flex-basis"];
|
|
88
|
+
}
|
|
89
|
+
const privateCls = [`.${clsRow}`, `.${clsCell}`];
|
|
90
|
+
editor.on(
|
|
91
|
+
"selector:add",
|
|
92
|
+
(selector) => privateCls.indexOf(selector.getFullName()) >= 0 && selector.set("private", 1)
|
|
93
|
+
);
|
|
94
|
+
const attrsToString = (attrs) => {
|
|
95
|
+
const result = [];
|
|
96
|
+
for (const key in attrs) {
|
|
97
|
+
let value = attrs[key];
|
|
98
|
+
const toParse = Array.isArray(value) || value instanceof Object;
|
|
99
|
+
value = toParse ? JSON.stringify(value) : value;
|
|
100
|
+
result.push(`${key}=${toParse ? `'${value}'` : `'${value}'`}`);
|
|
101
|
+
}
|
|
102
|
+
return result.length ? ` ${result.join(" ")}` : "";
|
|
103
|
+
};
|
|
104
|
+
const toAdd = (name) => blocks.indexOf(name) >= 0;
|
|
105
|
+
const attrsRow = attrsToString(rowAttr);
|
|
106
|
+
const attrsCell = attrsToString(colAttr);
|
|
107
|
+
const commonBlockProps = {
|
|
108
|
+
category,
|
|
109
|
+
select: true
|
|
110
|
+
};
|
|
111
|
+
toAdd("column1") && bm.add("column1", {
|
|
112
|
+
...commonBlockProps,
|
|
113
|
+
label: opts.labelColumn1,
|
|
114
|
+
media: `<svg viewBox="0 0 24 24">
|
|
115
|
+
<path fill="currentColor" d="M2 20h20V4H2v16Zm-1 0V4a1 1 0 0 1 1-1h20a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1Z"/>
|
|
116
|
+
</svg>`,
|
|
117
|
+
content: `<div ${attrsRow}>
|
|
118
|
+
<div ${attrsCell}></div>
|
|
119
|
+
</div>
|
|
120
|
+
${addBasicStyle ? `<style>
|
|
121
|
+
${styleRow}
|
|
122
|
+
${styleClm}
|
|
123
|
+
</style>` : ""}`
|
|
124
|
+
});
|
|
125
|
+
toAdd("column2") && bm.add("column2", {
|
|
126
|
+
...commonBlockProps,
|
|
127
|
+
label: opts.labelColumn2,
|
|
128
|
+
media: `<svg viewBox="0 0 23 24">
|
|
129
|
+
<path fill="currentColor" d="M2 20h8V4H2v16Zm-1 0V4a1 1 0 0 1 1-1h8a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1ZM13 20h8V4h-8v16Zm-1 0V4a1 1 0 0 1 1-1h8a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-8a1 1 0 0 1-1-1Z"/>
|
|
130
|
+
</svg>`,
|
|
131
|
+
content: `<div ${attrsRow}>
|
|
132
|
+
<div ${attrsCell}></div>
|
|
133
|
+
<div ${attrsCell}></div>
|
|
134
|
+
</div>
|
|
135
|
+
${addBasicStyle ? `<style>
|
|
136
|
+
${styleRow}
|
|
137
|
+
${styleClm}
|
|
138
|
+
</style>` : ""}`
|
|
139
|
+
});
|
|
140
|
+
toAdd("column3") && bm.add("column3", {
|
|
141
|
+
...commonBlockProps,
|
|
142
|
+
label: opts.labelColumn3,
|
|
143
|
+
media: `<svg viewBox="0 0 23 24">
|
|
144
|
+
<path fill="currentColor" d="M2 20h4V4H2v16Zm-1 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1ZM17 20h4V4h-4v16Zm-1 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1ZM9.5 20h4V4h-4v16Zm-1 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1Z"/>
|
|
145
|
+
</svg>`,
|
|
146
|
+
content: `<div ${attrsRow}>
|
|
147
|
+
<div ${attrsCell}></div>
|
|
148
|
+
<div ${attrsCell}></div>
|
|
149
|
+
<div ${attrsCell}></div>
|
|
150
|
+
</div>
|
|
151
|
+
${addBasicStyle ? `<style>
|
|
152
|
+
${styleRow}
|
|
153
|
+
${styleClm}
|
|
154
|
+
</style>` : ""}`
|
|
155
|
+
});
|
|
156
|
+
toAdd("column3-7") && bm.add("column3-7", {
|
|
157
|
+
...commonBlockProps,
|
|
158
|
+
label: opts.labelColumn37,
|
|
159
|
+
media: `<svg viewBox="0 0 24 24">
|
|
160
|
+
<path fill="currentColor" d="M2 20h5V4H2v16Zm-1 0V4a1 1 0 0 1 1-1h5a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1ZM10 20h12V4H10v16Zm-1 0V4a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H10a1 1 0 0 1-1-1Z"/>
|
|
161
|
+
</svg>`,
|
|
162
|
+
content: `<div ${attrsRow}>
|
|
163
|
+
<div ${attrsCell} style='${flexGrid ? "flex-basis" : "width"}: 30%;'></div>
|
|
164
|
+
<div ${attrsCell} style='${flexGrid ? "flex-basis" : "width"}: 70%;'></div>
|
|
165
|
+
</div>
|
|
166
|
+
${addBasicStyle ? `<style>
|
|
167
|
+
${styleRow}
|
|
168
|
+
${styleClm}
|
|
169
|
+
${styleClm30}
|
|
170
|
+
${styleClm70}
|
|
171
|
+
</style>` : ""}`
|
|
172
|
+
});
|
|
173
|
+
toAdd("text") && bm.add("text", {
|
|
174
|
+
...commonBlockProps,
|
|
175
|
+
activate: true,
|
|
176
|
+
label: opts.labelText,
|
|
177
|
+
media: `<svg viewBox="0 0 24 24">
|
|
178
|
+
<path fill="currentColor" d="M18.5,4L19.66,8.35L18.7,8.61C18.25,7.74 17.79,6.87 17.26,6.43C16.73,6 16.11,6 15.5,6H13V16.5C13,17 13,17.5 13.33,17.75C13.67,18 14.33,18 15,18V19H9V18C9.67,18 10.33,18 10.67,17.75C11,17.5 11,17 11,16.5V6H8.5C7.89,6 7.27,6 6.74,6.43C6.21,6.87 5.75,7.74 5.3,8.61L4.34,8.35L5.5,4H18.5Z" />
|
|
179
|
+
</svg>`,
|
|
180
|
+
content: {
|
|
181
|
+
type: "text",
|
|
182
|
+
content: "Insert your text here",
|
|
183
|
+
style: { padding: "10px" }
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
toAdd("link") && bm.add("link", {
|
|
187
|
+
...commonBlockProps,
|
|
188
|
+
label: opts.labelLink,
|
|
189
|
+
media: `<svg viewBox="0 0 24 24">
|
|
190
|
+
<path fill="currentColor" d="M3.9,12C3.9,10.29 5.29,8.9 7,8.9H11V7H7A5,5 0 0,0 2,12A5,5 0 0,0 7,17H11V15.1H7C5.29,15.1 3.9,13.71 3.9,12M8,13H16V11H8V13M17,7H13V8.9H17C18.71,8.9 20.1,10.29 20.1,12C20.1,13.71 18.71,15.1 17,15.1H13V17H17A5,5 0 0,0 22,12A5,5 0 0,0 17,7Z" />
|
|
191
|
+
</svg>`,
|
|
192
|
+
content: {
|
|
193
|
+
type: "link",
|
|
194
|
+
content: "Link",
|
|
195
|
+
style: { color: "#d983a6" }
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
toAdd("image") && bm.add("image", {
|
|
199
|
+
...commonBlockProps,
|
|
200
|
+
activate: true,
|
|
201
|
+
label: opts.labelImage,
|
|
202
|
+
media: `<svg viewBox="0 0 24 24">
|
|
203
|
+
<path fill="currentColor" d="M21,3H3C2,3 1,4 1,5V19A2,2 0 0,0 3,21H21C22,21 23,20 23,19V5C23,4 22,3 21,3M5,17L8.5,12.5L11,15.5L14.5,11L19,17H5Z" />
|
|
204
|
+
</svg>`,
|
|
205
|
+
content: {
|
|
206
|
+
style: { color: "black" },
|
|
207
|
+
type: "image"
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
toAdd("video") && bm.add("video", {
|
|
211
|
+
...commonBlockProps,
|
|
212
|
+
label: opts.labelVideo,
|
|
213
|
+
media: `<svg viewBox="0 0 24 24">
|
|
214
|
+
<path fill="currentColor" d="M10,15L15.19,12L10,9V15M21.56,7.17C21.69,7.64 21.78,8.27 21.84,9.07C21.91,9.87 21.94,10.56 21.94,11.16L22,12C22,14.19 21.84,15.8 21.56,16.83C21.31,17.73 20.73,18.31 19.83,18.56C19.36,18.69 18.5,18.78 17.18,18.84C15.88,18.91 14.69,18.94 13.59,18.94L12,19C7.81,19 5.2,18.84 4.17,18.56C3.27,18.31 2.69,17.73 2.44,16.83C2.31,16.36 2.22,15.73 2.16,14.93C2.09,14.13 2.06,13.44 2.06,12.84L2,12C2,9.81 2.16,8.2 2.44,7.17C2.69,6.27 3.27,5.69 4.17,5.44C4.64,5.31 5.5,5.22 6.82,5.16C8.12,5.09 9.31,5.06 10.41,5.06L12,5C16.19,5 18.8,5.16 19.83,5.44C20.73,5.69 21.31,6.27 21.56,7.17Z" />
|
|
215
|
+
</svg>`,
|
|
216
|
+
content: {
|
|
217
|
+
type: "video",
|
|
218
|
+
src: "img/video2.webm",
|
|
219
|
+
style: {
|
|
220
|
+
height: "350px",
|
|
221
|
+
width: "615px"
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
toAdd("map") && bm.add("map", {
|
|
226
|
+
...commonBlockProps,
|
|
227
|
+
label: opts.labelMap,
|
|
228
|
+
media: `<svg viewBox="0 0 24 24">
|
|
229
|
+
<path fill="currentColor" d="M20.5,3L20.34,3.03L15,5.1L9,3L3.36,4.9C3.15,4.97 3,5.15 3,5.38V20.5A0.5,0.5 0 0,0 3.5,21L3.66,20.97L9,18.9L15,21L20.64,19.1C20.85,19.03 21,18.85 21,18.62V3.5A0.5,0.5 0 0,0 20.5,3M10,5.47L14,6.87V18.53L10,17.13V5.47M5,6.46L8,5.45V17.15L5,18.31V6.46M19,17.54L16,18.55V6.86L19,5.7V17.54Z" />
|
|
230
|
+
</svg>`,
|
|
231
|
+
content: {
|
|
232
|
+
type: "map",
|
|
233
|
+
style: { height: "350px" }
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
export {
|
|
238
|
+
blocks_default as default
|
|
239
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Plugin } from 'grapesjs';
|
|
2
|
+
export type PluginOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Which blocks to add.
|
|
5
|
+
* @default ['column1', 'column2', 'column3', 'column3-7', 'text', 'link', 'image', 'video', 'map']
|
|
6
|
+
*/
|
|
7
|
+
blocks?: string[];
|
|
8
|
+
/**
|
|
9
|
+
* Make use of flexbox for the grid
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
flexGrid?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Classes prefix
|
|
15
|
+
* @default 'gjs-'
|
|
16
|
+
*/
|
|
17
|
+
stylePrefix?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Use basic CSS for blocks
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
addBasicStyle?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Blocks category name
|
|
25
|
+
* @default 'Basic'
|
|
26
|
+
*/
|
|
27
|
+
category?: string;
|
|
28
|
+
/**
|
|
29
|
+
* 1 Column label
|
|
30
|
+
* @default '1 Column'
|
|
31
|
+
*/
|
|
32
|
+
labelColumn1?: string;
|
|
33
|
+
/**
|
|
34
|
+
* 2 Columns label
|
|
35
|
+
* @default '2 Columns'
|
|
36
|
+
*/
|
|
37
|
+
labelColumn2?: string;
|
|
38
|
+
/**
|
|
39
|
+
* 3 Columns label
|
|
40
|
+
* @default '3 Columns'
|
|
41
|
+
*/
|
|
42
|
+
labelColumn3?: string;
|
|
43
|
+
/**
|
|
44
|
+
* 3/7 Columns label
|
|
45
|
+
* @default '2 Columns 3/7'
|
|
46
|
+
*/
|
|
47
|
+
labelColumn37?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Text label
|
|
50
|
+
* @default 'Text'
|
|
51
|
+
*/
|
|
52
|
+
labelText?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Link label
|
|
55
|
+
* @default 'Link'
|
|
56
|
+
*/
|
|
57
|
+
labelLink?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Image label
|
|
60
|
+
* @default 'Image'
|
|
61
|
+
*/
|
|
62
|
+
labelImage?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Video label
|
|
65
|
+
* @default 'Video'
|
|
66
|
+
*/
|
|
67
|
+
labelVideo?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Map label
|
|
70
|
+
* @default 'Map'
|
|
71
|
+
*/
|
|
72
|
+
labelMap?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Initial row height
|
|
75
|
+
* @default 75
|
|
76
|
+
*/
|
|
77
|
+
rowHeight?: number;
|
|
78
|
+
};
|
|
79
|
+
declare const plugin: Plugin<PluginOptions>;
|
|
80
|
+
export default plugin;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import loadBlocks from "./blocks.js";
|
|
2
|
+
const plugin = (editor, opts = {}) => {
|
|
3
|
+
const config = {
|
|
4
|
+
blocks: ["column1", "column2", "column3", "column3-7", "text", "link", "image", "video", "map"],
|
|
5
|
+
flexGrid: false,
|
|
6
|
+
stylePrefix: "gjs-",
|
|
7
|
+
addBasicStyle: true,
|
|
8
|
+
category: "Basic",
|
|
9
|
+
labelColumn1: "1 Column",
|
|
10
|
+
labelColumn2: "2 Columns",
|
|
11
|
+
labelColumn3: "3 Columns",
|
|
12
|
+
labelColumn37: "2 Columns 3/7",
|
|
13
|
+
labelText: "Text",
|
|
14
|
+
labelLink: "Link",
|
|
15
|
+
labelImage: "Image",
|
|
16
|
+
labelVideo: "Video",
|
|
17
|
+
labelMap: "Map",
|
|
18
|
+
rowHeight: 75,
|
|
19
|
+
...opts
|
|
20
|
+
};
|
|
21
|
+
loadBlocks(editor, config);
|
|
22
|
+
};
|
|
23
|
+
var blocks_default = plugin;
|
|
24
|
+
export {
|
|
25
|
+
blocks_default as default
|
|
26
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { typeCustomCode } from "./utils.js";
|
|
2
|
+
var blocks_default = (editor, { blockCustomCode } = {}) => {
|
|
3
|
+
const { Blocks } = editor;
|
|
4
|
+
blockCustomCode && Blocks.add(typeCustomCode, {
|
|
5
|
+
label: "Custom Code",
|
|
6
|
+
media: `
|
|
7
|
+
<svg viewBox="0 0 24 24">
|
|
8
|
+
<path d="M14.6 16.6l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4m-5.2 0L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4z"></path>
|
|
9
|
+
</svg>
|
|
10
|
+
`,
|
|
11
|
+
category: "Extra",
|
|
12
|
+
activate: true,
|
|
13
|
+
select: true,
|
|
14
|
+
content: { type: typeCustomCode },
|
|
15
|
+
...blockCustomCode
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
blocks_default as default
|
|
20
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { commandNameCustomCode, keyCustomCode } from "./utils.js";
|
|
2
|
+
var commands_default = (editor, opts = {}) => {
|
|
3
|
+
const { modalTitle, codeViewOptions, commandCustomCode } = opts;
|
|
4
|
+
const appendToContent = (target, content) => {
|
|
5
|
+
if (content instanceof HTMLElement) {
|
|
6
|
+
target.appendChild(content);
|
|
7
|
+
} else if (content) {
|
|
8
|
+
target.insertAdjacentHTML("beforeend", content);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
editor.Commands.add(commandNameCustomCode, {
|
|
12
|
+
keyCustomCode,
|
|
13
|
+
target: null,
|
|
14
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
15
|
+
codeViewer: null,
|
|
16
|
+
run(editor2, s, opts2 = {}) {
|
|
17
|
+
const target = opts2.target || editor2.getSelected();
|
|
18
|
+
this.target = target;
|
|
19
|
+
if (target?.get("editable")) {
|
|
20
|
+
this.showCustomCode(target, opts2);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
stop(editor2) {
|
|
24
|
+
editor2.Modal.close();
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* Method which tells how to show the custom code
|
|
28
|
+
* @param {Component} target
|
|
29
|
+
*/
|
|
30
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
31
|
+
showCustomCode(target, options) {
|
|
32
|
+
const title = options.title || modalTitle;
|
|
33
|
+
const code = target.get(keyCustomCode) || "";
|
|
34
|
+
const content = this.getContent();
|
|
35
|
+
editor.Modal.open({ title, content }).onceClose(
|
|
36
|
+
() => editor.stopCommand(commandNameCustomCode)
|
|
37
|
+
);
|
|
38
|
+
this.getCodeViewer().setContent(code);
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* Custom pre-content. Can be a simple string or an HTMLElement
|
|
42
|
+
*/
|
|
43
|
+
getPreContent() {
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Custom post-content. Can be a simple string or an HTMLElement
|
|
47
|
+
*/
|
|
48
|
+
getPostContent() {
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* Get all the content for the custom code
|
|
52
|
+
* @return {HTMLElement}
|
|
53
|
+
*/
|
|
54
|
+
getContent() {
|
|
55
|
+
const codeViewer = this.getCodeViewer();
|
|
56
|
+
const content = document.createElement("div");
|
|
57
|
+
const pfx = editor.getConfig("stylePrefix");
|
|
58
|
+
content.className = `${pfx}custom-code`;
|
|
59
|
+
appendToContent(content, this.getPreContent());
|
|
60
|
+
content.appendChild(codeViewer.getElement());
|
|
61
|
+
appendToContent(content, this.getPostContent());
|
|
62
|
+
appendToContent(content, this.getContentActions());
|
|
63
|
+
codeViewer.refresh();
|
|
64
|
+
setTimeout(() => codeViewer.focus(), 0);
|
|
65
|
+
return content;
|
|
66
|
+
},
|
|
67
|
+
/**
|
|
68
|
+
* Get the actions content. Can be a simple string or an HTMLElement
|
|
69
|
+
* @return {HTMLElement|String}
|
|
70
|
+
*/
|
|
71
|
+
getContentActions() {
|
|
72
|
+
const btn = document.createElement("button");
|
|
73
|
+
btn.setAttribute("type", "button");
|
|
74
|
+
const pfx = editor.getConfig("stylePrefix");
|
|
75
|
+
btn.innerHTML = opts.buttonLabel;
|
|
76
|
+
btn.className = `${pfx}btn-prim ${pfx}btn-import__custom-code`;
|
|
77
|
+
btn.onclick = () => this.handleSave();
|
|
78
|
+
return btn;
|
|
79
|
+
},
|
|
80
|
+
/**
|
|
81
|
+
* Handle the main save task
|
|
82
|
+
*/
|
|
83
|
+
handleSave() {
|
|
84
|
+
const { target } = this;
|
|
85
|
+
const code = this.getCodeViewer().getContent();
|
|
86
|
+
target?.set(keyCustomCode, code);
|
|
87
|
+
editor.Modal.close();
|
|
88
|
+
},
|
|
89
|
+
/**
|
|
90
|
+
* Return the code viewer instance
|
|
91
|
+
* @return {CodeViewer}
|
|
92
|
+
*/
|
|
93
|
+
getCodeViewer() {
|
|
94
|
+
if (!this.codeViewer) {
|
|
95
|
+
this.codeViewer = editor.CodeManager.createViewer({
|
|
96
|
+
codeName: "htmlmixed",
|
|
97
|
+
theme: "hopscotch",
|
|
98
|
+
readOnly: 0,
|
|
99
|
+
...codeViewOptions
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return this.codeViewer;
|
|
103
|
+
},
|
|
104
|
+
...commandCustomCode
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
export {
|
|
108
|
+
commands_default as default
|
|
109
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { commandNameCustomCode, keyCustomCode, typeCustomCode } from "./utils.js";
|
|
2
|
+
var components_default = (editor, opts = {}) => {
|
|
3
|
+
const { Components } = editor;
|
|
4
|
+
const { toolbarBtnCustomCode } = opts;
|
|
5
|
+
let timedInterval;
|
|
6
|
+
Components.addType("script", {
|
|
7
|
+
view: {
|
|
8
|
+
onRender() {
|
|
9
|
+
const { model, el } = this;
|
|
10
|
+
const isCC = model.closestType(typeCustomCode);
|
|
11
|
+
isCC && (el.innerHTML = "");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
Components.addType(typeCustomCode, {
|
|
16
|
+
model: {
|
|
17
|
+
defaults: {
|
|
18
|
+
name: "Custom Code",
|
|
19
|
+
editable: true,
|
|
20
|
+
components: {
|
|
21
|
+
tagName: "span",
|
|
22
|
+
components: { type: "textnode", content: "Insert here your custom code" }
|
|
23
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
24
|
+
},
|
|
25
|
+
...opts.propsCustomCode
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
* Initilize the component
|
|
29
|
+
*/
|
|
30
|
+
init() {
|
|
31
|
+
this.on(`change:${keyCustomCode}`, this.onCustomCodeChange);
|
|
32
|
+
const initialCode = this.get(keyCustomCode);
|
|
33
|
+
!this.components().length && this.components(initialCode);
|
|
34
|
+
const toolbar = this.get("toolbar");
|
|
35
|
+
const id = "custom-code";
|
|
36
|
+
if (toolbarBtnCustomCode && !toolbar.filter((tlb) => tlb.id === id).length) {
|
|
37
|
+
toolbar.unshift({
|
|
38
|
+
id,
|
|
39
|
+
command: commandNameCustomCode,
|
|
40
|
+
label: `<svg viewBox="0 0 24 24">
|
|
41
|
+
<path d="M14.6 16.6l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4m-5.2 0L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4z"></path>
|
|
42
|
+
</svg>`,
|
|
43
|
+
...toolbarBtnCustomCode
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
/**
|
|
48
|
+
* Callback to launch on keyCustomCode change
|
|
49
|
+
*/
|
|
50
|
+
onCustomCodeChange() {
|
|
51
|
+
this.components(this.get(keyCustomCode));
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
view: {
|
|
55
|
+
events: {
|
|
56
|
+
dblclick: "onActive"
|
|
57
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
58
|
+
},
|
|
59
|
+
init() {
|
|
60
|
+
this.listenTo(this.model.components(), "add remove reset", this.onComponentsChange);
|
|
61
|
+
this.onComponentsChange();
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* Things to do once inner components of custom code are changed
|
|
65
|
+
*/
|
|
66
|
+
onComponentsChange() {
|
|
67
|
+
timedInterval && clearInterval(timedInterval);
|
|
68
|
+
timedInterval = setTimeout(() => {
|
|
69
|
+
const { model, el } = this;
|
|
70
|
+
const content = model.get(keyCustomCode) || "";
|
|
71
|
+
let droppable = true;
|
|
72
|
+
if (content.indexOf("<script") >= 0 && opts.placeholderScript) {
|
|
73
|
+
el.innerHTML = opts.placeholderScript;
|
|
74
|
+
droppable = false;
|
|
75
|
+
}
|
|
76
|
+
model.set({ droppable });
|
|
77
|
+
}, 0);
|
|
78
|
+
},
|
|
79
|
+
onActive() {
|
|
80
|
+
const { model, em } = this;
|
|
81
|
+
em.get("Commands").run(commandNameCustomCode, { target: model });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
export {
|
|
87
|
+
components_default as default
|
|
88
|
+
};
|