@es-joy/jsoe 0.5.1 → 0.6.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.
Files changed (80) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.cjs +2 -0
  3. package/.nyc_output/out.json +121296 -0
  4. package/CHANGES.md +6 -0
  5. package/README.md +47 -21
  6. package/cypress.config.ts +13 -0
  7. package/demo/index-instrumented.html +29 -0
  8. package/demo/index.html +10 -1
  9. package/demo/index.js +482 -126
  10. package/dist/formatAndTypeChoices.d.ts +2 -2
  11. package/dist/formatAndTypeChoices.d.ts.map +1 -1
  12. package/dist/formats/json.d.ts.map +1 -1
  13. package/dist/formats/structuredCloning.d.ts +2 -1
  14. package/dist/formats/structuredCloning.d.ts.map +1 -1
  15. package/dist/fundamentalTypes/arrayType.d.ts +6 -37
  16. package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
  17. package/dist/fundamentalTypes/dateType.d.ts.map +1 -1
  18. package/dist/fundamentalTypes/errorType.d.ts +6 -0
  19. package/dist/fundamentalTypes/errorType.d.ts.map +1 -0
  20. package/dist/fundamentalTypes/mapType.d.ts +6 -0
  21. package/dist/fundamentalTypes/mapType.d.ts.map +1 -0
  22. package/dist/fundamentalTypes/nullType.d.ts.map +1 -1
  23. package/dist/fundamentalTypes/objectReferenceType.d.ts.map +1 -1
  24. package/dist/fundamentalTypes/setType.d.ts +6 -0
  25. package/dist/fundamentalTypes/setType.d.ts.map +1 -0
  26. package/dist/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -1
  27. package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -1
  28. package/dist/subTypes/blobHTMLType.d.ts +12 -6
  29. package/dist/subTypes/blobHTMLType.d.ts.map +1 -1
  30. package/dist/superTypes/SpecialNumberType.d.ts +14 -0
  31. package/dist/superTypes/SpecialNumberType.d.ts.map +1 -0
  32. package/dist/superTypes/SpecialRealNumberType.d.ts +6 -0
  33. package/dist/superTypes/SpecialRealNumberType.d.ts.map +1 -0
  34. package/dist/superTypes/errorsSpecialType.d.ts +8 -0
  35. package/dist/superTypes/errorsSpecialType.d.ts.map +1 -0
  36. package/dist/typeChoices.d.ts +4 -2
  37. package/dist/typeChoices.d.ts.map +1 -1
  38. package/dist/types.d.ts +83 -231
  39. package/dist/types.d.ts.map +1 -1
  40. package/dist/utils/dialogs.d.ts +22 -22
  41. package/dist/utils/dialogs.d.ts.map +1 -1
  42. package/dist/utils/templateUtils.d.ts +6 -6
  43. package/dist/utils/templateUtils.d.ts.map +1 -1
  44. package/dist/vendor-imports.d.ts +1 -1
  45. package/package.json +39 -34
  46. package/rollup.config.js +14 -2
  47. package/server.js +1 -1
  48. package/src/formatAndTypeChoices.js +9 -9
  49. package/src/formats/indexedDBKey.js +2 -2
  50. package/src/formats/json.js +1 -2
  51. package/src/formats/structuredCloning.js +104 -29
  52. package/src/formats.js +2 -2
  53. package/src/fundamentalTypes/arrayReferenceType.js +3 -3
  54. package/src/fundamentalTypes/arrayType.js +384 -79
  55. package/src/fundamentalTypes/dateType.js +4 -6
  56. package/src/fundamentalTypes/errorType.js +416 -0
  57. package/src/fundamentalTypes/mapType.js +34 -0
  58. package/src/fundamentalTypes/nullType.js +1 -2
  59. package/src/fundamentalTypes/objectReferenceType.js +2 -1
  60. package/src/fundamentalTypes/regexpType.js +2 -2
  61. package/src/fundamentalTypes/setType.js +34 -0
  62. package/src/fundamentalTypes/sparseUndefinedType.js +2 -3
  63. package/src/fundamentalTypes/undefinedType.js +2 -3
  64. package/src/jsoe.css +3 -0
  65. package/src/subTypes/blobHTMLType.js +37 -33
  66. package/src/subTypes/falseType.js +2 -2
  67. package/src/subTypes/trueType.js +2 -2
  68. package/src/superTypes/{SpecialNumberSuperType.js → SpecialNumberType.js} +1 -1
  69. package/src/superTypes/{SpecialRealNumberSuperType.js → SpecialRealNumberType.js} +3 -2
  70. package/src/superTypes/errorsSpecialType.js +768 -0
  71. package/src/typeChoices.js +27 -20
  72. package/src/types.js +71 -39
  73. package/src/utils/dialogs.js +11 -12
  74. package/src/utils/jsonPointer.js +3 -3
  75. package/src/utils/templateUtils.js +4 -4
  76. package/src/vendor-imports.js +2 -2
  77. package/tsconfig.json +1 -1
  78. package/typings/CypressPlugins.d.ts +10 -0
  79. package/vendor/jamilih/dist/jml-es.js +126 -106
  80. package/vendor/typeson-registry/dist/index.js +188 -44
@@ -6,9 +6,14 @@ import dialogs from '../utils/dialogs.js';
6
6
  import {isNullish} from '../utils/types.js';
7
7
 
8
8
  /**
9
- * @type {import('../types.js').TypeObject & {
10
- * loadBlob: (blob: Blob) => Promise<FileReader>,
9
+ * @typedef {HTMLTextAreaElement & {
11
10
  * sceditorInstance: {val: (val?: string) => string|void}
11
+ * }} SCEditorTextarea
12
+ */
13
+
14
+ /**
15
+ * @type {import('../types.js').TypeObject & {
16
+ * loadBlob: (blob: Blob) => Promise<string>
12
17
  * }}
13
18
  */
14
19
  const blobHTMLType = {
@@ -17,9 +22,6 @@ const blobHTMLType = {
17
22
  stringRegex: /^data:text\/html(?:;base64)?,.*$/u,
18
23
  valueMatch: (v) => v.type === 'text/html',
19
24
  superType: 'blob',
20
- sceditorInstance: {val () {
21
- throw new Error('Not yet instantiated');
22
- }},
23
25
  toValue (s) {
24
26
  // Todo (low): `Blob` untested; use https://stackoverflow.com/a/30407840/271577 ?
25
27
  /**
@@ -51,34 +53,26 @@ const blobHTMLType = {
51
53
  },
52
54
  /* istanbul ignore next -- No dupe keys, array refs, or validation */
53
55
  getInput ({root}) {
54
- return /** @type {HTMLTextAreaElement} */ ($e(root, 'textarea'));
56
+ return /** @type {HTMLTextAreaElement} */ (
57
+ $e(root, 'textarea[name$=-blobHTML]')
58
+ );
55
59
  },
56
- getValue (/* {root} */) {
60
+ getValue ({root}) {
57
61
  return this.toValue(
58
- 'data:text/html,' + this.sceditorInstance.val()
62
+ 'data:text/html,' + /** @type {SCEditorTextarea} */ (
63
+ this.getInput({root})
64
+ ).sceditorInstance.val()
59
65
  // this.getInput({root}).value
60
66
  ).value;
61
67
  },
62
- loadBlob (blob) {
63
- const reader = new FileReader();
64
- // eslint-disable-next-line promise/avoid-new
65
- return new Promise((resolve, reject) => {
66
- reader.addEventListener('loadend', () => {
67
- resolve(reader);
68
- });
69
- reader.addEventListener(
70
- 'error',
71
- /* istanbul ignore next -- How to simulate? */
72
- (_e) => {
73
- reject(reader.error);
74
- }
75
- );
76
- reader.readAsText(blob);
77
- });
68
+ async loadBlob (blob) {
69
+ return await blob.text();
78
70
  },
79
- async setValue ({/* root, */ value}) {
80
- const {result} = await this.loadBlob(value);
81
- this.sceditorInstance.val(/** @type {string} */ (result));
71
+ async setValue ({root, value}) {
72
+ const result = await this.loadBlob(value);
73
+ /** @type {SCEditorTextarea} */ (
74
+ this.getInput({root})
75
+ ).sceditorInstance.val(/** @type {string} */ (result));
82
76
  // this.getInput({root}).value = result;
83
77
  },
84
78
  viewUI ({value}) {
@@ -98,9 +92,9 @@ const blobHTMLType = {
98
92
  ])
99
93
  );
100
94
  // eslint-disable-next-line promise/prefer-await-to-then
101
- this.loadBlob(value).then(({
95
+ this.loadBlob(value).then((
102
96
  result
103
- }) => {
97
+ ) => {
104
98
  val = /** @type {string} */ (result);
105
99
  jml('iframe', {
106
100
  sandbox: '',
@@ -118,9 +112,19 @@ const blobHTMLType = {
118
112
  // return ['i', [`data:text/html,${value}`]];
119
113
  },
120
114
  editUI ({typeNamespace, value}) {
121
- const textarea = /** @type {HTMLTextAreaElement} */ (
122
- jml('textarea', {name: `${typeNamespace}-blobHTML`})
123
- );
115
+ const textarea =
116
+ /**
117
+ * @type {SCEditorTextarea}
118
+ */ (
119
+ jml('textarea', {name: `${typeNamespace}-blobHTML`})
120
+ );
121
+ textarea.sceditorInstance = {
122
+ /* istanbul ignore next */
123
+ val () {
124
+ throw new Error('Not yet instantiated');
125
+ }
126
+ };
127
+
124
128
  const root = /** @type {HTMLDivElement} */ (jml(
125
129
  'div',
126
130
  {dataset: {type: 'blobHTML'}},
@@ -166,7 +170,7 @@ const blobHTMLType = {
166
170
  emoticonsRoot: 'node_modules/sceditor/',
167
171
  style: 'node_modules/sceditor/minified/themes/content/default.min.css'
168
172
  });
169
- this.sceditorInstance = sceditor.instance(textarea);
173
+ textarea.sceditorInstance = sceditor.instance(textarea);
170
174
  if (!isNullish(value)) {
171
175
  /** @type {Required<import('../types.js').TypeObject>} */ (
172
176
  this
@@ -16,7 +16,7 @@ const falseType = {
16
16
  ct: 0,
17
17
  /* istanbul ignore next -- No dupe keys, array refs, or validation */
18
18
  getInput ({root}) {
19
- return /** @type {HTMLInputElement} */ ($e(root, 'input'));
19
+ return /** @type {HTMLInputElement} */ ($e(root, 'input[value=false]'));
20
20
  },
21
21
  editUI ({typeNamespace}) {
22
22
  this.ct++;
@@ -32,7 +32,7 @@ const falseType = {
32
32
  'False',
33
33
  ['input', {
34
34
  type: 'radio', name: `${typeNamespace}-false${this.ct}`,
35
- value: 'false', checked: true, disabled: true
35
+ value: 'false', checked: true
36
36
  }]
37
37
  ]]
38
38
  ]];
@@ -6,7 +6,7 @@ import {$e} from '../utils/templateUtils.js';
6
6
  const trueType = {
7
7
  option: ['Boolean (true)', {value: 'true'}],
8
8
  stringRegex: /^true$/u,
9
- toValue: (_s) => ({value: true}),
9
+ toValue: (/* _s */) => ({value: true}),
10
10
  valueMatch: (v) => v === true,
11
11
  superType: 'boolean',
12
12
  getValue: () => true,
@@ -25,7 +25,7 @@ const trueType = {
25
25
  'True',
26
26
  ['input', {
27
27
  type: 'radio', name: `${typeNamespace}-true${this.ct}`,
28
- value: 'true', checked: true, disabled: true
28
+ value: 'true', checked: true
29
29
  }]
30
30
  ]],
31
31
  ['label', [
@@ -41,7 +41,7 @@ const SpecialNumberSuperType = {
41
41
  setValue ({root, value}) {
42
42
  /** @type {Required<import('../types.js').TypeObject>} */ (
43
43
  this
44
- ).getSelect({root}).value = String(value);
44
+ ).getSelect({root}).value = Object.is(value, -0) ? '-0' : String(value);
45
45
  },
46
46
  viewUI ({value}) {
47
47
  return ['i', {dataset: {type: 'SpecialNumber'}}, [
@@ -1,7 +1,7 @@
1
1
  import {$e} from '../utils/templateUtils.js';
2
2
 
3
3
  /**
4
- * @type {import('./SpecialNumberSuperType.js').SuperTypeObject}
4
+ * @type {import('./SpecialNumberType.js').SuperTypeObject}
5
5
  */
6
6
  const SpecialRealNumberSuperType = {
7
7
  option: ['Special Real Number', {title: '`Infinity`, `-Infinity`, `-0`'}],
@@ -29,13 +29,14 @@ const SpecialRealNumberSuperType = {
29
29
  setValue ({root, value}) {
30
30
  /** @type {Required<import('../types.js').TypeObject>} */ (
31
31
  this
32
- ).getSelect({root}).value = String(value);
32
+ ).getSelect({root}).value = Object.is(value, -0) ? '-0' : String(value);
33
33
  },
34
34
  viewUI ({value}) {
35
35
  return ['i', {dataset: {type: 'SpecialRealNumber'}}, [
36
36
  Object.is(value, -0) ? '-0' : String(value)
37
37
  ]];
38
38
  },
39
+ /* istanbul ignore next -- No dupe keys, array refs, or validation */
39
40
  getInput ({root}) {
40
41
  return /** @type {HTMLSelectElement} */ ($e(root, 'select'));
41
42
  },