@cpsoft13/z-agent-ui 0.2.1 → 0.3.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.
Files changed (165) hide show
  1. package/bin/lines-baseline.json +1 -15
  2. package/bin/text-baseline.json +1 -2
  3. package/dist/build-info.json +2 -2
  4. package/dist/components/context-menu/ContextMenu.js +7 -7
  5. package/dist/components/context-menu/ContextMenu.js.map +1 -1
  6. package/dist/components/date-range/DateRange.js +4 -4
  7. package/dist/components/date-range/DateRange.js.map +1 -1
  8. package/dist/components/datepicker/Datepicker.js +207 -332
  9. package/dist/components/datepicker/Datepicker.js.map +1 -1
  10. package/dist/components/datepicker/datepicker-keyboard.js +66 -0
  11. package/dist/components/datepicker/datepicker-keyboard.js.map +1 -0
  12. package/dist/components/datepicker/datepicker-panel-render.js +78 -0
  13. package/dist/components/datepicker/datepicker-panel-render.js.map +1 -0
  14. package/dist/components/form/Form.js +69 -47
  15. package/dist/components/form/Form.js.map +1 -1
  16. package/dist/components/form/form-context.js +9 -0
  17. package/dist/components/form/form-context.js.map +1 -0
  18. package/dist/components/form.js +2 -0
  19. package/dist/components/form.js.map +1 -1
  20. package/dist/components/menu/Menu.js +27 -27
  21. package/dist/components/menu/Menu.js.map +1 -1
  22. package/dist/components/popover/Popover.js +1 -1
  23. package/dist/components/popover/Popover.js.map +1 -1
  24. package/dist/components/select/Select.js +235 -351
  25. package/dist/components/select/Select.js.map +1 -1
  26. package/dist/components/select/option-search.js +49 -0
  27. package/dist/components/select/option-search.js.map +1 -0
  28. package/dist/components/select/select-render.js +75 -0
  29. package/dist/components/select/select-render.js.map +1 -0
  30. package/dist/components/select/selection-strategy.js +151 -0
  31. package/dist/components/select/selection-strategy.js.map +1 -0
  32. package/dist/components/time-picker/TimePicker.js +1 -1
  33. package/dist/components/time-picker/TimePicker.js.map +1 -1
  34. package/dist/components/tooltip/Tooltip.js +16 -16
  35. package/dist/components/tooltip/Tooltip.js.map +1 -1
  36. package/dist/core/BaseElement.js +96 -77
  37. package/dist/core/BaseElement.js.map +1 -1
  38. package/dist/core/context.js +68 -0
  39. package/dist/core/context.js.map +1 -0
  40. package/dist/core/controller.js +2 -0
  41. package/dist/core/controller.js.map +1 -0
  42. package/dist/core/public.js +35 -30
  43. package/dist/core/public.js.map +1 -1
  44. package/dist/core.js +95 -90
  45. package/dist/core.js.map +1 -1
  46. package/dist/doc/doc-template-editor-core.js +12 -11
  47. package/dist/doc/doc-template-editor-core.js.map +1 -1
  48. package/dist/doc/doc-template-editor-panel.css.js +202 -0
  49. package/dist/doc/doc-template-editor-panel.css.js.map +1 -0
  50. package/dist/doc/doc-template-editor.css.js +1 -200
  51. package/dist/doc/doc-template-editor.css.js.map +1 -1
  52. package/dist/flow/Flow.js +104 -195
  53. package/dist/flow/Flow.js.map +1 -1
  54. package/dist/flow/flow-keyboard-controller.js +101 -0
  55. package/dist/flow/flow-keyboard-controller.js.map +1 -0
  56. package/dist/primitives/overlay/floatingPanel.js +6 -2
  57. package/dist/primitives/overlay/floatingPanel.js.map +1 -1
  58. package/dist/report/chart/Chart.js +271 -761
  59. package/dist/report/chart/Chart.js.map +1 -1
  60. package/dist/report/chart/chart-brush-controller.js +187 -0
  61. package/dist/report/chart/chart-brush-controller.js.map +1 -0
  62. package/dist/report/chart/chart-layout-pipeline.js +158 -0
  63. package/dist/report/chart/chart-layout-pipeline.js.map +1 -0
  64. package/dist/report/chart/chart-zoom.js +79 -0
  65. package/dist/report/chart/chart-zoom.js.map +1 -0
  66. package/dist/report/chart/geometry/build.js +41 -26
  67. package/dist/report/chart/geometry/build.js.map +1 -1
  68. package/dist/report/chart/geometry/extra-flow-dist.js +283 -0
  69. package/dist/report/chart/geometry/extra-flow-dist.js.map +1 -0
  70. package/dist/report/chart/geometry/extra-radial-grid.js +280 -0
  71. package/dist/report/chart/geometry/extra-radial-grid.js.map +1 -0
  72. package/dist/report/chart/geometry/extra-shared.js +36 -0
  73. package/dist/report/chart/geometry/extra-shared.js.map +1 -0
  74. package/dist/report/chart/geometry/extra.js +20 -583
  75. package/dist/report/chart/geometry/extra.js.map +1 -1
  76. package/dist/report/chart/geometry/registry.js +20 -0
  77. package/dist/report/chart/geometry/registry.js.map +1 -0
  78. package/dist/report/chart.js +12 -6
  79. package/dist/report/chart.js.map +1 -1
  80. package/dist/report/gantt/Gantt.js +199 -308
  81. package/dist/report/gantt/Gantt.js.map +1 -1
  82. package/dist/report/gantt/gantt-bars.css.js +247 -0
  83. package/dist/report/gantt/gantt-bars.css.js.map +1 -0
  84. package/dist/report/gantt/gantt-edit-controller.js +94 -0
  85. package/dist/report/gantt/gantt-edit-controller.js.map +1 -0
  86. package/dist/report/gantt/gantt.css.js +0 -272
  87. package/dist/report/gantt/gantt.css.js.map +1 -1
  88. package/dist/report/table/ReportTable.js +336 -493
  89. package/dist/report/table/ReportTable.js.map +1 -1
  90. package/dist/report/table/report-table-config.css.js +172 -0
  91. package/dist/report/table/report-table-config.css.js.map +1 -0
  92. package/dist/report/table/report-table-types.js.map +1 -1
  93. package/dist/report/table/report-table.css.js +0 -176
  94. package/dist/report/table/report-table.css.js.map +1 -1
  95. package/dist/report/table/table-cell-registry.js +29 -0
  96. package/dist/report/table/table-cell-registry.js.map +1 -0
  97. package/dist/report/table/table-keyboard-controller.js +96 -0
  98. package/dist/report/table/table-keyboard-controller.js.map +1 -0
  99. package/dist/report/table/table-pipeline.js +36 -0
  100. package/dist/report/table/table-pipeline.js.map +1 -0
  101. package/dist/report/table/table-render.js +97 -96
  102. package/dist/report/table/table-render.js.map +1 -1
  103. package/dist/report/table/table-scroll-controller.js +33 -0
  104. package/dist/report/table/table-scroll-controller.js.map +1 -0
  105. package/dist/report/table.js +7 -2
  106. package/dist/report/table.js.map +1 -1
  107. package/dist/report.js +39 -28
  108. package/dist/report.js.map +1 -1
  109. package/dist/types/components/datepicker/Datepicker.d.ts +1 -109
  110. package/dist/types/components/datepicker/datepicker-keyboard.d.ts +21 -0
  111. package/dist/types/components/datepicker/datepicker-panel-render.d.ts +25 -0
  112. package/dist/types/components/form/Form.d.ts +7 -2
  113. package/dist/types/components/form/form-context.d.ts +11 -0
  114. package/dist/types/components/form/index.d.ts +1 -1
  115. package/dist/types/components/select/Select.d.ts +7 -110
  116. package/dist/types/components/select/option-search.d.ts +38 -0
  117. package/dist/types/components/select/select-render.d.ts +39 -0
  118. package/dist/types/components/select/selection-strategy.d.ts +86 -0
  119. package/dist/types/core/BaseElement.d.ts +7 -1
  120. package/dist/types/core/context.d.ts +66 -0
  121. package/dist/types/core/controller.d.ts +22 -0
  122. package/dist/types/core/public.d.ts +2 -0
  123. package/dist/types/flow/Flow.d.ts +3 -76
  124. package/dist/types/flow/flow-keyboard-controller.d.ts +35 -0
  125. package/dist/types/primitives/overlay/floatingPanel.d.ts +2 -0
  126. package/dist/types/report/chart/Chart.d.ts +2 -245
  127. package/dist/types/report/chart/chart-brush-controller.d.ts +59 -0
  128. package/dist/types/report/chart/chart-layout-pipeline.d.ts +42 -0
  129. package/dist/types/report/chart/chart-zoom.d.ts +12 -0
  130. package/dist/types/report/chart/geometry/build.d.ts +2 -0
  131. package/dist/types/report/chart/geometry/extra-flow-dist.d.ts +6 -0
  132. package/dist/types/report/chart/geometry/extra-radial-grid.d.ts +6 -0
  133. package/dist/types/report/chart/geometry/extra-shared.d.ts +24 -0
  134. package/dist/types/report/chart/geometry/extra.d.ts +2 -34
  135. package/dist/types/report/chart/geometry/registry.d.ts +26 -0
  136. package/dist/types/report/chart/index.d.ts +1 -0
  137. package/dist/types/report/gantt/Gantt.d.ts +7 -97
  138. package/dist/types/report/gantt/gantt-edit-controller.d.ts +34 -0
  139. package/dist/types/report/table/ReportTable.d.ts +9 -180
  140. package/dist/types/report/table/index.d.ts +1 -0
  141. package/dist/types/report/table/report-table-types.d.ts +2 -0
  142. package/dist/types/report/table/table-cell-registry.d.ts +17 -0
  143. package/dist/types/report/table/table-keyboard-controller.d.ts +30 -0
  144. package/dist/types/report/table/table-pipeline.d.ts +33 -0
  145. package/dist/types/report/table/table-scroll-controller.d.ts +25 -0
  146. package/dist/z-agent-ui.js +35 -30
  147. package/dist/z-agent-ui.js.map +1 -1
  148. package/package.json +1 -1
  149. package/registry/component-manifest.json +39 -7
  150. package/src/components/context-menu/ContextMenu.ts +1 -1
  151. package/src/components/date-range/DateRange.ts +1 -1
  152. package/src/components/datepicker/Datepicker.ts +99 -417
  153. package/src/components/datepicker/datepicker-keyboard.ts +94 -0
  154. package/src/components/datepicker/datepicker-panel-render.ts +169 -0
  155. package/src/components/form/Form.ts +39 -11
  156. package/src/components/form/form-context.ts +11 -0
  157. package/src/components/form/index.ts +1 -1
  158. package/src/components/menu/Menu.ts +1 -1
  159. package/src/components/popover/Popover.ts +1 -1
  160. package/src/components/select/Select.ts +140 -525
  161. package/src/components/select/option-search.ts +114 -0
  162. package/src/components/select/select-render.ts +161 -0
  163. package/src/components/select/selection-strategy.ts +245 -0
  164. package/src/components/time-picker/TimePicker.ts +1 -1
  165. package/src/components/tooltip/Tooltip.ts +1 -1
@@ -0,0 +1,114 @@
1
+ import type { ReactiveController } from "../../core/index.js";
2
+ import type { ZOption } from "../option/Option.js";
3
+
4
+ export interface ZSelectOptionSpec {
5
+ value: string;
6
+ label: string;
7
+ disabled?: boolean;
8
+ }
9
+
10
+ export type ZSelectSearchMode = "frontend" | "backend";
11
+
12
+ export type RemoteSearchMethod = (
13
+ query: string,
14
+ ) => void | ZSelectOptionSpec[] | Promise<ZSelectOptionSpec[]>;
15
+
16
+ export interface SearchInputContext {
17
+ searchMode: ZSelectSearchMode;
18
+ remoteMethod: RemoteSearchMethod | null;
19
+ isOpen: () => boolean;
20
+ setLoading: (loading: boolean) => void;
21
+ applySpecs: (specs: ZSelectOptionSpec[]) => void;
22
+ onLocalFilter: () => void;
23
+ onSearchEmit: (query: string) => void;
24
+ }
25
+
26
+ const REMOTE_SEARCH_DELAY = 300;
27
+
28
+ /**
29
+ * `<z-select>` 搜索与选项变更观察控制器(ReactiveController)。
30
+ *
31
+ * 托管查询词、远程防抖定时器与子节点 MutationObserver,宿主断开时自动清理,
32
+ * 避免定时器泄漏或悬空观察者。
33
+ */
34
+ export class OptionSearchController implements ReactiveController {
35
+ private _query = "";
36
+ private _timer: number | null = null;
37
+ private _observer: MutationObserver | null = null;
38
+
39
+ get query(): string {
40
+ return this._query;
41
+ }
42
+
43
+ hostDisconnected(): void {
44
+ this.clearTimer();
45
+ this.stopObserving();
46
+ }
47
+
48
+ reset(): void {
49
+ this._query = "";
50
+ this.clearTimer();
51
+ }
52
+
53
+ clearTimer(): void {
54
+ if (this._timer !== null) {
55
+ window.clearTimeout(this._timer);
56
+ this._timer = null;
57
+ }
58
+ }
59
+
60
+ filter(options: ZOption[], searchable: boolean): ZOption[] {
61
+ if (!searchable || !this._query) return options;
62
+ const q = this._query.toLowerCase();
63
+ return options.filter(
64
+ (o) => o.label.toLowerCase().includes(q) || o.value.toLowerCase().includes(q),
65
+ );
66
+ }
67
+
68
+ handleInput(value: string, ctx: SearchInputContext): void {
69
+ this._query = value;
70
+ if (ctx.searchMode === "backend") {
71
+ this.clearTimer();
72
+ this._timer = window.setTimeout(() => {
73
+ this._timer = null;
74
+ this._runRemoteSearch(ctx);
75
+ }, REMOTE_SEARCH_DELAY);
76
+ } else {
77
+ ctx.onLocalFilter();
78
+ }
79
+ }
80
+
81
+ observeHost(host: HTMLElement, onChange: () => void): void {
82
+ if (this._observer) return;
83
+ this._observer = new MutationObserver(() => onChange());
84
+ this._observer.observe(host, { childList: true });
85
+ }
86
+
87
+ stopObserving(): void {
88
+ this._observer?.disconnect();
89
+ this._observer = null;
90
+ }
91
+
92
+ private _runRemoteSearch(ctx: SearchInputContext): void {
93
+ const query = this._query;
94
+ const result = ctx.remoteMethod ? ctx.remoteMethod(query) : undefined;
95
+
96
+ if (result && typeof (result as Promise<unknown>).then === "function") {
97
+ ctx.setLoading(true);
98
+ (result as Promise<ZSelectOptionSpec[]>)
99
+ .then((specs) => {
100
+ // 防竞态:下拉已关闭或查询词已变时丢弃过期结果
101
+ if (!ctx.isOpen() || this._query !== query || !Array.isArray(specs)) return;
102
+ ctx.applySpecs(specs);
103
+ })
104
+ .catch(() => {
105
+ // 远程搜索失败时保留现有选项
106
+ })
107
+ .finally(() => {
108
+ if (ctx.isOpen() && this._query === query) ctx.setLoading(false);
109
+ });
110
+ }
111
+
112
+ ctx.onSearchEmit(query);
113
+ }
114
+ }
@@ -0,0 +1,161 @@
1
+ import { COPY, escapeAttr, escapeHtml, html, t } from "../../core/index.js";
2
+ import type { ZOption } from "../option/Option.js";
3
+
4
+ export interface SelectTriggerRenderState {
5
+ open: boolean;
6
+ disabled: boolean;
7
+ invalid: boolean;
8
+ multiple: boolean;
9
+ clearable: boolean;
10
+ maxTags: number;
11
+ placeholder: string;
12
+ authoredPlaceholder: string;
13
+ emptyLabel: string;
14
+ selectedOption: ZOption | undefined;
15
+ selectedValues: string[];
16
+ labelOf: (value: string) => string;
17
+ }
18
+
19
+ export interface SelectShellRenderState {
20
+ uid: string;
21
+ searchable: boolean;
22
+ searchPlaceholder: string;
23
+ staging: boolean;
24
+ listName: string;
25
+ }
26
+
27
+ export interface SelectOptionsRenderState {
28
+ uid: string;
29
+ options: ZOption[];
30
+ multiple: boolean;
31
+ searchable: boolean;
32
+ query: string;
33
+ activeIndex: number;
34
+ isSelected: (optionValue: string) => boolean;
35
+ }
36
+
37
+ /** 渲染多选标签列表(超出 maxTags 折叠为 +N)。 */
38
+ export function renderSelectTags(
39
+ values: string[],
40
+ maxTags: number,
41
+ labelOf: (value: string) => string,
42
+ ): string {
43
+ const limit = maxTags > 0 ? maxTags : values.length;
44
+ const shown = values.slice(0, limit);
45
+ const rest = values.length - shown.length;
46
+ const tags = shown.map((v) => {
47
+ const text = labelOf(v);
48
+ return (
49
+ `<span class="z-select__tag" title="${escapeAttr(text)}">` +
50
+ `<span class="z-select__tag-label">${escapeHtml(text)}</span>` +
51
+ `<span class="z-select__tag-x" role="button" tabindex="-1" data-value="${escapeAttr(v)}"` +
52
+ ` aria-label="${escapeAttr(t("removeItem", { label: text }))}">` +
53
+ `<svg width="8" height="8" viewBox="0 0 8 8" fill="none" aria-hidden="true">` +
54
+ `<path d="M1.6 1.6l4.8 4.8M6.4 1.6L1.6 6.4" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/></svg>` +
55
+ `</span></span>`
56
+ );
57
+ });
58
+ if (rest > 0) {
59
+ const hidden = values.slice(limit).map(labelOf);
60
+ tags.push(
61
+ `<span class="z-select__tag z-select__tag--more" title="${escapeAttr(hidden.join("、"))}">+${rest}</span>`,
62
+ );
63
+ }
64
+ return tags.join("");
65
+ }
66
+
67
+ /** 渲染 `<z-select>` 触发按钮模板。 */
68
+ export function renderSelectTrigger(s: SelectTriggerRenderState): string {
69
+ const filled = s.multiple ? s.selectedValues.length > 0 : !!s.selectedOption;
70
+ const clear =
71
+ s.clearable && filled && !s.disabled && !s.multiple
72
+ ? `<span class="z-select__clear" part="clear" role="button" tabindex="-1" aria-label="${COPY.clear}">` +
73
+ `<svg width="10" height="10" viewBox="0 0 10 10" fill="none" aria-hidden="true">` +
74
+ `<path d="M2 2l6 6M8 2l-6 6" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/></svg></span>`
75
+ : "";
76
+
77
+ const body = s.multiple
78
+ ? s.selectedValues.length
79
+ ? `<span class="z-select__tags" part="value">${renderSelectTags(s.selectedValues, s.maxTags, s.labelOf)}</span>`
80
+ : `<span class="z-select__value z-select__placeholder" part="value">${escapeHtml(
81
+ s.authoredPlaceholder || s.emptyLabel || s.placeholder,
82
+ )}</span>`
83
+ : `<span class="z-select__value${s.selectedOption ? "" : " z-select__placeholder"}" part="value">${escapeHtml(
84
+ String(s.selectedOption ? s.selectedOption.label : s.placeholder),
85
+ )}</span>`;
86
+
87
+ const titleAttr =
88
+ !s.multiple && s.selectedOption ? ` title="${escapeAttr(String(s.selectedOption.label))}"` : "";
89
+
90
+ return html`
91
+ <button
92
+ type="button"
93
+ class="z-select__trigger ${s.open ? "z-select__trigger--open" : ""}${s.multiple ? " z-select__trigger--multi" : ""}"
94
+ ${s.disabled ? "disabled" : ""}
95
+ aria-expanded="${s.open ? "true" : "false"}"
96
+ aria-haspopup="listbox"
97
+ ${s.invalid ? 'aria-invalid="true"' : ""}
98
+ ${titleAttr}
99
+ part="trigger"
100
+ data-focus-key="trigger"
101
+ >
102
+ ${body}${clear}
103
+ <span class="z-select__chevron ${s.open ? "z-select__chevron--open" : ""}" part="chevron" aria-hidden="true">
104
+ <svg width="12" height="12" viewBox="0 0 12 12" fill="none">
105
+ <path d="M3 4.5L6 7.5L9 4.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
106
+ </svg>
107
+ </span>
108
+ </button>
109
+ `;
110
+ }
111
+
112
+ /** 构建浮层面板外壳(搜索栏 + listbox 容器 + 可选底部确认条)。 */
113
+ export function buildSelectDropdownShell(s: SelectShellRenderState): string {
114
+ const searchHTML = s.searchable
115
+ ? html`<input type="text" class="z-select__search" part="search" role="combobox" aria-autocomplete="list" aria-expanded="true" aria-controls="${s.uid}-listbox" placeholder="${escapeAttr(s.searchPlaceholder)}" aria-label="${escapeAttr(s.searchPlaceholder)}" autocomplete="off" />`
116
+ : "";
117
+ const footerHTML = s.staging
118
+ ? `<div class="z-select__footer" part="footer">` +
119
+ `<span class="z-select__count" part="count"></span>` +
120
+ `<span class="z-select__footer-actions">` +
121
+ `<button type="button" class="z-select__btn" data-act="reset">${escapeHtml(t("clearAll"))}</button>` +
122
+ `<button type="button" class="z-select__btn z-select__btn--primary" data-act="confirm">${escapeHtml(t("confirm"))}</button>` +
123
+ `</span></div>`
124
+ : "";
125
+ const listLabel = s.listName ? ` aria-label="${escapeAttr(s.listName)}"` : "";
126
+ return `${searchHTML}<div class="z-select__options" role="listbox" id="${s.uid}-listbox" tabindex="-1"${listLabel}></div>${footerHTML}`;
127
+ }
128
+
129
+ /** 构建选项列表 HTML。 */
130
+ export function buildSelectOptionsHTML(s: SelectOptionsRenderState): string {
131
+ if (s.options.length === 0) {
132
+ const msg = s.searchable && s.query ? "No results" : "No options";
133
+ return html`<div class="z-select__empty" part="empty">${msg}</div>`;
134
+ }
135
+ return s.options
136
+ .map((opt, i) => {
137
+ const on = s.isSelected(opt.value);
138
+ const cls = [
139
+ "z-select__option",
140
+ on ? "z-select__option--selected" : "",
141
+ s.multiple && on ? "z-select__option--multi" : "",
142
+ opt.disabled ? "z-select__option--disabled" : "",
143
+ i === s.activeIndex ? "z-select__option--active" : "",
144
+ ]
145
+ .filter(Boolean)
146
+ .join(" ");
147
+
148
+ const box = s.multiple
149
+ ? html`<span class="z-select__box ${on ? "z-select__box--on" : ""}" part="box">${on
150
+ ? `<svg width="12" height="12" viewBox="0 0 12 12"><path d="M2.5 6L5 8.5L9.5 3.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg>`
151
+ : ""}</span>`
152
+ : "";
153
+
154
+ return html`<div class="${cls}" id="${s.uid}-opt-${i}" data-value="${escapeAttr(String(opt.value))}" role="option" tabindex="-1" aria-selected="${on ? "true" : "false"}" aria-disabled="${opt.disabled ? "true" : "false"}">
155
+ ${box}
156
+ ${escapeHtml(String(opt.label ?? ""))}
157
+ ${!s.multiple && on ? html`<span class="z-select__check" part="check"><svg width="12" height="12" viewBox="0 0 12 12"><path d="M2.5 6L5 8.5L9.5 3.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg></span>` : ""}
158
+ </div>`;
159
+ })
160
+ .join("");
161
+ }
@@ -0,0 +1,245 @@
1
+ /**
2
+ * `<z-select>` 选择策略(无头状态机,零 DOM 依赖)。
3
+ *
4
+ * 将「单选 / 多选 / 多选暂存确认(commit-on-confirm)」三种模式从组件类中剥离为
5
+ * 可替换的策略对象,消除宿主内 `multiple && commitOnConfirm` 的组合分支爆炸。
6
+ */
7
+
8
+ export type SelectionMode = "single" | "multi" | "draft-multi";
9
+
10
+ export interface SelectChangeDetail {
11
+ value: string;
12
+ values?: string[];
13
+ }
14
+
15
+ export interface SelectPickResult {
16
+ nextValue?: string;
17
+ closeDropdown: boolean;
18
+ rerenderList: boolean;
19
+ changeDetail?: SelectChangeDetail;
20
+ }
21
+
22
+ export interface SelectMutationResult {
23
+ nextValue: string;
24
+ changeDetail: SelectChangeDetail;
25
+ }
26
+
27
+ export interface SelectionStrategy {
28
+ readonly mode: SelectionMode;
29
+ readonly isStaging: boolean;
30
+ getCommittedValues(rawValue: string): string[];
31
+ getActiveValues(rawValue: string): string[];
32
+ isSelected(optionValue: string, rawValue: string): boolean;
33
+ onOpen(rawValue: string): void;
34
+ onClose(): void;
35
+ pick(optionValue: string, rawValue: string): SelectPickResult;
36
+ removeValue(value: string, rawValue: string): SelectMutationResult | null;
37
+ clear(rawValue: string): SelectMutationResult | null;
38
+ commit(rawValue: string): SelectMutationResult | null;
39
+ resetDraft(): boolean;
40
+ draftCount(): number;
41
+ }
42
+
43
+ /** 解析逗号分隔的多选值(空串返回 [])。 */
44
+ export function parseMultiValues(rawValue: string): string[] {
45
+ if (!rawValue) return [];
46
+ return rawValue
47
+ .split(",")
48
+ .map((s) => s.trim())
49
+ .filter(Boolean);
50
+ }
51
+
52
+ function toggleInList(list: string[], value: string): string[] {
53
+ if (value === "") return [];
54
+ const next = list.slice();
55
+ const idx = next.indexOf(value);
56
+ if (idx >= 0) next.splice(idx, 1);
57
+ else next.push(value);
58
+ return next;
59
+ }
60
+
61
+ export class SingleSelectionStrategy implements SelectionStrategy {
62
+ readonly mode: SelectionMode = "single";
63
+ readonly isStaging = false;
64
+
65
+ getCommittedValues(): string[] {
66
+ return [];
67
+ }
68
+
69
+ getActiveValues(): string[] {
70
+ return [];
71
+ }
72
+
73
+ isSelected(optionValue: string, rawValue: string): boolean {
74
+ return optionValue === rawValue;
75
+ }
76
+
77
+ onOpen(): void {}
78
+ onClose(): void {}
79
+
80
+ pick(optionValue: string, rawValue: string): SelectPickResult {
81
+ if (rawValue === optionValue) {
82
+ return { closeDropdown: true, rerenderList: false };
83
+ }
84
+ return {
85
+ nextValue: optionValue,
86
+ closeDropdown: true,
87
+ rerenderList: false,
88
+ changeDetail: { value: optionValue },
89
+ };
90
+ }
91
+
92
+ removeValue(): SelectMutationResult | null {
93
+ return null;
94
+ }
95
+
96
+ clear(rawValue: string): SelectMutationResult | null {
97
+ if (!rawValue) return null;
98
+ return { nextValue: "", changeDetail: { value: "" } };
99
+ }
100
+
101
+ commit(): SelectMutationResult | null {
102
+ return null;
103
+ }
104
+
105
+ resetDraft(): boolean {
106
+ return false;
107
+ }
108
+
109
+ draftCount(): number {
110
+ return 0;
111
+ }
112
+ }
113
+
114
+ export class MultiSelectionStrategy implements SelectionStrategy {
115
+ readonly mode: SelectionMode = "multi";
116
+ readonly isStaging = false;
117
+
118
+ getCommittedValues(rawValue: string): string[] {
119
+ return parseMultiValues(rawValue);
120
+ }
121
+
122
+ getActiveValues(rawValue: string): string[] {
123
+ return parseMultiValues(rawValue);
124
+ }
125
+
126
+ isSelected(optionValue: string, rawValue: string): boolean {
127
+ return parseMultiValues(rawValue).includes(optionValue);
128
+ }
129
+
130
+ onOpen(): void {}
131
+ onClose(): void {}
132
+
133
+ pick(optionValue: string, rawValue: string): SelectPickResult {
134
+ const next = toggleInList(parseMultiValues(rawValue), optionValue);
135
+ const joined = next.join(",");
136
+ return {
137
+ nextValue: joined,
138
+ closeDropdown: false,
139
+ rerenderList: true,
140
+ changeDetail: { values: next.slice(), value: joined },
141
+ };
142
+ }
143
+
144
+ removeValue(value: string, rawValue: string): SelectMutationResult | null {
145
+ const prev = parseMultiValues(rawValue);
146
+ const next = prev.filter((v) => v !== value);
147
+ if (next.length === prev.length) return null;
148
+ const joined = next.join(",");
149
+ return { nextValue: joined, changeDetail: { values: next.slice(), value: joined } };
150
+ }
151
+
152
+ clear(rawValue: string): SelectMutationResult | null {
153
+ if (!rawValue) return null;
154
+ return { nextValue: "", changeDetail: { values: [], value: "" } };
155
+ }
156
+
157
+ commit(): SelectMutationResult | null {
158
+ return null;
159
+ }
160
+
161
+ resetDraft(): boolean {
162
+ return false;
163
+ }
164
+
165
+ draftCount(): number {
166
+ return 0;
167
+ }
168
+ }
169
+
170
+ export class DraftMultiSelectionStrategy implements SelectionStrategy {
171
+ readonly mode: SelectionMode = "draft-multi";
172
+ readonly isStaging = true;
173
+ private _draft: string[] | null = null;
174
+
175
+ getCommittedValues(rawValue: string): string[] {
176
+ return parseMultiValues(rawValue);
177
+ }
178
+
179
+ getActiveValues(rawValue: string): string[] {
180
+ return this._draft ?? parseMultiValues(rawValue);
181
+ }
182
+
183
+ isSelected(optionValue: string, rawValue: string): boolean {
184
+ return this.getActiveValues(rawValue).includes(optionValue);
185
+ }
186
+
187
+ onOpen(rawValue: string): void {
188
+ this._draft = parseMultiValues(rawValue);
189
+ }
190
+
191
+ onClose(): void {
192
+ this._draft = null;
193
+ }
194
+
195
+ pick(optionValue: string, rawValue: string): SelectPickResult {
196
+ const base = this._draft ?? parseMultiValues(rawValue);
197
+ this._draft = toggleInList(base, optionValue);
198
+ return { closeDropdown: false, rerenderList: true };
199
+ }
200
+
201
+ removeValue(value: string, rawValue: string): SelectMutationResult | null {
202
+ const prev = parseMultiValues(rawValue);
203
+ const next = prev.filter((v) => v !== value);
204
+ if (next.length === prev.length) return null;
205
+ this._draft = next.slice();
206
+ const joined = next.join(",");
207
+ return { nextValue: joined, changeDetail: { values: next.slice(), value: joined } };
208
+ }
209
+
210
+ clear(rawValue: string): SelectMutationResult | null {
211
+ if (!rawValue) return null;
212
+ this._draft = [];
213
+ return { nextValue: "", changeDetail: { values: [], value: "" } };
214
+ }
215
+
216
+ commit(rawValue: string): SelectMutationResult | null {
217
+ const next = (this._draft ?? []).slice();
218
+ const joined = next.join(",");
219
+ if (joined === rawValue) return null;
220
+ return { nextValue: joined, changeDetail: { values: next.slice(), value: joined } };
221
+ }
222
+
223
+ resetDraft(): boolean {
224
+ if (!this._draft?.length) return false;
225
+ this._draft = [];
226
+ return true;
227
+ }
228
+
229
+ draftCount(): number {
230
+ return (this._draft ?? []).length;
231
+ }
232
+ }
233
+
234
+ /** 按开关解析对应策略;若当前策略模式未变则直接复用以保留草稿态。 */
235
+ export function resolveSelectionStrategy(
236
+ multiple: boolean,
237
+ commitOnConfirm: boolean,
238
+ current?: SelectionStrategy,
239
+ ): SelectionStrategy {
240
+ const mode: SelectionMode = multiple ? (commitOnConfirm ? "draft-multi" : "multi") : "single";
241
+ if (current && current.mode === mode) return current;
242
+ if (mode === "draft-multi") return new DraftMultiSelectionStrategy();
243
+ if (mode === "multi") return new MultiSelectionStrategy();
244
+ return new SingleSelectionStrategy();
245
+ }
@@ -102,7 +102,7 @@ export class ZTimePicker extends BaseElement {
102
102
  @property({ type: String }) pmLabel = "PM";
103
103
 
104
104
  // [WHY] 浮层面板生命周期(创建/定位/外部关闭/隐藏动画)委托给公共控制器
105
- private _floating = new FloatingPanelController(this);
105
+ private _floating = this.addController(new FloatingPanelController(this));
106
106
  private _h = 0;
107
107
  private _m = 0;
108
108
  private _s = 0;
@@ -50,7 +50,7 @@ export class ZTooltip extends BaseElement {
50
50
  @property({ type: Number }) offset = 6;
51
51
  @property({ type: Number }) delay = 400;
52
52
 
53
- private _floating = new FloatingPanelController(this);
53
+ private _floating = this.addController(new FloatingPanelController(this));
54
54
  private _showTimer: ReturnType<typeof setTimeout> | null = null;
55
55
 
56
56
  render(): string {