@commmerce/ui 1.13.1 → 1.15.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.
@@ -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",
@@ -34232,6 +34321,17 @@
34232
34321
  "description": "Native autocomplete hint, e.g. `email`, `postal-code`.",
34233
34322
  "attribute": "autocomplete"
34234
34323
  },
34324
+ {
34325
+ "kind": "field",
34326
+ "name": "inputMode",
34327
+ "privacy": "public",
34328
+ "type": {
34329
+ "text": "string"
34330
+ },
34331
+ "default": "''",
34332
+ "description": "Which on-screen keyboard phones open: `email`, `url`, `tel`, `numeric`, `decimal`, `search` or `text`, passed to the\ninner input. Use it with `type=\"text\"` when your own check replaces the browser's (for example an email rule that\nmatches your server), so the box still opens the right keyboard. Since 1.15.",
34333
+ "attribute": "inputmode"
34334
+ },
34235
34335
  {
34236
34336
  "kind": "field",
34237
34337
  "name": "size",
@@ -34274,11 +34374,58 @@
34274
34374
  "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
34375
  "attribute": "step"
34276
34376
  },
34377
+ {
34378
+ "kind": "field",
34379
+ "name": "pattern",
34380
+ "privacy": "public",
34381
+ "type": {
34382
+ "text": "string | undefined"
34383
+ },
34384
+ "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.",
34385
+ "attribute": "pattern"
34386
+ },
34387
+ {
34388
+ "kind": "field",
34389
+ "name": "patternMessage",
34390
+ "privacy": "public",
34391
+ "type": {
34392
+ "text": "string"
34393
+ },
34394
+ "default": "''",
34395
+ "description": "The message when the value doesn't match `pattern`, e.g. \"Enter the 6-digit PIN.\". Since 1.14.",
34396
+ "attribute": "pattern-message"
34397
+ },
34398
+ {
34399
+ "kind": "field",
34400
+ "name": "minLength",
34401
+ "privacy": "public",
34402
+ "type": {
34403
+ "text": "number | undefined"
34404
+ },
34405
+ "description": "Fewest characters allowed (an empty value is left to `required`). Since 1.14.",
34406
+ "attribute": "minlength"
34407
+ },
34408
+ {
34409
+ "kind": "field",
34410
+ "name": "maxLength",
34411
+ "privacy": "public",
34412
+ "type": {
34413
+ "text": "number | undefined"
34414
+ },
34415
+ "description": "Most characters allowed: typing stops there, and a longer value set by code is invalid. Since 1.14.",
34416
+ "attribute": "maxlength"
34417
+ },
34277
34418
  {
34278
34419
  "kind": "field",
34279
34420
  "name": "#internals",
34280
34421
  "privacy": "private"
34281
34422
  },
34423
+ {
34424
+ "kind": "field",
34425
+ "name": "#v",
34426
+ "privacy": "private",
34427
+ "default": "new FieldValidity(this, this.#internals)"
34428
+ },
34282
34429
  {
34283
34430
  "kind": "field",
34284
34431
  "name": "#id",
@@ -34332,6 +34479,20 @@
34332
34479
  }
34333
34480
  ]
34334
34481
  },
34482
+ {
34483
+ "kind": "method",
34484
+ "name": "#matches",
34485
+ "privacy": "private",
34486
+ "parameters": [
34487
+ {
34488
+ "name": "value",
34489
+ "type": {
34490
+ "text": "string"
34491
+ }
34492
+ }
34493
+ ],
34494
+ "description": "Whether the whole value matches `pattern` (like the browser: `v` flag, anchored); a bad pattern never blocks."
34495
+ },
34335
34496
  {
34336
34497
  "kind": "method",
34337
34498
  "name": "#validate",
@@ -34624,6 +34785,15 @@
34624
34785
  "description": "Native autocomplete hint, e.g. `email`, `postal-code`.",
34625
34786
  "fieldName": "autocomplete"
34626
34787
  },
34788
+ {
34789
+ "name": "inputmode",
34790
+ "type": {
34791
+ "text": "string"
34792
+ },
34793
+ "default": "''",
34794
+ "description": "Which on-screen keyboard phones open: `email`, `url`, `tel`, `numeric`, `decimal`, `search` or `text`, passed to the\ninner input. Use it with `type=\"text\"` when your own check replaces the browser's (for example an email rule that\nmatches your server), so the box still opens the right keyboard. Since 1.15.",
34795
+ "fieldName": "inputMode"
34796
+ },
34627
34797
  {
34628
34798
  "name": "size",
34629
34799
  "type": {
@@ -34657,6 +34827,39 @@
34657
34827
  "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
34828
  "fieldName": "step"
34659
34829
  },
34830
+ {
34831
+ "name": "pattern",
34832
+ "type": {
34833
+ "text": "string | undefined"
34834
+ },
34835
+ "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.",
34836
+ "fieldName": "pattern"
34837
+ },
34838
+ {
34839
+ "name": "pattern-message",
34840
+ "type": {
34841
+ "text": "string"
34842
+ },
34843
+ "default": "''",
34844
+ "description": "The message when the value doesn't match `pattern`, e.g. \"Enter the 6-digit PIN.\". Since 1.14.",
34845
+ "fieldName": "patternMessage"
34846
+ },
34847
+ {
34848
+ "name": "minlength",
34849
+ "type": {
34850
+ "text": "number | undefined"
34851
+ },
34852
+ "description": "Fewest characters allowed (an empty value is left to `required`). Since 1.14.",
34853
+ "fieldName": "minLength"
34854
+ },
34855
+ {
34856
+ "name": "maxlength",
34857
+ "type": {
34858
+ "text": "number | undefined"
34859
+ },
34860
+ "description": "Most characters allowed: typing stops there, and a longer value set by code is invalid. Since 1.14.",
34861
+ "fieldName": "maxLength"
34862
+ },
34660
34863
  {
34661
34864
  "name": "strings",
34662
34865
  "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.13.1",
3
+ "version": "1.15.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.13.1",
54
- "@commmerce/tokens": "1.13.1",
53
+ "@commmerce/icons": "1.15.0",
54
+ "@commmerce/tokens": "1.15.0",
55
55
  "lit": "3.2.1"
56
56
  },
57
57
  "devDependencies": {