@plotdb/form 0.1.1 → 0.1.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/CHANGELOG.md +24 -0
- package/README.md +22 -20
- package/index.js +331 -76
- package/index.min.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v0.1.3
|
|
4
|
+
|
|
5
|
+
- upgrade dependencies
|
|
6
|
+
- add `widgets` api in manager
|
|
7
|
+
- tweak `condctrl` interface
|
|
8
|
+
- add valspec and valdef support in widget
|
|
9
|
+
- add choice opset for valspec @plotdb/form:valdef/choice
|
|
10
|
+
- support id in term
|
|
11
|
+
- support function-based meta in op
|
|
12
|
+
- tweak length opset i18n
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## v0.1.2
|
|
16
|
+
|
|
17
|
+
- fix bug: `disabled`, `isRequired`, `readonly` may return undefined, causing issue for caller that need an explicit defined value.
|
|
18
|
+
- disable widget manager if this widget is disabled.
|
|
19
|
+
- update manager disable status also upon deserialize is called.
|
|
20
|
+
- add dev note about manager disable status in widget doc
|
|
21
|
+
- support disabling managers with `disabled()` and `disable()` api
|
|
22
|
+
- disable nested managers if this manager is disabled.
|
|
23
|
+
- check progress only on enabled managers.
|
|
24
|
+
- progress return percent 1 if total = 0
|
|
25
|
+
|
|
26
|
+
|
|
3
27
|
## v0.1.1
|
|
4
28
|
|
|
5
29
|
- fix bug: exception when setting value with `manager.value` if value is undefined.
|
package/README.md
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
# @plotdb/form
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@plotdb/form` is a form management package with following feature:
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
- end user filled result of a form is also serializable.
|
|
8
|
-
- Aware of OT for collaborative editing.
|
|
9
|
-
- Works in both frontend and backend.
|
|
5
|
+
- form construction with block-based widget
|
|
6
|
+
- serializable form spec and filled data
|
|
10
7
|
|
|
8
|
+
It includes following modules:
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
`form.manager`: a recursive manager of a set of widgets.
|
|
11
|
+
`form.widget`: a form widget as a bridge between user and manager.
|
|
12
|
+
`form.opset` and `form.op`: operation set and individual operations for validating given inputs from users.
|
|
13
|
+
`form.term`: validation rule with configs including used opset/op and corresponding configurations.
|
|
14
|
+
`form.condctrl`: controller for form dynamics based on given conditions.
|
|
13
15
|
|
|
14
|
-
- `form.manager`: manage a set of form widgets.
|
|
15
|
-
- `form.widget`: interface between form manager and UI.
|
|
16
|
-
- `form.opset`: a set of op for validating given input from user.
|
|
17
|
-
- `form.op`: a specific operation for validating given input from user.
|
|
18
|
-
- `form.term`: a rule ( a op, opset and config based on the specified op ) for validating given input from user.
|
|
19
16
|
|
|
17
|
+
For more information, check markdown document for corresponding modules under `docs/` folder.
|
|
20
18
|
|
|
21
|
-
## Draft
|
|
22
19
|
|
|
23
|
-
|
|
20
|
+
## Simple Usage
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
mgr = form.manager!
|
|
23
|
+
# prepare a widget
|
|
24
|
+
widget = new form.widget({root: ...})
|
|
25
|
+
<~ widget.init!then _
|
|
26
|
+
widget.deserialize({isRequired: true}, {init: true})
|
|
27
|
+
mgr.add {widget, path: "name"}
|
|
28
|
+
mgr.on \change, -> console.log mgr.value!
|
|
29
|
+
# use condition control
|
|
30
|
+
mgr.condition!reset conditions: [{src: "name", config: {value: "dummy", path: [...]}}]
|
|
26
31
|
|
|
27
|
-
- `size` - size of all files combined.
|
|
28
|
-
- `count` - count of files.
|
|
29
|
-
- `modifiedtime` - modified time of last touched files.
|
|
30
|
-
- `ext` - type of files.
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
## License
|
|
33
34
|
|
|
35
|
+
MIT
|
package/index.js
CHANGED
|
@@ -3,58 +3,62 @@
|
|
|
3
3
|
var form, ref$, wordLen, countOps;
|
|
4
4
|
form = {};
|
|
5
5
|
form.condctrl = function(opt){
|
|
6
|
-
var ref
|
|
6
|
+
var ref$, this$ = this;
|
|
7
7
|
opt == null && (opt = {});
|
|
8
8
|
ref$ = this._ || (this._ = {});
|
|
9
9
|
ref$.hash = {};
|
|
10
10
|
ref$.enabled = {};
|
|
11
11
|
ref$.manager = opt.manager;
|
|
12
12
|
ref$.list = opt.conditions || [];
|
|
13
|
+
ref$.autorun = false;
|
|
13
14
|
ref$.applyBaseRule = opt.baseRule || function(){};
|
|
15
|
+
this._.manager.on('change', function(){
|
|
16
|
+
if (this$._.autorun) {
|
|
17
|
+
return this$.run();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
14
20
|
return this;
|
|
15
21
|
};
|
|
16
22
|
form.condctrl.prototype = (ref$ = Object.create(Object.prototype), ref$.isEnabled = function(it){
|
|
17
23
|
return this._.enabled[it];
|
|
18
24
|
}, ref$.get = function(it){
|
|
19
25
|
return this._.hash[it];
|
|
20
|
-
}, ref$.fields = function(){
|
|
21
|
-
return this._.manager._ws.w;
|
|
22
|
-
}, ref$.subcond = function(arg$){
|
|
23
|
-
var path, active, config, itf, ms;
|
|
24
|
-
path = arg$.path, active = arg$.active, config = arg$.config;
|
|
25
|
-
if (!((itf = this._.manager.widget(path)) && !itf.disabled() && (ms = itf.manager({
|
|
26
|
-
depth: 1
|
|
27
|
-
}) || []).length)) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
return ms.map(function(m){
|
|
31
|
-
var cond;
|
|
32
|
-
cond = m.condition();
|
|
33
|
-
cond.apply(import$({
|
|
34
|
-
active: active
|
|
35
|
-
}, config));
|
|
36
|
-
return cond.run();
|
|
37
|
-
});
|
|
38
26
|
}, ref$.reset = function(opt){
|
|
39
|
-
var fields, i$, to$, i, cond, results$ = [];
|
|
27
|
+
var fields, ref$, i$, to$, i, cond, results$ = [];
|
|
40
28
|
opt == null && (opt = {});
|
|
29
|
+
this._.autorun = opt.autorun != null && !opt.autorun ? false : true;
|
|
41
30
|
this._.list = opt.conditions || this._.list || [];
|
|
42
|
-
fields = this.
|
|
31
|
+
fields = this._.manager.widgets();
|
|
32
|
+
ref$ = this._ || (this._ = {});
|
|
33
|
+
ref$.hash = {};
|
|
34
|
+
ref$.enabled = {};
|
|
43
35
|
for (i$ = 0, to$ = this._.list.length; i$ < to$; ++i$) {
|
|
44
36
|
i = i$;
|
|
45
37
|
cond = this._.list[i];
|
|
46
|
-
cond.id = cond.id || (i + 1)
|
|
38
|
+
cond.id = cond.id || "_" + (i + 1);
|
|
47
39
|
this._.hash[cond.id] = cond;
|
|
48
40
|
if (!Array.isArray(cond.config)) {
|
|
49
41
|
cond.config = [cond.config];
|
|
50
42
|
}
|
|
51
|
-
|
|
43
|
+
cond.config = cond.config.map(fn$);
|
|
44
|
+
results$.push(cond.config.forEach(fn1$));
|
|
52
45
|
}
|
|
53
46
|
return results$;
|
|
54
|
-
function fn$(
|
|
47
|
+
function fn$(it){
|
|
48
|
+
var ref$;
|
|
49
|
+
return ref$ = import$({}, JSON.parse(JSON.stringify(it))), ref$.src = cond.src, ref$.func = cond.func, ref$;
|
|
50
|
+
}
|
|
51
|
+
function fn1$(cfg){
|
|
55
52
|
var k, v;
|
|
56
|
-
cfg.
|
|
57
|
-
|
|
53
|
+
if (!cfg.path && cfg.targets) {
|
|
54
|
+
cfg.path = cfg.targets;
|
|
55
|
+
}
|
|
56
|
+
if (!cfg.value && cfg.values) {
|
|
57
|
+
cfg.value = cfg.values;
|
|
58
|
+
}
|
|
59
|
+
if (!cfg.tag && cfg.tags) {
|
|
60
|
+
cfg.tag = cfg.tags;
|
|
61
|
+
}
|
|
58
62
|
return cfg.path = Array.from(new Set((cfg.prefix
|
|
59
63
|
? cfg.prefix
|
|
60
64
|
: []).concat(cfg.path || [], (function(){
|
|
@@ -81,21 +85,40 @@
|
|
|
81
85
|
return it.k;
|
|
82
86
|
}))));
|
|
83
87
|
}
|
|
88
|
+
}, ref$.subcond = function(arg$){
|
|
89
|
+
var path, active, config, itf, ms;
|
|
90
|
+
path = arg$.path, active = arg$.active, config = arg$.config;
|
|
91
|
+
if (!((itf = this._.manager.widget(path)) && !itf.disabled() && (ms = itf.manager({
|
|
92
|
+
depth: 1
|
|
93
|
+
}) || []).length)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
return ms.forEach(function(m){
|
|
97
|
+
var cond;
|
|
98
|
+
cond = m.condition();
|
|
99
|
+
cond.apply(import$({
|
|
100
|
+
active: active
|
|
101
|
+
}, config));
|
|
102
|
+
return cond.run();
|
|
103
|
+
});
|
|
84
104
|
}, ref$.apply = function(opt){
|
|
85
105
|
var path, active, enabled, isRequired, readonly, widget, curMeta, newMeta;
|
|
86
106
|
opt == null && (opt = {});
|
|
87
107
|
path = opt.path, active = opt.active, enabled = opt.enabled, isRequired = opt.isRequired, readonly = opt.readonly;
|
|
88
|
-
if (Array.isArray(path)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
108
|
+
if (Array.isArray(path)) {
|
|
109
|
+
if (path[1]) {
|
|
110
|
+
return this.subcond({
|
|
111
|
+
path: path[0],
|
|
112
|
+
active: active,
|
|
113
|
+
config: {
|
|
114
|
+
path: path.slice(1),
|
|
115
|
+
enabled: enabled,
|
|
116
|
+
isRequired: isRequired,
|
|
117
|
+
readonly: readonly
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
path = path[0];
|
|
99
122
|
}
|
|
100
123
|
if (enabled != null) {
|
|
101
124
|
this._.enabled[path] = !(!enabled !== !active && (enabled || active));
|
|
@@ -126,25 +149,25 @@
|
|
|
126
149
|
});
|
|
127
150
|
}
|
|
128
151
|
}, ref$._run = function(cfg, precond){
|
|
129
|
-
var src, values,
|
|
152
|
+
var src, values, paths, isRequired, enabled, readonly, func, result, i$, len$, path, active, ref$, itf, content;
|
|
130
153
|
cfg == null && (cfg = {});
|
|
131
|
-
src = cfg.src, values = cfg.
|
|
154
|
+
src = cfg.src, values = cfg.value, paths = cfg.path, isRequired = cfg.isRequired, enabled = cfg.enabled, readonly = cfg.readonly, func = cfg.func;
|
|
132
155
|
if (func) {
|
|
133
156
|
result = true;
|
|
134
|
-
for (i$ = 0, len$ =
|
|
135
|
-
|
|
136
|
-
active = !!func.apply(this, [(ref$ = import$({}, cfg), ref$.path =
|
|
157
|
+
for (i$ = 0, len$ = paths.length; i$ < len$; ++i$) {
|
|
158
|
+
path = paths[i$];
|
|
159
|
+
active = !!func.apply(this, [(ref$ = import$({}, cfg), ref$.path = path, ref$)]) && !(precond != null && !precond);
|
|
137
160
|
result = result && active;
|
|
138
|
-
if (Array.isArray(
|
|
161
|
+
if (Array.isArray(path) && path[1]) {
|
|
139
162
|
this.subcond({
|
|
140
|
-
path:
|
|
141
|
-
config: (ref$ = import$({}, cfg), ref$.path =
|
|
163
|
+
path: path[0],
|
|
164
|
+
config: (ref$ = import$({}, cfg), ref$.path = path.slice(1), ref$),
|
|
142
165
|
active: active
|
|
143
166
|
});
|
|
144
167
|
continue;
|
|
145
168
|
}
|
|
146
169
|
this.apply({
|
|
147
|
-
path:
|
|
170
|
+
path: path,
|
|
148
171
|
enabled: enabled,
|
|
149
172
|
active: active,
|
|
150
173
|
isRequired: isRequired,
|
|
@@ -152,36 +175,34 @@
|
|
|
152
175
|
});
|
|
153
176
|
}
|
|
154
177
|
} else {
|
|
178
|
+
values = Array.isArray(values)
|
|
179
|
+
? values
|
|
180
|
+
: [values];
|
|
155
181
|
if (!(itf = this._.manager.widget(src))) {
|
|
156
|
-
console.error("[@plotdb/form] condctrl:
|
|
157
|
-
return;
|
|
182
|
+
return console.error("[@plotdb/form] condctrl: field '" + src + "' not found");
|
|
158
183
|
}
|
|
159
184
|
content = itf.content();
|
|
160
185
|
content = Array.isArray(content)
|
|
161
186
|
? content
|
|
162
187
|
: [content];
|
|
163
|
-
active = !!content.filter(function(
|
|
164
|
-
|
|
165
|
-
return in$(c, values);
|
|
166
|
-
} else {
|
|
167
|
-
return c === values;
|
|
168
|
-
}
|
|
188
|
+
active = !!content.filter(function(it){
|
|
189
|
+
return in$(it, values);
|
|
169
190
|
}).length;
|
|
170
191
|
if (precond != null && !precond) {
|
|
171
192
|
active = false;
|
|
172
193
|
}
|
|
173
|
-
for (i$ = 0, len$ =
|
|
174
|
-
|
|
175
|
-
if (Array.isArray(
|
|
194
|
+
for (i$ = 0, len$ = paths.length; i$ < len$; ++i$) {
|
|
195
|
+
path = paths[i$];
|
|
196
|
+
if (Array.isArray(path) && path[1]) {
|
|
176
197
|
this.subcond({
|
|
177
|
-
path:
|
|
178
|
-
config: (ref$ = import$({}, cfg), ref$.path =
|
|
198
|
+
path: path[0],
|
|
199
|
+
config: (ref$ = import$({}, cfg), ref$.path = path.slice(1), ref$),
|
|
179
200
|
active: active
|
|
180
201
|
});
|
|
181
202
|
continue;
|
|
182
203
|
}
|
|
183
204
|
this.apply({
|
|
184
|
-
path:
|
|
205
|
+
path: path,
|
|
185
206
|
enabled: enabled,
|
|
186
207
|
active: active,
|
|
187
208
|
isRequired: isRequired,
|
|
@@ -194,8 +215,9 @@
|
|
|
194
215
|
}, ref$.run = function(){
|
|
195
216
|
var result, _, this$ = this;
|
|
196
217
|
result = {};
|
|
197
|
-
_ = function(list){
|
|
198
|
-
var i$, to$, i, lresult$, cond, j$, ref$, len$, cfg, results$ = [];
|
|
218
|
+
_ = function(list, ref){
|
|
219
|
+
var i$, to$, i, lresult$, cond, j$, ref$, len$, cfg, r, results$ = [];
|
|
220
|
+
ref == null && (ref = []);
|
|
199
221
|
for (i$ = 0, to$ = list.length; i$ < to$; ++i$) {
|
|
200
222
|
i = i$;
|
|
201
223
|
lresult$ = [];
|
|
@@ -204,11 +226,16 @@
|
|
|
204
226
|
continue;
|
|
205
227
|
}
|
|
206
228
|
if (cond.precond && this$._.hash[cond.precond]) {
|
|
207
|
-
|
|
229
|
+
if (in$(cond.id, ref)) {
|
|
230
|
+
console.error("[@plotdb/form] condctrl: circular ref id " + cond.id);
|
|
231
|
+
} else {
|
|
232
|
+
_([this$._.hash[cond.precond]], ref.concat([cond.id]));
|
|
233
|
+
}
|
|
208
234
|
}
|
|
209
235
|
for (j$ = 0, len$ = (ref$ = cond.config).length; j$ < len$; ++j$) {
|
|
210
236
|
cfg = ref$[j$];
|
|
211
|
-
|
|
237
|
+
r = this$._run(cfg, result[cond.precond]);
|
|
238
|
+
lresult$.push(result[cond.id] = result[cond.id] != null ? result[cond.id] && r : r);
|
|
212
239
|
}
|
|
213
240
|
results$.push(lresult$);
|
|
214
241
|
}
|
|
@@ -225,6 +252,7 @@
|
|
|
225
252
|
s: {},
|
|
226
253
|
l: {}
|
|
227
254
|
};
|
|
255
|
+
this._disabled = false;
|
|
228
256
|
this._evthdr = {};
|
|
229
257
|
this._status = 1;
|
|
230
258
|
this._mode = 'edit';
|
|
@@ -265,6 +293,12 @@
|
|
|
265
293
|
condition: function(){
|
|
266
294
|
return this._cond;
|
|
267
295
|
},
|
|
296
|
+
disabled: function(){
|
|
297
|
+
return !!this._disabled;
|
|
298
|
+
},
|
|
299
|
+
disable: function(it){
|
|
300
|
+
return this._disabled = it != null ? !!it : true;
|
|
301
|
+
},
|
|
268
302
|
fire: function(n){
|
|
269
303
|
var v, res$, i$, to$, ref$, len$, cb, results$ = [];
|
|
270
304
|
res$ = [];
|
|
@@ -338,6 +372,9 @@
|
|
|
338
372
|
delete this._ws.w[o.path];
|
|
339
373
|
return ref1$ = (ref$ = this._ws.l)[key$ = o.path], delete ref$[key$], ref1$;
|
|
340
374
|
},
|
|
375
|
+
widgets: function(){
|
|
376
|
+
return import$({}, this._ws.w || {});
|
|
377
|
+
},
|
|
341
378
|
widget: function(p){
|
|
342
379
|
return this._ws.w[p];
|
|
343
380
|
},
|
|
@@ -379,7 +416,9 @@
|
|
|
379
416
|
var w, ms, e;
|
|
380
417
|
w = this$._ws.w[o.k];
|
|
381
418
|
if (!_recurred && (ms = w.manager()).length) {
|
|
382
|
-
ms = ms.filter(function(
|
|
419
|
+
ms = ms.filter(function(it){
|
|
420
|
+
return !it.disabled();
|
|
421
|
+
}).filter(function(m){
|
|
383
422
|
var p;
|
|
384
423
|
p = m.progress({
|
|
385
424
|
_recurred: true
|
|
@@ -405,7 +444,9 @@
|
|
|
405
444
|
return ret.done += 1;
|
|
406
445
|
}
|
|
407
446
|
});
|
|
408
|
-
ret.percent = ret.
|
|
447
|
+
ret.percent = !ret.total
|
|
448
|
+
? 1
|
|
449
|
+
: ret.done / (ret.total || 1);
|
|
409
450
|
return ret;
|
|
410
451
|
},
|
|
411
452
|
_restatus: function(){
|
|
@@ -691,6 +732,11 @@
|
|
|
691
732
|
}
|
|
692
733
|
ret = ret.concat(mgrs);
|
|
693
734
|
}
|
|
735
|
+
if (this.disabled()) {
|
|
736
|
+
ret.map(function(it){
|
|
737
|
+
return it.disable();
|
|
738
|
+
});
|
|
739
|
+
}
|
|
694
740
|
return ret;
|
|
695
741
|
}
|
|
696
742
|
});
|
|
@@ -704,6 +750,13 @@
|
|
|
704
750
|
return this;
|
|
705
751
|
};
|
|
706
752
|
form.op.prototype = import$(Object.create(Object.prototype), {
|
|
753
|
+
getConfig: function(valspec){
|
|
754
|
+
if (typeof this.config === 'function') {
|
|
755
|
+
return this.config(valspec);
|
|
756
|
+
} else {
|
|
757
|
+
return this.config;
|
|
758
|
+
}
|
|
759
|
+
},
|
|
707
760
|
validate: function(val, cfg){
|
|
708
761
|
var ret;
|
|
709
762
|
cfg == null && (cfg = {});
|
|
@@ -716,10 +769,10 @@
|
|
|
716
769
|
return Promise.resolve(!!ret);
|
|
717
770
|
}
|
|
718
771
|
},
|
|
719
|
-
configDefault: function(){
|
|
772
|
+
configDefault: function(valspec){
|
|
720
773
|
var cfg, k, ref$, v;
|
|
721
774
|
cfg = {};
|
|
722
|
-
for (k in ref$ = this.
|
|
775
|
+
for (k in ref$ = this.getConfig(valspec)) {
|
|
723
776
|
v = ref$[k];
|
|
724
777
|
cfg[k] = v['default'];
|
|
725
778
|
}
|
|
@@ -733,6 +786,7 @@
|
|
|
733
786
|
this.id = opt.id;
|
|
734
787
|
this.i18n = opt.i18n;
|
|
735
788
|
this.convert = opt.convert;
|
|
789
|
+
this.valdef = opt.valdef || null;
|
|
736
790
|
this.ops = {};
|
|
737
791
|
ops = Array.isArray(opt.ops)
|
|
738
792
|
? opt.ops.map(function(it){
|
|
@@ -807,10 +861,28 @@
|
|
|
807
861
|
return (it.id || it.name) === id;
|
|
808
862
|
})[0];
|
|
809
863
|
};
|
|
810
|
-
form.opset.list = function(){
|
|
811
|
-
|
|
864
|
+
form.opset.list = function(opt){
|
|
865
|
+
var list, vd;
|
|
866
|
+
opt == null && (opt = {});
|
|
867
|
+
list = (this._list || []).map(function(it){
|
|
812
868
|
return it;
|
|
813
869
|
});
|
|
870
|
+
if (!opt.valdef) {
|
|
871
|
+
return list;
|
|
872
|
+
}
|
|
873
|
+
vd = Array.isArray(opt.valdef)
|
|
874
|
+
? opt.valdef
|
|
875
|
+
: [opt.valdef];
|
|
876
|
+
return list.filter(function(os){
|
|
877
|
+
if (!os.valdef) {
|
|
878
|
+
return !vd.length || vd.some(function(it){
|
|
879
|
+
return !it || it === "@plotdb/form:valdef/generic";
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
return vd.some(function(v){
|
|
883
|
+
return in$(v, os.valdef);
|
|
884
|
+
});
|
|
885
|
+
});
|
|
814
886
|
};
|
|
815
887
|
wordLen = function(v, method){
|
|
816
888
|
v == null && (v = "");
|
|
@@ -1143,18 +1215,24 @@
|
|
|
1143
1215
|
id: 'length',
|
|
1144
1216
|
i18n: {
|
|
1145
1217
|
"zh-TW": {
|
|
1146
|
-
length: "
|
|
1218
|
+
length: "字串長度",
|
|
1147
1219
|
lte: "≦ 小於或等於",
|
|
1148
1220
|
range: "範圍",
|
|
1149
1221
|
number: "數字",
|
|
1222
|
+
method: "計算方式",
|
|
1223
|
+
char: "字元",
|
|
1224
|
+
"simple-word": "簡易計字/詞",
|
|
1150
1225
|
"minimal length": "長度下限",
|
|
1151
1226
|
"maximal length": "長度上限"
|
|
1152
1227
|
},
|
|
1153
1228
|
"en": {
|
|
1154
|
-
length: "Length",
|
|
1229
|
+
length: "String Length",
|
|
1155
1230
|
lte: "≦",
|
|
1156
1231
|
range: "Range",
|
|
1157
1232
|
number: "Number",
|
|
1233
|
+
method: "Method",
|
|
1234
|
+
char: "By Character",
|
|
1235
|
+
"simple-word": "Count Word",
|
|
1158
1236
|
"minimal length": "Min Length",
|
|
1159
1237
|
"maximal length": "Max Length"
|
|
1160
1238
|
}
|
|
@@ -1379,6 +1457,154 @@
|
|
|
1379
1457
|
}
|
|
1380
1458
|
}
|
|
1381
1459
|
}
|
|
1460
|
+
}, {
|
|
1461
|
+
id: 'choice',
|
|
1462
|
+
valdef: ['@plotdb/form:valdef/choice'],
|
|
1463
|
+
i18n: {
|
|
1464
|
+
"zh-TW": {
|
|
1465
|
+
choice: "選擇",
|
|
1466
|
+
is: "選了",
|
|
1467
|
+
"is-not": "沒選",
|
|
1468
|
+
"is-any": "選了其中一個",
|
|
1469
|
+
val: "選項值",
|
|
1470
|
+
vals: "選項值(任一)"
|
|
1471
|
+
},
|
|
1472
|
+
"en": {
|
|
1473
|
+
choice: "Choice",
|
|
1474
|
+
is: "Is",
|
|
1475
|
+
"is-not": "Is Not",
|
|
1476
|
+
"is-any": "Is Any Of",
|
|
1477
|
+
val: "Option value",
|
|
1478
|
+
vals: "Option values (any)"
|
|
1479
|
+
}
|
|
1480
|
+
},
|
|
1481
|
+
convert: function(v){
|
|
1482
|
+
var toKey, list;
|
|
1483
|
+
toKey = function(item){
|
|
1484
|
+
if (typeof item === 'string') {
|
|
1485
|
+
return item;
|
|
1486
|
+
} else {
|
|
1487
|
+
return item.key || item.value || '';
|
|
1488
|
+
}
|
|
1489
|
+
};
|
|
1490
|
+
if (!v) {
|
|
1491
|
+
return {
|
|
1492
|
+
list: [],
|
|
1493
|
+
other: {}
|
|
1494
|
+
};
|
|
1495
|
+
}
|
|
1496
|
+
if (typeof v === 'string') {
|
|
1497
|
+
return {
|
|
1498
|
+
list: v
|
|
1499
|
+
? [v]
|
|
1500
|
+
: [],
|
|
1501
|
+
other: {}
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
list = (v.list || []).filter(function(it){
|
|
1505
|
+
return it;
|
|
1506
|
+
}).map(toKey);
|
|
1507
|
+
return {
|
|
1508
|
+
list: list,
|
|
1509
|
+
other: v.other || {}
|
|
1510
|
+
};
|
|
1511
|
+
},
|
|
1512
|
+
ops: {
|
|
1513
|
+
is: {
|
|
1514
|
+
func: function(v, c){
|
|
1515
|
+
c == null && (c = {});
|
|
1516
|
+
return !!(c.val && in$(c.val, v.list));
|
|
1517
|
+
},
|
|
1518
|
+
config: function(valspec){
|
|
1519
|
+
var values;
|
|
1520
|
+
values = ((valspec != null ? valspec.values : void 8) || []).map(function(v){
|
|
1521
|
+
return {
|
|
1522
|
+
value: v.key || v.value || v,
|
|
1523
|
+
name: v.label || v.value || v.key || v
|
|
1524
|
+
};
|
|
1525
|
+
});
|
|
1526
|
+
return {
|
|
1527
|
+
val: values.length
|
|
1528
|
+
? {
|
|
1529
|
+
type: 'choice',
|
|
1530
|
+
name: 'val',
|
|
1531
|
+
values: values
|
|
1532
|
+
}
|
|
1533
|
+
: {
|
|
1534
|
+
type: 'text',
|
|
1535
|
+
name: 'val'
|
|
1536
|
+
}
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
},
|
|
1540
|
+
"is-not": {
|
|
1541
|
+
func: function(v, c){
|
|
1542
|
+
c == null && (c = {});
|
|
1543
|
+
return !(c.val && in$(c.val, v.list));
|
|
1544
|
+
},
|
|
1545
|
+
config: function(valspec){
|
|
1546
|
+
var values;
|
|
1547
|
+
values = ((valspec != null ? valspec.values : void 8) || []).map(function(v){
|
|
1548
|
+
return {
|
|
1549
|
+
value: v.key || v.value || v,
|
|
1550
|
+
name: v.label || v.value || v.key || v
|
|
1551
|
+
};
|
|
1552
|
+
});
|
|
1553
|
+
return {
|
|
1554
|
+
val: values.length
|
|
1555
|
+
? {
|
|
1556
|
+
type: 'choice',
|
|
1557
|
+
name: 'val',
|
|
1558
|
+
values: values
|
|
1559
|
+
}
|
|
1560
|
+
: {
|
|
1561
|
+
type: 'text',
|
|
1562
|
+
name: 'val'
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
},
|
|
1567
|
+
"is-any": {
|
|
1568
|
+
func: function(v, c){
|
|
1569
|
+
var vals;
|
|
1570
|
+
c == null && (c = {});
|
|
1571
|
+
vals = Array.isArray(c.vals)
|
|
1572
|
+
? c.vals
|
|
1573
|
+
: typeof c.vals === 'string'
|
|
1574
|
+
? c.vals.split(',').map(function(it){
|
|
1575
|
+
return it.trim();
|
|
1576
|
+
}).filter(function(it){
|
|
1577
|
+
return it;
|
|
1578
|
+
})
|
|
1579
|
+
: [];
|
|
1580
|
+
return vals.some(function(it){
|
|
1581
|
+
return in$(it, v.list);
|
|
1582
|
+
});
|
|
1583
|
+
},
|
|
1584
|
+
config: function(valspec){
|
|
1585
|
+
var values;
|
|
1586
|
+
values = ((valspec != null ? valspec.values : void 8) || []).map(function(v){
|
|
1587
|
+
return {
|
|
1588
|
+
value: v.key || v.value || v,
|
|
1589
|
+
name: v.label || v.value || v.key || v
|
|
1590
|
+
};
|
|
1591
|
+
});
|
|
1592
|
+
return {
|
|
1593
|
+
vals: values.length
|
|
1594
|
+
? {
|
|
1595
|
+
type: 'choice',
|
|
1596
|
+
name: 'vals',
|
|
1597
|
+
values: values
|
|
1598
|
+
}
|
|
1599
|
+
: {
|
|
1600
|
+
type: 'text',
|
|
1601
|
+
name: 'vals',
|
|
1602
|
+
hint: "comma separated"
|
|
1603
|
+
}
|
|
1604
|
+
};
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1382
1608
|
}
|
|
1383
1609
|
];
|
|
1384
1610
|
form.opset['default'].map(function(it){
|
|
@@ -1395,6 +1621,9 @@
|
|
|
1395
1621
|
form.term = function(opt){
|
|
1396
1622
|
opt == null && (opt = {});
|
|
1397
1623
|
import$((this.enabled = true, this.opset = null, this.op = null, this.config = {}, this), opt);
|
|
1624
|
+
if (!this.id) {
|
|
1625
|
+
this.id = Math.random().toString(36).substring(2);
|
|
1626
|
+
}
|
|
1398
1627
|
this.setOpset(opt.opset, opt.op, opt.config);
|
|
1399
1628
|
return this;
|
|
1400
1629
|
};
|
|
@@ -1439,6 +1668,7 @@
|
|
|
1439
1668
|
},
|
|
1440
1669
|
serialize: function(){
|
|
1441
1670
|
return {
|
|
1671
|
+
id: this.id,
|
|
1442
1672
|
enabled: this.enabled,
|
|
1443
1673
|
opset: this.opset.id,
|
|
1444
1674
|
op: this.op.id,
|
|
@@ -1600,6 +1830,7 @@
|
|
|
1600
1830
|
init: o.init
|
|
1601
1831
|
});
|
|
1602
1832
|
}
|
|
1833
|
+
this.manager();
|
|
1603
1834
|
this._meta_dig = dig;
|
|
1604
1835
|
return Promise.resolve().then(function(){
|
|
1605
1836
|
if (!o.init) {
|
|
@@ -1669,13 +1900,13 @@
|
|
|
1669
1900
|
});
|
|
1670
1901
|
},
|
|
1671
1902
|
disabled: function(){
|
|
1672
|
-
return this._meta.disabled;
|
|
1903
|
+
return !!this._meta.disabled;
|
|
1673
1904
|
},
|
|
1674
1905
|
readonly: function(){
|
|
1675
|
-
return this._meta.readonly;
|
|
1906
|
+
return !!this._meta.readonly;
|
|
1676
1907
|
},
|
|
1677
1908
|
isRequired: function(){
|
|
1678
|
-
return this._meta.isRequired;
|
|
1909
|
+
return !!this._meta.isRequired;
|
|
1679
1910
|
},
|
|
1680
1911
|
isEmpty: function(v){
|
|
1681
1912
|
if (!arguments.length) {
|
|
@@ -1717,6 +1948,24 @@
|
|
|
1717
1948
|
return v;
|
|
1718
1949
|
}
|
|
1719
1950
|
},
|
|
1951
|
+
valdef: function(){
|
|
1952
|
+
if (this.mod && this.mod.valdef) {
|
|
1953
|
+
if (typeof this.mod.valdef === 'function') {
|
|
1954
|
+
return this.mod.valdef.call(this);
|
|
1955
|
+
}
|
|
1956
|
+
return this.mod.valdef;
|
|
1957
|
+
}
|
|
1958
|
+
return null;
|
|
1959
|
+
},
|
|
1960
|
+
valspec: function(){
|
|
1961
|
+
if (this.mod && this.mod.valspec) {
|
|
1962
|
+
if (typeof this.mod.valspec === 'function') {
|
|
1963
|
+
return this.mod.valspec.call(this);
|
|
1964
|
+
}
|
|
1965
|
+
return this.mod.valspec;
|
|
1966
|
+
}
|
|
1967
|
+
return null;
|
|
1968
|
+
},
|
|
1720
1969
|
validate: function(opt){
|
|
1721
1970
|
var v, this$ = this;
|
|
1722
1971
|
opt == null && (opt = {});
|
|
@@ -1805,11 +2054,17 @@
|
|
|
1805
2054
|
depth: depth
|
|
1806
2055
|
}])
|
|
1807
2056
|
: [];
|
|
1808
|
-
|
|
2057
|
+
ret = (Array.isArray(ret)
|
|
1809
2058
|
? ret
|
|
1810
2059
|
: [ret]).filter(function(it){
|
|
1811
2060
|
return it;
|
|
1812
2061
|
});
|
|
2062
|
+
if (this.disabled()) {
|
|
2063
|
+
ret.map(function(it){
|
|
2064
|
+
return it.disable();
|
|
2065
|
+
});
|
|
2066
|
+
}
|
|
2067
|
+
return ret;
|
|
1813
2068
|
},
|
|
1814
2069
|
ctrl: function(){
|
|
1815
2070
|
var args, res$, i$, to$;
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){var form,ref$,wordLen,countOps;form={};form.condctrl=function(opt){var ref$;opt==null&&(opt={});ref$=this._||(this._={});ref$.hash={};ref$.enabled={};ref$.manager=opt.manager;ref$.list=opt.conditions||[];ref$.applyBaseRule=opt.baseRule||function(){};return this};form.condctrl.prototype=(ref$=Object.create(Object.prototype),ref$.isEnabled=function(it){return this._.enabled[it]},ref$.get=function(it){return this._.hash[it]},ref$.fields=function(){return this._.manager._ws.w},ref$.subcond=function(arg$){var path,active,config,itf,ms;path=arg$.path,active=arg$.active,config=arg$.config;if(!((itf=this._.manager.widget(path))&&!itf.disabled()&&(ms=itf.manager({depth:1})||[]).length)){return}return ms.map(function(m){var cond;cond=m.condition();cond.apply(import$({active:active},config));return cond.run()})},ref$.reset=function(opt){var fields,i$,to$,i,cond,results$=[];opt==null&&(opt={});this._.list=opt.conditions||this._.list||[];fields=this.fields();for(i$=0,to$=this._.list.length;i$<to$;++i$){i=i$;cond=this._.list[i];cond.id=cond.id||i+1+"";this._.hash[cond.id]=cond;if(!Array.isArray(cond.config)){cond.config=[cond.config]}results$.push(cond.config.map(fn$))}return results$;function fn$(cfg){var k,v;cfg.src=cond.src;cfg.func=cond.func;return cfg.path=Array.from(new Set((cfg.prefix?cfg.prefix:[]).concat(cfg.path||[],function(){var ref$,results$=[];for(k in ref$=fields){v=ref$[k];results$.push({k:k,v:v})}return results$}().filter(function(arg$){var k,v,ref$;k=arg$.k,v=arg$.v;return(!cfg.prefix?0:cfg.prefix.filter(function(p){return k.startsWith(p)}).length)+((v!=null?(ref$=v.meta)!=null?ref$.tag:void 8:void 8)||[]).filter(function(t){return in$(t,cfg.tag||[])}).length>0}).map(function(it){return it.k}))))}},ref$.apply=function(opt){var path,active,enabled,isRequired,readonly,widget,curMeta,newMeta;opt==null&&(opt={});path=opt.path,active=opt.active,enabled=opt.enabled,isRequired=opt.isRequired,readonly=opt.readonly;if(Array.isArray(path)&&path[1]){return this.subcond({path:path[0],active:active,config:{path:path.slice(1),enabled:enabled,isRequired:isRequired,readonly:readonly}})}if(enabled!=null){this._.enabled[path]=!(!enabled!==!active&&(enabled||active))}if(widget=this._.manager.widget(path)){curMeta=widget.serialize();newMeta=JSON.parse(JSON.stringify(curMeta));if(enabled!=null){newMeta.disabled=!!(!enabled!==!active&&(enabled||active))}if(readonly!=null){newMeta.readonly=!(!readonly!==!active&&(readonly||active))}if(isRequired!=null){newMeta.isRequired=!(!isRequired!==!active&&(isRequired||active))}this._.applyBaseRule({path:path,widget:widget,meta:newMeta,opt:opt});if(!!curMeta.disabled===!!newMeta.disabled&&!!curMeta.isRequired===!!newMeta.isRequired&&!!curMeta.readonly===!!newMeta.readonly){return}return widget.deserialize(newMeta,{init:true})}},ref$._run=function(cfg,precond){var src,values,path,isRequired,enabled,readonly,func,result,i$,len$,p,active,ref$,itf,content;cfg==null&&(cfg={});src=cfg.src,values=cfg.values,path=cfg.path,isRequired=cfg.isRequired,enabled=cfg.enabled,readonly=cfg.readonly,func=cfg.func;if(func){result=true;for(i$=0,len$=path.length;i$<len$;++i$){p=path[i$];active=!!func.apply(this,[(ref$=import$({},cfg),ref$.path=p,ref$)])&&!(precond!=null&&!precond);result=result&&active;if(Array.isArray(p)&&p[1]){this.subcond({path:p[0],config:(ref$=import$({},cfg),ref$.path=p.slice(1),ref$),active:active});continue}this.apply({path:p[0],enabled:enabled,active:active,isRequired:isRequired,readonly:readonly})}}else{if(!(itf=this._.manager.widget(src))){console.error("[@plotdb/form] condctrl: run with nonexisted fields '"+src+"'");return}content=itf.content();content=Array.isArray(content)?content:[content];active=!!content.filter(function(c){if(Array.isArray(values)){return in$(c,values)}else{return c===values}}).length;if(precond!=null&&!precond){active=false}for(i$=0,len$=path.length;i$<len$;++i$){p=path[i$];if(Array.isArray(p)&&p[1]){this.subcond({path:p[0],config:(ref$=import$({},cfg),ref$.path=p.slice(1),ref$),active:active});continue}this.apply({path:p,enabled:enabled,active:active,isRequired:isRequired,readonly:readonly})}result=active}return result},ref$.run=function(){var result,_,this$=this;result={};_=function(list){var i$,to$,i,lresult$,cond,j$,ref$,len$,cfg,results$=[];for(i$=0,to$=list.length;i$<to$;++i$){i=i$;lresult$=[];cond=list[i];if(result[cond.id]!=null){continue}if(cond.precond&&this$._.hash[cond.precond]){_([this$._.hash[cond.precond]])}for(j$=0,len$=(ref$=cond.config).length;j$<len$;++j$){cfg=ref$[j$];lresult$.push(result[cond.id]=this$._run(cfg,result[cond.precond]))}results$.push(lresult$)}return results$};return _(this._.list||[])},ref$);form.manager=function(o){var this$=this;o==null&&(o={});this._ws={w:{},p:new WeakMap,s:{},l:{}};this._evthdr={};this._status=1;this._mode="edit";this._mod={};this._cond=new form.condctrl({manager:this});this._checkDebounced=debounce(10,function(){var args,res$,i$,to$;res$=[];for(i$=0,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}args=res$;return this$._check.apply(this$,args)});this._restatusDebounced=debounce(10,function(){var args,res$,i$,to$;res$=[];for(i$=0,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}args=res$;return this$._restatus.apply(this$,args)});return this};form.manager.prototype=import$(Object.create(Object.prototype),{on:function(n,cb){var this$=this;return(Array.isArray(n)?n:[n]).map(function(n){var ref$;return((ref$=this$._evthdr)[n]||(ref$[n]=[])).push(cb)})},condition:function(){return this._cond},fire:function(n){var v,res$,i$,to$,ref$,len$,cb,results$=[];res$=[];for(i$=1,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}v=res$;for(i$=0,len$=(ref$=this._evthdr[n]||[]).length;i$<len$;++i$){cb=ref$[i$];results$.push(cb.apply(this,v))}return results$},add:function(o){var ref$,w,p,this$=this;if(Array.isArray(o)){return o.map(function(it){return this$.add(it)})}ref$=[o.widget,o.path],w=ref$[0],p=ref$[1];if(this._ws.p.get(w)){return}this._ws.w[p]=w;this._ws.p.set(w,p);this._ws.l[p]={};this._ws.s[p]=w.status();w.mode(this._mode);w.on("meta",this._ws.l[p].m=function(v){return this$.fire("meta",{widget:w,path:p,meta:v})});w.on("change",this._ws.l[p].c=function(v){return this$.fire("change",{widget:w,path:p,value:v})});return w.on("status",this._ws.l[p].s=function(s){this$._ws.s[p]=s;if(this$._ws.w[p]._meta.disabled){return}this$.fire("status",{widget:w,path:p,status:s});return this$._restatusDebounced()})},remove:function(o){var ws,ref$,key$,ref1$,this$=this;if(Array.isArray(o)){return o.map(function(it){return this$.remove(it)})}if(!(ws=this._ws.w[o.path])){return}ws.off("meta",this._ws.l[o.path].m);ws.off("change",this._ws.l[o.path].c);ws.off("status",this._ws.l[o.path].s);this._ws.p["delete"](ws);delete this._ws.w[o.path];return ref1$=(ref$=this._ws.l)[key$=o.path],delete ref$[key$],ref1$},widget:function(p){return this._ws.w[p]},content:function(p){var that;if(that=this._ws.w[p]){return that.content()}else{return null}},status:function(){return this._status},progress:function(arg$){var _recurred,ref$,ret,list,k,s,this$=this;_recurred=(ref$=(arg$!=null?arg$:{})._recurred)!=null?ref$:false;ret={total:0,invalid:0,done:0};list=function(){var ref$,results$=[];for(k in ref$=this._ws.s){s=ref$[k];results$.push({k:k,s:s})}return results$}.call(this).filter(function(it){return this$._ws.w[it.k]&&this$._ws.w[it.k]._meta&&!this$._ws.w[it.k]._meta.disabled});list.forEach(function(o){var w,ms,e;w=this$._ws.w[o.k];if(!_recurred&&(ms=w.manager()).length){ms=ms.filter(function(m){var p;p=m.progress({_recurred:true});ret.total+=p.total;ret.invalid+=p.invalid;ret.done+=p.done;return!!p.invalid});if(ms.length){return}}ret.total+=1;e=w.errors();if(e.length===1&&e[0]==="nested"){return}if(o.s!=null&&o.s===2){ret.invalid+=1}if(o.s!=null&&o.s===0){return ret.done+=1}});ret.percent=ret.done/(ret.total||1);return ret},_restatus:function(){var os,ret,k,v,this$=this;os=this._status;delete this._status;ret=function(){var ref$,results$=[];for(k in ref$=this._ws.w){v=ref$[k];results$.push({k:k,v:v})}return results$}.call(this).filter(function(arg$){var k,v;k=arg$.k,v=arg$.v;return!v._meta.disabled}).map(function(arg$){var k,v,s;k=arg$.k,v=arg$.v;s=this$._ws.s[k];if(s==null){return true}if(s===0){return false}if(s===1&&!v._meta.isRequired){return false}return true}).filter(function(it){return it}).length;this._status=ret?1:0;if(os!==this._status){return this.fire("readystatechange",this._status===0)}},check:function(o,opt){var this$=this;if(typeof opt!=="object"){opt={now:opt}}return Promise.resolve().then(function(){var p,w;if(!o){return this$.check(function(){var ref$,results$=[];for(p in ref$=this._ws.w){w=ref$[p];results$.push({widget:w,path:p})}return results$}.call(this$).filter(function(arg$){var widget;widget=arg$.widget;if(widget._meta.disabled){return false}return!opt.skipEmpty?true:!widget.isEmpty()||widget.status()===2}),opt)}this$.checkList=(this$.checkList||(this$.checkList=[])).concat(Array.isArray(o)?o:[o]);return opt.now?this$._check(null,opt):this$._checkDebounced(null,opt)}).then(function(it){this$._restatus();return it})},_check:function(o,opt){var list,this$=this;opt==null&&(opt={});if(!o){list=this.checkList||[];this.checkList=[];return this._check(list,opt)}if(Array.isArray(o)){return Promise.all(o.map(function(it){return this$._check(it,opt)})).then(function(it){return it.filter(function(it){return it})})}return new Promise(function(res,rej){var ref$,w,p,_now;ref$=[o.widget,o.path,o.now],w=ref$[0],p=ref$[1],_now=ref$[2];if(!(w&&p)){return res()}if(!w&&!(w=this$._ws.w[p])){return res()}if(!p){p=this$._ws.p[w]}return w.validate({force:opt.force,init:opt.init,skipEmpty:opt.skipEmpty}).then(function(){var os;os=this$._ws.s[p];this$._ws.s[p]=w.status();if(os!==this$._ws.s[p]){this$.fire("status",{path:p,widget:w,status:this$._ws.s[p]})}return this$._ws.s[p]}).then(function(){if(this$._ws.s[p]===2){return res({widget:w,path:p,status:this$._ws.s[p]})}else{return res()}})})},formData:function(){var fd,p,ref$,w,val,i$,to$,i;fd=new FormData;for(p in ref$=this._ws.w){w=ref$[p];if(w._meta.disabled){continue}val=w.value();if(Array.isArray(v)){for(i$=0,to$=v.length;i$<to$;++i$){i=i$;fd.append(p+"[]",v[i])}}else{fd.append(p,val)}}return fd},value:function(v,opt){var ret,p,ref$,w,ps,res$,e;opt==null&&(opt={});if(!arguments.length){ret={};for(p in ref$=this._ws.w){w=ref$[p];if(!(opt.partial&&w._meta.disabled)){ret[p]=w.value()}}return ret}v=v!=null?JSON.parse(JSON.stringify(v)):{};try{res$=[];for(p in ref$=this._ws.w){w=ref$[p];if(!v.hasOwnProperty(p)&&opt.partial){continue}res$.push(w.value(v[p],opt))}ps=res$;return Promise.all(ps)}catch(e$){e=e$;return Promise.reject(e)}},mode:function(m){var this$=this;if(!(m!=null)){return this._mode}return Promise.resolve().then(function(){var ref$,p,w;if(!(m==="edit"||m==="view"||m==="config")){return Promise.reject((ref$=new Error,ref$.name="lderror",ref$.id=1015,ref$))}if(this$._mode===m){return}this$._mode=m;this$.fire("mode",m);return Promise.all(function(){var ref$,results$=[];for(p in ref$=this._ws.w){w=ref$[p];results$.push(w)}return results$}.call(this$).map(function(w){return w.mode(m)}))})},order:function(){var nodeIdx,_,obj;nodeIdx=function(r,n,opt){var i$,to$,i,v;opt.idx++;if(r===n){return true}if(!(r&&r.childNodes)){return}for(i$=0,to$=r.childNodes.length;i$<to$;++i$){i=i$;v=nodeIdx(r.childNodes[i],n,opt);if(v){return true}}};_=function(m,obj){var ws,k,v,ms,child,opt,results$=[];ws=m._ws.w;for(k in ws){v=ws[k];ms=v.manager()||[];if(ms.length){child={};ms.map(fn$)}opt={idx:0};nodeIdx(document.body,v._root,opt);results$.push(obj[k]={title:v._meta.title,idx:opt.idx,child:child,meta:v.serialize()})}return results$;function fn$(m){return _(m,child)}};_(this,obj={});return obj},manager:function(opt){var ret,k,ref$,s,w,mgrs;ret=[];for(k in ref$=this._ws.s){s=ref$[k];if(!(this._ws.w[it.k]&&this._ws.w[it.k]._meta&&!this._ws.w[it.k]._meta.disabled)){continue}if(!(w=this.widget(k))){continue}if(!(mgrs=w.manager(opt)||[]).length){continue}ret=ret.concat(mgrs)}return ret}});form.op=function(opt){opt==null&&(opt={});this.id=opt.id;this.name=opt.name;this.config=opt.config;this.func=opt.func;this.opset=opt.opset;return this};form.op.prototype=import$(Object.create(Object.prototype),{validate:function(val,cfg){var ret;cfg==null&&(cfg={});if(this.opset.convert){val=this.opset.convert(val)}if((ret=this.func(val,cfg))instanceof Promise){return ret}else{return Promise.resolve(!!ret)}},configDefault:function(){var cfg,k,ref$,v;cfg={};for(k in ref$=this.config){v=ref$[k];cfg[k]=v["default"]}return cfg}});form.opset=function(opt){var ops,k,v,this$=this;opt==null&&(opt={});this.name=opt.name;this.id=opt.id;this.i18n=opt.i18n;this.convert=opt.convert;this.ops={};ops=Array.isArray(opt.ops)?opt.ops.map(function(it){return{v:it,k:it.id}}):function(){var ref$,results$=[];for(k in ref$=opt.ops){v=ref$[k];results$.push({k:k,v:v})}return results$}();ops.map(function(arg$){var k,v,ref$,ref1$,results$=[];k=arg$.k,v=arg$.v;this$.ops[k]=v instanceof form.op?v:k?new form.op((ref$=typeof v==="function"?{func:v}:v,ref$.id=k,ref$.opset=this$,ref$)):function(){throw new Error("[@plotdb/form/opset] invalid op when initializing opset.")}();for(k in ref$=opt.ops){v=ref$[k];results$.push(this$.ops[k]=new form.op((ref1$=typeof v==="function"?{func:v}:v,ref1$.name=k,ref1$.id=k,ref1$.opset=this$,ref1$)))}return results$});this.defaultOp=this.ops[opt.defaultOp]?opt.defaultOp:function(){var ref$,results$=[];for(k in ref$=this.ops){v=ref$[k];results$.push(k)}return results$}.call(this)[0];return this};form.opset.prototype=import$(Object.create(Object.prototype),{getOp:function(id){return this.ops[id||this.defaultOp]},getOps:function(){var k,ref$,v,results$=[];for(k in ref$=this.ops){v=ref$[k];results$.push(v)}return results$}});form.opset.register=function(it){return(this._list||(this._list=[])).push(it instanceof form.opset?it:new form.opset(it))};form.opset.get=function(id){return(this._list||(this._list=[])).filter(function(it){return(it.id||it.name)===id})[0]};form.opset.list=function(){return(this._list||[]).map(function(it){return it})};wordLen=function(v,method){v==null&&(v="");return method==="simple-word"?v.split(/\s|[,.;:!?,。;:︰!?、. "]/).filter(function(it){return it}).map(function(it){return it.split(/[\u1000-\uffff]/).map(function(it){if(it.length){return 2}else{return 1}}).reduce(function(a,b){return a+b},0)-1}).reduce(function(a,b){return a+b},0):v.length};countOps={"count-max":{func:function(v,c){c==null&&(c={});return v.length<=c.val},config:{val:{type:"number",name:"count-max",hint:"maximal amount"}}},"count-min":{func:function(v,c){c==null&&(c={});return v.length>=c.val},config:{val:{type:"number",name:"count-min",hint:"minimal amount"}}},"count-range":{func:function(v,c){c==null&&(c={});return v.length>=c.min&&v.length<=c.max},config:{min:{type:"number",name:"count-min",hint:"minimal amount"},max:{type:"number",name:"count-max",hint:"maximal amount"}}},count:{func:function(v,c){c==null&&(c={});return v.length===c.val},config:{val:{type:"number",name:"count",hint:"number of entries"}}}};form.opset["default"]=[{id:"list",i18n:{"zh-TW":{list:"列表","count-max":"數量上限","count-min":"數量下限","count-range":"數量範圍",count:"數量要求"},en:{list:"List","count-max":"Maximal Count","count-min":"Minimal Count","count-range":"Count Range",count:"Required Count"}},convert:function(v){var ret;ret=Array.isArray(v)?v:v&&Array.isArray(v.list)?v.list.concat(v.other&&v.other.enabled?[v.other.text]:[]):[v];return ret.filter(function(it){return it})},ops:import$({},countOps)},{id:"file",i18n:{"zh-TW":{file:"檔案","size-limit":"檔案大小上限","count-limit":"檔案數量上限",extension:"副檔名限制","count-max":"檔案數量上限","count-min":"檔案數量下限","count-range":"檔案數量範圍"},en:{file:"File","size-limit":"Maximal File Size","count-limit":"Max File Count",extension:"File Extension","count-max":"Max File Count","count-min":"Min File Count","count-range":"File Count Range"}},convert:function(v){return(Array.isArray(v)?v:[v]).filter(function(it){return it})},ops:import$({"size-limit":{func:function(v,c){c==null&&(c={});return!v.filter(function(it){return it.size>c.val}).length},config:{val:{type:"number",name:"size-limit",hint:"maximal size"}}},extension:{func:function(v,c){var exts;c==null&&(c={});exts=(c.str.split(",")||[]).map(function(it){return(it||"").trim().toLowerCase()}).filter(function(it){return it});return!v.filter(function(it){var ext,ref$;return!in$(((ext=(ref$=(it.filename||"").split("."))[ref$.length-1])||"").trim().toLowerCase(),exts)}).length},config:{str:{type:"text",name:"extension",hint:"extension, comma separated, without dot"}}},"count-limit":{func:function(v,c){c==null&&(c={});return v.length<c.val},config:{val:{type:"number",name:"count-limit",hint:"maximal file amount"}}}},countOps)},{id:"image",i18n:{"zh-TW":{image:"圖像","long-side":"長邊尺寸限制","short-side":"短邊尺寸限制",width:"寬度限制",height:"高度限制","pixel-count":"像素量限制","min-size":"最小尺寸","max-size":"最大尺寸"},en:{image:"Image","long-side":"Long Side","short-side":"Short Side",width:"Width",height:"Height","pixel-count":"Max Pixel Count","min-size":"Min Size","max-size":"Max Size"}},convert:function(v){return(Array.isArray(v)?v:[v]).filter(function(it){return it})},ops:Object.fromEntries([["long-side","long"],["short-side","short"],["width","width"],["height","height"],["pixel-count","pixels"]].map(function(n){return[n[0],function(k){return{func:function(v,c){v==null&&(v=[]);c==null&&(c={});return!v.filter(function(it){return!((c.min==null||it[k]>=(c.min||0))&&(c.max==null||it[k]<=c.max))}).length},config:{min:{type:"number",name:"min-size",hint:"minimal size"},max:{type:"number",name:"max-size",hint:"minimal size"}}}}(n[1])]}))},{id:"string",i18n:{"zh-TW":{string:"文字",include:"包含",exclude:"排除",email:"電子郵件",url:"網址",regex:"正規表達式"},en:{string:"Text",include:"Include",exclude:"Exclude",email:"Email",url:"URL",regex:"Regular Expression"}},ops:{include:{func:function(v,c){c==null&&(c={});return~(""+(v||"")).indexOf(c.str||"")},config:{str:{type:"text",name:"include"}}},exclude:{func:function(v,c){c==null&&(c={});return!~(""+(v||"")).indexOf(c.str||"")},config:{str:{type:"text",name:"exclude"}}},email:{func:function(v){return/^[^@]+@[^@]+$/.exec(v)},config:{}},url:{func:function(v){return/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,15}\b([-a-zA-Z0-9@:%_\+.~#()?&//=]*)$/.exec(v)},config:{}},regex:{func:function(v,c){c==null&&(c={});if(!c.rule){return true}if(typeof c.rule==="object"&&c.rule.exec){return c.rule.exec(v)}return new RegExp(c.rule).exec(v)},config:{rule:{type:"text",name:"regex"}}}}},{id:"length",i18n:{"zh-TW":{length:"長度",lte:"≦ 小於或等於",range:"範圍",number:"數字","minimal length":"長度下限","maximal length":"長度上限"},en:{length:"Length",lte:"≦",range:"Range",number:"Number","minimal length":"Min Length","maximal length":"Max Length"}},ops:{range:{func:function(v,c){var len;c==null&&(c={});len=wordLen(v+"",c.method);return len>=+c.min&&len<=+c.max},config:{min:{type:"number",name:"minimal length"},max:{type:"number",name:"maximal length"},method:{type:"choice",default:"char",values:["char","simple-word"]}}},lte:{func:function(v,c){c==null&&(c={});return wordLen(v+"",c.method)<=+c.val},config:{val:{type:"number",name:"maximal length"},method:{type:"choice",default:"char",values:["char","simple-word"]}}},gte:{func:function(v,c){c==null&&(c={});return wordLen(v+"",c.method)>=+c.val},config:{val:{type:"number",name:"minimal length"},method:{type:"choice",default:"char",values:["char","simple-word"]}}},eq:{func:function(v,c){c==null&&(c={});return wordLen(v+"",c.method)===+c.val},config:{val:{type:"number",name:"length"},method:{type:"choice",default:"char",values:["char","simple-word"]}}}}},{id:"number",i18n:{"zh-TW":{number:"數字",lte:"≦ 小於或等於",gte:"≧ 大於或等於",ne:"≠ 不等於",eq:"= 等於",is:"任何數字","ref-val":"參考值"},en:{number:"Number",lte:"≦ Equal/Less Than",gte:"≧ Equal/Greater Than",ne:"≠ Not Equals",eq:"= Equals",is:"Is Number","ref-val":"Reference Value"}},convert:function(v){return+(v+"").replace(/,/g,"")},ops:{lte:{func:function(v,c){c==null&&(c={});if(isNaN(v)||isNaN(c.val)){return false}else{return+v<=+c.val}},config:{val:{type:"text",name:"ref-val"}}},gte:{func:function(v,c){c==null&&(c={});if(isNaN(v)||isNaN(c.val)){return false}else{return+v>=+c.val}},config:{val:{type:"text",name:"ref-val"}}},ne:{func:function(v,c){c==null&&(c={});if(isNaN(v)||isNaN(c.val)){return false}else{return+v!==+c.val}},config:{val:{type:"text",name:"ref-val"}}},eq:{func:function(v,c){c==null&&(c={});if(isNaN(v)||isNaN(c.val)){return false}else{return+v===+c.val}},config:{val:{type:"text",name:"ref-val"}}},is:{func:function(v){return!isNaN(v)},config:{}}}},{id:"date",i18n:{"zh-TW":{date:"日期","min age":"最小年齡","max age":"最大年齡",age:"年齡"},en:{date:"Date","min age":"Min Age","max age":"Max Age",age:"Age"}},convert:function(v){return new Date(v)},ops:{age:{config:{min:{type:"number",name:"min age"},max:{type:"number",name:"max age"}},func:function(v,c){var dmin,dmax,dnow;c==null&&(c={});dmin=new Date(v.getYear()+1900+(c.min||0),v.getMonth(),v.getDate()).getTime();dmax=new Date(v.getYear()+1900+(c.max||0),v.getMonth(),v.getDate()).getTime();dnow=Date.now();if(c.min!=null&&dmin>dnow){return false}if(c.max!=null&&dmax<dnow){return false}return true}}}}];form.opset["default"].map(function(it){return form.opset.register(it)});form.term=function(opt){opt==null&&(opt={});import$((this.enabled=true,this.opset=null,this.op=null,this.config={},this),opt);this.setOpset(opt.opset,opt.op,opt.config);return this};form.term.prototype=import$(Object.create(Object.prototype),{toggle:function(it){return this.enabled=it!=null?it:!this.enabled},setOpset:function(opset,op,cfg){if(typeof opset==="string"){if(!(this.opset=form.opset.get(opset))){throw new Error("no such opset '"+opset+"'")}}else if(opset instanceof form.opset){this.opset=opset}else{throw new Error("invalid opset")}return this.setOp(op,cfg)},setOp:function(id,cfg){if(!this.opset){throw new Error("opset not set")}if(!(this.op=this.opset.getOp(id))){throw new Error("no such op '"+id+"'")}return this.setConfig(cfg)},setConfig:function(cfg){if(!this.op){throw new Error("op not set")}return this.config=!cfg?this.op.configDefault():cfg},validate:function(v){if(!this.op){Promis.reject(new Error("op not set"))}return this.op.validate(v,this.config)},serialize:function(){return{enabled:this.enabled,opset:this.opset.id,op:this.op.id,config:this.config,msg:this.msg}},deserialize:function(v){this.toggle(v.enabled);return this.setOpset(v.opset,v.op,v.config)}});form.widget=function(opt){var o,this$=this;opt==null&&(opt={});this._root=typeof opt.root==="string"?document.querySelector(opt.root):opt.root;this.evtHandler={};this.mod=opt.mod||null;this.i18n={};this._custom={};this._status=1;this._meta={config:{},key:Math.random().toString(36).substring(2)};this._meta_dig="";this._value=undefined;this._empty=true;this._mode=opt.mode||"edit";this._validate=opt.validate||null;this._opsets=(opt.opsets||[]).concat((opt.mod||{}).opsets||[]).map(function(opset){if(typeof opset==="string"){return form.opset.get(opset)}else if(opset instanceof form.opset){return opset}else{return new form.opset(opset)}});this._opsets.filter(function(it){return it.i18n}).map(function(it){var k,ref$,v,ref1$,results$=[];for(k in ref$=it.i18n){v=ref$[k];results$.push(import$((ref1$=this$.i18n)[k]||(ref1$[k]={}),v))}return results$});this._opsets=Object.fromEntries(function(){var i$,ref$,len$,results$=[];for(i$=0,len$=(ref$=this._opsets).length;i$<len$;++i$){o=ref$[i$];results$.push([o.id||o.name||"",o])}return results$}.call(this));this._errors=[];this.init=proxise.once(function(){return this$._init()});return this};form.widget.prototype=import$(Object.create(Object.prototype),{on:function(n,cb){var this$=this;return(Array.isArray(n)?n:[n]).map(function(n){var ref$;return((ref$=this$.evtHandler)[n]||(ref$[n]=[])).push(cb)})},off:function(n,cb){var this$=this;return(Array.isArray(n)?n:[n]).map(function(n){var l,ref$;l=(ref$=this$.evtHandler)[n]||(ref$[n]=[]);if(l.indexOf(cb)>=0){return l.splice(l.indexOf(cb),1)}})},fire:function(n){var v,res$,i$,to$,ref$,len$,cb,results$=[];res$=[];for(i$=1,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}v=res$;for(i$=0,len$=(ref$=this.evtHandler[n]||[]).length;i$<len$;++i$){cb=ref$[i$];results$.push(cb.apply(this,v))}return results$},root:function(){return this._root},_init:function(){var this$=this;return Promise.resolve(this.mod&&this.mod.init?this.mod.init.apply(this):"").then(function(){return this$.fire("init")})},key:function(keyonly){keyonly==null&&(keyonly=false);return keyonly?this._meta.key:this._meta.alias||this._meta.key},status:function(v){var ov;if(!(v!=null)){return this._status}ov=this._status;this._status=v;if(ov!==v){return this.fire("status",v)}},serialize:function(){var ref$,ret,ref1$;ret=(ref1$={},ref1$.key=(ref$=this._meta).key,ref1$.title=ref$.title,ref1$.desc=ref$.desc,ref1$.isRequired=ref$.isRequired,ref1$.disabled=ref$.disabled,ref1$.readonly=ref$.readonly,ref1$.defaultValue=ref$.defaultValue,ref1$);ret.config=JSON.parse(JSON.stringify(this._meta.config||{}));ret.term=(this._meta.term||[]).map(function(it){return it.serialize()});return ret},deserialize:function(v,o){var ref$,dig,this$=this;o==null&&(o={});ref$=this._meta;ref$.key=v.key;ref$.title=v.title;ref$.desc=v.desc;ref$.isRequired=v.isRequired;ref$.disabled=v.disabled;ref$.readonly=v.readonly;ref$.defaultValue=v.defaultValue;this._meta.config=JSON.parse(JSON.stringify(v.config||{}));this._meta.term=(v.term||[]).map(function(t){var that;return new form.term(import$(import$({},t),(that=this$._opsets[t.opset||""])?{opset:that}:{}))});dig=JSON.stringify(v);if(this._meta_dig!==dig){this.fire("meta",this.serialize(),{init:o.init})}this._meta_dig=dig;return Promise.resolve().then(function(){if(!o.init){return}if(!(this$._meta.defaultValue!=null&&this$.isEmpty())){return}return this$.value(this$._meta.defaultValue,{init:true,fromSource:true})}).then(function(){return this$.validate({init:o.init})}).then(function(){return this$.render()})},mode:function(m){var this$=this;if(!(m!=null)){return this._mode}return Promise.resolve().then(function(){var ref$;if(!(m==="edit"||m==="view"||m==="config")){return Promise.reject((ref$=new Error,ref$.name="lderror",ref$.id=1015,ref$))}if(this$._mode===m){return}this$._mode=m;this$.fire("mode",m);return this$.validate({init:true}).then(function(){return this$.render()})})},errors:function(){return this._errors},value:function(v,opt){var _v,this$=this;opt==null&&(opt={});if(arguments.length===0){return this._value!=null?JSON.parse(JSON.stringify(this._value)):this._value}if(this.isEqual(v,this._value)){return Promise.resolve()}_v=v!=null?JSON.parse(JSON.stringify(v)):v;this._value=_v;this._empty=this.isEmpty(_v);return this.validate({init:opt.init}).then(function(){if(opt.fromSource){return}return this$.fire("change",this$._value!=null?JSON.parse(JSON.stringify(this$._value)):undefined)})},disabled:function(){return this._meta.disabled},readonly:function(){return this._meta.readonly},isRequired:function(){return this._meta.isRequired},isEmpty:function(v){if(!arguments.length){v=this._value}if(this.mod&&this.mod.isEmpty){return this.mod.isEmpty.call(this,v)}else{return v===null||typeof v==="undefined"||v===""}},isEqual:function(u,v){var eu,ev;if(arguments.length===1){v=this._value}if(this.mod&&this.mod.isEqual){return this.mod.isEqual.call(this,u,v)}eu=this.isEmpty(u);ev=this.isEmpty(v);if(!eu!==!ev&&(eu||ev)){return false}if(eu&&ev){return true}return JSON.stringify(u)===JSON.stringify(v)},content:function(v){if(!arguments.length){v=this._value}if(this.mod&&this.mod.content){return this.mod.content.call(this,v)}else if(typeof v==="object"&&v&&v.hasOwnProperty(v)){return v.v}else{return v}},validate:function(opt){var v,this$=this;opt==null&&(opt={});v=this.content();return Promise.resolve().then(function(){if(this$.mod&&this$.mod.validate){return this$.mod.validate.call(this$,opt)}if(this$._validate){return this$._validate(v)}}).then(function(ret){ret==null&&(ret=[]);if(ret.status===3){this$._errors=ret.errors||[];this$.status(3);this$.render();return this$._errors}if(ret&&ret.length){this$._errors=ret;this$.status(opt.init?1:2);this$.render();return this$._errors}if(this$._empty){if(this$._meta.isRequired){this$._errors=["required"];this$.status(opt.init?1:2);this$.render();return this$._errors}else{this$.status(0);this$.render();return this$._errors=[]}}return Promise.all(this$._meta.term.filter(function(t){return t.enabled}).map(function(t){return t.validate(v).then(function(v){return[t,v]})})).then(function(it){var nv;nv=this$.content();if(!this$.isEqual(nv,v)){return}this$._errors=it.filter(function(it){return!it[1]}).map(function(it){return it[0].msg||"error"});this$.status(this$._errors.length?2:0);return this$.render()}).then(function(){return this$._errors})})},render:function(){this.fire("render");if(this.mod&&this.mod.render){return this.mod.render.apply(this)}},adapt:function(){var args,res$,i$,to$;res$=[];for(i$=0,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}args=res$;if(this.mod&&this.mod.adapt){return this.mod.adapt.apply(this,args)}},manager:function(arg$){var depth,ref$,ret;depth=(ref$=(arg$!=null?arg$:{}).depth)!=null?ref$:0;ret=this.mod&&this.mod.manager?this.mod.manager.apply(this,[{depth:depth}]):[];return(Array.isArray(ret)?ret:[ret]).filter(function(it){return it})},ctrl:function(){var args,res$,i$,to$;res$=[];for(i$=0,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}args=res$;if(this.mod&&this.mod.ctrl){return this.mod.ctrl.apply(this,args)}}});if(typeof module!="undefined"&&module!==null){module.exports=form}else if(typeof window!="undefined"&&window!==null){window.form=form}function import$(obj,src){var own={}.hasOwnProperty;for(var key in src)if(own.call(src,key))obj[key]=src[key];return obj}function in$(x,xs){var i=-1,l=xs.length>>>0;while(++i<l)if(x===xs[i])return true;return false}}).call(this);
|
|
1
|
+
(function(){var form,ref$,wordLen,countOps;form={};form.condctrl=function(opt){var ref$,this$=this;opt==null&&(opt={});ref$=this._||(this._={});ref$.hash={};ref$.enabled={};ref$.manager=opt.manager;ref$.list=opt.conditions||[];ref$.autorun=false;ref$.applyBaseRule=opt.baseRule||function(){};this._.manager.on("change",function(){if(this$._.autorun){return this$.run()}});return this};form.condctrl.prototype=(ref$=Object.create(Object.prototype),ref$.isEnabled=function(it){return this._.enabled[it]},ref$.get=function(it){return this._.hash[it]},ref$.reset=function(opt){var fields,ref$,i$,to$,i,cond,results$=[];opt==null&&(opt={});this._.autorun=opt.autorun!=null&&!opt.autorun?false:true;this._.list=opt.conditions||this._.list||[];fields=this._.manager.widgets();ref$=this._||(this._={});ref$.hash={};ref$.enabled={};for(i$=0,to$=this._.list.length;i$<to$;++i$){i=i$;cond=this._.list[i];cond.id=cond.id||"_"+(i+1);this._.hash[cond.id]=cond;if(!Array.isArray(cond.config)){cond.config=[cond.config]}cond.config=cond.config.map(fn$);results$.push(cond.config.forEach(fn1$))}return results$;function fn$(it){var ref$;return ref$=import$({},JSON.parse(JSON.stringify(it))),ref$.src=cond.src,ref$.func=cond.func,ref$}function fn1$(cfg){var k,v;if(!cfg.path&&cfg.targets){cfg.path=cfg.targets}if(!cfg.value&&cfg.values){cfg.value=cfg.values}if(!cfg.tag&&cfg.tags){cfg.tag=cfg.tags}return cfg.path=Array.from(new Set((cfg.prefix?cfg.prefix:[]).concat(cfg.path||[],function(){var ref$,results$=[];for(k in ref$=fields){v=ref$[k];results$.push({k:k,v:v})}return results$}().filter(function(arg$){var k,v,ref$;k=arg$.k,v=arg$.v;return(!cfg.prefix?0:cfg.prefix.filter(function(p){return k.startsWith(p)}).length)+((v!=null?(ref$=v.meta)!=null?ref$.tag:void 8:void 8)||[]).filter(function(t){return in$(t,cfg.tag||[])}).length>0}).map(function(it){return it.k}))))}},ref$.subcond=function(arg$){var path,active,config,itf,ms;path=arg$.path,active=arg$.active,config=arg$.config;if(!((itf=this._.manager.widget(path))&&!itf.disabled()&&(ms=itf.manager({depth:1})||[]).length)){return}return ms.forEach(function(m){var cond;cond=m.condition();cond.apply(import$({active:active},config));return cond.run()})},ref$.apply=function(opt){var path,active,enabled,isRequired,readonly,widget,curMeta,newMeta;opt==null&&(opt={});path=opt.path,active=opt.active,enabled=opt.enabled,isRequired=opt.isRequired,readonly=opt.readonly;if(Array.isArray(path)){if(path[1]){return this.subcond({path:path[0],active:active,config:{path:path.slice(1),enabled:enabled,isRequired:isRequired,readonly:readonly}})}path=path[0]}if(enabled!=null){this._.enabled[path]=!(!enabled!==!active&&(enabled||active))}if(widget=this._.manager.widget(path)){curMeta=widget.serialize();newMeta=JSON.parse(JSON.stringify(curMeta));if(enabled!=null){newMeta.disabled=!!(!enabled!==!active&&(enabled||active))}if(readonly!=null){newMeta.readonly=!(!readonly!==!active&&(readonly||active))}if(isRequired!=null){newMeta.isRequired=!(!isRequired!==!active&&(isRequired||active))}this._.applyBaseRule({path:path,widget:widget,meta:newMeta,opt:opt});if(!!curMeta.disabled===!!newMeta.disabled&&!!curMeta.isRequired===!!newMeta.isRequired&&!!curMeta.readonly===!!newMeta.readonly){return}return widget.deserialize(newMeta,{init:true})}},ref$._run=function(cfg,precond){var src,values,paths,isRequired,enabled,readonly,func,result,i$,len$,path,active,ref$,itf,content;cfg==null&&(cfg={});src=cfg.src,values=cfg.value,paths=cfg.path,isRequired=cfg.isRequired,enabled=cfg.enabled,readonly=cfg.readonly,func=cfg.func;if(func){result=true;for(i$=0,len$=paths.length;i$<len$;++i$){path=paths[i$];active=!!func.apply(this,[(ref$=import$({},cfg),ref$.path=path,ref$)])&&!(precond!=null&&!precond);result=result&&active;if(Array.isArray(path)&&path[1]){this.subcond({path:path[0],config:(ref$=import$({},cfg),ref$.path=path.slice(1),ref$),active:active});continue}this.apply({path:path,enabled:enabled,active:active,isRequired:isRequired,readonly:readonly})}}else{values=Array.isArray(values)?values:[values];if(!(itf=this._.manager.widget(src))){return console.error("[@plotdb/form] condctrl: field '"+src+"' not found")}content=itf.content();content=Array.isArray(content)?content:[content];active=!!content.filter(function(it){return in$(it,values)}).length;if(precond!=null&&!precond){active=false}for(i$=0,len$=paths.length;i$<len$;++i$){path=paths[i$];if(Array.isArray(path)&&path[1]){this.subcond({path:path[0],config:(ref$=import$({},cfg),ref$.path=path.slice(1),ref$),active:active});continue}this.apply({path:path,enabled:enabled,active:active,isRequired:isRequired,readonly:readonly})}result=active}return result},ref$.run=function(){var result,_,this$=this;result={};_=function(list,ref){var i$,to$,i,lresult$,cond,j$,ref$,len$,cfg,r,results$=[];ref==null&&(ref=[]);for(i$=0,to$=list.length;i$<to$;++i$){i=i$;lresult$=[];cond=list[i];if(result[cond.id]!=null){continue}if(cond.precond&&this$._.hash[cond.precond]){if(in$(cond.id,ref)){console.error("[@plotdb/form] condctrl: circular ref id "+cond.id)}else{_([this$._.hash[cond.precond]],ref.concat([cond.id]))}}for(j$=0,len$=(ref$=cond.config).length;j$<len$;++j$){cfg=ref$[j$];r=this$._run(cfg,result[cond.precond]);lresult$.push(result[cond.id]=result[cond.id]!=null?result[cond.id]&&r:r)}results$.push(lresult$)}return results$};return _(this._.list||[])},ref$);form.manager=function(o){var this$=this;o==null&&(o={});this._ws={w:{},p:new WeakMap,s:{},l:{}};this._disabled=false;this._evthdr={};this._status=1;this._mode="edit";this._mod={};this._cond=new form.condctrl({manager:this});this._checkDebounced=debounce(10,function(){var args,res$,i$,to$;res$=[];for(i$=0,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}args=res$;return this$._check.apply(this$,args)});this._restatusDebounced=debounce(10,function(){var args,res$,i$,to$;res$=[];for(i$=0,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}args=res$;return this$._restatus.apply(this$,args)});return this};form.manager.prototype=import$(Object.create(Object.prototype),{on:function(n,cb){var this$=this;return(Array.isArray(n)?n:[n]).map(function(n){var ref$;return((ref$=this$._evthdr)[n]||(ref$[n]=[])).push(cb)})},condition:function(){return this._cond},disabled:function(){return!!this._disabled},disable:function(it){return this._disabled=it!=null?!!it:true},fire:function(n){var v,res$,i$,to$,ref$,len$,cb,results$=[];res$=[];for(i$=1,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}v=res$;for(i$=0,len$=(ref$=this._evthdr[n]||[]).length;i$<len$;++i$){cb=ref$[i$];results$.push(cb.apply(this,v))}return results$},add:function(o){var ref$,w,p,this$=this;if(Array.isArray(o)){return o.map(function(it){return this$.add(it)})}ref$=[o.widget,o.path],w=ref$[0],p=ref$[1];if(this._ws.p.get(w)){return}this._ws.w[p]=w;this._ws.p.set(w,p);this._ws.l[p]={};this._ws.s[p]=w.status();w.mode(this._mode);w.on("meta",this._ws.l[p].m=function(v){return this$.fire("meta",{widget:w,path:p,meta:v})});w.on("change",this._ws.l[p].c=function(v){return this$.fire("change",{widget:w,path:p,value:v})});return w.on("status",this._ws.l[p].s=function(s){this$._ws.s[p]=s;if(this$._ws.w[p]._meta.disabled){return}this$.fire("status",{widget:w,path:p,status:s});return this$._restatusDebounced()})},remove:function(o){var ws,ref$,key$,ref1$,this$=this;if(Array.isArray(o)){return o.map(function(it){return this$.remove(it)})}if(!(ws=this._ws.w[o.path])){return}ws.off("meta",this._ws.l[o.path].m);ws.off("change",this._ws.l[o.path].c);ws.off("status",this._ws.l[o.path].s);this._ws.p["delete"](ws);delete this._ws.w[o.path];return ref1$=(ref$=this._ws.l)[key$=o.path],delete ref$[key$],ref1$},widgets:function(){return import$({},this._ws.w||{})},widget:function(p){return this._ws.w[p]},content:function(p){var that;if(that=this._ws.w[p]){return that.content()}else{return null}},status:function(){return this._status},progress:function(arg$){var _recurred,ref$,ret,list,k,s,this$=this;_recurred=(ref$=(arg$!=null?arg$:{})._recurred)!=null?ref$:false;ret={total:0,invalid:0,done:0};list=function(){var ref$,results$=[];for(k in ref$=this._ws.s){s=ref$[k];results$.push({k:k,s:s})}return results$}.call(this).filter(function(it){return this$._ws.w[it.k]&&this$._ws.w[it.k]._meta&&!this$._ws.w[it.k]._meta.disabled});list.forEach(function(o){var w,ms,e;w=this$._ws.w[o.k];if(!_recurred&&(ms=w.manager()).length){ms=ms.filter(function(it){return!it.disabled()}).filter(function(m){var p;p=m.progress({_recurred:true});ret.total+=p.total;ret.invalid+=p.invalid;ret.done+=p.done;return!!p.invalid});if(ms.length){return}}ret.total+=1;e=w.errors();if(e.length===1&&e[0]==="nested"){return}if(o.s!=null&&o.s===2){ret.invalid+=1}if(o.s!=null&&o.s===0){return ret.done+=1}});ret.percent=!ret.total?1:ret.done/(ret.total||1);return ret},_restatus:function(){var os,ret,k,v,this$=this;os=this._status;delete this._status;ret=function(){var ref$,results$=[];for(k in ref$=this._ws.w){v=ref$[k];results$.push({k:k,v:v})}return results$}.call(this).filter(function(arg$){var k,v;k=arg$.k,v=arg$.v;return!v._meta.disabled}).map(function(arg$){var k,v,s;k=arg$.k,v=arg$.v;s=this$._ws.s[k];if(s==null){return true}if(s===0){return false}if(s===1&&!v._meta.isRequired){return false}return true}).filter(function(it){return it}).length;this._status=ret?1:0;if(os!==this._status){return this.fire("readystatechange",this._status===0)}},check:function(o,opt){var this$=this;if(typeof opt!=="object"){opt={now:opt}}return Promise.resolve().then(function(){var p,w;if(!o){return this$.check(function(){var ref$,results$=[];for(p in ref$=this._ws.w){w=ref$[p];results$.push({widget:w,path:p})}return results$}.call(this$).filter(function(arg$){var widget;widget=arg$.widget;if(widget._meta.disabled){return false}return!opt.skipEmpty?true:!widget.isEmpty()||widget.status()===2}),opt)}this$.checkList=(this$.checkList||(this$.checkList=[])).concat(Array.isArray(o)?o:[o]);return opt.now?this$._check(null,opt):this$._checkDebounced(null,opt)}).then(function(it){this$._restatus();return it})},_check:function(o,opt){var list,this$=this;opt==null&&(opt={});if(!o){list=this.checkList||[];this.checkList=[];return this._check(list,opt)}if(Array.isArray(o)){return Promise.all(o.map(function(it){return this$._check(it,opt)})).then(function(it){return it.filter(function(it){return it})})}return new Promise(function(res,rej){var ref$,w,p,_now;ref$=[o.widget,o.path,o.now],w=ref$[0],p=ref$[1],_now=ref$[2];if(!(w&&p)){return res()}if(!w&&!(w=this$._ws.w[p])){return res()}if(!p){p=this$._ws.p[w]}return w.validate({force:opt.force,init:opt.init,skipEmpty:opt.skipEmpty}).then(function(){var os;os=this$._ws.s[p];this$._ws.s[p]=w.status();if(os!==this$._ws.s[p]){this$.fire("status",{path:p,widget:w,status:this$._ws.s[p]})}return this$._ws.s[p]}).then(function(){if(this$._ws.s[p]===2){return res({widget:w,path:p,status:this$._ws.s[p]})}else{return res()}})})},formData:function(){var fd,p,ref$,w,val,i$,to$,i;fd=new FormData;for(p in ref$=this._ws.w){w=ref$[p];if(w._meta.disabled){continue}val=w.value();if(Array.isArray(v)){for(i$=0,to$=v.length;i$<to$;++i$){i=i$;fd.append(p+"[]",v[i])}}else{fd.append(p,val)}}return fd},value:function(v,opt){var ret,p,ref$,w,ps,res$,e;opt==null&&(opt={});if(!arguments.length){ret={};for(p in ref$=this._ws.w){w=ref$[p];if(!(opt.partial&&w._meta.disabled)){ret[p]=w.value()}}return ret}v=v!=null?JSON.parse(JSON.stringify(v)):{};try{res$=[];for(p in ref$=this._ws.w){w=ref$[p];if(!v.hasOwnProperty(p)&&opt.partial){continue}res$.push(w.value(v[p],opt))}ps=res$;return Promise.all(ps)}catch(e$){e=e$;return Promise.reject(e)}},mode:function(m){var this$=this;if(!(m!=null)){return this._mode}return Promise.resolve().then(function(){var ref$,p,w;if(!(m==="edit"||m==="view"||m==="config")){return Promise.reject((ref$=new Error,ref$.name="lderror",ref$.id=1015,ref$))}if(this$._mode===m){return}this$._mode=m;this$.fire("mode",m);return Promise.all(function(){var ref$,results$=[];for(p in ref$=this._ws.w){w=ref$[p];results$.push(w)}return results$}.call(this$).map(function(w){return w.mode(m)}))})},order:function(){var nodeIdx,_,obj;nodeIdx=function(r,n,opt){var i$,to$,i,v;opt.idx++;if(r===n){return true}if(!(r&&r.childNodes)){return}for(i$=0,to$=r.childNodes.length;i$<to$;++i$){i=i$;v=nodeIdx(r.childNodes[i],n,opt);if(v){return true}}};_=function(m,obj){var ws,k,v,ms,child,opt,results$=[];ws=m._ws.w;for(k in ws){v=ws[k];ms=v.manager()||[];if(ms.length){child={};ms.map(fn$)}opt={idx:0};nodeIdx(document.body,v._root,opt);results$.push(obj[k]={title:v._meta.title,idx:opt.idx,child:child,meta:v.serialize()})}return results$;function fn$(m){return _(m,child)}};_(this,obj={});return obj},manager:function(opt){var ret,k,ref$,s,w,mgrs;ret=[];for(k in ref$=this._ws.s){s=ref$[k];if(!(this._ws.w[it.k]&&this._ws.w[it.k]._meta&&!this._ws.w[it.k]._meta.disabled)){continue}if(!(w=this.widget(k))){continue}if(!(mgrs=w.manager(opt)||[]).length){continue}ret=ret.concat(mgrs)}if(this.disabled()){ret.map(function(it){return it.disable()})}return ret}});form.op=function(opt){opt==null&&(opt={});this.id=opt.id;this.name=opt.name;this.config=opt.config;this.func=opt.func;this.opset=opt.opset;return this};form.op.prototype=import$(Object.create(Object.prototype),{getConfig:function(valspec){if(typeof this.config==="function"){return this.config(valspec)}else{return this.config}},validate:function(val,cfg){var ret;cfg==null&&(cfg={});if(this.opset.convert){val=this.opset.convert(val)}if((ret=this.func(val,cfg))instanceof Promise){return ret}else{return Promise.resolve(!!ret)}},configDefault:function(valspec){var cfg,k,ref$,v;cfg={};for(k in ref$=this.getConfig(valspec)){v=ref$[k];cfg[k]=v["default"]}return cfg}});form.opset=function(opt){var ops,k,v,this$=this;opt==null&&(opt={});this.name=opt.name;this.id=opt.id;this.i18n=opt.i18n;this.convert=opt.convert;this.valdef=opt.valdef||null;this.ops={};ops=Array.isArray(opt.ops)?opt.ops.map(function(it){return{v:it,k:it.id}}):function(){var ref$,results$=[];for(k in ref$=opt.ops){v=ref$[k];results$.push({k:k,v:v})}return results$}();ops.map(function(arg$){var k,v,ref$,ref1$,results$=[];k=arg$.k,v=arg$.v;this$.ops[k]=v instanceof form.op?v:k?new form.op((ref$=typeof v==="function"?{func:v}:v,ref$.id=k,ref$.opset=this$,ref$)):function(){throw new Error("[@plotdb/form/opset] invalid op when initializing opset.")}();for(k in ref$=opt.ops){v=ref$[k];results$.push(this$.ops[k]=new form.op((ref1$=typeof v==="function"?{func:v}:v,ref1$.name=k,ref1$.id=k,ref1$.opset=this$,ref1$)))}return results$});this.defaultOp=this.ops[opt.defaultOp]?opt.defaultOp:function(){var ref$,results$=[];for(k in ref$=this.ops){v=ref$[k];results$.push(k)}return results$}.call(this)[0];return this};form.opset.prototype=import$(Object.create(Object.prototype),{getOp:function(id){return this.ops[id||this.defaultOp]},getOps:function(){var k,ref$,v,results$=[];for(k in ref$=this.ops){v=ref$[k];results$.push(v)}return results$}});form.opset.register=function(it){return(this._list||(this._list=[])).push(it instanceof form.opset?it:new form.opset(it))};form.opset.get=function(id){return(this._list||(this._list=[])).filter(function(it){return(it.id||it.name)===id})[0]};form.opset.list=function(opt){var list,vd;opt==null&&(opt={});list=(this._list||[]).map(function(it){return it});if(!opt.valdef){return list}vd=Array.isArray(opt.valdef)?opt.valdef:[opt.valdef];return list.filter(function(os){if(!os.valdef){return!vd.length||vd.some(function(it){return!it||it==="@plotdb/form:valdef/generic"})}return vd.some(function(v){return in$(v,os.valdef)})})};wordLen=function(v,method){v==null&&(v="");return method==="simple-word"?v.split(/\s|[,.;:!?,。;:︰!?、. "]/).filter(function(it){return it}).map(function(it){return it.split(/[\u1000-\uffff]/).map(function(it){if(it.length){return 2}else{return 1}}).reduce(function(a,b){return a+b},0)-1}).reduce(function(a,b){return a+b},0):v.length};countOps={"count-max":{func:function(v,c){c==null&&(c={});return v.length<=c.val},config:{val:{type:"number",name:"count-max",hint:"maximal amount"}}},"count-min":{func:function(v,c){c==null&&(c={});return v.length>=c.val},config:{val:{type:"number",name:"count-min",hint:"minimal amount"}}},"count-range":{func:function(v,c){c==null&&(c={});return v.length>=c.min&&v.length<=c.max},config:{min:{type:"number",name:"count-min",hint:"minimal amount"},max:{type:"number",name:"count-max",hint:"maximal amount"}}},count:{func:function(v,c){c==null&&(c={});return v.length===c.val},config:{val:{type:"number",name:"count",hint:"number of entries"}}}};form.opset["default"]=[{id:"list",i18n:{"zh-TW":{list:"列表","count-max":"數量上限","count-min":"數量下限","count-range":"數量範圍",count:"數量要求"},en:{list:"List","count-max":"Maximal Count","count-min":"Minimal Count","count-range":"Count Range",count:"Required Count"}},convert:function(v){var ret;ret=Array.isArray(v)?v:v&&Array.isArray(v.list)?v.list.concat(v.other&&v.other.enabled?[v.other.text]:[]):[v];return ret.filter(function(it){return it})},ops:import$({},countOps)},{id:"file",i18n:{"zh-TW":{file:"檔案","size-limit":"檔案大小上限","count-limit":"檔案數量上限",extension:"副檔名限制","count-max":"檔案數量上限","count-min":"檔案數量下限","count-range":"檔案數量範圍"},en:{file:"File","size-limit":"Maximal File Size","count-limit":"Max File Count",extension:"File Extension","count-max":"Max File Count","count-min":"Min File Count","count-range":"File Count Range"}},convert:function(v){return(Array.isArray(v)?v:[v]).filter(function(it){return it})},ops:import$({"size-limit":{func:function(v,c){c==null&&(c={});return!v.filter(function(it){return it.size>c.val}).length},config:{val:{type:"number",name:"size-limit",hint:"maximal size"}}},extension:{func:function(v,c){var exts;c==null&&(c={});exts=(c.str.split(",")||[]).map(function(it){return(it||"").trim().toLowerCase()}).filter(function(it){return it});return!v.filter(function(it){var ext,ref$;return!in$(((ext=(ref$=(it.filename||"").split("."))[ref$.length-1])||"").trim().toLowerCase(),exts)}).length},config:{str:{type:"text",name:"extension",hint:"extension, comma separated, without dot"}}},"count-limit":{func:function(v,c){c==null&&(c={});return v.length<c.val},config:{val:{type:"number",name:"count-limit",hint:"maximal file amount"}}}},countOps)},{id:"image",i18n:{"zh-TW":{image:"圖像","long-side":"長邊尺寸限制","short-side":"短邊尺寸限制",width:"寬度限制",height:"高度限制","pixel-count":"像素量限制","min-size":"最小尺寸","max-size":"最大尺寸"},en:{image:"Image","long-side":"Long Side","short-side":"Short Side",width:"Width",height:"Height","pixel-count":"Max Pixel Count","min-size":"Min Size","max-size":"Max Size"}},convert:function(v){return(Array.isArray(v)?v:[v]).filter(function(it){return it})},ops:Object.fromEntries([["long-side","long"],["short-side","short"],["width","width"],["height","height"],["pixel-count","pixels"]].map(function(n){return[n[0],function(k){return{func:function(v,c){v==null&&(v=[]);c==null&&(c={});return!v.filter(function(it){return!((c.min==null||it[k]>=(c.min||0))&&(c.max==null||it[k]<=c.max))}).length},config:{min:{type:"number",name:"min-size",hint:"minimal size"},max:{type:"number",name:"max-size",hint:"minimal size"}}}}(n[1])]}))},{id:"string",i18n:{"zh-TW":{string:"文字",include:"包含",exclude:"排除",email:"電子郵件",url:"網址",regex:"正規表達式"},en:{string:"Text",include:"Include",exclude:"Exclude",email:"Email",url:"URL",regex:"Regular Expression"}},ops:{include:{func:function(v,c){c==null&&(c={});return~(""+(v||"")).indexOf(c.str||"")},config:{str:{type:"text",name:"include"}}},exclude:{func:function(v,c){c==null&&(c={});return!~(""+(v||"")).indexOf(c.str||"")},config:{str:{type:"text",name:"exclude"}}},email:{func:function(v){return/^[^@]+@[^@]+$/.exec(v)},config:{}},url:{func:function(v){return/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,15}\b([-a-zA-Z0-9@:%_\+.~#()?&//=]*)$/.exec(v)},config:{}},regex:{func:function(v,c){c==null&&(c={});if(!c.rule){return true}if(typeof c.rule==="object"&&c.rule.exec){return c.rule.exec(v)}return new RegExp(c.rule).exec(v)},config:{rule:{type:"text",name:"regex"}}}}},{id:"length",i18n:{"zh-TW":{length:"字串長度",lte:"≦ 小於或等於",range:"範圍",number:"數字",method:"計算方式",char:"字元","simple-word":"簡易計字/詞","minimal length":"長度下限","maximal length":"長度上限"},en:{length:"String Length",lte:"≦",range:"Range",number:"Number",method:"Method",char:"By Character","simple-word":"Count Word","minimal length":"Min Length","maximal length":"Max Length"}},ops:{range:{func:function(v,c){var len;c==null&&(c={});len=wordLen(v+"",c.method);return len>=+c.min&&len<=+c.max},config:{min:{type:"number",name:"minimal length"},max:{type:"number",name:"maximal length"},method:{type:"choice",default:"char",values:["char","simple-word"]}}},lte:{func:function(v,c){c==null&&(c={});return wordLen(v+"",c.method)<=+c.val},config:{val:{type:"number",name:"maximal length"},method:{type:"choice",default:"char",values:["char","simple-word"]}}},gte:{func:function(v,c){c==null&&(c={});return wordLen(v+"",c.method)>=+c.val},config:{val:{type:"number",name:"minimal length"},method:{type:"choice",default:"char",values:["char","simple-word"]}}},eq:{func:function(v,c){c==null&&(c={});return wordLen(v+"",c.method)===+c.val},config:{val:{type:"number",name:"length"},method:{type:"choice",default:"char",values:["char","simple-word"]}}}}},{id:"number",i18n:{"zh-TW":{number:"數字",lte:"≦ 小於或等於",gte:"≧ 大於或等於",ne:"≠ 不等於",eq:"= 等於",is:"任何數字","ref-val":"參考值"},en:{number:"Number",lte:"≦ Equal/Less Than",gte:"≧ Equal/Greater Than",ne:"≠ Not Equals",eq:"= Equals",is:"Is Number","ref-val":"Reference Value"}},convert:function(v){return+(v+"").replace(/,/g,"")},ops:{lte:{func:function(v,c){c==null&&(c={});if(isNaN(v)||isNaN(c.val)){return false}else{return+v<=+c.val}},config:{val:{type:"text",name:"ref-val"}}},gte:{func:function(v,c){c==null&&(c={});if(isNaN(v)||isNaN(c.val)){return false}else{return+v>=+c.val}},config:{val:{type:"text",name:"ref-val"}}},ne:{func:function(v,c){c==null&&(c={});if(isNaN(v)||isNaN(c.val)){return false}else{return+v!==+c.val}},config:{val:{type:"text",name:"ref-val"}}},eq:{func:function(v,c){c==null&&(c={});if(isNaN(v)||isNaN(c.val)){return false}else{return+v===+c.val}},config:{val:{type:"text",name:"ref-val"}}},is:{func:function(v){return!isNaN(v)},config:{}}}},{id:"date",i18n:{"zh-TW":{date:"日期","min age":"最小年齡","max age":"最大年齡",age:"年齡"},en:{date:"Date","min age":"Min Age","max age":"Max Age",age:"Age"}},convert:function(v){return new Date(v)},ops:{age:{config:{min:{type:"number",name:"min age"},max:{type:"number",name:"max age"}},func:function(v,c){var dmin,dmax,dnow;c==null&&(c={});dmin=new Date(v.getYear()+1900+(c.min||0),v.getMonth(),v.getDate()).getTime();dmax=new Date(v.getYear()+1900+(c.max||0),v.getMonth(),v.getDate()).getTime();dnow=Date.now();if(c.min!=null&&dmin>dnow){return false}if(c.max!=null&&dmax<dnow){return false}return true}}}},{id:"choice",valdef:["@plotdb/form:valdef/choice"],i18n:{"zh-TW":{choice:"選擇",is:"選了","is-not":"沒選","is-any":"選了其中一個",val:"選項值",vals:"選項值(任一)"},en:{choice:"Choice",is:"Is","is-not":"Is Not","is-any":"Is Any Of",val:"Option value",vals:"Option values (any)"}},convert:function(v){var toKey,list;toKey=function(item){if(typeof item==="string"){return item}else{return item.key||item.value||""}};if(!v){return{list:[],other:{}}}if(typeof v==="string"){return{list:v?[v]:[],other:{}}}list=(v.list||[]).filter(function(it){return it}).map(toKey);return{list:list,other:v.other||{}}},ops:{is:{func:function(v,c){c==null&&(c={});return!!(c.val&&in$(c.val,v.list))},config:function(valspec){var values;values=((valspec!=null?valspec.values:void 8)||[]).map(function(v){return{value:v.key||v.value||v,name:v.label||v.value||v.key||v}});return{val:values.length?{type:"choice",name:"val",values:values}:{type:"text",name:"val"}}}},"is-not":{func:function(v,c){c==null&&(c={});return!(c.val&&in$(c.val,v.list))},config:function(valspec){var values;values=((valspec!=null?valspec.values:void 8)||[]).map(function(v){return{value:v.key||v.value||v,name:v.label||v.value||v.key||v}});return{val:values.length?{type:"choice",name:"val",values:values}:{type:"text",name:"val"}}}},"is-any":{func:function(v,c){var vals;c==null&&(c={});vals=Array.isArray(c.vals)?c.vals:typeof c.vals==="string"?c.vals.split(",").map(function(it){return it.trim()}).filter(function(it){return it}):[];return vals.some(function(it){return in$(it,v.list)})},config:function(valspec){var values;values=((valspec!=null?valspec.values:void 8)||[]).map(function(v){return{value:v.key||v.value||v,name:v.label||v.value||v.key||v}});return{vals:values.length?{type:"choice",name:"vals",values:values}:{type:"text",name:"vals",hint:"comma separated"}}}}}}];form.opset["default"].map(function(it){return form.opset.register(it)});form.term=function(opt){opt==null&&(opt={});import$((this.enabled=true,this.opset=null,this.op=null,this.config={},this),opt);if(!this.id){this.id=Math.random().toString(36).substring(2)}this.setOpset(opt.opset,opt.op,opt.config);return this};form.term.prototype=import$(Object.create(Object.prototype),{toggle:function(it){return this.enabled=it!=null?it:!this.enabled},setOpset:function(opset,op,cfg){if(typeof opset==="string"){if(!(this.opset=form.opset.get(opset))){throw new Error("no such opset '"+opset+"'")}}else if(opset instanceof form.opset){this.opset=opset}else{throw new Error("invalid opset")}return this.setOp(op,cfg)},setOp:function(id,cfg){if(!this.opset){throw new Error("opset not set")}if(!(this.op=this.opset.getOp(id))){throw new Error("no such op '"+id+"'")}return this.setConfig(cfg)},setConfig:function(cfg){if(!this.op){throw new Error("op not set")}return this.config=!cfg?this.op.configDefault():cfg},validate:function(v){if(!this.op){Promis.reject(new Error("op not set"))}return this.op.validate(v,this.config)},serialize:function(){return{id:this.id,enabled:this.enabled,opset:this.opset.id,op:this.op.id,config:this.config,msg:this.msg}},deserialize:function(v){this.toggle(v.enabled);return this.setOpset(v.opset,v.op,v.config)}});form.widget=function(opt){var o,this$=this;opt==null&&(opt={});this._root=typeof opt.root==="string"?document.querySelector(opt.root):opt.root;this.evtHandler={};this.mod=opt.mod||null;this.i18n={};this._custom={};this._status=1;this._meta={config:{},key:Math.random().toString(36).substring(2)};this._meta_dig="";this._value=undefined;this._empty=true;this._mode=opt.mode||"edit";this._validate=opt.validate||null;this._opsets=(opt.opsets||[]).concat((opt.mod||{}).opsets||[]).map(function(opset){if(typeof opset==="string"){return form.opset.get(opset)}else if(opset instanceof form.opset){return opset}else{return new form.opset(opset)}});this._opsets.filter(function(it){return it.i18n}).map(function(it){var k,ref$,v,ref1$,results$=[];for(k in ref$=it.i18n){v=ref$[k];results$.push(import$((ref1$=this$.i18n)[k]||(ref1$[k]={}),v))}return results$});this._opsets=Object.fromEntries(function(){var i$,ref$,len$,results$=[];for(i$=0,len$=(ref$=this._opsets).length;i$<len$;++i$){o=ref$[i$];results$.push([o.id||o.name||"",o])}return results$}.call(this));this._errors=[];this.init=proxise.once(function(){return this$._init()});return this};form.widget.prototype=import$(Object.create(Object.prototype),{on:function(n,cb){var this$=this;return(Array.isArray(n)?n:[n]).map(function(n){var ref$;return((ref$=this$.evtHandler)[n]||(ref$[n]=[])).push(cb)})},off:function(n,cb){var this$=this;return(Array.isArray(n)?n:[n]).map(function(n){var l,ref$;l=(ref$=this$.evtHandler)[n]||(ref$[n]=[]);if(l.indexOf(cb)>=0){return l.splice(l.indexOf(cb),1)}})},fire:function(n){var v,res$,i$,to$,ref$,len$,cb,results$=[];res$=[];for(i$=1,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}v=res$;for(i$=0,len$=(ref$=this.evtHandler[n]||[]).length;i$<len$;++i$){cb=ref$[i$];results$.push(cb.apply(this,v))}return results$},root:function(){return this._root},_init:function(){var this$=this;return Promise.resolve(this.mod&&this.mod.init?this.mod.init.apply(this):"").then(function(){return this$.fire("init")})},key:function(keyonly){keyonly==null&&(keyonly=false);return keyonly?this._meta.key:this._meta.alias||this._meta.key},status:function(v){var ov;if(!(v!=null)){return this._status}ov=this._status;this._status=v;if(ov!==v){return this.fire("status",v)}},serialize:function(){var ref$,ret,ref1$;ret=(ref1$={},ref1$.key=(ref$=this._meta).key,ref1$.title=ref$.title,ref1$.desc=ref$.desc,ref1$.isRequired=ref$.isRequired,ref1$.disabled=ref$.disabled,ref1$.readonly=ref$.readonly,ref1$.defaultValue=ref$.defaultValue,ref1$);ret.config=JSON.parse(JSON.stringify(this._meta.config||{}));ret.term=(this._meta.term||[]).map(function(it){return it.serialize()});return ret},deserialize:function(v,o){var ref$,dig,this$=this;o==null&&(o={});ref$=this._meta;ref$.key=v.key;ref$.title=v.title;ref$.desc=v.desc;ref$.isRequired=v.isRequired;ref$.disabled=v.disabled;ref$.readonly=v.readonly;ref$.defaultValue=v.defaultValue;this._meta.config=JSON.parse(JSON.stringify(v.config||{}));this._meta.term=(v.term||[]).map(function(t){var that;return new form.term(import$(import$({},t),(that=this$._opsets[t.opset||""])?{opset:that}:{}))});dig=JSON.stringify(v);if(this._meta_dig!==dig){this.fire("meta",this.serialize(),{init:o.init})}this.manager();this._meta_dig=dig;return Promise.resolve().then(function(){if(!o.init){return}if(!(this$._meta.defaultValue!=null&&this$.isEmpty())){return}return this$.value(this$._meta.defaultValue,{init:true,fromSource:true})}).then(function(){return this$.validate({init:o.init})}).then(function(){return this$.render()})},mode:function(m){var this$=this;if(!(m!=null)){return this._mode}return Promise.resolve().then(function(){var ref$;if(!(m==="edit"||m==="view"||m==="config")){return Promise.reject((ref$=new Error,ref$.name="lderror",ref$.id=1015,ref$))}if(this$._mode===m){return}this$._mode=m;this$.fire("mode",m);return this$.validate({init:true}).then(function(){return this$.render()})})},errors:function(){return this._errors},value:function(v,opt){var _v,this$=this;opt==null&&(opt={});if(arguments.length===0){return this._value!=null?JSON.parse(JSON.stringify(this._value)):this._value}if(this.isEqual(v,this._value)){return Promise.resolve()}_v=v!=null?JSON.parse(JSON.stringify(v)):v;this._value=_v;this._empty=this.isEmpty(_v);return this.validate({init:opt.init}).then(function(){if(opt.fromSource){return}return this$.fire("change",this$._value!=null?JSON.parse(JSON.stringify(this$._value)):undefined)})},disabled:function(){return!!this._meta.disabled},readonly:function(){return!!this._meta.readonly},isRequired:function(){return!!this._meta.isRequired},isEmpty:function(v){if(!arguments.length){v=this._value}if(this.mod&&this.mod.isEmpty){return this.mod.isEmpty.call(this,v)}else{return v===null||typeof v==="undefined"||v===""}},isEqual:function(u,v){var eu,ev;if(arguments.length===1){v=this._value}if(this.mod&&this.mod.isEqual){return this.mod.isEqual.call(this,u,v)}eu=this.isEmpty(u);ev=this.isEmpty(v);if(!eu!==!ev&&(eu||ev)){return false}if(eu&&ev){return true}return JSON.stringify(u)===JSON.stringify(v)},content:function(v){if(!arguments.length){v=this._value}if(this.mod&&this.mod.content){return this.mod.content.call(this,v)}else if(typeof v==="object"&&v&&v.hasOwnProperty(v)){return v.v}else{return v}},valdef:function(){if(this.mod&&this.mod.valdef){if(typeof this.mod.valdef==="function"){return this.mod.valdef.call(this)}return this.mod.valdef}return null},valspec:function(){if(this.mod&&this.mod.valspec){if(typeof this.mod.valspec==="function"){return this.mod.valspec.call(this)}return this.mod.valspec}return null},validate:function(opt){var v,this$=this;opt==null&&(opt={});v=this.content();return Promise.resolve().then(function(){if(this$.mod&&this$.mod.validate){return this$.mod.validate.call(this$,opt)}if(this$._validate){return this$._validate(v)}}).then(function(ret){ret==null&&(ret=[]);if(ret.status===3){this$._errors=ret.errors||[];this$.status(3);this$.render();return this$._errors}if(ret&&ret.length){this$._errors=ret;this$.status(opt.init?1:2);this$.render();return this$._errors}if(this$._empty){if(this$._meta.isRequired){this$._errors=["required"];this$.status(opt.init?1:2);this$.render();return this$._errors}else{this$.status(0);this$.render();return this$._errors=[]}}return Promise.all(this$._meta.term.filter(function(t){return t.enabled}).map(function(t){return t.validate(v).then(function(v){return[t,v]})})).then(function(it){var nv;nv=this$.content();if(!this$.isEqual(nv,v)){return}this$._errors=it.filter(function(it){return!it[1]}).map(function(it){return it[0].msg||"error"});this$.status(this$._errors.length?2:0);return this$.render()}).then(function(){return this$._errors})})},render:function(){this.fire("render");if(this.mod&&this.mod.render){return this.mod.render.apply(this)}},adapt:function(){var args,res$,i$,to$;res$=[];for(i$=0,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}args=res$;if(this.mod&&this.mod.adapt){return this.mod.adapt.apply(this,args)}},manager:function(arg$){var depth,ref$,ret;depth=(ref$=(arg$!=null?arg$:{}).depth)!=null?ref$:0;ret=this.mod&&this.mod.manager?this.mod.manager.apply(this,[{depth:depth}]):[];ret=(Array.isArray(ret)?ret:[ret]).filter(function(it){return it});if(this.disabled()){ret.map(function(it){return it.disable()})}return ret},ctrl:function(){var args,res$,i$,to$;res$=[];for(i$=0,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}args=res$;if(this.mod&&this.mod.ctrl){return this.mod.ctrl.apply(this,args)}}});if(typeof module!="undefined"&&module!==null){module.exports=form}else if(typeof window!="undefined"&&window!==null){window.form=form}function import$(obj,src){var own={}.hasOwnProperty;for(var key in src)if(own.call(src,key))obj[key]=src[key];return obj}function in$(x,xs){var i=-1,l=xs.length>>>0;while(++i<l)if(x===xs[i])return true;return false}}).call(this);
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"zbryikt","name":"@plotdb/form","license":"MIT","description":"form blocks","version":"0.1.
|
|
1
|
+
{"author":"zbryikt","name":"@plotdb/form","license":"MIT","description":"form blocks","version":"0.1.3","browser":"index.min.js","main":"index.min.js","homepage":"https://github.com/plotdb/form","repository":{"type":"git","url":"git+https://github.com/plotdb/form.git"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true"},"devDependencies":{"@grantdash/composer":"^0.0.3","@loadingio/bootstrap.ext":"^0.0.12","@loadingio/debounce.js":"^1.0.1","@loadingio/ldquery":"^3.0.6","@makeform/nest":"^0.3.11","@plotdb/datadom":"^0.2.0","@plotdb/datahub":"^0.6.0","@plotdb/json0":"^0.0.5","@plotdb/semver":"^0.0.3","@zbryikt/deploy":"^0.0.4","@zbryikt/template":"^2.4.1","bootstrap":"^4.6.1","bootstrap.native":"^3.0.13","fedep":"^1.6.0","i18next":"^19.9.2","ldcover":"^3.5.6","ldiconfont":"^0.2.8","ldview":"^1.7.0","livescript":"^1.6.0","marked":"^15.0.12","stylus":"^0.55.0","uglify-js":"^3.13.1","uglifycss":"^0.0.29"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["@grantdash/composer","@loadingio/bootstrap.ext","@loadingio/ldquery","@loadingio/debounce.js","@loadingio/ldcolorpicker","@makeform/nest","@plotdb/sheet","@plotdb/block","@plotdb/json0","@plotdb/datadom","@plotdb/datahub","@plotdb/semver","@plotdb/rescope","@plotdb/suuid","@plotdb/konfig","@plotdb/csscope","bootstrap","bootstrap.native","curegex","dompurify","i18next","ldcolor","ldcover","ldiconfont","ldslider","ldpalettepicker","ldview","marked","proxise"]},"dependencies":{"@loadingio/ldcolorpicker":"^3.0.6","@plotdb/block":"^5.7.2","@plotdb/csscope":"^5.0.4","@plotdb/datadom":"^0.2.0","@plotdb/konfig":"^4.10.0","@plotdb/rescope":"^5.0.17","@plotdb/sheet":"^0.7.0","@plotdb/suuid":"^0.5.1","curegex":"^0.0.4","dompurify":"^3.2.4","ldcolor":"^1.1.3","ldpalettepicker":"^4.1.2","ldslider":"^3.1.2","proxise":"^1.0.1"}}
|