@haiyue/ui 0.3.0 → 0.4.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 (73) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +84 -2
  3. package/dist/adapters/web/controls.js +48 -8
  4. package/dist/adapters/web/renderer.js +8 -3
  5. package/dist/anchor.d.ts +2 -0
  6. package/dist/anchor.js +23 -4
  7. package/dist/border-beam.js +2 -1
  8. package/dist/cascader.js +7 -1
  9. package/dist/context-menu.js +0 -1
  10. package/dist/core/actions.js +7 -8
  11. package/dist/core/data.d.ts +1 -1
  12. package/dist/core/data.js +44 -10
  13. package/dist/core/platform-view.js +8 -2
  14. package/dist/core/selection.js +4 -4
  15. package/dist/core/semantics.d.ts +26 -0
  16. package/dist/core/semantics.js +8 -0
  17. package/dist/core/text.js +3 -3
  18. package/dist/core/validation.d.ts +3 -1
  19. package/dist/core/validation.js +23 -5
  20. package/dist/date-picker.js +6 -0
  21. package/dist/dialog.d.ts +4 -0
  22. package/dist/dialog.js +37 -16
  23. package/dist/drag-source.d.ts +27 -0
  24. package/dist/drag-source.js +114 -0
  25. package/dist/draggable.d.ts +1 -2
  26. package/dist/draggable.js +25 -31
  27. package/dist/drawer.js +4 -12
  28. package/dist/dropdown.js +0 -1
  29. package/dist/dropzone.d.ts +29 -0
  30. package/dist/dropzone.js +89 -0
  31. package/dist/index.d.ts +6 -0
  32. package/dist/index.js +9 -0
  33. package/dist/input.js +3 -3
  34. package/dist/internal/drag-drop.d.ts +29 -0
  35. package/dist/internal/drag-drop.js +171 -0
  36. package/dist/internal/focus.d.ts +2 -0
  37. package/dist/internal/focus.js +31 -0
  38. package/dist/internal/keyboard.d.ts +2 -0
  39. package/dist/internal/keyboard.js +12 -0
  40. package/dist/internal/native-drop.d.ts +17 -0
  41. package/dist/internal/native-drop.js +62 -0
  42. package/dist/internal/numbers.d.ts +2 -0
  43. package/dist/internal/numbers.js +8 -0
  44. package/dist/internal/pointer-drag.d.ts +15 -0
  45. package/dist/internal/pointer-drag.js +100 -0
  46. package/dist/modal.js +1 -30
  47. package/dist/notification.js +2 -1
  48. package/dist/portable/page.js +25 -14
  49. package/dist/radio.js +1 -1
  50. package/dist/resizable.d.ts +1 -1
  51. package/dist/resizable.js +26 -27
  52. package/dist/sortable.d.ts +62 -0
  53. package/dist/sortable.js +363 -0
  54. package/dist/table.d.ts +3 -1
  55. package/dist/table.js +65 -42
  56. package/dist/time-picker.js +6 -0
  57. package/dist/toast.js +3 -2
  58. package/dist/tooltip.d.ts +6 -0
  59. package/dist/tooltip.js +103 -2
  60. package/dist/tour.js +15 -6
  61. package/dist/tree-model.d.ts +2 -0
  62. package/dist/tree-model.js +32 -11
  63. package/dist/tree.d.ts +0 -2
  64. package/dist/tree.js +8 -24
  65. package/dist/upload.d.ts +2 -5
  66. package/dist/upload.js +19 -25
  67. package/dist/virtual-keyboard.d.ts +1 -0
  68. package/dist/virtual-keyboard.js +67 -36
  69. package/dist/virtual-list.d.ts +1 -0
  70. package/dist/virtual-list.js +21 -4
  71. package/dist/virtual-mouse.js +2 -1
  72. package/dist/watermark.js +2 -1
  73. package/package.json +33 -6
package/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.4.0 - 2026-11-28
6
+
7
+ - 新增 `HYSortable`、`HYDragSource`、`HYDropzone`,覆盖纵向/横向/网格排序、同组跨列表转移、应用数据和原生文件拖放;支持手柄、鼠标/触屏/键盘、类型限制、取消和主题化示例。
8
+ - 拖拽交互共享指针激活、捕获与取消、接收区深度跟踪和拖拽会话;现有 Draggable、Resizable、Upload 接入共享实现,排序保留原始内容节点并在放下时提交顺序。
9
+
10
+ ## 0.3.1 - 2026-11-24
11
+
12
+ - 完成剩余审查项:统一缺省数值属性,修复 Drawer/Dialog/Tour/Tooltip 的焦点、无障碍与生命周期,以及选择器禁用和 Radio 组互斥行为。
13
+ - Table 每次操作仅筛选/排序一次;表头、Anchor 与 VirtualList 保留可复用节点,Tree 批量删除只重建一次索引并支持超宽分支移动。
14
+ - VirtualKeyboard 按字素移动和删除,安全处理不支持选区 API 的输入类型,并统一禁用/只读检查。
15
+ - 完善 portable RadioGroup 的键盘/RTL 导航、Checkbox/RadioGroup/Rate 的模态初始焦点及 Rate 错误描述;修复订阅自定义比较器、不可变协议快照、事务复制开销与 PlatformView 双重失败诊断。
16
+ - 行为说明:Dialog 每次有效关闭同步发送一次 `dialog-close`;Tour 保留高亮目标交互,明确为非模态引导;core/portable 在不可变快照上校验并拒绝访问器、不可枚举字段及稀疏/扩展数组。
17
+ - API 门禁增加可达声明签名比较,覆盖接口、参数、联合类型与事件 detail;更新当前 23 种语义和 11 类 Web 复用组件的文档与回归。
18
+ - 修复 Tree 自定义渲染器与 Draggable/Resizable 子控件的键盘事件被容器快捷键截获;Resizable 的键盘移动遵守 `movable=false`。
19
+ - 保留 Tree、Dropdown 和 ContextMenu 在挂载前的程序赋值,以及断开重连后的当前数据;声明式属性初始化和后续属性更新继续生效。
20
+ - Upload 在接受文件选择/拖放或移除后发送一次 composed `change`,使 FormItem 校验和 Form 的异步提交使用已提交的文件列表;上传进度不使字段校验失效。
21
+
5
22
  ## 0.3.0 - 2026-11-24
6
23
 
7
24
  - 发布检查兼容 npm 11/12 的打包结果格式。
package/README.md CHANGED
@@ -508,6 +508,11 @@ Statuses are `ready`, `uploading`, `done`, and `error`. `files` returns actual `
508
508
  `upload-change` carries `{ file, fileList, reason }`, including progress/success/error/abort, and
509
509
  `file-reject` carries `{ file, reason, message }`. Request callbacks receive an AbortSignal and a
510
510
  0–100 progress callback; removed/replaced/disconnected requests cannot report stale success.
511
+ After accepting a selection/drop batch or completing an uncanceled removal, the host emits one
512
+ bubbling, composed `change` event after synchronizing its file list and native form value. Form Item
513
+ change validation and pending Form submissions therefore observe the accepted list. Native picker
514
+ input does not bubble to field listeners before acceptance; rejected selections, vetoed removals, request
515
+ progress/status updates, and programmatic `fileList` assignment do not emit this field-edit event.
511
516
  Native form submission includes actual File objects under `name`; metadata-only preloaded entries
512
517
  are displayed but do not fabricate files. `required` checks whether the list is empty.
513
518
  Style `dropzone`, `trigger`, `list`, `file`, `file-name`, `file-status`, `progress`, `remove`, `retry`,
@@ -695,7 +700,7 @@ no writes; reordering preserves instances. Applications persist values on `commi
695
700
 
696
701
  The Web backend is available from `@haiyue/ui/adapters/web`: explicitly call
697
702
  `definePortableWebComponents()`, construct `new HYWebRenderer(connectedElement, options)`, then pass it
698
- to `HYPage`. It reuses seven existing Web Components and maps the other semantic kinds to browser
703
+ to `HYPage`. It reuses eleven existing Web Components and maps the other semantic kinds to browser
699
704
  elements. It introduces no runtime package dependencies or automatic registration. See the
700
705
  [Web adapter guide](docs/web-adapter.md) and [interactive example](examples/portable-ui/index.html).
701
706
  Run `npm run test:web-adapter` for Chromium/WebKit regression coverage.
@@ -1099,6 +1104,73 @@ the exported `HY_VIRTUAL_KEYBOARD_NUMERIC_LAYOUT` with digits, decimal, minus, d
1099
1104
  `virtual-keyboard-up`, and `virtual-keyboard-input`, or style `keyboard`, `row`, `key`, and per-code key parts
1100
1105
  with the `--hy-virtual-keyboard-*` tokens.
1101
1106
 
1107
+ ## Drag-and-drop
1108
+
1109
+ `@haiyue/ui/sortable`, `@haiyue/ui/drag-source` and `@haiyue/ui/dropzone` provide independent entries
1110
+ and explicit `defineSortableComponents()`, `defineDragSourceComponents()` and `defineDropzoneComponents()`
1111
+ registration. They are also included in `defineHaiyueUI()`.
1112
+
1113
+ ```html
1114
+ <hy-sortable group="tasks" aria-label="Backlog">
1115
+ <article data-id="a">Task A</article>
1116
+ <article data-id="b">Task B</article>
1117
+ </hy-sortable>
1118
+ <hy-sortable group="tasks" aria-label="Ready"></hy-sortable>
1119
+
1120
+ <hy-drag-source id="asset" type="asset" value="ocean" aria-label="Ocean material">
1121
+ Ocean material
1122
+ </hy-drag-source>
1123
+ <hy-dropzone id="target" accept="asset,Files" aria-label="Asset destination">
1124
+ Drop an asset or files here
1125
+ </hy-dropzone>
1126
+ ```
1127
+
1128
+ ```js
1129
+ const source = document.querySelector('#asset');
1130
+ source.data = { id: 'ocean', name: 'Ocean material' };
1131
+ document.querySelector('#target').addEventListener('data-drop', event => {
1132
+ const { data, files, type, source, effect, input } = event.detail;
1133
+ if (!canPlace(data, files)) event.preventDefault();
1134
+ else placeAsset(data, files);
1135
+ });
1136
+ document.addEventListener('sort-change', event => {
1137
+ const { from, to, item, oldIndex, newIndex, fromOrder, toOrder } = event.detail;
1138
+ saveListOrders(fromOrder, toOrder);
1139
+ });
1140
+ ```
1141
+
1142
+ Sortable uses the visible, unnamed direct children as items. `data-id` or `id` supplies a stable key in
1143
+ `order`, `fromOrder` and `toOrder`; items without either receive an internal stable key. `direction` accepts
1144
+ `vertical` (default), `horizontal` and `grid`; `columns` defaults to 3 for the grid. Lists with the same
1145
+ nonempty `group` accept transfers between them, including into empty lists. `handle` restricts pointer
1146
+ activation to a CSS selector, `data-sort-disabled` prevents picking up an individual item, and `disabled`
1147
+ prevents sorting. `keyboard="false"` disables keyboard sorting. `move(fromIndex, toIndex)` reorders through
1148
+ the API. `refresh()` synchronizes item accessibility after changing item-level attributes.
1149
+
1150
+ `sort-start` and `sort-before-change` are cancelable. Sortable commits the original DOM elements on a
1151
+ successful drop, then emits one composed `sort-change` from the destination. It retains editable content
1152
+ and restores focus. `sort-end` is emitted from the origin and includes `accepted` and `cancelled`.
1153
+ Press Space or Enter on an item to pick it up, arrows/Home/End to choose a position, and Enter to commit.
1154
+ Tab can focus another list; Escape cancels. Horizontal and grid navigation follow RTL. Drop indicators
1155
+ and polite announcements communicate the current operation. Pointer gestures activate after 6px and
1156
+ support edge scrolling. Touch gestures use `touch-action: none`; `--hy-sortable-touch-action` can override it.
1157
+
1158
+ Drag Source supplies a `type`, arbitrary JavaScript `data` (or a string `value` attribute), `effect`
1159
+ (`move` by default, or `copy`), optional `handle`, and `disabled`. Its composed `drag-start` is cancelable;
1160
+ `drag-end` includes the payload, `target`, `accepted` and `cancelled`. Keyboard users pick up with Space,
1161
+ Tab to a Dropzone and press Enter to drop. The receiving application handles content placement.
1162
+
1163
+ Dropzone accepts comma-separated payload or native transfer types through `accept` (default `*`).
1164
+ `Files` accepts operating-system file drags; native file drops expose real `File` objects in `files`.
1165
+ Application payloads retain their original `data` object. `data-drop` is cancelable, and `drag-enter` /
1166
+ `drag-leave` expose application payload hover changes. Nested targets choose the innermost accepting zone.
1167
+ For file selection, type/size/count validation, upload progress and retry, use `hy-upload drag`.
1168
+
1169
+ Sortable exposes `items`, `indicator` and `status` parts and `--hy-sortable-gap`, `--hy-sortable-min-height`,
1170
+ `--hy-sortable-drag-opacity`. Drag Source and Dropzone expose a `surface` part. Dropzone also accepts
1171
+ `--hy-dropzone-padding`, `--hy-dropzone-radius`, `--hy-dropzone-min-height` and `--hy-dropzone-bg-color`.
1172
+ Colors, typography, focus rings and drop feedback inherit the shared theme tokens.
1173
+
1102
1174
  ## Draggable container
1103
1175
 
1104
1176
  Import the transform-based container independently, then use any slotted element as its handle:
@@ -1339,7 +1411,7 @@ npm run release:check
1339
1411
  ```
1340
1412
 
1341
1413
  Candidates: `.artifacts/packages/`. Review API changes before `npm run api:update`.
1342
- See [release review](review/release-0.2.2.md).
1414
+ See [release history](CHANGELOG.md).
1343
1415
 
1344
1416
  ### 共享组件目录(开发中)
1345
1417
 
@@ -1376,3 +1448,13 @@ or validation errors preserves the existing input, selection and composition.
1376
1448
  `hyResponsiveWorkspace`, `HYResponsiveGridOptions` and
1377
1449
  `HYResponsiveWorkspaceOptions`. These return logical-pixel layout data without
1378
1450
  reading window or platform globals, so hosts can use actual split-window sizes.
1451
+
1452
+ ### 审查后的交互契约
1453
+
1454
+ 数值属性缺省或为空时使用文档默认值;显式 `0` 继续按各控件范围处理。Table 每次同步操作共享一次筛选/排序结果,公开数据 getter 仍读取最新记录和筛选闭包;更新列结构会重建表头,排序/筛选保留表头控件。VirtualList 滚动复用重叠行,`refresh()` 或替换数据/渲染器会重建内容;焦点行移出窗口时焦点回到列表视口。
1455
+
1456
+ Drawer 的模态 Tab 环绕包含插槽中的 Shadow DOM 控件。Dialog 断开时释放原生 modal 状态,重新连接后按 `open` 恢复;每次有效关闭同步发送一次 `dialog-close`,重新打开不会被旧原生 close 事件撤销。Tour 是允许高亮目标交互的非模态引导,不声明 `aria-modal`;打开时清空步骤会以 `programmatic` 关闭并清理监听。Tooltip 在真实触发目标所在树中提供可访问描述,保留应用自己的 `aria-describedby`,禁用或移除时清理关系。
1457
+
1458
+ VirtualKeyboard 对 textarea 及支持选区 API 的 text/search/url/tel/password input 编辑;其他 input 类型安全忽略编辑。移动和删除按完整字素处理,包括 emoji、组合字符与 ZWJ 序列;禁用或只读目标不会被修改。portable RadioGroup 仅保留一个 Tab 停靠点,方向键跳过禁用项并按 RTL 导航;所有选择仍经过受控状态回填。
1459
+
1460
+ core/portable 仅接受普通数据对象与无空洞数组;拒绝访问器、不可枚举属性、符号键和额外数组属性,在不可变快照上验证,调用方后续修改不影响已接受的数据。新增辅助模块保持私有,不新增公开入口;API 基线现同时记录导出名与可达声明签名。
@@ -14,7 +14,7 @@ import { defineRadioComponents } from '../../radio.js';
14
14
  import { defineRateComponents } from '../../rate.js';
15
15
  import { defineBadgeComponents } from '../../badge.js';
16
16
  import { defineDividerComponents } from '../../divider.js';
17
- import { attribute, flag, focusable } from './dom.js';
17
+ import { attribute, flag, focusable, captureFocus } from './dom.js';
18
18
  /** Registration is explicit and limited to the reused components. */
19
19
  export function definePortableWebComponents() {
20
20
  defineButtonComponents();
@@ -49,12 +49,47 @@ export function createControl(node, context, revision) {
49
49
  let props = node.props;
50
50
  const buttons = new Map(), groupName = `hy-portable-radio-${++radioGroupSequence}`;
51
51
  host.setAttribute('role', 'radiogroup');
52
- const render = () => { for (const [value, button] of buttons) {
53
- flag(button, 'checked', props.value === value);
54
- flag(button, 'disabled', !!props.disabled || !!props.options.find(o => o.value === value)?.disabled);
55
- } };
52
+ const enabled = () => props.disabled ? [] : props.options.filter(option => !option.disabled);
53
+ const focusValue = () => enabled().find(option => option.value === props.value)?.value ?? enabled()[0]?.value;
54
+ const focus = () => buttons.get(focusValue() ?? '')?.shadowRoot?.querySelector('input')?.focus();
55
+ const render = () => {
56
+ const tabValue = focusValue();
57
+ for (const [value, button] of buttons) {
58
+ flag(button, 'checked', props.value === value);
59
+ flag(button, 'disabled', !!props.disabled || !!props.options.find(o => o.value === value)?.disabled);
60
+ const input = button.shadowRoot?.querySelector('input');
61
+ if (input)
62
+ input.tabIndex = value === tabValue ? 0 : -1;
63
+ }
64
+ };
56
65
  listen(host, 'checked-change', event => { const detail = event.detail; if (detail.checked)
57
66
  controller.choose(detail.value, reason); render(); });
67
+ listen(host, 'keydown', event => {
68
+ const key = event;
69
+ if (key.defaultPrevented || key.altKey || key.ctrlKey || key.metaKey)
70
+ return;
71
+ const options = enabled();
72
+ if (!options.length)
73
+ return;
74
+ const target = key.composedPath().find((node) => node instanceof HTMLElement && [...buttons.values()].includes(node));
75
+ const current = options.findIndex(option => buttons.get(option.value) === target);
76
+ const rtl = getComputedStyle(host).direction === 'rtl';
77
+ let next;
78
+ if (key.key === 'Home')
79
+ next = 0;
80
+ else if (key.key === 'End')
81
+ next = options.length - 1;
82
+ else if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(key.key)) {
83
+ const forward = key.key === 'ArrowDown' || key.key === (rtl ? 'ArrowLeft' : 'ArrowRight');
84
+ next = current < 0 ? 0 : (current + (forward ? 1 : -1) + options.length) % options.length;
85
+ }
86
+ else
87
+ return;
88
+ key.preventDefault();
89
+ controller.choose(options[next].value, 'keyboard');
90
+ render();
91
+ focus();
92
+ });
58
93
  return { update(next) {
59
94
  if (next.kind !== 'RadioGroup')
60
95
  return;
@@ -65,6 +100,8 @@ export function createControl(node, context, revision) {
65
100
  button.remove();
66
101
  buttons.delete(value);
67
102
  }
103
+ const restoreFocus = captureFocus(host.ownerDocument);
104
+ let cursor = host.firstElementChild;
68
105
  for (const option of props.options) {
69
106
  let button = buttons.get(option.value);
70
107
  if (!button) {
@@ -74,11 +111,14 @@ export function createControl(node, context, revision) {
74
111
  attribute(button, 'value', option.value);
75
112
  attribute(button, 'label', option.label);
76
113
  attribute(button, 'name', groupName);
77
- host.append(button);
114
+ if (button !== cursor)
115
+ host.insertBefore(button, cursor);
116
+ cursor = button.nextElementSibling;
78
117
  }
79
118
  render();
119
+ restoreFocus();
80
120
  },
81
- focus() { focusable(host)[0]?.focus(); }, dispose() { controller.dispose(); buttons.clear(); } };
121
+ focus, dispose() { controller.dispose(); buttons.clear(); } };
82
122
  }
83
123
  if (node.kind === 'Rate') {
84
124
  let props = node.props, disposed = false, choosing = false;
@@ -101,7 +141,7 @@ export function createControl(node, context, revision) {
101
141
  }
102
142
  });
103
143
  return { update(next) { if (next.kind !== 'Rate')
104
- return; props = next.props; attribute(host, 'count', String(props.count)); flag(host, 'disabled', !!props.disabled); flag(host, 'readonly', !!props.readOnly); restore(); }, focus() { focusable(host)[0]?.focus(); }, dispose() { disposed = true; } };
144
+ return; props = next.props; attribute(host, 'count', String(props.count)); flag(host, 'disabled', !!props.disabled); flag(host, 'readonly', !!props.readOnly); restore(); }, focus() { host.shadowRoot?.querySelector('[role="slider"]')?.focus(); }, dispose() { disposed = true; } };
105
145
  }
106
146
  if (node.kind === 'Button') {
107
147
  const button = host;
@@ -8,6 +8,10 @@ import { componentTags, createControl } from './controls.js';
8
8
  import { applyAccessibility, applyLayout, attribute, captureFocus, deepActive, flag, focusable } from './dom.js';
9
9
  import { componentCSS, rootCSS } from './styles.js';
10
10
  const tags = { Row: 'div', Column: 'div', Grid: 'div', Overlay: 'div', Scroll: 'div', Text: 'span', Image: 'img', Icon: 'img', TextArea: 'textarea', FormGroup: 'fieldset', PlatformView: 'div', ...componentTags };
11
+ const a11ySelectors = {
12
+ Row: null, Column: null, Grid: null, Overlay: null, Scroll: null, Text: null, Image: null, Icon: null, TextArea: null, FormGroup: null, PlatformView: null, Badge: null, Divider: null,
13
+ Button: 'button', Checkbox: 'input', Toggle: 'input', RadioGroup: 'input', Rate: '[role="slider"]', Select: 'select', Tabs: '[role="tablist"],button', TextInput: 'input', Slider: 'button.upper', Dialog: 'dialog',
14
+ };
11
15
  let rendererSequence = 0;
12
16
  /** Browser-only adapter. Explicit registration and an attached, same-realm mount point are required. */
13
17
  export class HYWebRenderer {
@@ -334,11 +338,12 @@ export class HYWebRenderer {
334
338
  const description = [node.props.a11y?.description, groupProps?.description, node.props.a11y?.error ?? groupProps?.error].filter(Boolean).join('. ');
335
339
  const a11y = label === undefined ? undefined : { ...node.props.a11y, label, ...(groupProps?.error && !node.props.a11y?.error ? { error: groupProps.error } : {}) };
336
340
  applyAccessibility(element, a11y);
337
- const targets = element instanceof HYTabs ? [...element.shadowRoot.querySelectorAll('[role=tablist],button')]
338
- : element.shadowRoot ? [element.shadowRoot.querySelector(node.kind === 'Slider' ? 'button.upper' : 'input:not([type=search]),select,button,dialog')].filter((el) => !!el) : [element];
341
+ const selector = a11ySelectors[node.kind];
342
+ const targets = node.kind === 'RadioGroup' ? [...element.querySelectorAll('hy-radio')].flatMap(radio => [...radio.shadowRoot.querySelectorAll('input')])
343
+ : selector && element.shadowRoot ? [...element.shadowRoot.querySelectorAll(selector)] : [element];
339
344
  for (const target of targets) {
340
345
  // Tabs label belongs to the tablist; each tab keeps its option name.
341
- if (!(element instanceof HYTabs) || target.getAttribute('role') === 'tablist')
346
+ if (node.kind !== 'RadioGroup' && (!(element instanceof HYTabs) || target.getAttribute('role') === 'tablist'))
342
347
  applyAccessibility(target, a11y);
343
348
  attribute(target, 'aria-description', description || undefined);
344
349
  attribute(target, 'aria-invalid', (node.props.a11y?.error ?? groupProps?.error) ? 'true' : undefined);
package/dist/anchor.d.ts CHANGED
@@ -48,6 +48,8 @@ export declare class HYAnchor extends HTMLElement {
48
48
  private _readItemsAttribute;
49
49
  private _flatten;
50
50
  private _render;
51
+ private _syncLabel;
52
+ private _syncActive;
51
53
  private _onClick;
52
54
  private _resolveTarget;
53
55
  private _connect;
package/dist/anchor.js CHANGED
@@ -1,5 +1,6 @@
1
+ import { finiteNumber as readFiniteNumber } from './internal/numbers.js';
1
2
  function finiteNumber(value, fallback, min, max) {
2
- const number = Number(value);
3
+ const number = readFiniteNumber(value, fallback);
3
4
  return Number.isFinite(number) ? Math.min(max, Math.max(min, number)) : fallback;
4
5
  }
5
6
  /** Hash-link navigation that tracks targets inside the viewport or an owned scroll container. */
@@ -54,9 +55,14 @@ export class HYAnchor extends HTMLElement {
54
55
  attributeChangedCallback(name, oldValue, newValue) {
55
56
  if (oldValue === newValue)
56
57
  return;
57
- if (name === 'items')
58
+ if (name === 'items') {
58
59
  this._readItemsAttribute();
59
- this._render();
60
+ this._render();
61
+ }
62
+ else if (name === 'active-href')
63
+ this._syncActive();
64
+ else if (name === 'aria-label')
65
+ this._syncLabel();
60
66
  if (this.isConnected && ['offset-top', 'bounds'].includes(name))
61
67
  this.refresh();
62
68
  }
@@ -143,7 +149,7 @@ export class HYAnchor extends HTMLElement {
143
149
  _render() {
144
150
  if (!this._list)
145
151
  return;
146
- this._nav.setAttribute('aria-label', this.getAttribute('aria-label') ?? 'On this page');
152
+ this._syncLabel();
147
153
  this._list.replaceChildren();
148
154
  const append = (items, depth) => {
149
155
  for (const item of items) {
@@ -172,6 +178,19 @@ export class HYAnchor extends HTMLElement {
172
178
  };
173
179
  append(this._items, 0);
174
180
  }
181
+ _syncLabel() {
182
+ this._nav.setAttribute('aria-label', this.getAttribute('aria-label') ?? 'On this page');
183
+ }
184
+ _syncActive() {
185
+ for (const link of this._list.querySelectorAll('a[data-href]')) {
186
+ const active = link.dataset.href === this.activeHref;
187
+ link.classList.toggle('active', active);
188
+ if (active)
189
+ link.setAttribute('aria-current', 'location');
190
+ else
191
+ link.removeAttribute('aria-current');
192
+ }
193
+ }
175
194
  _onClick(event, item) {
176
195
  if (item.disabled) {
177
196
  event.preventDefault();
@@ -1,10 +1,11 @@
1
+ import { finiteNumber as readFiniteNumber } from './internal/numbers.js';
1
2
  const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
2
3
  const DEFAULT_THICKNESS = 2;
3
4
  const DEFAULT_SPEED = 1;
4
5
  const DEFAULT_COUNT = 1;
5
6
  const BASE_DURATION_SECONDS = 6;
6
7
  function finiteNumber(value, fallback) {
7
- const number = Number(value);
8
+ const number = readFiniteNumber(value, fallback);
8
9
  return Number.isFinite(number) ? number : fallback;
9
10
  }
10
11
  /** Decorative animated border that follows the host's live rounded rectangle. */
package/dist/cascader.js CHANGED
@@ -314,6 +314,10 @@ export class HYCascader extends HTMLElement {
314
314
  return resolved;
315
315
  }
316
316
  _render() {
317
+ if (this.disabled && this.open) {
318
+ this.open = false;
319
+ return;
320
+ }
317
321
  const selected = this._resolveOptions(this._value);
318
322
  const text = selected.map(option => option.label).join(this.displaySeparator);
319
323
  this._label.textContent = text || this.placeholder;
@@ -392,7 +396,7 @@ export class HYCascader extends HTMLElement {
392
396
  return row;
393
397
  }
394
398
  _activateOption(option, depth, focusNext = false) {
395
- if (option.disabled)
399
+ if (this.disabled || option.disabled)
396
400
  return;
397
401
  const next = [...this._activePath.slice(0, depth), option.value];
398
402
  this._activePath = next;
@@ -408,6 +412,8 @@ export class HYCascader extends HTMLElement {
408
412
  this._commit(next, true);
409
413
  }
410
414
  _commit(value, close) {
415
+ if (this.disabled)
416
+ return;
411
417
  this._value = this._normalizePath(value);
412
418
  this._activePath = [...this._value];
413
419
  this._reflectValue();
@@ -40,7 +40,6 @@ ${GE_MENU_ITEM_STYLES}
40
40
  this._root.append(this._style, this._menu);
41
41
  }
42
42
  connectedCallback() {
43
- this._readItemsAttribute();
44
43
  this._render();
45
44
  this._syncDocumentListeners();
46
45
  }
@@ -1,5 +1,4 @@
1
- import { snapshot } from './data.js';
2
- import { hyKey, hyValidateProps } from './validation.js';
1
+ import { hyKey, snapshotValidatedProps } from './validation.js';
3
2
  export class HYButtonController {
4
3
  key;
5
4
  emit;
@@ -17,8 +16,8 @@ export class HYButtonController {
17
16
  update(props) {
18
17
  if (this.#disposed)
19
18
  return;
20
- hyValidateProps('Button', props, { key: this.key });
21
- this.#props = snapshot(props);
19
+ props = snapshotValidatedProps('Button', props, { key: this.key });
20
+ this.#props = props;
22
21
  }
23
22
  /** Adapters pass the same gesture id for overlapping tap/click/accessibility callbacks. */
24
23
  activate(reason = 'pointer', gesture) {
@@ -58,8 +57,8 @@ export class HYToggleController {
58
57
  update(props) {
59
58
  if (this.#disposed)
60
59
  return;
61
- hyValidateProps('Toggle', props, { key: this.key });
62
- this.#props = snapshot(props);
60
+ props = snapshotValidatedProps('Toggle', props, { key: this.key });
61
+ this.#props = props;
63
62
  }
64
63
  choose(checked, reason = 'pointer') {
65
64
  if (typeof checked !== 'boolean' || this.#disposed || this.#emitting || this.#props.disabled || this.#props.visible === false || checked === this.#props.checked)
@@ -97,12 +96,12 @@ export class HYSliderController {
97
96
  update(props) {
98
97
  if (this.#disposed)
99
98
  return;
100
- hyValidateProps('Slider', props, { key: this.key });
99
+ props = snapshotValidatedProps('Slider', props, { key: this.key });
101
100
  if (!this.#props || props.value !== this.#props.value || props.min !== this.#props.min || props.max !== this.#props.max || props.step !== this.#props.step || props.disabled || props.visible === false) {
102
101
  this.#draft = props.value;
103
102
  this.#active = 0;
104
103
  }
105
- this.#props = snapshot(props);
104
+ this.#props = props;
106
105
  }
107
106
  change(value, reason = 'pointer') {
108
107
  if (this.#disposed || this.#props.disabled || this.#props.visible === false || !Number.isFinite(value))
@@ -1,4 +1,4 @@
1
1
  /** Internal structural comparison for immutable protocol data; never serializes props. */
2
2
  export declare function equalData(a: unknown, b: unknown): boolean;
3
3
  export declare function isSnapshot(value: object): boolean;
4
- export declare function snapshot<T>(value: T): T;
4
+ export declare function snapshot<T>(value: T, reject?: (message: string, property: string) => never): T;
package/dist/core/data.js CHANGED
@@ -11,17 +11,51 @@ export function equalData(a, b) {
11
11
  return keys.length === Object.keys(right).length
12
12
  && keys.every(key => Object.hasOwn(right, key) && equalData(left[key], right[key]));
13
13
  }
14
- /** Called only after schema validation, so cycles and platform handles are impossible. */
14
+ /** Only internally copied, deeply frozen data may bypass later descriptor checks. */
15
15
  const snapshots = new WeakSet();
16
16
  export function isSnapshot(value) { return snapshots.has(value); }
17
- export function snapshot(value) {
18
- if (!value || typeof value !== 'object')
19
- return value;
20
- if (snapshots.has(value))
21
- return value;
22
- const result = Array.isArray(value) ? Object.freeze(value.map(snapshot))
23
- : Object.freeze(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, snapshot(item)])));
24
- snapshots.add(result);
25
- return result;
17
+ export function snapshot(value, reject = message => { throw new TypeError(message); }) {
18
+ const ancestors = new Set();
19
+ const copies = new WeakMap();
20
+ const copy = (value, path) => {
21
+ if (!value || typeof value !== 'object')
22
+ return value;
23
+ if (snapshots.has(value))
24
+ return value;
25
+ if (ancestors.has(value))
26
+ return reject('Cyclic protocol data', path);
27
+ const existing = copies.get(value);
28
+ if (existing)
29
+ return existing;
30
+ const array = Array.isArray(value);
31
+ if (!array && ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
32
+ return reject('Expected plain data object', path);
33
+ const descriptors = Object.getOwnPropertyDescriptors(value);
34
+ const length = array ? descriptors.length.value : 0;
35
+ const keys = Reflect.ownKeys(descriptors);
36
+ if (array && keys.length !== length + 1)
37
+ return reject('Expected dense array without extra properties', path);
38
+ const result = array ? [] : {};
39
+ ancestors.add(value);
40
+ for (const key of keys) {
41
+ if (array && key === 'length')
42
+ continue;
43
+ const property = path ? `${path}.${String(key)}` : String(key);
44
+ if (typeof key !== 'string')
45
+ return reject('Symbols are not protocol data', property);
46
+ const descriptor = descriptors[key];
47
+ if (!descriptor.enumerable || !('value' in descriptor))
48
+ return reject('Accessors or non-enumerable properties are not protocol data', property);
49
+ if (array && (!/^(0|[1-9]\d*)$/.test(key) || Number(key) >= length))
50
+ return reject('Expected dense array index', property);
51
+ Object.defineProperty(result, key, { value: copy(descriptor.value, property), enumerable: true, writable: true, configurable: true });
52
+ }
53
+ ancestors.delete(value);
54
+ Object.freeze(result);
55
+ snapshots.add(result);
56
+ copies.set(value, result);
57
+ return result;
58
+ };
59
+ return copy(value, '');
26
60
  }
27
61
  //# sourceMappingURL=data.js.map
@@ -1,5 +1,5 @@
1
1
  import { equalData, snapshot } from './data.js';
2
- import { HYUIError } from './validation.js';
2
+ import { HYUIError, snapshotProtocolData } from './validation.js';
3
3
  /** Backend-owned resource lifetime. No GPU acquire/present or platform handles in page state. */
4
4
  export class HYPlatformViewController {
5
5
  factory;
@@ -29,7 +29,12 @@ export class HYPlatformViewController {
29
29
  this.#view.visible(this.shown && !this.#suspended);
30
30
  }
31
31
  catch (error) {
32
- this.dispose();
32
+ try {
33
+ this.dispose();
34
+ }
35
+ catch (cleanup) {
36
+ throw new AggregateError([error, cleanup], 'PlatformView initialization and cleanup failed', { cause: error });
37
+ }
33
38
  throw error;
34
39
  }
35
40
  }
@@ -45,6 +50,7 @@ export class HYPlatformViewController {
45
50
  layout(bounds) {
46
51
  if (this.#disposed)
47
52
  return;
53
+ bounds = snapshotProtocolData(bounds);
48
54
  if (![bounds.x, bounds.y, bounds.width, bounds.height, bounds.scale].every(Number.isFinite)
49
55
  || bounds.width < 0 || bounds.height < 0 || bounds.scale <= 0)
50
56
  throw new HYUIError('invalid-props', 'Invalid PlatformView bounds');
@@ -1,5 +1,5 @@
1
- import { equalData, snapshot } from './data.js';
2
- import { HYUIError, hyKey, hyValidateProps } from './validation.js';
1
+ import { equalData } from './data.js';
2
+ import { HYUIError, hyKey, snapshotValidatedProps } from './validation.js';
3
3
  /** Controlled Select/Tabs semantics. Views report user actions, never delayed setter echoes. */
4
4
  export class HYSelectionController {
5
5
  key;
@@ -22,10 +22,10 @@ export class HYSelectionController {
22
22
  update(props) {
23
23
  if (this.#disposed)
24
24
  return;
25
- hyValidateProps('Select', props, { key: this.key });
25
+ props = snapshotValidatedProps('Select', props, { key: this.key });
26
26
  if (equalData(props, this.#props))
27
27
  return;
28
- this.#props = snapshot(props);
28
+ this.#props = props;
29
29
  this.#generation++;
30
30
  this.#apply();
31
31
  }
@@ -0,0 +1,26 @@
1
+ /** Exhaustive semantic focus policy, independent of any platform's control implementation. */
2
+ export declare const componentInteraction: Readonly<{
3
+ Row: false;
4
+ Column: false;
5
+ Grid: false;
6
+ Overlay: false;
7
+ Scroll: false;
8
+ Text: false;
9
+ Image: false;
10
+ Icon: false;
11
+ Badge: false;
12
+ Divider: false;
13
+ FormGroup: false;
14
+ Button: true;
15
+ Checkbox: true;
16
+ Toggle: true;
17
+ RadioGroup: true;
18
+ Rate: true;
19
+ Select: true;
20
+ Tabs: true;
21
+ TextInput: true;
22
+ TextArea: true;
23
+ Slider: true;
24
+ Dialog: false;
25
+ PlatformView: true;
26
+ }>;
@@ -0,0 +1,8 @@
1
+ /** Exhaustive semantic focus policy, independent of any platform's control implementation. */
2
+ export const componentInteraction = Object.freeze({
3
+ Row: false, Column: false, Grid: false, Overlay: false, Scroll: false,
4
+ Text: false, Image: false, Icon: false, Badge: false, Divider: false, FormGroup: false,
5
+ Button: true, Checkbox: true, Toggle: true, RadioGroup: true, Rate: true,
6
+ Select: true, Tabs: true, TextInput: true, TextArea: true, Slider: true, Dialog: false, PlatformView: true,
7
+ });
8
+ //# sourceMappingURL=semantics.js.map
package/dist/core/text.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { equalData, snapshot } from './data.js';
2
- import { HYUIError, hyKey, hyValidateProps } from './validation.js';
2
+ import { HYUIError, hyKey, snapshotValidatedProps } from './validation.js';
3
3
  /** Local draft/IME state only. The application accepts or rejects commit through props/revision. */
4
4
  export class HYTextController {
5
5
  key;
@@ -28,7 +28,7 @@ export class HYTextController {
28
28
  update(props, revision = this.#revision) {
29
29
  if (this.#disposed)
30
30
  return;
31
- hyValidateProps(this.multiline ? 'TextArea' : 'TextInput', props, { key: this.key });
31
+ props = snapshotValidatedProps(this.multiline ? 'TextArea' : 'TextInput', props, { key: this.key });
32
32
  if (!Number.isSafeInteger(revision) || revision < 0)
33
33
  throw new HYUIError('invalid-props', 'Invalid application revision', { key: this.key });
34
34
  if (revision < this.#revision)
@@ -36,7 +36,7 @@ export class HYTextController {
36
36
  const changed = !this.#props || props.value !== this.#props.value;
37
37
  if (this.#props && changed && revision === this.#revision)
38
38
  throw new HYUIError('invalid-props', 'Changed accepted value requires a newer revision', { key: this.key });
39
- this.#props = snapshot(props);
39
+ this.#props = props;
40
40
  this.#revision = revision;
41
41
  if (changed) {
42
42
  if (this.#composing)
@@ -6,10 +6,12 @@ export declare class HYUIError extends Error {
6
6
  }
7
7
  export declare const HY_FEATURES: readonly HYFeature[];
8
8
  export declare const HY_COMPONENTS: readonly HYComponentKind[];
9
+ /** Internal descriptor-safe handoff: validation and consumers see the same immutable values. */
10
+ export declare function snapshotProtocolData<T>(value: T, context?: HYDiagnosticContext): T;
9
11
  export declare function hyValidateCapabilities(capabilities: HYCapabilities): void;
10
12
  export declare function hySupports(capabilities: HYCapabilities, feature: HYFeature): boolean;
11
13
  /** Internal immutable hand-off. Mutable and merely shallow-frozen inputs are always validated. */
12
- export declare function snapshotValidatedProps<K extends HYComponentKind>(kind: K, props: HYComponentProps[K], context: HYDiagnosticContext, capabilities: HYCapabilities): HYComponentProps[K];
14
+ export declare function snapshotValidatedProps<K extends HYComponentKind>(kind: K, props: HYComponentProps[K], context: HYDiagnosticContext, capabilities?: HYCapabilities): HYComponentProps[K];
13
15
  export declare function hyValidateProps<K extends HYComponentKind>(kind: K, props: HYComponentProps[K], context?: HYDiagnosticContext, capabilities?: HYCapabilities): void;
14
16
  /** Escaped, stable backend key. Author keys are unique across all slots of one parent. */
15
17
  export declare function hyKey(...parts: readonly string[]): string;