torch-glare 2.1.0 → 2.1.2

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 (65) hide show
  1. package/apps/lib/components/Badge.tsx +34 -137
  2. package/apps/lib/components/BadgeField.tsx +4 -4
  3. package/apps/lib/components/DataViews/ARCHITECTURE.md +439 -0
  4. package/apps/lib/components/DataViews/DataViewsConfigPanel.tsx +416 -0
  5. package/apps/lib/components/DataViews/DataViewsHeader.tsx +126 -0
  6. package/apps/lib/components/DataViews/DataViewsLayout.tsx +300 -0
  7. package/apps/lib/components/DataViews/FilterPanel.tsx +324 -0
  8. package/apps/lib/components/DataViews/InboxView.tsx +514 -0
  9. package/apps/lib/components/DataViews/KanbanView.tsx +242 -0
  10. package/apps/lib/components/DataViews/PanelControls.tsx +80 -0
  11. package/apps/lib/components/DataViews/SettingsPanel.tsx +285 -0
  12. package/apps/lib/components/DataViews/TableView.tsx +232 -0
  13. package/apps/lib/components/DataViews/TreeView.tsx +363 -0
  14. package/apps/lib/components/DataViews/badgeAdapter.ts +45 -0
  15. package/apps/lib/components/DataViews/fieldRenderers.tsx +334 -0
  16. package/apps/lib/components/DataViews/filters/DateRangePopover.tsx +113 -0
  17. package/apps/lib/components/DataViews/filters/PresetChips.tsx +45 -0
  18. package/apps/lib/components/DataViews/filters/RangeSliderWithInputs.tsx +154 -0
  19. package/apps/lib/components/DataViews/index.ts +30 -0
  20. package/apps/lib/components/DataViews/tree/TreeDrawer.tsx +54 -0
  21. package/apps/lib/components/DataViews/tree/TreeSidebar.tsx +77 -0
  22. package/apps/lib/components/DataViews/types.ts +177 -0
  23. package/apps/lib/components/TreeFolder/TreeFolder.tsx +387 -0
  24. package/apps/lib/components/TreeFolder/TreeFolderBreadcrumb.tsx +80 -0
  25. package/apps/lib/components/TreeFolder/TreeFolderRow.tsx +235 -0
  26. package/apps/lib/components/TreeFolder/TreeFolderStyles.tsx +60 -0
  27. package/apps/lib/components/TreeFolder/icons.tsx +63 -0
  28. package/apps/lib/components/TreeFolder/index.ts +17 -0
  29. package/apps/lib/components/TreeFolder/treeFolderUtils.ts +114 -0
  30. package/apps/lib/components/TreeFolder/types.ts +68 -0
  31. package/apps/lib/components/TreeFolder/useTreeFolderDnD.ts +261 -0
  32. package/apps/lib/hooks/useDataViewsState.ts +169 -0
  33. package/apps/lib/hooks/useIsMobile.ts +21 -0
  34. package/apps/lib/utils/dataViews/columnUtils.ts +130 -0
  35. package/apps/lib/utils/dataViews/fieldUtils.ts +198 -0
  36. package/apps/lib/utils/dataViews/nestedDataUtils.tsx +364 -0
  37. package/apps/lib/utils/dataViews/pathUtils.ts +132 -0
  38. package/apps/lib/utils/dataViews/rangeUtils.ts +225 -0
  39. package/apps/lib/utils/dataViews/treeUtils.ts +403 -0
  40. package/dist/bin/index.js +3 -3
  41. package/dist/bin/index.js.map +1 -1
  42. package/dist/src/commands/add.d.ts.map +1 -1
  43. package/dist/src/commands/add.js +29 -6
  44. package/dist/src/commands/add.js.map +1 -1
  45. package/dist/src/commands/utils.d.ts.map +1 -1
  46. package/dist/src/commands/utils.js +22 -2
  47. package/dist/src/commands/utils.js.map +1 -1
  48. package/dist/src/shared/copyComponentsRecursively.d.ts.map +1 -1
  49. package/dist/src/shared/copyComponentsRecursively.js +8 -1
  50. package/dist/src/shared/copyComponentsRecursively.js.map +1 -1
  51. package/dist/src/shared/getDependenciesAndInstallNestedComponents.d.ts +18 -4
  52. package/dist/src/shared/getDependenciesAndInstallNestedComponents.d.ts.map +1 -1
  53. package/dist/src/shared/getDependenciesAndInstallNestedComponents.js +110 -40
  54. package/dist/src/shared/getDependenciesAndInstallNestedComponents.js.map +1 -1
  55. package/docs/components/badge-field.md +21 -21
  56. package/docs/components/badge.md +156 -483
  57. package/docs/components/form-stepper.md +244 -0
  58. package/docs/components/stepper.md +215 -0
  59. package/docs/components/timeline.md +248 -0
  60. package/docs/reference/components.md +8 -7
  61. package/docs/reference/types.md +34 -26
  62. package/docs/tutorials/theming-basics.md +30 -27
  63. package/package.json +1 -1
  64. /package/docs/components/{labeled-checkbox.md → labeled-check-box.md} +0 -0
  65. /package/docs/components/{tree-dropdown.md → tree-drop-down.md} +0 -0
@@ -0,0 +1,80 @@
1
+ "use client"
2
+
3
+ import { ChevronRight } from "lucide-react"
4
+ import { cn } from "../../utils/cn"
5
+ import type { TreeFolderBreadcrumb as BreadcrumbItems } from "./types"
6
+
7
+ type Props = {
8
+ items: BreadcrumbItems
9
+ onSelect?: (id: string) => void
10
+ className?: string
11
+ maxItems?: number
12
+ }
13
+
14
+ export function TreeFolderBreadcrumb({
15
+ items,
16
+ onSelect,
17
+ className,
18
+ maxItems = 4,
19
+ }: Props) {
20
+ if (items.length === 0) {
21
+ return (
22
+ <div
23
+ className={cn(
24
+ "px-3 py-1.5 text-xs text-content-presentation-global-tertiary truncate",
25
+ className,
26
+ )}
27
+ >
28
+ No selection
29
+ </div>
30
+ )
31
+ }
32
+
33
+ const display =
34
+ items.length > maxItems
35
+ ? [items[0], { id: "__ellipsis", name: "…" }, ...items.slice(-(maxItems - 2))]
36
+ : items
37
+
38
+ return (
39
+ <nav
40
+ aria-label="Tree path"
41
+ className={cn(
42
+ "px-3 py-1.5 flex items-center gap-1 text-xs text-content-presentation-global-secondary min-w-0",
43
+ className,
44
+ )}
45
+ >
46
+ <ol className="flex items-center gap-1 min-w-0 flex-1">
47
+ {display.map((item, idx) => {
48
+ const isLast = idx === display.length - 1
49
+ const isEllipsis = item.id === "__ellipsis"
50
+ return (
51
+ <li key={`${item.id}-${idx}`} className="flex items-center gap-1 min-w-0">
52
+ {idx > 0 && (
53
+ <ChevronRight className="w-3 h-3 shrink-0 text-content-presentation-global-tertiary" />
54
+ )}
55
+ {isEllipsis ? (
56
+ <span className="text-content-presentation-global-tertiary">…</span>
57
+ ) : isLast ? (
58
+ <span
59
+ className="truncate text-content-presentation-global-primary font-medium"
60
+ title={item.name}
61
+ >
62
+ {item.name}
63
+ </span>
64
+ ) : (
65
+ <button
66
+ type="button"
67
+ onClick={() => onSelect?.(item.id)}
68
+ className="truncate hover:text-content-presentation-global-primary"
69
+ title={item.name}
70
+ >
71
+ {item.name}
72
+ </button>
73
+ )}
74
+ </li>
75
+ )
76
+ })}
77
+ </ol>
78
+ </nav>
79
+ )
80
+ }
@@ -0,0 +1,235 @@
1
+ "use client"
2
+
3
+ import { ChevronRight, ChevronDown, GripVertical } from "lucide-react"
4
+ import type { DragEvent } from "react"
5
+ import { cn } from "../../utils/cn"
6
+ import { resolveIcon } from "./icons"
7
+ import type {
8
+ TreeFolderIconResolver,
9
+ TreeFolderVisibleRow,
10
+ } from "./types"
11
+
12
+ export type TreeFolderRowDragHandlers = {
13
+ draggable: boolean
14
+ onDragStart: (e: DragEvent<HTMLElement>) => void
15
+ onDragEnd: (e: DragEvent<HTMLElement>) => void
16
+ onDragOver: (e: DragEvent<HTMLElement>) => void
17
+ onDragLeave: (e: DragEvent<HTMLElement>) => void
18
+ onDrop: (e: DragEvent<HTMLElement>) => void
19
+ }
20
+
21
+ export type TreeFolderRowProps = {
22
+ row: TreeFolderVisibleRow
23
+ rowHeight: number
24
+ indent: number
25
+ iconFor?: TreeFolderIconResolver
26
+
27
+ isSelected: boolean
28
+ isAncestor: boolean
29
+ isDescendantOfSelected: boolean
30
+ /** True when the previous visible row is part of the same selected-subtree band. */
31
+ isPrevInBand: boolean
32
+ /** True when the next visible row is part of the same selected-subtree band. */
33
+ isNextInBand: boolean
34
+
35
+ isDragging: boolean
36
+ isDropTargetInside: boolean
37
+ isDropBefore: boolean
38
+ isDropAfter: boolean
39
+
40
+ dndEnabled: boolean
41
+ onSelect: (id: string | null) => void
42
+ onToggle: (id: string) => void
43
+ dragHandlers: TreeFolderRowDragHandlers
44
+ }
45
+
46
+ export function TreeFolderRow({
47
+ row,
48
+ rowHeight,
49
+ indent,
50
+ iconFor,
51
+ isSelected,
52
+ isAncestor,
53
+ isDescendantOfSelected,
54
+ isPrevInBand,
55
+ isNextInBand,
56
+ isDragging,
57
+ isDropTargetInside,
58
+ isDropBefore,
59
+ isDropAfter,
60
+ dndEnabled,
61
+ onSelect,
62
+ onToggle,
63
+ dragHandlers,
64
+ }: TreeFolderRowProps) {
65
+ const { node, level, isOpen, isInternal } = row
66
+ const data = node
67
+ const hasChildren = isInternal
68
+
69
+ const willReceiveDrop = isDropTargetInside && dndEnabled
70
+ const inSubtreeOfSelected = isDescendantOfSelected
71
+ const inAncestorChain = isAncestor
72
+ const inBand = (isSelected || inSubtreeOfSelected) && !willReceiveDrop
73
+
74
+ const isBandStart = inBand && !isPrevInBand
75
+ const isBandEnd = inBand && !isNextInBand
76
+
77
+ const icon = resolveIcon(iconFor, data, {
78
+ isOpen,
79
+ isInternal,
80
+ isSelected,
81
+ })
82
+
83
+ const outerClassName = cn(
84
+ "relative w-full min-w-max",
85
+ isDragging && "opacity-40",
86
+ data.disabled && "opacity-50 pointer-events-none",
87
+ )
88
+
89
+ const bandClassName = cn(
90
+ "pointer-events-none absolute inset-y-0 inset-x-[2px] transition-colors duration-100",
91
+ "rounded-md",
92
+ inBand && !isBandStart && "rounded-t-none",
93
+ inBand && !isBandEnd && "rounded-b-none",
94
+ !willReceiveDrop && !inBand &&
95
+ "group-hover/row:bg-background-presentation-form-field-hover group-active/row:bg-background-presentation-action-hover/20",
96
+ inBand && "bg-background-presentation-state-information-primary",
97
+ inAncestorChain && !inBand &&
98
+ "bg-background-presentation-state-information-secondary",
99
+ willReceiveDrop && "bg-background-presentation-state-information-primary",
100
+ )
101
+
102
+ const rowClassName = cn(
103
+ "relative z-10 flex items-center gap-1 py-1 pr-2 cursor-pointer text-sm min-w-max",
104
+ inBand && "text-white",
105
+ willReceiveDrop && "text-white",
106
+ )
107
+
108
+ const rowStyle = {
109
+ paddingLeft: 4 + level * indent,
110
+ height: rowHeight,
111
+ }
112
+
113
+ const handleRowClick = () => {
114
+ if (data.disabled) return
115
+ onSelect(node.id)
116
+ }
117
+
118
+ // Insert lines for "between" drops (above/below sibling). Inset to the row's
119
+ // indent so they line up with the new sibling's level.
120
+ const insertLineInset = 4 + level * indent
121
+
122
+ return (
123
+ <div
124
+ data-row-id={node.id}
125
+ className={cn("select-none group/row", outerClassName)}
126
+ {...dragHandlers}
127
+ >
128
+ <span aria-hidden className={bandClassName} />
129
+
130
+ {isDropBefore && (
131
+ <span
132
+ aria-hidden
133
+ className="pointer-events-none absolute -top-px left-0 right-0 z-20 h-0.5 bg-background-presentation-state-information-primary"
134
+ style={{ marginLeft: insertLineInset }}
135
+ />
136
+ )}
137
+ {isDropAfter && (
138
+ <span
139
+ aria-hidden
140
+ className="pointer-events-none absolute -bottom-px left-0 right-0 z-20 h-0.5 bg-background-presentation-state-information-primary"
141
+ style={{ marginLeft: insertLineInset }}
142
+ />
143
+ )}
144
+
145
+ <div
146
+ role="treeitem"
147
+ aria-expanded={isInternal ? isOpen : undefined}
148
+ aria-selected={isSelected}
149
+ aria-disabled={data.disabled || undefined}
150
+ aria-level={level + 1}
151
+ onClick={handleRowClick}
152
+ className={rowClassName}
153
+ style={rowStyle}
154
+ >
155
+ {dndEnabled && (
156
+ <span
157
+ className="shrink-0 w-4 h-4 flex items-center justify-center opacity-0 group-hover/row:opacity-100 transition-opacity duration-150 cursor-grab active:cursor-grabbing"
158
+ aria-hidden
159
+ >
160
+ <GripVertical
161
+ className={cn(
162
+ "w-3.5 h-3.5",
163
+ inBand ? "text-white/80" : "text-content-presentation-global-tertiary",
164
+ )}
165
+ />
166
+ </span>
167
+ )}
168
+
169
+ {hasChildren ? (
170
+ <button
171
+ type="button"
172
+ onClick={(e) => {
173
+ e.stopPropagation()
174
+ onToggle(node.id)
175
+ }}
176
+ className={cn(
177
+ "shrink-0 w-4 h-4 flex items-center justify-center rounded",
178
+ inBand
179
+ ? "text-white/80 hover:text-white"
180
+ : "text-content-presentation-global-tertiary hover:text-content-presentation-global-primary",
181
+ )}
182
+ aria-label={isOpen ? "Collapse" : "Expand"}
183
+ >
184
+ {isOpen ? (
185
+ <ChevronDown className="w-3.5 h-3.5" />
186
+ ) : (
187
+ <ChevronRight className="w-3.5 h-3.5" />
188
+ )}
189
+ </button>
190
+ ) : (
191
+ <span className="shrink-0 w-4 h-4" />
192
+ )}
193
+
194
+ <span
195
+ className={cn(
196
+ "shrink-0 w-4 h-4 flex items-center justify-center",
197
+ inBand ? "text-white/90" : "text-content-presentation-global-tertiary",
198
+ )}
199
+ aria-hidden
200
+ >
201
+ {icon}
202
+ </span>
203
+
204
+ <span className="whitespace-nowrap pr-2" title={data.name}>
205
+ {data.name}
206
+ </span>
207
+
208
+ {hasChildren && !isOpen && (
209
+ <span
210
+ className={cn(
211
+ "shrink-0 text-xs tabular-nums",
212
+ inBand ? "text-white/80" : "text-content-presentation-global-tertiary",
213
+ )}
214
+ >
215
+ ({countDescendants(node)})
216
+ </span>
217
+ )}
218
+ </div>
219
+ </div>
220
+ )
221
+ }
222
+
223
+ function countDescendants(node: {
224
+ children?: { children?: any[] }[] | null
225
+ }): number {
226
+ if (!node.children) return 0
227
+ let n = 0
228
+ const stack: any[] = [...node.children]
229
+ while (stack.length) {
230
+ n++
231
+ const top = stack.pop()
232
+ if (top.children) for (const c of top.children) stack.push(c)
233
+ }
234
+ return n
235
+ }
@@ -0,0 +1,60 @@
1
+ "use client"
2
+
3
+ /**
4
+ * Component-scoped CSS for TreeFolder. Rendered once by TreeFolder itself so
5
+ * the styles ship with the component (no globals.css required by consumers).
6
+ *
7
+ * Why a <style> tag instead of a CSS import:
8
+ * - Some consumers may not run a CSS pipeline that picks up imports from
9
+ * node_modules.
10
+ * - The styles target pseudo-elements (::-webkit-scrollbar-*) that Tailwind
11
+ * can't express without a plugin, and CSS-in-JS libraries would add a dep.
12
+ * - Inlining keeps the public package zero-config.
13
+ *
14
+ * The rules are scoped to `.tf-scroll`, which only TreeFolder applies — no
15
+ * risk of leaking to other elements on the page.
16
+ */
17
+ const CSS = `
18
+ .tf-scroll {
19
+ scrollbar-width: thin;
20
+ scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
21
+ }
22
+ .tf-scroll::-webkit-scrollbar {
23
+ width: 10px;
24
+ height: 10px;
25
+ }
26
+ .tf-scroll::-webkit-scrollbar-track {
27
+ background: transparent;
28
+ }
29
+ .tf-scroll::-webkit-scrollbar-thumb {
30
+ background: rgba(255, 255, 255, 0.18);
31
+ border: 2px solid transparent;
32
+ background-clip: content-box;
33
+ border-radius: 999px;
34
+ }
35
+ .tf-scroll::-webkit-scrollbar-thumb:hover {
36
+ background: rgba(255, 255, 255, 0.3);
37
+ background-clip: content-box;
38
+ }
39
+ .tf-scroll::-webkit-scrollbar-corner {
40
+ background: transparent;
41
+ }
42
+ [data-theme="light"] .tf-scroll::-webkit-scrollbar-thumb {
43
+ background: rgba(0, 0, 0, 0.22);
44
+ background-clip: content-box;
45
+ }
46
+ [data-theme="light"] .tf-scroll::-webkit-scrollbar-thumb:hover {
47
+ background: rgba(0, 0, 0, 0.35);
48
+ background-clip: content-box;
49
+ }
50
+ `
51
+
52
+ /**
53
+ * Renders a single <style> tag containing TreeFolder's scoped CSS.
54
+ * Mounting multiple TreeFolder instances is fine — browsers deduplicate
55
+ * identical inline stylesheets; we additionally key on a known id so React
56
+ * keeps just one DOM node when it can.
57
+ */
58
+ export function TreeFolderStyles() {
59
+ return <style id="torch-treefolder-styles" dangerouslySetInnerHTML={{ __html: CSS }} />
60
+ }
@@ -0,0 +1,63 @@
1
+ "use client"
2
+
3
+ import {
4
+ Folder,
5
+ FolderOpen,
6
+ File,
7
+ Frame,
8
+ Group,
9
+ Component,
10
+ Box,
11
+ Type,
12
+ Image as ImageIcon,
13
+ Spline,
14
+ Link as LinkIcon,
15
+ Square,
16
+ LayoutGrid,
17
+ } from "lucide-react"
18
+ import type { ReactNode } from "react"
19
+ import type { TreeFolderIconResolver, TreeFolderNode } from "./types"
20
+
21
+ export const defaultIconRegistry: Record<
22
+ string,
23
+ (state: { isOpen: boolean }) => ReactNode
24
+ > = {
25
+ folder: ({ isOpen }) =>
26
+ isOpen ? <FolderOpen className="w-3.5 h-3.5" /> : <Folder className="w-3.5 h-3.5" />,
27
+ file: () => <File className="w-3.5 h-3.5" />,
28
+ frame: () => <Frame className="w-3.5 h-3.5" />,
29
+ group: () => <Group className="w-3.5 h-3.5" />,
30
+ component: () => <Component className="w-3.5 h-3.5" />,
31
+ instance: () => <Box className="w-3.5 h-3.5" />,
32
+ text: () => <Type className="w-3.5 h-3.5" />,
33
+ image: () => <ImageIcon className="w-3.5 h-3.5" />,
34
+ vector: () => <Spline className="w-3.5 h-3.5" />,
35
+ link: () => <LinkIcon className="w-3.5 h-3.5" />,
36
+ section: () => <LayoutGrid className="w-3.5 h-3.5" />,
37
+ container: () => <Square className="w-3.5 h-3.5" />,
38
+ }
39
+
40
+ export function defaultIconFor(
41
+ node: TreeFolderNode,
42
+ state: { isOpen: boolean; isInternal: boolean; isSelected: boolean },
43
+ ): ReactNode {
44
+ if (node.icon !== undefined) return node.icon
45
+ const type = node.type ?? (state.isInternal ? "folder" : "file")
46
+ const resolver = defaultIconRegistry[type]
47
+ if (resolver) return resolver({ isOpen: state.isOpen })
48
+ return state.isInternal
49
+ ? defaultIconRegistry.folder({ isOpen: state.isOpen })
50
+ : defaultIconRegistry.file({ isOpen: state.isOpen })
51
+ }
52
+
53
+ export function resolveIcon(
54
+ iconFor: TreeFolderIconResolver | undefined,
55
+ node: TreeFolderNode,
56
+ state: { isOpen: boolean; isInternal: boolean; isSelected: boolean },
57
+ ): ReactNode {
58
+ if (iconFor) {
59
+ const custom = iconFor(node, state)
60
+ if (custom !== undefined && custom !== null) return custom
61
+ }
62
+ return defaultIconFor(node, state)
63
+ }
@@ -0,0 +1,17 @@
1
+ export { TreeFolder } from "./TreeFolder"
2
+ export type { TreeFolderHandle, TreeFolderProps } from "./TreeFolder"
3
+ export { TreeFolderRow } from "./TreeFolderRow"
4
+ export type { TreeFolderRowProps, TreeFolderRowDragHandlers } from "./TreeFolderRow"
5
+ export { TreeFolderBreadcrumb } from "./TreeFolderBreadcrumb"
6
+ export { defaultIconRegistry, defaultIconFor } from "./icons"
7
+ export { applyMove, findPath, findNode, isAncestor, descendantIds, toBreadcrumb } from "./treeFolderUtils"
8
+ export type {
9
+ TreeFolderNode,
10
+ TreeFolderNodeType,
11
+ TreeFolderMoveArgs,
12
+ TreeFolderIconResolver,
13
+ TreeFolderVisibleRow,
14
+ TreeFolderDropPosition,
15
+ TreeFolderDropTarget,
16
+ TreeFolderBreadcrumb as TreeFolderBreadcrumbItems,
17
+ } from "./types"
@@ -0,0 +1,114 @@
1
+ import type { TreeFolderBreadcrumb, TreeFolderMoveArgs, TreeFolderNode } from "./types"
2
+
3
+ export function findPath(roots: TreeFolderNode[], id: string): TreeFolderNode[] | null {
4
+ for (const root of roots) {
5
+ const trail = walkPath(root, id, [])
6
+ if (trail) return trail
7
+ }
8
+ return null
9
+ }
10
+
11
+ function walkPath(
12
+ node: TreeFolderNode,
13
+ id: string,
14
+ trail: TreeFolderNode[],
15
+ ): TreeFolderNode[] | null {
16
+ const next = [...trail, node]
17
+ if (node.id === id) return next
18
+ if (node.children) {
19
+ for (const c of node.children) {
20
+ const found = walkPath(c, id, next)
21
+ if (found) return found
22
+ }
23
+ }
24
+ return null
25
+ }
26
+
27
+ export function toBreadcrumb(path: TreeFolderNode[]): TreeFolderBreadcrumb {
28
+ return path.map((n) => ({ id: n.id, name: n.name }))
29
+ }
30
+
31
+ export function findNode(roots: TreeFolderNode[], id: string): TreeFolderNode | null {
32
+ for (const root of roots) {
33
+ if (root.id === id) return root
34
+ if (root.children) {
35
+ const inChild = findNode(root.children, id)
36
+ if (inChild) return inChild
37
+ }
38
+ }
39
+ return null
40
+ }
41
+
42
+ export function isAncestor(parent: TreeFolderNode, id: string): boolean {
43
+ if (parent.id === id) return true
44
+ if (!parent.children) return false
45
+ for (const c of parent.children) {
46
+ if (isAncestor(c, id)) return true
47
+ }
48
+ return false
49
+ }
50
+
51
+ export function descendantIds(node: TreeFolderNode, includeSelf = false): Set<string> {
52
+ const out = new Set<string>()
53
+ if (includeSelf) out.add(node.id)
54
+ const walk = (n: TreeFolderNode) => {
55
+ if (!n.children) return
56
+ for (const c of n.children) {
57
+ out.add(c.id)
58
+ walk(c)
59
+ }
60
+ }
61
+ walk(node)
62
+ return out
63
+ }
64
+
65
+ export function applyMove(
66
+ roots: TreeFolderNode[],
67
+ args: TreeFolderMoveArgs,
68
+ ): TreeFolderNode[] {
69
+ const dragSet = new Set(args.dragIds)
70
+
71
+ if (args.parentId) {
72
+ for (const id of args.dragIds) {
73
+ const node = findNode(roots, id)
74
+ if (node && isAncestor(node, args.parentId)) return roots
75
+ }
76
+ }
77
+
78
+ const extracted: TreeFolderNode[] = []
79
+
80
+ const extract = (records: TreeFolderNode[]): TreeFolderNode[] =>
81
+ records
82
+ .map((n) => {
83
+ const next: TreeFolderNode = n.children
84
+ ? { ...n, children: extract(n.children) }
85
+ : n
86
+ if (dragSet.has(n.id)) {
87
+ extracted.push(next)
88
+ return null
89
+ }
90
+ return next
91
+ })
92
+ .filter((n): n is TreeFolderNode => n !== null)
93
+
94
+ const pruned = extract(roots)
95
+
96
+ if (args.parentId == null) {
97
+ const at = Math.max(0, Math.min(args.index, pruned.length))
98
+ return [...pruned.slice(0, at), ...extracted, ...pruned.slice(at)]
99
+ }
100
+
101
+ const insert = (records: TreeFolderNode[]): TreeFolderNode[] =>
102
+ records.map((n) => {
103
+ if (n.id === args.parentId) {
104
+ const kids = n.children ? [...n.children] : []
105
+ const at = Math.max(0, Math.min(args.index, kids.length))
106
+ kids.splice(at, 0, ...extracted)
107
+ return { ...n, children: kids }
108
+ }
109
+ if (n.children) return { ...n, children: insert(n.children) }
110
+ return n
111
+ })
112
+
113
+ return insert(pruned)
114
+ }
@@ -0,0 +1,68 @@
1
+ import type { ReactNode } from "react"
2
+
3
+ export type TreeFolderNodeType =
4
+ | "folder"
5
+ | "file"
6
+ | "frame"
7
+ | "group"
8
+ | "component"
9
+ | "instance"
10
+ | "text"
11
+ | "image"
12
+ | "vector"
13
+ | "link"
14
+ | "section"
15
+ | "container"
16
+ | (string & {})
17
+
18
+ export type TreeFolderNode = {
19
+ id: string
20
+ name: string
21
+ type?: TreeFolderNodeType
22
+ icon?: ReactNode
23
+ meta?: ReactNode
24
+ disabled?: boolean
25
+ draggable?: boolean
26
+ droppable?: boolean
27
+ data?: unknown
28
+ children?: TreeFolderNode[]
29
+ }
30
+
31
+ export type TreeFolderMoveArgs = {
32
+ dragIds: string[]
33
+ parentId: string | null
34
+ index: number
35
+ }
36
+
37
+ export type TreeFolderIconResolver = (
38
+ node: TreeFolderNode,
39
+ state: { isOpen: boolean; isInternal: boolean; isSelected: boolean },
40
+ ) => ReactNode
41
+
42
+ export type TreeFolderBreadcrumb = Array<{ id: string; name: string }>
43
+
44
+ // ---------------------------------------------------------------------------
45
+ // Visible-row + DnD primitives.
46
+ // ---------------------------------------------------------------------------
47
+
48
+ export type TreeFolderVisibleRow = {
49
+ node: TreeFolderNode
50
+ level: number
51
+ /** Resolved parent id (null for roots). */
52
+ parentId: string | null
53
+ /** Position of this node among its siblings in the source tree (0-based). */
54
+ childIndex: number
55
+ /** True when the node is internal AND open. */
56
+ isOpen: boolean
57
+ /** True for internal nodes (any node with non-empty children). */
58
+ isInternal: boolean
59
+ }
60
+
61
+ /** Where the pointer is dropping relative to the hovered row. */
62
+ export type TreeFolderDropPosition = "before" | "after" | "inside"
63
+
64
+ export type TreeFolderDropTarget = {
65
+ /** The id whose `parentId` the drop will resolve to. */
66
+ rowId: string
67
+ position: TreeFolderDropPosition
68
+ }