@es-joy/jsoe 0.16.0 → 0.17.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 (208) hide show
  1. package/.ncurc.cjs +4 -5
  2. package/CHANGES.md +4 -0
  3. package/README.md +27 -3
  4. package/badges/licenses-badge.svg +1 -0
  5. package/dist/formatAndTypeChoices.d.ts +39 -19
  6. package/dist/formatAndTypeChoices.d.ts.map +1 -1
  7. package/dist/formats/indexedDBKey.d.ts +1 -1
  8. package/dist/formats/indexedDBKey.d.ts.map +1 -1
  9. package/dist/formats/json.d.ts +1 -1
  10. package/dist/formats/json.d.ts.map +1 -1
  11. package/dist/formats/schema.d.ts +11 -0
  12. package/dist/formats/schema.d.ts.map +1 -0
  13. package/dist/formats/structuredCloning.d.ts +11 -13
  14. package/dist/formats/structuredCloning.d.ts.map +1 -1
  15. package/dist/formats.d.ts +86 -25
  16. package/dist/formats.d.ts.map +1 -1
  17. package/dist/fundamentalTypes/BooleanObjectType.d.ts +1 -1
  18. package/dist/fundamentalTypes/BooleanObjectType.d.ts.map +1 -1
  19. package/dist/fundamentalTypes/NumberObjectType.d.ts +1 -1
  20. package/dist/fundamentalTypes/NumberObjectType.d.ts.map +1 -1
  21. package/dist/fundamentalTypes/StringObjectType.d.ts +1 -1
  22. package/dist/fundamentalTypes/StringObjectType.d.ts.map +1 -1
  23. package/dist/fundamentalTypes/arrayReferenceType.d.ts +1 -1
  24. package/dist/fundamentalTypes/arrayType.d.ts +3 -3
  25. package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
  26. package/dist/fundamentalTypes/bigintObjectType.d.ts +6 -0
  27. package/dist/fundamentalTypes/bigintObjectType.d.ts.map +1 -0
  28. package/dist/fundamentalTypes/bigintType.d.ts +1 -1
  29. package/dist/fundamentalTypes/bigintType.d.ts.map +1 -1
  30. package/dist/fundamentalTypes/blobType.d.ts +1 -1
  31. package/dist/fundamentalTypes/blobType.d.ts.map +1 -1
  32. package/dist/fundamentalTypes/booleanType.d.ts +8 -0
  33. package/dist/fundamentalTypes/booleanType.d.ts.map +1 -0
  34. package/dist/fundamentalTypes/catchType.d.ts +6 -0
  35. package/dist/fundamentalTypes/catchType.d.ts.map +1 -0
  36. package/dist/fundamentalTypes/dateType.d.ts +4 -4
  37. package/dist/fundamentalTypes/dateType.d.ts.map +1 -1
  38. package/dist/fundamentalTypes/domexceptionType.d.ts +1 -1
  39. package/dist/fundamentalTypes/domexceptionType.d.ts.map +1 -1
  40. package/dist/fundamentalTypes/enumType.d.ts +6 -0
  41. package/dist/fundamentalTypes/enumType.d.ts.map +1 -0
  42. package/dist/fundamentalTypes/errorType.d.ts +1 -1
  43. package/dist/fundamentalTypes/errorType.d.ts.map +1 -1
  44. package/dist/fundamentalTypes/fileType.d.ts +1 -1
  45. package/dist/fundamentalTypes/fileType.d.ts.map +1 -1
  46. package/dist/fundamentalTypes/filelistType.d.ts +1 -1
  47. package/dist/fundamentalTypes/filelistType.d.ts.map +1 -1
  48. package/dist/fundamentalTypes/functionType.d.ts +6 -0
  49. package/dist/fundamentalTypes/functionType.d.ts.map +1 -0
  50. package/dist/fundamentalTypes/literalType.d.ts +6 -0
  51. package/dist/fundamentalTypes/literalType.d.ts.map +1 -0
  52. package/dist/fundamentalTypes/mapType.d.ts +1 -1
  53. package/dist/fundamentalTypes/mapType.d.ts.map +1 -1
  54. package/dist/fundamentalTypes/nanType.d.ts +6 -0
  55. package/dist/fundamentalTypes/nanType.d.ts.map +1 -0
  56. package/dist/fundamentalTypes/nativeEnumType.d.ts +6 -0
  57. package/dist/fundamentalTypes/nativeEnumType.d.ts.map +1 -0
  58. package/dist/fundamentalTypes/neverType.d.ts +6 -0
  59. package/dist/fundamentalTypes/neverType.d.ts.map +1 -0
  60. package/dist/fundamentalTypes/noneditableType.d.ts +1 -1
  61. package/dist/fundamentalTypes/noneditableType.d.ts.map +1 -1
  62. package/dist/fundamentalTypes/nullType.d.ts +1 -1
  63. package/dist/fundamentalTypes/nullType.d.ts.map +1 -1
  64. package/dist/fundamentalTypes/numberType.d.ts +1 -1
  65. package/dist/fundamentalTypes/numberType.d.ts.map +1 -1
  66. package/dist/fundamentalTypes/objectReferenceType.d.ts +1 -1
  67. package/dist/fundamentalTypes/objectType.d.ts +1 -1
  68. package/dist/fundamentalTypes/objectType.d.ts.map +1 -1
  69. package/dist/fundamentalTypes/promiseType.d.ts +6 -0
  70. package/dist/fundamentalTypes/promiseType.d.ts.map +1 -0
  71. package/dist/fundamentalTypes/recordType.d.ts +6 -0
  72. package/dist/fundamentalTypes/recordType.d.ts.map +1 -0
  73. package/dist/fundamentalTypes/regexpType.d.ts +1 -1
  74. package/dist/fundamentalTypes/regexpType.d.ts.map +1 -1
  75. package/dist/fundamentalTypes/setType.d.ts +1 -1
  76. package/dist/fundamentalTypes/setType.d.ts.map +1 -1
  77. package/dist/fundamentalTypes/sparseUndefinedType.d.ts +1 -1
  78. package/dist/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -1
  79. package/dist/fundamentalTypes/stringType.d.ts +1 -1
  80. package/dist/fundamentalTypes/stringType.d.ts.map +1 -1
  81. package/dist/fundamentalTypes/symbolType.d.ts +8 -0
  82. package/dist/fundamentalTypes/symbolType.d.ts.map +1 -0
  83. package/dist/fundamentalTypes/tupleType.d.ts +6 -0
  84. package/dist/fundamentalTypes/tupleType.d.ts.map +1 -0
  85. package/dist/fundamentalTypes/undefinedType.d.ts +1 -1
  86. package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -1
  87. package/dist/fundamentalTypes/voidType.d.ts +6 -0
  88. package/dist/fundamentalTypes/voidType.d.ts.map +1 -0
  89. package/dist/index.d.ts +2 -2
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +9660 -1586
  92. package/dist/subTypes/blobHTMLType.d.ts.map +1 -1
  93. package/dist/subTypes/falseType.d.ts +1 -1
  94. package/dist/subTypes/trueType.d.ts +1 -1
  95. package/dist/superTypes/SpecialNumberType.d.ts +1 -1
  96. package/dist/superTypes/SpecialRealNumberType.d.ts +1 -1
  97. package/dist/superTypes/SpecialRealNumberType.d.ts.map +1 -1
  98. package/dist/superTypes/buffersourceType.d.ts +1 -1
  99. package/dist/superTypes/buffersourceType.d.ts.map +1 -1
  100. package/dist/superTypes/dommatrixType.d.ts +1 -1
  101. package/dist/superTypes/dommatrixType.d.ts.map +1 -1
  102. package/dist/superTypes/dompointType.d.ts +1 -1
  103. package/dist/superTypes/dompointType.d.ts.map +1 -1
  104. package/dist/superTypes/domrectType.d.ts +1 -1
  105. package/dist/superTypes/domrectType.d.ts.map +1 -1
  106. package/dist/superTypes/errorsSpecialType.d.ts +1 -1
  107. package/dist/superTypes/errorsSpecialType.d.ts.map +1 -1
  108. package/dist/typeChoices.d.ts +33 -16
  109. package/dist/typeChoices.d.ts.map +1 -1
  110. package/dist/types.d.ts +161 -157
  111. package/dist/types.d.ts.map +1 -1
  112. package/dist/utils/dialogs.d.ts +3 -3
  113. package/dist/utils/dialogs.d.ts.map +1 -1
  114. package/dist/utils/jsonPointer.d.ts.map +1 -1
  115. package/dist/utils/media.d.ts.map +1 -1
  116. package/dist/utils/objects.d.ts +16 -0
  117. package/dist/utils/objects.d.ts.map +1 -0
  118. package/dist/utils/types.d.ts +1 -1
  119. package/dist/utils/types.d.ts.map +1 -1
  120. package/dist/vendor-imports.d.ts +1 -1
  121. package/eslint.config.js +74 -0
  122. package/licenseInfo.json +4 -0
  123. package/package.json +33 -42
  124. package/rollup.config.js +15 -0
  125. package/src/formatAndTypeChoices.js +68 -54
  126. package/src/formats/indexedDBKey.js +9 -4
  127. package/src/formats/json.js +7 -4
  128. package/src/formats/schema.js +772 -0
  129. package/src/formats/structuredCloning.js +187 -86
  130. package/src/formats.js +61 -26
  131. package/src/fundamentalTypes/BooleanObjectType.js +18 -6
  132. package/src/fundamentalTypes/NumberObjectType.js +18 -5
  133. package/src/fundamentalTypes/StringObjectType.js +20 -8
  134. package/src/fundamentalTypes/arrayType.js +1241 -533
  135. package/src/fundamentalTypes/bigintObjectType.js +64 -0
  136. package/src/fundamentalTypes/bigintType.js +31 -5
  137. package/src/fundamentalTypes/blobType.js +201 -190
  138. package/src/fundamentalTypes/booleanType.js +63 -0
  139. package/src/fundamentalTypes/catchType.js +140 -0
  140. package/src/fundamentalTypes/dateType.js +57 -19
  141. package/src/fundamentalTypes/domexceptionType.js +61 -63
  142. package/src/fundamentalTypes/enumType.js +52 -0
  143. package/src/fundamentalTypes/errorType.js +20 -7
  144. package/src/fundamentalTypes/fileType.js +195 -189
  145. package/src/fundamentalTypes/filelistType.js +4 -0
  146. package/src/fundamentalTypes/functionType.js +150 -0
  147. package/src/fundamentalTypes/literalType.js +81 -0
  148. package/src/fundamentalTypes/mapType.js +4 -0
  149. package/src/fundamentalTypes/nanType.js +41 -0
  150. package/src/fundamentalTypes/nativeEnumType.js +155 -0
  151. package/src/fundamentalTypes/neverType.js +44 -0
  152. package/src/fundamentalTypes/noneditableType.js +19 -5
  153. package/src/fundamentalTypes/nullType.js +16 -6
  154. package/src/fundamentalTypes/numberType.js +49 -6
  155. package/src/fundamentalTypes/objectType.js +10 -2
  156. package/src/fundamentalTypes/promiseType.js +60 -0
  157. package/src/fundamentalTypes/recordType.js +42 -0
  158. package/src/fundamentalTypes/regexpType.js +51 -33
  159. package/src/fundamentalTypes/setType.js +4 -0
  160. package/src/fundamentalTypes/sparseUndefinedType.js +3 -0
  161. package/src/fundamentalTypes/stringType.js +254 -6
  162. package/src/fundamentalTypes/symbolType.js +81 -0
  163. package/src/fundamentalTypes/tupleType.js +39 -0
  164. package/src/fundamentalTypes/undefinedType.js +14 -4
  165. package/src/fundamentalTypes/voidType.js +48 -0
  166. package/src/jsoe.css +37 -3
  167. package/src/subTypes/blobHTMLType.js +33 -24
  168. package/src/superTypes/SpecialRealNumberType.js +22 -6
  169. package/src/superTypes/buffersourceType.js +86 -30
  170. package/src/superTypes/dommatrixType.js +24 -7
  171. package/src/superTypes/dompointType.js +27 -7
  172. package/src/superTypes/domrectType.js +33 -7
  173. package/src/superTypes/errorsSpecialType.js +30 -14
  174. package/src/typeChoices.js +115 -44
  175. package/src/types.js +129 -45
  176. package/src/utils/FileList.js +3 -3
  177. package/src/utils/dialogs.js +6 -8
  178. package/src/utils/objects.js +22 -0
  179. package/src/vendor-imports.js +1 -1
  180. package/tsconfig.json +2 -2
  181. package/vendor/jamilih/dist/jml-es.js +23 -6
  182. package/vendor/typeson-registry/dist/index.js +77 -47
  183. package/vendor/zod/lib/index.mjs +4236 -0
  184. package/vendor/zodex/dist/esm/dezerialize.d.ts +26 -0
  185. package/vendor/zodex/dist/esm/dezerialize.js +393 -0
  186. package/vendor/zodex/dist/esm/index.d.ts +9 -0
  187. package/vendor/zodex/dist/esm/index.js +4 -0
  188. package/vendor/zodex/dist/esm/infer.d.ts +29 -0
  189. package/vendor/zodex/dist/esm/infer.js +1 -0
  190. package/vendor/zodex/dist/esm/package.json +1 -0
  191. package/vendor/zodex/dist/esm/types.d.ts +201 -0
  192. package/vendor/zodex/dist/esm/types.js +13 -0
  193. package/vendor/zodex/dist/esm/ui.d.ts +23 -0
  194. package/vendor/zodex/dist/esm/ui.js +10 -0
  195. package/vendor/zodex/dist/esm/zerialize.d.ts +50 -0
  196. package/vendor/zodex/dist/esm/zerialize.js +417 -0
  197. package/vendor/zodex/dist/esm/zod-types.d.ts +11 -0
  198. package/vendor/zodex/dist/esm/zod-types.js +1 -0
  199. package/.eslintignore +0 -13
  200. package/.eslintrc.cjs +0 -145
  201. package/.nyc_output/out.json +0 -117370
  202. package/cypress.config.ts +0 -15
  203. package/demo/index-instrumented.html +0 -29
  204. package/demo/index-instrumented.js +0 -644
  205. package/demo/index.html +0 -29
  206. package/demo/index.js +0 -215
  207. package/src/formats/schemaAndArbitrary.js +0 -20
  208. package/src/formats/schemaOnly.js +0 -539
@@ -0,0 +1,63 @@
1
+ import {$e} from '../utils/templateUtils.js';
2
+
3
+ /**
4
+ * @type {import('../types.js').TypeObject & {ct: number}}
5
+ */
6
+ const booleanType = {
7
+ option: ['Boolean', {value: 'boolean'}],
8
+ stringRegex: /^(?:true|false)$/u,
9
+ valueMatch (x) {
10
+ return typeof x === 'boolean';
11
+ },
12
+ toValue: (s) => ({value: s === 'true'}),
13
+ getValue ({root}) {
14
+ return /** @type {HTMLInputElement} */ (this.getInput({root})).checked;
15
+ },
16
+ /* istanbul ignore next -- No dupe keys, array refs, or validation */
17
+ getInput ({root}) {
18
+ return /** @type {HTMLInputElement} */ ($e(root, 'input[value=true]'));
19
+ },
20
+ setValue ({root, value}) {
21
+ const input = value
22
+ ? /** @type {HTMLInputElement} */ ($e(root, 'input[value=true]'))
23
+ : /** @type {HTMLInputElement} */ ($e(root, 'input[value=false]'));
24
+ input.checked = true;
25
+ },
26
+ viewUI ({value, specificSchemaObject}) {
27
+ return ['i', {
28
+ dataset: {type: 'boolean'},
29
+ title: specificSchemaObject?.description ?? '(a boolean)'
30
+ }, [value ? 'true' : 'false']];
31
+ },
32
+ ct: 0,
33
+ editUI ({typeNamespace, specificSchemaObject, value}) {
34
+ this.ct++;
35
+ const isLiteral = specificSchemaObject?.type === 'literal';
36
+ const val = isLiteral
37
+ ? specificSchemaObject?.value
38
+ : (value ?? specificSchemaObject?.defaultValue);
39
+ return ['div', {
40
+ dataset: {type: 'boolean'},
41
+ title: specificSchemaObject?.description ?? 'Boolean'
42
+ }, [
43
+ ['label', [
44
+ 'True',
45
+ ['input', {
46
+ disabled: isLiteral,
47
+ type: 'radio', name: `${typeNamespace}-boolean${this.ct}`,
48
+ value: 'true', checked: typeof val === 'boolean' ? val : true
49
+ }]
50
+ ]],
51
+ ['label', [
52
+ 'False',
53
+ ['input', {
54
+ disabled: isLiteral,
55
+ type: 'radio', name: `${typeNamespace}-boolean${this.ct}`,
56
+ value: 'false', checked: typeof val === 'boolean' ? !val : false
57
+ }]
58
+ ]]
59
+ ]];
60
+ }
61
+ };
62
+
63
+ export default booleanType;
@@ -0,0 +1,140 @@
1
+ import {$e} from '../utils/templateUtils.js';
2
+
3
+ /**
4
+ * @type {import('../types.js').TypeObject}
5
+ */
6
+ const catchType = {
7
+ option: ['Catch'],
8
+ stringRegex: /^catch\((.*)\)$/u,
9
+ valueMatch (x) {
10
+ // Todo: Should expand types here and in `toValue`
11
+ return ['number', 'string'].includes(typeof x);
12
+ },
13
+ toValue (s) {
14
+ const value = s.charAt(0) === '"' ? s.slice(1, -1) : Number(s);
15
+ return {value};
16
+ },
17
+ getInput ({root}) {
18
+ return /** @type {HTMLTextAreaElement} */ (
19
+ $e(root, 'input,textarea')
20
+ );
21
+ },
22
+ setValue ({root, value}) {
23
+ // input/textarea hasn't yet been added, so set timeout
24
+ setTimeout(() => {
25
+ this.getInput({root}).value = value;
26
+ });
27
+ },
28
+ getValue ({root}) {
29
+ return this.getInput({root}).value;
30
+ },
31
+ viewUI ({
32
+ specificSchemaObject, types,
33
+ resultType, typeNamespace, topRoot, format,
34
+ bringIntoFocus, buildTypeChoices, // schemaContent,
35
+ replaced, value
36
+ }) {
37
+ return ['span', {
38
+ dataset: {type: 'catch'},
39
+ title: specificSchemaObject?.description ?? '(a catch)'
40
+ }, [
41
+ ['b', ['Catch']],
42
+ ['br'],
43
+ 'Default value',
44
+ ['br'],
45
+ ['div', {
46
+ class: 'defaultValue'
47
+ }, [
48
+ types.getUIForModeAndType({
49
+ readonly: true,
50
+ specificSchemaObject: /** @type {import('zodex').SzCatch} */ (
51
+ specificSchemaObject
52
+ )?.innerType,
53
+ hasValue: true,
54
+ value,
55
+ resultType, typeNamespace,
56
+ type: /** @type {import('../types.js').AvailableType} */ (
57
+ /** @type {import('zodex').SzCatch} */ (
58
+ specificSchemaObject
59
+ )?.innerType?.type
60
+ ),
61
+ topRoot, bringIntoFocus,
62
+ buildTypeChoices, format,
63
+ // schemaContent,
64
+ replaced
65
+ })
66
+ ]],
67
+ 'Catch value',
68
+ ['br'],
69
+ ['div', {
70
+ class: 'catchValue'
71
+ }, [
72
+ types.getUIForModeAndType({
73
+ readonly: true,
74
+ specificSchemaObject: {
75
+ ...(/** @type {import('zodex').SzCatch} */ (
76
+ specificSchemaObject
77
+ )?.innerType),
78
+ description: '(catch value)'
79
+ },
80
+ hasValue: true,
81
+ value: /** @type {import('zodex').SzCatch} */ (
82
+ specificSchemaObject
83
+ ).value,
84
+ resultType, typeNamespace,
85
+ type: /** @type {import('../types.js').AvailableType} */ (
86
+ /** @type {import('zodex').SzCatch} */ (
87
+ specificSchemaObject
88
+ )?.innerType?.type
89
+ ),
90
+ topRoot, bringIntoFocus,
91
+ buildTypeChoices, format,
92
+ // schemaContent,
93
+ replaced
94
+ })
95
+ ]]
96
+ ]];
97
+ },
98
+ editUI ({
99
+ format, type, buildTypeChoices, specificSchemaObject,
100
+ topRoot, schemaContent, typeNamespace, value
101
+ }) {
102
+ const schemaValue =
103
+ /** @type {import('zodex').SzCatch} */ (
104
+ specificSchemaObject
105
+ )?.value;
106
+ return ['div', {
107
+ dataset: {type: 'catch'},
108
+ title: specificSchemaObject?.description ?? '(a `catch`)'
109
+ }, [
110
+ ['label', [
111
+ ['b', {
112
+ title: String(schemaValue)
113
+ }, ['Value']],
114
+ ' ',
115
+ ...(/** @type {import('../typeChoices.js').BuildTypeChoices} */ (
116
+ buildTypeChoices
117
+ )({
118
+ // resultType,
119
+ // eslint-disable-next-line object-shorthand -- TS
120
+ topRoot: /** @type {HTMLDivElement} */ (topRoot),
121
+ // eslint-disable-next-line object-shorthand -- TS
122
+ format: /** @type {import('../formats.js').AvailableFormat} */ (
123
+ format
124
+ ),
125
+ setValue: true,
126
+ value: value ?? schemaValue,
127
+ schemaOriginal: schemaContent,
128
+ schemaContent: /** @type {import('zodex').SzCatch} */ (
129
+ specificSchemaObject
130
+ )?.innerType,
131
+ state: type,
132
+ // itemIndex,
133
+ typeNamespace
134
+ }).domArray)
135
+ ]]
136
+ ]];
137
+ }
138
+ };
139
+
140
+ export default catchType;
@@ -1,9 +1,9 @@
1
- import {jml} from '../vendor-imports.js';
1
+ import {jml, toStringTag} from '../vendor-imports.js';
2
2
  import {$e} from '../utils/templateUtils.js';
3
3
 
4
4
  /**
5
5
  * @typedef {(
6
- * legitimateInvalid?: true|undefined
6
+ * legitimateInvalid?: boolean|undefined
7
7
  * ) => void} SetValidity
8
8
  */
9
9
 
@@ -20,7 +20,9 @@ import {$e} from '../utils/templateUtils.js';
20
20
  const dateType = {
21
21
  option: ['Date'],
22
22
  // ISO Date string
23
- dateRegex: /^(?:\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}\.\d{3}Z)?|(?:\+|-)\d{6}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)$/u,
23
+ dateRegex: /^(?:\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d)$/u, // ([+-][0-2]\d:[0-5]\d|Z)
24
+ // eslint-disable-next-line @stylistic/max-len -- Long
25
+ // /^(?:\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}\.\d{3}Z)?|(?:\+|-)\d{6}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)$/u,
24
26
  stringRegex () {
25
27
  const regex = this.dateRegex;
26
28
  if (!this.valid) {
@@ -29,11 +31,16 @@ const dateType = {
29
31
  }
30
32
  return new RegExp(regex, 'u');
31
33
  },
34
+ valueMatch (x) {
35
+ return toStringTag(x) === 'Date';
36
+ },
32
37
  toValue (s) {
33
38
  return {value: new Date(s)};
34
39
  },
35
40
  getInput ({root}) {
36
- return /** @type {HTMLInputElement} */ ($e(root, 'input[type="date"]'));
41
+ return /** @type {HTMLInputElement} */ (
42
+ $e(root, 'input[type="datetime-local"]')
43
+ );
37
44
  },
38
45
  setValue ({root, value}) {
39
46
  const notANum = value && Number.isNaN(value.getTime());
@@ -43,9 +50,10 @@ const dateType = {
43
50
  ).$setValidity(true);
44
51
  return;
45
52
  }
53
+
46
54
  const dateStr = new Date(Date.parse(value)).toISOString();
47
55
  this.getInput({root}).value = dateStr.length === 24
48
- ? dateStr.slice(0, 10)
56
+ ? dateStr.slice(0, -8)
49
57
  // eslint-disable-next-line @stylistic/max-len -- Long
50
58
  /* istanbul ignore next -- 6 digits year not reliable through `Date.parse` */
51
59
  : dateStr.slice(3, 13); // Will cut off ten/hundred thousand years
@@ -63,6 +71,7 @@ const dateType = {
63
71
  message: 'Must not be empty`'
64
72
  };
65
73
  }
74
+
66
75
  return {
67
76
  valid: new RegExp(this.dateRegex, 'u').test(val),
68
77
  message: 'Must match a valid date'
@@ -86,22 +95,32 @@ const dateType = {
86
95
  isValueInvalid (value) {
87
96
  return value && Number.isNaN(value.getTime());
88
97
  },
89
- viewUI ({value}) {
98
+ viewUI ({value, specificSchemaObject}) {
90
99
  return !this.valid && this.isValueInvalid(value)
91
100
  ? ['i', {
92
- dataset: {type: 'date'}, class: 'InvalidDate'
101
+ dataset: {type: 'date'}, class: 'InvalidDate',
102
+ title: specificSchemaObject?.description ?? '(an InvalidDate)'
93
103
  }, ['InvalidDate']]
94
- : ['i', {dataset: {type: 'date'}, class: 'ValidDate'}, [
95
- value.toISOString().slice(0, 10)
104
+ : ['i', {
105
+ dataset: {type: 'date'}, class: 'ValidDate',
106
+ title: specificSchemaObject?.description ?? '(a `Date`)'
107
+ }, [
108
+ value.toISOString().slice(0, -8)
96
109
  ]];
97
110
  },
98
111
  // Change to default to `new Date()` when can't be `NaN`
99
112
  // value (keys)?
100
- editUI ({typeNamespace, types, value = ''}) {
101
- const notANum = this.isValueInvalid(value);
113
+ editUI ({typeNamespace, specificSchemaObject, types, value}) {
114
+ const dateSchemaObject = /** @type {import('zodex').SzDate} */ (
115
+ specificSchemaObject
116
+ );
117
+ const val = value ?? (specificSchemaObject?.defaultValue
118
+ ? new Date(specificSchemaObject?.defaultValue)
119
+ : '');
120
+ const notANum = this.isValueInvalid(val);
102
121
  const invalid = this.valid
103
122
  ? ''
104
- : /** @type {HTMLDivElement} */ (jml('div', [
123
+ : jml('div', [
105
124
  ['label', [
106
125
  'Invalid date',
107
126
  ['input', {
@@ -116,7 +135,13 @@ const dateType = {
116
135
  $setValidity (legitimateInvalid) {
117
136
  // console.log('legitimateInvalid', legitimateInvalid);
118
137
  if (legitimateInvalid === true) {
119
- /** @type {HTMLInputElement} */ (this).checked = true;
138
+ /**
139
+ * @type {HTMLInputElement & {
140
+ * $setValidity: SetValidity
141
+ * }}
142
+ */ (
143
+ this
144
+ ).checked = true;
120
145
  }
121
146
  const label = /** @type {HTMLLabelElement} */ (
122
147
  /** @type {HTMLDivElement} */ (
@@ -132,24 +157,37 @@ const dateType = {
132
157
  },
133
158
  $on: {
134
159
  click (/* e */) {
135
- /** @type {HTMLElement & {$setValidity: SetValidity}} */ (
160
+ /** @type {HTMLInputElement & {$setValidity: SetValidity}} */ (
161
+ this
162
+ ).$setValidity(/** @type {HTMLInputElement} */ (
136
163
  this
137
- ).$setValidity();
164
+ ).checked);
138
165
  }
139
166
  }
140
167
  }]
141
168
  ]]
142
- ]));
143
- return ['div', {dataset: {type: this.valid ? 'ValidDate' : 'date'}}, [
169
+ ]);
170
+ return ['div', {
171
+ dataset: {type: this.valid ? 'ValidDate' : 'date'},
172
+ title: specificSchemaObject?.description ?? 'Date'
173
+ }, [
144
174
  ['label', {
145
175
  hidden: notANum
146
176
  }, [
147
177
  'Date: ',
148
178
  ['input', {
149
179
  name: `${typeNamespace}-date`,
150
- type: 'date',
180
+ type: 'datetime-local',
151
181
  // Required yyyy-MM-dd format
152
- value: !value || notANum ? '' : value.toISOString().slice(0, 10)
182
+ value: !val || notANum
183
+ ? ''
184
+ : val.toISOString().slice(0, -8),
185
+ min: dateSchemaObject?.min
186
+ ? new Date(dateSchemaObject.min).toISOString().slice(0, -8)
187
+ : undefined,
188
+ max: dateSchemaObject?.max
189
+ ? new Date(dateSchemaObject.max).toISOString().slice(0, -8)
190
+ : undefined
153
191
  }]
154
192
  ]],
155
193
  invalid
@@ -1,11 +1,17 @@
1
+ import {toStringTag} from '../vendor-imports.js';
1
2
  import {$e} from '../utils/templateUtils.js';
2
3
 
4
+ let domExceptionNameId = 0;
5
+
3
6
  /**
4
7
  * @type {import('../types.js').TypeObject}
5
8
  */
6
9
  const domexceptionType = {
7
10
  option: ['DOMException'],
8
11
  stringRegex: /^DOMException\((.*)\)$/u,
12
+ valueMatch (x) {
13
+ return toStringTag(x) === 'DOMException';
14
+ },
9
15
  toValue (s) {
10
16
  const {message, name} = JSON.parse(s);
11
17
  return {value: new DOMException(message, name)};
@@ -30,8 +36,11 @@ const domexceptionType = {
30
36
  ).value;
31
37
  return new DOMException(message, name);
32
38
  },
33
- viewUI ({value}) {
34
- return ['div', {dataset: {type: 'domexception'}}, [
39
+ viewUI ({value, specificSchemaObject}) {
40
+ return ['div', {
41
+ dataset: {type: 'domexception'},
42
+ title: specificSchemaObject?.description ?? '(a `DOMException`)'
43
+ }, [
35
44
  ['b', ['Message ']],
36
45
  value.message,
37
46
  ['br'],
@@ -42,79 +51,68 @@ const domexceptionType = {
42
51
  value.code
43
52
  ]];
44
53
  },
45
- editUI ({typeNamespace, value = ''}) {
46
- // eslint-disable-next-line @stylistic/max-len -- Long
47
- return ['div', {dataset: {type: 'domexception'}}, /** @type {import('jamilih').JamilihChildren} */ ([
54
+ editUI ({typeNamespace, specificSchemaObject, value = ''}) {
55
+ domExceptionNameId++;
56
+ return ['div', {
57
+ dataset: {type: 'domexception'},
58
+ title: specificSchemaObject?.description ?? 'DOMException'
59
+ }, /** @type {import('jamilih').JamilihChildren} */ ([
48
60
  ['label', [
49
61
  'Name: ',
50
62
  ['input', {
51
63
  class: 'name',
52
- name: `${typeNamespace}-domexception-name`, value
64
+ list: `domExceptionNames-${domExceptionNameId}`,
65
+ name: `${typeNamespace}-domexception-name`,
66
+ value: value?.name ?? '',
67
+ size: 30,
68
+ placeholder: '(Optional predefined name)'
53
69
  }]
54
70
  ]],
55
- ' ',
56
- ['select', {
57
- class: 'predefinedNames',
58
- $on: {
59
- /**
60
- * @this {HTMLSelectElement}
61
- */
62
- change () {
63
- /** @type {HTMLInputElement} */
64
- ($e(
65
- /** @type {HTMLLabelElement} */ (
66
- this.previousElementSibling
67
- ),
68
- '.name'
69
- )).value = this.value;
70
- }
71
- }
71
+ ['datalist', {
72
+ id: `domExceptionNames-${domExceptionNameId}`,
73
+ class: 'predefinedNames'
72
74
  }, [
73
- ['option', {value: ''}, [
74
- '(Choose an optional predefined name)'
75
- ]],
76
- ...[
77
- 'IndexSizeError',
78
- 'HierarchyRequestError',
79
- 'WrongDocumentError',
80
- 'InvalidCharacterError',
81
- 'NoModificationAllowedError',
82
- 'NotFoundError',
83
- 'NotSupportedError',
84
- 'InvalidStateError',
85
- 'InUseAttributeError',
86
- 'SyntaxError',
87
- 'InvalidModificationError',
88
- 'NamespaceError',
89
- 'InvalidAccessError',
90
- 'TypeMismatchError',
91
- 'SecurityError',
92
- 'NetworkError',
93
- 'AbortError',
94
- 'URLMismatchError',
95
- 'QuotaExceededError',
96
- 'TimeoutError',
97
- 'InvalidNodeTypeError',
98
- 'DataCloneError',
99
- 'EncodingError',
100
- 'NotReadableError',
101
- 'UnknownError',
102
- 'ConstraintError',
103
- 'DataError',
104
- 'TransactionInactiveError',
105
- 'ReadOnlyErrorVersionError',
106
- 'OperationError',
107
- 'NotAllowedError'
108
- ].map((name) => {
109
- return ['option', [name]];
110
- })
111
- ]],
75
+ 'IndexSizeError',
76
+ 'HierarchyRequestError',
77
+ 'WrongDocumentError',
78
+ 'InvalidCharacterError',
79
+ 'NoModificationAllowedError',
80
+ 'NotFoundError',
81
+ 'NotSupportedError',
82
+ 'InvalidStateError',
83
+ 'InUseAttributeError',
84
+ 'SyntaxError',
85
+ 'InvalidModificationError',
86
+ 'NamespaceError',
87
+ 'InvalidAccessError',
88
+ 'TypeMismatchError',
89
+ 'SecurityError',
90
+ 'NetworkError',
91
+ 'AbortError',
92
+ 'URLMismatchError',
93
+ 'QuotaExceededError',
94
+ 'TimeoutError',
95
+ 'InvalidNodeTypeError',
96
+ 'DataCloneError',
97
+ 'EncodingError',
98
+ 'NotReadableError',
99
+ 'UnknownError',
100
+ 'ConstraintError',
101
+ 'DataError',
102
+ 'TransactionInactiveError',
103
+ 'ReadOnlyErrorVersionError',
104
+ 'OperationError',
105
+ 'NotAllowedError'
106
+ ].map((name) => {
107
+ return ['option', [name]];
108
+ })],
112
109
  ['br'],
113
110
  ['label', [
114
111
  'Message: ',
115
112
  ['input', {
116
113
  class: 'message',
117
- name: `${typeNamespace}-domexception-message`, value
114
+ name: `${typeNamespace}-domexception-message`,
115
+ value: value?.message ?? ''
118
116
  }]
119
117
  ]]
120
118
  ])];
@@ -0,0 +1,52 @@
1
+ import {$e} from '../utils/templateUtils.js';
2
+
3
+ /**
4
+ * @type {import('../types.js').TypeObject}
5
+ */
6
+ const enumType = {
7
+ option: ['Enum'],
8
+ stringRegex: /^Enum\((.*)\)$/u,
9
+ valueMatch (x) {
10
+ return typeof x === 'string';
11
+ },
12
+ toValue (s) {
13
+ return {value: s.slice(1, -1)};
14
+ },
15
+ getInput ({root}) {
16
+ return /** @type {HTMLSelectElement} */ ($e(root, 'select'));
17
+ },
18
+ setValue ({root, value}) {
19
+ this.getInput({root}).value = value;
20
+ },
21
+ getValue ({root}) {
22
+ return this.getInput({root}).value;
23
+ },
24
+ viewUI ({value, specificSchemaObject}) {
25
+ return ['span', {
26
+ dataset: {type: 'enum'},
27
+ title: specificSchemaObject?.description ?? '(an enum)'
28
+ }, [
29
+ value
30
+ ]];
31
+ },
32
+ editUI ({typeNamespace, specificSchemaObject, value = ''}) {
33
+ return ['div', {
34
+ dataset: {type: 'enum'},
35
+ title: specificSchemaObject?.description ?? 'Enum'
36
+ }, [
37
+ ['select', {
38
+ name: `${typeNamespace}-enum`
39
+ }, /** @type {import('zodex').SzEnum} */ (
40
+ specificSchemaObject
41
+ )?.values.map((val) => {
42
+ return ['option', {
43
+ selected: value
44
+ ? value === val
45
+ : specificSchemaObject?.defaultValue === val
46
+ }, [val]];
47
+ })]
48
+ ]];
49
+ }
50
+ };
51
+
52
+ export default enumType;
@@ -1,6 +1,6 @@
1
1
  import {error as errorTypesonRegistry} from 'typeson-registry';
2
2
  import {$e} from '../utils/templateUtils.js';
3
- import {jml} from '../vendor-imports.js';
3
+ import {jml, toStringTag, hasConstructorOf} from '../vendor-imports.js';
4
4
 
5
5
  /**
6
6
  * @type {import('../types.js').TypeObject}
@@ -8,6 +8,11 @@ import {jml} from '../vendor-imports.js';
8
8
  const errorType = {
9
9
  option: ['Error'],
10
10
  stringRegex: /^Error\((.*)\)$/u,
11
+ valueMatch (x) {
12
+ return toStringTag(x) === 'Error' &&
13
+ // Exclude special errors to let it be handled elsewhere
14
+ hasConstructorOf(x, Error);
15
+ },
11
16
  toValue (s) {
12
17
  const obj = JSON.parse(s);
13
18
  const errObj = /** @type {{revive: import('typeson-registry').Reviver}} */ (
@@ -169,11 +174,16 @@ const errorType = {
169
174
  return errObj;
170
175
  },
171
176
  viewUI (
172
- {value: o, types, format}
177
+ {value: o, specificSchemaObject, types, format}
173
178
  ) {
174
179
  return /** @type {import('jamilih').JamilihArray} */ ([
175
180
  'div', {dataset: {type: 'error'}}, [
176
- ['b', {class: 'emphasis'}, ['Error']],
181
+ ['b', {
182
+ class: 'emphasis',
183
+ title: specificSchemaObject?.description ? '(an Error)' : undefined
184
+ }, [
185
+ specificSchemaObject?.description ?? 'Error'
186
+ ]],
177
187
  typeof o.message === 'string'
178
188
  ? ['div', [['b', ['Message: ']], ['span', [o.message]]]]
179
189
  : [],
@@ -217,7 +227,7 @@ const errorType = {
217
227
  ]
218
228
  ]);
219
229
  },
220
- editUI ({typeNamespace, types, value = {
230
+ editUI ({typeNamespace, types, specificSchemaObject, value = {
221
231
  message: '',
222
232
  name: '',
223
233
  fileName: '',
@@ -252,9 +262,12 @@ const errorType = {
252
262
  });
253
263
  }
254
264
 
255
- const div = /** @type {HTMLDivElement} */ (jml(
265
+ const div = jml(
256
266
  'div',
257
- {dataset: {type: 'error'}},
267
+ {
268
+ dataset: {type: 'error'},
269
+ title: specificSchemaObject?.description ?? 'Error'
270
+ },
258
271
  /** @type {import('jamilih').JamilihChildren} */ ([
259
272
  ['div', [
260
273
  ['label', [
@@ -410,7 +423,7 @@ const errorType = {
410
423
  ['div', {class: 'causeContents'}]
411
424
  ]]
412
425
  ])
413
- ));
426
+ );
414
427
 
415
428
  return [div];
416
429
  }