@fibrae/semi-foundation 0.6.0 → 0.7.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/dist/base/index.d.ts +2 -1
- package/dist/base/index.js +2 -1
- package/dist/base/overlay-session.d.ts +16 -0
- package/dist/base/overlay-session.js +36 -0
- package/dist/components/audio-player/foundation.js +1 -1
- package/dist/components/auto-complete/constants.d.ts +3 -1
- package/dist/components/auto-complete/foundation.d.ts +1 -1
- package/dist/components/auto-complete/foundation.js +15 -16
- package/dist/components/badge/constants.d.ts +3 -1
- package/dist/components/button/constants.d.ts +3 -1
- package/dist/components/card/constants.d.ts +3 -1
- package/dist/components/cascader/constants.d.ts +2 -0
- package/dist/components/cascader/foundation.d.ts +2 -4
- package/dist/components/cascader/foundation.js +4 -1
- package/dist/components/color-picker/foundation.d.ts +2 -0
- package/dist/components/color-picker/foundation.js +5 -0
- package/dist/components/cropper/constants.d.ts +2 -0
- package/dist/components/date-picker/_utils/index.d.ts +1 -2
- package/dist/components/date-picker/_utils/index.js +1 -2
- package/dist/components/date-picker/_utils/is-timestamp.js +1 -1
- package/dist/components/date-picker/_utils/parse-value.js +1 -1
- package/dist/components/date-picker/_utils/picker-type.js +1 -1
- package/dist/components/date-picker/constants.d.ts +2 -0
- package/dist/components/date-picker/foundation.d.ts +3 -4
- package/dist/components/date-picker/foundation.js +8 -3
- package/dist/components/date-picker/input-foundation.d.ts +1 -0
- package/dist/components/date-picker/input-foundation.js +1 -1
- package/dist/components/date-picker/month-foundation.d.ts +1 -1
- package/dist/components/date-picker/month-foundation.js +1 -0
- package/dist/components/date-picker/months-grid-foundation.d.ts +1 -1
- package/dist/components/date-picker/months-grid-foundation.js +1 -1
- package/dist/components/descriptions/constants.d.ts +3 -1
- package/dist/components/dropdown/constants.d.ts +2 -0
- package/dist/components/dropdown/menu-foundation.d.ts +1 -1
- package/dist/components/empty/constants.d.ts +3 -1
- package/dist/components/feedback/constants.d.ts +3 -1
- package/dist/components/highlight/constants.d.ts +3 -1
- package/dist/components/image/constants.d.ts +5 -1
- package/dist/components/image/preview-inner-foundation.js +6 -15
- package/dist/components/input/constants.d.ts +5 -1
- package/dist/components/input-number/constants.d.ts +3 -1
- package/dist/components/modal/constants.d.ts +3 -1
- package/dist/components/modal/modal-content-foundation.d.ts +3 -3
- package/dist/components/modal/modal-content-foundation.js +5 -3
- package/dist/components/modal/modal-foundation.d.ts +0 -2
- package/dist/components/modal/modal-foundation.js +6 -16
- package/dist/components/navigation/constants.d.ts +4 -0
- package/dist/components/overflow-list/constants.d.ts +2 -0
- package/dist/components/pagination/foundation.d.ts +1 -1
- package/dist/components/popconfirm/constants.d.ts +3 -1
- package/dist/components/popover/constants.d.ts +2 -0
- package/dist/components/radio/constants.d.ts +3 -1
- package/dist/components/scroll-list/item-foundation.js +1 -0
- package/dist/components/select/constants.d.ts +2 -0
- package/dist/components/select/foundation.d.ts +1 -4
- package/dist/components/select/foundation.js +31 -56
- package/dist/components/select/select.css +3 -3
- package/dist/components/select/select.scss +8 -3
- package/dist/components/side-sheet/constants.d.ts +2 -0
- package/dist/components/side-sheet/side-sheet-foundation.d.ts +6 -4
- package/dist/components/side-sheet/side-sheet-foundation.js +33 -23
- package/dist/components/slider/constants.d.ts +3 -1
- package/dist/components/slider/foundation.d.ts +7 -7
- package/dist/components/slider/foundation.js +9 -6
- package/dist/components/spin/constants.d.ts +3 -1
- package/dist/components/table/constants.d.ts +2 -0
- package/dist/components/tabs/constants.d.ts +2 -0
- package/dist/components/tabs/foundation.js +19 -60
- package/dist/components/time-picker/combobox-options.js +1 -1
- package/dist/components/time-picker/constants.d.ts +2 -0
- package/dist/components/time-picker/foundation.d.ts +3 -1
- package/dist/components/time-picker/foundation.js +7 -1
- package/dist/components/tooltip/constants.d.ts +2 -0
- package/dist/components/tooltip/foundation.d.ts +13 -15
- package/dist/components/tooltip/foundation.js +54 -15
- package/dist/components/tree/constants.d.ts +2 -0
- package/dist/components/tree/foundation.d.ts +17 -3
- package/dist/components/tree/foundation.js +37 -2
- package/dist/components/tree/shared.d.ts +37 -0
- package/dist/components/tree/shared.js +42 -1
- package/dist/components/tree-select/constants.d.ts +2 -0
- package/dist/components/tree-select/foundation.d.ts +15 -10
- package/dist/components/tree-select/foundation.js +44 -7
- package/dist/components/upload/constants.d.ts +4 -2
- package/dist/components/upload/utils.d.ts +5 -0
- package/dist/components/upload/utils.js +8 -2
- package/dist/components/video-player/foundation.js +1 -1
- package/dist/components/video-player/utils.d.ts +0 -2
- package/dist/components/video-player/utils.js +1 -14
- package/dist/locale/interface.d.ts +2 -0
- package/dist/locale/source/en_US.js +1 -0
- package/dist/locale/source/zh_CN.js +1 -0
- package/dist/utils/a11y.d.ts +9 -0
- package/dist/utils/a11y.js +19 -1
- package/dist/utils/date-fns-extra.d.ts +1 -0
- package/dist/utils/date-fns-extra.js +4 -1
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/index.js +3 -2
- package/dist/utils/media.d.ts +2 -0
- package/dist/utils/media.js +15 -0
- package/package.json +2 -2
- package/dist/components/date-picker/_utils/is-valid-date.d.ts +0 -1
- package/dist/components/date-picker/_utils/is-valid-date.js +0 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import BaseFoundation, { DefaultAdapter } from "../../base/foundation.js";
|
|
2
2
|
import "../../base/index.js";
|
|
3
|
+
import { TreeKeyEvent } from "./shared.js";
|
|
3
4
|
import { KeyMapProps } from "./tree-util.js";
|
|
4
5
|
export interface BasicTreeNodeProps {
|
|
5
6
|
[x: string]: any;
|
|
@@ -180,10 +181,8 @@ export interface BasicTreeProps {
|
|
|
180
181
|
renderDraggingNode?: (nodeInstance: HTMLElement, node: BasicTreeNodeData) => HTMLElement;
|
|
181
182
|
renderFullLabel?: (renderFullLabelProps: BasicRenderFullLabelProps) => any;
|
|
182
183
|
renderLabel?: (label?: any, treeNode?: BasicTreeNodeData) => any;
|
|
183
|
-
searchClassName?: string;
|
|
184
184
|
searchPlaceholder?: string;
|
|
185
185
|
searchRender?: ((searchRenderProps: BasicSearchRenderProps) => any) | false;
|
|
186
|
-
searchStyle?: any;
|
|
187
186
|
showClear?: boolean;
|
|
188
187
|
showFilteredOnly?: boolean;
|
|
189
188
|
showLine?: boolean;
|
|
@@ -226,6 +225,12 @@ export interface BasicTreeInnerData {
|
|
|
226
225
|
dragNodesKeys: Set<string>;
|
|
227
226
|
dragOverNodeKey: string | null;
|
|
228
227
|
dropPosition: number | null;
|
|
228
|
+
/** The row the keyboard or the pointer last moved to; aria-activedescendant follows it while the row is shown */
|
|
229
|
+
keyboardKey: string | null;
|
|
230
|
+
}
|
|
231
|
+
/** The foundation context a host passes: the reading direction, which flips Left and Right */
|
|
232
|
+
export interface TreeContext {
|
|
233
|
+
direction?: 'ltr' | 'rtl';
|
|
229
234
|
}
|
|
230
235
|
export interface BasicExpandedOtherProps {
|
|
231
236
|
expanded: boolean;
|
|
@@ -234,7 +239,7 @@ export interface BasicExpandedOtherProps {
|
|
|
234
239
|
/** The members of a drag event the foundation reads; DOM events and React synthetic events both satisfy it */
|
|
235
240
|
export type TreeDragEvent = Pick<DragEvent, 'dataTransfer' | 'clientY'>;
|
|
236
241
|
/** E is the host's node mouse event (right or double click), which the foundation only passes through */
|
|
237
|
-
export interface TreeAdapter<E = unknown> extends DefaultAdapter<BasicTreeProps, BasicTreeInnerData> {
|
|
242
|
+
export interface TreeAdapter<E = unknown> extends DefaultAdapter<BasicTreeProps, BasicTreeInnerData, TreeContext> {
|
|
238
243
|
notifyExpand: (expandedKeys: string[], { expanded, node }: BasicExpandedOtherProps) => void;
|
|
239
244
|
notifySelect: (selectKey: string, bool: boolean, node: BasicTreeNodeData) => void;
|
|
240
245
|
notifyChange: (value: BasicValue) => void;
|
|
@@ -250,6 +255,8 @@ export interface TreeAdapter<E = unknown> extends DefaultAdapter<BasicTreeProps,
|
|
|
250
255
|
notifyDrop: (props: BasicOnDragProps) => void;
|
|
251
256
|
/** Scrolls the virtualized list to a row of flattenNodes, found by key once the rendered rows catch up with a search */
|
|
252
257
|
scrollToNode: (key: string, align: ScrollAlign) => void;
|
|
258
|
+
/** Scrolls the row a key moved to into view; `index` is its place in flattenNodes */
|
|
259
|
+
revealRow: (index: number, key: string) => void;
|
|
253
260
|
}
|
|
254
261
|
export default class TreeFoundation<E = unknown> extends BaseFoundation<TreeAdapter<E>, BasicTreeProps, BasicTreeInnerData> {
|
|
255
262
|
#private;
|
|
@@ -262,6 +269,8 @@ export default class TreeFoundation<E = unknown> extends BaseFoundation<TreeAdap
|
|
|
262
269
|
/** The state that props imply, given the previous state; null when nothing changed (see `deriveTreeState`) */
|
|
263
270
|
static deriveState(props: BasicTreeProps, prevState: BasicTreeInnerData): Partial<BasicTreeInnerData> | null;
|
|
264
271
|
static getInitialState(props: BasicTreeProps): BasicTreeInnerData;
|
|
272
|
+
/** The row the keys act on: the keyboard row while it is shown, else the first selected row, else the first */
|
|
273
|
+
static getActiveIndex({ flattenNodes, selectedKeys, keyboardKey }: Pick<BasicTreeInnerData, 'flattenNodes' | 'selectedKeys' | 'keyboardKey'>): number;
|
|
265
274
|
destroy(): void;
|
|
266
275
|
/** Writes the state derived from new props back, so handlers read what was rendered */
|
|
267
276
|
syncDerivedState: (derived: Partial<BasicTreeInnerData>) => void;
|
|
@@ -270,6 +279,11 @@ export default class TreeFoundation<E = unknown> extends BaseFoundation<TreeAdap
|
|
|
270
279
|
align?: ScrollAlign;
|
|
271
280
|
}) => void;
|
|
272
281
|
handleInputChange: (sugInput: string) => void;
|
|
282
|
+
/**
|
|
283
|
+
* The keys of an APG tree view on role="tree", acting on the active row; a key on a tabbable control inside a row
|
|
284
|
+
* belongs to that control. Returns whether the key was handled.
|
|
285
|
+
*/
|
|
286
|
+
handleKeyDown: (e: TreeKeyEvent) => boolean;
|
|
273
287
|
handleNodeSelect: (e: unknown, treeNode: BasicTreeNodeProps) => void;
|
|
274
288
|
handleNodeRightClick: (e: E, treeNode: BasicTreeNodeProps) => void;
|
|
275
289
|
handleNodeDoubleClick: (e: E, treeNode: BasicTreeNodeProps) => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import BaseFoundation from "../../base/foundation.js";
|
|
2
|
+
import { Typeahead } from "../../utils/a11y.js";
|
|
2
3
|
import { strings } from "./constants.js";
|
|
3
|
-
import { deriveTreeState, getMultipleChange, getMultipleSelectResult, getSearchState, isTreeNodeLeaf, loadTreeNode } from "./shared.js";
|
|
4
|
+
import { buildRowProps, deriveTreeState, getMultipleChange, getMultipleSelectResult, getSearchState, getTreeActiveIndex, handleTreeKeyDown, isRowControlKey, isTreeNodeLeaf, loadTreeNode } from "./shared.js";
|
|
4
5
|
import { calcDropActualPosition, calcDropRelativePosition, flattenTreeData, getDragNodesKeys, getMotionKeys, getValueOrKey, normalizedArr } from "./tree-util.js";
|
|
5
6
|
import { throttle } from "es-toolkit";
|
|
6
7
|
import { get, pick as pick$1 } from "es-toolkit/compat";
|
|
@@ -13,6 +14,7 @@ var TreeFoundation = class TreeFoundation extends BaseFoundation {
|
|
|
13
14
|
#dragNode = null;
|
|
14
15
|
#dragEnterTimers = /* @__PURE__ */ new Set();
|
|
15
16
|
#autoExpandTimer;
|
|
17
|
+
#typeahead = new Typeahead();
|
|
16
18
|
/**
|
|
17
19
|
* Every prop `deriveState` reads, which it keeps as `prevProps`. They change state during render, so there is no
|
|
18
20
|
* `handlePropsChange`; a prop deriveState starts reading goes on this list too.
|
|
@@ -191,13 +193,19 @@ var TreeFoundation = class TreeFoundation extends BaseFoundation {
|
|
|
191
193
|
dragging: false,
|
|
192
194
|
dragNodesKeys: /* @__PURE__ */ new Set(),
|
|
193
195
|
dragOverNodeKey: null,
|
|
194
|
-
dropPosition: null
|
|
196
|
+
dropPosition: null,
|
|
197
|
+
keyboardKey: null
|
|
195
198
|
};
|
|
196
199
|
return {
|
|
197
200
|
...state,
|
|
198
201
|
...TreeFoundation.deriveState(props, state)
|
|
199
202
|
};
|
|
200
203
|
}
|
|
204
|
+
/** The row the keys act on: the keyboard row while it is shown, else the first selected row, else the first */
|
|
205
|
+
static getActiveIndex({ flattenNodes, selectedKeys, keyboardKey }) {
|
|
206
|
+
const selected = flattenNodes.findIndex((node) => selectedKeys.includes(node.key));
|
|
207
|
+
return getTreeActiveIndex(flattenNodes, keyboardKey, Math.max(selected, 0));
|
|
208
|
+
}
|
|
201
209
|
destroy() {
|
|
202
210
|
super.destroy();
|
|
203
211
|
this.#throttledDragOverUpdate.cancel();
|
|
@@ -216,18 +224,45 @@ var TreeFoundation = class TreeFoundation extends BaseFoundation {
|
|
|
216
224
|
this.adapter.notifySearch(sugInput, [...state.filteredExpandedKeys]);
|
|
217
225
|
this.setState(state);
|
|
218
226
|
};
|
|
227
|
+
/**
|
|
228
|
+
* The keys of an APG tree view on role="tree", acting on the active row; a key on a tabbable control inside a row
|
|
229
|
+
* belongs to that control. Returns whether the key was handled.
|
|
230
|
+
*/
|
|
231
|
+
handleKeyDown = (e) => {
|
|
232
|
+
if (isRowControlKey(e)) return false;
|
|
233
|
+
const state = this.getStates();
|
|
234
|
+
return handleTreeKeyDown(e, {
|
|
235
|
+
rows: state.flattenNodes,
|
|
236
|
+
activeIndex: TreeFoundation.getActiveIndex(state),
|
|
237
|
+
editing: false,
|
|
238
|
+
rtl: this.getContext("direction") === "rtl",
|
|
239
|
+
hasLoadData: Boolean(this.getProp("loadData")),
|
|
240
|
+
rowProps: (row) => buildRowProps(row, state, this.getProps()),
|
|
241
|
+
typeahead: this.#typeahead,
|
|
242
|
+
moveTo: (index, key) => {
|
|
243
|
+
this.setState({ keyboardKey: key });
|
|
244
|
+
this.adapter.revealRow(index, key);
|
|
245
|
+
},
|
|
246
|
+
select: this.handleNodeSelect,
|
|
247
|
+
expand: this.handleNodeExpand
|
|
248
|
+
});
|
|
249
|
+
};
|
|
219
250
|
handleNodeSelect = (e, treeNode) => {
|
|
251
|
+
this.setState({ keyboardKey: treeNode.eventKey });
|
|
220
252
|
if (this.#isDisabled(treeNode)) return;
|
|
221
253
|
if (!this.#isMultiple()) this.#handleSingleSelect(e, treeNode);
|
|
222
254
|
else this.#handleMultipleSelect(e, treeNode);
|
|
223
255
|
};
|
|
224
256
|
handleNodeRightClick = (e, treeNode) => {
|
|
257
|
+
this.setState({ keyboardKey: treeNode.eventKey });
|
|
225
258
|
this.adapter.notifyRightClick(e, treeNode.data);
|
|
226
259
|
};
|
|
227
260
|
handleNodeDoubleClick = (e, treeNode) => {
|
|
261
|
+
this.setState({ keyboardKey: treeNode.eventKey });
|
|
228
262
|
this.adapter.notifyDoubleClick(e, treeNode.data);
|
|
229
263
|
};
|
|
230
264
|
handleNodeExpand = (_e, treeNode) => {
|
|
265
|
+
this.setState({ keyboardKey: treeNode.eventKey });
|
|
231
266
|
const { loadData } = this.getProps();
|
|
232
267
|
if (!loadData && (!treeNode.children || !treeNode.children.length)) return;
|
|
233
268
|
if (isTreeNodeLeaf(treeNode, loadData)) return;
|
|
@@ -94,6 +94,43 @@ export declare function getTreeKeyboardAction<T extends BasicFlattenNode>(event:
|
|
|
94
94
|
isLeaf: (row: T) => boolean;
|
|
95
95
|
rtl: boolean;
|
|
96
96
|
}, typeahead: Typeahead): TreeKeyboardAction | null;
|
|
97
|
+
/** The row the keys act on: the one the keyboard or the pointer moved to while it is shown, else `defaultIndex` (-1 for none) */
|
|
98
|
+
export declare function getTreeActiveIndex(rows: BasicFlattenNode[], keyboardKey: string | null, defaultIndex: number): number;
|
|
99
|
+
/** The members of a key event the tree keys read; DOM events and React synthetic events both satisfy it */
|
|
100
|
+
export type TreeKeyEvent = Pick<KeyboardEvent, 'key' | 'ctrlKey' | 'metaKey' | 'altKey' | 'preventDefault' | 'target' | 'currentTarget'>;
|
|
101
|
+
export interface TreeKeyDownOptions<E, T extends BasicFlattenNode, R> {
|
|
102
|
+
rows: T[];
|
|
103
|
+
activeIndex: number;
|
|
104
|
+
/** The key goes to a text field (a combobox's search input): only Up, Down and Enter act on the tree */
|
|
105
|
+
editing: boolean;
|
|
106
|
+
rtl: boolean;
|
|
107
|
+
hasLoadData: boolean;
|
|
108
|
+
/** The props a row renders with, null for a row with nothing to act on */
|
|
109
|
+
rowProps: (row: T) => R | null;
|
|
110
|
+
/** One per tree, since the typed string belongs to that tree */
|
|
111
|
+
typeahead: Typeahead;
|
|
112
|
+
moveTo: (index: number, key: string) => void;
|
|
113
|
+
/** Enter, and Space outside a text field: selects, or checks in a multiple tree */
|
|
114
|
+
select: (event: E, row: R) => void;
|
|
115
|
+
expand: (event: E, row: R) => void;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The keys of an APG tree view on its active row, which aria-activedescendant points at while focus stays on the tree
|
|
119
|
+
* or the combobox (see `getTreeKeyboardAction`). Returns whether the key was handled; a handled key is prevented.
|
|
120
|
+
*/
|
|
121
|
+
export declare function handleTreeKeyDown<E extends TreeKeyEvent, T extends BasicFlattenNode, R extends Pick<BasicTreeNodeProps, 'expanded' | 'isLeaf' | 'children' | 'loaded'>>(event: E, { rows, activeIndex, editing, rtl, hasLoadData, rowProps, typeahead, moveTo, select, expand }: TreeKeyDownOptions<E, T, R>): boolean;
|
|
122
|
+
/** Whether a key on the tree comes from a tabbable control inside a row, which handles its own keys */
|
|
123
|
+
export declare function isRowControlKey({ target, currentTarget }: Pick<Event, 'target' | 'currentTarget'>): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Focus arriving in a tree that keeps it on itself. A click focuses the tabindex=-1 element it lands on (the virtual
|
|
126
|
+
* scroller, a row's checkbox), so the tree takes focus back and aria-activedescendant and the row's focus ring keep
|
|
127
|
+
* working. Keyboard focus on the tree calls `reveal`, since a virtual list may not have rendered the active row;
|
|
128
|
+
* pointer focus does not, because scrolling back to the stale active row would unmount the clicked row.
|
|
129
|
+
*/
|
|
130
|
+
export declare function handleTreeFocusIn({ target, currentTarget: tree }: {
|
|
131
|
+
target: EventTarget | null;
|
|
132
|
+
currentTarget: HTMLElement;
|
|
133
|
+
}, reveal: () => void): void;
|
|
97
134
|
/**
|
|
98
135
|
* The node for a selected key missing from treeData: found in the object value (onChangeWithObject), else built from
|
|
99
136
|
* the key. The label goes under keyMaps.label, then TreeSelect's treeNodeLabelProp, then 'label'.
|
|
@@ -231,6 +231,47 @@ function getTreeKeyboardAction(event, rows, activeIndex, editing, { isRow, isExp
|
|
|
231
231
|
if (action && action.type !== "move" && !hasRow) return { type: "none" };
|
|
232
232
|
return action;
|
|
233
233
|
}
|
|
234
|
+
/** The row the keys act on: the one the keyboard or the pointer moved to while it is shown, else `defaultIndex` (-1 for none) */
|
|
235
|
+
function getTreeActiveIndex(rows, keyboardKey, defaultIndex) {
|
|
236
|
+
const index = rows.findIndex((row) => row.key === keyboardKey);
|
|
237
|
+
return index === -1 ? defaultIndex : index;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The keys of an APG tree view on its active row, which aria-activedescendant points at while focus stays on the tree
|
|
241
|
+
* or the combobox (see `getTreeKeyboardAction`). Returns whether the key was handled; a handled key is prevented.
|
|
242
|
+
*/
|
|
243
|
+
function handleTreeKeyDown(event, { rows, activeIndex, editing, rtl, hasLoadData, rowProps, typeahead, moveTo, select, expand }) {
|
|
244
|
+
const action = getTreeKeyboardAction(event, rows, activeIndex, editing, {
|
|
245
|
+
isRow: (row) => rowProps(row) !== null,
|
|
246
|
+
isExpanded: (row) => Boolean(rowProps(row)?.expanded),
|
|
247
|
+
isLeaf: (row) => isTreeNodeLeaf(rowProps(row) ?? {}, hasLoadData),
|
|
248
|
+
rtl
|
|
249
|
+
}, typeahead);
|
|
250
|
+
if (!action) return false;
|
|
251
|
+
event.preventDefault();
|
|
252
|
+
const row = rows[activeIndex] ? rowProps(rows[activeIndex]) : null;
|
|
253
|
+
if (action.type === "move") moveTo(action.index, rows[action.index].key);
|
|
254
|
+
else if (row && action.type === "select") select(event, row);
|
|
255
|
+
else if (row && action.type !== "none") expand(event, row);
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
/** Whether a key on the tree comes from a tabbable control inside a row, which handles its own keys */
|
|
259
|
+
function isRowControlKey({ target, currentTarget }) {
|
|
260
|
+
return target !== currentTarget && (target instanceof HTMLElement || target instanceof SVGElement) && target.tabIndex >= 0;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Focus arriving in a tree that keeps it on itself. A click focuses the tabindex=-1 element it lands on (the virtual
|
|
264
|
+
* scroller, a row's checkbox), so the tree takes focus back and aria-activedescendant and the row's focus ring keep
|
|
265
|
+
* working. Keyboard focus on the tree calls `reveal`, since a virtual list may not have rendered the active row;
|
|
266
|
+
* pointer focus does not, because scrolling back to the stale active row would unmount the clicked row.
|
|
267
|
+
*/
|
|
268
|
+
function handleTreeFocusIn({ target, currentTarget: tree }, reveal) {
|
|
269
|
+
if (target !== tree) {
|
|
270
|
+
if ((target instanceof HTMLElement || target instanceof SVGElement) && target.tabIndex < 0) tree.focus({ preventScroll: true });
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (tree.matches(":focus-visible")) reveal();
|
|
274
|
+
}
|
|
234
275
|
/**
|
|
235
276
|
* The node for a selected key missing from treeData: found in the object value (onChangeWithObject), else built from
|
|
236
277
|
* the key. The label goes under keyMaps.label, then TreeSelect's treeNodeLabelProp, then 'label'.
|
|
@@ -562,4 +603,4 @@ function getMultipleSelectResult({ checked, eventKey }, { disableStrictly, check
|
|
|
562
603
|
}
|
|
563
604
|
return null;
|
|
564
605
|
}
|
|
565
|
-
export { buildRowProps, calcCheckedStatus, calcRelatedCheckedKeys, deriveExpandedKeys, deriveSearchingState, deriveTreeState, getCheckedState, getClearedSelection, getDataForKeyNotInKeyEntities, getMultipleChange, getMultipleSelectResult, getNodeData, getSearchState, getTransitionNodes, getTreeKeyAction, getTreeKeyboardAction, getTreeLabelClassMap, getTreeNodeProps, getTreeRowAria, getTreeRowClassMap, isTreeNodeLeaf, loadTreeNode, nodeId, sameKeys };
|
|
606
|
+
export { buildRowProps, calcCheckedStatus, calcRelatedCheckedKeys, deriveExpandedKeys, deriveSearchingState, deriveTreeState, getCheckedState, getClearedSelection, getDataForKeyNotInKeyEntities, getMultipleChange, getMultipleSelectResult, getNodeData, getSearchState, getTransitionNodes, getTreeActiveIndex, getTreeKeyAction, getTreeKeyboardAction, getTreeLabelClassMap, getTreeNodeProps, getTreeRowAria, getTreeRowClassMap, handleTreeFocusIn, handleTreeKeyDown, isRowControlKey, isTreeNodeLeaf, loadTreeNode, nodeId, sameKeys };
|
|
@@ -3,6 +3,8 @@ export declare const cssClasses: {
|
|
|
3
3
|
PREFIX_TREE: string;
|
|
4
4
|
PREFIX_OPTION: string;
|
|
5
5
|
};
|
|
6
|
+
/** Keys of `classNames` and `styles`; the root element takes `className` and `style` */
|
|
7
|
+
export type TreeSelectPart = 'dropdown' | 'optionList';
|
|
6
8
|
export declare const strings: {
|
|
7
9
|
readonly SIZE_SET: readonly ["small", "large", "default"];
|
|
8
10
|
readonly SEARCH_POSITION_DROPDOWN: "dropdown";
|
|
@@ -2,7 +2,8 @@ import BaseFoundation, { DefaultAdapter } from "../../base/foundation.js";
|
|
|
2
2
|
import { ValidateStatus } from "../../base/constants.js";
|
|
3
3
|
import "../../base/index.js";
|
|
4
4
|
import { Size } from "../../utils/type.js";
|
|
5
|
-
import { BasicExpandedOtherProps, BasicTreeInnerData, BasicTreeNodeData, BasicTreeNodeProps, BasicTreeProps } from "../tree/foundation.js";
|
|
5
|
+
import { BasicExpandedOtherProps, BasicTreeInnerData, BasicTreeNodeData, BasicTreeNodeProps, BasicTreeProps, TreeContext } from "../tree/foundation.js";
|
|
6
|
+
import { TreeKeyEvent } from "../tree/shared.js";
|
|
6
7
|
import { strings } from "./constants.js";
|
|
7
8
|
export type BasicRenderSelectedItemInMultiple = (treeNode: BasicTreeNodeData, otherProps: {
|
|
8
9
|
index: number | string;
|
|
@@ -38,13 +39,10 @@ export interface BasicTreeSelectProps extends Pick<BasicTreeProps, 'virtualize'
|
|
|
38
39
|
autoAdjustOverflow?: boolean;
|
|
39
40
|
clickToHide?: boolean;
|
|
40
41
|
defaultOpen?: boolean;
|
|
41
|
-
dropdownClassName?: string;
|
|
42
42
|
dropdownMatchSelectWidth?: boolean;
|
|
43
|
-
dropdownStyle?: any;
|
|
44
43
|
insetLabel?: any;
|
|
45
44
|
maxTagCount?: number;
|
|
46
45
|
motionExpand?: boolean;
|
|
47
|
-
optionListStyle?: any;
|
|
48
46
|
outerBottomSlot?: any;
|
|
49
47
|
outerTopSlot?: any;
|
|
50
48
|
placeholder?: string;
|
|
@@ -74,7 +72,7 @@ export interface BasicTreeSelectProps extends Pick<BasicTreeProps, 'virtualize'
|
|
|
74
72
|
onVisibleChange?: (isVisible: boolean) => void;
|
|
75
73
|
onLoad?: (keys: Set<string>, data: BasicTreeNodeData) => void;
|
|
76
74
|
}
|
|
77
|
-
export interface BasicTreeSelectInnerData extends Pick<BasicTreeInnerData, 'keyEntities' | 'treeData' | 'flattenNodes' | 'cachedFlattenNodes' | 'selectedKeys' | 'checkedKeys' | 'halfCheckedKeys' | 'motionKeys' | 'motionType' | 'expandedKeys' | 'filteredKeys' | 'filteredExpandedKeys' | 'filteredShownKeys' | 'cachedKeyValuePairs' | 'inputValue' | 'disabledKeys' | 'loadedKeys' | 'loadingKeys' | 'realCheckedKeys'> {
|
|
75
|
+
export interface BasicTreeSelectInnerData extends Pick<BasicTreeInnerData, 'keyEntities' | 'treeData' | 'flattenNodes' | 'cachedFlattenNodes' | 'selectedKeys' | 'checkedKeys' | 'halfCheckedKeys' | 'motionKeys' | 'motionType' | 'expandedKeys' | 'filteredKeys' | 'filteredExpandedKeys' | 'filteredShownKeys' | 'cachedKeyValuePairs' | 'inputValue' | 'disabledKeys' | 'loadedKeys' | 'loadingKeys' | 'realCheckedKeys' | 'keyboardKey'> {
|
|
78
76
|
inputTriggerFocus: boolean;
|
|
79
77
|
isOpen: boolean;
|
|
80
78
|
prevProps: BasicTreeSelectProps | null;
|
|
@@ -84,10 +82,9 @@ export interface BasicTreeSelectInnerData extends Pick<BasicTreeInnerData, 'keyE
|
|
|
84
82
|
* E is the host's trigger click or key event, passed on to onFocus and onBlur; focus entering or leaving passes the
|
|
85
83
|
* native FocusEvent, a mousedown outside blurs with the native MouseEvent
|
|
86
84
|
*/
|
|
87
|
-
export interface TreeSelectAdapter<P extends BasicTreeSelectProps = BasicTreeSelectProps, S extends BasicTreeSelectInnerData = BasicTreeSelectInnerData, E = unknown> extends DefaultAdapter<P, S> {
|
|
85
|
+
export interface TreeSelectAdapter<P extends BasicTreeSelectProps = BasicTreeSelectProps, S extends BasicTreeSelectInnerData = BasicTreeSelectInnerData, E = unknown> extends DefaultAdapter<P, S, TreeContext> {
|
|
88
86
|
notifySelect: (selectedKey: string, selected: boolean, selectedNode: BasicTreeNodeData) => void;
|
|
89
87
|
notifySearch: (input: string, filteredExpandedKeys: string[], filteredNodes: BasicTreeNodeData[]) => void;
|
|
90
|
-
/** Called right after `isOpen` is written; a host resets its own view state of the dropdown (the active row) here */
|
|
91
88
|
notifyVisibleChange: (visible: boolean) => void;
|
|
92
89
|
notifyClear: (e: any) => void;
|
|
93
90
|
notifyChange: BasicOnChangeWithBasic;
|
|
@@ -101,6 +98,8 @@ export interface TreeSelectAdapter<P extends BasicTreeSelectProps = BasicTreeSel
|
|
|
101
98
|
/** Focuses the element on the trigger that takes the keyboard: its search input, its tags or the trigger itself */
|
|
102
99
|
focusTrigger: () => void;
|
|
103
100
|
isInTrigger: (node?: EventTarget | null) => boolean;
|
|
101
|
+
/** Scrolls the row a key moved to into view; `index` is its place in flattenNodes, and the list may not be mounted yet */
|
|
102
|
+
revealRow: (index: number, key: string) => void;
|
|
104
103
|
}
|
|
105
104
|
export default class TreeSelectFoundation<P extends BasicTreeSelectProps = BasicTreeSelectProps, S extends BasicTreeSelectInnerData = BasicTreeSelectInnerData, E = unknown> extends BaseFoundation<TreeSelectAdapter<P, S, E>, P, S> {
|
|
106
105
|
#private;
|
|
@@ -113,6 +112,8 @@ export default class TreeSelectFoundation<P extends BasicTreeSelectProps = Basic
|
|
|
113
112
|
/** The state that props imply, given the previous state; null when nothing changed (see `deriveTreeState`) */
|
|
114
113
|
static deriveState(props: BasicTreeSelectProps, prevState: BasicTreeSelectInnerData): Partial<BasicTreeSelectInnerData> | null;
|
|
115
114
|
static getInitialState(props: BasicTreeSelectProps): BasicTreeSelectInnerData;
|
|
115
|
+
/** The row the keys act on, -1 for none: an APG combobox opens without an active option */
|
|
116
|
+
static getActiveIndex({ flattenNodes, keyboardKey }: Pick<BasicTreeSelectInnerData, 'flattenNodes' | 'keyboardKey'>): number;
|
|
116
117
|
/** The keys the trigger shows: the selection, or in multiple mode the checked keys merged as onChange reports them */
|
|
117
118
|
static getTriggerKeys(props: Pick<BasicTreeSelectProps, 'multiple' | 'checkRelation' | 'autoMergeValue' | 'leafOnly'>, { checkedKeys, realCheckedKeys, keyEntities, selectedKeys }: Pick<BasicTreeSelectInnerData, 'selectedKeys' | 'checkedKeys' | 'realCheckedKeys' | 'keyEntities'>): string[];
|
|
118
119
|
static hasValue(props: Pick<BasicTreeSelectProps, 'multiple' | 'checkRelation'>, { selectedKeys, checkedKeys, realCheckedKeys }: Pick<BasicTreeSelectInnerData, 'selectedKeys' | 'checkedKeys' | 'realCheckedKeys'>): boolean;
|
|
@@ -144,10 +145,14 @@ export default class TreeSelectFoundation<P extends BasicTreeSelectProps = Basic
|
|
|
144
145
|
/**
|
|
145
146
|
* Enter toggles the popup like a click; Down and Up open a closed one (APG combobox). Outside a text field (the
|
|
146
147
|
* select-only combobox) Space toggles it like Enter, and Home and End open a closed one: the view moves to the
|
|
147
|
-
* first or the last row
|
|
148
|
-
* view there.
|
|
148
|
+
* first or the last row.
|
|
149
149
|
*/
|
|
150
|
-
handleSelectionKeyDown: (e: E & Pick<KeyboardEvent, "
|
|
150
|
+
handleSelectionKeyDown: (e: E & TreeKeyEvent & Pick<KeyboardEvent, "detail">) => void;
|
|
151
|
+
/**
|
|
152
|
+
* Tree keys of the open popup (APG combobox with a tree popup), acting on the active row while the focus stays on
|
|
153
|
+
* the combobox. In a text field only Up, Down and Enter act on the tree. Returns whether the key was handled.
|
|
154
|
+
*/
|
|
155
|
+
handleRowKeyDown: (e: E & TreeKeyEvent) => boolean;
|
|
151
156
|
handleClear: (e?: E) => void;
|
|
152
157
|
removeTag: (eventKey: BasicTreeNodeData["key"]) => void;
|
|
153
158
|
handleNodeSelect: (e: E, treeNode: BasicTreeNodeProps) => void;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import BaseFoundation from "../../base/foundation.js";
|
|
2
|
-
import { isInnerControlActivation, isTextEditor } from "../../utils/a11y.js";
|
|
2
|
+
import { Typeahead, isBrowserChord, isInnerControlActivation, isTextEditor } from "../../utils/a11y.js";
|
|
3
3
|
import isEnterPress from "../../utils/is-enter-press.js";
|
|
4
4
|
import "../../utils/key-code.js";
|
|
5
|
-
import { calcRelatedCheckedKeys, deriveTreeState, getClearedSelection, getMultipleChange, getMultipleSelectResult, getNodeData, getSearchState, isTreeNodeLeaf, loadTreeNode } from "../tree/shared.js";
|
|
5
|
+
import { buildRowProps, calcRelatedCheckedKeys, deriveTreeState, getClearedSelection, getMultipleChange, getMultipleSelectResult, getNodeData, getSearchState, getTreeActiveIndex, handleTreeKeyDown, isTreeNodeLeaf, loadTreeNode } from "../tree/shared.js";
|
|
6
6
|
import { findAncestorKeys, flattenTreeData, getMotionKeys, getValueOrKey, normalizeKeyList } from "../tree/tree-util.js";
|
|
7
7
|
import { strings } from "./constants.js";
|
|
8
8
|
import { get } from "es-toolkit/compat";
|
|
9
9
|
// src/components/tree-select/foundation.ts
|
|
10
10
|
var TreeSelectFoundation = class TreeSelectFoundation extends BaseFoundation {
|
|
11
11
|
#blurPending = false;
|
|
12
|
+
#typeahead = new Typeahead();
|
|
12
13
|
/**
|
|
13
14
|
* Every prop `deriveState` reads, which it keeps as `prevProps`. They change state during render, so there is no
|
|
14
15
|
* `handlePropsChange`; a prop deriveState starts reading goes on this list too.
|
|
@@ -222,13 +223,18 @@ var TreeSelectFoundation = class TreeSelectFoundation extends BaseFoundation {
|
|
|
222
223
|
prevProps: null,
|
|
223
224
|
cachedKeyValuePairs: {},
|
|
224
225
|
loadedKeys: /* @__PURE__ */ new Set(),
|
|
225
|
-
loadingKeys: /* @__PURE__ */ new Set()
|
|
226
|
+
loadingKeys: /* @__PURE__ */ new Set(),
|
|
227
|
+
keyboardKey: null
|
|
226
228
|
};
|
|
227
229
|
return {
|
|
228
230
|
...state,
|
|
229
231
|
...TreeSelectFoundation.deriveState(props, state)
|
|
230
232
|
};
|
|
231
233
|
}
|
|
234
|
+
/** The row the keys act on, -1 for none: an APG combobox opens without an active option */
|
|
235
|
+
static getActiveIndex({ flattenNodes, keyboardKey }) {
|
|
236
|
+
return getTreeActiveIndex(flattenNodes, keyboardKey, -1);
|
|
237
|
+
}
|
|
232
238
|
/** The keys the trigger shows: the selection, or in multiple mode the checked keys merged as onChange reports them */
|
|
233
239
|
static getTriggerKeys(props, { checkedKeys, realCheckedKeys, keyEntities, selectedKeys }) {
|
|
234
240
|
if (!props.multiple) return selectedKeys;
|
|
@@ -300,7 +306,10 @@ var TreeSelectFoundation = class TreeSelectFoundation extends BaseFoundation {
|
|
|
300
306
|
this.#focusInput();
|
|
301
307
|
};
|
|
302
308
|
close = () => {
|
|
303
|
-
this.setState({
|
|
309
|
+
this.setState({
|
|
310
|
+
isOpen: false,
|
|
311
|
+
keyboardKey: null
|
|
312
|
+
});
|
|
304
313
|
this.adapter.notifyVisibleChange(false);
|
|
305
314
|
if (this.getProp("motionExpand")) this.setState({ motionKeys: /* @__PURE__ */ new Set([]) });
|
|
306
315
|
};
|
|
@@ -321,10 +330,10 @@ var TreeSelectFoundation = class TreeSelectFoundation extends BaseFoundation {
|
|
|
321
330
|
/**
|
|
322
331
|
* Enter toggles the popup like a click; Down and Up open a closed one (APG combobox). Outside a text field (the
|
|
323
332
|
* select-only combobox) Space toggles it like Enter, and Home and End open a closed one: the view moves to the
|
|
324
|
-
* first or the last row
|
|
325
|
-
* view there.
|
|
333
|
+
* first or the last row.
|
|
326
334
|
*/
|
|
327
335
|
handleSelectionKeyDown = (e) => {
|
|
336
|
+
if (isBrowserChord(e)) return;
|
|
328
337
|
const editing = isTextEditor(e.target);
|
|
329
338
|
const isClosed = !this.getState("isOpen");
|
|
330
339
|
const opensOnEdgeKey = isClosed && !editing && (e.key === "Home" || e.key === "End");
|
|
@@ -332,7 +341,30 @@ var TreeSelectFoundation = class TreeSelectFoundation extends BaseFoundation {
|
|
|
332
341
|
e.preventDefault();
|
|
333
342
|
this.handleClick(e);
|
|
334
343
|
}
|
|
335
|
-
|
|
344
|
+
if (opensOnEdgeKey) this.handleRowKeyDown(e);
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* Tree keys of the open popup (APG combobox with a tree popup), acting on the active row while the focus stays on
|
|
348
|
+
* the combobox. In a text field only Up, Down and Enter act on the tree. Returns whether the key was handled.
|
|
349
|
+
*/
|
|
350
|
+
handleRowKeyDown = (e) => {
|
|
351
|
+
const state = this.getStates();
|
|
352
|
+
if (!state.isOpen) return false;
|
|
353
|
+
return handleTreeKeyDown(e, {
|
|
354
|
+
rows: state.flattenNodes,
|
|
355
|
+
activeIndex: TreeSelectFoundation.getActiveIndex(state),
|
|
356
|
+
editing: isTextEditor(e.target),
|
|
357
|
+
rtl: this.getContext("direction") === "rtl",
|
|
358
|
+
hasLoadData: Boolean(this.getProp("loadData")),
|
|
359
|
+
rowProps: (row) => buildRowProps(row, state, this.getProps()),
|
|
360
|
+
typeahead: this.#typeahead,
|
|
361
|
+
moveTo: (index, key) => {
|
|
362
|
+
this.setState({ keyboardKey: key });
|
|
363
|
+
this.adapter.revealRow(index, key);
|
|
364
|
+
},
|
|
365
|
+
select: this.handleNodeSelect,
|
|
366
|
+
expand: this.handleNodeExpand
|
|
367
|
+
});
|
|
336
368
|
};
|
|
337
369
|
handleClear = (e) => {
|
|
338
370
|
const { searchPosition, filterTreeNode } = this.getProps();
|
|
@@ -373,11 +405,13 @@ var TreeSelectFoundation = class TreeSelectFoundation extends BaseFoundation {
|
|
|
373
405
|
this.adapter.notifySelect(eventKey, false, item);
|
|
374
406
|
};
|
|
375
407
|
handleNodeSelect = (e, treeNode) => {
|
|
408
|
+
this.setState({ keyboardKey: treeNode.eventKey });
|
|
376
409
|
if (this.#isDisabled(treeNode)) return;
|
|
377
410
|
if (!this.#isMultiple()) this.#handleSingleSelect(e, treeNode);
|
|
378
411
|
else this.#handleMultipleSelect(e, treeNode);
|
|
379
412
|
};
|
|
380
413
|
handleNodeExpand = (e, treeNode) => {
|
|
414
|
+
this.setState({ keyboardKey: treeNode.eventKey });
|
|
381
415
|
const { loadData, keyMaps } = this.getProps();
|
|
382
416
|
const { inputValue, keyEntities } = this.getStates();
|
|
383
417
|
const isSearching = Boolean(inputValue);
|
|
@@ -426,6 +460,9 @@ var TreeSelectFoundation = class TreeSelectFoundation extends BaseFoundation {
|
|
|
426
460
|
handlePopoverOpen = () => {
|
|
427
461
|
const { filterTreeNode, searchAutoFocus, searchPosition } = this.getProps();
|
|
428
462
|
if (filterTreeNode && searchPosition === strings.SEARCH_POSITION_DROPDOWN && searchAutoFocus) this.#focusInput();
|
|
463
|
+
const state = this.getStates();
|
|
464
|
+
const index = TreeSelectFoundation.getActiveIndex(state);
|
|
465
|
+
if (index !== -1) this.adapter.revealRow(index, state.flattenNodes[index].key);
|
|
429
466
|
};
|
|
430
467
|
handleAfterClose = () => {
|
|
431
468
|
const { filterTreeNode } = this.getProps();
|
|
@@ -11,7 +11,7 @@ export declare const strings: {
|
|
|
11
11
|
FILE_STATUS_WAIT_UPLOAD: string;
|
|
12
12
|
FILE_LIST_PIC: "picture";
|
|
13
13
|
FILE_LIST_DEFAULT: "list";
|
|
14
|
-
LIST_TYPE: ("none" | "
|
|
14
|
+
LIST_TYPE: ("none" | "list" | "picture")[];
|
|
15
15
|
DRAG_AREA_DEFAULT: string;
|
|
16
16
|
DRAG_AREA_LEGAL: string;
|
|
17
17
|
TRIGGER_AUTO: "auto";
|
|
@@ -21,4 +21,6 @@ export declare const strings: {
|
|
|
21
21
|
};
|
|
22
22
|
export declare const numbers: {
|
|
23
23
|
PROGRESS_COEFFICIENT: number;
|
|
24
|
-
};
|
|
24
|
+
};
|
|
25
|
+
/** Keys of `classNames` and `styles`; the root element takes `className` and `style` */
|
|
26
|
+
export type UploadPart = 'item';
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export declare const byteKB = 1024;
|
|
2
2
|
export declare const byteMB = 1048576;
|
|
3
|
+
export declare function isUploadProgressVisible({ percent, status }: {
|
|
4
|
+
percent?: number;
|
|
5
|
+
status?: string;
|
|
6
|
+
}): boolean;
|
|
7
|
+
export declare function isUploadFailed(status?: string): boolean;
|
|
3
8
|
/** The attributes `containsControl` and `containsName` read, which the add area observes to recheck them */
|
|
4
9
|
export declare const addAreaObservedAttributes: string[];
|
|
5
10
|
export declare function containsControl(node: HTMLElement): boolean;
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import FocusTrapHandle from "../../base/focus-handle.js";
|
|
2
2
|
import { handoverFocus } from "../../utils/focus-handover.js";
|
|
3
|
-
import { cssClasses } from "./constants.js";
|
|
3
|
+
import { cssClasses, strings } from "./constants.js";
|
|
4
4
|
// src/components/upload/utils.ts
|
|
5
5
|
const byteKB = 1024;
|
|
6
6
|
const byteMB = 1048576;
|
|
7
|
+
function isUploadProgressVisible({ percent, status }) {
|
|
8
|
+
return percent !== void 0 && percent !== 100 && status === strings.FILE_STATUS_UPLOADING;
|
|
9
|
+
}
|
|
10
|
+
function isUploadFailed(status) {
|
|
11
|
+
return status === strings.FILE_STATUS_UPLOAD_FAIL || status === strings.FILE_STATUS_VALID_FAIL;
|
|
12
|
+
}
|
|
7
13
|
/** The attributes `containsControl` and `containsName` read, which the add area observes to recheck them */
|
|
8
14
|
const addAreaObservedAttributes = [
|
|
9
15
|
"disabled",
|
|
@@ -103,4 +109,4 @@ async function mapFileTree(items) {
|
|
|
103
109
|
for (const result of [...traversals, ...reads]) if (result.status === "rejected") console.error(result.reason);
|
|
104
110
|
return reads.filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
105
111
|
}
|
|
106
|
-
export { ListFocusTracker, addAreaObservedAttributes, byteKB, byteMB, containsControl, containsName, getFileSize, getFocusHandoverTarget, indexOfCard, loopFiles, mapFileTree, removeUnlessPrevented };
|
|
112
|
+
export { ListFocusTracker, addAreaObservedAttributes, byteKB, byteMB, containsControl, containsName, getFileSize, getFocusHandoverTarget, indexOfCard, isUploadFailed, isUploadProgressVisible, loopFiles, mapFileTree, removeUnlessPrevented };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import FocusTrapHandle from "../../base/focus-handle.js";
|
|
2
2
|
import BaseFoundation from "../../base/foundation.js";
|
|
3
3
|
import { formatLocale } from "../../locale/format.js";
|
|
4
|
-
import { ignoreExpectedMediaErrors } from "
|
|
4
|
+
import { ignoreExpectedMediaErrors } from "../../utils/media.js";
|
|
5
5
|
import { clamp, throttle } from "es-toolkit";
|
|
6
6
|
// src/components/video-player/foundation.ts
|
|
7
7
|
var VideoPlayerFoundation = class extends BaseFoundation {
|
|
@@ -7,8 +7,6 @@ export interface TimeTexts {
|
|
|
7
7
|
}
|
|
8
8
|
/** The spoken form of a time, since a screen reader reads "1:05" as a ratio rather than a duration. */
|
|
9
9
|
export declare function formatTimeText(time: number, texts: TimeTexts): string;
|
|
10
|
-
/** Drops the rejections a media request is expected to meet in normal use; any other rejection stays a rejection. */
|
|
11
|
-
export declare function ignoreExpectedMediaErrors(request: Promise<unknown>): Promise<void>;
|
|
12
10
|
/**
|
|
13
11
|
* Where a pointer is along a slider track: `offset` from the track's start (the left edge, or the bottom edge when
|
|
14
12
|
* vertical) in px and the `ratio` of the track's `total` length, both clamped to the track: a captured pointer keeps
|
|
@@ -28,19 +28,6 @@ function formatTimeText(time, texts) {
|
|
|
28
28
|
});
|
|
29
29
|
return formatLocale(texts.timeS, { seconds });
|
|
30
30
|
}
|
|
31
|
-
const EXPECTED_MEDIA_ERRORS = /* @__PURE__ */ new Set([
|
|
32
|
-
"AbortError",
|
|
33
|
-
"NotAllowedError",
|
|
34
|
-
"InvalidStateError",
|
|
35
|
-
"NotSupportedError"
|
|
36
|
-
]);
|
|
37
|
-
/** Drops the rejections a media request is expected to meet in normal use; any other rejection stays a rejection. */
|
|
38
|
-
function ignoreExpectedMediaErrors(request) {
|
|
39
|
-
return request.then(() => void 0, (error) => {
|
|
40
|
-
if (error instanceof DOMException && EXPECTED_MEDIA_ERRORS.has(error.name)) return;
|
|
41
|
-
throw error;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
31
|
/**
|
|
45
32
|
* Where a pointer is along a slider track: `offset` from the track's start (the left edge, or the bottom edge when
|
|
46
33
|
* vertical) in px and the `ratio` of the track's `total` length, both clamped to the track: a captured pointer keeps
|
|
@@ -55,4 +42,4 @@ function getPointerRatio(rect, point, vertical) {
|
|
|
55
42
|
ratio: offset / total
|
|
56
43
|
};
|
|
57
44
|
}
|
|
58
|
-
export { formatTime, formatTimeText, getPointerRatio
|
|
45
|
+
export { formatTime, formatTimeText, getPointerRatio };
|
|
@@ -12,6 +12,8 @@ export interface Locale {
|
|
|
12
12
|
/** ISO 4217 code, passed to Intl.NumberFormat by InputNumber */
|
|
13
13
|
currency: string;
|
|
14
14
|
Pagination: {
|
|
15
|
+
/** name of the navigation landmark that wraps the page list */
|
|
16
|
+
label: string;
|
|
15
17
|
pageSize: string;
|
|
16
18
|
total: string;
|
|
17
19
|
jumpTo: string;
|
package/dist/utils/a11y.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
/** The id of the option at `index`, which `aria-activedescendant` points at and `revealOption` finds; `listId` is the host's id for the list */
|
|
2
|
+
export declare function getOptionId(listId: string, index: number): string;
|
|
3
|
+
/**
|
|
4
|
+
* Scrolls the option with `id` inside `root` to the centre of its listbox; a no-op when it is not rendered (virtual
|
|
5
|
+
* list). The listbox is found from the option, not by position, because group titles are siblings of the options.
|
|
6
|
+
*/
|
|
7
|
+
export declare function revealOption(root: HTMLElement | null | undefined, id: string): void;
|
|
1
8
|
export declare function handlePrevent(event: Pick<Event, 'stopPropagation' | 'preventDefault'>): void;
|
|
9
|
+
/** Chords belong to the browser and the system; Alt+Down and Alt+Up still open a popup (APG combobox), and Option+Tab is Safari's Tab to every control */
|
|
10
|
+
export declare function isBrowserChord({ key, ctrlKey, metaKey, altKey }: Pick<KeyboardEvent, 'key'> & Partial<Pick<KeyboardEvent, 'ctrlKey' | 'metaKey' | 'altKey'>>): boolean;
|
|
2
11
|
/**
|
|
3
12
|
* Space-separated ids for aria-labelledby and aria-describedby, undefined when there are none; the caller's ids go
|
|
4
13
|
* first, so the Form's ids are added to them instead of replacing them
|
package/dist/utils/a11y.js
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
|
+
import { centerInScroller } from "./dom.js";
|
|
1
2
|
import { isDev } from "./warning.js";
|
|
2
3
|
// src/utils/a11y.ts
|
|
4
|
+
/** The id of the option at `index`, which `aria-activedescendant` points at and `revealOption` finds; `listId` is the host's id for the list */
|
|
5
|
+
function getOptionId(listId, index) {
|
|
6
|
+
return `${listId}-option-${index}`;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Scrolls the option with `id` inside `root` to the centre of its listbox; a no-op when it is not rendered (virtual
|
|
10
|
+
* list). The listbox is found from the option, not by position, because group titles are siblings of the options.
|
|
11
|
+
*/
|
|
12
|
+
function revealOption(root, id) {
|
|
13
|
+
const option = root?.querySelector(`#${CSS.escape(id)}`);
|
|
14
|
+
const listbox = option?.closest("[role=\"listbox\"]");
|
|
15
|
+
if (option && listbox) centerInScroller(option, listbox);
|
|
16
|
+
}
|
|
3
17
|
function handlePrevent(event) {
|
|
4
18
|
event.stopPropagation();
|
|
5
19
|
event.preventDefault();
|
|
6
20
|
}
|
|
21
|
+
/** Chords belong to the browser and the system; Alt+Down and Alt+Up still open a popup (APG combobox), and Option+Tab is Safari's Tab to every control */
|
|
22
|
+
function isBrowserChord({ key, ctrlKey, metaKey, altKey }) {
|
|
23
|
+
return Boolean(ctrlKey || metaKey || altKey && key !== "ArrowDown" && key !== "ArrowUp" && key !== "Tab");
|
|
24
|
+
}
|
|
7
25
|
/**
|
|
8
26
|
* Space-separated ids for aria-labelledby and aria-describedby, undefined when there are none; the caller's ids go
|
|
9
27
|
* first, so the Form's ids are added to them instead of replacing them
|
|
@@ -179,4 +197,4 @@ function warnIfDialogUnnamed(dialog, component) {
|
|
|
179
197
|
const hasLabelElement = labelledBy?.split(/\s+/).some((id) => root.getElementById(id)?.textContent.trim());
|
|
180
198
|
if (!dialog.getAttribute("aria-label")?.trim() && !hasLabelElement) console.warn(`Warning: [Semi ${component}] the dialog has no accessible name. Pass \`title\`, \`aria-label\` or \`aria-labelledby\`.`);
|
|
181
199
|
}
|
|
182
|
-
export { Typeahead, crossesFocusBoundary, getEnabledStepIndex, getListTargetIndex, handlePrevent, isAriaKey, isInnerControl, isInnerControlActivation, isInnerControlKey, isNativeInputKey, isTextEditor, joinIds, namedRole, setFocusToFirstItem, setFocusToItem, setFocusToLastItem, stopButtonActivationKeys, warnIfDialogUnnamed };
|
|
200
|
+
export { Typeahead, crossesFocusBoundary, getEnabledStepIndex, getListTargetIndex, getOptionId, handlePrevent, isAriaKey, isBrowserChord, isInnerControl, isInnerControlActivation, isInnerControlKey, isNativeInputKey, isTextEditor, joinIds, namedRole, revealOption, setFocusToFirstItem, setFocusToItem, setFocusToLastItem, stopButtonActivationKeys, warnIfDialogUnnamed };
|