@studiocms/wysiwyg 0.1.0-experimental.5 → 0.1.0

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 (164) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +7 -28
  3. package/dist/common/gjs-blocks.d.ts +4 -0
  4. package/dist/common/gjs-blocks.js +27 -0
  5. package/dist/common/gjs-componentRegistry.d.ts +31 -0
  6. package/dist/common/gjs-componentRegistry.js +59 -0
  7. package/dist/common/gjs-editor-settings.d.ts +23 -0
  8. package/dist/common/gjs-editor-settings.js +357 -0
  9. package/dist/common/gjs-editor-utils.d.ts +165 -0
  10. package/dist/common/gjs-editor-utils.js +217 -0
  11. package/dist/common/grapesBlocks/blocks/basics.d.ts +4 -0
  12. package/dist/common/grapesBlocks/blocks/basics.js +279 -0
  13. package/dist/common/grapesBlocks/blocks/extras.d.ts +4 -0
  14. package/dist/common/grapesBlocks/blocks/extras.js +63 -0
  15. package/dist/common/grapesBlocks/blocks/forms.d.ts +4 -0
  16. package/dist/{wysiwyg/editorPlugins/forms/blocks.js → common/grapesBlocks/blocks/forms.js} +15 -14
  17. package/dist/common/grapesBlocks/blocks/index.d.ts +5 -0
  18. package/dist/common/grapesBlocks/blocks/index.js +23 -0
  19. package/dist/common/grapesBlocks/blocks/tabs.d.ts +4 -0
  20. package/dist/{wysiwyg/editorPlugins/tabs/blocks.js → common/grapesBlocks/blocks/tabs.js} +9 -8
  21. package/dist/common/grapesBlocks/commands/clear.d.ts +4 -0
  22. package/dist/common/grapesBlocks/commands/clear.js +21 -0
  23. package/dist/common/grapesBlocks/commands/customCodeCommands.d.ts +4 -0
  24. package/dist/{wysiwyg/editorPlugins/code/commands.js → common/grapesBlocks/commands/customCodeCommands.js} +11 -9
  25. package/dist/common/grapesBlocks/commands/deviceCommands.js +23 -0
  26. package/dist/common/grapesBlocks/commands/index.d.ts +5 -0
  27. package/dist/common/grapesBlocks/commands/index.js +40 -0
  28. package/dist/common/grapesBlocks/commands/openImport.d.ts +4 -0
  29. package/dist/common/grapesBlocks/commands/openImport.js +71 -0
  30. package/dist/common/grapesBlocks/components/countdown.d.ts +12 -0
  31. package/dist/common/grapesBlocks/components/countdown.js +147 -0
  32. package/dist/common/grapesBlocks/components/customCode.d.ts +4 -0
  33. package/dist/{wysiwyg/editorPlugins/code/components.js → common/grapesBlocks/components/customCode.js} +16 -15
  34. package/dist/common/grapesBlocks/components/forms.d.ts +3 -0
  35. package/dist/{wysiwyg/editorPlugins/forms/components.js → common/grapesBlocks/components/forms.js} +30 -36
  36. package/dist/common/grapesBlocks/components/index.d.ts +5 -0
  37. package/dist/common/grapesBlocks/components/index.js +23 -0
  38. package/dist/common/grapesBlocks/components/tabLoader.d.ts +4 -0
  39. package/dist/{wysiwyg/editorPlugins/tabs/components/index.js → common/grapesBlocks/components/tabLoader.js} +7 -7
  40. package/dist/{wysiwyg/editorPlugins/tabs/components → common/grapesBlocks/components/tabs}/Tab.d.ts +1 -1
  41. package/dist/{wysiwyg/editorPlugins/tabs/components → common/grapesBlocks/components/tabs}/Tab.js +2 -2
  42. package/dist/{wysiwyg/editorPlugins/tabs/components → common/grapesBlocks/components/tabs}/TabContainer.d.ts +1 -1
  43. package/dist/{wysiwyg/editorPlugins/tabs/components → common/grapesBlocks/components/tabs}/TabContent.d.ts +1 -1
  44. package/dist/{wysiwyg/editorPlugins/tabs/components → common/grapesBlocks/components/tabs}/TabContents.d.ts +1 -1
  45. package/dist/{wysiwyg/editorPlugins/tabs/components → common/grapesBlocks/components/tabs}/Tabs.d.ts +1 -1
  46. package/dist/{wysiwyg/editorPlugins/tabs/components → common/grapesBlocks/components/tabs}/Tabs.js +8 -8
  47. package/dist/common/grapesBlocks/components/tooltip.d.ts +4 -0
  48. package/dist/{wysiwyg/editorPlugins → common/grapesBlocks/components}/tooltip.js +15 -87
  49. package/dist/common/grapesBlocks/components/typed.d.ts +9 -0
  50. package/dist/{wysiwyg/editorPlugins/typed/components.js → common/grapesBlocks/components/typed.js} +7 -7
  51. package/dist/common/grapesBlocks/consts.d.ts +25 -0
  52. package/dist/common/grapesBlocks/consts.js +245 -0
  53. package/dist/common/grapesBlocks/i18n/index.d.ts +3 -0
  54. package/dist/common/grapesBlocks/i18n/index.js +19 -0
  55. package/dist/common/grapesBlocks/panels/index.d.ts +4 -0
  56. package/dist/common/grapesBlocks/panels/index.js +171 -0
  57. package/dist/{wysiwyg/editorPlugins → common/grapesBlocks}/rte/colorPicker.d.ts +9 -0
  58. package/dist/{wysiwyg/editorPlugins → common/grapesBlocks}/rte/colorPicker.js +16 -2
  59. package/dist/{wysiwyg/editorPlugins → common/grapesBlocks}/rte/index.d.ts +3 -3
  60. package/dist/{wysiwyg/editorPlugins → common/grapesBlocks}/rte/index.js +18 -12
  61. package/dist/common/grapesBlocks/selectors/index.d.ts +4 -0
  62. package/dist/common/grapesBlocks/selectors/index.js +9 -0
  63. package/dist/common/grapesBlocks/selectors/tooltip.d.ts +4 -0
  64. package/dist/common/grapesBlocks/selectors/tooltip.js +15 -0
  65. package/dist/common/grapesBlocks/traits/formTraits.d.ts +3 -0
  66. package/dist/{wysiwyg/editorPlugins/forms/traits.js → common/grapesBlocks/traits/formTraits.js} +12 -8
  67. package/dist/common/grapesBlocks/traits/index.d.ts +4 -0
  68. package/dist/common/grapesBlocks/traits/index.js +15 -0
  69. package/dist/common/grapesBlocks/traits/typedTraits.d.ts +3 -0
  70. package/dist/common/grapesBlocks/traits/typedTraits.js +24 -0
  71. package/dist/{wysiwyg/editorPlugins/tuiImageEditor.d.ts → common/grapesBlocks/tuiImageEditor/index.d.ts} +2 -2
  72. package/dist/{wysiwyg/editorPlugins/tuiImageEditor.js → common/grapesBlocks/tuiImageEditor/index.js} +6 -7
  73. package/dist/common/grapesBlocks/types.d.ts +446 -0
  74. package/dist/components/Editor.astro +153 -0
  75. package/dist/components/render.d.ts +15 -0
  76. package/dist/components/render.js +11 -0
  77. package/dist/consts.d.ts +31 -0
  78. package/dist/consts.js +15 -0
  79. package/dist/index.d.ts +39 -0
  80. package/dist/index.js +71 -0
  81. package/dist/lib/db.d.ts +83 -0
  82. package/dist/lib/db.js +50 -0
  83. package/dist/lib/prerender.d.ts +10 -0
  84. package/dist/lib/prerender.js +22 -0
  85. package/dist/{wysiwyg → lib}/shared.d.ts +3 -6
  86. package/dist/lib/shared.js +6 -0
  87. package/dist/{utils.d.ts → lib/utils.d.ts} +1 -1
  88. package/dist/lib/utils.js +10 -0
  89. package/dist/routes/grapes.css.d.ts +7 -0
  90. package/dist/routes/grapes.css.js +13 -0
  91. package/dist/routes/partial.astro +44 -0
  92. package/dist/routes/store.d.ts +1 -0
  93. package/dist/routes/store.js +121 -0
  94. package/dist/schema.d.ts +60 -0
  95. package/dist/schema.js +24 -0
  96. package/dist/styles/editor.css +150 -0
  97. package/dist/styles/grapes.css +71 -0
  98. package/dist/types.d.ts +66 -0
  99. package/dist/types.js +9 -0
  100. package/package.json +30 -28
  101. package/dist/common/prepareRender.d.ts +0 -11
  102. package/dist/common/prepareRender.js +0 -24
  103. package/dist/studio/components/Render.astro +0 -11
  104. package/dist/studio/components/StudioSDKEditor.astro +0 -334
  105. package/dist/studio/index.d.ts +0 -38
  106. package/dist/studio/index.js +0 -58
  107. package/dist/studio/routes/partial.astro +0 -27
  108. package/dist/studio/shared.d.ts +0 -17
  109. package/dist/studio/shared.js +0 -7
  110. package/dist/studio/utils.d.ts +0 -105
  111. package/dist/studio/utils.js +0 -244
  112. package/dist/studio/virtual.d.ts +0 -114
  113. package/dist/utils.js +0 -15
  114. package/dist/wysiwyg/components/Editor.astro +0 -765
  115. package/dist/wysiwyg/components/Render.astro +0 -11
  116. package/dist/wysiwyg/editorPlugins/blocks/blocks.d.ts +0 -3
  117. package/dist/wysiwyg/editorPlugins/blocks/blocks.js +0 -239
  118. package/dist/wysiwyg/editorPlugins/blocks/index.d.ts +0 -80
  119. package/dist/wysiwyg/editorPlugins/blocks/index.js +0 -26
  120. package/dist/wysiwyg/editorPlugins/code/blocks.d.ts +0 -4
  121. package/dist/wysiwyg/editorPlugins/code/blocks.js +0 -20
  122. package/dist/wysiwyg/editorPlugins/code/commands.d.ts +0 -4
  123. package/dist/wysiwyg/editorPlugins/code/components.d.ts +0 -4
  124. package/dist/wysiwyg/editorPlugins/code/index.d.ts +0 -47
  125. package/dist/wysiwyg/editorPlugins/code/index.js +0 -28
  126. package/dist/wysiwyg/editorPlugins/code/utils.d.ts +0 -3
  127. package/dist/wysiwyg/editorPlugins/code/utils.js +0 -8
  128. package/dist/wysiwyg/editorPlugins/countdown.d.ts +0 -86
  129. package/dist/wysiwyg/editorPlugins/countdown.js +0 -163
  130. package/dist/wysiwyg/editorPlugins/forms/blocks.d.ts +0 -3
  131. package/dist/wysiwyg/editorPlugins/forms/components.d.ts +0 -11
  132. package/dist/wysiwyg/editorPlugins/forms/index.d.ts +0 -21
  133. package/dist/wysiwyg/editorPlugins/forms/index.js +0 -18
  134. package/dist/wysiwyg/editorPlugins/forms/traits.d.ts +0 -2
  135. package/dist/wysiwyg/editorPlugins/index.d.ts +0 -9
  136. package/dist/wysiwyg/editorPlugins/index.js +0 -20
  137. package/dist/wysiwyg/editorPlugins/rte/styles.css +0 -63
  138. package/dist/wysiwyg/editorPlugins/tabs/blocks.d.ts +0 -3
  139. package/dist/wysiwyg/editorPlugins/tabs/components/index.d.ts +0 -4
  140. package/dist/wysiwyg/editorPlugins/tabs/index.d.ts +0 -5
  141. package/dist/wysiwyg/editorPlugins/tabs/index.js +0 -15
  142. package/dist/wysiwyg/editorPlugins/tabs/options.d.ts +0 -5
  143. package/dist/wysiwyg/editorPlugins/tabs/options.js +0 -80
  144. package/dist/wysiwyg/editorPlugins/tabs/types.d.ts +0 -81
  145. package/dist/wysiwyg/editorPlugins/tooltip.d.ts +0 -68
  146. package/dist/wysiwyg/editorPlugins/typed/blocks.d.ts +0 -4
  147. package/dist/wysiwyg/editorPlugins/typed/blocks.js +0 -15
  148. package/dist/wysiwyg/editorPlugins/typed/components.d.ts +0 -9
  149. package/dist/wysiwyg/editorPlugins/typed/index.d.ts +0 -35
  150. package/dist/wysiwyg/editorPlugins/typed/index.js +0 -18
  151. package/dist/wysiwyg/editorPlugins/typed/traits.js +0 -18
  152. package/dist/wysiwyg/editorPlugins/typed/utils.d.ts +0 -2
  153. package/dist/wysiwyg/editorPlugins/typed/utils.js +0 -6
  154. package/dist/wysiwyg/index.d.ts +0 -20
  155. package/dist/wysiwyg/index.js +0 -47
  156. package/dist/wysiwyg/routes/partial.astro +0 -27
  157. package/dist/wysiwyg/shared.js +0 -7
  158. package/dist/wysiwyg/styles/main.css +0 -52
  159. package/dist/wysiwyg/virtual.d.ts +0 -3
  160. /package/dist/{wysiwyg/editorPlugins/typed/traits.d.ts → common/grapesBlocks/commands/deviceCommands.d.ts} +0 -0
  161. /package/dist/{wysiwyg/editorPlugins/tabs/components → common/grapesBlocks/components/tabs}/TabContainer.js +0 -0
  162. /package/dist/{wysiwyg/editorPlugins/tabs/components → common/grapesBlocks/components/tabs}/TabContent.js +0 -0
  163. /package/dist/{wysiwyg/editorPlugins/tabs/components → common/grapesBlocks/components/tabs}/TabContents.js +0 -0
  164. /package/dist/{wysiwyg/editorPlugins/tabs → common/grapesBlocks}/types.js +0 -0
@@ -0,0 +1,165 @@
1
+ import type { AstroComponentProp, ComponentRegistryEntry } from '@withstudiocms/component-registry/types';
2
+ import type { Component, Editor, ProjectData, TraitProperties } from 'grapesjs';
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) => "text" | "number";
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
+ };
@@ -0,0 +1,217 @@
1
+ import { toast } from "@studiocms/ui/components/Toast/toast.js";
2
+ import { CSRF_HEADER_NAME, STORE_ENDPOINT_PATH } from "../consts.js";
3
+ import { firstUpperCase, parse } from "../lib/utils.js";
4
+ const generateHTML = async (editor) => {
5
+ const page = editor.Pages.getMain();
6
+ const component = page.getMainComponent();
7
+ const htmlData = component.toHTML({ tag: "div" });
8
+ const styles = editor.getCss({ component })?.replaceAll("body", "div");
9
+ const html = `${htmlData}${styles ? `<style>${styles}</style>` : ""}`;
10
+ return html;
11
+ };
12
+ const updateSaveIndicator = (editor) => {
13
+ const saveIndicator = document.querySelector(".save-indicator");
14
+ if (saveIndicator && editor.getDirtyCount() === 0) {
15
+ saveIndicator.classList.remove("dirty");
16
+ }
17
+ };
18
+ const StudioCMSDbStorageAdapter = (editor, opts) => {
19
+ editor.Storage.add("db", {
20
+ async load() {
21
+ const urlToFetch = new URL(STORE_ENDPOINT_PATH, window.location.origin);
22
+ urlToFetch.searchParams.set("projectId", opts.projectId);
23
+ const toastProps = {
24
+ title: "WYSIWYG: Error loading page",
25
+ description: "There was an error loading your page. Fallback data loaded...",
26
+ type: "warning",
27
+ duration: 3e3
28
+ };
29
+ try {
30
+ const data = await fetch(urlToFetch, {
31
+ method: "GET",
32
+ credentials: "same-origin",
33
+ headers: {
34
+ Accept: "application/json",
35
+ "Content-Type": "application/json",
36
+ [CSRF_HEADER_NAME]: opts.csrfToken
37
+ }
38
+ });
39
+ if (!data.ok) {
40
+ toast(toastProps);
41
+ return opts.projectData;
42
+ }
43
+ const json = await data.json();
44
+ const responseData = json?.data;
45
+ if (!responseData) {
46
+ toast(toastProps);
47
+ return opts.projectData;
48
+ }
49
+ return responseData;
50
+ } catch (error) {
51
+ console.error("Error loading project data:", error);
52
+ toast(toastProps);
53
+ return opts.projectData;
54
+ }
55
+ },
56
+ async store(data) {
57
+ const urlToFetch = new URL(STORE_ENDPOINT_PATH, window.location.origin);
58
+ const projectData = {
59
+ ...data,
60
+ __STUDIOCMS_HTML: await generateHTML(editor)
61
+ };
62
+ const toastProps = {
63
+ title: "WYSIWYG: Error saving page",
64
+ description: "There was an error saving your changes. Only saving fallback data...",
65
+ type: "danger",
66
+ duration: 3e3
67
+ };
68
+ try {
69
+ const response = await fetch(urlToFetch, {
70
+ method: "POST",
71
+ credentials: "same-origin",
72
+ body: JSON.stringify({ projectId: opts.projectId, data: projectData }),
73
+ headers: {
74
+ "Content-Type": "application/json",
75
+ [CSRF_HEADER_NAME]: opts.csrfToken
76
+ }
77
+ });
78
+ if (!response.ok) {
79
+ toast(toastProps);
80
+ opts.pageContent.innerText = JSON.stringify(projectData);
81
+ return;
82
+ }
83
+ opts.pageContent.innerText = JSON.stringify(projectData);
84
+ updateSaveIndicator(editor);
85
+ } catch (error) {
86
+ console.error("Error saving project data:", error);
87
+ toast(toastProps);
88
+ opts.pageContent.innerText = JSON.stringify(projectData);
89
+ }
90
+ }
91
+ });
92
+ };
93
+ function traitReducer(acc, trait) {
94
+ if (!trait.name) return acc;
95
+ let value = trait.default;
96
+ if (trait.type === "number") {
97
+ value = Number(trait.value !== "" ? trait.value : trait.default);
98
+ } else {
99
+ value = trait.value !== "" ? trait.value : trait.default;
100
+ }
101
+ acc[trait.name] = value;
102
+ return acc;
103
+ }
104
+ const getTraitData = (model) => {
105
+ const traitData = model.traits.toJSON();
106
+ const propsData = traitData.reduce(traitReducer, {});
107
+ return propsData;
108
+ };
109
+ const getSlotData = (model) => {
110
+ const children = model.components().toArray();
111
+ let slotData;
112
+ if (children.length > 0) {
113
+ slotData = children.map((child) => child.toHTML()).join("");
114
+ }
115
+ return slotData;
116
+ };
117
+ const traitTypeFilter = (type) => {
118
+ switch (type) {
119
+ case "number":
120
+ return "number";
121
+ default:
122
+ return "text";
123
+ }
124
+ };
125
+ const traitMapFn = (prop) => ({
126
+ type: traitTypeFilter(prop.type),
127
+ name: prop.name,
128
+ default: prop.defaultValue
129
+ });
130
+ const partialRequestBuilder = (model) => {
131
+ return {
132
+ method: "POST",
133
+ headers: {
134
+ "Content-Type": "application/json"
135
+ },
136
+ body: JSON.stringify({
137
+ componentKey: model.tagName,
138
+ props: getTraitData(model),
139
+ slot: getSlotData(model)
140
+ })
141
+ };
142
+ };
143
+ function getEditorElmData(document2, selectors) {
144
+ const container = document2.querySelector(selectors.container);
145
+ if (!container) {
146
+ throw new Error("GrapesJS container not found. Ensure the HTML structure is correct.");
147
+ }
148
+ const pageContent = document2.querySelector(
149
+ selectors.pageContent
150
+ );
151
+ if (!pageContent) {
152
+ throw new Error("Page content textarea not found. Ensure the HTML structure is correct.");
153
+ }
154
+ const componentRegistry = parse(
155
+ container.dataset.componentRegistry || "[]"
156
+ );
157
+ const projectId = container.dataset.pageId || "";
158
+ const csrfToken = container.dataset.editorCsrfToken || "";
159
+ const fallbackPages = {
160
+ pages: [{ name: "page" }]
161
+ };
162
+ const projectData = parse(pageContent.innerText || JSON.stringify(fallbackPages));
163
+ return {
164
+ astroComponentsOpts: { componentRegistry },
165
+ StudioCMSDbStorageAdapterOpts: {
166
+ projectId,
167
+ projectData,
168
+ pageContent,
169
+ csrfToken
170
+ }
171
+ };
172
+ }
173
+ const commonBlockProps = {
174
+ category: "Astro Components",
175
+ select: true,
176
+ activate: true,
177
+ attributes: { class: "gjs-fonts gjs-f-b1" },
178
+ media: '<svg xmlns="http://www.w3.org/2000/svg" style="width:48px;height:48px" viewBox="0 0 24 24"><path fill="currentColor" d="M9.24 19.035c-.901-.826-1.164-2.561-.789-3.819c.65.793 1.552 1.044 2.486 1.186c1.44.218 2.856.137 4.195-.524c.153-.076.295-.177.462-.278c.126.365.159.734.115 1.11c-.107.915-.56 1.622-1.283 2.158c-.289.215-.594.406-.892.608c-.916.622-1.164 1.35-.82 2.41l.034.114a2.4 2.4 0 0 1-1.07-.918a2.6 2.6 0 0 1-.412-1.401c-.003-.248-.003-.497-.036-.74c-.081-.595-.36-.86-.883-.876a1.034 1.034 0 0 0-1.075.843q-.013.058-.033.126M4.1 15.007s2.666-1.303 5.34-1.303l2.016-6.26c.075-.304.296-.51.544-.51c.25 0 .47.206.545.51l2.016 6.26c3.167 0 5.34 1.303 5.34 1.303L15.363 2.602c-.13-.366-.35-.602-.645-.602H9.283c-.296 0-.506.236-.645.602c-.01.024-4.538 12.405-4.538 12.405"/></svg>'
179
+ };
180
+ function buildBlockProps(name) {
181
+ switch (name) {
182
+ case "cms-img": {
183
+ return {
184
+ ...commonBlockProps,
185
+ id: name,
186
+ label: `${firstUpperCase(name)}`,
187
+ content: {
188
+ style: { color: "black" },
189
+ type: "image"
190
+ }
191
+ };
192
+ }
193
+ default: {
194
+ return {
195
+ ...commonBlockProps,
196
+ id: name,
197
+ label: `${firstUpperCase(name)}`,
198
+ content: {
199
+ type: name,
200
+ tagName: name
201
+ }
202
+ };
203
+ }
204
+ }
205
+ }
206
+ export {
207
+ StudioCMSDbStorageAdapter,
208
+ buildBlockProps,
209
+ generateHTML,
210
+ getEditorElmData,
211
+ getSlotData,
212
+ getTraitData,
213
+ partialRequestBuilder,
214
+ traitMapFn,
215
+ traitReducer,
216
+ traitTypeFilter
217
+ };
@@ -0,0 +1,4 @@
1
+ import type { Editor } from 'grapesjs';
2
+ import type { RequiredGrapesBlocksOptions } from '../types.js';
3
+ declare const _default: (editor: Editor, opts: RequiredGrapesBlocksOptions) => void;
4
+ export default _default;
@@ -0,0 +1,279 @@
1
+ import { AddBlocks } from "./index.js";
2
+ var basics_default = (editor, opts) => {
3
+ const addBlock = AddBlocks(editor, opts);
4
+ const { stylePrefix, flexGrid, rowHeight, addBasicStyle } = opts;
5
+ const clsRow = `${stylePrefix}row`;
6
+ const clsCell = `${stylePrefix}cell`;
7
+ const styleRow = flexGrid ? `
8
+ .${clsRow} {
9
+ display: flex;
10
+ justify-content: flex-start;
11
+ align-items: stretch;
12
+ flex-wrap: nowrap;
13
+ padding: 10px;
14
+ }
15
+ @media (max-width: 768px) {
16
+ .${clsRow} {
17
+ flex-wrap: wrap;
18
+ }
19
+ }` : `
20
+ .${clsRow} {
21
+ display: table;
22
+ padding: 10px;
23
+ width: 100%;
24
+ }
25
+ @media (max-width: 768px) {
26
+ .${stylePrefix}cell, .${stylePrefix}cell30, .${stylePrefix}cell70 {
27
+ width: 100%;
28
+ display: block;
29
+ }
30
+ }`;
31
+ const styleClm = flexGrid ? `
32
+ .${clsCell} {
33
+ min-height: ${rowHeight}px;
34
+ flex-grow: 1;
35
+ flex-basis: 100%;
36
+ }` : `
37
+ .${clsCell} {
38
+ width: 8%;
39
+ display: table-cell;
40
+ height: ${rowHeight}px;
41
+ }`;
42
+ const styleClm30 = `
43
+ .${stylePrefix}cell30 {
44
+ width: 30%;
45
+ }`;
46
+ const styleClm70 = `
47
+ .${stylePrefix}cell70 {
48
+ width: 70%;
49
+ }`;
50
+ const step = 0.2;
51
+ const minDim = 1;
52
+ const currentUnit = 1;
53
+ const resizerBtm = {
54
+ tl: 0,
55
+ tc: 0,
56
+ tr: 0,
57
+ cl: 0,
58
+ cr: 0,
59
+ bl: 0,
60
+ br: 0,
61
+ minDim
62
+ };
63
+ const resizerRight = {
64
+ ...resizerBtm,
65
+ cr: 1,
66
+ bc: 0,
67
+ currentUnit,
68
+ minDim,
69
+ step
70
+ };
71
+ if (flexGrid) {
72
+ resizerRight.keyWidth = "flex-basis";
73
+ }
74
+ const rowAttr = {
75
+ class: clsRow,
76
+ "data-gjs-droppable": `.${clsCell}`,
77
+ "data-gjs-resizable": resizerBtm,
78
+ "data-gjs-name": "Row"
79
+ };
80
+ const colAttr = {
81
+ class: clsCell,
82
+ "data-gjs-draggable": `.${clsRow}`,
83
+ "data-gjs-resizable": resizerRight,
84
+ "data-gjs-name": "Cell"
85
+ };
86
+ if (flexGrid) {
87
+ colAttr["data-gjs-unstylable"] = ["width"];
88
+ colAttr["data-gjs-stylable-require"] = ["flex-basis"];
89
+ }
90
+ const privateCls = [`.${clsRow}`, `.${clsCell}`];
91
+ editor.on(
92
+ "selector:add",
93
+ (selector) => privateCls.indexOf(selector.getFullName()) >= 0 && selector.set("private", 1)
94
+ );
95
+ const attrsToString = (attrs) => {
96
+ const result = [];
97
+ for (const key in attrs) {
98
+ let value = attrs[key];
99
+ const toParse = Array.isArray(value) || value instanceof Object;
100
+ value = toParse ? JSON.stringify(value) : value;
101
+ result.push(`${key}=${toParse ? `'${value}'` : `"${value}"`}`);
102
+ }
103
+ return result.length ? ` ${result.join(" ")}` : "";
104
+ };
105
+ const attrsRow = attrsToString(rowAttr);
106
+ const attrsCell = attrsToString(colAttr);
107
+ const category = "Basic";
108
+ const commonBasicBlockProps = {
109
+ category,
110
+ select: true
111
+ };
112
+ addBlock("link-block", {
113
+ category,
114
+ label: "Link Block",
115
+ media: `<svg viewBox="0 0 24 24">
116
+ <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"></path>
117
+ </svg>`,
118
+ content: {
119
+ type: "link",
120
+ editable: false,
121
+ droppable: true,
122
+ style: {
123
+ display: "inline-block",
124
+ padding: "5px",
125
+ "min-height": "50px",
126
+ "min-width": "50px"
127
+ }
128
+ }
129
+ });
130
+ addBlock("quote", {
131
+ category,
132
+ label: "Quote",
133
+ media: `<svg viewBox="0 0 24 24">
134
+ <path fill="currentColor" d="M14,17H17L19,13V7H13V13H16M6,17H9L11,13V7H5V13H8L6,17Z" />
135
+ </svg>`,
136
+ content: `<blockquote class="quote">
137
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore ipsum dolor sit
138
+ </blockquote>`
139
+ });
140
+ addBlock("text-basic", {
141
+ category,
142
+ label: "Text section",
143
+ media: `<svg viewBox="0 0 24 24">
144
+ <path fill="currentColor" d="M21,6V8H3V6H21M3,18H12V16H3V18M3,13H21V11H3V13Z" />
145
+ </svg>`,
146
+ content: `<section class="bdg-sect">
147
+ <h1 class="heading">Insert title here</h1>
148
+ <p class="paragraph">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</p>
149
+ </section>`
150
+ });
151
+ addBlock("column1", {
152
+ ...commonBasicBlockProps,
153
+ label: opts.labelColumn1,
154
+ media: `<svg viewBox="0 0 24 24">
155
+ <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"/>
156
+ </svg>`,
157
+ content: `<div ${attrsRow}>
158
+ <div ${attrsCell}></div>
159
+ </div>
160
+ ${addBasicStyle ? `<style>
161
+ ${styleRow}
162
+ ${styleClm}
163
+ </style>` : ""}`
164
+ });
165
+ addBlock("column2", {
166
+ ...commonBasicBlockProps,
167
+ label: opts.labelColumn2,
168
+ media: `<svg viewBox="0 0 23 24">
169
+ <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"/>
170
+ </svg>`,
171
+ content: `<div ${attrsRow}>
172
+ <div ${attrsCell}></div>
173
+ <div ${attrsCell}></div>
174
+ </div>
175
+ ${addBasicStyle ? `<style>
176
+ ${styleRow}
177
+ ${styleClm}
178
+ </style>` : ""}`
179
+ });
180
+ addBlock("column3", {
181
+ ...commonBasicBlockProps,
182
+ label: opts.labelColumn3,
183
+ media: `<svg viewBox="0 0 23 24">
184
+ <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"/>
185
+ </svg>`,
186
+ content: `<div ${attrsRow}>
187
+ <div ${attrsCell}></div>
188
+ <div ${attrsCell}></div>
189
+ <div ${attrsCell}></div>
190
+ </div>
191
+ ${addBasicStyle ? `<style>
192
+ ${styleRow}
193
+ ${styleClm}
194
+ </style>` : ""}`
195
+ });
196
+ addBlock("column3-7", {
197
+ ...commonBasicBlockProps,
198
+ label: opts.labelColumn37,
199
+ media: `<svg viewBox="0 0 24 24">
200
+ <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"/>
201
+ </svg>`,
202
+ content: `<div ${attrsRow}>
203
+ <div ${attrsCell} style='${flexGrid ? "flex-basis" : "width"}: 30%;'></div>
204
+ <div ${attrsCell} style='${flexGrid ? "flex-basis" : "width"}: 70%;'></div>
205
+ </div>
206
+ ${addBasicStyle ? `<style>
207
+ ${styleRow}
208
+ ${styleClm}
209
+ ${styleClm30}
210
+ ${styleClm70}
211
+ </style>` : ""}`
212
+ });
213
+ addBlock("text", {
214
+ ...commonBasicBlockProps,
215
+ activate: true,
216
+ label: opts.labelText,
217
+ media: `<svg viewBox="0 0 24 24">
218
+ <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" />
219
+ </svg>`,
220
+ content: {
221
+ type: "text",
222
+ content: "Insert your text here",
223
+ style: { padding: "10px" }
224
+ }
225
+ });
226
+ addBlock("link", {
227
+ ...commonBasicBlockProps,
228
+ label: opts.labelLink,
229
+ media: `<svg viewBox="0 0 24 24">
230
+ <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" />
231
+ </svg>`,
232
+ content: {
233
+ type: "link",
234
+ content: "Link",
235
+ style: { color: "#d983a6" }
236
+ }
237
+ });
238
+ addBlock("image", {
239
+ ...commonBasicBlockProps,
240
+ activate: true,
241
+ label: opts.labelImage,
242
+ media: `<svg viewBox="0 0 24 24">
243
+ <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" />
244
+ </svg>`,
245
+ content: {
246
+ style: { color: "black" },
247
+ type: "image"
248
+ }
249
+ });
250
+ addBlock("video", {
251
+ ...commonBasicBlockProps,
252
+ label: opts.labelVideo,
253
+ media: `<svg viewBox="0 0 24 24">
254
+ <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" />
255
+ </svg>`,
256
+ content: {
257
+ type: "video",
258
+ src: "img/video2.webm",
259
+ style: {
260
+ height: "350px",
261
+ width: "615px"
262
+ }
263
+ }
264
+ });
265
+ addBlock("map", {
266
+ ...commonBasicBlockProps,
267
+ label: opts.labelMap,
268
+ media: `<svg viewBox="0 0 24 24">
269
+ <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" />
270
+ </svg>`,
271
+ content: {
272
+ type: "map",
273
+ style: { height: "350px" }
274
+ }
275
+ });
276
+ };
277
+ export {
278
+ basics_default as default
279
+ };
@@ -0,0 +1,4 @@
1
+ import type { Editor } from 'grapesjs';
2
+ import type { RequiredGrapesBlocksOptions } from '../types.js';
3
+ declare const _default: (editor: Editor, opts: RequiredGrapesBlocksOptions) => void;
4
+ export default _default;