@plotdb/form 0.0.6 → 0.0.10
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 +21 -0
- package/index.js +142 -123
- package/index.min.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v0.0.10
|
|
4
|
+
|
|
5
|
+
- bug fix: `is-empty` of widget mod can't be executed correctly
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## v0.0.9
|
|
9
|
+
|
|
10
|
+
- bug fix: manager status isn't updated correctly due to status update logic incorrect
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## v0.0.8
|
|
14
|
+
|
|
15
|
+
- bug fix: race condition in value validation.
|
|
16
|
+
- spec changes: `mode`, `value`, `deserialize` now return Promise, resolves when validation is finished.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## v0.0.7
|
|
20
|
+
|
|
21
|
+
- bug fix: `manager.widget` doesn't work
|
|
22
|
+
|
|
23
|
+
|
|
3
24
|
## v0.0.6
|
|
4
25
|
|
|
5
26
|
- bug fix: widget status change isn't logged in form manager.
|
package/index.js
CHANGED
|
@@ -14,33 +14,36 @@
|
|
|
14
14
|
this._evthdr = {};
|
|
15
15
|
this._status = 1;
|
|
16
16
|
this._mode = 'edit';
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
} || {};
|
|
20
|
-
this.afterCheck = debounce(330, function(){
|
|
17
|
+
this._mod = {};
|
|
18
|
+
this._checkDebounced = debounce(10, function(){
|
|
21
19
|
var args, res$, i$, to$;
|
|
22
20
|
res$ = [];
|
|
23
21
|
for (i$ = 0, to$ = arguments.length; i$ < to$; ++i$) {
|
|
24
22
|
res$.push(arguments[i$]);
|
|
25
23
|
}
|
|
26
24
|
args = res$;
|
|
27
|
-
return this$.
|
|
25
|
+
return this$._check.apply(this$, args);
|
|
28
26
|
});
|
|
29
|
-
this.
|
|
27
|
+
this._restatusDebounced = debounce(10, function(){
|
|
30
28
|
var args, res$, i$, to$;
|
|
31
29
|
res$ = [];
|
|
32
30
|
for (i$ = 0, to$ = arguments.length; i$ < to$; ++i$) {
|
|
33
31
|
res$.push(arguments[i$]);
|
|
34
32
|
}
|
|
35
33
|
args = res$;
|
|
36
|
-
return this$.
|
|
34
|
+
return this$._restatus.apply(this$, args);
|
|
37
35
|
});
|
|
38
36
|
return this;
|
|
39
37
|
};
|
|
40
38
|
form.manager.prototype = import$(Object.create(Object.prototype), {
|
|
41
39
|
on: function(n, cb){
|
|
42
|
-
var
|
|
43
|
-
return (
|
|
40
|
+
var this$ = this;
|
|
41
|
+
return (Array.isArray(n)
|
|
42
|
+
? n
|
|
43
|
+
: [n]).map(function(n){
|
|
44
|
+
var ref$;
|
|
45
|
+
return ((ref$ = this$._evthdr)[n] || (ref$[n] = [])).push(cb);
|
|
46
|
+
});
|
|
44
47
|
},
|
|
45
48
|
fire: function(n){
|
|
46
49
|
var v, res$, i$, to$, ref$, len$, cb, results$ = [];
|
|
@@ -79,11 +82,12 @@
|
|
|
79
82
|
});
|
|
80
83
|
return w.on('status', this._ws.l[p].s = function(s){
|
|
81
84
|
this$._ws.s[p] = s;
|
|
82
|
-
|
|
85
|
+
this$.fire('status', {
|
|
83
86
|
widget: w,
|
|
84
87
|
path: p,
|
|
85
88
|
status: s
|
|
86
89
|
});
|
|
90
|
+
return this$._restatusDebounced();
|
|
87
91
|
});
|
|
88
92
|
},
|
|
89
93
|
remove: function(o){
|
|
@@ -103,12 +107,10 @@
|
|
|
103
107
|
return ref1$ = (ref$ = this._ws.l)[key$ = o.path], delete ref$[key$], ref1$;
|
|
104
108
|
},
|
|
105
109
|
widget: function(p){
|
|
106
|
-
return this._ws[p];
|
|
110
|
+
return this._ws.w[p];
|
|
107
111
|
},
|
|
108
|
-
status: function(
|
|
109
|
-
return
|
|
110
|
-
? this._status
|
|
111
|
-
: this._status = v;
|
|
112
|
+
status: function(){
|
|
113
|
+
return this._status;
|
|
112
114
|
},
|
|
113
115
|
progress: function(){
|
|
114
116
|
var ret, k, s;
|
|
@@ -134,50 +136,52 @@
|
|
|
134
136
|
ret.percent = ret.done / (ret.total || 1);
|
|
135
137
|
return ret;
|
|
136
138
|
},
|
|
137
|
-
|
|
139
|
+
_restatus: function(){
|
|
138
140
|
var os, ret, k, v;
|
|
139
141
|
os = this._status;
|
|
140
142
|
delete this._status;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}).length;
|
|
153
|
-
this._status = ret ? 1 : 0;
|
|
154
|
-
}
|
|
143
|
+
ret = (function(){
|
|
144
|
+
var ref$, results$ = [];
|
|
145
|
+
for (k in ref$ = this._ws.w) {
|
|
146
|
+
v = ref$[k];
|
|
147
|
+
results$.push(this._ws.s[k]);
|
|
148
|
+
}
|
|
149
|
+
return results$;
|
|
150
|
+
}.call(this)).filter(function(s){
|
|
151
|
+
return !(s != null && s === 0);
|
|
152
|
+
}).length;
|
|
153
|
+
this._status = ret ? 1 : 0;
|
|
155
154
|
if (os !== this._status) {
|
|
156
155
|
return this.fire('readystatechange', this._status === 0);
|
|
157
156
|
}
|
|
158
157
|
},
|
|
159
158
|
check: function(o, now){
|
|
160
|
-
var
|
|
159
|
+
var this$ = this;
|
|
161
160
|
now == null && (now = false);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
161
|
+
return Promise.resolve().then(function(){
|
|
162
|
+
var p, w;
|
|
163
|
+
if (!o) {
|
|
164
|
+
return this$.check((function(){
|
|
165
|
+
var ref$, results$ = [];
|
|
166
|
+
for (p in ref$ = this._ws.w) {
|
|
167
|
+
w = ref$[p];
|
|
168
|
+
results$.push({
|
|
169
|
+
widget: w,
|
|
170
|
+
path: p
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return results$;
|
|
174
|
+
}.call(this$)), now);
|
|
175
|
+
}
|
|
176
|
+
this$.checkList = (this$.checkList || (this$.checkList = [])).concat(Array.isArray(o)
|
|
177
|
+
? o
|
|
178
|
+
: [o]);
|
|
179
|
+
return now
|
|
180
|
+
? this$._check(null, true)
|
|
181
|
+
: this$._checkDebounced();
|
|
182
|
+
}).then(function(){
|
|
183
|
+
return this$._restatus();
|
|
184
|
+
});
|
|
181
185
|
},
|
|
182
186
|
_check: function(o, now){
|
|
183
187
|
var list, this$ = this;
|
|
@@ -208,22 +212,17 @@
|
|
|
208
212
|
p = this$._ws.p[w];
|
|
209
213
|
}
|
|
210
214
|
return w.validate().then(function(){
|
|
211
|
-
var os
|
|
215
|
+
var os;
|
|
212
216
|
os = this$._ws.s[p];
|
|
213
217
|
this$._ws.s[p] = w.status();
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
status: this$._ws.s[p]
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
return this$._ws.s[p];
|
|
226
|
-
});
|
|
218
|
+
if (os !== this$._ws.s[p]) {
|
|
219
|
+
this$.fire('status', {
|
|
220
|
+
path: p,
|
|
221
|
+
widget: w,
|
|
222
|
+
status: this$._ws.s[p]
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return this$._ws.s[p];
|
|
227
226
|
}).then(function(){
|
|
228
227
|
if (this$._ws.s[p] === 2) {
|
|
229
228
|
return res({
|
|
@@ -255,7 +254,7 @@
|
|
|
255
254
|
return fd;
|
|
256
255
|
},
|
|
257
256
|
value: function(v, opt){
|
|
258
|
-
var ret, p, ref$, w
|
|
257
|
+
var ret, p, ref$, w;
|
|
259
258
|
opt == null && (opt = {});
|
|
260
259
|
if (!v) {
|
|
261
260
|
ret = {};
|
|
@@ -265,14 +264,17 @@
|
|
|
265
264
|
}
|
|
266
265
|
return ret;
|
|
267
266
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
267
|
+
return Promise.all((function(){
|
|
268
|
+
var ref$, results$ = [];
|
|
269
|
+
for (p in ref$ = this._ws.w) {
|
|
270
|
+
w = ref$[p];
|
|
271
|
+
results$.push(w.value(v[p], opt));
|
|
272
|
+
}
|
|
273
|
+
return results$;
|
|
274
|
+
}.call(this)));
|
|
273
275
|
},
|
|
274
276
|
mode: function(m){
|
|
275
|
-
var ref$, p, w
|
|
277
|
+
var ref$, p, w;
|
|
276
278
|
if (!(m != null)) {
|
|
277
279
|
return this._mode;
|
|
278
280
|
}
|
|
@@ -284,11 +286,14 @@
|
|
|
284
286
|
}
|
|
285
287
|
this._mode = m;
|
|
286
288
|
this.fire('mode', m);
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
289
|
+
return Promise.all((function(){
|
|
290
|
+
var ref$, results$ = [];
|
|
291
|
+
for (p in ref$ = this._ws.w) {
|
|
292
|
+
w = ref$[p];
|
|
293
|
+
results$.push(w.mode(m));
|
|
294
|
+
}
|
|
295
|
+
return results$;
|
|
296
|
+
}.call(this)));
|
|
292
297
|
}
|
|
293
298
|
});
|
|
294
299
|
form.op = function(opt){
|
|
@@ -739,7 +744,7 @@
|
|
|
739
744
|
return ret;
|
|
740
745
|
},
|
|
741
746
|
deserialize: function(v){
|
|
742
|
-
var ref
|
|
747
|
+
var ref$, this$ = this;
|
|
743
748
|
ref$ = this._meta;
|
|
744
749
|
ref$.key = v.key;
|
|
745
750
|
ref$.title = v.title;
|
|
@@ -748,78 +753,92 @@
|
|
|
748
753
|
this._meta.term = (v.term || []).map(function(it){
|
|
749
754
|
return new form.term(it);
|
|
750
755
|
});
|
|
751
|
-
this.validate({
|
|
756
|
+
return this.validate({
|
|
752
757
|
init: true
|
|
758
|
+
}).then(function(){
|
|
759
|
+
return this$.render();
|
|
753
760
|
});
|
|
754
|
-
return this.render();
|
|
755
761
|
},
|
|
756
762
|
mode: function(m){
|
|
757
|
-
var
|
|
763
|
+
var this$ = this;
|
|
758
764
|
if (!(m != null)) {
|
|
759
765
|
return this._mode;
|
|
760
766
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
767
|
+
return Promise.resolve().then(function(){
|
|
768
|
+
var ref$;
|
|
769
|
+
if (!(m === 'edit' || m === 'view' || m === 'config')) {
|
|
770
|
+
return Promise.reject((ref$ = new Error(), ref$.name = 'lderror', ref$.id = 1015, ref$));
|
|
771
|
+
}
|
|
772
|
+
if (this$._mode === m) {
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
this$._mode = m;
|
|
776
|
+
this$.fire('mode', m);
|
|
777
|
+
return this$.validate({
|
|
778
|
+
init: true
|
|
779
|
+
}).then(function(){
|
|
780
|
+
return this$.render();
|
|
781
|
+
});
|
|
771
782
|
});
|
|
772
|
-
return this.render();
|
|
773
783
|
},
|
|
774
784
|
errors: function(){
|
|
775
785
|
return this._errors;
|
|
776
786
|
},
|
|
777
787
|
value: function(v, opt){
|
|
788
|
+
var this$ = this;
|
|
778
789
|
opt == null && (opt = {});
|
|
779
790
|
if (!(v != null)) {
|
|
780
791
|
return this._value;
|
|
781
792
|
}
|
|
782
793
|
this._value = v;
|
|
783
794
|
this._empty = this.mod && this.mod.isEmpty
|
|
784
|
-
? this.mod.isEmpty.
|
|
795
|
+
? this.mod.isEmpty.call(this, v)
|
|
785
796
|
: !v;
|
|
786
|
-
this.validate({
|
|
797
|
+
return this.validate({
|
|
787
798
|
init: opt.init
|
|
799
|
+
}).then(function(){
|
|
800
|
+
if (!opt.fromSource) {
|
|
801
|
+
return this$.fire('change', this$._value);
|
|
802
|
+
}
|
|
788
803
|
});
|
|
789
|
-
if (!opt.fromSource) {
|
|
790
|
-
return this.fire('change', this._value);
|
|
791
|
-
}
|
|
792
804
|
},
|
|
793
805
|
validate: function(opt){
|
|
794
|
-
var this$ = this;
|
|
806
|
+
var v, this$ = this;
|
|
795
807
|
opt == null && (opt = {});
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
this.
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
return
|
|
811
|
-
return
|
|
812
|
-
})
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
}).
|
|
817
|
-
|
|
808
|
+
v = this._value;
|
|
809
|
+
return Promise.resolve().then(function(){
|
|
810
|
+
if (this$.mod && this$.mod.validate) {
|
|
811
|
+
return this$.mod.validate.apply(this$, this$._value);
|
|
812
|
+
}
|
|
813
|
+
if (this$._validate) {
|
|
814
|
+
return this$._validate(this$._value);
|
|
815
|
+
}
|
|
816
|
+
if (this$._empty && this$._meta.config.isRequired) {
|
|
817
|
+
this$._errors = ["required"];
|
|
818
|
+
this$.status(opt.init ? 1 : 2);
|
|
819
|
+
this$.render();
|
|
820
|
+
return this$._errors;
|
|
821
|
+
}
|
|
822
|
+
return Promise.all(this$._meta.term.filter(function(t){
|
|
823
|
+
return t.enabled;
|
|
824
|
+
}).map(function(t){
|
|
825
|
+
return t.validate(this$._value).then(function(v){
|
|
826
|
+
return [t, v];
|
|
827
|
+
});
|
|
828
|
+
})).then(function(it){
|
|
829
|
+
if (v !== this$._value) {
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
this$._errors = it.filter(function(it){
|
|
833
|
+
return !it[1];
|
|
834
|
+
}).map(function(it){
|
|
835
|
+
return it[0].msg || 'error';
|
|
836
|
+
});
|
|
837
|
+
this$.status(this$._errors.length ? 2 : 0);
|
|
838
|
+
return this$.render();
|
|
839
|
+
}).then(function(){
|
|
840
|
+
return this$._errors;
|
|
818
841
|
});
|
|
819
|
-
this$.status(this$._errors.length ? 2 : 0);
|
|
820
|
-
return this$.render();
|
|
821
|
-
}).then(function(){
|
|
822
|
-
return this$._errors;
|
|
823
842
|
});
|
|
824
843
|
},
|
|
825
844
|
render: function(){
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){var form;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={afterCheck:o.mod.afterCheck}||{};this.afterCheck=debounce(330,function(){var args,res$,i$,to$;res$=[];for(i$=0,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}args=res$;return this$._afterCheck.apply(this$,args)});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)});return this};form.manager.prototype=import$(Object.create(Object.prototype),{on:function(n,cb){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.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;return this$.fire("status",{widget:w,path:p,status:s})})},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}o.off("change",this._ws.l[o.path].c);o.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[p]},status:function(v){return!(v!=null)?this._status:this._status=v},progress:function(){var ret,k,s;ret={total:function(){var results$=[];for(k in this._ws.w){results$.push(k)}return results$}.call(this).length,done:function(){var ref$,results$=[];for(k in ref$=this._ws.s){s=ref$[k];results$.push(s)}return results$}.call(this).filter(function(s){return s!=null&&s===0}).length};ret.percent=ret.done/(ret.total||1);return ret},_afterCheck:function(){var os,ret,k,v;os=this._status;delete this._status;this.mod.afterCheck.apply(this);if(!(this._status!=null)){ret=function(){var ref$,results$=[];for(k in ref$=this._ws.w){v=ref$[k];results$.push(this._ws.s[k])}return results$}.call(this).filter(function(s){return!(s!=null&&s===0)}).length;this._status=ret?1:0}if(os!==this._status){return this.fire("readystatechange",this._status===0)}},check:function(o,now){var p,w;now==null&&(now=false);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),now)}this.checkList=(this.checkList||(this.checkList=[])).concat(Array.isArray(o)?o:[o]);return now?this._check(null,true):this._checkDebounced()},_check:function(o,now){var list,this$=this;if(!o){list=this.checkList||[];this.checkList=[];return this._check(list,now)}if(Array.isArray(o)){return Promise.all(o.map(function(it){return this$._check(it,now)})).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().then(function(){var os,promise;os=this$._ws.s[p];this$._ws.s[p]=w.status();promise=now||_now?Promise.resolve(this$.afterCheck().now()):this$.afterCheck();return promise.then(function(){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];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,results$=[];opt==null&&(opt={});if(!v){ret={};for(p in ref$=this._ws.w){w=ref$[p];ret[p]=w.value()}return ret}for(p in ref$=this._ws.w){w=ref$[p];results$.push(w.value(v[p],opt))}return results$},mode:function(m){var ref$,p,w,results$=[];if(!(m!=null)){return this._mode}if(!(m==="edit"||m==="view"||m==="config")){throw ref$=new Error,ref$.name="lderror",ref$.id=1015,ref$}if(this._mode===m){return}this._mode=m;this.fire("mode",m);for(p in ref$=this._ws.w){w=ref$[p];results$.push(w.mode(m))}return results$}});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["default"]=[{id:"string",i18n:{"zh-TW":{string:"文字",include:"包含",exclude:"排除",email:"電子郵件"}},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:{}}}},{id:"length",i18n:{"zh-TW":{length:"長度",lte:"≦ 小於或等於",number:"數字","maximal length":"長度上限"}},ops:{lte:{func:function(v,c){c==null&&(c={});return(v+"").length<=+c.val},config:{val:{type:"number",hint:"maximal length"}}}}},{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:{}}}}];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}},deserialize:function(v){this.toggle(v.enabled);return this.setOpset(v.opset,v.op,v.config)}});form.widget=function(opt){var 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._value=null;this._empty=true;this._mode=opt.mode||"edit";this._validate=opt.validate||null;this._opsets=(opt.opsets||[]).map(function(opset){if(typeof opset==="string"){return form.opset.get(opset)}else if(typeof opset===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._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(){return Promise.resolve(this.mod&&this.mod.init?this.mod.init.apply(this):"")},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$);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){var ref$;ref$=this._meta;ref$.key=v.key;ref$.title=v.title;ref$.desc=v.desc;this._meta.config=JSON.parse(JSON.stringify(v.config||{}));this._meta.term=(v.term||[]).map(function(it){return new form.term(it)});this.validate({init:true});return this.render()},mode:function(m){var ref$;if(!(m!=null)){return this._mode}if(!(m==="edit"||m==="view"||m==="config")){throw ref$=new Error,ref$.name="lderror",ref$.id=1015,ref$}if(this._mode===m){return}this._mode=m;this.fire("mode",m);this.validate({init:true});return this.render()},errors:function(){return this._errors},value:function(v,opt){opt==null&&(opt={});if(!(v!=null)){return this._value}this._value=v;this._empty=this.mod&&this.mod.isEmpty?this.mod.isEmpty.apply(this,v):!v;this.validate({init:opt.init});if(!opt.fromSource){return this.fire("change",this._value)}},validate:function(opt){var this$=this;opt==null&&(opt={});if(this.mod&&this.mod.validate){return this.mod.validate.apply(this,this._value)}if(this._validate){return Promise.resolve(this._validate(this._value))}if(this._empty&&this._meta.config.isRequired){this._errors=["required"];this.status(opt.init?1:2);return this.render()}return Promise.all(this._meta.term.filter(function(t){return t.enabled}).map(function(t){return t.validate(this$._value).then(function(v){return[t,v]})})).then(function(it){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)}}});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}}).call(this);
|
|
1
|
+
(function(){var form;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.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;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}o.off("change",this._ws.l[o.path].c);o.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]},status:function(){return this._status},progress:function(){var ret,k,s;ret={total:function(){var results$=[];for(k in this._ws.w){results$.push(k)}return results$}.call(this).length,done:function(){var ref$,results$=[];for(k in ref$=this._ws.s){s=ref$[k];results$.push(s)}return results$}.call(this).filter(function(s){return s!=null&&s===0}).length};ret.percent=ret.done/(ret.total||1);return ret},_restatus:function(){var os,ret,k,v;os=this._status;delete this._status;ret=function(){var ref$,results$=[];for(k in ref$=this._ws.w){v=ref$[k];results$.push(this._ws.s[k])}return results$}.call(this).filter(function(s){return!(s!=null&&s===0)}).length;this._status=ret?1:0;if(os!==this._status){return this.fire("readystatechange",this._status===0)}},check:function(o,now){var this$=this;now==null&&(now=false);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$),now)}this$.checkList=(this$.checkList||(this$.checkList=[])).concat(Array.isArray(o)?o:[o]);return now?this$._check(null,true):this$._checkDebounced()}).then(function(){return this$._restatus()})},_check:function(o,now){var list,this$=this;if(!o){list=this.checkList||[];this.checkList=[];return this._check(list,now)}if(Array.isArray(o)){return Promise.all(o.map(function(it){return this$._check(it,now)})).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().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];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;opt==null&&(opt={});if(!v){ret={};for(p in ref$=this._ws.w){w=ref$[p];ret[p]=w.value()}return ret}return Promise.all(function(){var ref$,results$=[];for(p in ref$=this._ws.w){w=ref$[p];results$.push(w.value(v[p],opt))}return results$}.call(this))},mode:function(m){var ref$,p,w;if(!(m!=null)){return this._mode}if(!(m==="edit"||m==="view"||m==="config")){throw 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.mode(m))}return results$}.call(this))}});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["default"]=[{id:"string",i18n:{"zh-TW":{string:"文字",include:"包含",exclude:"排除",email:"電子郵件"}},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:{}}}},{id:"length",i18n:{"zh-TW":{length:"長度",lte:"≦ 小於或等於",number:"數字","maximal length":"長度上限"}},ops:{lte:{func:function(v,c){c==null&&(c={});return(v+"").length<=+c.val},config:{val:{type:"number",hint:"maximal length"}}}}},{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:{}}}}];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}},deserialize:function(v){this.toggle(v.enabled);return this.setOpset(v.opset,v.op,v.config)}});form.widget=function(opt){var 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._value=null;this._empty=true;this._mode=opt.mode||"edit";this._validate=opt.validate||null;this._opsets=(opt.opsets||[]).map(function(opset){if(typeof opset==="string"){return form.opset.get(opset)}else if(typeof opset===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._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(){return Promise.resolve(this.mod&&this.mod.init?this.mod.init.apply(this):"")},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$);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){var ref$,this$=this;ref$=this._meta;ref$.key=v.key;ref$.title=v.title;ref$.desc=v.desc;this._meta.config=JSON.parse(JSON.stringify(v.config||{}));this._meta.term=(v.term||[]).map(function(it){return new form.term(it)});return this.validate({init:true}).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 this$=this;opt==null&&(opt={});if(!(v!=null)){return this._value}this._value=v;this._empty=this.mod&&this.mod.isEmpty?this.mod.isEmpty.call(this,v):!v;return this.validate({init:opt.init}).then(function(){if(!opt.fromSource){return this$.fire("change",this$._value)}})},validate:function(opt){var v,this$=this;opt==null&&(opt={});v=this._value;return Promise.resolve().then(function(){if(this$.mod&&this$.mod.validate){return this$.mod.validate.apply(this$,this$._value)}if(this$._validate){return this$._validate(this$._value)}if(this$._empty&&this$._meta.config.isRequired){this$._errors=["required"];this$.status(opt.init?1:2);this$.render();return this$._errors}return Promise.all(this$._meta.term.filter(function(t){return t.enabled}).map(function(t){return t.validate(this$._value).then(function(v){return[t,v]})})).then(function(it){if(v!==this$._value){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)}}});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}}).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.0.10","browser":"index.min.js","main":"index.min.js","homepage":"https://github.com/plotdb/form","repository":{"type":"git","url":"https://github.com/plotdb/form"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true"},"devDependencies":{"@loadingio/bootstrap.ext":"^0.0.4","@loadingio/debounce.js":"^1.0.1","@loadingio/ldquery":"^3.0.2","@plotdb/datadom":"^0.2.0","@plotdb/datahub":"^0.2.2","@plotdb/semver":"^0.0.2","@zbryikt/deploy":"^0.0.1","@zbryikt/template":"^2.3.33","bootstrap":"^4.5.3","bootstrap.native":"^3.0.13","fedep":"^1.1.2","i18next":"^19.9.2","ldcover":"^3.0.1","ldiconfont":"^0.1.10","ldview":"^1.0.0","livescript":"^1.6.0","stylus":"^0.55.0","uglify-js":"^3.13.1","uglifycss":"^0.0.29"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["bootstrap","@loadingio/bootstrap.ext","bootstrap.native","ldcover","@loadingio/ldquery","@loadingio/debounce.js","@loadingio/ldcolorpicker","ldview","ldiconfont","ldslider","ldcolor","ldpalettepicker","curegex","dompurify","proxise","i18next","@plotdb/sheet","@plotdb/block","@plotdb/datadom","@plotdb/datahub","@plotdb/semver","@plotdb/rescope","@plotdb/suuid","@plotdb/konfig","@plotdb/csscope"]},"dependencies":{"@loadingio/ldcolorpicker":"^3.0.0","@plotdb/block":"^4.1.0","@plotdb/csscope":"^4.0.0","@plotdb/datadom":"^0.2.0","@plotdb/konfig":"^4.0.1","@plotdb/rescope":"^4.1.0","@plotdb/sheet":"^0.2.0","@plotdb/suuid":"^0.5.0","curegex":"^0.0.4","dompurify":"^2.2.6","ldcolor":"^1.0.0","ldpalettepicker":"^4.0.0","ldslider":"^3.0.2","proxise":"^1.0.1"}}
|