@formily-design/formily-setters 1.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 (108) hide show
  1. package/.umirc.js +44 -0
  2. package/LICENSE.md +20 -0
  3. package/README.md +7 -0
  4. package/copy.ts +6 -0
  5. package/esm/components/DataSourceSetter/DataSettingPanel.d.ts +10 -0
  6. package/esm/components/DataSourceSetter/DataSettingPanel.js +66 -0
  7. package/esm/components/DataSourceSetter/Header.d.ts +7 -0
  8. package/esm/components/DataSourceSetter/Header.js +10 -0
  9. package/esm/components/DataSourceSetter/Title.d.ts +7 -0
  10. package/esm/components/DataSourceSetter/Title.js +50 -0
  11. package/esm/components/DataSourceSetter/TreePanel.d.ts +12 -0
  12. package/esm/components/DataSourceSetter/TreePanel.js +98 -0
  13. package/esm/components/DataSourceSetter/index.d.ts +18 -0
  14. package/esm/components/DataSourceSetter/index.js +34 -0
  15. package/esm/components/DataSourceSetter/shared.d.ts +9 -0
  16. package/esm/components/DataSourceSetter/shared.js +47 -0
  17. package/esm/components/DataSourceSetter/styles.less +80 -0
  18. package/esm/components/DataSourceSetter/types.d.ts +18 -0
  19. package/esm/components/DataSourceSetter/types.js +1 -0
  20. package/esm/components/ReactionsSetter/FieldPropertySetter.d.ts +10 -0
  21. package/esm/components/ReactionsSetter/FieldPropertySetter.js +83 -0
  22. package/esm/components/ReactionsSetter/PathSelector.d.ts +10 -0
  23. package/esm/components/ReactionsSetter/PathSelector.js +107 -0
  24. package/esm/components/ReactionsSetter/declarations.d.ts +5 -0
  25. package/esm/components/ReactionsSetter/declarations.js +51 -0
  26. package/esm/components/ReactionsSetter/helpers.d.ts +10 -0
  27. package/esm/components/ReactionsSetter/helpers.js +384 -0
  28. package/esm/components/ReactionsSetter/index.d.ts +8 -0
  29. package/esm/components/ReactionsSetter/index.js +282 -0
  30. package/esm/components/ReactionsSetter/properties.d.ts +11 -0
  31. package/esm/components/ReactionsSetter/properties.js +41 -0
  32. package/esm/components/ReactionsSetter/styles.less +103 -0
  33. package/esm/components/ReactionsSetter/types.d.ts +13 -0
  34. package/esm/components/ReactionsSetter/types.js +1 -0
  35. package/esm/components/RemoteDataSourceSetter/RemoteDataSourcePanel.d.ts +8 -0
  36. package/esm/components/RemoteDataSourceSetter/RemoteDataSourcePanel.js +103 -0
  37. package/esm/components/RemoteDataSourceSetter/index.d.ts +17 -0
  38. package/esm/components/RemoteDataSourceSetter/index.js +25 -0
  39. package/esm/components/RemoteDataSourceSetter/styles.less +33 -0
  40. package/esm/components/RemoteDataSourceSetter/types.d.ts +8 -0
  41. package/esm/components/RemoteDataSourceSetter/types.js +1 -0
  42. package/esm/components/ValidatorSetter/index.d.ts +6 -0
  43. package/esm/components/ValidatorSetter/index.js +140 -0
  44. package/esm/components/index.d.ts +4 -0
  45. package/esm/components/index.js +4 -0
  46. package/esm/index.d.ts +2 -0
  47. package/esm/index.js +2 -0
  48. package/esm/locales/en-US.d.ts +110 -0
  49. package/esm/locales/en-US.js +115 -0
  50. package/esm/locales/index.d.ts +1 -0
  51. package/esm/locales/index.js +5 -0
  52. package/esm/locales/ko-KR.d.ts +110 -0
  53. package/esm/locales/ko-KR.js +115 -0
  54. package/esm/locales/zh-CN.d.ts +110 -0
  55. package/esm/locales/zh-CN.js +115 -0
  56. package/lib/components/DataSourceSetter/DataSettingPanel.d.ts +10 -0
  57. package/lib/components/DataSourceSetter/DataSettingPanel.js +102 -0
  58. package/lib/components/DataSourceSetter/Header.d.ts +7 -0
  59. package/lib/components/DataSourceSetter/Header.js +16 -0
  60. package/lib/components/DataSourceSetter/Title.d.ts +7 -0
  61. package/lib/components/DataSourceSetter/Title.js +56 -0
  62. package/lib/components/DataSourceSetter/TreePanel.d.ts +12 -0
  63. package/lib/components/DataSourceSetter/TreePanel.js +134 -0
  64. package/lib/components/DataSourceSetter/index.d.ts +18 -0
  65. package/lib/components/DataSourceSetter/index.js +73 -0
  66. package/lib/components/DataSourceSetter/shared.d.ts +9 -0
  67. package/lib/components/DataSourceSetter/shared.js +53 -0
  68. package/lib/components/DataSourceSetter/styles.less +80 -0
  69. package/lib/components/DataSourceSetter/types.d.ts +18 -0
  70. package/lib/components/DataSourceSetter/types.js +2 -0
  71. package/lib/components/ReactionsSetter/FieldPropertySetter.d.ts +10 -0
  72. package/lib/components/ReactionsSetter/FieldPropertySetter.js +120 -0
  73. package/lib/components/ReactionsSetter/PathSelector.d.ts +10 -0
  74. package/lib/components/ReactionsSetter/PathSelector.js +114 -0
  75. package/lib/components/ReactionsSetter/declarations.d.ts +5 -0
  76. package/lib/components/ReactionsSetter/declarations.js +55 -0
  77. package/lib/components/ReactionsSetter/helpers.d.ts +10 -0
  78. package/lib/components/ReactionsSetter/helpers.js +387 -0
  79. package/lib/components/ReactionsSetter/index.d.ts +8 -0
  80. package/lib/components/ReactionsSetter/index.js +319 -0
  81. package/lib/components/ReactionsSetter/properties.d.ts +11 -0
  82. package/lib/components/ReactionsSetter/properties.js +44 -0
  83. package/lib/components/ReactionsSetter/styles.less +103 -0
  84. package/lib/components/ReactionsSetter/types.d.ts +13 -0
  85. package/lib/components/ReactionsSetter/types.js +2 -0
  86. package/lib/components/RemoteDataSourceSetter/RemoteDataSourcePanel.d.ts +8 -0
  87. package/lib/components/RemoteDataSourceSetter/RemoteDataSourcePanel.js +140 -0
  88. package/lib/components/RemoteDataSourceSetter/index.d.ts +17 -0
  89. package/lib/components/RemoteDataSourceSetter/index.js +64 -0
  90. package/lib/components/RemoteDataSourceSetter/styles.less +33 -0
  91. package/lib/components/RemoteDataSourceSetter/types.d.ts +8 -0
  92. package/lib/components/RemoteDataSourceSetter/types.js +2 -0
  93. package/lib/components/ValidatorSetter/index.d.ts +6 -0
  94. package/lib/components/ValidatorSetter/index.js +146 -0
  95. package/lib/components/index.d.ts +4 -0
  96. package/lib/components/index.js +20 -0
  97. package/lib/index.d.ts +2 -0
  98. package/lib/index.js +18 -0
  99. package/lib/locales/en-US.d.ts +110 -0
  100. package/lib/locales/en-US.js +117 -0
  101. package/lib/locales/index.d.ts +1 -0
  102. package/lib/locales/index.js +10 -0
  103. package/lib/locales/ko-KR.d.ts +110 -0
  104. package/lib/locales/ko-KR.js +117 -0
  105. package/lib/locales/zh-CN.d.ts +110 -0
  106. package/lib/locales/zh-CN.js +117 -0
  107. package/package.json +53 -0
  108. package/tsconfig.build.json +10 -0
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.DataSourceSetter = void 0;
40
+ const react_1 = __importStar(require("react"));
41
+ const classnames_1 = __importDefault(require("classnames"));
42
+ const antd_1 = require("antd");
43
+ const reactive_1 = require("@formily/reactive");
44
+ const reactive_react_1 = require("@formily/reactive-react");
45
+ const react_2 = require("@formily-design/react");
46
+ const DataSettingPanel_1 = require("./DataSettingPanel");
47
+ const TreePanel_1 = require("./TreePanel");
48
+ const shared_1 = require("./shared");
49
+ require("./styles.less");
50
+ exports.DataSourceSetter = (0, reactive_react_1.observer)((props) => {
51
+ const { className, value = [], onChange, allowTree = true, allowExtendOption = true, defaultOptionValue, effects = () => { }, } = props;
52
+ const theme = (0, react_2.useTheme)();
53
+ const prefix = (0, react_2.usePrefix)('data-source-setter');
54
+ const [modalVisible, setModalVisible] = (0, react_1.useState)(false);
55
+ const treeDataSource = (0, react_1.useMemo)(() => (0, reactive_1.observable)({
56
+ dataSource: (0, shared_1.transformValueToData)(value),
57
+ selectedKey: '',
58
+ }), [value, modalVisible]);
59
+ const openModal = () => setModalVisible(true);
60
+ const closeModal = () => setModalVisible(false);
61
+ return (react_1.default.createElement(react_1.Fragment, null,
62
+ react_1.default.createElement(antd_1.Button, { block: true, onClick: openModal },
63
+ react_1.default.createElement(react_2.TextWidget, { token: "SettingComponents.DataSourceSetter.configureDataSource" })),
64
+ react_1.default.createElement(antd_1.Modal, { title: react_1.default.createElement(react_2.TextWidget, { token: "SettingComponents.DataSourceSetter.configureDataSource" }), width: "65%", bodyStyle: { padding: 10 }, transitionName: "", maskTransitionName: "", visible: modalVisible, onCancel: closeModal, onOk: () => {
65
+ onChange((0, shared_1.transformDataToValue)(treeDataSource.dataSource));
66
+ closeModal();
67
+ } },
68
+ react_1.default.createElement("div", { className: `${(0, classnames_1.default)(prefix, className)} ${prefix + '-' + theme} ${prefix + '-layout'}` },
69
+ react_1.default.createElement("div", { className: `${prefix + '-layout-item left'}` },
70
+ react_1.default.createElement(TreePanel_1.TreePanel, { defaultOptionValue: defaultOptionValue, allowTree: allowTree, treeDataSource: treeDataSource })),
71
+ react_1.default.createElement("div", { className: `${prefix + '-layout-item right'}` },
72
+ react_1.default.createElement(DataSettingPanel_1.DataSettingPanel, { allowExtendOption: allowExtendOption, treeDataSource: treeDataSource, effects: effects }))))));
73
+ });
@@ -0,0 +1,9 @@
1
+ import { IDataSourceItem, INodeItem } from './types';
2
+ export interface INode {
3
+ key?: string;
4
+ map?: any;
5
+ children?: INode[];
6
+ }
7
+ export declare const traverseTree: <T extends INode>(data: T[], callback: (dataItem: T, i: number, data: T[]) => any) => void;
8
+ export declare const transformValueToData: (value: IDataSourceItem[]) => INodeItem[];
9
+ export declare const transformDataToValue: (data: INodeItem[]) => IDataSourceItem[];
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformDataToValue = exports.transformValueToData = exports.traverseTree = void 0;
4
+ const shared_1 = require("@formily/shared");
5
+ const traverseTree = (data, callback) => {
6
+ var _a, _b;
7
+ for (let i = 0; i < data.length; i++) {
8
+ callback(data[i], i, data);
9
+ if ((_a = data[i]) === null || _a === void 0 ? void 0 : _a.children) {
10
+ (0, exports.traverseTree)((_b = data[i]) === null || _b === void 0 ? void 0 : _b.children, callback);
11
+ }
12
+ }
13
+ };
14
+ exports.traverseTree = traverseTree;
15
+ const transformValueToData = (value) => {
16
+ const data = (0, shared_1.clone)(value);
17
+ (0, exports.traverseTree)(data, (item, i, dataSource) => {
18
+ const dataItem = {
19
+ key: '',
20
+ duplicateKey: '',
21
+ map: [],
22
+ children: [],
23
+ };
24
+ for (const [key, value] of Object.entries(dataSource[i] || {})) {
25
+ if (key !== 'children')
26
+ dataItem.map.push({ label: key, value: value });
27
+ }
28
+ const uuid = (0, shared_1.uid)();
29
+ dataItem.key = uuid;
30
+ dataItem.duplicateKey = uuid;
31
+ dataItem.children = dataSource[i].children || [];
32
+ dataSource[i] = dataItem;
33
+ });
34
+ return data;
35
+ };
36
+ exports.transformValueToData = transformValueToData;
37
+ const transformDataToValue = (data) => {
38
+ const value = (0, shared_1.clone)(data);
39
+ (0, exports.traverseTree)(value, (item, i, dataSource) => {
40
+ var _a;
41
+ const valueItem = {
42
+ children: [],
43
+ };
44
+ (0, shared_1.toArr)(dataSource[i].map).forEach((item) => {
45
+ if (item.label)
46
+ valueItem[item.label] = item.value;
47
+ });
48
+ valueItem.children = ((_a = dataSource[i]) === null || _a === void 0 ? void 0 : _a.children) || [];
49
+ dataSource[i] = valueItem;
50
+ });
51
+ return value;
52
+ };
53
+ exports.transformDataToValue = transformDataToValue;
@@ -0,0 +1,80 @@
1
+ @root-entry-name: 'default';
2
+
3
+ .dn-data-source-setter {
4
+ ::-webkit-scrollbar {
5
+ width: 5px;
6
+ height: 5px;
7
+ }
8
+
9
+ ::-webkit-scrollbar-thumb {
10
+ background-color: rgba(0, 0, 0, 0.2);
11
+ border-radius: 0;
12
+ transition: all 0.25s ease-in-out;
13
+ }
14
+
15
+ ::-webkit-scrollbar-thumb:hover {
16
+ background-color: rgba(0, 0, 0, 0.3);
17
+ }
18
+ &-node-title {
19
+ display: flex;
20
+ justify-content: space-between;
21
+ align-items: center;
22
+
23
+ &-icon {
24
+ transition: all 0.15s ease-in-out;
25
+ opacity: 0;
26
+
27
+ &:hover {
28
+ }
29
+ }
30
+ }
31
+
32
+ &-layout {
33
+ display: flex;
34
+ justify-content: space-around;
35
+ border: 1px solid #d9d9d9;
36
+ border-radius: 3px;
37
+
38
+ .ant-tree-treenode {
39
+ padding-right: 10px;
40
+ white-space: nowrap;
41
+
42
+ &:hover {
43
+ .dn-data-source-setter-node-title-icon {
44
+ opacity: 1;
45
+ }
46
+ }
47
+ }
48
+
49
+ &-item {
50
+ position: relative;
51
+
52
+ &.left {
53
+ width: 40%;
54
+ border-right: 1px solid #d9d9d9;
55
+ }
56
+
57
+ &.right {
58
+ width: 60%;
59
+ }
60
+
61
+ &-header {
62
+ display: flex;
63
+ flex: none;
64
+ align-items: center;
65
+ justify-content: space-between;
66
+ height: 40px;
67
+ padding: 8px 12px 9px;
68
+ border-bottom: 1px solid #d9d9d9;
69
+ border-radius: 2px 2px 0 0;
70
+ }
71
+
72
+ &-content {
73
+ padding: 2%;
74
+ height: 300px;
75
+ max-height: 300px;
76
+ overflow: scroll;
77
+ }
78
+ }
79
+ }
80
+ }
@@ -0,0 +1,18 @@
1
+ export interface IDataSourceItem {
2
+ label?: '';
3
+ value?: any;
4
+ children?: any[];
5
+ }
6
+ export interface INodeItem {
7
+ key: string;
8
+ duplicateKey?: string;
9
+ map?: {
10
+ label: string;
11
+ value: any;
12
+ }[];
13
+ children?: INodeItem[];
14
+ }
15
+ export interface ITreeDataSource {
16
+ dataSource: INodeItem[];
17
+ selectedKey: string;
18
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ export interface IFieldProperty {
3
+ [key: string]: string;
4
+ }
5
+ export interface IFieldPropertySetterProps {
6
+ extraLib?: string;
7
+ value?: IFieldProperty;
8
+ onChange?: (value: IFieldProperty) => void;
9
+ }
10
+ export declare const FieldPropertySetter: React.FC<IFieldPropertySetterProps>;
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.FieldPropertySetter = void 0;
37
+ const react_1 = __importStar(require("react"));
38
+ const react_2 = require("@formily-design/react");
39
+ const antd_1 = require("antd");
40
+ const react_settings_form_1 = require("@formily-design/react-settings-form");
41
+ const shared_1 = require("@formily/shared");
42
+ const properties_1 = require("./properties");
43
+ const template = (code) => {
44
+ if (!code)
45
+ return;
46
+ return code.trim();
47
+ };
48
+ const FieldPropertySetter = (props) => {
49
+ const [selectKeys, setSelectKeys] = (0, react_1.useState)(['visible']);
50
+ const prefix = (0, react_2.usePrefix)('field-property-setter');
51
+ const value = { ...props.value };
52
+ const parseExpression = (expression) => {
53
+ var _a;
54
+ if (!expression)
55
+ return '';
56
+ return ((_a = String(expression).match(/^\{\{([\s\S]*)\}\}$/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
57
+ };
58
+ const filterEmpty = (value) => {
59
+ return (0, shared_1.reduce)(value, (buf, value, key) => {
60
+ if (!value || value === '{{}}')
61
+ return buf;
62
+ buf[key] = value;
63
+ return buf;
64
+ }, {});
65
+ };
66
+ const currentProperty = properties_1.FieldProperties.find((item) => item.key === selectKeys[0]);
67
+ return (react_1.default.createElement("div", { className: prefix },
68
+ react_1.default.createElement(antd_1.Menu, { mode: "vertical", style: {
69
+ width: 200,
70
+ height: 300,
71
+ paddingRight: 4,
72
+ overflowY: 'auto',
73
+ overflowX: 'hidden',
74
+ }, defaultSelectedKeys: selectKeys, selectedKeys: selectKeys, onSelect: ({ selectedKeys }) => {
75
+ setSelectKeys(selectedKeys);
76
+ } }, properties_1.FieldProperties.map((key) => {
77
+ if ((0, shared_1.isPlainObj)(key)) {
78
+ return (react_1.default.createElement(antd_1.Menu.Item, { key: key.key },
79
+ react_1.default.createElement(react_2.TextWidget, { token: `SettingComponents.ReactionsSetter.${key.token || key.key}` })));
80
+ }
81
+ return (react_1.default.createElement(antd_1.Menu.Item, { key: key },
82
+ react_1.default.createElement(react_2.TextWidget, { token: `SettingComponents.ReactionsSetter.${key}` })));
83
+ })),
84
+ react_1.default.createElement("div", { className: prefix + '-coder-wrapper' },
85
+ react_1.default.createElement("div", { className: prefix + '-coder-start' },
86
+ `$self.${selectKeys[0]} = (`,
87
+ react_1.default.createElement("span", { style: {
88
+ fontSize: 14,
89
+ marginLeft: 10,
90
+ color: '#888',
91
+ fontWeight: 'normal',
92
+ } },
93
+ '//',
94
+ ' ',
95
+ react_1.default.createElement(react_2.TextWidget, { token: "SettingComponents.ReactionsSetter.expressionValueTypeIs" }),
96
+ ' ',
97
+ '`', currentProperty === null || currentProperty === void 0 ? void 0 :
98
+ currentProperty.type,
99
+ '`')),
100
+ react_1.default.createElement("div", { className: prefix + '-coder' },
101
+ react_1.default.createElement(react_settings_form_1.MonacoInput, { key: selectKeys[0], language: "javascript.expression", extraLib: props.extraLib, helpCode: template(currentProperty === null || currentProperty === void 0 ? void 0 : currentProperty.helpCode), value: parseExpression(value[selectKeys[0]]), options: {
102
+ lineNumbers: 'off',
103
+ wordWrap: 'on',
104
+ glyphMargin: false,
105
+ folding: false,
106
+ lineDecorationsWidth: 0,
107
+ lineNumbersMinChars: 0,
108
+ minimap: {
109
+ enabled: false,
110
+ },
111
+ }, onChange: (expression) => {
112
+ var _a;
113
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, filterEmpty({
114
+ ...value,
115
+ [selectKeys[0]]: `{{${expression}}}`,
116
+ }));
117
+ } })),
118
+ react_1.default.createElement("div", { className: prefix + '-coder-end' }, `)`))));
119
+ };
120
+ exports.FieldPropertySetter = FieldPropertySetter;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { TreeNode } from '@formily-design/core';
3
+ import { TreeSelectProps } from 'antd';
4
+ export interface IPathSelectorProps extends Omit<TreeSelectProps<any>, 'onChange'> {
5
+ value?: string;
6
+ onChange?: (value: string, node: TreeNode) => void;
7
+ style?: React.CSSProperties;
8
+ className?: string;
9
+ }
10
+ export declare const PathSelector: React.FC<IPathSelectorProps>;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PathSelector = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const react_2 = require("@formily-design/react");
9
+ const antd_1 = require("antd");
10
+ const transformDataSource = (node) => {
11
+ const currentNode = node;
12
+ const dots = (count) => {
13
+ let dots = '';
14
+ for (let i = 0; i < count; i++) {
15
+ dots += '.';
16
+ }
17
+ return dots;
18
+ };
19
+ const targetPath = (parentNode, targetNode) => {
20
+ const path = [];
21
+ const transform = (node) => {
22
+ if (node && node !== parentNode) {
23
+ path.push(node.props.name || node.id);
24
+ }
25
+ else {
26
+ transform(node.parent);
27
+ }
28
+ };
29
+ transform(targetNode);
30
+ return path.reverse().join('.');
31
+ };
32
+ const hasNoVoidChildren = (node) => {
33
+ var _a;
34
+ return (_a = node.children) === null || _a === void 0 ? void 0 : _a.some((node) => {
35
+ if (node.props.type !== 'void' && node !== currentNode)
36
+ return true;
37
+ return hasNoVoidChildren(node);
38
+ });
39
+ };
40
+ const findRoot = (node) => {
41
+ var _a;
42
+ if (!(node === null || node === void 0 ? void 0 : node.parent))
43
+ return node;
44
+ if (((_a = node === null || node === void 0 ? void 0 : node.parent) === null || _a === void 0 ? void 0 : _a.componentName) !== node.componentName)
45
+ return node.parent;
46
+ return findRoot(node.parent);
47
+ };
48
+ const findArrayParent = (node) => {
49
+ if (!(node === null || node === void 0 ? void 0 : node.parent))
50
+ return;
51
+ if (node.parent.props.type === 'array')
52
+ return node.parent;
53
+ if (node.parent === root)
54
+ return;
55
+ return findArrayParent(node.parent);
56
+ };
57
+ const transformRelativePath = (arrayNode, targetNode) => {
58
+ if (targetNode.depth === currentNode.depth)
59
+ return `.${targetNode.props.name || targetNode.id}`;
60
+ return `${dots(currentNode.depth - arrayNode.depth)}[].${targetPath(arrayNode, targetNode)}`;
61
+ };
62
+ const transformChildren = (children, path = []) => {
63
+ return children.reduce((buf, node) => {
64
+ var _a;
65
+ if (node === currentNode)
66
+ return buf;
67
+ if (node.props.type === 'array' && !node.contains(currentNode))
68
+ return buf;
69
+ if (node.props.type === 'void' && !hasNoVoidChildren(node))
70
+ return buf;
71
+ const currentPath = path.concat(node.props.name || node.id);
72
+ const arrayNode = findArrayParent(node);
73
+ const label = node.props.title ||
74
+ ((_a = node.props['x-component-props']) === null || _a === void 0 ? void 0 : _a.title) ||
75
+ node.props.name ||
76
+ node.designerProps.title;
77
+ const value = arrayNode
78
+ ? transformRelativePath(arrayNode, node)
79
+ : currentPath.join('.');
80
+ return buf.concat({
81
+ label,
82
+ value,
83
+ node,
84
+ children: transformChildren(node.children, currentPath),
85
+ });
86
+ }, []);
87
+ };
88
+ const root = findRoot(node);
89
+ if (root) {
90
+ return transformChildren(root.children);
91
+ }
92
+ return [];
93
+ };
94
+ const PathSelector = (props) => {
95
+ const baseNode = (0, react_2.useSelectedNode)();
96
+ const dataSource = transformDataSource(baseNode);
97
+ const findNode = (dataSource, value) => {
98
+ var _a;
99
+ for (let i = 0; i < dataSource.length; i++) {
100
+ const item = dataSource[i];
101
+ if (item.value === value)
102
+ return item.node;
103
+ if ((_a = item.children) === null || _a === void 0 ? void 0 : _a.length) {
104
+ const fondedChild = findNode(item.children, value);
105
+ if (fondedChild)
106
+ return fondedChild;
107
+ }
108
+ }
109
+ };
110
+ return (react_1.default.createElement(antd_1.TreeSelect, { ...props, onChange: (value) => {
111
+ props.onChange(value, findNode(dataSource, value));
112
+ }, treeDefaultExpandAll: true, treeData: dataSource }));
113
+ };
114
+ exports.PathSelector = PathSelector;
@@ -0,0 +1,5 @@
1
+ export interface IDependency {
2
+ name: string;
3
+ path: string;
4
+ }
5
+ export declare const initDeclaration: () => Promise<void>;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initDeclaration = void 0;
4
+ const react_settings_form_1 = require("@formily-design/react-settings-form");
5
+ const loadDependencies = async (deps) => {
6
+ return Promise.all(deps.map(async ({ name, path }) => ({
7
+ name,
8
+ path,
9
+ library: await fetch(`${(0, react_settings_form_1.getNpmCDNRegistry)()}/${name}/${path}`).then((res) => res.text()),
10
+ })));
11
+ };
12
+ const initDeclaration = async () => {
13
+ return react_settings_form_1.MonacoInput.loader.init().then(async (monaco) => {
14
+ const deps = await loadDependencies([
15
+ { name: '@formily/core', path: 'dist/formily.core.all.d.ts' },
16
+ ]);
17
+ deps === null || deps === void 0 ? void 0 : deps.forEach(({ name, library }) => {
18
+ monaco.languages.typescript.typescriptDefaults.addExtraLib(`declare module '${name}'{ ${library} }`, `file:///node_modules/${name}/index.d.ts`);
19
+ });
20
+ monaco.languages.typescript.typescriptDefaults.addExtraLib(`
21
+ import { Form, Field } from '@formily/core'
22
+ declare global {
23
+ /*
24
+ * Form Model
25
+ **/
26
+ declare var $form: Form
27
+ /*
28
+ * Form Values
29
+ **/
30
+ declare var $values: any
31
+ /*
32
+ * Field Model
33
+ **/
34
+ declare var $self: Field
35
+ /*
36
+ * create an persistent observable state object
37
+ **/
38
+ declare var $observable: <T>(target: T, deps?: any[]) => T
39
+ /*
40
+ * create a persistent data
41
+ **/
42
+ declare var $memo: <T>(callback: () => T, deps?: any[]) => T
43
+ /*
44
+ * handle side-effect logic
45
+ **/
46
+ declare var $effect: (callback: () => void | (() => void), deps?: any[]) => void
47
+ /*
48
+ * set initial component props to current field
49
+ **/
50
+ declare var $props: (props: any) => void
51
+ }
52
+ `, `file:///node_modules/formily_global.d.ts`);
53
+ });
54
+ };
55
+ exports.initDeclaration = initDeclaration;
@@ -0,0 +1,10 @@
1
+ export declare const GlobalHelper = "\n/** \n * You can use the built-in context variables\n * \n * 1. `$self` is the current Field Model \n * \n * 2. `$form` is the current Form Model \n * \n * 3. `$deps` is the dependencies value\n * \n * 4. `$observable` function is used to create an persistent observable state object\n *\n * 5. `$memo` function is is used to create a persistent data\n * \n * 6. `$effect` function is used to handle side-effect logic\n * \n * 7. `$props` function is used to set component props to current field\n * \n * Document Links\n * \n * https://react.formilyjs.org/api/shared/schema#%E5%86%85%E7%BD%AE%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BD%9C%E7%94%A8%E5%9F%9F\n **/\n";
2
+ export declare const BooleanHelper = "\n/** \n * Example 1\n * Static Boolean\n **/\n\nfalse\n\n/** \n * Example 2\n * Equal Calculation\n **/\n\n$deps.VariableName === 'TARGET_VALUE'\n\n/** \n * Example 3\n * Not Equal Calculation\n **/\n\n$deps.VariableName !== 'TARGET_VALUE'\n\n/** \n * Example 4\n * And Logic Calculation\n **/\n\n$deps.VariableName1 && $deps.VariableName2\n\n/** \n * Example 5\n * Grater Logic Calculation\n **/\n\n$deps.VariableName > 100\n\n/** \n * Example 6\n * Not Logic Calculation\n **/\n\n!$deps.VariableName\n\n\n/** \n * You can use the built-in context variables\n * \n * 1. `$self` is the current Field Model \n * \n * 2. `$form` is the current Form Model \n * \n * 3. `$deps` is the dependencies value\n * \n * 4. `$observable` function is used to create an persistent observable state object\n *\n * 5. `$memo` function is is used to create a persistent data\n * \n * 6. `$effect` function is used to handle side-effect logic\n * \n * 7. `$props` function is used to set component props to current field\n * \n * Document Links\n * \n * https://react.formilyjs.org/api/shared/schema#%E5%86%85%E7%BD%AE%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BD%9C%E7%94%A8%E5%9F%9F\n **/\n\n";
3
+ export declare const DisplayHelper = "\n/** \n * Example 1\n * Static Mode\n **/\n\n'none'\n\n/** \n * Example 2\n * Equal Condition Associated\n **/\n\n$deps.VariableName === 'TARGET_VALUE' ? 'visible' : 'none'\n\n/** \n * Example 3\n * Not Equal Condition Associated\n **/\n\n$deps.VariableName !== 'TARGET_VALUE' ? 'visible' : 'hidden'\n\n/** \n * Example 4\n * And Logic Condition Associated\n **/\n\n$deps.VariableName1 && $deps.VariableName2 ? 'visible' : 'none'\n\n/** \n * Example 5\n * Grater Logic Condition Associated\n **/\n\n$deps.VariableName > 100 ? 'visible' : 'hidden'\n\n/** \n * Example 6\n * Not Logic Condition Associated\n **/\n\n!$deps.VariableName ? 'visible' : 'none'\n\n\n/** \n * You can use the built-in context variables\n * \n * 1. `$self` is the current Field Model \n * \n * 2. `$form` is the current Form Model \n * \n * 3. `$deps` is the dependencies value\n * \n * 4. `$observable` function is used to create an persistent observable state object\n *\n * 5. `$memo` function is is used to create a persistent data\n * \n * 6. `$effect` function is used to handle side-effect logic\n * \n * 7. `$props` function is used to set component props to current field\n * \n * Document Links\n * \n * https://react.formilyjs.org/api/shared/schema#%E5%86%85%E7%BD%AE%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BD%9C%E7%94%A8%E5%9F%9F\n **/\n\n";
4
+ export declare const PatternHelper = "\n/** \n * Example 1\n * Static Mode\n **/\n\n'readPretty'\n\n/** \n * Example 2\n * Equal Condition Associated\n **/\n\n$deps.VariableName === 'TARGET_VALUE' ? 'editable' : 'disabled'\n\n/** \n * Example 3\n * Not Equal Condition Associated\n **/\n\n$deps.VariableName !== 'TARGET_VALUE' ? 'editable' : 'readOnly'\n\n/** \n * Example 4\n * And Logic Condition Associated\n **/\n\n$deps.VariableName1 && $deps.VariableName2 ? 'editable' : 'readPretty'\n\n/** \n * Example 5\n * Grater Logic Condition Associated\n **/\n\n$deps.VariableName > 100 ? 'editable' : 'readOnly'\n\n/** \n * Example 6\n * Not Logic Condition Associated\n **/\n\n!$deps.VariableName ? 'editable' : 'disabled'\n\n\n/** \n * You can use the built-in context variables\n * \n * 1. `$self` is the current Field Model \n * \n * 2. `$form` is the current Form Model \n * \n * 3. `$deps` is the dependencies value\n * \n * 4. `$observable` function is used to create an persistent observable state object\n *\n * 5. `$memo` function is is used to create a persistent data\n * \n * 6. `$effect` function is used to handle side-effect logic\n * \n * 7. `$props` function is used to set component props to current field\n * \n * Document Links\n * \n * https://react.formilyjs.org/api/shared/schema#%E5%86%85%E7%BD%AE%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BD%9C%E7%94%A8%E5%9F%9F\n **/\n\n";
5
+ export declare const StringHelper = "\n/** \n * Example 1\n * Static String\n **/\n\n'Normal String Text'\n\n/** \n * Example 2\n * Associated String\n **/\n\n$deps.VariableName === 'TARGET_VALUE' ? 'Associated String Text' : ''\n\n\n/** \n * You can use the built-in context variables\n * \n * 1. `$self` is the current Field Model \n * \n * 2. `$form` is the current Form Model \n * \n * 3. `$deps` is the dependencies value\n * \n * 4. `$observable` function is used to create an persistent observable state object\n *\n * 5. `$memo` function is is used to create a persistent data\n * \n * 6. `$effect` function is used to handle side-effect logic\n * \n * 7. `$props` function is used to set component props to current field\n * \n * Document Links\n * \n * https://react.formilyjs.org/api/shared/schema#%E5%86%85%E7%BD%AE%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BD%9C%E7%94%A8%E5%9F%9F\n **/\n\n";
6
+ export declare const AnyHelper = "\n/** \n * Example 1\n * String Type\n **/\n\n'String'\n\n/** \n * Example 2\n * String Array\n **/\n\n['StringArray']\n\n/** \n * Example 3\n * Object Array\n **/\n\n[{ key: 'ObjectArray' }]\n\n/** \n * Example 4\n * Boolean\n **/\n\ntrue\n\n/** \n * Example 5\n * RegExp\n **/\n\n/d+/\n\n/** \n * Example 1\n * Associated String Value\n **/\n\n$deps.VariableName + 'Compose String'\n\n/** \n * Example 2\n * Associated Array Value\n **/\n\n[ $deps.VariableName ]\n\n/** \n * Example 3\n * Associated Object Value\n **/\n\n{\n key : $deps.VariableName\n}\n\n/** \n * Example 4\n * Associated Boolean Value\n **/\n\n!$deps.VariableName\n\n\n/** \n * You can use the built-in context variables\n * \n * 1. `$self` is the current Field Model \n * \n * 2. `$form` is the current Form Model \n * \n * 3. `$deps` is the dependencies value\n * \n * 4. `$observable` function is used to create an persistent observable state object\n *\n * 5. `$memo` function is is used to create a persistent data\n * \n * 6. `$effect` function is used to handle side-effect logic\n * \n * 7. `$props` function is used to set component props to current field\n * \n * Document Links\n * \n * https://react.formilyjs.org/api/shared/schema#%E5%86%85%E7%BD%AE%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BD%9C%E7%94%A8%E5%9F%9F\n **/\n\n";
7
+ export declare const DataSourceHelper = "\n/** \n * Example 1\n * Static DataSource\n **/\n\n[\n { label : \"item1\", value: \"1\" },\n { label : \"item2\", value: \"2\" }\n]\n\n/** \n * Example 2\n * Associated DataSource\n **/\n\n[\n { label : \"item1\", value: \"1\" },\n { label : \"item2\", value: \"2\" },\n ...$deps.VariableName\n]\n\n\n/** \n * You can use the built-in context variables\n * \n * 1. `$self` is the current Field Model \n * \n * 2. `$form` is the current Form Model \n * \n * 3. `$deps` is the dependencies value\n * \n * 4. `$observable` function is used to create an persistent observable state object\n *\n * 5. `$memo` function is is used to create a persistent data\n * \n * 6. `$effect` function is used to handle side-effect logic\n * \n * 7. `$props` function is used to set component props to current field\n * \n * Document Links\n * \n * https://react.formilyjs.org/api/shared/schema#%E5%86%85%E7%BD%AE%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BD%9C%E7%94%A8%E5%9F%9F\n **/\n\n";
8
+ export declare const ComponentPropsHelper = "\n/** \n * Example 1\n * Static Props\n **/\n\n{\n placeholder: \"This is placeholder\"\n}\n\n/** \n * Example 2\n * Associated Props\n **/\n\n{\n placeholder: $deps.VariableName\n}\n\n\n/** \n * You can use the built-in context variables\n * \n * 1. `$self` is the current Field Model \n * \n * 2. `$form` is the current Form Model \n * \n * 3. `$deps` is the dependencies value\n * \n * 4. `$observable` function is used to create an persistent observable state object\n *\n * 5. `$memo` function is is used to create a persistent data\n * \n * 6. `$effect` function is used to handle side-effect logic\n * \n * 7. `$props` function is used to set component props to current field\n * \n * Document Links\n * \n * https://react.formilyjs.org/api/shared/schema#%E5%86%85%E7%BD%AE%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BD%9C%E7%94%A8%E5%9F%9F\n **/\n\n";
9
+ export declare const DecoratorPropsHelper = "\n/** \n * Example 1\n * Static Props\n **/\n\n{\n labelCol:6\n}\n\n/** \n * Example 2\n * Associated Props\n **/\n\n{\n labelCol: $deps.VariableName\n}\n\n\n/** \n * You can use the built-in context variables\n * \n * 1. `$self` is the current Field Model \n * \n * 2. `$form` is the current Form Model \n * \n * 3. `$deps` is the dependencies value\n * \n * 4. `$observable` function is used to create an persistent observable state object\n *\n * 5. `$memo` function is is used to create a persistent data\n * \n * 6. `$effect` function is used to handle side-effect logic\n * \n * 7. `$props` function is used to set component props to current field\n * \n * Document Links\n * \n * https://react.formilyjs.org/api/shared/schema#%E5%86%85%E7%BD%AE%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BD%9C%E7%94%A8%E5%9F%9F\n **/\n\n";
10
+ export declare const FulfillRunHelper = "\n/** \n * Example 1\n * Async Select\n **/\n\n$effect(()=>{\n $self.loading = true\n fetch('//some.domain/getSomething')\n .then(response=>response.json())\n .then(({ data })=>{\n $self.loading = false\n $self.dataSource = data\n },()=>{\n $self.loading = false\n })\n},[])\n \n\n/** \n * Example 2\n * Async Search Select\n **/\n\nconst state = $observable({\n keyword:''\n})\n\n$props({\n onSearch(keyword){\n state.keyword = keyword\n }\n})\n\n$effect(()=>{\n $self.loading = true\n fetch(`//some.domain/getSomething?q=${state.keyword}`)\n .then(response=>response.json())\n .then(({ data })=>{\n $self.loading = false\n $self.dataSource = data\n },()=>{\n $self.loading = false\n })\n},[ state.keyword ])\n\n/** \n * Example 3\n * Async Associated Select\n **/\n\nconst state = $observable({\n keyword:''\n})\n\n$props({\n onSearch(keyword){\n state.keyword = keyword\n }\n})\n\n$effect(()=>{\n $self.loading = true\n fetch(`//some.domain/getSomething?q=${state.keyword}&other=${$deps.VariableName}`)\n .then(response=>response.json())\n .then(({ data })=>{\n $self.loading = false\n $self.dataSource = data\n },()=>{\n $self.loading = false\n })\n},[ state.keyword, $deps.VariableName ])\n\n\n/** \n * You can use the built-in context variables\n * \n * 1. `$self` is the current Field Model \n * \n * 2. `$form` is the current Form Model \n * \n * 3. `$deps` is the dependencies value\n * \n * 4. `$observable` function is used to create an persistent observable state object\n *\n * 5. `$memo` function is is used to create a persistent data\n * \n * 6. `$effect` function is used to handle side-effect logic\n * \n * 7. `$props` function is used to set component props to current field\n * \n * Document Links\n * \n * https://react.formilyjs.org/api/shared/schema#%E5%86%85%E7%BD%AE%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BD%9C%E7%94%A8%E5%9F%9F\n **/\n\n";