@greypan/web-ui 3.0.1 → 4.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.
- package/README.CN.md +292 -31
- package/README.md +294 -31
- package/dist/_virtual/{_@oxc-project_runtime@0.140.0 → _@oxc-project_runtime@0.146.0}/helpers/esm/decorate.js +1 -1
- package/dist/assets/glass.js +1 -1
- package/dist/assets/glass.js.map +1 -1
- package/dist/assets/menu-portal.js +1 -1
- package/dist/assets/menu-portal.js.map +1 -1
- package/dist/assets/overlay-motion.js +1 -1
- package/dist/assets/overlay-motion.js.map +1 -1
- package/dist/assets/toast-containers.js +1 -1
- package/dist/assets/toast-containers.js.map +1 -1
- package/dist/components/autocomplete/index.d.ts +4 -12
- package/dist/components/autocomplete/index.js +95 -102
- package/dist/components/autocomplete/index.js.map +1 -1
- package/dist/components/autocomplete/style.js +1 -1
- package/dist/components/autocomplete/style.js.map +1 -1
- package/dist/components/avatar/index.d.ts +0 -1
- package/dist/components/avatar/index.js +8 -13
- package/dist/components/avatar/index.js.map +1 -1
- package/dist/components/back-top/index.js +1 -1
- package/dist/components/back-top/style.js +1 -1
- package/dist/components/back-top/style.js.map +1 -1
- package/dist/components/badge/index.d.ts +1 -0
- package/dist/components/badge/index.js +12 -14
- package/dist/components/badge/index.js.map +1 -1
- package/dist/components/button/index.d.ts +2 -0
- package/dist/components/button/index.js +51 -38
- package/dist/components/button/index.js.map +1 -1
- package/dist/components/button/style.js +1 -1
- package/dist/components/button/style.js.map +1 -1
- package/dist/components/button-group/index.d.ts +1 -2
- package/dist/components/button-group/index.js +19 -23
- package/dist/components/button-group/index.js.map +1 -1
- package/dist/components/checkbox/index.d.ts +4 -7
- package/dist/components/checkbox/index.js +48 -37
- package/dist/components/checkbox/index.js.map +1 -1
- package/dist/components/checkbox/style.js +1 -1
- package/dist/components/checkbox/style.js.map +1 -1
- package/dist/components/checkbox-group/index.d.ts +4 -10
- package/dist/components/checkbox-group/index.js +74 -60
- package/dist/components/checkbox-group/index.js.map +1 -1
- package/dist/components/context-menu/index.js +7 -8
- package/dist/components/context-menu/index.js.map +1 -1
- package/dist/components/dialog/index.js +6 -6
- package/dist/components/dialog/index.js.map +1 -1
- package/dist/components/dialog/style.js +1 -1
- package/dist/components/dialog/style.js.map +1 -1
- package/dist/components/drawer/index.d.ts +15 -0
- package/dist/components/drawer/index.js +58 -34
- package/dist/components/drawer/index.js.map +1 -1
- package/dist/components/drawer/style.js +1 -1
- package/dist/components/drawer/style.js.map +1 -1
- package/dist/components/dropdown/index.js +1 -1
- package/dist/components/dropdown-divider/index.js +1 -1
- package/dist/components/dropdown-header/index.js +1 -1
- package/dist/components/dropdown-header/style.js +1 -1
- package/dist/components/dropdown-header/style.js.map +1 -1
- package/dist/components/dropdown-item/index.js +3 -2
- package/dist/components/dropdown-item/index.js.map +1 -1
- package/dist/components/empty/index.js +1 -1
- package/dist/components/empty/style.js +1 -1
- package/dist/components/empty/style.js.map +1 -1
- package/dist/components/icon/index.js +1 -1
- package/dist/components/index.js +9 -9
- package/dist/components/input/index.d.ts +2 -3
- package/dist/components/input/index.js +62 -52
- package/dist/components/input/index.js.map +1 -1
- package/dist/components/input/style.js +1 -1
- package/dist/components/input/style.js.map +1 -1
- package/dist/components/input-number/index.d.ts +2 -3
- package/dist/components/input-number/index.js +58 -38
- package/dist/components/input-number/index.js.map +1 -1
- package/dist/components/input-number/style.js +1 -1
- package/dist/components/input-number/style.js.map +1 -1
- package/dist/components/layout/index.d.ts +53 -3
- package/dist/components/layout/index.js +146 -39
- package/dist/components/layout/index.js.map +1 -1
- package/dist/components/layout/style.js +1 -1
- package/dist/components/layout/style.js.map +1 -1
- package/dist/components/option/index.js +1 -1
- package/dist/components/option/style.js +1 -1
- package/dist/components/option/style.js.map +1 -1
- package/dist/components/popover/index.js +7 -5
- package/dist/components/popover/index.js.map +1 -1
- package/dist/components/popover/style.js +1 -1
- package/dist/components/popover/style.js.map +1 -1
- package/dist/components/radio/index.d.ts +4 -7
- package/dist/components/radio/index.js +48 -37
- package/dist/components/radio/index.js.map +1 -1
- package/dist/components/radio/style.js +1 -1
- package/dist/components/radio/style.js.map +1 -1
- package/dist/components/radio-group/index.d.ts +4 -10
- package/dist/components/radio-group/index.js +70 -52
- package/dist/components/radio-group/index.js.map +1 -1
- package/dist/components/segmented/index.d.ts +6 -11
- package/dist/components/segmented/index.js +67 -55
- package/dist/components/segmented/index.js.map +1 -1
- package/dist/components/segmented/style.js +1 -1
- package/dist/components/segmented/style.js.map +1 -1
- package/dist/components/segmented-trigger/index.d.ts +1 -2
- package/dist/components/segmented-trigger/index.js +18 -19
- package/dist/components/segmented-trigger/index.js.map +1 -1
- package/dist/components/segmented-trigger/style.js +1 -1
- package/dist/components/segmented-trigger/style.js.map +1 -1
- package/dist/components/select/index.d.ts +13 -8
- package/dist/components/select/index.js +110 -75
- package/dist/components/select/index.js.map +1 -1
- package/dist/components/select/style.js +1 -1
- package/dist/components/select/style.js.map +1 -1
- package/dist/components/slider/index.d.ts +3 -5
- package/dist/components/slider/index.js +59 -42
- package/dist/components/slider/index.js.map +1 -1
- package/dist/components/slider/style.js +1 -1
- package/dist/components/slider/style.js.map +1 -1
- package/dist/components/spinner/index.d.ts +0 -2
- package/dist/components/spinner/index.js +14 -13
- package/dist/components/spinner/index.js.map +1 -1
- package/dist/components/spinner/style.js +1 -1
- package/dist/components/spinner/style.js.map +1 -1
- package/dist/components/svg-draw-lines/index.js +1 -1
- package/dist/components/switch/index.d.ts +5 -6
- package/dist/components/switch/index.js +51 -37
- package/dist/components/switch/index.js.map +1 -1
- package/dist/components/switch/style.js +1 -1
- package/dist/components/switch/style.js.map +1 -1
- package/dist/components/textarea/index.d.ts +5 -6
- package/dist/components/textarea/index.js +73 -63
- package/dist/components/textarea/index.js.map +1 -1
- package/dist/components/textarea/style.js +1 -1
- package/dist/components/textarea/style.js.map +1 -1
- package/dist/components/theme/index.js +1 -1
- package/dist/components/theme/style.js +1 -1
- package/dist/components/theme/style.js.map +1 -1
- package/dist/components/toast/style.js +1 -1
- package/dist/components/toast/style.js.map +1 -1
- package/dist/components/toast/toast.js +12 -12
- package/dist/components/toast/toast.js.map +1 -1
- package/dist/components/tooltip/index.js +1 -1
- package/dist/components/tooltip/style.js +1 -1
- package/dist/components/tooltip/style.js.map +1 -1
- package/dist/icons/generated/lucide-clapperboard.d.ts +6 -0
- package/dist/icons/generated/lucide-clapperboard.js +10 -0
- package/dist/icons/generated/lucide-clapperboard.js.map +1 -0
- package/dist/icons/generated/lucide-eye.d.ts +6 -0
- package/dist/icons/generated/lucide-eye.js +10 -0
- package/dist/icons/generated/lucide-eye.js.map +1 -0
- package/dist/icons/generated/lucide-headphones.d.ts +6 -0
- package/dist/icons/generated/lucide-headphones.js +10 -0
- package/dist/icons/generated/lucide-headphones.js.map +1 -0
- package/dist/icons/generated/lucide-link.d.ts +6 -0
- package/dist/icons/generated/lucide-link.js +10 -0
- package/dist/icons/generated/lucide-link.js.map +1 -0
- package/dist/icons/generated/lucide-pen-line.d.ts +6 -0
- package/dist/icons/generated/lucide-pen-line.js +10 -0
- package/dist/icons/generated/lucide-pen-line.js.map +1 -0
- package/dist/icons/generated/lucide-play.d.ts +6 -0
- package/dist/icons/generated/lucide-play.js +10 -0
- package/dist/icons/generated/lucide-play.js.map +1 -0
- package/dist/icons/generated/lucide-sliders-horizontal.d.ts +6 -0
- package/dist/icons/generated/lucide-sliders-horizontal.js +10 -0
- package/dist/icons/generated/lucide-sliders-horizontal.js.map +1 -0
- package/dist/icons/index.d.ts +7 -0
- package/dist/icons/index.js +8 -1
- package/dist/node_modules/.pnpm/@floating-ui_core@1.8.0/node_modules/@floating-ui/core/dist/floating-ui.core.js +1 -3
- package/dist/node_modules/.pnpm/@floating-ui_core@1.8.0/node_modules/@floating-ui/core/dist/floating-ui.core.js.map +1 -1
- package/dist/node_modules/.pnpm/@floating-ui_utils@0.2.12/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js +2 -1
- package/dist/node_modules/.pnpm/@floating-ui_utils@0.2.12/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js.map +1 -1
- package/dist/shared/events/user-change.js.map +1 -1
- package/dist/shared/form-association/index.js +41 -0
- package/dist/shared/form-association/index.js.map +1 -0
- package/dist/shared/group-management/index.js +109 -0
- package/dist/shared/group-management/index.js.map +1 -0
- package/dist/shared/menu-portal/menu-tree.js +20 -7
- package/dist/shared/menu-portal/menu-tree.js.map +1 -1
- package/dist/shared/option-portal/index.js +65 -0
- package/dist/shared/option-portal/index.js.map +1 -0
- package/dist/shared/overlay/overlay.js +1 -1
- package/dist/shared/overlay/overlay.js.map +1 -1
- package/dist/shared/overlay/portal.js +9 -6
- package/dist/shared/overlay/portal.js.map +1 -1
- package/dist/shared/overlay/presence.js.map +1 -1
- package/dist/shared/visible-area/index.js +69 -0
- package/dist/shared/visible-area/index.js.map +1 -0
- package/package.json +6 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/button-group/index.ts"],"sourcesContent":["import { html, LitElement, unsafeCSS } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\n// web-ui-button 必须注册(Rolldown tree-shake 副作用 import,引用类名阻止删除)\nimport '@/components/button'\nimport glass from '@/assets/glass.css?inline'\nimport { normalizeLiteral } from '@/shared/normalize'\n\nimport style from './style.css?inline'\n\nconst ALLOWED_DIRECTIONS = ['horizontal', 'vertical'] as const\n\n@customElement('web-ui-button-group')\nexport class WebUiButtonGroup extends LitElement {\n static override styles = [unsafeCSS(glass), unsafeCSS(style)]\n\n @property({ type: String, reflect: true })\n get direction(): 'horizontal' | 'vertical' {\n return this._direction\n }\n set direction(v: string) {\n const old = this._direction\n this._direction = normalizeLiteral(v, ALLOWED_DIRECTIONS, 'horizontal')\n this.requestUpdate('direction', old)\n }\n private _direction: 'horizontal' | 'vertical' = 'horizontal'\n\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/button-group/index.ts"],"sourcesContent":["import { html, LitElement, unsafeCSS } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\n// web-ui-button 必须注册(Rolldown tree-shake 副作用 import,引用类名阻止删除)\nimport '@/components/button'\nimport glass from '@/assets/glass.css?inline'\nimport { defineGroupPresentation, GroupController, type ButtonGroupContext } from '@/shared/group-management'\nimport { normalizeLiteral } from '@/shared/normalize'\n\nimport type { WebUiButton } from '../button'\n\nimport style from './style.css?inline'\n\nconst ALLOWED_DIRECTIONS = ['horizontal', 'vertical'] as const\n\n@customElement('web-ui-button-group')\nexport class WebUiButtonGroup extends LitElement {\n static override styles = [unsafeCSS(glass), unsafeCSS(style)]\n\n @property({ type: String, reflect: true })\n get direction(): 'horizontal' | 'vertical' {\n return this._direction\n }\n set direction(v: string) {\n const old = this._direction\n this._direction = normalizeLiteral(v, ALLOWED_DIRECTIONS, 'horizontal')\n this.requestUpdate('direction', old)\n }\n private _direction: 'horizontal' | 'vertical' = 'horizontal'\n\n private readonly _groupController = new GroupController(\n this,\n defineGroupPresentation<WebUiButton, ButtonGroupContext>({\n getItems: () => [...this.querySelectorAll<WebUiButton>('web-ui-button')],\n getContext: (_, index, buttons) => ({\n direction: this.direction,\n isLast: index === buttons.length - 1\n })\n }).make()\n )\n\n override render() {\n return html`\n <div class=\"wui-glass wui-button-group-inner\">\n <slot></slot>\n </div>\n `\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'web-ui-button-group': WebUiButtonGroup\n }\n}\n"],"mappings":";;;;;;;;;AAaA,IAAM,IAAqB,CAAC,cAAc,UAAU,GAGvC,IAAN,cAA+B,EAAW;;EAcX,aAFY,KAAA,aAAA,cAEZ,KAAA,mBAAA,IAAI,EACtC,MACA,EAAyD;GACvD,gBAAgB,CAAC,GAAG,KAAK,iBAA8B,eAAe,CAAC;GACvE,aAAa,GAAG,GAAO,OAAa;IAClC,WAAW,KAAK;IAChB,QAAQ,MAAU,EAAQ,SAAS;GACrC;EACF,CAAC,CAAC,CAAC,KAAK,CACV;;;EAtByB,KAAA,SAAA,CAAC,EAAU,CAAK,GAAG,EAAU,CAAK,CAAC;;CAE5D,IACI,YAAuC;EACzC,OAAO,KAAK;CACd;CACA,IAAI,UAAU,GAAW;EACvB,IAAM,IAAM,KAAK;EAEjB,AADA,KAAK,aAAa,EAAiB,GAAG,GAAoB,YAAY,GACtE,KAAK,cAAc,aAAa,CAAG;CACrC;CAcA,SAAkB;EAChB,OAAO,CAAI;;;;;CAKb;AACF;AA7BG,EAAA,CAAA,EAAS;CAAE,MAAM;CAAQ,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,aAAA,IAAA,GAJ1C,IAAA,EAAA,CAAA,EAAc,qBAAqB,CAAA,GAAA,CAAA"}
|
|
@@ -2,9 +2,7 @@ import { LitElement } from 'lit';
|
|
|
2
2
|
export declare class WebUiCheckbox extends LitElement {
|
|
3
3
|
static styles: import('lit').CSSResult;
|
|
4
4
|
static formAssociated: boolean;
|
|
5
|
-
private
|
|
6
|
-
private _formDisabled;
|
|
7
|
-
private _groupDisabled;
|
|
5
|
+
private readonly _groupManagement;
|
|
8
6
|
private _checked;
|
|
9
7
|
get checked(): boolean;
|
|
10
8
|
set checked(v: boolean);
|
|
@@ -14,12 +12,11 @@ export declare class WebUiCheckbox extends LitElement {
|
|
|
14
12
|
required: boolean;
|
|
15
13
|
private get _isDisabled();
|
|
16
14
|
private get _isManagedByGroup();
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
private readonly _formAssociation;
|
|
16
|
+
private readonly _formAssociationController;
|
|
19
17
|
formResetCallback(): void;
|
|
20
18
|
formDisabledCallback(disabled: boolean): void;
|
|
21
|
-
|
|
22
|
-
private _syncFormValue;
|
|
19
|
+
formStateRestoreCallback(state: string | File | FormData | null): void;
|
|
23
20
|
private _syncValidity;
|
|
24
21
|
private handleClick;
|
|
25
22
|
private handleKeyDown;
|
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
import e from "../../_virtual/_@oxc-project_runtime@0.
|
|
1
|
+
import e from "../../_virtual/_@oxc-project_runtime@0.146.0/helpers/esm/decorate.js";
|
|
2
2
|
import "../icon/index.js";
|
|
3
3
|
import t from "../../icons/generated/heroicons-check-16-solid.js";
|
|
4
|
-
import n from "
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
4
|
+
import { FormAssociationController as n, defineFormAssociation as r } from "../../shared/form-association/index.js";
|
|
5
|
+
import { defineGroupManaged as i } from "../../shared/group-management/index.js";
|
|
6
|
+
import a from "./style.js";
|
|
7
|
+
import { LitElement as o, html as s, unsafeCSS as c } from "lit";
|
|
8
|
+
import { customElement as l, property as u, state as d } from "lit/decorators.js";
|
|
9
|
+
import { classMap as f } from "lit/directives/class-map.js";
|
|
8
10
|
//#region src/components/checkbox/index.ts
|
|
9
|
-
var
|
|
11
|
+
var p = class extends o {
|
|
10
12
|
constructor(...e) {
|
|
11
|
-
super(...e), this.
|
|
13
|
+
super(...e), this._groupManagement = i(this, { requestUpdate: () => this.requestUpdate() }).make(), this._checked = !1, this.value = "", this.name = "", this.disabled = !1, this.required = !1, this._formAssociation = r({
|
|
14
|
+
host: this,
|
|
15
|
+
initialize: () => {
|
|
16
|
+
this.hasAttribute("checked") && (this._checked = !0);
|
|
17
|
+
},
|
|
18
|
+
getState: () => this._checked,
|
|
19
|
+
setState: (e) => {
|
|
20
|
+
this.checked = e;
|
|
21
|
+
},
|
|
22
|
+
getFormValue: () => !this._isManagedByGroup && this._checked ? this.value || "on" : null,
|
|
23
|
+
getFormState: () => String(this._checked),
|
|
24
|
+
restoreState: (e) => {
|
|
25
|
+
typeof e == "string" && (this.checked = e === "true");
|
|
26
|
+
},
|
|
27
|
+
isStateManaged: () => this._isManagedByGroup,
|
|
28
|
+
syncValidity: () => this._syncValidity()
|
|
29
|
+
}).make(), this._formAssociationController = new n(this, this._formAssociation);
|
|
12
30
|
}
|
|
13
31
|
static {
|
|
14
|
-
this.styles = a
|
|
32
|
+
this.styles = c(a);
|
|
15
33
|
}
|
|
16
34
|
static {
|
|
17
35
|
this.formAssociated = !0;
|
|
@@ -21,45 +39,37 @@ var u = class extends r {
|
|
|
21
39
|
}
|
|
22
40
|
set checked(e) {
|
|
23
41
|
let t = this._checked;
|
|
24
|
-
this._checked = e, this.
|
|
42
|
+
this._checked = e, this._formAssociation.sync(), this.requestUpdate("checked", t);
|
|
25
43
|
}
|
|
26
44
|
get _isDisabled() {
|
|
27
|
-
return this.disabled || this.
|
|
45
|
+
return this.disabled || this._formAssociation.isFormDisabled() || this._groupManagement.getContext()?.disabled === !0;
|
|
28
46
|
}
|
|
29
47
|
get _isManagedByGroup() {
|
|
30
|
-
return this.
|
|
31
|
-
}
|
|
32
|
-
setGroupDisabled(e) {
|
|
33
|
-
this._groupDisabled = e;
|
|
34
|
-
}
|
|
35
|
-
connectedCallback() {
|
|
36
|
-
super.connectedCallback(), !this._internals && (this._internals = this.attachInternals(), this.hasAttribute("checked") && (this._checked = !0), this._syncFormValue());
|
|
48
|
+
return this._groupManagement.getContext() !== void 0;
|
|
37
49
|
}
|
|
38
50
|
formResetCallback() {
|
|
39
|
-
this.
|
|
51
|
+
this._formAssociation.reset();
|
|
40
52
|
}
|
|
41
53
|
formDisabledCallback(e) {
|
|
42
|
-
this.
|
|
43
|
-
}
|
|
44
|
-
updated() {
|
|
45
|
-
this._syncFormValue(), this._syncValidity();
|
|
54
|
+
this._formAssociation.setDisabled(e);
|
|
46
55
|
}
|
|
47
|
-
|
|
48
|
-
this.
|
|
56
|
+
formStateRestoreCallback(e) {
|
|
57
|
+
this._formAssociation.restore(e);
|
|
49
58
|
}
|
|
50
59
|
_syncValidity() {
|
|
51
|
-
|
|
60
|
+
let e = this._formAssociation.getInternals();
|
|
61
|
+
if (!(!e || typeof e.setValidity != "function")) {
|
|
52
62
|
if (this._isDisabled || this._isManagedByGroup || !this.required || this._checked) {
|
|
53
|
-
|
|
63
|
+
e.setValidity({});
|
|
54
64
|
return;
|
|
55
65
|
}
|
|
56
|
-
|
|
66
|
+
e.setValidity({ valueMissing: !0 }, "请选择此项");
|
|
57
67
|
}
|
|
58
68
|
}
|
|
59
69
|
handleClick() {
|
|
60
70
|
if (this._isDisabled) return;
|
|
61
71
|
let e = this._checked;
|
|
62
|
-
this._checked = !e, this.
|
|
72
|
+
this._checked = !e, this._formAssociation.sync(), this.requestUpdate("checked", e);
|
|
63
73
|
let t = this._isManagedByGroup ? {
|
|
64
74
|
bubbles: !1,
|
|
65
75
|
composed: !1
|
|
@@ -73,13 +83,14 @@ var u = class extends r {
|
|
|
73
83
|
(e.key === "Enter" || e.key === " ") && (e.preventDefault(), this.handleClick());
|
|
74
84
|
}
|
|
75
85
|
render() {
|
|
76
|
-
|
|
77
|
-
<label
|
|
78
|
-
class=${l({
|
|
86
|
+
let e = {
|
|
79
87
|
"wui-checkbox": !0,
|
|
80
88
|
"is-checked": this._checked,
|
|
81
89
|
"is-disabled": this._isDisabled
|
|
82
|
-
}
|
|
90
|
+
};
|
|
91
|
+
return s`
|
|
92
|
+
<label
|
|
93
|
+
class=${f(e)}
|
|
83
94
|
tabindex=${this._isDisabled ? "-1" : "0"}
|
|
84
95
|
role="checkbox"
|
|
85
96
|
aria-checked=${String(this._checked)}
|
|
@@ -97,17 +108,17 @@ var u = class extends r {
|
|
|
97
108
|
`;
|
|
98
109
|
}
|
|
99
110
|
};
|
|
100
|
-
e([
|
|
111
|
+
e([d()], p.prototype, "_checked", void 0), e([u({ type: String })], p.prototype, "value", void 0), e([u({
|
|
101
112
|
type: String,
|
|
102
113
|
reflect: !0
|
|
103
|
-
})],
|
|
114
|
+
})], p.prototype, "name", void 0), e([u({
|
|
104
115
|
type: Boolean,
|
|
105
116
|
reflect: !0
|
|
106
|
-
})],
|
|
117
|
+
})], p.prototype, "disabled", void 0), e([u({
|
|
107
118
|
type: Boolean,
|
|
108
119
|
reflect: !0
|
|
109
|
-
})],
|
|
120
|
+
})], p.prototype, "required", void 0), p = e([l("web-ui-checkbox")], p);
|
|
110
121
|
//#endregion
|
|
111
|
-
export {
|
|
122
|
+
export { p as WebUiCheckbox };
|
|
112
123
|
|
|
113
124
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/checkbox/index.ts"],"sourcesContent":["import { html, LitElement, unsafeCSS } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\nimport { classMap } from 'lit/directives/class-map.js'\n\nimport '@/components/icon'\nimport { heroiconsCheck16Solid } from '@/icons'\n\nimport style from './style.css?inline'\n\n@customElement('web-ui-checkbox')\nexport class WebUiCheckbox extends LitElement {\n static override styles = unsafeCSS(style)\n static formAssociated = true\n\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/checkbox/index.ts"],"sourcesContent":["import { html, LitElement, unsafeCSS } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\nimport { classMap } from 'lit/directives/class-map.js'\n\nimport '@/components/icon'\nimport { heroiconsCheck16Solid } from '@/icons'\nimport { defineFormAssociation, FormAssociationController } from '@/shared/form-association'\nimport { defineGroupManaged, type SelectionGroupContext } from '@/shared/group-management'\n\nimport style from './style.css?inline'\n\n@customElement('web-ui-checkbox')\nexport class WebUiCheckbox extends LitElement {\n static override styles = unsafeCSS(style)\n static formAssociated = true\n\n private readonly _groupManagement = defineGroupManaged<SelectionGroupContext>(this, {\n requestUpdate: () => this.requestUpdate()\n }).make()\n\n // 内部 checked 状态,通过 getter/setter 暴露为公共 API\n @state() private _checked = false\n\n get checked(): boolean {\n return this._checked\n }\n\n set checked(v: boolean) {\n const old = this._checked\n this._checked = v\n this._formAssociation.sync()\n this.requestUpdate('checked', old)\n }\n\n @property({ type: String }) value = ''\n @property({ type: String, reflect: true }) name = ''\n @property({ type: Boolean, reflect: true }) disabled = false\n @property({ type: Boolean, reflect: true }) required = false\n\n private get _isDisabled(): boolean {\n return (\n this.disabled || this._formAssociation.isFormDisabled() || this._groupManagement.getContext()?.disabled === true\n )\n }\n\n private get _isManagedByGroup(): boolean {\n return this._groupManagement.getContext() !== undefined\n }\n\n private readonly _formAssociation = defineFormAssociation<boolean>({\n host: this,\n initialize: () => {\n if (this.hasAttribute('checked')) this._checked = true\n },\n getState: () => this._checked,\n setState: checked => {\n this.checked = checked\n },\n getFormValue: () => (!this._isManagedByGroup && this._checked ? this.value || 'on' : null),\n getFormState: () => String(this._checked),\n restoreState: state => {\n if (typeof state === 'string') this.checked = state === 'true'\n },\n isStateManaged: () => this._isManagedByGroup,\n syncValidity: () => this._syncValidity()\n }).make()\n\n private readonly _formAssociationController = new FormAssociationController(this, this._formAssociation)\n\n formResetCallback() {\n this._formAssociation.reset()\n }\n\n formDisabledCallback(disabled: boolean) {\n this._formAssociation.setDisabled(disabled)\n }\n\n formStateRestoreCallback(state: string | File | FormData | null) {\n this._formAssociation.restore(state)\n }\n\n private _syncValidity() {\n const internals = this._formAssociation.getInternals()\n if (!internals || typeof internals.setValidity !== 'function') return\n if (this._isDisabled || this._isManagedByGroup || !this.required || this._checked) {\n internals.setValidity({})\n return\n }\n internals.setValidity({ valueMissing: true }, '请选择此项')\n }\n\n // 用户点击切换\n private handleClick() {\n if (this._isDisabled) return\n const old = this._checked\n this._checked = !old\n this._formAssociation.sync()\n this.requestUpdate('checked', old)\n // group-managed 时事件不冒泡/不组合,由 group 统一派发一次 host 事件,避免同名事件外泄\n const opts: EventInit = this._isManagedByGroup\n ? { bubbles: false, composed: false }\n : { bubbles: true, composed: true }\n this.dispatchEvent(new Event('input', opts))\n this.dispatchEvent(new Event('change', opts))\n }\n\n private handleKeyDown(e: KeyboardEvent) {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault()\n this.handleClick()\n }\n }\n\n override render() {\n const cls = {\n 'wui-checkbox': true,\n 'is-checked': this._checked,\n 'is-disabled': this._isDisabled\n }\n\n return html`\n <label\n class=${classMap(cls)}\n tabindex=${this._isDisabled ? '-1' : '0'}\n role=\"checkbox\"\n aria-checked=${String(this._checked)}\n aria-disabled=${String(this._isDisabled)}\n @click=${this.handleClick}\n @keydown=${this.handleKeyDown}\n >\n <span class=\"wui-checkbox-box\">\n <span class=\"wui-checkbox-icon\"\n ><web-ui-icon .icon=${heroiconsCheck16Solid} size=\"18\" color=\"#fff\"></web-ui-icon\n ></span>\n </span>\n <span class=\"wui-checkbox-label\"><slot></slot></span>\n </label>\n `\n }\n\n declare readonly $events: {\n input: Event\n change: Event\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'web-ui-checkbox': WebUiCheckbox\n }\n}\n"],"mappings":";;;;;;;;;;AAYO,IAAM,IAAN,cAA4B,EAAW;;EAuDE,aAnDV,KAAA,mBAAA,EAA0C,MAAM,EAClF,qBAAqB,KAAK,cAAc,EAC1C,CAAC,CAAC,CAAC,KAAK,GAGoB,KAAA,WAAA,IAaQ,KAAA,QAAA,IACc,KAAA,OAAA,IACK,KAAA,WAAA,IACA,KAAA,WAAA,IAYnB,KAAA,mBAAA,EAA+B;GACjE,MAAM;GACN,kBAAkB;IAChB,AAAI,KAAK,aAAa,SAAS,MAAG,KAAK,WAAW;GACpD;GACA,gBAAgB,KAAK;GACrB,WAAU,MAAW;IACnB,KAAK,UAAU;GACjB;GACA,oBAAqB,CAAC,KAAK,qBAAqB,KAAK,WAAW,KAAK,SAAS,OAAO;GACrF,oBAAoB,OAAO,KAAK,QAAQ;GACxC,eAAc,MAAS;IACrB,AAAI,OAAO,KAAU,aAAU,KAAK,UAAU,MAAU;GAC1D;GACA,sBAAsB,KAAK;GAC3B,oBAAoB,KAAK,cAAc;EACzC,CAAC,CAAC,CAAC,KAAK,GAEsC,KAAA,6BAAA,IAAI,EAA0B,MAAM,KAAK,gBAAgB;;;EAtD9E,KAAA,SAAA,EAAU,CAAK;;;EAChB,KAAA,iBAAA;;CASxB,IAAI,UAAmB;EACrB,OAAO,KAAK;CACd;CAEA,IAAI,QAAQ,GAAY;EACtB,IAAM,IAAM,KAAK;EAGjB,AAFA,KAAK,W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AK;EACtB;EAEA,OAAO,CAAI;;gBAEC,EAAS,CAAG,EAAE;mBACX,KAAK,cAAc,OAAO,IAAI;;uBAE1B,OAAO,KAAK,QAAQ,EAAE;wBACrB,OAAO,KAAK,WAAW,EAAE;iBAChC,KAAK,YAAY;mBACf,KAAK,cAAc;;;;kCAIJ,EAAsB;;;;;;CAMtD;AAMF;AA3HG,EAAA,CAAA,EAAM,CAAA,GAAA,EAAA,WAAA,YAAA,KAAA,CAAA,GAaN,EAAA,CAAA,EAAS,EAAE,MAAM,OAAO,CAAC,CAAA,GAAA,EAAA,WAAA,SAAA,KAAA,CAAA,GACzB,EAAA,CAAA,EAAS;CAAE,MAAM;CAAQ,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,QAAA,KAAA,CAAA,GACxC,EAAA,CAAA,EAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,YAAA,KAAA,CAAA,GACzC,EAAA,CAAA,EAAS;CAAE,MAAM;CAAS,SAAS;AAAK,CAAC,CAAA,GAAA,EAAA,WAAA,YAAA,KAAA,CAAA,GA1B3C,IAAA,EAAA,CAAA,EAAc,iBAAiB,CAAA,GAAA,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/components/checkbox/style.css?inline
|
|
2
|
-
var e = "*,:before,:after{box-sizing:border-box}:host{cursor:pointer;display:inline-block}:host([disabled]){cursor:not-allowed}.wui-checkbox{cursor:pointer;-webkit-user-select:none;user-select:none;font-size:var(--wui-font-size,14px);color:var(--wui-color-text,#1b1b1b);align-items:center;gap:10px;line-height:1;display:inline-flex}.wui-checkbox:focus-visible{outline:3px solid var(--wui-focus-ring,#08f6);outline-offset:2px;border-radius:2147483647px}.wui-checkbox.is-disabled{cursor:not-allowed;color:var(--wui-color-text-
|
|
2
|
+
var e = "*,:before,:after{box-sizing:border-box}:host{cursor:pointer;display:inline-block}:host([disabled]){cursor:not-allowed}.wui-checkbox{cursor:pointer;-webkit-user-select:none;user-select:none;font-size:var(--wui-font-size,14px);color:var(--wui-color-text,#1b1b1b);align-items:center;gap:10px;line-height:1;display:inline-flex}.wui-checkbox:focus-visible{outline:var(--wui-focus-ring-width,3px) solid var(--wui-color-focus-ring,#08f6);outline-offset:2px;border-radius:2147483647px}.wui-checkbox.is-disabled{cursor:not-allowed;color:var(--wui-color-text-secondary,#6a6a6a);opacity:.4}.wui-checkbox-box{background-color:var(--wui-color-surface-raised,#f2f2f7);border-radius:6px;flex-shrink:0;justify-content:center;align-items:center;width:18px;height:18px;transition:background-color .2s,border-color .2s;display:flex}.is-checked .wui-checkbox-box{border-color:var(--wui-color-accent,#08f);background-color:var(--wui-color-accent,#08f)}.wui-checkbox-icon{opacity:0;transition:opacity var(--wui-duration-trigger,.16s) ease, transform var(--wui-duration-trigger,.16s) var(--wui-ease-enter,cubic-bezier(.23, 1, .32, 1));font-size:0;line-height:0;display:block;overflow:hidden;transform:scale(.85)}.is-checked .wui-checkbox-icon{opacity:1;transform:scale(1)}.wui-checkbox-label{pointer-events:none}@media (prefers-reduced-motion:reduce){.wui-checkbox-icon,.is-checked .wui-checkbox-icon{transform:none}}";
|
|
3
3
|
//#endregion
|
|
4
4
|
export { e as default };
|
|
5
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","names":[],"sources":["../../../src/components/checkbox/style.css?inline"],"sourcesContent":["*,\n*::before,\n*::after {\n box-sizing: border-box;\n}\n\n:host {\n cursor: pointer;\n display: inline-block;\n}\n\n:host([disabled]) {\n cursor: not-allowed;\n}\n\n.wui-checkbox {\n cursor: pointer;\n user-select: none;\n\n display: inline-flex;\n gap: 10px;\n align-items: center;\n\n font-size: var(--wui-font-size, 14px);\n line-height: 1;\n color: var(--wui-color-text, #1b1b1b);\n\n &:focus-visible {\n border-radius: calc(infinity * 1px);\n outline: 3px solid var(--wui-focus-ring, rgb(0 136 255 / 0.4));\n outline-offset: 2px;\n }\n}\n\n.wui-checkbox.is-disabled {\n cursor: not-allowed;\n color: var(--wui-color-text-
|
|
1
|
+
{"version":3,"file":"style.js","names":[],"sources":["../../../src/components/checkbox/style.css?inline"],"sourcesContent":["*,\n*::before,\n*::after {\n box-sizing: border-box;\n}\n\n:host {\n cursor: pointer;\n display: inline-block;\n}\n\n:host([disabled]) {\n cursor: not-allowed;\n}\n\n.wui-checkbox {\n cursor: pointer;\n user-select: none;\n\n display: inline-flex;\n gap: 10px;\n align-items: center;\n\n font-size: var(--wui-font-size, 14px);\n line-height: 1;\n color: var(--wui-color-text, #1b1b1b);\n\n &:focus-visible {\n border-radius: calc(infinity * 1px);\n outline: var(--wui-focus-ring-width, 3px) solid var(--wui-color-focus-ring, rgb(0 136 255 / 0.4));\n outline-offset: 2px;\n }\n}\n\n.wui-checkbox.is-disabled {\n cursor: not-allowed;\n color: var(--wui-color-text-secondary, #6a6a6a);\n opacity: 0.4;\n}\n\n.wui-checkbox-box {\n display: flex;\n flex-shrink: 0;\n align-items: center;\n justify-content: center;\n\n width: 18px;\n height: 18px;\n border-radius: 6px;\n\n background-color: var(--wui-color-surface-raised, #f2f2f7);\n\n transition:\n background-color 0.2s ease,\n border-color 0.2s ease;\n}\n\n.is-checked .wui-checkbox-box {\n border-color: var(--wui-color-accent, #08f);\n background-color: var(--wui-color-accent, #08f);\n}\n\n.wui-checkbox-icon {\n transform: scale(0.85);\n\n overflow: hidden;\n display: block;\n\n font-size: 0;\n line-height: 0;\n\n opacity: 0;\n\n transition:\n opacity var(--wui-duration-trigger, 160ms) ease,\n transform var(--wui-duration-trigger, 160ms) var(--wui-ease-enter, cubic-bezier(0.23, 1, 0.32, 1));\n}\n\n.is-checked .wui-checkbox-icon {\n transform: scale(1);\n opacity: 1;\n}\n\n.wui-checkbox-label {\n pointer-events: none;\n}\n\n@media (prefers-reduced-motion: reduce) {\n .wui-checkbox-icon,\n .is-checked .wui-checkbox-icon {\n transform: none;\n }\n}\n"],"mappings":""}
|
|
@@ -6,22 +6,16 @@ export declare class WebUiCheckboxGroup extends LitElement {
|
|
|
6
6
|
disabled: boolean;
|
|
7
7
|
required: boolean;
|
|
8
8
|
private _value;
|
|
9
|
-
private
|
|
10
|
-
private _internals?;
|
|
11
|
-
private _initialValue;
|
|
9
|
+
private readonly _groupController;
|
|
12
10
|
get value(): string[];
|
|
13
11
|
set value(v: string[]);
|
|
14
12
|
private get _isDisabled();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
updated(changed: Map<string, unknown>): void;
|
|
13
|
+
private readonly _formAssociation;
|
|
14
|
+
private readonly _formAssociationController;
|
|
18
15
|
formResetCallback(): void;
|
|
19
16
|
formDisabledCallback(disabled: boolean): void;
|
|
20
|
-
|
|
17
|
+
formStateRestoreCallback(state: string | File | FormData | null): void;
|
|
21
18
|
private _syncValidity;
|
|
22
|
-
private _syncValueToChildren;
|
|
23
|
-
private _handleChildChange;
|
|
24
|
-
private _handleSlotChange;
|
|
25
19
|
render(): import('lit').TemplateResult<1>;
|
|
26
20
|
readonly $events: {
|
|
27
21
|
input: Event;
|
|
@@ -1,14 +1,65 @@
|
|
|
1
|
-
import e from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
-
import t from "
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import e from "../../_virtual/_@oxc-project_runtime@0.146.0/helpers/esm/decorate.js";
|
|
2
|
+
import { FormAssociationController as t, defineFormAssociation as n } from "../../shared/form-association/index.js";
|
|
3
|
+
import { GroupController as r, defineGroupCoordinator as i } from "../../shared/group-management/index.js";
|
|
4
|
+
import a from "./style.js";
|
|
5
|
+
import { LitElement as o, html as s, unsafeCSS as c } from "lit";
|
|
6
|
+
import { customElement as l, property as u, state as d } from "lit/decorators.js";
|
|
5
7
|
//#region src/components/checkbox-group/index.ts
|
|
6
|
-
var
|
|
8
|
+
var f = class extends o {
|
|
7
9
|
constructor(...e) {
|
|
8
|
-
super(...e), this.name = "", this.disabled = !1, this.required = !1, this._value = [], this.
|
|
10
|
+
super(...e), this.name = "", this.disabled = !1, this.required = !1, this._value = [], this._groupController = new r(this, i({
|
|
11
|
+
host: this,
|
|
12
|
+
getItems: () => [...this.querySelectorAll("web-ui-checkbox")],
|
|
13
|
+
getValue: () => this._value,
|
|
14
|
+
setValue: (e) => {
|
|
15
|
+
this.value = e;
|
|
16
|
+
},
|
|
17
|
+
getDisabled: () => this._isDisabled,
|
|
18
|
+
isItem: (e) => e instanceof HTMLElement && e.matches("web-ui-checkbox"),
|
|
19
|
+
isItemSelected: (e, t) => t.includes(e.value),
|
|
20
|
+
getNextValue: (e, t) => e.checked ? [.../* @__PURE__ */ new Set([...t, e.value])] : t.filter((t) => t !== e.value),
|
|
21
|
+
valuesEqual: (e, t) => e.length === t.length && e.every((e, n) => e === t[n]),
|
|
22
|
+
copyValue: (e) => [...e],
|
|
23
|
+
setItemSelected: (e, t) => {
|
|
24
|
+
e.checked = t;
|
|
25
|
+
},
|
|
26
|
+
dispatchValueChange: () => {
|
|
27
|
+
this.dispatchEvent(new Event("input", {
|
|
28
|
+
bubbles: !0,
|
|
29
|
+
composed: !0
|
|
30
|
+
})), this.dispatchEvent(new Event("change", {
|
|
31
|
+
bubbles: !0,
|
|
32
|
+
composed: !0
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
}).make()), this._formAssociation = n({
|
|
36
|
+
host: this,
|
|
37
|
+
initialize: () => {
|
|
38
|
+
let e = this.getAttribute("value");
|
|
39
|
+
e !== null && (this.value = e.split(",").filter(Boolean));
|
|
40
|
+
},
|
|
41
|
+
getState: () => this._value,
|
|
42
|
+
setState: (e) => {
|
|
43
|
+
this.value = e;
|
|
44
|
+
},
|
|
45
|
+
copyState: (e) => [...e],
|
|
46
|
+
getFormValue: () => {
|
|
47
|
+
if (!this.name || this._value.length === 0) return null;
|
|
48
|
+
let e = new FormData();
|
|
49
|
+
return this._value.forEach((t) => e.append(this.name, t)), e;
|
|
50
|
+
},
|
|
51
|
+
getFormState: () => JSON.stringify(this._value),
|
|
52
|
+
restoreState: (e) => {
|
|
53
|
+
if (typeof e == "string") try {
|
|
54
|
+
let t = JSON.parse(e);
|
|
55
|
+
Array.isArray(t) && t.every((e) => typeof e == "string") && (this.value = t);
|
|
56
|
+
} catch {}
|
|
57
|
+
},
|
|
58
|
+
syncValidity: () => this._syncValidity()
|
|
59
|
+
}).make(), this._formAssociationController = new t(this, this._formAssociation);
|
|
9
60
|
}
|
|
10
61
|
static {
|
|
11
|
-
this.styles =
|
|
62
|
+
this.styles = c(a);
|
|
12
63
|
}
|
|
13
64
|
static {
|
|
14
65
|
this.formAssociated = !0;
|
|
@@ -18,82 +69,45 @@ var c = class extends n {
|
|
|
18
69
|
}
|
|
19
70
|
set value(e) {
|
|
20
71
|
let t = this._value;
|
|
21
|
-
this._value = [...e], this.
|
|
72
|
+
this._value = [...e], this._formAssociation.sync(), this.requestUpdate("value", t);
|
|
22
73
|
}
|
|
23
74
|
get _isDisabled() {
|
|
24
|
-
return this.disabled || this.
|
|
25
|
-
}
|
|
26
|
-
connectedCallback() {
|
|
27
|
-
super.connectedCallback(), this._internals ||= this.attachInternals();
|
|
28
|
-
let e = this.getAttribute("value");
|
|
29
|
-
e !== null && (this.value = e.split(",").filter(Boolean)), this._initialValue = [...this._value], this.addEventListener("change", this._handleChildChange, !0);
|
|
30
|
-
}
|
|
31
|
-
disconnectedCallback() {
|
|
32
|
-
super.disconnectedCallback(), this.removeEventListener("change", this._handleChildChange, !0);
|
|
33
|
-
}
|
|
34
|
-
updated(e) {
|
|
35
|
-
(e.has("value") || e.has("disabled") || e.has("_formDisabled")) && this._syncValueToChildren(), this._syncFormValue(), this._syncValidity();
|
|
75
|
+
return this.disabled || this._formAssociation.isFormDisabled();
|
|
36
76
|
}
|
|
37
77
|
formResetCallback() {
|
|
38
|
-
this.
|
|
78
|
+
this._formAssociation.reset();
|
|
39
79
|
}
|
|
40
80
|
formDisabledCallback(e) {
|
|
41
|
-
this.
|
|
81
|
+
this._formAssociation.setDisabled(e), this._groupController.sync();
|
|
42
82
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (!this.name || this._value.length === 0) {
|
|
46
|
-
this._internals.setFormValue?.(null);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
let e = new FormData();
|
|
50
|
-
this._value.forEach((t) => e.append(this.name, t)), this._internals.setFormValue?.(e);
|
|
83
|
+
formStateRestoreCallback(e) {
|
|
84
|
+
this._formAssociation.restore(e);
|
|
51
85
|
}
|
|
52
86
|
_syncValidity() {
|
|
53
|
-
|
|
87
|
+
let e = this._formAssociation.getInternals();
|
|
88
|
+
if (!(!e || typeof e.setValidity != "function")) {
|
|
54
89
|
if (this._isDisabled || !this.required || this._value.length > 0) {
|
|
55
|
-
|
|
90
|
+
e.setValidity({});
|
|
56
91
|
return;
|
|
57
92
|
}
|
|
58
|
-
|
|
93
|
+
e.setValidity({ valueMissing: !0 }, "请至少选择一项");
|
|
59
94
|
}
|
|
60
95
|
}
|
|
61
|
-
_syncValueToChildren() {
|
|
62
|
-
this.querySelectorAll("web-ui-checkbox").forEach((e) => {
|
|
63
|
-
e.checked = this._value.includes(e.value), e.setGroupDisabled(this._isDisabled);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
_handleChildChange(e) {
|
|
67
|
-
if (this._isDisabled) return;
|
|
68
|
-
let t = e.target;
|
|
69
|
-
if (!t.matches?.("web-ui-checkbox")) return;
|
|
70
|
-
let n = t, r = n.checked ? [.../* @__PURE__ */ new Set([...this._value, n.value])] : this._value.filter((e) => e !== n.value);
|
|
71
|
-
this.value = r, this.dispatchEvent(new Event("input", {
|
|
72
|
-
bubbles: !0,
|
|
73
|
-
composed: !0
|
|
74
|
-
})), this.dispatchEvent(new Event("change", {
|
|
75
|
-
bubbles: !0,
|
|
76
|
-
composed: !0
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
_handleSlotChange() {
|
|
80
|
-
this._syncValueToChildren();
|
|
81
|
-
}
|
|
82
96
|
render() {
|
|
83
|
-
return
|
|
97
|
+
return s`<div class="wui-checkbox-group"><slot></slot></div>`;
|
|
84
98
|
}
|
|
85
99
|
};
|
|
86
|
-
e([
|
|
100
|
+
e([u({
|
|
87
101
|
type: String,
|
|
88
102
|
reflect: !0
|
|
89
|
-
})],
|
|
103
|
+
})], f.prototype, "name", void 0), e([u({
|
|
90
104
|
type: Boolean,
|
|
91
105
|
reflect: !0
|
|
92
|
-
})],
|
|
106
|
+
})], f.prototype, "disabled", void 0), e([u({
|
|
93
107
|
type: Boolean,
|
|
94
108
|
reflect: !0
|
|
95
|
-
})],
|
|
109
|
+
})], f.prototype, "required", void 0), e([d()], f.prototype, "_value", void 0), f = e([l("web-ui-checkbox-group")], f);
|
|
96
110
|
//#endregion
|
|
97
|
-
export {
|
|
111
|
+
export { f as WebUiCheckboxGroup };
|
|
98
112
|
|
|
99
113
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/checkbox-group/index.ts"],"sourcesContent":["import { html, LitElement, unsafeCSS } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport type { WebUiCheckbox } from '../checkbox'\n\nimport style from './style.css?inline'\n\n@customElement('web-ui-checkbox-group')\nexport class WebUiCheckboxGroup extends LitElement {\n static override styles = unsafeCSS(style)\n static formAssociated = true\n\n @property({ type: String, reflect: true }) name = ''\n @property({ type: Boolean, reflect: true }) disabled = false\n @property({ type: Boolean, reflect: true }) required = false\n\n @state() private _value: string[] = []\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/checkbox-group/index.ts"],"sourcesContent":["import { html, LitElement, unsafeCSS } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { defineFormAssociation, FormAssociationController } from '@/shared/form-association'\nimport { defineGroupCoordinator, GroupController } from '@/shared/group-management'\n\nimport type { WebUiCheckbox } from '../checkbox'\n\nimport style from './style.css?inline'\n\n@customElement('web-ui-checkbox-group')\nexport class WebUiCheckboxGroup extends LitElement {\n static override styles = unsafeCSS(style)\n static formAssociated = true\n\n @property({ type: String, reflect: true }) name = ''\n @property({ type: Boolean, reflect: true }) disabled = false\n @property({ type: Boolean, reflect: true }) required = false\n\n @state() private _value: string[] = []\n\n private readonly _groupController = new GroupController(\n this,\n defineGroupCoordinator<WebUiCheckbox, string[]>({\n host: this,\n getItems: () => [...this.querySelectorAll<WebUiCheckbox>('web-ui-checkbox')],\n getValue: () => this._value,\n setValue: value => {\n this.value = value\n },\n getDisabled: () => this._isDisabled,\n isItem: (target): target is WebUiCheckbox => target instanceof HTMLElement && target.matches('web-ui-checkbox'),\n isItemSelected: (checkbox, value) => value.includes(checkbox.value),\n getNextValue: (checkbox, value) =>\n checkbox.checked ? [...new Set([...value, checkbox.value])] : value.filter(item => item !== checkbox.value),\n valuesEqual: (a, b) => a.length === b.length && a.every((value, index) => value === b[index]),\n copyValue: value => [...value],\n setItemSelected: (checkbox, selected) => {\n checkbox.checked = selected\n },\n dispatchValueChange: () => {\n this.dispatchEvent(new Event('input', { bubbles: true, composed: true }))\n this.dispatchEvent(new Event('change', { bubbles: true, composed: true }))\n }\n }).make()\n )\n\n get value(): string[] {\n return this._value\n }\n\n set value(v: string[]) {\n const old = this._value\n this._value = [...v]\n this._formAssociation.sync()\n this.requestUpdate('value', old)\n }\n\n private get _isDisabled(): boolean {\n return this.disabled || this._formAssociation.isFormDisabled()\n }\n\n private readonly _formAssociation = defineFormAssociation<string[]>({\n host: this,\n initialize: () => {\n const attributeValue = this.getAttribute('value')\n if (attributeValue !== null) this.value = attributeValue.split(',').filter(Boolean)\n },\n getState: () => this._value,\n setState: value => {\n this.value = value\n },\n copyState: value => [...value],\n getFormValue: () => {\n if (!this.name || this._value.length === 0) return null\n const formData = new FormData()\n this._value.forEach(value => formData.append(this.name, value))\n return formData\n },\n getFormState: () => JSON.stringify(this._value),\n restoreState: state => {\n if (typeof state !== 'string') return\n try {\n const value = JSON.parse(state)\n if (Array.isArray(value) && value.every(item => typeof item === 'string')) this.value = value\n } catch {\n // 忽略无法解析的历史表单状态。\n }\n },\n syncValidity: () => this._syncValidity()\n }).make()\n\n private readonly _formAssociationController = new FormAssociationController(this, this._formAssociation)\n\n formResetCallback() {\n this._formAssociation.reset()\n }\n\n formDisabledCallback(disabled: boolean) {\n this._formAssociation.setDisabled(disabled)\n this._groupController.sync()\n }\n\n formStateRestoreCallback(state: string | File | FormData | null) {\n this._formAssociation.restore(state)\n }\n\n private _syncValidity() {\n const internals = this._formAssociation.getInternals()\n if (!internals || typeof internals.setValidity !== 'function') return\n if (this._isDisabled || !this.required || this._value.length > 0) {\n internals.setValidity({})\n return\n }\n internals.setValidity({ valueMissing: true }, '请至少选择一项')\n }\n\n override render() {\n return html`<div class=\"wui-checkbox-group\"><slot></slot></div>`\n }\n\n declare readonly $events: {\n input: Event\n change: Event\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'web-ui-checkbox-group': WebUiCheckboxGroup\n }\n}\n"],"mappings":";;;;;;;AAWO,IAAM,IAAN,cAAiC,EAAW;;EAiFH,aA7EI,KAAA,OAAA,IACK,KAAA,WAAA,IACA,KAAA,WAAA,IAEnB,KAAA,SAAA,CAAC,GAED,KAAA,mBAAA,IAAI,EACtC,MACA,EAAgD;GAC9C,MAAM;GACN,gBAAgB,CAAC,GAAG,KAAK,iBAAgC,iBAAiB,CAAC;GAC3E,gBAAgB,KAAK;GACrB,WAAU,MAAS;IACjB,KAAK,QAAQ;GACf;GACA,mBAAmB,KAAK;GACxB,SAAS,MAAoC,aAAkB,eAAe,EAAO,QAAQ,iBAAiB;GAC9G,iBAAiB,GAAU,MAAU,EAAM,SAAS,EAAS,KAAK;GAClE,eAAe,GAAU,MACvB,EAAS,UAAU,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,GAAO,EAAS,KAAK,CAAC,CAAC,IAAI,EAAM,QAAO,MAAQ,MAAS,EAAS,KAAK;GAC5G,cAAc,GAAG,MAAM,EAAE,W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4 +1,4 @@
|
|
|
1
|
-
import e from "../../_virtual/_@oxc-project_runtime@0.
|
|
1
|
+
import e from "../../_virtual/_@oxc-project_runtime@0.146.0/helpers/esm/decorate.js";
|
|
2
2
|
import { hideOverlayPresence as t, showOverlayPresence as n } from "../../shared/overlay/presence.js";
|
|
3
3
|
import { defineScrollLockLease as r } from "../../shared/scroll-lock/scroll-lock.js";
|
|
4
4
|
import "../dropdown-divider/index.js";
|
|
@@ -118,7 +118,7 @@ var b = class extends m {
|
|
|
118
118
|
this._openAt(e, t, !0);
|
|
119
119
|
}
|
|
120
120
|
_openAt(e, t, n) {
|
|
121
|
-
return this.disabled
|
|
121
|
+
return !this.disabled && (this._x = e, this._y = t, this._shouldOpenInstantly = n, this._ignoreCurrentOutsideClick(), this._isOpen ? (this._closeSubmenusFrom(0, !0), this._restoreClosingSubmenus(), requestAnimationFrame(() => this._positionMenu()), !1) : (this._restoreFocusTarget ??= document.activeElement instanceof HTMLElement ? document.activeElement : void 0, this._isOpen = !0, !0));
|
|
122
122
|
}
|
|
123
123
|
close() {
|
|
124
124
|
this._isOpen &&= !1;
|
|
@@ -130,7 +130,7 @@ var b = class extends m {
|
|
|
130
130
|
let { width: t, height: n } = e.getBoundingClientRect(), r = window.innerWidth, i = window.innerHeight, a = this._x, o = this._y;
|
|
131
131
|
a + t > r && (a = r - t - 8), o + n > i && (o = i - n - 8), a < 0 && (a = 8), o < 0 && (o = 8), e.style.left = `${a}px`, e.style.top = `${o}px`;
|
|
132
132
|
let s = a < this._x ? "right" : "left", c = o < this._y ? "bottom" : "top";
|
|
133
|
-
e.style.setProperty("--wui-overlay-transform-origin", `${c} ${s}`), e.style.visibility = "";
|
|
133
|
+
e.style.setProperty("--wui-internal-overlay-transform-origin", `${c} ${s}`), e.style.visibility = "";
|
|
134
134
|
}
|
|
135
135
|
_focusFirstItem() {
|
|
136
136
|
let e = this._menu?.content.querySelectorAll("web-ui-dropdown-item:not([disabled])")?.[0];
|
|
@@ -161,10 +161,9 @@ var b = class extends m {
|
|
|
161
161
|
this._closingSubmenus.delete(e), this._activeSubmenus[r] = i, this._activeSubmenuItems[r] = e, e.setAttribute("active", ""), this._positionSubmenu(e, i), n(i.panel, { isInstant: t }), this._bindLevelHovers();
|
|
162
162
|
return;
|
|
163
163
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
s.panel.dataset.level = String(r), s.panel.setAttribute("role", "menu"), s.panel.setAttribute("aria-label", "子菜单"), s.panel.style.visibility = "hidden", s.panel.addEventListener("click", this._onMenuClick), s.content.append(...o), this._activeSubmenus[r] = s, this._activeSubmenuItems[r] = e, e.setAttribute("active", ""), this._positionSubmenu(e, s), n(s.panel, { isInstant: t }), this._bindLevelHovers();
|
|
164
|
+
if (l(e).length === 0) return;
|
|
165
|
+
let o = a("context-submenu", this);
|
|
166
|
+
o.panel.dataset.level = String(r), o.panel.setAttribute("role", "menu"), o.panel.setAttribute("aria-label", "子菜单"), o.panel.style.visibility = "hidden", o.panel.addEventListener("click", this._onMenuClick), f(e, o.content), this._activeSubmenus[r] = o, this._activeSubmenuItems[r] = e, e.setAttribute("active", ""), this._positionSubmenu(e, o), n(o.panel, { isInstant: t }), this._bindLevelHovers();
|
|
168
167
|
}
|
|
169
168
|
_closeSubmenusFrom(e, t = !1) {
|
|
170
169
|
for (let n = this._activeSubmenus.length - 1; n >= e; n--) {
|
|
@@ -191,7 +190,7 @@ var b = class extends m {
|
|
|
191
190
|
}
|
|
192
191
|
_positionSubmenu(e, t) {
|
|
193
192
|
let n = e.getBoundingClientRect(), r = t.panel.getBoundingClientRect(), i = n.right + r.width + 8 <= window.innerWidth, a = i ? n.right : Math.max(8, n.left - r.width), o = Math.min(Math.max(8, n.top), window.innerHeight - r.height - 8);
|
|
194
|
-
t.panel.style.left = `${a}px`, t.panel.style.top = `${o}px`, t.panel.style.setProperty("--wui-overlay-transform-origin", i ? "top left" : "top right"), t.panel.style.visibility = "";
|
|
193
|
+
t.panel.style.left = `${a}px`, t.panel.style.top = `${o}px`, t.panel.style.setProperty("--wui-internal-overlay-transform-origin", i ? "top left" : "top right"), t.panel.style.visibility = "";
|
|
195
194
|
}
|
|
196
195
|
_dispatchChange(e) {
|
|
197
196
|
this.dispatchEvent(new CustomEvent("open-change", {
|