@fibrae/semi-foundation 0.8.0 → 0.9.1
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/components/anchor/foundation.js +6 -4
- package/dist/components/calendar/event-util.js +1 -1
- package/dist/components/calendar/foundation.js +4 -4
- package/dist/components/carousel/foundation.js +1 -1
- package/dist/components/cascader/foundation.d.ts +6 -2
- package/dist/components/cascader/foundation.js +61 -7
- 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/dropdown/dropdown.css +1 -0
- package/dist/components/dropdown/menu-foundation.d.ts +1 -1
- package/dist/components/form/form.css +18 -1
- package/dist/components/form/form.scss +22 -1
- package/dist/components/form/json-schema.d.ts +44 -1
- package/dist/components/form/rules.js +1 -1
- package/dist/components/form/variables.scss +1 -1
- package/dist/components/image/preview-image-foundation.js +1 -1
- package/dist/components/image/preview-inner-foundation.js +2 -4
- package/dist/components/input-number/foundation.js +2 -2
- package/dist/components/json-viewer/foundation.js +1 -1
- package/dist/components/navigation/foundation.js +6 -8
- package/dist/components/pagination/foundation.d.ts +1 -1
- package/dist/components/popover/popover.css +1 -0
- package/dist/components/select/option-foundation.d.ts +2 -1
- package/dist/components/side-sheet/side-sheet-foundation.js +1 -1
- package/dist/components/slider/foundation.d.ts +1 -1
- package/dist/components/table/foundation.js +2 -2
- package/dist/components/tooltip/foundation.d.ts +2 -0
- package/dist/components/tooltip/foundation.js +102 -15
- package/dist/components/tooltip/position.scss +4 -1
- package/dist/components/tooltip/tooltip.css +1 -0
- package/dist/components/tree/tree-util.js +4 -4
- package/dist/components/upload/foundation.js +1 -1
- package/dist/components/video-player/foundation.js +1 -1
- package/dist/utils/a11y.d.ts +2 -0
- package/dist/utils/a11y.js +5 -1
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/index.js +3 -2
- package/dist/utils/pointer-grace.d.ts +29 -0
- package/dist/utils/pointer-grace.js +109 -0
- package/package.json +2 -2
|
@@ -6,6 +6,7 @@ import scrollIntoView from "scroll-into-view-if-needed";
|
|
|
6
6
|
// src/components/anchor/foundation.ts
|
|
7
7
|
var AnchorFoundation = class AnchorFoundation extends BaseFoundation {
|
|
8
8
|
#container = null;
|
|
9
|
+
#scrollController = null;
|
|
9
10
|
#slideBarTop = null;
|
|
10
11
|
#activeFromScroll = false;
|
|
11
12
|
#throttledScroll = throttle(() => this.handleScroll(), 100);
|
|
@@ -19,12 +20,13 @@ var AnchorFoundation = class AnchorFoundation extends BaseFoundation {
|
|
|
19
20
|
#bind() {
|
|
20
21
|
const container = this.#getContainer();
|
|
21
22
|
this.#container = container;
|
|
22
|
-
|
|
23
|
-
container.addEventListener("scroll", this.#
|
|
23
|
+
this.#scrollController = new AbortController();
|
|
24
|
+
container.addEventListener("scroll", this.#throttledScroll, { signal: this.#scrollController.signal });
|
|
25
|
+
container.addEventListener("scroll", this.#debouncedScrollEnd, { signal: this.#scrollController.signal });
|
|
24
26
|
}
|
|
25
27
|
#unbind() {
|
|
26
|
-
this.#
|
|
27
|
-
this.#
|
|
28
|
+
this.#scrollController?.abort();
|
|
29
|
+
this.#scrollController = null;
|
|
28
30
|
this.#container = null;
|
|
29
31
|
}
|
|
30
32
|
#scrollIntoView(link) {
|
|
@@ -143,7 +143,7 @@ function parseRangeAllDayEvent(event, startDate, rangeStart, rangeEnd, parsed) {
|
|
|
143
143
|
let dateLength;
|
|
144
144
|
const j = differenceInCalendarDays(startDate, rangeStart);
|
|
145
145
|
let i = 0;
|
|
146
|
-
while (
|
|
146
|
+
while (parsed[i] && parsed[i][j]) i++;
|
|
147
147
|
if (!end) dateLength = 0;
|
|
148
148
|
else dateLength = isDateInRange(end, rangeStart, rangeEnd) ? differenceInCalendarDays(end, startDate) : differenceInCalendarDays(rangeEnd, startDate);
|
|
149
149
|
itemInfo.leftPos = round(Number(j) / dateRangeLen);
|
|
@@ -172,12 +172,12 @@ var CalendarFoundation = class CalendarFoundation extends BaseFoundation {
|
|
|
172
172
|
}, CalendarFoundation.getTodayRefreshDelay());
|
|
173
173
|
};
|
|
174
174
|
arm();
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
const controller = new AbortController();
|
|
176
|
+
document.addEventListener("visibilitychange", onChange, { signal: controller.signal });
|
|
177
|
+
window.addEventListener("focus", onChange, { signal: controller.signal });
|
|
177
178
|
return () => {
|
|
178
179
|
clearTimeout(timer);
|
|
179
|
-
|
|
180
|
-
window.removeEventListener("focus", onChange);
|
|
180
|
+
controller.abort();
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
183
|
static getItemLimit(cellHeight) {
|
|
@@ -44,7 +44,7 @@ var CarouselFoundation = class CarouselFoundation extends BaseFoundation {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
#play(interval) {
|
|
47
|
-
|
|
47
|
+
clearInterval(this.#interval);
|
|
48
48
|
this.#interval = setInterval(() => {
|
|
49
49
|
this.next();
|
|
50
50
|
}, interval);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import BaseFoundation, { DefaultAdapter } from "../../base/foundation.js";
|
|
2
2
|
import "../../base/index.js";
|
|
3
|
+
import { Size } from "../../utils/type.js";
|
|
3
4
|
import { strings } from "./constants.js";
|
|
4
5
|
import { KeyMapProps } from "./util.js";
|
|
5
|
-
import { Size } from "../../utils/type.js";
|
|
6
6
|
import { isEqual } from "es-toolkit";
|
|
7
7
|
export interface BasicData {
|
|
8
8
|
data: BasicCascaderData;
|
|
@@ -179,6 +179,8 @@ export interface CascaderAdapter<E = unknown, LE = unknown> extends DefaultAdapt
|
|
|
179
179
|
notifyOnExceed: (data: BasicEntity[]) => void;
|
|
180
180
|
/** `index` is the option's place in its column or in the search results */
|
|
181
181
|
scrollToOption: (key: string, index: number) => void;
|
|
182
|
+
/** Viewport rect of the option column at `index`, 0 for the top level; null while it is not rendered */
|
|
183
|
+
getColumnRect: (index: number) => DOMRect | null;
|
|
182
184
|
}
|
|
183
185
|
type MultipleView = Pick<BasicCascaderInnerData, 'keyEntities' | 'checkedKeys' | 'halfCheckedKeys' | 'resolvedCheckedKeys' | 'disabledKeys'>;
|
|
184
186
|
interface TreeItemState {
|
|
@@ -235,6 +237,7 @@ export default class CascaderFoundation<E = unknown, LE = unknown> extends BaseF
|
|
|
235
237
|
/** `keyboardKey` while its option is shown; hover or a click elsewhere can close its column */
|
|
236
238
|
static getKeyboardKey({ keyboardKey, keyEntities, activeKeys, isSearching, filteredKeys }: BasicCascaderInnerData): string | null;
|
|
237
239
|
static getItemPropPath(selectedKey: string, prop: string | unknown[], keyEntities: BasicEntities): any[];
|
|
240
|
+
destroy(): void;
|
|
238
241
|
getStates(): BasicCascaderInnerData;
|
|
239
242
|
getState<K extends keyof BasicCascaderInnerData>(key: K): BasicCascaderInnerData[K];
|
|
240
243
|
handleKeyDown: (e: E & Pick<KeyboardEvent, "key" | "preventDefault" | "target">) => void;
|
|
@@ -277,7 +280,8 @@ export default class CascaderFoundation<E = unknown, LE = unknown> extends BaseF
|
|
|
277
280
|
/** A key that opens the dropdown sets the current option before the list mounts; it is scrolled to once shown */
|
|
278
281
|
handlePopoverOpen: () => void;
|
|
279
282
|
handleItemClick: (e: E, item: BasicEntity | BasicData) => void;
|
|
280
|
-
|
|
283
|
+
/** `e` is the option's mouseenter; its element is read while the event is dispatched */
|
|
284
|
+
handleItemHover: (e: Pick<MouseEvent, "clientX" | "clientY" | "currentTarget">, item: BasicEntity) => void;
|
|
281
285
|
onItemCheckboxClick: (item: BasicEntity | BasicData) => void;
|
|
282
286
|
handleClick: (e: E & Pick<UIEvent, "detail" | "target" | "currentTarget">) => void;
|
|
283
287
|
/**
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import BaseFoundation from "../../base/foundation.js";
|
|
2
|
-
import { calcCheckedStatus, calcRelatedCheckedKeys } from "../tree/shared.js";
|
|
3
|
-
import { calcCheckedKeys, calcDisabledKeys, findAncestorKeys, normalizeKeyList, normalizedArr } from "../tree/tree-util.js";
|
|
4
|
-
import { strings } from "./constants.js";
|
|
5
|
-
import { calcMergeType, convertDataToEntities, filter, getColumns, getKeyByPos, getKeyByValuePath, getKeysByValuePath, getValueOrKey } from "./util.js";
|
|
6
2
|
import { Typeahead, getListTargetIndex, isBrowserChord, isInnerControlActivation, isTextEditor } from "../../utils/a11y.js";
|
|
7
3
|
import isEnterPress from "../../utils/is-enter-press.js";
|
|
8
4
|
import isObject from "../../utils/is-object.js";
|
|
9
5
|
import "../../utils/key-code.js";
|
|
6
|
+
import { trackPointerGrace } from "../../utils/pointer-grace.js";
|
|
7
|
+
import { calcCheckedStatus, calcRelatedCheckedKeys } from "../tree/shared.js";
|
|
8
|
+
import { calcCheckedKeys, calcDisabledKeys, findAncestorKeys, normalizeKeyList, normalizedArr } from "../tree/tree-util.js";
|
|
9
|
+
import { strings } from "./constants.js";
|
|
10
|
+
import { calcMergeType, convertDataToEntities, filter, getColumns, getKeyByPos, getKeyByValuePath, getKeysByValuePath, getValueOrKey } from "./util.js";
|
|
10
11
|
import { isEqual } from "es-toolkit";
|
|
11
12
|
// src/components/cascader/foundation.ts
|
|
12
13
|
const keyEntitiesCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -22,6 +23,7 @@ const DERIVED_STATE_KEYS = /* @__PURE__ */ new Set([
|
|
|
22
23
|
var CascaderFoundation = class CascaderFoundation extends BaseFoundation {
|
|
23
24
|
static #missingEntities = /* @__PURE__ */ new WeakSet();
|
|
24
25
|
#blurPending = false;
|
|
26
|
+
#hoverGrace = null;
|
|
25
27
|
#typeahead = new Typeahead();
|
|
26
28
|
static propKeys = [
|
|
27
29
|
"treeData",
|
|
@@ -301,6 +303,41 @@ var CascaderFoundation = class CascaderFoundation extends BaseFoundation {
|
|
|
301
303
|
if (isShow || focusInside) this.focus();
|
|
302
304
|
});
|
|
303
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* An option hovered while another option of its column has the next column open: a pointer heading for that column
|
|
308
|
+
* switches nothing, and the option hovered last switches once the grace fails with the pointer still on it.
|
|
309
|
+
* Returns whether a grace started.
|
|
310
|
+
*/
|
|
311
|
+
#startHoverGrace(exit, pending) {
|
|
312
|
+
const { level, key } = pending.item;
|
|
313
|
+
const active = [...this.getState("activeKeys")][level];
|
|
314
|
+
const column = active && active !== key ? this.adapter.getColumnRect(level + 1) : null;
|
|
315
|
+
if (!column || typeof exit.x !== "number") return false;
|
|
316
|
+
const from = {
|
|
317
|
+
left: exit.x,
|
|
318
|
+
right: exit.x,
|
|
319
|
+
top: exit.y,
|
|
320
|
+
bottom: exit.y
|
|
321
|
+
};
|
|
322
|
+
const cancel = trackPointerGrace(exit, from, column, (reached, last) => this.#finishHoverGrace(reached, last));
|
|
323
|
+
if (!cancel) return false;
|
|
324
|
+
this.#hoverGrace = {
|
|
325
|
+
level,
|
|
326
|
+
cancel,
|
|
327
|
+
pending
|
|
328
|
+
};
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
#finishHoverGrace(reached, last) {
|
|
332
|
+
const { item, element } = this.#hoverGrace.pending;
|
|
333
|
+
this.#hoverGrace = null;
|
|
334
|
+
const rect = element?.isConnected ? element.getBoundingClientRect() : null;
|
|
335
|
+
if (!reached && rect && this.getState("isOpen") && last.x >= rect.left && last.x <= rect.right && last.y >= rect.top && last.y <= rect.bottom) this.#handleShowNextByHover(item);
|
|
336
|
+
}
|
|
337
|
+
#cancelHoverGrace() {
|
|
338
|
+
this.#hoverGrace?.cancel();
|
|
339
|
+
this.#hoverGrace = null;
|
|
340
|
+
}
|
|
304
341
|
#handleShowNextByHover(item) {
|
|
305
342
|
const { keyEntities } = this.getStates();
|
|
306
343
|
const { data, key } = item;
|
|
@@ -593,7 +630,7 @@ var CascaderFoundation = class CascaderFoundation extends BaseFoundation {
|
|
|
593
630
|
}
|
|
594
631
|
static getRenderData(props, state) {
|
|
595
632
|
const { keyEntities, isSearching } = state;
|
|
596
|
-
if (isSearching &&
|
|
633
|
+
if (isSearching && props.filterTreeNode) return CascaderFoundation.#getFilteredData(props, state);
|
|
597
634
|
return Object.values(keyEntities).filter((item) => item.parentKey === null && !CascaderFoundation.#missingEntities.has(item)).sort((a, b) => a.ind - b.ind);
|
|
598
635
|
}
|
|
599
636
|
static isBranch(data, loadData) {
|
|
@@ -637,6 +674,9 @@ var CascaderFoundation = class CascaderFoundation extends BaseFoundation {
|
|
|
637
674
|
}
|
|
638
675
|
return path;
|
|
639
676
|
}
|
|
677
|
+
destroy() {
|
|
678
|
+
this.#cancelHoverGrace();
|
|
679
|
+
}
|
|
640
680
|
getStates() {
|
|
641
681
|
const state = super.getStates();
|
|
642
682
|
if (!this.getProp("multiple")) return state;
|
|
@@ -783,11 +823,25 @@ var CascaderFoundation = class CascaderFoundation extends BaseFoundation {
|
|
|
783
823
|
};
|
|
784
824
|
handleItemClick = (e, item) => {
|
|
785
825
|
if (this.#isDisabled()) return;
|
|
826
|
+
this.#cancelHoverGrace();
|
|
786
827
|
this.#handleSingleSelect(e, item);
|
|
787
828
|
};
|
|
788
|
-
|
|
829
|
+
/** `e` is the option's mouseenter; its element is read while the event is dispatched */
|
|
830
|
+
handleItemHover = (e, item) => {
|
|
789
831
|
if (this.#isDisabled()) return;
|
|
790
|
-
|
|
832
|
+
const pending = {
|
|
833
|
+
item,
|
|
834
|
+
element: e.currentTarget instanceof Element ? e.currentTarget : null
|
|
835
|
+
};
|
|
836
|
+
if (this.#hoverGrace?.level === item.level) {
|
|
837
|
+
this.#hoverGrace.pending = pending;
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
this.#cancelHoverGrace();
|
|
841
|
+
if (!this.#startHoverGrace({
|
|
842
|
+
x: e.clientX,
|
|
843
|
+
y: e.clientY
|
|
844
|
+
}, pending)) this.#handleShowNextByHover(item);
|
|
791
845
|
};
|
|
792
846
|
onItemCheckboxClick = (item) => {
|
|
793
847
|
if (this.#isDisabled()) return;
|
|
@@ -113,7 +113,7 @@ export default class MonthsGridFoundation extends BaseFoundation<MonthsGridAdapt
|
|
|
113
113
|
static getYAMOpenType(state: Pick<MonthsGridFoundationState, 'monthLeft' | 'monthRight'>): "none" | "left" | "right" | "both";
|
|
114
114
|
static isYearOrTime(panel: PanelState): boolean;
|
|
115
115
|
/** The `x-open-type` of a panel: what it shows in place of, or beside, its month */
|
|
116
|
-
static getOpenType(panel: PanelState): "
|
|
116
|
+
static getOpenType(panel: PanelState): "time" | "year" | "date";
|
|
117
117
|
static formatMonthText(locale: Pick<Locale['DatePicker'], 'monthText' | 'months'>, month?: Date): string;
|
|
118
118
|
/** The texts of a panel's date and time switch; the date is the picked range endpoint, else the shown date */
|
|
119
119
|
static getSwitchTexts({ rangeEndpoint, showDate, dateFormat, format: formatProp, locale, dateFnsLocale }: {
|
|
@@ -104,7 +104,7 @@ var MonthsGridFoundation = class MonthsGridFoundation extends BaseFoundation {
|
|
|
104
104
|
#updateSelectedFromProps(values) {
|
|
105
105
|
const type = this.getProp("type");
|
|
106
106
|
const { selected, rangeStart, rangeEnd } = this.getStates();
|
|
107
|
-
if (values
|
|
107
|
+
if (values?.length) switch (type) {
|
|
108
108
|
case "date":
|
|
109
109
|
this.#initDatePickerFromValue(values);
|
|
110
110
|
break;
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
animation: semi-dropdown-zoom-in 100ms cubic-bezier(0.215, 0.61, 0.355, 1);
|
|
30
30
|
}
|
|
31
31
|
.semi-dropdown-wrapper:popover-open:not(.semi-dropdown-wrapper-show) {
|
|
32
|
+
pointer-events: none;
|
|
32
33
|
animation: semi-dropdown-zoom-out 100ms cubic-bezier(0.215, 0.61, 0.355, 1) forwards;
|
|
33
34
|
}
|
|
34
35
|
.semi-dropdown-wrapper.semi-dropdown-no-motion:popover-open {
|
|
@@ -5,7 +5,7 @@ export type DropdownSelectionMode = 'single' | 'multiple';
|
|
|
5
5
|
* Role and checked state of a menu item, from the menu's selectionMode (as React Aria Menu) and showTick. Without a
|
|
6
6
|
* selectionMode a tick shows a checked state, so showTick alone makes the items checkboxes.
|
|
7
7
|
*/
|
|
8
|
-
export declare function getItemRole(selectionMode?: DropdownSelectionMode, showTick?: boolean): "
|
|
8
|
+
export declare function getItemRole(selectionMode?: DropdownSelectionMode, showTick?: boolean): "menuitemradio" | "menuitemcheckbox" | "menuitem";
|
|
9
9
|
/**
|
|
10
10
|
* What a Dropdown provides to everything inside its popup, read by the menus there and by a Dropdown whose trigger is
|
|
11
11
|
* one of their items. A framework adapter passes it as the foundation context, with the reading direction added.
|
|
@@ -86,11 +86,14 @@
|
|
|
86
86
|
align-items: center;
|
|
87
87
|
max-width: 100%;
|
|
88
88
|
padding-inline-end: 16px;
|
|
89
|
+
margin-top: 0px;
|
|
90
|
+
margin-bottom: 4px;
|
|
89
91
|
}
|
|
90
92
|
.semi-form-field-label-with-tooltip .semi-form-field-label {
|
|
91
93
|
flex: 0 1 auto;
|
|
92
94
|
min-width: 0;
|
|
93
95
|
padding-inline-end: 4px;
|
|
96
|
+
margin: 0;
|
|
94
97
|
}
|
|
95
98
|
.semi-form-field-label-tooltip {
|
|
96
99
|
padding: 0;
|
|
@@ -108,7 +111,7 @@
|
|
|
108
111
|
display: inline-flex;
|
|
109
112
|
flex-shrink: 0;
|
|
110
113
|
align-items: center;
|
|
111
|
-
font-size:
|
|
114
|
+
font-size: var(--semi-font-size-regular);
|
|
112
115
|
color: var(--semi-color-tertiary);
|
|
113
116
|
}
|
|
114
117
|
.semi-form-field-error-message, .semi-form-field-help-text {
|
|
@@ -153,6 +156,13 @@
|
|
|
153
156
|
margin-inline-end: 0;
|
|
154
157
|
margin-bottom: 0;
|
|
155
158
|
}
|
|
159
|
+
.semi-form-field[x-label-pos=left] .semi-form-field-label-with-tooltip {
|
|
160
|
+
margin-inline-end: 0;
|
|
161
|
+
margin-bottom: 0;
|
|
162
|
+
}
|
|
163
|
+
.semi-form-field[x-label-pos=left] .semi-form-field-label-with-tooltip .semi-form-field-label {
|
|
164
|
+
margin: 0;
|
|
165
|
+
}
|
|
156
166
|
.semi-form-field[x-label-pos=left] .semi-form-field-label-with-extra {
|
|
157
167
|
display: flex;
|
|
158
168
|
align-items: center;
|
|
@@ -225,6 +235,13 @@
|
|
|
225
235
|
margin-inline-end: 0;
|
|
226
236
|
margin-bottom: 0;
|
|
227
237
|
}
|
|
238
|
+
.semi-form-field-group[x-label-pos=left] .semi-form-field-label-with-tooltip {
|
|
239
|
+
margin-inline-end: 0;
|
|
240
|
+
margin-bottom: 0;
|
|
241
|
+
}
|
|
242
|
+
.semi-form-field-group[x-label-pos=left] .semi-form-field-label-with-tooltip .semi-form-field-label {
|
|
243
|
+
margin: 0;
|
|
244
|
+
}
|
|
228
245
|
|
|
229
246
|
.semi-form-section {
|
|
230
247
|
min-inline-size: 0;
|
|
@@ -130,18 +130,23 @@ $rating: #{$prefix}-rating;
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
// The tooltip button sits beside the label element, not in it: a label's content names the control, and a
|
|
133
|
-
// button must not be nested in a label. The width of the label moves to this wrapper to keep columns aligned
|
|
133
|
+
// button must not be nested in a label. The width of the label moves to this wrapper to keep columns aligned, and
|
|
134
|
+
// so do the label's outer margins: align-items centers margin boxes, so a bottom margin left on the label would
|
|
135
|
+
// drop the button below the text's center line.
|
|
134
136
|
&-field-label-with-tooltip {
|
|
135
137
|
display: flex;
|
|
136
138
|
flex-shrink: 0;
|
|
137
139
|
align-items: center;
|
|
138
140
|
max-width: 100%;
|
|
139
141
|
padding-inline-end: $spacing-form_label-paddingRight;
|
|
142
|
+
margin-top: $spacing-form_label-marginTop;
|
|
143
|
+
margin-bottom: $spacing-form_label-marginBottom;
|
|
140
144
|
|
|
141
145
|
.#{$field}-label {
|
|
142
146
|
flex: 0 1 auto;
|
|
143
147
|
min-width: 0;
|
|
144
148
|
padding-inline-end: $spacing-form_label_tooltip-marginLeft;
|
|
149
|
+
margin: 0;
|
|
145
150
|
}
|
|
146
151
|
}
|
|
147
152
|
|
|
@@ -202,6 +207,14 @@ $rating: #{$prefix}-rating;
|
|
|
202
207
|
margin-inline-end: $spacing-form_label_posLeft-marginRight;
|
|
203
208
|
margin-bottom: $spacing-form_label_posLeft-marginBottom;
|
|
204
209
|
}
|
|
210
|
+
.#{$field}-label-with-tooltip {
|
|
211
|
+
margin-inline-end: $spacing-form_label_posLeft-marginRight;
|
|
212
|
+
margin-bottom: $spacing-form_label_posLeft-marginBottom;
|
|
213
|
+
|
|
214
|
+
.#{$field}-label {
|
|
215
|
+
margin: 0;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
205
218
|
.#{$field}-label-with-extra {
|
|
206
219
|
display: flex;
|
|
207
220
|
align-items: center;
|
|
@@ -287,6 +300,14 @@ $rating: #{$prefix}-rating;
|
|
|
287
300
|
margin-inline-end: $spacing-form_label_posLeft-marginRight;
|
|
288
301
|
margin-bottom: $spacing-form_label_posLeft-marginBottom;
|
|
289
302
|
}
|
|
303
|
+
.#{$field}-label-with-tooltip {
|
|
304
|
+
margin-inline-end: $spacing-form_label_posLeft-marginRight;
|
|
305
|
+
margin-bottom: $spacing-form_label_posLeft-marginBottom;
|
|
306
|
+
|
|
307
|
+
.#{$field}-label {
|
|
308
|
+
margin: 0;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
290
311
|
}
|
|
291
312
|
}
|
|
292
313
|
|
|
@@ -62,7 +62,50 @@ export declare function arrayState(node: SchemaFieldNode, count: number): {
|
|
|
62
62
|
canRemove: boolean;
|
|
63
63
|
};
|
|
64
64
|
/** The props semiRenderers gives the Form control of a leaf node, by kind */
|
|
65
|
-
export declare function controlProps(node: SchemaFieldNode):
|
|
65
|
+
export declare function controlProps(node: SchemaFieldNode): {
|
|
66
|
+
maxLength: number;
|
|
67
|
+
maxCount?: undefined;
|
|
68
|
+
max?: undefined;
|
|
69
|
+
min?: undefined;
|
|
70
|
+
precision?: undefined;
|
|
71
|
+
multiple?: undefined;
|
|
72
|
+
optionList?: undefined;
|
|
73
|
+
} | {
|
|
74
|
+
maxCount: number;
|
|
75
|
+
maxLength?: undefined;
|
|
76
|
+
max?: undefined;
|
|
77
|
+
min?: undefined;
|
|
78
|
+
precision?: undefined;
|
|
79
|
+
multiple?: undefined;
|
|
80
|
+
optionList?: undefined;
|
|
81
|
+
} | {
|
|
82
|
+
max: number;
|
|
83
|
+
min: number;
|
|
84
|
+
precision: number;
|
|
85
|
+
maxLength?: undefined;
|
|
86
|
+
maxCount?: undefined;
|
|
87
|
+
multiple?: undefined;
|
|
88
|
+
optionList?: undefined;
|
|
89
|
+
} | {
|
|
90
|
+
multiple: boolean;
|
|
91
|
+
optionList: {
|
|
92
|
+
label: string;
|
|
93
|
+
value: string | number | boolean;
|
|
94
|
+
}[];
|
|
95
|
+
maxLength?: undefined;
|
|
96
|
+
maxCount?: undefined;
|
|
97
|
+
max?: undefined;
|
|
98
|
+
min?: undefined;
|
|
99
|
+
precision?: undefined;
|
|
100
|
+
} | {
|
|
101
|
+
maxLength?: undefined;
|
|
102
|
+
maxCount?: undefined;
|
|
103
|
+
max?: undefined;
|
|
104
|
+
min?: undefined;
|
|
105
|
+
precision?: undefined;
|
|
106
|
+
multiple?: undefined;
|
|
107
|
+
optionList?: undefined;
|
|
108
|
+
};
|
|
66
109
|
export declare const schemaFieldWarnings: {
|
|
67
110
|
noSchema: string;
|
|
68
111
|
noRenderer: (field: string, kind: string) => string;
|
|
@@ -14,7 +14,7 @@ const typeCheckers = {
|
|
|
14
14
|
string: (value) => typeof value === "string",
|
|
15
15
|
number: (value) => typeof value === "number" && !Number.isNaN(value),
|
|
16
16
|
integer: (value) => Number.isInteger(value),
|
|
17
|
-
float: (value) =>
|
|
17
|
+
float: (value) => Number.isFinite(value) && !Number.isInteger(value),
|
|
18
18
|
boolean: (value) => typeof value === "boolean",
|
|
19
19
|
array: (value) => Array.isArray(value),
|
|
20
20
|
object: (value) => typeof value === "object" && value !== null && !Array.isArray(value),
|
|
@@ -34,7 +34,7 @@ $color-form_label_optional-text-default: var(--semi-color-tertiary); // 表单
|
|
|
34
34
|
$color-form_label_extra-text-default: var(--semi-color-tertiary); // 表单项标签图标颜色
|
|
35
35
|
$color-form_label_tooltip-icon-default: var(--semi-color-tertiary); // 表单项标签提示图标颜色
|
|
36
36
|
$spacing-form_label_tooltip-marginLeft: $spacing-extra-tight; // 表单项标签与提示图标的间距
|
|
37
|
-
$width-form_label_tooltip-icon: $
|
|
37
|
+
$width-form_label_tooltip-icon: $font-size-regular; // 表单项标签提示图标大小,与标签文字同大
|
|
38
38
|
$color-form_requiredMark-text-default: var(--semi-color-danger); // 必填标记颜色
|
|
39
39
|
$font-form_requiredMark-fontWeight: $font-weight-bold; // 表单必填标识字重
|
|
40
40
|
|
|
@@ -52,7 +52,7 @@ var PreviewImageFoundation = class extends BaseFoundation {
|
|
|
52
52
|
const { ratio, initialZoom } = this.getProps();
|
|
53
53
|
let _zoom = 1;
|
|
54
54
|
this.#syncInitialZoomFlagWithSrc();
|
|
55
|
-
if (!this.#initialZoomApplied &&
|
|
55
|
+
if (!this.#initialZoomApplied && Number.isFinite(initialZoom) && initialZoom > 0) {
|
|
56
56
|
this.#initialZoomApplied = true;
|
|
57
57
|
return this.#clampZoom(initialZoom);
|
|
58
58
|
}
|
|
@@ -62,10 +62,8 @@ var PreviewInnerFoundation = class PreviewInnerFoundation extends BaseFoundation
|
|
|
62
62
|
if (wrap && (!active || active === document.body)) wrap.focus({ preventScroll: true });
|
|
63
63
|
}
|
|
64
64
|
#clearTimer() {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
this.#timer = null;
|
|
68
|
-
}
|
|
65
|
+
clearTimeout(this.#timer);
|
|
66
|
+
this.#timer = null;
|
|
69
67
|
}
|
|
70
68
|
#onWheel(e) {
|
|
71
69
|
const { zoomStep } = this.getProps();
|
|
@@ -155,7 +155,7 @@ var InputNumberFoundation = class InputNumberFoundation extends BaseFoundation {
|
|
|
155
155
|
const { scientificNotation } = this.getProps();
|
|
156
156
|
if (typeof scientificNotation === "object" && scientificNotation !== null) {
|
|
157
157
|
const t = scientificNotation.threshold;
|
|
158
|
-
return
|
|
158
|
+
return Number.isFinite(t) && t >= 1 ? t : 15;
|
|
159
159
|
}
|
|
160
160
|
return 15;
|
|
161
161
|
}
|
|
@@ -425,7 +425,7 @@ var InputNumberFoundation = class InputNumberFoundation extends BaseFoundation {
|
|
|
425
425
|
}
|
|
426
426
|
const key = isComposing(event) || event.altKey || event.ctrlKey || event.metaKey ? "" : event.key;
|
|
427
427
|
const bound = event.shiftKey ? null : key === "Home" ? this.getProp("min") : key === "End" ? this.getProp("max") : null;
|
|
428
|
-
const jumpsToBound =
|
|
428
|
+
const jumpsToBound = Number.isFinite(bound);
|
|
429
429
|
if ((key === "ArrowUp" || key === "ArrowDown") && !this.#canStep(key === "ArrowUp" ? 1 : -1)) event.preventDefault();
|
|
430
430
|
else if (key === "ArrowUp" || key === "ArrowDown" || jumpsToBound) {
|
|
431
431
|
this.#lastChangeWasStep = true;
|
|
@@ -39,7 +39,7 @@ var JsonViewerFoundation = class extends BaseFoundation {
|
|
|
39
39
|
height
|
|
40
40
|
};
|
|
41
41
|
this.#resetMeasuredHeights ||= rewrap;
|
|
42
|
-
|
|
42
|
+
cancelAnimationFrame(this.#resizeRafId);
|
|
43
43
|
this.#resizeRafId = requestAnimationFrame(() => {
|
|
44
44
|
this.#resizeRafId = null;
|
|
45
45
|
if (this.#resetMeasuredHeights) this.#jsonViewer?.resetMeasuredHeights();
|
|
@@ -31,22 +31,20 @@ var NavigationFoundation = class NavigationFoundation extends BaseFoundation {
|
|
|
31
31
|
}
|
|
32
32
|
static getZeroParentKeys(itemKeysMap = {}, ...itemKeys) {
|
|
33
33
|
const willAddKeys = [];
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (levelZeroParentKey != null) willAddKeys.push(levelZeroParentKey);
|
|
38
|
-
}
|
|
34
|
+
for (const itemKey of itemKeys) if (Array.isArray(itemKeysMap[itemKey])) {
|
|
35
|
+
const levelZeroParentKey = itemKeysMap[itemKey][0];
|
|
36
|
+
if (levelZeroParentKey != null) willAddKeys.push(levelZeroParentKey);
|
|
39
37
|
}
|
|
40
38
|
return willAddKeys;
|
|
41
39
|
}
|
|
42
40
|
static buildItemKeysMap(items = [], keysMap = {}, parentKeys = [], keyPropName = "itemKey") {
|
|
43
|
-
if (Array.isArray(items)
|
|
41
|
+
if (Array.isArray(items)) for (const item of items) if (Array.isArray(item)) NavigationFoundation.buildItemKeysMap(item, keysMap, [...parentKeys], keyPropName);
|
|
44
42
|
else {
|
|
45
43
|
let itemKey;
|
|
46
44
|
if (item && typeof item === "object") itemKey = item[keyPropName];
|
|
47
45
|
if (itemKey != null) {
|
|
48
46
|
keysMap[itemKey] = [...parentKeys];
|
|
49
|
-
if (Array.isArray(item.items)
|
|
47
|
+
if (Array.isArray(item.items)) NavigationFoundation.buildItemKeysMap(item.items, keysMap, [...parentKeys, itemKey], keyPropName);
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
return keysMap;
|
|
@@ -74,7 +72,7 @@ var NavigationFoundation = class NavigationFoundation extends BaseFoundation {
|
|
|
74
72
|
}
|
|
75
73
|
static getShouldOpenKeys(itemKeysMap = {}, selectedKeys = []) {
|
|
76
74
|
const willOpenKeySet = /* @__PURE__ */ new Set();
|
|
77
|
-
if (Array.isArray(selectedKeys)
|
|
75
|
+
if (Array.isArray(selectedKeys)) selectedKeys.forEach((item) => {
|
|
78
76
|
if (item != null) {
|
|
79
77
|
const parentKeys = itemKeysMap[item];
|
|
80
78
|
if (Array.isArray(parentKeys)) parentKeys.forEach((k) => willOpenKeySet.add(k));
|
|
@@ -53,7 +53,7 @@ export default class PaginationFoundation<P extends PaginationBaseProps = Pagina
|
|
|
53
53
|
sizeChangerShown: boolean;
|
|
54
54
|
hidden: boolean;
|
|
55
55
|
quickJumpDisabled: boolean;
|
|
56
|
-
switchPosition: "
|
|
56
|
+
switchPosition: "bottomLeft" | "left" | "right" | "top" | "bottom" | "topLeft" | "topRight" | "leftTop" | "leftBottom" | "rightTop" | "rightBottom" | "bottomRight" | "leftTopOver" | "rightTopOver" | "leftBottomOver" | "rightBottomOver";
|
|
57
57
|
};
|
|
58
58
|
static getDisabled(currentPage: number, total: number, pageSize: number): {
|
|
59
59
|
prevDisabled: boolean;
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
animation: semi-popover-zoom-in 100ms cubic-bezier(0.215, 0.61, 0.355, 1);
|
|
25
25
|
}
|
|
26
26
|
.semi-popover-wrapper:popover-open:not(.semi-popover-wrapper-show) {
|
|
27
|
+
pointer-events: none;
|
|
27
28
|
animation: semi-popover-zoom-out 100ms cubic-bezier(0.215, 0.61, 0.355, 1) forwards;
|
|
28
29
|
}
|
|
29
30
|
.semi-popover-wrapper.semi-popover-no-motion:popover-open {
|
|
@@ -110,7 +110,7 @@ var SideSheetFoundation = class SideSheetFoundation extends BaseFoundation {
|
|
|
110
110
|
focus: dialog,
|
|
111
111
|
preventScroll: true
|
|
112
112
|
});
|
|
113
|
-
warnIfDialogUnnamed(dialog
|
|
113
|
+
warnIfDialogUnnamed(dialog, "SideSheet");
|
|
114
114
|
};
|
|
115
115
|
afterHide = () => {
|
|
116
116
|
if (this.#session.end()) this.#resources.release();
|
|
@@ -95,7 +95,7 @@ export default class SliderFoundation<P extends SliderProps = SliderProps> exten
|
|
|
95
95
|
* `reverse` is the class suffix of a vertical slider drawn from the bottom.
|
|
96
96
|
*/
|
|
97
97
|
static getLayout(props: SliderProps, value: SliderState['currentValue'], { chooseMovePos, isDrag }: Pick<SliderState, 'chooseMovePos' | 'isDrag'>, direction?: string): {
|
|
98
|
-
startProp: "
|
|
98
|
+
startProp: "left" | "right" | "top";
|
|
99
99
|
inputDir: "rtl" | "ltr";
|
|
100
100
|
reverse: string;
|
|
101
101
|
track: {
|
|
@@ -349,11 +349,11 @@ var TableFoundation = class TableFoundation extends BaseFoundation {
|
|
|
349
349
|
if (!(keysSet instanceof Set)) keysSet = new Set(keys);
|
|
350
350
|
const childrenRecordName = this.getProp("childrenRecordName");
|
|
351
351
|
const records = [];
|
|
352
|
-
if (keysSet.size && Array.isArray(dataSource)
|
|
352
|
+
if (keysSet.size && Array.isArray(dataSource)) {
|
|
353
353
|
records.push(...dataSource.filter((data) => keysSet.has(this.getRecordKey(data))));
|
|
354
354
|
if (records.length < keys.length) for (const item of dataSource) {
|
|
355
355
|
const children = get(item, childrenRecordName);
|
|
356
|
-
if (Array.isArray(children)
|
|
356
|
+
if (Array.isArray(children)) records.push(...this.getRecordsByKeys(children, keys, keysSet));
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
return records;
|
|
@@ -54,6 +54,8 @@ export interface TooltipBaseProps {
|
|
|
54
54
|
position?: Position;
|
|
55
55
|
preventScroll?: boolean;
|
|
56
56
|
returnFocusOnClose?: boolean;
|
|
57
|
+
/** The popup's role; undefined means the host's default, 'tooltip' */
|
|
58
|
+
role?: string;
|
|
57
59
|
showArrow?: unknown;
|
|
58
60
|
spacing?: number | {
|
|
59
61
|
x: number;
|
|
@@ -4,6 +4,7 @@ import PopupLifecycle from "../../base/popup-lifecycle.js";
|
|
|
4
4
|
import ReleaseHolder from "../../base/release-holder.js";
|
|
5
5
|
import { isEventInside } from "../../utils/dom.js";
|
|
6
6
|
import { openLayer, popupTriggerSelector } from "../../utils/layer.js";
|
|
7
|
+
import { trackPointerGrace } from "../../utils/pointer-grace.js";
|
|
7
8
|
import warning from "../../utils/warning.js";
|
|
8
9
|
import { adjustPosition } from "./adjust-position.js";
|
|
9
10
|
import { TRIGGER_EVENT_NAMES, numbers, strings } from "./constants.js";
|
|
@@ -29,6 +30,9 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
29
30
|
static #tracking = /* @__PURE__ */ new Set();
|
|
30
31
|
static #pending = /* @__PURE__ */ new Set();
|
|
31
32
|
static #frame = 0;
|
|
33
|
+
static #exclusiveOpen = /* @__PURE__ */ new Set();
|
|
34
|
+
static #exclusiveWaiting = /* @__PURE__ */ new Set();
|
|
35
|
+
static #grace = null;
|
|
32
36
|
#timer;
|
|
33
37
|
#mounted;
|
|
34
38
|
#isClickToHide = false;
|
|
@@ -87,6 +91,17 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
87
91
|
const layouts = batch.map((tooltip) => tooltip.#measure(viewport));
|
|
88
92
|
batch.forEach((tooltip, i) => tooltip.#apply(layouts[i]));
|
|
89
93
|
}
|
|
94
|
+
/** Ends the running grace: a pointer that reached the popup leaves it open, otherwise the leave goes through */
|
|
95
|
+
static #finishGrace(reached) {
|
|
96
|
+
const grace = Tooltip.#grace;
|
|
97
|
+
if (!grace) return;
|
|
98
|
+
Tooltip.#grace = null;
|
|
99
|
+
grace.cancel();
|
|
100
|
+
if (!reached) {
|
|
101
|
+
grace.owner.delayHide();
|
|
102
|
+
for (const tooltip of grace.pending) tooltip.delayShow();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
90
105
|
#handleClickOutside = (e) => {
|
|
91
106
|
const popup = this.adapter.getPortalContainer();
|
|
92
107
|
if (!popup || this.adapter.isEventInTrigger(e) || e === this.#pressedInside || isEventInside(e, popup, ...this.adapter.getNestedPopups())) return;
|
|
@@ -238,20 +253,31 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
238
253
|
case "hover":
|
|
239
254
|
triggerEventSet[TRIGGER_EVENT_NAMES.mouseEnter] = () => {
|
|
240
255
|
this.#isClickToHide = false;
|
|
241
|
-
if (this.getProp("condition") !== false) this.delayShow();
|
|
256
|
+
if (this.getProp("condition") !== false && !this.#deferToGrace()) this.delayShow();
|
|
242
257
|
};
|
|
243
|
-
triggerEventSet[TRIGGER_EVENT_NAMES.mouseLeave] = () => {
|
|
244
|
-
|
|
258
|
+
triggerEventSet[TRIGGER_EVENT_NAMES.mouseLeave] = (event) => {
|
|
259
|
+
Tooltip.#grace?.pending.delete(this);
|
|
260
|
+
if (!this.#startGrace(event)) this.delayHide();
|
|
245
261
|
};
|
|
246
|
-
triggerEventSet[TRIGGER_EVENT_NAMES.focus] = () => {
|
|
262
|
+
triggerEventSet[TRIGGER_EVENT_NAMES.focus] = (event) => {
|
|
247
263
|
const { disableFocusListener } = this.getProps();
|
|
248
|
-
|
|
264
|
+
const target = event?.target;
|
|
265
|
+
if (this.getProp("condition") !== false && !disableFocusListener && target?.matches?.(":focus-visible") !== false) this.delayShow();
|
|
249
266
|
};
|
|
250
267
|
triggerEventSet[TRIGGER_EVENT_NAMES.blur] = () => {
|
|
251
268
|
const { disableFocusListener } = this.getProps();
|
|
252
269
|
if (!disableFocusListener) this.delayHide();
|
|
253
270
|
};
|
|
254
|
-
portalEventSet = {
|
|
271
|
+
portalEventSet = {
|
|
272
|
+
...triggerEventSet,
|
|
273
|
+
[TRIGGER_EVENT_NAMES.mouseEnter]: () => {
|
|
274
|
+
this.#isClickToHide = false;
|
|
275
|
+
if (this.getProp("condition") !== false) this.delayShow();
|
|
276
|
+
},
|
|
277
|
+
[TRIGGER_EVENT_NAMES.mouseLeave]: () => {
|
|
278
|
+
this.delayHide();
|
|
279
|
+
}
|
|
280
|
+
};
|
|
255
281
|
if (this.getProp("clickToHide")) {
|
|
256
282
|
portalEventSet[TRIGGER_EVENT_NAMES.click] = () => {
|
|
257
283
|
this.#isClickToHide = true;
|
|
@@ -308,10 +334,58 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
308
334
|
event.preventDefault();
|
|
309
335
|
}
|
|
310
336
|
#clearDelayTimer() {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
337
|
+
clearTimeout(this.#timer);
|
|
338
|
+
this.#timer = null;
|
|
339
|
+
Tooltip.#exclusiveWaiting.delete(this);
|
|
340
|
+
this.#dropGrace(false);
|
|
341
|
+
}
|
|
342
|
+
/** Ends this popup's grace without hiding it; the triggers entered meanwhile open only if `resume` */
|
|
343
|
+
#dropGrace(resume) {
|
|
344
|
+
const grace = Tooltip.#grace;
|
|
345
|
+
if (grace?.owner !== this) return;
|
|
346
|
+
Tooltip.#grace = null;
|
|
347
|
+
grace.cancel();
|
|
348
|
+
if (resume) for (const tooltip of grace.pending) tooltip.delayShow();
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* On the trigger's mouseleave of an open, placed popup: a pointer heading for the popup keeps it open instead of
|
|
352
|
+
* starting the leave delay. Returns whether a grace started.
|
|
353
|
+
*/
|
|
354
|
+
#startGrace(event) {
|
|
355
|
+
const popup = this.adapter.getPortalContainer();
|
|
356
|
+
const triggerRect = this.adapter.getTriggerRect();
|
|
357
|
+
if (!this.#open || !this.#applied || !popup || !triggerRect?.width || !triggerRect.height || typeof event?.clientX !== "number" || !matchMedia("(hover: hover)").matches) return false;
|
|
358
|
+
Tooltip.#finishGrace(false);
|
|
359
|
+
const cancel = trackPointerGrace({
|
|
360
|
+
x: event.clientX,
|
|
361
|
+
y: event.clientY
|
|
362
|
+
}, triggerRect, popup.getBoundingClientRect(), (reached) => Tooltip.#finishGrace(reached));
|
|
363
|
+
if (!cancel) return false;
|
|
364
|
+
this.#clearDelayTimer();
|
|
365
|
+
Tooltip.#grace = {
|
|
366
|
+
owner: this,
|
|
367
|
+
cancel,
|
|
368
|
+
pending: /* @__PURE__ */ new Set()
|
|
369
|
+
};
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
/** A closed hover trigger entered during an unrelated popup's grace waits for it; returns whether it waits */
|
|
373
|
+
#deferToGrace() {
|
|
374
|
+
const grace = Tooltip.#grace;
|
|
375
|
+
if (!grace || this.#open || grace.owner === this || this.#isNestedIn(grace.owner) || grace.owner.#isNestedIn(this)) return false;
|
|
376
|
+
grace.pending.add(this);
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
#isExclusive() {
|
|
380
|
+
const { trigger, role } = this.getProps();
|
|
381
|
+
return (trigger === "hover" || trigger === "focus") && (role ?? "tooltip") === "tooltip";
|
|
382
|
+
}
|
|
383
|
+
/** Whether this trigger sits in the other tooltip's trigger or popup, which then stays open */
|
|
384
|
+
#isNestedIn(other) {
|
|
385
|
+
const node = this.adapter.getTriggerElement() ?? this.adapter.getTriggerNode();
|
|
386
|
+
const container = other.adapter.getPortalContainer();
|
|
387
|
+
const otherTrigger = other.adapter.getTriggerElement() ?? other.adapter.getTriggerNode();
|
|
388
|
+
return Boolean(node && (container && isInside(node, container) || otherTrigger && isInside(node, otherTrigger)));
|
|
315
389
|
}
|
|
316
390
|
/** Under a controlled `visible` that differs, a trigger only asks the owner (D-1); returns whether it asked */
|
|
317
391
|
#requestFromOwner(visible) {
|
|
@@ -662,6 +736,8 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
662
736
|
if (this.getState("transitionState") === "leave" && !this.getProp("keepDOM")) this.#removePortal();
|
|
663
737
|
this.#mounted = false;
|
|
664
738
|
this.#requestedVisible = void 0;
|
|
739
|
+
Tooltip.#exclusiveOpen.delete(this);
|
|
740
|
+
Tooltip.#grace?.pending.delete(this);
|
|
665
741
|
this.#endTracking();
|
|
666
742
|
this.#unwatchClickOutside();
|
|
667
743
|
this.#clearDelayTimer();
|
|
@@ -698,11 +774,16 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
698
774
|
delayShow() {
|
|
699
775
|
const mouseEnterDelay = this.getProp("mouseEnterDelay");
|
|
700
776
|
this.#clearDelayTimer();
|
|
701
|
-
if (mouseEnterDelay > 0)
|
|
702
|
-
this
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
777
|
+
if (mouseEnterDelay > 0) {
|
|
778
|
+
if (!this.#open && this.#isExclusive()) {
|
|
779
|
+
for (const other of Tooltip.#exclusiveWaiting) if (!this.#isNestedIn(other) && !other.#isNestedIn(this)) other.#clearDelayTimer();
|
|
780
|
+
Tooltip.#exclusiveWaiting.add(this);
|
|
781
|
+
}
|
|
782
|
+
this.#timer = setTimeout(() => {
|
|
783
|
+
this.show();
|
|
784
|
+
this.#clearDelayTimer();
|
|
785
|
+
}, mouseEnterDelay);
|
|
786
|
+
} else this.show();
|
|
706
787
|
}
|
|
707
788
|
show() {
|
|
708
789
|
if (this.#open || this.#requestFromOwner(true)) return;
|
|
@@ -712,6 +793,10 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
712
793
|
if (this.getState("transitionState") === "leave") this.#lifecycle.ended(() => this.adapter.notifyAfterClose());
|
|
713
794
|
this.#lifecycle.show();
|
|
714
795
|
this.#clearDelayTimer();
|
|
796
|
+
if (this.#isExclusive()) {
|
|
797
|
+
for (const other of Tooltip.#exclusiveOpen) if (!this.#isNestedIn(other)) other.hide();
|
|
798
|
+
Tooltip.#exclusiveOpen.add(this);
|
|
799
|
+
}
|
|
715
800
|
this.setState({
|
|
716
801
|
isInsert: true,
|
|
717
802
|
transitionState: "enter",
|
|
@@ -734,12 +819,14 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
734
819
|
else this.hide();
|
|
735
820
|
}
|
|
736
821
|
hide = () => {
|
|
822
|
+
this.#dropGrace(true);
|
|
737
823
|
if (this.#mounted && this.getState("isInsert") && this.#requestFromOwner(false)) {
|
|
738
824
|
this.#clearDelayTimer();
|
|
739
825
|
return;
|
|
740
826
|
}
|
|
741
827
|
const wasOpen = this.#open;
|
|
742
828
|
this.#open = false;
|
|
829
|
+
Tooltip.#exclusiveOpen.delete(this);
|
|
743
830
|
this.#clearDelayTimer();
|
|
744
831
|
if (!this.#mounted) return;
|
|
745
832
|
this.#unwatchClickOutside();
|
|
@@ -29,8 +29,11 @@
|
|
|
29
29
|
animation: #{$module}-zoom-in $animation_duration-tooltip_out $animation_function-tooltip_out;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
// closing renders the popup without the show class; forwards holds it invisible until hidePopover()
|
|
32
|
+
// closing renders the popup without the show class; forwards holds it invisible until hidePopover(). A closing
|
|
33
|
+
// popup takes no pointer: it is transparent from halfway, and a hover there would reopen it, only for the reopened
|
|
34
|
+
// popup to close again as neither its trigger nor focus holds it (Ant Design's leave motion does the same)
|
|
33
35
|
&:popover-open:not(.#{$module}-wrapper-show) {
|
|
36
|
+
pointer-events: none;
|
|
34
37
|
animation: #{$module}-zoom-out $animation_duration-tooltip_out $animation_function-tooltip_out forwards;
|
|
35
38
|
}
|
|
36
39
|
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
animation: semi-tooltip-zoom-in 100ms cubic-bezier(0.215, 0.61, 0.355, 1);
|
|
42
42
|
}
|
|
43
43
|
.semi-tooltip-wrapper:popover-open:not(.semi-tooltip-wrapper-show) {
|
|
44
|
+
pointer-events: none;
|
|
44
45
|
animation: semi-tooltip-zoom-out 100ms cubic-bezier(0.215, 0.61, 0.355, 1) forwards;
|
|
45
46
|
}
|
|
46
47
|
.semi-tooltip-wrapper.semi-tooltip-no-motion:popover-open {
|
|
@@ -366,8 +366,8 @@ function calcCheckedKeysForUnchecked(key, keyEntities, checkedKeys, halfCheckedK
|
|
|
366
366
|
const descendantKeys = findDescendantKeys([key], keyEntities, true);
|
|
367
367
|
const nodeItem = keyEntities[key];
|
|
368
368
|
descendantKeys.forEach((descendantKey) => {
|
|
369
|
-
|
|
370
|
-
|
|
369
|
+
checkedKeys.delete(descendantKey);
|
|
370
|
+
halfCheckedKeys.delete(descendantKey);
|
|
371
371
|
});
|
|
372
372
|
const calcCurrLevel = (node) => {
|
|
373
373
|
const par = node.parent;
|
|
@@ -383,8 +383,8 @@ function calcCheckedKeysForUnchecked(key, keyEntities, checkedKeys, halfCheckedK
|
|
|
383
383
|
}
|
|
384
384
|
});
|
|
385
385
|
else {
|
|
386
|
-
|
|
387
|
-
|
|
386
|
+
checkedKeys.delete(par.key);
|
|
387
|
+
halfCheckedKeys.delete(par.key);
|
|
388
388
|
calcCurrLevel(par);
|
|
389
389
|
}
|
|
390
390
|
};
|
|
@@ -145,7 +145,7 @@ var UploadFoundation = class extends BaseFoundation {
|
|
|
145
145
|
this.#handleBeforeUploadResultInObject(newResult, file);
|
|
146
146
|
break;
|
|
147
147
|
}
|
|
148
|
-
case
|
|
148
|
+
case isPromise(buResult):
|
|
149
149
|
Promise.resolve(buResult).then((resolveData) => {
|
|
150
150
|
let newResult = { shouldUpload: true };
|
|
151
151
|
if (isPlainObject(resolveData)) newResult = {
|
|
@@ -12,7 +12,7 @@ var VideoPlayerFoundation = class extends BaseFoundation {
|
|
|
12
12
|
#stalled = false;
|
|
13
13
|
#restoreController;
|
|
14
14
|
#clearTimer() {
|
|
15
|
-
|
|
15
|
+
clearTimeout(this.#controlsTimer);
|
|
16
16
|
}
|
|
17
17
|
#handleMouseMove = throttle(() => {
|
|
18
18
|
this.setState({ showControls: true });
|
package/dist/utils/a11y.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export declare function isBrowserChord({ key, ctrlKey, metaKey, altKey }: Pick<K
|
|
|
13
13
|
* first, so the Form's ids are added to them instead of replacing them
|
|
14
14
|
*/
|
|
15
15
|
export declare function joinIds(...ids: unknown[]): string | undefined;
|
|
16
|
+
/** aria-invalid is a token: the string 'false' is truthy but means valid */
|
|
17
|
+
export declare function isAriaInvalid(value: unknown): boolean;
|
|
16
18
|
/** An explicit role wins; otherwise a generic div given a name becomes a group, since a div without a role cannot carry one */
|
|
17
19
|
export declare function namedRole<A extends object>(attrs: A): RoleOf<A> | 'group' | undefined;
|
|
18
20
|
/** The role type the caller's own attribute bag declares, so each framework's typed `role` attribute accepts the result */
|
package/dist/utils/a11y.js
CHANGED
|
@@ -29,6 +29,10 @@ function isBrowserChord({ key, ctrlKey, metaKey, altKey }) {
|
|
|
29
29
|
function joinIds(...ids) {
|
|
30
30
|
return ids.filter((id) => typeof id === "string" && id !== "").join(" ") || void 0;
|
|
31
31
|
}
|
|
32
|
+
/** aria-invalid is a token: the string 'false' is truthy but means valid */
|
|
33
|
+
function isAriaInvalid(value) {
|
|
34
|
+
return Boolean(value) && value !== "false";
|
|
35
|
+
}
|
|
32
36
|
/** An explicit role wins; otherwise a generic div given a name becomes a group, since a div without a role cannot carry one */
|
|
33
37
|
function namedRole(attrs) {
|
|
34
38
|
const { role, "aria-label": label, "aria-labelledby": labelledby } = attrs;
|
|
@@ -197,4 +201,4 @@ function warnIfDialogUnnamed(dialog, component) {
|
|
|
197
201
|
const hasLabelElement = labelledBy?.split(/\s+/).some((id) => root.getElementById(id)?.textContent.trim());
|
|
198
202
|
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\`.`);
|
|
199
203
|
}
|
|
200
|
-
export { Typeahead, crossesFocusBoundary, getEnabledStepIndex, getListTargetIndex, getOptionId, handlePrevent, isAriaKey, isBrowserChord, isInnerControl, isInnerControlActivation, isInnerControlKey, isNativeInputKey, isTextEditor, joinIds, namedRole, revealOption, setFocusToFirstItem, setFocusToItem, setFocusToLastItem, stopButtonActivationKeys, warnIfDialogUnnamed };
|
|
204
|
+
export { Typeahead, crossesFocusBoundary, getEnabledStepIndex, getListTargetIndex, getOptionId, handlePrevent, isAriaInvalid, isAriaKey, isBrowserChord, isInnerControl, isInnerControlActivation, isInnerControlKey, isNativeInputKey, isTextEditor, joinIds, namedRole, revealOption, setFocusToFirstItem, setFocusToItem, setFocusToLastItem, stopButtonActivationKeys, warnIfDialogUnnamed };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ListNavigationOptions, Typeahead, crossesFocusBoundary, getEnabledStepIndex, getListTargetIndex, getOptionId, handlePrevent, isAriaKey, isBrowserChord, isInnerControl, isInnerControlActivation, isInnerControlKey, isNativeInputKey, isTextEditor, joinIds, namedRole, revealOption, setFocusToFirstItem, setFocusToItem, setFocusToLastItem, stopButtonActivationKeys, warnIfDialogUnnamed } from "./a11y.js";
|
|
1
|
+
import { ListNavigationOptions, Typeahead, crossesFocusBoundary, getEnabledStepIndex, getListTargetIndex, getOptionId, handlePrevent, isAriaInvalid, isAriaKey, isBrowserChord, isInnerControl, isInnerControlActivation, isInnerControlKey, isNativeInputKey, isTextEditor, joinIds, namedRole, revealOption, setFocusToFirstItem, setFocusToItem, setFocusToLastItem, stopButtonActivationKeys, warnIfDialogUnnamed } from "./a11y.js";
|
|
2
2
|
import { pinAnimatedHeight } from "./animated-height.js";
|
|
3
3
|
import Announcer, { ANNOUNCE_DELAY, ANNOUNCE_HOLD } from "./announcer.js";
|
|
4
4
|
import arrayMove from "./array-move.js";
|
|
@@ -22,6 +22,7 @@ import { KEEP_INTERACTIVE_ATTRIBUTE, Layer, POPUP_ID_ATTRIBUTE, POPUP_SELECTOR,
|
|
|
22
22
|
import { ignoreExpectedMediaErrors } from "./media.js";
|
|
23
23
|
import { get, has, isEmpty, remove, set } from "./object.js";
|
|
24
24
|
import { isSecondaryPress } from "./pointer.js";
|
|
25
|
+
import { GracePoint, GraceRect, GraceSide, GraceTriangle, POINTER_GRACE_TIMEOUT, getGraceArea, getGraceSide, isPointInTriangle, trackPointerGrace } from "./pointer-grace.js";
|
|
25
26
|
import { lockBodyScroll } from "./scroll-lock.js";
|
|
26
27
|
import shallowEqualObjects from "./shallow-equal-objects.js";
|
|
27
28
|
import { focusWithoutRing, scrollIntoViewWithin, supportsFocusVisibleOption, supportsScrollContainerOption, supportsScrollbarGutter } from "./supports.js";
|
|
@@ -29,4 +30,4 @@ import { Easing, TweenOptions, easeInOutCubic, linear, tween } from "./tween.js"
|
|
|
29
30
|
import { ArrayElement, Size } from "./type.js";
|
|
30
31
|
import { createId } from "./uuid.js";
|
|
31
32
|
import warning, { isDev } from "./warning.js";
|
|
32
|
-
export { ANNOUNCE_DELAY, ANNOUNCE_HOLD, Announcer, ArrayElement, CopiedTimer, ENTER_KEY, ESC_KEY, Easing, Event as EventEmitter, KEEP_INTERACTIVE_ATTRIBUTE, Layer, ListNavigationOptions, POPUP_ID_ATTRIBUTE, POPUP_SELECTOR, RegisterMediaQueryOption, Size, TweenOptions, Typeahead, addClass, arrayMove, assertClient, centerInScroller, containsWithPopups, copyText, coversPage, createId, crossesFocusBoundary, defaultPopupContainer, differenceUnique, easeInOutCubic, escapeHtmlInMarkdown, findFocusAfter, fitInputWidth, fitTextareaHeight, focusWithoutRing, get, getDataAttr, getEnabledStepIndex, getListTargetIndex, getOptionId, getPopupTrigger, handlePrevent, handoverFocus, has, ignoreExpectedMediaErrors, isAriaKey, isBrowserChord, isComposing, isDev, isEmpty, isEnterPress, isEventInside, isHTMLElement, isInnerControl, isInnerControlActivation, isInnerControlKey, isNativeInputKey, isObject, isPromise, isSecondaryPress, isTextEditor, isValidTimeZone, joinIds, linear, lockBodyScroll, namedRole, noop, onFontsLoaded, openLayer, pinAnimatedHeight, popupTriggerSelector, popupTriggers, registerMediaQuery, remove, removeClass, resolvePopupContainer, revealOption, scrollIntoViewWithin, set, setFocusToFirstItem, setFocusToItem, setFocusToLastItem, shallowEqualObjects, stopButtonActivationKeys, supportsFieldSizing, supportsFocusVisibleOption, supportsScrollContainerOption, supportsScrollbarGutter, toCssLength, tween, warnIfDialogUnnamed, warning, withOrderSort };
|
|
33
|
+
export { ANNOUNCE_DELAY, ANNOUNCE_HOLD, Announcer, ArrayElement, CopiedTimer, ENTER_KEY, ESC_KEY, Easing, Event as EventEmitter, GracePoint, GraceRect, GraceSide, GraceTriangle, KEEP_INTERACTIVE_ATTRIBUTE, Layer, ListNavigationOptions, POINTER_GRACE_TIMEOUT, POPUP_ID_ATTRIBUTE, POPUP_SELECTOR, RegisterMediaQueryOption, Size, TweenOptions, Typeahead, addClass, arrayMove, assertClient, centerInScroller, containsWithPopups, copyText, coversPage, createId, crossesFocusBoundary, defaultPopupContainer, differenceUnique, easeInOutCubic, escapeHtmlInMarkdown, findFocusAfter, fitInputWidth, fitTextareaHeight, focusWithoutRing, get, getDataAttr, getEnabledStepIndex, getGraceArea, getGraceSide, getListTargetIndex, getOptionId, getPopupTrigger, handlePrevent, handoverFocus, has, ignoreExpectedMediaErrors, isAriaInvalid, isAriaKey, isBrowserChord, isComposing, isDev, isEmpty, isEnterPress, isEventInside, isHTMLElement, isInnerControl, isInnerControlActivation, isInnerControlKey, isNativeInputKey, isObject, isPointInTriangle, isPromise, isSecondaryPress, isTextEditor, isValidTimeZone, joinIds, linear, lockBodyScroll, namedRole, noop, onFontsLoaded, openLayer, pinAnimatedHeight, popupTriggerSelector, popupTriggers, registerMediaQuery, remove, removeClass, resolvePopupContainer, revealOption, scrollIntoViewWithin, set, setFocusToFirstItem, setFocusToItem, setFocusToLastItem, shallowEqualObjects, stopButtonActivationKeys, supportsFieldSizing, supportsFocusVisibleOption, supportsScrollContainerOption, supportsScrollbarGutter, toCssLength, trackPointerGrace, tween, warnIfDialogUnnamed, warning, withOrderSort };
|
package/dist/utils/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Typeahead, crossesFocusBoundary, getEnabledStepIndex, getListTargetIndex, getOptionId, handlePrevent, isAriaKey, isBrowserChord, isInnerControl, isInnerControlActivation, isInnerControlKey, isNativeInputKey, isTextEditor, joinIds, namedRole, revealOption, setFocusToFirstItem, setFocusToItem, setFocusToLastItem, stopButtonActivationKeys, warnIfDialogUnnamed } from "./a11y.js";
|
|
1
|
+
import { Typeahead, crossesFocusBoundary, getEnabledStepIndex, getListTargetIndex, getOptionId, handlePrevent, isAriaInvalid, isAriaKey, isBrowserChord, isInnerControl, isInnerControlActivation, isInnerControlKey, isNativeInputKey, isTextEditor, joinIds, namedRole, revealOption, setFocusToFirstItem, setFocusToItem, setFocusToLastItem, stopButtonActivationKeys, warnIfDialogUnnamed } from "./a11y.js";
|
|
2
2
|
import { pinAnimatedHeight } from "./animated-height.js";
|
|
3
3
|
import Announcer, { ANNOUNCE_DELAY, ANNOUNCE_HOLD } from "./announcer.js";
|
|
4
4
|
import arrayMove from "./array-move.js";
|
|
@@ -22,10 +22,11 @@ import { KEEP_INTERACTIVE_ATTRIBUTE, POPUP_ID_ATTRIBUTE, POPUP_SELECTOR, contain
|
|
|
22
22
|
import { ignoreExpectedMediaErrors } from "./media.js";
|
|
23
23
|
import { get, has, isEmpty, remove, set } from "./object.js";
|
|
24
24
|
import { isSecondaryPress } from "./pointer.js";
|
|
25
|
+
import { POINTER_GRACE_TIMEOUT, getGraceArea, getGraceSide, isPointInTriangle, trackPointerGrace } from "./pointer-grace.js";
|
|
25
26
|
import { lockBodyScroll } from "./scroll-lock.js";
|
|
26
27
|
import shallowEqualObjects from "./shallow-equal-objects.js";
|
|
27
28
|
import { focusWithoutRing, scrollIntoViewWithin, supportsFocusVisibleOption, supportsScrollContainerOption, supportsScrollbarGutter } from "./supports.js";
|
|
28
29
|
import { easeInOutCubic, linear, tween } from "./tween.js";
|
|
29
30
|
import { createId } from "./uuid.js";
|
|
30
31
|
import warning, { isDev } from "./warning.js";
|
|
31
|
-
export { ANNOUNCE_DELAY, ANNOUNCE_HOLD, Announcer, CopiedTimer, ENTER_KEY, ESC_KEY, Event as EventEmitter, KEEP_INTERACTIVE_ATTRIBUTE, POPUP_ID_ATTRIBUTE, POPUP_SELECTOR, Typeahead, addClass, arrayMove, assertClient, centerInScroller, containsWithPopups, copyText, coversPage, createId, crossesFocusBoundary, defaultPopupContainer, differenceUnique, easeInOutCubic, escapeHtmlInMarkdown, findFocusAfter, fitInputWidth, fitTextareaHeight, focusWithoutRing, get, getDataAttr, getEnabledStepIndex, getListTargetIndex, getOptionId, getPopupTrigger, handlePrevent, handoverFocus, has, ignoreExpectedMediaErrors, isAriaKey, isBrowserChord, isComposing, isDev, isEmpty, isEnterPress, isEventInside, isHTMLElement, isInnerControl, isInnerControlActivation, isInnerControlKey, isNativeInputKey, isObject, isPromise, isSecondaryPress, isTextEditor, isValidTimeZone, joinIds, linear, lockBodyScroll, namedRole, noop, onFontsLoaded, openLayer, pinAnimatedHeight, popupTriggerSelector, popupTriggers, registerMediaQuery, remove, removeClass, resolvePopupContainer, revealOption, scrollIntoViewWithin, set, setFocusToFirstItem, setFocusToItem, setFocusToLastItem, shallowEqualObjects, stopButtonActivationKeys, supportsFieldSizing, supportsFocusVisibleOption, supportsScrollContainerOption, supportsScrollbarGutter, toCssLength, tween, warnIfDialogUnnamed, warning, withOrderSort };
|
|
32
|
+
export { ANNOUNCE_DELAY, ANNOUNCE_HOLD, Announcer, CopiedTimer, ENTER_KEY, ESC_KEY, Event as EventEmitter, KEEP_INTERACTIVE_ATTRIBUTE, POINTER_GRACE_TIMEOUT, POPUP_ID_ATTRIBUTE, POPUP_SELECTOR, Typeahead, addClass, arrayMove, assertClient, centerInScroller, containsWithPopups, copyText, coversPage, createId, crossesFocusBoundary, defaultPopupContainer, differenceUnique, easeInOutCubic, escapeHtmlInMarkdown, findFocusAfter, fitInputWidth, fitTextareaHeight, focusWithoutRing, get, getDataAttr, getEnabledStepIndex, getGraceArea, getGraceSide, getListTargetIndex, getOptionId, getPopupTrigger, handlePrevent, handoverFocus, has, ignoreExpectedMediaErrors, isAriaInvalid, isAriaKey, isBrowserChord, isComposing, isDev, isEmpty, isEnterPress, isEventInside, isHTMLElement, isInnerControl, isInnerControlActivation, isInnerControlKey, isNativeInputKey, isObject, isPointInTriangle, isPromise, isSecondaryPress, isTextEditor, isValidTimeZone, joinIds, linear, lockBodyScroll, namedRole, noop, onFontsLoaded, openLayer, pinAnimatedHeight, popupTriggerSelector, popupTriggers, registerMediaQuery, remove, removeClass, resolvePopupContainer, revealOption, scrollIntoViewWithin, set, setFocusToFirstItem, setFocusToItem, setFocusToLastItem, shallowEqualObjects, stopButtonActivationKeys, supportsFieldSizing, supportsFocusVisibleOption, supportsScrollContainerOption, supportsScrollbarGutter, toCssLength, trackPointerGrace, tween, warnIfDialogUnnamed, warning, withOrderSort };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pointer grace (menu aim): a pointer leaving a hover trigger diagonally toward the popup it opened crosses other
|
|
3
|
+
* triggers on the way. While it keeps heading for the popup inside the triangle between its exit point and the popup's
|
|
4
|
+
* near edge, the popup stays open and the crossed triggers wait. Radix Menu's pointer grace, with its 300ms limit.
|
|
5
|
+
*/
|
|
6
|
+
export interface GracePoint {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
}
|
|
10
|
+
export type GraceRect = Pick<DOMRectReadOnly, 'left' | 'top' | 'right' | 'bottom'>;
|
|
11
|
+
export type GraceSide = 'top' | 'right' | 'bottom' | 'left';
|
|
12
|
+
export declare const POINTER_GRACE_TIMEOUT = 300;
|
|
13
|
+
export type GraceTriangle = [GracePoint, GracePoint, GracePoint];
|
|
14
|
+
/** A point on an edge counts as inside. Runs on every pointermove, hence plain numbers and no allocation */
|
|
15
|
+
export declare function isPointInTriangle(x: number, y: number, [a, b, c]: GraceTriangle): boolean;
|
|
16
|
+
/** The side of `from` that `to` lies beyond; horizontal sides first, as submenus open sideways. Null when they overlap */
|
|
17
|
+
export declare function getGraceSide(from: GraceRect, to: GraceRect): GraceSide | null;
|
|
18
|
+
/** The triangle from the exit point to the two corners of `to` on its edge nearest the exit */
|
|
19
|
+
export declare function getGraceArea(exit: GracePoint, to: GraceRect, side: GraceSide): GraceTriangle;
|
|
20
|
+
/**
|
|
21
|
+
* Starts a grace for a mouse that left `from` at `exit`, heading for `to`. Listens to document pointermove (mouse
|
|
22
|
+
* only) until it ends: `onEnd(true, last)` once the pointer is in `to`; `onEnd(false, last)` once it leaves the
|
|
23
|
+
* triangle, moves away from `to` along the side's axis, or after POINTER_GRACE_TIMEOUT. A move with no change along
|
|
24
|
+
* that axis says nothing about direction. Returns the cancel function, which ends it without calling `onEnd`, or
|
|
25
|
+
* null when no grace applies: `to` has no area, overlaps `from` or already holds the exit point, or the pointer left
|
|
26
|
+
* past `from`'s far edge, away from `to`. `from` and `to` are read once here: the pointermove handler never touches
|
|
27
|
+
* layout.
|
|
28
|
+
*/
|
|
29
|
+
export declare function trackPointerGrace(exit: GracePoint, from: GraceRect, to: GraceRect, onEnd: (reached: boolean, last: GracePoint) => void): () => void;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// src/utils/pointer-grace.ts
|
|
2
|
+
const POINTER_GRACE_TIMEOUT = 300;
|
|
3
|
+
const BLEED = 5;
|
|
4
|
+
const AXES = {
|
|
5
|
+
right: ["x", 1],
|
|
6
|
+
left: ["x", -1],
|
|
7
|
+
bottom: ["y", 1],
|
|
8
|
+
top: ["y", -1]
|
|
9
|
+
};
|
|
10
|
+
const isInRect = (x, y, rect) => x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
|
|
11
|
+
const cross = (x, y, a, b) => (b.x - a.x) * (y - a.y) - (b.y - a.y) * (x - a.x);
|
|
12
|
+
/** A point on an edge counts as inside. Runs on every pointermove, hence plain numbers and no allocation */
|
|
13
|
+
function isPointInTriangle(x, y, [a, b, c]) {
|
|
14
|
+
const ab = cross(x, y, a, b);
|
|
15
|
+
const bc = cross(x, y, b, c);
|
|
16
|
+
const ca = cross(x, y, c, a);
|
|
17
|
+
return !((ab < 0 || bc < 0 || ca < 0) && (ab > 0 || bc > 0 || ca > 0));
|
|
18
|
+
}
|
|
19
|
+
/** The side of `from` that `to` lies beyond; horizontal sides first, as submenus open sideways. Null when they overlap */
|
|
20
|
+
function getGraceSide(from, to) {
|
|
21
|
+
if (to.left >= from.right) return "right";
|
|
22
|
+
if (to.right <= from.left) return "left";
|
|
23
|
+
if (to.top >= from.bottom) return "bottom";
|
|
24
|
+
if (to.bottom <= from.top) return "top";
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
/** The triangle from the exit point to the two corners of `to` on its edge nearest the exit */
|
|
28
|
+
function getGraceArea(exit, to, side) {
|
|
29
|
+
const [axis, sign] = AXES[side];
|
|
30
|
+
const apex = {
|
|
31
|
+
...exit,
|
|
32
|
+
[axis]: exit[axis] - sign * BLEED
|
|
33
|
+
};
|
|
34
|
+
if (axis === "x") {
|
|
35
|
+
const near = side === "right" ? to.left : to.right;
|
|
36
|
+
return [
|
|
37
|
+
apex,
|
|
38
|
+
{
|
|
39
|
+
x: near,
|
|
40
|
+
y: to.top
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
x: near,
|
|
44
|
+
y: to.bottom
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
const near = side === "bottom" ? to.top : to.bottom;
|
|
49
|
+
return [
|
|
50
|
+
apex,
|
|
51
|
+
{
|
|
52
|
+
x: to.left,
|
|
53
|
+
y: near
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
x: to.right,
|
|
57
|
+
y: near
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Starts a grace for a mouse that left `from` at `exit`, heading for `to`. Listens to document pointermove (mouse
|
|
63
|
+
* only) until it ends: `onEnd(true, last)` once the pointer is in `to`; `onEnd(false, last)` once it leaves the
|
|
64
|
+
* triangle, moves away from `to` along the side's axis, or after POINTER_GRACE_TIMEOUT. A move with no change along
|
|
65
|
+
* that axis says nothing about direction. Returns the cancel function, which ends it without calling `onEnd`, or
|
|
66
|
+
* null when no grace applies: `to` has no area, overlaps `from` or already holds the exit point, or the pointer left
|
|
67
|
+
* past `from`'s far edge, away from `to`. `from` and `to` are read once here: the pointermove handler never touches
|
|
68
|
+
* layout.
|
|
69
|
+
*/
|
|
70
|
+
function trackPointerGrace(exit, from, to, onEnd) {
|
|
71
|
+
const side = getGraceSide(from, to);
|
|
72
|
+
if (!side || to.right <= to.left || to.bottom <= to.top || isInRect(exit.x, exit.y, to)) return null;
|
|
73
|
+
const [axis, sign] = AXES[side];
|
|
74
|
+
const farEdge = {
|
|
75
|
+
right: from.left,
|
|
76
|
+
left: from.right,
|
|
77
|
+
bottom: from.top,
|
|
78
|
+
top: from.bottom
|
|
79
|
+
}[side];
|
|
80
|
+
if ((exit[axis] - farEdge) * sign < 0) return null;
|
|
81
|
+
const area = getGraceArea(exit, to, side);
|
|
82
|
+
const controller = new AbortController();
|
|
83
|
+
let lastX = exit.x;
|
|
84
|
+
let lastY = exit.y;
|
|
85
|
+
let timer;
|
|
86
|
+
const cancel = () => {
|
|
87
|
+
controller.abort();
|
|
88
|
+
clearTimeout(timer);
|
|
89
|
+
};
|
|
90
|
+
const end = (reached) => {
|
|
91
|
+
cancel();
|
|
92
|
+
onEnd(reached, {
|
|
93
|
+
x: lastX,
|
|
94
|
+
y: lastY
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
timer = setTimeout(() => end(false), 300);
|
|
98
|
+
document.addEventListener("pointermove", (e) => {
|
|
99
|
+
if (e.pointerType !== "mouse") return;
|
|
100
|
+
const { clientX: x, clientY: y } = e;
|
|
101
|
+
const away = (axis === "x" ? x - lastX : y - lastY) * sign < 0;
|
|
102
|
+
lastX = x;
|
|
103
|
+
lastY = y;
|
|
104
|
+
if (isInRect(x, y, to)) end(true);
|
|
105
|
+
else if (away || !isPointInTriangle(x, y, area)) end(false);
|
|
106
|
+
}, { signal: controller.signal });
|
|
107
|
+
return cancel;
|
|
108
|
+
}
|
|
109
|
+
export { POINTER_GRACE_TIMEOUT, getGraceArea, getGraceSide, isPointInTriangle, trackPointerGrace };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibrae/semi-foundation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://semi-design-next.pages.dev",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@date-fns/tz": "^1.5.0",
|
|
30
30
|
"@dnd-kit/dom": "~0.5.3",
|
|
31
|
-
"@fibrae/semi-json-viewer-core": "0.
|
|
31
|
+
"@fibrae/semi-json-viewer-core": "0.9.1",
|
|
32
32
|
"@mdx-js/mdx": "^3.1.1",
|
|
33
33
|
"@shikijs/core": "^4.6.0",
|
|
34
34
|
"clsx": "^2.1.1",
|