@noya-app/noya-designsystem 0.1.63 → 0.1.64
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +13 -0
- package/dist/index.css +1 -1
- package/dist/index.d.mts +169 -127
- package/dist/index.d.ts +169 -127
- package/dist/index.js +3131 -2642
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2941 -2459
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -22
- package/src/__tests__/validateDropIndicator.test.ts +26 -41
- package/src/__tests__/workspaceLayout.test.ts +281 -0
- package/src/components/ActionMenu.tsx +2 -0
- package/src/components/ActivityIndicator.tsx +5 -3
- package/src/components/AnimatePresence.tsx +6 -4
- package/src/components/Avatar.tsx +4 -2
- package/src/components/BaseToolbar.tsx +45 -34
- package/src/components/Breadcrumbs.tsx +2 -0
- package/src/components/Button.tsx +9 -3
- package/src/components/Chip.tsx +2 -0
- package/src/components/Collection.tsx +4 -1
- package/src/components/ColorSwatch.tsx +42 -22
- package/src/components/ColorSwatchControl.tsx +5 -3
- package/src/components/Combobox.tsx +2 -0
- package/src/components/CommandPalette.tsx +2 -0
- package/src/components/ContextMenu.tsx +3 -1
- package/src/components/Dialog.tsx +3 -1
- package/src/components/DimensionInput.tsx +2 -0
- package/src/components/Divider.tsx +10 -6
- package/src/components/DraggableMenuButton.tsx +2 -0
- package/src/components/Drawer.tsx +11 -3
- package/src/components/DropdownMenu.tsx +3 -1
- package/src/components/EditableText.tsx +2 -0
- package/src/components/FileUploadIndicator.tsx +108 -0
- package/src/components/FillPreviewBackground.tsx +2 -0
- package/src/components/FloatingWindow.tsx +2 -0
- package/src/components/GradientPicker.tsx +2 -0
- package/src/components/Grid.tsx +47 -38
- package/src/components/GridView.tsx +33 -11
- package/src/components/IconButton.tsx +2 -0
- package/src/components/Icons.tsx +1 -1
- package/src/components/InputField.tsx +2 -0
- package/src/components/Label.tsx +1 -1
- package/src/components/LabeledElementView.tsx +6 -2
- package/src/components/LabeledField.tsx +2 -0
- package/src/components/List.tsx +10 -2
- package/src/components/ListView.tsx +27 -14
- package/src/components/MediaThumbnail.tsx +31 -2
- package/src/components/Message.tsx +8 -9
- package/src/components/Popover.tsx +3 -1
- package/src/components/Progress.tsx +20 -7
- package/src/components/ScrollArea.tsx +3 -1
- package/src/components/SearchCompletionMenu.tsx +2 -0
- package/src/components/Section.tsx +2 -0
- package/src/components/SegmentedControl.tsx +42 -16
- package/src/components/SelectMenu.tsx +3 -1
- package/src/components/SelectionToolbar.tsx +3 -1
- package/src/components/Slider.tsx +3 -1
- package/src/components/Switch.tsx +3 -1
- package/src/components/Tabs.tsx +3 -1
- package/src/components/Text.tsx +6 -5
- package/src/components/TextArea.tsx +2 -0
- package/src/components/Toast.tsx +1 -1
- package/src/components/Toolbar.tsx +8 -2
- package/src/components/ToolbarDrawer.tsx +29 -0
- package/src/components/Tooltip.tsx +1 -1
- package/src/components/TreeView.tsx +2 -0
- package/src/components/UserPointer.tsx +2 -0
- package/src/components/ai-assistant/AIAssistantLayout.tsx +2 -0
- package/src/components/blocks/ImageBlockComponent.tsx +156 -0
- package/src/components/connected-users-menu/ConnectedUsersMenuLayout.tsx +2 -0
- package/src/components/file-explorer/FileExplorerLayout.tsx +2 -0
- package/src/components/internal/Checkmark.tsx +24 -0
- package/src/components/internal/Menu.tsx +2 -1
- package/src/components/internal/MenuViewport.tsx +4 -2
- package/src/components/internal/SelectItem.tsx +4 -23
- package/src/components/internal/TextInput.tsx +2 -0
- package/src/components/sorting/DragRegistration.tsx +8 -4
- package/src/components/sorting/SharedDragProvider.tsx +43 -18
- package/src/components/sorting/Sortable.tsx +19 -10
- package/src/components/sorting/createSharedDrag.tsx +7 -6
- package/src/components/sorting/sorting.ts +6 -9
- package/src/components/workspace/DrawerWorkspaceLayout.tsx +107 -26
- package/src/components/workspace/PanelWorkspaceLayout.tsx +98 -65
- package/src/components/workspace/VerticalTabMenu.tsx +36 -0
- package/src/components/workspace/WorkspaceLayout.tsx +46 -42
- package/src/components/workspace/constants.ts +4 -0
- package/src/components/workspace/panelStorage.ts +216 -0
- package/src/components/workspace/types.ts +11 -4
- package/src/contexts/DesignSystemConfiguration.tsx +12 -5
- package/src/contexts/DialogContext.tsx +2 -0
- package/src/contexts/FloatingWindowContext.tsx +2 -0
- package/src/contexts/GlobalInputBlurContext.tsx +2 -0
- package/src/contexts/ImageDataContext.tsx +2 -0
- package/src/contexts/LinkComponentContext.tsx +17 -0
- package/src/contexts/OpenPortalsContext.tsx +2 -0
- package/src/contexts/PortalScopeContext.tsx +2 -0
- package/src/hooks/mergeEventHandlers.ts +1 -1
- package/src/hooks/useHover.ts +30 -17
- package/src/hooks/useIndent.ts +2 -0
- package/src/hooks/useLabel.ts +2 -0
- package/src/hooks/useObjectURL.ts +5 -3
- package/src/hooks/usePlatform.ts +5 -3
- package/src/hooks/useTheme.ts +3 -1
- package/src/index.css +19 -0
- package/src/index.tsx +5 -2
- package/src/utils/classNames.ts +4 -3
- package/src/utils/combobox.ts +2 -0
- package/src/utils/formatByteSize.ts +8 -0
- package/src/utils/withSeparatorElements.ts +1 -1
- package/src/hooks/usePreservePanelSize.tsx +0 -183
- package/src/mediaQuery.ts +0 -13
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
import { getCurrentPlatform, PlatformName } from "@noya-app/noya-keymap";
|
|
2
4
|
import * as React from "react";
|
|
3
5
|
import { ToastProvider } from "../components/Toast";
|
|
4
6
|
import { DialogProvider } from "./DialogContext";
|
|
5
7
|
import { FloatingWindowProvider } from "./FloatingWindowContext";
|
|
8
|
+
import { LinkComponent, LinkComponentProvider } from "./LinkComponentContext";
|
|
6
9
|
import { OpenPortalsProvider } from "./OpenPortalsContext";
|
|
7
10
|
|
|
8
11
|
export type DesignSystemConfigurationContextValue = {
|
|
@@ -18,9 +21,11 @@ export const DesignSystemConfigurationProvider = React.memo(
|
|
|
18
21
|
function DesignSystemConfigurationProvider({
|
|
19
22
|
children,
|
|
20
23
|
platform,
|
|
24
|
+
LinkComponent,
|
|
21
25
|
}: {
|
|
22
26
|
children: React.ReactNode;
|
|
23
27
|
platform?: PlatformName;
|
|
28
|
+
LinkComponent?: LinkComponent;
|
|
24
29
|
}) {
|
|
25
30
|
const [internalPlatform, setInternalPlatform] =
|
|
26
31
|
React.useState<PlatformName>(platform ?? "key");
|
|
@@ -41,11 +46,13 @@ export const DesignSystemConfigurationProvider = React.memo(
|
|
|
41
46
|
return (
|
|
42
47
|
<DesignSystemConfigurationContext.Provider value={contextValue}>
|
|
43
48
|
<OpenPortalsProvider>
|
|
44
|
-
<
|
|
45
|
-
<
|
|
46
|
-
<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
<LinkComponentProvider value={LinkComponent}>
|
|
50
|
+
<DialogProvider>
|
|
51
|
+
<ToastProvider>
|
|
52
|
+
<FloatingWindowProvider>{children}</FloatingWindowProvider>
|
|
53
|
+
</ToastProvider>
|
|
54
|
+
</DialogProvider>
|
|
55
|
+
</LinkComponentProvider>
|
|
49
56
|
</OpenPortalsProvider>
|
|
50
57
|
</DesignSystemConfigurationContext.Provider>
|
|
51
58
|
);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { createContext, useContext } from "react";
|
|
4
|
+
|
|
5
|
+
export type LinkComponent = React.ComponentType<React.ComponentProps<"a">>;
|
|
6
|
+
|
|
7
|
+
const LinkComponentContext = createContext<LinkComponent | undefined>(
|
|
8
|
+
undefined
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export const LinkComponentProvider = LinkComponentContext.Provider;
|
|
12
|
+
|
|
13
|
+
export const useLinkComponent = () => {
|
|
14
|
+
const Link = useContext(LinkComponentContext);
|
|
15
|
+
|
|
16
|
+
return Link ?? "a";
|
|
17
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { unique } from "@noya-app/noya-utils";
|
|
2
2
|
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
3
3
|
|
|
4
|
-
function composeAllEventHandlers<E>(...handlers: ((e: E) => void)[]) {
|
|
4
|
+
function composeAllEventHandlers<E extends { defaultPrevented: boolean }>(...handlers: ((e: E) => void)[]) {
|
|
5
5
|
const [first, ...rest] = handlers;
|
|
6
6
|
|
|
7
7
|
return rest.reduce(
|
package/src/hooks/useHover.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
// From: https://github.com/radix-ui/primitives/blob/main/packages/react/scroll-area/src/useHover.ts
|
|
2
4
|
// MIT License
|
|
3
5
|
|
|
@@ -8,13 +10,13 @@
|
|
|
8
10
|
// @see https://github.com/adobe/react-spectrum/tree/452d1cb6a49f9f493757737edaf2b64014108de6/packages/%40react-aria
|
|
9
11
|
// @see https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
10
12
|
|
|
11
|
-
import * as React from
|
|
13
|
+
import * as React from "react";
|
|
12
14
|
|
|
13
15
|
export interface HoverEvent {
|
|
14
16
|
/** The type of hover event being fired. */
|
|
15
|
-
type:
|
|
17
|
+
type: "hoverstart" | "hoverend";
|
|
16
18
|
/** The pointer type that triggered the hover event. */
|
|
17
|
-
pointerType:
|
|
19
|
+
pointerType: "mouse" | "pen";
|
|
18
20
|
/** The target element of the hover event. */
|
|
19
21
|
target: HTMLElement;
|
|
20
22
|
}
|
|
@@ -58,17 +60,17 @@ function setGlobalIgnoreEmulatedMouseEvents() {
|
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
function handleGlobalPointerEvent(event: PointerEvent) {
|
|
61
|
-
if (event.pointerType ===
|
|
63
|
+
if (event.pointerType === "touch") {
|
|
62
64
|
setGlobalIgnoreEmulatedMouseEvents();
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
function setupGlobalTouchEvents() {
|
|
67
|
-
if (typeof document ===
|
|
69
|
+
if (typeof document === "undefined") {
|
|
68
70
|
return;
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
document.addEventListener(
|
|
73
|
+
document.addEventListener("pointerup", handleGlobalPointerEvent);
|
|
72
74
|
|
|
73
75
|
hoverCount++;
|
|
74
76
|
return function teardownGlobalTouchEvents() {
|
|
@@ -76,7 +78,7 @@ function setupGlobalTouchEvents() {
|
|
|
76
78
|
if (hoverCount > 0) {
|
|
77
79
|
return;
|
|
78
80
|
}
|
|
79
|
-
document.removeEventListener(
|
|
81
|
+
document.removeEventListener("pointerup", handleGlobalPointerEvent);
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
|
|
@@ -98,10 +100,14 @@ export function useHover(props: HoverProps = {}): HoverResult {
|
|
|
98
100
|
const hoverProps = React.useMemo(
|
|
99
101
|
function getHoverProps() {
|
|
100
102
|
function triggerHoverStart(
|
|
101
|
-
event:
|
|
102
|
-
|
|
103
|
+
event:
|
|
104
|
+
| PointerEvent
|
|
105
|
+
| React.PointerEvent
|
|
106
|
+
| MouseEvent
|
|
107
|
+
| React.MouseEvent,
|
|
108
|
+
pointerType: "mouse" | "pen" | "touch"
|
|
103
109
|
) {
|
|
104
|
-
if (isDisabled || pointerType ===
|
|
110
|
+
if (isDisabled || pointerType === "touch" || state.isHovered) {
|
|
105
111
|
return;
|
|
106
112
|
}
|
|
107
113
|
|
|
@@ -110,7 +116,7 @@ export function useHover(props: HoverProps = {}): HoverResult {
|
|
|
110
116
|
|
|
111
117
|
if (onHoverStart) {
|
|
112
118
|
onHoverStart({
|
|
113
|
-
type:
|
|
119
|
+
type: "hoverstart",
|
|
114
120
|
target,
|
|
115
121
|
pointerType,
|
|
116
122
|
});
|
|
@@ -124,10 +130,14 @@ export function useHover(props: HoverProps = {}): HoverResult {
|
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
function triggerHoverEnd(
|
|
127
|
-
event:
|
|
128
|
-
|
|
133
|
+
event:
|
|
134
|
+
| PointerEvent
|
|
135
|
+
| React.PointerEvent
|
|
136
|
+
| MouseEvent
|
|
137
|
+
| React.MouseEvent,
|
|
138
|
+
pointerType: "mouse" | "pen" | "touch"
|
|
129
139
|
) {
|
|
130
|
-
if (isDisabled || pointerType ===
|
|
140
|
+
if (isDisabled || pointerType === "touch" || !state.isHovered) {
|
|
131
141
|
return;
|
|
132
142
|
}
|
|
133
143
|
|
|
@@ -136,7 +146,7 @@ export function useHover(props: HoverProps = {}): HoverResult {
|
|
|
136
146
|
|
|
137
147
|
if (onHoverEnd) {
|
|
138
148
|
onHoverEnd({
|
|
139
|
-
type:
|
|
149
|
+
type: "hoverend",
|
|
140
150
|
target,
|
|
141
151
|
pointerType,
|
|
142
152
|
});
|
|
@@ -151,7 +161,10 @@ export function useHover(props: HoverProps = {}): HoverResult {
|
|
|
151
161
|
|
|
152
162
|
const hoverProps: React.HTMLAttributes<HTMLElement> = {
|
|
153
163
|
onPointerEnter(event: React.PointerEvent<HTMLElement>) {
|
|
154
|
-
if (
|
|
164
|
+
if (
|
|
165
|
+
globalIgnoreEmulatedMouseEvents &&
|
|
166
|
+
event.pointerType === "mouse"
|
|
167
|
+
) {
|
|
155
168
|
return;
|
|
156
169
|
}
|
|
157
170
|
triggerHoverStart(event, event.pointerType);
|
|
@@ -170,4 +183,4 @@ export function useHover(props: HoverProps = {}): HoverResult {
|
|
|
170
183
|
hoverProps,
|
|
171
184
|
isHovered,
|
|
172
185
|
};
|
|
173
|
-
}
|
|
186
|
+
}
|
package/src/hooks/useIndent.ts
CHANGED
package/src/hooks/useLabel.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useLayoutEffect, useMemo } from "react";
|
|
2
4
|
|
|
3
5
|
export function useObjectURL(object?: ArrayBuffer | Uint8Array | Blob) {
|
|
4
6
|
const objectURL = useMemo(() => {
|
|
@@ -8,8 +10,8 @@ export function useObjectURL(object?: ArrayBuffer | Uint8Array | Blob) {
|
|
|
8
10
|
object instanceof Uint8Array
|
|
9
11
|
? object
|
|
10
12
|
: object !== undefined
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
? new Uint8Array(object)
|
|
14
|
+
: new Uint8Array();
|
|
13
15
|
|
|
14
16
|
return URL.createObjectURL(new Blob([bytes]));
|
|
15
17
|
}, [object]);
|
package/src/hooks/usePlatform.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useDesignSystemConfiguration } from "../contexts/DesignSystemConfiguration";
|
|
2
4
|
|
|
3
5
|
export function usePlatform() {
|
|
4
6
|
return useDesignSystemConfiguration().platform;
|
|
@@ -7,7 +9,7 @@ export function usePlatform() {
|
|
|
7
9
|
/**
|
|
8
10
|
* Either ctrl or meta, depending on the platform
|
|
9
11
|
*/
|
|
10
|
-
export function usePlatformModKey():
|
|
12
|
+
export function usePlatformModKey(): "ctrlKey" | "metaKey" {
|
|
11
13
|
const platform = useDesignSystemConfiguration().platform;
|
|
12
|
-
return platform ===
|
|
14
|
+
return platform === "mac" ? "metaKey" : "ctrlKey";
|
|
13
15
|
}
|
package/src/hooks/useTheme.ts
CHANGED
package/src/index.css
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
--n-primary-150: rgb(225, 219, 255);
|
|
12
12
|
--n-primary-100: rgb(234, 230, 255); /* --n-primary-pastel */
|
|
13
13
|
--n-primary-50: rgb(243, 242, 255);
|
|
14
|
+
--n-primary-25: rgb(250, 248, 255);
|
|
14
15
|
|
|
15
16
|
--n-indigo-950: rgb(18, 26, 37);
|
|
16
17
|
--n-indigo-900: rgb(30, 40, 60);
|
|
@@ -58,6 +59,13 @@
|
|
|
58
59
|
--n-button-background-active-hover: var(--n-primary-50);
|
|
59
60
|
--n-button-text: var(--n-text);
|
|
60
61
|
--n-button-text-active: var(--n-primary);
|
|
62
|
+
--n-toolbar-drawer-background: var(--n-primary-25);
|
|
63
|
+
--n-toolbar-drawer-border: color-mix(
|
|
64
|
+
in srgb,
|
|
65
|
+
var(--n-primary) 30%,
|
|
66
|
+
transparent
|
|
67
|
+
);
|
|
68
|
+
--n-toolbar-drawer-shadow: rgba(153, 153, 153, 0.25);
|
|
61
69
|
--n-canvas-background: var(--n-indigo-25);
|
|
62
70
|
--n-canvas-grid: rgba(0, 0, 0, 0.05);
|
|
63
71
|
--n-sidebar-background: rgb(255, 255, 255);
|
|
@@ -162,6 +170,17 @@
|
|
|
162
170
|
--n-button-text-active: var(--n-primary-100);
|
|
163
171
|
--n-secondary-bright: #36fe91;
|
|
164
172
|
--n-code-background: rgb(20, 19, 23);
|
|
173
|
+
--n-toolbar-drawer-background: color-mix(
|
|
174
|
+
in srgb,
|
|
175
|
+
var(--n-primary-900) 50%,
|
|
176
|
+
var(--n-background)
|
|
177
|
+
);
|
|
178
|
+
--n-toolbar-drawer-border: color-mix(
|
|
179
|
+
in srgb,
|
|
180
|
+
var(--n-primary-700) 30%,
|
|
181
|
+
transparent
|
|
182
|
+
);
|
|
183
|
+
--n-toolbar-drawer-shadow: rgba(255, 255, 255, 0.1);
|
|
165
184
|
--n-canvas-background: rgb(20, 19, 23);
|
|
166
185
|
--n-canvas-grid: rgba(0, 0, 0, 0.1);
|
|
167
186
|
--n-sidebar-background: rgb(34, 33, 39);
|
package/src/index.tsx
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./components/ai-assistant/AIAssistantLayout";
|
|
|
5
5
|
export * from "./components/AnimatePresence";
|
|
6
6
|
export * from "./components/Avatar";
|
|
7
7
|
export * from "./components/Banner";
|
|
8
|
+
export * from "./components/blocks/ImageBlockComponent";
|
|
8
9
|
export * from "./components/Breadcrumbs";
|
|
9
10
|
export * from "./components/Button";
|
|
10
11
|
export * from "./components/Checkbox";
|
|
@@ -25,6 +26,7 @@ export * from "./components/DropdownMenu";
|
|
|
25
26
|
export * from "./components/EditableText";
|
|
26
27
|
export * from "./components/Fade";
|
|
27
28
|
export * from "./components/file-explorer/FileExplorerLayout";
|
|
29
|
+
export * from "./components/FileUploadIndicator";
|
|
28
30
|
export * from "./components/FillInputField";
|
|
29
31
|
export * from "./components/FillPreviewBackground";
|
|
30
32
|
export * from "./components/FloatingWindow";
|
|
@@ -81,6 +83,7 @@ export * from "./contexts/DialogContext";
|
|
|
81
83
|
export * from "./contexts/FloatingWindowContext";
|
|
82
84
|
export * from "./contexts/GlobalInputBlurContext";
|
|
83
85
|
export * from "./contexts/ImageDataContext";
|
|
86
|
+
export * from "./contexts/LinkComponentContext";
|
|
84
87
|
export * from "./contexts/OpenPortalsContext";
|
|
85
88
|
export * from "./contexts/PortalScopeContext";
|
|
86
89
|
// Hooks
|
|
@@ -88,12 +91,11 @@ export * from "./hooks/useHover";
|
|
|
88
91
|
export * from "./hooks/useIndent";
|
|
89
92
|
export * from "./hooks/useLabel";
|
|
90
93
|
export * from "./hooks/usePlatform";
|
|
91
|
-
export * from "./hooks/usePreservePanelSize";
|
|
92
94
|
export * from "./hooks/useTheme";
|
|
93
|
-
export * from "./mediaQuery";
|
|
94
95
|
export * from "./theme";
|
|
95
96
|
export * from "./utils/classNames";
|
|
96
97
|
export * from "./utils/createSectionedMenu";
|
|
98
|
+
export * from "./utils/formatByteSize";
|
|
97
99
|
export * from "./utils/getGradientBackground";
|
|
98
100
|
// Utils
|
|
99
101
|
export * from "./utils/colorFromString";
|
|
@@ -112,3 +114,4 @@ export * as InspectorPrimitives from "./components/InspectorPrimitives";
|
|
|
112
114
|
|
|
113
115
|
export * from "./components/BaseToolbar";
|
|
114
116
|
export * from "./components/Toolbar";
|
|
117
|
+
export * from "./components/ToolbarDrawer";
|
package/src/utils/classNames.ts
CHANGED
|
@@ -41,8 +41,9 @@ const keyMap: Record<Category, Set<string>> = {
|
|
|
41
41
|
position: positionKeysSet,
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
export function cx(...args: ClassNameItem[]): string {
|
|
45
|
-
|
|
44
|
+
export function cx(...args: ClassNameItem[]): string | undefined {
|
|
45
|
+
const classes = args.filter(Boolean).join(" ").trim();
|
|
46
|
+
return classes.length > 0 ? classes : undefined;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
const filterLastClassNameInCategory = ({
|
|
@@ -68,7 +69,7 @@ export function mergeConflictingClassNames(
|
|
|
68
69
|
const classes = Array.isArray(classNames)
|
|
69
70
|
? cx(...classNames)
|
|
70
71
|
: cx(classNames);
|
|
71
|
-
let classNamesList = classes
|
|
72
|
+
let classNamesList = classes?.split(/\s+/) ?? [];
|
|
72
73
|
options?.categories?.forEach((category) => {
|
|
73
74
|
classNamesList = filterLastClassNameInCategory({
|
|
74
75
|
classNames: classNamesList,
|
package/src/utils/combobox.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const byteSizeUnits = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
2
|
+
|
|
3
|
+
export function formatByteSize(size: number) {
|
|
4
|
+
const unitIndex = Math.floor(Math.log(size) / Math.log(1024));
|
|
5
|
+
const unit = byteSizeUnits[unitIndex];
|
|
6
|
+
const value = size / Math.pow(1024, unitIndex);
|
|
7
|
+
return `${value.toFixed(1)} ${unit}`;
|
|
8
|
+
}
|
|
@@ -16,7 +16,7 @@ function flattenChildren(
|
|
|
16
16
|
): ReactNode[] {
|
|
17
17
|
return Children.toArray(children).flatMap((child) => {
|
|
18
18
|
if (traverseFragments && isValidElement(child) && child.type === Fragment) {
|
|
19
|
-
return flattenChildren(child.props.children, traverseFragments);
|
|
19
|
+
return flattenChildren((child as any).props.children, traverseFragments);
|
|
20
20
|
}
|
|
21
21
|
return child;
|
|
22
22
|
});
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { useWindowSize } from "@noya-app/react-utils";
|
|
2
|
-
import React, { useLayoutEffect, useRef } from "react";
|
|
3
|
-
import { ImperativePanelGroupHandle } from "react-resizable-panels";
|
|
4
|
-
import { PanelLayoutState } from "../components/workspace/types";
|
|
5
|
-
|
|
6
|
-
export const EDITOR_PANEL_GROUP_ID = "editor-panel-group";
|
|
7
|
-
export const LEFT_SIDEBAR_ID = "editor-left-sidebar";
|
|
8
|
-
export const RIGHT_SIDEBAR_ID = "editor-right-sidebar";
|
|
9
|
-
export const CONTENT_AREA_ID = "editor-content-area";
|
|
10
|
-
|
|
11
|
-
export function usePreservePanelSize(
|
|
12
|
-
panelGroupRef: React.RefObject<ImperativePanelGroupHandle | null>,
|
|
13
|
-
setPanelLayoutState?: (state: PanelLayoutState) => void
|
|
14
|
-
) {
|
|
15
|
-
const windowSize = useWindowSize();
|
|
16
|
-
const layoutRef = useRef<
|
|
17
|
-
{ windowWidth: number; panelPercentages: number[] } | undefined
|
|
18
|
-
>();
|
|
19
|
-
|
|
20
|
-
useLayoutEffect(() => {
|
|
21
|
-
const panelGroup = document.querySelector(
|
|
22
|
-
`[data-panel-group-id="${EDITOR_PANEL_GROUP_ID}"]`
|
|
23
|
-
) as HTMLElement;
|
|
24
|
-
|
|
25
|
-
function observePanels() {
|
|
26
|
-
const panels = [
|
|
27
|
-
...panelGroup.querySelectorAll<HTMLElement>("[data-panel]"),
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
const panelObserver = new ResizeObserver(() => {
|
|
31
|
-
const layout = {
|
|
32
|
-
windowWidth: panelGroup.offsetWidth,
|
|
33
|
-
panelPercentages: panelGroupRef.current?.getLayout() ?? [],
|
|
34
|
-
};
|
|
35
|
-
layoutRef.current = layout;
|
|
36
|
-
|
|
37
|
-
const leftSidebar = panels.find(
|
|
38
|
-
(panel) => panel.id === LEFT_SIDEBAR_ID
|
|
39
|
-
);
|
|
40
|
-
const rightSidebar = panels.find(
|
|
41
|
-
(panel) => panel.id === RIGHT_SIDEBAR_ID
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
setPanelLayoutState?.({
|
|
45
|
-
leftSidebarCollapsed: leftSidebar?.offsetWidth === 0,
|
|
46
|
-
rightSidebarCollapsed: rightSidebar?.offsetWidth === 0,
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
panels.forEach((panel) => panelObserver.observe(panel));
|
|
51
|
-
|
|
52
|
-
return () => {
|
|
53
|
-
panelObserver.disconnect();
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let disconnectPanelObserver = observePanels();
|
|
58
|
-
|
|
59
|
-
const panelGroupObserver = new MutationObserver(() => {
|
|
60
|
-
disconnectPanelObserver();
|
|
61
|
-
disconnectPanelObserver = observePanels();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
panelGroupObserver.observe(panelGroup, {
|
|
65
|
-
childList: true,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
return () => {
|
|
69
|
-
disconnectPanelObserver();
|
|
70
|
-
panelGroupObserver.disconnect();
|
|
71
|
-
};
|
|
72
|
-
}, [panelGroupRef, setPanelLayoutState]);
|
|
73
|
-
|
|
74
|
-
useLayoutEffect(() => {
|
|
75
|
-
if (!layoutRef.current) return;
|
|
76
|
-
|
|
77
|
-
// Preserve the pixel values of the left and right sidebar when the window is resized.
|
|
78
|
-
// To do this we convert the percentage values to pixel values based on the old window width,
|
|
79
|
-
// then convert the pixel values to percentage values based on the new window width.
|
|
80
|
-
const {
|
|
81
|
-
windowWidth: oldWindowWidth,
|
|
82
|
-
panelPercentages: oldPanelPercentages,
|
|
83
|
-
} = layoutRef.current;
|
|
84
|
-
|
|
85
|
-
// Check the types of the values in the array
|
|
86
|
-
if (
|
|
87
|
-
oldPanelPercentages.some(
|
|
88
|
-
(value) => typeof value !== "number" || isNaN(value)
|
|
89
|
-
) ||
|
|
90
|
-
oldWindowWidth === 0
|
|
91
|
-
) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const currentLayout = panelGroupRef.current?.getLayout();
|
|
96
|
-
|
|
97
|
-
// Ensure we have the same number of panels
|
|
98
|
-
if (!currentLayout || currentLayout.length !== oldPanelPercentages.length) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (currentLayout.length === 3) {
|
|
103
|
-
const leftSidebarWidth = (oldPanelPercentages[0] / 100) * oldWindowWidth;
|
|
104
|
-
const rightSidebarWidth = (oldPanelPercentages[2] / 100) * oldWindowWidth;
|
|
105
|
-
|
|
106
|
-
const newLeftSidebarPercentage =
|
|
107
|
-
(leftSidebarWidth / windowSize.width) * 100;
|
|
108
|
-
const newRightSidebarPercentage =
|
|
109
|
-
(rightSidebarWidth / windowSize.width) * 100;
|
|
110
|
-
|
|
111
|
-
const newLayout = [
|
|
112
|
-
newLeftSidebarPercentage,
|
|
113
|
-
100 - newLeftSidebarPercentage - newRightSidebarPercentage,
|
|
114
|
-
newRightSidebarPercentage,
|
|
115
|
-
];
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
panelGroupRef.current?.setLayout(newLayout);
|
|
119
|
-
} catch (e) {
|
|
120
|
-
console.error(e);
|
|
121
|
-
console.info("snapshot on error", {
|
|
122
|
-
oldWindowWidth,
|
|
123
|
-
oldPanelPercentages,
|
|
124
|
-
newLayout,
|
|
125
|
-
currentLayout,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
} else if (currentLayout.length === 2) {
|
|
129
|
-
// Check if this is a right sidebar layout by looking at the panel IDs
|
|
130
|
-
const panelGroup = document.querySelector(
|
|
131
|
-
`[data-panel-group-id="${EDITOR_PANEL_GROUP_ID}"]`
|
|
132
|
-
);
|
|
133
|
-
const panels = [
|
|
134
|
-
...(panelGroup?.querySelectorAll<HTMLElement>("[data-panel]") ?? []),
|
|
135
|
-
];
|
|
136
|
-
const isRightSidebarLayout = panels[1]?.id === RIGHT_SIDEBAR_ID;
|
|
137
|
-
|
|
138
|
-
if (isRightSidebarLayout) {
|
|
139
|
-
const rightSidebarWidth =
|
|
140
|
-
(oldPanelPercentages[1] / 100) * oldWindowWidth;
|
|
141
|
-
const newRightSidebarPercentage =
|
|
142
|
-
(rightSidebarWidth / windowSize.width) * 100;
|
|
143
|
-
const newLayout = [
|
|
144
|
-
100 - newRightSidebarPercentage,
|
|
145
|
-
newRightSidebarPercentage,
|
|
146
|
-
];
|
|
147
|
-
|
|
148
|
-
try {
|
|
149
|
-
panelGroupRef.current?.setLayout(newLayout);
|
|
150
|
-
} catch (e) {
|
|
151
|
-
console.error(e);
|
|
152
|
-
console.info("snapshot on error", {
|
|
153
|
-
oldWindowWidth,
|
|
154
|
-
oldPanelPercentages,
|
|
155
|
-
newLayout,
|
|
156
|
-
currentLayout,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
} else {
|
|
160
|
-
const leftSidebarWidth =
|
|
161
|
-
(oldPanelPercentages[0] / 100) * oldWindowWidth;
|
|
162
|
-
const newLeftSidebarPercentage =
|
|
163
|
-
(leftSidebarWidth / windowSize.width) * 100;
|
|
164
|
-
const newLayout = [
|
|
165
|
-
newLeftSidebarPercentage,
|
|
166
|
-
100 - newLeftSidebarPercentage,
|
|
167
|
-
];
|
|
168
|
-
|
|
169
|
-
try {
|
|
170
|
-
panelGroupRef.current?.setLayout(newLayout);
|
|
171
|
-
} catch (e) {
|
|
172
|
-
console.error(e);
|
|
173
|
-
console.info("snapshot on error", {
|
|
174
|
-
oldWindowWidth,
|
|
175
|
-
oldPanelPercentages,
|
|
176
|
-
newLayout,
|
|
177
|
-
currentLayout,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}, [panelGroupRef, windowSize.width]);
|
|
183
|
-
}
|
package/src/mediaQuery.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export const size = {
|
|
2
|
-
medium: '800px',
|
|
3
|
-
large: '1280px',
|
|
4
|
-
xlarge: '1550px',
|
|
5
|
-
xxlarge: '1680px',
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const mediaQuery = {
|
|
9
|
-
small: `@media (max-width: ${size.medium})`,
|
|
10
|
-
medium: `@media (max-width: ${size.large}) and (min-width: ${size.medium})`,
|
|
11
|
-
large: `@media (max-width: ${size.xlarge}) and (min-width: ${size.large})`,
|
|
12
|
-
xlarge: `@media (min-width: ${size.xlarge})`,
|
|
13
|
-
};
|