@noya-app/noya-designsystem 0.1.62 → 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.
Files changed (118) hide show
  1. package/.eslintrc.js +1 -5
  2. package/.turbo/turbo-build.log +10 -10
  3. package/.turbo/turbo-lint.log +0 -1
  4. package/CHANGELOG.md +23 -0
  5. package/dist/index.css +1 -1
  6. package/dist/index.d.mts +299 -179
  7. package/dist/index.d.ts +299 -179
  8. package/dist/index.js +3772 -2999
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +3485 -2720
  11. package/dist/index.mjs.map +1 -1
  12. package/package.json +10 -22
  13. package/src/__tests__/validateDropIndicator.test.ts +26 -41
  14. package/src/__tests__/workspaceLayout.test.ts +281 -0
  15. package/src/components/ActionMenu.tsx +2 -0
  16. package/src/components/ActivityIndicator.tsx +5 -3
  17. package/src/components/AnimatePresence.tsx +6 -4
  18. package/src/components/Avatar.tsx +4 -2
  19. package/src/components/BaseToolbar.tsx +45 -34
  20. package/src/components/Breadcrumbs.tsx +2 -0
  21. package/src/components/Button.tsx +35 -21
  22. package/src/components/Chip.tsx +2 -0
  23. package/src/components/Collection.tsx +4 -1
  24. package/src/components/ColorSwatch.tsx +42 -22
  25. package/src/components/ColorSwatchControl.tsx +5 -3
  26. package/src/components/Combobox.tsx +2 -0
  27. package/src/components/CommandPalette.tsx +2 -0
  28. package/src/components/ContextMenu.tsx +3 -1
  29. package/src/components/Dialog.tsx +3 -1
  30. package/src/components/DimensionInput.tsx +3 -1
  31. package/src/components/Divider.tsx +10 -6
  32. package/src/components/DraggableMenuButton.tsx +22 -4
  33. package/src/components/Drawer.tsx +11 -3
  34. package/src/components/DropdownMenu.tsx +34 -6
  35. package/src/components/EditableText.tsx +2 -0
  36. package/src/components/FileUploadIndicator.tsx +108 -0
  37. package/src/components/FillPreviewBackground.tsx +2 -0
  38. package/src/components/FloatingWindow.tsx +2 -0
  39. package/src/components/GradientPicker.tsx +2 -0
  40. package/src/components/Grid.tsx +47 -38
  41. package/src/components/GridView.tsx +33 -11
  42. package/src/components/IconButton.tsx +4 -2
  43. package/src/components/Icons.tsx +1 -1
  44. package/src/components/InputField.tsx +7 -5
  45. package/src/components/Label.tsx +1 -3
  46. package/src/components/LabeledElementView.tsx +6 -2
  47. package/src/components/LabeledField.tsx +38 -34
  48. package/src/components/List.tsx +10 -2
  49. package/src/components/ListView.tsx +27 -14
  50. package/src/components/MediaThumbnail.tsx +31 -2
  51. package/src/components/Message.tsx +8 -9
  52. package/src/components/Popover.tsx +15 -4
  53. package/src/components/Progress.tsx +20 -7
  54. package/src/components/ScrollArea.tsx +3 -1
  55. package/src/components/SearchCompletionMenu.tsx +2 -0
  56. package/src/components/Section.tsx +2 -0
  57. package/src/components/SegmentedControl.tsx +43 -17
  58. package/src/components/SelectMenu.tsx +6 -4
  59. package/src/components/SelectionToolbar.tsx +31 -8
  60. package/src/components/Slider.tsx +4 -2
  61. package/src/components/Spacer.tsx +0 -1
  62. package/src/components/Switch.tsx +3 -1
  63. package/src/components/Tabs.tsx +48 -0
  64. package/src/components/Text.tsx +6 -5
  65. package/src/components/TextArea.tsx +2 -0
  66. package/src/components/Toast.tsx +1 -1
  67. package/src/components/Toolbar.tsx +113 -12
  68. package/src/components/ToolbarDrawer.tsx +29 -0
  69. package/src/components/Tooltip.tsx +9 -9
  70. package/src/components/TreeView.tsx +2 -0
  71. package/src/components/UserPointer.tsx +2 -0
  72. package/src/components/ai-assistant/AIAssistantLayout.tsx +2 -0
  73. package/src/components/blocks/ImageBlockComponent.tsx +156 -0
  74. package/src/components/connected-users-menu/ConnectedUsersMenuLayout.tsx +2 -0
  75. package/src/components/file-explorer/FileExplorerLayout.tsx +14 -6
  76. package/src/components/internal/Checkmark.tsx +24 -0
  77. package/src/components/internal/Menu.tsx +21 -3
  78. package/src/components/internal/MenuViewport.tsx +8 -5
  79. package/src/components/internal/SelectItem.tsx +4 -23
  80. package/src/components/internal/TextInput.tsx +2 -0
  81. package/src/components/sorting/DragRegistration.tsx +8 -4
  82. package/src/components/sorting/SharedDragProvider.tsx +43 -18
  83. package/src/components/sorting/Sortable.tsx +19 -10
  84. package/src/components/sorting/createSharedDrag.tsx +7 -6
  85. package/src/components/sorting/sorting.ts +6 -9
  86. package/src/components/workspace/DrawerWorkspaceLayout.tsx +113 -28
  87. package/src/components/workspace/PanelWorkspaceLayout.tsx +149 -16
  88. package/src/components/workspace/VerticalTabMenu.tsx +36 -0
  89. package/src/components/workspace/WorkspaceLayout.tsx +132 -47
  90. package/src/components/workspace/constants.ts +4 -0
  91. package/src/components/workspace/panelStorage.ts +216 -0
  92. package/src/components/workspace/renderPanelChildren.tsx +12 -0
  93. package/src/components/workspace/types.ts +30 -7
  94. package/src/contexts/DesignSystemConfiguration.tsx +12 -5
  95. package/src/contexts/DialogContext.tsx +2 -0
  96. package/src/contexts/FloatingWindowContext.tsx +2 -0
  97. package/src/contexts/GlobalInputBlurContext.tsx +2 -0
  98. package/src/contexts/ImageDataContext.tsx +2 -0
  99. package/src/contexts/LinkComponentContext.tsx +17 -0
  100. package/src/contexts/OpenPortalsContext.tsx +2 -0
  101. package/src/contexts/PortalScopeContext.tsx +2 -0
  102. package/src/hooks/mergeEventHandlers.ts +1 -1
  103. package/src/hooks/useHover.ts +30 -17
  104. package/src/hooks/useIndent.ts +2 -0
  105. package/src/hooks/useLabel.ts +12 -10
  106. package/src/hooks/useObjectURL.ts +5 -3
  107. package/src/hooks/usePlatform.ts +5 -3
  108. package/src/hooks/useTheme.ts +3 -1
  109. package/src/index.css +25 -4
  110. package/src/index.tsx +7 -2
  111. package/src/utils/classNames.ts +4 -3
  112. package/src/utils/combobox.ts +2 -0
  113. package/src/utils/editableBlockStyles.ts +10 -0
  114. package/src/utils/formatByteSize.ts +8 -0
  115. package/src/utils/withSeparatorElements.ts +1 -1
  116. package/src/hooks/usePreservePanelSize.tsx +0 -183
  117. package/src/hooks/useWindowSize.tsx +0 -26
  118. package/src/mediaQuery.ts +0 -13
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";
@@ -66,6 +68,7 @@ export * from "./components/sorting/Sortable";
66
68
  export * from "./components/sorting/sorting";
67
69
  export * from "./components/Spacer";
68
70
  export * from "./components/Switch";
71
+ export * from "./components/Tabs";
69
72
  export * from "./components/Text";
70
73
  export * from "./components/TextArea";
71
74
  export * from "./components/Toast";
@@ -80,6 +83,7 @@ export * from "./contexts/DialogContext";
80
83
  export * from "./contexts/FloatingWindowContext";
81
84
  export * from "./contexts/GlobalInputBlurContext";
82
85
  export * from "./contexts/ImageDataContext";
86
+ export * from "./contexts/LinkComponentContext";
83
87
  export * from "./contexts/OpenPortalsContext";
84
88
  export * from "./contexts/PortalScopeContext";
85
89
  // Hooks
@@ -87,16 +91,16 @@ export * from "./hooks/useHover";
87
91
  export * from "./hooks/useIndent";
88
92
  export * from "./hooks/useLabel";
89
93
  export * from "./hooks/usePlatform";
90
- export * from "./hooks/usePreservePanelSize";
91
94
  export * from "./hooks/useTheme";
92
- export * from "./mediaQuery";
93
95
  export * from "./theme";
94
96
  export * from "./utils/classNames";
95
97
  export * from "./utils/createSectionedMenu";
98
+ export * from "./utils/formatByteSize";
96
99
  export * from "./utils/getGradientBackground";
97
100
  // Utils
98
101
  export * from "./utils/colorFromString";
99
102
  export * from "./utils/combobox";
103
+ export * from "./utils/editableBlockStyles";
100
104
  export * from "./utils/fuzzyScorer";
101
105
  export * from "./utils/moveTreeItem";
102
106
  export * from "./utils/selection";
@@ -110,3 +114,4 @@ export * as InspectorPrimitives from "./components/InspectorPrimitives";
110
114
 
111
115
  export * from "./components/BaseToolbar";
112
116
  export * from "./components/Toolbar";
117
+ export * from "./components/ToolbarDrawer";
@@ -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
- return args.filter(Boolean).join(" ").trim();
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.split(/\s+/);
72
+ let classNamesList = classes?.split(/\s+/) ?? [];
72
73
  options?.categories?.forEach((category) => {
73
74
  classNamesList = filterLastClassNameInCategory({
74
75
  classNames: classNamesList,
@@ -1,3 +1,5 @@
1
+ "use client";
2
+
1
3
  import { chunkBy, partition } from "@noya-app/noya-utils";
2
4
  import { useSyncExternalStore } from "react";
3
5
  import {
@@ -0,0 +1,10 @@
1
+ import { cx } from "./classNames";
2
+
3
+ export const editableBlockStyles = (
4
+ viewType: "editable" | "readOnly" | "preview" = "editable"
5
+ ) =>
6
+ cx(
7
+ "relative outline-primary focus:outline focus:outline-1",
8
+ viewType !== "preview" &&
9
+ "hover:outline-2 [&:not(:has([data-editor-selectable-block]:hover))]:hover:outline"
10
+ );
@@ -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 React, { useLayoutEffect, useRef } from "react";
2
- import { ImperativePanelGroupHandle } from "react-resizable-panels";
3
- import { PanelLayoutState } from "../components/workspace/types";
4
- import { useWindowSize } from "./useWindowSize";
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
- }
@@ -1,26 +0,0 @@
1
- import { useEffect, useState } from "react";
2
-
3
- export function useWindowSize() {
4
- const [size, setSize] = useState(
5
- typeof window === "undefined"
6
- ? { width: 0, height: 0 }
7
- : {
8
- width: window.innerWidth,
9
- height: window.innerHeight,
10
- }
11
- );
12
-
13
- useEffect(() => {
14
- const handleResize = () =>
15
- setSize({
16
- width: window.innerWidth,
17
- height: window.innerHeight,
18
- });
19
-
20
- window.addEventListener("resize", handleResize);
21
-
22
- return () => window.removeEventListener("resize", handleResize);
23
- }, []);
24
-
25
- return size;
26
- }
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
- };