@cratis/components 1.8.2 → 1.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/cjs/Toolbar/Toolbar.css +105 -2
- package/dist/cjs/Toolbar/ToolbarButton.js +10 -3
- package/dist/cjs/Toolbar/ToolbarButton.js.map +1 -1
- package/dist/cjs/Toolbar/ToolbarContext.js.map +1 -1
- package/dist/cjs/Toolbar/ToolbarFolder.js +12 -7
- package/dist/cjs/Toolbar/ToolbarFolder.js.map +1 -1
- package/dist/cjs/Toolbar/ToolbarFolderContext.js +20 -0
- package/dist/cjs/Toolbar/ToolbarFolderContext.js.map +1 -0
- package/dist/cjs/Toolbar/ToolbarGroup.js +102 -0
- package/dist/cjs/Toolbar/ToolbarGroup.js.map +1 -0
- package/dist/cjs/Toolbar/ToolbarSection.js +44 -5
- package/dist/cjs/Toolbar/ToolbarSection.js.map +1 -1
- package/dist/cjs/Toolbar/ToolbarSlot.js +125 -0
- package/dist/cjs/Toolbar/ToolbarSlot.js.map +1 -0
- package/dist/cjs/Toolbar/index.js +6 -0
- package/dist/cjs/Toolbar/index.js.map +1 -1
- package/dist/cjs/tailwind-utilities.css +12 -0
- package/dist/esm/Toolbar/Toolbar.css +105 -2
- package/dist/esm/Toolbar/Toolbar.stories.d.ts +6 -1
- package/dist/esm/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/esm/Toolbar/Toolbar.stories.js +69 -16
- package/dist/esm/Toolbar/Toolbar.stories.js.map +1 -1
- package/dist/esm/Toolbar/ToolbarButton.d.ts +2 -2
- package/dist/esm/Toolbar/ToolbarButton.d.ts.map +1 -1
- package/dist/esm/Toolbar/ToolbarButton.js +11 -4
- package/dist/esm/Toolbar/ToolbarButton.js.map +1 -1
- package/dist/esm/Toolbar/ToolbarContext.d.ts +1 -0
- package/dist/esm/Toolbar/ToolbarContext.d.ts.map +1 -1
- package/dist/esm/Toolbar/ToolbarContext.js.map +1 -1
- package/dist/esm/Toolbar/ToolbarFolder.d.ts +4 -2
- package/dist/esm/Toolbar/ToolbarFolder.d.ts.map +1 -1
- package/dist/esm/Toolbar/ToolbarFolder.js +13 -8
- package/dist/esm/Toolbar/ToolbarFolder.js.map +1 -1
- package/dist/esm/Toolbar/ToolbarFolderContext.d.ts +4 -0
- package/dist/esm/Toolbar/ToolbarFolderContext.d.ts.map +1 -0
- package/dist/esm/Toolbar/ToolbarFolderContext.js +17 -0
- package/dist/esm/Toolbar/ToolbarFolderContext.js.map +1 -0
- package/dist/esm/Toolbar/ToolbarGroup.d.ts +8 -0
- package/dist/esm/Toolbar/ToolbarGroup.d.ts.map +1 -0
- package/dist/esm/Toolbar/ToolbarGroup.js +100 -0
- package/dist/esm/Toolbar/ToolbarGroup.js.map +1 -0
- package/dist/esm/Toolbar/ToolbarSection.d.ts.map +1 -1
- package/dist/esm/Toolbar/ToolbarSection.js +45 -6
- package/dist/esm/Toolbar/ToolbarSection.js.map +1 -1
- package/dist/esm/Toolbar/ToolbarSlot.d.ts +13 -0
- package/dist/esm/Toolbar/ToolbarSlot.d.ts.map +1 -0
- package/dist/esm/Toolbar/ToolbarSlot.js +121 -0
- package/dist/esm/Toolbar/ToolbarSlot.js.map +1 -0
- package/dist/esm/Toolbar/index.d.ts +5 -0
- package/dist/esm/Toolbar/index.d.ts.map +1 -1
- package/dist/esm/Toolbar/index.js +2 -0
- package/dist/esm/Toolbar/index.js.map +1 -1
- package/dist/esm/tailwind-utilities.css +12 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { useState, useRef, useMemo, Children, useEffect } from 'react';
|
|
3
3
|
import { IconDisplay } from '../Common/Icon.js';
|
|
4
4
|
import { Tooltip } from '../Common/Tooltip.js';
|
|
5
|
+
import { ToolbarFolderContext } from './ToolbarFolderContext.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
* A toolbar folder that reveals a
|
|
8
|
+
* A toolbar folder that reveals a panel of buttons when clicked.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
* items are added
|
|
10
|
+
* **Grid mode** (default): items are arranged in a balanced grid that grows naturally as
|
|
11
|
+
* more items are added and keeps a compact footprint for small sets.
|
|
12
|
+
*
|
|
13
|
+
* **List mode**: items are stacked vertically with their icon and title label rendered
|
|
14
|
+
* side by side — useful when labels add important context to icon-only buttons.
|
|
11
15
|
*/
|
|
12
|
-
const ToolbarFolder = ({ icon,
|
|
16
|
+
const ToolbarFolder = ({ icon, title, tooltipPosition = 'right', folderDirection = 'right', mode = 'grid', maxColumns = 5, children, }) => {
|
|
13
17
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
14
18
|
const containerRef = useRef(null);
|
|
15
19
|
const items = useMemo(() => Children.toArray(children).filter(child => child !== null && child !== undefined), [children]);
|
|
@@ -39,9 +43,10 @@ const ToolbarFolder = ({ icon, tooltip, tooltipPosition = 'right', folderDirecti
|
|
|
39
43
|
const activeClass = isExpanded ? 'toolbar-button--active' : '';
|
|
40
44
|
const panelVisibleClass = isExpanded ? 'toolbar-folder-panel--visible' : '';
|
|
41
45
|
const directionClass = `toolbar-folder-panel--${folderDirection}`;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
const modeClass = mode === 'list' ? 'toolbar-folder-panel--list' : '';
|
|
47
|
+
return (jsx(ToolbarFolderContext.Provider, { value: mode, children: jsxs("div", { className: 'toolbar-folder-item', ref: containerRef, children: [jsx(Tooltip, { content: title, position: tooltipPosition, children: jsx("button", { type: 'button', "aria-label": title, "aria-expanded": isExpanded, onClick: toggleExpanded, className: `toolbar-button w-10 h-10 flex items-center justify-center rounded-lg cursor-pointer ${activeClass}`, children: jsx(IconDisplay, { icon: icon, className: 'text-lg' }) }) }), jsx("div", { className: `toolbar-folder-panel ${directionClass} ${panelVisibleClass} ${modeClass}`, style: mode === 'grid' ? {
|
|
48
|
+
gridTemplateColumns: `repeat(${columns}, minmax(2.5rem, 2.5rem))`,
|
|
49
|
+
} : undefined, children: items })] }) }));
|
|
45
50
|
};
|
|
46
51
|
|
|
47
52
|
export { ToolbarFolder };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolbarFolder.js","sources":["../../../Toolbar/ToolbarFolder.tsx"],"sourcesContent":[null],"names":["
|
|
1
|
+
{"version":3,"file":"ToolbarFolder.js","sources":["../../../Toolbar/ToolbarFolder.tsx"],"sourcesContent":[null],"names":["_jsx","_jsxs"],"mappings":";;;;;;AAwCA;;;;;;;;AAQG;AACI,MAAM,aAAa,GAAG,CAAC,EAC1B,IAAI,EACJ,KAAK,EACL,eAAe,GAAG,OAAO,EACzB,eAAe,GAAG,OAAO,EACzB,IAAI,GAAG,MAAM,EACb,UAAU,GAAG,CAAC,EACd,QAAQ,GACS,KAAI;IACrB,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;AACnD,IAAA,MAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC;AAEjD,IAAA,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;AAC1H,IAAA,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC;AAE3C,IAAA,MAAM,OAAO,GAAG,OAAO,CAAC,MAAK;QACzB,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC;AAC1C,QAAA,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvD,OAAO,IAAI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AA,QAAA,EAAA,EACI,IAAI,EAAC,QAAQ,gBACD,KAAK,EAAA,eAAA,EACF,UAAU,EACzB,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,CAAA,oFAAA,EAAuF,WAAW,EAAE,EAAA,QAAA,EAE/GA,GAAA,CAAC,WAAW,EAAA,EAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAC,SAAS,EAAA,CAAG,EAAA,CAC1C,EAAA,CACH,EACVA,aACI,SAAS,EAAE,wBAAwB,cAAc,CAAA,CAAA,EAAI,iBAAiB,CAAA,CAAA,EAAI,SAAS,CAAA,CAAE,EACrF,KAAK,EAAE,IAAI,KAAK,MAAM,GAAG;wBACrB,mBAAmB,EAAE,CAAA,OAAA,EAAU,OAAO,CAAA,yBAAA,CAA2B;qBACpE,GAAG,SAAS,EAAA,QAAA,EAEZ,KAAK,EAAA,CACJ,CAAA,EAAA,CACJ,EAAA,CACsB;AAExC;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolbarFolderContext.d.ts","sourceRoot":"","sources":["../../../Toolbar/ToolbarFolderContext.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,MAAM,CAAC;AAMhD,eAAO,MAAM,oBAAoB,4CAA2C,CAAC;AAM7E,eAAO,MAAM,oBAAoB,QAAO,iBAAqD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
4
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
5
|
+
/**
|
|
6
|
+
* Internal context propagated from {@link ToolbarFolder} to its children.
|
|
7
|
+
* Allows {@link ToolbarButton} to adapt its rendering to the folder's display mode.
|
|
8
|
+
*/
|
|
9
|
+
const ToolbarFolderContext = createContext('grid');
|
|
10
|
+
/**
|
|
11
|
+
* Returns the current {@link ToolbarFolderMode}.
|
|
12
|
+
* Defaults to `'grid'` when used outside a {@link ToolbarFolder}.
|
|
13
|
+
*/
|
|
14
|
+
const useToolbarFolderMode = () => useContext(ToolbarFolderContext);
|
|
15
|
+
|
|
16
|
+
export { ToolbarFolderContext, useToolbarFolderMode };
|
|
17
|
+
//# sourceMappingURL=ToolbarFolderContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolbarFolderContext.js","sources":["../../../Toolbar/ToolbarFolderContext.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;AACA;AAOA;;;AAGG;MACU,oBAAoB,GAAG,aAAa,CAAoB,MAAM;AAE3E;;;AAGG;AACI,MAAM,oBAAoB,GAAG,MAAyB,UAAU,CAAC,oBAAoB;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export interface ToolbarGroupProps {
|
|
3
|
+
children?: ReactNode;
|
|
4
|
+
slotName?: string;
|
|
5
|
+
orientation?: 'vertical' | 'horizontal';
|
|
6
|
+
}
|
|
7
|
+
export declare const ToolbarGroup: ({ children, slotName, orientation }: ToolbarGroupProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
//# sourceMappingURL=ToolbarGroup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolbarGroup.d.ts","sourceRoot":"","sources":["../../../Toolbar/ToolbarGroup.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAA6D,MAAM,OAAO,CAAC;AA4G7F,MAAM,WAAW,iBAAiB;IAE9B,QAAQ,CAAC,EAAE,SAAS,CAAC;IAQrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,WAAW,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;CAC3C;AAmBD,eAAO,MAAM,YAAY,GAAI,qCAAkD,iBAAiB,4CAS/F,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useRef, useCallback, useLayoutEffect, useEffect } from 'react';
|
|
3
|
+
import { useToolbarSlot } from './ToolbarSlot.js';
|
|
4
|
+
|
|
5
|
+
/** How long the fade-out animation runs (ms). React unmounts exiting content after this. */
|
|
6
|
+
const SLOT_TRANSITION_MS = 220;
|
|
7
|
+
/**
|
|
8
|
+
* Renders slot items with a cross-fade and size-morph transition that mirrors the
|
|
9
|
+
* {@link ToolbarSection} / {@link ToolbarContext} animation:
|
|
10
|
+
*
|
|
11
|
+
* - The slot container resizes smoothly to fit the incoming content.
|
|
12
|
+
* - The outgoing content fades out while the incoming content fades in simultaneously.
|
|
13
|
+
*
|
|
14
|
+
* The size update is intentionally deferred to {@link useEffect} (after paint) so that
|
|
15
|
+
* the opacity animations start one frame before the resize — matching the feel of
|
|
16
|
+
* {@link ToolbarSection} context switching.
|
|
17
|
+
*/
|
|
18
|
+
const SlotTransition = ({ slotName, flexClass }) => {
|
|
19
|
+
const liveItems = useToolbarSlot(slotName);
|
|
20
|
+
// `current` is the content fading in (or already settled at full opacity).
|
|
21
|
+
// `exiting` is the previous content fading out, kept alive until its animation completes.
|
|
22
|
+
const [current, setCurrent] = useState(liveItems);
|
|
23
|
+
const [exiting, setExiting] = useState([]);
|
|
24
|
+
const [exitRevision, setExitRevision] = useState(0);
|
|
25
|
+
// Track `current` in a ref so the liveItems effect can read the latest value
|
|
26
|
+
// without needing it in its dependency array (avoids an unnecessary re-run loop).
|
|
27
|
+
const currentRef = useRef(current);
|
|
28
|
+
currentRef.current = current;
|
|
29
|
+
const incomingRef = useRef(null);
|
|
30
|
+
const [size, setSize] = useState(null);
|
|
31
|
+
const timerRef = useRef(undefined);
|
|
32
|
+
const hasMountedRef = useRef(false);
|
|
33
|
+
const measureIncoming = useCallback(() => {
|
|
34
|
+
if (incomingRef.current) {
|
|
35
|
+
setSize({
|
|
36
|
+
width: incomingRef.current.offsetWidth,
|
|
37
|
+
height: incomingRef.current.offsetHeight,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}, []);
|
|
41
|
+
// Set the initial size synchronously before the first paint — no layout flash.
|
|
42
|
+
useLayoutEffect(() => {
|
|
43
|
+
measureIncoming();
|
|
44
|
+
}, []); // mount only
|
|
45
|
+
// Detect live-items reference change → start cross-fade transition.
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (liveItems === currentRef.current)
|
|
48
|
+
return;
|
|
49
|
+
const old = currentRef.current;
|
|
50
|
+
if (timerRef.current !== undefined)
|
|
51
|
+
clearTimeout(timerRef.current);
|
|
52
|
+
setCurrent(liveItems);
|
|
53
|
+
if (old.length > 0) {
|
|
54
|
+
setExiting(old);
|
|
55
|
+
setExitRevision(r => r + 1);
|
|
56
|
+
timerRef.current = setTimeout(() => setExiting([]), SLOT_TRANSITION_MS);
|
|
57
|
+
}
|
|
58
|
+
}, [liveItems]);
|
|
59
|
+
// Re-measure the incoming content whenever `current` changes so the container
|
|
60
|
+
// can size-morph. useEffect (not useLayoutEffect) is intentional: we let the
|
|
61
|
+
// opacity animation start one frame before the resize — matching ToolbarSection.
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (!hasMountedRef.current) {
|
|
64
|
+
hasMountedRef.current = true;
|
|
65
|
+
return; // initial measurement handled by useLayoutEffect above
|
|
66
|
+
}
|
|
67
|
+
measureIncoming();
|
|
68
|
+
}, [current, measureIncoming]);
|
|
69
|
+
useEffect(() => () => {
|
|
70
|
+
if (timerRef.current !== undefined)
|
|
71
|
+
clearTimeout(timerRef.current);
|
|
72
|
+
}, []);
|
|
73
|
+
if (current.length === 0 && exiting.length === 0)
|
|
74
|
+
return null;
|
|
75
|
+
return (jsxs("div", { className: 'toolbar-slot-section', style: size ? { width: size.width, height: size.height } : undefined, children: [jsx("div", { ref: incomingRef, className: `toolbar-slot-incoming inline-flex ${flexClass} items-center gap-1`, children: current }), exiting.length > 0 && (jsx("div", { className: `toolbar-slot-outgoing inline-flex ${flexClass} items-center gap-1`, children: exiting }, exitRevision))] }));
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* A logical sub-grouping of toolbar items within a {@link Toolbar}.
|
|
79
|
+
*
|
|
80
|
+
* Use `ToolbarGroup` to cluster related buttons into a visually cohesive unit.
|
|
81
|
+
* Groups can participate in the slot system by providing a `slotName` — external
|
|
82
|
+
* components anywhere in the {@link ToolbarSlotProvider} tree can then inject additional
|
|
83
|
+
* buttons at a chosen position via {@link ToolbarSlot}.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```tsx
|
|
87
|
+
* <Toolbar>
|
|
88
|
+
* <ToolbarGroup slotName="canvas-tools">
|
|
89
|
+
* <ToolbarButton icon="pi pi-pencil" title="Draw" />
|
|
90
|
+
* </ToolbarGroup>
|
|
91
|
+
* </Toolbar>
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
const ToolbarGroup = ({ children, slotName, orientation = 'vertical' }) => {
|
|
95
|
+
const flexClass = orientation === 'horizontal' ? 'flex-row' : 'flex-col';
|
|
96
|
+
return (jsxs("div", { className: `toolbar-group inline-flex ${flexClass} items-center gap-1 p-2 rounded-2xl`, children: [children, slotName && jsx(SlotTransition, { slotName: slotName, flexClass: flexClass })] }));
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export { ToolbarGroup };
|
|
100
|
+
//# sourceMappingURL=ToolbarGroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolbarGroup.js","sources":["../../../Toolbar/ToolbarGroup.tsx"],"sourcesContent":[null],"names":["_jsxs","_jsx"],"mappings":";;;;AAMA;AACA,MAAM,kBAAkB,GAAG,GAAG;AAE9B;;;;;;;;;;AAUG;AACH,MAAM,cAAc,GAAG,CAAC,EAAE,QAAQ,EAAE,SAAS,EAA2C,KAAI;AACxF,IAAA,MAAM,SAAS,GAAG,cAAc,CAAC,QAAQ,CAAC;;;IAI1C,MAAM,CAAC,OAAO,EAAE,UAAU,CAA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CACT,CAAA,EAAA,CACC;AAEd,CAAC;AAmBD;;;;;;;;;;;;;;;;AAgBG;AACI,MAAM,YAAY,GAAG,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,GAAG,UAAU,EAAqB,KAAI;AAChG,IAAA,MAAM,SAAS,GAAG,WAAW,KAAK,YAAY,GAAG,UAAU,GAAG,UAAU;IAExE,QACID,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,CAAA,0BAAA,EAA6B,SAAS,CAAA,mCAAA,CAAqC,EAAA,QAAA,EAAA,CACtF,QAAQ,EACR,QAAQ,IAAIC,IAAC,cAAc,EAAA,EAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAA,CAAI,CAAA,EAAA,CACvE;AAEd;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolbarSection.d.ts","sourceRoot":"","sources":["../../../Toolbar/ToolbarSection.tsx"],"names":[],"mappings":"AAGA,OAAO,EAA0B,SAAS,EAA6E,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ToolbarSection.d.ts","sourceRoot":"","sources":["../../../Toolbar/ToolbarSection.tsx"],"names":[],"mappings":"AAGA,OAAO,EAA0B,SAAS,EAA6E,MAAM,OAAO,CAAC;AA0BrI,MAAM,WAAW,mBAAmB;IAMhC,aAAa,CAAC,EAAE,MAAM,CAAC;IAGvB,QAAQ,EAAE,SAAS,CAAC;IAGpB,WAAW,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;CAC3C;AAaD,eAAO,MAAM,cAAc,GAAI,0CAAuD,mBAAmB,4CAkIxG,CAAC"}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { useRef, useState, Children, isValidElement, useCallback, useLayoutEffect, useEffect } from 'react';
|
|
3
|
+
import { useToolbarSlot } from './ToolbarSlot.js';
|
|
3
4
|
|
|
5
|
+
/** Width/height transition duration used by the section resize animation (ms). */
|
|
6
|
+
const SECTION_TRANSITION_MS = 350;
|
|
7
|
+
/**
|
|
8
|
+
* Renders the children of a single {@link ToolbarContext} together with any slot items
|
|
9
|
+
* that have been registered under the context's `slotName`.
|
|
10
|
+
*
|
|
11
|
+
* Extracted into its own component so that the `useToolbarSlot` hook can be called
|
|
12
|
+
* inside it — hooks cannot be called inside a callback or loop in the parent.
|
|
13
|
+
*/
|
|
14
|
+
const ContextRenderer = ({ children, slotName }) => {
|
|
15
|
+
const slotItems = useToolbarSlot(slotName ?? '');
|
|
16
|
+
return (jsxs(Fragment, { children: [children, slotName && slotItems.length > 0 && slotItems] }));
|
|
17
|
+
};
|
|
4
18
|
/**
|
|
5
19
|
* A section within a {@link Toolbar} that supports multiple named contexts.
|
|
6
20
|
*
|
|
@@ -16,7 +30,10 @@ const ToolbarSection = ({ activeContext, children, orientation = 'vertical' }) =
|
|
|
16
30
|
const contextRefs = useRef({});
|
|
17
31
|
const resizeObserverRef = useRef(null);
|
|
18
32
|
const mutationObserverRef = useRef(null);
|
|
33
|
+
const transitionTimeoutRef = useRef(null);
|
|
34
|
+
const previousContextRef = useRef(null);
|
|
19
35
|
const [size, setSize] = useState(null);
|
|
36
|
+
const [isTransitioning, setIsTransitioning] = useState(false);
|
|
20
37
|
const contexts = Children.toArray(children).filter((child) => isValidElement(child) && typeof child.props.name === 'string');
|
|
21
38
|
// Default to the first context if activeContext is not provided
|
|
22
39
|
const effectiveContext = activeContext ?? contexts[0]?.props?.name ?? '';
|
|
@@ -26,8 +43,8 @@ const ToolbarSection = ({ activeContext, children, orientation = 'vertical' }) =
|
|
|
26
43
|
const ref = contextRefs.current[contextName];
|
|
27
44
|
if (ref) {
|
|
28
45
|
setSize({
|
|
29
|
-
width:
|
|
30
|
-
height:
|
|
46
|
+
width: ref.offsetWidth,
|
|
47
|
+
height: ref.offsetHeight,
|
|
31
48
|
});
|
|
32
49
|
}
|
|
33
50
|
}, []);
|
|
@@ -36,6 +53,24 @@ const ToolbarSection = ({ activeContext, children, orientation = 'vertical' }) =
|
|
|
36
53
|
useLayoutEffect(() => {
|
|
37
54
|
measureAndSetSize(effectiveContext);
|
|
38
55
|
}, []); // run only on mount
|
|
56
|
+
// Clip content only while the section is morphing between contexts so incoming
|
|
57
|
+
// buttons do not float outside the current bounds during growth.
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (previousContextRef.current === null) {
|
|
60
|
+
previousContextRef.current = effectiveContext;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (previousContextRef.current === effectiveContext)
|
|
64
|
+
return;
|
|
65
|
+
previousContextRef.current = effectiveContext;
|
|
66
|
+
setIsTransitioning(true);
|
|
67
|
+
if (transitionTimeoutRef.current)
|
|
68
|
+
clearTimeout(transitionTimeoutRef.current);
|
|
69
|
+
transitionTimeoutRef.current = setTimeout(() => {
|
|
70
|
+
setIsTransitioning(false);
|
|
71
|
+
transitionTimeoutRef.current = null;
|
|
72
|
+
}, SECTION_TRANSITION_MS);
|
|
73
|
+
}, [effectiveContext]);
|
|
39
74
|
// After a context switch, let the browser paint the opacity transition first,
|
|
40
75
|
// then update the explicit size so the CSS width/height transition kicks in.
|
|
41
76
|
useEffect(() => {
|
|
@@ -75,10 +110,14 @@ const ToolbarSection = ({ activeContext, children, orientation = 'vertical' }) =
|
|
|
75
110
|
mutationObserverRef.current = null;
|
|
76
111
|
};
|
|
77
112
|
}, [effectiveContext, measureAndSetSize]);
|
|
78
|
-
|
|
79
|
-
|
|
113
|
+
useEffect(() => () => {
|
|
114
|
+
if (transitionTimeoutRef.current)
|
|
115
|
+
clearTimeout(transitionTimeoutRef.current);
|
|
116
|
+
}, []);
|
|
117
|
+
return (jsx("div", { className: `toolbar-section ${isTransitioning ? 'toolbar-section--transitioning' : ''}`, style: size ? { width: size.width, height: size.height } : undefined, children: contexts.map((child) => {
|
|
118
|
+
const { name, children: contextChildren, slotName } = child.props;
|
|
80
119
|
const isActive = name === effectiveContext;
|
|
81
|
-
return (jsx("div", { ref: (element) => { contextRefs.current[name] = element; }, className: `toolbar-context inline-flex ${flexClass} items-center gap-1 ${isActive ? 'toolbar-context--active' : 'toolbar-context--inactive'}`, children: contextChildren }, name));
|
|
120
|
+
return (jsx("div", { ref: (element) => { contextRefs.current[name] = element; }, className: `toolbar-context inline-flex ${flexClass} items-center gap-1 ${isActive ? 'toolbar-context--active' : 'toolbar-context--inactive'}`, children: jsx(ContextRenderer, { slotName: slotName, children: contextChildren }) }, name));
|
|
82
121
|
}) }));
|
|
83
122
|
};
|
|
84
123
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolbarSection.js","sources":["../../../Toolbar/ToolbarSection.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ToolbarSection.js","sources":["../../../Toolbar/ToolbarSection.tsx"],"sourcesContent":[null],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;AAQA;AACA,MAAM,qBAAqB,GAAG,GAAG;AAEjC;;;;;;AAMG;AACH,MAAM,eAAe,GAAG,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAA8C,KAAI;IAC3F,MAAM,SAAS,GAAG,cAAc,CAAC,QAAQ,IAAI,EAAE,CAAC;AAChD,IAAA,QACIA,IAAA,CAAAC,QAAA,EAAA,EAAA,QAAA,EAAA,CACK,QAAQ,EACR,QAAQ,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,CAAA,EAAA,CAC/C;AAEX,CAAC;AAkBD;;;;;;;;;;AAUG;AACI,MAAM,cAAc,GAAG,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,GAAG,UAAU,EAAuB,KAAI;AACzG,IAAA,MAAM,WAAW,GAAG,MAAM,CAAwC,EAAE,CAAC;AACrE,IAAA,MAAM,iBAAiB,GAAG,MAAM,CAAwB,IAAI,CAAC;AAC7D,IAAA,MA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G,OAAO,CAAC,CAAC,CAAC,EAC1D,SAAS,EAAE,CAAA,4BAAA,EAA+B,SAAS,uBAC/C,QAAQ,GAAG,yBAAyB,GAAG,2BAC3C,CAAA,CAAE,EAAA,QAAA,EAEFA,GAAA,CAAC,eAAe,EAAA,EAAC,QAAQ,EAAE,QAAQ,EAAA,QAAA,EAAG,eAAe,GAAmB,EAAA,EANnE,IAAI,CAOP;QAEd,CAAC,CAAC,EAAA,CACA;AAEd;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export interface ToolbarSlotProviderProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
}
|
|
5
|
+
export declare const ToolbarSlotProvider: ({ children }: ToolbarSlotProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export declare const useToolbarSlot: (slotName: string) => ReactNode[];
|
|
7
|
+
export interface ToolbarSlotProps {
|
|
8
|
+
slotName: string;
|
|
9
|
+
order?: number;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export declare const ToolbarSlot: ({ slotName, order, children }: ToolbarSlotProps) => null;
|
|
13
|
+
//# sourceMappingURL=ToolbarSlot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolbarSlot.d.ts","sourceRoot":"","sources":["../../../Toolbar/ToolbarSlot.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAiB,SAAS,EAA8F,MAAM,OAAO,CAAC;AAkF7I,MAAM,WAAW,wBAAwB;IAKrC,QAAQ,EAAE,SAAS,CAAC;CACvB;AAQD,eAAO,MAAM,mBAAmB,GAAI,cAAc,wBAAwB,4CAGzE,CAAC;AAQF,eAAO,MAAM,cAAc,GAAI,UAAU,MAAM,KAAG,SAAS,EAQ1D,CAAC;AAGF,MAAM,WAAW,gBAAgB;IAK7B,QAAQ,EAAE,MAAM,CAAC;IAMjB,KAAK,CAAC,EAAE,MAAM,CAAC;IAMf,QAAQ,EAAE,SAAS,CAAC;CACvB;AAkBD,eAAO,MAAM,WAAW,GAAI,+BAAmC,gBAAgB,SAa9E,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { createContext, useId, useContext, useLayoutEffect, useEffect, useState, useCallback, useSyncExternalStore } from 'react';
|
|
3
|
+
|
|
4
|
+
/** Stable empty snapshot returned when a slot name has no registered content. */
|
|
5
|
+
const _emptySnapshot = [];
|
|
6
|
+
/**
|
|
7
|
+
* Registry for named toolbar slot entries.
|
|
8
|
+
* Maintained outside React state so slot registrations never re-render the provider.
|
|
9
|
+
*/
|
|
10
|
+
class ToolbarSlotRegistry {
|
|
11
|
+
_slots = new Map();
|
|
12
|
+
_snapshots = new Map();
|
|
13
|
+
_subscribers = new Set();
|
|
14
|
+
/**
|
|
15
|
+
* Register or update a slot entry.
|
|
16
|
+
* Notifies subscribers only when the content reference or order actually changes.
|
|
17
|
+
*/
|
|
18
|
+
register(slotName, id, content, order) {
|
|
19
|
+
if (!this._slots.has(slotName)) {
|
|
20
|
+
this._slots.set(slotName, new Map());
|
|
21
|
+
}
|
|
22
|
+
const slotMap = this._slots.get(slotName);
|
|
23
|
+
const previous = slotMap.get(id);
|
|
24
|
+
if (previous?.content === content && previous?.order === order)
|
|
25
|
+
return;
|
|
26
|
+
slotMap.set(id, { content, order });
|
|
27
|
+
this._recompute(slotName);
|
|
28
|
+
this._notify();
|
|
29
|
+
}
|
|
30
|
+
/** Remove a slot entry and notify subscribers. */
|
|
31
|
+
unregister(slotName, id) {
|
|
32
|
+
const slotMap = this._slots.get(slotName);
|
|
33
|
+
if (!slotMap?.has(id))
|
|
34
|
+
return;
|
|
35
|
+
slotMap.delete(id);
|
|
36
|
+
this._recompute(slotName);
|
|
37
|
+
this._notify();
|
|
38
|
+
}
|
|
39
|
+
/** Subscribe to any slot change. Returns an unsubscribe function. */
|
|
40
|
+
subscribe(fn) {
|
|
41
|
+
this._subscribers.add(fn);
|
|
42
|
+
return () => this._subscribers.delete(fn);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Returns a stable snapshot of sorted slot contents for the given slot name.
|
|
46
|
+
* The reference only changes when the slot set actually changes.
|
|
47
|
+
*/
|
|
48
|
+
getSnapshot(slotName) {
|
|
49
|
+
return this._snapshots.get(slotName) ?? _emptySnapshot;
|
|
50
|
+
}
|
|
51
|
+
_recompute(slotName) {
|
|
52
|
+
const slotMap = this._slots.get(slotName);
|
|
53
|
+
if (!slotMap || slotMap.size === 0) {
|
|
54
|
+
this._snapshots.delete(slotName);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this._snapshots.set(slotName, [...slotMap.values()]
|
|
58
|
+
.sort((a, b) => a.order - b.order)
|
|
59
|
+
.map(entry => entry.content));
|
|
60
|
+
}
|
|
61
|
+
_notify() {
|
|
62
|
+
this._subscribers.forEach(fn => fn());
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const ToolbarSlotContext = createContext(null);
|
|
66
|
+
/**
|
|
67
|
+
* Provides the toolbar slot registry to the component tree.
|
|
68
|
+
*
|
|
69
|
+
* Mount once above both the toolbar and the components that fill slots.
|
|
70
|
+
* Each provider creates an isolated registry — nesting providers creates isolated scopes.
|
|
71
|
+
*/
|
|
72
|
+
const ToolbarSlotProvider = ({ children }) => {
|
|
73
|
+
const [registry] = useState(() => new ToolbarSlotRegistry());
|
|
74
|
+
return jsx(ToolbarSlotContext.Provider, { value: registry, children: children });
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Returns the sorted slot contents for a given `slotName` as a stable array.
|
|
78
|
+
* Returns an empty array when no {@link ToolbarSlotProvider} is present or when the slot has no content.
|
|
79
|
+
*
|
|
80
|
+
* Suitable for direct use inside components that host a slot (e.g. {@link ToolbarGroup}).
|
|
81
|
+
*/
|
|
82
|
+
const useToolbarSlot = (slotName) => {
|
|
83
|
+
const registry = useContext(ToolbarSlotContext);
|
|
84
|
+
const subscribe = useCallback((fn) => {
|
|
85
|
+
if (!registry)
|
|
86
|
+
return () => { };
|
|
87
|
+
return registry.subscribe(fn);
|
|
88
|
+
}, [registry]);
|
|
89
|
+
const getSnapshot = useCallback(() => registry?.getSnapshot(slotName) ?? _emptySnapshot, [registry, slotName]);
|
|
90
|
+
return useSyncExternalStore(subscribe, getSnapshot);
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Teleports its children into the named toolbar slot without prop drilling.
|
|
94
|
+
* Renders nothing itself — place it anywhere inside a {@link ToolbarSlotProvider} tree.
|
|
95
|
+
*
|
|
96
|
+
* The nearest {@link ToolbarGroup} or {@link ToolbarContext} with a matching `slotName`
|
|
97
|
+
* will render the content. Use {@link ToolbarSlotProps.order} to control position relative to
|
|
98
|
+
* other {@link ToolbarSlot} entries in the same slot.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```tsx
|
|
102
|
+
* // In a feature component, inject a button into the 'canvas-tools' slot:
|
|
103
|
+
* <ToolbarSlot slotName="canvas-tools" order={10}>
|
|
104
|
+
* <ToolbarButton icon="pi pi-star" title="Favorite" />
|
|
105
|
+
* </ToolbarSlot>
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
const ToolbarSlot = ({ slotName, order = 0, children }) => {
|
|
109
|
+
const id = useId();
|
|
110
|
+
const registry = useContext(ToolbarSlotContext);
|
|
111
|
+
// Re-register on every render so fresh closures are always captured.
|
|
112
|
+
// The registry skips notification when the content reference hasn't changed.
|
|
113
|
+
useLayoutEffect(() => {
|
|
114
|
+
registry?.register(slotName, id, children, order);
|
|
115
|
+
});
|
|
116
|
+
useEffect(() => () => registry?.unregister(slotName, id), [id, registry, slotName]);
|
|
117
|
+
return null;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export { ToolbarSlot, ToolbarSlotProvider, useToolbarSlot };
|
|
121
|
+
//# sourceMappingURL=ToolbarSlot.js.map
|
|
@@ -0,0 +1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arButton';
|
|
5
5
|
export { ToolbarContext } from './ToolbarContext';
|
|
6
6
|
export type { ToolbarContextProps } from './ToolbarContext';
|
|
7
|
+
export { ToolbarGroup } from './ToolbarGroup';
|
|
8
|
+
export type { ToolbarGroupProps } from './ToolbarGroup';
|
|
7
9
|
export { ToolbarSection } from './ToolbarSection';
|
|
8
10
|
export type { ToolbarSectionProps } from './ToolbarSection';
|
|
9
11
|
export { ToolbarSeparator } from './ToolbarSeparator';
|
|
@@ -12,4 +14,7 @@ export { ToolbarFanOutItem } from './ToolbarFanOutItem';
|
|
|
12
14
|
export type { ToolbarFanOutItemProps } from './ToolbarFanOutItem';
|
|
13
15
|
export { ToolbarFolder } from './ToolbarFolder';
|
|
14
16
|
export type { ToolbarFolderProps } from './ToolbarFolder';
|
|
17
|
+
export type { ToolbarFolderMode } from './ToolbarFolderContext';
|
|
18
|
+
export { ToolbarSlot, ToolbarSlotProvider, useToolbarSlot } from './ToolbarSlot';
|
|
19
|
+
export type { ToolbarSlotProps, ToolbarSlotProviderProps } from './ToolbarSlot';
|
|
15
20
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../Toolbar/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EA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,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACjF,YAAY,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export { Toolbar } from './Toolbar.js';
|
|
2
2
|
export { ToolbarButton } from './ToolbarButton.js';
|
|
3
3
|
export { ToolbarContext } from './ToolbarContext.js';
|
|
4
|
+
export { ToolbarGroup } from './ToolbarGroup.js';
|
|
4
5
|
export { ToolbarSection } from './ToolbarSection.js';
|
|
5
6
|
export { ToolbarSeparator } from './ToolbarSeparator.js';
|
|
6
7
|
export { ToolbarFanOutItem } from './ToolbarFanOutItem.js';
|
|
7
8
|
export { ToolbarFolder } from './ToolbarFolder.js';
|
|
9
|
+
export { ToolbarSlot, ToolbarSlotProvider, useToolbarSlot } from './ToolbarSlot.js';
|
|
8
10
|
|
|
9
11
|
// Copyright (c) Cratis. All rights reserved.
|
|
10
12
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../Toolbar/index.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../Toolbar/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;AAAA;AACA"}
|
|
@@ -335,6 +335,9 @@
|
|
|
335
335
|
.block {
|
|
336
336
|
display: block;
|
|
337
337
|
}
|
|
338
|
+
.contents {
|
|
339
|
+
display: contents;
|
|
340
|
+
}
|
|
338
341
|
.flex {
|
|
339
342
|
display: flex;
|
|
340
343
|
}
|
|
@@ -371,6 +374,9 @@
|
|
|
371
374
|
.flex-1 {
|
|
372
375
|
flex: 1;
|
|
373
376
|
}
|
|
377
|
+
.flex-shrink-0 {
|
|
378
|
+
flex-shrink: 0;
|
|
379
|
+
}
|
|
374
380
|
.flex-grow {
|
|
375
381
|
flex-grow: 1;
|
|
376
382
|
}
|
|
@@ -409,6 +415,9 @@
|
|
|
409
415
|
.justify-center {
|
|
410
416
|
justify-content: center;
|
|
411
417
|
}
|
|
418
|
+
.justify-start {
|
|
419
|
+
justify-content: flex-start;
|
|
420
|
+
}
|
|
412
421
|
.gap-1 {
|
|
413
422
|
gap: calc(var(--spacing) * 1);
|
|
414
423
|
}
|
|
@@ -424,6 +433,9 @@
|
|
|
424
433
|
.gap-6 {
|
|
425
434
|
gap: calc(var(--spacing) * 6);
|
|
426
435
|
}
|
|
436
|
+
.gap-8 {
|
|
437
|
+
gap: calc(var(--spacing) * 8);
|
|
438
|
+
}
|
|
427
439
|
.space-y-2 {
|
|
428
440
|
:where(& > :not(:last-child)) {
|
|
429
441
|
--tw-space-y-reverse: 0;
|