@thienvu18/designable-react-settings-form 2.0.0
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/LICENSE.md +20 -0
- package/README.md +1 -0
- package/esm/SchemaField.d.ts +1580 -0
- package/esm/SchemaField.js +42 -0
- package/esm/SettingsForm.d.ts +4 -0
- package/esm/SettingsForm.js +54 -0
- package/esm/components/BackgroundStyleSetter/index.d.ts +6 -0
- package/esm/components/BackgroundStyleSetter/index.js +43 -0
- package/esm/components/BorderRadiusStyleSetter/index.d.ts +6 -0
- package/esm/components/BorderRadiusStyleSetter/index.js +11 -0
- package/esm/components/BorderStyleSetter/index.d.ts +7 -0
- package/esm/components/BorderStyleSetter/index.js +74 -0
- package/esm/components/BorderStyleSetter/styles.less +70 -0
- package/esm/components/BoxShadowStyleSetter/index.d.ts +8 -0
- package/esm/components/BoxShadowStyleSetter/index.js +25 -0
- package/esm/components/BoxStyleSetter/index.d.ts +9 -0
- package/esm/components/BoxStyleSetter/index.js +49 -0
- package/esm/components/CollapseItem/index.d.ts +8 -0
- package/esm/components/CollapseItem/index.js +16 -0
- package/esm/components/CollapseItem/styles.less +45 -0
- package/esm/components/ColorInput/index.d.ts +7 -0
- package/esm/components/ColorInput/index.js +18 -0
- package/esm/components/ColorInput/styles.less +17 -0
- package/esm/components/CornerInput/index.d.ts +9 -0
- package/esm/components/CornerInput/index.js +22 -0
- package/esm/components/CornerInput/styles.less +25 -0
- package/esm/components/DisplayStyleSetter/index.d.ts +9 -0
- package/esm/components/DisplayStyleSetter/index.js +34 -0
- package/esm/components/DisplayStyleSetter/styles.less +15 -0
- package/esm/components/DrawerSetter/index.d.ts +8 -0
- package/esm/components/DrawerSetter/index.js +43 -0
- package/esm/components/DrawerSetter/styles.less +54 -0
- package/esm/components/FlexStyleSetter/index.d.ts +7 -0
- package/esm/components/FlexStyleSetter/index.js +111 -0
- package/esm/components/FlexStyleSetter/styles.less +23 -0
- package/esm/components/FoldItem/index.d.ts +7 -0
- package/esm/components/FoldItem/index.js +49 -0
- package/esm/components/FoldItem/styles.less +42 -0
- package/esm/components/FontStyleSetter/index.d.ts +6 -0
- package/esm/components/FontStyleSetter/index.js +88 -0
- package/esm/components/ImageInput/index.d.ts +9 -0
- package/esm/components/ImageInput/index.js +41 -0
- package/esm/components/ImageInput/styles.less +3 -0
- package/esm/components/InputItems/index.d.ts +23 -0
- package/esm/components/InputItems/index.js +18 -0
- package/esm/components/InputItems/styles.less +45 -0
- package/esm/components/MonacoInput/config.d.ts +1 -0
- package/esm/components/MonacoInput/config.js +39 -0
- package/esm/components/MonacoInput/format.d.ts +1 -0
- package/esm/components/MonacoInput/format.js +31 -0
- package/esm/components/MonacoInput/index.d.ts +16 -0
- package/esm/components/MonacoInput/index.js +216 -0
- package/esm/components/MonacoInput/styles.less +33 -0
- package/esm/components/MonacoInput/themes/chrome.d.ts +39 -0
- package/esm/components/MonacoInput/themes/chrome.js +106 -0
- package/esm/components/MonacoInput/themes/monokai.d.ts +31 -0
- package/esm/components/MonacoInput/themes/monokai.js +140 -0
- package/esm/components/PolyInput/index.d.ts +21 -0
- package/esm/components/PolyInput/index.js +70 -0
- package/esm/components/PolyInput/styles.less +31 -0
- package/esm/components/PositionInput/index.d.ts +9 -0
- package/esm/components/PositionInput/index.js +22 -0
- package/esm/components/PositionInput/styles.less +28 -0
- package/esm/components/SizeInput/index.d.ts +3 -0
- package/esm/components/SizeInput/index.js +53 -0
- package/esm/components/SizeInput/styles.less +23 -0
- package/esm/components/ValueInput/index.d.ts +2 -0
- package/esm/components/ValueInput/index.js +81 -0
- package/esm/components/ValueInput/styles.less +0 -0
- package/esm/components/index.d.ts +20 -0
- package/esm/components/index.js +20 -0
- package/esm/effects/index.d.ts +2 -0
- package/esm/effects/index.js +2 -0
- package/esm/effects/useLocales.d.ts +2 -0
- package/esm/effects/useLocales.js +63 -0
- package/esm/effects/useSnapshot.d.ts +2 -0
- package/esm/effects/useSnapshot.js +10 -0
- package/esm/index.d.ts +5 -0
- package/esm/index.js +5 -0
- package/esm/locales/en-US.d.ts +13 -0
- package/esm/locales/en-US.js +12 -0
- package/esm/locales/index.d.ts +1 -0
- package/esm/locales/index.js +5 -0
- package/esm/locales/ko-KR.d.ts +13 -0
- package/esm/locales/ko-KR.js +12 -0
- package/esm/locales/zh-CN.d.ts +13 -0
- package/esm/locales/zh-CN.js +12 -0
- package/esm/registry.d.ts +2 -0
- package/esm/registry.js +13 -0
- package/esm/shared/context.d.ts +3 -0
- package/esm/shared/context.js +2 -0
- package/esm/shared/loadScript.d.ts +7 -0
- package/esm/shared/loadScript.js +29 -0
- package/esm/styles.less +121 -0
- package/esm/types.d.ts +10 -0
- package/esm/types.js +1 -0
- package/lib/SchemaField.d.ts +1580 -0
- package/lib/SchemaField.js +45 -0
- package/lib/SettingsForm.d.ts +4 -0
- package/lib/SettingsForm.js +60 -0
- package/lib/components/BackgroundStyleSetter/index.d.ts +6 -0
- package/lib/components/BackgroundStyleSetter/index.js +49 -0
- package/lib/components/BorderRadiusStyleSetter/index.d.ts +6 -0
- package/lib/components/BorderRadiusStyleSetter/index.js +15 -0
- package/lib/components/BorderStyleSetter/index.d.ts +7 -0
- package/lib/components/BorderStyleSetter/index.js +80 -0
- package/lib/components/BorderStyleSetter/styles.less +70 -0
- package/lib/components/BoxShadowStyleSetter/index.d.ts +8 -0
- package/lib/components/BoxShadowStyleSetter/index.js +31 -0
- package/lib/components/BoxStyleSetter/index.d.ts +9 -0
- package/lib/components/BoxStyleSetter/index.js +55 -0
- package/lib/components/CollapseItem/index.d.ts +8 -0
- package/lib/components/CollapseItem/index.js +22 -0
- package/lib/components/CollapseItem/styles.less +45 -0
- package/lib/components/ColorInput/index.d.ts +7 -0
- package/lib/components/ColorInput/index.js +22 -0
- package/lib/components/ColorInput/styles.less +17 -0
- package/lib/components/CornerInput/index.d.ts +9 -0
- package/lib/components/CornerInput/index.js +29 -0
- package/lib/components/CornerInput/styles.less +25 -0
- package/lib/components/DisplayStyleSetter/index.d.ts +9 -0
- package/lib/components/DisplayStyleSetter/index.js +40 -0
- package/lib/components/DisplayStyleSetter/styles.less +15 -0
- package/lib/components/DrawerSetter/index.d.ts +8 -0
- package/lib/components/DrawerSetter/index.js +49 -0
- package/lib/components/DrawerSetter/styles.less +54 -0
- package/lib/components/FlexStyleSetter/index.d.ts +7 -0
- package/lib/components/FlexStyleSetter/index.js +117 -0
- package/lib/components/FlexStyleSetter/styles.less +23 -0
- package/lib/components/FoldItem/index.d.ts +7 -0
- package/lib/components/FoldItem/index.js +78 -0
- package/lib/components/FoldItem/styles.less +42 -0
- package/lib/components/FontStyleSetter/index.d.ts +6 -0
- package/lib/components/FontStyleSetter/index.js +94 -0
- package/lib/components/ImageInput/index.d.ts +9 -0
- package/lib/components/ImageInput/index.js +49 -0
- package/lib/components/ImageInput/styles.less +3 -0
- package/lib/components/InputItems/index.d.ts +23 -0
- package/lib/components/InputItems/index.js +48 -0
- package/lib/components/InputItems/styles.less +45 -0
- package/lib/components/MonacoInput/config.d.ts +1 -0
- package/lib/components/MonacoInput/config.js +46 -0
- package/lib/components/MonacoInput/format.d.ts +1 -0
- package/lib/components/MonacoInput/format.js +35 -0
- package/lib/components/MonacoInput/index.d.ts +16 -0
- package/lib/components/MonacoInput/index.js +246 -0
- package/lib/components/MonacoInput/styles.less +33 -0
- package/lib/components/MonacoInput/themes/chrome.d.ts +39 -0
- package/lib/components/MonacoInput/themes/chrome.js +108 -0
- package/lib/components/MonacoInput/themes/monokai.d.ts +31 -0
- package/lib/components/MonacoInput/themes/monokai.js +142 -0
- package/lib/components/PolyInput/index.d.ts +21 -0
- package/lib/components/PolyInput/index.js +100 -0
- package/lib/components/PolyInput/styles.less +31 -0
- package/lib/components/PositionInput/index.d.ts +9 -0
- package/lib/components/PositionInput/index.js +29 -0
- package/lib/components/PositionInput/styles.less +28 -0
- package/lib/components/SizeInput/index.d.ts +3 -0
- package/lib/components/SizeInput/index.js +56 -0
- package/lib/components/SizeInput/styles.less +23 -0
- package/lib/components/ValueInput/index.d.ts +2 -0
- package/lib/components/ValueInput/index.js +84 -0
- package/lib/components/ValueInput/styles.less +0 -0
- package/lib/components/index.d.ts +20 -0
- package/lib/components/index.js +36 -0
- package/lib/effects/index.d.ts +2 -0
- package/lib/effects/index.js +18 -0
- package/lib/effects/useLocales.d.ts +2 -0
- package/lib/effects/useLocales.js +67 -0
- package/lib/effects/useSnapshot.d.ts +2 -0
- package/lib/effects/useSnapshot.js +14 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +21 -0
- package/lib/locales/en-US.d.ts +13 -0
- package/lib/locales/en-US.js +14 -0
- package/lib/locales/index.d.ts +1 -0
- package/lib/locales/index.js +10 -0
- package/lib/locales/ko-KR.d.ts +13 -0
- package/lib/locales/ko-KR.js +14 -0
- package/lib/locales/zh-CN.d.ts +13 -0
- package/lib/locales/zh-CN.js +14 -0
- package/lib/registry.d.ts +2 -0
- package/lib/registry.js +21 -0
- package/lib/shared/context.d.ts +3 -0
- package/lib/shared/context.js +5 -0
- package/lib/shared/loadScript.d.ts +7 -0
- package/lib/shared/loadScript.js +33 -0
- package/lib/styles.less +121 -0
- package/lib/types.d.ts +10 -0
- package/lib/types.js +2 -0
- package/package.json +71 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useEffect, useState, useRef } from 'react';
|
|
3
|
+
import { Button } from 'antd';
|
|
4
|
+
import { usePrefix, IconWidget } from '@thienvu18/designable-react';
|
|
5
|
+
import cls from 'classnames';
|
|
6
|
+
import './styles.less';
|
|
7
|
+
const isValid = (val) => val !== undefined && val !== null;
|
|
8
|
+
const getEventValue = (event) => {
|
|
9
|
+
if (event?.target) {
|
|
10
|
+
if (isValid(event.target.value))
|
|
11
|
+
return event.target.value;
|
|
12
|
+
if (isValid(event.target.checked))
|
|
13
|
+
return event.target.checked;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
return event;
|
|
17
|
+
};
|
|
18
|
+
const createTypes = (types, exclude, include) => {
|
|
19
|
+
return types.filter(({ type }) => {
|
|
20
|
+
if (Array.isArray(include) && include.length) {
|
|
21
|
+
return include.includes(type);
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(exclude) && exclude.length) {
|
|
24
|
+
return !exclude.includes(type);
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
export function createPolyInput(polyTypes = []) {
|
|
30
|
+
return ({ className, style, value, onChange, exclude, include, ...props }) => {
|
|
31
|
+
const prefix = usePrefix('poly-input');
|
|
32
|
+
const types = createTypes(polyTypes, exclude, include);
|
|
33
|
+
const [current, setCurrent] = useState(types[0]?.type);
|
|
34
|
+
const type = types?.find(({ type }) => type === current);
|
|
35
|
+
const component = type?.component;
|
|
36
|
+
const typesValue = useRef({});
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
types?.forEach(({ checker, type }) => {
|
|
39
|
+
if (checker(value)) {
|
|
40
|
+
setCurrent(type);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}, [value]);
|
|
44
|
+
const getNextType = () => {
|
|
45
|
+
const currentIndex = types?.findIndex(({ type }) => type === current);
|
|
46
|
+
const nextIndex = currentIndex + 1 > types?.length - 1 ? 0 : currentIndex + 1;
|
|
47
|
+
return types[nextIndex];
|
|
48
|
+
};
|
|
49
|
+
const transformOnChangeValue = (value, type) => {
|
|
50
|
+
return type?.toChangeValue ? type?.toChangeValue(value) : value;
|
|
51
|
+
};
|
|
52
|
+
return (_jsxs("div", { className: cls(prefix, className), style: style, children: [component && (_jsx("div", { className: prefix + '-content', children: React.createElement(component, {
|
|
53
|
+
...props,
|
|
54
|
+
value: type?.toInputValue ? type?.toInputValue(value) : value,
|
|
55
|
+
onChange: (event) => {
|
|
56
|
+
const value = getEventValue(event);
|
|
57
|
+
typesValue.current[type?.type] = value;
|
|
58
|
+
onChange?.(transformOnChangeValue(value, type));
|
|
59
|
+
},
|
|
60
|
+
}) })), _jsx(Button, { className: prefix + '-controller', style: {
|
|
61
|
+
width: !component ? '100%' : 'auto',
|
|
62
|
+
}, block: true, onClick: () => {
|
|
63
|
+
const nextType = getNextType();
|
|
64
|
+
if (nextType === type)
|
|
65
|
+
return;
|
|
66
|
+
setCurrent(nextType?.type);
|
|
67
|
+
onChange?.(transformOnChangeValue(typesValue.current[nextType?.type], nextType));
|
|
68
|
+
}, children: type?.icon ? (_jsx(IconWidget, { infer: type.icon })) : (type?.title || type?.type) })] }));
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
@ant-prefix: ant;
|
|
2
|
+
.dn-poly-input {
|
|
3
|
+
display: flex;
|
|
4
|
+
width: 100%;
|
|
5
|
+
align-items: center;
|
|
6
|
+
|
|
7
|
+
.dn-poly-input-content {
|
|
8
|
+
flex-grow: 2;
|
|
9
|
+
margin-right: 2px;
|
|
10
|
+
display: flex;
|
|
11
|
+
|
|
12
|
+
.@{ant-prefix}-select {
|
|
13
|
+
width: 100%;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.@{ant-prefix}-input-number {
|
|
17
|
+
width: 100%;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.dn-poly-input-controller {
|
|
22
|
+
border: 1px solid var(--dn-color-border, #d9d9d9);
|
|
23
|
+
border-radius: 2px;
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
padding: 0 8px;
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
justify-content: center;
|
|
29
|
+
flex-grow: 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './styles.less';
|
|
3
|
+
export interface IPositionInputProps {
|
|
4
|
+
className?: string;
|
|
5
|
+
style?: React.CSSProperties;
|
|
6
|
+
value?: string;
|
|
7
|
+
onChange?: (value: string) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const PositionInput: React.FC<IPositionInputProps>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
import { usePrefix } from '@thienvu18/designable-react';
|
|
4
|
+
import cls from 'classnames';
|
|
5
|
+
import './styles.less';
|
|
6
|
+
export const PositionInput = (props) => {
|
|
7
|
+
const prefix = usePrefix('position-input');
|
|
8
|
+
const [current, setCurrent] = useState(props.value);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!props.value) {
|
|
11
|
+
setCurrent('center');
|
|
12
|
+
}
|
|
13
|
+
}, [props.value]);
|
|
14
|
+
const createCellProps = (type) => ({
|
|
15
|
+
className: cls(prefix + '-cell', { active: current === type }),
|
|
16
|
+
onClick() {
|
|
17
|
+
setCurrent(type);
|
|
18
|
+
props.onChange?.(type);
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
return (_jsxs("div", { className: cls(prefix, props.className), style: props.style, children: [_jsx("div", { className: prefix + '-row', children: _jsx("div", { ...createCellProps('top'), children: "\u2533" }) }), _jsxs("div", { className: prefix + '-row', children: [_jsx("div", { ...createCellProps('left'), children: "\u2523" }), _jsx("div", { ...createCellProps('center'), children: "\u254B" }), _jsx("div", { ...createCellProps('right'), children: "\u252B" })] }), _jsx("div", { className: prefix + '-row', children: _jsx("div", { ...createCellProps('bottom'), children: "\u253B" }) })] }));
|
|
22
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
.dn-position-input {
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
|
|
6
|
+
&-row {
|
|
7
|
+
display: flex;
|
|
8
|
+
justify-content: center;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
&-cell {
|
|
12
|
+
width: 26px;
|
|
13
|
+
height: 26px;
|
|
14
|
+
box-sizing: border-box;
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
border-radius: 3px;
|
|
20
|
+
color: rgba(0, 0, 0, 0.6);
|
|
21
|
+
margin: 5px;
|
|
22
|
+
color: var(--dn-color-text, rgba(0, 0, 0, 0.88));
|
|
23
|
+
|
|
24
|
+
&.active {
|
|
25
|
+
background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.2));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { InputNumber } from 'antd';
|
|
2
|
+
import { createPolyInput } from '../PolyInput';
|
|
3
|
+
const takeNumber = (value) => {
|
|
4
|
+
const num = String(value)
|
|
5
|
+
.trim()
|
|
6
|
+
.replace(/[^\d\.]+/, '');
|
|
7
|
+
if (num === '')
|
|
8
|
+
return;
|
|
9
|
+
return Number(num);
|
|
10
|
+
};
|
|
11
|
+
const createUnitType = (type) => {
|
|
12
|
+
return {
|
|
13
|
+
type,
|
|
14
|
+
component: InputNumber,
|
|
15
|
+
checker(value) {
|
|
16
|
+
return String(value).includes(type);
|
|
17
|
+
},
|
|
18
|
+
toInputValue(value) {
|
|
19
|
+
return takeNumber(value);
|
|
20
|
+
},
|
|
21
|
+
toChangeValue(value) {
|
|
22
|
+
return `${value || 0}${type}`;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const createSpecialSizeOption = (type) => ({
|
|
27
|
+
type: type,
|
|
28
|
+
checker(value) {
|
|
29
|
+
if (value === type)
|
|
30
|
+
return true;
|
|
31
|
+
return false;
|
|
32
|
+
},
|
|
33
|
+
toChangeValue() {
|
|
34
|
+
return type;
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const NormalSizeOptions = [
|
|
38
|
+
createSpecialSizeOption('inherit'),
|
|
39
|
+
createSpecialSizeOption('auto'),
|
|
40
|
+
createUnitType('px'),
|
|
41
|
+
createUnitType('%'),
|
|
42
|
+
createUnitType('vh'),
|
|
43
|
+
createUnitType('em'),
|
|
44
|
+
];
|
|
45
|
+
export const SizeInput = createPolyInput(NormalSizeOptions);
|
|
46
|
+
export const BackgroundSizeInput = createPolyInput([
|
|
47
|
+
createSpecialSizeOption('cover'),
|
|
48
|
+
createSpecialSizeOption('contain'),
|
|
49
|
+
createUnitType('px'),
|
|
50
|
+
createUnitType('%'),
|
|
51
|
+
createUnitType('vh'),
|
|
52
|
+
createUnitType('em'),
|
|
53
|
+
]);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
.dn-size-input {
|
|
3
|
+
display: flex;
|
|
4
|
+
width: 100%;
|
|
5
|
+
|
|
6
|
+
.@{ant-prefix}-input-number {
|
|
7
|
+
flex-grow: 2;
|
|
8
|
+
margin-right: 2px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.dn-size-input-unit {
|
|
12
|
+
border: 1px solid var(--dn-color-border, #d9d9d9);
|
|
13
|
+
border-radius: 2px;
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
height: 32px;
|
|
16
|
+
padding: 0 8px;
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
flex-grow: 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
@ant-prefix: ant;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createPolyInput } from '../PolyInput';
|
|
3
|
+
import { Input, Button, Popover, InputNumber, Select } from 'antd';
|
|
4
|
+
import { MonacoInput } from '../MonacoInput';
|
|
5
|
+
import { TextWidget } from '@thienvu18/designable-react';
|
|
6
|
+
const STARTTAG_REX = /<([-A-Za-z0-9_]+)((?:\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/;
|
|
7
|
+
const EXPRESSION_REX = /^\{\{([\s\S]*)\}\}$/;
|
|
8
|
+
const isNumber = (value) => typeof value === 'number';
|
|
9
|
+
const isBoolean = (value) => typeof value === 'boolean';
|
|
10
|
+
const isExpression = (value) => {
|
|
11
|
+
return typeof value === 'string' && EXPRESSION_REX.test(value);
|
|
12
|
+
};
|
|
13
|
+
const isRichText = (value) => {
|
|
14
|
+
return typeof value === 'string' && STARTTAG_REX.test(value);
|
|
15
|
+
};
|
|
16
|
+
const isNormalText = (value) => {
|
|
17
|
+
return typeof value === 'string' && !isExpression(value) && !isRichText(value);
|
|
18
|
+
};
|
|
19
|
+
const takeNumber = (value) => {
|
|
20
|
+
const num = String(value).replace(/[^\d\.]+/, '');
|
|
21
|
+
if (num === '')
|
|
22
|
+
return;
|
|
23
|
+
return Number(num);
|
|
24
|
+
};
|
|
25
|
+
export const ValueInput = createPolyInput([
|
|
26
|
+
{
|
|
27
|
+
type: 'TEXT',
|
|
28
|
+
icon: 'Text',
|
|
29
|
+
component: Input,
|
|
30
|
+
checker: isNormalText,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: 'EXPRESSION',
|
|
34
|
+
icon: 'Expression',
|
|
35
|
+
component: (props) => {
|
|
36
|
+
return (_jsx(Popover, { content: _jsx("div", { style: {
|
|
37
|
+
width: 400,
|
|
38
|
+
height: 200,
|
|
39
|
+
marginLeft: -16,
|
|
40
|
+
marginRight: -16,
|
|
41
|
+
marginBottom: -12,
|
|
42
|
+
}, children: _jsx(MonacoInput, { ...props, language: "javascript.expression" }) }), trigger: "click", children: _jsx(Button, { block: true, children: _jsx(TextWidget, { token: "SettingComponents.ValueInput.expression" }) }) }));
|
|
43
|
+
},
|
|
44
|
+
checker: isExpression,
|
|
45
|
+
toInputValue: (value) => {
|
|
46
|
+
if (!value || value === '{{}}')
|
|
47
|
+
return;
|
|
48
|
+
const matched = String(value).match(EXPRESSION_REX);
|
|
49
|
+
return matched?.[1] || value || '';
|
|
50
|
+
},
|
|
51
|
+
toChangeValue: (value) => {
|
|
52
|
+
if (!value || value === '{{}}')
|
|
53
|
+
return;
|
|
54
|
+
const matched = String(value).match(EXPRESSION_REX);
|
|
55
|
+
return `{{${matched?.[1] || value || ''}}}`;
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: 'BOOLEAN',
|
|
60
|
+
icon: 'Boolean',
|
|
61
|
+
component: (props) => (_jsx(Select, { ...props, options: [
|
|
62
|
+
{ label: 'True', value: true },
|
|
63
|
+
{ label: 'False', value: false },
|
|
64
|
+
] })),
|
|
65
|
+
checker: isBoolean,
|
|
66
|
+
toInputValue: (value) => {
|
|
67
|
+
return !!value;
|
|
68
|
+
},
|
|
69
|
+
toChangeValue: (value) => {
|
|
70
|
+
return !!value;
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: 'NUMBER',
|
|
75
|
+
icon: 'Number',
|
|
76
|
+
component: InputNumber,
|
|
77
|
+
checker: isNumber,
|
|
78
|
+
toInputValue: takeNumber,
|
|
79
|
+
toChangeValue: takeNumber,
|
|
80
|
+
},
|
|
81
|
+
]);
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from './ColorInput';
|
|
2
|
+
export * from './CornerInput';
|
|
3
|
+
export * from './ImageInput';
|
|
4
|
+
export * from './PositionInput';
|
|
5
|
+
export * from './SizeInput';
|
|
6
|
+
export * from './PolyInput';
|
|
7
|
+
export * from './ValueInput';
|
|
8
|
+
export * from './MonacoInput';
|
|
9
|
+
export * from './DrawerSetter';
|
|
10
|
+
export * from './BoxStyleSetter';
|
|
11
|
+
export * from './BorderStyleSetter';
|
|
12
|
+
export * from './BorderRadiusStyleSetter';
|
|
13
|
+
export * from './BackgroundStyleSetter';
|
|
14
|
+
export * from './BoxShadowStyleSetter';
|
|
15
|
+
export * from './FontStyleSetter';
|
|
16
|
+
export * from './DisplayStyleSetter';
|
|
17
|
+
export * from './FlexStyleSetter';
|
|
18
|
+
export * from './FoldItem';
|
|
19
|
+
export * from './CollapseItem';
|
|
20
|
+
export * from './InputItems';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export * from './ColorInput';
|
|
2
|
+
export * from './CornerInput';
|
|
3
|
+
export * from './ImageInput';
|
|
4
|
+
export * from './PositionInput';
|
|
5
|
+
export * from './SizeInput';
|
|
6
|
+
export * from './PolyInput';
|
|
7
|
+
export * from './ValueInput';
|
|
8
|
+
export * from './MonacoInput';
|
|
9
|
+
export * from './DrawerSetter';
|
|
10
|
+
export * from './BoxStyleSetter';
|
|
11
|
+
export * from './BorderStyleSetter';
|
|
12
|
+
export * from './BorderRadiusStyleSetter';
|
|
13
|
+
export * from './BackgroundStyleSetter';
|
|
14
|
+
export * from './BoxShadowStyleSetter';
|
|
15
|
+
export * from './FontStyleSetter';
|
|
16
|
+
export * from './DisplayStyleSetter';
|
|
17
|
+
export * from './FlexStyleSetter';
|
|
18
|
+
export * from './FoldItem';
|
|
19
|
+
export * from './CollapseItem';
|
|
20
|
+
export * from './InputItems';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { isVoidField, onFieldReact } from '@formily/core';
|
|
3
|
+
import { GlobalRegistry } from '@thienvu18/designable-core';
|
|
4
|
+
import { isStr } from '@thienvu18/designable-shared';
|
|
5
|
+
import { IconWidget } from '@thienvu18/designable-react';
|
|
6
|
+
const takeIcon = (message) => {
|
|
7
|
+
if (!isStr(message))
|
|
8
|
+
return;
|
|
9
|
+
const matched = message.match(/@([^:\s]+)(?:\s*\:\s*([\s\S]+))?/);
|
|
10
|
+
if (matched)
|
|
11
|
+
return [matched[1], matched[2]];
|
|
12
|
+
return;
|
|
13
|
+
};
|
|
14
|
+
const mapEnum = (dataSource) => (item, index) => {
|
|
15
|
+
const label = dataSource[index] || dataSource[item.value] || item.label;
|
|
16
|
+
const icon = takeIcon(label);
|
|
17
|
+
return {
|
|
18
|
+
...item,
|
|
19
|
+
value: item?.value ?? null,
|
|
20
|
+
label: icon ? (_jsx(IconWidget, { infer: icon[0], tooltip: icon[1] })) : (label?.label ?? label ?? 'Unknow'),
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export const useLocales = (node) => {
|
|
24
|
+
onFieldReact('*', (field) => {
|
|
25
|
+
const path = field.path.toString().replace(/\.[\d+]/g, '');
|
|
26
|
+
const takeMessage = (prop) => {
|
|
27
|
+
const token = `settings.${path}${prop ? `.${prop}` : ''}`;
|
|
28
|
+
return node.getMessage(token) || GlobalRegistry.getDesignerMessage(token);
|
|
29
|
+
};
|
|
30
|
+
const title = takeMessage('title') || takeMessage();
|
|
31
|
+
const description = takeMessage('description');
|
|
32
|
+
const tooltip = takeMessage('tooltip');
|
|
33
|
+
const dataSource = takeMessage('dataSource');
|
|
34
|
+
const placeholder = takeMessage('placeholder');
|
|
35
|
+
if (title) {
|
|
36
|
+
field.title = title;
|
|
37
|
+
}
|
|
38
|
+
if (description) {
|
|
39
|
+
field.description = description;
|
|
40
|
+
}
|
|
41
|
+
if (tooltip) {
|
|
42
|
+
field.decorator[1] = field.decorator[1] || [];
|
|
43
|
+
field.decorator[1].tooltip = tooltip;
|
|
44
|
+
}
|
|
45
|
+
if (placeholder) {
|
|
46
|
+
field.component[1] = field.component[1] || [];
|
|
47
|
+
field.component[1].placeholder = placeholder;
|
|
48
|
+
}
|
|
49
|
+
if (!isVoidField(field)) {
|
|
50
|
+
if (dataSource?.length) {
|
|
51
|
+
if (field.dataSource?.length) {
|
|
52
|
+
field.dataSource = field.dataSource.map(mapEnum(dataSource));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
field.dataSource = dataSource.slice();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
field.dataSource = field.dataSource?.filter(Boolean);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { onFieldInputValueChange } from '@formily/core';
|
|
2
|
+
let timeRequest = null;
|
|
3
|
+
export const useSnapshot = (operation) => {
|
|
4
|
+
onFieldInputValueChange('*', () => {
|
|
5
|
+
clearTimeout(timeRequest);
|
|
6
|
+
timeRequest = setTimeout(() => {
|
|
7
|
+
operation.snapshot('update:node:props');
|
|
8
|
+
}, 1000);
|
|
9
|
+
});
|
|
10
|
+
};
|
package/esm/index.d.ts
ADDED
package/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/registry.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import loader from '@monaco-editor/loader';
|
|
2
|
+
const Registry = {
|
|
3
|
+
cdn: '//cdn.jsdelivr.net/npm',
|
|
4
|
+
};
|
|
5
|
+
export const setNpmCDNRegistry = (registry) => {
|
|
6
|
+
Registry.cdn = registry;
|
|
7
|
+
loader.config({
|
|
8
|
+
paths: {
|
|
9
|
+
vs: `${registry}/monaco-editor@0.30.1/min/vs`,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export const getNpmCDNRegistry = () => String(Registry.cdn).replace(/\/$/, '');
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getNpmCDNRegistry } from '../registry';
|
|
2
|
+
import { globalThisPolyfill } from '@thienvu18/designable-shared';
|
|
3
|
+
export const loadScript = async (props) => {
|
|
4
|
+
const options = {
|
|
5
|
+
base: getNpmCDNRegistry(),
|
|
6
|
+
...props,
|
|
7
|
+
};
|
|
8
|
+
if (globalThisPolyfill[props.root])
|
|
9
|
+
return globalThisPolyfill[options.root];
|
|
10
|
+
const path = `${options.base}/${options.package}/${options.entry}`;
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const script = document.createElement('script');
|
|
13
|
+
script.type = 'text/javascript';
|
|
14
|
+
script.async = false;
|
|
15
|
+
script.src = path;
|
|
16
|
+
script.onload = () => {
|
|
17
|
+
const module = globalThisPolyfill[options.root];
|
|
18
|
+
globalThisPolyfill['define'] = define;
|
|
19
|
+
resolve(module);
|
|
20
|
+
script.remove();
|
|
21
|
+
};
|
|
22
|
+
script.onerror = (err) => {
|
|
23
|
+
reject(err);
|
|
24
|
+
};
|
|
25
|
+
const define = globalThisPolyfill['define'];
|
|
26
|
+
globalThisPolyfill['define'] = undefined;
|
|
27
|
+
document.body.appendChild(script);
|
|
28
|
+
});
|
|
29
|
+
};
|