@peak-ai/canvas 1.4.22 → 1.4.23

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 (209) hide show
  1. package/package.json +7 -45
  2. package/.babelrc +0 -14
  3. package/.eslintcache +0 -1
  4. package/.eslintignore +0 -5
  5. package/.eslintrc.js +0 -29
  6. package/dist/package.json +0 -62
  7. package/scripts/build.ts +0 -120
  8. package/src/GrapesjsCanvas.tsx +0 -494
  9. package/src/constants/index.ts +0 -25
  10. package/src/declaration.d.ts +0 -1
  11. package/src/helpers/compiled-table.css +0 -2429
  12. package/src/helpers/css.ts +0 -2667
  13. package/src/helpers/date-picker.ts +0 -807
  14. package/src/helpers/filter-placeholder.ts +0 -18
  15. package/src/helpers/index.ts +0 -13
  16. package/src/helpers/merge-json.ts +0 -106
  17. package/src/index.styles.ts +0 -58
  18. package/src/index.ts +0 -9
  19. package/src/plugins/grapejs-plugin.tsx +0 -196
  20. package/src/plugins/helpers/custom-modal.tsx +0 -123
  21. package/src/plugins/helpers/data-table.tsx +0 -300
  22. package/src/plugins/helpers/extra.tsx +0 -164
  23. package/src/plugins/helpers/query-cache-context.tsx +0 -154
  24. package/src/plugins/helpers/query-cache-singleton.ts +0 -176
  25. package/src/plugins/helpers/query-cache-utils.ts +0 -226
  26. package/src/plugins/helpers/query-details-modal.tsx +0 -400
  27. package/src/plugins/helpers/query-heading-formatter.ts +0 -24
  28. package/src/plugins/helpers/query-loading-modal.tsx +0 -94
  29. package/src/plugins/helpers/render-components.tsx +0 -1450
  30. package/src/plugins/helpers/styled-info-button.tsx +0 -504
  31. package/src/public/canvas.css +0 -42
  32. package/src/public/components-css/table/table-output.css +0 -2436
  33. package/src/public/components-css/table/table.css +0 -30
  34. package/src/public/output.css +0 -2465
  35. package/src/public/table.css +0 -135
  36. package/src/shadcn/components/icons/AiAvatarIcon.tsx +0 -47
  37. package/src/shadcn/components/icons/Co_driver Expanding button copy.svg +0 -21
  38. package/src/shadcn/components/icons/ai-avatar.svg +0 -7
  39. package/src/shadcn/components/icons/thinking.gif +0 -0
  40. package/src/shadcn/components/ui/button.tsx +0 -132
  41. package/src/shadcn/components/ui/card.tsx +0 -92
  42. package/src/shadcn/components/ui/chart.tsx +0 -324
  43. package/src/shadcn/components/ui/checkbox.tsx +0 -27
  44. package/src/shadcn/components/ui/component-wrapper.tsx +0 -61
  45. package/src/shadcn/components/ui/date-filter.tsx +0 -816
  46. package/src/shadcn/components/ui/error-container.tsx +0 -125
  47. package/src/shadcn/components/ui/error-wrapper.tsx +0 -99
  48. package/src/shadcn/components/ui/filter.tsx +0 -368
  49. package/src/shadcn/components/ui/hover-card.tsx +0 -36
  50. package/src/shadcn/components/ui/input.tsx +0 -20
  51. package/src/shadcn/components/ui/label.tsx +0 -24
  52. package/src/shadcn/components/ui/pagination.tsx +0 -213
  53. package/src/shadcn/components/ui/scroll-area.tsx +0 -59
  54. package/src/shadcn/components/ui/search.tsx +0 -150
  55. package/src/shadcn/components/ui/separator.tsx +0 -26
  56. package/src/shadcn/components/ui/skeleton.tsx +0 -69
  57. package/src/shadcn/components/ui/table.tsx +0 -196
  58. package/src/shadcn/components/ui/tabs.tsx +0 -55
  59. package/src/shadcn/components/ui/textarea.tsx +0 -18
  60. package/src/shadcn/components/ui/tooltip.tsx +0 -87
  61. package/src/shadcn/utils.ts +0 -6
  62. package/src/types/grapesjs-tailwind.d.ts +0 -61
  63. package/src/types/images.d.ts +0 -1
  64. package/tailwind.config.js +0 -5
  65. package/tooling/tailwind-compiler/index.js +0 -99
  66. package/tooling/tailwind-compiler/package.json +0 -11
  67. package/tooling/tailwind-compiler/yarn.lock +0 -123
  68. package/tsconfig.build.json +0 -15
  69. package/tsconfig.json +0 -8
  70. /package/{dist/GrapesjsCanvas.d.ts → GrapesjsCanvas.d.ts} +0 -0
  71. /package/{dist/GrapesjsCanvas.js → GrapesjsCanvas.js} +0 -0
  72. /package/{dist/GrapesjsCanvas.js.map → GrapesjsCanvas.js.map} +0 -0
  73. /package/{dist/constants → constants}/index.d.ts +0 -0
  74. /package/{dist/constants → constants}/index.js +0 -0
  75. /package/{dist/constants → constants}/index.js.map +0 -0
  76. /package/{dist/declaration.d.js → declaration.d.js} +0 -0
  77. /package/{dist/declaration.d.js.map → declaration.d.js.map} +0 -0
  78. /package/{dist/helpers → helpers}/compiled-table.css +0 -0
  79. /package/{dist/helpers → helpers}/css.d.ts +0 -0
  80. /package/{dist/helpers → helpers}/css.js +0 -0
  81. /package/{dist/helpers → helpers}/css.js.map +0 -0
  82. /package/{dist/helpers → helpers}/date-picker.d.ts +0 -0
  83. /package/{dist/helpers → helpers}/date-picker.js +0 -0
  84. /package/{dist/helpers → helpers}/date-picker.js.map +0 -0
  85. /package/{dist/helpers → helpers}/filter-placeholder.d.ts +0 -0
  86. /package/{dist/helpers → helpers}/filter-placeholder.js +0 -0
  87. /package/{dist/helpers → helpers}/filter-placeholder.js.map +0 -0
  88. /package/{dist/helpers → helpers}/index.d.ts +0 -0
  89. /package/{dist/helpers → helpers}/index.js +0 -0
  90. /package/{dist/helpers → helpers}/index.js.map +0 -0
  91. /package/{dist/helpers → helpers}/merge-json.d.ts +0 -0
  92. /package/{dist/helpers → helpers}/merge-json.js +0 -0
  93. /package/{dist/helpers → helpers}/merge-json.js.map +0 -0
  94. /package/{dist/index.d.ts → index.d.ts} +0 -0
  95. /package/{dist/index.js → index.js} +0 -0
  96. /package/{dist/index.js.map → index.js.map} +0 -0
  97. /package/{dist/index.styles.d.ts → index.styles.d.ts} +0 -0
  98. /package/{dist/index.styles.js → index.styles.js} +0 -0
  99. /package/{dist/index.styles.js.map → index.styles.js.map} +0 -0
  100. /package/{dist/plugins → plugins}/grapejs-plugin.d.ts +0 -0
  101. /package/{dist/plugins → plugins}/grapejs-plugin.js +0 -0
  102. /package/{dist/plugins → plugins}/grapejs-plugin.js.map +0 -0
  103. /package/{dist/plugins → plugins}/helpers/custom-modal.d.ts +0 -0
  104. /package/{dist/plugins → plugins}/helpers/custom-modal.js +0 -0
  105. /package/{dist/plugins → plugins}/helpers/custom-modal.js.map +0 -0
  106. /package/{dist/plugins → plugins}/helpers/data-table.d.ts +0 -0
  107. /package/{dist/plugins → plugins}/helpers/data-table.js +0 -0
  108. /package/{dist/plugins → plugins}/helpers/data-table.js.map +0 -0
  109. /package/{dist/plugins → plugins}/helpers/extra.d.ts +0 -0
  110. /package/{dist/plugins → plugins}/helpers/extra.js +0 -0
  111. /package/{dist/plugins → plugins}/helpers/extra.js.map +0 -0
  112. /package/{dist/plugins → plugins}/helpers/query-cache-context.d.ts +0 -0
  113. /package/{dist/plugins → plugins}/helpers/query-cache-context.js +0 -0
  114. /package/{dist/plugins → plugins}/helpers/query-cache-context.js.map +0 -0
  115. /package/{dist/plugins → plugins}/helpers/query-cache-singleton.d.ts +0 -0
  116. /package/{dist/plugins → plugins}/helpers/query-cache-singleton.js +0 -0
  117. /package/{dist/plugins → plugins}/helpers/query-cache-singleton.js.map +0 -0
  118. /package/{dist/plugins → plugins}/helpers/query-cache-utils.d.ts +0 -0
  119. /package/{dist/plugins → plugins}/helpers/query-cache-utils.js +0 -0
  120. /package/{dist/plugins → plugins}/helpers/query-cache-utils.js.map +0 -0
  121. /package/{dist/plugins → plugins}/helpers/query-details-modal.d.ts +0 -0
  122. /package/{dist/plugins → plugins}/helpers/query-details-modal.js +0 -0
  123. /package/{dist/plugins → plugins}/helpers/query-details-modal.js.map +0 -0
  124. /package/{dist/plugins → plugins}/helpers/query-heading-formatter.d.ts +0 -0
  125. /package/{dist/plugins → plugins}/helpers/query-heading-formatter.js +0 -0
  126. /package/{dist/plugins → plugins}/helpers/query-heading-formatter.js.map +0 -0
  127. /package/{dist/plugins → plugins}/helpers/query-loading-modal.d.ts +0 -0
  128. /package/{dist/plugins → plugins}/helpers/query-loading-modal.js +0 -0
  129. /package/{dist/plugins → plugins}/helpers/query-loading-modal.js.map +0 -0
  130. /package/{dist/plugins → plugins}/helpers/render-components.d.ts +0 -0
  131. /package/{dist/plugins → plugins}/helpers/render-components.js +0 -0
  132. /package/{dist/plugins → plugins}/helpers/render-components.js.map +0 -0
  133. /package/{dist/plugins → plugins}/helpers/styled-info-button.d.ts +0 -0
  134. /package/{dist/plugins → plugins}/helpers/styled-info-button.js +0 -0
  135. /package/{dist/plugins → plugins}/helpers/styled-info-button.js.map +0 -0
  136. /package/{dist/shadcn → shadcn}/components/icons/AiAvatarIcon.d.ts +0 -0
  137. /package/{dist/shadcn → shadcn}/components/icons/AiAvatarIcon.js +0 -0
  138. /package/{dist/shadcn → shadcn}/components/icons/AiAvatarIcon.js.map +0 -0
  139. /package/{dist/shadcn → shadcn}/components/icons/thinking.gif +0 -0
  140. /package/{dist/shadcn → shadcn}/components/ui/button.d.ts +0 -0
  141. /package/{dist/shadcn → shadcn}/components/ui/button.js +0 -0
  142. /package/{dist/shadcn → shadcn}/components/ui/button.js.map +0 -0
  143. /package/{dist/shadcn → shadcn}/components/ui/card.d.ts +0 -0
  144. /package/{dist/shadcn → shadcn}/components/ui/card.js +0 -0
  145. /package/{dist/shadcn → shadcn}/components/ui/card.js.map +0 -0
  146. /package/{dist/shadcn → shadcn}/components/ui/chart.d.ts +0 -0
  147. /package/{dist/shadcn → shadcn}/components/ui/chart.js +0 -0
  148. /package/{dist/shadcn → shadcn}/components/ui/chart.js.map +0 -0
  149. /package/{dist/shadcn → shadcn}/components/ui/checkbox.d.ts +0 -0
  150. /package/{dist/shadcn → shadcn}/components/ui/checkbox.js +0 -0
  151. /package/{dist/shadcn → shadcn}/components/ui/checkbox.js.map +0 -0
  152. /package/{dist/shadcn → shadcn}/components/ui/component-wrapper.d.ts +0 -0
  153. /package/{dist/shadcn → shadcn}/components/ui/component-wrapper.js +0 -0
  154. /package/{dist/shadcn → shadcn}/components/ui/component-wrapper.js.map +0 -0
  155. /package/{dist/shadcn → shadcn}/components/ui/date-filter.d.ts +0 -0
  156. /package/{dist/shadcn → shadcn}/components/ui/date-filter.js +0 -0
  157. /package/{dist/shadcn → shadcn}/components/ui/date-filter.js.map +0 -0
  158. /package/{dist/shadcn → shadcn}/components/ui/error-container.d.ts +0 -0
  159. /package/{dist/shadcn → shadcn}/components/ui/error-container.js +0 -0
  160. /package/{dist/shadcn → shadcn}/components/ui/error-container.js.map +0 -0
  161. /package/{dist/shadcn → shadcn}/components/ui/error-wrapper.d.ts +0 -0
  162. /package/{dist/shadcn → shadcn}/components/ui/error-wrapper.js +0 -0
  163. /package/{dist/shadcn → shadcn}/components/ui/error-wrapper.js.map +0 -0
  164. /package/{dist/shadcn → shadcn}/components/ui/filter.d.ts +0 -0
  165. /package/{dist/shadcn → shadcn}/components/ui/filter.js +0 -0
  166. /package/{dist/shadcn → shadcn}/components/ui/filter.js.map +0 -0
  167. /package/{dist/shadcn → shadcn}/components/ui/hover-card.d.ts +0 -0
  168. /package/{dist/shadcn → shadcn}/components/ui/hover-card.js +0 -0
  169. /package/{dist/shadcn → shadcn}/components/ui/hover-card.js.map +0 -0
  170. /package/{dist/shadcn → shadcn}/components/ui/input.d.ts +0 -0
  171. /package/{dist/shadcn → shadcn}/components/ui/input.js +0 -0
  172. /package/{dist/shadcn → shadcn}/components/ui/input.js.map +0 -0
  173. /package/{dist/shadcn → shadcn}/components/ui/label.d.ts +0 -0
  174. /package/{dist/shadcn → shadcn}/components/ui/label.js +0 -0
  175. /package/{dist/shadcn → shadcn}/components/ui/label.js.map +0 -0
  176. /package/{dist/shadcn → shadcn}/components/ui/pagination.d.ts +0 -0
  177. /package/{dist/shadcn → shadcn}/components/ui/pagination.js +0 -0
  178. /package/{dist/shadcn → shadcn}/components/ui/pagination.js.map +0 -0
  179. /package/{dist/shadcn → shadcn}/components/ui/scroll-area.d.ts +0 -0
  180. /package/{dist/shadcn → shadcn}/components/ui/scroll-area.js +0 -0
  181. /package/{dist/shadcn → shadcn}/components/ui/scroll-area.js.map +0 -0
  182. /package/{dist/shadcn → shadcn}/components/ui/search.d.ts +0 -0
  183. /package/{dist/shadcn → shadcn}/components/ui/search.js +0 -0
  184. /package/{dist/shadcn → shadcn}/components/ui/search.js.map +0 -0
  185. /package/{dist/shadcn → shadcn}/components/ui/separator.d.ts +0 -0
  186. /package/{dist/shadcn → shadcn}/components/ui/separator.js +0 -0
  187. /package/{dist/shadcn → shadcn}/components/ui/separator.js.map +0 -0
  188. /package/{dist/shadcn → shadcn}/components/ui/skeleton.d.ts +0 -0
  189. /package/{dist/shadcn → shadcn}/components/ui/skeleton.js +0 -0
  190. /package/{dist/shadcn → shadcn}/components/ui/skeleton.js.map +0 -0
  191. /package/{dist/shadcn → shadcn}/components/ui/table.d.ts +0 -0
  192. /package/{dist/shadcn → shadcn}/components/ui/table.js +0 -0
  193. /package/{dist/shadcn → shadcn}/components/ui/table.js.map +0 -0
  194. /package/{dist/shadcn → shadcn}/components/ui/tabs.d.ts +0 -0
  195. /package/{dist/shadcn → shadcn}/components/ui/tabs.js +0 -0
  196. /package/{dist/shadcn → shadcn}/components/ui/tabs.js.map +0 -0
  197. /package/{dist/shadcn → shadcn}/components/ui/textarea.d.ts +0 -0
  198. /package/{dist/shadcn → shadcn}/components/ui/textarea.js +0 -0
  199. /package/{dist/shadcn → shadcn}/components/ui/textarea.js.map +0 -0
  200. /package/{dist/shadcn → shadcn}/components/ui/tooltip.d.ts +0 -0
  201. /package/{dist/shadcn → shadcn}/components/ui/tooltip.js +0 -0
  202. /package/{dist/shadcn → shadcn}/components/ui/tooltip.js.map +0 -0
  203. /package/{dist/shadcn → shadcn}/utils.d.ts +0 -0
  204. /package/{dist/shadcn → shadcn}/utils.js +0 -0
  205. /package/{dist/shadcn → shadcn}/utils.js.map +0 -0
  206. /package/{dist/types → types}/grapesjs-tailwind.d.js +0 -0
  207. /package/{dist/types → types}/grapesjs-tailwind.d.js.map +0 -0
  208. /package/{dist/types → types}/images.d.js +0 -0
  209. /package/{dist/types → types}/images.d.js.map +0 -0
@@ -1,494 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import React, { useEffect, useRef } from 'react';
3
- // eslint-disable-next-line import/no-named-as-default
4
- import grapesjs, { Component, Editor } from 'grapesjs';
5
- import 'grapesjs/dist/css/grapes.min.css';
6
- import tailwind from 'grapesjs-tailwind';
7
- import { TypesToRegister } from './constants';
8
- import { toKebabCase } from './helpers';
9
- import { createGrapesjsShadcnGenericPlugin } from './plugins/grapejs-plugin';
10
- import { StyledEditor } from './index.styles';
11
- import { tailwindCompiledCss } from './helpers/css';
12
- import { datePickerCss } from './helpers/date-picker';
13
-
14
- type NotificationHandler = (newData: {
15
- componentId: string;
16
- newProps: Record<string, any>;
17
- newAttributes: Record<string, any>;
18
- }) => boolean;
19
-
20
- type GrapesjsCanvasProps = {
21
- json: any;
22
- mode?: 'editor' | 'preview';
23
- setEditor: (editor: Editor) => void;
24
- performInteraction: (payload: Record<string, any>) => Promise<Record<string, any> | undefined>;
25
- newDataNotifier: (notifHandler: NotificationHandler) => void;
26
- setHasChanged: (hasChanged: boolean) => void;
27
- isStreaming: boolean;
28
- };
29
-
30
- function setComponentProperties(editor: Editor, isPreview: boolean) {
31
- function setPropertiesRecursively(comp: Component) {
32
- comp.set({
33
- editable: !isPreview,
34
- draggable: !isPreview,
35
- droppable: !isPreview && comp.getName() !== 'Shadcn-generic',
36
- selectable: !isPreview,
37
- hoverable: !isPreview,
38
- highlightable: !isPreview,
39
- copyable: false,
40
- resizable: false,
41
- removable: !isPreview,
42
- badgable: false,
43
- });
44
-
45
- if (!isPreview) {
46
- comp.set('toolbar', [
47
- { attributes: { class: 'fa fa-arrows' }, command: 'tlb-move' },
48
- { attributes: { class: 'fa fa-trash' }, command: 'tlb-delete' },
49
- ]);
50
- }
51
-
52
- comp.components().forEach(setPropertiesRecursively);
53
- }
54
-
55
- if (isPreview) {
56
- editor.runCommand('core:preview');
57
- } else {
58
- editor.stopCommand('core:preview');
59
- }
60
-
61
- const wrapper = editor.getWrapper();
62
- wrapper?.find('*').forEach(setPropertiesRecursively);
63
- }
64
-
65
- function convertStyles(stylesArray: any[]): string {
66
- return stylesArray
67
- .map((block) => {
68
- const selectors = Array.isArray(block.selectors)
69
- ? block.selectors.join(', ')
70
- : block.selectors;
71
- const declarations = Object.entries(block.style)
72
- .map(([prop, value]) => `${toKebabCase(prop)}: ${value};`)
73
- .join(' ');
74
-
75
- return `${selectors} { ${declarations} }`;
76
- })
77
- .join('\n');
78
- }
79
-
80
- function createActionCardConfig(action: any, index?: number): any {
81
- const { icon, title, description } = action;
82
-
83
- return {
84
- type: 'shadcn-generic',
85
- componentName: 'ActionCard',
86
- badgable: false,
87
- copyable: false,
88
- removable: true,
89
- draggable: true,
90
- componentProps: {
91
- icon,
92
- headerContent: title,
93
- bodyContent: description,
94
- },
95
- };
96
- }
97
-
98
- function expandActions(node: any): any {
99
- if (
100
- node.type === 'shadcn-generic' &&
101
- node.componentName === 'Actions'
102
- ) {
103
- const actions = node.componentProps?.actions;
104
-
105
- if (Array.isArray(actions) && actions.length > 0) {
106
- return {
107
- ...node,
108
- type: 'div',
109
- classes: ['dashboard-cards', ...(node.classes || [])],
110
- componentName: undefined,
111
- componentProps: undefined,
112
- components: actions.map((action: any, i: number) => ({
113
- ...createActionCardConfig(action, i),
114
- id: `${node.id}--action-card-${i}`,
115
- })),
116
- };
117
- }
118
-
119
- return node;
120
- }
121
-
122
- if (Array.isArray(node.components)) {
123
- return {
124
- ...node,
125
- components: node.components.map(expandActions),
126
- };
127
- }
128
-
129
- return node;
130
- }
131
-
132
- function setInteracting(
133
- renderedComponents: Record<string, Component>,
134
- components: { componentId: string; showLoader: boolean }[],
135
- inProgress: boolean,
136
- ) {
137
- components.forEach((component) => {
138
- const { componentId, showLoader } = component;
139
-
140
- if (!showLoader) {
141
- return;
142
- }
143
-
144
- const gjsModel = renderedComponents[componentId];
145
-
146
- if (gjsModel) {
147
- gjsModel.set('attributes', {
148
- ...gjsModel.get('attributes'),
149
- interactionApiInProgress: inProgress,
150
- });
151
- }
152
- });
153
- }
154
-
155
- function expandActionsComponent(model: Component, actions: any[]): void {
156
- model.components('');
157
-
158
- actions.forEach((action: any) => {
159
- model.append(createActionCardConfig(action));
160
- });
161
-
162
- model.set('type', 'div');
163
- model.addClass('dashboard-cards');
164
- model.set('componentName', undefined);
165
- model.set('componentProps', {});
166
- }
167
-
168
- function GrapesjsCanvas({
169
- json,
170
- mode = 'preview',
171
- setEditor,
172
- performInteraction,
173
- newDataNotifier = () => {
174
- // no op
175
- },
176
- setHasChanged,
177
- isStreaming,
178
- }: GrapesjsCanvasProps) {
179
- const editorRef = useRef<HTMLDivElement>(null);
180
- const editorInstance = useRef<Editor | null>(null);
181
- const renderedComponents = useRef<Record<string, Component>>({});
182
- const isStreamingRef = useRef(isStreaming);
183
- const isSystemUpdateRef = useRef(false);
184
- const lastJsonRef = useRef<string>('');
185
- const isEditorAliveRef = useRef(false);
186
-
187
- useEffect(() => {
188
- isStreamingRef.current = isStreaming;
189
- }, [isStreaming]);
190
-
191
- function notificationHandler(
192
- props: Parameters<NotificationHandler>[0],
193
- ): ReturnType<NotificationHandler> {
194
- if (!props) {
195
- return true;
196
- }
197
-
198
- const { componentId, newProps = {}, newAttributes = {} } = props;
199
-
200
- const model = renderedComponents.current[componentId];
201
-
202
- if (!model) {
203
- return false;
204
- }
205
-
206
- // Filter out complex placeholder objects that shouldn't be stored in the model, done intentionally to keep grapejs out of errors
207
- const filteredProps = { ...newProps };
208
-
209
- Object.keys(filteredProps).forEach((key) => {
210
- const value = filteredProps[key];
211
-
212
- if (value && typeof value === 'object' && value.name === '__peak_placeholder') {
213
- delete filteredProps[key];
214
- }
215
- });
216
-
217
- const parsedNewProps = {
218
- ...filteredProps,
219
- };
220
-
221
- if (filteredProps.pagination) {
222
- parsedNewProps.pagination = {
223
- ...(model.get('componentProps').pagination || {}),
224
- ...filteredProps.pagination,
225
- };
226
- }
227
-
228
- // Handle Actions component: expand into ActionCards when data arrives via streaming
229
- const isActionsComponent = model.get('componentName') === 'Actions';
230
- const hasValidActionsData = parsedNewProps.actions &&
231
- parsedNewProps.actions !== null &&
232
- Array.isArray(parsedNewProps.actions) &&
233
- parsedNewProps.actions.length > 0;
234
-
235
- if (isActionsComponent && hasValidActionsData) {
236
- const isAlreadyExpanded = model.components().length > 0 &&
237
- model.components().at(0)?.get('componentName') === 'ActionCard';
238
-
239
- if (!isAlreadyExpanded) {
240
- expandActionsComponent(model, parsedNewProps.actions);
241
-
242
- return true;
243
- }
244
- }
245
-
246
- model.set('componentProps', {
247
- ...model.get('componentProps'),
248
- ...parsedNewProps,
249
- });
250
-
251
- model.set('attributes', {
252
- ...model.get('attributes'),
253
- ...newAttributes,
254
- });
255
-
256
- return true;
257
- }
258
-
259
- useEffect(() => {
260
- newDataNotifier(notificationHandler);
261
- }, []);
262
-
263
- async function performInteractionWrapper(payload: Record<string, any>) {
264
- const updatedJson = await editorInstance.current?.store();
265
- setInteracting(renderedComponents.current, payload.affectedComponents, true);
266
-
267
- try {
268
- const apiResponse = await performInteraction({
269
- ...payload,
270
- json: updatedJson,
271
- });
272
-
273
- const componentUpdates = apiResponse || {};
274
-
275
- Object.entries(componentUpdates).forEach(([key, value]) => {
276
- const model = renderedComponents.current[key];
277
-
278
- if (model) {
279
- model.set('attributes', {
280
- ...model.get('attributes'),
281
- error: undefined,
282
- });
283
-
284
- model.set('componentProps', {
285
- ...model.get('componentProps'),
286
- ...value,
287
- error: undefined,
288
- isMissing: undefined,
289
- });
290
- }
291
- });
292
-
293
- return componentUpdates;
294
- } catch (error) {
295
- payload.affectedComponents.forEach((componentId: string) => {
296
- const model = renderedComponents.current[componentId];
297
-
298
- if (model) {
299
- const errorMessage =
300
- error instanceof Error ? error.message : 'Something went wrong. Please try again.';
301
-
302
- model.set('attributes', {
303
- ...model.get('attributes'),
304
- error: errorMessage,
305
- });
306
-
307
- model.set('componentProps', {
308
- ...model.get('componentProps'),
309
- error: errorMessage,
310
- isMissing: undefined,
311
- });
312
- }
313
- });
314
-
315
- throw error;
316
- } finally {
317
- setInteracting(renderedComponents.current, payload.affectedComponents, false);
318
- }
319
- }
320
-
321
- useEffect(() => {
322
- if (!editorRef.current) {
323
- return () => {
324
- // no op
325
- };
326
- }
327
-
328
- if (editorInstance.current) {
329
- editorInstance.current.destroy();
330
- editorInstance.current = null;
331
- isEditorAliveRef.current = false;
332
- }
333
-
334
- const currentMode = mode;
335
-
336
- const editor = grapesjs.init({
337
- container: editorRef.current,
338
- height: '100%',
339
- plugins: [
340
- tailwind,
341
- createGrapesjsShadcnGenericPlugin(
342
- currentMode,
343
- performInteractionWrapper,
344
- renderedComponents.current,
345
- setHasChanged,
346
- ),
347
- ],
348
- storageManager: { type: 'none' },
349
- richTextEditor: {
350
- actions: ['bold', 'italic', 'underline', 'strikethrough'],
351
- },
352
- canvas: {
353
- customBadgeLabel: (component) => {
354
- const tagName = component.get('tagName');
355
-
356
- return tagName === 'body' ? '' : tagName || '';
357
- },
358
- },
359
- });
360
-
361
- isEditorAliveRef.current = true;
362
-
363
- async function checkDirty() {
364
- if (isStreamingRef.current || isSystemUpdateRef.current) {
365
- return;
366
- }
367
-
368
- if (!isEditorAliveRef.current || !editorInstance.current) {
369
- return;
370
- }
371
-
372
- let stored = null;
373
-
374
- try {
375
- stored = await editorInstance.current.store();
376
- } catch (err) {
377
- return;
378
- }
379
-
380
- if (!stored) {
381
- return;
382
- }
383
-
384
- const newJson = JSON.stringify(stored);
385
-
386
- if (newJson !== lastJsonRef.current) {
387
- setHasChanged(true);
388
- lastJsonRef.current = newJson;
389
- }
390
- }
391
-
392
- const debouncedCheckDirty = (() => {
393
- let timeout: NodeJS.Timeout | null = null;
394
-
395
- return () => {
396
- if (timeout) {
397
- clearTimeout(timeout);
398
- }
399
-
400
- timeout = setTimeout(checkDirty, 200);
401
- };
402
- })();
403
-
404
- [
405
- 'component:add',
406
- 'component:remove',
407
- 'component:update:content',
408
- 'style:update',
409
- 'component:drag:end',
410
- 'rte:change',
411
- ].forEach((evt) => editor.on(evt, debouncedCheckDirty));
412
-
413
- editor.on('component:update', (model, prop) => {
414
- if (['attributes', 'componentProps', 'content'].includes(prop)) {
415
- debouncedCheckDirty();
416
- }
417
- });
418
-
419
- // Tailwind CSS rules aren't fully added to our component
420
- // So, adding them from here!
421
- editor.on('load', async () => {
422
- const canvasHead = editor.Canvas.getDocument().head;
423
- const style = document.createElement('style');
424
- const fullCss = `
425
- ${tailwindCompiledCss}
426
- ${datePickerCss}
427
- ::-webkit-scrollbar {
428
- width: 0px;
429
- height: 0px;
430
- }
431
- html, body {
432
- overflow: auto !important;
433
- -ms-overflow-style: none; /* IE and Edge */
434
- scrollbar-width: none; /* Firefox */
435
- }
436
-
437
- `;
438
- style.innerHTML = fullCss;
439
- style.setAttribute('type', 'text/css');
440
- canvasHead.appendChild(style);
441
-
442
- isSystemUpdateRef.current = true;
443
- setComponentProperties(editor, mode === 'preview');
444
- lastJsonRef.current = JSON.stringify(await editor.store());
445
- isSystemUpdateRef.current = false;
446
- });
447
-
448
- editorInstance.current = editor;
449
-
450
- if (setEditor) {
451
- setEditor(editor);
452
- }
453
-
454
- TypesToRegister.forEach(({ type, tagName }) => {
455
- if (!editor.DomComponents.getType(type)) {
456
- editor.DomComponents.addType(type, {
457
- model: {
458
- defaults: { tagName },
459
- },
460
- view: {},
461
- });
462
- }
463
- });
464
-
465
- if (json && json.pages?.length > 0 && json.pages[0].frames?.length > 0) {
466
- isSystemUpdateRef.current = true;
467
- const raw = json.pages[0].frames[0].component;
468
- const processed = expandActions(raw);
469
- editor.setComponents(processed);
470
-
471
- const cssText = convertStyles(json.styles || []);
472
- editor.setStyle(cssText);
473
-
474
- editor.on('load', async () => {
475
- lastJsonRef.current = JSON.stringify(await editor.store());
476
- isSystemUpdateRef.current = false;
477
- });
478
- }
479
-
480
- return function cleanup() {
481
- editor.destroy();
482
- isEditorAliveRef.current = false;
483
- };
484
- }, [json, mode]);
485
-
486
- return (
487
- <React.Fragment>
488
- <StyledEditor />
489
- <div ref={editorRef} id="grapesjs-editor" />
490
- </React.Fragment>
491
- );
492
- }
493
-
494
- export default GrapesjsCanvas;
@@ -1,25 +0,0 @@
1
- export const TypesToRegister = [
2
- { tagName: 'div', type: 'div' },
3
- { tagName: 'h1', type: 'heading' },
4
- { tagName: 'p', type: 'text' },
5
- { tagName: 'div', type: 'container' },
6
- { tagName: 'div', type: 'grid' },
7
- { tagName: 'table', type: 'table' },
8
- { tagName: 'thead', type: 'thead' },
9
- { tagName: 'tbody', type: 'tbody' },
10
- { tagName: 'tr', type: 'tr' },
11
- { tagName: 'th', type: 'th' },
12
- { tagName: 'td', type: 'td' },
13
- { tagName: 'button', type: 'button' },
14
- { tagName: 'section', type: 'section' },
15
- { tagName: 'a', type: 'link' },
16
- { tagName: 'form', type: 'form' },
17
- { tagName: 'input', type: 'input' },
18
- { tagName: 'textarea', type: 'textarea' },
19
- { tagName: 'select', type: 'select' },
20
- { tagName: 'ul', type: 'ul' },
21
- { tagName: 'ol', type: 'ol' },
22
- { tagName: 'li', type: 'li' },
23
- { tagName: 'header', type: 'header' },
24
- { tagName: 'footer', type: 'footer' },
25
- ];
@@ -1 +0,0 @@
1
- declare module '*.gif';