@plotdb/form 0.0.68 → 0.1.0
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 +9 -0
- package/index.js +334 -29
- package/index.min.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v0.1.0
|
|
4
|
+
|
|
5
|
+
- [breaking change] remove the `init` event inside deserialize; use `meta` with `init` option instead.
|
|
6
|
+
- add `opset.list` api for listing available opsets
|
|
7
|
+
- add experimental condctrl submodule
|
|
8
|
+
- add depth option in manager api
|
|
9
|
+
- add english translation for opset i18n object
|
|
10
|
+
|
|
11
|
+
|
|
3
12
|
## v0.0.68
|
|
4
13
|
|
|
5
14
|
- add `order` api in form.manager for automatically determing field orders
|
package/index.js
CHANGED
|
@@ -1,7 +1,221 @@
|
|
|
1
1
|
// Generated by LiveScript 1.6.0
|
|
2
2
|
(function(){
|
|
3
|
-
var form, wordLen, countOps;
|
|
3
|
+
var form, ref$, wordLen, countOps;
|
|
4
4
|
form = {};
|
|
5
|
+
form.condctrl = function(opt){
|
|
6
|
+
var ref$;
|
|
7
|
+
opt == null && (opt = {});
|
|
8
|
+
ref$ = this._ || (this._ = {});
|
|
9
|
+
ref$.hash = {};
|
|
10
|
+
ref$.enabled = {};
|
|
11
|
+
ref$.manager = opt.manager;
|
|
12
|
+
ref$.list = opt.conditions || [];
|
|
13
|
+
ref$.applyBaseRule = opt.baseRule || function(){};
|
|
14
|
+
return this;
|
|
15
|
+
};
|
|
16
|
+
form.condctrl.prototype = (ref$ = Object.create(Object.prototype), ref$.isEnabled = function(it){
|
|
17
|
+
return this._.enabled[it];
|
|
18
|
+
}, ref$.get = function(it){
|
|
19
|
+
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
|
+
}, ref$.reset = function(opt){
|
|
39
|
+
var fields, i$, to$, i, cond, results$ = [];
|
|
40
|
+
opt == null && (opt = {});
|
|
41
|
+
this._.list = opt.conditions || this._.list || [];
|
|
42
|
+
fields = this.fields();
|
|
43
|
+
for (i$ = 0, to$ = this._.list.length; i$ < to$; ++i$) {
|
|
44
|
+
i = i$;
|
|
45
|
+
cond = this._.list[i];
|
|
46
|
+
cond.id = cond.id || (i + 1) + "";
|
|
47
|
+
this._.hash[cond.id] = cond;
|
|
48
|
+
if (!Array.isArray(cond.config)) {
|
|
49
|
+
cond.config = [cond.config];
|
|
50
|
+
}
|
|
51
|
+
results$.push(cond.config.map(fn$));
|
|
52
|
+
}
|
|
53
|
+
return results$;
|
|
54
|
+
function fn$(cfg){
|
|
55
|
+
var k, v;
|
|
56
|
+
cfg.src = cond.src;
|
|
57
|
+
cfg.func = cond.func;
|
|
58
|
+
return cfg.path = Array.from(new Set((cfg.prefix
|
|
59
|
+
? cfg.prefix
|
|
60
|
+
: []).concat(cfg.path || [], (function(){
|
|
61
|
+
var ref$, results$ = [];
|
|
62
|
+
for (k in ref$ = fields) {
|
|
63
|
+
v = ref$[k];
|
|
64
|
+
results$.push({
|
|
65
|
+
k: k,
|
|
66
|
+
v: v
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return results$;
|
|
70
|
+
}()).filter(function(arg$){
|
|
71
|
+
var k, v, ref$;
|
|
72
|
+
k = arg$.k, v = arg$.v;
|
|
73
|
+
return (!cfg.prefix
|
|
74
|
+
? 0
|
|
75
|
+
: cfg.prefix.filter(function(p){
|
|
76
|
+
return k.startsWith(p);
|
|
77
|
+
}).length) + ((v != null ? (ref$ = v.meta) != null ? ref$.tag : void 8 : void 8) || []).filter(function(t){
|
|
78
|
+
return in$(t, cfg.tag || []);
|
|
79
|
+
}).length > 0;
|
|
80
|
+
}).map(function(it){
|
|
81
|
+
return it.k;
|
|
82
|
+
}))));
|
|
83
|
+
}
|
|
84
|
+
}, ref$.apply = function(opt){
|
|
85
|
+
var path, active, enabled, isRequired, readonly, widget, curMeta, newMeta;
|
|
86
|
+
opt == null && (opt = {});
|
|
87
|
+
path = opt.path, active = opt.active, enabled = opt.enabled, isRequired = opt.isRequired, readonly = opt.readonly;
|
|
88
|
+
if (Array.isArray(path) && path[1]) {
|
|
89
|
+
return this.subcond({
|
|
90
|
+
path: path[0],
|
|
91
|
+
active: active,
|
|
92
|
+
config: {
|
|
93
|
+
path: path.slice(1),
|
|
94
|
+
enabled: enabled,
|
|
95
|
+
isRequired: isRequired,
|
|
96
|
+
readonly: readonly
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
if (enabled != null) {
|
|
101
|
+
this._.enabled[path] = !(!enabled !== !active && (enabled || active));
|
|
102
|
+
}
|
|
103
|
+
if (widget = this._.manager.widget(path)) {
|
|
104
|
+
curMeta = widget.serialize();
|
|
105
|
+
newMeta = JSON.parse(JSON.stringify(curMeta));
|
|
106
|
+
if (enabled != null) {
|
|
107
|
+
newMeta.disabled = !!(!enabled !== !active && (enabled || active));
|
|
108
|
+
}
|
|
109
|
+
if (readonly != null) {
|
|
110
|
+
newMeta.readonly = !(!readonly !== !active && (readonly || active));
|
|
111
|
+
}
|
|
112
|
+
if (isRequired != null) {
|
|
113
|
+
newMeta.isRequired = !(!isRequired !== !active && (isRequired || active));
|
|
114
|
+
}
|
|
115
|
+
this._.applyBaseRule({
|
|
116
|
+
path: path,
|
|
117
|
+
widget: widget,
|
|
118
|
+
meta: newMeta,
|
|
119
|
+
opt: opt
|
|
120
|
+
});
|
|
121
|
+
if (!!curMeta.disabled === !!newMeta.disabled && !!curMeta.isRequired === !!newMeta.isRequired && !!curMeta.readonly === !!newMeta.readonly) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
return widget.deserialize(newMeta, {
|
|
125
|
+
init: true
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}, ref$._run = function(cfg, precond){
|
|
129
|
+
var src, values, path, isRequired, enabled, readonly, func, result, i$, len$, p, active, ref$, itf, content;
|
|
130
|
+
cfg == null && (cfg = {});
|
|
131
|
+
src = cfg.src, values = cfg.values, path = cfg.path, isRequired = cfg.isRequired, enabled = cfg.enabled, readonly = cfg.readonly, func = cfg.func;
|
|
132
|
+
if (func) {
|
|
133
|
+
result = true;
|
|
134
|
+
for (i$ = 0, len$ = path.length; i$ < len$; ++i$) {
|
|
135
|
+
p = path[i$];
|
|
136
|
+
active = !!func.apply(this, [(ref$ = import$({}, cfg), ref$.path = p, ref$)]) && !(precond != null && !precond);
|
|
137
|
+
result = result && active;
|
|
138
|
+
if (Array.isArray(p) && p[1]) {
|
|
139
|
+
this.subcond({
|
|
140
|
+
path: p[0],
|
|
141
|
+
config: (ref$ = import$({}, cfg), ref$.path = p.slice(1), ref$),
|
|
142
|
+
active: active
|
|
143
|
+
});
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
this.apply({
|
|
147
|
+
path: p[0],
|
|
148
|
+
enabled: enabled,
|
|
149
|
+
active: active,
|
|
150
|
+
isRequired: isRequired,
|
|
151
|
+
readonly: readonly
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
if (!(itf = this._.manager.widget(src))) {
|
|
156
|
+
console.error("[@plotdb/form] condctrl: run with nonexisted fields '" + src + "'");
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
content = itf.content();
|
|
160
|
+
content = Array.isArray(content)
|
|
161
|
+
? content
|
|
162
|
+
: [content];
|
|
163
|
+
active = !!content.filter(function(c){
|
|
164
|
+
if (Array.isArray(values)) {
|
|
165
|
+
return in$(c, values);
|
|
166
|
+
} else {
|
|
167
|
+
return c === values;
|
|
168
|
+
}
|
|
169
|
+
}).length;
|
|
170
|
+
if (precond != null && !precond) {
|
|
171
|
+
active = false;
|
|
172
|
+
}
|
|
173
|
+
for (i$ = 0, len$ = path.length; i$ < len$; ++i$) {
|
|
174
|
+
p = path[i$];
|
|
175
|
+
if (Array.isArray(p) && p[1]) {
|
|
176
|
+
this.subcond({
|
|
177
|
+
path: p[0],
|
|
178
|
+
config: (ref$ = import$({}, cfg), ref$.path = p.slice(1), ref$),
|
|
179
|
+
active: active
|
|
180
|
+
});
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
this.apply({
|
|
184
|
+
path: p,
|
|
185
|
+
enabled: enabled,
|
|
186
|
+
active: active,
|
|
187
|
+
isRequired: isRequired,
|
|
188
|
+
readonly: readonly
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
result = active;
|
|
192
|
+
}
|
|
193
|
+
return result;
|
|
194
|
+
}, ref$.run = function(){
|
|
195
|
+
var result, _, this$ = this;
|
|
196
|
+
result = {};
|
|
197
|
+
_ = function(list){
|
|
198
|
+
var i$, to$, i, lresult$, cond, j$, ref$, len$, cfg, results$ = [];
|
|
199
|
+
for (i$ = 0, to$ = list.length; i$ < to$; ++i$) {
|
|
200
|
+
i = i$;
|
|
201
|
+
lresult$ = [];
|
|
202
|
+
cond = list[i];
|
|
203
|
+
if (result[cond.id] != null) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (cond.precond && this$._.hash[cond.precond]) {
|
|
207
|
+
_([this$._.hash[cond.precond]]);
|
|
208
|
+
}
|
|
209
|
+
for (j$ = 0, len$ = (ref$ = cond.config).length; j$ < len$; ++j$) {
|
|
210
|
+
cfg = ref$[j$];
|
|
211
|
+
lresult$.push(result[cond.id] = this$._run(cfg, result[cond.precond]));
|
|
212
|
+
}
|
|
213
|
+
results$.push(lresult$);
|
|
214
|
+
}
|
|
215
|
+
return results$;
|
|
216
|
+
};
|
|
217
|
+
return _(this._.list || []);
|
|
218
|
+
}, ref$);
|
|
5
219
|
form.manager = function(o){
|
|
6
220
|
var this$ = this;
|
|
7
221
|
o == null && (o = {});
|
|
@@ -15,6 +229,9 @@
|
|
|
15
229
|
this._status = 1;
|
|
16
230
|
this._mode = 'edit';
|
|
17
231
|
this._mod = {};
|
|
232
|
+
this._cond = new form.condctrl({
|
|
233
|
+
manager: this
|
|
234
|
+
});
|
|
18
235
|
this._checkDebounced = debounce(10, function(){
|
|
19
236
|
var args, res$, i$, to$;
|
|
20
237
|
res$ = [];
|
|
@@ -45,6 +262,9 @@
|
|
|
45
262
|
return ((ref$ = this$._evthdr)[n] || (ref$[n] = [])).push(cb);
|
|
46
263
|
});
|
|
47
264
|
},
|
|
265
|
+
condition: function(){
|
|
266
|
+
return this._cond;
|
|
267
|
+
},
|
|
48
268
|
fire: function(n){
|
|
49
269
|
var v, res$, i$, to$, ref$, len$, cb, results$ = [];
|
|
50
270
|
res$ = [];
|
|
@@ -556,15 +776,20 @@
|
|
|
556
776
|
}
|
|
557
777
|
});
|
|
558
778
|
form.opset.register = function(it){
|
|
559
|
-
return (this.
|
|
779
|
+
return (this._list || (this._list = [])).push(it instanceof form.opset
|
|
560
780
|
? it
|
|
561
781
|
: new form.opset(it));
|
|
562
782
|
};
|
|
563
783
|
form.opset.get = function(id){
|
|
564
|
-
return (this.
|
|
784
|
+
return (this._list || (this._list = [])).filter(function(it){
|
|
565
785
|
return (it.id || it.name) === id;
|
|
566
786
|
})[0];
|
|
567
787
|
};
|
|
788
|
+
form.opset.list = function(){
|
|
789
|
+
return (this._list || []).map(function(it){
|
|
790
|
+
return it;
|
|
791
|
+
});
|
|
792
|
+
};
|
|
568
793
|
wordLen = function(v, method){
|
|
569
794
|
v == null && (v = "");
|
|
570
795
|
return method === 'simple-word'
|
|
@@ -594,6 +819,7 @@
|
|
|
594
819
|
config: {
|
|
595
820
|
val: {
|
|
596
821
|
type: 'number',
|
|
822
|
+
name: "count-max",
|
|
597
823
|
hint: "maximal amount"
|
|
598
824
|
}
|
|
599
825
|
}
|
|
@@ -606,6 +832,7 @@
|
|
|
606
832
|
config: {
|
|
607
833
|
val: {
|
|
608
834
|
type: 'number',
|
|
835
|
+
name: "count-min",
|
|
609
836
|
hint: "minimal amount"
|
|
610
837
|
}
|
|
611
838
|
}
|
|
@@ -618,10 +845,12 @@
|
|
|
618
845
|
config: {
|
|
619
846
|
min: {
|
|
620
847
|
type: 'number',
|
|
848
|
+
name: "count-min",
|
|
621
849
|
hint: "minimal amount"
|
|
622
850
|
},
|
|
623
851
|
max: {
|
|
624
852
|
type: 'number',
|
|
853
|
+
name: "count-max",
|
|
625
854
|
hint: "maximal amount"
|
|
626
855
|
}
|
|
627
856
|
}
|
|
@@ -634,6 +863,7 @@
|
|
|
634
863
|
config: {
|
|
635
864
|
val: {
|
|
636
865
|
type: 'number',
|
|
866
|
+
name: "count",
|
|
637
867
|
hint: "number of entries"
|
|
638
868
|
}
|
|
639
869
|
}
|
|
@@ -644,10 +874,18 @@
|
|
|
644
874
|
id: "list",
|
|
645
875
|
i18n: {
|
|
646
876
|
"zh-TW": {
|
|
877
|
+
"list": "列表",
|
|
647
878
|
"count-max": "數量上限",
|
|
648
879
|
"count-min": "數量下限",
|
|
649
880
|
"count-range": "數量範圍",
|
|
650
881
|
"count": "數量要求"
|
|
882
|
+
},
|
|
883
|
+
"en": {
|
|
884
|
+
"list": "List",
|
|
885
|
+
"count-max": "Maximal Count",
|
|
886
|
+
"count-min": "Minimal Count",
|
|
887
|
+
"count-range": "Count Range",
|
|
888
|
+
"count": "Required Count"
|
|
651
889
|
}
|
|
652
890
|
},
|
|
653
891
|
convert: function(v){
|
|
@@ -668,12 +906,22 @@
|
|
|
668
906
|
id: "file",
|
|
669
907
|
i18n: {
|
|
670
908
|
"zh-TW": {
|
|
909
|
+
"file": "檔案",
|
|
671
910
|
"size-limit": "檔案大小上限",
|
|
672
911
|
"count-limit": "檔案數量上限",
|
|
673
912
|
"extension": "副檔名限制",
|
|
674
913
|
"count-max": "檔案數量上限",
|
|
675
914
|
"count-min": "檔案數量下限",
|
|
676
915
|
"count-range": "檔案數量範圍"
|
|
916
|
+
},
|
|
917
|
+
"en": {
|
|
918
|
+
"file": "File",
|
|
919
|
+
"size-limit": "Maximal File Size",
|
|
920
|
+
"count-limit": "Max File Count",
|
|
921
|
+
"extension": "File Extension",
|
|
922
|
+
"count-max": "Max File Count",
|
|
923
|
+
"count-min": "Min File Count",
|
|
924
|
+
"count-range": "File Count Range"
|
|
677
925
|
}
|
|
678
926
|
},
|
|
679
927
|
convert: function(v){
|
|
@@ -694,6 +942,7 @@
|
|
|
694
942
|
config: {
|
|
695
943
|
val: {
|
|
696
944
|
type: 'number',
|
|
945
|
+
name: 'size-limit',
|
|
697
946
|
hint: "maximal size"
|
|
698
947
|
}
|
|
699
948
|
}
|
|
@@ -715,6 +964,7 @@
|
|
|
715
964
|
config: {
|
|
716
965
|
str: {
|
|
717
966
|
type: 'text',
|
|
967
|
+
name: 'extension',
|
|
718
968
|
hint: "extension, comma separated, without dot"
|
|
719
969
|
}
|
|
720
970
|
}
|
|
@@ -727,6 +977,7 @@
|
|
|
727
977
|
config: {
|
|
728
978
|
val: {
|
|
729
979
|
type: 'number',
|
|
980
|
+
name: 'count-limit',
|
|
730
981
|
hint: "maximal file amount"
|
|
731
982
|
}
|
|
732
983
|
}
|
|
@@ -736,11 +987,24 @@
|
|
|
736
987
|
id: "image",
|
|
737
988
|
i18n: {
|
|
738
989
|
"zh-TW": {
|
|
739
|
-
"
|
|
740
|
-
"
|
|
990
|
+
"image": "圖像",
|
|
991
|
+
"long-side": "長邊尺寸限制",
|
|
992
|
+
"short-side": "短邊尺寸限制",
|
|
741
993
|
"width": "寬度限制",
|
|
742
994
|
"height": "高度限制",
|
|
743
|
-
"pixel-count": "像素量限制"
|
|
995
|
+
"pixel-count": "像素量限制",
|
|
996
|
+
"min-size": "最小尺寸",
|
|
997
|
+
"max-size": "最大尺寸"
|
|
998
|
+
},
|
|
999
|
+
"en": {
|
|
1000
|
+
"image": "Image",
|
|
1001
|
+
"long-side": "Long Side",
|
|
1002
|
+
"short-side": "Short Side",
|
|
1003
|
+
"width": "Width",
|
|
1004
|
+
"height": "Height",
|
|
1005
|
+
"pixel-count": "Max Pixel Count",
|
|
1006
|
+
"min-size": "Min Size",
|
|
1007
|
+
"max-size": "Max Size"
|
|
744
1008
|
}
|
|
745
1009
|
},
|
|
746
1010
|
convert: function(v){
|
|
@@ -764,10 +1028,12 @@
|
|
|
764
1028
|
config: {
|
|
765
1029
|
min: {
|
|
766
1030
|
type: 'number',
|
|
1031
|
+
name: 'min-size',
|
|
767
1032
|
hint: "minimal size"
|
|
768
1033
|
},
|
|
769
1034
|
max: {
|
|
770
1035
|
type: 'number',
|
|
1036
|
+
name: 'max-size',
|
|
771
1037
|
hint: "minimal size"
|
|
772
1038
|
}
|
|
773
1039
|
}
|
|
@@ -785,6 +1051,14 @@
|
|
|
785
1051
|
email: "電子郵件",
|
|
786
1052
|
url: "網址",
|
|
787
1053
|
regex: "正規表達式"
|
|
1054
|
+
},
|
|
1055
|
+
"en": {
|
|
1056
|
+
string: "Text",
|
|
1057
|
+
include: "Include",
|
|
1058
|
+
exclude: "Exclude",
|
|
1059
|
+
email: "Email",
|
|
1060
|
+
url: "URL",
|
|
1061
|
+
regex: "Regular Expression"
|
|
788
1062
|
}
|
|
789
1063
|
},
|
|
790
1064
|
ops: {
|
|
@@ -795,7 +1069,8 @@
|
|
|
795
1069
|
},
|
|
796
1070
|
config: {
|
|
797
1071
|
str: {
|
|
798
|
-
type: 'text'
|
|
1072
|
+
type: 'text',
|
|
1073
|
+
name: 'include'
|
|
799
1074
|
}
|
|
800
1075
|
}
|
|
801
1076
|
},
|
|
@@ -806,7 +1081,8 @@
|
|
|
806
1081
|
},
|
|
807
1082
|
config: {
|
|
808
1083
|
str: {
|
|
809
|
-
type: 'text'
|
|
1084
|
+
type: 'text',
|
|
1085
|
+
name: 'exclude'
|
|
810
1086
|
}
|
|
811
1087
|
}
|
|
812
1088
|
},
|
|
@@ -835,7 +1111,8 @@
|
|
|
835
1111
|
},
|
|
836
1112
|
config: {
|
|
837
1113
|
rule: {
|
|
838
|
-
type: 'text'
|
|
1114
|
+
type: 'text',
|
|
1115
|
+
name: 'regex'
|
|
839
1116
|
}
|
|
840
1117
|
}
|
|
841
1118
|
}
|
|
@@ -850,6 +1127,14 @@
|
|
|
850
1127
|
number: "數字",
|
|
851
1128
|
"minimal length": "長度下限",
|
|
852
1129
|
"maximal length": "長度上限"
|
|
1130
|
+
},
|
|
1131
|
+
"en": {
|
|
1132
|
+
length: "Length",
|
|
1133
|
+
lte: "≦",
|
|
1134
|
+
range: "Range",
|
|
1135
|
+
number: "Number",
|
|
1136
|
+
"minimal length": "Min Length",
|
|
1137
|
+
"maximal length": "Max Length"
|
|
853
1138
|
}
|
|
854
1139
|
},
|
|
855
1140
|
ops: {
|
|
@@ -863,11 +1148,11 @@
|
|
|
863
1148
|
config: {
|
|
864
1149
|
min: {
|
|
865
1150
|
type: 'number',
|
|
866
|
-
|
|
1151
|
+
name: 'minimal length'
|
|
867
1152
|
},
|
|
868
1153
|
max: {
|
|
869
1154
|
type: 'number',
|
|
870
|
-
|
|
1155
|
+
name: 'maximal length'
|
|
871
1156
|
},
|
|
872
1157
|
method: {
|
|
873
1158
|
type: 'choice',
|
|
@@ -884,7 +1169,7 @@
|
|
|
884
1169
|
config: {
|
|
885
1170
|
val: {
|
|
886
1171
|
type: 'number',
|
|
887
|
-
|
|
1172
|
+
name: "maximal length"
|
|
888
1173
|
},
|
|
889
1174
|
method: {
|
|
890
1175
|
type: 'choice',
|
|
@@ -901,7 +1186,7 @@
|
|
|
901
1186
|
config: {
|
|
902
1187
|
val: {
|
|
903
1188
|
type: 'number',
|
|
904
|
-
|
|
1189
|
+
name: "minimal length"
|
|
905
1190
|
},
|
|
906
1191
|
method: {
|
|
907
1192
|
type: 'choice',
|
|
@@ -918,7 +1203,7 @@
|
|
|
918
1203
|
config: {
|
|
919
1204
|
val: {
|
|
920
1205
|
type: 'number',
|
|
921
|
-
|
|
1206
|
+
name: "length"
|
|
922
1207
|
},
|
|
923
1208
|
method: {
|
|
924
1209
|
type: 'choice',
|
|
@@ -937,7 +1222,17 @@
|
|
|
937
1222
|
gte: "≧ 大於或等於",
|
|
938
1223
|
ne: "≠ 不等於",
|
|
939
1224
|
eq: "= 等於",
|
|
940
|
-
is: "任何數字"
|
|
1225
|
+
is: "任何數字",
|
|
1226
|
+
"ref-val": "參考值"
|
|
1227
|
+
},
|
|
1228
|
+
"en": {
|
|
1229
|
+
number: "Number",
|
|
1230
|
+
lte: "≦ Equal/Less Than",
|
|
1231
|
+
gte: "≧ Equal/Greater Than",
|
|
1232
|
+
ne: "≠ Not Equals",
|
|
1233
|
+
eq: "= Equals",
|
|
1234
|
+
is: "Is Number",
|
|
1235
|
+
"ref-val": "Reference Value"
|
|
941
1236
|
}
|
|
942
1237
|
},
|
|
943
1238
|
convert: function(v){
|
|
@@ -956,7 +1251,7 @@
|
|
|
956
1251
|
config: {
|
|
957
1252
|
val: {
|
|
958
1253
|
type: 'text',
|
|
959
|
-
|
|
1254
|
+
name: "ref-val"
|
|
960
1255
|
}
|
|
961
1256
|
}
|
|
962
1257
|
},
|
|
@@ -972,7 +1267,7 @@
|
|
|
972
1267
|
config: {
|
|
973
1268
|
val: {
|
|
974
1269
|
type: 'text',
|
|
975
|
-
|
|
1270
|
+
name: "ref-val"
|
|
976
1271
|
}
|
|
977
1272
|
}
|
|
978
1273
|
},
|
|
@@ -988,7 +1283,7 @@
|
|
|
988
1283
|
config: {
|
|
989
1284
|
val: {
|
|
990
1285
|
type: 'text',
|
|
991
|
-
|
|
1286
|
+
name: "ref-val"
|
|
992
1287
|
}
|
|
993
1288
|
}
|
|
994
1289
|
},
|
|
@@ -1004,7 +1299,7 @@
|
|
|
1004
1299
|
config: {
|
|
1005
1300
|
val: {
|
|
1006
1301
|
type: 'text',
|
|
1007
|
-
|
|
1302
|
+
name: "ref-val"
|
|
1008
1303
|
}
|
|
1009
1304
|
}
|
|
1010
1305
|
},
|
|
@@ -1019,9 +1314,16 @@
|
|
|
1019
1314
|
id: 'date',
|
|
1020
1315
|
i18n: {
|
|
1021
1316
|
"zh-TW": {
|
|
1317
|
+
date: '日期',
|
|
1022
1318
|
"min age": "最小年齡",
|
|
1023
1319
|
"max age": "最大年齡",
|
|
1024
1320
|
age: "年齡"
|
|
1321
|
+
},
|
|
1322
|
+
"en": {
|
|
1323
|
+
date: 'Date',
|
|
1324
|
+
"min age": "Min Age",
|
|
1325
|
+
"max age": "Max Age",
|
|
1326
|
+
age: "Age"
|
|
1025
1327
|
}
|
|
1026
1328
|
},
|
|
1027
1329
|
convert: function(v){
|
|
@@ -1032,11 +1334,11 @@
|
|
|
1032
1334
|
config: {
|
|
1033
1335
|
min: {
|
|
1034
1336
|
type: 'number',
|
|
1035
|
-
|
|
1337
|
+
name: 'min age'
|
|
1036
1338
|
},
|
|
1037
1339
|
max: {
|
|
1038
1340
|
type: 'number',
|
|
1039
|
-
|
|
1341
|
+
name: 'max age'
|
|
1040
1342
|
}
|
|
1041
1343
|
},
|
|
1042
1344
|
func: function(v, c){
|
|
@@ -1272,11 +1574,9 @@
|
|
|
1272
1574
|
});
|
|
1273
1575
|
dig = JSON.stringify(v);
|
|
1274
1576
|
if (this._meta_dig !== dig) {
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
}
|
|
1278
|
-
this.fire('init');
|
|
1279
|
-
}
|
|
1577
|
+
this.fire('meta', this.serialize(), {
|
|
1578
|
+
init: o.init
|
|
1579
|
+
});
|
|
1280
1580
|
}
|
|
1281
1581
|
this._meta_dig = dig;
|
|
1282
1582
|
return Promise.resolve().then(function(){
|
|
@@ -1473,10 +1773,15 @@
|
|
|
1473
1773
|
return this.mod.adapt.apply(this, args);
|
|
1474
1774
|
}
|
|
1475
1775
|
},
|
|
1476
|
-
manager: function(){
|
|
1477
|
-
var ret;
|
|
1776
|
+
manager: function(arg$){
|
|
1777
|
+
var depth, ref$, ret;
|
|
1778
|
+
depth = (ref$ = (arg$ != null
|
|
1779
|
+
? arg$
|
|
1780
|
+
: {}).depth) != null ? ref$ : 0;
|
|
1478
1781
|
ret = this.mod && this.mod.manager
|
|
1479
|
-
? this.mod.manager.apply(this
|
|
1782
|
+
? this.mod.manager.apply(this, [{
|
|
1783
|
+
depth: depth
|
|
1784
|
+
}])
|
|
1480
1785
|
: [];
|
|
1481
1786
|
return (Array.isArray(ret)
|
|
1482
1787
|
? ret
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){var form,wordLen,countOps;form={};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._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)})},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,this$=this;opt==null&&(opt={});if(!v){ret={};for(p in ref$=this._ws.w){w=ref$[p];if(!(opt.partial&&w._meta.disabled)){ret[p]=w.value()}}return ret}v=JSON.parse(JSON.stringify(v));return Promise.resolve().then(function(){var ps,res$,p,ref$,w;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)})},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}});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]};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",hint:"maximal amount"}}},"count-min":{func:function(v,c){c==null&&(c={});return v.length>=c.val},config:{val:{type:"number",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",hint:"minimal amount"},max:{type:"number",hint:"maximal amount"}}},count:{func:function(v,c){c==null&&(c={});return v.length===c.val},config:{val:{type:"number",hint:"number of entries"}}}};form.opset["default"]=[{id:"list",i18n:{"zh-TW":{"count-max":"數量上限","count-min":"數量下限","count-range":"數量範圍",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":{"size-limit":"檔案大小上限","count-limit":"檔案數量上限",extension:"副檔名限制","count-max":"檔案數量上限","count-min":"檔案數量下限","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",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",hint:"extension, comma separated, without dot"}}},"count-limit":{func:function(v,c){c==null&&(c={});return v.length<c.val},config:{val:{type:"number",hint:"maximal file amount"}}}},countOps)},{id:"image",i18n:{"zh-TW":{"long-size":"長邊尺寸限制","short-size":"短邊尺寸限制",width:"寬度限制",height:"高度限制","pixel-count":"像素量限制"}},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",hint:"minimal size"},max:{type:"number",hint:"minimal size"}}}}(n[1])]}))},{id:"string",i18n:{"zh-TW":{string:"文字",include:"包含",exclude:"排除",email:"電子郵件",url:"網址",regex:"正規表達式"}},ops:{include:{func:function(v,c){c==null&&(c={});return~(""+(v||"")).indexOf(c.str||"")},config:{str:{type:"text"}}},exclude:{func:function(v,c){c==null&&(c={});return!~(""+(v||"")).indexOf(c.str||"")},config:{str:{type:"text"}}},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"}}}}},{id:"length",i18n:{"zh-TW":{length:"長度",lte:"≦ 小於或等於",range:"範圍",number:"數字","minimal length":"長度下限","maximal 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",hint:"minimal length"},max:{type:"number",hint:"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",hint:"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",hint:"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",hint:"length"},method:{type:"choice",default:"char",values:["char","simple-word"]}}}}},{id:"number",i18n:{"zh-TW":{number:"數字",lte:"≦ 小於或等於",gte:"≧ 大於或等於",ne:"≠ 不等於",eq:"= 等於",is:"任何數字"}},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",hint:"number for comparison"}}},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",hint:"number for comparison"}}},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",hint:"number for comparison"}}},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",hint:"number for comparison"}}},is:{func:function(v){return!isNaN(v)},config:{}}}},{id:"date",i18n:{"zh-TW":{"min age":"最小年齡","max age":"最大年齡",age:"年齡"}},convert:function(v){return new Date(v)},ops:{age:{config:{min:{type:"number",hint:"min age"},max:{type:"number",hint:"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){if(!o.init){this.fire("meta",this._meta)}else{this.fire("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(){var ret;ret=this.mod&&this.mod.manager?this.mod.manager.apply(this):[];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$;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,this$=this;opt==null&&(opt={});if(!v){ret={};for(p in ref$=this._ws.w){w=ref$[p];if(!(opt.partial&&w._meta.disabled)){ret[p]=w.value()}}return ret}v=JSON.parse(JSON.stringify(v));return Promise.resolve().then(function(){var ps,res$,p,ref$,w;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)})},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}});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);
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"zbryikt","name":"@plotdb/form","license":"MIT","description":"form blocks","version":"0.0
|
|
1
|
+
{"author":"zbryikt","name":"@plotdb/form","license":"MIT","description":"form blocks","version":"0.1.0","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.6.3","@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"}}
|