lightview 1.8.1-b → 2.0.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 (224) hide show
  1. package/.agent/workflows/daisyui-component-migration.md +155 -0
  2. package/.codacy/cli.sh +149 -0
  3. package/.codacy/codacy.yaml +15 -0
  4. package/.github/instructions/codacy.instructions.md +72 -0
  5. package/.wranglerignore +21 -0
  6. package/README.md +1331 -21
  7. package/_headers +4 -0
  8. package/build.js +70 -0
  9. package/components/actions/button.js +151 -0
  10. package/components/actions/dropdown.js +120 -0
  11. package/components/actions/modal.js +146 -0
  12. package/components/actions/swap.js +118 -0
  13. package/components/daisyui.js +288 -0
  14. package/components/data-display/accordion.js +128 -0
  15. package/components/data-display/alert.js +112 -0
  16. package/components/data-display/avatar.js +170 -0
  17. package/components/data-display/badge.js +82 -0
  18. package/components/data-display/card.js +151 -0
  19. package/components/data-display/carousel.js +94 -0
  20. package/components/data-display/chart.js +220 -0
  21. package/components/data-display/chat.js +128 -0
  22. package/components/data-display/collapse.js +103 -0
  23. package/components/data-display/countdown.js +69 -0
  24. package/components/data-display/diff.js +111 -0
  25. package/components/data-display/kbd.js +65 -0
  26. package/components/data-display/loading.js +75 -0
  27. package/components/data-display/progress.js +79 -0
  28. package/components/data-display/radial-progress.js +88 -0
  29. package/components/data-display/skeleton.js +66 -0
  30. package/components/data-display/stats.js +159 -0
  31. package/components/data-display/table.js +146 -0
  32. package/components/data-display/timeline.js +146 -0
  33. package/components/data-display/toast.js +72 -0
  34. package/components/data-display/tooltip.js +74 -0
  35. package/components/data-input/checkbox.js +253 -0
  36. package/components/data-input/file-input.js +224 -0
  37. package/components/data-input/input.js +264 -0
  38. package/components/data-input/radio.js +338 -0
  39. package/components/data-input/range.js +204 -0
  40. package/components/data-input/rating.js +219 -0
  41. package/components/data-input/select.js +287 -0
  42. package/components/data-input/textarea.js +287 -0
  43. package/components/data-input/toggle.js +201 -0
  44. package/components/index.js +137 -0
  45. package/components/layout/divider.js +72 -0
  46. package/components/layout/drawer.js +142 -0
  47. package/components/layout/footer.js +100 -0
  48. package/components/layout/hero.js +109 -0
  49. package/components/layout/indicator.js +90 -0
  50. package/components/layout/join.js +78 -0
  51. package/components/layout/navbar.js +110 -0
  52. package/components/navigation/breadcrumbs.js +91 -0
  53. package/components/navigation/dock.js +103 -0
  54. package/components/navigation/menu.js +126 -0
  55. package/components/navigation/pagination.js +105 -0
  56. package/components/navigation/steps.js +89 -0
  57. package/components/navigation/tabs.css +177 -0
  58. package/components/navigation/tabs.js +123 -0
  59. package/components/theme/theme-switch.css +65 -0
  60. package/components/theme/theme-switch.js +177 -0
  61. package/docs/about.html +164 -0
  62. package/docs/api/computed.html +184 -0
  63. package/docs/api/effects.html +173 -0
  64. package/docs/api/elements.html +180 -0
  65. package/docs/api/enhance.html +225 -0
  66. package/docs/api/hypermedia.html +165 -0
  67. package/docs/api/index.html +178 -0
  68. package/docs/api/nav.html +18 -0
  69. package/docs/api/signals.html +136 -0
  70. package/docs/api/state.html +217 -0
  71. package/docs/assets/images/logo-favicon.svg +42 -0
  72. package/docs/assets/images/logo-static.svg +40 -0
  73. package/docs/assets/images/logo.svg +66 -0
  74. package/docs/assets/js/examplify.js +395 -0
  75. package/docs/assets/styles/site.css +1102 -0
  76. package/docs/assets/styles/themes.css +236 -0
  77. package/docs/components/accordion.html +439 -0
  78. package/docs/components/alert.html +528 -0
  79. package/docs/components/avatar.html +586 -0
  80. package/docs/components/badge.html +531 -0
  81. package/docs/components/breadcrumbs.html +278 -0
  82. package/docs/components/button.html +579 -0
  83. package/docs/components/card.html +561 -0
  84. package/docs/components/carousel.html +286 -0
  85. package/docs/components/chart-area.html +702 -0
  86. package/docs/components/chart-bar.html +782 -0
  87. package/docs/components/chart-column.html +735 -0
  88. package/docs/components/chart-line.html +794 -0
  89. package/docs/components/chart-pie.html +823 -0
  90. package/docs/components/chart.html +612 -0
  91. package/docs/components/chat.html +547 -0
  92. package/docs/components/checkbox.html +641 -0
  93. package/docs/components/collapse.html +536 -0
  94. package/docs/components/component-nav.html +53 -0
  95. package/docs/components/countdown.html +470 -0
  96. package/docs/components/diff.html +245 -0
  97. package/docs/components/divider.html +240 -0
  98. package/docs/components/dock.html +277 -0
  99. package/docs/components/drawer.html +515 -0
  100. package/docs/components/dropdown.html +479 -0
  101. package/docs/components/file-input.html +591 -0
  102. package/docs/components/footer.html +301 -0
  103. package/docs/components/gallery.html +504 -0
  104. package/docs/components/hero.html +264 -0
  105. package/docs/components/index.css +840 -0
  106. package/docs/components/index.html +735 -0
  107. package/docs/components/indicator.html +342 -0
  108. package/docs/components/input.html +644 -0
  109. package/docs/components/join.html +285 -0
  110. package/docs/components/kbd.html +322 -0
  111. package/docs/components/loading.html +521 -0
  112. package/docs/components/menu.html +461 -0
  113. package/docs/components/modal.html +639 -0
  114. package/docs/components/navbar.html +321 -0
  115. package/docs/components/pagination.html +279 -0
  116. package/docs/components/progress.html +514 -0
  117. package/docs/components/radial-progress.html +434 -0
  118. package/docs/components/radio.html +655 -0
  119. package/docs/components/range.html +611 -0
  120. package/docs/components/rating.html +642 -0
  121. package/docs/components/select.html +696 -0
  122. package/docs/components/sidebar-setup.js +93 -0
  123. package/docs/components/skeleton.html +447 -0
  124. package/docs/components/spinner.html +68 -0
  125. package/docs/components/stats.html +486 -0
  126. package/docs/components/steps.html +356 -0
  127. package/docs/components/swap.html +517 -0
  128. package/docs/components/switch.html +68 -0
  129. package/docs/components/table.html +668 -0
  130. package/docs/components/tabs.html +506 -0
  131. package/docs/components/text-input.html +68 -0
  132. package/docs/components/textarea.html +603 -0
  133. package/docs/components/timeline.html +487 -0
  134. package/docs/components/toast.html +474 -0
  135. package/docs/components/toggle.html +564 -0
  136. package/docs/components/tooltip.html +423 -0
  137. package/docs/examples/getting-started-example.html +40 -0
  138. package/docs/examples/index.html +93 -0
  139. package/docs/getting-started/index.html +739 -0
  140. package/docs/getting-started/reviews.html +23 -0
  141. package/docs/getting-started/reviews.odom +108 -0
  142. package/docs/getting-started/reviews.vdom +84 -0
  143. package/docs/index.html +134 -0
  144. package/docs/playground.html +416 -0
  145. package/docs/router.html +285 -0
  146. package/docs/styles/index.html +190 -0
  147. package/functions/_middleware.js +32 -0
  148. package/index.html +309 -0
  149. package/lightview-router.js +364 -0
  150. package/lightview-x.js +1577 -0
  151. package/lightview.js +658 -1109
  152. package/lightview.js.backup +793 -0
  153. package/middleware/locale.js +25 -0
  154. package/middleware/markdown.js +44 -0
  155. package/middleware/notFound.js +37 -0
  156. package/package.json +27 -41
  157. package/watch.js +92 -0
  158. package/wrangler.toml +12 -0
  159. package/.idea/lightview.iml +0 -12
  160. package/.idea/modules.xml +0 -8
  161. package/.idea/vcs.xml +0 -6
  162. package/LICENSE +0 -21
  163. package/codepen-no-tabs-embed.css +0 -2
  164. package/components/chart/chart.html +0 -17
  165. package/components/chart/example.html +0 -32
  166. package/components/chart.html +0 -83
  167. package/components/components.js +0 -113
  168. package/components/gantt/example.html +0 -22
  169. package/components/gantt/gantt.html +0 -42
  170. package/components/gauge/example.html +0 -28
  171. package/components/gauge/gauge.html +0 -20
  172. package/components/gauge.html +0 -60
  173. package/components/orgchart/example.html +0 -25
  174. package/components/orgchart/orgchart.html +0 -41
  175. package/components/repl/code-editor.html +0 -64
  176. package/components/repl/editor.html +0 -37
  177. package/components/repl/editorjs-inline-tool/index.js +0 -3
  178. package/components/repl/editorjs-inline-tool/inline-tools.js +0 -28
  179. package/components/repl/editorjs-inline-tool/tool.js +0 -175
  180. package/components/repl/repl-with-wysiwyg.html +0 -355
  181. package/components/repl/repl.html +0 -345
  182. package/components/repl/sup.js +0 -44
  183. package/components/repl/wysiwyg-repl.html +0 -258
  184. package/components/timeline/example.html +0 -33
  185. package/components/timeline/timeline.html +0 -44
  186. package/components/timeline.html +0 -81
  187. package/examples/anchor.html +0 -11
  188. package/examples/chart.html +0 -34
  189. package/examples/counter.html +0 -26
  190. package/examples/counter.test.mjs +0 -47
  191. package/examples/counter2.html +0 -26
  192. package/examples/directives.html +0 -79
  193. package/examples/foreign.html +0 -50
  194. package/examples/forgeinform.html +0 -98
  195. package/examples/form.html +0 -61
  196. package/examples/gauge.html +0 -18
  197. package/examples/invalid-template-literals.html +0 -44
  198. package/examples/medium/remote.html +0 -60
  199. package/examples/message.html +0 -18
  200. package/examples/nested.html +0 -11
  201. package/examples/object-bound-form.html +0 -34
  202. package/examples/remote-server.js +0 -51
  203. package/examples/remote.html +0 -34
  204. package/examples/remote.json +0 -1
  205. package/examples/scratch.html +0 -69
  206. package/examples/sensors/index.html +0 -30
  207. package/examples/sensors/sensor-server.js +0 -30
  208. package/examples/shared.html +0 -41
  209. package/examples/template.html +0 -33
  210. package/examples/timeline.html +0 -21
  211. package/examples/todo.html +0 -38
  212. package/examples/top.html +0 -10
  213. package/examples/types.html +0 -94
  214. package/examples/xor.html +0 -62
  215. package/jest-puppeteer.config.js +0 -5
  216. package/jest.config.json +0 -12
  217. package/sites/client.html +0 -48
  218. package/sites/index.html +0 -247
  219. package/test/basic.html +0 -93
  220. package/test/basic.test.mjs +0 -315
  221. package/test/extended.html +0 -29
  222. package/test/extended.test.mjs +0 -448
  223. package/types.js +0 -534
  224. package/unsplash.key +0 -1
package/types.js DELETED
@@ -1,534 +0,0 @@
1
- const toJSON = (value) => {
2
- if([-Infinity,Infinity].includes(value)) return `@${value}`;
3
- if(typeof(value)==="number" && isNaN(value)) return "@NaN";
4
- if(value && typeof(value)==="object") {
5
- return Object.entries(value)
6
- .reduce((json,[key,value]) => {
7
- if(value && typeof(value)==="object" && value.toJSON) value = value.toJSON();
8
- json[key] = toJSON(value);
9
- return json;
10
- },Array.isArray(value) ? [] : {})
11
- }
12
- return value;
13
- };
14
- function reviver(property,value) {
15
- if(value==="@-Infinity") return -Infinity;
16
- if(value==="@Infinity") return Infinity;
17
- if(value==="@NaN") return NaN;
18
- return value;
19
- }
20
-
21
- function ValidityState(options) {
22
- if(!this || !(this instanceof ValidityState)) return new ValidityState(options);
23
- Object.assign(this,{
24
- valid:false,
25
- badInput:undefined,
26
- customError:undefined,
27
- patternMismatch:undefined,
28
- rangeUnderflow:undefined,
29
- rangeOverflow:undefined,
30
- typeMismatch:undefined,
31
- valueMissing:undefined,
32
- stepMistmatch:undefined,
33
- tooLong:undefined,
34
- tooShort:undefined
35
- },options);
36
- }
37
-
38
- function DataType(options) {
39
- if(!this || !(this instanceof DataType)) return new DataType(options);
40
- Object.assign(this,options);
41
- }
42
- DataType.prototype.toJSON = function() {
43
- return toJSON(this);
44
- }
45
-
46
- const tryParse = (value) => {
47
- try {
48
- return JSON.parse(value+"",reviver)
49
- } catch(e) {
50
-
51
- }
52
- }
53
-
54
- const ifInvalid = (variable) => {
55
- variable.validityState.type = typeof(variable.type)==="string" ? variable.type : variable.type.type;
56
- throw new TypeError(JSON.stringify(DataType(variable)));
57
- // or could return existing value variable.value
58
- // or could return nothing
59
- }
60
-
61
- const validateAny = function(value,variable) {
62
- if(value===undefined && variable.value===undefined) {
63
- return this.default;
64
- }
65
- if(this.required && value==null) {
66
- variable.validityState = ValidityState({valueMissing: true});
67
- } else {
68
- variable.validityState = ValidityState({valid:true});
69
- return value;
70
- }
71
- return this.whenInvalid(variable,value);
72
- }
73
- const any = ({required=false,whenInvalid = ifInvalid,...rest}) => { // ...rest allows use of property "default", which is otherwise reserved
74
- if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
75
- if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
76
- return {
77
- type: "any",
78
- required,
79
- whenInvalid,
80
- ...rest,
81
- validate: validateAny
82
- }
83
- }
84
- any.validate = validateAny;
85
- any.required = false;
86
-
87
- const validateArray = function(value,variable) {
88
- if(value===undefined && variable.value===undefined) {
89
- return this.default;
90
- }
91
- if(this.required && value==null) {
92
- variable.validityState = ValidityState({valueMissing: true});
93
- } else {
94
- let result = this.coerce && typeof(value)==="string" ? tryParse(value.startsWith("[") ? value : `[${value}]`) : value;
95
- if (!Array.isArray(result)) {
96
- if (value.includes(",")) result = value.split(",");
97
- }
98
- if(typeof(result)!=="object" || !(result instanceof Array || Array.isArray(result))) {
99
- variable.validityState = ValidityState({typeMismatch:true,value});
100
- } else if(result.length<this.minlength) {
101
- variable.validityState = ValidityState({tooShort:true,value});
102
- } else if(result.length>this.maxlength) {
103
- variable.validityState = ValidityState({tooLong:true,value});
104
- } else {
105
- variable.validityState = ValidityState({valid:true});
106
- return result;
107
- }
108
- }
109
- return this.whenInvalid(variable,value);
110
- }
111
- const array = ({coerce=false, required = false,whenInvalid = ifInvalid,maxlength=Infinity,minlength=0,...rest}={}) => {
112
- if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
113
- if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
114
- if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
115
- if(typeof(maxlength)!=="number") throw new TypeError(`maxlength, ${JSON.stringify(maxlength)}, must be a number`);
116
- if(typeof(minlength)!=="number") throw new TypeError(`minlength, ${JSON.stringify(minlength)}, must be a number`);
117
- if(rest.default!==undefined && (typeof(rest.default)!=="object" || !(rest.default instanceof Array || Array.isArray(rest.default)))) throw new TypeError(`default, ${rest.default}, must be an Array`);
118
- return {
119
- type: "array",
120
- coerce,
121
- required,
122
- whenInvalid,
123
- maxlength,
124
- minlength,
125
- ...rest,
126
- validate: validateArray
127
- }
128
- }
129
-
130
-
131
- const validateBoolean = function(value,variable) {
132
- if(value===undefined && variable.value===undefined) {
133
- return this.default;
134
- }
135
- if(variable.value===undefined) value = this.default;
136
- if(this.required && value==null) {
137
- variable.validityState = ValidityState({valueMissing: true});
138
- } else {
139
- const result = this.coerce ? tryParse(value) : value;
140
- if(typeof(result)!=="boolean") {
141
- variable.validityState = ValidityState({typeMismatch: true, value});
142
- } else {
143
- variable.validityState = ValidityState({valid:true});
144
- return result;
145
- }
146
- }
147
- return this.whenInvalid(variable,value);
148
- }
149
- const boolean = ({coerce=false,required=false, whenInvalid = ifInvalid,...rest}={}) =>{
150
- if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
151
- if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
152
- if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
153
- if(rest.default!==undefined && typeof(rest.default)!=="boolean") throw new TypeError(`default, ${rest.default}, must be a boolean`);
154
- return {
155
- type: "boolean",
156
- coerce,
157
- required,
158
- whenInvalid,
159
- ...rest,
160
- validate: validateBoolean
161
- }
162
- }
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;
235
-
236
- const validateNumber = function(value,variable) {
237
- if(value===undefined && variable.value===undefined) {
238
- return this.default;
239
- }
240
- if(this.required && value==null) {
241
- variable.validityState = ValidityState({valueMissing: true});
242
- } else {
243
- const result = this.coerce ? tryParse(value) : value;
244
- if(typeof(result)!=="number") {
245
- variable.validityState = ValidityState({typeMismatch:true,value});
246
- } else if(isNaN(result) && !this.allowNaN) {
247
- variable.validityState = ValidityState({badInput:true,value});
248
- } else if(this.min!=null && result<this.min) {
249
- variable.validityState = ValidityState({rangeUnderflow:true,value});
250
- } else if(this.max!=null && result>this.max) {
251
- variable.validityState = ValidityState({rangeOverflow:true,value});
252
- } else if(this.step!==null && (result % this.step)!==0) {
253
- variable.validityState = ValidityState({rangeUnderflow:true,value});
254
- } else {
255
- variable.validityState = ValidityState({valid:true});
256
- return result;
257
- }
258
- }
259
- return this.whenInvalid(variable,value);
260
- }
261
- const number = ({coerce=false,required = false,whenInvalid = ifInvalid,min=-Infinity,max=Infinity,step = 1,allowNaN = true,...rest}={}) => {
262
- if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
263
- if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
264
- if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
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`);
268
- if(typeof(allowNaN)!=="boolean") throw new TypeError(`step, ${JSON.stringify(allowNaN)}, must be a boolean`);
269
- if(rest.default!==undefined && typeof(rest.default)!=="number") throw new TypeError(`default, ${JSON.stringify(rest.default)}, must be a number`);
270
- return {
271
- type: "number",
272
- coerce,
273
- required,
274
- whenInvalid,
275
- min,
276
- max,
277
- step,
278
- allowNaN,
279
- ...rest,
280
- validate: validateNumber
281
- }
282
- }
283
-
284
-
285
- const validateObject = function(value,variable) {
286
- if(value===undefined && variable.value===undefined) {
287
- return this.default;
288
- }
289
- if(this.required && value==null) {
290
- variable.validityState = ValidityState({valueMissing: true});
291
- } else {
292
- const result = this.coerce ? tryParse(value) : value;
293
- if(typeof(result)!=="object") {
294
- variable.validityState = ValidityState({typeMismatch:true,value});
295
- } else {
296
- variable.validityState = ValidityState({valid:true});
297
- return result;
298
- }
299
- }
300
- return this.whenInvalid(variable,value);
301
- }
302
- const object = ({coerce=false, required = false,whenInvalid = ifInvalid,...rest}={}) => {
303
- if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
304
- if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
305
- if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
306
- if(rest.default!==undefined && typeof(rest.default)!=="object") throw new TypeError(`default, ${rest.default}, must be of type object`);
307
- return {
308
- type: "object",
309
- coerce,
310
- required,
311
- whenInvalid,
312
- ...rest,
313
- validate: validateObject
314
- }
315
- }
316
-
317
-
318
- const validateString = function(value,variable) {
319
- if(value===undefined && variable.value===undefined) {
320
- return this.default;
321
- }
322
- if(this.required && value==null) {
323
- variable.validityState = ValidityState({valueMissing: true});
324
- } else {
325
- const result = this.coerce ? value+"" : value;
326
- if(typeof(result)!=="string") {
327
- variable.validityState = ValidityState({typeMismatch:true,value});
328
- } else if(result.length<this.minlength) {
329
- variable.validityState = ValidityState({tooShort:true,value});
330
- } else if(result.length>this.maxlength) {
331
- variable.validityState = ValidityState({tooLong:true,value});
332
- } else {
333
- variable.validityState = ValidityState({valid:true});
334
- return result;
335
- }
336
- }
337
- return this.whenInvalid(variable,value);
338
- }
339
- const string = ({coerce=false, required = false,whenInvalid = ifInvalid, maxlength = Infinity, minlength = 0, pattern,...rest}={}) => {
340
- if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
341
- if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
342
- if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
343
- if(typeof(maxlength)!=="number") throw new TypeError(`maxlength, ${JSON.stringify(maxlength)}, must be a number`);
344
- if(typeof(minlength)!=="number") throw new TypeError(`minlength, ${JSON.stringify(minlength)}, must be a number`);
345
- if(pattern && (typeof(pattern)!=="object" || !(pattern instanceof RegExp))) throw new TypeError(`pattern, ${pattern}, must be a RegExp`);
346
- if(rest.default!==undefined && typeof(rest.default)!=="string") throw new TypeError(`default, ${rest.default}, must be a string`);
347
- return {
348
- type: "string",
349
- coerce,
350
- required,
351
- whenInvalid,
352
- maxlength,
353
- minlength,
354
- ...rest,
355
- validate: validateString
356
- }
357
- }
358
-
359
- const html = (...args) => string(...args);
360
- html.safe = true;
361
-
362
- const css = (...args) => string(...args);
363
- css.safe = true;
364
-
365
- const script = (...args) => string(...args);
366
- script.safe = true;
367
-
368
-
369
- const validateSymbol = function(value,variable) {
370
- if(value===undefined && variable.value===undefined) {
371
- return this.default;
372
- }
373
- if(this.required && value==null) {
374
- variable.validityState = ValidityState({valueMissing: true});
375
- } else {
376
- const result = !!(this.coerce && typeof(value)!=="symbol" ? Symbol(value+"") : value);
377
- if(typeof(result)!=="symbol") {
378
- variable.validityState = ValidityState({typeMismatch: true, value});
379
- } else {
380
- variable.validityState = ValidityState({valid:true});
381
- return result;
382
- }
383
- }
384
- return this.whenInvalid(variable,value);
385
- }
386
- const symbol = ({coerce=false,required=false, whenInvalid = ifInvalid,...rest}={}) =>{
387
- if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
388
- if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
389
- if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
390
- if(rest.default!==undefined && typeof(rest.default)!=="symbol") throw new TypeError(`default, ${rest.default}, must be a symbol`);
391
- return {
392
- type: "symbol",
393
- coerce,
394
- required,
395
- whenInvalid,
396
- ...rest,
397
- validate: validateSymbol
398
- }
399
- }
400
-
401
- const remoteProxy = ({json, variable,config, reactive, component}) => {
402
- const type = typeof (config);
403
- return new Proxy(json, {
404
- get(target,property) {
405
- if(property==="__remoteProxytarget__") return json;
406
- return target[property];
407
- },
408
- async set(target, property, value) {
409
- if(value && typeof(value)==="object" && value instanceof Promise) value = await value;
410
- const oldValue = target[property];
411
- if (oldValue !== value) {
412
- let remotevalue;
413
- if (type === "string") {
414
- const href = new URL(config,window.location.href).href;
415
- remotevalue = patch({target,property,value,oldValue},href,variable);
416
- } else if(config && type==="object") {
417
- let href;
418
- if(config.path) href = new URL(config.path,window.location.href).href;
419
- if(!config.patch) {
420
- if(!href) throw new Error(`A remote path is required is no put function is provided for remote data`)
421
- config.patch = patch;
422
- }
423
- remotevalue = config.patch({target,property,value,oldValue},href,variable);
424
- }
425
- if(remotevalue) {
426
- await remotevalue.then((newjson) => {
427
- if (newjson && typeof (newjson) === "object" && reactive) {
428
- const target = variable.value?.__reactorProxyTarget__ ? json : variable.value;
429
- Object.entries(newjson).forEach(([key,newValue]) => {
430
- if(target[key]!==newValue) target[key] = newValue;
431
- })
432
- Object.keys(target).forEach((key) => {
433
- if(!(key in newjson)) delete target[key];
434
- });
435
- if(variable.value?.__reactorProxyTarget__) {
436
- const dependents = variable.value.__dependents__,
437
- observers = dependents[property] || [];
438
- [...observers].forEach((f) => {
439
- if (f.cancelled) dependents[property].delete(f);
440
- else f();
441
- })
442
- }
443
- } else {
444
- component.setVariableValue(variable.name,newjson)
445
- //variable.value = json;
446
- }
447
- })
448
- }
449
- }
450
- return true;
451
- }
452
- })
453
- }
454
-
455
- const patch = ({target,property,value,oldValue},href,variable) => {
456
- return fetch(href, {
457
- method: "PATCH",
458
- body: JSON.stringify({property,value,oldValue}),
459
- headers: {
460
- "Content-Type": "application/json"
461
- }
462
- }).then((response) => {
463
- if (response.status < 400) return response.json();
464
- })
465
- }
466
-
467
- const get = (href,variable) => {
468
- return fetch(href)
469
- .then((response) => {
470
- if (response.status < 400) return response.json();
471
- })
472
- }
473
-
474
- const put = (href,variable) => {
475
- return fetch(href, {
476
- method: "PUT",
477
- body: JSON.stringify(variable.value),
478
- headers: {
479
- "Content-Type": "application/json"
480
- }
481
- }).then((response) => {
482
- if (response.status === 200) return response.json();
483
- })
484
- }
485
-
486
- const handleRemote = async ({variable, functionalType, config=functionalType, component},doput) => {
487
- const type = typeof (config);
488
- let value;
489
- if (type === "string") {
490
- const href = new URL(config,window.location.href).href;
491
- value = (doput
492
- ? put(href,variable)
493
- : get(href,variable));
494
- if(variable.value===undefined) variable.value = value; // do not await here
495
- } else if (remote && type === "object") {
496
- if(!config.path) config.path = `./${variable.name}`;
497
- if(config.path.endsWith("/")) config.path = `${config.path}${variable.name}`;
498
- const href = new URL(config.path,window.location.href).href;
499
- if(!config.get || !config.put) {
500
- if(!href) throw new Error(`A remote path is required if no put function is provided for remote data`)
501
- if(!config.get) config.get = get;
502
- if(!config.put && variable.reactive) config.put = put;
503
- }
504
- value = (doput
505
- ? config.put(href,variable)
506
- : config.get(href,variable));
507
- if(config.ttl && !doput && !config.intervalId) {
508
- config.intervalId = setInterval(async () => {
509
- await handleRemote({variable, config, component});
510
- //schedule();
511
- },config.ttl);
512
- }
513
- if(variable.value===undefined) variable.value = value;
514
- }
515
- if(value) {
516
- const json = await value;
517
- if (json && typeof (json) === "object" && variable.reactive) {
518
- variable.value = remoteProxy({json, variable,config, component});
519
- } else {
520
- component.setVariableValue(variable.name,json);
521
- }
522
- }
523
- }
524
-
525
- const remote = (config) => {
526
- return {
527
- config,
528
- handleRemote
529
- }
530
- }
531
-
532
- const remoteGenerator = handleRemote;
533
-
534
- export {ValidityState,any,array,boolean,duration,number,object,remote,remoteGenerator,string,symbol,reviver,html,css,script}
package/unsplash.key DELETED
@@ -1 +0,0 @@
1
- nRe-dHABvjv2shxyvDFQd3Y9MPni77qBG9ImAVH0wig