@noya-app/noya-designsystem 0.1.76 → 0.1.78

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 (86) hide show
  1. package/.turbo/turbo-build.log +20 -12
  2. package/CHANGELOG.md +19 -0
  3. package/dist/chunk-D57E6H3M.mjs +36 -0
  4. package/dist/chunk-D57E6H3M.mjs.map +1 -0
  5. package/dist/emojis.d.mts +1 -0
  6. package/dist/emojis.d.ts +1 -0
  7. package/dist/emojis.js +31 -0
  8. package/dist/emojis.js.map +1 -0
  9. package/dist/emojis.mjs +8 -0
  10. package/dist/emojis.mjs.map +1 -0
  11. package/dist/index.css +1 -1
  12. package/dist/index.d.mts +192 -93
  13. package/dist/index.d.ts +192 -93
  14. package/dist/index.js +3355 -1763
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +3622 -2030
  17. package/dist/index.mjs.map +1 -1
  18. package/package.json +13 -9
  19. package/src/__tests__/__snapshots__/fuzzyScorer.test.ts.snap +1 -1
  20. package/src/components/Avatar.tsx +10 -10
  21. package/src/components/Banner.tsx +1 -1
  22. package/src/components/BaseToolbar.tsx +20 -6
  23. package/src/components/Button.tsx +2 -1
  24. package/src/components/Chip.tsx +1 -1
  25. package/src/components/ColorSwatchControl.tsx +22 -14
  26. package/src/components/CommandPalette.tsx +10 -6
  27. package/src/components/ContextMenu.tsx +249 -38
  28. package/src/components/Dialog.tsx +70 -67
  29. package/src/components/Drawer.tsx +56 -17
  30. package/src/components/DropdownMenu.tsx +307 -46
  31. package/src/components/EditableText.tsx +1 -1
  32. package/src/components/EmojiPicker.tsx +645 -0
  33. package/src/components/GridBackground.tsx +40 -0
  34. package/src/components/GridView.tsx +5 -1
  35. package/src/components/IVirtualizedList.tsx +21 -1
  36. package/src/components/InputField.tsx +2 -10
  37. package/src/components/InspectorContainer.tsx +4 -2
  38. package/src/components/Message.tsx +5 -16
  39. package/src/components/OverlayToolbar.tsx +97 -0
  40. package/src/components/Popover.tsx +73 -107
  41. package/src/components/Progress.tsx +18 -18
  42. package/src/components/ScrollArea.tsx +66 -31
  43. package/src/components/ScrollableSidebar.tsx +1 -1
  44. package/src/components/SegmentedControl.tsx +166 -38
  45. package/src/components/SelectMenu.tsx +193 -101
  46. package/src/components/Slider.tsx +40 -38
  47. package/src/components/StackNavigator.tsx +1 -0
  48. package/src/components/Switch.tsx +4 -4
  49. package/src/components/TextArea.tsx +1 -1
  50. package/src/components/Toast.tsx +99 -26
  51. package/src/components/Toolbar.tsx +133 -24
  52. package/src/components/Tooltip.tsx +18 -8
  53. package/src/components/UserPointer.tsx +5 -3
  54. package/src/components/Virtualized.tsx +193 -14
  55. package/src/components/VisuallyHidden.tsx +20 -0
  56. package/src/components/__tests__/Virtualized.math.test.ts +426 -1
  57. package/src/components/__tests__/Virtualized.test.tsx +129 -1
  58. package/src/components/ai-assistant/AIAssistantLayout.tsx +11 -6
  59. package/src/components/internal/Menu.tsx +4 -0
  60. package/src/components/listView/ListViewEditableRowTitle.tsx +1 -1
  61. package/src/components/listView/ListViewRoot.tsx +5 -1
  62. package/src/components/resizablePanels/Panel.tsx +94 -0
  63. package/src/components/resizablePanels/PanelGroup.tsx +498 -0
  64. package/src/components/resizablePanels/PanelGroupContext.tsx +14 -0
  65. package/src/components/resizablePanels/PanelResizeHandle.tsx +61 -0
  66. package/src/components/resizablePanels/index.ts +7 -0
  67. package/src/components/resizablePanels/types.ts +65 -0
  68. package/src/components/workspace/DrawerWorkspaceLayout.tsx +22 -7
  69. package/src/components/workspace/PanelWorkspaceLayout.tsx +30 -84
  70. package/src/components/workspace/WorkspaceLayout.tsx +82 -76
  71. package/src/components/workspace/types.ts +6 -4
  72. package/src/contexts/DialogContext.tsx +15 -24
  73. package/src/emojis.ts +1 -0
  74. package/src/hooks/useTriggerToggle.ts +95 -0
  75. package/src/index.css +2 -0
  76. package/src/index.tsx +3 -2
  77. package/src/theme/proseTheme.ts +22 -0
  78. package/src/utils/mergeProps.ts +57 -0
  79. package/src/utils/skinTone.ts +90 -0
  80. package/tailwind.config.ts +6 -1
  81. package/tsup.config.ts +1 -1
  82. package/src/__tests__/workspaceLayout.test.ts +0 -281
  83. package/src/components/ScrollArea2.tsx +0 -76
  84. package/src/components/internal/MenuViewport.tsx +0 -178
  85. package/src/components/internal/SelectItem.tsx +0 -138
  86. package/src/components/workspace/panelStorage.ts +0 -216
@@ -1,178 +0,0 @@
1
- "use client";
2
-
3
- import { ChevronRightIcon } from "@noya-app/noya-icons";
4
- import {
5
- ContextMenu as RadixContextMenu,
6
- DropdownMenu as RadixDropdownMenu,
7
- } from "radix-ui";
8
- import React from "react";
9
- import {
10
- portalScopeProps,
11
- usePortalScopeId,
12
- } from "../../contexts/PortalScopeContext";
13
- import { cx } from "../../utils/classNames";
14
- import {
15
- isSelectableMenuItem,
16
- MenuItem,
17
- SectionHeaderMenuItem,
18
- styles,
19
- } from "./Menu";
20
- import { SelectItem } from "./SelectItem";
21
-
22
- type MenuSeparatorComponent = React.FC<{ className?: string }>;
23
- type MenuItemTextComponent = React.FC<{ children?: React.ReactNode }>;
24
- type MenuItemComponent = React.ForwardRefExoticComponent<
25
- React.RefAttributes<HTMLDivElement> &
26
- React.PropsWithoutRef<{
27
- className?: string;
28
- disabled?: boolean;
29
- children?: React.ReactNode;
30
- value: string;
31
- onSelect?: (event: any) => void;
32
- onClick?: (event: React.MouseEvent<any>) => void;
33
- }>
34
- >;
35
- type MenuCheckboxItemComponent = React.FC<{
36
- checked?: boolean | "indeterminate";
37
- disabled?: boolean;
38
- onSelect?: (event: any) => void;
39
- className?: string;
40
- children?: React.ReactNode;
41
- }>;
42
-
43
- type MenuItemIndicatorComponent = React.FC<{
44
- className?: string;
45
- children?: React.ReactNode;
46
- }>;
47
-
48
- export type MenuComponents = {
49
- Separator: MenuSeparatorComponent;
50
- ItemText: MenuItemTextComponent;
51
- Item: MenuItemComponent;
52
- CheckboxItem?: MenuCheckboxItemComponent;
53
- ItemIndicator?: MenuItemIndicatorComponent;
54
- Sub?: typeof RadixDropdownMenu.Sub | typeof RadixContextMenu.Sub;
55
- SubTrigger?:
56
- | typeof RadixDropdownMenu.SubTrigger
57
- | typeof RadixContextMenu.SubTrigger;
58
- SubContent?:
59
- | typeof RadixDropdownMenu.SubContent
60
- | typeof RadixContextMenu.SubContent;
61
- Portal?: typeof RadixDropdownMenu.Portal | typeof RadixContextMenu.Portal;
62
- };
63
-
64
- type MenuViewportProps<T extends string> = {
65
- items: MenuItem<T>[];
66
- Components: MenuComponents;
67
- onSelect?: (value: any) => void;
68
- };
69
-
70
- export const MenuViewport = <T extends string>({
71
- items,
72
- Components,
73
- onSelect,
74
- }: MenuViewportProps<T>) => {
75
- const portalScopeId = usePortalScopeId();
76
-
77
- const hasCheckedItem = items.some(
78
- (item) => isSelectableMenuItem(item) && item.checked
79
- );
80
-
81
- return (
82
- <>
83
- {items.map((item, index) => {
84
- switch (item.type) {
85
- case "separator":
86
- return (
87
- <Components.Separator
88
- key={index}
89
- className={styles.separatorStyle}
90
- />
91
- );
92
-
93
- case "sectionHeader":
94
- return (
95
- <SectionHeaderMenuItem
96
- isFirst={index === 0}
97
- key={item.id}
98
- {...item}
99
- indented={hasCheckedItem}
100
- />
101
- );
102
- case "popover":
103
- return null;
104
- case "submenu":
105
- if (
106
- item.items &&
107
- Components.Sub &&
108
- Components.SubTrigger &&
109
- Components.SubContent &&
110
- Components.Portal
111
- ) {
112
- return (
113
- <Components.Sub key={item.id}>
114
- <Components.SubTrigger
115
- className={cx(
116
- styles.itemStyle({ disabled: item.disabled }),
117
- styles.selectedItemStyle
118
- )}
119
- asChild
120
- onClick={(e) => {
121
- e.stopPropagation();
122
- e.preventDefault();
123
- }}
124
- disabled={item.disabled}
125
- >
126
- <SelectItem
127
- value={item.id}
128
- icon={item.icon}
129
- checked={item.checked}
130
- onSelect={onSelect}
131
- Components={Components}
132
- indented={hasCheckedItem}
133
- disabled={item.disabled}
134
- >
135
- <div className="n-flex n-items-center n-flex-1">
136
- {item.title}
137
- </div>
138
- <ChevronRightIcon className="-n-mr-1" />
139
- </SelectItem>
140
- </Components.SubTrigger>
141
- <Components.Portal>
142
- <Components.SubContent
143
- {...portalScopeProps(portalScopeId)}
144
- alignOffset={-5}
145
- className={styles.contentStyle}
146
- >
147
- <MenuViewport
148
- items={item.items}
149
- Components={Components}
150
- onSelect={onSelect}
151
- />
152
- </Components.SubContent>
153
- </Components.Portal>
154
- </Components.Sub>
155
- );
156
- } else return null;
157
- default:
158
- return (
159
- <SelectItem
160
- key={item.value}
161
- value={item.value}
162
- icon={item.icon}
163
- checked={item.checked}
164
- shortcut={item.shortcut}
165
- onSelect={onSelect}
166
- Components={Components}
167
- indented={hasCheckedItem}
168
- testSelected={item.testSelected}
169
- disabled={item.disabled}
170
- >
171
- {item.title ?? item.value}
172
- </SelectItem>
173
- );
174
- }
175
- })}
176
- </>
177
- );
178
- };
@@ -1,138 +0,0 @@
1
- "use client";
2
-
3
- import { renderIcon } from "../Icons";
4
-
5
- import { Select } from "radix-ui";
6
- import React, { useCallback } from "react";
7
- import { cx } from "../../utils/classNames";
8
- import { Spacer } from "../Spacer";
9
- import { Checkmark } from "./Checkmark";
10
- import {
11
- CHECKBOX_INDENT_WIDTH,
12
- CHECKBOX_RIGHT_INSET,
13
- CHECKBOX_WIDTH,
14
- KeyboardShortcut,
15
- styles,
16
- } from "./Menu";
17
- import { MenuComponents } from "./MenuViewport";
18
-
19
- export const SelectItem = React.forwardRef(
20
- (
21
- {
22
- children,
23
- icon,
24
- disabled,
25
- checked,
26
- Components,
27
- value,
28
- onSelect,
29
- shortcut,
30
- indented,
31
- testSelected,
32
- ...props
33
- }: Select.SelectItemProps & {
34
- icon?: React.ReactNode;
35
- checked?: boolean | "indeterminate";
36
- Components: MenuComponents;
37
- onSelect?: (value: any) => void;
38
- shortcut?: string;
39
- indented?: boolean;
40
- testSelected?: boolean;
41
- },
42
- forwardedRef: React.ForwardedRef<HTMLDivElement>
43
- ) => {
44
- const handleSelectItem = useCallback(() => {
45
- if (!value) return;
46
- onSelect?.(value);
47
- }, [onSelect, value]);
48
-
49
- // Prevent the click from propagating outside the menu
50
- const cancelClickPropagation = useCallback(
51
- (event: React.MouseEvent<HTMLDivElement>) => {
52
- event.stopPropagation();
53
- },
54
- []
55
- );
56
-
57
- if (checked && Components.CheckboxItem) {
58
- return (
59
- <div className="n-px-1">
60
- <Components.CheckboxItem
61
- checked={checked}
62
- disabled={disabled}
63
- onSelect={handleSelectItem}
64
- className={cx(
65
- styles.itemStyle({ disabled }),
66
- styles.selectedItemStyle,
67
- testSelected && styles.testSelectedItemStyle
68
- )}
69
- >
70
- <Spacer.Horizontal size={CHECKBOX_INDENT_WIDTH} />
71
- {Components.ItemIndicator && (
72
- <Components.ItemIndicator {...styles.itemIndicator}>
73
- <Checkmark />
74
- </Components.ItemIndicator>
75
- )}
76
- {icon && (
77
- <>
78
- {renderIcon(icon)}
79
- <Spacer.Horizontal size={8} />
80
- </>
81
- )}
82
- {children}
83
- {shortcut && (
84
- <>
85
- <Spacer.Horizontal />
86
- <Spacer.Horizontal size={24} />
87
- <KeyboardShortcut shortcut={shortcut} />
88
- </>
89
- )}
90
- </Components.CheckboxItem>
91
- </div>
92
- );
93
- }
94
-
95
- return (
96
- <div className="n-px-1">
97
- <Components.Item
98
- className={cx(
99
- styles.itemStyle({ disabled }),
100
- styles.selectedItemStyle,
101
- testSelected && styles.testSelectedItemStyle
102
- )}
103
- disabled={disabled}
104
- value={value}
105
- ref={forwardedRef}
106
- onClick={cancelClickPropagation}
107
- onSelect={handleSelectItem}
108
- {...props}
109
- >
110
- <div className="n-flex n-flex-1 n-items-center">
111
- {indented && <Spacer.Horizontal size={CHECKBOX_INDENT_WIDTH} />}
112
- {checked ? (
113
- <div {...styles.itemIndicator}>
114
- <Checkmark />
115
- </div>
116
- ) : indented ? (
117
- <Spacer.Horizontal size={CHECKBOX_WIDTH - CHECKBOX_RIGHT_INSET} />
118
- ) : null}
119
- {icon && (
120
- <>
121
- {renderIcon(icon)}
122
- <Spacer.Horizontal size={8} />
123
- </>
124
- )}
125
- <Components.ItemText>{children}</Components.ItemText>
126
- {shortcut && (
127
- <>
128
- <Spacer.Horizontal />
129
- <Spacer.Horizontal size={24} />
130
- <KeyboardShortcut shortcut={shortcut} />
131
- </>
132
- )}
133
- </div>
134
- </Components.Item>
135
- </div>
136
- );
137
- }
138
- );
@@ -1,216 +0,0 @@
1
- import { clientStorage, IClientStorage } from "@noya-app/react-utils";
2
- import { PanelGroupStorage } from "react-resizable-panels";
3
- import {
4
- CONTENT_AREA_ID,
5
- LEFT_SIDEBAR_ID,
6
- RIGHT_SIDEBAR_ID,
7
- } from "./constants";
8
- import {
9
- PercentageSidebarOptions,
10
- WorkspaceLayoutGroup,
11
- WorkspaceLayoutState,
12
- } from "./types";
13
-
14
- // Workspace sizes are stored as percentages (e.g. layout: [78.7224911972, 21.2775088028])
15
- // we need to convert them to pixels relative to the window width before storing
16
- // and convert them back to percentages when getting the item
17
- export const panelStorage: PanelGroupStorage = {
18
- getItem: (name) => {
19
- const item = clientStorage.getItem(name);
20
-
21
- if (item) {
22
- const parsed = JSON.parse(item);
23
- const percentageSize = mapWorkspaceLayoutState(parsed, (size) =>
24
- toPercentageSize(size)
25
- );
26
- const stringified = JSON.stringify(percentageSize);
27
- // console.log("getItem", name, stringified);
28
- return stringified;
29
- }
30
-
31
- return item;
32
- },
33
-
34
- setItem: (name, value) => {
35
- const parsed = JSON.parse(value);
36
- const pixelSize = mapWorkspaceLayoutState(parsed, (size) =>
37
- toPixelSize(size)
38
- );
39
- // console.log("setItem", name, pixelSize);
40
- clientStorage.setItem(name, JSON.stringify(pixelSize));
41
- },
42
- };
43
-
44
- export const toPixelSize = (size: number, windowWidth = window.innerWidth) =>
45
- Math.round((size * windowWidth) / 100);
46
- export const toPercentageSize = (
47
- size: number,
48
- windowWidth = window.innerWidth
49
- ) => (size * 100) / windowWidth;
50
-
51
- export function mapWorkspaceLayoutState(
52
- layout: WorkspaceLayoutState,
53
- f: (size: number) => number
54
- ): WorkspaceLayoutState {
55
- return Object.fromEntries(
56
- Object.entries(layout).map(
57
- ([key, value]): [string, WorkspaceLayoutGroup] => {
58
- const expandToSizes = Object.fromEntries(
59
- Object.entries(value.expandToSizes).map(([key, value]) => [
60
- key,
61
- f(value),
62
- ])
63
- );
64
-
65
- return [
66
- key,
67
- {
68
- expandToSizes,
69
- layout: value.layout.map(f),
70
- },
71
- ];
72
- }
73
- )
74
- );
75
- }
76
-
77
- export function getLayoutIds({
78
- hasLeftPanel,
79
- hasRightPanel,
80
- hasCenterPanel,
81
- }: {
82
- hasLeftPanel: boolean;
83
- hasRightPanel: boolean;
84
- hasCenterPanel: boolean;
85
- }) {
86
- return [
87
- hasLeftPanel && LEFT_SIDEBAR_ID,
88
- hasCenterPanel && CONTENT_AREA_ID,
89
- hasRightPanel && RIGHT_SIDEBAR_ID,
90
- ].flatMap((id) => (id ? [id] : []));
91
- }
92
-
93
- export function getPropertyKey(layoutIds: string[]) {
94
- return layoutIds.sort().join(",");
95
- }
96
-
97
- export function getStorageKey(autoSaveId: string) {
98
- return `react-resizable-panels:${autoSaveId}`;
99
- }
100
-
101
- export function getInitialLayout({
102
- layoutIds,
103
- leftSidebarOptions,
104
- rightSidebarOptions,
105
- centerPanelPercentage,
106
- hasLeftPanel,
107
- hasRightPanel,
108
- hasCenterPanel,
109
- windowWidth = window.innerWidth,
110
- }: {
111
- layoutIds: string[];
112
- leftSidebarOptions: PercentageSidebarOptions;
113
- rightSidebarOptions: PercentageSidebarOptions;
114
- centerPanelPercentage: number;
115
- hasLeftPanel: boolean;
116
- hasRightPanel: boolean;
117
- hasCenterPanel: boolean;
118
- windowWidth?: number;
119
- }) {
120
- return layoutIds.map((id) => {
121
- if (id === LEFT_SIDEBAR_ID && hasLeftPanel) {
122
- return leftSidebarOptions.defaultCollapsed
123
- ? 0
124
- : toPixelSize(leftSidebarOptions.initialSize ?? 0, windowWidth);
125
- } else if (id === RIGHT_SIDEBAR_ID && hasRightPanel) {
126
- return rightSidebarOptions.defaultCollapsed
127
- ? 0
128
- : toPixelSize(rightSidebarOptions.initialSize ?? 0, windowWidth);
129
- } else if (id === CONTENT_AREA_ID && hasCenterPanel) {
130
- const shouldShowLeftSidebar =
131
- hasLeftPanel && !leftSidebarOptions.defaultCollapsed;
132
- const shouldShowRightSidebar =
133
- hasRightPanel && !rightSidebarOptions.defaultCollapsed;
134
-
135
- if (!shouldShowLeftSidebar && !shouldShowRightSidebar) {
136
- return toPixelSize(100, windowWidth);
137
- }
138
-
139
- return toPixelSize(centerPanelPercentage, windowWidth);
140
- }
141
- return 0;
142
- });
143
- }
144
-
145
- export function setInitialLayout({
146
- storageKey,
147
- propertyKey,
148
- calculateLayout,
149
- storage = clientStorage,
150
- }: {
151
- storageKey: string;
152
- propertyKey: string;
153
- calculateLayout: () => number[];
154
- storage?: IClientStorage;
155
- }) {
156
- const savedLayout = storage.getItem(storageKey);
157
-
158
- if (!savedLayout) {
159
- const layoutObject: WorkspaceLayoutState = {
160
- [propertyKey]: {
161
- layout: calculateLayout(),
162
- expandToSizes: {},
163
- },
164
- };
165
-
166
- storage.setItem(storageKey, JSON.stringify(layoutObject));
167
- } else {
168
- let parsedLayout: WorkspaceLayoutState;
169
-
170
- try {
171
- parsedLayout = JSON.parse(savedLayout);
172
- } catch (error) {
173
- console.error(error);
174
- return;
175
- }
176
-
177
- if (!(propertyKey in parsedLayout)) {
178
- const layoutObject: WorkspaceLayoutState = {
179
- ...parsedLayout,
180
- [propertyKey]: {
181
- layout: calculateLayout(),
182
- expandToSizes: {},
183
- },
184
- };
185
-
186
- storage.setItem(storageKey, JSON.stringify(layoutObject));
187
- }
188
- }
189
- }
190
-
191
- export function getLayoutCollapsedState({
192
- layoutGroup,
193
- layoutIds,
194
- hasLeftPanel,
195
- hasRightPanel,
196
- }: {
197
- layoutGroup: WorkspaceLayoutGroup;
198
- propertyKey: string;
199
- layoutIds: string[];
200
- hasLeftPanel: boolean;
201
- hasRightPanel: boolean;
202
- }) {
203
- const propertySize = Object.fromEntries(
204
- layoutIds.map((id, index) => [id, layoutGroup.layout?.[index]])
205
- );
206
-
207
- const leftSize = propertySize?.[LEFT_SIDEBAR_ID];
208
- const leftSidebarCollapsed = hasLeftPanel && leftSize === 0 ? true : false;
209
- const rightSize = propertySize?.[RIGHT_SIDEBAR_ID];
210
- const rightSidebarCollapsed = hasRightPanel && rightSize === 0 ? true : false;
211
-
212
- return {
213
- leftSidebarCollapsed,
214
- rightSidebarCollapsed,
215
- };
216
- }