@commmerce/ui 1.13.1 → 1.14.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/dist/cdn.js +583 -573
- package/dist/components/checkbox.d.ts +3 -0
- package/dist/components/checkbox.js +18 -7
- package/dist/components/color-field.js +8 -4
- package/dist/components/combobox.js +12 -7
- package/dist/components/date-picker.js +17 -6
- package/dist/components/date-range-picker.js +12 -6
- package/dist/components/file-upload.js +12 -9
- package/dist/components/option-group.js +13 -5
- package/dist/components/radio.js +11 -7
- package/dist/components/select.js +12 -8
- package/dist/components/signature-field.js +9 -5
- package/dist/components/text-field.d.ts +29 -0
- package/dist/components/text-field.js +46 -8
- package/dist/custom-elements.json +183 -0
- package/dist/validation.d.ts +39 -0
- package/dist/validation.js +121 -0
- package/package.json +3 -3
|
@@ -9356,6 +9356,12 @@
|
|
|
9356
9356
|
"name": "#internals",
|
|
9357
9357
|
"privacy": "private"
|
|
9358
9358
|
},
|
|
9359
|
+
{
|
|
9360
|
+
"kind": "field",
|
|
9361
|
+
"name": "#v",
|
|
9362
|
+
"privacy": "private",
|
|
9363
|
+
"default": "new FieldValidity(this, this.#internals)"
|
|
9364
|
+
},
|
|
9359
9365
|
{
|
|
9360
9366
|
"kind": "field",
|
|
9361
9367
|
"name": "#id",
|
|
@@ -9375,10 +9381,24 @@
|
|
|
9375
9381
|
"name": "form",
|
|
9376
9382
|
"readonly": true
|
|
9377
9383
|
},
|
|
9384
|
+
{
|
|
9385
|
+
"kind": "field",
|
|
9386
|
+
"name": "validity",
|
|
9387
|
+
"readonly": true
|
|
9388
|
+
},
|
|
9389
|
+
{
|
|
9390
|
+
"kind": "field",
|
|
9391
|
+
"name": "validationMessage",
|
|
9392
|
+
"readonly": true
|
|
9393
|
+
},
|
|
9378
9394
|
{
|
|
9379
9395
|
"kind": "method",
|
|
9380
9396
|
"name": "checkValidity"
|
|
9381
9397
|
},
|
|
9398
|
+
{
|
|
9399
|
+
"kind": "method",
|
|
9400
|
+
"name": "reportValidity"
|
|
9401
|
+
},
|
|
9382
9402
|
{
|
|
9383
9403
|
"kind": "method",
|
|
9384
9404
|
"name": "formResetCallback"
|
|
@@ -9839,6 +9859,12 @@
|
|
|
9839
9859
|
"name": "#internals",
|
|
9840
9860
|
"privacy": "private"
|
|
9841
9861
|
},
|
|
9862
|
+
{
|
|
9863
|
+
"kind": "field",
|
|
9864
|
+
"name": "#v",
|
|
9865
|
+
"privacy": "private",
|
|
9866
|
+
"default": "new FieldValidity(this, this.#internals)"
|
|
9867
|
+
},
|
|
9842
9868
|
{
|
|
9843
9869
|
"kind": "field",
|
|
9844
9870
|
"name": "#id",
|
|
@@ -10643,6 +10669,12 @@
|
|
|
10643
10669
|
"name": "#internals",
|
|
10644
10670
|
"privacy": "private"
|
|
10645
10671
|
},
|
|
10672
|
+
{
|
|
10673
|
+
"kind": "field",
|
|
10674
|
+
"name": "#v",
|
|
10675
|
+
"privacy": "private",
|
|
10676
|
+
"default": "new FieldValidity(this, this.#internals)"
|
|
10677
|
+
},
|
|
10646
10678
|
{
|
|
10647
10679
|
"kind": "field",
|
|
10648
10680
|
"name": "#id",
|
|
@@ -14389,6 +14421,12 @@
|
|
|
14389
14421
|
"name": "#internals",
|
|
14390
14422
|
"privacy": "private"
|
|
14391
14423
|
},
|
|
14424
|
+
{
|
|
14425
|
+
"kind": "field",
|
|
14426
|
+
"name": "#v",
|
|
14427
|
+
"privacy": "private",
|
|
14428
|
+
"default": "new FieldValidity(this, this.#internals)"
|
|
14429
|
+
},
|
|
14392
14430
|
{
|
|
14393
14431
|
"kind": "field",
|
|
14394
14432
|
"name": "#id",
|
|
@@ -14688,6 +14726,11 @@
|
|
|
14688
14726
|
"name": "#validate",
|
|
14689
14727
|
"privacy": "private"
|
|
14690
14728
|
},
|
|
14729
|
+
{
|
|
14730
|
+
"kind": "method",
|
|
14731
|
+
"name": "#setValidity",
|
|
14732
|
+
"privacy": "private"
|
|
14733
|
+
},
|
|
14691
14734
|
{
|
|
14692
14735
|
"kind": "method",
|
|
14693
14736
|
"name": "#validateTime",
|
|
@@ -15558,6 +15601,12 @@
|
|
|
15558
15601
|
"name": "#internals",
|
|
15559
15602
|
"privacy": "private"
|
|
15560
15603
|
},
|
|
15604
|
+
{
|
|
15605
|
+
"kind": "field",
|
|
15606
|
+
"name": "#v",
|
|
15607
|
+
"privacy": "private",
|
|
15608
|
+
"default": "new FieldValidity(this, this.#internals)"
|
|
15609
|
+
},
|
|
15561
15610
|
{
|
|
15562
15611
|
"kind": "field",
|
|
15563
15612
|
"name": "#id",
|
|
@@ -16660,6 +16709,12 @@
|
|
|
16660
16709
|
"name": "#internals",
|
|
16661
16710
|
"privacy": "private"
|
|
16662
16711
|
},
|
|
16712
|
+
{
|
|
16713
|
+
"kind": "field",
|
|
16714
|
+
"name": "#v",
|
|
16715
|
+
"privacy": "private",
|
|
16716
|
+
"default": "new FieldValidity(this, this.#internals)"
|
|
16717
|
+
},
|
|
16663
16718
|
{
|
|
16664
16719
|
"kind": "field",
|
|
16665
16720
|
"name": "#id",
|
|
@@ -24156,6 +24211,12 @@
|
|
|
24156
24211
|
"name": "#internals",
|
|
24157
24212
|
"privacy": "private"
|
|
24158
24213
|
},
|
|
24214
|
+
{
|
|
24215
|
+
"kind": "field",
|
|
24216
|
+
"name": "#v",
|
|
24217
|
+
"privacy": "private",
|
|
24218
|
+
"default": "new FieldValidity(this, this.#internals, () => this.renderRoot.querySelector<HTMLElement>('button[tabindex=\"0\"]')?.focus())"
|
|
24219
|
+
},
|
|
24159
24220
|
{
|
|
24160
24221
|
"kind": "field",
|
|
24161
24222
|
"name": "#id",
|
|
@@ -25848,6 +25909,12 @@
|
|
|
25848
25909
|
"name": "#internals",
|
|
25849
25910
|
"privacy": "private"
|
|
25850
25911
|
},
|
|
25912
|
+
{
|
|
25913
|
+
"kind": "field",
|
|
25914
|
+
"name": "#v",
|
|
25915
|
+
"privacy": "private",
|
|
25916
|
+
"default": "new FieldValidity(this, this.#internals)"
|
|
25917
|
+
},
|
|
25851
25918
|
{
|
|
25852
25919
|
"kind": "field",
|
|
25853
25920
|
"name": "#id",
|
|
@@ -28499,6 +28566,16 @@
|
|
|
28499
28566
|
"module": "src/components/option-group.ts"
|
|
28500
28567
|
}
|
|
28501
28568
|
},
|
|
28569
|
+
{
|
|
28570
|
+
"kind": "field",
|
|
28571
|
+
"name": "#v",
|
|
28572
|
+
"privacy": "private",
|
|
28573
|
+
"default": "new FieldValidity(this, this.#internals, () => this.renderRoot.querySelector<HTMLElement>('button[tabindex=\"0\"]')?.focus())",
|
|
28574
|
+
"inheritedFrom": {
|
|
28575
|
+
"name": "CmOptionGroup",
|
|
28576
|
+
"module": "src/components/option-group.ts"
|
|
28577
|
+
}
|
|
28578
|
+
},
|
|
28502
28579
|
{
|
|
28503
28580
|
"kind": "field",
|
|
28504
28581
|
"name": "#id",
|
|
@@ -29155,6 +29232,12 @@
|
|
|
29155
29232
|
"name": "#internals",
|
|
29156
29233
|
"privacy": "private"
|
|
29157
29234
|
},
|
|
29235
|
+
{
|
|
29236
|
+
"kind": "field",
|
|
29237
|
+
"name": "#v",
|
|
29238
|
+
"privacy": "private",
|
|
29239
|
+
"default": "new FieldValidity(this, this.#internals)"
|
|
29240
|
+
},
|
|
29158
29241
|
{
|
|
29159
29242
|
"kind": "field",
|
|
29160
29243
|
"name": "#id",
|
|
@@ -30954,6 +31037,12 @@
|
|
|
30954
31037
|
"name": "#internals",
|
|
30955
31038
|
"privacy": "private"
|
|
30956
31039
|
},
|
|
31040
|
+
{
|
|
31041
|
+
"kind": "field",
|
|
31042
|
+
"name": "#v",
|
|
31043
|
+
"privacy": "private",
|
|
31044
|
+
"default": "new FieldValidity(this, this.#internals)"
|
|
31045
|
+
},
|
|
30957
31046
|
{
|
|
30958
31047
|
"kind": "field",
|
|
30959
31048
|
"name": "#id",
|
|
@@ -34274,11 +34363,58 @@
|
|
|
34274
34363
|
"description": "Allowed steps from `min`, as on a native input: a number for `number`, days for `date`, seconds for `time` and\n`datetime-local` (`900` = 15 minutes; under 60 shows seconds). `any` allows every value.",
|
|
34275
34364
|
"attribute": "step"
|
|
34276
34365
|
},
|
|
34366
|
+
{
|
|
34367
|
+
"kind": "field",
|
|
34368
|
+
"name": "pattern",
|
|
34369
|
+
"privacy": "public",
|
|
34370
|
+
"type": {
|
|
34371
|
+
"text": "string | undefined"
|
|
34372
|
+
},
|
|
34373
|
+
"description": "A regular expression the whole value must match, as on a native input (`[0-9]{6}` for a 6-digit PIN). An empty\nvalue is left to `required`. Say what's expected in `pattern-message`. Since 1.14.",
|
|
34374
|
+
"attribute": "pattern"
|
|
34375
|
+
},
|
|
34376
|
+
{
|
|
34377
|
+
"kind": "field",
|
|
34378
|
+
"name": "patternMessage",
|
|
34379
|
+
"privacy": "public",
|
|
34380
|
+
"type": {
|
|
34381
|
+
"text": "string"
|
|
34382
|
+
},
|
|
34383
|
+
"default": "''",
|
|
34384
|
+
"description": "The message when the value doesn't match `pattern`, e.g. \"Enter the 6-digit PIN.\". Since 1.14.",
|
|
34385
|
+
"attribute": "pattern-message"
|
|
34386
|
+
},
|
|
34387
|
+
{
|
|
34388
|
+
"kind": "field",
|
|
34389
|
+
"name": "minLength",
|
|
34390
|
+
"privacy": "public",
|
|
34391
|
+
"type": {
|
|
34392
|
+
"text": "number | undefined"
|
|
34393
|
+
},
|
|
34394
|
+
"description": "Fewest characters allowed (an empty value is left to `required`). Since 1.14.",
|
|
34395
|
+
"attribute": "minlength"
|
|
34396
|
+
},
|
|
34397
|
+
{
|
|
34398
|
+
"kind": "field",
|
|
34399
|
+
"name": "maxLength",
|
|
34400
|
+
"privacy": "public",
|
|
34401
|
+
"type": {
|
|
34402
|
+
"text": "number | undefined"
|
|
34403
|
+
},
|
|
34404
|
+
"description": "Most characters allowed: typing stops there, and a longer value set by code is invalid. Since 1.14.",
|
|
34405
|
+
"attribute": "maxlength"
|
|
34406
|
+
},
|
|
34277
34407
|
{
|
|
34278
34408
|
"kind": "field",
|
|
34279
34409
|
"name": "#internals",
|
|
34280
34410
|
"privacy": "private"
|
|
34281
34411
|
},
|
|
34412
|
+
{
|
|
34413
|
+
"kind": "field",
|
|
34414
|
+
"name": "#v",
|
|
34415
|
+
"privacy": "private",
|
|
34416
|
+
"default": "new FieldValidity(this, this.#internals)"
|
|
34417
|
+
},
|
|
34282
34418
|
{
|
|
34283
34419
|
"kind": "field",
|
|
34284
34420
|
"name": "#id",
|
|
@@ -34332,6 +34468,20 @@
|
|
|
34332
34468
|
}
|
|
34333
34469
|
]
|
|
34334
34470
|
},
|
|
34471
|
+
{
|
|
34472
|
+
"kind": "method",
|
|
34473
|
+
"name": "#matches",
|
|
34474
|
+
"privacy": "private",
|
|
34475
|
+
"parameters": [
|
|
34476
|
+
{
|
|
34477
|
+
"name": "value",
|
|
34478
|
+
"type": {
|
|
34479
|
+
"text": "string"
|
|
34480
|
+
}
|
|
34481
|
+
}
|
|
34482
|
+
],
|
|
34483
|
+
"description": "Whether the whole value matches `pattern` (like the browser: `v` flag, anchored); a bad pattern never blocks."
|
|
34484
|
+
},
|
|
34335
34485
|
{
|
|
34336
34486
|
"kind": "method",
|
|
34337
34487
|
"name": "#validate",
|
|
@@ -34657,6 +34807,39 @@
|
|
|
34657
34807
|
"description": "Allowed steps from `min`, as on a native input: a number for `number`, days for `date`, seconds for `time` and\n`datetime-local` (`900` = 15 minutes; under 60 shows seconds). `any` allows every value.",
|
|
34658
34808
|
"fieldName": "step"
|
|
34659
34809
|
},
|
|
34810
|
+
{
|
|
34811
|
+
"name": "pattern",
|
|
34812
|
+
"type": {
|
|
34813
|
+
"text": "string | undefined"
|
|
34814
|
+
},
|
|
34815
|
+
"description": "A regular expression the whole value must match, as on a native input (`[0-9]{6}` for a 6-digit PIN). An empty\nvalue is left to `required`. Say what's expected in `pattern-message`. Since 1.14.",
|
|
34816
|
+
"fieldName": "pattern"
|
|
34817
|
+
},
|
|
34818
|
+
{
|
|
34819
|
+
"name": "pattern-message",
|
|
34820
|
+
"type": {
|
|
34821
|
+
"text": "string"
|
|
34822
|
+
},
|
|
34823
|
+
"default": "''",
|
|
34824
|
+
"description": "The message when the value doesn't match `pattern`, e.g. \"Enter the 6-digit PIN.\". Since 1.14.",
|
|
34825
|
+
"fieldName": "patternMessage"
|
|
34826
|
+
},
|
|
34827
|
+
{
|
|
34828
|
+
"name": "minlength",
|
|
34829
|
+
"type": {
|
|
34830
|
+
"text": "number | undefined"
|
|
34831
|
+
},
|
|
34832
|
+
"description": "Fewest characters allowed (an empty value is left to `required`). Since 1.14.",
|
|
34833
|
+
"fieldName": "minLength"
|
|
34834
|
+
},
|
|
34835
|
+
{
|
|
34836
|
+
"name": "maxlength",
|
|
34837
|
+
"type": {
|
|
34838
|
+
"text": "number | undefined"
|
|
34839
|
+
},
|
|
34840
|
+
"description": "Most characters allowed: typing stops there, and a longer value set by code is invalid. Since 1.14.",
|
|
34841
|
+
"fieldName": "maxLength"
|
|
34842
|
+
},
|
|
34660
34843
|
{
|
|
34661
34844
|
"name": "strings",
|
|
34662
34845
|
"type": {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ReactiveElement } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* Field validation messages (1.14): one behaviour for every form field.
|
|
4
|
+
*
|
|
5
|
+
* - Leaving a field the person changed shows its own message under it when the value is wrong for any reason except
|
|
6
|
+
* "required and empty" (format, range, step, pattern, length, text that isn't a date). Tabbing past an empty
|
|
7
|
+
* required field shows nothing.
|
|
8
|
+
* - A submit that fails because of invalid fields shows the message on every invalid field, required ones included,
|
|
9
|
+
* instead of the browser's bubble, and moves focus to the first one.
|
|
10
|
+
* - Once shown, the message follows the value: it changes while the person types and goes as soon as the value is
|
|
11
|
+
* valid. An `error` set by the app always wins.
|
|
12
|
+
*
|
|
13
|
+
* "A submit" means `invalid` events caused by something the person did: a click (a submit button, the save bar) or
|
|
14
|
+
* Enter or a Ctrl/Cmd shortcut, or the field's own `reportValidity()`. Silent checks by the app (`checkValidity()`
|
|
15
|
+
* while typing or on load) keep the browser's behaviour and show nothing, so a Save button that is enabled from
|
|
16
|
+
* `form.checkValidity()` doesn't light up every field.
|
|
17
|
+
*
|
|
18
|
+
* Usage: `#v = new FieldValidity(this, this.#internals)`; render `this.#v.message` where `error` was rendered (and
|
|
19
|
+
* in aria-invalid / aria-describedby); call `this.#v.sync()` after every validity change (end of `updated()`);
|
|
20
|
+
* `this.#v.reset()` in `formResetCallback`; `this.#v.report()` in a `reportValidity()` override. While a message
|
|
21
|
+
* shows, the host has the `data-cm-invalid` attribute, for the critical border.
|
|
22
|
+
*/
|
|
23
|
+
type Host = ReactiveElement & {
|
|
24
|
+
error?: string;
|
|
25
|
+
};
|
|
26
|
+
export declare class FieldValidity {
|
|
27
|
+
#private;
|
|
28
|
+
/** `focus` moves focus to the field; the default focuses the host (components with `delegatesFocus`). */
|
|
29
|
+
constructor(host: Host, internals: ElementInternals, focus?: () => void);
|
|
30
|
+
/** The message to show under the field: the app's `error`, or the field's own message once it is shown. */
|
|
31
|
+
get message(): string;
|
|
32
|
+
/** Call after the validity changed: re-renders when the message to show is different from the one on screen. */
|
|
33
|
+
sync(): void;
|
|
34
|
+
/** The form was reset: back to showing nothing. */
|
|
35
|
+
reset(): void;
|
|
36
|
+
/** For the field's own `reportValidity()`: show its message (no browser bubble) and focus it when invalid. */
|
|
37
|
+
report(check: () => boolean): boolean;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _FieldValidity_instances, _FieldValidity_host, _FieldValidity_internals, _FieldValidity_focus, _FieldValidity_changed, _FieldValidity_shown, _FieldValidity_synced, _FieldValidity_reporting, _FieldValidity_compute, _FieldValidity_onEdit, _FieldValidity_onLeave, _FieldValidity_onInvalid;
|
|
13
|
+
// Set during the task of a click, Enter or Ctrl/Cmd shortcut anywhere on the page; cleared on the next task.
|
|
14
|
+
let userAction = false;
|
|
15
|
+
// The first invalid field of this action has been focused.
|
|
16
|
+
let focused = false;
|
|
17
|
+
let listening = false;
|
|
18
|
+
const mark = () => {
|
|
19
|
+
if (userAction)
|
|
20
|
+
return;
|
|
21
|
+
userAction = true;
|
|
22
|
+
setTimeout(() => { userAction = false; focused = false; });
|
|
23
|
+
};
|
|
24
|
+
function listen() {
|
|
25
|
+
if (listening || typeof document === 'undefined')
|
|
26
|
+
return;
|
|
27
|
+
listening = true;
|
|
28
|
+
document.addEventListener('click', mark, true);
|
|
29
|
+
document.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.ctrlKey || e.metaKey)
|
|
30
|
+
mark(); }, true);
|
|
31
|
+
}
|
|
32
|
+
export class FieldValidity {
|
|
33
|
+
/** `focus` moves focus to the field; the default focuses the host (components with `delegatesFocus`). */
|
|
34
|
+
constructor(host, internals, focus) {
|
|
35
|
+
_FieldValidity_instances.add(this);
|
|
36
|
+
_FieldValidity_host.set(this, void 0);
|
|
37
|
+
_FieldValidity_internals.set(this, void 0);
|
|
38
|
+
_FieldValidity_focus.set(this, void 0);
|
|
39
|
+
_FieldValidity_changed.set(this, false);
|
|
40
|
+
_FieldValidity_shown.set(this, false);
|
|
41
|
+
_FieldValidity_synced.set(this, '');
|
|
42
|
+
_FieldValidity_reporting.set(this, false);
|
|
43
|
+
_FieldValidity_onEdit.set(this, () => { __classPrivateFieldSet(this, _FieldValidity_changed, true, "f"); });
|
|
44
|
+
_FieldValidity_onLeave.set(this, (e) => {
|
|
45
|
+
const to = e.relatedTarget;
|
|
46
|
+
if (to && (__classPrivateFieldGet(this, _FieldValidity_host, "f").contains(to) || __classPrivateFieldGet(this, _FieldValidity_host, "f").shadowRoot?.contains(to)))
|
|
47
|
+
return;
|
|
48
|
+
__classPrivateFieldGet(this, _FieldValidity_host, "f").updateComplete.then(() => {
|
|
49
|
+
if (!__classPrivateFieldGet(this, _FieldValidity_changed, "f") || __classPrivateFieldGet(this, _FieldValidity_shown, "f"))
|
|
50
|
+
return;
|
|
51
|
+
const v = __classPrivateFieldGet(this, _FieldValidity_internals, "f").validity;
|
|
52
|
+
if (v.valid || v.valueMissing)
|
|
53
|
+
return;
|
|
54
|
+
__classPrivateFieldSet(this, _FieldValidity_shown, true, "f");
|
|
55
|
+
__classPrivateFieldGet(this, _FieldValidity_host, "f").requestUpdate();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
_FieldValidity_onInvalid.set(this, (e) => {
|
|
59
|
+
if (!userAction && !__classPrivateFieldGet(this, _FieldValidity_reporting, "f"))
|
|
60
|
+
return; // a silent check: leave it to the browser
|
|
61
|
+
e.preventDefault(); // our message instead of the browser's bubble
|
|
62
|
+
__classPrivateFieldSet(this, _FieldValidity_shown, true, "f");
|
|
63
|
+
__classPrivateFieldGet(this, _FieldValidity_host, "f").requestUpdate();
|
|
64
|
+
if (__classPrivateFieldGet(this, _FieldValidity_reporting, "f")) {
|
|
65
|
+
__classPrivateFieldGet(this, _FieldValidity_focus, "f").call(this);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (focused)
|
|
69
|
+
return;
|
|
70
|
+
focused = true; // invalid fires in document order: this is the first invalid field of the submit
|
|
71
|
+
__classPrivateFieldGet(this, _FieldValidity_focus, "f").call(this);
|
|
72
|
+
});
|
|
73
|
+
__classPrivateFieldSet(this, _FieldValidity_host, host, "f");
|
|
74
|
+
__classPrivateFieldSet(this, _FieldValidity_internals, internals, "f");
|
|
75
|
+
__classPrivateFieldSet(this, _FieldValidity_focus, focus ?? (() => host.focus()), "f");
|
|
76
|
+
listen();
|
|
77
|
+
host.addEventListener('invalid', __classPrivateFieldGet(this, _FieldValidity_onInvalid, "f"));
|
|
78
|
+
// Capture: some fields stop their inner input's own `input` event and send one only for a committed value.
|
|
79
|
+
host.addEventListener('input', __classPrivateFieldGet(this, _FieldValidity_onEdit, "f"), true);
|
|
80
|
+
host.addEventListener('change', __classPrivateFieldGet(this, _FieldValidity_onEdit, "f"), true);
|
|
81
|
+
host.addEventListener('focusout', __classPrivateFieldGet(this, _FieldValidity_onLeave, "f"));
|
|
82
|
+
}
|
|
83
|
+
/** The message to show under the field: the app's `error`, or the field's own message once it is shown. */
|
|
84
|
+
get message() {
|
|
85
|
+
return __classPrivateFieldGet(this, _FieldValidity_instances, "m", _FieldValidity_compute).call(this);
|
|
86
|
+
}
|
|
87
|
+
/** Call after the validity changed: re-renders when the message to show is different from the one on screen. */
|
|
88
|
+
sync() {
|
|
89
|
+
const m = __classPrivateFieldGet(this, _FieldValidity_instances, "m", _FieldValidity_compute).call(this);
|
|
90
|
+
__classPrivateFieldGet(this, _FieldValidity_host, "f").toggleAttribute('data-cm-invalid', !!m);
|
|
91
|
+
// Validity is set after render, so a render may have shown the previous message: render once more when it
|
|
92
|
+
// changed. Compared with the last synced message, never with what render read, so it can't loop.
|
|
93
|
+
if (m === __classPrivateFieldGet(this, _FieldValidity_synced, "f"))
|
|
94
|
+
return;
|
|
95
|
+
__classPrivateFieldSet(this, _FieldValidity_synced, m, "f");
|
|
96
|
+
queueMicrotask(() => __classPrivateFieldGet(this, _FieldValidity_host, "f").requestUpdate());
|
|
97
|
+
}
|
|
98
|
+
/** The form was reset: back to showing nothing. */
|
|
99
|
+
reset() {
|
|
100
|
+
__classPrivateFieldSet(this, _FieldValidity_changed, __classPrivateFieldSet(this, _FieldValidity_shown, false, "f"), "f");
|
|
101
|
+
__classPrivateFieldGet(this, _FieldValidity_host, "f").requestUpdate();
|
|
102
|
+
}
|
|
103
|
+
/** For the field's own `reportValidity()`: show its message (no browser bubble) and focus it when invalid. */
|
|
104
|
+
report(check) {
|
|
105
|
+
__classPrivateFieldSet(this, _FieldValidity_reporting, true, "f");
|
|
106
|
+
try {
|
|
107
|
+
return check();
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
__classPrivateFieldSet(this, _FieldValidity_reporting, false, "f");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
_FieldValidity_host = new WeakMap(), _FieldValidity_internals = new WeakMap(), _FieldValidity_focus = new WeakMap(), _FieldValidity_changed = new WeakMap(), _FieldValidity_shown = new WeakMap(), _FieldValidity_synced = new WeakMap(), _FieldValidity_reporting = new WeakMap(), _FieldValidity_onEdit = new WeakMap(), _FieldValidity_onLeave = new WeakMap(), _FieldValidity_onInvalid = new WeakMap(), _FieldValidity_instances = new WeakSet(), _FieldValidity_compute = function _FieldValidity_compute() {
|
|
115
|
+
if (__classPrivateFieldGet(this, _FieldValidity_host, "f").error)
|
|
116
|
+
return __classPrivateFieldGet(this, _FieldValidity_host, "f").error;
|
|
117
|
+
if (!__classPrivateFieldGet(this, _FieldValidity_shown, "f"))
|
|
118
|
+
return '';
|
|
119
|
+
const v = __classPrivateFieldGet(this, _FieldValidity_internals, "f").validity;
|
|
120
|
+
return v.valid ? '' : __classPrivateFieldGet(this, _FieldValidity_internals, "f").validationMessage;
|
|
121
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commmerce/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Commmerce UI web components: build apps that feel native to the Commmerce admin. Works in plain HTML, React, Vue and server-rendered pages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"test": "vitest run"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@commmerce/icons": "1.
|
|
54
|
-
"@commmerce/tokens": "1.
|
|
53
|
+
"@commmerce/icons": "1.14.0",
|
|
54
|
+
"@commmerce/tokens": "1.14.0",
|
|
55
55
|
"lit": "3.2.1"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|