@nokecy/designer-formily-setters 0.0.0-stage → 2.0.0-beta.11
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 +21 -0
- package/LICENSE.md +21 -0
- package/PROVENANCE.json +45 -0
- package/README.md +15 -2
- package/esm/components/DataSourceSetter/DataSettingPanel.d.ts +10 -0
- package/esm/components/DataSourceSetter/DataSettingPanel.js +55 -0
- package/esm/components/DataSourceSetter/DataSettingPanel.js.map +1 -0
- package/esm/components/DataSourceSetter/Header.d.ts +7 -0
- package/esm/components/DataSourceSetter/Header.js +9 -0
- package/esm/components/DataSourceSetter/Header.js.map +1 -0
- package/esm/components/DataSourceSetter/Title.d.ts +7 -0
- package/esm/components/DataSourceSetter/Title.js +49 -0
- package/esm/components/DataSourceSetter/Title.js.map +1 -0
- package/esm/components/DataSourceSetter/TreePanel.d.ts +12 -0
- package/esm/components/DataSourceSetter/TreePanel.js +98 -0
- package/esm/components/DataSourceSetter/TreePanel.js.map +1 -0
- package/esm/components/DataSourceSetter/index.d.ts +18 -0
- package/esm/components/DataSourceSetter/index.js +28 -0
- package/esm/components/DataSourceSetter/index.js.map +1 -0
- package/esm/components/DataSourceSetter/shared.d.ts +9 -0
- package/esm/components/DataSourceSetter/shared.js +48 -0
- package/esm/components/DataSourceSetter/shared.js.map +1 -0
- package/esm/components/DataSourceSetter/styles.less +81 -0
- package/esm/components/DataSourceSetter/types.d.ts +18 -0
- package/esm/components/DataSourceSetter/types.js +2 -0
- package/esm/components/DataSourceSetter/types.js.map +1 -0
- package/esm/components/ReactionsSetter/FieldPropertySetter.d.ts +10 -0
- package/esm/components/ReactionsSetter/FieldPropertySetter.js +70 -0
- package/esm/components/ReactionsSetter/FieldPropertySetter.js.map +1 -0
- package/esm/components/ReactionsSetter/PathSelector.d.ts +10 -0
- package/esm/components/ReactionsSetter/PathSelector.js +109 -0
- package/esm/components/ReactionsSetter/PathSelector.js.map +1 -0
- package/esm/components/ReactionsSetter/declarations.d.ts +5 -0
- package/esm/components/ReactionsSetter/declarations.js +45 -0
- package/esm/components/ReactionsSetter/declarations.js.map +1 -0
- package/esm/components/ReactionsSetter/formilyTypes.generated.d.ts +1 -0
- package/esm/components/ReactionsSetter/formilyTypes.generated.js +4 -0
- package/esm/components/ReactionsSetter/formilyTypes.generated.js.map +1 -0
- package/esm/components/ReactionsSetter/helpers.d.ts +10 -0
- package/esm/components/ReactionsSetter/helpers.js +385 -0
- package/esm/components/ReactionsSetter/helpers.js.map +1 -0
- package/esm/components/ReactionsSetter/index.d.ts +8 -0
- package/esm/components/ReactionsSetter/index.js +256 -0
- package/esm/components/ReactionsSetter/index.js.map +1 -0
- package/esm/components/ReactionsSetter/properties.d.ts +11 -0
- package/esm/components/ReactionsSetter/properties.js +42 -0
- package/esm/components/ReactionsSetter/properties.js.map +1 -0
- package/esm/components/ReactionsSetter/styles.less +103 -0
- package/esm/components/ReactionsSetter/types.d.ts +13 -0
- package/esm/components/ReactionsSetter/types.js +2 -0
- package/esm/components/ReactionsSetter/types.js.map +1 -0
- package/esm/components/ValidatorSetter/index.d.ts +6 -0
- package/esm/components/ValidatorSetter/index.js +136 -0
- package/esm/components/ValidatorSetter/index.js.map +1 -0
- package/esm/components/index.d.ts +3 -0
- package/esm/components/index.js +4 -0
- package/esm/components/index.js.map +1 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +3 -0
- package/esm/index.js.map +1 -0
- package/esm/locales/en-US.d.ts +93 -0
- package/esm/locales/en-US.js +99 -0
- package/esm/locales/en-US.js.map +1 -0
- package/esm/locales/index.d.ts +1 -0
- package/esm/locales/index.js +6 -0
- package/esm/locales/index.js.map +1 -0
- package/esm/locales/ko-KR.d.ts +93 -0
- package/esm/locales/ko-KR.js +99 -0
- package/esm/locales/ko-KR.js.map +1 -0
- package/esm/locales/zh-CN.d.ts +93 -0
- package/esm/locales/zh-CN.js +99 -0
- package/esm/locales/zh-CN.js.map +1 -0
- package/lib/components/DataSourceSetter/DataSettingPanel.d.ts +10 -0
- package/lib/components/DataSourceSetter/DataSettingPanel.js +58 -0
- package/lib/components/DataSourceSetter/DataSettingPanel.js.map +1 -0
- package/lib/components/DataSourceSetter/Header.d.ts +7 -0
- package/lib/components/DataSourceSetter/Header.js +12 -0
- package/lib/components/DataSourceSetter/Header.js.map +1 -0
- package/lib/components/DataSourceSetter/Title.d.ts +7 -0
- package/lib/components/DataSourceSetter/Title.js +52 -0
- package/lib/components/DataSourceSetter/Title.js.map +1 -0
- package/lib/components/DataSourceSetter/TreePanel.d.ts +12 -0
- package/lib/components/DataSourceSetter/TreePanel.js +101 -0
- package/lib/components/DataSourceSetter/TreePanel.js.map +1 -0
- package/lib/components/DataSourceSetter/index.d.ts +18 -0
- package/lib/components/DataSourceSetter/index.js +34 -0
- package/lib/components/DataSourceSetter/index.js.map +1 -0
- package/lib/components/DataSourceSetter/shared.d.ts +9 -0
- package/lib/components/DataSourceSetter/shared.js +54 -0
- package/lib/components/DataSourceSetter/shared.js.map +1 -0
- package/lib/components/DataSourceSetter/styles.less +81 -0
- package/lib/components/DataSourceSetter/types.d.ts +18 -0
- package/lib/components/DataSourceSetter/types.js +3 -0
- package/lib/components/DataSourceSetter/types.js.map +1 -0
- package/lib/components/ReactionsSetter/FieldPropertySetter.d.ts +10 -0
- package/lib/components/ReactionsSetter/FieldPropertySetter.js +74 -0
- package/lib/components/ReactionsSetter/FieldPropertySetter.js.map +1 -0
- package/lib/components/ReactionsSetter/PathSelector.d.ts +10 -0
- package/lib/components/ReactionsSetter/PathSelector.js +113 -0
- package/lib/components/ReactionsSetter/PathSelector.js.map +1 -0
- package/lib/components/ReactionsSetter/declarations.d.ts +5 -0
- package/lib/components/ReactionsSetter/declarations.js +82 -0
- package/lib/components/ReactionsSetter/declarations.js.map +1 -0
- package/lib/components/ReactionsSetter/formilyTypes.generated.d.ts +1 -0
- package/lib/components/ReactionsSetter/formilyTypes.generated.js +7 -0
- package/lib/components/ReactionsSetter/formilyTypes.generated.js.map +1 -0
- package/lib/components/ReactionsSetter/helpers.d.ts +10 -0
- package/lib/components/ReactionsSetter/helpers.js +388 -0
- package/lib/components/ReactionsSetter/helpers.js.map +1 -0
- package/lib/components/ReactionsSetter/index.d.ts +8 -0
- package/lib/components/ReactionsSetter/index.js +260 -0
- package/lib/components/ReactionsSetter/index.js.map +1 -0
- package/lib/components/ReactionsSetter/properties.d.ts +11 -0
- package/lib/components/ReactionsSetter/properties.js +45 -0
- package/lib/components/ReactionsSetter/properties.js.map +1 -0
- package/lib/components/ReactionsSetter/styles.less +103 -0
- package/lib/components/ReactionsSetter/types.d.ts +13 -0
- package/lib/components/ReactionsSetter/types.js +3 -0
- package/lib/components/ReactionsSetter/types.js.map +1 -0
- package/lib/components/ValidatorSetter/index.d.ts +6 -0
- package/lib/components/ValidatorSetter/index.js +139 -0
- package/lib/components/ValidatorSetter/index.js.map +1 -0
- package/lib/components/index.d.ts +3 -0
- package/lib/components/index.js +20 -0
- package/lib/components/index.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +1 -0
- package/lib/locales/en-US.d.ts +93 -0
- package/lib/locales/en-US.js +101 -0
- package/lib/locales/en-US.js.map +1 -0
- package/lib/locales/index.d.ts +1 -0
- package/lib/locales/index.js +11 -0
- package/lib/locales/index.js.map +1 -0
- package/lib/locales/ko-KR.d.ts +93 -0
- package/lib/locales/ko-KR.js +101 -0
- package/lib/locales/ko-KR.js.map +1 -0
- package/lib/locales/zh-CN.d.ts +93 -0
- package/lib/locales/zh-CN.js +101 -0
- package/lib/locales/zh-CN.js.map +1 -0
- package/package.json +66 -4
- package/src/components/DataSourceSetter/DataSettingPanel.tsx +130 -0
- package/src/components/DataSourceSetter/Header.tsx +19 -0
- package/src/components/DataSourceSetter/Title.tsx +64 -0
- package/src/components/DataSourceSetter/TreePanel.tsx +147 -0
- package/src/components/DataSourceSetter/index.tsx +95 -0
- package/src/components/DataSourceSetter/shared.ts +56 -0
- package/src/components/DataSourceSetter/styles.less +81 -0
- package/src/components/DataSourceSetter/types.ts +17 -0
- package/src/components/ReactionsSetter/FieldPropertySetter.tsx +125 -0
- package/src/components/ReactionsSetter/PathSelector.tsx +123 -0
- package/src/components/ReactionsSetter/__tests__/declarations.test.ts +65 -0
- package/src/components/ReactionsSetter/declarations.ts +51 -0
- package/src/components/ReactionsSetter/formilyTypes.generated.ts +3 -0
- package/src/components/ReactionsSetter/helpers.ts +393 -0
- package/src/components/ReactionsSetter/index.tsx +452 -0
- package/src/components/ReactionsSetter/properties.ts +51 -0
- package/src/components/ReactionsSetter/styles.less +103 -0
- package/src/components/ReactionsSetter/types.ts +13 -0
- package/src/components/ValidatorSetter/index.tsx +172 -0
- package/src/components/index.ts +3 -0
- package/src/index.ts +2 -0
- package/src/locales/en-US.ts +102 -0
- package/src/locales/index.ts +6 -0
- package/src/locales/ko-KR.ts +100 -0
- package/src/locales/zh-CN.ts +100 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Alibaba
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Alibaba
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/PROVENANCE.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ownedName": "@nokecy/designer-formily-setters",
|
|
3
|
+
"ownedPath": "packages/designer/formily-setters",
|
|
4
|
+
"version": "2.0.0-beta.6",
|
|
5
|
+
"previousPath": "vendor/nokecy-designable/formily/setters",
|
|
6
|
+
"upstream": {
|
|
7
|
+
"repository": "https://github.com/pindjs/designable.git",
|
|
8
|
+
"commit": "5edb2236bdfd8309da7677414180923966246d85",
|
|
9
|
+
"package": "@nokecy/designable-formily-setters",
|
|
10
|
+
"path": "formily/setters",
|
|
11
|
+
"record": "docs/maintenance/origins/designable-fork-import.json",
|
|
12
|
+
"sourceChecksumField": "packages[name=@nokecy/designable-formily-setters].sourceSha256"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"licenseFile": "LICENSE",
|
|
16
|
+
"migrationDate": "2026-10-17",
|
|
17
|
+
"moduleRenameSourceFiles": [
|
|
18
|
+
"components/DataSourceSetter/DataSettingPanel.tsx",
|
|
19
|
+
"components/DataSourceSetter/Header.tsx",
|
|
20
|
+
"components/DataSourceSetter/Title.tsx",
|
|
21
|
+
"components/DataSourceSetter/TreePanel.tsx",
|
|
22
|
+
"components/DataSourceSetter/index.tsx",
|
|
23
|
+
"components/DataSourceSetter/shared.ts",
|
|
24
|
+
"components/ReactionsSetter/FieldPropertySetter.tsx",
|
|
25
|
+
"components/ReactionsSetter/PathSelector.tsx",
|
|
26
|
+
"components/ReactionsSetter/declarations.ts",
|
|
27
|
+
"components/ReactionsSetter/index.tsx",
|
|
28
|
+
"components/ValidatorSetter/index.tsx",
|
|
29
|
+
"locales/index.ts"
|
|
30
|
+
],
|
|
31
|
+
"changes": [
|
|
32
|
+
"Moved preserved package source, tests and documentation into the maintained packages tree.",
|
|
33
|
+
"Renamed internal imports, exports, require paths and declarations to owned workspace package names.",
|
|
34
|
+
"Pinned dependencies on other owned workspaces to their exact unchanged local versions.",
|
|
35
|
+
"Preserved previous Ant Design 6 adaptations and historical upstream provenance.",
|
|
36
|
+
"React and ReactDOM peer ranges target major 19; React runtime compatibility is tracked separately from the namespace/layout migration.",
|
|
37
|
+
"Removed obsolete standalone Rollup/Dumi/npmignore configuration; historical bytes and exclusion reasons are recorded in source-closure.json. Root scripts are the only supported build contract."
|
|
38
|
+
],
|
|
39
|
+
"previousBuildScripts": {},
|
|
40
|
+
"react19AdaptedSourceFiles": [],
|
|
41
|
+
"sourceClosure": "docs/maintenance/source-closure.json",
|
|
42
|
+
"upgradeGuide": "docs/maintenance/upstream-upgrades.md",
|
|
43
|
+
"patchCategories": "docs/maintenance/patch-classification.json",
|
|
44
|
+
"maintenancePolicy": "Source may evolve with tests and an adaptation entry; baseline hashes are provenance evidence, not equality assertions on maintained implementations."
|
|
45
|
+
}
|
package/README.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nokecy/designer-formily-setters
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
### Install
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install --save @nokecy/designer-formily-setters
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## QC_UI owned workspace
|
|
10
|
+
|
|
11
|
+
- Active package: `@nokecy/designer-formily-setters@2.0.0-beta.6` at `packages/designer/formily-setters`.
|
|
12
|
+
- Historical package: `@nokecy/designable-formily-setters`. The original repository, commit, license and source-checksum references are recorded in [PROVENANCE.json](./PROVENANCE.json).
|
|
13
|
+
- Use the QC_UI root workspace installation and build. `npm run build --workspace @nokecy/designer-formily-setters` delegates to the root builder; `npm run typecheck --workspace @nokecy/designer-formily-setters` checks this package and its local dependency closure.
|
|
14
|
+
- All source, tests and package documentation were retained. Generated `esm/`, `lib/`, `dist/` and `node_modules/` content is not maintained source.
|
|
15
|
+
- React-facing workspaces target React 19. Runtime dependencies on the owned Formily/designer family use exact local versions.
|
|
16
|
+
- Any retained upstream documentation-site or Rollup configuration is historical context and is not part of the root workspace build. Documentation examples for non-active Vue/Next adapters describe upstream packages, not QC_UI workspaces.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Form as FormCore } from '@nokecy/formily-core';
|
|
3
|
+
import { ITreeDataSource } from './types';
|
|
4
|
+
import './styles.less';
|
|
5
|
+
export interface IDataSettingPanelProps {
|
|
6
|
+
treeDataSource: ITreeDataSource;
|
|
7
|
+
allowExtendOption?: boolean;
|
|
8
|
+
effects?: (form: FormCore<any>) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const DataSettingPanel: React.FC<IDataSettingPanelProps>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, Fragment } from 'react';
|
|
3
|
+
import { Button } from 'antd';
|
|
4
|
+
import { PlusOutlined } from '@ant-design/icons';
|
|
5
|
+
import { ArrayItems, Form, Input, FormItem } from '@nokecy/formily-antd';
|
|
6
|
+
import { createForm } from '@nokecy/formily-core';
|
|
7
|
+
import { observer } from '@nokecy/formily-reactive-react';
|
|
8
|
+
import { createSchemaField } from '@nokecy/formily-react';
|
|
9
|
+
import { ValueInput } from '@nokecy/designer-react-settings-form';
|
|
10
|
+
import { usePrefix, TextWidget } from '@nokecy/designer-react';
|
|
11
|
+
import { Header } from './Header';
|
|
12
|
+
import { traverseTree } from './shared';
|
|
13
|
+
import './styles.less';
|
|
14
|
+
const SchemaField = createSchemaField({
|
|
15
|
+
components: {
|
|
16
|
+
FormItem,
|
|
17
|
+
Input,
|
|
18
|
+
ArrayItems,
|
|
19
|
+
ValueInput,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
export const DataSettingPanel = observer((props) => {
|
|
23
|
+
const { allowExtendOption, effects } = props;
|
|
24
|
+
const prefix = usePrefix('data-source-setter');
|
|
25
|
+
const form = useMemo(() => {
|
|
26
|
+
let values;
|
|
27
|
+
traverseTree(props.treeDataSource.dataSource, (dataItem) => {
|
|
28
|
+
if (dataItem.key === props.treeDataSource.selectedKey) {
|
|
29
|
+
values = dataItem;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return createForm({
|
|
33
|
+
values,
|
|
34
|
+
effects: effects,
|
|
35
|
+
});
|
|
36
|
+
}, [
|
|
37
|
+
props.treeDataSource.selectedKey,
|
|
38
|
+
props.treeDataSource.dataSource.length,
|
|
39
|
+
]);
|
|
40
|
+
if (!props.treeDataSource.selectedKey)
|
|
41
|
+
return (_jsxs(Fragment, { children: [_jsx(Header, { title: _jsx(TextWidget, { token: "SettingComponents.DataSourceSetter.nodeProperty" }), extra: null }), _jsx("div", { className: `${prefix + '-layout-item-content'}`, children: _jsx(TextWidget, { token: "SettingComponents.DataSourceSetter.pleaseSelectNode" }) })] }));
|
|
42
|
+
return (_jsxs(Fragment, { children: [_jsx(Header, { title: _jsx(TextWidget, { token: "SettingComponents.DataSourceSetter.nodeProperty" }), extra: allowExtendOption ? (_jsx(Button, { type: "text", onClick: () => {
|
|
43
|
+
form.setFieldState('map', (state) => {
|
|
44
|
+
state.value.push({});
|
|
45
|
+
});
|
|
46
|
+
}, icon: _jsx(PlusOutlined, {}), children: _jsx(TextWidget, { token: "SettingComponents.DataSourceSetter.addKeyValuePair" }) })) : null }), _jsx("div", { className: `${prefix + '-layout-item-content'}`, children: _jsx(Form, { form: form, labelWidth: 60, wrapperWidth: 160, children: _jsx(SchemaField, { children: _jsx(SchemaField.Array, { name: "map", "x-component": "ArrayItems", children: _jsxs(SchemaField.Object, { "x-decorator": "ArrayItems.Item", "x-decorator-props": { type: 'divide' }, children: [_jsx(SchemaField.String, { title: _jsx(TextWidget, { token: "SettingComponents.DataSourceSetter.label" }), "x-decorator": "FormItem", "x-disabled": !allowExtendOption, name: "label", "x-component": "Input" }), _jsx(SchemaField.String, { title: _jsx(TextWidget, { token: "SettingComponents.DataSourceSetter.value" }), "x-decorator": "FormItem", name: "value", "x-component": "ValueInput" }), _jsx(SchemaField.Void, { "x-component": "ArrayItems.Remove", "x-visible": allowExtendOption, "x-component-props": {
|
|
47
|
+
style: {
|
|
48
|
+
margin: 5,
|
|
49
|
+
display: 'flex',
|
|
50
|
+
justifyContent: 'center',
|
|
51
|
+
alignItems: 'center',
|
|
52
|
+
},
|
|
53
|
+
} })] }) }) }) }) })] }));
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=DataSettingPanel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataSettingPanel.js","sourceRoot":"","sources":["../../../src/components/DataSourceSetter/DataSettingPanel.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EAAE,UAAU,EAAoB,MAAM,sBAAsB,CAAA;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AACjE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEvC,OAAO,eAAe,CAAA;AAEtB,MAAM,WAAW,GAAG,iBAAiB,CAAC;IACpC,UAAU,EAAE;QACV,QAAQ;QACR,KAAK;QACL,UAAU;QACV,UAAU;KACX;CACF,CAAC,CAAA;AAQF,MAAM,CAAC,MAAM,gBAAgB,GAAqC,QAAQ,CACxE,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,KAA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C,CAAC,CAAA;oBACJ,CAAC,EACD,IAAI,EAAE,KAAC,YAAY,KAAG,YAEtB,KAAC,UAAU,IAAC,KAAK,EAAC,oDAAoD,GAAG,GAClE,CACV,CAAC,CAAC,CAAC,IAAI,GAEV,EACF,cAAK,SAAS,EAAE,GAAG,MAAM,GAAG,sBAAsB,EAAE,YAClD,KAAC,IAAI,IAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,YACjD,KAAC,WAAW,cACV,KAAC,WAAW,CAAC,KAAK,IAAC,IAAI,EAAC,KAAK,iBAAa,YAAY,YACpD,MAAC,WAAW,CAAC,MAAM,mBACL,iBAAiB,uBACV,EAAE,IAAI,EAAE,QAAQ,EAAE,aAErC,KAAC,WAAW,CAAC,MAAM,IACjB,KAAK,EACH,KAAC,UAAU,IAAC,KAAK,EAAC,0CAA0C,GAAG,iBAErD,UAAU,gBACV,CAAC,iBAAiB,EAC9B,IAAI,EAAC,OAAO,iBACA,OAAO,GACnB,EACF,KAAC,WAAW,CAAC,MAAM,IACjB,KAAK,EACH,KAAC,UAAU,IAAC,KAAK,EAAC,0CAA0C,GAAG,iBAErD,UAAU,EACtB,IAAI,EAAC,OAAO,iBACA,YAAY,GACxB,EACF,KAAC,WAAW,CAAC,IAAI,mBACH,mBAAmB,eACpB,iBAAiB,uBACT;4CACjB,KAAK,EAAE;gDACL,MAAM,EAAE,CAAC;gDACT,OAAO,EAAE,MAAM;gDACf,cAAc,EAAE,QAAQ;gDACxB,UAAU,EAAE,QAAQ;6CACrB;yCACF,GACD,IACiB,GACH,GACR,GACT,GACH,IACG,CACZ,CAAA;AACH,CAAC,CACF,CAAA","sourcesContent":["import React, { useMemo, Fragment } from 'react'\nimport { Button } from 'antd'\nimport { PlusOutlined } from '@ant-design/icons'\nimport { ArrayItems, Form, Input, FormItem } from '@nokecy/formily-antd'\nimport { createForm, Form as FormCore } from '@nokecy/formily-core'\nimport { observer } from '@nokecy/formily-reactive-react'\nimport { createSchemaField } from '@nokecy/formily-react'\nimport { ValueInput } from '@nokecy/designer-react-settings-form'\nimport { usePrefix, TextWidget } from '@nokecy/designer-react'\nimport { Header } from './Header'\nimport { traverseTree } from './shared'\nimport { INodeItem, ITreeDataSource } from './types'\nimport './styles.less'\n\nconst SchemaField = createSchemaField({\n components: {\n FormItem,\n Input,\n ArrayItems,\n ValueInput,\n },\n})\n\nexport interface IDataSettingPanelProps {\n treeDataSource: ITreeDataSource\n allowExtendOption?: boolean\n effects?: (form: FormCore<any>) => void\n}\n\nexport const DataSettingPanel: React.FC<IDataSettingPanelProps> = observer(\n (props) => {\n const { allowExtendOption, effects } = props\n const prefix = usePrefix('data-source-setter')\n const form = useMemo(() => {\n let values: INodeItem | undefined\n traverseTree(props.treeDataSource.dataSource, (dataItem) => {\n if (dataItem.key === props.treeDataSource.selectedKey) {\n values = dataItem\n }\n })\n return createForm({\n values,\n effects: effects,\n })\n }, [\n props.treeDataSource.selectedKey,\n props.treeDataSource.dataSource.length,\n ])\n if (!props.treeDataSource.selectedKey)\n return (\n <Fragment>\n <Header\n title={\n <TextWidget token=\"SettingComponents.DataSourceSetter.nodeProperty\" />\n }\n extra={null}\n />\n <div className={`${prefix + '-layout-item-content'}`}>\n <TextWidget token=\"SettingComponents.DataSourceSetter.pleaseSelectNode\" />\n </div>\n </Fragment>\n )\n return (\n <Fragment>\n <Header\n title={\n <TextWidget token=\"SettingComponents.DataSourceSetter.nodeProperty\" />\n }\n extra={\n allowExtendOption ? (\n <Button\n type=\"text\"\n onClick={() => {\n form.setFieldState('map', (state) => {\n state.value.push({})\n })\n }}\n icon={<PlusOutlined />}\n >\n <TextWidget token=\"SettingComponents.DataSourceSetter.addKeyValuePair\" />\n </Button>\n ) : null\n }\n />\n <div className={`${prefix + '-layout-item-content'}`}>\n <Form form={form} labelWidth={60} wrapperWidth={160}>\n <SchemaField>\n <SchemaField.Array name=\"map\" x-component=\"ArrayItems\">\n <SchemaField.Object\n x-decorator=\"ArrayItems.Item\"\n x-decorator-props={{ type: 'divide' }}\n >\n <SchemaField.String\n title={\n <TextWidget token=\"SettingComponents.DataSourceSetter.label\" />\n }\n x-decorator=\"FormItem\"\n x-disabled={!allowExtendOption}\n name=\"label\"\n x-component=\"Input\"\n />\n <SchemaField.String\n title={\n <TextWidget token=\"SettingComponents.DataSourceSetter.value\" />\n }\n x-decorator=\"FormItem\"\n name=\"value\"\n x-component=\"ValueInput\"\n />\n <SchemaField.Void\n x-component=\"ArrayItems.Remove\"\n x-visible={allowExtendOption}\n x-component-props={{\n style: {\n margin: 5,\n display: 'flex',\n justifyContent: 'center',\n alignItems: 'center',\n },\n }}\n />\n </SchemaField.Object>\n </SchemaField.Array>\n </SchemaField>\n </Form>\n </div>\n </Fragment>\n )\n }\n)\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { observer } from '@nokecy/formily-reactive-react';
|
|
3
|
+
import { usePrefix } from '@nokecy/designer-react';
|
|
4
|
+
import './styles.less';
|
|
5
|
+
export const Header = observer(({ extra, title }) => {
|
|
6
|
+
const prefix = usePrefix('data-source-setter');
|
|
7
|
+
return (_jsxs("div", { className: `${prefix + '-layout-item-header'}`, children: [_jsx("div", { className: `${prefix + '-layout-item-title'}`, children: title }), extra] }));
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=Header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Header.js","sourceRoot":"","sources":["../../../src/components/DataSourceSetter/Header.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,eAAe,CAAA;AAOtB,MAAM,CAAC,MAAM,MAAM,GAA2B,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE;IAC1E,MAAM,MAAM,GAAG,SAAS,CAAC,oBAAoB,CAAC,CAAA;IAC9C,OAAO,CACL,eAAK,SAAS,EAAE,GAAG,MAAM,GAAG,qBAAqB,EAAE,aACjD,cAAK,SAAS,EAAE,GAAG,MAAM,GAAG,oBAAoB,EAAE,YAAG,KAAK,GAAO,EAChE,KAAK,IACF,CACP,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import React, { ReactNode } from 'react'\nimport { observer } from '@nokecy/formily-reactive-react'\nimport { usePrefix } from '@nokecy/designer-react'\nimport './styles.less'\n\nexport interface IHeaderProps {\n extra: ReactNode | null\n title: ReactNode | string\n}\n\nexport const Header: React.FC<IHeaderProps> = observer(({ extra, title }) => {\n const prefix = usePrefix('data-source-setter')\n return (\n <div className={`${prefix + '-layout-item-header'}`}>\n <div className={`${prefix + '-layout-item-title'}`}>{title}</div>\n {extra}\n </div>\n )\n})\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { clone, toArr } from '@nokecy/formily-shared';
|
|
3
|
+
import { observer } from '@nokecy/formily-reactive-react';
|
|
4
|
+
import { IconWidget, TextWidget, usePrefix } from '@nokecy/designer-react';
|
|
5
|
+
import { traverseTree } from './shared';
|
|
6
|
+
import './styles.less';
|
|
7
|
+
export const Title = observer((props) => {
|
|
8
|
+
const prefix = usePrefix('data-source-setter-node-title');
|
|
9
|
+
const getTitleValue = (dataSource) => {
|
|
10
|
+
const optionalKeys = ['label', 'title', 'header'];
|
|
11
|
+
let nodeTitle;
|
|
12
|
+
optionalKeys.some((key) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const title = (_a = toArr(dataSource).find((item) => item.label === key)) === null || _a === void 0 ? void 0 : _a.value;
|
|
15
|
+
if (title !== undefined) {
|
|
16
|
+
nodeTitle = title;
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
});
|
|
21
|
+
if (nodeTitle === undefined) {
|
|
22
|
+
toArr(dataSource || []).some((item) => {
|
|
23
|
+
if (item.value && typeof item.value === 'string') {
|
|
24
|
+
nodeTitle = item.value;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return nodeTitle;
|
|
31
|
+
};
|
|
32
|
+
const renderTitle = (dataSource) => {
|
|
33
|
+
const nodeTitle = getTitleValue(dataSource);
|
|
34
|
+
if (nodeTitle === undefined)
|
|
35
|
+
return (_jsx(TextWidget, { token: "SettingComponents.DataSourceSetter.defaultTitle" }));
|
|
36
|
+
else
|
|
37
|
+
return nodeTitle + '';
|
|
38
|
+
};
|
|
39
|
+
return (_jsxs("div", { className: prefix, children: [_jsx("span", { style: { marginRight: '5px' }, children: renderTitle((props === null || props === void 0 ? void 0 : props.map) || []) }), _jsx(IconWidget, { className: prefix + '-icon', infer: "Remove", onClick: () => {
|
|
40
|
+
var _a;
|
|
41
|
+
const newDataSource = clone((_a = props === null || props === void 0 ? void 0 : props.treeDataSource) === null || _a === void 0 ? void 0 : _a.dataSource);
|
|
42
|
+
traverseTree(newDataSource || [], (dataItem, i, data) => {
|
|
43
|
+
if (data[i].key === props.duplicateKey)
|
|
44
|
+
toArr(data).splice(i, 1);
|
|
45
|
+
});
|
|
46
|
+
props.treeDataSource.dataSource = newDataSource;
|
|
47
|
+
} })] }));
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=Title.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Title.js","sourceRoot":"","sources":["../../../src/components/DataSourceSetter/Title.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AA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AS,KAAK,SAAS;YACzB,OAAO,CACL,KAAC,UAAU,IAAC,KAAK,EAAC,iDAAiD,GAAG,CACvE,CAAA;;YACE,OAAO,SAAS,GAAG,EAAE,CAAA;IAC5B,CAAC,CAAA;IAED,OAAO,CACL,eAAK,SAAS,EAAE,MAAM,aACpB,eAAM,KAAK,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,YAChC,WAAW,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,GAAG,KAAI,EAAE,CAAC,GACzB,EACP,KAAC,UAAU,IACT,SAAS,EAAE,MAAM,GAAG,OAAO,EAC3B,KAAK,EAAC,QAAQ,EACd,OAAO,EAAE,GAAG,EAAE;;oBACZ,MAAM,aAAa,GAAG,KAAK,CAAC,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc,0CAAE,UAAU,CAAC,CAAA;oBAC9D,YAAY,CAAC,aAAa,IAAI,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;wBACtD,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,KAAK,CAAC,YAAY;4BAAE,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;oBAClE,CAAC,CAAC,CAAA;oBACF,KAAK,CAAC,cAAc,CAAC,UAAU,GAAG,aAAa,CAAA;gBACjD,CAAC,GACD,IACE,CACP,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import React from 'react'\nimport { clone, toArr } from '@nokecy/formily-shared'\nimport { observer } from '@nokecy/formily-reactive-react'\nimport { IconWidget, TextWidget, usePrefix } from '@nokecy/designer-react'\nimport { INodeItem, ITreeDataSource } from './types'\nimport { traverseTree } from './shared'\nimport './styles.less'\nexport interface ITitleProps extends INodeItem {\n treeDataSource: ITreeDataSource\n}\n\nexport const Title: React.FC<ITitleProps> = observer((props) => {\n const prefix = usePrefix('data-source-setter-node-title')\n const getTitleValue = (dataSource: { label: string; value: any }[]) => {\n const optionalKeys = ['label', 'title', 'header']\n let nodeTitle: string | undefined\n optionalKeys.some((key) => {\n const title = toArr(dataSource).find((item) => item.label === key)?.value\n if (title !== undefined) {\n nodeTitle = title\n return true\n }\n return false\n })\n if (nodeTitle === undefined) {\n toArr(dataSource || []).some((item) => {\n if (item.value && typeof item.value === 'string') {\n nodeTitle = item.value\n return true\n }\n return false\n })\n }\n return nodeTitle\n }\n\n const renderTitle = (dataSource: { label: string; value: any }[]) => {\n const nodeTitle = getTitleValue(dataSource)\n if (nodeTitle === undefined)\n return (\n <TextWidget token=\"SettingComponents.DataSourceSetter.defaultTitle\" />\n )\n else return nodeTitle + ''\n }\n\n return (\n <div className={prefix}>\n <span style={{ marginRight: '5px' }}>\n {renderTitle(props?.map || [])}\n </span>\n <IconWidget\n className={prefix + '-icon'}\n infer=\"Remove\"\n onClick={() => {\n const newDataSource = clone(props?.treeDataSource?.dataSource)\n traverseTree(newDataSource || [], (dataItem, i, data) => {\n if (data[i].key === props.duplicateKey) toArr(data).splice(i, 1)\n })\n props.treeDataSource.dataSource = newDataSource\n }}\n />\n </div>\n )\n})\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ITreeDataSource } from './types';
|
|
3
|
+
import './styles.less';
|
|
4
|
+
export interface ITreePanelProps {
|
|
5
|
+
treeDataSource: ITreeDataSource;
|
|
6
|
+
allowTree: boolean;
|
|
7
|
+
defaultOptionValue: {
|
|
8
|
+
label: string;
|
|
9
|
+
value: any;
|
|
10
|
+
}[];
|
|
11
|
+
}
|
|
12
|
+
export declare const TreePanel: React.FC<ITreePanelProps>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment } from 'react';
|
|
3
|
+
import { Tree, Button } from 'antd';
|
|
4
|
+
import { uid } from '@nokecy/formily-shared';
|
|
5
|
+
import { observer } from '@nokecy/formily-reactive-react';
|
|
6
|
+
import { usePrefix, TextWidget, IconWidget } from '@nokecy/designer-react';
|
|
7
|
+
import { Title } from './Title';
|
|
8
|
+
import { Header } from './Header';
|
|
9
|
+
import { traverseTree } from './shared';
|
|
10
|
+
import './styles.less';
|
|
11
|
+
import { GlobalRegistry } from '@nokecy/designer-core';
|
|
12
|
+
const limitTreeDrag = ({ dropPosition }) => {
|
|
13
|
+
if (dropPosition === 0) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
};
|
|
18
|
+
export const TreePanel = observer((props) => {
|
|
19
|
+
const prefix = usePrefix('data-source-setter');
|
|
20
|
+
const dropHandler = (info) => {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
const dropKey = (_a = info.node) === null || _a === void 0 ? void 0 : _a.key;
|
|
23
|
+
const dragKey = (_b = info.dragNode) === null || _b === void 0 ? void 0 : _b.key;
|
|
24
|
+
const dropPos = info.node.pos.split('-');
|
|
25
|
+
const dropPosition = info.dropPosition - Number(dropPos[dropPos.length - 1]);
|
|
26
|
+
const data = [...props.treeDataSource.dataSource];
|
|
27
|
+
// Find dragObject
|
|
28
|
+
let dragObj = {
|
|
29
|
+
key: '',
|
|
30
|
+
};
|
|
31
|
+
traverseTree(data, (item, index, arr) => {
|
|
32
|
+
if (arr[index].key === dragKey) {
|
|
33
|
+
arr.splice(index, 1);
|
|
34
|
+
dragObj = item;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (!info.dropToGap) {
|
|
38
|
+
traverseTree(data, (item) => {
|
|
39
|
+
if (item.key === dropKey) {
|
|
40
|
+
item.children = item.children || [];
|
|
41
|
+
item.children.unshift(dragObj);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else if ((info.node.children || []).length > 0 &&
|
|
46
|
+
info.node.expanded &&
|
|
47
|
+
dropPosition === 1) {
|
|
48
|
+
traverseTree(data, (item) => {
|
|
49
|
+
if (item.key === dropKey) {
|
|
50
|
+
item.children = item.children || [];
|
|
51
|
+
item.children.unshift(dragObj);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
let ar = [];
|
|
57
|
+
let i = 0;
|
|
58
|
+
traverseTree(data, (item, index, arr) => {
|
|
59
|
+
if (item.key === dropKey) {
|
|
60
|
+
ar = arr;
|
|
61
|
+
i = index;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
if (dropPosition === -1) {
|
|
65
|
+
ar.splice(i, 0, dragObj);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
ar.splice(i + 1, 0, dragObj);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
props.treeDataSource.dataSource = data;
|
|
72
|
+
};
|
|
73
|
+
return (_jsxs(Fragment, { children: [_jsx(Header, { title: _jsx(TextWidget, { token: "SettingComponents.DataSourceSetter.dataSourceTree" }), extra: _jsx(Button, { type: "text", onClick: () => {
|
|
74
|
+
var _a;
|
|
75
|
+
const uuid = uid();
|
|
76
|
+
const dataSource = props.treeDataSource.dataSource;
|
|
77
|
+
const initialKeyValuePairs = ((_a = props.defaultOptionValue) === null || _a === void 0 ? void 0 : _a.map((item) => ({ ...item }))) || [
|
|
78
|
+
{
|
|
79
|
+
label: 'label',
|
|
80
|
+
value: `${GlobalRegistry.getDesignerMessage(`SettingComponents.DataSourceSetter.item`)} ${dataSource.length + 1}`,
|
|
81
|
+
},
|
|
82
|
+
{ label: 'value', value: uuid },
|
|
83
|
+
];
|
|
84
|
+
props.treeDataSource.dataSource = dataSource.concat({
|
|
85
|
+
key: uuid,
|
|
86
|
+
duplicateKey: uuid,
|
|
87
|
+
map: initialKeyValuePairs,
|
|
88
|
+
children: [],
|
|
89
|
+
});
|
|
90
|
+
}, icon: _jsx(IconWidget, { infer: "Add" }), children: _jsx(TextWidget, { token: "SettingComponents.DataSourceSetter.addNode" }) }) }), _jsx("div", { className: `${prefix + '-layout-item-content'}`, children: _jsx(Tree, { blockNode: true, draggable: true, allowDrop: props.allowTree ? () => true : limitTreeDrag, defaultExpandAll: true, defaultExpandParent: true, autoExpandParent: true, showLine: { showLeafIcon: false }, treeData: props.treeDataSource.dataSource, onDragEnter: () => { }, onDrop: dropHandler, titleRender: (titleProps) => {
|
|
91
|
+
return (_jsx(Title, { ...titleProps, treeDataSource: props.treeDataSource }));
|
|
92
|
+
}, onSelect: (selectedKeys) => {
|
|
93
|
+
if (selectedKeys[0]) {
|
|
94
|
+
props.treeDataSource.selectedKey = selectedKeys[0].toString();
|
|
95
|
+
}
|
|
96
|
+
} }) })] }));
|
|
97
|
+
});
|
|
98
|
+
//# sourceMappingURL=TreePanel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreePanel.js","sourceRoot":"","sources":["../../../src/components/DataSourceSetter/TreePanel.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAa,MAAM,MAAM,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEvC,OAAO,eAAe,CAAA;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,MAAM,aAAa,GAAG,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE;IACzC,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAA;IACd,CAAC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AE,EAAE,YAAY,EAAE,KAAK,EAAE,EACjC,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC,UAAU,EACzC,WAAW,EAAE,GAAG,EAAE,GAAE,CAAC,EACrB,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,CAAC,UAAqB,EAAE,EAAE;wBACrC,OAAO,CACL,KAAC,KAAK,OACA,UAAU,EACd,cAAc,EAAE,KAAK,CAAC,cAAc,GAC7B,CACV,CAAA;oBACH,CAAC,EACD,QAAQ,EAAE,CAAC,YAAY,EAAE,EAAE;wBACzB,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;4BACpB,KAAK,CAAC,cAAc,CAAC,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;wBAC/D,CAAC;oBACH,CAAC,GACK,GACJ,IACG,CACZ,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import React, { Fragment } from 'react'\nimport { Tree, Button, TreeProps } from 'antd'\nimport { uid } from '@nokecy/formily-shared'\nimport { observer } from '@nokecy/formily-reactive-react'\nimport { usePrefix, TextWidget, IconWidget } from '@nokecy/designer-react'\nimport { Title } from './Title'\nimport { Header } from './Header'\nimport { traverseTree } from './shared'\nimport { ITreeDataSource, INodeItem } from './types'\nimport './styles.less'\nimport { GlobalRegistry } from '@nokecy/designer-core'\n\nconst limitTreeDrag = ({ dropPosition }) => {\n if (dropPosition === 0) {\n return false\n }\n return true\n}\n\nexport interface ITreePanelProps {\n treeDataSource: ITreeDataSource\n allowTree: boolean\n defaultOptionValue: {\n label: string\n value: any\n }[]\n}\n\nexport const TreePanel: React.FC<ITreePanelProps> = observer((props) => {\n const prefix = usePrefix('data-source-setter')\n const dropHandler = (info: Parameters<Required<TreeProps>['onDrop']>[0]) => {\n const dropKey = info.node?.key\n const dragKey = info.dragNode?.key\n const dropPos = info.node.pos.split('-')\n const dropPosition = info.dropPosition - Number(dropPos[dropPos.length - 1])\n const data = [...props.treeDataSource.dataSource]\n // Find dragObject\n let dragObj: INodeItem = {\n key: '',\n }\n traverseTree(data, (item, index, arr) => {\n if (arr[index].key === dragKey) {\n arr.splice(index, 1)\n dragObj = item\n }\n })\n if (!info.dropToGap) {\n traverseTree(data, (item) => {\n if (item.key === dropKey) {\n item.children = item.children || []\n item.children.unshift(dragObj)\n }\n })\n } else if (\n (info.node.children || []).length > 0 &&\n info.node.expanded &&\n dropPosition === 1\n ) {\n traverseTree(data, (item) => {\n if (item.key === dropKey) {\n item.children = item.children || []\n item.children.unshift(dragObj)\n }\n })\n } else {\n let ar: INodeItem[] = []\n let i = 0\n traverseTree(data, (item, index, arr) => {\n if (item.key === dropKey) {\n ar = arr\n i = index\n }\n })\n if (dropPosition === -1) {\n ar.splice(i, 0, dragObj)\n } else {\n ar.splice(i + 1, 0, dragObj)\n }\n }\n props.treeDataSource.dataSource = data\n }\n return (\n <Fragment>\n <Header\n title={\n <TextWidget token=\"SettingComponents.DataSourceSetter.dataSourceTree\" />\n }\n extra={\n <Button\n type=\"text\"\n onClick={() => {\n const uuid = uid()\n const dataSource = props.treeDataSource.dataSource\n const initialKeyValuePairs = props.defaultOptionValue?.map(\n (item) => ({ ...item })\n ) || [\n {\n label: 'label',\n value: `${GlobalRegistry.getDesignerMessage(\n `SettingComponents.DataSourceSetter.item`\n )} ${dataSource.length + 1}`,\n },\n { label: 'value', value: uuid },\n ]\n props.treeDataSource.dataSource = dataSource.concat({\n key: uuid,\n duplicateKey: uuid,\n map: initialKeyValuePairs,\n children: [],\n })\n }}\n icon={<IconWidget infer=\"Add\" />}\n >\n <TextWidget token=\"SettingComponents.DataSourceSetter.addNode\" />\n </Button>\n }\n />\n <div className={`${prefix + '-layout-item-content'}`}>\n <Tree\n blockNode\n draggable={true}\n allowDrop={props.allowTree ? () => true : limitTreeDrag}\n defaultExpandAll\n defaultExpandParent\n autoExpandParent\n showLine={{ showLeafIcon: false }}\n treeData={props.treeDataSource.dataSource}\n onDragEnter={() => {}}\n onDrop={dropHandler}\n titleRender={(titleProps: INodeItem) => {\n return (\n <Title\n {...titleProps}\n treeDataSource={props.treeDataSource}\n ></Title>\n )\n }}\n onSelect={(selectedKeys) => {\n if (selectedKeys[0]) {\n props.treeDataSource.selectedKey = selectedKeys[0].toString()\n }\n }}\n ></Tree>\n </div>\n </Fragment>\n )\n})\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Form } from '@nokecy/formily-core';
|
|
3
|
+
import { IDataSourceItem } from './types';
|
|
4
|
+
import './styles.less';
|
|
5
|
+
export interface IDataSourceSetterProps {
|
|
6
|
+
className?: string;
|
|
7
|
+
style?: React.CSSProperties;
|
|
8
|
+
onChange: (dataSource: IDataSourceItem[]) => void;
|
|
9
|
+
value: IDataSourceItem[];
|
|
10
|
+
allowTree?: boolean;
|
|
11
|
+
allowExtendOption?: boolean;
|
|
12
|
+
defaultOptionValue?: {
|
|
13
|
+
label: string;
|
|
14
|
+
value: any;
|
|
15
|
+
}[];
|
|
16
|
+
effects?: (form: Form<any>) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare const DataSourceSetter: React.FC<IDataSourceSetterProps>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, useMemo, useState } from 'react';
|
|
3
|
+
import cls from 'classnames';
|
|
4
|
+
import { Modal, Button } from 'antd';
|
|
5
|
+
import { observable } from '@nokecy/formily-reactive';
|
|
6
|
+
import { observer } from '@nokecy/formily-reactive-react';
|
|
7
|
+
import { usePrefix, useTheme, TextWidget } from '@nokecy/designer-react';
|
|
8
|
+
import { DataSettingPanel } from './DataSettingPanel';
|
|
9
|
+
import { TreePanel } from './TreePanel';
|
|
10
|
+
import { transformDataToValue, transformValueToData } from './shared';
|
|
11
|
+
import './styles.less';
|
|
12
|
+
export const DataSourceSetter = observer((props) => {
|
|
13
|
+
const { className, value = [], onChange, allowTree = true, allowExtendOption = true, defaultOptionValue, effects = () => { }, } = props;
|
|
14
|
+
const theme = useTheme();
|
|
15
|
+
const prefix = usePrefix('data-source-setter');
|
|
16
|
+
const [modalOpen, setModalOpen] = useState(false);
|
|
17
|
+
const treeDataSource = useMemo(() => observable({
|
|
18
|
+
dataSource: transformValueToData(value),
|
|
19
|
+
selectedKey: '',
|
|
20
|
+
}), [value, modalOpen]);
|
|
21
|
+
const openModal = () => setModalOpen(true);
|
|
22
|
+
const closeModal = () => setModalOpen(false);
|
|
23
|
+
return (_jsxs(Fragment, { children: [_jsx(Button, { block: true, onClick: openModal, children: _jsx(TextWidget, { token: "SettingComponents.DataSourceSetter.configureDataSource" }) }), _jsx(Modal, { title: _jsx(TextWidget, { token: "SettingComponents.DataSourceSetter.configureDataSource" }), width: "65%", styles: { body: { padding: 10 } }, transitionName: "", maskTransitionName: "", open: modalOpen, onCancel: closeModal, onOk: () => {
|
|
24
|
+
onChange(transformDataToValue(treeDataSource.dataSource));
|
|
25
|
+
closeModal();
|
|
26
|
+
}, children: _jsxs("div", { className: `${cls(prefix, className)} ${prefix + '-' + theme} ${prefix + '-layout'}`, children: [_jsx("div", { className: `${prefix + '-layout-item left'}`, children: _jsx(TreePanel, { defaultOptionValue: defaultOptionValue, allowTree: allowTree, treeDataSource: treeDataSource }) }), _jsx("div", { className: `${prefix + '-layout-item right'}`, children: _jsx(DataSettingPanel, { allowExtendOption: allowExtendOption, treeDataSource: treeDataSource, effects: effects }) })] }) })] }));
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/DataSourceSetter/index.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC1D,OAAO,GAAG,MAAM,YAAY,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,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AAC,OAAO,EAAE,SAAS,YAC9B,KAAC,UAAU,IAAC,KAAK,EAAC,wDAAwD,GAAG,GACtE,EACT,KAAC,KAAK,IACJ,KAAK,EACH,KAAC,UAAU,IAAC,KAAK,EAAC,wDAAwD,GAAG,EAE/E,KAAK,EAAC,KAAK,EACX,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EACjC,cAAc,EAAC,EAAE,EACjB,kBAAkB,EAAC,EAAE,EACrB,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,UAAU,EACpB,IAAI,EAAE,GAAG,EAAE;oBACT,QAAQ,CAAC,oBAAoB,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAA;oBACzD,UAAU,EAAE,CAAA;gBACd,CAAC,YAED,eACE,SAAS,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,MAAM,GAAG,GAAG,GAAG,KAAK,IAC1D,MAAM,GAAG,SACX,EAAE,aAEF,cAAK,SAAS,EAAE,GAAG,MAAM,GAAG,mBAAmB,EAAE,YAC/C,KAAC,SAAS,IACR,kBAAkB,EAAE,kBAAyB,EAC7C,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,cAAc,GACnB,GACT,EACN,cAAK,SAAS,EAAE,GAAG,MAAM,GAAG,oBAAoB,EAAE,YAChD,KAAC,gBAAgB,IACf,iBAAiB,EAAE,iBAAiB,EACpC,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,OAAO,GACE,GAChB,IACF,GACA,IACC,CACZ,CAAA;AACH,CAAC,CACF,CAAA","sourcesContent":["import React, { Fragment, useMemo, useState } from 'react'\nimport cls from 'classnames'\nimport { Modal, Button } from 'antd'\nimport { Form } from '@nokecy/formily-core'\nimport { observable } from '@nokecy/formily-reactive'\nimport { observer } from '@nokecy/formily-reactive-react'\nimport { usePrefix, useTheme, TextWidget } from '@nokecy/designer-react'\nimport { DataSettingPanel } from './DataSettingPanel'\nimport { TreePanel } from './TreePanel'\nimport { transformDataToValue, transformValueToData } from './shared'\nimport { IDataSourceItem, ITreeDataSource } from './types'\nimport './styles.less'\nexport interface IDataSourceSetterProps {\n className?: string\n style?: React.CSSProperties\n onChange: (dataSource: IDataSourceItem[]) => void\n value: IDataSourceItem[]\n allowTree?: boolean\n allowExtendOption?: boolean\n defaultOptionValue?: {\n label: string\n value: any\n }[]\n effects?: (form: Form<any>) => void\n}\n\nexport const DataSourceSetter: React.FC<IDataSourceSetterProps> = observer(\n (props) => {\n const {\n className,\n value = [],\n onChange,\n allowTree = true,\n allowExtendOption = true,\n defaultOptionValue,\n effects = () => {},\n } = props\n const theme = useTheme()\n const prefix = usePrefix('data-source-setter')\n const [modalOpen, setModalOpen] = useState(false)\n const treeDataSource: ITreeDataSource = useMemo(\n () =>\n observable({\n dataSource: transformValueToData(value),\n selectedKey: '',\n }),\n [value, modalOpen]\n )\n const openModal = () => setModalOpen(true)\n const closeModal = () => setModalOpen(false)\n return (\n <Fragment>\n <Button block onClick={openModal}>\n <TextWidget token=\"SettingComponents.DataSourceSetter.configureDataSource\" />\n </Button>\n <Modal\n title={\n <TextWidget token=\"SettingComponents.DataSourceSetter.configureDataSource\" />\n }\n width=\"65%\"\n styles={{ body: { padding: 10 } }}\n transitionName=\"\"\n maskTransitionName=\"\"\n open={modalOpen}\n onCancel={closeModal}\n onOk={() => {\n onChange(transformDataToValue(treeDataSource.dataSource))\n closeModal()\n }}\n >\n <div\n className={`${cls(prefix, className)} ${prefix + '-' + theme} ${\n prefix + '-layout'\n }`}\n >\n <div className={`${prefix + '-layout-item left'}`}>\n <TreePanel\n defaultOptionValue={defaultOptionValue as any}\n allowTree={allowTree}\n treeDataSource={treeDataSource}\n ></TreePanel>\n </div>\n <div className={`${prefix + '-layout-item right'}`}>\n <DataSettingPanel\n allowExtendOption={allowExtendOption}\n treeDataSource={treeDataSource}\n effects={effects}\n ></DataSettingPanel>\n </div>\n </div>\n </Modal>\n </Fragment>\n )\n }\n)\n"]}
|
|
@@ -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,48 @@
|
|
|
1
|
+
import { uid, clone, toArr } from '@nokecy/formily-shared';
|
|
2
|
+
export const traverseTree = (data, callback) => {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
for (let i = 0; i < data.length; i++) {
|
|
5
|
+
callback(data[i], i, data);
|
|
6
|
+
if ((_a = data[i]) === null || _a === void 0 ? void 0 : _a.children) {
|
|
7
|
+
traverseTree(((_b = data[i]) === null || _b === void 0 ? void 0 : _b.children) || [], callback);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export const transformValueToData = (value) => {
|
|
12
|
+
const data = clone(value);
|
|
13
|
+
traverseTree(data, (item, i, dataSource) => {
|
|
14
|
+
const dataItem = {
|
|
15
|
+
key: '',
|
|
16
|
+
duplicateKey: '',
|
|
17
|
+
map: [],
|
|
18
|
+
children: [],
|
|
19
|
+
};
|
|
20
|
+
for (const [key, value] of Object.entries(dataSource[i] || {})) {
|
|
21
|
+
if (key !== 'children')
|
|
22
|
+
dataItem.map.push({ label: key, value: value });
|
|
23
|
+
}
|
|
24
|
+
const uuid = uid();
|
|
25
|
+
dataItem.key = uuid;
|
|
26
|
+
dataItem.duplicateKey = uuid;
|
|
27
|
+
dataItem.children = dataSource[i].children || [];
|
|
28
|
+
dataSource[i] = dataItem;
|
|
29
|
+
});
|
|
30
|
+
return data;
|
|
31
|
+
};
|
|
32
|
+
export const transformDataToValue = (data) => {
|
|
33
|
+
const value = clone(data);
|
|
34
|
+
traverseTree(value, (item, i, dataSource) => {
|
|
35
|
+
var _a;
|
|
36
|
+
const valueItem = {
|
|
37
|
+
children: [],
|
|
38
|
+
};
|
|
39
|
+
toArr(dataSource[i].map).forEach((item) => {
|
|
40
|
+
if (item.label)
|
|
41
|
+
valueItem[item.label] = item.value;
|
|
42
|
+
});
|
|
43
|
+
valueItem.children = ((_a = dataSource[i]) === null || _a === void 0 ? void 0 : _a.children) || [];
|
|
44
|
+
dataSource[i] = valueItem;
|
|
45
|
+
});
|
|
46
|
+
return value;
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/components/DataSourceSetter/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAS1D,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,IAAS,EACT,QAAoD,EACpD,EAAE;;IACF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAA;QAC1B,IAAI,MAAA,IAAI,CAAC,CAAC,CAAC,0CAAE,QAAQ,EAAE,CAAC;YACtB,YAAY,CAAC,CAAA,MAAA,IAAI,CAAC,CAAC,CAAC,0CAAE,QAAQ,KAAI,EAAE,EAAE,QAAQ,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAwB,EAAe,EAAE;IAC5E,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;IACzB,YAAY,CAAC,IAAI,EAAE,CAAC,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G,IAAI,CAAC,KAAK,CAAA;QACpD,CAAC,CAAC,CAAA;QACF,SAAS,CAAC,QAAQ,GAAG,CAAA,MAAA,UAAU,CAAC,CAAC,CAAC,0CAAE,QAAQ,KAAI,EAAE,CAAA;QAClD,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;IAC3B,CAAC,CAAC,CAAA;IACF,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { uid, clone, toArr } from '@nokecy/formily-shared'\nimport { IDataSourceItem, INodeItem } from './types'\n\nexport interface INode {\n key?: string\n map?: any\n children?: INode[]\n}\n\nexport const traverseTree = <T extends INode>(\n data: T[],\n callback: (dataItem: T, i: number, data: T[]) => any\n) => {\n for (let i = 0; i < data.length; i++) {\n callback(data[i], i, data)\n if (data[i]?.children) {\n traverseTree(data[i]?.children || [], callback)\n }\n }\n}\n\nexport const transformValueToData = (value: IDataSourceItem[]): INodeItem[] => {\n const data = clone(value)\n traverseTree(data, (item, i, dataSource) => {\n const dataItem = {\n key: '',\n duplicateKey: '',\n map: [] as { label: string; value: any }[],\n children: [] as INode[],\n }\n for (const [key, value] of Object.entries(dataSource[i] || {})) {\n if (key !== 'children') dataItem.map.push({ label: key, value: value })\n }\n const uuid = uid()\n dataItem.key = uuid\n dataItem.duplicateKey = uuid\n dataItem.children = dataSource[i].children || []\n dataSource[i] = dataItem\n })\n return data\n}\n\nexport const transformDataToValue = (data: INodeItem[]): IDataSourceItem[] => {\n const value = clone(data)\n traverseTree(value, (item, i, dataSource) => {\n const valueItem: IDataSourceItem = {\n children: [],\n }\n toArr(dataSource[i].map).forEach((item) => {\n if (item.label) valueItem[item.label] = item.value\n })\n valueItem.children = dataSource[i]?.children || []\n dataSource[i] = valueItem\n })\n return value\n}\n"]}
|