@studiocms/wysiwyg 0.1.0-beta.24

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.
Files changed (104) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +20 -0
  3. package/dist/common/componentRegistry.d.ts +31 -0
  4. package/dist/common/componentRegistry.js +59 -0
  5. package/dist/common/editor-settings.d.ts +23 -0
  6. package/dist/common/editor-settings.js +357 -0
  7. package/dist/common/editor-utils.d.ts +165 -0
  8. package/dist/common/editor-utils.js +217 -0
  9. package/dist/common/grapesBlocks/blocks/basics.d.ts +4 -0
  10. package/dist/common/grapesBlocks/blocks/basics.js +279 -0
  11. package/dist/common/grapesBlocks/blocks/extras.d.ts +4 -0
  12. package/dist/common/grapesBlocks/blocks/extras.js +63 -0
  13. package/dist/common/grapesBlocks/blocks/forms.d.ts +4 -0
  14. package/dist/common/grapesBlocks/blocks/forms.js +94 -0
  15. package/dist/common/grapesBlocks/blocks/index.d.ts +5 -0
  16. package/dist/common/grapesBlocks/blocks/index.js +23 -0
  17. package/dist/common/grapesBlocks/blocks/tabs.d.ts +4 -0
  18. package/dist/common/grapesBlocks/blocks/tabs.js +20 -0
  19. package/dist/common/grapesBlocks/commands/clear.d.ts +4 -0
  20. package/dist/common/grapesBlocks/commands/clear.js +21 -0
  21. package/dist/common/grapesBlocks/commands/customCodeCommands.d.ts +4 -0
  22. package/dist/common/grapesBlocks/commands/customCodeCommands.js +111 -0
  23. package/dist/common/grapesBlocks/commands/deviceCommands.d.ts +3 -0
  24. package/dist/common/grapesBlocks/commands/deviceCommands.js +23 -0
  25. package/dist/common/grapesBlocks/commands/index.d.ts +5 -0
  26. package/dist/common/grapesBlocks/commands/index.js +40 -0
  27. package/dist/common/grapesBlocks/commands/openImport.d.ts +4 -0
  28. package/dist/common/grapesBlocks/commands/openImport.js +71 -0
  29. package/dist/common/grapesBlocks/components/countdown.d.ts +12 -0
  30. package/dist/common/grapesBlocks/components/countdown.js +148 -0
  31. package/dist/common/grapesBlocks/components/customCode.d.ts +4 -0
  32. package/dist/common/grapesBlocks/components/customCode.js +89 -0
  33. package/dist/common/grapesBlocks/components/forms.d.ts +3 -0
  34. package/dist/common/grapesBlocks/components/forms.js +278 -0
  35. package/dist/common/grapesBlocks/components/index.d.ts +5 -0
  36. package/dist/common/grapesBlocks/components/index.js +23 -0
  37. package/dist/common/grapesBlocks/components/tabLoader.d.ts +4 -0
  38. package/dist/common/grapesBlocks/components/tabLoader.js +29 -0
  39. package/dist/common/grapesBlocks/components/tabs/Tab.d.ts +10 -0
  40. package/dist/common/grapesBlocks/components/tabs/Tab.js +100 -0
  41. package/dist/common/grapesBlocks/components/tabs/TabContainer.d.ts +5 -0
  42. package/dist/common/grapesBlocks/components/tabs/TabContainer.js +23 -0
  43. package/dist/common/grapesBlocks/components/tabs/TabContent.d.ts +5 -0
  44. package/dist/common/grapesBlocks/components/tabs/TabContent.js +23 -0
  45. package/dist/common/grapesBlocks/components/tabs/TabContents.d.ts +4 -0
  46. package/dist/common/grapesBlocks/components/tabs/TabContents.js +19 -0
  47. package/dist/common/grapesBlocks/components/tabs/Tabs.d.ts +4 -0
  48. package/dist/common/grapesBlocks/components/tabs/Tabs.js +169 -0
  49. package/dist/common/grapesBlocks/components/tooltip.d.ts +4 -0
  50. package/dist/common/grapesBlocks/components/tooltip.js +246 -0
  51. package/dist/common/grapesBlocks/components/typed.d.ts +9 -0
  52. package/dist/common/grapesBlocks/components/typed.js +109 -0
  53. package/dist/common/grapesBlocks/consts.d.ts +25 -0
  54. package/dist/common/grapesBlocks/consts.js +245 -0
  55. package/dist/common/grapesBlocks/i18n/index.d.ts +3 -0
  56. package/dist/common/grapesBlocks/i18n/index.js +19 -0
  57. package/dist/common/grapesBlocks/index.d.ts +4 -0
  58. package/dist/common/grapesBlocks/index.js +27 -0
  59. package/dist/common/grapesBlocks/panels/index.d.ts +4 -0
  60. package/dist/common/grapesBlocks/panels/index.js +171 -0
  61. package/dist/common/grapesBlocks/rte/colorPicker.d.ts +104 -0
  62. package/dist/common/grapesBlocks/rte/colorPicker.js +199 -0
  63. package/dist/common/grapesBlocks/rte/index.d.ts +48 -0
  64. package/dist/common/grapesBlocks/rte/index.js +375 -0
  65. package/dist/common/grapesBlocks/selectors/index.d.ts +4 -0
  66. package/dist/common/grapesBlocks/selectors/index.js +9 -0
  67. package/dist/common/grapesBlocks/selectors/tooltip.d.ts +4 -0
  68. package/dist/common/grapesBlocks/selectors/tooltip.js +15 -0
  69. package/dist/common/grapesBlocks/traits/formTraits.d.ts +3 -0
  70. package/dist/common/grapesBlocks/traits/formTraits.js +51 -0
  71. package/dist/common/grapesBlocks/traits/index.d.ts +4 -0
  72. package/dist/common/grapesBlocks/traits/index.js +15 -0
  73. package/dist/common/grapesBlocks/traits/typedTraits.d.ts +3 -0
  74. package/dist/common/grapesBlocks/traits/typedTraits.js +24 -0
  75. package/dist/common/grapesBlocks/tuiImageEditor/index.d.ts +86 -0
  76. package/dist/common/grapesBlocks/tuiImageEditor/index.js +203 -0
  77. package/dist/common/grapesBlocks/types.d.ts +446 -0
  78. package/dist/common/grapesBlocks/types.js +0 -0
  79. package/dist/components/Editor.astro +147 -0
  80. package/dist/components/Render.astro +24 -0
  81. package/dist/consts.d.ts +31 -0
  82. package/dist/consts.js +15 -0
  83. package/dist/index.d.ts +29 -0
  84. package/dist/index.js +65 -0
  85. package/dist/lib/db.d.ts +104 -0
  86. package/dist/lib/db.js +50 -0
  87. package/dist/lib/prerender.d.ts +10 -0
  88. package/dist/lib/prerender.js +22 -0
  89. package/dist/lib/shared.d.ts +14 -0
  90. package/dist/lib/shared.js +7 -0
  91. package/dist/lib/utils.d.ts +16 -0
  92. package/dist/lib/utils.js +10 -0
  93. package/dist/routes/grapes.css.d.ts +7 -0
  94. package/dist/routes/grapes.css.js +13 -0
  95. package/dist/routes/partial.astro +44 -0
  96. package/dist/routes/store.d.ts +32 -0
  97. package/dist/routes/store.js +100 -0
  98. package/dist/schema.d.ts +60 -0
  99. package/dist/schema.js +24 -0
  100. package/dist/styles/editor.css +150 -0
  101. package/dist/styles/grapes.css +71 -0
  102. package/dist/types.d.ts +66 -0
  103. package/dist/types.js +9 -0
  104. package/package.json +78 -0
@@ -0,0 +1,51 @@
1
+ import { typeOption } from "../consts.js";
2
+ import { AddTrait } from "./index.js";
3
+ var formTraits_default = (editor) => {
4
+ const addTrait = AddTrait(editor);
5
+ addTrait("select-options", {
6
+ events: {
7
+ keyup: "onChange"
8
+ },
9
+ onValueChange() {
10
+ const { model, target } = this;
11
+ const optionsStr = model.get("value").trim();
12
+ const options = optionsStr.split("\n");
13
+ const optComps = [];
14
+ for (let i = 0; i < options.length; i++) {
15
+ const optionStr = options[i];
16
+ if (!optionStr.trim()) continue;
17
+ const option = optionStr.split("::");
18
+ if (option.length === 0) continue;
19
+ optComps.push({
20
+ type: typeOption,
21
+ components: option[1] || option[0],
22
+ attributes: { value: option[0] }
23
+ });
24
+ }
25
+ target.components().reset(optComps);
26
+ target.view?.render();
27
+ },
28
+ getInputEl() {
29
+ if (!this.$input) {
30
+ const optionsArr = [];
31
+ const options = this.target.components();
32
+ for (let i = 0; i < options.length; i++) {
33
+ const option = options.at(i);
34
+ if (!option) continue;
35
+ const optAttr = option.get("attributes");
36
+ const optValue = optAttr?.value || "";
37
+ const optTxtNode = option.components().at(0);
38
+ const optLabel = optTxtNode?.get("content") || "";
39
+ optionsArr.push(`${optValue}::${optLabel}`);
40
+ }
41
+ const el = document.createElement("textarea");
42
+ el.value = optionsArr.join("\n");
43
+ this.$input = el;
44
+ }
45
+ return this.$input;
46
+ }
47
+ });
48
+ };
49
+ export {
50
+ formTraits_default as default
51
+ };
@@ -0,0 +1,4 @@
1
+ import type { CustomTrait, Editor } from 'grapesjs';
2
+ export declare const AddTrait: (editor: Editor) => <T>(id: string, def: CustomTrait<T>) => void;
3
+ export declare function loadTraits(editor: Editor): void;
4
+ export default loadTraits;
@@ -0,0 +1,15 @@
1
+ import formTraits from "./formTraits.js";
2
+ import typedTraits from "./typedTraits.js";
3
+ const AddTrait = (editor) => (id, def) => {
4
+ editor.TraitManager.addType(id, def);
5
+ };
6
+ function loadTraits(editor) {
7
+ typedTraits(editor);
8
+ formTraits(editor);
9
+ }
10
+ var traits_default = loadTraits;
11
+ export {
12
+ AddTrait,
13
+ traits_default as default,
14
+ loadTraits
15
+ };
@@ -0,0 +1,3 @@
1
+ import type { Editor } from 'grapesjs';
2
+ declare const _default: (editor: Editor) => void;
3
+ export default _default;
@@ -0,0 +1,24 @@
1
+ import { typedTraitStringId } from "../consts.js";
2
+ import { AddTrait } from "./index.js";
3
+ var typedTraits_default = (editor) => {
4
+ const addTrait = AddTrait(editor);
5
+ addTrait(typedTraitStringId, {
6
+ createInput({ component }) {
7
+ const strings = component.get("strings");
8
+ const stringsArray = Array.isArray(strings) ? strings : [];
9
+ return `<textarea>${stringsArray.join("\n")}</textarea>`;
10
+ },
11
+ onUpdate({ component, elInput }) {
12
+ const strings = component.get("strings");
13
+ const stringsArray = Array.isArray(strings) ? strings : [];
14
+ elInput.value = stringsArray.join("\n");
15
+ },
16
+ onEvent({ component, elInput }) {
17
+ const value = (elInput.value || "").split("\n");
18
+ component.set("strings", value);
19
+ }
20
+ });
21
+ };
22
+ export {
23
+ typedTraits_default as default
24
+ };
@@ -0,0 +1,86 @@
1
+ import type { Component, Editor } from 'grapesjs';
2
+ type ImageEditor = tuiImageEditor.ImageEditor;
3
+ type IOptions = tuiImageEditor.IOptions;
4
+ export type PluginOptions = {
5
+ /**
6
+ * TOAST UI's configurations
7
+ * https://nhn.github.io/tui.image-editor/latest/ImageEditor
8
+ */
9
+ config?: IOptions;
10
+ /**
11
+ * Pass the editor constructor.
12
+ * By default, the `tui.ImageEditor` will be used.
13
+ */
14
+ constructor?: any;
15
+ /**
16
+ * Label for the image editor (used in the modal)
17
+ * @default 'Image Editor'
18
+ */
19
+ labelImageEditor?: string;
20
+ /**
21
+ * Label used on the apply button
22
+ * @default 'Apply'
23
+ */
24
+ labelApply?: string;
25
+ /**
26
+ * Default editor height
27
+ * @default '650px'
28
+ */
29
+ height?: string;
30
+ /**
31
+ * Default editor width
32
+ * @default '100%'
33
+ */
34
+ width?: string;
35
+ /**
36
+ * Id to use to create the image editor command
37
+ * @default 'tui-image-editor'
38
+ */
39
+ commandId?: string;
40
+ /**
41
+ * Icon used in the image component toolbar. Pass an empty string to avoid adding the icon.
42
+ */
43
+ toolbarIcon?: string;
44
+ /**
45
+ * Hide the default editor header
46
+ * @default true
47
+ */
48
+ hideHeader?: boolean;
49
+ /**
50
+ * By default, GrapesJS takes the modified image, adds it to the Asset Manager and update the target.
51
+ * If you need some custom logic you can use this custom 'onApply' function.
52
+ * @example
53
+ * onApply: (imageEditor, imageModel) => {
54
+ * const dataUrl = imageEditor.toDataURL();
55
+ * editor.AssetManager.add({ src: dataUrl }); // Add it to Assets
56
+ * imageModel.set('src', dataUrl); // Update the image component
57
+ * }
58
+ */
59
+ onApply?: ((imageEditor: ImageEditor, imageModel: Component) => void) | null;
60
+ /**
61
+ * If no custom `onApply` is passed and this option is `true`, the result image will be added to assets
62
+ * @default true
63
+ */
64
+ addToAssets?: boolean;
65
+ /**
66
+ * If no custom `onApply` is passed, on confirm, the edited image, will be passed to the
67
+ * AssetManager's uploader and the result (eg. instead of having the dataURL you'll have the URL)
68
+ * will be passed to the default `onApply` process (update target, etc.)
69
+ */
70
+ upload?: boolean;
71
+ /**
72
+ * The apply button (HTMLElement) will be passed as an argument to this function, once created.
73
+ * This will allow you a higher customization.
74
+ */
75
+ onApplyButton?: (btn: HTMLElement) => void;
76
+ /**
77
+ * Scripts to load dynamically in case no TOAST UI editor instance was found
78
+ */
79
+ script?: string[];
80
+ /**
81
+ * In case the script is loaded this style will be loaded too
82
+ */
83
+ style?: string[];
84
+ };
85
+ declare const plugin: (editor: Editor) => void;
86
+ export default plugin;
@@ -0,0 +1,203 @@
1
+ const plugin = (editor) => {
2
+ const opts = {
3
+ config: {},
4
+ constructor: "",
5
+ labelImageEditor: "Image Editor",
6
+ labelApply: "Apply",
7
+ height: "650px",
8
+ width: "100%",
9
+ commandId: "tui-image-editor",
10
+ toolbarIcon: `<svg viewBox="0 0 24 24">
11
+ <path d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25z">
12
+ </path>
13
+ </svg>`,
14
+ hideHeader: true,
15
+ addToAssets: true,
16
+ upload: false,
17
+ onApplyButton: () => {
18
+ },
19
+ onApply: null,
20
+ script: [
21
+ "https://uicdn.toast.com/tui.code-snippet/v1.5.2/tui-code-snippet.min.js",
22
+ "https://uicdn.toast.com/tui-color-picker/v2.2.7/tui-color-picker.min.js",
23
+ "https://uicdn.toast.com/tui-image-editor/v3.15.2/tui-image-editor.min.js"
24
+ ],
25
+ style: [
26
+ "https://uicdn.toast.com/tui-color-picker/v2.2.7/tui-color-picker.min.css",
27
+ "https://uicdn.toast.com/tui-image-editor/v3.15.2/tui-image-editor.min.css"
28
+ ]
29
+ };
30
+ const { script, style, height, width, hideHeader, onApply, upload, addToAssets, commandId } = opts;
31
+ const hasWindow = typeof window !== "undefined";
32
+ const getConstructor = () => {
33
+ return opts.constructor || hasWindow && window.tui?.ImageEditor;
34
+ };
35
+ let constr = getConstructor();
36
+ if (!constr && script?.length && hasWindow) {
37
+ const { head } = document;
38
+ const scripts = Array.isArray(script) ? [...script] : [script];
39
+ const styles = Array.isArray(style) ? [...style] : [style];
40
+ const appendStyle = (styles2) => {
41
+ if (styles2.length) {
42
+ const link = document.createElement("link");
43
+ link.href = styles2.shift();
44
+ link.rel = "stylesheet";
45
+ head.appendChild(link);
46
+ appendStyle(styles2);
47
+ }
48
+ };
49
+ const appendScript = (scripts2) => {
50
+ if (scripts2.length) {
51
+ const scr = document.createElement("script");
52
+ scr.src = scripts2.shift();
53
+ scr.onerror = scr.onload = appendScript.bind(null, scripts2);
54
+ head.appendChild(scr);
55
+ } else {
56
+ constr = getConstructor();
57
+ }
58
+ };
59
+ appendStyle(styles);
60
+ appendScript(scripts);
61
+ }
62
+ if (opts.toolbarIcon) {
63
+ editor.Components.addType("image", {
64
+ extendFn: ["initToolbar"],
65
+ model: {
66
+ initToolbar() {
67
+ const tb = this.get("toolbar");
68
+ const tbExists = tb?.some((item) => item.command === commandId);
69
+ if (!tbExists) {
70
+ tb?.unshift({
71
+ command: commandId,
72
+ label: opts.toolbarIcon
73
+ });
74
+ this.set("toolbar", tb);
75
+ }
76
+ }
77
+ }
78
+ });
79
+ }
80
+ const errorOpts = { level: "error", ns: commandId };
81
+ editor.Commands.add(commandId, {
82
+ imageEditor: null,
83
+ run(ed, _s, options = {}) {
84
+ if (!constr) {
85
+ ed.log("TOAST UI Image editor not found", errorOpts);
86
+ return ed.stopCommand(commandId);
87
+ }
88
+ const target = options.target || ed.getSelected();
89
+ if (!target) {
90
+ ed.log("Target not available", errorOpts);
91
+ return ed.stopCommand(commandId);
92
+ }
93
+ const content = this.createContent();
94
+ const title = opts.labelImageEditor;
95
+ const btn = content.children[1];
96
+ ed.Modal.open({ title, content }).onceClose(() => ed.stopCommand(commandId));
97
+ const editorConfig = this.getEditorConfig(target.get("src"));
98
+ this.imageEditor = new constr(content.children[0], editorConfig);
99
+ ed.getModel().setEditing(true);
100
+ btn.onclick = () => this.applyChanges(target);
101
+ opts.onApplyButton(btn);
102
+ },
103
+ stop(ed) {
104
+ this.imageEditor?.destroy();
105
+ ed.getModel().setEditing(false);
106
+ },
107
+ getEditorConfig(path) {
108
+ const config = { ...opts.config };
109
+ if (!config.includeUI) config.includeUI = {};
110
+ config.includeUI = {
111
+ theme: {},
112
+ ...config.includeUI,
113
+ loadImage: { path, name: "1" },
114
+ uiSize: { height, width }
115
+ };
116
+ if (hideHeader) {
117
+ config.includeUI.theme["header.display"] = "none";
118
+ }
119
+ return config;
120
+ },
121
+ createContent() {
122
+ const content = document.createElement("div");
123
+ content.style.position = "relative";
124
+ content.innerHTML = `
125
+ <div></div>
126
+ <button class="tui-image-editor__apply-btn" style="
127
+ position: absolute;
128
+ top: 0; right: 0;
129
+ margin: 10px;
130
+ background-color: #fff;
131
+ font-size: 1rem;
132
+ border-radius: 3px;
133
+ border: none;
134
+ padding: 10px 20px;
135
+ cursor: pointer
136
+ ">
137
+ ${opts.labelApply}
138
+ </button>
139
+ `;
140
+ return content;
141
+ },
142
+ applyChanges(target) {
143
+ const ied = this.imageEditor;
144
+ if (onApply) {
145
+ onApply(ied, target);
146
+ } else {
147
+ if (ied.getDrawingMode() === "CROPPER") {
148
+ ied.crop(ied.getCropzoneRect()).then(() => {
149
+ this.uploadImage(ied, target);
150
+ });
151
+ } else {
152
+ this.uploadImage(ied, target);
153
+ }
154
+ }
155
+ },
156
+ uploadImage(imageEditor, target) {
157
+ const am = editor.Assets;
158
+ const dataURL = imageEditor.toDataURL();
159
+ if (upload) {
160
+ const file = this.dataUrlToBlob(dataURL);
161
+ am.FileUploader().uploadFile(
162
+ {
163
+ dataTransfer: {
164
+ // @ts-ignore
165
+ files: [file]
166
+ }
167
+ },
168
+ // biome-ignore lint/suspicious/noExplicitAny: This is the type that was already used in the original code
169
+ (res) => {
170
+ const obj = res?.data?.[0];
171
+ const src = obj && (typeof obj === "string" ? obj : obj.src);
172
+ src && this.applyToTarget(src, target);
173
+ }
174
+ );
175
+ } else {
176
+ addToAssets && am.add({
177
+ src: dataURL,
178
+ name: (target.get("src") || "").split("/").pop()
179
+ });
180
+ this.applyToTarget(dataURL, target);
181
+ }
182
+ },
183
+ applyToTarget(result, target) {
184
+ target.set("src", result);
185
+ editor.Modal.close();
186
+ },
187
+ dataUrlToBlob(dataURL) {
188
+ const data = dataURL.split(",");
189
+ const byteStr = window.atob(data[1]);
190
+ const type = data[0].split(":")[1].split(";")[0];
191
+ const ab = new ArrayBuffer(byteStr.length);
192
+ const ia = new Uint8Array(ab);
193
+ for (let i = 0; i < byteStr.length; i++) {
194
+ ia[i] = byteStr.charCodeAt(i);
195
+ }
196
+ return new Blob([ab], { type });
197
+ }
198
+ });
199
+ };
200
+ var tuiImageEditor_default = plugin;
201
+ export {
202
+ tuiImageEditor_default as default
203
+ };