@nokecy/designer-formily-transformer 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 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.
@@ -0,0 +1,34 @@
1
+ {
2
+ "ownedName": "@nokecy/designer-formily-transformer",
3
+ "ownedPath": "packages/designer/formily-transformer",
4
+ "version": "2.0.0-beta.6",
5
+ "previousPath": "vendor/nokecy-designable/formily/transformer",
6
+ "upstream": {
7
+ "repository": "https://github.com/pindjs/designable.git",
8
+ "commit": "5edb2236bdfd8309da7677414180923966246d85",
9
+ "package": "@nokecy/designable-formily-transformer",
10
+ "path": "formily/transformer",
11
+ "record": "docs/maintenance/origins/designable-fork-import.json",
12
+ "sourceChecksumField": "packages[name=@nokecy/designable-formily-transformer].sourceSha256"
13
+ },
14
+ "license": "MIT",
15
+ "licenseFile": "LICENSE",
16
+ "migrationDate": "2026-10-17",
17
+ "moduleRenameSourceFiles": [
18
+ "index.ts"
19
+ ],
20
+ "changes": [
21
+ "Moved preserved package source, tests and documentation into the maintained packages tree.",
22
+ "Renamed internal imports, exports, require paths and declarations to owned workspace package names.",
23
+ "Pinned dependencies on other owned workspaces to their exact unchanged local versions.",
24
+ "Preserved previous Ant Design 6 adaptations and historical upstream provenance.",
25
+ "React and ReactDOM peer ranges target major 19; React runtime compatibility is tracked separately from the namespace/layout migration.",
26
+ "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."
27
+ ],
28
+ "previousBuildScripts": {},
29
+ "react19AdaptedSourceFiles": [],
30
+ "sourceClosure": "docs/maintenance/source-closure.json",
31
+ "upgradeGuide": "docs/maintenance/upstream-upgrades.md",
32
+ "patchCategories": "docs/maintenance/patch-classification.json",
33
+ "maintenancePolicy": "Source may evolve with tests and an adaptation entry; baseline hashes are provenance evidence, not equality assertions on maintained implementations."
34
+ }
package/README.md CHANGED
@@ -1,3 +1,16 @@
1
- # Temporary Holding Version
1
+ # @nokecy/designer-formily-transformer
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ### Install
4
+
5
+ ```bash
6
+ npm install --save @nokecy/designer-formily-transformer
7
+ ```
8
+
9
+ ## QC_UI owned workspace
10
+
11
+ - Active package: `@nokecy/designer-formily-transformer@2.0.0-beta.6` at `packages/designer/formily-transformer`.
12
+ - Historical package: `@nokecy/designable-formily-transformer`. 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-transformer` delegates to the root builder; `npm run typecheck --workspace @nokecy/designer-formily-transformer` 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.
package/esm/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { ISchema } from '@nokecy/formily-json-schema';
2
+ import { ITreeNode } from '@nokecy/designer-core';
3
+ export interface ITransformerOptions {
4
+ designableFieldName?: string;
5
+ designableFormName?: string;
6
+ }
7
+ export interface IFormilySchema {
8
+ schema?: ISchema;
9
+ form?: Record<string, any>;
10
+ }
11
+ export declare const transformToSchema: (node: ITreeNode, options?: ITransformerOptions) => IFormilySchema;
12
+ export declare const transformToTreeNode: (formily?: IFormilySchema, options?: ITransformerOptions) => ITreeNode;
package/esm/index.js ADDED
@@ -0,0 +1,112 @@
1
+ import { Schema } from '@nokecy/formily-json-schema';
2
+ import { clone, uid } from '@nokecy/designer-shared';
3
+ const createOptions = (options) => {
4
+ return {
5
+ designableFieldName: 'Field',
6
+ designableFormName: 'Form',
7
+ ...options,
8
+ };
9
+ };
10
+ const findNode = (node, finder) => {
11
+ if (!node)
12
+ return;
13
+ if (finder === null || finder === void 0 ? void 0 : finder(node))
14
+ return node;
15
+ if (!node.children)
16
+ return;
17
+ for (let i = 0; i < node.children.length; i++) {
18
+ const found = findNode(node.children[i], finder);
19
+ if (found)
20
+ return found;
21
+ }
22
+ return;
23
+ };
24
+ export const transformToSchema = (node, options) => {
25
+ const realOptions = createOptions(options);
26
+ const root = findNode(node, (child) => {
27
+ return child.componentName === realOptions.designableFormName;
28
+ });
29
+ const schema = {
30
+ type: 'object',
31
+ properties: {},
32
+ };
33
+ if (!root)
34
+ return { schema };
35
+ const createSchema = (node, schema = {}) => {
36
+ var _a, _b, _c;
37
+ if (node !== root) {
38
+ Object.assign(schema, clone(node.props));
39
+ }
40
+ schema['x-designable-id'] = node.id;
41
+ if (schema.type === 'array') {
42
+ if ((_a = node.children) === null || _a === void 0 ? void 0 : _a[0]) {
43
+ if (node.children[0].componentName === realOptions.designableFieldName) {
44
+ schema.items = createSchema(node.children[0]);
45
+ schema['x-index'] = 0;
46
+ }
47
+ }
48
+ (_b = node.children) === null || _b === void 0 ? void 0 : _b.slice(1).forEach((child, index) => {
49
+ if (child.componentName !== realOptions.designableFieldName)
50
+ return;
51
+ const key = child.props.name || child.id;
52
+ schema.properties = schema.properties || {};
53
+ schema.properties[key] = createSchema(child);
54
+ schema.properties[key]['x-index'] = index;
55
+ });
56
+ }
57
+ else {
58
+ (_c = node.children) === null || _c === void 0 ? void 0 : _c.forEach((child, index) => {
59
+ if (child.componentName !== realOptions.designableFieldName)
60
+ return;
61
+ const key = child.props.name || child.id;
62
+ schema.properties = schema.properties || {};
63
+ schema.properties[key] = createSchema(child);
64
+ schema.properties[key]['x-index'] = index;
65
+ });
66
+ }
67
+ return schema;
68
+ };
69
+ return { form: clone(root.props), schema: createSchema(root, schema) };
70
+ };
71
+ export const transformToTreeNode = (formily = {}, options) => {
72
+ const realOptions = createOptions(options);
73
+ const root = {
74
+ componentName: realOptions.designableFormName,
75
+ props: formily.form,
76
+ children: [],
77
+ };
78
+ const schema = new Schema(formily.schema);
79
+ const cleanProps = (props) => {
80
+ if (props['name'] === props['x-designable-id']) {
81
+ delete props.name;
82
+ }
83
+ delete props['version'];
84
+ delete props['_isJSONSchemaObject'];
85
+ return props;
86
+ };
87
+ const appendTreeNode = (parent, schema) => {
88
+ var _a;
89
+ if (!schema)
90
+ return;
91
+ const current = {
92
+ id: schema['x-designable-id'] || uid(),
93
+ componentName: realOptions.designableFieldName,
94
+ props: cleanProps(schema.toJSON(false)),
95
+ children: [],
96
+ };
97
+ (_a = parent.children) === null || _a === void 0 ? void 0 : _a.push(current);
98
+ if (schema.items && !Array.isArray(schema.items)) {
99
+ appendTreeNode(current, schema.items);
100
+ }
101
+ schema.mapProperties((schema) => {
102
+ schema['x-designable-id'] = schema['x-designable-id'] || uid();
103
+ appendTreeNode(current, schema);
104
+ });
105
+ };
106
+ schema.mapProperties((schema) => {
107
+ schema['x-designable-id'] = schema['x-designable-id'] || uid();
108
+ appendTreeNode(root, schema);
109
+ });
110
+ return root;
111
+ };
112
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAE,MAAM,6BAA6B,CAAA;AAE7D,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAYpD,MAAM,aAAa,GAAG,CAAC,OAA6B,EAAuB,EAAE;IAC3E,OAAO;QACL,mBAAmB,EAAE,OAAO;QAC5B,kB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AAO,GAAc;YACzB,EAAE,EAAE,MAAM,CAAC,iBAAiB,CAAC,IAAI,GAAG,EAAE;YACtC,aAAa,EAAE,WAAW,CAAC,mBAA6B;YACxD,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvC,QAAQ,EAAE,EAAE;SACb,CAAA;QACD,MAAA,MAAM,CAAC,QAAQ,0CAAE,IAAI,CAAC,OAAO,CAAC,CAAA;QAC9B,IAAI,MAAM,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACjD,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;QACvC,CAAC;QACD,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM,EAAE,EAAE;YAC9B,MAAM,CAAC,iBAAiB,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC,IAAI,GAAG,EAAE,CAAA;YAC9D,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QACjC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IACD,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM,EAAE,EAAE;QAC9B,MAAM,CAAC,iBAAiB,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC,IAAI,GAAG,EAAE,CAAA;QAC9D,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAC9B,CAAC,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC,CAAA","sourcesContent":["import { ISchema, Schema } from '@nokecy/formily-json-schema'\nimport { ITreeNode } from '@nokecy/designer-core'\nimport { clone, uid } from '@nokecy/designer-shared'\n\nexport interface ITransformerOptions {\n designableFieldName?: string\n designableFormName?: string\n}\n\nexport interface IFormilySchema {\n schema?: ISchema\n form?: Record<string, any>\n}\n\nconst createOptions = (options?: ITransformerOptions): ITransformerOptions => {\n return {\n designableFieldName: 'Field',\n designableFormName: 'Form',\n ...options,\n }\n}\n\nconst findNode = (\n node: ITreeNode,\n finder?: (node: ITreeNode) => boolean\n): ITreeNode | undefined => {\n if (!node) return\n if (finder?.(node)) return node\n if (!node.children) return\n for (let i = 0; i < node.children.length; i++) {\n const found = findNode(node.children[i], finder)\n if (found) return found\n }\n return\n}\n\nexport const transformToSchema = (\n node: ITreeNode,\n options?: ITransformerOptions\n): IFormilySchema => {\n const realOptions = createOptions(options)\n const root = findNode(node, (child) => {\n return child.componentName === realOptions.designableFormName\n })\n const schema = {\n type: 'object',\n properties: {},\n }\n if (!root) return { schema }\n const createSchema = (node: ITreeNode, schema: ISchema = {}) => {\n if (node !== root) {\n Object.assign(schema, clone(node.props))\n }\n schema['x-designable-id'] = node.id\n if (schema.type === 'array') {\n if (node.children?.[0]) {\n if (\n node.children[0].componentName === realOptions.designableFieldName\n ) {\n schema.items = createSchema(node.children[0])\n schema['x-index'] = 0\n }\n }\n node.children?.slice(1).forEach((child, index) => {\n if (child.componentName !== realOptions.designableFieldName) return\n const key = child.props.name || child.id\n schema.properties = schema.properties || {}\n schema.properties[key] = createSchema(child)\n schema.properties[key]['x-index'] = index\n })\n } else {\n node.children?.forEach((child, index) => {\n if (child.componentName !== realOptions.designableFieldName) return\n const key = child.props.name || child.id\n schema.properties = schema.properties || {}\n schema.properties[key] = createSchema(child)\n schema.properties[key]['x-index'] = index\n })\n }\n return schema\n }\n return { form: clone(root.props), schema: createSchema(root, schema) }\n}\n\nexport const transformToTreeNode = (\n formily: IFormilySchema = {},\n options?: ITransformerOptions\n) => {\n const realOptions = createOptions(options)\n const root: ITreeNode = {\n componentName: realOptions.designableFormName as string,\n props: formily.form as ITreeNode['props'],\n children: [],\n }\n const schema = new Schema(formily.schema as ISchema)\n const cleanProps = (props: Record<string, unknown>) => {\n if (props['name'] === props['x-designable-id']) {\n delete props.name\n }\n delete props['version']\n delete props['_isJSONSchemaObject']\n return props\n }\n const appendTreeNode = (parent: ITreeNode, schema: Schema) => {\n if (!schema) return\n const current: ITreeNode = {\n id: schema['x-designable-id'] || uid(),\n componentName: realOptions.designableFieldName as string,\n props: cleanProps(schema.toJSON(false)),\n children: [],\n }\n parent.children?.push(current)\n if (schema.items && !Array.isArray(schema.items)) {\n appendTreeNode(current, schema.items)\n }\n schema.mapProperties((schema) => {\n schema['x-designable-id'] = schema['x-designable-id'] || uid()\n appendTreeNode(current, schema)\n })\n }\n schema.mapProperties((schema) => {\n schema['x-designable-id'] = schema['x-designable-id'] || uid()\n appendTreeNode(root, schema)\n })\n return root\n}\n"]}
package/lib/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { ISchema } from '@nokecy/formily-json-schema';
2
+ import { ITreeNode } from '@nokecy/designer-core';
3
+ export interface ITransformerOptions {
4
+ designableFieldName?: string;
5
+ designableFormName?: string;
6
+ }
7
+ export interface IFormilySchema {
8
+ schema?: ISchema;
9
+ form?: Record<string, any>;
10
+ }
11
+ export declare const transformToSchema: (node: ITreeNode, options?: ITransformerOptions) => IFormilySchema;
12
+ export declare const transformToTreeNode: (formily?: IFormilySchema, options?: ITransformerOptions) => ITreeNode;
package/lib/index.js ADDED
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformToTreeNode = exports.transformToSchema = void 0;
4
+ const formily_json_schema_1 = require("@nokecy/formily-json-schema");
5
+ const designer_shared_1 = require("@nokecy/designer-shared");
6
+ const createOptions = (options) => {
7
+ return {
8
+ designableFieldName: 'Field',
9
+ designableFormName: 'Form',
10
+ ...options,
11
+ };
12
+ };
13
+ const findNode = (node, finder) => {
14
+ if (!node)
15
+ return;
16
+ if (finder === null || finder === void 0 ? void 0 : finder(node))
17
+ return node;
18
+ if (!node.children)
19
+ return;
20
+ for (let i = 0; i < node.children.length; i++) {
21
+ const found = findNode(node.children[i], finder);
22
+ if (found)
23
+ return found;
24
+ }
25
+ return;
26
+ };
27
+ const transformToSchema = (node, options) => {
28
+ const realOptions = createOptions(options);
29
+ const root = findNode(node, (child) => {
30
+ return child.componentName === realOptions.designableFormName;
31
+ });
32
+ const schema = {
33
+ type: 'object',
34
+ properties: {},
35
+ };
36
+ if (!root)
37
+ return { schema };
38
+ const createSchema = (node, schema = {}) => {
39
+ var _a, _b, _c;
40
+ if (node !== root) {
41
+ Object.assign(schema, (0, designer_shared_1.clone)(node.props));
42
+ }
43
+ schema['x-designable-id'] = node.id;
44
+ if (schema.type === 'array') {
45
+ if ((_a = node.children) === null || _a === void 0 ? void 0 : _a[0]) {
46
+ if (node.children[0].componentName === realOptions.designableFieldName) {
47
+ schema.items = createSchema(node.children[0]);
48
+ schema['x-index'] = 0;
49
+ }
50
+ }
51
+ (_b = node.children) === null || _b === void 0 ? void 0 : _b.slice(1).forEach((child, index) => {
52
+ if (child.componentName !== realOptions.designableFieldName)
53
+ return;
54
+ const key = child.props.name || child.id;
55
+ schema.properties = schema.properties || {};
56
+ schema.properties[key] = createSchema(child);
57
+ schema.properties[key]['x-index'] = index;
58
+ });
59
+ }
60
+ else {
61
+ (_c = node.children) === null || _c === void 0 ? void 0 : _c.forEach((child, index) => {
62
+ if (child.componentName !== realOptions.designableFieldName)
63
+ return;
64
+ const key = child.props.name || child.id;
65
+ schema.properties = schema.properties || {};
66
+ schema.properties[key] = createSchema(child);
67
+ schema.properties[key]['x-index'] = index;
68
+ });
69
+ }
70
+ return schema;
71
+ };
72
+ return { form: (0, designer_shared_1.clone)(root.props), schema: createSchema(root, schema) };
73
+ };
74
+ exports.transformToSchema = transformToSchema;
75
+ const transformToTreeNode = (formily = {}, options) => {
76
+ const realOptions = createOptions(options);
77
+ const root = {
78
+ componentName: realOptions.designableFormName,
79
+ props: formily.form,
80
+ children: [],
81
+ };
82
+ const schema = new formily_json_schema_1.Schema(formily.schema);
83
+ const cleanProps = (props) => {
84
+ if (props['name'] === props['x-designable-id']) {
85
+ delete props.name;
86
+ }
87
+ delete props['version'];
88
+ delete props['_isJSONSchemaObject'];
89
+ return props;
90
+ };
91
+ const appendTreeNode = (parent, schema) => {
92
+ var _a;
93
+ if (!schema)
94
+ return;
95
+ const current = {
96
+ id: schema['x-designable-id'] || (0, designer_shared_1.uid)(),
97
+ componentName: realOptions.designableFieldName,
98
+ props: cleanProps(schema.toJSON(false)),
99
+ children: [],
100
+ };
101
+ (_a = parent.children) === null || _a === void 0 ? void 0 : _a.push(current);
102
+ if (schema.items && !Array.isArray(schema.items)) {
103
+ appendTreeNode(current, schema.items);
104
+ }
105
+ schema.mapProperties((schema) => {
106
+ schema['x-designable-id'] = schema['x-designable-id'] || (0, designer_shared_1.uid)();
107
+ appendTreeNode(current, schema);
108
+ });
109
+ };
110
+ schema.mapProperties((schema) => {
111
+ schema['x-designable-id'] = schema['x-designable-id'] || (0, designer_shared_1.uid)();
112
+ appendTreeNode(root, schema);
113
+ });
114
+ return root;
115
+ };
116
+ exports.transformToTreeNode = transformToTreeNode;
117
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qEAA6D;AAE7D,6DAAoD;AAYpD,MAAM,aAAa,GAAG,CAAC,OAA6B,EAAuB,EAAE;IAC3E,OAAO;QACL,mBAAmB,EAAE,OAAO;QAC5B,kBAAkB,EAAE,MAAM;QAC1B,GAAG,OAAO;KACX,CAAA;AACH,CAAC,CAAA;AAED,MAAM,QAAQ,GAAG,CACf,IAAe,EACf,MAAqC,EACd,EAAE;IACzB,IAAI,CAAC,IAAI;QAAE,OAAM;IACjB,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,IAAI,CAAC;QAAE,OAAO,IAAI,CAAA;IAC/B,IAAI,CAAC,IAAI,CAAC,QAAQ;QAAE,OAAM;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9C,MAAM,KAAK,GAAG,QAAQ,CA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,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;QACvC,CAAC;QACD,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM,EAAE,EAAE;YAC9B,MAAM,CAAC,iBAAiB,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC,IAAI,IAAA,qBAAG,GAAE,CAAA;YAC9D,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QACjC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IACD,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM,EAAE,EAAE;QAC9B,MAAM,CAAC,iBAAiB,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC,IAAI,IAAA,qBAAG,GAAE,CAAA;QAC9D,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAC9B,CAAC,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAzCY,QAAA,mBAAmB,uBAyC/B","sourcesContent":["import { ISchema, Schema } from '@nokecy/formily-json-schema'\nimport { ITreeNode } from '@nokecy/designer-core'\nimport { clone, uid } from '@nokecy/designer-shared'\n\nexport interface ITransformerOptions {\n designableFieldName?: string\n designableFormName?: string\n}\n\nexport interface IFormilySchema {\n schema?: ISchema\n form?: Record<string, any>\n}\n\nconst createOptions = (options?: ITransformerOptions): ITransformerOptions => {\n return {\n designableFieldName: 'Field',\n designableFormName: 'Form',\n ...options,\n }\n}\n\nconst findNode = (\n node: ITreeNode,\n finder?: (node: ITreeNode) => boolean\n): ITreeNode | undefined => {\n if (!node) return\n if (finder?.(node)) return node\n if (!node.children) return\n for (let i = 0; i < node.children.length; i++) {\n const found = findNode(node.children[i], finder)\n if (found) return found\n }\n return\n}\n\nexport const transformToSchema = (\n node: ITreeNode,\n options?: ITransformerOptions\n): IFormilySchema => {\n const realOptions = createOptions(options)\n const root = findNode(node, (child) => {\n return child.componentName === realOptions.designableFormName\n })\n const schema = {\n type: 'object',\n properties: {},\n }\n if (!root) return { schema }\n const createSchema = (node: ITreeNode, schema: ISchema = {}) => {\n if (node !== root) {\n Object.assign(schema, clone(node.props))\n }\n schema['x-designable-id'] = node.id\n if (schema.type === 'array') {\n if (node.children?.[0]) {\n if (\n node.children[0].componentName === realOptions.designableFieldName\n ) {\n schema.items = createSchema(node.children[0])\n schema['x-index'] = 0\n }\n }\n node.children?.slice(1).forEach((child, index) => {\n if (child.componentName !== realOptions.designableFieldName) return\n const key = child.props.name || child.id\n schema.properties = schema.properties || {}\n schema.properties[key] = createSchema(child)\n schema.properties[key]['x-index'] = index\n })\n } else {\n node.children?.forEach((child, index) => {\n if (child.componentName !== realOptions.designableFieldName) return\n const key = child.props.name || child.id\n schema.properties = schema.properties || {}\n schema.properties[key] = createSchema(child)\n schema.properties[key]['x-index'] = index\n })\n }\n return schema\n }\n return { form: clone(root.props), schema: createSchema(root, schema) }\n}\n\nexport const transformToTreeNode = (\n formily: IFormilySchema = {},\n options?: ITransformerOptions\n) => {\n const realOptions = createOptions(options)\n const root: ITreeNode = {\n componentName: realOptions.designableFormName as string,\n props: formily.form as ITreeNode['props'],\n children: [],\n }\n const schema = new Schema(formily.schema as ISchema)\n const cleanProps = (props: Record<string, unknown>) => {\n if (props['name'] === props['x-designable-id']) {\n delete props.name\n }\n delete props['version']\n delete props['_isJSONSchemaObject']\n return props\n }\n const appendTreeNode = (parent: ITreeNode, schema: Schema) => {\n if (!schema) return\n const current: ITreeNode = {\n id: schema['x-designable-id'] || uid(),\n componentName: realOptions.designableFieldName as string,\n props: cleanProps(schema.toJSON(false)),\n children: [],\n }\n parent.children?.push(current)\n if (schema.items && !Array.isArray(schema.items)) {\n appendTreeNode(current, schema.items)\n }\n schema.mapProperties((schema) => {\n schema['x-designable-id'] = schema['x-designable-id'] || uid()\n appendTreeNode(current, schema)\n })\n }\n schema.mapProperties((schema) => {\n schema['x-designable-id'] = schema['x-designable-id'] || uid()\n appendTreeNode(root, schema)\n })\n return root\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@nokecy/designer-formily-transformer",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.0-beta.11",
4
+ "license": "MIT",
5
+ "main": "lib/index.js",
6
+ "engines": {
7
+ "npm": ">=3.0.0"
8
+ },
9
+ "module": "esm/index.js",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/pindjs/designable.git"
13
+ },
14
+ "types": "esm/index.d.ts",
15
+ "bugs": {
16
+ "url": "https://github.com/pindjs/designable/issues"
17
+ },
18
+ "homepage": "https://github.com/pindjs/designable#readme",
19
+ "peerDependencies": {
20
+ "@nokecy/formily-core": "2.3.7",
21
+ "@nokecy/formily-json-schema": "2.3.7"
22
+ },
23
+ "dependencies": {
24
+ "@nokecy/designer-core": "2.0.0-beta.11",
25
+ "@nokecy/designer-shared": "2.0.0-beta.11"
26
+ },
27
+ "gitHead": "5edb2236bdfd8309da7677414180923966246d85",
28
+ "private": false,
29
+ "sideEffects": true,
30
+ "files": [
31
+ "src",
32
+ "esm",
33
+ "lib",
34
+ "LICENSE",
35
+ "LICENSE.md",
36
+ "PROVENANCE.json",
37
+ "PROVENANCE.md",
38
+ "README.md"
39
+ ],
40
+ "qcUiSource": {
41
+ "upstreamName": "@nokecy/designable-formily-transformer",
42
+ "previousPath": "vendor/nokecy-designable/formily/transformer",
43
+ "ownedPath": "packages/designer/formily-transformer"
44
+ },
45
+ "scripts": {
46
+ "build": "cd ../../.. && node scripts/build/packages.mjs --only @nokecy/designer-formily-transformer",
47
+ "typecheck": "cd ../../.. && node scripts/build/packages.mjs --check --only @nokecy/designer-formily-transformer"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ }
52
+ }
package/src/index.ts ADDED
@@ -0,0 +1,126 @@
1
+ import { ISchema, Schema } from '@nokecy/formily-json-schema'
2
+ import { ITreeNode } from '@nokecy/designer-core'
3
+ import { clone, uid } from '@nokecy/designer-shared'
4
+
5
+ export interface ITransformerOptions {
6
+ designableFieldName?: string
7
+ designableFormName?: string
8
+ }
9
+
10
+ export interface IFormilySchema {
11
+ schema?: ISchema
12
+ form?: Record<string, any>
13
+ }
14
+
15
+ const createOptions = (options?: ITransformerOptions): ITransformerOptions => {
16
+ return {
17
+ designableFieldName: 'Field',
18
+ designableFormName: 'Form',
19
+ ...options,
20
+ }
21
+ }
22
+
23
+ const findNode = (
24
+ node: ITreeNode,
25
+ finder?: (node: ITreeNode) => boolean
26
+ ): ITreeNode | undefined => {
27
+ if (!node) return
28
+ if (finder?.(node)) return node
29
+ if (!node.children) return
30
+ for (let i = 0; i < node.children.length; i++) {
31
+ const found = findNode(node.children[i], finder)
32
+ if (found) return found
33
+ }
34
+ return
35
+ }
36
+
37
+ export const transformToSchema = (
38
+ node: ITreeNode,
39
+ options?: ITransformerOptions
40
+ ): IFormilySchema => {
41
+ const realOptions = createOptions(options)
42
+ const root = findNode(node, (child) => {
43
+ return child.componentName === realOptions.designableFormName
44
+ })
45
+ const schema = {
46
+ type: 'object',
47
+ properties: {},
48
+ }
49
+ if (!root) return { schema }
50
+ const createSchema = (node: ITreeNode, schema: ISchema = {}) => {
51
+ if (node !== root) {
52
+ Object.assign(schema, clone(node.props))
53
+ }
54
+ schema['x-designable-id'] = node.id
55
+ if (schema.type === 'array') {
56
+ if (node.children?.[0]) {
57
+ if (
58
+ node.children[0].componentName === realOptions.designableFieldName
59
+ ) {
60
+ schema.items = createSchema(node.children[0])
61
+ schema['x-index'] = 0
62
+ }
63
+ }
64
+ node.children?.slice(1).forEach((child, index) => {
65
+ if (child.componentName !== realOptions.designableFieldName) return
66
+ const key = child.props.name || child.id
67
+ schema.properties = schema.properties || {}
68
+ schema.properties[key] = createSchema(child)
69
+ schema.properties[key]['x-index'] = index
70
+ })
71
+ } else {
72
+ node.children?.forEach((child, index) => {
73
+ if (child.componentName !== realOptions.designableFieldName) return
74
+ const key = child.props.name || child.id
75
+ schema.properties = schema.properties || {}
76
+ schema.properties[key] = createSchema(child)
77
+ schema.properties[key]['x-index'] = index
78
+ })
79
+ }
80
+ return schema
81
+ }
82
+ return { form: clone(root.props), schema: createSchema(root, schema) }
83
+ }
84
+
85
+ export const transformToTreeNode = (
86
+ formily: IFormilySchema = {},
87
+ options?: ITransformerOptions
88
+ ) => {
89
+ const realOptions = createOptions(options)
90
+ const root: ITreeNode = {
91
+ componentName: realOptions.designableFormName as string,
92
+ props: formily.form as ITreeNode['props'],
93
+ children: [],
94
+ }
95
+ const schema = new Schema(formily.schema as ISchema)
96
+ const cleanProps = (props: Record<string, unknown>) => {
97
+ if (props['name'] === props['x-designable-id']) {
98
+ delete props.name
99
+ }
100
+ delete props['version']
101
+ delete props['_isJSONSchemaObject']
102
+ return props
103
+ }
104
+ const appendTreeNode = (parent: ITreeNode, schema: Schema) => {
105
+ if (!schema) return
106
+ const current: ITreeNode = {
107
+ id: schema['x-designable-id'] || uid(),
108
+ componentName: realOptions.designableFieldName as string,
109
+ props: cleanProps(schema.toJSON(false)),
110
+ children: [],
111
+ }
112
+ parent.children?.push(current)
113
+ if (schema.items && !Array.isArray(schema.items)) {
114
+ appendTreeNode(current, schema.items)
115
+ }
116
+ schema.mapProperties((schema) => {
117
+ schema['x-designable-id'] = schema['x-designable-id'] || uid()
118
+ appendTreeNode(current, schema)
119
+ })
120
+ }
121
+ schema.mapProperties((schema) => {
122
+ schema['x-designable-id'] = schema['x-designable-id'] || uid()
123
+ appendTreeNode(root, schema)
124
+ })
125
+ return root
126
+ }