@es-joy/jsoe 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/demo/index.js CHANGED
@@ -9,26 +9,6 @@ import {
9
9
 
10
10
  const types = new Types();
11
11
 
12
- /**
13
- *
14
- */
15
- const makeNoneditableType = () => {
16
- /**
17
- *
18
- */
19
- class NonEditableType {
20
- /* eslint-disable class-methods-use-this -- `this` not needed */
21
- /**
22
- * @returns {string}
23
- */
24
- get [Symbol.toStringTag] () {
25
- /* eslint-enable class-methods-use-this -- `this` not needed */
26
- return 'NonEditableType';
27
- }
28
- }
29
- return new NonEditableType();
30
- };
31
-
32
12
  const keyPathNotExpectedTypeChoices = formatAndTypeChoices({
33
13
  hasKeyPath: false,
34
14
  typeNamespace: 'demo-keypath-not-expected'
@@ -85,9 +65,7 @@ setTimeout(async function () {
85
65
  // eslint-disable-next-line @stylistic/max-len -- Long
86
66
  await keyPathNotExpectedTypeChoices.formats.getControlsForFormatAndValue(
87
67
  keyPathNotExpectedTypeChoices.types,
88
- $('#useIndexedDBKey').checked
89
- ? 'indexedDBKey'
90
- : 'structuredCloning',
68
+ 'structuredCloning',
91
69
  keyPathNotExpectedTypeChoices.getValue(),
92
70
  {
93
71
  readonly: true
@@ -110,134 +88,6 @@ setTimeout(async function () {
110
88
  }
111
89
  }, ['Initialize with a value']],
112
90
 
113
- ['button', {
114
- id: 'initializeWithComplexValue',
115
- $on: {
116
- async click () {
117
- const a = {
118
- bbb: {},
119
- xxx: {yyy: []}
120
- };
121
- a.bbb.ccc = a;
122
- a.zzz = a.xxx.yyy;
123
- await keyPathNotExpectedTypeChoices.setValue(a);
124
- }
125
- }
126
- }, ['Initialize with a complex value']],
127
-
128
- ['button', {
129
- id: 'initializeWithNoneditableValue',
130
- $on: {
131
- click () {
132
- const a = makeNoneditableType();
133
- const root = $(
134
- '#formatAndTypeChoices div[data-type="resurrectable"]'
135
- );
136
- keyPathNotExpectedTypeChoices.types.setValue({
137
- type: 'resurrectable',
138
- root,
139
- value: a
140
- });
141
- keyPathNotExpectedTypeChoices.types.validate({
142
- type: 'resurrectable',
143
- root
144
- });
145
-
146
- setTimeout(() => {
147
- keyPathNotExpectedTypeChoices.types.setValue({
148
- type: 'resurrectable',
149
- root,
150
- value: undefined
151
- });
152
- keyPathNotExpectedTypeChoices.types.validate({
153
- type: 'resurrectable',
154
- root
155
- });
156
- }, 3000);
157
- // await keyPathNotExpectedTypeChoices.setValue(a);
158
- }
159
- }
160
- }, ['Initialize with noneditable value then change']],
161
-
162
- ['button', {
163
- id: 'programmaticallySetFormatToJSON',
164
- $on: {
165
- click () {
166
- keyPathNotExpectedTypeChoices.formatChoices.$setFormat('json');
167
- }
168
- }
169
- }, [
170
- 'Programmatically set format (to JSON)'
171
- ]],
172
-
173
- ['button', {
174
- id: 'setCustomValidateAllReferences',
175
- $on: {
176
- click () {
177
- keyPathNotExpectedTypeChoices.types.customValidateAllReferences =
178
- () => {
179
- // eslint-disable-next-line no-alert -- Simple demo
180
- alert('customValidateAllReferences set');
181
- };
182
- }
183
- }
184
- }, [
185
- 'Set custom all reference validation'
186
- ]],
187
-
188
- ['button', {
189
- id: 'showRootFormControl',
190
- $on: {
191
- click () {
192
- const root = $(
193
- '#formatAndTypeChoices > .typesHolder > ' +
194
- '.typeContainer > div[data-type]'
195
- );
196
- const formControl =
197
- keyPathNotExpectedTypeChoices.types.getFormControlForRoot(root);
198
- formControl.style.backgroundColor = 'red';
199
- setTimeout(() => {
200
- formControl.style.backgroundColor = 'white';
201
- }, 3000);
202
- }
203
- }
204
- }, ['Show root form control']],
205
-
206
- ['button', {
207
- id: 'getValueFromRootAncestor',
208
- $on: {
209
- click () {
210
- const val =
211
- keyPathNotExpectedTypeChoices.types.getValueFromRootAncestor(
212
- '#formatAndTypeChoices > .typesHolder > ' +
213
- '.typeContainer'
214
- );
215
- console.log(val);
216
- }
217
- }
218
- }, [
219
- 'Get value from root ancestor'
220
- ]],
221
-
222
- ['button', {
223
- id: 'showFormControlFromRootAncestor',
224
- $on: {
225
- click () {
226
- const formControl =
227
- keyPathNotExpectedTypeChoices.types.getFormControlFromRootAncestor(
228
- '#formatAndTypeChoices > .typesHolder > ' +
229
- '.typeContainer'
230
- );
231
- formControl.style.backgroundColor = 'red';
232
- setTimeout(() => {
233
- formControl.style.backgroundColor = 'initial';
234
- }, 3000);
235
- }
236
- }
237
- }, [
238
- 'Show form control from root ancestor'
239
- ]],
240
-
241
91
  ['h2', [
242
92
  'Format and type choices: Key path expected (object required at root)'
243
93
  ]],
@@ -325,204 +175,6 @@ setTimeout(async function () {
325
175
  ]];
326
176
  })(),
327
177
 
328
- ['h2', [
329
- 'Type choices with initial value set'
330
- ]],
331
-
332
- (() => {
333
- const badDate = new Date('Bad date');
334
- const cause = new Error('some cause');
335
- const error = new Error('msg');
336
- error.cause = cause;
337
-
338
- // eslint-disable-next-line unicorn/error-message -- Testing empty
339
- const error2 = new Error();
340
- error2.message = undefined; // Needed to force (at least in Chrome)
341
- error2.fileName = 'abc';
342
- error2.name = undefined;
343
- error2.stack = undefined;
344
- error2.lineNumber = 10;
345
- error2.columnNumber = 20;
346
-
347
- const typeError = new TypeError('msg');
348
- const typeCause = new RangeError('some cause');
349
- typeError.cause = typeCause;
350
-
351
- // eslint-disable-next-line unicorn/error-message -- Testing empty
352
- const error3 = new TypeError();
353
- error3.message = undefined; // Needed to force (at least in Chrome)
354
- error3.fileName = 'abc';
355
- error3.name = undefined;
356
- error3.stack = undefined;
357
- error3.lineNumber = 10;
358
- error3.columnNumber = 20;
359
-
360
- const aggregate1 = new RangeError('agg err1');
361
- const aggregate2 = new TypeError('agg err2');
362
- const aggregate3 = new Error('agg err3');
363
- const errAggregate = new AggregateError(
364
- [aggregate1, aggregate2, aggregate3], 'agg msg'
365
- );
366
-
367
- const typeSelection = typeChoices({
368
- format: 'structuredCloning',
369
- setValue: true,
370
- value: [
371
- 42, 123n, 'test123', new Date('1999-01-01'), badDate,
372
- // eslint-disable-next-line require-unicode-regexp -- Testing
373
- /.*?/,
374
- // eslint-disable-next-line @stylistic/max-len -- Long
375
- // eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins -- Testing
376
- new Boolean(false),
377
- // eslint-disable-next-line @stylistic/max-len -- Long
378
- // eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins -- Testing
379
- new Boolean(true),
380
- // eslint-disable-next-line @stylistic/max-len -- Long
381
- // eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins -- Testing
382
- new Number(42),
383
- // eslint-disable-next-line @stylistic/max-len -- Long
384
- // eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins -- Testing
385
- new String('test123'),
386
- Number.NaN,
387
- -0,
388
- new Blob(['<b>Testing</b>'], {type: 'text/html'}),
389
- new Map([
390
- [null, 3],
391
- [true, new Map([[false, 5]])],
392
- [new Map([[6, 4]]), 7]
393
- ]),
394
- error,
395
- error2,
396
- error3,
397
- typeError,
398
- errAggregate,
399
- new File(['abc'], 'someName', {
400
- lastModified: 1231231230,
401
- type: 'text/plain'
402
- }),
403
- new Blob(['abc'], {
404
- type: 'text/plain'
405
- }),
406
- new DOMException('some message', 'someName'),
407
- new DOMRect(1, 2, 3, 4),
408
- new DOMRectReadOnly(1, 2, 3, 4),
409
- new DOMPoint(1, 2, 3, 4),
410
- new DOMPointReadOnly(1, 2, 3, 4),
411
- new DOMMatrix([1, 2, 3, 4, 5, 6]),
412
- new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]),
413
- new DOMMatrix([
414
- 1, 2, 3, 4,
415
- 5, 6, 7, 8,
416
- 9, 10, 11, 12,
417
- 13, 14, 15, 16
418
- ]),
419
- makeNoneditableType()
420
- ],
421
- typeNamespace: 'demo-type-choices-only-initial-value'
422
- });
423
-
424
- const typeSelectionBlobHTML = typeChoices({
425
- format: 'structuredCloning',
426
- setValue: true,
427
- value: new Blob(['<b>Testing</b>'], {type: 'text/html'}),
428
- typeNamespace: 'demo-type-choices-only-initial-value'
429
- });
430
-
431
- const error4 = new Error('msg2');
432
- const cause4 = new Error('some cause2');
433
- error4.cause = cause4;
434
- const typeSelectionErrorWithCause = typeChoices({
435
- format: 'structuredCloning',
436
- setValue: true,
437
- value: error4,
438
- typeNamespace: 'demo-type-choices-only-initial-value-ErrorCause'
439
- });
440
-
441
- const error5 = new TypeError('msg2');
442
- const cause5 = new RangeError('some cause2');
443
- error5.cause = cause5;
444
- const typeSelectionTypeErrorWithCause = typeChoices({
445
- format: 'structuredCloning',
446
- setValue: true,
447
- value: error5,
448
- typeNamespace: 'demo-type-choices-only-initial-value-ErrorsCause'
449
- });
450
-
451
- const typeSelectionIndexedDBKey = typeChoices({
452
- format: 'indexedDBKey',
453
- setValue: true,
454
- value: [-0, Number.NEGATIVE_INFINITY],
455
- typeNamespace: 'demo-type-choices-only-initial-value',
456
- keySelectClass: 'only-initial'
457
- });
458
-
459
- const agg1 = new RangeError('some err1');
460
- const agg2 = new TypeError('some err2');
461
- const agg3 = new Error('some err3');
462
- const errorAggregate = new AggregateError([agg1, agg2, agg3], 'msg2');
463
- errorAggregate.stack = undefined; // For coverage
464
- const typeSelectionTypeErrorWithAggregate = typeChoices({
465
- format: 'structuredCloning',
466
- setValue: true,
467
- value: errorAggregate,
468
- typeNamespace: 'demo-type-choices-only-initial-value-ErrorsAggregate'
469
- });
470
-
471
- const typeSelectionFile = typeChoices({
472
- format: 'structuredCloning',
473
- setValue: true,
474
- value: new File(['abc'], 'anotherName', {
475
- lastModified: 1231231230,
476
- type: 'text/plain'
477
- }),
478
- typeNamespace: 'demo-type-choices-only-initial-value'
479
- });
480
-
481
- const typeSelectionBlob = typeChoices({
482
- format: 'structuredCloning',
483
- setValue: true,
484
- value: new Blob(['abc'], {
485
- type: 'text/plain'
486
- }),
487
- typeNamespace: 'demo-type-choices-only-initial-value'
488
- });
489
-
490
- const typeSelectionNoneditable = typeChoices({
491
- format: 'structuredCloning',
492
- setValue: true,
493
- value: makeNoneditableType(),
494
- typeNamespace: 'demo-type-choices-only-initial-value'
495
- });
496
-
497
- return ['form', [
498
- ...typeSelection.domArray,
499
- ...typeSelectionBlobHTML.domArray,
500
- ...typeSelectionErrorWithCause.domArray,
501
- ...typeSelectionIndexedDBKey.domArray,
502
- ...typeSelectionTypeErrorWithCause.domArray,
503
- ...typeSelectionTypeErrorWithAggregate.domArray,
504
- ...typeSelectionFile.domArray,
505
- ...typeSelectionBlob.domArray,
506
- ...typeSelectionNoneditable.domArray
507
- ]];
508
- })(),
509
-
510
- ['button', {
511
- id: 'validValuesSet',
512
- $on: {
513
- click () {
514
- // eslint-disable-next-line no-alert -- Simple demo
515
- alert(Types.validValuesSet({
516
- form: this.previousElementSibling,
517
- typeNamespace: 'demo-type-choices-only-initial-value',
518
- keySelectClass: 'only-initial'
519
- }));
520
- }
521
- }
522
- }, [
523
- 'Valid values set?'
524
- ]],
525
-
526
178
  ['h2', [
527
179
  'Convert arbitrary value to an editable menu'
528
180
  ]],
@@ -553,81 +205,11 @@ setTimeout(async function () {
553
205
  change () {
554
206
  const types = new Types();
555
207
  const value = types.getValueForString(this.value, {
556
- format: $('#useIndexedDBKey').checked
557
- ? 'indexedDBKey'
558
- : 'structuredCloning'
208
+ format: 'structuredCloning'
559
209
  })[0];
560
210
  console.log(value);
561
211
  }
562
212
  }
563
- }],
564
-
565
- (() => {
566
- return ['form', {
567
- $on: {
568
- submit (e) {
569
- e.preventDefault();
570
- }
571
- }
572
- }, [
573
- ['button', {
574
- id: 'attemptBadIndexedDBKey',
575
- $on: {
576
- click () {
577
- const badDate = new Date('Bad date');
578
- typeChoices({
579
- format: 'indexedDBKey',
580
- setValue: true,
581
- value: [badDate],
582
- typeNamespace: 'demo-type-choices-only-initial-value'
583
- });
584
- }
585
- }
586
- }, [
587
- 'Attempt bad indexedDBKey (invalid Date)'
588
- ]],
589
- ['button', {
590
- id: 'attemptBadIndexedDBKeyStringObject',
591
- $on: {
592
- click () {
593
- typeChoices({
594
- format: 'indexedDBKey',
595
- setValue: true,
596
- // eslint-disable-next-line @stylistic/max-len -- Long
597
- // eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins -- Testing
598
- value: [new String('Bad value')],
599
- typeNamespace: 'demo-type-choices-only-initial-value'
600
- });
601
- }
602
- }
603
- }, [
604
- 'Attempt bad indexedDBKey (String object)'
605
- ]],
606
- ['button', {
607
- id: 'attemptBadJSON',
608
- $on: {
609
- click () {
610
- typeChoices({
611
- format: 'json',
612
- setValue: true,
613
- // eslint-disable-next-line no-sparse-arrays -- Testing
614
- value: [,],
615
- typeNamespace: 'demo-type-choices-only-initial-value'
616
- });
617
- }
618
- }
619
- }, [
620
- 'Attempt bad JSON (sparse array)'
621
- ]]
622
- ]];
623
- })(),
624
-
625
- ['label', [
626
- 'Use indexedDBKey (valid dates only)',
627
- ['input', {
628
- id: 'useIndexedDBKey',
629
- type: 'checkbox'
630
- }]
631
- ]]
213
+ }]
632
214
  ], body);
633
215
  }, 500);
@@ -1 +1 @@
1
- {"version":3,"file":"indexedDBKey.d.ts","sourceRoot":"","sources":["../../src/formats/indexedDBKey.js"],"names":[],"mappings":";AAEA,6CAA6C;AAC7C,4BADW,OAAO,eAAe,EAAE,MAAM,CAuCvC"}
1
+ {"version":3,"file":"indexedDBKey.d.ts","sourceRoot":"","sources":["../../src/formats/indexedDBKey.js"],"names":[],"mappings":";AAEA,6CAA6C;AAC7C,4BADW,OAAO,eAAe,EAAE,MAAM,CAwCvC"}
@@ -1 +1 @@
1
- {"version":3,"file":"structuredCloning.d.ts","sourceRoot":"","sources":["../../src/formats/structuredCloning.js"],"names":[],"mappings":";2CAsBoB;IACnB,QAAY,EAAE,MAAM,CAAC;IACrB,IAAQ,EAAE,OAAO,aAAa,EAAE,aAAa,CAAC;IAC9C,KAAS,EAAE,OAAO,eAAe,EAAE,oBAAoB,CAAC;IACxD,cAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,SAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAe,CAAC,EAAE,OAAO,aAAa,EAAE,gCAAgC,CAAA;CACrE,KAAK,WAAW,GAAC,IAAI;kCAIZ,OAAO,kBAAkB,EAAE,mBAAmB;uCA2WhD,OAAO,eAAe,EAAE,oBAAoB,YAC5C,OAAO,aAAa,EAAE,WAAW,KAC/B,QAAQ,OAAO,CAAC;AAJ7B;;;;;GAKG;AAEH,6CAA6C;AAC7C,iCADW,OAAO,eAAe,EAAE,MAAM,CAkJvC"}
1
+ {"version":3,"file":"structuredCloning.d.ts","sourceRoot":"","sources":["../../src/formats/structuredCloning.js"],"names":[],"mappings":";2CAsBoB;IACnB,QAAY,EAAE,MAAM,CAAC;IACrB,IAAQ,EAAE,OAAO,aAAa,EAAE,aAAa,CAAC;IAC9C,KAAS,EAAE,OAAO,eAAe,EAAE,oBAAoB,CAAC;IACxD,cAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,SAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAe,CAAC,EAAE,OAAO,aAAa,EAAE,gCAAgC,CAAA;CACrE,KAAK,WAAW,GAAC,IAAI;kCAIZ,OAAO,kBAAkB,EAAE,mBAAmB;uCA2WhD,OAAO,eAAe,EAAE,oBAAoB,YAC5C,OAAO,aAAa,EAAE,WAAW,KAC/B,QAAQ,OAAO,CAAC;AAJ7B;;;;;GAKG;AAEH,6CAA6C;AAC7C,iCADW,OAAO,eAAe,EAAE,MAAM,CAwHvC"}