-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd46ec1
commit 58cb97c
Showing
41 changed files
with
7,964 additions
and
4,907 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use client' | ||
|
||
import { useEffect } from 'react' | ||
|
||
import { cn } from '@/lib/utils' | ||
import { isClapEntity } from '@/components/tree-browsers/utils/isSomething' | ||
import { TreeNodeItem, LibraryNodeType } from '@/components/tree-browsers/types' | ||
import { Tree } from '@/components/core/tree' | ||
|
||
import { useFilterTree } from './useFilterTree' | ||
import { useFilterEditor } from '@/services/editors/filter-editor/useFilterEditor' | ||
|
||
export function FilterTree({ | ||
className = '', | ||
}: { | ||
className?: string | ||
} = {}) { | ||
const libraryTreeRoot = useFilterTree((s) => s.libraryTreeRoot) | ||
const selectTreeNode = useFilterTree((s) => s.selectTreeNode) | ||
const selectedTreeNodeId = useFilterTree((s) => s.selectedTreeNodeId) | ||
const setAvailableFilters = useFilterTree((s) => s.setAvailableFilters) | ||
|
||
const availableFilters = useFilterEditor((s) => s.availableFilters) | ||
const activeFilters = useFilterEditor((s) => s.activeFilters) | ||
const current = useFilterEditor((s) => s.current) | ||
|
||
useEffect(() => { | ||
console.log('TODO: populate the filter tree') | ||
}, [availableFilters.map((f) => f.id).join(',')]) | ||
/** | ||
* handle click on tree node | ||
* yes, this is where the magic happens! | ||
* | ||
* @param id | ||
* @param nodeType | ||
* @param node | ||
* @returns | ||
*/ | ||
const handleOnChange = async ( | ||
id: string | null, | ||
nodeType?: LibraryNodeType, | ||
nodeItem?: TreeNodeItem | ||
) => { | ||
console.log(`calling selectTreeNodeById(id)`) | ||
selectTreeNode(id, nodeType, nodeItem) | ||
|
||
if (!nodeType || !nodeItem) { | ||
console.log('tree-browser: clicked on an undefined node') | ||
return | ||
} | ||
if (isClapEntity(nodeType, nodeItem)) { | ||
// ClapEntity | ||
} else { | ||
console.log( | ||
`tree-browser: no action attached to ${nodeType}, so skipping` | ||
) | ||
return | ||
} | ||
console.log(`tree-browser: clicked on a ${nodeType}`, nodeItem) | ||
} | ||
|
||
return ( | ||
<Tree.Root<LibraryNodeType, TreeNodeItem> | ||
value={selectedTreeNodeId} | ||
onChange={handleOnChange} | ||
className={cn(`not-prose h-full w-full px-2 pt-2`, className)} | ||
label="Filters" | ||
> | ||
{libraryTreeRoot.map((node) => ( | ||
<Tree.Node node={node} key={node.id} /> | ||
))} | ||
</Tree.Root> | ||
) | ||
} |
147 changes: 147 additions & 0 deletions
147
src/components/editors/FilterEditor/FilterTree/useFilterTree.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
'use client' | ||
|
||
import { create } from 'zustand' | ||
import { ClapEntity, UUID } from '@aitube/clap' | ||
import { Filter } from '@aitube/clapper-services' | ||
|
||
import { | ||
LibraryTreeNode, | ||
TreeNodeItem, | ||
LibraryNodeType, | ||
} from '@/components/tree-browsers/types' | ||
import { icons } from '@/components/icons' | ||
import { | ||
collectionClassName, | ||
libraryClassName, | ||
} from '@/components/tree-browsers/style/treeNodeStyles' | ||
|
||
export const useFilterTree = create<{ | ||
availableFiltersLibraryTreeNodeId: string | ||
|
||
// activeFiltersLibraryTreeNodeId: string | ||
|
||
libraryTreeRoot: LibraryTreeNode[] | ||
init: () => void | ||
|
||
/** | ||
* Load available filters into the tree | ||
* | ||
* @param collections | ||
* @returns | ||
*/ | ||
setAvailableFilters: (filters: Filter[]) => void | ||
|
||
// we support those all selection modes for convenience - please keep them! | ||
selectedNodeItem?: TreeNodeItem | ||
selectedNodeType?: LibraryNodeType | ||
selectTreeNode: ( | ||
treeNodeId?: string | null, | ||
nodeType?: LibraryNodeType, | ||
nodeItem?: TreeNodeItem | ||
) => void | ||
selectedTreeNodeId: string | null | ||
}>((set, get) => ({ | ||
availableFiltersLibraryTreeNodeId: '', | ||
|
||
// activeFiltersLibraryTreeNodeId: '', | ||
|
||
libraryTreeRoot: [], | ||
init: () => { | ||
const availableFilterLibrary: LibraryTreeNode = { | ||
id: UUID(), | ||
nodeType: 'TREE_ROOT_PROJECT', | ||
label: 'Available filters', | ||
icon: icons.project, | ||
className: libraryClassName, | ||
isExpanded: true, | ||
children: [ | ||
{ | ||
id: UUID(), | ||
nodeType: 'DEFAULT_TREE_NODE_EMPTY', | ||
label: 'Empty', | ||
icon: icons.project, | ||
className: collectionClassName, | ||
}, | ||
], | ||
} | ||
|
||
const libraryTreeRoot = [availableFilterLibrary] | ||
|
||
set({ | ||
availableFiltersLibraryTreeNodeId: availableFilterLibrary.id, | ||
libraryTreeRoot, | ||
selectedNodeItem: undefined, | ||
selectedTreeNodeId: null, | ||
}) | ||
}, | ||
|
||
setAvailableFilters: (filters: Filter[]) => { | ||
const availableFilterLibrary: LibraryTreeNode = { | ||
id: UUID(), | ||
nodeType: 'TREE_ROOT_PROJECT', | ||
label: 'Filters', | ||
icon: icons.project, | ||
className: libraryClassName, | ||
isExpanded: true, | ||
children: [ | ||
{ | ||
id: UUID(), | ||
nodeType: 'DEFAULT_TREE_NODE_EMPTY', | ||
label: 'Empty', | ||
icon: icons.project, | ||
className: collectionClassName, | ||
}, | ||
], | ||
} | ||
|
||
const libraryTreeRoot = [availableFilterLibrary] | ||
|
||
set({ | ||
availableFiltersLibraryTreeNodeId: availableFilterLibrary.id, | ||
libraryTreeRoot, | ||
selectedNodeItem: undefined, | ||
selectedTreeNodeId: null, | ||
}) | ||
}, | ||
|
||
/* | ||
setCommunityCollections: (collections: CommunityEntityCollection[]) => { | ||
// TODO: implement this | ||
}, | ||
*/ | ||
|
||
selectedNodeItem: undefined, | ||
selectEntity: (entity?: ClapEntity) => { | ||
if (entity) { | ||
console.log( | ||
'TODO julian: change this code to search in the entity collections' | ||
) | ||
const selectedTreeNode = get().libraryTreeRoot.find( | ||
(node) => node.data?.id === entity.id | ||
) | ||
|
||
// set({ selectedTreeNode }) | ||
set({ selectedTreeNodeId: selectedTreeNode?.id || null }) | ||
set({ selectedNodeItem: entity }) | ||
} else { | ||
// set({ selectedTreeNode: undefined }) | ||
set({ selectedTreeNodeId: null }) | ||
set({ selectedNodeItem: undefined }) | ||
} | ||
}, | ||
|
||
// selectedTreeNode: undefined, | ||
selectedTreeNodeId: null, | ||
selectTreeNode: ( | ||
treeNodeId?: string | null, | ||
nodeType?: LibraryNodeType, | ||
nodeItem?: TreeNodeItem | ||
) => { | ||
set({ selectedTreeNodeId: treeNodeId ? treeNodeId : undefined }) | ||
set({ selectedNodeType: nodeType ? nodeType : undefined }) | ||
set({ selectedNodeItem: nodeItem ? nodeItem : undefined }) | ||
}, | ||
})) | ||
|
||
useFilterTree.getState().init() |
33 changes: 33 additions & 0 deletions
33
src/components/editors/FilterEditor/FilterViewer/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { FormSection } from '@/components/forms' | ||
import { useFilterEditor, useUI } from '@/services' | ||
|
||
export function FilterViewer() { | ||
const current = useFilterEditor((s) => s.current) | ||
const setCurrent = useFilterEditor((s) => s.setCurrent) | ||
const undo = useFilterEditor((s) => s.undo) | ||
const redo = useFilterEditor((s) => s.redo) | ||
|
||
const hasBetaAccess = useUI((s) => s.hasBetaAccess) | ||
|
||
if (!hasBetaAccess) { | ||
return ( | ||
<FormSection label={'Filter Editor'} className="p-4"> | ||
Storyboard filters are WIP and not available yet. | ||
</FormSection> | ||
) | ||
} | ||
|
||
if (!current) { | ||
return ( | ||
<FormSection label={'Filter Editor'} className="p-4"> | ||
No filter selected. | ||
</FormSection> | ||
) | ||
} | ||
|
||
return ( | ||
<FormSection label={'Filter Editor'} className="p-4"> | ||
<p>Put filter parameters</p> | ||
</FormSection> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ReflexContainer, ReflexElement, ReflexSplitter } from 'react-reflex' | ||
import { FilterTree } from './FilterTree' | ||
import { FilterViewer } from './FilterViewer' | ||
|
||
export function FilterEditor() { | ||
return ( | ||
<ReflexContainer orientation="vertical"> | ||
<ReflexElement minSize={70} size={200}> | ||
<FilterTree /> | ||
</ReflexElement> | ||
<ReflexSplitter /> | ||
<ReflexElement minSize={70}> | ||
<FilterViewer /> | ||
</ReflexElement> | ||
</ReflexContainer> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.