icarys-fc-vant 1.0.15 → 1.0.16
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/README.md +87 -278
- package/dist/components/common/subform/package.json +48 -0
- package/dist/components/common/subform/src/component.jsx +75 -0
- package/dist/components/common/subform/src/index.js +3 -0
- package/dist/components/common/wangeditor/package-lock.json +114 -0
- package/dist/components/common/wangeditor/package.json +52 -0
- package/dist/components/common/wangeditor/src/component.jsx +74 -0
- package/dist/components/common/wangeditor/src/index.js +3 -0
- package/dist/core/babel.config.js +13 -0
- package/dist/core/bili.config.js +34 -0
- package/dist/core/package-lock.json +13 -0
- package/dist/core/package.json +61 -0
- package/dist/core/src/components/formCreate.js +287 -0
- package/dist/core/src/components/fragment.js +12 -0
- package/dist/core/src/factory/context.js +264 -0
- package/dist/core/src/factory/creator.js +63 -0
- package/dist/core/src/factory/maker.js +17 -0
- package/dist/core/src/factory/manager.js +87 -0
- package/dist/core/src/factory/node.js +89 -0
- package/dist/core/src/factory/parser.js +28 -0
- package/dist/core/src/frame/api.js +691 -0
- package/dist/core/src/frame/attrs.js +12 -0
- package/dist/core/src/frame/dataDriver.js +76 -0
- package/dist/core/src/frame/fetch.js +128 -0
- package/dist/core/src/frame/index.js +792 -0
- package/dist/core/src/frame/language.js +50 -0
- package/dist/core/src/frame/provider.js +297 -0
- package/dist/core/src/frame/util.js +311 -0
- package/dist/core/src/handler/context.js +573 -0
- package/dist/core/src/handler/effect.js +122 -0
- package/dist/core/src/handler/index.js +143 -0
- package/dist/core/src/handler/inject.js +199 -0
- package/dist/core/src/handler/input.js +199 -0
- package/dist/core/src/handler/lifecycle.js +55 -0
- package/dist/core/src/handler/loader.js +375 -0
- package/dist/core/src/handler/page.js +46 -0
- package/dist/core/src/handler/render.js +29 -0
- package/dist/core/src/index.js +12 -0
- package/dist/core/src/parser/html.js +17 -0
- package/dist/core/src/render/cache.js +47 -0
- package/dist/core/src/render/index.js +33 -0
- package/dist/core/src/render/render.js +418 -0
- package/dist/core/types/index.d.ts +842 -0
- package/dist/icarys-fc-vant.umd.js +17 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.esm.js +39 -0
- package/dist/index.js +46 -0
- package/dist/utils/lib/console.js +16 -0
- package/dist/utils/lib/debounce.js +9 -0
- package/dist/utils/lib/deepextend.js +51 -0
- package/dist/utils/lib/deepset.js +14 -0
- package/dist/utils/lib/extend.js +20 -0
- package/dist/utils/lib/index.js +14 -0
- package/dist/utils/lib/json.js +90 -0
- package/dist/utils/lib/mergeprops.js +62 -0
- package/dist/utils/lib/mitt.js +43 -0
- package/dist/utils/lib/modify.js +8 -0
- package/dist/utils/lib/slot.js +8 -0
- package/dist/utils/lib/toarray.js +5 -0
- package/dist/utils/lib/tocase.js +11 -0
- package/dist/utils/lib/todate.js +10 -0
- package/dist/utils/lib/toline.js +10 -0
- package/dist/utils/lib/topromise.js +10 -0
- package/dist/utils/lib/tostring.js +7 -0
- package/dist/utils/lib/type.js +45 -0
- package/dist/utils/lib/unique.js +6 -0
- package/dist/utils/package.json +32 -0
- package/dist/vant/auto-import.d.ts +5 -0
- package/dist/vant/auto-import.js +50 -0
- package/dist/vant/babel.config.js +10 -0
- package/dist/vant/bili.config.js +40 -0
- package/dist/vant/examples/main.js +13 -0
- package/dist/vant/examples/rule.js +366 -0
- package/dist/vant/package.json +83 -0
- package/dist/vant/src/components/calendar.jsx +128 -0
- package/dist/vant/src/components/cascader.jsx +120 -0
- package/dist/vant/src/components/checkbox.jsx +38 -0
- package/dist/vant/src/components/datePicker.jsx +87 -0
- package/dist/vant/src/components/group.jsx +384 -0
- package/dist/vant/src/components/index.js +26 -0
- package/dist/vant/src/components/radio.jsx +38 -0
- package/dist/vant/src/components/select.jsx +81 -0
- package/dist/vant/src/components/timePicker.jsx +76 -0
- package/dist/vant/src/components/uploader.jsx +99 -0
- package/dist/vant/src/core/alias.js +31 -0
- package/dist/vant/src/core/api.js +135 -0
- package/dist/vant/src/core/config.js +35 -0
- package/dist/vant/src/core/index.js +45 -0
- package/dist/vant/src/core/manager.js +282 -0
- package/dist/vant/src/core/provider.js +63 -0
- package/dist/vant/src/core/utils.js +15 -0
- package/dist/vant/src/index.js +13 -0
- package/dist/vant/src/parsers/hidden.js +12 -0
- package/dist/vant/src/parsers/index.js +59 -0
- package/dist/vant/src/parsers/row.js +10 -0
- package/dist/vant/src/style/index.css +495 -0
- package/dist/vant/types/config.d.ts +99 -0
- package/dist/vant/types/index.d.ts +27 -0
- package/dist/vant/vue.config.js +21 -0
- package/package.json +29 -67
- package/dist/index.min.js +0 -7411
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
en: {
|
|
3
|
+
required: '{title} is required',
|
|
4
|
+
validate: {
|
|
5
|
+
url: '{title} is not a valid url',
|
|
6
|
+
email: '{title} is not a valid email',
|
|
7
|
+
ip: '{title} {title} is not a valid ip',
|
|
8
|
+
phone: '{title} {title} is not a valid phone',
|
|
9
|
+
pattern: '{title} does not match pattern {pattern}',
|
|
10
|
+
uppercase: '{title} must be all uppercase',
|
|
11
|
+
lowercase: '{title} must be all lowercased',
|
|
12
|
+
positive: '{title} is not a positive number',
|
|
13
|
+
negative: '{title} is not a negative number',
|
|
14
|
+
equal: '{title} is not equal to {equal}',
|
|
15
|
+
min: '{title} cannot be less than {min}',
|
|
16
|
+
max: '{title} cannot be greater than {max}',
|
|
17
|
+
enum: '{title} must be one of {enum}',
|
|
18
|
+
hasKeys: '{title} does not contain required fields {hasKeys}',
|
|
19
|
+
minLen: '{title} must be at least {minLen}',
|
|
20
|
+
maxLen: '{title} cannot be longer than {maxLen}',
|
|
21
|
+
len: '{title} must be exactly {len}',
|
|
22
|
+
integer: '{title} is not an integer',
|
|
23
|
+
number: '{title} is not an number',
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
'zh-cn': {
|
|
27
|
+
required: '{title}不能为空',
|
|
28
|
+
validate: {
|
|
29
|
+
url: '{title}不是有效的 url 地址',
|
|
30
|
+
email: '{title}不是有效的邮箱地址',
|
|
31
|
+
ip: '{title}不是有效的 IP 地址',
|
|
32
|
+
phone: '{title}不是正确的手机号',
|
|
33
|
+
pattern: '{title}必须匹配 {pattern}',
|
|
34
|
+
uppercase: '{title}必须全大写',
|
|
35
|
+
lowercase: '{title}必须全小写',
|
|
36
|
+
positive: '{title}不是正数',
|
|
37
|
+
negative: '{title}不是负数',
|
|
38
|
+
equal: '{title}必须等于 {equal}',
|
|
39
|
+
min: '{title}必须大于等于 {min}',
|
|
40
|
+
max: '{title}必须小于等于 {max}',
|
|
41
|
+
enum: '{title}必须是 {enum} 之一',
|
|
42
|
+
hasKeys: '{title}必须包含 {hasKeys} 字段',
|
|
43
|
+
minLen: '{title}长度必须大于 {minLen}',
|
|
44
|
+
maxLen: '{title}长度必须小于 {maxLen}',
|
|
45
|
+
len: '{title}长度必须为 {len}',
|
|
46
|
+
integer: '{title}必须为整数',
|
|
47
|
+
number: '{title}必须为数字',
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import {err} from '../../../utils/lib/console';
|
|
2
|
+
import {byCtx, deepGet, invoke, parseFn} from './util';
|
|
3
|
+
import is, {hasProperty} from '../../../utils/lib/type';
|
|
4
|
+
import deepSet from '../../../utils/lib/deepset';
|
|
5
|
+
import {deepCopy} from '../../../utils/lib/deepextend';
|
|
6
|
+
import toArray from '../../../utils/lib/toarray';
|
|
7
|
+
import debounce from '../../../utils/lib/debounce';
|
|
8
|
+
import {nextTick} from 'vue';
|
|
9
|
+
import {toPromise} from '@form-create/utils';
|
|
10
|
+
|
|
11
|
+
const loadData = function (fc) {
|
|
12
|
+
const loadData = {
|
|
13
|
+
name: 'loadData',
|
|
14
|
+
_fn: [],
|
|
15
|
+
loaded(inject, rule, api) {
|
|
16
|
+
this.deleted(inject);
|
|
17
|
+
nextTick(() => {
|
|
18
|
+
let attrs = toArray(inject.getValue());
|
|
19
|
+
const unwatchs = [];
|
|
20
|
+
attrs.forEach(attr => {
|
|
21
|
+
if (attr && (attr.attr || attr.template)) {
|
|
22
|
+
let fn = (get) => {
|
|
23
|
+
let group;
|
|
24
|
+
if (rule && rule.__fc__) {
|
|
25
|
+
group = rule.__fc__.getParentGroup();
|
|
26
|
+
}
|
|
27
|
+
let value;
|
|
28
|
+
if (attr.template) {
|
|
29
|
+
value = fc.$handle.loadStrVar(attr.template, get, group ? {rule, value: (fc.$handle.subRuleData[group.id] || {})} : null);
|
|
30
|
+
} else if (attr.handler && is.Function(attr.handler)) {
|
|
31
|
+
value = attr.handler(get, rule, api);
|
|
32
|
+
} else {
|
|
33
|
+
value = fc.$handle.loadStrVar(`{{${attr.attr}}}`, get, group ? {rule, value: (fc.$handle.subRuleData[group.id] || {})} : null);
|
|
34
|
+
}
|
|
35
|
+
if ((value == null || value === '') && attr.default != null) {
|
|
36
|
+
value = attr.default;
|
|
37
|
+
}
|
|
38
|
+
if (attr.copy !== false) {
|
|
39
|
+
value = deepCopy(value)
|
|
40
|
+
}
|
|
41
|
+
const _rule = (attr.modify ? rule : inject.getProp());
|
|
42
|
+
if (attr.to === 'child') {
|
|
43
|
+
if (_rule.children) {
|
|
44
|
+
_rule.children[0] = value;
|
|
45
|
+
} else {
|
|
46
|
+
_rule.children = [value];
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
deepSet(_rule, attr.to || 'options', value);
|
|
50
|
+
}
|
|
51
|
+
api.sync(rule);
|
|
52
|
+
};
|
|
53
|
+
let callback = (get) => fn(get);
|
|
54
|
+
const unwatch = fc.watchLoadData(callback);
|
|
55
|
+
fn = debounce(fn, attr.wait || 300)
|
|
56
|
+
if (attr.watch !== false) {
|
|
57
|
+
unwatchs.push(unwatch);
|
|
58
|
+
} else {
|
|
59
|
+
unwatch();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
this._fn[inject.id] = unwatchs;
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
deleted(inject) {
|
|
67
|
+
if (this._fn[inject.id]) {
|
|
68
|
+
this._fn[inject.id].forEach(un => {
|
|
69
|
+
un();
|
|
70
|
+
})
|
|
71
|
+
delete this._fn[inject.id];
|
|
72
|
+
}
|
|
73
|
+
inject.clearProp();
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
loadData.watch = loadData.loaded;
|
|
77
|
+
return loadData;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const t = function (fc) {
|
|
81
|
+
const t = {
|
|
82
|
+
name: 't',
|
|
83
|
+
_fn: [],
|
|
84
|
+
loaded(inject, rule, api) {
|
|
85
|
+
this.deleted(inject);
|
|
86
|
+
let attrs = inject.getValue() || {};
|
|
87
|
+
const unwatchs = [];
|
|
88
|
+
Object.keys(attrs).forEach(key => {
|
|
89
|
+
const attr = attrs[key];
|
|
90
|
+
if (attr) {
|
|
91
|
+
const isObj = typeof attr === 'object';
|
|
92
|
+
let fn = (get) => {
|
|
93
|
+
let value = fc.t(isObj ? attr.attr : attr, isObj ? attr.params : null, get);
|
|
94
|
+
const _rule = ((isObj && attr.modify) ? rule : inject.getProp());
|
|
95
|
+
if (key === 'child') {
|
|
96
|
+
if (_rule.children) {
|
|
97
|
+
_rule.children[0] = value;
|
|
98
|
+
} else {
|
|
99
|
+
_rule.children = [value];
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
deepSet(_rule, key, value);
|
|
103
|
+
}
|
|
104
|
+
api.sync(rule);
|
|
105
|
+
};
|
|
106
|
+
let callback = (get) => fn(get);
|
|
107
|
+
const unwatch = fc.watchLoadData(callback);
|
|
108
|
+
fn = debounce(fn, attr.wait || 300)
|
|
109
|
+
if (attr.watch !== false) {
|
|
110
|
+
unwatchs.push(unwatch);
|
|
111
|
+
} else {
|
|
112
|
+
unwatch();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
this._fn[inject.id] = unwatchs;
|
|
117
|
+
},
|
|
118
|
+
deleted(inject) {
|
|
119
|
+
if (this._fn[inject.id]) {
|
|
120
|
+
this._fn[inject.id].forEach(un => {
|
|
121
|
+
un();
|
|
122
|
+
})
|
|
123
|
+
delete this._fn[inject.id];
|
|
124
|
+
}
|
|
125
|
+
inject.clearProp();
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
t.watch = t.loaded;
|
|
129
|
+
return t;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const componentValidate = {
|
|
133
|
+
name: 'componentValidate',
|
|
134
|
+
load(attr, rule, api) {
|
|
135
|
+
let options = attr.getValue();
|
|
136
|
+
if (!options || options.method === false) {
|
|
137
|
+
attr.clearProp();
|
|
138
|
+
api.clearValidateState([rule.field]);
|
|
139
|
+
} else {
|
|
140
|
+
if (!is.Object(options)) {
|
|
141
|
+
options = {method: options};
|
|
142
|
+
}
|
|
143
|
+
const method = options.method;
|
|
144
|
+
const validate = {
|
|
145
|
+
...options,
|
|
146
|
+
validator(...args) {
|
|
147
|
+
const ctx = byCtx(rule);
|
|
148
|
+
if (ctx) {
|
|
149
|
+
return api.exec(ctx.id, is.String(method) ? method : 'formCreateValidate', ...args, {
|
|
150
|
+
attr,
|
|
151
|
+
rule,
|
|
152
|
+
api
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
delete validate.method;
|
|
158
|
+
attr.getProp().validate = [validate];
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
watch(...args) {
|
|
162
|
+
componentValidate.load(...args);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
const fetch = function (fc) {
|
|
168
|
+
|
|
169
|
+
function parseOpt(option) {
|
|
170
|
+
if (is.String(option)) {
|
|
171
|
+
option = {
|
|
172
|
+
action: option,
|
|
173
|
+
to: 'options'
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return option;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function run(inject, rule, api) {
|
|
180
|
+
let option = inject.value;
|
|
181
|
+
fetchAttr.deleted(inject);
|
|
182
|
+
if (is.Function(option)) {
|
|
183
|
+
option = option(rule, api);
|
|
184
|
+
}
|
|
185
|
+
option = parseOpt(option);
|
|
186
|
+
|
|
187
|
+
const set = (val) => {
|
|
188
|
+
if (val === undefined) {
|
|
189
|
+
inject.clearProp();
|
|
190
|
+
} else {
|
|
191
|
+
deepSet(inject.getProp(), option.to || 'options', val);
|
|
192
|
+
}
|
|
193
|
+
if (val != null && option && option.key && fc.$handle.options.globalData[option.key]) {
|
|
194
|
+
fc.fetchCache.set(fc.$handle.options.globalData[option.key], {status: true, data: val});
|
|
195
|
+
}
|
|
196
|
+
api.sync(rule);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (!option || (!option.action && !option.key)) {
|
|
200
|
+
set(undefined);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
option = deepCopy(option);
|
|
204
|
+
if (!option.to) {
|
|
205
|
+
option.to = 'options';
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const onError = option.onError;
|
|
209
|
+
|
|
210
|
+
const check = () => {
|
|
211
|
+
if (!inject.getValue()) {
|
|
212
|
+
inject.clearProp();
|
|
213
|
+
api.sync(rule);
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
fetchAttr._fn[inject.id] = fc.watchLoadData(debounce((get, change) => {
|
|
218
|
+
if (change && option.watch === false) {
|
|
219
|
+
return fetchAttr._fn[inject.id]();
|
|
220
|
+
}
|
|
221
|
+
if(option.key) {
|
|
222
|
+
fc.targetRule = rule;
|
|
223
|
+
const res = get('$globalData.' + option.key);
|
|
224
|
+
delete fc.targetRule;
|
|
225
|
+
if (res) {
|
|
226
|
+
if (check()) return;
|
|
227
|
+
set(res);
|
|
228
|
+
}
|
|
229
|
+
return ;
|
|
230
|
+
}
|
|
231
|
+
const _option = fc.$handle.loadFetchVar(deepCopy(option), get, rule);
|
|
232
|
+
const config = {
|
|
233
|
+
headers: {},
|
|
234
|
+
..._option,
|
|
235
|
+
onSuccess(body, flag) {
|
|
236
|
+
if (check()) return;
|
|
237
|
+
let fn = (v) => flag ? v : (hasProperty(v, 'data') ? v.data : v);
|
|
238
|
+
const parse = parseFn(_option.parse);
|
|
239
|
+
if (is.Function(parse)) {
|
|
240
|
+
fn = parse;
|
|
241
|
+
} else if (parse && is.String(parse)) {
|
|
242
|
+
fn = (v) => {
|
|
243
|
+
return deepGet(v, parse);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
toPromise(fn(body, rule, api)).then(res => {
|
|
247
|
+
set(res);
|
|
248
|
+
})
|
|
249
|
+
},
|
|
250
|
+
onError(e) {
|
|
251
|
+
set(undefined);
|
|
252
|
+
if (check()) return;
|
|
253
|
+
(onError || ((e) => err(e.message || 'fetch fail ' + _option.action)))(e, rule, api);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
fc.$handle.beforeFetch(config, {rule, api}).then(() => {
|
|
257
|
+
if (is.Function(_option.action)) {
|
|
258
|
+
toPromise(_option.action(rule, api)).then((val) => {
|
|
259
|
+
config.onSuccess(val, true);
|
|
260
|
+
}).catch((e) => {
|
|
261
|
+
config.onError(e);
|
|
262
|
+
});
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
invoke(() => fc.create.fetch(config, {inject, rule, api}));
|
|
266
|
+
}).catch(e => {});
|
|
267
|
+
}, option.wait || 600));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const fetchAttr = {
|
|
271
|
+
name: 'fetch',
|
|
272
|
+
_fn: [],
|
|
273
|
+
loaded(...args) {
|
|
274
|
+
run(...args);
|
|
275
|
+
},
|
|
276
|
+
watch(...args) {
|
|
277
|
+
run(...args);
|
|
278
|
+
},
|
|
279
|
+
deleted(inject) {
|
|
280
|
+
if (this._fn[inject.id]) {
|
|
281
|
+
this._fn[inject.id]();
|
|
282
|
+
delete this._fn[inject.id];
|
|
283
|
+
}
|
|
284
|
+
inject.clearProp();
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
return fetchAttr;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
export default {
|
|
293
|
+
fetch,
|
|
294
|
+
loadData,
|
|
295
|
+
t,
|
|
296
|
+
componentValidate,
|
|
297
|
+
};
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import deepExtend from '../../../utils/lib/deepextend';
|
|
2
|
+
import is from '../../../utils/lib/type';
|
|
3
|
+
import mergeProps from '../../../utils/lib/mergeprops';
|
|
4
|
+
import {arrayAttrs, normalAttrs} from './attrs';
|
|
5
|
+
import {logError} from '../../../utils/lib/console';
|
|
6
|
+
import {isVNode} from 'vue';
|
|
7
|
+
import {upper} from '../../../utils/lib/toline';
|
|
8
|
+
import toCase from '../../../utils/lib/tocase';
|
|
9
|
+
|
|
10
|
+
export {parseJson, parseFn, toJson} from '../../../utils/lib/json';
|
|
11
|
+
|
|
12
|
+
export function enumerable(value, writable) {
|
|
13
|
+
return {
|
|
14
|
+
value,
|
|
15
|
+
enumerable: false,
|
|
16
|
+
configurable: false,
|
|
17
|
+
writable: !!writable
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//todo 优化位置
|
|
22
|
+
export function copyRule(rule, mode) {
|
|
23
|
+
return copyRules([rule], mode || false)[0];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function copyRules(rules, mode) {
|
|
27
|
+
return deepExtend([], [...rules], mode || false);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function mergeRule(rule, merge) {
|
|
31
|
+
mergeProps(Array.isArray(merge) ? merge : [merge], rule, {array: arrayAttrs, normal: normalAttrs});
|
|
32
|
+
return rule;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getRule(rule) {
|
|
36
|
+
const r = is.Function(rule.getRule) ? rule.getRule() : rule;
|
|
37
|
+
if (!r.type) {
|
|
38
|
+
r.type = 'input';
|
|
39
|
+
}
|
|
40
|
+
return r;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function mergeGlobal(target, merge) {
|
|
44
|
+
if (!target) return merge;
|
|
45
|
+
Object.keys(merge || {}).forEach((k) => {
|
|
46
|
+
if (merge[k]) {
|
|
47
|
+
target[k] = mergeRule(target[k] || {}, merge[k])
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return target;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function funcProxy(that, proxy) {
|
|
54
|
+
Object.defineProperties(that, Object.keys(proxy).reduce((initial, k) => {
|
|
55
|
+
initial[k] = {
|
|
56
|
+
get() {
|
|
57
|
+
return proxy[k]();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return initial;
|
|
61
|
+
}, {}))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function byCtx(rule) {
|
|
65
|
+
return rule.__fc__ || (rule.__origin__ ? rule.__origin__.__fc__ : null)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function invoke(fn, def) {
|
|
69
|
+
try {
|
|
70
|
+
def = fn()
|
|
71
|
+
} catch (e) {
|
|
72
|
+
logError(e);
|
|
73
|
+
}
|
|
74
|
+
return def;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function makeSlotBag() {
|
|
78
|
+
const slotBag = {};
|
|
79
|
+
const slotName = (n) => n || 'default';
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
setSlot(slot, vnFn) {
|
|
83
|
+
slot = slotName(slot);
|
|
84
|
+
if (!vnFn || (Array.isArray(vnFn) && vnFn.length))
|
|
85
|
+
return;
|
|
86
|
+
if (!slotBag[slot]) slotBag[slot] = [];
|
|
87
|
+
slotBag[slot].push(vnFn);
|
|
88
|
+
},
|
|
89
|
+
getSlot(slot, val) {
|
|
90
|
+
slot = slotName(slot);
|
|
91
|
+
const children = [];
|
|
92
|
+
(slotBag[slot] || []).forEach(fn => {
|
|
93
|
+
if (Array.isArray(fn)) {
|
|
94
|
+
children.push(...fn);
|
|
95
|
+
} else if (is.Function(fn)) {
|
|
96
|
+
const res = fn(...(val || []));
|
|
97
|
+
if (Array.isArray(res)) {
|
|
98
|
+
children.push(...res);
|
|
99
|
+
} else {
|
|
100
|
+
children.push(res);
|
|
101
|
+
}
|
|
102
|
+
} else if (!is.Undef(fn)) {
|
|
103
|
+
children.push(fn);
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
return children;
|
|
107
|
+
},
|
|
108
|
+
getSlots() {
|
|
109
|
+
const slots = {};
|
|
110
|
+
Object.keys(slotBag).forEach(k => {
|
|
111
|
+
slots[k] = (...args) => {
|
|
112
|
+
return this.getSlot(k, args);
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
return slots
|
|
116
|
+
},
|
|
117
|
+
slotLen(slot) {
|
|
118
|
+
slot = slotName(slot);
|
|
119
|
+
return slotBag[slot] ? slotBag[slot].length : 0;
|
|
120
|
+
},
|
|
121
|
+
mergeBag(bag) {
|
|
122
|
+
if (!bag) return this;
|
|
123
|
+
const slots = is.Function(bag.getSlots) ? bag.getSlots() : bag;
|
|
124
|
+
if (Array.isArray(bag) || isVNode(bag)) {
|
|
125
|
+
this.setSlot(undefined, () => bag);
|
|
126
|
+
} else {
|
|
127
|
+
Object.keys(slots).forEach(k => {
|
|
128
|
+
this.setSlot(k, slots[k]);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function toProps(rule) {
|
|
138
|
+
const prop = {...(rule.props || {})};
|
|
139
|
+
|
|
140
|
+
Object.keys(rule.on || {}).forEach(k => {
|
|
141
|
+
if (k.indexOf('-') > 0) {
|
|
142
|
+
k = toCase(k);
|
|
143
|
+
}
|
|
144
|
+
const name = `on${upper(k)}`;
|
|
145
|
+
if (Array.isArray(prop[name])) {
|
|
146
|
+
prop[name] = [...prop[name], rule.on[k]];
|
|
147
|
+
} else if (prop[name]) {
|
|
148
|
+
prop[name] = [prop[name], rule.on[k]];
|
|
149
|
+
} else {
|
|
150
|
+
prop[name] = rule.on[k];
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
prop.key = rule.key;
|
|
154
|
+
prop.ref = rule.ref;
|
|
155
|
+
prop.class = rule.class;
|
|
156
|
+
prop.id = rule.id;
|
|
157
|
+
prop.style = rule.style;
|
|
158
|
+
if (prop.slot) delete prop.slot;
|
|
159
|
+
|
|
160
|
+
return prop;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function setPrototypeOf(o, proto) {
|
|
164
|
+
Object.setPrototypeOf(o, proto);
|
|
165
|
+
return o;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
const changeType = (a, b) => {
|
|
170
|
+
if (typeof a === 'string') {
|
|
171
|
+
return String(b);
|
|
172
|
+
} else if (typeof a === 'number') {
|
|
173
|
+
return Number(b);
|
|
174
|
+
}
|
|
175
|
+
return b;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export const condition = {
|
|
179
|
+
'==': (a, b) => {
|
|
180
|
+
return JSON.stringify(a) === JSON.stringify(changeType(a, b));
|
|
181
|
+
},
|
|
182
|
+
'!=': (a, b) => {
|
|
183
|
+
return !condition['=='](a, b);
|
|
184
|
+
},
|
|
185
|
+
'>': (a, b) => {
|
|
186
|
+
return a > b;
|
|
187
|
+
},
|
|
188
|
+
'>=': (a, b) => {
|
|
189
|
+
return a >= b;
|
|
190
|
+
},
|
|
191
|
+
'<': (a, b) => {
|
|
192
|
+
return a < b;
|
|
193
|
+
},
|
|
194
|
+
'<=': (a, b) => {
|
|
195
|
+
return a <= b;
|
|
196
|
+
},
|
|
197
|
+
on(a, b) {
|
|
198
|
+
return a && a.indexOf && a.indexOf(changeType(a[0], b)) > -1;
|
|
199
|
+
},
|
|
200
|
+
notOn(a, b) {
|
|
201
|
+
return !condition.on(a, b);
|
|
202
|
+
},
|
|
203
|
+
in(a, b) {
|
|
204
|
+
return b && b.indexOf && b.indexOf(a) > -1;
|
|
205
|
+
},
|
|
206
|
+
notIn(a, b) {
|
|
207
|
+
return !condition.in(a, b);
|
|
208
|
+
},
|
|
209
|
+
between(a, b) {
|
|
210
|
+
return a > b[0] && a < b[1];
|
|
211
|
+
},
|
|
212
|
+
notBetween(a, b) {
|
|
213
|
+
return a < b[0] || a > b[1];
|
|
214
|
+
},
|
|
215
|
+
empty(a) {
|
|
216
|
+
return is.empty(a);
|
|
217
|
+
},
|
|
218
|
+
notEmpty(a) {
|
|
219
|
+
return !is.empty(a);
|
|
220
|
+
},
|
|
221
|
+
pattern(a, b) {
|
|
222
|
+
return new RegExp(b, 'g').test(a);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export function deepGet(val, split) {
|
|
227
|
+
(Array.isArray(split) ? split : (split || '').split('.')).forEach(k => {
|
|
228
|
+
if (val != null) {
|
|
229
|
+
val = val[k];
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
return val;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function extractVar(str) {
|
|
236
|
+
const regex = /{{\s*(.*?)\s*}}/g;
|
|
237
|
+
let match;
|
|
238
|
+
const matches = {};
|
|
239
|
+
while ((match = regex.exec(str)) !== null) {
|
|
240
|
+
if (match[1]) {
|
|
241
|
+
matches[match[1]] = true;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return Object.keys(matches);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function convertFieldToConditions(field) {
|
|
248
|
+
let parts = field.split('.');
|
|
249
|
+
let conditions = [];
|
|
250
|
+
let currentCondition = '';
|
|
251
|
+
|
|
252
|
+
parts.forEach((part, index) => {
|
|
253
|
+
if (index === 0) {
|
|
254
|
+
currentCondition = part;
|
|
255
|
+
} else {
|
|
256
|
+
currentCondition += '.' + part;
|
|
257
|
+
}
|
|
258
|
+
conditions.push(currentCondition);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
return conditions.join(' && ');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export function parseTemplateToTree(template) {
|
|
265
|
+
const tokens = [];
|
|
266
|
+
let current = '';
|
|
267
|
+
let depth = 0;
|
|
268
|
+
|
|
269
|
+
for (let i = 0; i < template.length; i++) {
|
|
270
|
+
const char = template[i];
|
|
271
|
+
|
|
272
|
+
if (char === '[') {
|
|
273
|
+
if (depth === 0 && current) {
|
|
274
|
+
tokens.push({type: 'key', value: current});
|
|
275
|
+
current = '';
|
|
276
|
+
}
|
|
277
|
+
depth++;
|
|
278
|
+
current += char;
|
|
279
|
+
} else if (char === ']') {
|
|
280
|
+
depth--;
|
|
281
|
+
current += char;
|
|
282
|
+
|
|
283
|
+
if (depth === 0) {
|
|
284
|
+
tokens.push({
|
|
285
|
+
type: 'bracket',
|
|
286
|
+
value: parseTemplateToTree(current.slice(1, -1))
|
|
287
|
+
});
|
|
288
|
+
current = '';
|
|
289
|
+
}
|
|
290
|
+
} else if (char === '.' && depth === 0) {
|
|
291
|
+
if (current) {
|
|
292
|
+
tokens.push({type: 'key', value: current});
|
|
293
|
+
current = '';
|
|
294
|
+
}
|
|
295
|
+
} else {
|
|
296
|
+
current += char;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (current) {
|
|
301
|
+
tokens.push({type: 'key', value: current});
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return tokens.map(token => {
|
|
305
|
+
if (token.type === 'key') {
|
|
306
|
+
return {key: token.value};
|
|
307
|
+
} else {
|
|
308
|
+
return {children: token.value};
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|