@mistriwork/ui 1.0.0-rc.58 → 1.0.0-rc.59

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 (122) hide show
  1. package/README.md +46 -12
  2. package/dist/Avatar.js +3 -3
  3. package/dist/Button.d.ts +4 -14
  4. package/dist/Button.js +26 -13
  5. package/dist/Carousel.d.ts +6 -5
  6. package/dist/Carousel.js +58 -67
  7. package/dist/Choices.d.ts +2 -9
  8. package/dist/Choices.js +127 -64
  9. package/dist/DateField.d.ts +9 -4
  10. package/dist/DateField.js +102 -119
  11. package/dist/Drawer.d.ts +1 -19
  12. package/dist/Drawer.js +8 -9
  13. package/dist/DropMenu.d.ts +8 -21
  14. package/dist/DropMenu.js +84 -30
  15. package/dist/Dropdown.d.ts +9 -8
  16. package/dist/Dropdown.js +69 -65
  17. package/dist/Field.d.ts +2 -1
  18. package/dist/Field.js +12 -18
  19. package/dist/FileField.d.ts +3 -10
  20. package/dist/FileField.js +12 -9
  21. package/dist/FormParts.d.ts +17 -10
  22. package/dist/FormParts.js +26 -41
  23. package/dist/HeroBlocks.d.ts +7 -3
  24. package/dist/HeroBlocks.js +11 -6
  25. package/dist/Modal.d.ts +6 -17
  26. package/dist/Modal.js +90 -21
  27. package/dist/Pagination.d.ts +1 -12
  28. package/dist/Pagination.js +17 -3
  29. package/dist/Popover.d.ts +1 -15
  30. package/dist/Popover.js +10 -15
  31. package/dist/Resizable.d.ts +3 -21
  32. package/dist/Resizable.js +14 -91
  33. package/dist/ScrollArea.d.ts +4 -2
  34. package/dist/ScrollArea.js +11 -11
  35. package/dist/Select.d.ts +1 -6
  36. package/dist/Select.js +16 -7
  37. package/dist/SensitiveField.d.ts +1 -8
  38. package/dist/SensitiveField.js +6 -4
  39. package/dist/Slider.d.ts +1 -5
  40. package/dist/Slider.js +13 -5
  41. package/dist/Switch.d.ts +1 -11
  42. package/dist/Switch.js +10 -9
  43. package/dist/Tabs.d.ts +3 -3
  44. package/dist/Tabs.js +3 -3
  45. package/dist/TextArea.d.ts +4 -6
  46. package/dist/TextArea.js +14 -5
  47. package/dist/TextField.d.ts +5 -9
  48. package/dist/TextField.js +67 -9
  49. package/dist/Tooltip.d.ts +1 -21
  50. package/dist/Tooltip.js +13 -31
  51. package/dist/Typeahead.d.ts +15 -18
  52. package/dist/Typeahead.js +151 -86
  53. package/dist/UiKit.d.ts +63 -4
  54. package/dist/UiKit.js +46 -5
  55. package/dist/behaviors/DaysParts.js +28 -0
  56. package/dist/behaviors/EditableParts.js +21 -0
  57. package/dist/behaviors/PickParts.js +30 -0
  58. package/dist/behaviors/ScrubParts.js +21 -0
  59. package/dist/behaviors/SortableParts.js +32 -0
  60. package/dist/behaviors/SpansParts.js +12 -0
  61. package/dist/behaviors/TransferParts.js +37 -0
  62. package/dist/behaviors/TurnsParts.js +31 -0
  63. package/dist/behaviors/WidthsParts.js +27 -0
  64. package/dist/behaviors/days.js +216 -0
  65. package/dist/behaviors/dress.js +86 -0
  66. package/dist/behaviors/editable.js +104 -0
  67. package/dist/behaviors/heard.js +22 -0
  68. package/dist/behaviors/index.d.ts +310 -0
  69. package/dist/behaviors/index.js +44 -0
  70. package/dist/behaviors/pick.js +158 -0
  71. package/dist/behaviors/scrub.js +152 -0
  72. package/dist/behaviors/sortable.js +170 -0
  73. package/dist/behaviors/spans.js +240 -0
  74. package/dist/behaviors/testing.js +48 -0
  75. package/dist/behaviors/transfer.js +202 -0
  76. package/dist/behaviors/turns.js +106 -0
  77. package/dist/behaviors/widths.js +150 -0
  78. package/dist/behaviors.css +309 -0
  79. package/dist/changeDetails.d.ts +4 -8
  80. package/dist/changeDetails.js +0 -6
  81. package/dist/conformance.js +107 -1
  82. package/dist/controls.css +36 -0
  83. package/dist/fieldFrame.d.ts +2 -15
  84. package/dist/fieldFrame.js +1 -17
  85. package/dist/index.d.ts +6 -5
  86. package/dist/index.js +6 -5
  87. package/dist/internal/Frame.d.ts +6 -0
  88. package/dist/internal/Frame.js +25 -0
  89. package/dist/internal/HelpTip.d.ts +5 -0
  90. package/dist/internal/HelpTip.js +37 -0
  91. package/dist/internal/layers.d.ts +21 -0
  92. package/dist/internal/layers.js +66 -0
  93. package/dist/internal/popups.d.ts +12 -10
  94. package/dist/internal/popups.js +18 -14
  95. package/dist/internal/told.d.ts +14 -0
  96. package/dist/internal/told.js +20 -0
  97. package/dist/internal/uiKitContext.js +6 -4
  98. package/dist/preferences.css +2 -3
  99. package/dist/style.css +5 -16
  100. package/dist/styles/extras.css +461 -0
  101. package/dist/styles/forms.css +346 -0
  102. package/dist/styles/guard.css +114 -0
  103. package/dist/styles/kit-fields.css +181 -0
  104. package/dist/styles/kit-parts.css +130 -0
  105. package/dist/styles/kit.css +558 -0
  106. package/dist/styles/layers.css +4 -0
  107. package/dist/styles/looks.css +374 -0
  108. package/dist/styles/m-tokens.css +173 -0
  109. package/dist/styles/overlays.css +107 -0
  110. package/dist/styles/parts.css +456 -0
  111. package/dist/styles/screens.css +76 -0
  112. package/dist/styles/ui-sdk.css +1635 -0
  113. package/dist/tokens.css +15 -4
  114. package/dist/uiKitSlots.d.ts +1 -1
  115. package/dist/uiKitSlots.js +18 -2
  116. package/package.json +13 -11
  117. package/dist/forms.css +0 -225
  118. package/dist/hero.css +0 -23
  119. package/dist/internal/anchor.d.ts +0 -19
  120. package/dist/internal/anchor.js +0 -52
  121. package/dist/primitives.css +0 -200
  122. package/dist/standalone.css +0 -478
@@ -0,0 +1,158 @@
1
+ /* One of a list, picked, and shown beside the list: the behavior under a list with its detail, an inbox, a set of
2
+ settings by section. As a UI SDK primitive the pick is a value with a change, so a page can hold it (the pick in
3
+ the address) or leave it alone.
4
+
5
+ The list is one stop in the Tab order. Up, Down, Home and End walk it, and where the list and what is picked
6
+ are both in view (`follow`, the default) walking picks as it goes, so the pane keeps up with the keyboard.
7
+ Enter or Space picks a row and takes the keyboard into the pane; Escape there brings it back to the row. Where
8
+ only one of the two is in view (`follow` off: a phone), walking only moves along the rows, a press on a row
9
+ picks it and goes to the pane, and Escape or the back part unpicks it and returns to its row.
10
+
11
+ What is drawn after a pick is not there yet when the key is handled, so the keyboard is landed a frame or two
12
+ later, on the pane or on the row it came from. */
13
+ import { createChange, definePrimitive } from '@ui-sdk/core';
14
+ export const pick = definePrimitive({
15
+ name: 'pick',
16
+ options: { keys: 'list', value: 'value', defaultValue: 'value', onValueChange: 'callback', follow: 'boolean' },
17
+ controlled: ['value'],
18
+ state: (options) => ({
19
+ value: (options.value ?? options.defaultValue ?? null),
20
+ /* The row the keyboard was last on, where that is not the picked one. */
21
+ cursor: null,
22
+ }),
23
+ sync: (options) => (options.value === undefined ? {} : { value: options.value }),
24
+ api: (context) => {
25
+ const change = createChange(context);
26
+ const keys = () => context.options().keys ?? [];
27
+ const follows = () => context.options().follow !== false;
28
+ /* The keyboard goes to the pane or to a row once it is drawn. */
29
+ const land = (from, to) => {
30
+ const root = from?.closest('[data-slot="pick"]');
31
+ if (!root)
32
+ return;
33
+ const find = () => to === 'pane'
34
+ ? root.querySelector('[data-slot="pick-pane"]')
35
+ : root.querySelector(`[data-slot="pick-option"][data-key="${CSS.escape(to)}"]`);
36
+ let tries = 0;
37
+ const go = () => {
38
+ const target = find();
39
+ if (target)
40
+ target.focus();
41
+ else if (++tries < 12 && typeof requestAnimationFrame !== 'undefined')
42
+ requestAnimationFrame(go);
43
+ };
44
+ go();
45
+ };
46
+ return {
47
+ keys,
48
+ follows,
49
+ now: () => context.store.get(),
50
+ land,
51
+ /* The row that is the list's one stop in the Tab order: the picked one, else the one last walked to, else
52
+ the first. */
53
+ stop() {
54
+ const { value, cursor } = context.store.get();
55
+ const all = keys();
56
+ if (value !== null && all.includes(value))
57
+ return value;
58
+ if (cursor !== null && all.includes(cursor))
59
+ return cursor;
60
+ return all[0] ?? null;
61
+ },
62
+ walked(key) {
63
+ if (context.store.get().cursor !== key)
64
+ context.store.set({ cursor: key });
65
+ },
66
+ choose(key, reason, event) {
67
+ if (key === context.store.get().value)
68
+ return true;
69
+ return change('value', key, { reason, event });
70
+ },
71
+ /* Where a key takes the keyboard from a row, or nowhere. */
72
+ step(from, key) {
73
+ const all = keys();
74
+ const at = all.indexOf(from);
75
+ const to = { ArrowDown: at + 1, ArrowUp: at - 1, Home: 0, End: all.length - 1 }[key];
76
+ return to === undefined || at < 0 ? undefined : all[Math.min(Math.max(to, 0), all.length - 1)];
77
+ },
78
+ };
79
+ },
80
+ slots: (slot) => ({
81
+ root: slot({
82
+ state: (state, part) => ({ value: state.value, follow: part.api.follows() }),
83
+ attrs: (state) => ({ 'data-picked': state.value === null ? undefined : '' }),
84
+ }),
85
+ list: slot({
86
+ attrs: () => ({ role: 'listbox' }),
87
+ }),
88
+ option: slot({
89
+ props: { value: 'string' },
90
+ state: (state, part) => ({ picked: state.value === part.props.value }),
91
+ attrs: (state, part) => ({
92
+ role: 'option',
93
+ tabindex: part.api.stop() === part.props.value ? '0' : '-1',
94
+ 'data-key': part.props.value,
95
+ 'aria-selected': String(state.value === part.props.value),
96
+ 'data-picked': state.value === part.props.value ? '' : undefined,
97
+ }),
98
+ on: {
99
+ keydown: (event, { api, el, props }) => {
100
+ if (event.target !== el)
101
+ return;
102
+ const to = api.step(props.value, event.key);
103
+ if (to !== undefined) {
104
+ event.preventDefault();
105
+ if (to === props.value)
106
+ return;
107
+ api.walked(to);
108
+ // Where both are seen, walking picks as it goes; where one is, a row is only walked to.
109
+ if (api.follows())
110
+ api.choose(to, 'move-key', event);
111
+ api.land(el, to);
112
+ }
113
+ else if (event.key === 'Enter' || event.key === ' ') {
114
+ event.preventDefault();
115
+ if (api.choose(props.value, 'enter-key', event))
116
+ api.land(el, 'pane');
117
+ }
118
+ },
119
+ focus: (event, { api, el, props }) => {
120
+ if (event.target === el)
121
+ api.walked(props.value);
122
+ },
123
+ click: (event, { api, el, props }) => {
124
+ api.walked(props.value);
125
+ if (api.choose(props.value, 'item-press', event) && !api.follows())
126
+ api.land(el, 'pane');
127
+ },
128
+ },
129
+ }),
130
+ pane: slot({
131
+ state: (state) => ({ value: state.value }),
132
+ attrs: (state) => ({ tabindex: '-1', 'data-empty': state.value === null ? '' : undefined }),
133
+ on: {
134
+ keydown: (event, { api, el }) => {
135
+ const picked = api.now().value;
136
+ if (event.key !== 'Escape' || event.defaultPrevented || picked === null)
137
+ return;
138
+ event.preventDefault();
139
+ // Where only the pane is in view, leaving it is unpicking; where both are, it is going back to the row.
140
+ if (!api.follows() && !api.choose(null, 'escape-key', event))
141
+ return;
142
+ api.land(el, picked);
143
+ },
144
+ },
145
+ }),
146
+ /* The way back to the list, for where only the pane is in view. */
147
+ back: slot({
148
+ attrs: () => ({ type: 'button' }),
149
+ on: {
150
+ click: (event, { api, el }) => {
151
+ const picked = api.now().value;
152
+ if (picked !== null && api.choose(null, 'close-press', event))
153
+ api.land(el, picked);
154
+ },
155
+ },
156
+ }),
157
+ }),
158
+ });
@@ -0,0 +1,152 @@
1
+ /* One position out of several along a line, read by passing over it: the behavior under a chart's crosshair, a
2
+ sparkline's readout and anything else where the reader points at a place and is told what is there. As a UI
3
+ SDK primitive the position is a value with a change, so a page can hold it (two charts reading the same month)
4
+ or leave it alone.
5
+
6
+ The track is one stop in the Tab order and a slider to a screen reader, because that is what it is to a
7
+ keyboard: arrows move along it, Home and End go to its ends, and what is at each position is its value's text,
8
+ said as the position changes. Nothing is set by moving along it. Enter, Space or a press picks the position,
9
+ for a page that opens something from it.
10
+
11
+ A position is read while a pointer is over the track or the keyboard is on it, and none is when neither is.
12
+ The last one read is kept, so the keyboard arrives where the reader left off. */
13
+ import { createChange, definePrimitive } from '@ui-sdk/core';
14
+ export const scrub = definePrimitive({
15
+ name: 'scrub',
16
+ options: {
17
+ count: 'number',
18
+ value: 'value',
19
+ defaultValue: 'value',
20
+ onValueChange: 'callback',
21
+ scale: 'string',
22
+ orientation: 'string',
23
+ text: 'action',
24
+ onPick: 'callback',
25
+ },
26
+ controlled: ['value'],
27
+ state: (options) => ({
28
+ value: (options.value ?? options.defaultValue ?? null),
29
+ last: 0,
30
+ }),
31
+ sync: (options) => (options.value === undefined ? {} : { value: options.value }),
32
+ api: (context) => {
33
+ const change = createChange(context);
34
+ const count = () => Math.max(context.options().count ?? 0, 0);
35
+ const vertical = () => context.options().orientation === 'vertical';
36
+ const set = (to, reason, event) => {
37
+ const held = to === null || count() === 0 ? null : Math.min(Math.max(to, 0), count() - 1);
38
+ if (held === context.store.get().value)
39
+ return false;
40
+ if (held !== null)
41
+ context.store.set({ last: held });
42
+ return change('value', held, { reason, event });
43
+ };
44
+ return {
45
+ count,
46
+ vertical,
47
+ set,
48
+ now: () => context.store.get(),
49
+ text: (index) => context.options().text?.(index),
50
+ /* The position under a pointer. A share of the track's own box, so a zoomed page needs no correcting. */
51
+ under(event, track) {
52
+ const box = track.getBoundingClientRect();
53
+ let share = vertical() ? (event.clientY - box.top) / (box.height || 1) : (event.clientX - box.left) / (box.width || 1);
54
+ if (!vertical() && getComputedStyle(track).direction === 'rtl')
55
+ share = 1 - share;
56
+ share = Math.min(Math.max(share, 0), 1);
57
+ const last = count() - 1;
58
+ return context.options().scale === 'point' ? Math.round(share * last) : Math.min(last, Math.floor(share * count()));
59
+ },
60
+ pick(index, event) {
61
+ if (index !== null)
62
+ context.options().onPick?.(index, event);
63
+ },
64
+ };
65
+ },
66
+ slots: (slot) => ({
67
+ root: slot({
68
+ state: (state) => ({ at: state.value, last: state.last }),
69
+ attrs: (state) => ({ 'data-scrubbing': state.value === null ? undefined : '' }),
70
+ }),
71
+ track: slot({
72
+ attrs: (state, part) => {
73
+ const count = part.api.count();
74
+ const at = Math.min(state.value ?? state.last, Math.max(count - 1, 0));
75
+ return {
76
+ role: 'slider',
77
+ tabindex: count === 0 ? '-1' : '0',
78
+ 'aria-orientation': part.api.vertical() ? 'vertical' : 'horizontal',
79
+ 'aria-valuemin': '0',
80
+ 'aria-valuemax': String(Math.max(count - 1, 0)),
81
+ 'aria-valuenow': String(at),
82
+ 'aria-valuetext': count === 0 ? undefined : part.api.text(at),
83
+ 'data-at': state.value === null ? undefined : String(state.value),
84
+ };
85
+ },
86
+ on: {
87
+ pointermove: (event, { api, el }) => {
88
+ if (el && api.count() > 0)
89
+ api.set(api.under(event, el), 'scrub', event);
90
+ },
91
+ // A finger does not hover: the place it lands is read at once.
92
+ pointerdown: (event, { api, el }) => {
93
+ if (el && api.count() > 0)
94
+ api.set(api.under(event, el), 'scrub', event);
95
+ },
96
+ pointerleave: (event, { api, el }) => {
97
+ // The keyboard's reading outlasts a pointer that only passed over.
98
+ if (!el?.matches(':focus-visible'))
99
+ api.set(null, 'scrub', event);
100
+ },
101
+ focus: (event, { api, el }) => {
102
+ const state = api.now();
103
+ if (state.value === null && el?.matches(':focus-visible'))
104
+ api.set(state.last, 'focus-in', event);
105
+ },
106
+ blur: (event, { api }) => {
107
+ api.set(null, 'focus-out', event);
108
+ },
109
+ click: (event, { api, el }) => {
110
+ if (el && api.count() > 0)
111
+ api.pick(api.under(event, el), event);
112
+ },
113
+ keydown: (event, { api }) => {
114
+ const state = api.now();
115
+ const count = api.count();
116
+ if (count === 0)
117
+ return;
118
+ const at = state.value ?? state.last;
119
+ const back = api.vertical() ? 'ArrowUp' : 'ArrowLeft';
120
+ const on = api.vertical() ? 'ArrowDown' : 'ArrowRight';
121
+ const big = Math.max(1, Math.round(count / 6));
122
+ const to = event.key === back
123
+ ? at - 1
124
+ : event.key === on
125
+ ? at + 1
126
+ : event.key === 'Home'
127
+ ? 0
128
+ : event.key === 'End'
129
+ ? count - 1
130
+ : event.key === 'PageUp'
131
+ ? at - big
132
+ : event.key === 'PageDown'
133
+ ? at + big
134
+ : undefined;
135
+ if (to !== undefined) {
136
+ event.preventDefault();
137
+ // A first arrow on a track nothing is read on reads the place the keyboard arrived at.
138
+ api.set(state.value === null ? at : to, 'move-key', event);
139
+ }
140
+ else if (event.key === 'Escape' && state.value !== null) {
141
+ event.preventDefault();
142
+ api.set(null, 'escape-key', event);
143
+ }
144
+ else if (event.key === 'Enter' || event.key === ' ') {
145
+ event.preventDefault();
146
+ api.pick(at, event);
147
+ }
148
+ },
149
+ },
150
+ }),
151
+ }),
152
+ });
@@ -0,0 +1,170 @@
1
+ /* A list whose order is the reader's to set, as a UI SDK primitive: defined the way UI SDK defines its own, from
2
+ the behaviors it ships (`createReorder`, `createRovingFocus`, `createChange`), so it answers like one. The order
3
+ is a value with a change that can be cancelled or controlled; an item is dragged with a pointer or picked up with
4
+ Space and placed with the arrows; a screen reader hears the pick-up, each move and the drop; and every state is
5
+ an attribute on a part with a `data-slot`. Nothing here draws: Sortable.tsx gives it React parts, and a
6
+ component composes those (the column chooser, a checklist) and dresses them.
7
+
8
+ It has two shapes, by what an item is picked up by. An item that is only its words is the thing itself: a
9
+ listbox of options, each one focusable, Space on it picks it up. An item with controls of its own (a checkbox, a
10
+ link) cannot be an option, so it is a list item with a handle: the handle is the button the keyboard and a
11
+ finger pick it up by, and a mouse still carries it from anywhere that is not one of its controls. */
12
+ import { createChange, createReorder, createRovingFocus, definePrimitive, } from '@ui-sdk/core';
13
+ import { dressCopyOf, zoomOf } from './dress.js';
14
+ const CONTROLS = 'button, input, select, textarea, a, [role="checkbox"], [role="switch"], [role="menu"]';
15
+ export const sortable = definePrimitive({
16
+ name: 'sortable',
17
+ options: {
18
+ value: 'list',
19
+ defaultValue: 'list',
20
+ onValueChange: 'callback',
21
+ orientation: 'string',
22
+ by: 'string',
23
+ preview: 'boolean',
24
+ },
25
+ controlled: ['value'],
26
+ state: (options) => ({
27
+ value: options.value ?? options.defaultValue ?? [],
28
+ moving: null,
29
+ focused: null,
30
+ }),
31
+ sync: (options) => (options.value === undefined ? {} : { value: options.value }),
32
+ api: (context) => {
33
+ const change = createChange(context);
34
+ const orientation = () => context.options().orientation ?? 'vertical';
35
+ const handled = () => context.options().by === 'handle';
36
+ const preview = context.options().preview ?? false;
37
+ const reorder = createReorder(context, {
38
+ slot: 'item',
39
+ key: 'value',
40
+ draft: 'moving',
41
+ set: (value, details) => change('value', value, details),
42
+ orientation,
43
+ preview,
44
+ disabled: (item) => item.props.disabled === true,
45
+ });
46
+ const roving = createRovingFocus(context, {
47
+ slot: handled() ? 'handle' : 'item',
48
+ key: 'focused',
49
+ orientation: () => {
50
+ const way = orientation();
51
+ return way === 'grid' ? 'both' : way;
52
+ },
53
+ });
54
+ /* Core writes where a dragged item belongs as `--drag-x` and `--drag-y`: how far the pointer has gone, less how
55
+ far the item has already been moved by taking a new place in the list. On a zoomed page (mistri zooms its
56
+ root for density) those two are not in the same pixels, the first the screen's and the second the
57
+ stylesheet's, so the item runs ahead of the pointer by the zoom. Only the pointer's part is wrong, and core
58
+ does not say it apart, so it is followed here from the press: `--drag-dx` and `--drag-dy` are how far the
59
+ pointer has gone, and `--drag-ease` what to scale that by to take the excess back. The sheet adds the
60
+ product. On a page that is not zoomed none of it is set. */
61
+ const measure = (item, down) => {
62
+ const zoom = zoomOf(item);
63
+ if (zoom === 1)
64
+ return;
65
+ const page = item.ownerDocument;
66
+ item.style.setProperty('--drag-ease', String(1 / zoom - 1));
67
+ const moved = (event) => {
68
+ item.style.setProperty('--drag-dx', `${event.clientX - down.clientX}px`);
69
+ item.style.setProperty('--drag-dy', `${event.clientY - down.clientY}px`);
70
+ };
71
+ const lifted = () => {
72
+ page.removeEventListener('pointermove', moved, true);
73
+ page.removeEventListener('pointerup', lifted, true);
74
+ page.removeEventListener('pointercancel', lifted, true);
75
+ for (const name of ['--drag-ease', '--drag-dx', '--drag-dy'])
76
+ item.style.removeProperty(name);
77
+ };
78
+ page.addEventListener('pointermove', moved, true);
79
+ page.addEventListener('pointerup', lifted, true);
80
+ page.addEventListener('pointercancel', lifted, true);
81
+ context.onDestroy(lifted);
82
+ };
83
+ return { reorder, roving, orientation, handled, preview, measure };
84
+ },
85
+ slots: (slot) => ({
86
+ root: slot({
87
+ state: (state, part) => ({ order: part.api.reorder.order(state), moving: state.moving?.key ?? null }),
88
+ attrs: (state, part) => ({
89
+ role: part.api.handled() ? 'list' : 'listbox',
90
+ 'aria-roledescription': part.api.handled() ? undefined : 'sortable list',
91
+ 'aria-orientation': !part.api.handled() && part.api.orientation() === 'horizontal' ? 'horizontal' : undefined,
92
+ 'data-orientation': part.api.orientation(),
93
+ 'data-sorting': state.moving ? '' : undefined,
94
+ }),
95
+ }),
96
+ item: slot({
97
+ props: { value: 'string', disabled: 'boolean' },
98
+ state: (state, part) => ({ grabbed: part.api.reorder.moving(state, part.key) }),
99
+ attrs: (state, part) => {
100
+ const grabbed = part.api.reorder.moving(state, part.key);
101
+ const marks = {
102
+ 'data-grabbed': grabbed ? '' : undefined,
103
+ 'data-dragging': part.api.reorder.dragging(state, part.key) ? '' : undefined,
104
+ 'data-disabled': part.props.disabled ? '' : undefined,
105
+ };
106
+ if (part.api.handled())
107
+ return { role: 'listitem', ...marks };
108
+ return {
109
+ role: 'option',
110
+ 'aria-roledescription': 'sortable item',
111
+ 'aria-selected': String(grabbed),
112
+ 'aria-disabled': part.props.disabled ? 'true' : undefined,
113
+ tabindex: part.api.roving.tabIndex(state, part),
114
+ ...marks,
115
+ };
116
+ },
117
+ on: {
118
+ keydown: (event, { el, api, key }) => {
119
+ if (api.handled())
120
+ return;
121
+ if (!api.reorder.keydown(event, key) && el)
122
+ api.roving.keydown(event, el);
123
+ },
124
+ pointerdown: (event, { api, key, el }) => {
125
+ if (api.handled() && (event.pointerType === 'touch' || event.target.closest(CONTROLS)))
126
+ return;
127
+ if (api.preview && el)
128
+ dressCopyOf(el);
129
+ if (el)
130
+ api.measure(el, event);
131
+ api.reorder.pointerdown(event, key);
132
+ },
133
+ },
134
+ bind: (el, part) => {
135
+ const undo = [part.api.reorder.bind(el, part)];
136
+ if (!part.api.handled())
137
+ undo.push(part.api.roving.bind(el, part));
138
+ return () => undo.forEach((each) => each());
139
+ },
140
+ }),
141
+ handle: slot({
142
+ props: { value: { kind: 'string', from: 'item', required: true } },
143
+ state: (state, part) => ({ grabbed: part.api.reorder.moving(state, part.key) }),
144
+ attrs: (state, part) => ({
145
+ type: 'button',
146
+ 'aria-roledescription': 'sort handle',
147
+ 'aria-pressed': String(part.api.reorder.moving(state, part.key)),
148
+ tabindex: part.api.roving.tabIndex(state, part),
149
+ 'data-grabbed': part.api.reorder.moving(state, part.key) ? '' : undefined,
150
+ }),
151
+ on: {
152
+ keydown: (event, { el, api, key }) => {
153
+ if (!api.reorder.keydown(event, key) && el)
154
+ api.roving.keydown(event, el);
155
+ },
156
+ pointerdown: (event, { api, key, el }) => {
157
+ const item = el?.closest('[data-slot="sortable-item"]');
158
+ if (api.preview && item)
159
+ dressCopyOf(item);
160
+ if (item)
161
+ api.measure(item, event);
162
+ api.reorder.pointerdown(event, key);
163
+ // The item around the handle hears the same press; it has been answered here.
164
+ event.stopPropagation();
165
+ },
166
+ },
167
+ bind: (el, part) => part.api.roving.bind(el, part),
168
+ }),
169
+ }),
170
+ });