diff --git a/package-lock.json b/package-lock.json index 545122e..d8c305c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3263,18 +3263,6 @@ "dev": true, "license": "ISC" }, - "node_modules/jiti": { - "version": "1.21.7", - "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.7.tgz", - "integrity": "sha512-/imKNG4EbWNrVjoNC/1H5/9GFy+tqjGBHCaSsN+P2RnPqjsLmv6UD3Ej+Kj8nBWaRAwyk7kK5ZUc+OEatnTR3A==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "bin": { - "jiti": "bin/jiti.js" - } - }, "node_modules/js-yaml": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz", @@ -4240,21 +4228,6 @@ } } }, - "node_modules/svelte-check/node_modules/picomatch": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", - "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/jonschlinkert" - } - }, "node_modules/svelte-check/node_modules/readdirp": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz", @@ -4825,21 +4798,6 @@ "node": ">=10" } }, - "node_modules/yaml": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.1.tgz", - "integrity": "sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw==", - "dev": true, - "license": "ISC", - "optional": true, - "peer": true, - "bin": { - "yaml": "bin.mjs" - }, - "engines": { - "node": ">= 14.6" - } - }, "node_modules/yargs": { "version": "17.7.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", diff --git a/src/lib/components/tree/ConfigTree.svelte b/src/lib/components/tree/ConfigTree.svelte index e3c2536..24fc6c5 100644 --- a/src/lib/components/tree/ConfigTree.svelte +++ b/src/lib/components/tree/ConfigTree.svelte @@ -15,19 +15,16 @@ compatible_config_types, selectClosestMatch, } from "./../../../routes/EditorLayout"; - import { type Config } from "../../schemas"; + import type { Config } from "../../schemas"; import { Tree } from "./ConfigTree"; - import { createEventDispatcher } from "svelte"; + import { createEventDispatcher, tick } from "svelte"; import { parentIframeCommunication } from "../../utils"; import { dragTarget } from "../../actions/drag.action"; import ProfileCloudTreeItem from "./ProfileCloudTreeItem.svelte"; - import { - type AbstractFolderData, - AbstractTreeNode, - TreeItemType, - type ContextMenuOptions, - type TreeProperties, - } from "./TreeNode.svelte"; + import { TreeItemType } from "./TreeNode.svelte"; + import type { AbstractFolderData, AbstractTreeNode } from "./TreeNode.svelte"; + import type { TreeProperties } from "./TreeComponent.svelte"; + import type { ContextMenuOptions } from "@intechstudio/grid-uikit"; import TreeFolder from "./TreeFolder.svelte"; @@ -36,8 +33,11 @@ const dispatch = createEventDispatcher(); export let configs: Config[]; + export let scrollToSelectionTrigger = 0; let treeProps: TreeProperties; + let treeRoot: Tree.Node; + let filteredConfigs: Config[] = []; export function debounced(store: Writable, delay = 300) { let timeout: ReturnType; @@ -56,7 +56,7 @@ export const debounced_filter_value = debounced(filter_value, 300); $: { - treeProps = buildProps( + const tree = buildTree( configs, $debounced_filter_value, $sort_key, @@ -64,6 +64,23 @@ $hide_community_configs, $compatible_config_types, ); + treeRoot = tree.root; + filteredConfigs = tree.filteredConfigs; + } + + $: if (treeRoot) { + selectClosestMatch($selected_config, filteredConfigs); + const selected = get(selected_config); + treeProps = { + root: treeRoot, + selected: selected?.id, + expanded: treeRoot.getIncludingNodes(selected?.id), + scrollBehaviour: { + scrollToIndex: scrollToSelectionTrigger > 0, + scrollTrigger: scrollToSelectionTrigger, + easing: "smooth", + }, + }; } function filterNode(node: Tree.Node, filter: FilterValue, level = 0) { @@ -112,14 +129,14 @@ }); } - function buildProps( + function buildTree( configs: Config[], filter: FilterValue, key: Sort.Key, supported: boolean, community: boolean, compatibileTypes: string[], - ): TreeProperties { + ) { const filteredConfigs = configs.filter((e) => matches(e, filter)); const root = Tree.create(configs, { showSupportedOnly: supported, @@ -129,14 +146,7 @@ filterNode(root, filter); - selectClosestMatch($selected_config, filteredConfigs); - - return { - root: root, - selected: $selected_config?.id, - expanded: root.getIncludingNodes($selected_config?.id), - scrollBehaviour: { scrollToIndex: true, easing: "instant" }, - }; + return { root, filteredConfigs }; } function handleDeleteVirtualDirectory(title: string) { diff --git a/src/lib/components/tree/ConfigTree.ts b/src/lib/components/tree/ConfigTree.ts index a51b18e..f9e1d87 100644 --- a/src/lib/components/tree/ConfigTree.ts +++ b/src/lib/components/tree/ConfigTree.ts @@ -4,7 +4,7 @@ import { config_manager, compatible_config_types, } from "./../../../routes/EditorLayout"; -import { type Config } from "../../schemas"; +import type { Config } from "../../schemas"; import { filter_value } from "../../../routes/Filter"; import { Sort } from "../../../routes/Sorter"; @@ -22,6 +22,7 @@ import { ElementType, grid, ModuleType } from "@intechstudio/grid-protocol"; export namespace Tree { export interface Options { showSupportedOnly?: boolean; + hideCommunityConfigs?: boolean; compatibileTypes: string[]; } @@ -287,7 +288,7 @@ export namespace Tree { e.owner ?? "", ); - const cct = get(compatible_config_types); + const cct = get(compatible_config_types) as string[]; return ( !isMyConfig && @@ -311,7 +312,7 @@ export namespace Tree { const isOfficialConfig = configuration.WORKFLOW_CONFIG_PROFILE_IDS.includes(e.owner ?? ""); - const cct = get(compatible_config_types); + const cct = get(compatible_config_types) as string[]; return ( !isMyConfig && @@ -336,7 +337,7 @@ export namespace Tree { configuration.RECOMMENDED_CONFIG_PROFILE_IDS.includes( e.owner ?? "", ); - const cct = get(compatible_config_types); + const cct = get(compatible_config_types) as string[]; return ( !isMyConfig && !isOfficialConfig && @@ -356,7 +357,7 @@ export namespace Tree { .filter((e: Config) => { const isMyConfig = e.syncStatus == "local" || e.owner === cm?.getCurrentOwnerId(); - const cct = get(compatible_config_types); + const cct = get(compatible_config_types) as string[]; return !isMyConfig && (!showSupportedOnly || cct.includes(e.type)); }) .map( @@ -372,7 +373,7 @@ export namespace Tree { .filter((e: Config) => { const isMyConfig = e.syncStatus == "local" || e.owner === cm?.getCurrentOwnerId(); - const cct = get(compatible_config_types); + const cct = get(compatible_config_types) as string[]; return !isMyConfig && showSupportedOnly && !cct.includes(e.type); }) diff --git a/src/lib/components/tree/TreeComponent.svelte b/src/lib/components/tree/TreeComponent.svelte index b786a79..d6a4bd9 100644 --- a/src/lib/components/tree/TreeComponent.svelte +++ b/src/lib/components/tree/TreeComponent.svelte @@ -2,6 +2,7 @@ export interface TreeScrollBehaviour { scrollToIndex?: boolean; easing?: "smooth" | "instant"; + scrollTrigger?: number; } export interface TreeProperties { @@ -13,10 +14,12 @@ -{#key tree} -
    - - - - +
      + + + + - - - - -
    -{/key} + + + +
    +