xote 4.4.1 → 4.4.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xote",
3
- "version": "4.4.1",
3
+ "version": "4.4.2",
4
4
  "repository": {
5
5
  "url": "https://github.com/brnrdog/xote"
6
6
  },
package/src/Xote__JSX.res CHANGED
@@ -65,6 +65,7 @@ module Elements = {
65
65
 
66
66
  /* Props type for HTML elements - supports common attributes and events
67
67
  * String-like attributes use polymorphic types to accept strings, signals, or computed functions
68
+ * Boolean attributes also use polymorphic types to accept bools, signals, or computed functions
68
69
  */
69
70
  type props<
70
71
  'id,
@@ -89,6 +90,14 @@ module Elements = {
89
90
  'height,
90
91
  'role,
91
92
  'ariaLabel,
93
+ 'disabled,
94
+ 'checked,
95
+ 'required,
96
+ 'readOnly,
97
+ 'multiple,
98
+ 'ariaHidden,
99
+ 'ariaExpanded,
100
+ 'ariaSelected,
92
101
  > = {
93
102
  /* Standard attributes - can be static strings, signals, or computed values */
94
103
  id?: 'id,
@@ -99,10 +108,10 @@ module Elements = {
99
108
  name?: 'name,
100
109
  value?: 'value,
101
110
  placeholder?: 'placeholder,
102
- disabled?: bool,
103
- checked?: bool,
104
- required?: bool,
105
- readOnly?: bool,
111
+ disabled?: 'disabled,
112
+ checked?: 'checked,
113
+ required?: 'required,
114
+ readOnly?: 'readOnly,
106
115
  maxLength?: int,
107
116
  minLength?: int,
108
117
  min?: 'min,
@@ -110,7 +119,7 @@ module Elements = {
110
119
  step?: 'step,
111
120
  pattern?: 'pattern,
112
121
  autoComplete?: 'autoComplete,
113
- multiple?: bool,
122
+ multiple?: 'multiple,
114
123
  accept?: 'accept,
115
124
  rows?: int,
116
125
  cols?: int,
@@ -128,9 +137,9 @@ module Elements = {
128
137
  role?: 'role,
129
138
  tabIndex?: int,
130
139
  @as("aria-label") ariaLabel?: 'ariaLabel,
131
- @as("aria-hidden") ariaHidden?: bool,
132
- @as("aria-expanded") ariaExpanded?: bool,
133
- @as("aria-selected") ariaSelected?: bool,
140
+ @as("aria-hidden") ariaHidden?: 'ariaHidden,
141
+ @as("aria-expanded") ariaExpanded?: 'ariaExpanded,
142
+ @as("aria-selected") ariaSelected?: 'ariaSelected,
134
143
  /* Data attributes */
135
144
  data?: Obj.t,
136
145
  /* Event handlers */
@@ -169,6 +178,26 @@ module Elements = {
169
178
  }
170
179
  }
171
180
 
181
+ /* Helper to convert boolean attribute values (static bool, signal, or computed) to Component.attrValue */
182
+ let convertBoolAttrValue = (key: string, value: 'a): (string, Component.attrValue) => {
183
+ // Check if it's a function (computed)
184
+ if typeof(value) == #function {
185
+ // It's a computed function that returns bool
186
+ let f: unit => bool = Obj.magic(value)
187
+ Component.computedAttr(key, () => f() ? "true" : "false")
188
+ } else if typeof(value) == #object && hasId(value)->Option.isSome {
189
+ // It's a signal of bool
190
+ let sig: Signal.t<bool> = Obj.magic(value)
191
+ // Create a computed signal that converts bool to string
192
+ let strSignal = Computed.make(() => Signal.get(sig) ? "true" : "false")
193
+ Component.signalAttr(key, strSignal)
194
+ } else {
195
+ // It's a static bool
196
+ let b: bool = Obj.magic(value)
197
+ Component.attr(key, b ? "true" : "false")
198
+ }
199
+ }
200
+
172
201
  /* Convert props to attrs array */
173
202
  let propsToAttrs = (
174
203
  props: props<
@@ -194,6 +223,14 @@ module Elements = {
194
223
  'height,
195
224
  'role,
196
225
  'ariaLabel,
226
+ 'disabled,
227
+ 'checked,
228
+ 'required,
229
+ 'readOnly,
230
+ 'multiple,
231
+ 'ariaHidden,
232
+ 'ariaExpanded,
233
+ 'ariaSelected,
197
234
  >,
198
235
  ): array<(string, Component.attrValue)> => {
199
236
  let attrs = []
@@ -236,23 +273,23 @@ module Elements = {
236
273
  }
237
274
 
238
275
  switch props.disabled {
239
- | Some(true) => attrs->Array.push(Component.attr("disabled", "true"))
240
- | _ => ()
276
+ | Some(v) => attrs->Array.push(convertBoolAttrValue("disabled", v))
277
+ | None => ()
241
278
  }
242
279
 
243
280
  switch props.checked {
244
- | Some(true) => attrs->Array.push(Component.attr("checked", "true"))
245
- | _ => ()
281
+ | Some(v) => attrs->Array.push(convertBoolAttrValue("checked", v))
282
+ | None => ()
246
283
  }
247
284
 
248
285
  switch props.required {
249
- | Some(true) => attrs->Array.push(Component.attr("required", "true"))
250
- | _ => ()
286
+ | Some(v) => attrs->Array.push(convertBoolAttrValue("required", v))
287
+ | None => ()
251
288
  }
252
289
 
253
290
  switch props.readOnly {
254
- | Some(true) => attrs->Array.push(Component.attr("readonly", "true"))
255
- | _ => ()
291
+ | Some(v) => attrs->Array.push(convertBoolAttrValue("readonly", v))
292
+ | None => ()
256
293
  }
257
294
 
258
295
  switch props.maxLength {
@@ -291,8 +328,8 @@ module Elements = {
291
328
  }
292
329
 
293
330
  switch props.multiple {
294
- | Some(true) => attrs->Array.push(Component.attr("multiple", "true"))
295
- | _ => ()
331
+ | Some(v) => attrs->Array.push(convertBoolAttrValue("multiple", v))
332
+ | None => ()
296
333
  }
297
334
 
298
335
  switch props.accept {
@@ -365,20 +402,17 @@ module Elements = {
365
402
  }
366
403
 
367
404
  switch props.ariaHidden {
368
- | Some(true) => attrs->Array.push(Component.attr("aria-hidden", "true"))
369
- | Some(false) => attrs->Array.push(Component.attr("aria-hidden", "false"))
405
+ | Some(v) => attrs->Array.push(convertBoolAttrValue("aria-hidden", v))
370
406
  | None => ()
371
407
  }
372
408
 
373
409
  switch props.ariaExpanded {
374
- | Some(true) => attrs->Array.push(Component.attr("aria-expanded", "true"))
375
- | Some(false) => attrs->Array.push(Component.attr("aria-expanded", "false"))
410
+ | Some(v) => attrs->Array.push(convertBoolAttrValue("aria-expanded", v))
376
411
  | None => ()
377
412
  }
378
413
 
379
414
  switch props.ariaSelected {
380
- | Some(true) => attrs->Array.push(Component.attr("aria-selected", "true"))
381
- | Some(false) => attrs->Array.push(Component.attr("aria-selected", "false"))
415
+ | Some(v) => attrs->Array.push(convertBoolAttrValue("aria-selected", v))
382
416
  | None => ()
383
417
  }
384
418
 
@@ -422,6 +456,14 @@ module Elements = {
422
456
  'height,
423
457
  'role,
424
458
  'ariaLabel,
459
+ 'disabled,
460
+ 'checked,
461
+ 'required,
462
+ 'readOnly,
463
+ 'multiple,
464
+ 'ariaHidden,
465
+ 'ariaExpanded,
466
+ 'ariaSelected,
425
467
  >,
426
468
  ): array<(string, Dom.event => unit)> => {
427
469
  let events = []
@@ -504,6 +546,14 @@ module Elements = {
504
546
  'height,
505
547
  'role,
506
548
  'ariaLabel,
549
+ 'disabled,
550
+ 'checked,
551
+ 'required,
552
+ 'readOnly,
553
+ 'multiple,
554
+ 'ariaHidden,
555
+ 'ariaExpanded,
556
+ 'ariaSelected,
507
557
  >,
508
558
  ): array<element> => {
509
559
  switch props.children {
@@ -539,6 +589,14 @@ module Elements = {
539
589
  'height,
540
590
  'role,
541
591
  'ariaLabel,
592
+ 'disabled,
593
+ 'checked,
594
+ 'required,
595
+ 'readOnly,
596
+ 'multiple,
597
+ 'ariaHidden,
598
+ 'ariaExpanded,
599
+ 'ariaSelected,
542
600
  >,
543
601
  ): element => {
544
602
  Component.Element({
@@ -575,6 +633,14 @@ module Elements = {
575
633
  'height,
576
634
  'role,
577
635
  'ariaLabel,
636
+ 'disabled,
637
+ 'checked,
638
+ 'required,
639
+ 'readOnly,
640
+ 'multiple,
641
+ 'ariaHidden,
642
+ 'ariaExpanded,
643
+ 'ariaSelected,
578
644
  >,
579
645
  ): element => createElement(tag, props)
580
646
 
@@ -603,6 +669,14 @@ module Elements = {
603
669
  'height,
604
670
  'role,
605
671
  'ariaLabel,
672
+ 'disabled,
673
+ 'checked,
674
+ 'required,
675
+ 'readOnly,
676
+ 'multiple,
677
+ 'ariaHidden,
678
+ 'ariaExpanded,
679
+ 'ariaSelected,
606
680
  >,
607
681
  ): element => createElement(tag, props)
608
682
 
@@ -631,6 +705,14 @@ module Elements = {
631
705
  'height,
632
706
  'role,
633
707
  'ariaLabel,
708
+ 'disabled,
709
+ 'checked,
710
+ 'required,
711
+ 'readOnly,
712
+ 'multiple,
713
+ 'ariaHidden,
714
+ 'ariaExpanded,
715
+ 'ariaSelected,
634
716
  >,
635
717
  ~key: option<string>=?,
636
718
  _: unit,
@@ -664,6 +746,14 @@ module Elements = {
664
746
  'height,
665
747
  'role,
666
748
  'ariaLabel,
749
+ 'disabled,
750
+ 'checked,
751
+ 'required,
752
+ 'readOnly,
753
+ 'multiple,
754
+ 'ariaHidden,
755
+ 'ariaExpanded,
756
+ 'ariaSelected,
667
757
  >,
668
758
  ~key: option<string>=?,
669
759
  _: unit,
@@ -1,5 +1,6 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
+ import * as Signals from "rescript-signals/src/Signals.res.mjs";
3
4
  import * as Core__Option from "@rescript/core/src/Core__Option.res.mjs";
4
5
  import * as Xote__Component from "./Xote__Component.res.mjs";
5
6
  import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
@@ -53,6 +54,29 @@ function convertAttrValue(key, value) {
53
54
  }
54
55
  }
55
56
 
57
+ function convertBoolAttrValue(key, value) {
58
+ if (typeof value === "function") {
59
+ return Xote__Component.computedAttr(key, () => {
60
+ if (value()) {
61
+ return "true";
62
+ } else {
63
+ return "false";
64
+ }
65
+ });
66
+ }
67
+ if (!(typeof value === "object" && Core__Option.isSome(value.id))) {
68
+ return Xote__Component.attr(key, value ? "true" : "false");
69
+ }
70
+ let strSignal = Signals.Computed.make(() => {
71
+ if (Signals.Signal.get(value)) {
72
+ return "true";
73
+ } else {
74
+ return "false";
75
+ }
76
+ }, undefined);
77
+ return Xote__Component.signalAttr(key, strSignal);
78
+ }
79
+
56
80
  function propsToAttrs(props) {
57
81
  let attrs = [];
58
82
  let v = props.id;
@@ -83,129 +107,117 @@ function propsToAttrs(props) {
83
107
  if (v$6 !== undefined) {
84
108
  attrs.push(convertAttrValue("placeholder", Primitive_option.valFromOption(v$6)));
85
109
  }
86
- let match = props.disabled;
87
- if (match !== undefined && match) {
88
- attrs.push(Xote__Component.attr("disabled", "true"));
89
- }
90
- let match$1 = props.checked;
91
- if (match$1 !== undefined && match$1) {
92
- attrs.push(Xote__Component.attr("checked", "true"));
93
- }
94
- let match$2 = props.required;
95
- if (match$2 !== undefined && match$2) {
96
- attrs.push(Xote__Component.attr("required", "true"));
97
- }
98
- let match$3 = props.readOnly;
99
- if (match$3 !== undefined && match$3) {
100
- attrs.push(Xote__Component.attr("readonly", "true"));
101
- }
102
- let v$7 = props.maxLength;
110
+ let v$7 = props.disabled;
103
111
  if (v$7 !== undefined) {
104
- attrs.push(Xote__Component.attr("maxlength", v$7.toString()));
112
+ attrs.push(convertBoolAttrValue("disabled", Primitive_option.valFromOption(v$7)));
105
113
  }
106
- let v$8 = props.minLength;
114
+ let v$8 = props.checked;
107
115
  if (v$8 !== undefined) {
108
- attrs.push(Xote__Component.attr("minlength", v$8.toString()));
116
+ attrs.push(convertBoolAttrValue("checked", Primitive_option.valFromOption(v$8)));
109
117
  }
110
- let v$9 = props.min;
118
+ let v$9 = props.required;
111
119
  if (v$9 !== undefined) {
112
- attrs.push(convertAttrValue("min", Primitive_option.valFromOption(v$9)));
120
+ attrs.push(convertBoolAttrValue("required", Primitive_option.valFromOption(v$9)));
113
121
  }
114
- let v$10 = props.max;
122
+ let v$10 = props.readOnly;
115
123
  if (v$10 !== undefined) {
116
- attrs.push(convertAttrValue("max", Primitive_option.valFromOption(v$10)));
124
+ attrs.push(convertBoolAttrValue("readonly", Primitive_option.valFromOption(v$10)));
117
125
  }
118
- let v$11 = props.step;
126
+ let v$11 = props.maxLength;
119
127
  if (v$11 !== undefined) {
120
- attrs.push(convertAttrValue("step", Primitive_option.valFromOption(v$11)));
128
+ attrs.push(Xote__Component.attr("maxlength", v$11.toString()));
121
129
  }
122
- let v$12 = props.pattern;
130
+ let v$12 = props.minLength;
123
131
  if (v$12 !== undefined) {
124
- attrs.push(convertAttrValue("pattern", Primitive_option.valFromOption(v$12)));
132
+ attrs.push(Xote__Component.attr("minlength", v$12.toString()));
125
133
  }
126
- let v$13 = props.autoComplete;
134
+ let v$13 = props.min;
127
135
  if (v$13 !== undefined) {
128
- attrs.push(convertAttrValue("autocomplete", Primitive_option.valFromOption(v$13)));
136
+ attrs.push(convertAttrValue("min", Primitive_option.valFromOption(v$13)));
129
137
  }
130
- let match$4 = props.multiple;
131
- if (match$4 !== undefined && match$4) {
132
- attrs.push(Xote__Component.attr("multiple", "true"));
133
- }
134
- let v$14 = props.accept;
138
+ let v$14 = props.max;
135
139
  if (v$14 !== undefined) {
136
- attrs.push(convertAttrValue("accept", Primitive_option.valFromOption(v$14)));
140
+ attrs.push(convertAttrValue("max", Primitive_option.valFromOption(v$14)));
137
141
  }
138
- let v$15 = props.rows;
142
+ let v$15 = props.step;
139
143
  if (v$15 !== undefined) {
140
- attrs.push(Xote__Component.attr("rows", v$15.toString()));
144
+ attrs.push(convertAttrValue("step", Primitive_option.valFromOption(v$15)));
141
145
  }
142
- let v$16 = props.cols;
146
+ let v$16 = props.pattern;
143
147
  if (v$16 !== undefined) {
144
- attrs.push(Xote__Component.attr("cols", v$16.toString()));
148
+ attrs.push(convertAttrValue("pattern", Primitive_option.valFromOption(v$16)));
145
149
  }
146
- let v$17 = props.for;
150
+ let v$17 = props.autoComplete;
147
151
  if (v$17 !== undefined) {
148
- attrs.push(convertAttrValue("for", Primitive_option.valFromOption(v$17)));
152
+ attrs.push(convertAttrValue("autocomplete", Primitive_option.valFromOption(v$17)));
149
153
  }
150
- let v$18 = props.href;
154
+ let v$18 = props.multiple;
151
155
  if (v$18 !== undefined) {
152
- attrs.push(convertAttrValue("href", Primitive_option.valFromOption(v$18)));
156
+ attrs.push(convertBoolAttrValue("multiple", Primitive_option.valFromOption(v$18)));
153
157
  }
154
- let v$19 = props.target;
158
+ let v$19 = props.accept;
155
159
  if (v$19 !== undefined) {
156
- attrs.push(convertAttrValue("target", Primitive_option.valFromOption(v$19)));
160
+ attrs.push(convertAttrValue("accept", Primitive_option.valFromOption(v$19)));
157
161
  }
158
- let v$20 = props.src;
162
+ let v$20 = props.rows;
159
163
  if (v$20 !== undefined) {
160
- attrs.push(convertAttrValue("src", Primitive_option.valFromOption(v$20)));
164
+ attrs.push(Xote__Component.attr("rows", v$20.toString()));
161
165
  }
162
- let v$21 = props.alt;
166
+ let v$21 = props.cols;
163
167
  if (v$21 !== undefined) {
164
- attrs.push(convertAttrValue("alt", Primitive_option.valFromOption(v$21)));
168
+ attrs.push(Xote__Component.attr("cols", v$21.toString()));
165
169
  }
166
- let v$22 = props.width;
170
+ let v$22 = props.for;
167
171
  if (v$22 !== undefined) {
168
- attrs.push(convertAttrValue("width", Primitive_option.valFromOption(v$22)));
172
+ attrs.push(convertAttrValue("for", Primitive_option.valFromOption(v$22)));
169
173
  }
170
- let v$23 = props.height;
174
+ let v$23 = props.href;
171
175
  if (v$23 !== undefined) {
172
- attrs.push(convertAttrValue("height", Primitive_option.valFromOption(v$23)));
176
+ attrs.push(convertAttrValue("href", Primitive_option.valFromOption(v$23)));
173
177
  }
174
- let v$24 = props.role;
178
+ let v$24 = props.target;
175
179
  if (v$24 !== undefined) {
176
- attrs.push(convertAttrValue("role", Primitive_option.valFromOption(v$24)));
180
+ attrs.push(convertAttrValue("target", Primitive_option.valFromOption(v$24)));
177
181
  }
178
- let v$25 = props.tabIndex;
182
+ let v$25 = props.src;
179
183
  if (v$25 !== undefined) {
180
- attrs.push(Xote__Component.attr("tabindex", v$25.toString()));
184
+ attrs.push(convertAttrValue("src", Primitive_option.valFromOption(v$25)));
181
185
  }
182
- let v$26 = props["aria-label"];
186
+ let v$26 = props.alt;
183
187
  if (v$26 !== undefined) {
184
- attrs.push(convertAttrValue("aria-label", Primitive_option.valFromOption(v$26)));
188
+ attrs.push(convertAttrValue("alt", Primitive_option.valFromOption(v$26)));
185
189
  }
186
- let match$5 = props["aria-hidden"];
187
- if (match$5 !== undefined) {
188
- if (match$5) {
189
- attrs.push(Xote__Component.attr("aria-hidden", "true"));
190
- } else {
191
- attrs.push(Xote__Component.attr("aria-hidden", "false"));
192
- }
190
+ let v$27 = props.width;
191
+ if (v$27 !== undefined) {
192
+ attrs.push(convertAttrValue("width", Primitive_option.valFromOption(v$27)));
193
193
  }
194
- let match$6 = props["aria-expanded"];
195
- if (match$6 !== undefined) {
196
- if (match$6) {
197
- attrs.push(Xote__Component.attr("aria-expanded", "true"));
198
- } else {
199
- attrs.push(Xote__Component.attr("aria-expanded", "false"));
200
- }
194
+ let v$28 = props.height;
195
+ if (v$28 !== undefined) {
196
+ attrs.push(convertAttrValue("height", Primitive_option.valFromOption(v$28)));
201
197
  }
202
- let match$7 = props["aria-selected"];
203
- if (match$7 !== undefined) {
204
- if (match$7) {
205
- attrs.push(Xote__Component.attr("aria-selected", "true"));
206
- } else {
207
- attrs.push(Xote__Component.attr("aria-selected", "false"));
208
- }
198
+ let v$29 = props.role;
199
+ if (v$29 !== undefined) {
200
+ attrs.push(convertAttrValue("role", Primitive_option.valFromOption(v$29)));
201
+ }
202
+ let v$30 = props.tabIndex;
203
+ if (v$30 !== undefined) {
204
+ attrs.push(Xote__Component.attr("tabindex", v$30.toString()));
205
+ }
206
+ let v$31 = props["aria-label"];
207
+ if (v$31 !== undefined) {
208
+ attrs.push(convertAttrValue("aria-label", Primitive_option.valFromOption(v$31)));
209
+ }
210
+ let v$32 = props["aria-hidden"];
211
+ if (v$32 !== undefined) {
212
+ attrs.push(convertBoolAttrValue("aria-hidden", Primitive_option.valFromOption(v$32)));
213
+ }
214
+ let v$33 = props["aria-expanded"];
215
+ if (v$33 !== undefined) {
216
+ attrs.push(convertBoolAttrValue("aria-expanded", Primitive_option.valFromOption(v$33)));
217
+ }
218
+ let v$34 = props["aria-selected"];
219
+ if (v$34 !== undefined) {
220
+ attrs.push(convertBoolAttrValue("aria-selected", Primitive_option.valFromOption(v$34)));
209
221
  }
210
222
  let _dataObj = props.data;
211
223
  if (_dataObj !== undefined) {
@@ -330,6 +342,7 @@ let Elements = {
330
342
  signal: signal,
331
343
  computed: computed,
332
344
  convertAttrValue: convertAttrValue,
345
+ convertBoolAttrValue: convertBoolAttrValue,
333
346
  propsToAttrs: propsToAttrs,
334
347
  propsToEvents: propsToEvents,
335
348
  getChildren: getChildren,
@@ -353,4 +366,4 @@ export {
353
366
  $$null,
354
367
  Elements,
355
368
  }
356
- /* Xote__Component Not a pure module */
369
+ /* Signals Not a pure module */