@it-consultis/page-builder 1.1.34

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 (124) hide show
  1. package/Editor.d.ts +77 -0
  2. package/Editor.js +312 -0
  3. package/LICENSE.txt +674 -0
  4. package/README.md +248 -0
  5. package/assets/svg/mp.d.ts +2 -0
  6. package/assets/svg/mp.js +37 -0
  7. package/assets/svg/status-bar.d.ts +2 -0
  8. package/assets/svg/status-bar.js +38 -0
  9. package/constants/index.d.ts +11 -0
  10. package/constants/index.js +17 -0
  11. package/contexts/I18nContext.d.ts +15 -0
  12. package/contexts/I18nContext.js +56 -0
  13. package/controls/AlignmentControl/AlignmentControl.d.ts +5 -0
  14. package/controls/AlignmentControl/AlignmentControl.js +58 -0
  15. package/controls/AlignmentControl/index.d.ts +3 -0
  16. package/controls/AlignmentControl/index.js +9 -0
  17. package/controls/DeviceSwitcher/DeviceSwitcher.d.ts +10 -0
  18. package/controls/DeviceSwitcher/DeviceSwitcher.js +64 -0
  19. package/controls/DeviceSwitcher/index.d.ts +2 -0
  20. package/controls/DeviceSwitcher/index.js +9 -0
  21. package/controls/GradientColorPicker/GradientColorPicker.d.ts +8 -0
  22. package/controls/GradientColorPicker/GradientColorPicker.js +81 -0
  23. package/controls/GradientColorPicker/index.d.ts +2 -0
  24. package/controls/GradientColorPicker/index.js +9 -0
  25. package/controls/HeadingControl/HeadingControl.d.ts +14 -0
  26. package/controls/HeadingControl/HeadingControl.js +251 -0
  27. package/controls/HeadingControl/HeadingView.d.ts +21 -0
  28. package/controls/HeadingControl/HeadingView.js +43 -0
  29. package/controls/HeadingControl/index.d.ts +4 -0
  30. package/controls/HeadingControl/index.js +16 -0
  31. package/controls/MediaLibraryControl/FileBrowserDialog.d.ts +14 -0
  32. package/controls/MediaLibraryControl/FileBrowserDialog.js +138 -0
  33. package/controls/MediaLibraryControl/MediaLibraryControl.d.ts +38 -0
  34. package/controls/MediaLibraryControl/MediaLibraryControl.js +537 -0
  35. package/controls/MediaLibraryControl/index.d.ts +3 -0
  36. package/controls/MediaLibraryControl/index.js +9 -0
  37. package/controls/PaddingMarginControl/PaddingMarginControl.d.ts +30 -0
  38. package/controls/PaddingMarginControl/PaddingMarginControl.js +88 -0
  39. package/controls/PaddingMarginControl/PaddingMarginForm.d.ts +8 -0
  40. package/controls/PaddingMarginControl/PaddingMarginForm.js +109 -0
  41. package/controls/PaddingMarginControl/index.d.ts +4 -0
  42. package/controls/PaddingMarginControl/index.js +16 -0
  43. package/controls/PaddingMarginControl/utils.d.ts +3 -0
  44. package/controls/PaddingMarginControl/utils.js +21 -0
  45. package/controls/SelectableControl/SelectableControl.d.ts +5 -0
  46. package/controls/SelectableControl/SelectableControl.js +35 -0
  47. package/controls/SelectableControl/index.d.ts +3 -0
  48. package/controls/SelectableControl/index.js +9 -0
  49. package/hooks/ui-optimizations/useDebounce.d.ts +3 -0
  50. package/hooks/ui-optimizations/useDebounce.js +23 -0
  51. package/hooks/ui-optimizations/useThrottle.d.ts +3 -0
  52. package/hooks/ui-optimizations/useThrottle.js +22 -0
  53. package/hooks/useMediaImageQuery.d.ts +10 -0
  54. package/hooks/useMediaImageQuery.js +51 -0
  55. package/hooks/useSortable.d.ts +20 -0
  56. package/hooks/useSortable.js +70 -0
  57. package/index.d.ts +7 -0
  58. package/index.js +54 -0
  59. package/layouts/BlocksBar/LayerPanel.d.ts +8 -0
  60. package/layouts/BlocksBar/LayerPanel.js +299 -0
  61. package/layouts/BlocksBar/index.d.ts +7 -0
  62. package/layouts/BlocksBar/index.js +575 -0
  63. package/layouts/EditorPreview/BlockView.d.ts +16 -0
  64. package/layouts/EditorPreview/BlockView.js +435 -0
  65. package/layouts/EditorPreview/index.d.ts +9 -0
  66. package/layouts/EditorPreview/index.js +463 -0
  67. package/layouts/Header/index.d.ts +18 -0
  68. package/layouts/Header/index.js +202 -0
  69. package/layouts/Header/menus/ExportDataDialog.d.ts +4 -0
  70. package/layouts/Header/menus/ExportDataDialog.js +95 -0
  71. package/layouts/Header/menus/ImportDataDialog.d.ts +4 -0
  72. package/layouts/Header/menus/ImportDataDialog.js +100 -0
  73. package/layouts/Header/menus/LeftMenu.d.ts +9 -0
  74. package/layouts/Header/menus/LeftMenu.js +369 -0
  75. package/layouts/Header/menus/RightMenu.d.ts +14 -0
  76. package/layouts/Header/menus/RightMenu.js +91 -0
  77. package/layouts/Header/menus/SaveTemplateDialog.d.ts +4 -0
  78. package/layouts/Header/menus/SaveTemplateDialog.js +203 -0
  79. package/layouts/MessageBus.d.ts +13 -0
  80. package/layouts/MessageBus.js +76 -0
  81. package/layouts/Sidebar/AddBlockButton.d.ts +12 -0
  82. package/layouts/Sidebar/AddBlockButton.js +267 -0
  83. package/layouts/Sidebar/BlockForm.d.ts +20 -0
  84. package/layouts/Sidebar/BlockForm.js +517 -0
  85. package/layouts/Sidebar/BlocksControl.d.ts +21 -0
  86. package/layouts/Sidebar/BlocksControl.js +190 -0
  87. package/layouts/Sidebar/index.d.ts +10 -0
  88. package/layouts/Sidebar/index.js +451 -0
  89. package/layouts/Snackbar.d.ts +3 -0
  90. package/layouts/Snackbar.js +43 -0
  91. package/package.json +133 -0
  92. package/store/Provider.d.ts +15 -0
  93. package/store/Provider.js +71 -0
  94. package/store/editor-store-core.d.ts +4 -0
  95. package/store/editor-store-core.js +271 -0
  96. package/store/index.d.ts +112 -0
  97. package/store/index.js +178 -0
  98. package/theme.d.ts +10 -0
  99. package/theme.js +9 -0
  100. package/translation/cn.json +29 -0
  101. package/translation/en.json +29 -0
  102. package/translation/fr.json +31 -0
  103. package/translation/index.d.ts +6 -0
  104. package/translation/index.js +23 -0
  105. package/translation/types.d.ts +13 -0
  106. package/translation/types.js +5 -0
  107. package/types/Block.d.ts +22 -0
  108. package/types/Block.js +5 -0
  109. package/types/BlockType.d.ts +50 -0
  110. package/types/BlockType.js +5 -0
  111. package/types/ConfigStorageAdapter.d.ts +11 -0
  112. package/types/ConfigStorageAdapter.js +5 -0
  113. package/types/ObjectStorageAdapter.d.ts +68 -0
  114. package/types/ObjectStorageAdapter.js +5 -0
  115. package/types/index.d.ts +5 -0
  116. package/types/index.js +100 -0
  117. package/types/throttle-and-debounce.d.ts +2 -0
  118. package/types/throttle-and-debounce.js +5 -0
  119. package/utils/block.d.ts +16 -0
  120. package/utils/block.js +41 -0
  121. package/utils/helpers.d.ts +5 -0
  122. package/utils/helpers.js +22 -0
  123. package/utils/strings.d.ts +1 -0
  124. package/utils/strings.js +11 -0
package/package.json ADDED
@@ -0,0 +1,133 @@
1
+ {
2
+ "name": "@it-consultis/page-builder",
3
+ "version": "1.1.34",
4
+ "license": "MIT",
5
+ "author": "itc",
6
+ "scripts": {
7
+ "tsc": "tsc --project ./tsconfig.prod.json",
8
+ "dev": "cross-env NODE_ENV=development webpack serve --progress --mode development",
9
+ "prebuild": "babel build.ts --out-file build.js",
10
+ "build": "cross-env NODE_ENV=production node build.js",
11
+ "build:dev": "cross-env NODE_ENV=development node build.js",
12
+ "release": "npm run prebuild && npm run build",
13
+ "postbuild": "rm build.js",
14
+ "npm-pack": "npm run build && cd ./dist && npm pack",
15
+ "npm-pack:dev": "npm run prebuild && npm run build:dev && cd ./dist && npm pack",
16
+ "sync-package-lock-file": "npm install --package-lock-only --ignore-scripts --no-audit --no-fund"
17
+ },
18
+ "keywords": [
19
+ "editor",
20
+ "react",
21
+ "block editor",
22
+ "react block editor"
23
+ ],
24
+ "peerDependencies": {
25
+ "@mui/icons-material": "^5.11.0",
26
+ "@mui/lab": "^5.0.0-alpha.118",
27
+ "@mui/material": "^5.11.0",
28
+ "react": "^17.0.0 || ^18.0.0 || ^19.0.0",
29
+ "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
30
+ },
31
+ "resolutions": {
32
+ "@types/react": "^19.1.0",
33
+ "@types/react-dom": "^19.1.0",
34
+ "@types/eslint": "^8.4.1"
35
+ },
36
+ "dependencies": {
37
+ "@mui/x-tree-view": "^7.28.1",
38
+ "@tanstack/react-query": "^4.36.1",
39
+ "itc-file-browser": "^0.0.15",
40
+ "itc-tailwindcss-container-queries": "^0.1.2",
41
+ "js-cookie": "^3.0.5",
42
+ "react-colorful": "^5.6.1",
43
+ "sortablejs": "^1.15.0",
44
+ "uuid": "^9.0",
45
+ "zod": "^3.20.6",
46
+ "zundo": "^2.3.0",
47
+ "zustand": "^4.3.2"
48
+ },
49
+ "devDependencies": {
50
+ "@babel/cli": "^7.21.0",
51
+ "@babel/core": "^7.20.12",
52
+ "@babel/preset-env": "^7.20.2",
53
+ "@babel/preset-react": "^7.18.6",
54
+ "@babel/preset-typescript": "^7.18.6",
55
+ "@babel/register": "^7.21.0",
56
+ "@emotion/cache": "^11.10.5",
57
+ "@emotion/react": "^11.14.0",
58
+ "@emotion/styled": "^11.14.0",
59
+ "@fontsource/roboto": "^4.5.8",
60
+ "@mui/icons-material": "^5.11.0",
61
+ "@mui/lab": "^5.0.0-alpha.118",
62
+ "@mui/material": "^5.16.13",
63
+ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
64
+ "@types/babel__core": "^7.20.0",
65
+ "@types/js-cookie": "^3.0.6",
66
+ "@types/loadable__component": "^5.13.4",
67
+ "@types/node": "^18.14.0",
68
+ "@types/pica": "^9.0.1",
69
+ "@types/react": "^19.1.0",
70
+ "@types/react-dom": "^19.1.0",
71
+ "@types/shelljs": "^0.8.11",
72
+ "@types/sortablejs": "^1.10.7",
73
+ "@types/uuid": "^8.3.1",
74
+ "@typescript-eslint/eslint-plugin": "^5.21.0",
75
+ "@typescript-eslint/parser": "^5.21.0",
76
+ "autoprefixer": "^10.4.13",
77
+ "babel-loader": "^8.2.2",
78
+ "babel-plugin-direct-import": "^1.0.0",
79
+ "babel-plugin-import": "^1.13.3",
80
+ "babel-plugin-module-resolver": "^5.0.2",
81
+ "babel-plugin-transform-inline-environment-variables": "^0.4.4",
82
+ "clsx": "^1.2.1",
83
+ "copyfiles": "^2.4.1",
84
+ "cross-env": "^10.0.0",
85
+ "css-loader": "^6.7.3",
86
+ "eslint": "^8.14.0",
87
+ "eslint-config-airbnb": "^19.0.4",
88
+ "eslint-config-airbnb-typescript": "^17.0.0",
89
+ "eslint-plugin-import": "^2.26.0",
90
+ "eslint-plugin-jsx-a11y": "^6.5.1",
91
+ "eslint-plugin-react": "^7.28.0",
92
+ "eslint-plugin-react-hooks": "^4.5.0",
93
+ "html-webpack-plugin": "^5.3.2",
94
+ "idb": "^7.1.1",
95
+ "pica": "^9.0.1",
96
+ "postcss": "^8.4.21",
97
+ "postcss-loader": "^7.0.2",
98
+ "react": "^19.1.0",
99
+ "react-dom": "^19.1.0",
100
+ "react-refresh": "^0.10.0",
101
+ "rimraf": "^3.0.2",
102
+ "shelljs": "^0.8.5",
103
+ "style-loader": "^3.3.1",
104
+ "tailwindcss": "^3.4.16",
105
+ "tsc-alias": "^1.8.16",
106
+ "typescript": "^4.9.5",
107
+ "webpack": "^5.75.0",
108
+ "webpack-cli": "^4.9.2",
109
+ "webpack-dev-server": "^4.8.1"
110
+ },
111
+ "overrides": {
112
+ "itc-file-browser": {
113
+ "react": "^18 || ^19",
114
+ "react-dom": "^18 || ^19"
115
+ },
116
+ "@tanstack/react-query": {
117
+ "react": "^18 || ^19",
118
+ "react-dom": "^18 || ^19"
119
+ },
120
+ "@mui/lab": {
121
+ "react": "^18 || ^19",
122
+ "react-dom": "^18 || ^19",
123
+ "@types/react": "^18 || ^19",
124
+ "@types/react-dom": "^18 || ^19"
125
+ },
126
+ "@mui/icons-material": {
127
+ "react": "^18 || ^19",
128
+ "react-dom": "^18 || ^19",
129
+ "@types/react": "^18 || ^19",
130
+ "@types/react-dom": "^18 || ^19"
131
+ }
132
+ }
133
+ }
@@ -0,0 +1,15 @@
1
+ import { type EditorState } from '../store';
2
+ import { LocaleType } from '../translation';
3
+ import { Block, BlockType } from '../types';
4
+ import { Theme } from '@mui/material/styles';
5
+ import { QueryClient } from '@tanstack/react-query';
6
+ import { type FC, type ReactNode } from 'react';
7
+ declare const Provider: FC<{
8
+ children: ReactNode;
9
+ data?: Block[];
10
+ queryClient?: QueryClient;
11
+ mpNavigationProps?: BlockType | null;
12
+ locale?: LocaleType;
13
+ editorTheme?: Theme;
14
+ } & Omit<Partial<EditorState>, 'data'>>;
15
+ export default Provider;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _I18nContext = require("../contexts/I18nContext");
8
+ var _ = require("./");
9
+ var _theme = _interopRequireDefault(require("../theme"));
10
+ var _CssBaseline = _interopRequireDefault(require("@mui/material/CssBaseline/CssBaseline.js"));
11
+ var _styles = require("@mui/material/styles");
12
+ var _reactQuery = require("@tanstack/react-query");
13
+ var _react = require("react");
14
+ var _jsxRuntime = require("react/jsx-runtime");
15
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
+ const Provider = props => {
17
+ const {
18
+ children,
19
+ queryClient: propQueryClient,
20
+ locale = 'en',
21
+ editorTheme = _theme.default,
22
+ ...editorState
23
+ } = props;
24
+ const editorStoreRef = (0, _react.useRef)(undefined);
25
+ if (!editorStoreRef.current) {
26
+ editorStoreRef.current = (0, _.createEditorStore)(editorState);
27
+ }
28
+ const queryClientRef = (0, _react.useRef)(undefined);
29
+ if (!queryClientRef.current) {
30
+ queryClientRef.current = propQueryClient || new _reactQuery.QueryClient();
31
+ }
32
+ const {
33
+ data,
34
+ allowedOrigins,
35
+ blockTypes,
36
+ ...other
37
+ } = editorState;
38
+ (0, _react.useEffect)(() => {
39
+ const editorStore = editorStoreRef.current;
40
+ const currentState = editorStore.getState();
41
+ if (data?.length) {
42
+ currentState.setData(data);
43
+ }
44
+ if (allowedOrigins) {
45
+ currentState.setAllowedOrigins(allowedOrigins);
46
+ }
47
+ if (blockTypes) {
48
+ currentState.setBlockTypes(blockTypes);
49
+ }
50
+ if (other) {
51
+ editorStore.getState().setMultipleStates(other);
52
+ }
53
+ }, [data, allowedOrigins, blockTypes, other]);
54
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_I18nContext.I18nProvider, {
55
+ locale: locale,
56
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.ThemeProvider, {
57
+ theme: editorTheme,
58
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("link", {
59
+ rel: "stylesheet",
60
+ href: "https://fonts.googleapis.com/icon?family=Material+Icons"
61
+ }), editorTheme === _theme.default && /*#__PURE__*/(0, _jsxRuntime.jsx)(_CssBaseline.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_.EditorContext.Provider, {
62
+ value: editorStoreRef.current,
63
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactQuery.QueryClientProvider, {
64
+ client: queryClientRef.current,
65
+ children: children
66
+ })
67
+ })]
68
+ })
69
+ });
70
+ };
71
+ var _default = exports.default = Provider;
@@ -0,0 +1,4 @@
1
+ import type { EditorState } from '../store/index';
2
+ type InitialStateType = Partial<Omit<EditorState, 'setBlockTypes' | 'setData' | 'setAllowedOrigins' | 'setPreviewWidth' | 'setPreviewDeviceList' | 'setPreviewInstance'>>;
3
+ declare const editorCoreWithDevtools: ({ includingMp, isMp, isFullScreen, isNested, cardinality, blockTypes, data, allowedOrigins, previewSrc, previewWidth, previewDeviceList, storage, theme }: InitialStateType) => import("zustand").StateCreator<EditorState, [], [["zustand/devtools", never]], EditorState>;
4
+ export default editorCoreWithDevtools;
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _jsCookie = _interopRequireDefault(require("js-cookie"));
8
+ var _uuid = require("uuid");
9
+ var _zod = require("zod");
10
+ var _middleware = require("zustand/middleware");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ const options = {
13
+ name: 'ITC-page-builder',
14
+ trace: true,
15
+ traceLimit: 30
16
+ };
17
+ const editorCoreWithDevtools = ({
18
+ includingMp = null,
19
+ isMp = false,
20
+ isFullScreen = false,
21
+ isNested = false,
22
+ cardinality = -1,
23
+ blockTypes = [],
24
+ data = [],
25
+ allowedOrigins = [],
26
+ previewSrc = '',
27
+ previewWidth,
28
+ previewDeviceList = ['sm', 'md', 'lg', 'xl', 'full'],
29
+ storage,
30
+ theme = {}
31
+ }) => (0, _middleware.devtools)((set, get) => ({
32
+ selectedBlockId: '',
33
+ setSelectedBlockId(id) {
34
+ set({
35
+ selectedBlockId: id
36
+ }, false, 'setSelectedBlockId');
37
+ },
38
+ theme,
39
+ editingBlockId: '',
40
+ setEditingBlockId(id) {
41
+ set({
42
+ editingBlockId: id
43
+ }, false, 'setEditingBlockId');
44
+ },
45
+ isFullScreen,
46
+ isMp,
47
+ setIsMp(_isMp) {
48
+ set({
49
+ isMp: _isMp
50
+ }, false, 'setIsMp');
51
+ },
52
+ includingMp,
53
+ setIncludingMp(_includingMp) {
54
+ set({
55
+ includingMp: _includingMp
56
+ }, false, 'setIncludingMp');
57
+ },
58
+ setIsFullScreen(_isFullScreen) {
59
+ set({
60
+ isFullScreen: _isFullScreen
61
+ }, false, 'setIsFullScreen');
62
+ },
63
+ isNested,
64
+ cardinality,
65
+ blockTypes,
66
+ setBlockTypes(newTypes) {
67
+ const prevTypes = get().blockTypes;
68
+ const prevTypesId = prevTypes.map(t => t.id).join('/');
69
+ const sortedNewTypes = newTypes.sort((a, b) => a.label < b.label ? -1 : 1);
70
+ const sortedNewTypesId = sortedNewTypes.sort().map(t => t.id).join('/');
71
+ if (sortedNewTypesId !== prevTypesId) {
72
+ set({
73
+ blockTypes: sortedNewTypes
74
+ }, false, 'setBlockTypes');
75
+ }
76
+ },
77
+ data,
78
+ onDataChange: null,
79
+ async parseUnsafeData(unsafeData) {
80
+ let parsedUnsafeData = null;
81
+ const issues = [];
82
+ if (Array.isArray(unsafeData)) {
83
+ parsedUnsafeData = unsafeData;
84
+ } else if (typeof unsafeData === 'string') {
85
+ if (!unsafeData.toLowerCase().includes('<script>')) {
86
+ try {
87
+ parsedUnsafeData = JSON.parse(unsafeData);
88
+ } catch (err) {
89
+ issues.push({
90
+ fatal: true,
91
+ code: 'custom',
92
+ message: err.message,
93
+ path: []
94
+ });
95
+ }
96
+ }
97
+ } else {
98
+ issues.push({
99
+ fatal: true,
100
+ code: 'custom',
101
+ message: 'Data is not valid.',
102
+ path: []
103
+ });
104
+ }
105
+ if (issues.length > 0) {
106
+ return {
107
+ success: false,
108
+ errors: [{
109
+ issues
110
+ }]
111
+ };
112
+ }
113
+ const blockTypesIds = get().blockTypes.map(bt => bt.id);
114
+ const docSchema = _zod.z.array(_zod.z.object({
115
+ id: _zod.z.string(),
116
+ type: _zod.z.string().refine(type => blockTypesIds.includes(type), type => ({
117
+ message: `Block type must be one of: ${blockTypesIds.join(', ')}. Current value: ${type}`
118
+ })),
119
+ top: _zod.z.boolean(),
120
+ data: _zod.z.object({}).passthrough().nullable(),
121
+ settings: _zod.z.object({}).passthrough().nullable(),
122
+ meta: _zod.z.object({
123
+ created: _zod.z.number(),
124
+ changed: _zod.z.number()
125
+ }).passthrough()
126
+ }));
127
+ const result = docSchema.safeParse(parsedUnsafeData);
128
+ if (!result.success) {
129
+ return {
130
+ success: false,
131
+ errors: [result.error]
132
+ };
133
+ }
134
+ const maybeSafeData = result.data;
135
+ const results = await Promise.all(maybeSafeData.map(async (block, i) => {
136
+ const blockType = blockTypes.find(bt => bt.id === block.type);
137
+ if (blockType.getDataSchema && block.data) {
138
+ const schema = await blockType.getDataSchema();
139
+ const blockResult = schema.safeParse(block.data);
140
+ if (!blockResult.success) {
141
+ return blockResult;
142
+ }
143
+ maybeSafeData[i].data = blockResult.data;
144
+ }
145
+ if (blockType.getSettingsSchema && block.settings) {
146
+ const schema = await blockType.getSettingsSchema();
147
+ const blockResult = schema.safeParse(block.settings);
148
+ if (!blockResult.success) {
149
+ return blockResult;
150
+ }
151
+ maybeSafeData[i].settings = blockResult.data;
152
+ }
153
+ return undefined;
154
+ }));
155
+ const allErrors = [];
156
+ results.forEach(r => {
157
+ if (r && !r.success) {
158
+ allErrors.push(r.error);
159
+ }
160
+ });
161
+ if (allErrors.length === 0) {
162
+ return {
163
+ success: true,
164
+ data: maybeSafeData
165
+ };
166
+ }
167
+ return {
168
+ success: false,
169
+ errors: allErrors
170
+ };
171
+ },
172
+ async importData(rawData) {
173
+ const result = await get().parseUnsafeData(rawData);
174
+ if (result.success) {
175
+ get().setData(result.data);
176
+ return result;
177
+ }
178
+ return result;
179
+ },
180
+ setData(argData, userEqualityFn) {
181
+ const prevData = get().data;
182
+ const newData = Array.isArray(argData) ? argData : argData(prevData);
183
+ const equalityFn = userEqualityFn || ((a, b) => {
184
+ const aId = a.map(block => `${block.id}:${block.meta.changed}`).join('/');
185
+ const bId = b.map(block => `${block.id}:${block.meta.changed}`).join('/');
186
+ return aId === bId;
187
+ });
188
+ const selected = equalityFn(prevData, newData) ? prevData : newData;
189
+ set({
190
+ data: selected
191
+ }, false, 'setData');
192
+ return selected;
193
+ },
194
+ setMultipleStates(states) {
195
+ Object.entries(states).forEach(([key, value]) => {
196
+ if (typeof value !== 'undefined') {
197
+ set({
198
+ [key]: value
199
+ }, false, `provider-setState-${key}`);
200
+ }
201
+ });
202
+ },
203
+ allowedOrigins,
204
+ setAllowedOrigins(newOrigins) {
205
+ const prevOrigins = get().allowedOrigins;
206
+ const sortedNewOrigins = newOrigins.sort();
207
+ if (prevOrigins.join(',') !== sortedNewOrigins.join(',')) {
208
+ set({
209
+ allowedOrigins: sortedNewOrigins
210
+ }, false, 'setAllowedOrigins');
211
+ }
212
+ },
213
+ previewSrc,
214
+ previewWidth: includingMp ? 'sm' : 'lg',
215
+ setPreviewWidth(width) {
216
+ const currentDeviceList = get().previewDeviceList;
217
+ if (currentDeviceList === null) {
218
+ return;
219
+ }
220
+ if (Array.isArray(currentDeviceList) && !currentDeviceList.includes(width)) {
221
+ return;
222
+ }
223
+ set({
224
+ previewWidth: width
225
+ }, false, 'setPreviewWidth');
226
+ // get domain name from hostname
227
+ const domain = window.location.hostname.split('.').slice(-2).join('.');
228
+ _jsCookie.default.set('editor-preview-width', width, {
229
+ domain
230
+ });
231
+ set({
232
+ device: width === 'sm' ? 'mobile' : 'desktop'
233
+ });
234
+ },
235
+ previewDeviceList,
236
+ setPreviewDeviceList(deviceList) {
237
+ set({
238
+ previewDeviceList: deviceList
239
+ }, false, 'setPreviewDeviceList');
240
+ },
241
+ device: previewWidth === 'sm' ? 'mobile' : 'desktop',
242
+ setDevice(device) {
243
+ set({
244
+ device
245
+ }, false, 'setDevice');
246
+ },
247
+ // previewInstance,
248
+ // setPreviewInstance(instance) {
249
+ // set({ previewInstance: instance });
250
+ // },
251
+ alertMessages: [],
252
+ addAlertMessages(messages) {
253
+ const prevMessages = get().alertMessages;
254
+ set({
255
+ alertMessages: [...prevMessages, ...messages.map(m => ({
256
+ ...m,
257
+ autoHideDuration: m.autoHideDuration || 3000,
258
+ id: (0, _uuid.v4)(),
259
+ visible: false
260
+ }))]
261
+ }, false, 'addAlertMessages');
262
+ },
263
+ removeAlertMessage(id) {
264
+ const prevMessages = get().alertMessages;
265
+ set({
266
+ alertMessages: prevMessages.filter(m => m.id !== id)
267
+ }, false, 'removeAlertMessage');
268
+ },
269
+ storage: storage
270
+ }), options);
271
+ var _default = exports.default = editorCoreWithDevtools;
@@ -0,0 +1,112 @@
1
+ /// <reference types="react" />
2
+ import { DeviceType } from '../Editor';
3
+ import type { Block, BlockType } from '../types';
4
+ import type { Config, ConfigStorageAdapter } from '../types/ConfigStorageAdapter';
5
+ import type ObjectStorageAdapter from '../types/ObjectStorageAdapter';
6
+ import type { AlertProps, SnackbarProps } from '@mui/material';
7
+ import { Theme } from '@mui/material/styles';
8
+ import { z } from 'zod';
9
+ import { TemporalState } from 'zundo';
10
+ type Storage = {
11
+ object?: ObjectStorageAdapter;
12
+ config?: ConfigStorageAdapter;
13
+ };
14
+ export type EditorState = {
15
+ isFullScreen: boolean;
16
+ isMp: boolean;
17
+ theme: Theme;
18
+ includingMp: boolean | null;
19
+ setIncludingMp(includingMp: boolean): void;
20
+ setIsMp(isMp: boolean): void;
21
+ setIsFullScreen(isFullScreen: boolean): void;
22
+ isNested: boolean;
23
+ cardinality: number;
24
+ blockTypes: BlockType[];
25
+ setBlockTypes(newTypes: BlockType[]): void;
26
+ data: Block[];
27
+ setData(data: Block[] | ((prevData: Block[]) => Block[]), areEqual?: (prevData: Block[], newData: Block[]) => boolean): Block[];
28
+ setMultipleStates(otherData: Record<string, any>): void;
29
+ parseUnsafeData(data: unknown[] | string): Promise<{
30
+ success: true;
31
+ data: Block[];
32
+ } | {
33
+ success: false;
34
+ errors: {
35
+ issues: z.ZodIssue[];
36
+ }[];
37
+ }>;
38
+ importData(rawData: string): Promise<{
39
+ success: true;
40
+ data: Block[];
41
+ } | {
42
+ success: false;
43
+ errors: {
44
+ issues: z.ZodIssue[];
45
+ }[];
46
+ }>;
47
+ allowedOrigins: string[];
48
+ setAllowedOrigins(newOrigins: string[]): void;
49
+ previewSrc: string;
50
+ previewWidth: DeviceType;
51
+ setPreviewWidth(width: EditorState['previewWidth']): void;
52
+ previewDeviceList: DeviceType[];
53
+ setPreviewDeviceList(deviceList: EditorState['previewDeviceList']): void;
54
+ selectedBlockId: string;
55
+ setSelectedBlockId(id: EditorState['selectedBlockId']): void;
56
+ editingBlockId: string;
57
+ setEditingBlockId(id: EditorState['editingBlockId']): void;
58
+ device: 'desktop' | 'mobile';
59
+ setDevice(device: EditorState['device']): void;
60
+ alertMessages: {
61
+ id: string;
62
+ severity: AlertProps['severity'];
63
+ message: string | string[];
64
+ autoHideDuration: number;
65
+ visible: boolean;
66
+ }[];
67
+ addAlertMessages(messages: {
68
+ severity: AlertProps['severity'];
69
+ message: string | string[];
70
+ autoHideDuration?: SnackbarProps['autoHideDuration'];
71
+ }[]): void;
72
+ removeAlertMessage(id: string): void;
73
+ storage: Storage | boolean;
74
+ };
75
+ export type EditorStore = ReturnType<typeof createEditorStore>;
76
+ export declare const createEditorStore: (initialState?: {}) => import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<EditorState>, "temporal"> & {
77
+ temporal: import("zustand").StoreApi<TemporalState<EditorState>>;
78
+ }, "setState"> & {
79
+ setState<A extends string | {
80
+ type: string;
81
+ }>(partial: EditorState | Partial<EditorState> | ((state: EditorState) => EditorState | Partial<EditorState>), replace?: boolean | undefined, action?: A | undefined): void;
82
+ }>;
83
+ export declare const EditorContext: import("react").Context<void | import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<EditorState>, "temporal"> & {
84
+ temporal: import("zustand").StoreApi<TemporalState<EditorState>>;
85
+ }, "setState"> & {
86
+ setState<A extends string | {
87
+ type: string;
88
+ }>(partial: EditorState | Partial<EditorState> | ((state: EditorState) => EditorState | Partial<EditorState>), replace?: boolean | undefined, action?: A | undefined): void;
89
+ }>>;
90
+ export declare const useEditorStore: <U>(selector: (state: EditorState) => U) => U;
91
+ export declare const useTemporalEditorStore: <T>(selector: (state: TemporalState<Pick<EditorState, 'data'>>) => T) => T;
92
+ export declare const useObjectStorage: () => ObjectStorageAdapter | undefined;
93
+ export declare const useConfigStorage: () => ConfigStorageAdapter | undefined;
94
+ export declare const useConfigStorageQueryClient: () => {
95
+ useGetQuery<ConfigData>(id: string, options?: {
96
+ enabled?: boolean;
97
+ }): import("@tanstack/react-query").UseQueryResult<Config<ConfigData> | null, unknown>;
98
+ useListQuery(options?: {
99
+ enabled?: boolean;
100
+ }): import("@tanstack/react-query").UseQueryResult<string[], unknown>;
101
+ useDeleteMutation(options?: {
102
+ onSuccess?(id: string): void;
103
+ } | undefined): import("@tanstack/react-query").UseMutationResult<string, unknown, string, unknown>;
104
+ useSaveMutation(options?: {
105
+ onSuccess?(config: Config): void;
106
+ } | undefined): import("@tanstack/react-query").UseMutationResult<Config<any>, unknown, Config<any>, unknown>;
107
+ };
108
+ export type ConfigTemplate = Config<{
109
+ name: string;
110
+ blocks: Block[];
111
+ }>;
112
+ export {};