@accelint/design-toolkit 4.0.0 → 5.0.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/components/accordion/index.d.ts +1 -1
- package/dist/components/accordion/index.js +1 -1
- package/dist/components/accordion/index.js.map +1 -1
- package/dist/components/accordion/styles.js +1 -1
- package/dist/components/accordion/styles.js.map +1 -1
- package/dist/components/accordion/types.d.ts +1 -1
- package/dist/components/action-bar/index.d.ts +10 -0
- package/dist/components/action-bar/index.js +2 -0
- package/dist/components/action-bar/index.js.map +1 -0
- package/dist/components/action-bar/styles.d.ts +5 -0
- package/dist/components/action-bar/styles.js +2 -0
- package/dist/components/action-bar/styles.js.map +1 -0
- package/dist/components/action-bar/types.d.ts +5 -0
- package/dist/components/action-bar/types.js +2 -0
- package/dist/components/action-bar/types.js.map +1 -0
- package/dist/components/avatar/index.d.ts +1 -1
- package/dist/components/avatar/index.js +1 -1
- package/dist/components/avatar/index.js.map +1 -1
- package/dist/components/avatar/styles.js +1 -1
- package/dist/components/avatar/styles.js.map +1 -1
- package/dist/components/avatar/types.d.ts +1 -1
- package/dist/components/badge/index.d.ts +1 -1
- package/dist/components/badge/index.js.map +1 -1
- package/dist/components/badge/styles.js +1 -1
- package/dist/components/badge/styles.js.map +1 -1
- package/dist/components/button/index.d.ts +1 -1
- package/dist/components/button/index.js.map +1 -1
- package/dist/components/button/styles.js +1 -1
- package/dist/components/button/styles.js.map +1 -1
- package/dist/components/button/types.d.ts +1 -1
- package/dist/components/checkbox/styles.js +1 -1
- package/dist/components/checkbox/styles.js.map +1 -1
- package/dist/components/chip/index.d.ts +1 -1
- package/dist/components/chip/index.js.map +1 -1
- package/dist/components/chip/styles.js +1 -1
- package/dist/components/chip/styles.js.map +1 -1
- package/dist/components/classification-badge/index.d.ts +1 -1
- package/dist/components/classification-badge/index.js.map +1 -1
- package/dist/components/classification-badge/styles.js +1 -1
- package/dist/components/classification-badge/styles.js.map +1 -1
- package/dist/components/classification-banner/index.d.ts +1 -1
- package/dist/components/classification-banner/index.js.map +1 -1
- package/dist/components/classification-banner/styles.js +1 -1
- package/dist/components/classification-banner/styles.js.map +1 -1
- package/dist/components/color-picker/styles.js +1 -1
- package/dist/components/color-picker/styles.js.map +1 -1
- package/dist/components/combobox-field/index.d.ts +1 -1
- package/dist/components/combobox-field/index.js.map +1 -1
- package/dist/components/combobox-field/styles.js +1 -1
- package/dist/components/combobox-field/styles.js.map +1 -1
- package/dist/components/combobox-field/types.d.ts +1 -1
- package/dist/components/date-field/index.js.map +1 -1
- package/dist/components/date-field/styles.js +1 -1
- package/dist/components/date-field/styles.js.map +1 -1
- package/dist/components/details-list/index.d.ts +1 -1
- package/dist/components/details-list/index.js +1 -1
- package/dist/components/details-list/index.js.map +1 -1
- package/dist/components/details-list/styles.js +1 -1
- package/dist/components/details-list/styles.js.map +1 -1
- package/dist/components/dialog/index.js +1 -1
- package/dist/components/dialog/index.js.map +1 -1
- package/dist/components/dialog/styles.js +1 -1
- package/dist/components/dialog/styles.js.map +1 -1
- package/dist/components/drawer/index.d.ts +1 -1
- package/dist/components/drawer/index.js +1 -1
- package/dist/components/drawer/index.js.map +1 -1
- package/dist/components/drawer/styles.d.ts +2 -2
- package/dist/components/drawer/styles.js +1 -1
- package/dist/components/drawer/styles.js.map +1 -1
- package/dist/components/drawer/types.d.ts +1 -1
- package/dist/components/hero/index.js +1 -1
- package/dist/components/hero/index.js.map +1 -1
- package/dist/components/hero/styles.js +1 -1
- package/dist/components/hero/styles.js.map +1 -1
- package/dist/components/hotkey/index.d.ts +1 -1
- package/dist/components/hotkey/index.js.map +1 -1
- package/dist/components/hotkey/styles.js +1 -1
- package/dist/components/hotkey/styles.js.map +1 -1
- package/dist/components/icon/index.d.ts +1 -1
- package/dist/components/icon/index.js.map +1 -1
- package/dist/components/input/index.d.ts +1 -1
- package/dist/components/input/index.js.map +1 -1
- package/dist/components/input/styles.js +1 -1
- package/dist/components/input/styles.js.map +1 -1
- package/dist/components/label/index.d.ts +1 -1
- package/dist/components/label/index.js.map +1 -1
- package/dist/components/label/styles.js +1 -1
- package/dist/components/label/styles.js.map +1 -1
- package/dist/components/lines/index.d.ts +9 -0
- package/dist/components/lines/index.js +2 -0
- package/dist/components/lines/index.js.map +1 -0
- package/dist/components/lines/styles.d.ts +32 -0
- package/dist/components/lines/styles.js +2 -0
- package/dist/components/lines/styles.js.map +1 -0
- package/dist/components/lines/types.d.ts +10 -0
- package/dist/components/lines/types.js +2 -0
- package/dist/components/lines/types.js.map +1 -0
- package/dist/components/link/index.d.ts +17 -0
- package/dist/components/link/index.js +2 -0
- package/dist/components/link/index.js.map +1 -0
- package/dist/components/link/styles.d.ts +5 -0
- package/dist/components/link/styles.js +2 -0
- package/dist/components/link/styles.js.map +1 -0
- package/dist/components/link/types.d.ts +9 -0
- package/dist/components/link/types.js +2 -0
- package/dist/components/link/types.js.map +1 -0
- package/dist/components/menu/index.js +1 -1
- package/dist/components/menu/index.js.map +1 -1
- package/dist/components/menu/styles.js +1 -1
- package/dist/components/menu/styles.js.map +1 -1
- package/dist/components/options/index.js.map +1 -1
- package/dist/components/options/styles.js +1 -1
- package/dist/components/options/styles.js.map +1 -1
- package/dist/components/popover/index.js.map +1 -1
- package/dist/components/popover/styles.js +1 -1
- package/dist/components/popover/styles.js.map +1 -1
- package/dist/components/query-builder/action-element.js.map +1 -1
- package/dist/components/query-builder/group.js +1 -1
- package/dist/components/query-builder/group.js.map +1 -1
- package/dist/components/query-builder/index.js +1 -1
- package/dist/components/query-builder/index.js.map +1 -1
- package/dist/components/query-builder/value-editor.js.map +1 -1
- package/dist/components/query-builder/value-selector.js.map +1 -1
- package/dist/components/radio/styles.js +1 -1
- package/dist/components/radio/styles.js.map +1 -1
- package/dist/components/search-field/index.d.ts +3 -3
- package/dist/components/search-field/index.js.map +1 -1
- package/dist/components/search-field/styles.js +1 -1
- package/dist/components/search-field/styles.js.map +1 -1
- package/dist/components/select-field/index.d.ts +1 -1
- package/dist/components/select-field/index.js +1 -1
- package/dist/components/select-field/index.js.map +1 -1
- package/dist/components/select-field/styles.js +1 -1
- package/dist/components/select-field/styles.js.map +1 -1
- package/dist/components/select-field/types.d.ts +1 -1
- package/dist/components/sidenav/events.d.ts +8 -0
- package/dist/components/sidenav/events.js +2 -0
- package/dist/components/sidenav/events.js.map +1 -0
- package/dist/components/sidenav/index.d.ts +51 -0
- package/dist/components/sidenav/index.js +2 -0
- package/dist/components/sidenav/index.js.map +1 -0
- package/dist/components/sidenav/styles.d.ts +114 -0
- package/dist/components/sidenav/styles.js +2 -0
- package/dist/components/sidenav/styles.js.map +1 -0
- package/dist/components/sidenav/types.d.ts +38 -0
- package/dist/components/sidenav/types.js +2 -0
- package/dist/components/sidenav/types.js.map +1 -0
- package/dist/components/skeleton/styles.d.ts +2 -2
- package/dist/components/skeleton/styles.js +1 -1
- package/dist/components/skeleton/styles.js.map +1 -1
- package/dist/components/slider/index.js.map +1 -1
- package/dist/components/slider/styles.js +1 -1
- package/dist/components/slider/styles.js.map +1 -1
- package/dist/components/switch/index.d.ts +1 -1
- package/dist/components/switch/index.js.map +1 -1
- package/dist/components/switch/styles.js +1 -1
- package/dist/components/switch/styles.js.map +1 -1
- package/dist/components/tabs/index.d.ts +37 -36
- package/dist/components/tabs/index.js +1 -1
- package/dist/components/tabs/index.js.map +1 -1
- package/dist/components/tabs/styles.d.ts +48 -0
- package/dist/components/tabs/styles.js +2 -0
- package/dist/components/tabs/styles.js.map +1 -0
- package/dist/components/tabs/types.d.ts +6 -0
- package/dist/components/tabs/types.js +2 -0
- package/dist/components/tabs/types.js.map +1 -0
- package/dist/components/text-area-field/index.d.ts +1 -1
- package/dist/components/text-area-field/index.js.map +1 -1
- package/dist/components/text-area-field/styles.js +1 -1
- package/dist/components/text-area-field/styles.js.map +1 -1
- package/dist/components/text-field/index.js.map +1 -1
- package/dist/components/text-field/styles.js +1 -1
- package/dist/components/text-field/styles.js.map +1 -1
- package/dist/components/tooltip/index.d.ts +1 -1
- package/dist/components/tooltip/index.js +1 -1
- package/dist/components/tooltip/index.js.map +1 -1
- package/dist/components/tooltip/styles.d.ts +1 -1
- package/dist/components/tooltip/styles.js +1 -1
- package/dist/components/tooltip/styles.js.map +1 -1
- package/dist/components/tooltip/types.d.ts +3 -1
- package/dist/components/tree/index.d.ts +51 -0
- package/dist/components/tree/index.js +2 -0
- package/dist/components/tree/index.js.map +1 -0
- package/dist/components/tree/styles.d.ts +128 -0
- package/dist/components/tree/styles.js +2 -0
- package/dist/components/tree/styles.js.map +1 -0
- package/dist/components/tree/types.d.ts +41 -0
- package/dist/components/tree/types.js +2 -0
- package/dist/components/tree/types.js.map +1 -0
- package/dist/components/view-stack/index.js.map +1 -1
- package/dist/foundation/token-data.d.ts +17 -0
- package/dist/foundation/token-data.js +2 -0
- package/dist/foundation/token-data.js.map +1 -0
- package/dist/hooks/use-tree/actions/cache.d.ts +78 -0
- package/dist/hooks/use-tree/actions/cache.js +2 -0
- package/dist/hooks/use-tree/actions/cache.js.map +1 -0
- package/dist/hooks/use-tree/actions/index.d.ts +38 -0
- package/dist/hooks/use-tree/actions/index.js +2 -0
- package/dist/hooks/use-tree/actions/index.js.map +1 -0
- package/dist/hooks/use-tree/state/index.d.ts +8 -0
- package/dist/hooks/use-tree/state/index.js +2 -0
- package/dist/hooks/use-tree/state/index.js.map +1 -0
- package/dist/hooks/use-tree/state/utils.d.ts +7 -0
- package/dist/hooks/use-tree/state/utils.js +2 -0
- package/dist/hooks/use-tree/state/utils.js.map +1 -0
- package/dist/hooks/use-tree/types.d.ts +171 -0
- package/dist/hooks/use-tree/types.js +2 -0
- package/dist/hooks/use-tree/types.js.map +1 -0
- package/dist/icons/catalog.js +1 -1
- package/dist/icons/catalog.js.map +1 -1
- package/dist/index.css +9 -15
- package/dist/index.d.ts +26 -3
- package/dist/index.js +1 -1
- package/dist/lib/react.d.ts +22 -8
- package/dist/lib/react.js +8 -4
- package/dist/lib/react.js.map +1 -1
- package/dist/lib/utils.d.ts +2 -2
- package/dist/lib/utils.js +1 -1
- package/dist/lib/utils.js.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/providers/theme-provider.d.ts +22 -0
- package/dist/providers/theme-provider.js +2 -0
- package/dist/providers/theme-provider.js.map +1 -0
- package/dist/styles.css +1606 -904
- package/dist/tokens/themes.css +729 -53
- package/dist/tokens/tokens.css +121 -65
- package/dist/tokens/tokens.d.ts +449 -1
- package/dist/tokens/tokens.js +2 -0
- package/dist/tokens/tokens.js.map +1 -0
- package/dist/tokens/types.d.ts +299 -0
- package/dist/tokens/types.js +2 -0
- package/dist/tokens/types.js.map +1 -0
- package/dist/variants/variants.css +6 -1
- package/package.json +10 -6
- package/dist/tokens/index.d.ts +0 -123
- package/dist/tokens/index.js +0 -2
- package/dist/tokens/index.js.map +0 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Key } from '@react-types/shared';
|
|
2
|
+
import { TreeProps as TreeProps$1, TreeItemProps as TreeItemProps$1, RenderProps, TreeItemContentRenderProps as TreeItemContentRenderProps$1 } from 'react-aria-components';
|
|
3
|
+
import { VariantProps } from 'tailwind-variants';
|
|
4
|
+
import { TreeNode, DragAndDropConfig } from '../../hooks/use-tree/types.js';
|
|
5
|
+
import { TreeStyles } from './styles.js';
|
|
6
|
+
import 'react';
|
|
7
|
+
|
|
8
|
+
type TreeProps<T> = Omit<TreeProps$1<TreeNode<T>>, 'defaultExpandedKeys' | 'defaultSelectedKeys' | 'disabledKeys' | 'expandedKeys' | 'selectedKeys' | 'onSelectionChange'> & VariantProps<typeof TreeStyles> & {
|
|
9
|
+
disabledKeys?: Set<Key>;
|
|
10
|
+
dragAndDropConfig?: DragAndDropConfig;
|
|
11
|
+
expandedKeys?: Set<Key>;
|
|
12
|
+
selectedKeys?: Set<Key>;
|
|
13
|
+
visibleKeys?: Set<Key>;
|
|
14
|
+
showRuleLines?: boolean;
|
|
15
|
+
showVisibility?: boolean;
|
|
16
|
+
onVisibilityChange?: (keys: Set<Key>) => void;
|
|
17
|
+
onSelectionChange?: (keys: Set<Key>) => void;
|
|
18
|
+
};
|
|
19
|
+
type TreeItemProps = Omit<TreeItemProps$1, 'id'> & {
|
|
20
|
+
id: Key;
|
|
21
|
+
};
|
|
22
|
+
type TreeItemContentProps = Pick<RenderProps<TreeItemContentRenderProps>, 'children'>;
|
|
23
|
+
type TreeItemContentRenderProps = TreeItemContentRenderProps$1 & VariantProps<typeof TreeStyles> & {
|
|
24
|
+
isViewable?: boolean;
|
|
25
|
+
isVisible?: boolean;
|
|
26
|
+
};
|
|
27
|
+
type TreeContextValue = Required<Pick<TreeProps<unknown>, 'showRuleLines' | 'showVisibility' | 'variant' | 'onVisibilityChange'>> & {
|
|
28
|
+
disabledKeys?: Set<Key>;
|
|
29
|
+
expandedKeys?: Set<Key>;
|
|
30
|
+
selectedKeys?: Set<Key>;
|
|
31
|
+
visibleKeys?: Set<Key>;
|
|
32
|
+
visibilityComputedKeys?: Set<Key>;
|
|
33
|
+
isStatic: boolean;
|
|
34
|
+
};
|
|
35
|
+
type TreeItemContextValue = {
|
|
36
|
+
isVisible?: boolean;
|
|
37
|
+
isViewable?: boolean;
|
|
38
|
+
ancestors: Key[];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type { TreeContextValue, TreeItemContentProps, TreeItemContentRenderProps, TreeItemContextValue, TreeItemProps, TreeProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"types.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/view-stack/index.tsx"],"names":["Broadcast","h","ViewStackContext","createContext","q","ViewStackEventHandlers","bus","o","types","useContext","d","type","event","isUUID","l","id","parent","I","x","ViewStackTrigger","E","register","unregister","view","b","stack","setStack","useState","defaultView","g","useCallback","data","next","onChange","handleClear","handlePush","views","prev","handleReset","ViewStackEventTypes","off","listeners","handleBack","jsx","ViewStack"],"mappings":"iTAsCYA,MAAU,CAA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AAA,CAAAA,CAAWL,CAAAA,GAAe,CAAA,EAAI,IAGlC,CAACb,GAAIa,CAAAA,CAAaK,CAAQ,CAC5B,CAAA,CAEA,CAAA,CAAA,CAAA,CAAA,OAAUb,SAAA,CAAM,IACd,CAAA,MACEd,CAAI,CAAA,CAAA,CAAGiC,CAAAA,EAAoB,CAAAhC,mBAAA,CAAA,IAC3BD,CAAAA,CAAI,CAAA,CAAA,CAAGiC,CAAAA,EAAoB,CAAAhC,mBAAA,CAAA,KAC3BD,CAAAA,CAAI,CAAA,CAAA,CAAGiC,CAAAA,EAAoB,CAAAhC,mBAAA,CAAA,IAC3BD,CAAAA,CAAI,GAAGiC,CAAAA,EAAoB,CAAAhC,mBAAA,CAAA,KAC7B,CAEA,CAAA,CAAA,CAAA,CAAA,OAAa,IACX,CAAA,IAAA,MAAWiC,CAAOC,IACZ,CAER,CACF,CAAA,GAAIC,CAAAA,CAAYR,CAAAA,CAAaC,CAAAA,CAAYG,CAAW,CAAC,CAAA,CAGnDK,CAAAA,CAACzC,CAAAA,CAAiBe,GAAA,CAAA,CAAA,CAAA,QAChB,CAAA,CAAA,KACE,CAAA,CAAA,MACA,CAAA,CAAA,CAAA,KACA,CAAA,CAAA,CAAA,IACA,CAAA,CAAA,CAAA,QAA8BmB,CAAAA,CAAM,EAAA,CAAA,CAAA,OAAQ,CAAIb,GAChD,CAAA,CAAA,CAAA,CAAA,UAAgCa,CAAAA,CAAM,EAAA,CAAA,CAAA,OAAQ,CAAA,MAChD,CAEC,CAAA,CAAA,CAAA,CAAA,QAGP,CACAQ,CAAAA,CAAU,CAAA,CAAA,CAAA,CAAA,WAAc,CAAA,WACd,CAAA,CAAA,CAAA,IACVA,CAAU,CAAA,CAAA,CAAA,CAAA,OAAUzB,CAAAA,CAAAA","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n'use client';\n\nimport 'client-only';\nimport { Broadcast } from '@accelint/bus';\nimport { type UniqueId, isUUID } from '@accelint/core';\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\nimport { Pressable } from 'react-aria-components';\nimport { ViewStackEventTypes } from './events';\nimport type {\n ViewStackBackEvent,\n ViewStackClearEvent,\n ViewStackContextValue,\n ViewStackEvent,\n ViewStackProps,\n ViewStackPushEvent,\n ViewStackResetEvent,\n ViewStackTriggerProps,\n ViewStackViewProps,\n} from './types';\n\nconst bus = Broadcast.getInstance<ViewStackEvent>();\n\nexport const ViewStackContext = createContext<ViewStackContextValue>({\n parent: null,\n stack: [],\n view: null,\n register: () => undefined,\n unregister: () => undefined,\n});\n\nexport const ViewStackEventHandlers = {\n back: (stack: UniqueId) => bus.emit(ViewStackEventTypes.back, { stack }),\n clear: (stack: UniqueId) => bus.emit(ViewStackEventTypes.clear, { stack }),\n push: (view: UniqueId) => bus.emit(ViewStackEventTypes.push, { view }),\n reset: (stack: UniqueId) => bus.emit(ViewStackEventTypes.reset, { stack }),\n} as const;\n\nfunction ViewStackTrigger({ children, for: types }: ViewStackTriggerProps) {\n const { parent } = useContext(ViewStackContext);\n\n function handlePress() {\n for (const type of Array.isArray(types) ? types : [types]) {\n let [event, id] = (isUUID(type) ? ['push', type] : type.split(':')) as [\n 'back' | 'clear' | 'reset' | 'push',\n UniqueId | undefined | null,\n ];\n\n id ??= parent;\n\n if (!id) {\n continue;\n }\n\n ViewStackEventHandlers[event](id);\n }\n }\n\n return <Pressable onPress={handlePress}>{children}</Pressable>;\n}\nViewStackTrigger.displayName = 'ViewStack.Trigger';\n\nfunction ViewStackView({ id, children }: ViewStackViewProps) {\n const { parent, view, register, unregister } = useContext(ViewStackContext);\n\n if (!parent) {\n throw new Error('ViewStack.View must be implemented within a ViewStack');\n }\n\n if (!isUUID(id)) {\n throw new Error(`ViewStack.View's id must be a UniqueId`);\n }\n\n useEffect(() => {\n register(id);\n\n () => unregister(id);\n }, [register, unregister, id]);\n\n return view === id ? children : null;\n}\nViewStackView.displayName = 'ViewStack.View';\n\nexport function ViewStack({\n id,\n children,\n defaultView,\n onChange,\n}: ViewStackProps) {\n if (!isUUID(id)) {\n throw new Error(`ViewStack's id must be a UniqueId`);\n }\n\n const views = useRef(new Set<UniqueId>());\n const [stack, setStack] = useState<UniqueId[]>(\n defaultView ? [defaultView] : [],\n );\n const view = stack.at(-1) ?? null;\n\n const handleBack = useCallback(\n (data: ViewStackBackEvent) => {\n if (id === data?.payload?.stack) {\n const next = stack.slice(0, -1);\n\n if (!next.length && defaultView) {\n next.push(defaultView);\n }\n\n setStack(next);\n onChange?.(next.at(-1) ?? null);\n }\n },\n [id, defaultView, onChange, stack],\n );\n\n const handleClear = useCallback(\n (data: ViewStackClearEvent) => {\n if (id === data?.payload?.stack) {\n setStack([]);\n onChange?.(null);\n }\n },\n [id, onChange],\n );\n\n const handlePush = useCallback(\n (data: ViewStackPushEvent) => {\n if (views.current.has(data?.payload?.view)) {\n setStack((prev) => [...prev, data?.payload?.view]);\n onChange?.(data?.payload?.view);\n }\n },\n [onChange],\n );\n\n const handleReset = useCallback(\n (data: ViewStackResetEvent) => {\n if (id === data?.payload?.stack) {\n setStack(defaultView ? [defaultView] : []);\n onChange?.(defaultView ?? null);\n }\n },\n [id, defaultView, onChange],\n );\n\n useEffect(() => {\n const listeners = [\n bus.on(ViewStackEventTypes.back, handleBack),\n bus.on(ViewStackEventTypes.clear, handleClear),\n bus.on(ViewStackEventTypes.push, handlePush),\n bus.on(ViewStackEventTypes.reset, handleReset),\n ];\n\n return () => {\n for (const off of listeners) {\n off();\n }\n };\n }, [handleBack, handleClear, handlePush, handleReset]);\n\n return (\n <ViewStackContext.Provider\n value={{\n parent: id,\n stack,\n view,\n register: (view: UniqueId) => views.current.add(view),\n unregister: (view: UniqueId) => views.current.delete(view),\n }}\n >\n {children}\n </ViewStackContext.Provider>\n );\n}\nViewStack.displayName = 'ViewStack';\nViewStack.View = ViewStackView;\nViewStack.Trigger = ViewStackTrigger;\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/view-stack/index.tsx"],"names":["Broadcast","h","ViewStackContext","createContext","q","ViewStackEventHandlers","bus","o","types","useContext","d","type","event","isUUID","l","id","parent","I","x","ViewStackTrigger","E","register","unregister","view","b","stack","setStack","useState","defaultView","g","useCallback","data","next","onChange","handleClear","handlePush","views","prev","handleReset","ViewStackEventTypes","off","listeners","handleBack","jsx","ViewStack"],"mappings":"iTAsCYA,MAAU,CAAA,CAAAC,SAAA,CAAA,WAETC,EAAmBC,CAAqC,CACnE,CAAAC,aAAA,CAAA,CAAA,MAAQ,CAAA,IACR,CAAA,KACA,CAAA,EAAA,CAAA,IAAM,CAAA,IACN,CAAA,QAAU,CAAG,IACb,CAAA,CAAA,CAAA,UAAY,CAAG,IAChB,CAEYC,CAAAA,CAAyB,CACpC,CAAA,CAAA,CAAA,CAAA,IAA2BC,CAAAA,CAAI,EAAA,CAAA,CAAA,IAAyB,CAAAC,mBAAA,CAAA,IAAQ,CAAA,CAAA,KAAO,CACvE,CAAA,CAAA,CAAA,CAAA,KAA4BD,CAAAA,CAAI,EAAA,CAAA,CAAA,IAAyB,CAAAC,mBAAA,CAAA,KAAS,CAAA,CAAA,KAAO,CACzE,CAAA,CAAA,CAAA,CAAA,IAA0BD,CAAAA,CAAI,EAAA,CAAA,CAAA,IAAyB,CAAAC,mBAAA,CAAA,IAAQ,CAAA,CAAA,KAC/D,CAAA,CAAA,CAAA,CAAA,KAA4BD,CAAAA,CAAI,EAAA,CAAA,CAAA,IAAyB,CAAAC,mBAAA,CAAA,KAAS,CAAA,CAAA,KACpE,CAAA,CAEA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,MACA,CAAA,CAAA,CAAA,KACA,CAAA,CAAA,CAAA,IACA,CAAA,CAAA,CAAA,QAA8BmB,CAAAA,CAAM,EAAA,CAAA,CAAA,OAAQ,CAAIb,GAChD,CAAA,CAAA,CAAA,CAAA,UAAgCa,CAAAA,CAAM,EAAA,CAAA,CAAA,OAAQ,CAAA,MAChD,CAEC,CAAA,CAAA,CAAA,CAAA,QAGP,CACAQ,CAAAA,CAAU,CAAA,CAAA,CAAA,CAAA,WAAc,CAAA,WACd,CAAA,CAAA,CAAA,IACVA,CAAU,CAAA,CAAA,CAAA,CAAA,OAAUzB,CAAAA,CAAAA","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n'use client';\n\nimport 'client-only';\nimport { Broadcast } from '@accelint/bus';\nimport { isUUID, type UniqueId } from '@accelint/core';\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\nimport { Pressable } from 'react-aria-components';\nimport { ViewStackEventTypes } from './events';\nimport type {\n ViewStackBackEvent,\n ViewStackClearEvent,\n ViewStackContextValue,\n ViewStackEvent,\n ViewStackProps,\n ViewStackPushEvent,\n ViewStackResetEvent,\n ViewStackTriggerProps,\n ViewStackViewProps,\n} from './types';\n\nconst bus = Broadcast.getInstance<ViewStackEvent>();\n\nexport const ViewStackContext = createContext<ViewStackContextValue>({\n parent: null,\n stack: [],\n view: null,\n register: () => undefined,\n unregister: () => undefined,\n});\n\nexport const ViewStackEventHandlers = {\n back: (stack: UniqueId) => bus.emit(ViewStackEventTypes.back, { stack }),\n clear: (stack: UniqueId) => bus.emit(ViewStackEventTypes.clear, { stack }),\n push: (view: UniqueId) => bus.emit(ViewStackEventTypes.push, { view }),\n reset: (stack: UniqueId) => bus.emit(ViewStackEventTypes.reset, { stack }),\n} as const;\n\nfunction ViewStackTrigger({ children, for: types }: ViewStackTriggerProps) {\n const { parent } = useContext(ViewStackContext);\n\n function handlePress() {\n for (const type of Array.isArray(types) ? types : [types]) {\n let [event, id] = (isUUID(type) ? ['push', type] : type.split(':')) as [\n 'back' | 'clear' | 'reset' | 'push',\n UniqueId | undefined | null,\n ];\n\n id ??= parent;\n\n if (!id) {\n continue;\n }\n\n ViewStackEventHandlers[event](id);\n }\n }\n\n return <Pressable onPress={handlePress}>{children}</Pressable>;\n}\nViewStackTrigger.displayName = 'ViewStack.Trigger';\n\nfunction ViewStackView({ id, children }: ViewStackViewProps) {\n const { parent, view, register, unregister } = useContext(ViewStackContext);\n\n if (!parent) {\n throw new Error('ViewStack.View must be implemented within a ViewStack');\n }\n\n if (!isUUID(id)) {\n throw new Error(`ViewStack.View's id must be a UniqueId`);\n }\n\n useEffect(() => {\n register(id);\n\n () => unregister(id);\n }, [register, unregister, id]);\n\n return view === id ? children : null;\n}\nViewStackView.displayName = 'ViewStack.View';\n\nexport function ViewStack({\n id,\n children,\n defaultView,\n onChange,\n}: ViewStackProps) {\n if (!isUUID(id)) {\n throw new Error(`ViewStack's id must be a UniqueId`);\n }\n\n const views = useRef(new Set<UniqueId>());\n const [stack, setStack] = useState<UniqueId[]>(\n defaultView ? [defaultView] : [],\n );\n const view = stack.at(-1) ?? null;\n\n const handleBack = useCallback(\n (data: ViewStackBackEvent) => {\n if (id === data?.payload?.stack) {\n const next = stack.slice(0, -1);\n\n if (!next.length && defaultView) {\n next.push(defaultView);\n }\n\n setStack(next);\n onChange?.(next.at(-1) ?? null);\n }\n },\n [id, defaultView, onChange, stack],\n );\n\n const handleClear = useCallback(\n (data: ViewStackClearEvent) => {\n if (id === data?.payload?.stack) {\n setStack([]);\n onChange?.(null);\n }\n },\n [id, onChange],\n );\n\n const handlePush = useCallback(\n (data: ViewStackPushEvent) => {\n if (views.current.has(data?.payload?.view)) {\n setStack((prev) => [...prev, data?.payload?.view]);\n onChange?.(data?.payload?.view);\n }\n },\n [onChange],\n );\n\n const handleReset = useCallback(\n (data: ViewStackResetEvent) => {\n if (id === data?.payload?.stack) {\n setStack(defaultView ? [defaultView] : []);\n onChange?.(defaultView ?? null);\n }\n },\n [id, defaultView, onChange],\n );\n\n useEffect(() => {\n const listeners = [\n bus.on(ViewStackEventTypes.back, handleBack),\n bus.on(ViewStackEventTypes.clear, handleClear),\n bus.on(ViewStackEventTypes.push, handlePush),\n bus.on(ViewStackEventTypes.reset, handleReset),\n ];\n\n return () => {\n for (const off of listeners) {\n off();\n }\n };\n }, [handleBack, handleClear, handlePush, handleReset]);\n\n return (\n <ViewStackContext.Provider\n value={{\n parent: id,\n stack,\n view,\n register: (view: UniqueId) => views.current.add(view),\n unregister: (view: UniqueId) => views.current.delete(view),\n }}\n >\n {children}\n </ViewStackContext.Provider>\n );\n}\nViewStack.displayName = 'ViewStack';\nViewStack.View = ViewStackView;\nViewStack.Trigger = ViewStackTrigger;\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e={bg:{base:["bg-surface-default","bg-surface-raised","bg-surface-overlay","bg-surface-muted","bg-interactive-bold","bg-interactive-bold-hover","bg-interactive-bold-pressed","bg-interactive-muted","bg-interactive-muted-hover","bg-interactive-muted-pressed","bg-interactive-disabled","bg-accent-primary-bold","bg-accent-primary-hover","bg-accent-primary-pressed","bg-accent-primary-muted"],utility:["bg-info-bold","bg-info-hover","bg-info-pressed","bg-info-muted","bg-advisory-bold","bg-advisory-hover","bg-advisory-pressed","bg-advisory-muted","bg-normal-bold","bg-normal-hover","bg-normal-pressed","bg-normal-muted","bg-serious-bold","bg-serious-hover","bg-serious-pressed","bg-serious-muted","bg-critical-bold","bg-critical-hover","bg-critical-pressed","bg-critical-muted"]},fg:{base:["fg-primary-bold","fg-primary-muted","fg-inverse-bold","fg-inverse-muted","fg-disabled"],utility:["fg-accent-primary-bold","fg-accent-primary-hover","fg-accent-primary-pressed","fg-info-bold","fg-info-hover","fg-info-pressed","fg-advisory-bold","fg-advisory-hover","fg-advisory-pressed","fg-normal-bold","fg-normal-hover","fg-normal-pressed","fg-serious-bold","fg-serious-hover","fg-serious-pressed","fg-critical-bold","fg-critical-hover","fg-critical-pressed"],a11y:["fg-a11y-on-accent","fg-a11y-on-utility"]},outline:{base:["outline-static","outline-interactive","outline-interactive-hover","outline-interactive-pressed","outline-interactive-disabled","outline-accent-primary-bold","outline-accent-primary-hover","outline-accent-primary-pressed"],utility:["outline-info-bold","outline-info-hover","outline-info-pressed","outline-advisory-bold","outline-advisory-hover","outline-advisory-pressed","outline-normal-bold","outline-normal-hover","outline-normal-pressed","outline-serious-bold","outline-serious-hover","outline-serious-pressed","outline-critical-bold","outline-critical-hover","outline-critical-pressed"]}};export{e as tokens};//# sourceMappingURL=token-data.js.map
|
|
2
|
+
//# sourceMappingURL=token-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/foundation/token-data.ts"],"names":["tokens"],"mappings":"AAgBO,MAAMA,CAAAA,CAAS,CACpB,EAAA,CAAI,CACF,IAAA,CAAM,CACJ,oBAAA,CACA,mBAAA,CACA,oBAAA,CACA,kBAAA,CACA,qBAAA,CACA,2BAAA,CACA,8BACA,sBAAA,CACA,4BAAA,CACA,8BAAA,CACA,yBAAA,CACA,wBAAA,CACA,yBAAA,CACA,2BAAA,CACA,yBACF,CAAA,CACA,OAAA,CAAS,CACP,cAAA,CACA,eAAA,CACA,iBAAA,CACA,gBACA,kBAAA,CACA,mBAAA,CACA,qBAAA,CACA,mBAAA,CACA,gBAAA,CACA,iBAAA,CACA,mBAAA,CACA,iBAAA,CACA,iBAAA,CACA,kBAAA,CACA,oBAAA,CACA,kBAAA,CACA,kBAAA,CACA,mBAAA,CACA,sBACA,mBACF,CACF,CAAA,CACA,EAAA,CAAI,CACF,IAAA,CAAM,CACJ,iBAAA,CACA,kBAAA,CACA,iBAAA,CACA,kBAAA,CACA,aACF,CAAA,CACA,OAAA,CAAS,CACP,wBAAA,CACA,yBAAA,CACA,2BAAA,CACA,cAAA,CACA,eAAA,CACA,iBAAA,CACA,mBACA,mBAAA,CACA,qBAAA,CACA,gBAAA,CACA,iBAAA,CACA,mBAAA,CACA,iBAAA,CACA,mBACA,oBAAA,CACA,kBAAA,CACA,mBAAA,CACA,qBACF,CAAA,CACA,IAAA,CAAM,CAAC,mBAAA,CAAqB,oBAAoB,CAClD,CAAA,CACA,OAAA,CAAS,CACP,IAAA,CAAM,CACJ,gBAAA,CACA,qBAAA,CACA,2BAAA,CACA,6BAAA,CACA,8BAAA,CACA,6BAAA,CACA,8BAAA,CACA,gCACF,CAAA,CACA,OAAA,CAAS,CACP,mBAAA,CACA,oBAAA,CACA,sBAAA,CACA,wBACA,wBAAA,CACA,0BAAA,CACA,qBAAA,CACA,sBAAA,CACA,wBAAA,CACA,sBAAA,CACA,uBAAA,CACA,yBAAA,CACA,uBAAA,CACA,wBAAA,CACA,0BACF,CACF,CACF","file":"token-data.js","sourcesContent":["// __private-exports\n/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// These tokens drive the storybook stories.\n// future: generate these\n\nexport const tokens = {\n bg: {\n base: [\n 'bg-surface-default',\n 'bg-surface-raised',\n 'bg-surface-overlay',\n 'bg-surface-muted',\n 'bg-interactive-bold',\n 'bg-interactive-bold-hover',\n 'bg-interactive-bold-pressed',\n 'bg-interactive-muted',\n 'bg-interactive-muted-hover',\n 'bg-interactive-muted-pressed',\n 'bg-interactive-disabled',\n 'bg-accent-primary-bold',\n 'bg-accent-primary-hover',\n 'bg-accent-primary-pressed',\n 'bg-accent-primary-muted',\n ],\n utility: [\n 'bg-info-bold',\n 'bg-info-hover',\n 'bg-info-pressed',\n 'bg-info-muted',\n 'bg-advisory-bold',\n 'bg-advisory-hover',\n 'bg-advisory-pressed',\n 'bg-advisory-muted',\n 'bg-normal-bold',\n 'bg-normal-hover',\n 'bg-normal-pressed',\n 'bg-normal-muted',\n 'bg-serious-bold',\n 'bg-serious-hover',\n 'bg-serious-pressed',\n 'bg-serious-muted',\n 'bg-critical-bold',\n 'bg-critical-hover',\n 'bg-critical-pressed',\n 'bg-critical-muted',\n ],\n },\n fg: {\n base: [\n 'fg-primary-bold',\n 'fg-primary-muted',\n 'fg-inverse-bold',\n 'fg-inverse-muted',\n 'fg-disabled',\n ],\n utility: [\n 'fg-accent-primary-bold',\n 'fg-accent-primary-hover',\n 'fg-accent-primary-pressed',\n 'fg-info-bold',\n 'fg-info-hover',\n 'fg-info-pressed',\n 'fg-advisory-bold',\n 'fg-advisory-hover',\n 'fg-advisory-pressed',\n 'fg-normal-bold',\n 'fg-normal-hover',\n 'fg-normal-pressed',\n 'fg-serious-bold',\n 'fg-serious-hover',\n 'fg-serious-pressed',\n 'fg-critical-bold',\n 'fg-critical-hover',\n 'fg-critical-pressed',\n ],\n a11y: ['fg-a11y-on-accent', 'fg-a11y-on-utility'],\n },\n outline: {\n base: [\n 'outline-static',\n 'outline-interactive',\n 'outline-interactive-hover',\n 'outline-interactive-pressed',\n 'outline-interactive-disabled',\n 'outline-accent-primary-bold',\n 'outline-accent-primary-hover',\n 'outline-accent-primary-pressed',\n ],\n utility: [\n 'outline-info-bold',\n 'outline-info-hover',\n 'outline-info-pressed',\n 'outline-advisory-bold',\n 'outline-advisory-hover',\n 'outline-advisory-pressed',\n 'outline-normal-bold',\n 'outline-normal-hover',\n 'outline-normal-pressed',\n 'outline-serious-bold',\n 'outline-serious-hover',\n 'outline-serious-pressed',\n 'outline-critical-bold',\n 'outline-critical-hover',\n 'outline-critical-pressed',\n ],\n },\n};\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Key } from '@react-types/shared';
|
|
2
|
+
import { TreeNode } from '../types.js';
|
|
3
|
+
import 'react';
|
|
4
|
+
import 'react-aria-components';
|
|
5
|
+
|
|
6
|
+
type CacheTreeNode<T> = Omit<TreeNode<T>, 'children'> & {
|
|
7
|
+
children?: Key[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* This is a cache created only for performance reasons and is considered
|
|
11
|
+
* to be only a temporary mirror of the data. The data is *always* correct
|
|
12
|
+
* cache should be updated according to the data, only. If the data and
|
|
13
|
+
* the cache do not match, the cache is invalidated and rebuilt.
|
|
14
|
+
*
|
|
15
|
+
* This will initialize once on load with data, then
|
|
16
|
+
* updated with each tree operation.
|
|
17
|
+
*/
|
|
18
|
+
declare class Cache<T> {
|
|
19
|
+
protected cache: {
|
|
20
|
+
lookup: Map<Key, CacheTreeNode<T>>;
|
|
21
|
+
roots: Key[];
|
|
22
|
+
};
|
|
23
|
+
constructor(nodes?: TreeNode<T>[]);
|
|
24
|
+
/**
|
|
25
|
+
* Recursively creates the cache object from tree data
|
|
26
|
+
*/
|
|
27
|
+
rebuild(nodes: TreeNode<T>[], lookup?: Map<Key, CacheTreeNode<T>>, parentKey?: Key | null): {
|
|
28
|
+
lookup: Map<Key, CacheTreeNode<T>>;
|
|
29
|
+
roots: Key[];
|
|
30
|
+
};
|
|
31
|
+
protected get(key: Key): CacheTreeNode<T>;
|
|
32
|
+
protected set(key: Key, node: CacheTreeNode<T>): void;
|
|
33
|
+
protected delete(key: Key): void;
|
|
34
|
+
protected addToParent(parentKey: Key, childKey: Key, idx: number): void;
|
|
35
|
+
protected addToRoot(key: Key, idx: number): void;
|
|
36
|
+
protected removeFromParent(parentKey: Key, childKey: Key): void;
|
|
37
|
+
protected removeFromRoot(key: Key): void;
|
|
38
|
+
protected parentOrSibling(target: Key | null, position: 'before' | 'after'): {
|
|
39
|
+
parentKey: Key | null;
|
|
40
|
+
index: number;
|
|
41
|
+
};
|
|
42
|
+
protected traverse(key: Key): void;
|
|
43
|
+
protected calculateVisibility(key: Key): boolean;
|
|
44
|
+
protected deriveVisibility(): void[];
|
|
45
|
+
/**
|
|
46
|
+
* Recursively builds a TreeNode from a key
|
|
47
|
+
*
|
|
48
|
+
* @param key
|
|
49
|
+
*/
|
|
50
|
+
protected buildNode(key: Key): TreeNode<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Builds a tree structure from cache
|
|
53
|
+
*
|
|
54
|
+
* TODO: optimization - rebuild only from change to root
|
|
55
|
+
* Rebuild only from the changed node up the tree to avoid
|
|
56
|
+
* rebuilding the entire tree
|
|
57
|
+
*
|
|
58
|
+
* @param deriveVisible boolean - if true, will recompute visibility for nodes based on ancestry
|
|
59
|
+
*/
|
|
60
|
+
toTree(deriveVisible?: boolean): TreeNode<T>[];
|
|
61
|
+
/**
|
|
62
|
+
* CACHE FUNCTIONS
|
|
63
|
+
* These manage cache operations. No cache operations should ever be done
|
|
64
|
+
* outside this file.
|
|
65
|
+
**/
|
|
66
|
+
getNode(key: Key): TreeNode<T>;
|
|
67
|
+
getAllKeys(): MapIterator<Key>;
|
|
68
|
+
getAllNodes(): MapIterator<CacheTreeNode<T>>;
|
|
69
|
+
setNode(key: Key, node: TreeNode<T>): void;
|
|
70
|
+
setAllNodes({ parentKey, children, ...rest }: Partial<TreeNode<T>>): void;
|
|
71
|
+
deleteNode(key: Key): void;
|
|
72
|
+
addNodes(target: Key | null, nodes: TreeNode<T>[], position: 'before' | 'after'): void;
|
|
73
|
+
insertNode(parentKey: Key | null, node: TreeNode<T>, idx: number): void;
|
|
74
|
+
moveNodes(target: Key | null, nodes: Set<Key>, position: 'before' | 'after'): void;
|
|
75
|
+
moveNode(parentKey: Key | null, key: Key, idx: number): void;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { Cache };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
class d{cache={lookup:new Map,roots:[]};constructor(e=[]){this.rebuild(e);}rebuild(e,t=new Map,s=null){e.forEach(r=>{const{children:o,...n}=r;t.set(r.key,{isDisabled:false,isExpanded:false,isSelected:false,isVisible:false,isVisibleComputed:false,...n,parentKey:s,...o?{children:o.map(l=>l.key)}:{}}),r.children&&this.rebuild(r.children,t,r.key);});const i={lookup:t,roots:e.map(r=>r.key)};return s||(this.cache=i),this.deriveVisibility(),i}get(e){const t=this.cache.lookup.get(e);if(t===void 0)throw new Error(`Key of ${e} does not exist in tree`);return t}set(e,t){this.cache.lookup.set(e,t);}delete(e){this.cache.lookup.delete(e);}addToParent(e,t,s){const i=this.get(e),r=this.get(t),o=Math.max(0,s);this.set(t,{...r,parentKey:e});const n=(i.children??[]).slice(0);n.splice(o,0,t),this.set(e,{...i,children:n});}addToRoot(e,t){const s=this.get(e),i=Math.max(0,t);this.set(e,{...s,parentKey:null}),this.cache.roots.splice(i,0,e);}removeFromParent(e,t){const s=this.get(e),i=this.get(t);this.set(t,{...i,parentKey:null}),this.cache.lookup.set(e,{...s,children:s.children?.filter(r=>r!==t)});}removeFromRoot(e){const t=this.get(e),s=this.cache.roots.indexOf(e);s>=0&&(this.set(e,{...t,parentKey:null}),this.cache.roots.splice(s,1));}parentOrSibling(e,t){let s,i=null;if(e===null)s=t==="before"?0:this.cache.roots.length;else {const r=this.get(e);if(r.parentKey){const o=this.get(r.parentKey);i=o.key,s=o.children?.findIndex(n=>n===e)??0;}else s=this.cache.roots.findIndex(o=>o===e);}return {parentKey:i,index:s}}traverse(e){const t=this.get(e);this.cache.lookup.set(e,{...t,isVisibleComputed:this.calculateVisibility(e)}),t.children?.map(s=>this.traverse(s));}calculateVisibility(e){let t=this.get(e);const s=[t];for(;t.parentKey;){const i=this.get(t.parentKey);i&&s.push(i),t=i;}return s.every(i=>i.isVisible)}deriveVisibility(){return this.cache.roots.map(e=>this.traverse(e))}buildNode(e){const t=this.get(e),s=(t.children??[]).reduce((i,r)=>{const o=this.cache.lookup.get(r);return o&&o.parentKey===e&&i.push(this.buildNode(r)),i},[]);return {...t,children:s}}toTree(e){return e&&this.deriveVisibility(),this.cache.roots.map(t=>this.buildNode(t))}getNode(e){const t=this.get(e);return {...t,children:t.children?.map(s=>this.buildNode(s))}}getAllKeys(){return this.cache.lookup.keys()}getAllNodes(){return this.cache.lookup.values()}setNode(e,t){this.set(e,{...t,children:(t.children??[]).map(s=>s.key)});}setAllNodes({parentKey:e,children:t,...s}){for(const i of this.cache.lookup.values())this.set(i.key,{...i,...s});}deleteNode(e){const t=this.cache.lookup.get(e);t&&(t.children?.map(s=>this.deleteNode(s)),t.parentKey?this.removeFromParent(t.parentKey,e):this.removeFromRoot(e),this.delete(e));}addNodes(e,t,s){const{parentKey:i,index:r}=this.parentOrSibling(e,s),o=r+(s==="before"?0:1);t.map((n,l)=>this.insertNode(i,n,o+l));}insertNode(e,t,s){const{children:i,...r}=t;this.set(t.key,{isDisabled:false,isExpanded:false,isSelected:false,isVisible:false,isVisibleComputed:false,...r,parentKey:e,...i?{children:i.map(o=>o.key)}:{}}),t.children?.map((o,n)=>this.insertNode(t.key,o,n)),e===null?this.addToRoot(t.key,s):this.addToParent(e,t.key,s);}moveNodes(e,t,s){const{parentKey:i,index:r}=this.parentOrSibling(e,s),o=r+(s==="before"?0:1);Array.from(t).map((n,l)=>this.moveNode(i,n,o+l));}moveNode(e,t,s){const i=this.get(t);i.parentKey?this.removeFromParent(i.parentKey,t):this.removeFromRoot(t),e?this.addToParent(e,t,s):this.addToRoot(t,s);}}export{d as Cache};//# sourceMappingURL=cache.js.map
|
|
2
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/hooks/use-tree/actions/cache.ts"],"names":["Cache","nodes","lookup","parentKey","node","children","rest","child","cache","key","childKey","idx","parent","index","target","position","targetNode","rootKey","current","ancestry","n","acc","childNode","deriveVisible","i"],"mappings":"AA6BO,MAAMA,CAAS,CACV,KAAA,CAA8D,CACtE,OAAQ,IAAI,GAAA,CACZ,KAAA,CAAO,EACT,CAAA,CAEA,YAAYC,CAAAA,CAAuB,EAAC,CAAG,CACrC,IAAA,CAAK,OAAA,CAAQA,CAAK,EACpB,CAKA,OAAA,CACEA,CAAAA,CACAC,CAAAA,CAAqC,IAAI,IACzCC,CAAAA,CAAwB,IAAA,CACxB,CACAF,CAAAA,CAAM,OAAA,CAASG,CAAAA,EAAS,CACtB,KAAM,CAAE,QAAA,CAAAC,CAAAA,CAAU,GAAGC,CAAK,EAAIF,CAAAA,CAE9BF,CAAAA,CAAO,GAAA,CAAIE,CAAAA,CAAK,GAAA,CAAK,CACnB,WAAY,KAAA,CACZ,UAAA,CAAY,KAAA,CACZ,UAAA,CAAY,KAAA,CACZ,SAAA,CAAW,MACX,iBAAA,CAAmB,KAAA,CACnB,GAAGE,CAAAA,CACH,SAAA,CAAAH,EACA,GAAIE,CAAAA,CAAW,CAAE,QAAA,CAAUA,CAAAA,CAAS,GAAA,CAAKE,GAAUA,CAAAA,CAAM,GAAG,CAAE,CAAA,CAAI,EACpE,CAAC,CAAA,CAEGH,CAAAA,CAAK,QAAA,EACP,IAAA,CAAK,OAAA,CAAQA,CAAAA,CAAK,SAAUF,CAAAA,CAAQE,CAAAA,CAAK,GAAG,EAEhD,CAAC,CAAA,CAED,MAAMI,CAAAA,CAAQ,CAAE,MAAA,CAAAN,CAAAA,CAAQ,KAAA,CAAOD,CAAAA,CAAM,IAAKG,CAAAA,EAASA,CAAAA,CAAK,GAAG,CAAE,CAAA,CAE7D,OAAKD,IACH,IAAA,CAAK,KAAA,CAAQK,CAAAA,CAAAA,CAGf,IAAA,CAAK,gBAAA,EAAiB,CACfA,CACT,CAEU,GAAA,CAAIC,EAAU,CACtB,MAAML,EAAO,IAAA,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AAA,CAAO,IAAA,CAAK,GAAA,CAAIK,CAAG,CAAA,CAGzBL,CAAAA,CAAK,SAAA,CACD,IAAA,CAAK,gBAAA,CAAiBA,CAAAA,CAAK,UAAWK,CAAG,CAAA,CACzC,IAAA,CAAK,cAAA,CAAeA,CAAG,CAAA,CAG3BN,EACI,IAAA,CAAK,WAAA,CAAYA,CAAAA,CAAWM,CAAAA,CAAKE,CAAG,CAAA,CACpC,KAAK,SAAA,CAAUF,CAAAA,CAAKE,CAAG,EAC7B,CACF","file":"cache.js","sourcesContent":["// __private-exports\n/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type { Key } from '@react-types/shared';\nimport type { TreeNode } from '../types';\n\ntype CacheTreeNode<T> = Omit<TreeNode<T>, 'children'> & {\n children?: Key[];\n};\n\n/**\n * This is a cache created only for performance reasons and is considered\n * to be only a temporary mirror of the data. The data is *always* correct\n * cache should be updated according to the data, only. If the data and\n * the cache do not match, the cache is invalidated and rebuilt.\n *\n * This will initialize once on load with data, then\n * updated with each tree operation.\n */\nexport class Cache<T> {\n protected cache: { lookup: Map<Key, CacheTreeNode<T>>; roots: Key[] } = {\n lookup: new Map(),\n roots: [],\n };\n\n constructor(nodes: TreeNode<T>[] = []) {\n this.rebuild(nodes);\n }\n\n /**\n * Recursively creates the cache object from tree data\n */\n rebuild(\n nodes: TreeNode<T>[],\n lookup: Map<Key, CacheTreeNode<T>> = new Map(),\n parentKey: Key | null = null,\n ) {\n nodes.forEach((node) => {\n const { children, ...rest } = node;\n\n lookup.set(node.key, {\n isDisabled: false,\n isExpanded: false,\n isSelected: false,\n isVisible: false,\n isVisibleComputed: false,\n ...rest,\n parentKey,\n ...(children ? { children: children.map((child) => child.key) } : {}),\n });\n\n if (node.children) {\n this.rebuild(node.children, lookup, node.key);\n }\n });\n\n const cache = { lookup, roots: nodes.map((node) => node.key) };\n\n if (!parentKey) {\n this.cache = cache;\n }\n\n this.deriveVisibility();\n return cache;\n }\n\n protected get(key: Key) {\n const node = this.cache.lookup.get(key);\n\n if (node === undefined) {\n throw new Error(`Key of ${key} does not exist in tree`);\n }\n\n return node;\n }\n\n protected set(key: Key, node: CacheTreeNode<T>) {\n this.cache.lookup.set(key, node);\n }\n\n protected delete(key: Key) {\n this.cache.lookup.delete(key);\n }\n\n protected addToParent(parentKey: Key, childKey: Key, idx: number) {\n const parent = this.get(parentKey);\n const child = this.get(childKey);\n const index = Math.max(0, idx);\n\n this.set(childKey, {\n ...child,\n parentKey,\n });\n\n const children = (parent.children ?? []).slice(0);\n\n children.splice(index, 0, childKey);\n\n this.set(parentKey, {\n ...parent,\n children,\n });\n }\n\n protected addToRoot(key: Key, idx: number) {\n const node = this.get(key);\n const index = Math.max(0, idx);\n\n this.set(key, {\n ...node,\n parentKey: null,\n });\n\n this.cache.roots.splice(index, 0, key);\n }\n\n protected removeFromParent(parentKey: Key, childKey: Key) {\n const parent = this.get(parentKey);\n const child = this.get(childKey);\n\n this.set(childKey, {\n ...child,\n parentKey: null,\n });\n\n this.cache.lookup.set(parentKey, {\n ...parent,\n children: parent.children?.filter((key) => key !== childKey),\n });\n }\n\n protected removeFromRoot(key: Key) {\n const node = this.get(key);\n const idx = this.cache.roots.indexOf(key);\n\n if (idx >= 0) {\n this.set(key, {\n ...node,\n parentKey: null,\n });\n\n this.cache.roots.splice(idx, 1);\n }\n }\n\n protected parentOrSibling(target: Key | null, position: 'before' | 'after') {\n let index: number;\n let parentKey: Key | null = null;\n\n if (target === null) {\n index = position === 'before' ? 0 : this.cache.roots.length;\n } else {\n const targetNode = this.get(target);\n\n if (targetNode.parentKey) {\n const parent = this.get(targetNode.parentKey);\n\n parentKey = parent.key;\n index = parent.children?.findIndex((key) => key === target) ?? 0;\n } else {\n index = this.cache.roots.findIndex((rootKey) => rootKey === target);\n }\n }\n\n return { parentKey, index };\n }\n\n protected traverse(key: Key) {\n const node = this.get(key);\n\n this.cache.lookup.set(key, {\n ...node,\n isVisibleComputed: this.calculateVisibility(key),\n });\n\n node.children?.map((child) => this.traverse(child));\n }\n\n protected calculateVisibility(key: Key) {\n let current = this.get(key);\n const ancestry = [current];\n\n while (current.parentKey) {\n const parent = this.get(current.parentKey);\n if (parent) {\n ancestry.push(parent);\n }\n current = parent;\n }\n\n return ancestry.every((n) => n.isVisible);\n }\n\n protected deriveVisibility() {\n return this.cache.roots.map((key) => this.traverse(key));\n }\n /**\n * Recursively builds a TreeNode from a key\n *\n * @param key\n */\n protected buildNode(key: Key): TreeNode<T> {\n const node = this.get(key);\n\n const children = (node.children ?? []).reduce(\n (acc: TreeNode<T>[], child) => {\n const childNode = this.cache.lookup.get(child);\n\n if (childNode && childNode.parentKey === key) {\n acc.push(this.buildNode(child));\n }\n\n return acc;\n },\n [],\n );\n\n return {\n ...node,\n children,\n };\n }\n\n /**\n * Builds a tree structure from cache\n *\n * TODO: optimization - rebuild only from change to root\n * Rebuild only from the changed node up the tree to avoid\n * rebuilding the entire tree\n *\n * @param deriveVisible boolean - if true, will recompute visibility for nodes based on ancestry\n */\n toTree(deriveVisible?: boolean): TreeNode<T>[] {\n if (deriveVisible) {\n this.deriveVisibility();\n }\n return this.cache.roots.map((key) => this.buildNode(key));\n }\n\n /**\n * CACHE FUNCTIONS\n * These manage cache operations. No cache operations should ever be done\n * outside this file.\n **/\n getNode(key: Key): TreeNode<T> {\n const node = this.get(key);\n\n return {\n ...node,\n children: node.children?.map((key) => this.buildNode(key)),\n };\n }\n\n getAllKeys() {\n return this.cache.lookup.keys();\n }\n\n getAllNodes() {\n return this.cache.lookup.values();\n }\n\n setNode(key: Key, node: TreeNode<T>) {\n this.set(key, {\n ...node,\n children: (node.children ?? []).map((child) => child.key),\n });\n }\n\n setAllNodes({ parentKey, children, ...rest }: Partial<TreeNode<T>>) {\n for (const node of this.cache.lookup.values()) {\n this.set(node.key, {\n ...node,\n ...rest,\n });\n }\n }\n\n deleteNode(key: Key) {\n const node = this.cache.lookup.get(key);\n\n if (!node) {\n return;\n }\n\n // remove children\n node.children?.map((key) => this.deleteNode(key));\n\n // remove node from previous parent or root\n node.parentKey\n ? this.removeFromParent(node.parentKey, key)\n : this.removeFromRoot(key);\n\n // remove the actual node\n this.delete(key);\n }\n\n addNodes(\n target: Key | null,\n nodes: TreeNode<T>[],\n position: 'before' | 'after',\n ) {\n const { parentKey, index } = this.parentOrSibling(target, position);\n const idx = index + (position === 'before' ? 0 : 1);\n\n nodes.map((node, i) => this.insertNode(parentKey, node, idx + i));\n }\n\n insertNode(parentKey: Key | null, node: TreeNode<T>, idx: number) {\n const { children, ...rest } = node;\n\n this.set(node.key, {\n isDisabled: false,\n isExpanded: false,\n isSelected: false,\n isVisible: false,\n isVisibleComputed: false,\n ...rest,\n parentKey,\n ...(children ? { children: children.map((child) => child.key) } : {}),\n });\n\n node.children?.map((child, i) => this.insertNode(node.key, child, i));\n\n parentKey === null\n ? this.addToRoot(node.key, idx)\n : this.addToParent(parentKey, node.key, idx);\n }\n\n moveNodes(target: Key | null, nodes: Set<Key>, position: 'before' | 'after') {\n const { parentKey, index } = this.parentOrSibling(target, position);\n const idx = index + (position === 'before' ? 0 : 1);\n\n Array.from(nodes).map((key, i) => this.moveNode(parentKey, key, idx + i));\n }\n\n moveNode(parentKey: Key | null, key: Key, idx: number) {\n const node = this.get(key);\n\n // remove from previous parent\n node.parentKey\n ? this.removeFromParent(node.parentKey, key)\n : this.removeFromRoot(key);\n\n // add as child to new parent or root at position\n parentKey\n ? this.addToParent(parentKey, key, idx)\n : this.addToRoot(key, idx);\n }\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { UseTreeActionsOptions, TreeActions } from '../types.js';
|
|
2
|
+
import '@react-types/shared';
|
|
3
|
+
import 'react';
|
|
4
|
+
import 'react-aria-components';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Stateless hook that transforms tree data according to actions
|
|
8
|
+
* it takes in nodes and returns a new version of the tree.
|
|
9
|
+
*
|
|
10
|
+
* Note: each operation returns the whole tree. Future iterations
|
|
11
|
+
* might want to return only the changed portion of the tree.
|
|
12
|
+
*
|
|
13
|
+
* @returns {TreeActions<T>} Object containing all tree manipulation functions
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const treeActions = useTreeActions({
|
|
18
|
+
* nodes: [
|
|
19
|
+
* {
|
|
20
|
+
* key: 'root',
|
|
21
|
+
* label: 'Root',
|
|
22
|
+
* children: [
|
|
23
|
+
* { key: 'child1', label: 'Child 1' },
|
|
24
|
+
* { key: 'child2', label: 'Child 2' }
|
|
25
|
+
* ]
|
|
26
|
+
* }
|
|
27
|
+
* ]
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Use tree actions
|
|
31
|
+
* const updatedTree = treeActions.insertAfter('child1', [
|
|
32
|
+
* { key: 'newChild', label: 'New Child' }
|
|
33
|
+
* ]);Type T | undefined is not assignable to type T | undefined. Two different types with this name exist, but they are unrelated.
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare function useTreeActions<T>({ nodes, }: UseTreeActionsOptions<T>): TreeActions<T>;
|
|
37
|
+
|
|
38
|
+
export { useTreeActions };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import'client-only';import {useUpdateEffect}from'@react-aria/utils';import {useRef}from'react';import {Cache}from'./cache.js';function V({nodes:n}){const e=useRef(new Cache(n)).current;useUpdateEffect(()=>{e.rebuild(n);},[n]);function u(o){return e.getNode(o)}function i(o,t){return e.addNodes(o,t,"after"),e.toTree(true)}function l(o,t){return e.addNodes(o,t,"before"),e.toTree(true)}function f(o,t){for(const r of t)e.insertNode(o,r,0);return e.toTree(true)}function c(o,t){return e.moveNodes(o,t,"after"),e.toTree()}function N(o,t){return e.moveNodes(o,t,"before"),e.toTree()}function a(o,t){for(const r of t)e.moveNode(o,r,0);return e.toTree()}function y(o,t){const r=e.getNode(o);return e.setNode(o,t(r)),e.toTree(true)}function p(o){for(const t of o.values())e.deleteNode(t);return e.toTree(true)}function A(o){d();for(const t of o){const r=e.getNode(t);e.setNode(r.key,{...r,isSelected:true});}return e.toTree()}function m(){return e.setAllNodes({isSelected:true}),e.toTree()}function d(){return e.setAllNodes({isSelected:false}),e.toTree()}function K(o){T();for(const t of o){const r=e.getNode(t);e.setNode(r.key,{...r,isExpanded:true});}return e.toTree()}function S(){return e.setAllNodes({isExpanded:true}),e.toTree()}function T(){return e.setAllNodes({isExpanded:false}),e.toTree()}function g(o){s();for(const t of o){const r=e.getNode(t);e.setNode(r.key,{...r,isVisible:true});}return e.toTree(true)}function v(){return e.setAllNodes({isVisible:true}),e.toTree(true)}function s(){return e.setAllNodes({isVisible:false}),e.toTree(true)}return {getNode:u,insertAfter:i,insertBefore:l,insertInto:f,moveAfter:c,moveBefore:N,moveInto:a,remove:p,updateNode:y,collapseAll:T,expandAll:S,onExpandedChange:K,selectAll:m,unselectAll:d,onSelectionChange:A,hideAll:s,revealAll:v,onVisibilityChange:g}}export{V as useTreeActions};//# sourceMappingURL=index.js.map
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/hooks/use-tree/actions/index.ts"],"names":["h","Cache","k","b","nodes","node","keys","key","callback","cache","unselectAll","collapseAll","hideAll"],"mappings":"8HAwDO,SACL,CAAA,CAAA,CAAA,KAC2C,CAC3C,CAAA,CAAA,CAAA,CAAA,MAAqB,CAAA,CAAAA,MAAA,CAAIC,IAAeC,KAAA,CAAE,WAE1B,CAAAC,eAAA,CAAM,IACd,CAAA,CAAA,CAAA,OACR,CA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H,CAAA,CAAA,SACD,CACH,IACA,CAAA,EAAA,CAAA,eACF,CAEA,IAAA,CAAA,CAAA,SACE,WAAM,CAAA,CAAA,WAAc,CAAA,CAAA,SAAiB,KAE9BI,CAAM,CAAA,CAAA,CAAA,CAAA,MACf,CAEA,IAAA,CAAA,CAAA,SACE,CAAA,EAAA,CAAA,OAAM,CAAA,CAAA,sBAAgC,CAAA,KAE/BA,CAAM,CAAA,CAAA,CAAA,CAAA,MACf,CAEA,IAAA,CAAA,CAAA,OACE,CAAA,OACA,CAAA,CAAA,CAAA,WACA,CAAA,CAAA,CAAA,YACA,CAAA,CAAA,CAAA,UACA,CAAA,CAAA,CAAA,sBAEA,CAAA,CAAA,CAAA,QACA,CAAA,CAAA,CAAA,MACA,CAAA,CAAA,CAAA,UAGA,CAAA,CAAA,CAAA,WACA,CAAA,CAAA,CAAA,SACA,CAAA,CAAA,CAAA,4BAIA,CAAA,CAAA,CAAA,WACA,CAAA,CAAA,CAAA,iBAGA,CAAA,CAAA,CAAA,OACA,CAAA,CAAA,CAAA,SACA,CAAA,CAAA,CAAA,kBAEJ,CAAA,CAAA,CAAA","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n'use client';\n\nimport 'client-only';\nimport { useUpdateEffect } from '@react-aria/utils';\nimport { useRef } from 'react';\nimport { Cache } from './cache';\nimport type { Key } from '@react-types/shared';\nimport type {\n TreeActions,\n TreeData,\n TreeNode,\n TreeNodeBase,\n UseTreeActionsOptions,\n} from '../types';\n\n/**\n * Stateless hook that transforms tree data according to actions\n * it takes in nodes and returns a new version of the tree.\n *\n * Note: each operation returns the whole tree. Future iterations\n * might want to return only the changed portion of the tree.\n *\n * @returns {TreeActions<T>} Object containing all tree manipulation functions\n *\n * @example\n * ```tsx\n * const treeActions = useTreeActions({\n * nodes: [\n * {\n * key: 'root',\n * label: 'Root',\n * children: [\n * { key: 'child1', label: 'Child 1' },\n * { key: 'child2', label: 'Child 2' }\n * ]\n * }\n * ]\n * });\n *\n * // Use tree actions\n * const updatedTree = treeActions.insertAfter('child1', [\n * { key: 'newChild', label: 'New Child' }\n * ]);Type T | undefined is not assignable to type T | undefined. Two different types with this name exist, but they are unrelated.\n * ```\n */\nexport function useTreeActions<T>({\n nodes,\n}: UseTreeActionsOptions<T>): TreeActions<T> {\n const cache = useRef(new Cache<T>(nodes)).current;\n\n useUpdateEffect(() => {\n cache.rebuild(nodes);\n }, [nodes]);\n\n /** GET NODE **/\n function getNode(key: Key) {\n return cache.getNode(key);\n }\n\n /** INSERT NODES **/\n function insertAfter(\n target: Key | null,\n nodes: TreeNode<T>[],\n ): TreeNode<T>[] {\n cache.addNodes(target, nodes, 'after');\n\n return cache.toTree(true);\n }\n\n function insertBefore(\n target: Key | null,\n nodes: TreeNode<T>[],\n ): TreeNode<T>[] {\n cache.addNodes(target, nodes, 'before');\n\n return cache.toTree(true);\n }\n\n function insertInto(target: Key | null, nodes: TreeNode<T>[]): TreeNode<T>[] {\n for (const node of nodes) {\n cache.insertNode(target, node, 0);\n }\n\n return cache.toTree(true);\n }\n\n /** MOVE NODES **/\n function moveAfter(target: Key | null, keys: Set<Key>): TreeNode<T>[] {\n cache.moveNodes(target, keys, 'after');\n\n return cache.toTree();\n }\n\n function moveBefore(target: Key | null, keys: Set<Key>): TreeNode<T>[] {\n cache.moveNodes(target, keys, 'before');\n\n return cache.toTree();\n }\n\n function moveInto(target: Key | null, keys: Set<Key>): TreeNode<T>[] {\n for (const key of keys) {\n cache.moveNode(target, key, 0);\n }\n\n return cache.toTree();\n }\n\n /** UPDATE NODES **/\n function updateNode(\n key: Key,\n callback: (node: TreeNodeBase<T>) => TreeNodeBase<T>,\n ): TreeNode<T>[] {\n const node = cache.getNode(key);\n\n cache.setNode(key, callback(node));\n\n return cache.toTree(true);\n }\n\n /** REMOVE NODES **/\n function remove(keys: Set<Key>): TreeNode<T>[] {\n for (const key of keys.values()) {\n cache.deleteNode(key);\n }\n\n return cache.toTree(true);\n }\n\n /** SELECTION **/\n function onSelectionChange(keys: Set<Key>): TreeNode<T>[] {\n unselectAll();\n\n for (const key of keys) {\n const node = cache.getNode(key);\n\n cache.setNode(node.key, {\n ...node,\n isSelected: true,\n });\n }\n\n return cache.toTree();\n }\n\n function selectAll(): TreeNode<T>[] {\n cache.setAllNodes({ isSelected: true });\n\n return cache.toTree();\n }\n\n function unselectAll(): TreeNode<T>[] {\n cache.setAllNodes({ isSelected: false });\n\n return cache.toTree();\n }\n\n /** EXPANSION **/\n function onExpandedChange(keys: Set<Key>): TreeNode<T>[] {\n collapseAll();\n\n for (const key of keys) {\n const node = cache.getNode(key);\n\n cache.setNode(node.key, {\n ...node,\n isExpanded: true,\n });\n }\n\n return cache.toTree();\n }\n\n function expandAll(): TreeNode<T>[] {\n cache.setAllNodes({ isExpanded: true });\n\n return cache.toTree();\n }\n\n function collapseAll(): TreeNode<T>[] {\n cache.setAllNodes({ isExpanded: false });\n\n return cache.toTree();\n }\n\n /** VISIBILITY **/\n function onVisibilityChange(keys: Set<Key>): TreeData<T> {\n hideAll();\n\n for (const key of keys) {\n const node = cache.getNode(key);\n cache.setNode(node.key, {\n ...node,\n isVisible: true,\n });\n }\n return cache.toTree(true);\n }\n\n function revealAll(): TreeNode<T>[] {\n cache.setAllNodes({ isVisible: true });\n\n return cache.toTree(true);\n }\n\n function hideAll(): TreeNode<T>[] {\n cache.setAllNodes({ isVisible: false });\n\n return cache.toTree(true);\n }\n\n return {\n getNode,\n insertAfter,\n insertBefore,\n insertInto,\n moveAfter,\n moveBefore,\n moveInto,\n remove,\n updateNode,\n\n // Expansion\n collapseAll,\n expandAll,\n onExpandedChange,\n\n // Selection\n selectAll,\n unselectAll,\n onSelectionChange,\n\n // Visibility\n hideAll,\n revealAll,\n onVisibilityChange,\n };\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { UseTreeStateOptions, UseTreeState } from '../types.js';
|
|
2
|
+
import '@react-types/shared';
|
|
3
|
+
import 'react';
|
|
4
|
+
import 'react-aria-components';
|
|
5
|
+
|
|
6
|
+
declare function useTreeState<T>({ items, }: UseTreeStateOptions<T>): UseTreeState<T>;
|
|
7
|
+
|
|
8
|
+
export { useTreeState };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import'client-only';import {useState}from'react';import {useTreeActions}from'../actions/index.js';import {processDroppedItems}from'./utils.js';function E({items:d}){const[s,t]=useState(d),o=useTreeActions({nodes:s}),l={getItems:e=>[...e].map(n=>{const r=o.getNode(n);return {key:`${n}`,"text/plain":JSON.stringify(r)}}),onReorder:e=>{e.target.dropPosition==="before"?t(o.moveBefore(e.target.key,e.keys)):t(o.moveAfter(e.target.key,e.keys));},onInsert:({items:e,target:n})=>{(async()=>{const r=await processDroppedItems(e,l.acceptedDragTypes??[]);t(o.remove(new Set(r.map(i=>i.id)))),n.dropPosition==="before"?t(o.insertBefore(n.key,r)):n.dropPosition==="after"&&t(o.insertAfter(n.key,r));})();},onItemDrop:({target:e,items:n})=>{(async()=>{const r=o.getNode(e.key),[i]=n;if(e.dropPosition==="on"&&r&&i&&i.kind!=="directory"){const a=await i.getText("key");a&&t(o.moveInto(e.key,new Set([a])));}})();},onRootDrop:({items:e})=>{(async()=>{const n=await processDroppedItems(e,l.acceptedDragTypes??[]);t(o.remove(new Set(n.map(r=>r.key)))),t(o.insertAfter(null,n));})();}};function f(){t(o.collapseAll());}function m(){t(o.expandAll());}function y(e){t(o.onExpandedChange(e));}function p(){t(o.selectAll());}function D(){t(o.unselectAll());}function g(e){if(e==="all")return p();t(o.onSelectionChange(e));}function u(){t(o.hideAll());}function A(){t(o.revealAll());}function C(e){t(o.onVisibilityChange(e));}return {nodes:s,actions:{collapseAll:f,expandAll:m,onExpandedChange:y,selectAll:p,unselectAll:D,onSelectionChange:g,hideAll:u,revealAll:A,onVisibilityChange:C},dragAndDropConfig:l}}export{E as useTreeState};//# sourceMappingURL=index.js.map
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/hooks/use-tree/state/index.ts"],"names":["useState","items","useTreeActions","S","nodes","dragAndDropConfig","keys","key","node","actions","setNodes","processDroppedItems","c","item","target","collapseAll","expandAll","onExpandedChange","selectAll","unselectAll","onSelectionChange","hideAll","revealAll"],"mappings":"+IAiCE,SAEA,CAAA,CAAA,CAAA,KAAsB,EAAIA,CAAAA,CAASC,CAAK,KACxBC,CAAkB,CAAE,CAAA,CAAA,CAAA,CAAAC,QAAA,CAAAC,CAAM,CAAC,CAAA,CAErCC,CAAAA,cAAuC,CAC3C,CAAA,KAAA,CAAA,CAAA,CAAWC,CAAAA,CAAAA,CACT,CAAC,CAAA,QAAS,CAAKC,CAAAA,EAAQ,CACrB,GAAA,CAAA,CAAA,CAAMC,GAAOC,CAAQ,CAAA,EAAA,CAAA,MAAW,CAEhC,CAAA,CAAA,CAAA,OACE,CAAK,CAAA,CAAA,CAAGF,OACR,CAAA,GAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAc,aAAK,CAAA,IAEvB,CAAC,SACH,CAAA,CAAA,CAAY,CAAA,CAAA,CAAuC,CAC7C,SAAS,0BACFE,GAAQ,QAAA,CAAA,CAAW,CAAA,CAAE,WAAY,CAAA,CAAE,OAE5CC,IAAiB,CAAA,CAAA,CAAA,IAAA,CAAA,CAAA,CAAU,EAAE,CAAA,CAAA,SAAY,EAAE,CAAA,MAE/C,CACA,UAAW,CAAE,YAAO,CAAA,CAAA,CAAA,KAAO,CAA0C,CAAA,CAClE,SAAY,GACX,CAAA,CAAA,S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AAC,CAC9B,CAEA,UAASS,EAAc,EACrBT,UAAiB,CAAA,EAAA,CAAA,CAAA,CAAY,CAAC,CAChC,WAESU,EAAkBd,EAAiB,CAC1C,aACE,CAAA,GAAA,CAAA,GAAOY,KAGAT,CAAAA,gCAGFY,GAAU,EACjBX,CAAAA,SAAiB,CAAA,EAAS,CAC5B,CAEA,CAAA,CAAA,CAAA,SAAqB,EACnBA,CAAAA,SAAiB,CAAA,EAAA,CAAU,CAAC,CAC9B,CAEA,CAAA,WAA4BJ,EAAgB,CAC1CI,SAAiB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,uBAIjBN,CAAAA,OACA,CAAA,KAEE,CAAA,CAAA,CAAA,OAAAW,CAAAA,CACA,WAAAC,CACA,CAAA,CAAA,SAAA,CAAA,CAAA,CAAA,gBAGAE,CACA,YAAAC,CAAAA,CACA,WAAA,CAAA,CAAA,CAAA,2BAIAG,CACA,CAAA,CAAA,SAAA,CAAA,CAAA,CAAA,kBAEF,CAAA,CAAA,CAAA,CAAA,iBAEJ,CAAA,CAAA,CAAA","file":"index.js","sourcesContent":["/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n'use client';\n\nimport 'client-only';\nimport { useState } from 'react';\nimport { useTreeActions } from '../actions';\nimport { processDroppedItems } from './utils';\nimport type {\n DragItem,\n DroppableCollectionInsertDropEvent,\n DroppableCollectionOnItemDropEvent,\n DroppableCollectionReorderEvent,\n DroppableCollectionRootDropEvent,\n Key,\n Selection,\n} from '@react-types/shared';\nimport type {\n DragAndDropConfig,\n UseTreeState,\n UseTreeStateOptions,\n} from '../types';\n\nexport function useTreeState<T>({\n items,\n}: UseTreeStateOptions<T>): UseTreeState<T> {\n const [nodes, setNodes] = useState(items);\n const actions = useTreeActions<T>({ nodes });\n\n const dragAndDropConfig: DragAndDropConfig = {\n getItems: (keys: Set<Key>): DragItem[] =>\n [...keys].map((key) => {\n const node = actions.getNode(key);\n\n return {\n key: `${key}`,\n 'text/plain': JSON.stringify(node),\n };\n }),\n onReorder: (e: DroppableCollectionReorderEvent) => {\n if (e.target.dropPosition === 'before') {\n setNodes(actions.moveBefore(e.target.key, e.keys));\n } else {\n setNodes(actions.moveAfter(e.target.key, e.keys));\n }\n },\n onInsert: ({ items, target }: DroppableCollectionInsertDropEvent) => {\n (async () => {\n const processedItems = await processDroppedItems(\n items,\n dragAndDropConfig.acceptedDragTypes ?? [],\n );\n\n setNodes(\n actions.remove(new Set(processedItems.map((item) => item.id))),\n );\n\n if (target.dropPosition === 'before') {\n setNodes(actions.insertBefore(target.key, processedItems));\n } else if (target.dropPosition === 'after') {\n setNodes(actions.insertAfter(target.key, processedItems));\n }\n })();\n },\n onItemDrop: ({ target, items }: DroppableCollectionOnItemDropEvent) => {\n (async () => {\n const targetNode = actions.getNode(target.key);\n const [item] = items;\n\n if (\n target.dropPosition === 'on' &&\n targetNode &&\n item &&\n item.kind !== 'directory'\n ) {\n const key = await item.getText('key');\n\n if (key) {\n setNodes(actions.moveInto(target.key, new Set([key])));\n }\n }\n })();\n },\n onRootDrop: ({ items }: DroppableCollectionRootDropEvent) => {\n (async () => {\n const processedItems = await processDroppedItems(\n items,\n dragAndDropConfig.acceptedDragTypes ?? [],\n );\n\n setNodes(\n actions.remove(new Set(processedItems.map((item) => item.key))),\n );\n setNodes(actions.insertAfter(null, processedItems));\n })();\n },\n };\n\n function collapseAll() {\n setNodes(actions.collapseAll());\n }\n\n function expandAll() {\n setNodes(actions.expandAll());\n }\n\n function onExpandedChange(keys: Set<Key>) {\n setNodes(actions.onExpandedChange(keys));\n }\n\n function selectAll() {\n setNodes(actions.selectAll());\n }\n\n function unselectAll() {\n setNodes(actions.unselectAll());\n }\n\n function onSelectionChange(keys: Selection) {\n if (keys === 'all') {\n return selectAll();\n }\n\n setNodes(actions.onSelectionChange(keys));\n }\n\n function hideAll() {\n setNodes(actions.hideAll());\n }\n\n function revealAll() {\n setNodes(actions.revealAll());\n }\n\n function onVisibilityChange(keys: Set<Key>) {\n setNodes(actions.onVisibilityChange(keys));\n }\n\n return {\n nodes,\n actions: {\n // Expansion\n collapseAll,\n expandAll,\n onExpandedChange,\n\n // Selection\n selectAll,\n unselectAll,\n onSelectionChange,\n\n // Visibility\n hideAll,\n revealAll,\n onVisibilityChange,\n },\n dragAndDropConfig,\n };\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DropItem, TextDropItem } from '@react-types/shared';
|
|
2
|
+
|
|
3
|
+
declare function processDroppedItems(items: DropItem[], acceptedDragTypes: string[]): Promise<any[]>;
|
|
4
|
+
declare function processDroppedItem(item: TextDropItem, acceptedDragTypes: string[]): Promise<any>;
|
|
5
|
+
declare function getDroppedItemPayload(item: TextDropItem, acceptedDragTypes: string[]): Promise<string>;
|
|
6
|
+
|
|
7
|
+
export { getDroppedItemPayload, processDroppedItem, processDroppedItems };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {isTextDropItem}from'@react-aria/dnd';async function n(r,t){return await Promise.all(r.filter(isTextDropItem).map(e=>p(e,t)))}async function p(r,t){const e=await a(r,t);return e?JSON.parse(e):Promise.reject(new Error("No supported type payload"))}async function a(r,t){return await Promise.any(t.map(async e=>await r.getText(e)??Promise.reject(new Error("Unsupported type"))))}export{a as getDroppedItemPayload,p as processDroppedItem,n as processDroppedItems};//# sourceMappingURL=utils.js.map
|
|
2
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/hooks/use-tree/state/utils.ts"],"names":["processDroppedItems","items","acceptedDragTypes","isTextDropItem","item","processDroppedItem","payload","getDroppedItemPayload","type"],"mappings":"6CAgBA,eAAsBA,CAAAA,CACpBC,EACAC,CAAAA,CACA,CACA,OAAO,MAAM,QAAQ,GAAA,CACnBD,CAAAA,CACG,MAAA,CAAOE,cAAc,EACrB,GAAA,CAAKC,CAAAA,EAASC,CAAAA,CAAmBD,CAAAA,CAAMF,CAAiB,CAAC,CAC9D,CACF,CAEA,eAAsBG,CAAAA,CACpBD,CAAAA,CACAF,CAAAA,CACA,CACA,MAAMI,CAAAA,CAAU,MAAMC,CAAAA,CAAsBH,CAAAA,CAAMF,CAAiB,CAAA,CAEnE,OAAOI,CAAAA,CACH,IAAA,CAAK,MAAMA,CAAO,CAAA,CAClB,OAAA,CAAQ,MAAA,CAAO,IAAI,KAAA,CAAM,2BAA2B,CAAC,CAC3D,CAEA,eAAsBC,CAAAA,CACpBH,CAAAA,CACAF,CAAAA,CACA,CACA,OAAO,MAAM,OAAA,CAAQ,GAAA,CACnBA,EAAkB,GAAA,CAChB,MAAOM,CAAAA,EACJ,MAAMJ,EAAK,OAAA,CAAQI,CAAI,CAAA,EACxB,OAAA,CAAQ,OAAO,IAAI,KAAA,CAAM,kBAAkB,CAAC,CAChD,CACF,CACF","file":"utils.js","sourcesContent":["// __private-exports\n/*\n * Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { isTextDropItem } from '@react-aria/dnd';\nimport type { DropItem, TextDropItem } from '@react-types/shared';\n\nexport async function processDroppedItems(\n items: DropItem[],\n acceptedDragTypes: string[],\n) {\n return await Promise.all(\n items\n .filter(isTextDropItem)\n .map((item) => processDroppedItem(item, acceptedDragTypes)),\n );\n}\n\nexport async function processDroppedItem(\n item: TextDropItem,\n acceptedDragTypes: string[],\n) {\n const payload = await getDroppedItemPayload(item, acceptedDragTypes);\n\n return payload\n ? JSON.parse(payload)\n : Promise.reject(new Error('No supported type payload'));\n}\n\nexport async function getDroppedItemPayload(\n item: TextDropItem,\n acceptedDragTypes: string[],\n) {\n return await Promise.any(\n acceptedDragTypes.map(\n async (type) =>\n (await item.getText(type)) ??\n Promise.reject(new Error('Unsupported type')),\n ),\n );\n}\n"]}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { Key, DragItem, DroppableCollectionRootDropEvent, DroppableCollectionReorderEvent, DroppableCollectionInsertDropEvent, DroppableCollectionOnItemDropEvent } from '@react-types/shared';
|
|
2
|
+
import { ReactElement } from 'react';
|
|
3
|
+
import { DropTarget, Selection } from 'react-aria-components';
|
|
4
|
+
|
|
5
|
+
type DragAndDropConfig = {
|
|
6
|
+
getItems: (key: Set<Key>) => DragItem[];
|
|
7
|
+
/**
|
|
8
|
+
* Handler that is called when external items are dropped on the droppable collection's root.
|
|
9
|
+
*/
|
|
10
|
+
onRootDrop?: (e: DroppableCollectionRootDropEvent) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Handler that is called when items are reordered within the collection.
|
|
13
|
+
* This handler only allows dropping between items, not on items.
|
|
14
|
+
* It does not allow moving items to a different parent item within a tree.
|
|
15
|
+
*/
|
|
16
|
+
onReorder?: (e: DroppableCollectionReorderEvent) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Handler that is called when items are moved within the source collection.
|
|
19
|
+
* This handler allows dropping both on or between items, and items may be
|
|
20
|
+
* moved to a different parent item within a tree.
|
|
21
|
+
*/
|
|
22
|
+
onMove?: (e: DroppableCollectionReorderEvent) => void;
|
|
23
|
+
renderDragPreview?: (items: DragItem[]) => ReactElement;
|
|
24
|
+
renderDropIndicator?: (target: DropTarget) => ReactElement;
|
|
25
|
+
acceptedDragTypes?: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Handler that is called when external items are dropped "between" items.
|
|
28
|
+
*/
|
|
29
|
+
onInsert?: (e: DroppableCollectionInsertDropEvent) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Handler that is called when items are dropped "on" an item.
|
|
32
|
+
*/
|
|
33
|
+
onItemDrop?: (e: DroppableCollectionOnItemDropEvent) => void;
|
|
34
|
+
};
|
|
35
|
+
type UseTreeStateOptions<T> = {
|
|
36
|
+
/** Initial root items in the tree. If omitted, will return an empty tree. */
|
|
37
|
+
items: TreeNode<T>[];
|
|
38
|
+
};
|
|
39
|
+
type UseTreeState<T> = {
|
|
40
|
+
nodes: TreeNode<T>[];
|
|
41
|
+
dragAndDropConfig: DragAndDropConfig;
|
|
42
|
+
actions: {
|
|
43
|
+
collapseAll: () => void;
|
|
44
|
+
expandAll: () => void;
|
|
45
|
+
onExpandedChange: (keys: Set<Key>) => void;
|
|
46
|
+
selectAll: () => void;
|
|
47
|
+
unselectAll: () => void;
|
|
48
|
+
onSelectionChange: (keys: Selection) => void;
|
|
49
|
+
hideAll: () => void;
|
|
50
|
+
revealAll: () => void;
|
|
51
|
+
onVisibilityChange: (keys: Set<Key>) => void;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
type TreeData<T> = TreeNode<T>[];
|
|
55
|
+
/**
|
|
56
|
+
* The TreeNode is a wrapper that describes the relationship of this node
|
|
57
|
+
* to other nodes in the tree.
|
|
58
|
+
* TreeNode properties describe the metadata - state and position of the node.
|
|
59
|
+
* The item property represents the action tree item data.
|
|
60
|
+
*/
|
|
61
|
+
type TreeNodeBase<T> = {
|
|
62
|
+
/** A unique key for the tree node. */
|
|
63
|
+
key: Key;
|
|
64
|
+
/** Label string **/
|
|
65
|
+
label: string;
|
|
66
|
+
/** Application specific values in node **/
|
|
67
|
+
values?: T;
|
|
68
|
+
/** Whether node has interactive capability **/
|
|
69
|
+
isDisabled?: boolean;
|
|
70
|
+
/** Whether node children are rendered **/
|
|
71
|
+
isExpanded?: boolean;
|
|
72
|
+
/** Node selection marker **/
|
|
73
|
+
isSelected?: boolean;
|
|
74
|
+
/** Whether node visibility is marked on or off **/
|
|
75
|
+
isVisible?: boolean;
|
|
76
|
+
/** Computed actual visibility based on ancestors and self visibility **/
|
|
77
|
+
isVisibleComputed?: boolean;
|
|
78
|
+
};
|
|
79
|
+
type TreeNode<T> = TreeNodeBase<T> & {
|
|
80
|
+
/** The key of the parent node. */
|
|
81
|
+
parentKey?: Key | null;
|
|
82
|
+
/** Children of the tree node. */
|
|
83
|
+
children?: TreeNode<T>[];
|
|
84
|
+
};
|
|
85
|
+
type UseTreeActionsOptions<T> = {
|
|
86
|
+
nodes: TreeNode<T>[];
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Stateless collection of transform actions to simplify tree operations
|
|
90
|
+
*/
|
|
91
|
+
type TreeActions<T> = {
|
|
92
|
+
/**
|
|
93
|
+
* Retrieves a specific tree node by key
|
|
94
|
+
* If not found, throws error
|
|
95
|
+
*/
|
|
96
|
+
getNode: (key: Key) => TreeNode<T>;
|
|
97
|
+
/**
|
|
98
|
+
* Inserts nodes as children of the target node
|
|
99
|
+
*/
|
|
100
|
+
insertInto: (target: Key | null, nodes: TreeNode<T>[]) => TreeData<T>;
|
|
101
|
+
/**
|
|
102
|
+
* Inserts nodes before the target node
|
|
103
|
+
*/
|
|
104
|
+
insertBefore: (target: Key | null, nodes: TreeNode<T>[]) => TreeData<T>;
|
|
105
|
+
/**
|
|
106
|
+
* Inserts nodes after the target node
|
|
107
|
+
*/
|
|
108
|
+
insertAfter: (target: Key | null, nodes: TreeNode<T>[]) => TreeData<T>;
|
|
109
|
+
/**
|
|
110
|
+
* Removes one or more nodes from the tree by their keys.
|
|
111
|
+
* Does nothing if the key is not found.
|
|
112
|
+
*/
|
|
113
|
+
remove: (keys: Set<Key>) => TreeData<T>;
|
|
114
|
+
/**
|
|
115
|
+
* Updates a specific node using a callback function
|
|
116
|
+
*/
|
|
117
|
+
updateNode: (key: Key, callback: (node: TreeNode<T>) => TreeNode<T>) => TreeData<T>;
|
|
118
|
+
/**
|
|
119
|
+
* Moves nodes as children of the target node
|
|
120
|
+
*/
|
|
121
|
+
moveInto: (target: Key | null, nodes: Set<Key>) => TreeData<T>;
|
|
122
|
+
/**
|
|
123
|
+
* Moves nodes before the target node
|
|
124
|
+
*/
|
|
125
|
+
moveBefore: (target: Key | null, nodes: Set<Key>) => TreeData<T>;
|
|
126
|
+
/**
|
|
127
|
+
* Moves nodes after the target node
|
|
128
|
+
*/
|
|
129
|
+
moveAfter: (target: Key | null, nodes: Set<Key>) => TreeData<T>;
|
|
130
|
+
/**
|
|
131
|
+
* Updates the expansion state of nodes. If a key is not
|
|
132
|
+
* in the set, it is collapsed.
|
|
133
|
+
*/
|
|
134
|
+
onExpandedChange: (keys: Set<Key>) => TreeData<T>;
|
|
135
|
+
/**
|
|
136
|
+
* Expands all nodes in the tree
|
|
137
|
+
*/
|
|
138
|
+
expandAll: () => TreeData<T>;
|
|
139
|
+
/**
|
|
140
|
+
* Collapses all nodes in the tree
|
|
141
|
+
*/
|
|
142
|
+
collapseAll: () => TreeData<T>;
|
|
143
|
+
/**
|
|
144
|
+
* Updates the selection state of nodes. If a key is
|
|
145
|
+
* not in the Set, it is unselected.
|
|
146
|
+
*/
|
|
147
|
+
onSelectionChange: (keys: Set<Key>) => TreeData<T>;
|
|
148
|
+
/**
|
|
149
|
+
* Selects all nodes in the tree
|
|
150
|
+
*/
|
|
151
|
+
selectAll: () => TreeData<T>;
|
|
152
|
+
/**
|
|
153
|
+
* Unselects all nodes in the tree
|
|
154
|
+
*/
|
|
155
|
+
unselectAll: () => TreeData<T>;
|
|
156
|
+
/**
|
|
157
|
+
* Changes visibility of nodes. Updates both isVisible and isViewable properties.
|
|
158
|
+
* If a key is not in the Set, it will be hidden.
|
|
159
|
+
*/
|
|
160
|
+
onVisibilityChange: (keys: Set<Key>) => TreeData<T>;
|
|
161
|
+
/**
|
|
162
|
+
* Makes all nodes visible in the tree
|
|
163
|
+
*/
|
|
164
|
+
revealAll: () => TreeData<T>;
|
|
165
|
+
/**
|
|
166
|
+
* Hides all nodes in the tree
|
|
167
|
+
*/
|
|
168
|
+
hideAll: () => TreeData<T>;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export type { DragAndDropConfig, TreeActions, TreeData, TreeNode, TreeNodeBase, UseTreeActionsOptions, UseTreeState, UseTreeStateOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"types.js"}
|