@fibrae/semi-foundation 0.9.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/foundation.js +4 -4
- package/dist/components/cascader/foundation.d.ts +6 -2
- package/dist/components/cascader/foundation.js +60 -6
- package/dist/components/date-picker/months-grid-foundation.d.ts +1 -1
- package/dist/components/dropdown/dropdown.css +1 -0
- package/dist/components/popover/popover.css +1 -0
- package/dist/components/tooltip/foundation.d.ts +2 -0
- package/dist/components/tooltip/foundation.js +100 -11
- package/dist/components/tooltip/position.scss +4 -1
- package/dist/components/tooltip/tooltip.css +1 -0
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +2 -1
- 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) {
|
|
@@ -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) {
|
|
@@ -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;
|
|
@@ -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): "time" | "
|
|
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 }: {
|
|
@@ -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 {
|
|
@@ -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 {
|
|
@@ -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;
|
|
@@ -310,6 +336,56 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
310
336
|
#clearDelayTimer() {
|
|
311
337
|
clearTimeout(this.#timer);
|
|
312
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)));
|
|
313
389
|
}
|
|
314
390
|
/** Under a controlled `visible` that differs, a trigger only asks the owner (D-1); returns whether it asked */
|
|
315
391
|
#requestFromOwner(visible) {
|
|
@@ -660,6 +736,8 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
660
736
|
if (this.getState("transitionState") === "leave" && !this.getProp("keepDOM")) this.#removePortal();
|
|
661
737
|
this.#mounted = false;
|
|
662
738
|
this.#requestedVisible = void 0;
|
|
739
|
+
Tooltip.#exclusiveOpen.delete(this);
|
|
740
|
+
Tooltip.#grace?.pending.delete(this);
|
|
663
741
|
this.#endTracking();
|
|
664
742
|
this.#unwatchClickOutside();
|
|
665
743
|
this.#clearDelayTimer();
|
|
@@ -696,11 +774,16 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
696
774
|
delayShow() {
|
|
697
775
|
const mouseEnterDelay = this.getProp("mouseEnterDelay");
|
|
698
776
|
this.#clearDelayTimer();
|
|
699
|
-
if (mouseEnterDelay > 0)
|
|
700
|
-
this
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
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();
|
|
704
787
|
}
|
|
705
788
|
show() {
|
|
706
789
|
if (this.#open || this.#requestFromOwner(true)) return;
|
|
@@ -710,6 +793,10 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
710
793
|
if (this.getState("transitionState") === "leave") this.#lifecycle.ended(() => this.adapter.notifyAfterClose());
|
|
711
794
|
this.#lifecycle.show();
|
|
712
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
|
+
}
|
|
713
800
|
this.setState({
|
|
714
801
|
isInsert: true,
|
|
715
802
|
transitionState: "enter",
|
|
@@ -732,12 +819,14 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
732
819
|
else this.hide();
|
|
733
820
|
}
|
|
734
821
|
hide = () => {
|
|
822
|
+
this.#dropGrace(true);
|
|
735
823
|
if (this.#mounted && this.getState("isInsert") && this.#requestFromOwner(false)) {
|
|
736
824
|
this.#clearDelayTimer();
|
|
737
825
|
return;
|
|
738
826
|
}
|
|
739
827
|
const wasOpen = this.#open;
|
|
740
828
|
this.#open = false;
|
|
829
|
+
Tooltip.#exclusiveOpen.delete(this);
|
|
741
830
|
this.#clearDelayTimer();
|
|
742
831
|
if (!this.#mounted) return;
|
|
743
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 {
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -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, isAriaInvalid, 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
|
@@ -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, isAriaInvalid, 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.9.
|
|
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.9.
|
|
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",
|