@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.
- package/package.json +6 -44
- package/plugins/helpers/styled-info-button.js +2 -0
- package/plugins/helpers/styled-info-button.js.map +1 -0
- package/.babelrc +0 -14
- package/.eslintcache +0 -1
- package/.eslintignore +0 -5
- package/.eslintrc.js +0 -29
- package/dist/package.json +0 -62
- package/dist/plugins/helpers/styled-info-button.js +0 -2
- package/dist/plugins/helpers/styled-info-button.js.map +0 -1
- package/scripts/build.ts +0 -88
- package/src/GrapesjsCanvas.tsx +0 -340
- package/src/constants/index.ts +0 -27
- package/src/helpers/compiled-table.css +0 -2429
- package/src/helpers/css.ts +0 -2515
- package/src/helpers/date-picker.ts +0 -807
- package/src/helpers/index.ts +0 -13
- package/src/helpers/merge-json.ts +0 -106
- package/src/index.styles.ts +0 -58
- package/src/index.ts +0 -9
- package/src/plugins/grapejs-plugin.tsx +0 -139
- package/src/plugins/helpers/custom-modal.tsx +0 -111
- package/src/plugins/helpers/data-table.tsx +0 -300
- package/src/plugins/helpers/extra.tsx +0 -164
- package/src/plugins/helpers/query-details-modal.tsx +0 -240
- package/src/plugins/helpers/query-loading-modal.tsx +0 -36
- package/src/plugins/helpers/render-components.tsx +0 -1211
- package/src/plugins/helpers/styled-info-button.tsx +0 -320
- package/src/public/canvas.css +0 -42
- package/src/public/components-css/table/table-output.css +0 -2436
- package/src/public/components-css/table/table.css +0 -30
- package/src/public/output.css +0 -2336
- package/src/public/table.css +0 -135
- package/src/shadcn/components/icons/AiAvatarIcon.tsx +0 -47
- package/src/shadcn/components/icons/Co_driver Expanding button copy.svg +0 -21
- package/src/shadcn/components/icons/ai-avatar.svg +0 -7
- package/src/shadcn/components/icons/thinking.gif +0 -0
- package/src/shadcn/components/ui/button.tsx +0 -132
- package/src/shadcn/components/ui/card.tsx +0 -92
- package/src/shadcn/components/ui/chart.tsx +0 -324
- package/src/shadcn/components/ui/checkbox.tsx +0 -27
- package/src/shadcn/components/ui/component-wrapper.tsx +0 -61
- package/src/shadcn/components/ui/date-filter.tsx +0 -816
- package/src/shadcn/components/ui/error-container.tsx +0 -125
- package/src/shadcn/components/ui/error-wrapper.tsx +0 -124
- package/src/shadcn/components/ui/filter.tsx +0 -366
- package/src/shadcn/components/ui/hover-card.tsx +0 -36
- package/src/shadcn/components/ui/input.tsx +0 -20
- package/src/shadcn/components/ui/label.tsx +0 -24
- package/src/shadcn/components/ui/pagination.tsx +0 -213
- package/src/shadcn/components/ui/scroll-area.tsx +0 -59
- package/src/shadcn/components/ui/search.tsx +0 -149
- package/src/shadcn/components/ui/separator.tsx +0 -26
- package/src/shadcn/components/ui/skeleton.tsx +0 -69
- package/src/shadcn/components/ui/table.tsx +0 -196
- package/src/shadcn/components/ui/tabs.tsx +0 -55
- package/src/shadcn/components/ui/textarea.tsx +0 -18
- package/src/shadcn/components/ui/tooltip.tsx +0 -87
- package/src/shadcn/utils.ts +0 -6
- package/src/types/grapesjs-tailwind.d.ts +0 -61
- package/tailwind.config.js +0 -5
- package/tooling/tailwind-compiler/index.js +0 -99
- package/tooling/tailwind-compiler/package.json +0 -11
- package/tooling/tailwind-compiler/yarn.lock +0 -123
- package/tsconfig.build.json +0 -15
- package/tsconfig.json +0 -8
- /package/{dist/GrapesjsCanvas.d.ts → GrapesjsCanvas.d.ts} +0 -0
- /package/{dist/GrapesjsCanvas.js → GrapesjsCanvas.js} +0 -0
- /package/{dist/GrapesjsCanvas.js.map → GrapesjsCanvas.js.map} +0 -0
- /package/{dist/constants → constants}/index.d.ts +0 -0
- /package/{dist/constants → constants}/index.js +0 -0
- /package/{dist/constants → constants}/index.js.map +0 -0
- /package/{dist/helpers → helpers}/compiled-table.css +0 -0
- /package/{dist/helpers → helpers}/css.d.ts +0 -0
- /package/{dist/helpers → helpers}/css.js +0 -0
- /package/{dist/helpers → helpers}/css.js.map +0 -0
- /package/{dist/helpers → helpers}/date-picker.d.ts +0 -0
- /package/{dist/helpers → helpers}/date-picker.js +0 -0
- /package/{dist/helpers → helpers}/date-picker.js.map +0 -0
- /package/{dist/helpers → helpers}/index.d.ts +0 -0
- /package/{dist/helpers → helpers}/index.js +0 -0
- /package/{dist/helpers → helpers}/index.js.map +0 -0
- /package/{dist/helpers → helpers}/merge-json.d.ts +0 -0
- /package/{dist/helpers → helpers}/merge-json.js +0 -0
- /package/{dist/helpers → helpers}/merge-json.js.map +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/index.js.map → index.js.map} +0 -0
- /package/{dist/index.styles.d.ts → index.styles.d.ts} +0 -0
- /package/{dist/index.styles.js → index.styles.js} +0 -0
- /package/{dist/index.styles.js.map → index.styles.js.map} +0 -0
- /package/{dist/plugins → plugins}/grapejs-plugin.d.ts +0 -0
- /package/{dist/plugins → plugins}/grapejs-plugin.js +0 -0
- /package/{dist/plugins → plugins}/grapejs-plugin.js.map +0 -0
- /package/{dist/plugins → plugins}/helpers/custom-modal.d.ts +0 -0
- /package/{dist/plugins → plugins}/helpers/custom-modal.js +0 -0
- /package/{dist/plugins → plugins}/helpers/custom-modal.js.map +0 -0
- /package/{dist/plugins → plugins}/helpers/data-table.d.ts +0 -0
- /package/{dist/plugins → plugins}/helpers/data-table.js +0 -0
- /package/{dist/plugins → plugins}/helpers/data-table.js.map +0 -0
- /package/{dist/plugins → plugins}/helpers/extra.d.ts +0 -0
- /package/{dist/plugins → plugins}/helpers/extra.js +0 -0
- /package/{dist/plugins → plugins}/helpers/extra.js.map +0 -0
- /package/{dist/plugins → plugins}/helpers/query-details-modal.d.ts +0 -0
- /package/{dist/plugins → plugins}/helpers/query-details-modal.js +0 -0
- /package/{dist/plugins → plugins}/helpers/query-details-modal.js.map +0 -0
- /package/{dist/plugins → plugins}/helpers/query-loading-modal.d.ts +0 -0
- /package/{dist/plugins → plugins}/helpers/query-loading-modal.js +0 -0
- /package/{dist/plugins → plugins}/helpers/query-loading-modal.js.map +0 -0
- /package/{dist/plugins → plugins}/helpers/render-components.d.ts +0 -0
- /package/{dist/plugins → plugins}/helpers/render-components.js +0 -0
- /package/{dist/plugins → plugins}/helpers/render-components.js.map +0 -0
- /package/{dist/plugins → plugins}/helpers/styled-info-button.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/icons/AiAvatarIcon.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/icons/AiAvatarIcon.js +0 -0
- /package/{dist/shadcn → shadcn}/components/icons/AiAvatarIcon.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/button.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/button.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/button.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/card.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/card.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/card.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/chart.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/chart.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/chart.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/checkbox.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/checkbox.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/checkbox.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/component-wrapper.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/component-wrapper.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/component-wrapper.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/date-filter.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/date-filter.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/date-filter.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/error-container.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/error-container.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/error-container.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/error-wrapper.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/error-wrapper.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/error-wrapper.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/filter.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/filter.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/filter.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/hover-card.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/hover-card.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/hover-card.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/input.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/input.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/input.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/label.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/label.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/label.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/pagination.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/pagination.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/pagination.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/scroll-area.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/scroll-area.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/scroll-area.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/search.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/search.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/search.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/separator.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/separator.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/separator.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/skeleton.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/skeleton.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/skeleton.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/table.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/table.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/table.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/tabs.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/tabs.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/tabs.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/textarea.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/textarea.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/textarea.js.map +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/tooltip.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/tooltip.js +0 -0
- /package/{dist/shadcn → shadcn}/components/ui/tooltip.js.map +0 -0
- /package/{dist/shadcn → shadcn}/utils.d.ts +0 -0
- /package/{dist/shadcn → shadcn}/utils.js +0 -0
- /package/{dist/shadcn → shadcn}/utils.js.map +0 -0
- /package/{dist/types → types}/grapesjs-tailwind.d.js +0 -0
- /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
|
-
}
|
package/src/GrapesjsCanvas.tsx
DELETED
|
@@ -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;
|
package/src/constants/index.ts
DELETED
|
@@ -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
|
-
];
|