@peak-ai/canvas 1.4.11 → 1.4.12-rc.12

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 (184) hide show
  1. package/package.json +6 -44
  2. package/plugins/helpers/styled-info-button.js +2 -0
  3. package/plugins/helpers/styled-info-button.js.map +1 -0
  4. package/.babelrc +0 -14
  5. package/.eslintcache +0 -1
  6. package/.eslintignore +0 -5
  7. package/.eslintrc.js +0 -29
  8. package/dist/package.json +0 -62
  9. package/dist/plugins/helpers/styled-info-button.js +0 -2
  10. package/dist/plugins/helpers/styled-info-button.js.map +0 -1
  11. package/scripts/build.ts +0 -88
  12. package/src/GrapesjsCanvas.tsx +0 -340
  13. package/src/constants/index.ts +0 -27
  14. package/src/helpers/compiled-table.css +0 -2429
  15. package/src/helpers/css.ts +0 -2515
  16. package/src/helpers/date-picker.ts +0 -807
  17. package/src/helpers/index.ts +0 -13
  18. package/src/helpers/merge-json.ts +0 -106
  19. package/src/index.styles.ts +0 -58
  20. package/src/index.ts +0 -9
  21. package/src/plugins/grapejs-plugin.tsx +0 -139
  22. package/src/plugins/helpers/custom-modal.tsx +0 -111
  23. package/src/plugins/helpers/data-table.tsx +0 -300
  24. package/src/plugins/helpers/extra.tsx +0 -164
  25. package/src/plugins/helpers/query-details-modal.tsx +0 -240
  26. package/src/plugins/helpers/query-loading-modal.tsx +0 -36
  27. package/src/plugins/helpers/render-components.tsx +0 -1211
  28. package/src/plugins/helpers/styled-info-button.tsx +0 -320
  29. package/src/public/canvas.css +0 -42
  30. package/src/public/components-css/table/table-output.css +0 -2436
  31. package/src/public/components-css/table/table.css +0 -30
  32. package/src/public/output.css +0 -2336
  33. package/src/public/table.css +0 -135
  34. package/src/shadcn/components/icons/AiAvatarIcon.tsx +0 -47
  35. package/src/shadcn/components/icons/Co_driver Expanding button copy.svg +0 -21
  36. package/src/shadcn/components/icons/ai-avatar.svg +0 -7
  37. package/src/shadcn/components/icons/thinking.gif +0 -0
  38. package/src/shadcn/components/ui/button.tsx +0 -132
  39. package/src/shadcn/components/ui/card.tsx +0 -92
  40. package/src/shadcn/components/ui/chart.tsx +0 -324
  41. package/src/shadcn/components/ui/checkbox.tsx +0 -27
  42. package/src/shadcn/components/ui/component-wrapper.tsx +0 -61
  43. package/src/shadcn/components/ui/date-filter.tsx +0 -816
  44. package/src/shadcn/components/ui/error-container.tsx +0 -125
  45. package/src/shadcn/components/ui/error-wrapper.tsx +0 -124
  46. package/src/shadcn/components/ui/filter.tsx +0 -366
  47. package/src/shadcn/components/ui/hover-card.tsx +0 -36
  48. package/src/shadcn/components/ui/input.tsx +0 -20
  49. package/src/shadcn/components/ui/label.tsx +0 -24
  50. package/src/shadcn/components/ui/pagination.tsx +0 -213
  51. package/src/shadcn/components/ui/scroll-area.tsx +0 -59
  52. package/src/shadcn/components/ui/search.tsx +0 -149
  53. package/src/shadcn/components/ui/separator.tsx +0 -26
  54. package/src/shadcn/components/ui/skeleton.tsx +0 -69
  55. package/src/shadcn/components/ui/table.tsx +0 -196
  56. package/src/shadcn/components/ui/tabs.tsx +0 -55
  57. package/src/shadcn/components/ui/textarea.tsx +0 -18
  58. package/src/shadcn/components/ui/tooltip.tsx +0 -87
  59. package/src/shadcn/utils.ts +0 -6
  60. package/src/types/grapesjs-tailwind.d.ts +0 -61
  61. package/tailwind.config.js +0 -5
  62. package/tooling/tailwind-compiler/index.js +0 -99
  63. package/tooling/tailwind-compiler/package.json +0 -11
  64. package/tooling/tailwind-compiler/yarn.lock +0 -123
  65. package/tsconfig.build.json +0 -15
  66. package/tsconfig.json +0 -8
  67. /package/{dist/GrapesjsCanvas.d.ts → GrapesjsCanvas.d.ts} +0 -0
  68. /package/{dist/GrapesjsCanvas.js → GrapesjsCanvas.js} +0 -0
  69. /package/{dist/GrapesjsCanvas.js.map → GrapesjsCanvas.js.map} +0 -0
  70. /package/{dist/constants → constants}/index.d.ts +0 -0
  71. /package/{dist/constants → constants}/index.js +0 -0
  72. /package/{dist/constants → constants}/index.js.map +0 -0
  73. /package/{dist/helpers → helpers}/compiled-table.css +0 -0
  74. /package/{dist/helpers → helpers}/css.d.ts +0 -0
  75. /package/{dist/helpers → helpers}/css.js +0 -0
  76. /package/{dist/helpers → helpers}/css.js.map +0 -0
  77. /package/{dist/helpers → helpers}/date-picker.d.ts +0 -0
  78. /package/{dist/helpers → helpers}/date-picker.js +0 -0
  79. /package/{dist/helpers → helpers}/date-picker.js.map +0 -0
  80. /package/{dist/helpers → helpers}/index.d.ts +0 -0
  81. /package/{dist/helpers → helpers}/index.js +0 -0
  82. /package/{dist/helpers → helpers}/index.js.map +0 -0
  83. /package/{dist/helpers → helpers}/merge-json.d.ts +0 -0
  84. /package/{dist/helpers → helpers}/merge-json.js +0 -0
  85. /package/{dist/helpers → helpers}/merge-json.js.map +0 -0
  86. /package/{dist/index.d.ts → index.d.ts} +0 -0
  87. /package/{dist/index.js → index.js} +0 -0
  88. /package/{dist/index.js.map → index.js.map} +0 -0
  89. /package/{dist/index.styles.d.ts → index.styles.d.ts} +0 -0
  90. /package/{dist/index.styles.js → index.styles.js} +0 -0
  91. /package/{dist/index.styles.js.map → index.styles.js.map} +0 -0
  92. /package/{dist/plugins → plugins}/grapejs-plugin.d.ts +0 -0
  93. /package/{dist/plugins → plugins}/grapejs-plugin.js +0 -0
  94. /package/{dist/plugins → plugins}/grapejs-plugin.js.map +0 -0
  95. /package/{dist/plugins → plugins}/helpers/custom-modal.d.ts +0 -0
  96. /package/{dist/plugins → plugins}/helpers/custom-modal.js +0 -0
  97. /package/{dist/plugins → plugins}/helpers/custom-modal.js.map +0 -0
  98. /package/{dist/plugins → plugins}/helpers/data-table.d.ts +0 -0
  99. /package/{dist/plugins → plugins}/helpers/data-table.js +0 -0
  100. /package/{dist/plugins → plugins}/helpers/data-table.js.map +0 -0
  101. /package/{dist/plugins → plugins}/helpers/extra.d.ts +0 -0
  102. /package/{dist/plugins → plugins}/helpers/extra.js +0 -0
  103. /package/{dist/plugins → plugins}/helpers/extra.js.map +0 -0
  104. /package/{dist/plugins → plugins}/helpers/query-details-modal.d.ts +0 -0
  105. /package/{dist/plugins → plugins}/helpers/query-details-modal.js +0 -0
  106. /package/{dist/plugins → plugins}/helpers/query-details-modal.js.map +0 -0
  107. /package/{dist/plugins → plugins}/helpers/query-loading-modal.d.ts +0 -0
  108. /package/{dist/plugins → plugins}/helpers/query-loading-modal.js +0 -0
  109. /package/{dist/plugins → plugins}/helpers/query-loading-modal.js.map +0 -0
  110. /package/{dist/plugins → plugins}/helpers/render-components.d.ts +0 -0
  111. /package/{dist/plugins → plugins}/helpers/render-components.js +0 -0
  112. /package/{dist/plugins → plugins}/helpers/render-components.js.map +0 -0
  113. /package/{dist/plugins → plugins}/helpers/styled-info-button.d.ts +0 -0
  114. /package/{dist/shadcn → shadcn}/components/icons/AiAvatarIcon.d.ts +0 -0
  115. /package/{dist/shadcn → shadcn}/components/icons/AiAvatarIcon.js +0 -0
  116. /package/{dist/shadcn → shadcn}/components/icons/AiAvatarIcon.js.map +0 -0
  117. /package/{dist/shadcn → shadcn}/components/ui/button.d.ts +0 -0
  118. /package/{dist/shadcn → shadcn}/components/ui/button.js +0 -0
  119. /package/{dist/shadcn → shadcn}/components/ui/button.js.map +0 -0
  120. /package/{dist/shadcn → shadcn}/components/ui/card.d.ts +0 -0
  121. /package/{dist/shadcn → shadcn}/components/ui/card.js +0 -0
  122. /package/{dist/shadcn → shadcn}/components/ui/card.js.map +0 -0
  123. /package/{dist/shadcn → shadcn}/components/ui/chart.d.ts +0 -0
  124. /package/{dist/shadcn → shadcn}/components/ui/chart.js +0 -0
  125. /package/{dist/shadcn → shadcn}/components/ui/chart.js.map +0 -0
  126. /package/{dist/shadcn → shadcn}/components/ui/checkbox.d.ts +0 -0
  127. /package/{dist/shadcn → shadcn}/components/ui/checkbox.js +0 -0
  128. /package/{dist/shadcn → shadcn}/components/ui/checkbox.js.map +0 -0
  129. /package/{dist/shadcn → shadcn}/components/ui/component-wrapper.d.ts +0 -0
  130. /package/{dist/shadcn → shadcn}/components/ui/component-wrapper.js +0 -0
  131. /package/{dist/shadcn → shadcn}/components/ui/component-wrapper.js.map +0 -0
  132. /package/{dist/shadcn → shadcn}/components/ui/date-filter.d.ts +0 -0
  133. /package/{dist/shadcn → shadcn}/components/ui/date-filter.js +0 -0
  134. /package/{dist/shadcn → shadcn}/components/ui/date-filter.js.map +0 -0
  135. /package/{dist/shadcn → shadcn}/components/ui/error-container.d.ts +0 -0
  136. /package/{dist/shadcn → shadcn}/components/ui/error-container.js +0 -0
  137. /package/{dist/shadcn → shadcn}/components/ui/error-container.js.map +0 -0
  138. /package/{dist/shadcn → shadcn}/components/ui/error-wrapper.d.ts +0 -0
  139. /package/{dist/shadcn → shadcn}/components/ui/error-wrapper.js +0 -0
  140. /package/{dist/shadcn → shadcn}/components/ui/error-wrapper.js.map +0 -0
  141. /package/{dist/shadcn → shadcn}/components/ui/filter.d.ts +0 -0
  142. /package/{dist/shadcn → shadcn}/components/ui/filter.js +0 -0
  143. /package/{dist/shadcn → shadcn}/components/ui/filter.js.map +0 -0
  144. /package/{dist/shadcn → shadcn}/components/ui/hover-card.d.ts +0 -0
  145. /package/{dist/shadcn → shadcn}/components/ui/hover-card.js +0 -0
  146. /package/{dist/shadcn → shadcn}/components/ui/hover-card.js.map +0 -0
  147. /package/{dist/shadcn → shadcn}/components/ui/input.d.ts +0 -0
  148. /package/{dist/shadcn → shadcn}/components/ui/input.js +0 -0
  149. /package/{dist/shadcn → shadcn}/components/ui/input.js.map +0 -0
  150. /package/{dist/shadcn → shadcn}/components/ui/label.d.ts +0 -0
  151. /package/{dist/shadcn → shadcn}/components/ui/label.js +0 -0
  152. /package/{dist/shadcn → shadcn}/components/ui/label.js.map +0 -0
  153. /package/{dist/shadcn → shadcn}/components/ui/pagination.d.ts +0 -0
  154. /package/{dist/shadcn → shadcn}/components/ui/pagination.js +0 -0
  155. /package/{dist/shadcn → shadcn}/components/ui/pagination.js.map +0 -0
  156. /package/{dist/shadcn → shadcn}/components/ui/scroll-area.d.ts +0 -0
  157. /package/{dist/shadcn → shadcn}/components/ui/scroll-area.js +0 -0
  158. /package/{dist/shadcn → shadcn}/components/ui/scroll-area.js.map +0 -0
  159. /package/{dist/shadcn → shadcn}/components/ui/search.d.ts +0 -0
  160. /package/{dist/shadcn → shadcn}/components/ui/search.js +0 -0
  161. /package/{dist/shadcn → shadcn}/components/ui/search.js.map +0 -0
  162. /package/{dist/shadcn → shadcn}/components/ui/separator.d.ts +0 -0
  163. /package/{dist/shadcn → shadcn}/components/ui/separator.js +0 -0
  164. /package/{dist/shadcn → shadcn}/components/ui/separator.js.map +0 -0
  165. /package/{dist/shadcn → shadcn}/components/ui/skeleton.d.ts +0 -0
  166. /package/{dist/shadcn → shadcn}/components/ui/skeleton.js +0 -0
  167. /package/{dist/shadcn → shadcn}/components/ui/skeleton.js.map +0 -0
  168. /package/{dist/shadcn → shadcn}/components/ui/table.d.ts +0 -0
  169. /package/{dist/shadcn → shadcn}/components/ui/table.js +0 -0
  170. /package/{dist/shadcn → shadcn}/components/ui/table.js.map +0 -0
  171. /package/{dist/shadcn → shadcn}/components/ui/tabs.d.ts +0 -0
  172. /package/{dist/shadcn → shadcn}/components/ui/tabs.js +0 -0
  173. /package/{dist/shadcn → shadcn}/components/ui/tabs.js.map +0 -0
  174. /package/{dist/shadcn → shadcn}/components/ui/textarea.d.ts +0 -0
  175. /package/{dist/shadcn → shadcn}/components/ui/textarea.js +0 -0
  176. /package/{dist/shadcn → shadcn}/components/ui/textarea.js.map +0 -0
  177. /package/{dist/shadcn → shadcn}/components/ui/tooltip.d.ts +0 -0
  178. /package/{dist/shadcn → shadcn}/components/ui/tooltip.js +0 -0
  179. /package/{dist/shadcn → shadcn}/components/ui/tooltip.js.map +0 -0
  180. /package/{dist/shadcn → shadcn}/utils.d.ts +0 -0
  181. /package/{dist/shadcn → shadcn}/utils.js +0 -0
  182. /package/{dist/shadcn → shadcn}/utils.js.map +0 -0
  183. /package/{dist/types → types}/grapesjs-tailwind.d.js +0 -0
  184. /package/{dist/types → types}/grapesjs-tailwind.d.js.map +0 -0
package/scripts/build.ts DELETED
@@ -1,88 +0,0 @@
1
- #!/usr/bin/env node
2
- /* eslint-disable @typescript-eslint/no-var-requires */
3
- const path = require('path');
4
- const fs = require('fs');
5
- const { execSync } = require('child_process');
6
-
7
- // CommonJS always has __dirname defined already
8
- console.log('Building canvas-ui-toolkit...');
9
-
10
- const distDir = path.join(__dirname, '../dist');
11
-
12
- try {
13
- // Clean dist directory
14
- console.log('Cleaning dist directory...');
15
- fs.rmSync(distDir, { recursive: true, force: true });
16
- fs.mkdirSync(distDir, { recursive: true });
17
-
18
- // Generate TypeScript declarations
19
- console.log('Generating TypeScript declarations...');
20
- execSync('tsc --project tsconfig.build.json --emitDeclarationOnly', { stdio: 'inherit' });
21
-
22
- // Transpile with Babel
23
- console.log('Transpiling with Babel...');
24
- execSync(
25
- 'babel src --out-dir dist --extensions ".ts,.tsx" --ignore "**/*.stories.tsx,**/__tests__/*,**/*.test.ts,**/*.test.tsx" --source-maps --minified',
26
- { stdio: 'inherit' },
27
- );
28
-
29
- // Copy README.md
30
- console.log('Copying README.md...');
31
- const readmeSrc = path.join(__dirname, '../README.md');
32
- const readmeDest = path.join(distDir, 'README.md');
33
- if (fs.existsSync(readmeSrc)) {
34
- fs.copyFileSync(readmeSrc, readmeDest);
35
- }
36
-
37
- // Copy compiled table.css file
38
- console.log('Copying compiled-table.css file...');
39
- const copyTableCss = (source: string, destination: string): void => {
40
- if (fs.existsSync(source)) {
41
- if (fs.statSync(source).isDirectory()) {
42
- if (!fs.existsSync(destination)) {
43
- fs.mkdirSync(destination, { recursive: true });
44
- }
45
- fs.readdirSync(source).forEach((file: string) => {
46
- const srcPath = path.join(source, file);
47
- const destPath = path.join(destination, file);
48
- copyTableCss(srcPath, destPath);
49
- });
50
- } else if (source.endsWith('compiled-table.css')) {
51
- const destDir = path.dirname(destination);
52
- if (!fs.existsSync(destDir)) {
53
- fs.mkdirSync(destDir, { recursive: true });
54
- }
55
- fs.copyFileSync(source, destination);
56
- }
57
- }
58
- };
59
- copyTableCss(path.join(__dirname, '../src'), distDir);
60
-
61
- // Copy and clean package.json
62
- console.log('Preparing package.json...');
63
- const packageJsonPath = path.join(__dirname, '../package.json');
64
- const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
65
-
66
- delete pkg.devDependencies;
67
- delete pkg.files;
68
- delete pkg.scripts;
69
-
70
- pkg.main = 'index.js';
71
- pkg.types = 'index.d.ts';
72
- pkg.module = 'index.js';
73
- pkg.sideEffects = false;
74
-
75
- fs.writeFileSync(path.join(distDir, 'package.json'), JSON.stringify(pkg, null, 2));
76
-
77
- const npmrcSrc = path.join(__dirname, '../.npmrc');
78
- const npmrcDest = path.join(distDir, '.npmrc');
79
-
80
- if (fs.existsSync(npmrcSrc)) {
81
- fs.copyFileSync(npmrcSrc, npmrcDest);
82
- }
83
-
84
- console.log('Build completed successfully! ✨');
85
- } catch (err) {
86
- console.error('Build failed:', err);
87
- process.exit(1);
88
- }
@@ -1,340 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import React, { useEffect, useRef, useState } 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
-
21
- type GrapesjsCanvasProps = {
22
- json: any;
23
- mode?: 'editor' | 'preview';
24
- setEditor: (editor: Editor) => void;
25
- performInteraction: (payload: Record<string, any>) => Promise<Record<string, any> | undefined>;
26
- newDataNotifier: (notifHandler: NotificationHandler) => void;
27
- };
28
-
29
- function setComponentProperties(editor: Editor, isPreview: boolean) {
30
- function setPropertiesRecursively(comp: Component) {
31
- comp.set({
32
- editable: !isPreview,
33
- draggable: !isPreview,
34
- droppable: !isPreview && comp.getName() !== 'Shadcn-generic',
35
- selectable: !isPreview,
36
- hoverable: !isPreview,
37
- highlightable: !isPreview,
38
- copyable: false,
39
- resizable: false,
40
- removable: !isPreview,
41
- badgable: false,
42
- });
43
-
44
- if (!isPreview) {
45
- comp.set('toolbar', [
46
- { attributes: { class: 'fa fa-arrows' }, command: 'tlb-move' },
47
- { attributes: { class: 'fa fa-trash' }, command: 'tlb-delete' },
48
- ]);
49
- }
50
-
51
- comp.components().forEach(setPropertiesRecursively);
52
- }
53
-
54
- if (isPreview) {
55
- editor.runCommand('core:preview');
56
- } else {
57
- editor.stopCommand('core:preview');
58
- }
59
-
60
- const wrapper = editor.getWrapper();
61
- wrapper?.find('*').forEach(setPropertiesRecursively);
62
- }
63
-
64
- function convertStyles(stylesArray: any[]): string {
65
- return stylesArray
66
- .map((block) => {
67
- const selectors = Array.isArray(block.selectors)
68
- ? block.selectors.join(', ')
69
- : block.selectors;
70
- const declarations = Object.entries(block.style)
71
- .map(([prop, value]) => `${toKebabCase(prop)}: ${value};`)
72
- .join(' ');
73
-
74
- return `${selectors} { ${declarations} }`;
75
- })
76
- .join('\n');
77
- }
78
-
79
- function expandActions(node: any): any {
80
- if (
81
- node.type === 'shadcn-generic' &&
82
- node.componentName === 'Actions' &&
83
- Array.isArray(node.componentProps?.actions)
84
- ) {
85
- const { actions } = node.componentProps;
86
-
87
- return {
88
- ...node,
89
- type: 'div',
90
- classes: ['dashboard-cards', ...(node.classes || [])],
91
- componentName: undefined,
92
- componentProps: undefined,
93
- components: actions.map((action: any, i: number) => {
94
- const { icon, title, description } = action;
95
-
96
- return {
97
- id: `${node.id}--action-card-${i}`,
98
- type: 'shadcn-generic',
99
- componentName: 'ActionCard',
100
- badgable: false,
101
- copyable: false,
102
- componentProps: {
103
- icon,
104
- headerContent: title,
105
- bodyContent: description,
106
- },
107
- };
108
- }),
109
- };
110
- }
111
-
112
- if (Array.isArray(node.components)) {
113
- return {
114
- ...node,
115
- components: node.components.map(expandActions),
116
- };
117
- }
118
-
119
- return node;
120
- }
121
-
122
- function setInteracting(
123
- renderedComponents: Record<string, Component>,
124
- components: { componentId: string; showLoader: boolean }[],
125
- inProgress: boolean,
126
- ) {
127
- components.forEach((component) => {
128
- const { componentId, showLoader } = component;
129
-
130
- if (!showLoader) {
131
- return;
132
- }
133
-
134
- const gjsModel = renderedComponents[componentId];
135
-
136
- if (gjsModel) {
137
- gjsModel.set('attributes', {
138
- ...gjsModel.get('attributes'),
139
- interactionApiInProgress: inProgress,
140
- });
141
- }
142
- });
143
- }
144
-
145
- function GrapesjsCanvas({
146
- json,
147
- mode = 'preview',
148
- setEditor,
149
- performInteraction,
150
- newDataNotifier = () => {
151
- // Default empty handler
152
- },
153
- }: GrapesjsCanvasProps) {
154
- const editorRef = useRef<HTMLDivElement>(null);
155
- const editorInstance = useRef<any>(null);
156
- const renderedComponents: Record<string, Component> = {};
157
-
158
- function notificationHandler(props: Parameters<NotificationHandler>[0]): ReturnType<NotificationHandler> {
159
- if (!props) {
160
- return true;
161
- }
162
-
163
- const {
164
- componentId,
165
- newProps,
166
- newAttributes,
167
- } = props;
168
-
169
- const model = renderedComponents[componentId];
170
-
171
- if (!model) {
172
- return false;
173
- }
174
-
175
- const parsedNewProps = {
176
- ...newProps,
177
- };
178
-
179
- if (newProps.pagination) {
180
- parsedNewProps.pagination = {
181
- ...(model.get('componentProps').pagination || {}),
182
- ...newProps.pagination,
183
- }
184
- }
185
-
186
- model.set('componentProps', {
187
- ...model.get('componentProps'),
188
- ...parsedNewProps,
189
- });
190
-
191
- model.set('attributes', {
192
- ...model.get('attributes'),
193
- ...newAttributes,
194
- });
195
- return true;
196
- }
197
-
198
-
199
-
200
- useEffect(() => {
201
- newDataNotifier(notificationHandler);
202
- }, []);
203
-
204
-
205
- async function performInteractionWrapper(payload: Record<string, any>) {
206
- const updatedJson = await editorInstance.current?.store();
207
- setInteracting(renderedComponents, payload.affectedComponents, true);
208
-
209
- try {
210
- const apiResponse = await performInteraction({
211
- ...payload,
212
- json: updatedJson,
213
- });
214
-
215
- const componentUpdates = apiResponse || {};
216
-
217
- Object.entries(componentUpdates).forEach(([key, value]) => {
218
- const model = renderedComponents[key];
219
-
220
- if (model) {
221
- model.set('componentProps', {
222
- ...model.get('componentProps'),
223
- ...value,
224
- });
225
- }
226
- });
227
-
228
- return componentUpdates;
229
- } finally {
230
- setInteracting(renderedComponents, payload.affectedComponents, false);
231
- }
232
- }
233
-
234
-
235
- useEffect(() => {
236
- if (!editorRef.current) {
237
- return function cleanup() {
238
- // Cleanup if editorRef is not available
239
- };
240
- }
241
-
242
- if (editorInstance.current) {
243
- editorInstance.current.destroy();
244
- editorInstance.current = null;
245
- }
246
-
247
- const currentMode = mode;
248
-
249
- const editor = grapesjs.init({
250
- container: editorRef.current,
251
- height: '100%',
252
- plugins: [
253
- tailwind,
254
- createGrapesjsShadcnGenericPlugin(
255
- currentMode,
256
- performInteractionWrapper,
257
- renderedComponents,
258
- ),
259
- ],
260
- storageManager: { type: 'none' },
261
- richTextEditor: {
262
- actions: ['bold', 'italic', 'underline', 'strikethrough'],
263
- },
264
- canvas: {
265
- customBadgeLabel: (component) => {
266
- const tagName = component.get('tagName');
267
-
268
- return tagName === 'body' ? '' : tagName || '';
269
- },
270
- },
271
- });
272
-
273
- // Tailwind CSS rules aren't fully added to our component
274
- // So, adding them from here!
275
- editor.on('load', () => {
276
- const canvasHead = editor.Canvas.getDocument().head;
277
- const style = document.createElement('style');
278
- const fullCss = `
279
- ${tailwindCompiledCss}
280
- ${datePickerCss}
281
- ::-webkit-scrollbar {
282
- width: 0px;
283
- height: 0px;
284
- }
285
- html, body {
286
- overflow: auto !important;
287
- -ms-overflow-style: none; /* IE and Edge */
288
- scrollbar-width: none; /* Firefox */
289
- }
290
-
291
- `;
292
- style.innerHTML = fullCss;
293
- style.setAttribute('type', 'text/css');
294
- canvasHead.appendChild(style);
295
- });
296
-
297
- editorInstance.current = editor;
298
-
299
- if (setEditor) {
300
- setEditor(editor);
301
- }
302
-
303
- TypesToRegister.forEach(({ type, tagName }) => {
304
- if (!editor.DomComponents.getType(type)) {
305
- editor.DomComponents.addType(type, {
306
- model: {
307
- defaults: { tagName },
308
- },
309
- view: {},
310
- });
311
- }
312
- });
313
-
314
- if (json && json.pages?.length > 0 && json.pages[0].frames?.length > 0) {
315
- const raw = json.pages[0].frames[0].component;
316
- const processed = expandActions(raw);
317
- editor.setComponents(processed);
318
-
319
- const cssText = convertStyles(json.styles || []);
320
- editor.setStyle(cssText);
321
- }
322
-
323
- editor.on('load', () => {
324
- setComponentProperties(editor, mode === 'preview');
325
- });
326
-
327
- return function cleanup() {
328
- editor.destroy();
329
- };
330
- }, [json, mode]);
331
-
332
- return (
333
- <React.Fragment>
334
- <StyledEditor />
335
- <div ref={editorRef} id="grapesjs-editor" />
336
- </React.Fragment>
337
- );
338
- }
339
-
340
- export default GrapesjsCanvas;
@@ -1,27 +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: 'img', type: 'image' },
16
- { tagName: 'a', type: 'link' },
17
- { tagName: 'video', type: 'video' },
18
- { tagName: 'form', type: 'form' },
19
- { tagName: 'input', type: 'input' },
20
- { tagName: 'textarea', type: 'textarea' },
21
- { tagName: 'select', type: 'select' },
22
- { tagName: 'ul', type: 'ul' },
23
- { tagName: 'ol', type: 'ol' },
24
- { tagName: 'li', type: 'li' },
25
- { tagName: 'header', type: 'header' },
26
- { tagName: 'footer', type: 'footer' },
27
- ];