@fibrae/semi-foundation 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/calendar/event-util.js +1 -1
- package/dist/components/carousel/foundation.js +1 -1
- package/dist/components/cascader/foundation.js +1 -1
- 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/menu-foundation.d.ts +1 -1
- package/dist/components/form/form.css +64 -2
- package/dist/components/form/form.scss +65 -2
- package/dist/components/form/foundation.d.ts +2 -1
- package/dist/components/form/foundation.js +63 -3
- package/dist/components/form/interface.d.ts +9 -1
- package/dist/components/form/json-schema.d.ts +78 -2
- package/dist/components/form/json-schema.js +75 -8
- package/dist/components/form/rules.js +1 -1
- package/dist/components/form/variables.scss +4 -0
- 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/select/foundation.d.ts +1 -1
- 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 +2 -2
- package/dist/components/table/foundation.d.ts +8 -0
- package/dist/components/table/foundation.js +14 -2
- package/dist/components/table/rtl.scss +5 -0
- package/dist/components/table/table.css +123 -0
- package/dist/components/table/table.scss +174 -0
- package/dist/components/toast/toast.css +1 -1
- package/dist/components/toast/toast.scss +2 -1
- package/dist/components/tooltip/foundation.js +2 -4
- package/dist/components/tooltip/tooltip.css +1 -1
- package/dist/components/tooltip/tooltip.scss +4 -2
- package/dist/components/tree/tree-util.js +4 -4
- package/dist/components/upload/constants.d.ts +1 -1
- package/dist/components/upload/foundation.js +1 -1
- package/dist/components/video-player/foundation.js +1 -1
- package/dist/locale/interface.d.ts +4 -0
- package/dist/locale/source/en_US.js +3 -1
- package/dist/locale/source/zh_CN.js +3 -1
- package/dist/utils/a11y.d.ts +2 -0
- package/dist/utils/a11y.js +5 -1
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +3 -3
- package/dist/utils/scroll-lock.d.ts +4 -3
- package/dist/utils/scroll-lock.js +15 -11
- package/dist/utils/supports.d.ts +2 -0
- package/dist/utils/supports.js +7 -1
- package/package.json +2 -2
|
@@ -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
|
};
|
|
@@ -11,7 +11,7 @@ export declare const strings: {
|
|
|
11
11
|
FILE_STATUS_WAIT_UPLOAD: string;
|
|
12
12
|
FILE_LIST_PIC: "picture";
|
|
13
13
|
FILE_LIST_DEFAULT: "list";
|
|
14
|
-
LIST_TYPE: ("none" | "
|
|
14
|
+
LIST_TYPE: ("none" | "picture" | "list")[];
|
|
15
15
|
DRAG_AREA_DEFAULT: string;
|
|
16
16
|
DRAG_AREA_LEGAL: string;
|
|
17
17
|
TRIGGER_AUTO: "auto";
|
|
@@ -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 });
|
|
@@ -362,6 +362,8 @@ export interface Locale {
|
|
|
362
362
|
};
|
|
363
363
|
Form: {
|
|
364
364
|
optional: string;
|
|
365
|
+
/** name of the button that shows the tooltip of a label */
|
|
366
|
+
labelTooltip: string;
|
|
365
367
|
/** Default rule messages; `${len}`, `${min}`, `${max}` are the rule's bounds */
|
|
366
368
|
required: string;
|
|
367
369
|
invalid: string;
|
|
@@ -380,6 +382,8 @@ export interface Locale {
|
|
|
380
382
|
moveUpItem: string;
|
|
381
383
|
moveDownItem: string;
|
|
382
384
|
item: string;
|
|
385
|
+
/** Name of a single-value row, which shows no label; `${title}` is the array's title */
|
|
386
|
+
arrayItem: string;
|
|
383
387
|
};
|
|
384
388
|
Image: {
|
|
385
389
|
preview: string;
|
|
@@ -289,6 +289,7 @@ const local = {
|
|
|
289
289
|
},
|
|
290
290
|
Form: {
|
|
291
291
|
optional: "(optional)",
|
|
292
|
+
labelTooltip: "More information",
|
|
292
293
|
required: "This field is required",
|
|
293
294
|
invalid: "Invalid value",
|
|
294
295
|
stringLen: "Must be exactly ${len} characters",
|
|
@@ -304,7 +305,8 @@ const local = {
|
|
|
304
305
|
removeItem: "Remove item ${index}",
|
|
305
306
|
moveUpItem: "Move item ${index} up",
|
|
306
307
|
moveDownItem: "Move item ${index} down",
|
|
307
|
-
item: "Item ${index}"
|
|
308
|
+
item: "Item ${index}",
|
|
309
|
+
arrayItem: "${title} item ${index}"
|
|
308
310
|
},
|
|
309
311
|
Image: {
|
|
310
312
|
fallback: "fallback",
|
|
@@ -289,6 +289,7 @@ const local = {
|
|
|
289
289
|
},
|
|
290
290
|
Form: {
|
|
291
291
|
optional: "(可选)",
|
|
292
|
+
labelTooltip: "更多说明",
|
|
292
293
|
required: "此项为必填项",
|
|
293
294
|
invalid: "格式不正确",
|
|
294
295
|
stringLen: "长度须为 ${len} 个字符",
|
|
@@ -304,7 +305,8 @@ const local = {
|
|
|
304
305
|
removeItem: "删除第 ${index} 项",
|
|
305
306
|
moveUpItem: "上移第 ${index} 项",
|
|
306
307
|
moveDownItem: "下移第 ${index} 项",
|
|
307
|
-
item: "第 ${index} 项"
|
|
308
|
+
item: "第 ${index} 项",
|
|
309
|
+
arrayItem: "${title} 第 ${index} 项"
|
|
308
310
|
},
|
|
309
311
|
Image: {
|
|
310
312
|
fallback: "占位图",
|
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";
|
|
@@ -24,9 +24,9 @@ import { get, has, isEmpty, remove, set } from "./object.js";
|
|
|
24
24
|
import { isSecondaryPress } from "./pointer.js";
|
|
25
25
|
import { lockBodyScroll } from "./scroll-lock.js";
|
|
26
26
|
import shallowEqualObjects from "./shallow-equal-objects.js";
|
|
27
|
-
import { focusWithoutRing, scrollIntoViewWithin, supportsFocusVisibleOption, supportsScrollContainerOption } from "./supports.js";
|
|
27
|
+
import { focusWithoutRing, scrollIntoViewWithin, supportsFocusVisibleOption, supportsScrollContainerOption, supportsScrollbarGutter } from "./supports.js";
|
|
28
28
|
import { Easing, TweenOptions, easeInOutCubic, linear, tween } from "./tween.js";
|
|
29
29
|
import { ArrayElement, Size } from "./type.js";
|
|
30
30
|
import { createId } from "./uuid.js";
|
|
31
31
|
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, toCssLength, tween, warnIfDialogUnnamed, warning, withOrderSort };
|
|
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 };
|
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";
|
|
@@ -24,8 +24,8 @@ import { get, has, isEmpty, remove, set } from "./object.js";
|
|
|
24
24
|
import { isSecondaryPress } from "./pointer.js";
|
|
25
25
|
import { lockBodyScroll } from "./scroll-lock.js";
|
|
26
26
|
import shallowEqualObjects from "./shallow-equal-objects.js";
|
|
27
|
-
import { focusWithoutRing, scrollIntoViewWithin, supportsFocusVisibleOption, supportsScrollContainerOption } from "./supports.js";
|
|
27
|
+
import { focusWithoutRing, scrollIntoViewWithin, supportsFocusVisibleOption, supportsScrollContainerOption, supportsScrollbarGutter } from "./supports.js";
|
|
28
28
|
import { easeInOutCubic, linear, tween } from "./tween.js";
|
|
29
29
|
import { createId } from "./uuid.js";
|
|
30
30
|
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, toCssLength, tween, warnIfDialogUnnamed, warning, withOrderSort };
|
|
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 };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Locks are counted, so stacked overlays release the page only when the last one closes.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Locks are counted, so stacked overlays release the page only when the last one closes. While the page shows a
|
|
3
|
+
* scrollbar, the root keeps its gutter, so nothing shifts sideways when the scrollbar disappears, fixed elements
|
|
4
|
+
* included. Without scrollbar-gutter the body's end padding grows by the scrollbar width instead, which fixed elements
|
|
5
|
+
* do not follow; padding rather than width keeps the body's own margin and any width set by the page's stylesheet.
|
|
5
6
|
*/
|
|
6
7
|
export declare function lockBodyScroll(): () => void;
|
|
@@ -1,24 +1,27 @@
|
|
|
1
|
+
import { supportsScrollbarGutter } from "./supports.js";
|
|
1
2
|
// src/utils/scroll-lock.ts
|
|
2
3
|
let lockCount = 0;
|
|
3
4
|
let restore = null;
|
|
4
5
|
/**
|
|
5
|
-
* Locks are counted, so stacked overlays release the page only when the last one closes.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Locks are counted, so stacked overlays release the page only when the last one closes. While the page shows a
|
|
7
|
+
* scrollbar, the root keeps its gutter, so nothing shifts sideways when the scrollbar disappears, fixed elements
|
|
8
|
+
* included. Without scrollbar-gutter the body's end padding grows by the scrollbar width instead, which fixed elements
|
|
9
|
+
* do not follow; padding rather than width keeps the body's own margin and any width set by the page's stylesheet.
|
|
8
10
|
*/
|
|
9
11
|
function lockBodyScroll() {
|
|
10
12
|
if (lockCount === 0) {
|
|
11
|
-
const {
|
|
12
|
-
if (style.overflow === "hidden") restore = null;
|
|
13
|
+
const { body, documentElement: root } = document;
|
|
14
|
+
if (body.style.overflow === "hidden") restore = null;
|
|
13
15
|
else {
|
|
14
|
-
const scrollbarWidth = window.innerWidth -
|
|
15
|
-
const padding = getComputedStyle(document.body).paddingInlineEnd;
|
|
16
|
+
const scrollbarWidth = window.innerWidth - root.clientWidth;
|
|
16
17
|
restore = {
|
|
17
|
-
overflow: style.overflow,
|
|
18
|
-
paddingInlineEnd: style.paddingInlineEnd
|
|
18
|
+
overflow: body.style.overflow,
|
|
19
|
+
paddingInlineEnd: body.style.paddingInlineEnd,
|
|
20
|
+
scrollbarGutter: root.style.scrollbarGutter
|
|
19
21
|
};
|
|
20
|
-
style.overflow = "hidden";
|
|
21
|
-
style.
|
|
22
|
+
body.style.overflow = "hidden";
|
|
23
|
+
if (scrollbarWidth > 0 && supportsScrollbarGutter()) root.style.scrollbarGutter = "stable";
|
|
24
|
+
else if (scrollbarWidth > 0) body.style.paddingInlineEnd = `calc(${getComputedStyle(body).paddingInlineEnd} + ${scrollbarWidth}px)`;
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
lockCount++;
|
|
@@ -30,6 +33,7 @@ function lockBodyScroll() {
|
|
|
30
33
|
if (lockCount === 0 && restore) {
|
|
31
34
|
document.body.style.overflow = restore.overflow;
|
|
32
35
|
document.body.style.paddingInlineEnd = restore.paddingInlineEnd;
|
|
36
|
+
document.documentElement.style.scrollbarGutter = restore.scrollbarGutter;
|
|
33
37
|
restore = null;
|
|
34
38
|
}
|
|
35
39
|
};
|
package/dist/utils/supports.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** CSS `scrollbar-gutter`. Removable once the oldest supported Safari is 18.2. */
|
|
2
|
+
export declare function supportsScrollbarGutter(): boolean;
|
|
1
3
|
/**
|
|
2
4
|
* `scrollIntoView({ container: 'nearest' })` limits scrolling to the nearest scroller.
|
|
3
5
|
* Removable once the oldest supported browsers are Chrome 140, Firefox and Safari (neither supports it yet).
|
package/dist/utils/supports.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
// src/utils/supports.ts
|
|
2
2
|
let containerOption;
|
|
3
3
|
let focusVisibleOption;
|
|
4
|
+
let scrollbarGutter;
|
|
5
|
+
/** CSS `scrollbar-gutter`. Removable once the oldest supported Safari is 18.2. */
|
|
6
|
+
function supportsScrollbarGutter() {
|
|
7
|
+
scrollbarGutter ??= CSS.supports("scrollbar-gutter", "stable");
|
|
8
|
+
return scrollbarGutter;
|
|
9
|
+
}
|
|
4
10
|
/**
|
|
5
11
|
* `scrollIntoView({ container: 'nearest' })` limits scrolling to the nearest scroller.
|
|
6
12
|
* Removable once the oldest supported browsers are Chrome 140, Firefox and Safari (neither supports it yet).
|
|
@@ -90,4 +96,4 @@ function focusWithoutRing(el, options = {}) {
|
|
|
90
96
|
el.focus(options);
|
|
91
97
|
if (el.ownerDocument.activeElement !== el) clear();
|
|
92
98
|
}
|
|
93
|
-
export { focusWithoutRing, scrollIntoViewWithin, supportsFocusVisibleOption, supportsScrollContainerOption };
|
|
99
|
+
export { focusWithoutRing, scrollIntoViewWithin, supportsFocusVisibleOption, supportsScrollContainerOption, supportsScrollbarGutter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibrae/semi-foundation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
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.0",
|
|
32
32
|
"@mdx-js/mdx": "^3.1.1",
|
|
33
33
|
"@shikijs/core": "^4.6.0",
|
|
34
34
|
"clsx": "^2.1.1",
|