lightview 1.6.5-b → 1.7.2-b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/components/chart/chart.html +15 -0
- package/components/chart/example.html +32 -0
- package/components/chart.html +22 -18
- package/components/components.js +93 -0
- package/components/gantt/example.html +27 -0
- package/components/gantt/gantt.html +34 -0
- package/components/gauge/example.html +28 -0
- package/components/gauge/guage.html +19 -0
- package/components/timeline.html +81 -0
- package/examples/counter.html +1 -1
- package/examples/foreign.html +27 -13
- package/examples/forgeinform.html +29 -8
- package/examples/form.html +1 -1
- package/examples/invalid-template-literals.html +1 -4
- package/examples/medium/remote.html +2 -1
- package/examples/message.html +0 -1
- package/examples/object-bound-form.html +32 -0
- package/examples/remote.json +1 -1
- package/examples/timeline.html +21 -0
- package/examples/todo.html +38 -0
- package/examples/types.html +3 -2
- package/lightview.js +376 -243
- package/package.json +1 -1
- package/test/basic.html +8 -4
- package/test/extended.html +10 -7
- package/test/extended.test.mjs +182 -4
- package/types.js +98 -52
package/package.json
CHANGED
package/test/basic.html
CHANGED
|
@@ -3,12 +3,16 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<title>Basic</title>
|
|
6
|
-
<template id="x-test" name="joe" open="true" count=1 children='["mary"]' l-on:click="bump">
|
|
6
|
+
<template id="x-test" name="joe" open="true" count=1 children='["mary"]' l-on:click="${bump}">
|
|
7
|
+
|
|
8
|
+
<span id="children">${children}</span>
|
|
9
|
+
|
|
10
|
+
<input id="idatetime" type="datetime" value="${idatetime}">
|
|
7
11
|
|
|
8
12
|
<span id="name">${name}</span>
|
|
9
13
|
<span id="open">${open}</span>
|
|
10
14
|
<span id="count">${count}</span>
|
|
11
|
-
|
|
15
|
+
|
|
12
16
|
<span id="color">${color}</span>
|
|
13
17
|
<span id="checked">${checked}</span>
|
|
14
18
|
<span id="age">${age}</span>
|
|
@@ -28,12 +32,12 @@
|
|
|
28
32
|
<input id="inumber" type="number" value="${inumber}">
|
|
29
33
|
<input id="irange" type="range" value="${irange}">
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
|
|
32
36
|
|
|
33
37
|
<input id="icheckbox" type="checkbox" value="${icheckbox}">
|
|
34
38
|
|
|
35
39
|
<script type="lightview/module">
|
|
36
|
-
|
|
40
|
+
// debugger;
|
|
37
41
|
self.variables({name:"string",open:"boolean",count:"number",children:Array},{imported,reactive});
|
|
38
42
|
self.variables({color:"string",checked:"boolean",age:"number",hamburger:Array},{exported,reactive});
|
|
39
43
|
self.variables({counter:"number"},{reactive});
|
package/test/extended.html
CHANGED
|
@@ -14,15 +14,18 @@ self.variables({strictboolean:boolean},{set:true});
|
|
|
14
14
|
self.variables({strictnumber:number},{set:0});
|
|
15
15
|
self.variables({strictobject:object},{set:{}});
|
|
16
16
|
self.variables({strictstring:string},{set:"test"});
|
|
17
|
+
self.variables({extendedarray:array({required:true,minlength:2,maxlength:3})});
|
|
18
|
+
self.variables({extendedboolean:boolean({required:true})});
|
|
19
|
+
self.variables({extendednumber:number({required:true,min:1,max:4,step:2,allowNaN:false})});
|
|
20
|
+
self.variables({extendedobject:object({required:true})});
|
|
21
|
+
self.variables({extendedstring:string({required:true,minlength:2,maxlength:4})});
|
|
17
22
|
|
|
23
|
+
self.variables({allowNaNnumber:number({min:null,max:null,step:null})});
|
|
24
|
+
self.variables({noNaNnumber:number({allowNaN:false})});
|
|
18
25
|
|
|
19
|
-
|
|
20
|
-
self.
|
|
21
|
-
|
|
22
|
-
self.variables({requiredobject:object({required:true})});
|
|
23
|
-
self.variables({requiredstring:string({required:true})});
|
|
24
|
-
|
|
25
|
-
//self.setVariableValue("requirednumber",null);
|
|
26
|
+
//debugger;
|
|
27
|
+
//self.setVariableValue("extendedarray",[]);
|
|
28
|
+
//console.log(typeof(extendedarray),extendedarray);
|
|
26
29
|
|
|
27
30
|
</script>
|
|
28
31
|
</body>
|
package/test/extended.test.mjs
CHANGED
|
@@ -253,18 +253,196 @@ describe('Lightview - Variables', () => {
|
|
|
253
253
|
expect(validityState.value).toBe(0);
|
|
254
254
|
});
|
|
255
255
|
|
|
256
|
-
test('
|
|
256
|
+
test('extendedarray - should respect minlength', async () => {
|
|
257
257
|
const result = await page.evaluate(() => {
|
|
258
258
|
try {
|
|
259
|
-
document.body.setVariableValue("
|
|
259
|
+
document.body.setVariableValue("extendedarray",[]);
|
|
260
260
|
} catch(e) {
|
|
261
261
|
return e.message;
|
|
262
262
|
}
|
|
263
|
-
return document.body.getVariableValue("
|
|
263
|
+
return document.body.getVariableValue("extendedarray")
|
|
264
264
|
});
|
|
265
265
|
const {name,validityState} = JSON.parse(result,reviver);
|
|
266
|
-
expect(name).toBe("
|
|
266
|
+
expect(name).toBe("extendedarray");
|
|
267
|
+
expect(validityState.tooShort).toBe(true);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test('extendedarray - should respect maxlength', async () => {
|
|
271
|
+
const result = await page.evaluate(() => {
|
|
272
|
+
try {
|
|
273
|
+
document.body.setVariableValue("extendedarray",[1,2,3,4,5]);
|
|
274
|
+
} catch(e) {
|
|
275
|
+
return e.message;
|
|
276
|
+
}
|
|
277
|
+
return document.body.getVariableValue("extendedarray")
|
|
278
|
+
});
|
|
279
|
+
const {name,validityState} = JSON.parse(result,reviver);
|
|
280
|
+
expect(name).toBe("extendedarray");
|
|
281
|
+
expect(validityState.tooLong).toBe(true);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test('extendedarray - should throw and not allow null', async () => {
|
|
285
|
+
const result = await page.evaluate(() => {
|
|
286
|
+
try {
|
|
287
|
+
document.body.setVariableValue("extendedarray",null);
|
|
288
|
+
} catch(e) {
|
|
289
|
+
return e.message;
|
|
290
|
+
}
|
|
291
|
+
return document.body.getVariableValue("extendedarray")
|
|
292
|
+
});
|
|
293
|
+
const {name,validityState} = JSON.parse(result,reviver);
|
|
294
|
+
expect(name).toBe("extendedarray");
|
|
267
295
|
expect(validityState.valueMissing).toBe(true);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test('extendednumber - should throw and not allow null', async () => {
|
|
299
|
+
const result = await page.evaluate(() => {
|
|
300
|
+
try {
|
|
301
|
+
document.body.setVariableValue("extendednumber",null);
|
|
302
|
+
} catch(e) {
|
|
303
|
+
return e.message;
|
|
304
|
+
}
|
|
305
|
+
return document.body.getVariableValue("extendednumber")
|
|
306
|
+
});
|
|
307
|
+
const {name,validityState} = JSON.parse(result,reviver);
|
|
308
|
+
expect(name).toBe("extendednumber");
|
|
309
|
+
expect(validityState.valueMissing).toBe(true);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test('extendednumber - should throw and not allow NaN', async () => {
|
|
313
|
+
const result = await page.evaluate(() => {
|
|
314
|
+
try {
|
|
315
|
+
document.body.setVariableValue("extendednumber",NaN);
|
|
316
|
+
} catch(e) {
|
|
317
|
+
return e.message;
|
|
318
|
+
}
|
|
319
|
+
return document.body.getVariableValue("extendednumber")
|
|
320
|
+
});
|
|
321
|
+
const {name,validityState} = JSON.parse(result,reviver);
|
|
322
|
+
expect(name).toBe("extendednumber");
|
|
323
|
+
expect(validityState.badInput).toBe(true);
|
|
268
324
|
//expect(validityState.value).toBe(null);
|
|
269
325
|
});
|
|
326
|
+
|
|
327
|
+
test('extendednumber - should respect min', async () => {
|
|
328
|
+
const result = await page.evaluate(() => {
|
|
329
|
+
try {
|
|
330
|
+
document.body.setVariableValue("extendednumber",0);
|
|
331
|
+
} catch(e) {
|
|
332
|
+
return e.message;
|
|
333
|
+
}
|
|
334
|
+
return document.body.getVariableValue("extendednumber")
|
|
335
|
+
});
|
|
336
|
+
const {name,validityState} = JSON.parse(result,reviver);
|
|
337
|
+
expect(name).toBe("extendednumber");
|
|
338
|
+
expect(validityState.rangeUnderflow).toBe(true);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
test('extendednumber - should allow between and allow step', async () => {
|
|
342
|
+
const result = await page.evaluate(() => {
|
|
343
|
+
try {
|
|
344
|
+
document.body.setVariableValue("extendednumber",4);
|
|
345
|
+
} catch(e) {
|
|
346
|
+
return e.message;
|
|
347
|
+
}
|
|
348
|
+
return document.body.getVariableValue("extendednumber")
|
|
349
|
+
});
|
|
350
|
+
expect(result).toBe(4);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test('extendednumber - should respect max', async () => {
|
|
354
|
+
const result = await page.evaluate(() => {
|
|
355
|
+
try {
|
|
356
|
+
document.body.setVariableValue("extendednumber",5);
|
|
357
|
+
} catch(e) {
|
|
358
|
+
return e.message;
|
|
359
|
+
}
|
|
360
|
+
return document.body.getVariableValue("extendednumber")
|
|
361
|
+
});
|
|
362
|
+
const {name,validityState} = JSON.parse(result,reviver);
|
|
363
|
+
expect(name).toBe("extendednumber");
|
|
364
|
+
expect(validityState.rangeOverflow).toBe(true);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
test('extendednumber - should respect step', async () => {
|
|
368
|
+
const result = await page.evaluate(() => {
|
|
369
|
+
try {
|
|
370
|
+
document.body.setVariableValue("extendednumber",3);
|
|
371
|
+
} catch(e) {
|
|
372
|
+
return e.message;
|
|
373
|
+
}
|
|
374
|
+
return document.body.getVariableValue("extendednumber")
|
|
375
|
+
});
|
|
376
|
+
const {name,validityState} = JSON.parse(result,reviver);
|
|
377
|
+
expect(name).toBe("extendednumber");
|
|
378
|
+
expect(validityState.rangeUnderflow).toBe(true);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
test('allowNaNnumber - should allow NaN', async () => {
|
|
382
|
+
const result = await page.evaluate(() => {
|
|
383
|
+
try {
|
|
384
|
+
document.body.setVariableValue("allowNaNnumber",NaN);
|
|
385
|
+
} catch(e) {
|
|
386
|
+
return e.message;
|
|
387
|
+
}
|
|
388
|
+
return document.body.getVariableValue("allowNaNnumber")
|
|
389
|
+
});
|
|
390
|
+
expect(typeof(result)==="number" && isNaN(result)).toBe(true);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
test('noNaNnumber - should not allow NaN', async () => {
|
|
394
|
+
const result = await page.evaluate(() => {
|
|
395
|
+
try {
|
|
396
|
+
document.body.setVariableValue("noNaNnumber",NaN);
|
|
397
|
+
} catch(e) {
|
|
398
|
+
return e.message;
|
|
399
|
+
}
|
|
400
|
+
return document.body.getVariableValue("noNaNnumber")
|
|
401
|
+
});
|
|
402
|
+
const {name,validityState} = JSON.parse(result,reviver);
|
|
403
|
+
expect(name).toBe("noNaNnumber");
|
|
404
|
+
expect(validityState.badInput).toBe(true);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
test('extendedstring - should respect minlength', async () => {
|
|
408
|
+
const result = await page.evaluate(() => {
|
|
409
|
+
try {
|
|
410
|
+
document.body.setVariableValue("extendedstring","a");
|
|
411
|
+
} catch(e) {
|
|
412
|
+
return e.message;
|
|
413
|
+
}
|
|
414
|
+
return document.body.getVariableValue("extendedstring")
|
|
415
|
+
});
|
|
416
|
+
const {name,validityState} = JSON.parse(result,reviver);
|
|
417
|
+
expect(name).toBe("extendedstring");
|
|
418
|
+
expect(validityState.tooShort).toBe(true);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
test('extendedstring - should respect maxlength', async () => {
|
|
422
|
+
const result = await page.evaluate(() => {
|
|
423
|
+
try {
|
|
424
|
+
document.body.setVariableValue("extendedstring","abcdefg");
|
|
425
|
+
} catch(e) {
|
|
426
|
+
return e.message;
|
|
427
|
+
}
|
|
428
|
+
return document.body.getVariableValue("extendedstring")
|
|
429
|
+
});
|
|
430
|
+
const {name,validityState} = JSON.parse(result,reviver);
|
|
431
|
+
expect(name).toBe("extendedstring");
|
|
432
|
+
expect(validityState.tooLong).toBe(true);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
test('extendedstring - should throw and not allow null', async () => {
|
|
436
|
+
const result = await page.evaluate(() => {
|
|
437
|
+
try {
|
|
438
|
+
document.body.setVariableValue("extendedstring",null);
|
|
439
|
+
} catch(e) {
|
|
440
|
+
return e.message;
|
|
441
|
+
}
|
|
442
|
+
return document.body.getVariableValue("extendedstring")
|
|
443
|
+
});
|
|
444
|
+
const {name,validityState} = JSON.parse(result,reviver);
|
|
445
|
+
expect(name).toBe("extendedstring");
|
|
446
|
+
expect(validityState.valueMissing).toBe(true);
|
|
447
|
+
});
|
|
270
448
|
})
|
package/types.js
CHANGED
|
@@ -108,7 +108,7 @@ const validateArray = function(value,variable) {
|
|
|
108
108
|
}
|
|
109
109
|
return this.whenInvalid(variable,value);
|
|
110
110
|
}
|
|
111
|
-
const array = ({coerce=false, required = false,whenInvalid = ifInvalid,maxlength=Infinity,minlength=0,...rest}) => {
|
|
111
|
+
const array = ({coerce=false, required = false,whenInvalid = ifInvalid,maxlength=Infinity,minlength=0,...rest}={}) => {
|
|
112
112
|
if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
|
|
113
113
|
if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
|
|
114
114
|
if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
|
|
@@ -126,10 +126,7 @@ const array = ({coerce=false, required = false,whenInvalid = ifInvalid,maxlength
|
|
|
126
126
|
validate: validateArray
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
|
|
130
|
-
array.whenInvalid = ifInvalid;
|
|
131
|
-
array.coerce = false;
|
|
132
|
-
array.required = false;
|
|
129
|
+
|
|
133
130
|
|
|
134
131
|
const validateBoolean = function(value,variable) {
|
|
135
132
|
if(value===undefined && variable.value===undefined) {
|
|
@@ -149,7 +146,7 @@ const validateBoolean = function(value,variable) {
|
|
|
149
146
|
}
|
|
150
147
|
return this.whenInvalid(variable,value);
|
|
151
148
|
}
|
|
152
|
-
const boolean = ({coerce=false,required=false, whenInvalid = ifInvalid,...rest}) =>{
|
|
149
|
+
const boolean = ({coerce=false,required=false, whenInvalid = ifInvalid,...rest}={}) =>{
|
|
153
150
|
if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
|
|
154
151
|
if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
|
|
155
152
|
if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
|
|
@@ -163,10 +160,78 @@ const boolean = ({coerce=false,required=false, whenInvalid = ifInvalid,...rest})
|
|
|
163
160
|
validate: validateBoolean
|
|
164
161
|
}
|
|
165
162
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
163
|
+
|
|
164
|
+
const isDuration = (value) => {
|
|
165
|
+
return parseDuration(value)!==undefined;
|
|
166
|
+
}
|
|
167
|
+
const durationMilliseconds = {
|
|
168
|
+
ms: 1,
|
|
169
|
+
s: 1000,
|
|
170
|
+
m: 1000 * 60,
|
|
171
|
+
h: 1000 * 60 * 60,
|
|
172
|
+
d: 1000 * 60 * 60 * 24,
|
|
173
|
+
w: 1000 * 60 * 60 * 24 * 7,
|
|
174
|
+
mo: (1000 * 60 * 60 * 24 * 365.25)/12,
|
|
175
|
+
q: (1000 * 60 * 60 * 24 * 365.25)/4,
|
|
176
|
+
y: (1000 * 60 * 60 * 24 * 365.25)
|
|
177
|
+
}
|
|
178
|
+
const parseDuration = (value) => {
|
|
179
|
+
if(typeof(value)==="number") return value;
|
|
180
|
+
if(typeof(value)==="string") {
|
|
181
|
+
const num = parseFloat(value),
|
|
182
|
+
suffix = value.substring((num+"").length);
|
|
183
|
+
if(typeof(num)==="number" && !isNaN(num) && suffix in durationMilliseconds) {
|
|
184
|
+
return durationMilliseconds[suffix] * num;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const validateDuration = function(value,variable) {
|
|
191
|
+
const result = parseDuration(value);
|
|
192
|
+
if(result==null && variable.value===undefined) {
|
|
193
|
+
return parseDuration(this.default);
|
|
194
|
+
}
|
|
195
|
+
if(this.required && result==null) {
|
|
196
|
+
variable.validityState = ValidityState({valueMissing: true});
|
|
197
|
+
} else {
|
|
198
|
+
if(typeof(result)!=="number") {
|
|
199
|
+
variable.validityState = ValidityState({typeMismatch:true,value});
|
|
200
|
+
} else if(isNaN(result)) {
|
|
201
|
+
variable.validityState = ValidityState({badInput:true,value});
|
|
202
|
+
} else if(this.min!=null && result<parseDuration(this.min)) {
|
|
203
|
+
variable.validityState = ValidityState({rangeUnderflow:true,value});
|
|
204
|
+
} else if(this.max!=null && result>parseDuration(this.max)) {
|
|
205
|
+
variable.validityState = ValidityState({rangeOverflow:true,value});
|
|
206
|
+
} else if(this.step!==null && (result % parseDuration(this.step)!==0)) {
|
|
207
|
+
variable.validityState = ValidityState({rangeUnderflow:true,value});
|
|
208
|
+
} else {
|
|
209
|
+
variable.validityState = ValidityState({valid:true});
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return this.whenInvalid(variable,value);
|
|
214
|
+
}
|
|
215
|
+
const duration = ({required = false,whenInvalid = ifInvalid,min=-Infinity,max=Infinity,step = 1,...rest}={}) => {
|
|
216
|
+
if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
|
|
217
|
+
if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
|
|
218
|
+
if(min!=null && !parseDuration(min)) throw new TypeError(`min, ${JSON.stringify(min)}, must be a duration`);
|
|
219
|
+
if(max!=null && !parseDuration(max)) throw new TypeError(`max, ${JSON.stringify(max)}, must be a duration`);
|
|
220
|
+
if(step!=null && !parseDuration(step)) throw new TypeError(`step, ${JSON.stringify(step)}, must be a duration`);
|
|
221
|
+
if(rest.default!==undefined && !parseDuration(rest.default)) throw new TypeError(`default, ${JSON.stringify(rest.default)}, must be a duration`);
|
|
222
|
+
return {
|
|
223
|
+
type: "duration",
|
|
224
|
+
coerce: false,
|
|
225
|
+
required,
|
|
226
|
+
whenInvalid,
|
|
227
|
+
min,
|
|
228
|
+
max,
|
|
229
|
+
step,
|
|
230
|
+
...rest,
|
|
231
|
+
validate: validateDuration
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
duration.parse = parseDuration;
|
|
170
235
|
|
|
171
236
|
const validateNumber = function(value,variable) {
|
|
172
237
|
if(value===undefined && variable.value===undefined) {
|
|
@@ -178,13 +243,13 @@ const validateNumber = function(value,variable) {
|
|
|
178
243
|
const result = this.coerce ? tryParse(value) : value;
|
|
179
244
|
if(typeof(result)!=="number") {
|
|
180
245
|
variable.validityState = ValidityState({typeMismatch:true,value});
|
|
181
|
-
} else if(isNaN(result) && !allowNaN) {
|
|
246
|
+
} else if(isNaN(result) && !this.allowNaN) {
|
|
182
247
|
variable.validityState = ValidityState({badInput:true,value});
|
|
183
|
-
} else if(result<this.min) {
|
|
248
|
+
} else if(this.min!=null && result<this.min) {
|
|
184
249
|
variable.validityState = ValidityState({rangeUnderflow:true,value});
|
|
185
|
-
} else if(result>this.max) {
|
|
250
|
+
} else if(this.max!=null && result>this.max) {
|
|
186
251
|
variable.validityState = ValidityState({rangeOverflow:true,value});
|
|
187
|
-
} else if((result % this.step)!==0) {
|
|
252
|
+
} else if(this.step!==null && (result % this.step)!==0) {
|
|
188
253
|
variable.validityState = ValidityState({rangeUnderflow:true,value});
|
|
189
254
|
} else {
|
|
190
255
|
variable.validityState = ValidityState({valid:true});
|
|
@@ -193,15 +258,15 @@ const validateNumber = function(value,variable) {
|
|
|
193
258
|
}
|
|
194
259
|
return this.whenInvalid(variable,value);
|
|
195
260
|
}
|
|
196
|
-
const number = ({coerce=false,required = false,whenInvalid = ifInvalid,min=-Infinity,max=Infinity,step = 1,allowNaN = true,...rest}) => {
|
|
261
|
+
const number = ({coerce=false,required = false,whenInvalid = ifInvalid,min=-Infinity,max=Infinity,step = 1,allowNaN = true,...rest}={}) => {
|
|
197
262
|
if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
|
|
198
263
|
if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
|
|
199
264
|
if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
|
|
200
|
-
if(typeof(min)!=="number") throw new TypeError(`min, ${JSON.stringify(min)}, must be a number`);
|
|
201
|
-
if(typeof(max)!=="number") throw new TypeError(`max, ${JSON.stringify(max)}, must be a number`);
|
|
202
|
-
if(typeof(step)!=="number") throw new TypeError(`step, ${JSON.stringify(step)}, must be a number`);
|
|
265
|
+
if(min!=null && typeof(min)!=="number") throw new TypeError(`min, ${JSON.stringify(min)}, must be a number`);
|
|
266
|
+
if(max!=null && typeof(max)!=="number") throw new TypeError(`max, ${JSON.stringify(max)}, must be a number`);
|
|
267
|
+
if(step!=null && typeof(step)!=="number") throw new TypeError(`step, ${JSON.stringify(step)}, must be a number`);
|
|
203
268
|
if(typeof(allowNaN)!=="boolean") throw new TypeError(`step, ${JSON.stringify(allowNaN)}, must be a boolean`);
|
|
204
|
-
if(rest.default!==undefined && typeof(rest.default)!=="number") throw new TypeError(`default, ${rest.default}, must be a number`);
|
|
269
|
+
if(rest.default!==undefined && typeof(rest.default)!=="number") throw new TypeError(`default, ${JSON.stringify(rest.default)}, must be a number`);
|
|
205
270
|
return {
|
|
206
271
|
type: "number",
|
|
207
272
|
coerce,
|
|
@@ -215,14 +280,7 @@ const number = ({coerce=false,required = false,whenInvalid = ifInvalid,min=-Infi
|
|
|
215
280
|
validate: validateNumber
|
|
216
281
|
}
|
|
217
282
|
}
|
|
218
|
-
|
|
219
|
-
number.whenInvalid = ifInvalid;
|
|
220
|
-
number.min = -Infinity;
|
|
221
|
-
number.max = Infinity;
|
|
222
|
-
number.coerce = false;
|
|
223
|
-
number.required = false;
|
|
224
|
-
number.allowNaN = true;
|
|
225
|
-
number.step = 1;
|
|
283
|
+
|
|
226
284
|
|
|
227
285
|
const validateObject = function(value,variable) {
|
|
228
286
|
if(value===undefined && variable.value===undefined) {
|
|
@@ -241,7 +299,7 @@ const validateObject = function(value,variable) {
|
|
|
241
299
|
}
|
|
242
300
|
return this.whenInvalid(variable,value);
|
|
243
301
|
}
|
|
244
|
-
const object = ({coerce=false, required = false,whenInvalid = ifInvalid,...rest}) => {
|
|
302
|
+
const object = ({coerce=false, required = false,whenInvalid = ifInvalid,...rest}={}) => {
|
|
245
303
|
if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
|
|
246
304
|
if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
|
|
247
305
|
if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
|
|
@@ -255,10 +313,7 @@ const object = ({coerce=false, required = false,whenInvalid = ifInvalid,...rest}
|
|
|
255
313
|
validate: validateObject
|
|
256
314
|
}
|
|
257
315
|
}
|
|
258
|
-
|
|
259
|
-
object.whenInvalid = ifInvalid;
|
|
260
|
-
object.coerce = false;
|
|
261
|
-
object.required = false;
|
|
316
|
+
|
|
262
317
|
|
|
263
318
|
const validateString = function(value,variable) {
|
|
264
319
|
if(value===undefined && variable.value===undefined) {
|
|
@@ -281,7 +336,7 @@ const validateString = function(value,variable) {
|
|
|
281
336
|
}
|
|
282
337
|
return this.whenInvalid(variable,value);
|
|
283
338
|
}
|
|
284
|
-
const string = ({coerce=false, required = false,whenInvalid = ifInvalid, maxlength = Infinity, minlength = 0, pattern
|
|
339
|
+
const string = ({coerce=false, required = false,whenInvalid = ifInvalid, maxlength = Infinity, minlength = 0, pattern,...rest}={}) => {
|
|
285
340
|
if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
|
|
286
341
|
if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
|
|
287
342
|
if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
|
|
@@ -300,12 +355,7 @@ const string = ({coerce=false, required = false,whenInvalid = ifInvalid, maxleng
|
|
|
300
355
|
validate: validateString
|
|
301
356
|
}
|
|
302
357
|
}
|
|
303
|
-
|
|
304
|
-
string.whenInvalid = ifInvalid;
|
|
305
|
-
string.coerce = false;
|
|
306
|
-
string.required = false;
|
|
307
|
-
string.maxlength = Infinity;
|
|
308
|
-
string.minlength = 0;
|
|
358
|
+
|
|
309
359
|
|
|
310
360
|
const validateSymbol = function(value,variable) {
|
|
311
361
|
if(value===undefined && variable.value===undefined) {
|
|
@@ -324,7 +374,7 @@ const validateSymbol = function(value,variable) {
|
|
|
324
374
|
}
|
|
325
375
|
return this.whenInvalid(variable,value);
|
|
326
376
|
}
|
|
327
|
-
const symbol = ({coerce=false,required=false, whenInvalid = ifInvalid,...rest}) =>{
|
|
377
|
+
const symbol = ({coerce=false,required=false, whenInvalid = ifInvalid,...rest}={}) =>{
|
|
328
378
|
if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
|
|
329
379
|
if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
|
|
330
380
|
if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
|
|
@@ -338,10 +388,6 @@ const symbol = ({coerce=false,required=false, whenInvalid = ifInvalid,...rest})
|
|
|
338
388
|
validate: validateSymbol
|
|
339
389
|
}
|
|
340
390
|
}
|
|
341
|
-
symbol.validate = validateSymbol;
|
|
342
|
-
symbol.whenInvalid = ifInvalid;
|
|
343
|
-
symbol.coerce = false;
|
|
344
|
-
symbol.required = false;
|
|
345
391
|
|
|
346
392
|
const remoteProxy = ({json, variable,config, reactive, component}) => {
|
|
347
393
|
const type = typeof (config);
|
|
@@ -428,7 +474,7 @@ const put = (href,variable) => {
|
|
|
428
474
|
})
|
|
429
475
|
}
|
|
430
476
|
|
|
431
|
-
const handleRemote = async ({variable,
|
|
477
|
+
const handleRemote = async ({variable, functionalType, config=functionalType, component},doput) => {
|
|
432
478
|
const type = typeof (config);
|
|
433
479
|
let value;
|
|
434
480
|
if (type === "string") {
|
|
@@ -444,14 +490,14 @@ const handleRemote = async ({variable, config, reactive, component},doput) => {
|
|
|
444
490
|
if(!config.get || !config.put) {
|
|
445
491
|
if(!href) throw new Error(`A remote path is required if no put function is provided for remote data`)
|
|
446
492
|
if(!config.get) config.get = get;
|
|
447
|
-
if(!config.put && reactive) config.put = put;
|
|
493
|
+
if(!config.put && variable.reactive) config.put = put;
|
|
448
494
|
}
|
|
449
495
|
value = (doput
|
|
450
496
|
? config.put(href,variable)
|
|
451
497
|
: config.get(href,variable));
|
|
452
498
|
if(config.ttl && !doput && !config.intervalId) {
|
|
453
499
|
config.intervalId = setInterval(async () => {
|
|
454
|
-
await handleRemote({variable, config,
|
|
500
|
+
await handleRemote({variable, config, component});
|
|
455
501
|
//schedule();
|
|
456
502
|
},config.ttl);
|
|
457
503
|
}
|
|
@@ -459,13 +505,11 @@ const handleRemote = async ({variable, config, reactive, component},doput) => {
|
|
|
459
505
|
}
|
|
460
506
|
if(value) {
|
|
461
507
|
const json = await value;
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
variable.value = remoteProxy({json, variable,config, reactive, component});
|
|
508
|
+
if (json && typeof (json) === "object" && variable.reactive) {
|
|
509
|
+
variable.value = remoteProxy({json, variable,config, component});
|
|
465
510
|
} else {
|
|
466
511
|
component.setVariableValue(variable.name,json);
|
|
467
512
|
}
|
|
468
|
-
//})
|
|
469
513
|
}
|
|
470
514
|
}
|
|
471
515
|
|
|
@@ -476,4 +520,6 @@ const remote = (config) => {
|
|
|
476
520
|
}
|
|
477
521
|
}
|
|
478
522
|
|
|
479
|
-
|
|
523
|
+
const remoteGenerator = handleRemote;
|
|
524
|
+
|
|
525
|
+
export {ValidityState,any,array,boolean,duration,number,object,remote,remoteGenerator,string,symbol,reviver}
|