@blocklet/editor 2.2.1 → 2.2.3
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.
|
@@ -1,32 +1,41 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
-
import { Box, Button,
|
|
4
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, IconButton, useMediaQuery, Typography, Skeleton, } from '@mui/material';
|
|
4
|
+
import { useEffect, useMemo, useState, lazy, Suspense } from 'react';
|
|
5
5
|
import SettingsOutlinedIcon from '@mui/icons-material/SettingsOutlined';
|
|
6
6
|
import { CustomComponentRenderer, customComponentStates } from '@blocklet/pages-kit/components';
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import { translations } from '@blocklet/pages-kit-runtime/locales';
|
|
9
|
+
import { LocaleProvider } from '@arcblock/ux/lib/Locale/context';
|
|
7
10
|
import { isBlockletRunning } from '../utils';
|
|
8
|
-
import { mode,
|
|
9
|
-
|
|
11
|
+
import { mode,
|
|
12
|
+
// isValidPropertyType,
|
|
13
|
+
getLocalizedValue, } from './utils';
|
|
14
|
+
// @FIXME: 需要移除这些无用的代码,现在使用 Pages Kit 提供的 ParametersConfig 组件
|
|
15
|
+
// import { PropertyField } from './PropertyField';
|
|
10
16
|
import { useContentLocale } from '../ContentLocale';
|
|
17
|
+
const ParametersConfigLazy = lazy(() => import('@blocklet/pages-kit-runtime/components').then((mod) => ({
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
default: mod.ParametersConfig,
|
|
20
|
+
})));
|
|
11
21
|
export function PagesKitComponentRenderer({ id, name, properties, onPropertiesChange }) {
|
|
12
22
|
const locale = useContentLocale();
|
|
13
23
|
const [editor] = useLexicalComposerContext();
|
|
14
24
|
const isEditable = editor.isEditable();
|
|
15
25
|
const [loading, setLoading] = useState(true);
|
|
16
|
-
const [
|
|
17
|
-
const open = Boolean(anchorEl);
|
|
26
|
+
const [open, setOpen] = useState(false);
|
|
18
27
|
const upMd = useMediaQuery((theme) => theme.breakpoints.up('md'));
|
|
19
28
|
const [pendingProperties, setPendingProperties] = useState(properties || {});
|
|
20
|
-
const handleClick = (
|
|
21
|
-
|
|
29
|
+
const handleClick = () => {
|
|
30
|
+
setOpen(true);
|
|
22
31
|
};
|
|
23
32
|
const handleCancel = () => {
|
|
24
|
-
|
|
33
|
+
setOpen(false);
|
|
25
34
|
setPendingProperties(properties || {});
|
|
26
35
|
};
|
|
27
36
|
const handleSave = () => {
|
|
28
37
|
onPropertiesChange(pendingProperties);
|
|
29
|
-
|
|
38
|
+
setOpen(false);
|
|
30
39
|
};
|
|
31
40
|
const instanceId = useMemo(() => `${id}-${hashCode(JSON.stringify(pendingProperties))}`, [id, pendingProperties]);
|
|
32
41
|
useEffect(() => {
|
|
@@ -60,36 +69,35 @@ export function PagesKitComponentRenderer({ id, name, properties, onPropertiesCh
|
|
|
60
69
|
load();
|
|
61
70
|
}
|
|
62
71
|
}, [id, name, pendingProperties]);
|
|
63
|
-
const
|
|
72
|
+
const allComponents = customComponentStates().getState()?.state?.components;
|
|
73
|
+
const component = allComponents?.[id]?.component;
|
|
74
|
+
const mergedPropertiesValues = useMemo(() => Object.fromEntries(Object.values(component?.properties ?? {}).map(({ data }) => {
|
|
75
|
+
return [
|
|
76
|
+
data.id,
|
|
77
|
+
{
|
|
78
|
+
value: pendingProperties?.[locale]?.[data.id] ??
|
|
79
|
+
getLocalizedValue({ key: 'defaultValue', locale, data: data.locales }),
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
})), [component, locale, pendingProperties]);
|
|
83
|
+
const componentRenderer = useMemo(() => (_jsx(CustomComponentRenderer, { instanceId: instanceId, componentId: id, locale: locale, dev: { mode }, properties: mergedPropertiesValues })), [instanceId, id, locale, mergedPropertiesValues]);
|
|
64
84
|
if (loading || !component) {
|
|
65
85
|
return null;
|
|
66
86
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
color: 'text.secondary',
|
|
82
|
-
fontSize: 14,
|
|
83
|
-
fontWeight: 600,
|
|
84
|
-
}, children: [_jsx(Box, { component: "span", className: "iconify", "data-icon": "tabler:settings-2", sx: { fontSize: 20 } }), _jsx("span", { children: "Properties" })] }) }), _jsx(Divider, { sx: { mt: 0.75, mb: 2 } }), propDefinitions.map((x) => {
|
|
85
|
-
// @ts-ignore
|
|
86
|
-
const multiline = !!x.multiline;
|
|
87
|
-
return (_jsx(Box, { sx: { mt: 2 }, children: _jsx(PropertyField, { label: getPropertyLabel({ locale, locales: x.locales }) || x.key || '', type: x.type, value: pendingProperties[locale]?.[x.id] ??
|
|
88
|
-
getLocalizedValue({ key: 'defaultValue', locale, data: x.locales }), onChange: (v) => setPendingProperties({
|
|
89
|
-
...pendingProperties,
|
|
90
|
-
[locale]: { ...pendingProperties[locale], [x.id]: v },
|
|
91
|
-
}), multiline: multiline }) }, x.id));
|
|
92
|
-
}), _jsxs(Box, { sx: { display: 'flex', justifyContent: 'flex-end', gap: 1, py: 2 }, children: [_jsx(Button, { color: "inherit", onClick: handleCancel, children: "Cancel" }), _jsx(Button, { color: "primary", variant: "contained", onClick: handleSave, children: "Save" })] })] }) })] }))] }));
|
|
87
|
+
return (_jsxs(Box, { sx: { position: 'relative', ...(isEditable && { mt: 2 }) }, children: [componentRenderer, isEditable && !!Object.keys(component?.properties ?? {}).length && upMd && (_jsxs(_Fragment, { children: [_jsx(IconButton, { sx: { position: 'absolute', right: 0, top: -32 }, onClick: handleClick, children: _jsx(SettingsOutlinedIcon, {}) }), _jsxs(Dialog, { disableEnforceFocus: true, fullWidth: true, maxWidth: "lg", open: open, onClose: handleCancel, disableScrollLock: false, children: [_jsx(DialogTitle, { children: _jsxs(Typography, { variant: "h6", children: [name, " "] }) }), _jsx(DialogContent, { sx: {
|
|
88
|
+
zIndex: 1200,
|
|
89
|
+
maxHeight: '70vh',
|
|
90
|
+
overflow: 'hidden',
|
|
91
|
+
}, children: _jsxs(Box, { sx: { display: 'flex', height: '70vh' }, children: [_jsx(Box, { sx: { flex: 1, p: 4, borderRight: '1px solid', borderColor: 'divider', overflow: 'auto' }, children: componentRenderer }), _jsx(Box, { sx: { width: 320, ml: 2, overflow: 'auto', overflowX: 'hidden' }, children: _jsx(LocaleProvider, { translations: translations, fallbackLocale: "en", children: _jsx(Suspense, { fallback: _jsx(Skeleton, { variant: "rectangular", height: "100%" }), children: _jsx(ParametersConfigLazy
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
, {
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
config: component, allComponents: allComponents, defaultLocale: "en", locale: locale, propertiesValue: mergedPropertiesValues, onChange: ({ id: propertyId, value }) => {
|
|
96
|
+
setPendingProperties({
|
|
97
|
+
...pendingProperties,
|
|
98
|
+
[locale]: { ...pendingProperties[locale], [propertyId]: value?.value },
|
|
99
|
+
});
|
|
100
|
+
} }) }) }) })] }) }), _jsxs(DialogActions, { children: [_jsx(Button, { color: "inherit", onClick: handleCancel, children: "Cancel" }), _jsx(Button, { color: "primary", variant: "contained", onClick: handleSave, children: "Save" })] })] })] }))] }));
|
|
93
101
|
}
|
|
94
102
|
function hashCode(str) {
|
|
95
103
|
let hash = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/editor",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"@blocklet/embed": "^0.2.3",
|
|
29
29
|
"@blocklet/js-sdk": "^1.16.41-beta-20250319-131732-1224cca5",
|
|
30
30
|
"@blocklet/pages-kit": "^0.4.85",
|
|
31
|
+
"@blocklet/pages-kit-runtime": "^0.4.90",
|
|
31
32
|
"@excalidraw/excalidraw": "^0.14.2",
|
|
32
33
|
"@iconify/iconify": "^3.1.1",
|
|
33
34
|
"@iconify/icons-tabler": "^1.2.95",
|
|
@@ -66,7 +67,7 @@
|
|
|
66
67
|
"ufo": "^1.5.4",
|
|
67
68
|
"url-join": "^4.0.1",
|
|
68
69
|
"zustand": "^4.5.5",
|
|
69
|
-
"@blocklet/pdf": "^2.2.
|
|
70
|
+
"@blocklet/pdf": "^2.2.3"
|
|
70
71
|
},
|
|
71
72
|
"devDependencies": {
|
|
72
73
|
"@babel/core": "^7.25.2",
|
|
@@ -95,14 +96,14 @@
|
|
|
95
96
|
"vite-plugin-svgr": "^4.2.0"
|
|
96
97
|
},
|
|
97
98
|
"peerDependencies": {
|
|
99
|
+
"@arcblock/did-connect": "^2.10.36",
|
|
100
|
+
"@arcblock/ux": "^2.10.46",
|
|
98
101
|
"@emotion/css": "*",
|
|
99
102
|
"@emotion/react": "*",
|
|
100
103
|
"@emotion/styled": "*",
|
|
101
104
|
"@mui/material": "*",
|
|
102
105
|
"react": "*",
|
|
103
|
-
"react-dom": "*"
|
|
104
|
-
"@arcblock/did-connect": "^2.10.36",
|
|
105
|
-
"@arcblock/ux": "^2.10.46"
|
|
106
|
+
"react-dom": "*"
|
|
106
107
|
},
|
|
107
108
|
"scripts": {
|
|
108
109
|
"dev": "npm run storybook",
|