@blueking/bkui-form 1.0.1-beta.2 → 1.0.1-beta.3
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/esm/adapter/common/FieldGroupWrap.tsx.js +199 -0
- package/esm/adapter/field/ArrayField.tsx.js +55 -0
- package/esm/adapter/field/BooleanField.tsx.js +41 -0
- package/esm/adapter/field/CompositionField.tsx.js +113 -0
- package/esm/adapter/field/FieldProps.ts.js +85 -0
- package/esm/adapter/field/NumberField.tsx.js +19 -0
- package/esm/adapter/field/ObjectField.tsx.js +58 -0
- package/esm/adapter/field/SchemaField.tsx.js +28 -0
- package/esm/adapter/field/StringField.tsx.js +4 -0
- package/esm/adapter/widget/ArrayWidget.ts.js +196 -0
- package/esm/adapter/widget/ButtonWidget.ts.js +76 -0
- package/esm/adapter/widget/CheckboxWidget.ts.js +101 -0
- package/esm/adapter/widget/CollapseGroupWidget.ts.js +140 -0
- package/esm/adapter/widget/ColorPickerWidget.ts.js +71 -0
- package/esm/adapter/widget/InputWidget.ts.js +79 -0
- package/esm/adapter/widget/KeyValueArrayWidget.tsx.js +156 -0
- package/esm/adapter/widget/RadioWidget.ts.js +98 -0
- package/esm/adapter/widget/SelectWidget.ts.js +98 -0
- package/esm/adapter/widget/SwitchWidget.ts.js +73 -0
- package/esm/adapter/widget/TabGroupWidget.ts.js +145 -0
- package/esm/adapter/widget/TableWidget.ts.js +205 -0
- package/esm/adapter/widget/Widget.ts.js +497 -0
- package/esm/assets/fonts/iconcool.eot +0 -0
- package/esm/assets/fonts/iconcool.ttf +0 -0
- package/esm/assets/fonts/iconcool.woff +0 -0
- package/esm/assets/style.css +43 -0
- package/esm/controller/form.css +164 -0
- package/esm/controller/form.tsx.js +159 -0
- package/esm/controller/props.ts.js +75 -0
- package/esm/core/events.ts.js +74 -0
- package/esm/core/expression.ts.js +67 -0
- package/esm/core/lang.ts.js +25 -0
- package/esm/core/layout.ts.js +149 -0
- package/esm/core/path.ts.js +60 -0
- package/esm/core/proxy.ts.js +10 -0
- package/esm/core/reaction.ts.js +116 -0
- package/esm/core/register.ts.js +74 -0
- package/esm/core/schema.ts.js +302 -0
- package/esm/core/validator.ts.js +248 -0
- package/esm/core/widgetTree.ts.js +163 -0
- package/esm/index.ts.js +6 -0
- package/esm/node_modules/@blueking/cli-service/dist/lib/path.js +35 -0
- package/esm/node_modules/@blueking/cli-service/dist/lib/util.js +233 -0
- package/esm/node_modules/@blueking/cli-service/dist/tools/rust/helper/path.js +172 -0
- package/esm/node_modules/ajv/dist/ajv.js +50 -0
- package/esm/node_modules/ajv/dist/compile/codegen/code.js +156 -0
- package/esm/node_modules/ajv/dist/compile/codegen/index.js +697 -0
- package/esm/node_modules/ajv/dist/compile/codegen/scope.js +143 -0
- package/esm/node_modules/ajv/dist/compile/errors.js +123 -0
- package/esm/node_modules/ajv/dist/compile/index.js +242 -0
- package/esm/node_modules/ajv/dist/compile/names.js +28 -0
- package/esm/node_modules/ajv/dist/compile/ref_error.js +12 -0
- package/esm/node_modules/ajv/dist/compile/resolve.js +155 -0
- package/esm/node_modules/ajv/dist/compile/rules.js +26 -0
- package/esm/node_modules/ajv/dist/compile/util.js +178 -0
- package/esm/node_modules/ajv/dist/compile/validate/applicability.js +19 -0
- package/esm/node_modules/ajv/dist/compile/validate/boolSchema.js +50 -0
- package/esm/node_modules/ajv/dist/compile/validate/dataType.js +203 -0
- package/esm/node_modules/ajv/dist/compile/validate/defaults.js +35 -0
- package/esm/node_modules/ajv/dist/compile/validate/index.js +520 -0
- package/esm/node_modules/ajv/dist/compile/validate/keyword.js +124 -0
- package/esm/node_modules/ajv/dist/compile/validate/subschema.js +81 -0
- package/esm/node_modules/ajv/dist/core.js +618 -0
- package/esm/node_modules/ajv/dist/refs/data.json +13 -0
- package/esm/node_modules/ajv/dist/refs/json-schema-draft-07.json +151 -0
- package/esm/node_modules/ajv/dist/runtime/equal.js +7 -0
- package/esm/node_modules/ajv/dist/runtime/ucs2length.js +24 -0
- package/esm/node_modules/ajv/dist/runtime/uri.js +6 -0
- package/esm/node_modules/ajv/dist/runtime/validation_error.js +11 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +49 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +106 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/allOf.js +23 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +12 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/contains.js +95 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +85 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/if.js +66 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/index.js +44 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/items.js +52 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/items2020.js +30 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/not.js +26 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +60 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +75 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +12 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/properties.js +54 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +38 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +13 -0
- package/esm/node_modules/ajv/dist/vocabularies/code.js +131 -0
- package/esm/node_modules/ajv/dist/vocabularies/core/id.js +10 -0
- package/esm/node_modules/ajv/dist/vocabularies/core/index.js +16 -0
- package/esm/node_modules/ajv/dist/vocabularies/core/ref.js +122 -0
- package/esm/node_modules/ajv/dist/vocabularies/discriminator/index.js +104 -0
- package/esm/node_modules/ajv/dist/vocabularies/discriminator/types.js +9 -0
- package/esm/node_modules/ajv/dist/vocabularies/draft7.js +17 -0
- package/esm/node_modules/ajv/dist/vocabularies/format/format.js +92 -0
- package/esm/node_modules/ajv/dist/vocabularies/format/index.js +6 -0
- package/esm/node_modules/ajv/dist/vocabularies/metadata.js +18 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/const.js +25 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/enum.js +48 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/index.js +33 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitItems.js +24 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitLength.js +27 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +27 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +24 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +26 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/pattern.js +24 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/required.js +79 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +64 -0
- package/esm/node_modules/ajv-formats/dist/formats.js +173 -0
- package/esm/node_modules/ajv-formats/dist/index.js +37 -0
- package/esm/node_modules/ajv-formats/dist/limit.js +69 -0
- package/esm/node_modules/ajv-i18n/localize/zh/index.js +154 -0
- package/esm/node_modules/fast-deep-equal/index.js +46 -0
- package/esm/node_modules/fast-uri/index.js +303 -0
- package/esm/node_modules/fast-uri/lib/schemes.js +188 -0
- package/esm/node_modules/fast-uri/lib/scopedChars.js +30 -0
- package/esm/node_modules/fast-uri/lib/utils.js +244 -0
- package/esm/node_modules/json-schema-traverse/index.js +89 -0
- package/esm/node_modules/semver/classes/comparator.js +143 -0
- package/esm/node_modules/semver/classes/range.js +557 -0
- package/esm/node_modules/semver/classes/semver.js +333 -0
- package/esm/node_modules/semver/functions/clean.js +8 -0
- package/esm/node_modules/semver/functions/cmp.js +54 -0
- package/esm/node_modules/semver/functions/coerce.js +62 -0
- package/esm/node_modules/semver/functions/compare-build.js +9 -0
- package/esm/node_modules/semver/functions/compare-loose.js +5 -0
- package/esm/node_modules/semver/functions/compare.js +7 -0
- package/esm/node_modules/semver/functions/diff.js +60 -0
- package/esm/node_modules/semver/functions/eq.js +5 -0
- package/esm/node_modules/semver/functions/gt.js +5 -0
- package/esm/node_modules/semver/functions/gte.js +5 -0
- package/esm/node_modules/semver/functions/inc.js +21 -0
- package/esm/node_modules/semver/functions/lt.js +5 -0
- package/esm/node_modules/semver/functions/lte.js +5 -0
- package/esm/node_modules/semver/functions/major.js +5 -0
- package/esm/node_modules/semver/functions/minor.js +5 -0
- package/esm/node_modules/semver/functions/neq.js +5 -0
- package/esm/node_modules/semver/functions/parse.js +18 -0
- package/esm/node_modules/semver/functions/patch.js +5 -0
- package/esm/node_modules/semver/functions/prerelease.js +8 -0
- package/esm/node_modules/semver/functions/rcompare.js +5 -0
- package/esm/node_modules/semver/functions/rsort.js +5 -0
- package/esm/node_modules/semver/functions/satisfies.js +12 -0
- package/esm/node_modules/semver/functions/sort.js +5 -0
- package/esm/node_modules/semver/functions/valid.js +8 -0
- package/esm/node_modules/semver/index.js +91 -0
- package/esm/node_modules/semver/internal/constants.js +37 -0
- package/esm/node_modules/semver/internal/debug.js +11 -0
- package/esm/node_modules/semver/internal/identifiers.js +29 -0
- package/esm/node_modules/semver/internal/lrucache.js +42 -0
- package/esm/node_modules/semver/internal/parse-options.js +17 -0
- package/esm/node_modules/semver/internal/re.js +223 -0
- package/esm/node_modules/semver/ranges/gtr.js +6 -0
- package/esm/node_modules/semver/ranges/intersects.js +9 -0
- package/esm/node_modules/semver/ranges/ltr.js +6 -0
- package/esm/node_modules/semver/ranges/max-satisfying.js +27 -0
- package/esm/node_modules/semver/ranges/min-satisfying.js +26 -0
- package/esm/node_modules/semver/ranges/min-version.js +63 -0
- package/esm/node_modules/semver/ranges/outside.js +82 -0
- package/esm/node_modules/semver/ranges/simplify.js +49 -0
- package/esm/node_modules/semver/ranges/subset.js +249 -0
- package/esm/node_modules/semver/ranges/to-comparators.js +10 -0
- package/esm/node_modules/semver/ranges/valid.js +13 -0
- package/esm/util/fetch.ts.js +190 -0
- package/esm/util/index.ts.js +276 -0
- package/package.json +3 -3
- package/dist/main.css +0 -208
- package/dist/main.js +0 -17353
- /package/{dist/svg/iconcool.eb237688.svg → esm/assets/fonts/iconcool.svg} +0 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _object_spread(target) {
|
|
15
|
+
for(var i = 1; i < arguments.length; i++){
|
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
+
var ownKeys = Object.keys(source);
|
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
ownKeys.forEach(function(key) {
|
|
24
|
+
_define_property(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
}
|
|
29
|
+
class Layout {
|
|
30
|
+
static findLayoutByProp(prop, layout) {
|
|
31
|
+
let layoutConfig;
|
|
32
|
+
layout.find((row)=>{
|
|
33
|
+
layoutConfig = row.find((col)=>col.prop === prop);
|
|
34
|
+
return layoutConfig;
|
|
35
|
+
});
|
|
36
|
+
return layoutConfig;
|
|
37
|
+
}
|
|
38
|
+
transformValueToPixel(value) {
|
|
39
|
+
if (typeof value === 'number') {
|
|
40
|
+
return `${value}px`;
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
parseLayout(config) {
|
|
45
|
+
const dim = this.getLayoutDimension(config.group);
|
|
46
|
+
const gridTemplate = this.parseGridTemplate(dim);
|
|
47
|
+
const group = (config.group || []).map((current)=>{
|
|
48
|
+
if (!Array.isArray(current)) {
|
|
49
|
+
console.error(`layout ${JSON.stringify(current)} error, must be a array`);
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
const parseCurrent = current.map((item)=>{
|
|
53
|
+
if (typeof item === 'string' || typeof item === 'number') {
|
|
54
|
+
return {
|
|
55
|
+
prop: item,
|
|
56
|
+
item: {
|
|
57
|
+
gridArea: item,
|
|
58
|
+
overflow: 'hidden'
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
if (typeof item === 'object' && Reflect.has(item, 'group')) {
|
|
63
|
+
return this.parseLayout(item);
|
|
64
|
+
}
|
|
65
|
+
return item;
|
|
66
|
+
});
|
|
67
|
+
return parseCurrent;
|
|
68
|
+
});
|
|
69
|
+
const gridTemplateAreas = this.parseGridTemplateAreas(dim, group);
|
|
70
|
+
const layoutConfig = {
|
|
71
|
+
prop: config.prop || '',
|
|
72
|
+
item: _object_spread({
|
|
73
|
+
gridArea: config.prop,
|
|
74
|
+
overflow: 'hidden'
|
|
75
|
+
}, config.item),
|
|
76
|
+
container: _object_spread({
|
|
77
|
+
display: 'grid',
|
|
78
|
+
gridTemplateAreas,
|
|
79
|
+
gridGap: '24px'
|
|
80
|
+
}, gridTemplate, config.container),
|
|
81
|
+
group
|
|
82
|
+
};
|
|
83
|
+
return layoutConfig;
|
|
84
|
+
}
|
|
85
|
+
getLayoutDimension(layout = []) {
|
|
86
|
+
return layout.reduce((pre, current)=>{
|
|
87
|
+
if (!Array.isArray(current)) {
|
|
88
|
+
console.error(`layout ${JSON.stringify(current)} error, must be a array`);
|
|
89
|
+
}
|
|
90
|
+
if (current) {
|
|
91
|
+
pre.columns = Math.max(pre.columns, current.length || 0);
|
|
92
|
+
}
|
|
93
|
+
pre.rows += 1;
|
|
94
|
+
return pre;
|
|
95
|
+
}, {
|
|
96
|
+
columns: 0,
|
|
97
|
+
rows: 0
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
parseGridTemplate(dim) {
|
|
101
|
+
return {
|
|
102
|
+
gridTemplateColumns: this.repeatTemplate(dim.columns, false),
|
|
103
|
+
gridTemplateRows: this.repeatTemplate(dim.rows)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
parseGridTemplateAreas(gridTemplate, group) {
|
|
107
|
+
return group.reduce((area, rows)=>{
|
|
108
|
+
const newRows = this.autoFillColumns(rows, gridTemplate.columns);
|
|
109
|
+
area.push(`"${newRows.join(' ')}"`);
|
|
110
|
+
return area;
|
|
111
|
+
}, []).join('\n');
|
|
112
|
+
}
|
|
113
|
+
// 当前列数不够时自动填充
|
|
114
|
+
autoFillColumns(rows, maxColumns) {
|
|
115
|
+
if (rows.length === maxColumns) {
|
|
116
|
+
// 等于最大列时不扩展rows
|
|
117
|
+
return rows.map((row)=>row.prop);
|
|
118
|
+
}
|
|
119
|
+
// 均分补全的列
|
|
120
|
+
const fillLen = Math.floor((maxColumns - rows.length) / rows.length);
|
|
121
|
+
const newRows = rows.reduce((pre, row)=>{
|
|
122
|
+
pre.push(row.prop);
|
|
123
|
+
const fillData = new Array(fillLen).fill(row.prop);
|
|
124
|
+
return pre.concat(fillData);
|
|
125
|
+
}, []);
|
|
126
|
+
// 补全不够均分的列
|
|
127
|
+
if (newRows.length < maxColumns) {
|
|
128
|
+
const remainData = new Array(maxColumns - newRows.length).fill('.');
|
|
129
|
+
return newRows.concat(remainData);
|
|
130
|
+
}
|
|
131
|
+
return newRows;
|
|
132
|
+
}
|
|
133
|
+
repeatTemplate(len, auto = true) {
|
|
134
|
+
return new Array(len + 1).join(auto ? 'auto ' : '1fr ').trim();
|
|
135
|
+
}
|
|
136
|
+
constructor(layout = []){
|
|
137
|
+
_define_property(this, "layout", void 0);
|
|
138
|
+
if (Array.isArray(layout)) {
|
|
139
|
+
this.layout = this.parseLayout({
|
|
140
|
+
prop: '',
|
|
141
|
+
group: layout
|
|
142
|
+
});
|
|
143
|
+
} else {
|
|
144
|
+
this.layout = this.parseLayout(layout);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// 布局管理器
|
|
149
|
+
export { Layout as default };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
class Path {
|
|
15
|
+
static getCurPath(parent, current) {
|
|
16
|
+
return parent === '' ? current : [
|
|
17
|
+
parent,
|
|
18
|
+
current
|
|
19
|
+
].join(this.separator);
|
|
20
|
+
}
|
|
21
|
+
static getPathVal(obj, path, leftDeviation = 0) {
|
|
22
|
+
if (!path) return obj;
|
|
23
|
+
const pathArr = path.split(this.separator);
|
|
24
|
+
for(let i = 0; i < pathArr.length - leftDeviation; i += 1){
|
|
25
|
+
if (obj === undefined) return undefined;
|
|
26
|
+
obj = pathArr[i] === '' ? obj : obj[pathArr[i]];
|
|
27
|
+
}
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
30
|
+
static setPathValue(obj = {}, path, value) {
|
|
31
|
+
const newValue = JSON.parse(JSON.stringify(obj));
|
|
32
|
+
const pathArr = path.split(this.separator);
|
|
33
|
+
const lastProp = pathArr.pop() || '';
|
|
34
|
+
let target = newValue;
|
|
35
|
+
pathArr.forEach((prop)=>{
|
|
36
|
+
if (!target[prop]) target[prop] = {};
|
|
37
|
+
target = target[prop];
|
|
38
|
+
});
|
|
39
|
+
target[lastProp] = value;
|
|
40
|
+
return newValue;
|
|
41
|
+
}
|
|
42
|
+
// 获取当前路径的字路径(相对于父路径)
|
|
43
|
+
static getSubPath(parent, current) {
|
|
44
|
+
return current.replace(`${parent}.`, '');
|
|
45
|
+
}
|
|
46
|
+
// 获取路径最后一个属性
|
|
47
|
+
static getPathLastProp(path) {
|
|
48
|
+
return path.split(this.separator).pop();
|
|
49
|
+
}
|
|
50
|
+
// 获取父路径
|
|
51
|
+
static getParentPath(path) {
|
|
52
|
+
const arrPath = path.split(this.separator);
|
|
53
|
+
if (arrPath.length <= 1) {
|
|
54
|
+
return ''; // root path
|
|
55
|
+
}
|
|
56
|
+
return arrPath.slice(0, arrPath.length - 1).join(this.separator);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
_define_property(Path, "separator", '.');
|
|
60
|
+
export { Path as default };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { executeExpression, isExpression } from './expression.ts.js';
|
|
2
|
+
import widgetTree from './widgetTree.ts.js';
|
|
3
|
+
const reactionsMap = {};
|
|
4
|
+
const subscribe = (path, typeName, fn)=>{
|
|
5
|
+
if (!reactionsMap[path]) {
|
|
6
|
+
reactionsMap[path] = {
|
|
7
|
+
lifetime: {},
|
|
8
|
+
effect: {},
|
|
9
|
+
fns: []
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (typeName === 'valChange') {
|
|
13
|
+
reactionsMap[path].fns.push(fn);
|
|
14
|
+
} else {
|
|
15
|
+
const [type, name] = typeName.split('/');
|
|
16
|
+
if (!reactionsMap[path][type][name]) {
|
|
17
|
+
reactionsMap[path][type][name] = [
|
|
18
|
+
fn
|
|
19
|
+
];
|
|
20
|
+
} else {
|
|
21
|
+
reactionsMap[path][type][name].push(fn);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* 解析单个reaction
|
|
27
|
+
*
|
|
28
|
+
* @param crtInsPath 当前表单组件的path
|
|
29
|
+
* @param targetPath 需要操作执行操作表单的path
|
|
30
|
+
* @param reaction 传入的reacion配置
|
|
31
|
+
* @returns viod
|
|
32
|
+
*/ const resolveReaction = (crtInsPath, targetPath, reaction)=>()=>{
|
|
33
|
+
const { instance: crtInstance } = widgetTree.widgetMap[crtInsPath] || {}; // 当前组件实例,用来条件表达式判断
|
|
34
|
+
const { instance: operateInstance } = widgetTree.widgetMap[targetPath] || {}; // 需要执行操作的组件实例,可能为其他组件也可能为当前组件
|
|
35
|
+
let fullfill = true;
|
|
36
|
+
const deps = [];
|
|
37
|
+
if (reaction.source) {
|
|
38
|
+
const sources = Array.isArray(reaction.source) ? reaction.source : [
|
|
39
|
+
reaction.source
|
|
40
|
+
];
|
|
41
|
+
sources.forEach((item)=>{
|
|
42
|
+
const { instance } = widgetTree.widgetMap[parsePath(item, crtInsPath)];
|
|
43
|
+
deps.push(instance);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (typeof reaction.if === 'string') {
|
|
47
|
+
fullfill = executeExpression(reaction.if, crtInstance, deps);
|
|
48
|
+
}
|
|
49
|
+
const operations = fullfill ? reaction.then : reaction.else;
|
|
50
|
+
executeOperations(operations, operateInstance, deps);
|
|
51
|
+
};
|
|
52
|
+
const executeOperations = (operations, instance, deps)=>{
|
|
53
|
+
if (operations) {
|
|
54
|
+
if (operations.state) {
|
|
55
|
+
Object.keys(operations.state).forEach((key)=>{
|
|
56
|
+
let val = operations.state[key];
|
|
57
|
+
if (typeof val === 'string' && /^{{.+}}$/.test(val.trim())) {
|
|
58
|
+
val = executeExpression(val, instance, deps);
|
|
59
|
+
}
|
|
60
|
+
instance.setState(key, val);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (Array.isArray(operations.actions)) {
|
|
64
|
+
operations.actions.forEach((item)=>{
|
|
65
|
+
executeExpression(item, instance, deps);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const parsePath = (path, instance)=>isExpression(path) ? executeExpression(path, instance) : path;
|
|
71
|
+
export const reactionRegister = (path, reactions = [])=>{
|
|
72
|
+
const { instance } = widgetTree.widgetMap[path] || {};
|
|
73
|
+
if (reactions && Array.isArray(reactions)) {
|
|
74
|
+
reactions.forEach((reaction)=>{
|
|
75
|
+
// source 和 target 互斥,如果schema中同时定义,则取source,如果都没有定义则默认source为当前表单
|
|
76
|
+
// source可能会用数组同时定义多个
|
|
77
|
+
const subscribePaths = reaction.source ? Array.isArray(reaction.source) ? reaction.source : [
|
|
78
|
+
reaction.source
|
|
79
|
+
] : [
|
|
80
|
+
path
|
|
81
|
+
];
|
|
82
|
+
const targePath = parsePath(typeof reaction.target === 'string' ? reaction.target : path, instance);
|
|
83
|
+
subscribePaths.forEach((p)=>{
|
|
84
|
+
const sourcePathItem = parsePath(p, instance);
|
|
85
|
+
if (typeof reaction.lifetime === 'string') {
|
|
86
|
+
subscribe(sourcePathItem, `lifetime/${reaction.lifetime}`, resolveReaction(path, targePath, reaction));
|
|
87
|
+
}
|
|
88
|
+
if (typeof reaction.effect === 'string') {
|
|
89
|
+
subscribe(sourcePathItem, `effect/${reaction.effect}`, resolveReaction(path, targePath, reaction));
|
|
90
|
+
}
|
|
91
|
+
if (!reaction.lifetime && !reaction.effect) {
|
|
92
|
+
subscribe(sourcePathItem, 'valChange', resolveReaction(path, targePath, reaction));
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
// 销毁widget对应的reaction
|
|
99
|
+
export const reactionUnRegister = (path)=>{
|
|
100
|
+
delete reactionsMap[path];
|
|
101
|
+
};
|
|
102
|
+
export const reactionDispatch = (path, typeName)=>{
|
|
103
|
+
const [type = '', name = ''] = typeName.split('/');
|
|
104
|
+
let fns = [];
|
|
105
|
+
if (reactionsMap[path]) {
|
|
106
|
+
var _reactionsMap_path_type, _reactionsMap_path;
|
|
107
|
+
if (type === 'valChange') {
|
|
108
|
+
fns = reactionsMap[path].fns;
|
|
109
|
+
} else if ((_reactionsMap_path = reactionsMap[path]) === null || _reactionsMap_path === void 0 ? void 0 : (_reactionsMap_path_type = _reactionsMap_path[type]) === null || _reactionsMap_path_type === void 0 ? void 0 : _reactionsMap_path_type[name]) {
|
|
110
|
+
fns = reactionsMap[path][type][name];
|
|
111
|
+
}
|
|
112
|
+
fns.forEach((fn)=>{
|
|
113
|
+
fn();
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
import { resolveComponent } from 'vue';
|
|
15
|
+
/**
|
|
16
|
+
* Registry注册Form组件全局相关内容
|
|
17
|
+
*/ export class Registry {
|
|
18
|
+
addComponentsMap(coms = {}) {
|
|
19
|
+
this.addMap('components', coms);
|
|
20
|
+
}
|
|
21
|
+
getComponent(key) {
|
|
22
|
+
return this.components.get(key);
|
|
23
|
+
}
|
|
24
|
+
addFieldsMap(map = {}) {
|
|
25
|
+
this.addMap('fields', map);
|
|
26
|
+
}
|
|
27
|
+
getField(key) {
|
|
28
|
+
return this.fields.get(key);
|
|
29
|
+
}
|
|
30
|
+
addBaseWidgets(widgets = {}) {
|
|
31
|
+
this.addMap('widgets', widgets);
|
|
32
|
+
}
|
|
33
|
+
// 获取基础控件
|
|
34
|
+
getBaseWidget(name) {
|
|
35
|
+
if (!name) {
|
|
36
|
+
console.warn('base widget name is empty');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (this.widgets.has(name)) {
|
|
40
|
+
return this.widgets.get(name);
|
|
41
|
+
}
|
|
42
|
+
if (name && name.indexOf(Registry.namespace) !== 0) {
|
|
43
|
+
return resolveComponent(`${Registry.namespace}-${name}`);
|
|
44
|
+
}
|
|
45
|
+
return resolveComponent(name);
|
|
46
|
+
}
|
|
47
|
+
addMap(props, map) {
|
|
48
|
+
if (!props || !map) return;
|
|
49
|
+
Object.entries(map).forEach(([key, value])=>{
|
|
50
|
+
if (this[props].has(key)) {
|
|
51
|
+
console.warn('repeat key', key);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (typeof value === 'string') {
|
|
55
|
+
this[props].set(key, resolveComponent(value));
|
|
56
|
+
} else {
|
|
57
|
+
this[props].set(key, value);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
constructor(){
|
|
62
|
+
// 基础类型控件
|
|
63
|
+
_define_property(this, "widgets", new Map());
|
|
64
|
+
// 自定义组件
|
|
65
|
+
_define_property(this, "components", new Map());
|
|
66
|
+
// 每种Schema type对于的处理器
|
|
67
|
+
_define_property(this, "fields", new Map());
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// 全局命名空间
|
|
71
|
+
_define_property(Registry, "namespace", 'bk');
|
|
72
|
+
// 全局上下
|
|
73
|
+
_define_property(Registry, "context", {});
|
|
74
|
+
export default new Registry();
|