@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.
Files changed (191) hide show
  1. package/LICENSE.md +20 -0
  2. package/README.md +1 -0
  3. package/esm/SchemaField.d.ts +1580 -0
  4. package/esm/SchemaField.js +42 -0
  5. package/esm/SettingsForm.d.ts +4 -0
  6. package/esm/SettingsForm.js +54 -0
  7. package/esm/components/BackgroundStyleSetter/index.d.ts +6 -0
  8. package/esm/components/BackgroundStyleSetter/index.js +43 -0
  9. package/esm/components/BorderRadiusStyleSetter/index.d.ts +6 -0
  10. package/esm/components/BorderRadiusStyleSetter/index.js +11 -0
  11. package/esm/components/BorderStyleSetter/index.d.ts +7 -0
  12. package/esm/components/BorderStyleSetter/index.js +74 -0
  13. package/esm/components/BorderStyleSetter/styles.less +70 -0
  14. package/esm/components/BoxShadowStyleSetter/index.d.ts +8 -0
  15. package/esm/components/BoxShadowStyleSetter/index.js +25 -0
  16. package/esm/components/BoxStyleSetter/index.d.ts +9 -0
  17. package/esm/components/BoxStyleSetter/index.js +49 -0
  18. package/esm/components/CollapseItem/index.d.ts +8 -0
  19. package/esm/components/CollapseItem/index.js +16 -0
  20. package/esm/components/CollapseItem/styles.less +45 -0
  21. package/esm/components/ColorInput/index.d.ts +7 -0
  22. package/esm/components/ColorInput/index.js +18 -0
  23. package/esm/components/ColorInput/styles.less +17 -0
  24. package/esm/components/CornerInput/index.d.ts +9 -0
  25. package/esm/components/CornerInput/index.js +22 -0
  26. package/esm/components/CornerInput/styles.less +25 -0
  27. package/esm/components/DisplayStyleSetter/index.d.ts +9 -0
  28. package/esm/components/DisplayStyleSetter/index.js +34 -0
  29. package/esm/components/DisplayStyleSetter/styles.less +15 -0
  30. package/esm/components/DrawerSetter/index.d.ts +8 -0
  31. package/esm/components/DrawerSetter/index.js +43 -0
  32. package/esm/components/DrawerSetter/styles.less +54 -0
  33. package/esm/components/FlexStyleSetter/index.d.ts +7 -0
  34. package/esm/components/FlexStyleSetter/index.js +111 -0
  35. package/esm/components/FlexStyleSetter/styles.less +23 -0
  36. package/esm/components/FoldItem/index.d.ts +7 -0
  37. package/esm/components/FoldItem/index.js +49 -0
  38. package/esm/components/FoldItem/styles.less +42 -0
  39. package/esm/components/FontStyleSetter/index.d.ts +6 -0
  40. package/esm/components/FontStyleSetter/index.js +88 -0
  41. package/esm/components/ImageInput/index.d.ts +9 -0
  42. package/esm/components/ImageInput/index.js +41 -0
  43. package/esm/components/ImageInput/styles.less +3 -0
  44. package/esm/components/InputItems/index.d.ts +23 -0
  45. package/esm/components/InputItems/index.js +18 -0
  46. package/esm/components/InputItems/styles.less +45 -0
  47. package/esm/components/MonacoInput/config.d.ts +1 -0
  48. package/esm/components/MonacoInput/config.js +39 -0
  49. package/esm/components/MonacoInput/format.d.ts +1 -0
  50. package/esm/components/MonacoInput/format.js +31 -0
  51. package/esm/components/MonacoInput/index.d.ts +16 -0
  52. package/esm/components/MonacoInput/index.js +216 -0
  53. package/esm/components/MonacoInput/styles.less +33 -0
  54. package/esm/components/MonacoInput/themes/chrome.d.ts +39 -0
  55. package/esm/components/MonacoInput/themes/chrome.js +106 -0
  56. package/esm/components/MonacoInput/themes/monokai.d.ts +31 -0
  57. package/esm/components/MonacoInput/themes/monokai.js +140 -0
  58. package/esm/components/PolyInput/index.d.ts +21 -0
  59. package/esm/components/PolyInput/index.js +70 -0
  60. package/esm/components/PolyInput/styles.less +31 -0
  61. package/esm/components/PositionInput/index.d.ts +9 -0
  62. package/esm/components/PositionInput/index.js +22 -0
  63. package/esm/components/PositionInput/styles.less +28 -0
  64. package/esm/components/SizeInput/index.d.ts +3 -0
  65. package/esm/components/SizeInput/index.js +53 -0
  66. package/esm/components/SizeInput/styles.less +23 -0
  67. package/esm/components/ValueInput/index.d.ts +2 -0
  68. package/esm/components/ValueInput/index.js +81 -0
  69. package/esm/components/ValueInput/styles.less +0 -0
  70. package/esm/components/index.d.ts +20 -0
  71. package/esm/components/index.js +20 -0
  72. package/esm/effects/index.d.ts +2 -0
  73. package/esm/effects/index.js +2 -0
  74. package/esm/effects/useLocales.d.ts +2 -0
  75. package/esm/effects/useLocales.js +63 -0
  76. package/esm/effects/useSnapshot.d.ts +2 -0
  77. package/esm/effects/useSnapshot.js +10 -0
  78. package/esm/index.d.ts +5 -0
  79. package/esm/index.js +5 -0
  80. package/esm/locales/en-US.d.ts +13 -0
  81. package/esm/locales/en-US.js +12 -0
  82. package/esm/locales/index.d.ts +1 -0
  83. package/esm/locales/index.js +5 -0
  84. package/esm/locales/ko-KR.d.ts +13 -0
  85. package/esm/locales/ko-KR.js +12 -0
  86. package/esm/locales/zh-CN.d.ts +13 -0
  87. package/esm/locales/zh-CN.js +12 -0
  88. package/esm/registry.d.ts +2 -0
  89. package/esm/registry.js +13 -0
  90. package/esm/shared/context.d.ts +3 -0
  91. package/esm/shared/context.js +2 -0
  92. package/esm/shared/loadScript.d.ts +7 -0
  93. package/esm/shared/loadScript.js +29 -0
  94. package/esm/styles.less +121 -0
  95. package/esm/types.d.ts +10 -0
  96. package/esm/types.js +1 -0
  97. package/lib/SchemaField.d.ts +1580 -0
  98. package/lib/SchemaField.js +45 -0
  99. package/lib/SettingsForm.d.ts +4 -0
  100. package/lib/SettingsForm.js +60 -0
  101. package/lib/components/BackgroundStyleSetter/index.d.ts +6 -0
  102. package/lib/components/BackgroundStyleSetter/index.js +49 -0
  103. package/lib/components/BorderRadiusStyleSetter/index.d.ts +6 -0
  104. package/lib/components/BorderRadiusStyleSetter/index.js +15 -0
  105. package/lib/components/BorderStyleSetter/index.d.ts +7 -0
  106. package/lib/components/BorderStyleSetter/index.js +80 -0
  107. package/lib/components/BorderStyleSetter/styles.less +70 -0
  108. package/lib/components/BoxShadowStyleSetter/index.d.ts +8 -0
  109. package/lib/components/BoxShadowStyleSetter/index.js +31 -0
  110. package/lib/components/BoxStyleSetter/index.d.ts +9 -0
  111. package/lib/components/BoxStyleSetter/index.js +55 -0
  112. package/lib/components/CollapseItem/index.d.ts +8 -0
  113. package/lib/components/CollapseItem/index.js +22 -0
  114. package/lib/components/CollapseItem/styles.less +45 -0
  115. package/lib/components/ColorInput/index.d.ts +7 -0
  116. package/lib/components/ColorInput/index.js +22 -0
  117. package/lib/components/ColorInput/styles.less +17 -0
  118. package/lib/components/CornerInput/index.d.ts +9 -0
  119. package/lib/components/CornerInput/index.js +29 -0
  120. package/lib/components/CornerInput/styles.less +25 -0
  121. package/lib/components/DisplayStyleSetter/index.d.ts +9 -0
  122. package/lib/components/DisplayStyleSetter/index.js +40 -0
  123. package/lib/components/DisplayStyleSetter/styles.less +15 -0
  124. package/lib/components/DrawerSetter/index.d.ts +8 -0
  125. package/lib/components/DrawerSetter/index.js +49 -0
  126. package/lib/components/DrawerSetter/styles.less +54 -0
  127. package/lib/components/FlexStyleSetter/index.d.ts +7 -0
  128. package/lib/components/FlexStyleSetter/index.js +117 -0
  129. package/lib/components/FlexStyleSetter/styles.less +23 -0
  130. package/lib/components/FoldItem/index.d.ts +7 -0
  131. package/lib/components/FoldItem/index.js +78 -0
  132. package/lib/components/FoldItem/styles.less +42 -0
  133. package/lib/components/FontStyleSetter/index.d.ts +6 -0
  134. package/lib/components/FontStyleSetter/index.js +94 -0
  135. package/lib/components/ImageInput/index.d.ts +9 -0
  136. package/lib/components/ImageInput/index.js +49 -0
  137. package/lib/components/ImageInput/styles.less +3 -0
  138. package/lib/components/InputItems/index.d.ts +23 -0
  139. package/lib/components/InputItems/index.js +48 -0
  140. package/lib/components/InputItems/styles.less +45 -0
  141. package/lib/components/MonacoInput/config.d.ts +1 -0
  142. package/lib/components/MonacoInput/config.js +46 -0
  143. package/lib/components/MonacoInput/format.d.ts +1 -0
  144. package/lib/components/MonacoInput/format.js +35 -0
  145. package/lib/components/MonacoInput/index.d.ts +16 -0
  146. package/lib/components/MonacoInput/index.js +246 -0
  147. package/lib/components/MonacoInput/styles.less +33 -0
  148. package/lib/components/MonacoInput/themes/chrome.d.ts +39 -0
  149. package/lib/components/MonacoInput/themes/chrome.js +108 -0
  150. package/lib/components/MonacoInput/themes/monokai.d.ts +31 -0
  151. package/lib/components/MonacoInput/themes/monokai.js +142 -0
  152. package/lib/components/PolyInput/index.d.ts +21 -0
  153. package/lib/components/PolyInput/index.js +100 -0
  154. package/lib/components/PolyInput/styles.less +31 -0
  155. package/lib/components/PositionInput/index.d.ts +9 -0
  156. package/lib/components/PositionInput/index.js +29 -0
  157. package/lib/components/PositionInput/styles.less +28 -0
  158. package/lib/components/SizeInput/index.d.ts +3 -0
  159. package/lib/components/SizeInput/index.js +56 -0
  160. package/lib/components/SizeInput/styles.less +23 -0
  161. package/lib/components/ValueInput/index.d.ts +2 -0
  162. package/lib/components/ValueInput/index.js +84 -0
  163. package/lib/components/ValueInput/styles.less +0 -0
  164. package/lib/components/index.d.ts +20 -0
  165. package/lib/components/index.js +36 -0
  166. package/lib/effects/index.d.ts +2 -0
  167. package/lib/effects/index.js +18 -0
  168. package/lib/effects/useLocales.d.ts +2 -0
  169. package/lib/effects/useLocales.js +67 -0
  170. package/lib/effects/useSnapshot.d.ts +2 -0
  171. package/lib/effects/useSnapshot.js +14 -0
  172. package/lib/index.d.ts +5 -0
  173. package/lib/index.js +21 -0
  174. package/lib/locales/en-US.d.ts +13 -0
  175. package/lib/locales/en-US.js +14 -0
  176. package/lib/locales/index.d.ts +1 -0
  177. package/lib/locales/index.js +10 -0
  178. package/lib/locales/ko-KR.d.ts +13 -0
  179. package/lib/locales/ko-KR.js +14 -0
  180. package/lib/locales/zh-CN.d.ts +13 -0
  181. package/lib/locales/zh-CN.js +14 -0
  182. package/lib/registry.d.ts +2 -0
  183. package/lib/registry.js +21 -0
  184. package/lib/shared/context.d.ts +3 -0
  185. package/lib/shared/context.js +5 -0
  186. package/lib/shared/loadScript.d.ts +7 -0
  187. package/lib/shared/loadScript.js +33 -0
  188. package/lib/styles.less +121 -0
  189. package/lib/types.d.ts +10 -0
  190. package/lib/types.js +2 -0
  191. 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,3 @@
1
+ /// <reference types="react" />
2
+ export declare const SizeInput: import("react").FC<import("../PolyInput").IInput>;
3
+ export declare const BackgroundSizeInput: import("react").FC<import("../PolyInput").IInput>;
@@ -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,2 @@
1
+ import React from 'react';
2
+ export declare const ValueInput: React.FC<import("../PolyInput").IInput>;
@@ -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,2 @@
1
+ export * from './useLocales';
2
+ export * from './useSnapshot';
@@ -0,0 +1,2 @@
1
+ export * from './useLocales';
2
+ export * from './useSnapshot';
@@ -0,0 +1,2 @@
1
+ import { TreeNode } from '@thienvu18/designable-core';
2
+ export declare const useLocales: (node: TreeNode) => void;
@@ -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,2 @@
1
+ import { Operation } from '@thienvu18/designable-core';
2
+ export declare const useSnapshot: (operation: Operation) => void;
@@ -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
@@ -0,0 +1,5 @@
1
+ import './locales';
2
+ export * from './registry';
3
+ export * from './components';
4
+ export * from './SchemaField';
5
+ export * from './SettingsForm';
package/esm/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import './locales';
2
+ export * from './registry';
3
+ export * from './components';
4
+ export * from './SchemaField';
5
+ export * from './SettingsForm';
@@ -0,0 +1,13 @@
1
+ declare const _default: {
2
+ 'en-US': {
3
+ SettingComponents: {
4
+ ValueInput: {
5
+ expression: string;
6
+ };
7
+ MonacoInput: {
8
+ helpDocument: string;
9
+ };
10
+ };
11
+ };
12
+ };
13
+ export default _default;
@@ -0,0 +1,12 @@
1
+ export default {
2
+ 'en-US': {
3
+ SettingComponents: {
4
+ ValueInput: {
5
+ expression: 'Expression',
6
+ },
7
+ MonacoInput: {
8
+ helpDocument: 'Help Documents',
9
+ },
10
+ },
11
+ },
12
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { GlobalRegistry } from '@thienvu18/designable-core';
2
+ import zhCN from './zh-CN';
3
+ import enUS from './en-US';
4
+ import koKR from './ko-KR';
5
+ GlobalRegistry.registerDesignerLocales(zhCN, enUS, koKR);
@@ -0,0 +1,13 @@
1
+ declare const _default: {
2
+ 'ko-KR': {
3
+ SettingComponents: {
4
+ ValueInput: {
5
+ expression: string;
6
+ };
7
+ MonacoInput: {
8
+ helpDocument: string;
9
+ };
10
+ };
11
+ };
12
+ };
13
+ export default _default;
@@ -0,0 +1,12 @@
1
+ export default {
2
+ 'ko-KR': {
3
+ SettingComponents: {
4
+ ValueInput: {
5
+ expression: '표현식',
6
+ },
7
+ MonacoInput: {
8
+ helpDocument: '도움말 문서',
9
+ },
10
+ },
11
+ },
12
+ };
@@ -0,0 +1,13 @@
1
+ declare const _default: {
2
+ 'zh-CN': {
3
+ SettingComponents: {
4
+ ValueInput: {
5
+ expression: string;
6
+ };
7
+ MonacoInput: {
8
+ helpDocument: string;
9
+ };
10
+ };
11
+ };
12
+ };
13
+ export default _default;
@@ -0,0 +1,12 @@
1
+ export default {
2
+ 'zh-CN': {
3
+ SettingComponents: {
4
+ ValueInput: {
5
+ expression: '表达式',
6
+ },
7
+ MonacoInput: {
8
+ helpDocument: '帮助文档',
9
+ },
10
+ },
11
+ },
12
+ };
@@ -0,0 +1,2 @@
1
+ export declare const setNpmCDNRegistry: (registry: string) => void;
2
+ export declare const getNpmCDNRegistry: () => string;
@@ -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,3 @@
1
+ /// <reference types="react" />
2
+ import { ISettingFormProps } from '../types';
3
+ export declare const SettingsFormContext: import("react").Context<ISettingFormProps>;
@@ -0,0 +1,2 @@
1
+ import { createContext } from 'react';
2
+ export const SettingsFormContext = createContext(null);
@@ -0,0 +1,7 @@
1
+ export interface ILoadScriptProps {
2
+ package: string;
3
+ entry: string;
4
+ root: string;
5
+ base?: string;
6
+ }
7
+ export declare const loadScript: (props: ILoadScriptProps) => Promise<any>;
@@ -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
+ };