@plotdb/form 0.0.1

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 ADDED
@@ -0,0 +1,5 @@
1
+ # Change Logs
2
+
3
+ ## v0.0.1
4
+
5
+ - initial release
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @plotdb/form
2
+
3
+ Form related modules for interactive form design throught GUI, with following (expected, TODO) features:
4
+
5
+ - design a form through GUI.
6
+ - designed form serializable and renderable in frontend for end users to fill.
7
+ - end user filled result of a form is also serializable.
8
+ - Aware of OT for collaborative editing.
9
+ - Works in both frontend and backend.
10
+
11
+
12
+ `@plotdb/form` includes following modules:
13
+
14
+ - `form.manager`: manage a set of form widgets.
15
+ - `form.widget`: interface between form manager and UI.
16
+ - `form.opset`: a set of op for validating given input from user.
17
+ - `form.op`: a specific operation for validating given input from user.
18
+ - `form.term`: a rule ( a op, opset and config based on the specified op ) for validating given input from user.
19
+
20
+
21
+ ## Draft
22
+
23
+ ### form.block attrubite
24
+
25
+ An attribute is an aspect of data from a form.block. For example, a File form.block could contains following attributes:
26
+
27
+ - `size` - size of all files combined.
28
+ - `count` - count of files.
29
+ - `modifiedtime` - modified time of last touched files.
30
+ - `ext` - type of files.
31
+
32
+ Every attribute can be associated with one or multiple `form.opset` For example, above `ext` attribute can be associated with `extensions` type, which helps in determining if files in a given `ext` array all belong to certain file type.
33
+
package/index.js ADDED
@@ -0,0 +1,526 @@
1
+ // Generated by LiveScript 1.6.0
2
+ (function(){
3
+ var form;
4
+ form = {};
5
+ form.manager = function(){
6
+ this._fields = [];
7
+ return this;
8
+ };
9
+ form.manager.prototype = import$(Object.create(Object.prototype), {
10
+ add: function(it){
11
+ return this._fields = this._fields.concat(Array.isArray(it)
12
+ ? it
13
+ : [it]);
14
+ },
15
+ fields: function(){
16
+ return this._fields;
17
+ },
18
+ serialize: function(){
19
+ return this._fields.map(function(it){
20
+ return it.serialize();
21
+ });
22
+ },
23
+ value: function(vs){
24
+ var k, v, f, results$ = [];
25
+ if (!vs) {
26
+ return Object.fromEntries(this._fields.map(function(it){
27
+ return [it.key(), it.value()];
28
+ }));
29
+ }
30
+ for (k in vs) {
31
+ v = vs[k];
32
+ f = this._fields.filter(fn$)[0];
33
+ if (!f) {
34
+ continue;
35
+ }
36
+ results$.push(f.value(v));
37
+ }
38
+ return results$;
39
+ function fn$(it){
40
+ return it.key() === k;
41
+ }
42
+ },
43
+ mode: function(m){
44
+ return this._fields.map(function(it){
45
+ return it.mode(m);
46
+ });
47
+ }
48
+ });
49
+ form.op = function(opt){
50
+ opt == null && (opt = {});
51
+ this.id = opt.id;
52
+ this.name = opt.name;
53
+ this.config = opt.config;
54
+ this.func = opt.func;
55
+ this.i18n = opt.i18n;
56
+ return this;
57
+ };
58
+ form.op.prototype = import$(Object.create(Object.prototype), {
59
+ validate: function(val, cfg){
60
+ var ret;
61
+ cfg == null && (cfg = {});
62
+ if ((ret = this.func(val, cfg)) instanceof Promise) {
63
+ return ret;
64
+ } else {
65
+ return Promise.resolve(!!ret);
66
+ }
67
+ },
68
+ configDefault: function(){
69
+ var cfg, k, ref$, v;
70
+ cfg = {};
71
+ for (k in ref$ = this.config) {
72
+ v = ref$[k];
73
+ cfg[k] = v['default'];
74
+ }
75
+ return cfg;
76
+ }
77
+ });
78
+ form.opset = function(opt){
79
+ var ops, k, v, this$ = this;
80
+ opt == null && (opt = {});
81
+ this.name = opt.name;
82
+ this.id = opt.id;
83
+ this.i18n = opt.i18n;
84
+ this.ops = {};
85
+ ops = Array.isArray(opt.ops)
86
+ ? opt.ops.map(function(it){
87
+ return {
88
+ v: it,
89
+ k: it.id
90
+ };
91
+ })
92
+ : (function(){
93
+ var ref$, results$ = [];
94
+ for (k in ref$ = opt.ops) {
95
+ v = ref$[k];
96
+ results$.push({
97
+ k: k,
98
+ v: v
99
+ });
100
+ }
101
+ return results$;
102
+ }());
103
+ ops.map(function(arg$){
104
+ var k, v, ref$, ref1$, results$ = [];
105
+ k = arg$.k, v = arg$.v;
106
+ this$.ops[k] = v instanceof form.op
107
+ ? v
108
+ : k
109
+ ? new form.op((ref$ = typeof v === 'function' ? {
110
+ func: v
111
+ } : v, ref$.id = k, ref$))
112
+ : (function(){
113
+ throw new Error('[@plotdb/form/opset] invalid op when initializing opset.');
114
+ }());
115
+ for (k in ref$ = opt.ops) {
116
+ v = ref$[k];
117
+ results$.push(this$.ops[k] = new form.op((ref1$ = typeof v === 'function' ? {
118
+ func: v
119
+ } : v, ref1$.name = k, ref1$.id = k, ref1$)));
120
+ }
121
+ return results$;
122
+ });
123
+ this.defaultOp = this.ops[opt.defaultOp]
124
+ ? opt.defaultOp
125
+ : (function(){
126
+ var ref$, results$ = [];
127
+ for (k in ref$ = this.ops) {
128
+ v = ref$[k];
129
+ results$.push(k);
130
+ }
131
+ return results$;
132
+ }.call(this))[0];
133
+ return this;
134
+ };
135
+ form.opset.prototype = import$(Object.create(Object.prototype), {
136
+ getOp: function(id){
137
+ return this.ops[id || this.defaultOp];
138
+ },
139
+ getOps: function(){
140
+ var k, ref$, v, results$ = [];
141
+ for (k in ref$ = this.ops) {
142
+ v = ref$[k];
143
+ results$.push(v);
144
+ }
145
+ return results$;
146
+ }
147
+ });
148
+ form.opset.register = function(it){
149
+ return (this.list || (this.list = [])).push(it instanceof form.opset
150
+ ? it
151
+ : new form.opset(it));
152
+ };
153
+ form.opset.get = function(id){
154
+ return (this.list || (this.list = [])).filter(function(it){
155
+ return (it.id || it.name) === id;
156
+ })[0];
157
+ };
158
+ form.opset['default'] = [
159
+ {
160
+ id: 'string',
161
+ i18n: {
162
+ "zh-TW": {
163
+ string: "文字",
164
+ include: "包含",
165
+ exclude: "排除",
166
+ email: "電子郵件"
167
+ }
168
+ },
169
+ ops: {
170
+ include: {
171
+ func: function(v, c){
172
+ c == null && (c = {});
173
+ return ~("" + (v || '')).indexOf(c.str || '');
174
+ },
175
+ config: {
176
+ str: {
177
+ type: 'text'
178
+ }
179
+ }
180
+ },
181
+ exclude: {
182
+ func: function(v, c){
183
+ c == null && (c = {});
184
+ return !~("" + (v || '')).indexOf(c.str || '');
185
+ },
186
+ config: {
187
+ str: {
188
+ type: 'text'
189
+ }
190
+ }
191
+ },
192
+ email: {
193
+ func: function(v){
194
+ return /^[^@]+@[^@]+$/.exec(v);
195
+ },
196
+ config: {}
197
+ }
198
+ }
199
+ }, {
200
+ id: 'number',
201
+ i18n: {
202
+ "zh-TW": {
203
+ number: "數字",
204
+ lte: "≦ 小於或等於",
205
+ gte: "≧ 大於或等於",
206
+ ne: "≠ 不等於",
207
+ eq: "= 等於"
208
+ }
209
+ },
210
+ ops: {
211
+ lte: {
212
+ func: function(v, c){
213
+ c == null && (c = {});
214
+ if (isNaN(v) || isNaN(c.val)) {
215
+ return false;
216
+ } else {
217
+ return +v <= +c.val;
218
+ }
219
+ },
220
+ config: {
221
+ val: {
222
+ type: 'text',
223
+ hint: "number for comparison"
224
+ }
225
+ }
226
+ },
227
+ gte: {
228
+ func: function(v, c){
229
+ c == null && (c = {});
230
+ if (isNaN(v) || isNaN(c.val)) {
231
+ return false;
232
+ } else {
233
+ return +v >= +c.val;
234
+ }
235
+ },
236
+ config: {
237
+ val: {
238
+ type: 'text',
239
+ hint: "number for comparison"
240
+ }
241
+ }
242
+ },
243
+ ne: {
244
+ func: function(v, c){
245
+ c == null && (c = {});
246
+ if (isNaN(v) || isNaN(c.val)) {
247
+ return false;
248
+ } else {
249
+ return +v !== +c.val;
250
+ }
251
+ },
252
+ config: {
253
+ val: {
254
+ type: 'text',
255
+ hint: "number for comparison"
256
+ }
257
+ }
258
+ },
259
+ eq: {
260
+ func: function(v, c){
261
+ c == null && (c = {});
262
+ if (isNaN(v) || isNaN(c.val)) {
263
+ return false;
264
+ } else {
265
+ return +v === +c.val;
266
+ }
267
+ },
268
+ config: {
269
+ val: {
270
+ type: 'text',
271
+ hint: "number for comparison"
272
+ }
273
+ }
274
+ }
275
+ }
276
+ }
277
+ ];
278
+ form.opset['default'].map(function(it){
279
+ return form.opset.register(it);
280
+ });
281
+ /**
282
+ * term, for verification of values based on assigned op and config.
283
+ * @constructor
284
+ * @param {boolean} enabled - determine if this term is enabled or not
285
+ * @param {string} opset - id of opset used by this term.
286
+ * @param {string} op - id of op used by this term
287
+ * @param {object} config - additional config for chosen op.
288
+ */
289
+ form.term = function(opt){
290
+ opt == null && (opt = {});
291
+ import$((this.enabled = true, this.opset = null, this.op = null, this.config = {}, this), opt);
292
+ this.setOpset(opt.opset, opt.op, opt.config);
293
+ return this;
294
+ };
295
+ form.term.prototype = import$(Object.create(Object.prototype), {
296
+ toggle: function(it){
297
+ return this.enabled = it != null
298
+ ? it
299
+ : !this.enabled;
300
+ },
301
+ setOpset: function(opset, op, cfg){
302
+ if (typeof opset === 'string') {
303
+ if (!(this.opset = form.opset.get(opset))) {
304
+ throw new Error("no such opset '" + opset + "'");
305
+ }
306
+ } else if (opset instanceof form.opset) {
307
+ this.opset = opset;
308
+ } else {
309
+ throw new Error("invalid opset");
310
+ }
311
+ return this.setOp(op, cfg);
312
+ },
313
+ setOp: function(id, cfg){
314
+ if (!this.opset) {
315
+ throw new Error("opset not set");
316
+ }
317
+ if (!(this.op = this.opset.getOp(id))) {
318
+ throw new Error("no such op '" + id + "'");
319
+ }
320
+ return this.setConfig(cfg);
321
+ },
322
+ setConfig: function(cfg){
323
+ if (!this.op) {
324
+ throw new Error("op not set");
325
+ }
326
+ return this.config = !cfg ? this.op.configDefault() : cfg;
327
+ },
328
+ validate: function(v){
329
+ if (!this.op) {
330
+ Promis.reject(new Error("op not set"));
331
+ }
332
+ return this.op.validate(v, this.config);
333
+ },
334
+ serialize: function(){
335
+ return {
336
+ enabled: this.enabled,
337
+ opset: this.opset.id,
338
+ op: this.op.id,
339
+ config: this.config
340
+ };
341
+ },
342
+ deserialize: function(v){
343
+ this.toggle(v.enabled);
344
+ return this.setOpset(v.opset, v.op, v.config);
345
+ }
346
+ });
347
+ form.widget = function(opt){
348
+ var this$ = this;
349
+ opt == null && (opt = {});
350
+ this.root = typeof opt.root === 'string'
351
+ ? document.querySelector(opt.root)
352
+ : opt.root;
353
+ this.evtHandler = {};
354
+ this.mod = opt.mod || null;
355
+ this.i18n = {};
356
+ this._custom = {};
357
+ this._meta = {
358
+ config: {},
359
+ key: Math.random().toString(36).substring(2)
360
+ };
361
+ this._value = null;
362
+ this._empty = true;
363
+ this._mode = opt.mode || 'view';
364
+ this._validate = opt.validate || null;
365
+ this._opsets = (opt.opsets || []).map(function(opset){
366
+ if (typeof opset === 'string') {
367
+ return form.opset.get(opset);
368
+ } else if (typeof opset === form.opset) {
369
+ return opset;
370
+ } else {
371
+ return new form.opset(opset);
372
+ }
373
+ });
374
+ this._opsets.filter(function(it){
375
+ return it.i18n;
376
+ }).map(function(it){
377
+ var k, ref$, v, ref1$, results$ = [];
378
+ for (k in ref$ = it.i18n) {
379
+ v = ref$[k];
380
+ results$.push(import$((ref1$ = this$.i18n)[k] || (ref1$[k] = {}), v));
381
+ }
382
+ return results$;
383
+ });
384
+ this._errors = [];
385
+ this.init = proxise.once(function(){
386
+ return this$._init();
387
+ });
388
+ return this;
389
+ };
390
+ form.widget.prototype = import$(Object.create(Object.prototype), {
391
+ on: function(n, cb){
392
+ var this$ = this;
393
+ return (Array.isArray(n)
394
+ ? n
395
+ : [n]).map(function(n){
396
+ var ref$;
397
+ return ((ref$ = this$.evtHandler)[n] || (ref$[n] = [])).push(cb);
398
+ });
399
+ },
400
+ fire: function(n){
401
+ var v, res$, i$, to$, ref$, len$, cb, results$ = [];
402
+ res$ = [];
403
+ for (i$ = 1, to$ = arguments.length; i$ < to$; ++i$) {
404
+ res$.push(arguments[i$]);
405
+ }
406
+ v = res$;
407
+ for (i$ = 0, len$ = (ref$ = this.evtHandler[n] || []).length; i$ < len$; ++i$) {
408
+ cb = ref$[i$];
409
+ results$.push(cb.apply(this, v));
410
+ }
411
+ return results$;
412
+ },
413
+ _init: function(){
414
+ return Promise.resolve(this.mod && this.mod.init ? this.mod.init.apply(this) : '');
415
+ },
416
+ key: function(keyonly){
417
+ keyonly == null && (keyonly = false);
418
+ return keyonly
419
+ ? this._meta.key
420
+ : this._meta.alias || this._meta.key;
421
+ },
422
+ serialize: function(){
423
+ var ref$, ret, ref1$;
424
+ ret = (ref1$ = {}, ref1$.key = (ref$ = this._meta).key, ref1$.title = ref$.title, ref1$.desc = ref$.desc, ref1$);
425
+ ret.config = JSON.parse(JSON.stringify(this._meta.config || {}));
426
+ ret.term = this._meta.term.map(function(it){
427
+ return it.serialize();
428
+ });
429
+ return ret;
430
+ },
431
+ deserialize: function(v){
432
+ var ref$;
433
+ ref$ = this._meta;
434
+ ref$.key = v.key;
435
+ ref$.title = v.title;
436
+ ref$.desc = v.desc;
437
+ this._meta.config = JSON.parse(JSON.stringify(v.config || {}));
438
+ this._meta.term = (v.term || []).map(function(it){
439
+ return new form.term(it);
440
+ });
441
+ this.validate();
442
+ return this.render();
443
+ },
444
+ mode: function(it){
445
+ if (!(it != null)) {
446
+ return this._mode;
447
+ }
448
+ this._mode = it;
449
+ this.validate();
450
+ return this.render();
451
+ },
452
+ errors: function(){
453
+ return this._errors;
454
+ },
455
+ value: function(v, fromSource){
456
+ fromSource == null && (fromSource = false);
457
+ if (!(v != null)) {
458
+ return this._value;
459
+ }
460
+ this._value = v;
461
+ this._empty = this.mod && this.mod.isEmpty
462
+ ? this.mod.isEmpty.apply(this, v)
463
+ : !v;
464
+ this.validate();
465
+ if (!fromSource) {
466
+ return this.fire('change', this._value);
467
+ }
468
+ },
469
+ validate: function(){
470
+ var this$ = this;
471
+ if (this.mod && this.mod.validate) {
472
+ return this.mod.validate.apply(this, this._value);
473
+ }
474
+ if (this._validate) {
475
+ return Promise.resolve(this._validate(this._value));
476
+ }
477
+ if (this._empty && this._meta.config.isRequired) {
478
+ this._errors = ["required"];
479
+ return this.render();
480
+ }
481
+ return Promise.all(this._meta.term.filter(function(t){
482
+ return t.enabled;
483
+ }).map(function(t){
484
+ return t.validate(this$._value).then(function(v){
485
+ return [t, v];
486
+ });
487
+ })).then(function(it){
488
+ this$._errors = it.filter(function(it){
489
+ return !it[1];
490
+ }).map(function(it){
491
+ return it[0].msg || 'error';
492
+ });
493
+ return this$.render();
494
+ }).then(function(){
495
+ return this$._errors;
496
+ });
497
+ },
498
+ render: function(){
499
+ this.fire('render');
500
+ if (this.mod && this.mod.render) {
501
+ return this.mod.render.apply(this);
502
+ }
503
+ },
504
+ adapt: function(){
505
+ var args, res$, i$, to$;
506
+ res$ = [];
507
+ for (i$ = 0, to$ = arguments.length; i$ < to$; ++i$) {
508
+ res$.push(arguments[i$]);
509
+ }
510
+ args = res$;
511
+ if (this.mod && this.mod.adapt) {
512
+ return this.mod.adapt.apply(this, args);
513
+ }
514
+ }
515
+ });
516
+ if (typeof module != 'undefined' && module !== null) {
517
+ module.exports = form;
518
+ } else if (typeof window != 'undefined' && window !== null) {
519
+ window.form = form;
520
+ }
521
+ function import$(obj, src){
522
+ var own = {}.hasOwnProperty;
523
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
524
+ return obj;
525
+ }
526
+ }).call(this);
package/index.min.js ADDED
@@ -0,0 +1 @@
1
+ (function(){var form;form={};form.manager=function(){this._fields=[];return this};form.manager.prototype=import$(Object.create(Object.prototype),{add:function(it){return this._fields=this._fields.concat(Array.isArray(it)?it:[it])},fields:function(){return this._fields},serialize:function(){return this._fields.map(function(it){return it.serialize()})},value:function(vs){var k,v,f,results$=[];if(!vs){return Object.fromEntries(this._fields.map(function(it){return[it.key(),it.value()]}))}for(k in vs){v=vs[k];f=this._fields.filter(fn$)[0];if(!f){continue}results$.push(f.value(v))}return results$;function fn$(it){return it.key()===k}},mode:function(m){return this._fields.map(function(it){return it.mode(m)})}});form.op=function(opt){opt==null&&(opt={});this.id=opt.id;this.name=opt.name;this.config=opt.config;this.func=opt.func;this.i18n=opt.i18n;return this};form.op.prototype=import$(Object.create(Object.prototype),{validate:function(val,cfg){var ret;cfg==null&&(cfg={});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.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$)):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$)))}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:"number",i18n:{"zh-TW":{number:"數字",lte:"≦ 小於或等於",gte:"≧ 大於或等於",ne:"≠ 不等於",eq:"= 等於"}},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"}}}}}];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._meta={config:{},key:Math.random().toString(36).substring(2)};this._value=null;this._empty=true;this._mode=opt.mode||"view";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)})},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$},_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},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();return this.render()},mode:function(it){if(!(it!=null)){return this._mode}this._mode=it;this.validate();return this.render()},errors:function(){return this._errors},value:function(v,fromSource){fromSource==null&&(fromSource=false);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();if(!fromSource){return this.fire("change",this._value)}},validate:function(){var this$=this;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"];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"});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 ADDED
@@ -0,0 +1 @@
1
+ {"author":"zbryikt","name":"@plotdb/form","license":"MIT","description":"form blocks","version":"0.0.1","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"}}