@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 StudioCMS - withstudiocms (https://github.com/withstudiocms)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @studiocms/wysiwyg
2
+
3
+ Add a WYSIWYG editor to your StudioCMS dashboard.
4
+
5
+ ## Overview
6
+
7
+ Add this plugin to your StudioCMS config (`studiocms.config.mjs` or `.mts`):
8
+
9
+ ```ts
10
+ import wysiwyg from '@studiocms/wysiwyg';
11
+
12
+ export default defineStudioCMSConfig({
13
+ // other options here
14
+ plugins: [wysiwyg()]
15
+ });
16
+ ```
17
+
18
+ ## License
19
+
20
+ [MIT Licensed](./LICENSE).
@@ -0,0 +1,31 @@
1
+ import type { Plugin } from 'grapesjs';
2
+ import type { ComponentRegistryEntry } from 'studiocms/componentRegistry/types';
3
+ /**
4
+ * Represents a collection of registered components for use within the Astro environment.
5
+ *
6
+ * @property componentRegistry - An array of `ComponentRegistryEntry` objects, each describing a registered component.
7
+ */
8
+ interface AstroComponents {
9
+ componentRegistry: ComponentRegistryEntry[];
10
+ }
11
+ /**
12
+ * Registers custom Astro components in the GrapesJS editor using a provided component registry.
13
+ *
14
+ * This plugin iterates over the given `componentRegistry` array and for each entry:
15
+ * - Adds a new component type to the GrapesJS `DomComponents` manager, mapping the component's props to GrapesJS traits.
16
+ * - Registers a new block in the GrapesJS `BlockManager` for easy drag-and-drop usage in the editor.
17
+ *
18
+ * @param editor - The GrapesJS editor instance to extend.
19
+ * @param opts - Optional configuration object.
20
+ * @param opts.componentRegistry - An array of component registry entries, each describing an Astro component to register.
21
+ *
22
+ * Each component registry entry should have:
23
+ * - `name`: The tag name of the component.
24
+ * - `props`: An array of prop definitions, each with `name`, `type`, and `defaultValue`.
25
+ *
26
+ * @remarks
27
+ * - The function expects helper functions such as `traitTypeFilter`, `renderComponentPreview`, `firstUpperCase`, and the `AstroSVG` asset to be available in scope.
28
+ * - The registered components and blocks will appear under the "Astro Components" category in the GrapesJS block manager.
29
+ */
30
+ export declare const astroComponents: Plugin<AstroComponents>;
31
+ export {};
@@ -0,0 +1,59 @@
1
+ import { PARTIAL_PATH } from "../consts.js";
2
+ import { buildBlockProps, partialRequestBuilder, traitMapFn } from "./editor-utils.js";
3
+ const astroComponents = (editor, { componentRegistry }) => {
4
+ const componentKeys = componentRegistry.map(({ name }) => name);
5
+ for (const component of componentRegistry) {
6
+ const { name, props } = component;
7
+ let timedInterval;
8
+ let abortController;
9
+ editor.DomComponents.addType(name, {
10
+ isComponent: (el) => componentKeys.includes(el.tagName?.toLowerCase()),
11
+ model: {
12
+ defaults: {
13
+ tagName: name,
14
+ traits: props.map(traitMapFn)
15
+ }
16
+ },
17
+ view: {
18
+ tagName: () => "div",
19
+ init() {
20
+ this.listenTo(this.model.components(), "add remove reset", this.onChange);
21
+ this.listenTo(this.model, "change", this.onChange);
22
+ this.onChange();
23
+ },
24
+ onChange() {
25
+ timedInterval && clearTimeout(timedInterval);
26
+ abortController?.abort();
27
+ timedInterval = setTimeout(() => {
28
+ abortController = new AbortController();
29
+ fetch(PARTIAL_PATH, {
30
+ ...partialRequestBuilder(this.model),
31
+ signal: abortController.signal
32
+ }).then((getCompResponse) => {
33
+ if (!getCompResponse.ok) {
34
+ console.log("[Error]: Could not fetch component HTML, please try again.");
35
+ const html = `<div class="error">Error: ${getCompResponse.statusText}</div>`;
36
+ this.el.innerHTML = html;
37
+ return;
38
+ }
39
+ return getCompResponse.text();
40
+ }).then((html) => {
41
+ if (html !== void 0) {
42
+ this.el.innerHTML = html;
43
+ }
44
+ }).catch((error) => {
45
+ if (error.name !== "AbortError") {
46
+ console.log("[Error]: Network or parsing error:", error);
47
+ this.el.innerHTML = `<div class="error">Network Error</div>`;
48
+ }
49
+ });
50
+ }, 100);
51
+ }
52
+ }
53
+ });
54
+ editor.BlockManager.add(name, buildBlockProps(name));
55
+ }
56
+ };
57
+ export {
58
+ astroComponents
59
+ };
@@ -0,0 +1,23 @@
1
+ import type { EditorConfig } from 'grapesjs';
2
+ /**
3
+ * The base configuration object for the WYSIWYG editor.
4
+ *
5
+ * This partial configuration of `EditorConfig` defines the default settings for the editor container,
6
+ * dimensions, storage management, panels, canvas styles, and the style manager sectors.
7
+ *
8
+ * @remarks
9
+ * - The `container` property specifies the DOM selector for the editor.
10
+ * - The `height` and `width` properties define the editor's dimensions.
11
+ * - `storageManager` is set to use inline storage.
12
+ * - `panels` are initialized as empty.
13
+ * - The `canvas` property includes an array of stylesheets to be loaded.
14
+ * - The `styleManager` property organizes style controls into sectors such as General, Dimension, Typography, Decorations, Extra, and Flex.
15
+ * Each sector contains properties or buildProps for customizing the appearance and layout of elements within the editor.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { baseConfig } from './editor-settings';
20
+ * // Use baseConfig to initialize the editor
21
+ * ```
22
+ */
23
+ export declare const baseConfig: Partial<EditorConfig>;
@@ -0,0 +1,357 @@
1
+ import { GRAPES_CSS_PATH } from "../consts.js";
2
+ const baseConfig = {
3
+ container: "#gjs",
4
+ height: "100%",
5
+ width: "auto",
6
+ fromElement: false,
7
+ storageManager: {
8
+ type: "db",
9
+ stepsBeforeSave: 10
10
+ },
11
+ panels: { defaults: [] },
12
+ canvas: {
13
+ styles: [GRAPES_CSS_PATH]
14
+ },
15
+ styleManager: {
16
+ sectors: [
17
+ {
18
+ name: "General",
19
+ properties: [
20
+ {
21
+ extend: "float",
22
+ type: "radio",
23
+ default: "none",
24
+ options: [
25
+ {
26
+ value: "none",
27
+ className: "fa fa-times",
28
+ id: ""
29
+ },
30
+ {
31
+ value: "left",
32
+ className: "fa fa-align-left",
33
+ id: ""
34
+ },
35
+ {
36
+ value: "right",
37
+ className: "fa fa-align-right",
38
+ id: ""
39
+ }
40
+ ]
41
+ },
42
+ "display",
43
+ { extend: "position", type: "select" },
44
+ "top",
45
+ "right",
46
+ "left",
47
+ "bottom"
48
+ ]
49
+ },
50
+ {
51
+ name: "Dimension",
52
+ open: false,
53
+ properties: [
54
+ "width",
55
+ {
56
+ id: "flex-width",
57
+ type: "integer",
58
+ name: "Width",
59
+ units: ["px", "%"],
60
+ property: "flex-basis",
61
+ toRequire: true
62
+ },
63
+ "height",
64
+ "max-width",
65
+ "min-height",
66
+ "margin",
67
+ "padding"
68
+ ]
69
+ },
70
+ {
71
+ name: "Typography",
72
+ open: false,
73
+ properties: [
74
+ "font-family",
75
+ "font-size",
76
+ "font-weight",
77
+ "letter-spacing",
78
+ "color",
79
+ "line-height",
80
+ {
81
+ extend: "text-align",
82
+ options: [
83
+ {
84
+ id: "left",
85
+ label: "Left",
86
+ className: "fa fa-align-left"
87
+ },
88
+ {
89
+ id: "center",
90
+ label: "Center",
91
+ className: "fa fa-align-center"
92
+ },
93
+ {
94
+ id: "right",
95
+ label: "Right",
96
+ className: "fa fa-align-right"
97
+ },
98
+ {
99
+ id: "justify",
100
+ label: "Justify",
101
+ className: "fa fa-align-justify"
102
+ }
103
+ ]
104
+ },
105
+ {
106
+ property: "text-decoration",
107
+ type: "radio",
108
+ default: "none",
109
+ options: [
110
+ {
111
+ id: "none",
112
+ label: "None",
113
+ className: "fa fa-times"
114
+ },
115
+ {
116
+ id: "underline",
117
+ label: "underline",
118
+ className: "fa fa-underline"
119
+ },
120
+ {
121
+ id: "line-through",
122
+ label: "Line-through",
123
+ className: "fa fa-strikethrough"
124
+ }
125
+ ]
126
+ },
127
+ "text-shadow"
128
+ ]
129
+ },
130
+ {
131
+ name: "Decorations",
132
+ open: false,
133
+ properties: [
134
+ "opacity",
135
+ "border-radius",
136
+ "border",
137
+ "box-shadow",
138
+ "background"
139
+ // { id: 'background-bg', property: 'background', type: 'bg' }
140
+ ]
141
+ },
142
+ {
143
+ name: "Extra",
144
+ open: false,
145
+ buildProps: ["transition", "perspective", "transform"]
146
+ },
147
+ {
148
+ name: "Flex",
149
+ open: false,
150
+ properties: [
151
+ {
152
+ name: "Flex Container",
153
+ property: "display",
154
+ type: "select",
155
+ defaults: "block",
156
+ list: [
157
+ { value: "block", name: "Disable", id: "" },
158
+ { value: "flex", name: "Enable", id: "" }
159
+ ]
160
+ },
161
+ {
162
+ name: "Flex Parent",
163
+ property: "label-parent-flex",
164
+ type: "integer"
165
+ },
166
+ {
167
+ name: "Direction",
168
+ property: "flex-direction",
169
+ type: "radio",
170
+ defaults: "row",
171
+ list: [
172
+ {
173
+ value: "row",
174
+ name: "Row",
175
+ className: "icons-flex icon-dir-row",
176
+ title: "Row",
177
+ id: ""
178
+ },
179
+ {
180
+ value: "row-reverse",
181
+ name: "Row reverse",
182
+ className: "icons-flex icon-dir-row-rev",
183
+ title: "Row reverse",
184
+ id: ""
185
+ },
186
+ {
187
+ value: "column",
188
+ name: "Column",
189
+ title: "Column",
190
+ className: "icons-flex icon-dir-col",
191
+ id: ""
192
+ },
193
+ {
194
+ value: "column-reverse",
195
+ name: "Column reverse",
196
+ title: "Column reverse",
197
+ className: "icons-flex icon-dir-col-rev",
198
+ id: ""
199
+ }
200
+ ]
201
+ },
202
+ {
203
+ name: "Justify",
204
+ property: "justify-content",
205
+ type: "radio",
206
+ defaults: "flex-start",
207
+ list: [
208
+ {
209
+ value: "flex-start",
210
+ className: "icons-flex icon-just-start",
211
+ title: "Start",
212
+ id: ""
213
+ },
214
+ {
215
+ value: "flex-end",
216
+ title: "End",
217
+ className: "icons-flex icon-just-end",
218
+ id: ""
219
+ },
220
+ {
221
+ value: "space-between",
222
+ title: "Space between",
223
+ className: "icons-flex icon-just-sp-bet",
224
+ id: ""
225
+ },
226
+ {
227
+ value: "space-around",
228
+ title: "Space around",
229
+ className: "icons-flex icon-just-sp-ar",
230
+ id: ""
231
+ },
232
+ {
233
+ value: "center",
234
+ title: "Center",
235
+ className: "icons-flex icon-just-sp-cent",
236
+ id: ""
237
+ }
238
+ ]
239
+ },
240
+ {
241
+ name: "Align",
242
+ property: "align-items",
243
+ type: "radio",
244
+ defaults: "center",
245
+ list: [
246
+ {
247
+ value: "flex-start",
248
+ title: "Start",
249
+ className: "icons-flex icon-al-start",
250
+ id: ""
251
+ },
252
+ {
253
+ value: "flex-end",
254
+ title: "End",
255
+ className: "icons-flex icon-al-end",
256
+ id: ""
257
+ },
258
+ {
259
+ value: "stretch",
260
+ title: "Stretch",
261
+ className: "icons-flex icon-al-str",
262
+ id: ""
263
+ },
264
+ {
265
+ value: "center",
266
+ title: "Center",
267
+ className: "icons-flex icon-al-center",
268
+ id: ""
269
+ }
270
+ ]
271
+ },
272
+ {
273
+ name: "Flex Children",
274
+ property: "label-parent-flex",
275
+ type: "integer"
276
+ },
277
+ {
278
+ name: "Order",
279
+ property: "order",
280
+ type: "integer",
281
+ defaults: "0",
282
+ min: 0
283
+ },
284
+ {
285
+ name: "Flex",
286
+ property: "flex",
287
+ type: "composite",
288
+ properties: [
289
+ {
290
+ name: "Grow",
291
+ property: "flex-grow",
292
+ type: "integer",
293
+ defaults: "0",
294
+ min: 0
295
+ },
296
+ {
297
+ name: "Shrink",
298
+ property: "flex-shrink",
299
+ type: "integer",
300
+ defaults: "0",
301
+ min: 0
302
+ },
303
+ {
304
+ name: "Basis",
305
+ property: "flex-basis",
306
+ type: "integer",
307
+ units: ["px", "%", ""],
308
+ unit: "",
309
+ defaults: "auto"
310
+ }
311
+ ]
312
+ },
313
+ {
314
+ name: "Align",
315
+ property: "align-self",
316
+ type: "radio",
317
+ defaults: "auto",
318
+ list: [
319
+ {
320
+ value: "auto",
321
+ name: "Auto",
322
+ id: ""
323
+ },
324
+ {
325
+ value: "flex-start",
326
+ title: "Start",
327
+ className: "icons-flex icon-al-start",
328
+ id: ""
329
+ },
330
+ {
331
+ value: "flex-end",
332
+ title: "End",
333
+ className: "icons-flex icon-al-end",
334
+ id: ""
335
+ },
336
+ {
337
+ value: "stretch",
338
+ title: "Stretch",
339
+ className: "icons-flex icon-al-str",
340
+ id: ""
341
+ },
342
+ {
343
+ value: "center",
344
+ title: "Center",
345
+ className: "icons-flex icon-al-center",
346
+ id: ""
347
+ }
348
+ ]
349
+ }
350
+ ]
351
+ }
352
+ ]
353
+ }
354
+ };
355
+ export {
356
+ baseConfig
357
+ };
@@ -0,0 +1,165 @@
1
+ import type { Component, Editor, ProjectData, TraitProperties } from 'grapesjs';
2
+ import type { AstroComponentProp, ComponentRegistryEntry } from 'studiocms/componentRegistry/types';
3
+ /**
4
+ * Generates an HTML string representation of the main component within the editor,
5
+ * including its styles. The styles are adjusted to replace all occurrences of 'body'
6
+ * with 'div' to ensure proper scoping.
7
+ *
8
+ * @param editor - The editor instance from which to extract the main page and component.
9
+ * @returns A promise that resolves to a string containing the HTML and scoped styles.
10
+ */
11
+ export declare const generateHTML: (editor: Editor) => Promise<string>;
12
+ /**
13
+ * Registers a custom storage adapter named 'db' for the provided editor instance.
14
+ * This adapter enables loading and storing project data to a backend database using fetch requests.
15
+ *
16
+ * @param editor - The editor instance to which the storage adapter will be added.
17
+ * @param opts - Configuration options for the storage adapter.
18
+ * @param opts.projectId - The unique identifier for the project whose data is being managed.
19
+ * @param opts.projectData - The initial project data to use as a fallback if loading fails.
20
+ * @param opts.pageContent - The HTML element where the serialized project data and generated HTML will be stored.
21
+ *
22
+ * The storage adapter provides two asynchronous methods:
23
+ * - `load`: Fetches project data from the backend using the projectId. Returns the fetched data or the fallback projectData if the request fails.
24
+ * - `store`: Sends the updated project data to the backend and updates the pageContent element with the serialized data and generated HTML.
25
+ */
26
+ export declare const StudioCMSDbStorageAdapter: (editor: Editor, opts: {
27
+ projectId: string;
28
+ projectData: ProjectData;
29
+ pageContent: HTMLElement;
30
+ csrfToken: string;
31
+ }) => void;
32
+ /**
33
+ * Reduces an array of `TraitProperties` into an accumulator object, mapping trait names to their values.
34
+ *
35
+ * - If the trait type is `'number'`, the value is coerced to a number.
36
+ * - If the trait value is an empty string, the default value is used.
37
+ * - Traits without a name are skipped.
38
+ *
39
+ * @param acc - The accumulator object that collects trait name-value pairs.
40
+ * @param trait - The trait to process and add to the accumulator.
41
+ * @returns The updated accumulator with the trait's name and resolved value.
42
+ */
43
+ export declare function traitReducer(acc: Record<string, any>, trait: TraitProperties): Record<string, any>;
44
+ /**
45
+ * Extracts and aggregates trait properties from a given component model.
46
+ *
47
+ * @param model - The component model containing traits to extract.
48
+ * @returns An object containing the aggregated trait properties.
49
+ */
50
+ export declare const getTraitData: (model: Component) => Record<string, any>;
51
+ /**
52
+ * Generates an HTML string representing the slot data for a given component model.
53
+ *
54
+ * Iterates through the child components of the provided model, converts each child to HTML,
55
+ * and wraps it with its respective tag name. The resulting HTML strings are concatenated
56
+ * and returned as a single string.
57
+ *
58
+ * @param model - The component model whose children will be processed.
59
+ * @returns A string containing the HTML representation of the model's child components,
60
+ * or an empty string if there are no children.
61
+ */
62
+ export declare const getSlotData: (model: Component) => string | undefined;
63
+ /**
64
+ * Returns the appropriate input type for a given trait type.
65
+ *
66
+ * @param type - The trait type to filter (e.g., "number", "string", etc.).
67
+ * @returns The corresponding input type as a string. Returns "number" if the type is "number", otherwise returns "text".
68
+ */
69
+ export declare const traitTypeFilter: (type: string) => "number" | "text";
70
+ /**
71
+ * Maps an `AstroComponentProp` to a new object with filtered type, name, and default value.
72
+ *
73
+ * @param prop - The Astro component property to map.
74
+ * @returns An object containing:
75
+ * - `type`: The filtered type of the property.
76
+ * - `name`: The name of the property.
77
+ * - `default`: The default value of the property.
78
+ */
79
+ export declare const traitMapFn: (prop: AstroComponentProp) => {
80
+ type: string;
81
+ name: string;
82
+ default: string | undefined;
83
+ };
84
+ /**
85
+ * Builds a partial request configuration for a given component model.
86
+ *
87
+ * @param model - The component model to build the request from.
88
+ * @returns A `RequestInit` object configured for a POST request with the component's data as JSON.
89
+ */
90
+ export declare const partialRequestBuilder: (model: Component) => RequestInit;
91
+ /**
92
+ * Retrieves and parses essential editor elements and data from the DOM.
93
+ *
94
+ * @param document - The `Document` object to query for elements.
95
+ * @param selectors - An object containing CSS selectors for the container and page content elements.
96
+ * @param selectors.container - CSS selector for the GrapesJS container element.
97
+ * @param selectors.pageContent - CSS selector for the page content textarea element.
98
+ * @returns An object containing:
99
+ * - `astroComponentsOpts`: Options including the parsed component registry.
100
+ * - `inlineStorageOpts`: Options including the page content element and parsed project data.
101
+ * @throws Will throw an error if the container or page content elements are not found in the DOM.
102
+ */
103
+ export declare function getEditorElmData(document: Document, selectors: {
104
+ container: string;
105
+ pageContent: string;
106
+ }): {
107
+ astroComponentsOpts: {
108
+ componentRegistry: ComponentRegistryEntry[];
109
+ };
110
+ StudioCMSDbStorageAdapterOpts: {
111
+ projectId: string;
112
+ projectData: ProjectData;
113
+ pageContent: HTMLTextAreaElement;
114
+ csrfToken: string;
115
+ };
116
+ };
117
+ /**
118
+ * Builds and returns the block properties object for a given block name.
119
+ *
120
+ * For the special case of 'cms-img', it returns a block configuration with
121
+ * specific content type and style. For all other names, it returns a generic
122
+ * block configuration using the provided name as the type and tagName.
123
+ *
124
+ * @param name - The name of the block to build properties for.
125
+ * @returns The block properties object configured for the specified block name.
126
+ */
127
+ export declare function buildBlockProps(name: string): {
128
+ id: "cms-img";
129
+ label: string;
130
+ content: {
131
+ style: {
132
+ color: string;
133
+ };
134
+ type: string;
135
+ tagName?: undefined;
136
+ };
137
+ media?: string | undefined;
138
+ category?: (string | import("grapesjs").BlockCategoryProperties) | undefined;
139
+ activate?: boolean | undefined;
140
+ select?: boolean | undefined;
141
+ resetId?: boolean | undefined;
142
+ disable?: boolean | undefined;
143
+ onClick?: ((block: import("grapesjs").Block, editor: Editor) => void) | undefined;
144
+ attributes?: Record<string, any> | undefined;
145
+ activeOnRender?: boolean | undefined;
146
+ dragDef?: import("grapesjs").ComponentDefinition | undefined;
147
+ } | {
148
+ id: string;
149
+ label: string;
150
+ content: {
151
+ type: string;
152
+ tagName: string;
153
+ style?: undefined;
154
+ };
155
+ media?: string | undefined;
156
+ category?: (string | import("grapesjs").BlockCategoryProperties) | undefined;
157
+ activate?: boolean | undefined;
158
+ select?: boolean | undefined;
159
+ resetId?: boolean | undefined;
160
+ disable?: boolean | undefined;
161
+ onClick?: ((block: import("grapesjs").Block, editor: Editor) => void) | undefined;
162
+ attributes?: Record<string, any> | undefined;
163
+ activeOnRender?: boolean | undefined;
164
+ dragDef?: import("grapesjs").ComponentDefinition | undefined;
165
+ };