@embedpdf/react 3.0.0-next.14 → 3.0.0-next.16
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/AnnotationList-DcyhF2kU-CiBFOq1z.d.cts +878 -0
- package/dist/AnnotationList-DcyhF2kU-CiBFOq1z.d.ts +878 -0
- package/dist/actions.cjs +25 -5
- package/dist/actions.cjs.map +1 -1
- package/dist/actions.d.cts +18 -5
- package/dist/actions.d.ts +18 -5
- package/dist/actions.js +22 -6
- package/dist/actions.js.map +1 -1
- package/dist/anchored-DeX95xSd.d.ts +85 -0
- package/dist/anchored-DzN3JywS.d.cts +85 -0
- package/dist/anchored.cjs +71 -28
- package/dist/anchored.cjs.map +1 -1
- package/dist/anchored.d.cts +2 -45
- package/dist/anchored.d.ts +2 -45
- package/dist/anchored.js +56 -19
- package/dist/anchored.js.map +1 -1
- package/dist/annotation-3UvABfJm.d.cts +305 -0
- package/dist/annotation-BNHQpMKv.cjs +806 -0
- package/dist/annotation-BNHQpMKv.cjs.map +1 -0
- package/dist/annotation-CDI8CFb3.js +684 -0
- package/dist/annotation-CDI8CFb3.js.map +1 -0
- package/dist/annotation-DhEfs0pH.d.ts +305 -0
- package/dist/annotation.cjs +20 -784
- package/dist/annotation.d.cts +2 -2
- package/dist/annotation.d.ts +2 -2
- package/dist/annotation.js +2 -769
- package/dist/attachment.cjs +39 -0
- package/dist/attachment.cjs.map +1 -0
- package/dist/attachment.d.cts +29 -0
- package/dist/attachment.d.ts +29 -0
- package/dist/attachment.js +28 -0
- package/dist/attachment.js.map +1 -0
- package/dist/commands.cjs +68 -28
- package/dist/commands.cjs.map +1 -1
- package/dist/commands.d.cts +37 -10
- package/dist/commands.d.ts +37 -10
- package/dist/commands.js +68 -31
- package/dist/commands.js.map +1 -1
- package/dist/form-BSGvjA5D.js +511 -0
- package/dist/form-BSGvjA5D.js.map +1 -0
- package/dist/form-BgztZyOK.cjs +548 -0
- package/dist/form-BgztZyOK.cjs.map +1 -0
- package/dist/form.cjs +5 -5
- package/dist/form.d.cts +41 -2
- package/dist/form.d.ts +41 -2
- package/dist/form.js +2 -3
- package/dist/history.cjs +38 -0
- package/dist/history.cjs.map +1 -0
- package/dist/history.d.cts +27 -0
- package/dist/history.d.ts +27 -0
- package/dist/history.js +27 -0
- package/dist/history.js.map +1 -0
- package/dist/i18n.cjs +26 -30
- package/dist/i18n.cjs.map +1 -1
- package/dist/i18n.d.cts +24 -21
- package/dist/i18n.d.ts +24 -21
- package/dist/i18n.js +24 -31
- package/dist/i18n.js.map +1 -1
- package/dist/index.cjs +227 -57
- package/dist/index.d.cts +35 -32
- package/dist/index.d.ts +35 -32
- package/dist/index.js +36 -30
- package/dist/inert-CmBEbKCn.cjs +19 -0
- package/dist/inert-CmBEbKCn.cjs.map +1 -0
- package/dist/inert-D8fkennb.js +14 -0
- package/dist/inert-D8fkennb.js.map +1 -0
- package/dist/interaction.cjs +48 -102
- package/dist/interaction.cjs.map +1 -1
- package/dist/interaction.d.cts +23 -32
- package/dist/interaction.d.ts +23 -32
- package/dist/interaction.js +33 -102
- package/dist/interaction.js.map +1 -1
- package/dist/link.cjs +65 -104
- package/dist/link.cjs.map +1 -1
- package/dist/link.d.cts +21 -16
- package/dist/link.d.ts +22 -17
- package/dist/link.js +67 -107
- package/dist/link.js.map +1 -1
- package/dist/measurement.cjs +36 -11
- package/dist/measurement.cjs.map +1 -1
- package/dist/measurement.d.cts +33 -7
- package/dist/measurement.d.ts +33 -7
- package/dist/measurement.js +35 -14
- package/dist/measurement.js.map +1 -1
- package/dist/metadata.cjs +20 -7
- package/dist/metadata.cjs.map +1 -1
- package/dist/metadata.d.cts +22 -7
- package/dist/metadata.d.ts +22 -7
- package/dist/metadata.js +20 -10
- package/dist/metadata.js.map +1 -1
- package/dist/outline.cjs +39 -0
- package/dist/outline.cjs.map +1 -0
- package/dist/outline.d.cts +31 -0
- package/dist/outline.d.ts +31 -0
- package/dist/outline.js +28 -0
- package/dist/outline.js.map +1 -0
- package/dist/page-edit.cjs +15 -3
- package/dist/page-edit.cjs.map +1 -1
- package/dist/page-edit.d.cts +17 -2
- package/dist/page-edit.d.ts +17 -2
- package/dist/page-edit.js +15 -5
- package/dist/page-edit.js.map +1 -1
- package/dist/page-layers-Bkaaz8Zf.js +26 -0
- package/dist/page-layers-Bkaaz8Zf.js.map +1 -0
- package/dist/page-layers-BloZDoOV.cjs +37 -0
- package/dist/page-layers-BloZDoOV.cjs.map +1 -0
- package/dist/page-view.cjs +89 -82
- package/dist/page-view.cjs.map +1 -1
- package/dist/page-view.d.cts +14 -7
- package/dist/page-view.d.ts +18 -11
- package/dist/page-view.js +86 -81
- package/dist/page-view.js.map +1 -1
- package/dist/redaction.cjs +30 -15
- package/dist/redaction.cjs.map +1 -1
- package/dist/redaction.d.cts +27 -9
- package/dist/redaction.d.ts +27 -9
- package/dist/redaction.js +29 -18
- package/dist/redaction.js.map +1 -1
- package/dist/render.cjs +71 -46
- package/dist/render.cjs.map +1 -1
- package/dist/render.d.cts +17 -5
- package/dist/render.d.ts +17 -5
- package/dist/render.js +70 -49
- package/dist/render.js.map +1 -1
- package/dist/runtime-BfnpyfY0.cjs +556 -0
- package/dist/runtime-BfnpyfY0.cjs.map +1 -0
- package/dist/runtime-DBEBlpQV.d.cts +237 -0
- package/dist/runtime-V3MVMb91.d.ts +237 -0
- package/dist/runtime-tD5iJU83.js +399 -0
- package/dist/runtime-tD5iJU83.js.map +1 -0
- package/dist/runtime.cjs +45 -324
- package/dist/runtime.d.cts +2 -2
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.js +2 -306
- package/dist/search.cjs +81 -50
- package/dist/search.cjs.map +1 -1
- package/dist/search.d.cts +37 -24
- package/dist/search.d.ts +37 -24
- package/dist/search.js +81 -53
- package/dist/search.js.map +1 -1
- package/dist/selection.cjs +105 -108
- package/dist/selection.cjs.map +1 -1
- package/dist/selection.d.cts +54 -26
- package/dist/selection.d.ts +56 -28
- package/dist/selection.js +103 -110
- package/dist/selection.js.map +1 -1
- package/dist/shell.cjs +36 -21
- package/dist/shell.cjs.map +1 -1
- package/dist/shell.d.cts +32 -17
- package/dist/shell.d.ts +32 -17
- package/dist/shell.js +36 -24
- package/dist/shell.js.map +1 -1
- package/dist/signature.cjs +29 -48
- package/dist/signature.cjs.map +1 -1
- package/dist/signature.d.cts +26 -26
- package/dist/signature.d.ts +26 -26
- package/dist/signature.js +30 -48
- package/dist/signature.js.map +1 -1
- package/dist/stage-B7BG2e8Q.cjs +369 -0
- package/dist/stage-B7BG2e8Q.cjs.map +1 -0
- package/dist/stage-BqfBjDu6.js +302 -0
- package/dist/stage-BqfBjDu6.js.map +1 -0
- package/dist/stage-ByFPD-Fv.d.cts +117 -0
- package/dist/stage-DaboaheR.d.ts +117 -0
- package/dist/stage-scope-CQgCuf1w.cjs +46 -0
- package/dist/stage-scope-CQgCuf1w.cjs.map +1 -0
- package/dist/stage-scope-D7ZeNduT.js +23 -0
- package/dist/stage-scope-D7ZeNduT.js.map +1 -0
- package/dist/stage.cjs +12 -235
- package/dist/stage.d.cts +2 -116
- package/dist/stage.d.ts +2 -116
- package/dist/stage.js +3 -228
- package/dist/stamp.cjs +41 -35
- package/dist/stamp.cjs.map +1 -1
- package/dist/stamp.d.cts +25 -18
- package/dist/stamp.d.ts +25 -18
- package/dist/stamp.js +40 -37
- package/dist/stamp.js.map +1 -1
- package/dist/state-0K1I5cM4.d.cts +29 -0
- package/dist/state-0K1I5cM4.d.ts +29 -0
- package/dist/state-CzI2KlZb.js +62 -0
- package/dist/state-CzI2KlZb.js.map +1 -0
- package/dist/state-Dtf8HAue.cjs +73 -0
- package/dist/state-Dtf8HAue.cjs.map +1 -0
- package/dist/svg-shapes-Dm1yTR1b.js +40 -0
- package/dist/svg-shapes-Dm1yTR1b.js.map +1 -0
- package/dist/svg-shapes-zo0GNkc9.cjs +53 -0
- package/dist/svg-shapes-zo0GNkc9.cjs.map +1 -0
- package/dist/toolbar.cjs +297 -295
- package/dist/toolbar.cjs.map +1 -1
- package/dist/toolbar.d.cts +58 -68
- package/dist/toolbar.d.ts +67 -77
- package/dist/toolbar.js +271 -293
- package/dist/toolbar.js.map +1 -1
- package/dist/view-manager.cjs +34 -0
- package/dist/view-manager.cjs.map +1 -0
- package/dist/view-manager.d.cts +21 -0
- package/dist/view-manager.d.ts +21 -0
- package/dist/view-manager.js +23 -0
- package/dist/view-manager.js.map +1 -0
- package/package.json +47 -39
- package/dist/annotation-BCED_p9H.d.cts +0 -160
- package/dist/annotation-anchors-CetwM1g7.js +0 -15
- package/dist/annotation-anchors-CetwM1g7.js.map +0 -1
- package/dist/annotation-anchors-DuYRBJLl.cjs +0 -26
- package/dist/annotation-anchors-DuYRBJLl.cjs.map +0 -1
- package/dist/annotation-hooks-BB5ZhPpf.cjs +0 -16
- package/dist/annotation-hooks-BB5ZhPpf.cjs.map +0 -1
- package/dist/annotation-hooks-Df8EmzDO.js +0 -11
- package/dist/annotation-hooks-Df8EmzDO.js.map +0 -1
- package/dist/annotation-k38KDlIZ.d.ts +0 -160
- package/dist/annotation-menu.cjs +0 -64
- package/dist/annotation-menu.cjs.map +0 -1
- package/dist/annotation-menu.d.cts +0 -33
- package/dist/annotation-menu.d.ts +0 -33
- package/dist/annotation-menu.js +0 -48
- package/dist/annotation-menu.js.map +0 -1
- package/dist/annotation.cjs.map +0 -1
- package/dist/annotation.js.map +0 -1
- package/dist/form-BVumS7up.cjs +0 -926
- package/dist/form-BVumS7up.cjs.map +0 -1
- package/dist/form-Bdjk0Z3T.d.cts +0 -537
- package/dist/form-CK3mp99m.js +0 -895
- package/dist/form-CK3mp99m.js.map +0 -1
- package/dist/form-CYRYgthn.d.ts +0 -537
- package/dist/rolldown-runtime-BBjsoOtd.js +0 -27
- package/dist/runtime-DE76hlnl.d.ts +0 -216
- package/dist/runtime-umHA_xHt.d.cts +0 -216
- package/dist/runtime.cjs.map +0 -1
- package/dist/runtime.js.map +0 -1
- package/dist/scrollbar.cjs +0 -241
- package/dist/scrollbar.cjs.map +0 -1
- package/dist/scrollbar.d.cts +0 -42
- package/dist/scrollbar.d.ts +0 -42
- package/dist/scrollbar.js +0 -213
- package/dist/scrollbar.js.map +0 -1
- package/dist/stage.cjs.map +0 -1
- package/dist/stage.js.map +0 -1
- package/dist/views.cjs +0 -35
- package/dist/views.cjs.map +0 -1
- package/dist/views.d.cts +0 -21
- package/dist/views.d.ts +0 -21
- package/dist/views.js +0 -27
- package/dist/views.js.map +0 -1
package/dist/toolbar.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { b as useKernel, f as useCapability, h as useDocumentId, x as useKernelValue } from "./runtime-tD5iJU83.js";
|
|
2
|
+
import { t as INERT } from "./inert-D8fkennb.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { TOOLBAR_ITEM_ATTRIBUTE, attachMenuKeys, attachToolbarFocus, createToolbarLengths, focusablesIn, observeContentLength, observeLength, observeOutsidePress, paintDefault, toolbarMeasureKey } from "@embedpdf/web";
|
|
5
|
+
import * as React$1 from "react";
|
|
5
6
|
import { useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState } from "react";
|
|
6
|
-
import {
|
|
7
|
-
import { CommandsToken
|
|
8
|
-
|
|
7
|
+
import { DEFAULT_IMPORTANCE, PINNED, custom, group, groupMenuView, item, layoutToolbar, normalizeBar, sameStripGroups, stripGroupsOf } from "@embedpdf/core-ui";
|
|
8
|
+
import { CommandsToken } from "@embedpdf/plugin-commands/contract/host";
|
|
9
|
+
import { resolvedCommandsEqual, unregisteredCommand } from "@embedpdf/plugin-commands/contract";
|
|
9
10
|
//#region src/toolbar.tsx
|
|
10
|
-
const stripGroupsEqual = (
|
|
11
|
+
const stripGroupsEqual = (left, right) => sameStripGroups(left, right, resolvedCommandsEqual);
|
|
11
12
|
const NO_STRIP_GROUPS = [];
|
|
12
13
|
/**
|
|
13
14
|
* The live projection of a bar through the command registry — <Toolbar>'s
|
|
14
|
-
* un-measured sibling, for contextual strips (
|
|
15
|
-
* declares what
|
|
16
|
-
*
|
|
15
|
+
* un-measured sibling, for contextual strips (a bar over a selection). The schema
|
|
16
|
+
* declares what could appear; each command's `visible` derivation decides what
|
|
17
|
+
* does; null means nothing currently applies, so `if (!view) return null` is
|
|
17
18
|
* the caller's entire show/hide logic. `execute` is pre-bound to this
|
|
18
19
|
* subtree's document. Reads are value-equal (resolvedCommandsEqual), so
|
|
19
20
|
* consumers re-render on real change, not on every store action.
|
|
@@ -22,41 +23,24 @@ function useStripView(bar) {
|
|
|
22
23
|
const commands = useCapability(CommandsToken);
|
|
23
24
|
const documentId = useDocumentId();
|
|
24
25
|
const normalized = useMemo(() => bar ? normalizeBar(bar) : null, [bar]);
|
|
25
|
-
const groups = useKernelValue(() =>
|
|
26
|
-
if (!normalized) return NO_STRIP_GROUPS;
|
|
27
|
-
const resolved = /* @__PURE__ */ new Map();
|
|
28
|
-
const visible = (id) => {
|
|
29
|
-
const cmd = commands.resolve(id, documentId ?? void 0);
|
|
30
|
-
if (cmd) resolved.set(id, cmd);
|
|
31
|
-
return cmd?.visible === true;
|
|
32
|
-
};
|
|
33
|
-
return projectStrip(normalized, visible).map((g) => ({
|
|
34
|
-
id: g.id,
|
|
35
|
-
labelKey: g.labelKey,
|
|
36
|
-
commands: g.commands.map((id) => resolved.get(id))
|
|
37
|
-
}));
|
|
38
|
-
}, stripGroupsEqual);
|
|
26
|
+
const groups = useKernelValue(() => normalized ? stripGroupsOf(normalized, (id) => commands.resolveCommand(id, documentId ?? void 0)) : NO_STRIP_GROUPS, stripGroupsEqual);
|
|
39
27
|
return useMemo(() => groups.length === 0 ? null : {
|
|
40
28
|
groups,
|
|
41
|
-
execute: (id) => commands.execute(id, documentId ?? void 0)
|
|
29
|
+
execute: (id) => void commands.execute(id, { documentId: documentId ?? void 0 })
|
|
42
30
|
}, [
|
|
43
31
|
groups,
|
|
44
32
|
commands,
|
|
45
33
|
documentId
|
|
46
34
|
]);
|
|
47
35
|
}
|
|
48
|
-
/** Report this node's border-box
|
|
49
|
-
function Measured({ k,
|
|
36
|
+
/** Report this node's border-box length along the toolbar under `k`, live. */
|
|
37
|
+
function Measured({ k, orientation, onLength, children }) {
|
|
50
38
|
const ref = useRef(null);
|
|
51
|
-
useLayoutEffect(() =>
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const observer = new ResizeObserver(report);
|
|
57
|
-
observer.observe(el);
|
|
58
|
-
return () => observer.disconnect();
|
|
59
|
-
}, [k, onWidth]);
|
|
39
|
+
useLayoutEffect(() => ref.current ? observeLength(ref.current, orientation, (length) => onLength(k, length)) : void 0, [
|
|
40
|
+
k,
|
|
41
|
+
orientation,
|
|
42
|
+
onLength
|
|
43
|
+
]);
|
|
60
44
|
return /* @__PURE__ */ jsx("span", {
|
|
61
45
|
ref,
|
|
62
46
|
style: {
|
|
@@ -70,20 +54,16 @@ function Measured({ k, onWidth, children }) {
|
|
|
70
54
|
* The socket for an unregistered custom unit: a real `<slot>` element. Inside
|
|
71
55
|
* the <embedpdf-viewer> shadow root the browser projects same-named light-DOM
|
|
72
56
|
* children into it; anywhere else it just displays its fallback (the terminal
|
|
73
|
-
* command). Measured live — the projected content lives in the
|
|
74
|
-
* so its
|
|
57
|
+
* command). Measured live — the projected content lives in the host's world,
|
|
58
|
+
* so its length can only be observed where it actually renders.
|
|
75
59
|
*/
|
|
76
|
-
function NativeSlotSocket({ name, k,
|
|
60
|
+
function NativeSlotSocket({ name, k, orientation, onLength, children }) {
|
|
77
61
|
const ref = useRef(null);
|
|
78
|
-
useLayoutEffect(() =>
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const observer = new ResizeObserver(report);
|
|
84
|
-
observer.observe(el);
|
|
85
|
-
return () => observer.disconnect();
|
|
86
|
-
}, [k, onWidth]);
|
|
62
|
+
useLayoutEffect(() => ref.current ? observeLength(ref.current, orientation, (length) => onLength(k, length)) : void 0, [
|
|
63
|
+
k,
|
|
64
|
+
orientation,
|
|
65
|
+
onLength
|
|
66
|
+
]);
|
|
87
67
|
return /* @__PURE__ */ jsx("slot", {
|
|
88
68
|
ref,
|
|
89
69
|
name,
|
|
@@ -95,7 +75,13 @@ function NativeSlotSocket({ name, k, onWidth, children }) {
|
|
|
95
75
|
children
|
|
96
76
|
});
|
|
97
77
|
}
|
|
98
|
-
|
|
78
|
+
/**
|
|
79
|
+
* The hidden measurement layer: a row for a horizontal toolbar, a column for a
|
|
80
|
+
* vertical one, and no height either way, so it never adds to the page. A
|
|
81
|
+
* column keeps each item at its own width, so no text wraps and changes the
|
|
82
|
+
* heights it reports.
|
|
83
|
+
*/
|
|
84
|
+
const measureLayerStyle = (orientation) => ({
|
|
99
85
|
position: "absolute",
|
|
100
86
|
left: 0,
|
|
101
87
|
top: 0,
|
|
@@ -104,9 +90,20 @@ const measureLayerStyle = {
|
|
|
104
90
|
visibility: "hidden",
|
|
105
91
|
pointerEvents: "none",
|
|
106
92
|
display: "flex",
|
|
107
|
-
whiteSpace: "nowrap"
|
|
108
|
-
|
|
109
|
-
|
|
93
|
+
whiteSpace: "nowrap",
|
|
94
|
+
...orientation === "vertical" ? {
|
|
95
|
+
flexDirection: "column",
|
|
96
|
+
alignItems: "flex-start"
|
|
97
|
+
} : null
|
|
98
|
+
});
|
|
99
|
+
/** Marks the element around each item of the live row: its first focusable element is a stop. */
|
|
100
|
+
const TOOLBAR_ITEM = { [TOOLBAR_ITEM_ATTRIBUTE]: "" };
|
|
101
|
+
/** The element around an item adds no box, so the item lays out as the section's own child. */
|
|
102
|
+
const ITEM_STYLE = { display: "contents" };
|
|
103
|
+
const SURFACE = paintDefault("toolbar-surface");
|
|
104
|
+
const BORDER = paintDefault("toolbar-border");
|
|
105
|
+
const ACTIVE = paintDefault("toolbar-active");
|
|
106
|
+
const defaultRenderCommand = (cmd, _variant, run) => /* @__PURE__ */ jsx("button", {
|
|
110
107
|
type: "button",
|
|
111
108
|
onClick: run,
|
|
112
109
|
disabled: !cmd.enabled,
|
|
@@ -119,20 +116,25 @@ const defaultRenderCommand = (cmd, variant, run) => /* @__PURE__ */ jsxs("button
|
|
|
119
116
|
gap: 4,
|
|
120
117
|
padding: "4px 8px",
|
|
121
118
|
whiteSpace: "nowrap",
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
color: "inherit",
|
|
120
|
+
font: "inherit",
|
|
121
|
+
background: cmd.active ? ACTIVE : "transparent",
|
|
122
|
+
border: `1px solid ${BORDER}`,
|
|
124
123
|
borderRadius: 4,
|
|
125
124
|
cursor: cmd.enabled ? "pointer" : "default",
|
|
126
125
|
opacity: cmd.enabled ? 1 : .4
|
|
127
126
|
},
|
|
128
|
-
children:
|
|
127
|
+
children: cmd.label
|
|
129
128
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
129
|
+
/** A 1px line across the toolbar: upright in a horizontal one, flat in a vertical one. */
|
|
130
|
+
function DefaultSeparator({ orientation }) {
|
|
131
|
+
return /* @__PURE__ */ jsx("span", { style: {
|
|
132
|
+
...orientation === "vertical" ? { height: 1 } : { width: 1 },
|
|
133
|
+
alignSelf: "stretch",
|
|
134
|
+
background: "currentColor",
|
|
135
|
+
opacity: .2
|
|
136
|
+
} });
|
|
137
|
+
}
|
|
136
138
|
const defaultRenderOverflowTrigger = (isOpen, toggle) => /* @__PURE__ */ jsx("button", {
|
|
137
139
|
type: "button",
|
|
138
140
|
onClick: toggle,
|
|
@@ -143,39 +145,64 @@ const defaultRenderOverflowTrigger = (isOpen, toggle) => /* @__PURE__ */ jsx("bu
|
|
|
143
145
|
display: "inline-flex",
|
|
144
146
|
alignItems: "center",
|
|
145
147
|
padding: "4px 8px",
|
|
146
|
-
|
|
148
|
+
color: "inherit",
|
|
149
|
+
font: "inherit",
|
|
150
|
+
border: `1px solid ${BORDER}`,
|
|
147
151
|
borderRadius: 4,
|
|
148
|
-
background: isOpen ?
|
|
152
|
+
background: isOpen ? ACTIVE : "transparent",
|
|
149
153
|
cursor: "pointer"
|
|
150
154
|
},
|
|
151
155
|
children: "⋯"
|
|
152
156
|
});
|
|
153
|
-
|
|
157
|
+
/** Where a default menu opens: under a horizontal toolbar's button, beside a vertical one's. */
|
|
158
|
+
const menuPlacement = (orientation) => orientation === "vertical" ? {
|
|
159
|
+
top: 0,
|
|
160
|
+
insetInlineStart: "100%"
|
|
161
|
+
} : {
|
|
162
|
+
top: "100%",
|
|
163
|
+
insetInlineEnd: 0
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* The default menu, opened by the button beside it in the same parent: it
|
|
167
|
+
* closes on a press outside that parent, and takes the menu keys while open.
|
|
168
|
+
*/
|
|
169
|
+
function DefaultOverflowMenu({ view, orientation }) {
|
|
170
|
+
const menu = useRef(null);
|
|
171
|
+
const close = useRef(view.close);
|
|
172
|
+
close.current = view.close;
|
|
173
|
+
useLayoutEffect(() => {
|
|
174
|
+
const element = menu.current;
|
|
175
|
+
if (!view.isOpen || !element) return;
|
|
176
|
+
const container = element.parentElement ?? element;
|
|
177
|
+
const trigger = focusablesIn(container).find((candidate) => !element.contains(candidate)) ?? null;
|
|
178
|
+
const stopOutside = observeOutsidePress(container, () => close.current());
|
|
179
|
+
const detachKeys = attachMenuKeys(element, {
|
|
180
|
+
trigger,
|
|
181
|
+
close: () => close.current()
|
|
182
|
+
});
|
|
183
|
+
return () => {
|
|
184
|
+
stopOutside();
|
|
185
|
+
detachKeys();
|
|
186
|
+
};
|
|
187
|
+
}, [view.isOpen]);
|
|
154
188
|
if (!view.isOpen) return null;
|
|
155
|
-
return /* @__PURE__ */
|
|
156
|
-
|
|
157
|
-
position: "fixed",
|
|
158
|
-
inset: 0,
|
|
159
|
-
zIndex: 40
|
|
160
|
-
},
|
|
161
|
-
onClick: view.close
|
|
162
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
189
|
+
return /* @__PURE__ */ jsx("div", {
|
|
190
|
+
ref: menu,
|
|
163
191
|
role: "menu",
|
|
164
192
|
style: {
|
|
165
193
|
position: "absolute",
|
|
166
|
-
|
|
167
|
-
top: "100%",
|
|
194
|
+
...menuPlacement(orientation),
|
|
168
195
|
zIndex: 41,
|
|
169
196
|
minWidth: 200,
|
|
170
197
|
padding: 4,
|
|
171
|
-
background:
|
|
172
|
-
border:
|
|
198
|
+
background: SURFACE,
|
|
199
|
+
border: `1px solid ${BORDER}`,
|
|
173
200
|
borderRadius: 6,
|
|
174
201
|
boxShadow: "0 4px 16px rgba(0,0,0,0.15)"
|
|
175
202
|
},
|
|
176
|
-
children: view.sections.map((section, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [i > 0 && /* @__PURE__ */ jsx("div", { style: {
|
|
203
|
+
children: view.sections.map((section, i) => /* @__PURE__ */ jsxs(React$1.Fragment, { children: [i > 0 && /* @__PURE__ */ jsx("div", { style: {
|
|
177
204
|
height: 1,
|
|
178
|
-
background:
|
|
205
|
+
background: BORDER,
|
|
179
206
|
margin: "4px 0"
|
|
180
207
|
} }), section.rows.map((row) => {
|
|
181
208
|
const cmd = view.resolve(row.command);
|
|
@@ -186,6 +213,7 @@ function DefaultOverflowMenu({ view }) {
|
|
|
186
213
|
role: section.role === "radio" ? "menuitemradio" : "menuitem",
|
|
187
214
|
"aria-checked": section.role === "radio" ? cmd.active : void 0,
|
|
188
215
|
disabled: !cmd.enabled,
|
|
216
|
+
tabIndex: -1,
|
|
189
217
|
onClick: () => {
|
|
190
218
|
view.execute(row.command);
|
|
191
219
|
if (!isSubmenu) view.close();
|
|
@@ -198,6 +226,8 @@ function DefaultOverflowMenu({ view }) {
|
|
|
198
226
|
gap: 16,
|
|
199
227
|
padding: "6px 8px",
|
|
200
228
|
border: "none",
|
|
229
|
+
color: "inherit",
|
|
230
|
+
font: "inherit",
|
|
201
231
|
background: "transparent",
|
|
202
232
|
cursor: cmd.enabled ? "pointer" : "default",
|
|
203
233
|
opacity: cmd.enabled ? 1 : .4,
|
|
@@ -206,61 +236,48 @@ function DefaultOverflowMenu({ view }) {
|
|
|
206
236
|
children: [/* @__PURE__ */ jsxs("span", { children: [cmd.active && section.role === "radio" ? "• " : "", cmd.label] }), isSubmenu ? /* @__PURE__ */ jsx("span", { children: "▸" }) : null]
|
|
207
237
|
}, row.command);
|
|
208
238
|
})] }, i))
|
|
209
|
-
})
|
|
239
|
+
});
|
|
210
240
|
}
|
|
211
|
-
function DefaultCollapsed({ view }) {
|
|
241
|
+
function DefaultCollapsed({ view, orientation }) {
|
|
212
242
|
if (view.collapse === "select") return /* @__PURE__ */ jsx("select", {
|
|
213
|
-
value: view.commands.find((
|
|
214
|
-
onChange: (
|
|
243
|
+
value: view.commands.find((command) => command.active)?.id ?? "",
|
|
244
|
+
onChange: (event) => view.execute(event.target.value),
|
|
215
245
|
style: {
|
|
216
246
|
padding: "4px 6px",
|
|
217
|
-
|
|
247
|
+
font: "inherit",
|
|
248
|
+
borderRadius: 4,
|
|
249
|
+
border: `1px solid ${BORDER}`,
|
|
250
|
+
background: SURFACE
|
|
218
251
|
},
|
|
219
|
-
children: view.commands.map((
|
|
220
|
-
value:
|
|
221
|
-
disabled: !
|
|
222
|
-
children:
|
|
223
|
-
},
|
|
252
|
+
children: view.commands.map((command) => /* @__PURE__ */ jsx("option", {
|
|
253
|
+
value: command.id,
|
|
254
|
+
disabled: !command.enabled,
|
|
255
|
+
children: command.label
|
|
256
|
+
}, command.id))
|
|
257
|
+
});
|
|
258
|
+
return /* @__PURE__ */ jsx(CollapsedMenuButton, {
|
|
259
|
+
view,
|
|
260
|
+
orientation
|
|
224
261
|
});
|
|
225
|
-
return /* @__PURE__ */ jsx(CollapsedMenuButton, { view });
|
|
226
262
|
}
|
|
227
|
-
function CollapsedMenuButton({ view }) {
|
|
263
|
+
function CollapsedMenuButton({ view, orientation }) {
|
|
228
264
|
const [isOpen, setOpen] = useState(false);
|
|
229
|
-
const sections = [{
|
|
230
|
-
labelKey: view.labelKey,
|
|
231
|
-
role: view.role === "tabs" ? "radio" : void 0,
|
|
232
|
-
rows: view.commands.map((c) => ({
|
|
233
|
-
type: "command",
|
|
234
|
-
command: c.id
|
|
235
|
-
}))
|
|
236
|
-
}];
|
|
237
265
|
return /* @__PURE__ */ jsxs("span", {
|
|
238
266
|
style: {
|
|
239
267
|
position: "relative",
|
|
240
268
|
display: "inline-flex"
|
|
241
269
|
},
|
|
242
|
-
children: [defaultRenderOverflowTrigger(isOpen, () => setOpen((
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
resolve: (id) => view.commands.find((c) => c.id === id) ?? null,
|
|
247
|
-
execute: view.execute
|
|
248
|
-
} })]
|
|
270
|
+
children: [defaultRenderOverflowTrigger(isOpen, () => setOpen((previous) => !previous)), /* @__PURE__ */ jsx(DefaultOverflowMenu, {
|
|
271
|
+
view: groupMenuView(view, isOpen, () => setOpen(false)),
|
|
272
|
+
orientation
|
|
273
|
+
})]
|
|
249
274
|
});
|
|
250
275
|
}
|
|
251
276
|
/** Default shed-group disclosure: a chevron opening a radio menu of the
|
|
252
|
-
* hidden children
|
|
253
|
-
function DefaultGroupTrigger({ view }) {
|
|
277
|
+
* hidden children. */
|
|
278
|
+
function DefaultGroupTrigger({ view, orientation }) {
|
|
254
279
|
const [isOpen, setOpen] = useState(false);
|
|
255
|
-
const someActive = view.commands.some((
|
|
256
|
-
const sections = [{
|
|
257
|
-
labelKey: view.labelKey,
|
|
258
|
-
role: view.role === "tabs" ? "radio" : void 0,
|
|
259
|
-
rows: view.commands.map((c) => ({
|
|
260
|
-
type: "command",
|
|
261
|
-
command: c.id
|
|
262
|
-
}))
|
|
263
|
-
}];
|
|
280
|
+
const someActive = view.commands.some((command) => command.active);
|
|
264
281
|
return /* @__PURE__ */ jsxs("span", {
|
|
265
282
|
style: {
|
|
266
283
|
position: "relative",
|
|
@@ -268,7 +285,7 @@ function DefaultGroupTrigger({ view }) {
|
|
|
268
285
|
},
|
|
269
286
|
children: [/* @__PURE__ */ jsx("button", {
|
|
270
287
|
type: "button",
|
|
271
|
-
onClick: () => setOpen((
|
|
288
|
+
onClick: () => setOpen((previous) => !previous),
|
|
272
289
|
"aria-haspopup": "menu",
|
|
273
290
|
"aria-expanded": isOpen,
|
|
274
291
|
title: "More",
|
|
@@ -276,169 +293,138 @@ function DefaultGroupTrigger({ view }) {
|
|
|
276
293
|
display: "inline-flex",
|
|
277
294
|
alignItems: "center",
|
|
278
295
|
padding: "4px 6px",
|
|
279
|
-
|
|
296
|
+
color: "inherit",
|
|
297
|
+
font: "inherit",
|
|
298
|
+
border: `1px solid ${BORDER}`,
|
|
280
299
|
borderRadius: 4,
|
|
281
|
-
background: isOpen || someActive ?
|
|
300
|
+
background: isOpen || someActive ? ACTIVE : "transparent",
|
|
282
301
|
cursor: "pointer"
|
|
283
302
|
},
|
|
284
303
|
children: "▾"
|
|
285
|
-
}), /* @__PURE__ */ jsx(DefaultOverflowMenu, {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
resolve: (id) => view.commands.find((c) => c.id === id) ?? null,
|
|
290
|
-
execute: view.execute
|
|
291
|
-
} })]
|
|
304
|
+
}), /* @__PURE__ */ jsx(DefaultOverflowMenu, {
|
|
305
|
+
view: groupMenuView(view, isOpen, () => setOpen(false)),
|
|
306
|
+
orientation
|
|
307
|
+
})]
|
|
292
308
|
});
|
|
293
309
|
}
|
|
294
|
-
|
|
295
|
-
const groupKey = (id) => `g:${id}`;
|
|
296
|
-
const groupTriggerKey = (id) => `gt:${id}`;
|
|
297
|
-
const TRIGGER_KEY = "t:";
|
|
298
|
-
function Toolbar({ bar, gap = 8, separatorWidth = 1, className, style, renderCommand = defaultRenderCommand, renderCustom, renderCollapsed, renderGroupTrigger, renderSeparator = defaultRenderSeparator, renderOverflowTrigger = defaultRenderOverflowTrigger, renderOverflowMenu }) {
|
|
310
|
+
function Toolbar({ bar, orientation = "horizontal", gap = 8, separatorWidth = 1, "aria-label": ariaLabel, className, style, renderCommand = defaultRenderCommand, renderCustom, renderCollapsed, renderGroupTrigger, renderSeparator, renderOverflowTrigger = defaultRenderOverflowTrigger, renderOverflowMenu }) {
|
|
299
311
|
const kernel = useKernel();
|
|
300
312
|
const commands = useCapability(CommandsToken);
|
|
301
313
|
const documentId = useDocumentId();
|
|
314
|
+
const vertical = orientation === "vertical";
|
|
302
315
|
const [, force] = useReducer((x) => x + 1, 0);
|
|
303
316
|
useEffect(() => kernel.subscribe(force), [kernel]);
|
|
304
317
|
const containerRef = useRef(null);
|
|
305
|
-
const [
|
|
318
|
+
const [containerLength, setContainerLength] = useState(0);
|
|
319
|
+
useLayoutEffect(() => containerRef.current ? observeContentLength(containerRef.current, orientation, setContainerLength) : void 0, [orientation]);
|
|
320
|
+
const [lengths] = useState(createToolbarLengths);
|
|
321
|
+
const [, bumpMeasureVersion] = useReducer((version) => version + 1, 0);
|
|
322
|
+
const onLength = useMemo(() => (key, length) => {
|
|
323
|
+
if (lengths.report(orientation, key, length)) bumpMeasureVersion();
|
|
324
|
+
}, [lengths, orientation]);
|
|
325
|
+
const roving = useRef(null);
|
|
306
326
|
useLayoutEffect(() => {
|
|
307
|
-
const
|
|
308
|
-
if (!
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const
|
|
318
|
-
const
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
unit: (key, variant) => widthsRef.current.get(`u:${key}@${variant}`),
|
|
331
|
-
groupCollapsed: (id) => widthsRef.current.get(groupKey(id)),
|
|
332
|
-
groupTrigger: (id) => widthsRef.current.get(groupTriggerKey(id)),
|
|
333
|
-
overflowTrigger: widthsRef.current.get(TRIGGER_KEY) ?? 32,
|
|
334
|
-
gap,
|
|
335
|
-
separator: separatorWidth + gap
|
|
336
|
-
}, containerWidth);
|
|
337
|
-
const overflowSections = projectOverflow(visibleBar, fit, (id) => commands.menuTarget(id));
|
|
327
|
+
const toolbar = containerRef.current;
|
|
328
|
+
if (!toolbar) return;
|
|
329
|
+
const focus = attachToolbarFocus(toolbar, orientation);
|
|
330
|
+
roving.current = focus;
|
|
331
|
+
return () => {
|
|
332
|
+
focus.detach();
|
|
333
|
+
roving.current = null;
|
|
334
|
+
};
|
|
335
|
+
}, [orientation]);
|
|
336
|
+
useLayoutEffect(() => roving.current?.refresh());
|
|
337
|
+
const resolveCmd = (id) => commands.resolveCommand(id, documentId ?? void 0);
|
|
338
|
+
const executeCmd = (id) => void commands.execute(id, { documentId: documentId ?? void 0 });
|
|
339
|
+
const layout = layoutToolbar({
|
|
340
|
+
bar: useMemo(() => normalizeBar(bar), [bar]),
|
|
341
|
+
resolve: resolveCmd,
|
|
342
|
+
unregistered: unregisteredCommand,
|
|
343
|
+
execute: executeCmd,
|
|
344
|
+
menuTarget: (id) => commands.getMenuTarget(id),
|
|
345
|
+
metrics: lengths.metrics(orientation, gap, separatorWidth),
|
|
346
|
+
measureKey: toolbarMeasureKey,
|
|
347
|
+
containerLength,
|
|
348
|
+
orientation
|
|
349
|
+
});
|
|
338
350
|
const [overflowOpen, setOverflowOpen] = useState(false);
|
|
339
351
|
useEffect(() => {
|
|
340
|
-
if (!
|
|
341
|
-
}, [
|
|
342
|
-
/** External = custom
|
|
343
|
-
* live-measured (it must
|
|
352
|
+
if (!layout.hasOverflow) setOverflowOpen(false);
|
|
353
|
+
}, [layout.hasOverflow]);
|
|
354
|
+
/** External = custom part with no registered renderer → native socket,
|
|
355
|
+
* live-measured (it must not appear in the measurement layer: only the
|
|
344
356
|
* first same-named <slot> in tree order receives the projected nodes). */
|
|
345
|
-
const isExternalSlot = (
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
+
const isExternalSlot = (part) => part.kind === "custom" && !renderCustom?.[part.name];
|
|
358
|
+
const renderPart = (part, layer) => {
|
|
359
|
+
switch (part.kind) {
|
|
360
|
+
case "command": return renderCommand(part.command, part.variant, part.run);
|
|
361
|
+
case "custom": {
|
|
362
|
+
const terminal = () => part.terminal ? renderCommand(part.terminal, "icon", part.runTerminal) : null;
|
|
363
|
+
const registered = renderCustom?.[part.name];
|
|
364
|
+
if (registered) {
|
|
365
|
+
const custom = registered(part.variant, {
|
|
366
|
+
layer,
|
|
367
|
+
measure: (length) => onLength(part.measureKey, length)
|
|
368
|
+
});
|
|
369
|
+
return custom === void 0 ? terminal() : custom;
|
|
370
|
+
}
|
|
371
|
+
if (layer === "measure") return null;
|
|
357
372
|
return /* @__PURE__ */ jsx(NativeSlotSocket, {
|
|
358
|
-
name:
|
|
359
|
-
k:
|
|
360
|
-
|
|
361
|
-
|
|
373
|
+
name: part.name,
|
|
374
|
+
k: part.measureKey,
|
|
375
|
+
orientation,
|
|
376
|
+
onLength,
|
|
377
|
+
children: terminal()
|
|
362
378
|
});
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
379
|
+
}
|
|
380
|
+
case "collapsed": {
|
|
381
|
+
const drawn = renderCollapsed?.(part.view);
|
|
382
|
+
return drawn === void 0 ? /* @__PURE__ */ jsx(DefaultCollapsed, {
|
|
383
|
+
view: part.view,
|
|
384
|
+
orientation
|
|
385
|
+
}) : drawn;
|
|
386
|
+
}
|
|
387
|
+
case "disclosure": {
|
|
388
|
+
const drawn = renderGroupTrigger?.(part.view);
|
|
389
|
+
return drawn === void 0 ? /* @__PURE__ */ jsx(DefaultGroupTrigger, {
|
|
390
|
+
view: part.view,
|
|
391
|
+
orientation
|
|
392
|
+
}) : drawn;
|
|
393
|
+
}
|
|
366
394
|
}
|
|
367
|
-
const cmd = resolveCmd(u.command);
|
|
368
|
-
if (!cmd) return renderCommand({
|
|
369
|
-
id: u.command,
|
|
370
|
-
label: u.command,
|
|
371
|
-
shortcuts: [],
|
|
372
|
-
enabled: false,
|
|
373
|
-
active: false,
|
|
374
|
-
visible: true,
|
|
375
|
-
categories: []
|
|
376
|
-
}, variant, () => {});
|
|
377
|
-
return renderCommand(cmd, variant, () => executeCmd(u.command));
|
|
378
395
|
};
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
commands: g.units.map((u) => resolveCmd(commandOf(u))).filter((c) => c !== null && c.visible),
|
|
385
|
-
execute: executeCmd
|
|
386
|
-
});
|
|
387
|
-
const renderCollapsedGroup = (g) => renderCollapsed ? renderCollapsed(collapsedView(g)) : /* @__PURE__ */ jsx(DefaultCollapsed, { view: collapsedView(g) });
|
|
388
|
-
/** The disclosure view: shed children for the live trigger; the WHOLE group
|
|
389
|
-
* for the measured trigger, so width is budgeted at its fullest content. */
|
|
390
|
-
const disclosureView = (g, allChildren) => ({
|
|
391
|
-
id: g.id,
|
|
392
|
-
labelKey: g.labelKey,
|
|
393
|
-
role: g.role,
|
|
394
|
-
commands: g.units.filter((u) => allChildren || fit.units.get(u.key)?.kind === "shed").map((u) => resolveCmd(commandOf(u))).filter((c) => c !== null && c.visible),
|
|
395
|
-
execute: executeCmd
|
|
396
|
-
});
|
|
397
|
-
const renderDisclosure = (g, allChildren) => renderGroupTrigger ? renderGroupTrigger(disclosureView(g, allChildren)) : /* @__PURE__ */ jsx(DefaultGroupTrigger, { view: disclosureView(g, allChildren) });
|
|
398
|
-
const renderLiveGroup = (g) => {
|
|
399
|
-
const assignment = fit.groups.get(g.id);
|
|
400
|
-
if (!assignment || assignment.overflowed) return [];
|
|
401
|
-
if (assignment.collapsed) return [/* @__PURE__ */ jsx(React.Fragment, { children: renderCollapsedGroup(g) }, g.id)];
|
|
402
|
-
const nodes = [];
|
|
403
|
-
for (const u of g.units) {
|
|
404
|
-
const a = fit.units.get(u.key);
|
|
405
|
-
if (a?.kind !== "variant") continue;
|
|
406
|
-
nodes.push(/* @__PURE__ */ jsx(React.Fragment, { children: renderUnitAt(u, a.variant, "live") }, u.key));
|
|
407
|
-
}
|
|
408
|
-
if (assignment.shedCount > 0) nodes.push(/* @__PURE__ */ jsx(React.Fragment, { children: renderDisclosure(g, false) }, `${g.id}::trigger`));
|
|
409
|
-
return nodes.length ? [/* @__PURE__ */ jsx(React.Fragment, { children: nodes }, g.id)] : [];
|
|
410
|
-
};
|
|
411
|
-
const renderLiveSection = (section) => {
|
|
412
|
-
if (!section) return null;
|
|
413
|
-
return section.groups.map((g) => ({
|
|
414
|
-
id: g.id,
|
|
415
|
-
nodes: renderLiveGroup(g)
|
|
416
|
-
})).filter((g) => g.nodes.length > 0).map((g, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [i > 0 && renderSeparator(), g.nodes] }, g.id));
|
|
417
|
-
};
|
|
418
|
-
const sectionByName = (name) => visibleBar.sections.find((s) => s.name === name);
|
|
396
|
+
const renderLiveSection = (section) => section.groups.map((group, i) => /* @__PURE__ */ jsxs(React$1.Fragment, { children: [i > 0 && (renderSeparator ? renderSeparator() : /* @__PURE__ */ jsx(DefaultSeparator, { orientation })), group.parts.map((part) => /* @__PURE__ */ jsx("span", {
|
|
397
|
+
...TOOLBAR_ITEM,
|
|
398
|
+
style: ITEM_STYLE,
|
|
399
|
+
children: renderPart(part, "live")
|
|
400
|
+
}, part.key))] }, group.id));
|
|
419
401
|
/**
|
|
420
|
-
* Segment layout
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
* per-unit gaps) is exactly the layout's minimum
|
|
402
|
+
* Segment layout, along the toolbar's axis. The center segment carries auto
|
|
403
|
+
* margins: it balances in the leftover space (true center when the flanks
|
|
404
|
+
* are symmetric) and yields when they aren't, collapsing to zero before
|
|
405
|
+
* anything can overlap. The container itself has no gap — segments space
|
|
406
|
+
* themselves — so the solver's global budget (sum of unit lengths +
|
|
407
|
+
* per-unit gaps) is exactly the layout's minimum length: what the solver
|
|
426
408
|
* says fits, fits. Its cross-segment gap allowance (≤ 2×gap) becomes slack
|
|
427
409
|
* the auto margins absorb, keeping ≥ gap between segments at the floor.
|
|
428
|
-
* Segments never grow or shrink: fit is the
|
|
410
|
+
* Segments never grow or shrink: fit is the solver's job, not flexbox's.
|
|
429
411
|
*/
|
|
430
412
|
const sectionStyle = (position) => ({
|
|
431
413
|
display: "flex",
|
|
414
|
+
flexDirection: vertical ? "column" : "row",
|
|
432
415
|
alignItems: "center",
|
|
433
416
|
gap,
|
|
434
417
|
flex: "0 0 auto",
|
|
435
|
-
...position
|
|
418
|
+
...position !== "center" ? null : vertical ? {
|
|
419
|
+
marginTop: "auto",
|
|
420
|
+
marginBottom: "auto"
|
|
421
|
+
} : {
|
|
436
422
|
marginLeft: "auto",
|
|
437
423
|
marginRight: "auto"
|
|
438
|
-
}
|
|
424
|
+
}
|
|
439
425
|
});
|
|
440
426
|
const overflowView = {
|
|
441
|
-
sections:
|
|
427
|
+
sections: layout.overflow,
|
|
442
428
|
isOpen: overflowOpen,
|
|
443
429
|
close: () => setOverflowOpen(false),
|
|
444
430
|
resolve: resolveCmd,
|
|
@@ -446,61 +432,53 @@ function Toolbar({ bar, gap = 8, separatorWidth = 1, className, style, renderCom
|
|
|
446
432
|
};
|
|
447
433
|
return /* @__PURE__ */ jsxs("div", {
|
|
448
434
|
ref: containerRef,
|
|
435
|
+
role: "toolbar",
|
|
436
|
+
"aria-orientation": orientation,
|
|
437
|
+
"aria-label": ariaLabel,
|
|
449
438
|
className,
|
|
450
439
|
style: {
|
|
451
440
|
position: "relative",
|
|
452
441
|
display: "flex",
|
|
442
|
+
flexDirection: vertical ? "column" : "row",
|
|
453
443
|
alignItems: "center",
|
|
454
444
|
...style
|
|
455
445
|
},
|
|
456
|
-
children: [
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
children: [renderLiveSection(sectionByName("end")), fit.hasOverflow && /* @__PURE__ */ jsxs("span", {
|
|
468
|
-
style: {
|
|
469
|
-
position: "relative",
|
|
470
|
-
display: "inline-flex"
|
|
471
|
-
},
|
|
472
|
-
children: [renderOverflowTrigger(overflowOpen, () => setOverflowOpen((o) => !o)), renderOverflowMenu ? renderOverflowMenu(overflowView) : /* @__PURE__ */ jsx(DefaultOverflowMenu, { view: overflowView })]
|
|
473
|
-
})]
|
|
474
|
-
}),
|
|
475
|
-
/* @__PURE__ */ jsxs("div", {
|
|
476
|
-
"aria-hidden": true,
|
|
477
|
-
style: measureLayerStyle,
|
|
478
|
-
children: [visibleBar.sections.flatMap((s) => s.groups.flatMap((g) => [
|
|
479
|
-
...g.units.filter((u) => !isExternalSlot(u)).flatMap((u) => u.variants.map((variant) => /* @__PURE__ */ jsx(Measured, {
|
|
480
|
-
k: unitKey(u, variant),
|
|
481
|
-
onWidth,
|
|
482
|
-
children: renderUnitAt(u, variant, "measure")
|
|
483
|
-
}, unitKey(u, variant)))),
|
|
484
|
-
...g.collapse ? [/* @__PURE__ */ jsx(Measured, {
|
|
485
|
-
k: groupKey(g.id),
|
|
486
|
-
onWidth,
|
|
487
|
-
children: renderCollapsedGroup(g)
|
|
488
|
-
}, groupKey(g.id))] : [],
|
|
489
|
-
...g.shed ? [/* @__PURE__ */ jsx(Measured, {
|
|
490
|
-
k: groupTriggerKey(g.id),
|
|
491
|
-
onWidth,
|
|
492
|
-
children: renderDisclosure(g, true)
|
|
493
|
-
}, groupTriggerKey(g.id))] : []
|
|
494
|
-
])), /* @__PURE__ */ jsx(Measured, {
|
|
495
|
-
k: TRIGGER_KEY,
|
|
496
|
-
onWidth,
|
|
497
|
-
children: renderOverflowTrigger(false, () => {})
|
|
446
|
+
children: [layout.sections.map((section) => /* @__PURE__ */ jsxs("div", {
|
|
447
|
+
style: sectionStyle(section.name),
|
|
448
|
+
children: [renderLiveSection(section), section.name === "end" && layout.hasOverflow && /* @__PURE__ */ jsxs("span", {
|
|
449
|
+
...TOOLBAR_ITEM,
|
|
450
|
+
style: {
|
|
451
|
+
position: "relative",
|
|
452
|
+
display: "inline-flex"
|
|
453
|
+
},
|
|
454
|
+
children: [renderOverflowTrigger(overflowOpen, () => setOverflowOpen((previous) => !previous)), renderOverflowMenu ? renderOverflowMenu(overflowView) : /* @__PURE__ */ jsx(DefaultOverflowMenu, {
|
|
455
|
+
view: overflowView,
|
|
456
|
+
orientation
|
|
498
457
|
})]
|
|
499
|
-
})
|
|
500
|
-
|
|
458
|
+
})]
|
|
459
|
+
}, section.name)), /* @__PURE__ */ jsxs("div", {
|
|
460
|
+
"aria-hidden": true,
|
|
461
|
+
...INERT,
|
|
462
|
+
style: measureLayerStyle(orientation),
|
|
463
|
+
children: [layout.measured.filter((part) => !isExternalSlot(part)).map((part) => {
|
|
464
|
+
const drawn = renderPart(part, "measure");
|
|
465
|
+
if (part.kind === "custom" && drawn === null) return null;
|
|
466
|
+
return /* @__PURE__ */ jsx(Measured, {
|
|
467
|
+
k: part.measureKey,
|
|
468
|
+
orientation,
|
|
469
|
+
onLength,
|
|
470
|
+
children: drawn
|
|
471
|
+
}, part.measureKey);
|
|
472
|
+
}), /* @__PURE__ */ jsx(Measured, {
|
|
473
|
+
k: toolbarMeasureKey.overflowTrigger,
|
|
474
|
+
orientation,
|
|
475
|
+
onLength,
|
|
476
|
+
children: renderOverflowTrigger(false, () => {})
|
|
477
|
+
})]
|
|
478
|
+
})]
|
|
501
479
|
});
|
|
502
480
|
}
|
|
503
481
|
//#endregion
|
|
504
|
-
export { Toolbar, useStripView };
|
|
482
|
+
export { DEFAULT_IMPORTANCE, PINNED, Toolbar, custom, group, item, useStripView };
|
|
505
483
|
|
|
506
484
|
//# sourceMappingURL=toolbar.js.map
|