@thi.ng/rdom-forms 1.0.63 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/api.d.ts +9 -9
- package/compile.js +28 -21
- package/package.json +4 -4
package/README.md
CHANGED
package/api.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ export interface Num extends Value, WithPresets<number> {
|
|
|
70
70
|
placeholder?: StringAttrib;
|
|
71
71
|
size?: number;
|
|
72
72
|
step?: number | "any";
|
|
73
|
-
value?: ISubscription<number, number>;
|
|
73
|
+
value?: number | ISubscription<number, number>;
|
|
74
74
|
attribs?: Partial<InputNumericAttribs>;
|
|
75
75
|
}
|
|
76
76
|
export interface Range extends Omit<Num, "type" | "placeholder" | "size"> {
|
|
@@ -84,7 +84,7 @@ export interface Str extends Value, WithPresets<string> {
|
|
|
84
84
|
pattern?: string | RegExp | Predicate<string>;
|
|
85
85
|
placeholder?: StringAttrib;
|
|
86
86
|
size?: number;
|
|
87
|
-
value?: ISubscription<string, string>;
|
|
87
|
+
value?: string | ISubscription<string, string>;
|
|
88
88
|
attribs?: Partial<InputTextAttribs>;
|
|
89
89
|
}
|
|
90
90
|
export interface Email extends Omit<Str, "type"> {
|
|
@@ -107,19 +107,19 @@ export interface Text extends Value {
|
|
|
107
107
|
cols?: number;
|
|
108
108
|
rows?: number;
|
|
109
109
|
placeholder?: StringAttrib;
|
|
110
|
-
value?: ISubscription<string, string>;
|
|
110
|
+
value?: string | ISubscription<string, string>;
|
|
111
111
|
attribs?: Partial<TextAreaAttribs>;
|
|
112
112
|
}
|
|
113
113
|
export interface Color extends Value, WithPresets<string> {
|
|
114
114
|
type: "color";
|
|
115
|
-
value?: ISubscription<string, string>;
|
|
115
|
+
value?: string | ISubscription<string, string>;
|
|
116
116
|
}
|
|
117
117
|
export interface DateTime extends Value, WithPresets<string> {
|
|
118
118
|
type: "dateTime";
|
|
119
119
|
min?: string;
|
|
120
120
|
max?: string;
|
|
121
121
|
step?: number;
|
|
122
|
-
value?: ISubscription<string, string>;
|
|
122
|
+
value?: string | ISubscription<string, string>;
|
|
123
123
|
}
|
|
124
124
|
export interface DateVal extends Omit<DateTime, "type"> {
|
|
125
125
|
type: "date";
|
|
@@ -135,7 +135,7 @@ export interface Month extends Omit<DateTime, "type" | "list"> {
|
|
|
135
135
|
}
|
|
136
136
|
export interface Select<T> extends Value {
|
|
137
137
|
items: (T | SelectItem<T> | SelectItemGroup<T>)[];
|
|
138
|
-
value?: ISubscription<T, T>;
|
|
138
|
+
value?: T | ISubscription<T, T>;
|
|
139
139
|
attribs?: Partial<Omit<SelectAttribs, "multiple">>;
|
|
140
140
|
}
|
|
141
141
|
export interface SelectItemGroup<T> {
|
|
@@ -155,7 +155,7 @@ export interface SelectNum<T extends number = number> extends Select<T> {
|
|
|
155
155
|
}
|
|
156
156
|
export interface MultiSelect<T> extends Value {
|
|
157
157
|
items: (T | SelectItem<T> | SelectItemGroup<T>)[];
|
|
158
|
-
value?: ISubscription<T[], T[]>;
|
|
158
|
+
value?: T | ISubscription<T[], T[]>;
|
|
159
159
|
size?: number;
|
|
160
160
|
attribs?: Partial<Omit<SelectAttribs, "multiple">>;
|
|
161
161
|
}
|
|
@@ -167,7 +167,7 @@ export interface MultiSelectNum<T extends number = number> extends MultiSelect<T
|
|
|
167
167
|
}
|
|
168
168
|
export interface Toggle extends Value {
|
|
169
169
|
type: "toggle";
|
|
170
|
-
value?: ISubscription<boolean, boolean>;
|
|
170
|
+
value?: boolean | ISubscription<boolean, boolean>;
|
|
171
171
|
attribs?: Partial<InputCheckboxAttribs>;
|
|
172
172
|
}
|
|
173
173
|
export interface Trigger extends Value {
|
|
@@ -188,7 +188,7 @@ export interface Reset extends Omit<Value, "required" | "readonly"> {
|
|
|
188
188
|
}
|
|
189
189
|
export interface Radio<T> extends Value {
|
|
190
190
|
items: (T | SelectItem<T>)[];
|
|
191
|
-
value?: ISubscription<T, T>;
|
|
191
|
+
value?: T | ISubscription<T, T>;
|
|
192
192
|
attribs?: Partial<InputRadioAttribs>;
|
|
193
193
|
}
|
|
194
194
|
export interface RadioNum extends Radio<number> {
|
package/compile.js
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
$inputTrigger,
|
|
37
37
|
$replace
|
|
38
38
|
} from "@thi.ng/rdom";
|
|
39
|
+
import { isSubscriptionLike } from "@thi.ng/rstream/checks";
|
|
39
40
|
const form = (attribs, ...items) => ({
|
|
40
41
|
type: "form",
|
|
41
42
|
attribs,
|
|
@@ -216,7 +217,7 @@ const compileForm = defmulti(
|
|
|
216
217
|
const ctrl = checkbox(
|
|
217
218
|
__attribs(
|
|
218
219
|
{ ...opts.typeAttribs?.toggle },
|
|
219
|
-
{ onchange: $inputCheckbox(
|
|
220
|
+
isSubscriptionLike(val.value) ? { onchange: $inputCheckbox(val.value) } : {},
|
|
220
221
|
val,
|
|
221
222
|
opts,
|
|
222
223
|
"checked"
|
|
@@ -277,7 +278,7 @@ const compileForm = defmulti(
|
|
|
277
278
|
onchange: val.value && __useValues(opts) ? () => val.value.next(item.value) : void 0,
|
|
278
279
|
id: __genID(id, opts),
|
|
279
280
|
name: val.name || val.id,
|
|
280
|
-
checked: val.value && __useValues(opts) ? val.value.map((x) => x === item.value) : void 0,
|
|
281
|
+
checked: isSubscriptionLike(val.value) && __useValues(opts) ? val.value.map((x) => x === item.value) : void 0,
|
|
281
282
|
value: item.value
|
|
282
283
|
});
|
|
283
284
|
return div(
|
|
@@ -303,7 +304,11 @@ const compileForm = defmulti(
|
|
|
303
304
|
opts,
|
|
304
305
|
inputColor,
|
|
305
306
|
{ ...opts.typeAttribs?.color },
|
|
306
|
-
|
|
307
|
+
isSubscriptionLike($val.value) ? {
|
|
308
|
+
onchange: $input(
|
|
309
|
+
$val.value
|
|
310
|
+
)
|
|
311
|
+
} : {}
|
|
307
312
|
),
|
|
308
313
|
file: ($val, opts) => {
|
|
309
314
|
const val = $val;
|
|
@@ -338,7 +343,7 @@ const compileForm = defmulti(
|
|
|
338
343
|
placeholder: val.placeholder,
|
|
339
344
|
size: val.size
|
|
340
345
|
},
|
|
341
|
-
{ onchange: $inputNum(val.value) }
|
|
346
|
+
isSubscriptionLike(val.value) ? { onchange: $inputNum(val.value) } : {}
|
|
342
347
|
);
|
|
343
348
|
},
|
|
344
349
|
range: ($val, opts) => {
|
|
@@ -353,7 +358,7 @@ const compileForm = defmulti(
|
|
|
353
358
|
max: val.max,
|
|
354
359
|
step: val.step
|
|
355
360
|
},
|
|
356
|
-
{ [edit]: $inputNum(val.value) },
|
|
361
|
+
isSubscriptionLike(val.value) ? { [edit]: $inputNum(val.value) } : {},
|
|
357
362
|
val,
|
|
358
363
|
opts
|
|
359
364
|
)
|
|
@@ -361,14 +366,16 @@ const compileForm = defmulti(
|
|
|
361
366
|
];
|
|
362
367
|
if (val.value && val.vlabel !== false && __useValues(opts)) {
|
|
363
368
|
const fmt = val.vlabel === true || val.vlabel === void 0 ? opts.behaviors?.rangeLabelFmt ?? 2 : val.vlabel;
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
+
if (isSubscriptionLike(val.value)) {
|
|
370
|
+
children.push(
|
|
371
|
+
span(
|
|
372
|
+
{ ...opts.typeAttribs?.rangeLabel },
|
|
373
|
+
val.value.map(
|
|
374
|
+
isFunction(fmt) ? fmt : (x) => x.toFixed(fmt)
|
|
375
|
+
)
|
|
369
376
|
)
|
|
370
|
-
)
|
|
371
|
-
|
|
377
|
+
);
|
|
378
|
+
}
|
|
372
379
|
}
|
|
373
380
|
return div(
|
|
374
381
|
{ ...opts.wrapperAttribs, ...val.wrapperAttribs },
|
|
@@ -394,7 +401,7 @@ const compileForm = defmulti(
|
|
|
394
401
|
pattern: isString(val.pattern) ? val.pattern : void 0,
|
|
395
402
|
size: val.size
|
|
396
403
|
},
|
|
397
|
-
{ [edit]: __edit(val) }
|
|
404
|
+
isSubscriptionLike(val.value) ? { [edit]: __edit(val) } : {}
|
|
398
405
|
);
|
|
399
406
|
},
|
|
400
407
|
text: ($val, opts) => {
|
|
@@ -410,7 +417,7 @@ const compileForm = defmulti(
|
|
|
410
417
|
rows: val.rows,
|
|
411
418
|
placeholder: val.placeholder
|
|
412
419
|
},
|
|
413
|
-
{ [edit]: $input(val.value) }
|
|
420
|
+
isSubscriptionLike(val.value) ? { [edit]: $input(val.value) } : {}
|
|
414
421
|
);
|
|
415
422
|
},
|
|
416
423
|
date: ($val, opts) => {
|
|
@@ -427,7 +434,7 @@ const compileForm = defmulti(
|
|
|
427
434
|
max: val.max,
|
|
428
435
|
step: val.step
|
|
429
436
|
},
|
|
430
|
-
{ onchange: $input(val.value) }
|
|
437
|
+
isSubscriptionLike(val.value) ? { onchange: $input(val.value) } : {}
|
|
431
438
|
);
|
|
432
439
|
},
|
|
433
440
|
select: ($val, opts) => {
|
|
@@ -448,9 +455,9 @@ const compileForm = defmulti(
|
|
|
448
455
|
{
|
|
449
456
|
...opts.typeAttribs?.[val.type] || opts.typeAttribs?.select
|
|
450
457
|
},
|
|
451
|
-
{
|
|
458
|
+
isSubscriptionLike(val.value) ? {
|
|
452
459
|
onchange: isNumeric ? $inputNum(val.value) : $input(val.value)
|
|
453
|
-
},
|
|
460
|
+
} : {},
|
|
454
461
|
val,
|
|
455
462
|
opts,
|
|
456
463
|
false
|
|
@@ -465,14 +472,14 @@ const compileForm = defmulti(
|
|
|
465
472
|
return div(
|
|
466
473
|
{ ...opts.wrapperAttribs, ...val.wrapperAttribs },
|
|
467
474
|
...__genCommon(val, opts),
|
|
468
|
-
val.value && __useValues(opts) ? $replace(val.value.map($select)) : $select()
|
|
475
|
+
isSubscriptionLike(val.value) && __useValues(opts) ? $replace(val.value.map($select)) : $select()
|
|
469
476
|
);
|
|
470
477
|
},
|
|
471
478
|
multiSelect: ($val, opts) => {
|
|
472
479
|
const val = $val;
|
|
473
480
|
const isNumeric = val.type.endsWith("Num");
|
|
474
481
|
const coerce = isNumeric ? (x) => parseFloat(x.value) : (x) => x.value;
|
|
475
|
-
const sel = val.value && __useValues(opts) ? val.value.map((x) => isArray(x) ? x : [x]) : null;
|
|
482
|
+
const sel = isSubscriptionLike(val.value) && __useValues(opts) ? val.value.map((x) => isArray(x) ? x : [x]) : null;
|
|
476
483
|
const $option = ($item) => {
|
|
477
484
|
const item = isPlainObject($item) ? $item : { value: $item };
|
|
478
485
|
return option(
|
|
@@ -492,7 +499,7 @@ const compileForm = defmulti(
|
|
|
492
499
|
multiple: true,
|
|
493
500
|
size: val.size
|
|
494
501
|
},
|
|
495
|
-
{
|
|
502
|
+
isSubscriptionLike(val.value) ? {
|
|
496
503
|
onchange: (e) => {
|
|
497
504
|
val.value.next(
|
|
498
505
|
[
|
|
@@ -500,7 +507,7 @@ const compileForm = defmulti(
|
|
|
500
507
|
].map(coerce)
|
|
501
508
|
);
|
|
502
509
|
}
|
|
503
|
-
},
|
|
510
|
+
} : {},
|
|
504
511
|
false,
|
|
505
512
|
...val.items.map(
|
|
506
513
|
(item) => isPlainObject(item) && "items" in item ? optGroup(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/rdom-forms",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Data-driven declarative & extensible HTML form generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"@thi.ng/checks": "^3.8.6",
|
|
45
45
|
"@thi.ng/defmulti": "^3.0.93",
|
|
46
46
|
"@thi.ng/hiccup-html": "^2.7.48",
|
|
47
|
-
"@thi.ng/rdom": "^1.7.
|
|
48
|
-
"@thi.ng/rstream": "^9.
|
|
47
|
+
"@thi.ng/rdom": "^1.7.81",
|
|
48
|
+
"@thi.ng/rstream": "^9.4.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"esbuild": "^0.27.2",
|
|
@@ -99,5 +99,5 @@
|
|
|
99
99
|
"status": "alpha",
|
|
100
100
|
"year": 2023
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "18e5911e6d52c86190706438b753de415379d3fa\n"
|
|
103
103
|
}
|