@byline/admin 6.0.3 → 6.2.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/forms/form-renderer.d.ts +8 -2
- package/dist/forms/form-renderer.js +10 -4
- package/dist/forms/path-widget.d.ts +9 -1
- package/dist/forms/path-widget.js +8 -5
- package/dist/presentation/tab-strip-drag.d.ts +75 -0
- package/dist/presentation/tab-strip-drag.js +25 -0
- package/dist/presentation/tab-strip-drag.test.node.d.ts +8 -0
- package/dist/presentation/tab-strip-geometry.d.ts +75 -0
- package/dist/presentation/tab-strip-geometry.js +36 -0
- package/dist/presentation/tab-strip-geometry.test.node.d.ts +8 -0
- package/dist/presentation/tabs.d.ts +30 -7
- package/dist/presentation/tabs.js +260 -29
- package/dist/presentation/tabs.module.js +11 -1
- package/dist/presentation/tabs_module.css +166 -5
- package/package.json +7 -7
- package/src/forms/form-renderer-capabilities.test.tsx +72 -2
- package/src/forms/form-renderer.tsx +24 -5
- package/src/forms/path-widget.test.tsx +96 -2
- package/src/forms/path-widget.tsx +31 -11
- package/src/presentation/tab-strip-drag.test.node.ts +143 -0
- package/src/presentation/tab-strip-drag.ts +114 -0
- package/src/presentation/tab-strip-geometry.test.node.ts +254 -0
- package/src/presentation/tab-strip-geometry.ts +158 -0
- package/src/presentation/tabs.module.css +209 -11
- package/src/presentation/tabs.test.tsx +481 -0
- package/src/presentation/tabs.tsx +369 -34
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Copyright (c) Infonomic Company Limited
|
|
7
7
|
*/
|
|
8
8
|
import { type ReactNode } from 'react';
|
|
9
|
-
import type {
|
|
9
|
+
import type { AdminResourceConfig, Field, WorkflowStatus } from '@byline/core';
|
|
10
10
|
import type { DocumentPatch } from '@byline/core/patches';
|
|
11
11
|
import { type DocumentActionsLocaleOption } from './document-actions.js';
|
|
12
12
|
import { type ScheduledPublicationInfo, type SchedulePublicationInput } from './scheduled-publication-control.js';
|
|
@@ -95,7 +95,13 @@ export interface FormRendererProps {
|
|
|
95
95
|
workflowStatuses?: WorkflowStatus[];
|
|
96
96
|
publishedVersion?: PublishedVersionInfo | null;
|
|
97
97
|
initialData?: Record<string, any>;
|
|
98
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Presentation configuration for the resource being edited — a collection
|
|
100
|
+
* or a singleton. Typed as the union rather than the shared
|
|
101
|
+
* `FormAdminConfig` base so the renderer can read collection-only members
|
|
102
|
+
* such as `lockPath`.
|
|
103
|
+
*/
|
|
104
|
+
adminConfig?: AdminResourceConfig;
|
|
99
105
|
/**
|
|
100
106
|
* Name of the schema field to render as the live form heading.
|
|
101
107
|
* Sourced from `CollectionDefinition.useAsTitle` by the caller.
|
|
@@ -10,7 +10,7 @@ import { FieldRenderer } from "../fields/field-renderer.js";
|
|
|
10
10
|
import { useBylineFieldServices } from "../fields/field-services-context.js";
|
|
11
11
|
import { AdminGroup } from "../presentation/group.js";
|
|
12
12
|
import { AdminRow } from "../presentation/row.js";
|
|
13
|
-
import { AdminTabs } from "../presentation/tabs.js";
|
|
13
|
+
import { AdminTabs, tabPanelId, tabTriggerId } from "../presentation/tabs.js";
|
|
14
14
|
import { AvailableLocalesWidget } from "./available-locales-widget.js";
|
|
15
15
|
import { DocumentActions } from "./document-actions.js";
|
|
16
16
|
import { FormProvider, useFieldValue, useFormContext } from "./form-context.js";
|
|
@@ -284,10 +284,12 @@ const FormContent = ({ mode, mutationIssue, mutationsBlocked = false, observedRe
|
|
|
284
284
|
const requested = activeTabBySet[set.name] ?? '';
|
|
285
285
|
const resolvedActive = visibleTabs.length > 0 && !visibleTabs.some((t)=>t.name === requested) ? visibleTabs[0]?.name ?? requested : requested;
|
|
286
286
|
const activeTab = visibleTabs.find((t)=>t.name === resolvedActive);
|
|
287
|
+
const idBase = `tabset:${set.name}`;
|
|
287
288
|
return /*#__PURE__*/ jsxs("div", {
|
|
288
289
|
className: clsx('byline-form-tabset', form_renderer_module.tabset),
|
|
289
290
|
children: [
|
|
290
291
|
visibleTabs.length > 0 && /*#__PURE__*/ jsx(AdminTabs, {
|
|
292
|
+
idBase: idBase,
|
|
291
293
|
tabs: visibleTabs,
|
|
292
294
|
activeTab: resolvedActive,
|
|
293
295
|
onChange: (tabName)=>handleTabChange(set.name, tabName),
|
|
@@ -295,11 +297,14 @@ const FormContent = ({ mode, mutationIssue, mutationsBlocked = false, observedRe
|
|
|
295
297
|
className: clsx('byline-form-tabset-tabs', form_renderer_module["tabset-tabs"])
|
|
296
298
|
}),
|
|
297
299
|
activeTab && /*#__PURE__*/ jsx("div", {
|
|
300
|
+
role: "tabpanel",
|
|
301
|
+
id: tabPanelId(idBase, activeTab.name),
|
|
302
|
+
"aria-labelledby": tabTriggerId(idBase, activeTab.name),
|
|
298
303
|
className: clsx('byline-form-tabset-fields', form_renderer_module["tabset-fields"]),
|
|
299
304
|
children: activeTab.fields.map((name)=>renderItem(name))
|
|
300
305
|
})
|
|
301
306
|
]
|
|
302
|
-
},
|
|
307
|
+
}, idBase);
|
|
303
308
|
};
|
|
304
309
|
const busyAnnouncement = isUploading ? t('forms.actions.uploading') : isSubmitting ? t('forms.actions.saving') : '';
|
|
305
310
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
@@ -533,7 +538,7 @@ const FormContent = ({ mode, mutationIssue, mutationsBlocked = false, observedRe
|
|
|
533
538
|
/*#__PURE__*/ jsxs("div", {
|
|
534
539
|
className: clsx('byline-form-sidebar', form_renderer_module.sidebar),
|
|
535
540
|
children: [
|
|
536
|
-
showPath && (useAsPath || 'string' == typeof initialData?.path && initialData.path.length > 0) && /*#__PURE__*/ jsx(PathWidget, {
|
|
541
|
+
showPath && (useAsPath || adminConfig?.lockPath === true || 'string' == typeof initialData?.path && initialData.path.length > 0) && /*#__PURE__*/ jsx(PathWidget, {
|
|
537
542
|
disabled: mutationsBlocked || discarding,
|
|
538
543
|
useAsPath: useAsPath,
|
|
539
544
|
collectionPath: collectionPath ?? '',
|
|
@@ -541,7 +546,8 @@ const FormContent = ({ mode, mutationIssue, mutationsBlocked = false, observedRe
|
|
|
541
546
|
activeLocale: contentLocale,
|
|
542
547
|
mode: mode,
|
|
543
548
|
slugifier: pathSlugifier,
|
|
544
|
-
sourceLocked: pathSourceLocked
|
|
549
|
+
sourceLocked: pathSourceLocked,
|
|
550
|
+
lockPath: adminConfig?.lockPath
|
|
545
551
|
}),
|
|
546
552
|
tree && 'edit' === mode && 'string' == typeof initialData?.id && /*#__PURE__*/ jsx(TreePlacementWidget, {
|
|
547
553
|
disabled: mutationsBlocked || discarding,
|
|
@@ -35,6 +35,14 @@ export interface PathWidgetProps {
|
|
|
35
35
|
* persisted path. Defaults to `false`.
|
|
36
36
|
*/
|
|
37
37
|
sourceLocked?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* When `true`, the collection declares its paths managed
|
|
40
|
+
* (`CollectionAdminConfig.lockPath`): the input renders read-only in both
|
|
41
|
+
* modes and the preview placeholder and "Regenerate" action are
|
|
42
|
+
* suppressed. Independent of `sourceLocked`, which answers whether the
|
|
43
|
+
* form can derive a preview at all. Defaults to `false`.
|
|
44
|
+
*/
|
|
45
|
+
lockPath?: boolean;
|
|
38
46
|
}
|
|
39
47
|
/**
|
|
40
48
|
* System-managed `path` widget.
|
|
@@ -52,4 +60,4 @@ export interface PathWidgetProps {
|
|
|
52
60
|
* Stable override handles: `.byline-form-path`, `.byline-form-path-header`,
|
|
53
61
|
* `.byline-form-path-regenerate`.
|
|
54
62
|
*/
|
|
55
|
-
export declare const PathWidget: ({ useAsPath, collectionPath, defaultLocale, activeLocale, mode, slugifier, sourceLocked, disabled, }: PathWidgetProps) => import("react").JSX.Element;
|
|
63
|
+
export declare const PathWidget: ({ useAsPath, collectionPath, defaultLocale, activeLocale, mode, slugifier, sourceLocked, lockPath, disabled, }: PathWidgetProps) => import("react").JSX.Element;
|
|
@@ -12,13 +12,14 @@ function coerceToString(value) {
|
|
|
12
12
|
if (value instanceof Date) return value.toISOString();
|
|
13
13
|
return String(value);
|
|
14
14
|
}
|
|
15
|
-
const PathWidget = ({ useAsPath, collectionPath, defaultLocale, activeLocale, mode, slugifier, sourceLocked = false, disabled = false })=>{
|
|
15
|
+
const PathWidget = ({ useAsPath, collectionPath, defaultLocale, activeLocale, mode, slugifier, sourceLocked = false, lockPath = false, disabled = false })=>{
|
|
16
16
|
const { setSystemPath } = useFormContext();
|
|
17
17
|
const { t } = useTranslation('byline-admin');
|
|
18
18
|
const systemPath = useSystemPath();
|
|
19
19
|
const sourceValue = useFieldValue(useAsPath ?? '');
|
|
20
20
|
const runSlugify = slugifier ?? slugify;
|
|
21
|
-
const
|
|
21
|
+
const translationLocked = activeLocale !== defaultLocale;
|
|
22
|
+
const isReadOnly = lockPath || translationLocked;
|
|
22
23
|
const livePreview = useMemo(()=>{
|
|
23
24
|
if (!useAsPath || sourceLocked) return '';
|
|
24
25
|
const asString = coerceToString(sourceValue);
|
|
@@ -37,10 +38,11 @@ const PathWidget = ({ useAsPath, collectionPath, defaultLocale, activeLocale, mo
|
|
|
37
38
|
]);
|
|
38
39
|
const inputValue = systemPath ?? '';
|
|
39
40
|
const handleChange = useCallback((next)=>{
|
|
40
|
-
if (disabled) return;
|
|
41
|
+
if (disabled || isReadOnly) return;
|
|
41
42
|
setSystemPath(0 === next.length ? null : next);
|
|
42
43
|
}, [
|
|
43
44
|
disabled,
|
|
45
|
+
isReadOnly,
|
|
44
46
|
setSystemPath
|
|
45
47
|
]);
|
|
46
48
|
const handleRegenerate = useCallback(()=>{
|
|
@@ -65,10 +67,11 @@ const PathWidget = ({ useAsPath, collectionPath, defaultLocale, activeLocale, mo
|
|
|
65
67
|
const validationHint = inputValue.length > 0 && formatted !== inputValue ? t('pathWidget.suggestedHint', {
|
|
66
68
|
formatted
|
|
67
69
|
}) : void 0;
|
|
68
|
-
const
|
|
70
|
+
const lockedHint = lockPath ? 'create' === mode ? t('pathWidget.lockedCreateHint') : t('pathWidget.lockedHint') : void 0;
|
|
71
|
+
const translationHint = translationLocked ? t('pathWidget.readOnlyHint', {
|
|
69
72
|
locale: defaultLocale
|
|
70
73
|
}) : void 0;
|
|
71
|
-
const hint =
|
|
74
|
+
const hint = lockedHint ?? translationHint ?? validationHint;
|
|
72
75
|
const placeholder = !isReadOnly && 'create' === mode && livePreview.length > 0 ? t('pathWidget.willBeSavedAs', {
|
|
73
76
|
preview: livePreview
|
|
74
77
|
}) : void 0;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Pure state for click-and-drag scrolling of the tab strip.
|
|
10
|
+
*
|
|
11
|
+
* The DOM plumbing — pointer capture, the click suppression, the cursor —
|
|
12
|
+
* lives in `tabs.tsx`; the rules it follows are here so they can be tested
|
|
13
|
+
* without a pointer.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* How far the pointer must travel before the gesture stops being a click and
|
|
17
|
+
* becomes a drag.
|
|
18
|
+
*
|
|
19
|
+
* Without a threshold every click on a tab would nudge the strip by a pixel or
|
|
20
|
+
* two, and the click suppression that follows a drag would swallow the very
|
|
21
|
+
* clicks that select tabs.
|
|
22
|
+
*/
|
|
23
|
+
export declare const DRAG_THRESHOLD_PX = 5;
|
|
24
|
+
/**
|
|
25
|
+
* How long after a drag a click is treated as that drag's own click.
|
|
26
|
+
*
|
|
27
|
+
* A window rather than a consume-once flag, because the click is not
|
|
28
|
+
* guaranteed to arrive: a drag released outside the strip produces none, and
|
|
29
|
+
* a flag left armed would swallow the reader's next deliberate click on a tab.
|
|
30
|
+
* Far longer than the browser's synthetic click takes to arrive, far shorter
|
|
31
|
+
* than anyone can release and deliberately click again.
|
|
32
|
+
*/
|
|
33
|
+
export declare const CLICK_SUPPRESSION_MS = 100;
|
|
34
|
+
/** Where a gesture began. An internal part of `DragState`, not a public type. */
|
|
35
|
+
interface DragOrigin {
|
|
36
|
+
/** Pointer x at the moment the button went down. */
|
|
37
|
+
pointerX: number;
|
|
38
|
+
/** The viewport's scroll offset at that same moment. */
|
|
39
|
+
scrollLeft: number;
|
|
40
|
+
}
|
|
41
|
+
export interface DragState {
|
|
42
|
+
origin: DragOrigin;
|
|
43
|
+
/** Whether the threshold has already been crossed. */
|
|
44
|
+
dragging: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface DragAdvance {
|
|
47
|
+
dragging: boolean;
|
|
48
|
+
/** The offset to scroll to, or `null` while the gesture is still a click. */
|
|
49
|
+
scrollLeft: number | null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether a `pointerdown` should begin a potential drag.
|
|
53
|
+
*
|
|
54
|
+
* Mouse only. Touch and pen already scroll the viewport natively, with
|
|
55
|
+
* momentum and rubber-banding that a hand-rolled drag does not reproduce, so
|
|
56
|
+
* taking the gesture over would trade a good interaction for a worse one.
|
|
57
|
+
*/
|
|
58
|
+
export declare function shouldStartDrag({ pointerType, button, overflowing, }: {
|
|
59
|
+
pointerType: string;
|
|
60
|
+
button: number;
|
|
61
|
+
overflowing: boolean;
|
|
62
|
+
}): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Advance a gesture given the pointer's current x.
|
|
65
|
+
*
|
|
66
|
+
* Returns `scrollLeft: null` while the pointer is still within the threshold,
|
|
67
|
+
* so the caller leaves the viewport alone and lets the click through.
|
|
68
|
+
*/
|
|
69
|
+
export declare function advanceDrag({ origin, dragging }: DragState, pointerX: number, maxScroll: number): DragAdvance;
|
|
70
|
+
/**
|
|
71
|
+
* Whether a click arriving now belongs to a drag that has just ended, and
|
|
72
|
+
* should therefore not reach the tab underneath.
|
|
73
|
+
*/
|
|
74
|
+
export declare function shouldSuppressClick(dragEndedAt: number | null, now: number): boolean;
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const DRAG_THRESHOLD_PX = 5;
|
|
2
|
+
const CLICK_SUPPRESSION_MS = 100;
|
|
3
|
+
function shouldStartDrag({ pointerType, button, overflowing }) {
|
|
4
|
+
if ('mouse' !== pointerType) return false;
|
|
5
|
+
if (0 !== button) return false;
|
|
6
|
+
return overflowing;
|
|
7
|
+
}
|
|
8
|
+
function advanceDrag({ origin, dragging }, pointerX, maxScroll) {
|
|
9
|
+
const delta = pointerX - origin.pointerX;
|
|
10
|
+
const isDragging = dragging || Math.abs(delta) >= DRAG_THRESHOLD_PX;
|
|
11
|
+
if (false === isDragging) return {
|
|
12
|
+
dragging: false,
|
|
13
|
+
scrollLeft: null
|
|
14
|
+
};
|
|
15
|
+
const next = origin.scrollLeft - delta;
|
|
16
|
+
return {
|
|
17
|
+
dragging: true,
|
|
18
|
+
scrollLeft: Math.min(Math.max(next, 0), maxScroll)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function shouldSuppressClick(dragEndedAt, now) {
|
|
22
|
+
if (null == dragEndedAt) return false;
|
|
23
|
+
return now - dragEndedAt < CLICK_SUPPRESSION_MS;
|
|
24
|
+
}
|
|
25
|
+
export { CLICK_SUPPRESSION_MS, DRAG_THRESHOLD_PX, advanceDrag, shouldStartDrag, shouldSuppressClick };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
export interface StripMeasurements {
|
|
9
|
+
/**
|
|
10
|
+
* Intrinsic content width of the tablist row.
|
|
11
|
+
*
|
|
12
|
+
* The row is laid out at `max-content`, so this is the width the tabs want
|
|
13
|
+
* regardless of how much room the viewport currently gives them. A row that
|
|
14
|
+
* shrank to its container would report the container's width back and the
|
|
15
|
+
* strip could never detect overflow at all.
|
|
16
|
+
*/
|
|
17
|
+
rowWidth: number;
|
|
18
|
+
/**
|
|
19
|
+
* Usable width of the strip container.
|
|
20
|
+
*
|
|
21
|
+
* Independent of whether the trigger is rendered — the container is sized by
|
|
22
|
+
* the layout above it, not by its own children.
|
|
23
|
+
*/
|
|
24
|
+
containerWidth: number;
|
|
25
|
+
/** Width the overflow trigger occupies when it is rendered. */
|
|
26
|
+
triggerWidth: number;
|
|
27
|
+
/** Gap between the viewport and the trigger. */
|
|
28
|
+
triggerGap: number;
|
|
29
|
+
/** Current horizontal scroll offset of the viewport. */
|
|
30
|
+
scrollLeft: number;
|
|
31
|
+
}
|
|
32
|
+
export interface StripState {
|
|
33
|
+
/** Whether the row needs the scrolling viewport and the overflow trigger. */
|
|
34
|
+
overflowing: boolean;
|
|
35
|
+
/** Width available to the scrolling viewport. */
|
|
36
|
+
viewportWidth: number;
|
|
37
|
+
/** Whether the viewport is scrolled fully left (hides the leading fade). */
|
|
38
|
+
atStart: boolean;
|
|
39
|
+
/** Whether the viewport is scrolled fully right (hides the trailing fade). */
|
|
40
|
+
atEnd: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface RevealMeasurements {
|
|
43
|
+
viewportWidth: number;
|
|
44
|
+
scrollLeft: number;
|
|
45
|
+
/** The tab's offset from the start of the row. */
|
|
46
|
+
tabOffsetLeft: number;
|
|
47
|
+
tabWidth: number;
|
|
48
|
+
rowWidth: number;
|
|
49
|
+
padding?: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Resolve whether the strip overflows, and where it sits within its scroll
|
|
53
|
+
* range.
|
|
54
|
+
*
|
|
55
|
+
* Overflow is decided against the bare container, and deliberately takes no
|
|
56
|
+
* account of the trigger: a row that fits the container fits, and reserving
|
|
57
|
+
* the trigger's width first would summon a menu for tabs that were never cut
|
|
58
|
+
* off. The trigger is subtracted only afterwards, to size the viewport it now
|
|
59
|
+
* shares the container with.
|
|
60
|
+
*
|
|
61
|
+
* That ordering is also what keeps the result stable. The trigger's presence
|
|
62
|
+
* changes the viewport but never `containerWidth` — which the layout above
|
|
63
|
+
* sets — and never `rowWidth`, which the row holds at `max-content`. So the
|
|
64
|
+
* overflow answer cannot feed back into its own inputs.
|
|
65
|
+
*/
|
|
66
|
+
export declare function computeStripState({ rowWidth, containerWidth, triggerWidth, triggerGap, scrollLeft, }: StripMeasurements): StripState;
|
|
67
|
+
/**
|
|
68
|
+
* The scroll offset that brings one tab into view, or `null` when the tab is
|
|
69
|
+
* already visible and the viewport should be left untouched.
|
|
70
|
+
*
|
|
71
|
+
* Returning `null` rather than the current offset is the point: this runs on
|
|
72
|
+
* selection and on focus, and writing `scrollLeft` unconditionally would
|
|
73
|
+
* cancel a scroll the reader is in the middle of.
|
|
74
|
+
*/
|
|
75
|
+
export declare function computeRevealScroll({ viewportWidth, scrollLeft, tabOffsetLeft, tabWidth, rowWidth, padding, }: RevealMeasurements): number | null;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const EDGE_EPSILON = 1;
|
|
2
|
+
const DEFAULT_REVEAL_PADDING = 8;
|
|
3
|
+
function computeStripState({ rowWidth, containerWidth, triggerWidth, triggerGap, scrollLeft }) {
|
|
4
|
+
const measured = containerWidth > 0;
|
|
5
|
+
const overflowing = measured && rowWidth > containerWidth;
|
|
6
|
+
if (false === overflowing) return {
|
|
7
|
+
overflowing: false,
|
|
8
|
+
viewportWidth: Math.max(0, containerWidth),
|
|
9
|
+
atStart: true,
|
|
10
|
+
atEnd: true
|
|
11
|
+
};
|
|
12
|
+
const viewportWidth = Math.max(0, containerWidth - triggerWidth - triggerGap);
|
|
13
|
+
const maxScroll = Math.max(0, rowWidth - viewportWidth);
|
|
14
|
+
return {
|
|
15
|
+
overflowing: true,
|
|
16
|
+
viewportWidth,
|
|
17
|
+
atStart: scrollLeft <= EDGE_EPSILON,
|
|
18
|
+
atEnd: scrollLeft >= maxScroll - EDGE_EPSILON
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function computeRevealScroll({ viewportWidth, scrollLeft, tabOffsetLeft, tabWidth, rowWidth, padding = DEFAULT_REVEAL_PADDING }) {
|
|
22
|
+
const maxScroll = Math.max(0, rowWidth - viewportWidth);
|
|
23
|
+
const clamp = (value)=>Math.min(Math.max(value, 0), maxScroll);
|
|
24
|
+
const leadingEdge = tabOffsetLeft - padding;
|
|
25
|
+
const trailingEdge = tabOffsetLeft + tabWidth + padding;
|
|
26
|
+
let next;
|
|
27
|
+
if (tabWidth + 2 * padding >= viewportWidth) next = leadingEdge;
|
|
28
|
+
else if (leadingEdge < scrollLeft) next = leadingEdge;
|
|
29
|
+
else {
|
|
30
|
+
if (!(trailingEdge > scrollLeft + viewportWidth)) return null;
|
|
31
|
+
next = trailingEdge - viewportWidth;
|
|
32
|
+
}
|
|
33
|
+
const clamped = clamp(next);
|
|
34
|
+
return clamped === scrollLeft ? null : clamped;
|
|
35
|
+
}
|
|
36
|
+
export { computeRevealScroll, computeStripState };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
@@ -6,20 +6,43 @@ interface AdminTabsProps {
|
|
|
6
6
|
tabs: AdminTabItem[];
|
|
7
7
|
activeTab: string;
|
|
8
8
|
onChange: (name: string) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Prefix for the generated tab and panel ids. The consumer that renders the
|
|
11
|
+
* panels builds its panel ids from the same base via `tabPanelId`, which is
|
|
12
|
+
* what associates the two halves for assistive technology.
|
|
13
|
+
*/
|
|
14
|
+
idBase: string;
|
|
9
15
|
/** Error counts keyed by tab name — shows a danger badge when > 0. */
|
|
10
16
|
errorCounts?: Record<string, number>;
|
|
11
17
|
className?: string;
|
|
12
18
|
}
|
|
19
|
+
/** Id of the button for one tab. */
|
|
20
|
+
export declare const tabTriggerId: (idBase: string, name: string) => string;
|
|
21
|
+
/** Id the consumer must put on the panel belonging to one tab. */
|
|
22
|
+
export declare const tabPanelId: (idBase: string, name: string) => string;
|
|
13
23
|
/**
|
|
14
24
|
* Tabs navigation bar for admin form layouts.
|
|
15
25
|
*
|
|
16
|
-
* Used by FormRenderer when a CollectionAdminConfig declares a `tabs` array
|
|
17
|
-
*
|
|
18
|
-
*
|
|
26
|
+
* Used by FormRenderer when a CollectionAdminConfig declares a `tabs` array,
|
|
27
|
+
* and by the collection history view. The number of tabs a collection can
|
|
28
|
+
* declare is unbounded while the column they sit in is not, so the strip
|
|
29
|
+
* scrolls horizontally and — only once the tabs genuinely exceed the column —
|
|
30
|
+
* grows a menu listing every tab.
|
|
19
31
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
32
|
+
* The menu is a jump list rather than a list of the tabs that happen to be
|
|
33
|
+
* out of view: its contents stay put as the strip scrolls, and no tab ever
|
|
34
|
+
* changes position in the strip as a result of being selected. Editors learn
|
|
35
|
+
* where a tab lives and it stays there.
|
|
36
|
+
*
|
|
37
|
+
* Scroll position is moved only when the selection changes or a tab takes
|
|
38
|
+
* focus. A reader who scrolls the strip to look at other labels keeps their
|
|
39
|
+
* position through re-measurement, re-render and resize.
|
|
40
|
+
*
|
|
41
|
+
* Stable override handles: `.byline-admin-tabs`, `.byline-admin-tabs-viewport`,
|
|
42
|
+
* `.byline-admin-tablist`, `.byline-admin-tab`, `.byline-admin-tab-active`,
|
|
43
|
+
* `.byline-admin-tab-label`, `.byline-admin-tab-badge`,
|
|
44
|
+
* `.byline-admin-tabs-overflow-trigger`, `.byline-admin-tabs-overflow-menu`,
|
|
45
|
+
* `.byline-admin-tabs-overflow-item`.
|
|
23
46
|
*/
|
|
24
|
-
export declare const AdminTabs: ({ tabs, activeTab, onChange, errorCounts, className, }: AdminTabsProps) => import("react").JSX.Element;
|
|
47
|
+
export declare const AdminTabs: ({ tabs, activeTab, onChange, idBase, errorCounts, className, }: AdminTabsProps) => import("react").JSX.Element;
|
|
25
48
|
export {};
|