@itwin/presentation-hierarchies-react 2.0.0-alpha.49 → 2.0.0-alpha.50
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/CHANGELOG.md +23 -0
- package/README.md +1 -3
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts +2 -2
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/Renderers.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts +3 -3
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/TreeNode.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts +2 -2
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts +9 -7
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js +6 -14
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +2 -2
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js +5 -5
- package/lib/esm/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts +9 -8
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +9 -10
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts +8 -20
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js +8 -27
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +5 -22
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +7 -10
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts +2 -2
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts +8 -8
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +2 -2
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +11 -11
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js +86 -68
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react.d.ts +2 -3
- package/lib/esm/presentation-hierarchies-react.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react.js +1 -2
- package/lib/esm/presentation-hierarchies-react.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,wBAAwB,CAAC;AAEhC,OAAO,EACL,YAAY,EAGZ,UAAU,EACV,cAAc,EACd,IAAI,EAIJ,WAAW,EACX,SAAS,EACT,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,YAAY,MAAM,gCAAgC,CAAC;AAC1D,OAAO,UAAU,MAAM,8BAA8B,CAAC;AACtD,OAAO,UAAU,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,gBAAgB,IAAI,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAGxF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,cAAc,EAA4B,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAuCrE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAyE,IAAI,CACjH,UAAU,CAAqC,SAAS,aAAa,CAAC,KAAK,EAAE,YAAY;IACvF,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,aAAa,EAAE,GAAG,KAAK,CAAC;IAC9H,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACtD,MAAM,aAAa,GAA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EAAE,CAAC;gCACtB,CAAC;4BACH,CAAC,GACD,GACW,EACf,KAAC,UAAU,IAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAI,EAC5F,KAAC,UAAU,IAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,CAAC,SAAS,GAAI,IACjH,EACL,mBAAmB,KAAK,SAAS,CAAC,CAAC,CAAC,CACnC,KAAC,WAAW,IAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,YAC3F,KAAC,IAAI,IAAC,OAAO,EAAC,YAAY,YAAE,mBAAmB,GAAQ,GAC3C,CACf,CAAC,CAAC,CAAC,SAAS,KA3BL,YAAY,CA4BhB,CACP,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAoB,EAAE,OAA4C;IAC7F,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAA2B,MAAM,CAAC,CAAC;SACpE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAA2B,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;AAClF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport \"./TreeNodeRenderer.css\";\n\nimport {\n cloneElement,\n ComponentPropsWithoutRef,\n FC,\n forwardRef,\n isValidElement,\n memo,\n PropsWithRef,\n ReactNode,\n RefAttributes,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { Description, IconButton, Spinner, Text, TextBox } from \"@stratakit/bricks\";\nimport checkmarkSvg from \"@stratakit/icons/checkmark.svg\";\nimport dismissSvg from \"@stratakit/icons/dismiss.svg\";\nimport refreshSvg from \"@stratakit/icons/refresh.svg\";\nimport { DropdownMenu, unstable_Popover as Popover, Tree } from \"@stratakit/structures\";\nimport { TreeRendererProps } from \"../Renderers.js\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { TreeActionBase, TreeActionBaseAttributes } from \"./TreeAction.js\";\nimport { useTreeNodeRenameContext } from \"./TreeNodeRenameAction.js\";\n\n/** @internal */\ninterface TreeNodeRendererOwnProps extends Pick<TreeRendererProps, \"expandNode\" | \"reloadTree\"> {\n /** Node that is rendered. */\n node: PresentationHierarchyNode;\n /**\n * Menu actions for tree item.\n * Must be an array of `<TreeActionBase />` or `<Divider />` elements.\n */\n menuActions?: ReactNode[];\n /**\n * Inline actions for tree item.\n * Must be an array of `<TreeActionBase />` elements.\n * Max 2 items.\n */\n inlineActions?: ReactNode[];\n /**\n * Context menu actions for tree item.\n * Must be an array of `<TreeActionBase />` or `<Divider />` elements.\n */\n contextMenuActions?: ReactNode[];\n}\n\n/** @alpha */\nexport type StrataKitTreeItemProps = Omit<\n ComponentPropsWithoutRef<typeof Tree.Item>,\n \"actions\" | \"inlineActions\" | \"expanded\" | \"onExpandedChange\" | \"icon\" | \"unstable_decorations\" | \"error\"\n> & {\n /**\n * Used to render elements between expander and label.\n * E.g. icons, color picker, etc.\n */\n decorations?: ReactNode;\n};\n\n/** @internal */\nexport type TreeNodeRendererProps = StrataKitTreeItemProps & TreeNodeRendererOwnProps;\n\n/**\n * A component that renders given `FlatTreeNode` using the `Tree.Item` component from `@itwin/itwinui-react`. The\n * `FlatTreeNode` objects for this renderer are generally created using the `useFlatTreeNodeList` hook.\n *\n * @internal\n */\nexport const StrataKitTreeNodeRenderer: FC<PropsWithRef<TreeNodeRendererProps & RefAttributes<HTMLElement>>> = memo(\n forwardRef<HTMLElement, TreeNodeRendererProps>(function HierarchyNode(props, forwardedRef) {\n const { node, decorations, inlineActions, menuActions, contextMenuActions, expandNode, reloadTree, ...treeItemProps } = props;\n const { localizedStrings } = useLocalizationContext();\n const renameContext = useTreeNodeRenameContext();\n const [contextMenuProps, setContextMenuProps] = useState<{ position: { x: number; y: number }; actions: ReactNode[] } | undefined>(undefined);\n\n const label = treeItemProps.label ?? node.label;\n const inlineActionItems = useMemo(() => {\n if (node.error !== undefined && node.error.type === \"ChildrenLoad\") {\n return [\n <TreeActionBase\n key=\"retry\"\n label={localizedStrings.retry}\n onClick={() => reloadTree({ parentNodeId: node.id, state: \"reset\" })}\n visible={true}\n icon={refreshSvg}\n variant=\"inline\"\n />,\n ];\n }\n if (!inlineActions) {\n return undefined;\n }\n return injectActionVariant(inlineActions, \"inline\");\n }, [node, inlineActions, localizedStrings.retry, reloadTree]);\n\n const menuActionItems = useMemo(() => {\n if (!menuActions) {\n return undefined;\n }\n return injectActionVariant(menuActions, \"default\");\n }, [menuActions]);\n\n const expanded = useMemo(() => {\n if (node.error) {\n return undefined;\n }\n\n if (node.isExpanded || node.children === true || node.children.length > 0) {\n return node.isExpanded;\n }\n\n return undefined;\n }, [node.children, node.error, node.isExpanded]);\n\n const { renameParameters, cancelRename } = renameContext ?? {};\n const labelEditor = (\n <LabelEditor\n initialLabel={node.label}\n onChange={renameParameters?.commit}\n onCancel={cancelRename}\n labelValidationHint={renameParameters?.labelValidationHint}\n validate={renameParameters?.validate}\n />\n );\n\n return (\n <>\n <Popover content={labelEditor} placement=\"bottom\" open={renameParameters?.nodeId === node.id} setOpen={cancelRename} unmountOnHide>\n <Tree.Item\n {...treeItemProps}\n ref={forwardedRef}\n label={label}\n expanded={expanded}\n onExpandedChange={useCallback(\n (isExpanded: boolean) => {\n expandNode(node.id, isExpanded);\n },\n [node, expandNode],\n )}\n inlineActions={inlineActionItems}\n actions={menuActionItems}\n unstable_decorations={decorations}\n error={node.error ? node.error.id : undefined}\n onContextMenu={(e) => {\n if (treeItemProps.onContextMenu) {\n treeItemProps.onContextMenu(e);\n }\n\n if (!contextMenuActions) {\n return;\n }\n\n e.preventDefault();\n const actions = injectActionVariant(contextMenuActions, \"context-menu\");\n if (actions.length === 0) {\n return;\n }\n\n setContextMenuProps({\n position: {\n x: e.clientX,\n y: e.clientY,\n },\n actions,\n });\n }}\n />\n </Popover>\n <DropdownMenu.Provider\n open={contextMenuProps !== undefined}\n setOpen={(open) => {\n if (!open) {\n setContextMenuProps(undefined);\n }\n }}\n key={`${node.id}-${contextMenuProps?.position.x ?? \"\"}-${contextMenuProps?.position.y ?? \"\"}`}\n >\n {contextMenuProps ? (\n <DropdownMenu.Button style={{ position: \"fixed\", top: contextMenuProps.position.y, left: contextMenuProps.position.x }} render={<div />} />\n ) : null}\n {/* `autoFocus` prop is coming from ariakit and is not native HTML `autoFocus` prop. */}\n {/* `focusable` is needed for `autoFocus` to work. StrataKit exposes only `autoFocus` and does not set `focusable` internally. */}\n {/* eslint-disable jsx-a11y/no-autofocus */}\n {/* @ts-expect-error focusable is passed through */}\n <DropdownMenu.Content focusable autoFocus={true}>\n {contextMenuProps?.actions}\n </DropdownMenu.Content>\n </DropdownMenu.Provider>\n </>\n );\n }),\n);\n\nexport const PlaceholderNode: FC<\n PropsWithRef<Pick<StrataKitTreeItemProps, \"style\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\"> & RefAttributes<HTMLElement>>\n> = memo(\n forwardRef<HTMLElement, Pick<StrataKitTreeItemProps, \"style\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\">>(function PlaceholderNode(\n { ...props },\n forwardedRef,\n ) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <Tree.Item\n {...props}\n ref={forwardedRef}\n label={localizedStrings.loading}\n unstable_decorations={<Spinner size={\"small\"} title={localizedStrings.loading} />}\n />\n );\n }),\n);\n\nfunction LabelEditor({\n initialLabel,\n labelValidationHint,\n onChange,\n onCancel,\n validate,\n}: {\n initialLabel: string;\n labelValidationHint?: string;\n onChange?: (newLabel: string) => void;\n onCancel?: () => void;\n validate?: (newLabel: string) => boolean;\n}) {\n const { localizedStrings } = useLocalizationContext();\n const inputRef = useRef<HTMLInputElement>(null);\n const [newLabelValue, setNewLabelValue] = useState(initialLabel);\n const [hasError, setHasError] = useState<boolean>(false);\n const handleLabelChange = () => {\n if (validate && !validate(newLabelValue)) {\n setHasError(true);\n return;\n }\n\n if (initialLabel !== newLabelValue) {\n onChange?.(newLabelValue);\n return;\n }\n onCancel?.();\n };\n\n const cancelLabelChange = () => {\n setNewLabelValue(initialLabel);\n onCancel?.();\n };\n\n useEffect(() => {\n if (inputRef.current) {\n inputRef.current.focus();\n inputRef.current.select();\n }\n }, []);\n\n const canRename = newLabelValue && newLabelValue !== initialLabel && !hasError;\n const inputId = useId();\n\n return (\n <div key={initialLabel} className=\"phr-node-label-editor\">\n <div className=\"phr-node-label-editor-input-row\">\n <TextBox.Root style={{ width: \"100%\" }} className={hasError ? \"with-error\" : undefined}>\n <TextBox.Input\n id={inputId}\n ref={inputRef}\n value={newLabelValue}\n onChange={(event) => {\n setNewLabelValue(event.target.value);\n setHasError(false);\n }}\n onKeyDown={(event) => {\n if (event.key === \"Enter\") {\n handleLabelChange();\n } else if (event.key === \"Escape\") {\n cancelLabelChange();\n }\n }}\n />\n </TextBox.Root>\n <IconButton icon={dismissSvg} label={localizedStrings.cancel} onClick={cancelLabelChange} />\n <IconButton icon={checkmarkSvg} label={localizedStrings.confirm} onClick={handleLabelChange} disabled={!canRename} />\n </div>\n {labelValidationHint !== undefined ? (\n <Description id={inputId} tone={hasError ? \"critical\" : \"neutral\"} style={{ display: \"flex\" }}>\n <Text variant=\"caption-lg\">{labelValidationHint}</Text>\n </Description>\n ) : undefined}\n </div>\n );\n}\n\nfunction injectActionVariant(actions: ReactNode[], variant: TreeActionBaseAttributes[\"variant\"]) {\n return actions\n .filter((action) => isValidElement<TreeActionBaseAttributes>(action))\n .map((action) => cloneElement<TreeActionBaseAttributes>(action, { variant }));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,wBAAwB,CAAC;AAEhC,OAAO,EACL,YAAY,EAGZ,UAAU,EACV,cAAc,EACd,IAAI,EAIJ,WAAW,EACX,SAAS,EACT,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,YAAY,MAAM,gCAAgC,CAAC;AAC1D,OAAO,UAAU,MAAM,8BAA8B,CAAC;AACtD,OAAO,UAAU,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,gBAAgB,IAAI,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAGxF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,cAAc,EAA4B,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAuCrE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAyE,IAAI,CACjH,UAAU,CAAqC,SAAS,aAAa,CAAC,KAAK,EAAE,YAAY;IACvF,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,aAAa,EAAE,GAAG,KAAK,CAAC;IAC9H,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACtD,MAAM,aAAa,GAAG,wBAAwB,EAAE,CAAC;IACjD,MAAM,CAAC,gBAAgB,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f,KAAC,UAAU,IAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAI,EAC5F,KAAC,UAAU,IAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,CAAC,SAAS,GAAI,IACjH,EACL,mBAAmB,KAAK,SAAS,CAAC,CAAC,CAAC,CACnC,KAAC,WAAW,IAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,YAC3F,KAAC,IAAI,IAAC,OAAO,EAAC,YAAY,YAAE,mBAAmB,GAAQ,GAC3C,CACf,CAAC,CAAC,CAAC,SAAS,KA3BL,YAAY,CA4BhB,CACP,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAoB,EAAE,OAA4C;IAC7F,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAA2B,MAAM,CAAC,CAAC;SACpE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAA2B,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;AAClF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport \"./TreeNodeRenderer.css\";\n\nimport {\n cloneElement,\n ComponentPropsWithoutRef,\n FC,\n forwardRef,\n isValidElement,\n memo,\n PropsWithRef,\n ReactNode,\n RefAttributes,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { Description, IconButton, Spinner, Text, TextBox } from \"@stratakit/bricks\";\nimport checkmarkSvg from \"@stratakit/icons/checkmark.svg\";\nimport dismissSvg from \"@stratakit/icons/dismiss.svg\";\nimport refreshSvg from \"@stratakit/icons/refresh.svg\";\nimport { DropdownMenu, unstable_Popover as Popover, Tree } from \"@stratakit/structures\";\nimport { TreeRendererProps } from \"../Renderers.js\";\nimport { TreeNode } from \"../TreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { TreeActionBase, TreeActionBaseAttributes } from \"./TreeAction.js\";\nimport { useTreeNodeRenameContext } from \"./TreeNodeRenameAction.js\";\n\n/** @internal */\ninterface TreeNodeRendererOwnProps extends Pick<TreeRendererProps, \"expandNode\" | \"reloadTree\"> {\n /** Node that is rendered. */\n node: TreeNode;\n /**\n * Menu actions for tree item.\n * Must be an array of `<TreeActionBase />` or `<Divider />` elements.\n */\n menuActions?: ReactNode[];\n /**\n * Inline actions for tree item.\n * Must be an array of `<TreeActionBase />` elements.\n * Max 2 items.\n */\n inlineActions?: ReactNode[];\n /**\n * Context menu actions for tree item.\n * Must be an array of `<TreeActionBase />` or `<Divider />` elements.\n */\n contextMenuActions?: ReactNode[];\n}\n\n/** @alpha */\nexport type StrataKitTreeItemProps = Omit<\n ComponentPropsWithoutRef<typeof Tree.Item>,\n \"actions\" | \"inlineActions\" | \"expanded\" | \"onExpandedChange\" | \"icon\" | \"unstable_decorations\" | \"error\"\n> & {\n /**\n * Used to render elements between expander and label.\n * E.g. icons, color picker, etc.\n */\n decorations?: ReactNode;\n};\n\n/** @internal */\nexport type TreeNodeRendererProps = StrataKitTreeItemProps & TreeNodeRendererOwnProps;\n\n/**\n * A component that renders given `FlatTreeNode` using the `Tree.Item` component from `@itwin/itwinui-react`. The\n * `FlatTreeNode` objects for this renderer are generally created using the `useFlatTreeNodeList` hook.\n *\n * @internal\n */\nexport const StrataKitTreeNodeRenderer: FC<PropsWithRef<TreeNodeRendererProps & RefAttributes<HTMLElement>>> = memo(\n forwardRef<HTMLElement, TreeNodeRendererProps>(function HierarchyNode(props, forwardedRef) {\n const { node, decorations, inlineActions, menuActions, contextMenuActions, expandNode, reloadTree, ...treeItemProps } = props;\n const { localizedStrings } = useLocalizationContext();\n const renameContext = useTreeNodeRenameContext();\n const [contextMenuProps, setContextMenuProps] = useState<{ position: { x: number; y: number }; actions: ReactNode[] } | undefined>(undefined);\n\n const label = treeItemProps.label ?? node.label;\n const inlineActionItems = useMemo(() => {\n if (node.error !== undefined && node.error.type === \"ChildrenLoad\") {\n return [\n <TreeActionBase\n key=\"retry\"\n label={localizedStrings.retry}\n onClick={() => reloadTree({ parentNodeId: node.id, state: \"reset\" })}\n visible={true}\n icon={refreshSvg}\n variant=\"inline\"\n />,\n ];\n }\n if (!inlineActions) {\n return undefined;\n }\n return injectActionVariant(inlineActions, \"inline\");\n }, [node, inlineActions, localizedStrings.retry, reloadTree]);\n\n const menuActionItems = useMemo(() => {\n if (!menuActions) {\n return undefined;\n }\n return injectActionVariant(menuActions, \"default\");\n }, [menuActions]);\n\n const expanded = useMemo(() => {\n if (node.error) {\n return undefined;\n }\n\n if (node.isExpanded || node.children === true || node.children.length > 0) {\n return node.isExpanded;\n }\n\n return undefined;\n }, [node.children, node.error, node.isExpanded]);\n\n const { renameParameters, cancelRename } = renameContext ?? {};\n const labelEditor = (\n <LabelEditor\n initialLabel={node.label}\n onChange={renameParameters?.commit}\n onCancel={cancelRename}\n labelValidationHint={renameParameters?.labelValidationHint}\n validate={renameParameters?.validate}\n />\n );\n\n return (\n <>\n <Popover content={labelEditor} placement=\"bottom\" open={renameParameters?.nodeId === node.id} setOpen={cancelRename} unmountOnHide>\n <Tree.Item\n {...treeItemProps}\n ref={forwardedRef}\n label={label}\n expanded={expanded}\n onExpandedChange={useCallback(\n (isExpanded: boolean) => {\n expandNode(node.id, isExpanded);\n },\n [node, expandNode],\n )}\n inlineActions={inlineActionItems}\n actions={menuActionItems}\n unstable_decorations={decorations}\n error={node.error ? node.error.id : undefined}\n onContextMenu={(e) => {\n if (treeItemProps.onContextMenu) {\n treeItemProps.onContextMenu(e);\n }\n\n if (!contextMenuActions) {\n return;\n }\n\n e.preventDefault();\n const actions = injectActionVariant(contextMenuActions, \"context-menu\");\n if (actions.length === 0) {\n return;\n }\n\n setContextMenuProps({\n position: {\n x: e.clientX,\n y: e.clientY,\n },\n actions,\n });\n }}\n />\n </Popover>\n <DropdownMenu.Provider\n open={contextMenuProps !== undefined}\n setOpen={(open) => {\n if (!open) {\n setContextMenuProps(undefined);\n }\n }}\n key={`${node.id}-${contextMenuProps?.position.x ?? \"\"}-${contextMenuProps?.position.y ?? \"\"}`}\n >\n {contextMenuProps ? (\n <DropdownMenu.Button style={{ position: \"fixed\", top: contextMenuProps.position.y, left: contextMenuProps.position.x }} render={<div />} />\n ) : null}\n {/* `autoFocus` prop is coming from ariakit and is not native HTML `autoFocus` prop. */}\n {/* `focusable` is needed for `autoFocus` to work. StrataKit exposes only `autoFocus` and does not set `focusable` internally. */}\n {/* eslint-disable jsx-a11y/no-autofocus */}\n {/* @ts-expect-error focusable is passed through */}\n <DropdownMenu.Content focusable autoFocus={true}>\n {contextMenuProps?.actions}\n </DropdownMenu.Content>\n </DropdownMenu.Provider>\n </>\n );\n }),\n);\n\nexport const PlaceholderNode: FC<\n PropsWithRef<Pick<StrataKitTreeItemProps, \"style\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\"> & RefAttributes<HTMLElement>>\n> = memo(\n forwardRef<HTMLElement, Pick<StrataKitTreeItemProps, \"style\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\">>(function PlaceholderNode(\n { ...props },\n forwardedRef,\n ) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <Tree.Item\n {...props}\n ref={forwardedRef}\n label={localizedStrings.loading}\n unstable_decorations={<Spinner size={\"small\"} title={localizedStrings.loading} />}\n />\n );\n }),\n);\n\nfunction LabelEditor({\n initialLabel,\n labelValidationHint,\n onChange,\n onCancel,\n validate,\n}: {\n initialLabel: string;\n labelValidationHint?: string;\n onChange?: (newLabel: string) => void;\n onCancel?: () => void;\n validate?: (newLabel: string) => boolean;\n}) {\n const { localizedStrings } = useLocalizationContext();\n const inputRef = useRef<HTMLInputElement>(null);\n const [newLabelValue, setNewLabelValue] = useState(initialLabel);\n const [hasError, setHasError] = useState<boolean>(false);\n const handleLabelChange = () => {\n if (validate && !validate(newLabelValue)) {\n setHasError(true);\n return;\n }\n\n if (initialLabel !== newLabelValue) {\n onChange?.(newLabelValue);\n return;\n }\n onCancel?.();\n };\n\n const cancelLabelChange = () => {\n setNewLabelValue(initialLabel);\n onCancel?.();\n };\n\n useEffect(() => {\n if (inputRef.current) {\n inputRef.current.focus();\n inputRef.current.select();\n }\n }, []);\n\n const canRename = newLabelValue && newLabelValue !== initialLabel && !hasError;\n const inputId = useId();\n\n return (\n <div key={initialLabel} className=\"phr-node-label-editor\">\n <div className=\"phr-node-label-editor-input-row\">\n <TextBox.Root style={{ width: \"100%\" }} className={hasError ? \"with-error\" : undefined}>\n <TextBox.Input\n id={inputId}\n ref={inputRef}\n value={newLabelValue}\n onChange={(event) => {\n setNewLabelValue(event.target.value);\n setHasError(false);\n }}\n onKeyDown={(event) => {\n if (event.key === \"Enter\") {\n handleLabelChange();\n } else if (event.key === \"Escape\") {\n cancelLabelChange();\n }\n }}\n />\n </TextBox.Root>\n <IconButton icon={dismissSvg} label={localizedStrings.cancel} onClick={cancelLabelChange} />\n <IconButton icon={checkmarkSvg} label={localizedStrings.confirm} onClick={handleLabelChange} disabled={!canRename} />\n </div>\n {labelValidationHint !== undefined ? (\n <Description id={inputId} tone={hasError ? \"critical\" : \"neutral\"} style={{ display: \"flex\" }}>\n <Text variant=\"caption-lg\">{labelValidationHint}</Text>\n </Description>\n ) : undefined}\n </div>\n );\n}\n\nfunction injectActionVariant(actions: ReactNode[], variant: TreeActionBaseAttributes[\"variant\"]) {\n return actions\n .filter((action) => isValidElement<TreeActionBaseAttributes>(action))\n .map((action) => cloneElement<TreeActionBaseAttributes>(action, { variant }));\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComponentProps, ComponentPropsWithoutRef, FC, PropsWithoutRef, ReactElement, ReactNode, RefAttributes } from "react";
|
|
2
2
|
import { Tree } from "@stratakit/structures";
|
|
3
3
|
import { TreeRendererProps } from "../Renderers.js";
|
|
4
|
-
import {
|
|
4
|
+
import { TreeNode } from "../TreeNode.js";
|
|
5
5
|
import { SelectionMode } from "../UseSelectionHandler.js";
|
|
6
6
|
import { LocalizationContextProvider } from "./LocalizationContext.js";
|
|
7
7
|
import { TreeErrorRendererProps } from "./TreeErrorRenderer.js";
|
|
@@ -20,18 +20,18 @@ interface TreeRendererOwnProps {
|
|
|
20
20
|
/** A render function for errors' display component. Defaults to `<TreeErrorRenderer />`. */
|
|
21
21
|
errorRenderer?: (props: TreeErrorRendererProps) => ReactElement;
|
|
22
22
|
/** Props that defines if current node supports editing. */
|
|
23
|
-
getEditingProps?: (node:
|
|
23
|
+
getEditingProps?: (node: TreeNode) => TreeNodeEditingProps | undefined;
|
|
24
24
|
/** Custom props for the root Tree component. */
|
|
25
25
|
treeRootProps?: Partial<Omit<ComponentProps<typeof Tree.Root>, "style">>;
|
|
26
26
|
/** A callback that returns tree item props for specific node. */
|
|
27
|
-
getTreeItemProps?: (node:
|
|
27
|
+
getTreeItemProps?: (node: TreeNode) => Partial<Omit<StrataKitTreeItemProps, "selected" | "aria-level" | "aria-posinset" | "aria-setsize">>;
|
|
28
28
|
/**
|
|
29
29
|
* Callback that returns menu actions for tree item.
|
|
30
30
|
* Must return an array of `<TreeActionBase />` or `<Divider />` elements.
|
|
31
31
|
*/
|
|
32
32
|
getMenuActions?: (props: {
|
|
33
|
-
targetNode:
|
|
34
|
-
selectedNodes:
|
|
33
|
+
targetNode: TreeNode;
|
|
34
|
+
selectedNodes: TreeNode[];
|
|
35
35
|
}) => ReactNode[];
|
|
36
36
|
/**
|
|
37
37
|
* Callback that returns inline actions for tree item.
|
|
@@ -39,16 +39,16 @@ interface TreeRendererOwnProps {
|
|
|
39
39
|
* Max 2 items.
|
|
40
40
|
*/
|
|
41
41
|
getInlineActions?: (props: {
|
|
42
|
-
targetNode:
|
|
43
|
-
selectedNodes:
|
|
42
|
+
targetNode: TreeNode;
|
|
43
|
+
selectedNodes: TreeNode[];
|
|
44
44
|
}) => ReactNode[];
|
|
45
45
|
/**
|
|
46
46
|
* Callback that returns actions for tree item context menu.
|
|
47
47
|
* Must return an array of `<TreeActionBase />` or `<Divider />` elements.
|
|
48
48
|
*/
|
|
49
49
|
getContextMenuActions?: (props: {
|
|
50
|
-
targetNode:
|
|
51
|
-
selectedNodes:
|
|
50
|
+
targetNode: TreeNode;
|
|
51
|
+
selectedNodes: TreeNode[];
|
|
52
52
|
}) => ReactNode[];
|
|
53
53
|
}
|
|
54
54
|
/** @alpha */
|
|
@@ -59,10 +59,10 @@ export interface StrataKitTreeRendererAttributes {
|
|
|
59
59
|
*
|
|
60
60
|
* Returns "node-not-found" if no node matches the predicate, "success" if rename was initiated.
|
|
61
61
|
*/
|
|
62
|
-
renameNode: (
|
|
62
|
+
renameNode: (nodePredicate: (node: TreeNode) => boolean) => "node-not-found" | "success";
|
|
63
63
|
}
|
|
64
64
|
/** @alpha */
|
|
65
|
-
type StrataKitTreeRendererProps = TreeRendererProps & Pick<TreeErrorRendererProps, "
|
|
65
|
+
type StrataKitTreeRendererProps = TreeRendererProps & Pick<TreeErrorRendererProps, "filterHierarchyLevel"> & TreeRendererOwnProps & ComponentPropsWithoutRef<typeof LocalizationContextProvider>;
|
|
66
66
|
/**
|
|
67
67
|
* A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes
|
|
68
68
|
* are rendered using `TreeNodeRenderer` component from this package.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EACL,cAAc,EACd,wBAAwB,EAExB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 @@ import { Tree } from "@stratakit/structures";
|
|
|
8
8
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
9
9
|
import { useSelectionHandler } from "../UseSelectionHandler.js";
|
|
10
10
|
import { useEvent, useMergedRefs } from "../Utils.js";
|
|
11
|
-
import {
|
|
11
|
+
import { isPlaceholderItem, useErrorNodes, useFlatTreeItems } from "./FlatTreeNode.js";
|
|
12
12
|
import { LocalizationContextProvider } from "./LocalizationContext.js";
|
|
13
13
|
import { TreeErrorRenderer } from "./TreeErrorRenderer.js";
|
|
14
14
|
import { TreeNodeRenameContextProvider, useTreeNodeRenameContextValue } from "./TreeNodeRenameAction.js";
|
|
@@ -21,15 +21,14 @@ import { PlaceholderNode, StrataKitTreeNodeRenderer } from "./TreeNodeRenderer.j
|
|
|
21
21
|
* @alpha
|
|
22
22
|
*/
|
|
23
23
|
export const StrataKitTreeRenderer = forwardRef(function StrataKitTreeRenderer(props, forwardedRef) {
|
|
24
|
-
const { id, rootNodes, selectNodes, selectionMode, expandNode, treeLabel, localizedStrings, getHierarchyLevelDetails,
|
|
25
|
-
const {
|
|
24
|
+
const { id, rootNodes, selectNodes, selectionMode, expandNode, treeLabel, localizedStrings, getHierarchyLevelDetails, filterHierarchyLevel, reloadTree, isNodeSelected, errorRenderer, treeRootProps, getContextMenuActions, getEditingProps, getInlineActions, getMenuActions, getTreeItemProps, } = props;
|
|
25
|
+
const { handleNodeSelect } = useSelectionHandler({
|
|
26
26
|
rootNodes,
|
|
27
27
|
selectNodes: selectNodes ?? noopSelectNodes,
|
|
28
28
|
selectionMode: selectionMode ?? "single",
|
|
29
29
|
});
|
|
30
30
|
const flatItems = useFlatTreeItems(rootNodes);
|
|
31
|
-
const
|
|
32
|
-
const scrollToNode = useRef(undefined);
|
|
31
|
+
const errorNodes = useErrorNodes(rootNodes);
|
|
33
32
|
const parentRef = useRef(null);
|
|
34
33
|
const virtualizer = useVirtualizer({
|
|
35
34
|
count: flatItems.length,
|
|
@@ -39,58 +38,18 @@ export const StrataKitTreeRenderer = forwardRef(function StrataKitTreeRenderer(p
|
|
|
39
38
|
overscan: 10,
|
|
40
39
|
});
|
|
41
40
|
const items = virtualizer.getVirtualItems();
|
|
41
|
+
const expandAndScrollToNode = useExpandAndScrollToNode({ rootNodes, flatItems, expandNode, virtualizer });
|
|
42
42
|
const renameContext = useTreeNodeRenameContextValue({
|
|
43
43
|
getEditingProps,
|
|
44
44
|
});
|
|
45
|
-
const scrollToElement = useCallback(({ errorNode, expandTo }) => {
|
|
46
|
-
const index = flatItems.findIndex((flatItem) => flatItem.id === errorNode.id);
|
|
47
|
-
if (index === -1) {
|
|
48
|
-
expandTo((nodeId) => expandNode(nodeId, true));
|
|
49
|
-
scrollToNode.current = { id: errorNode.id };
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
virtualizer.scrollToIndex(index, { align: "end" });
|
|
53
|
-
}, [expandNode, flatItems, virtualizer]);
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
if (scrollToNode.current === undefined) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const targetNodeId = scrollToNode.current.id;
|
|
59
|
-
const index = flatItems.findIndex((flatItem) => flatItem.id === targetNodeId);
|
|
60
|
-
if (index === -1) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
virtualizer.scrollToIndex(index, { align: "auto" });
|
|
64
|
-
scrollToNode.current.action?.();
|
|
65
|
-
scrollToNode.current = undefined;
|
|
66
|
-
}, [flatItems, virtualizer]);
|
|
67
45
|
useImperativeHandle(forwardedRef, () => ({
|
|
68
|
-
renameNode: (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return "node-not-found";
|
|
72
|
-
}
|
|
73
|
-
const targetNode = pathToNode.pop();
|
|
74
|
-
const collapsedNodes = pathToNode.filter((pathNode) => !pathNode.isExpanded);
|
|
75
|
-
const handleRename = () => {
|
|
46
|
+
renameNode: (nodePredicate) => expandAndScrollToNode({
|
|
47
|
+
nodePredicate,
|
|
48
|
+
onComplete: (targetNode) => {
|
|
76
49
|
// give time to scroll node into view before starting rename
|
|
77
|
-
requestAnimationFrame(() =>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
if (collapsedNodes.length > 0) {
|
|
82
|
-
collapsedNodes.forEach((node) => expandNode(node.id, true));
|
|
83
|
-
scrollToNode.current = {
|
|
84
|
-
id: targetNode.id,
|
|
85
|
-
action: handleRename,
|
|
86
|
-
};
|
|
87
|
-
return "success";
|
|
88
|
-
}
|
|
89
|
-
const index = flatItems.findIndex((flatItem) => flatItem.id === targetNode.id);
|
|
90
|
-
virtualizer.scrollToIndex(index, { align: "auto" });
|
|
91
|
-
handleRename();
|
|
92
|
-
return "success";
|
|
93
|
-
},
|
|
50
|
+
requestAnimationFrame(() => renameContext.startRename(targetNode));
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
94
53
|
}));
|
|
95
54
|
const cancelRename = renameContext.cancelRename;
|
|
96
55
|
const isScrolling = virtualizer.isScrolling;
|
|
@@ -102,11 +61,11 @@ export const StrataKitTreeRenderer = forwardRef(function StrataKitTreeRenderer(p
|
|
|
102
61
|
}, [isScrolling, cancelRename]);
|
|
103
62
|
const errorRendererProps = {
|
|
104
63
|
treeLabel,
|
|
105
|
-
|
|
106
|
-
|
|
64
|
+
errorNodes,
|
|
65
|
+
scrollToNode: (node) => expandAndScrollToNode({ nodePredicate: (n) => n.id === node.id }),
|
|
107
66
|
getHierarchyLevelDetails,
|
|
108
|
-
|
|
109
|
-
reloadTree,
|
|
67
|
+
filterHierarchyLevel,
|
|
68
|
+
reloadTree: useCallback(({ parentNodeId }) => reloadTree({ parentNodeId, state: "reset" }), [reloadTree]),
|
|
110
69
|
};
|
|
111
70
|
const getSelectedNodes = useMemo(() => {
|
|
112
71
|
let calculatedSelectedNodes;
|
|
@@ -122,9 +81,68 @@ export const StrataKitTreeRenderer = forwardRef(function StrataKitTreeRenderer(p
|
|
|
122
81
|
return (_jsxs(LocalizationContextProvider, { localizedStrings: localizedStrings, children: [errorRenderer ? errorRenderer(errorRendererProps) : _jsx(TreeErrorRenderer, { ...errorRendererProps }), _jsx("div", { id: id, style: { height: "100%", width: "100%", overflowY: "auto" }, ref: parentRef, children: _jsx(Tree.Root, { ...treeRootProps, style: { height: virtualizer.getTotalSize(), minHeight: "100%", width: "100%", position: "relative", overflow: "hidden" }, children: _jsx(TreeNodeRenameContextProvider, { value: renameContext, children: items.map((virtualizedItem) => {
|
|
123
82
|
const item = flatItems[virtualizedItem.index];
|
|
124
83
|
const selected = isNodeSelected?.(item.id) ?? false;
|
|
125
|
-
return (_jsx(VirtualTreeItem, { ref: virtualizer.measureElement, "data-index": virtualizedItem.index, start: virtualizedItem.start, item: item, selected: selected, expandNode: expandNode, reloadTree: reloadTree,
|
|
84
|
+
return (_jsx(VirtualTreeItem, { ref: virtualizer.measureElement, "data-index": virtualizedItem.index, start: virtualizedItem.start, item: item, selected: selected, expandNode: expandNode, reloadTree: reloadTree, handleNodeSelect: handleNodeSelect, getSelectedNodes: getSelectedNodes, getContextMenuActions: getContextMenuActions, getInlineActions: getInlineActions, getMenuActions: getMenuActions, getTreeItemProps: getTreeItemProps }, virtualizedItem.key));
|
|
126
85
|
}) }) }) })] }));
|
|
127
86
|
});
|
|
87
|
+
function useExpandAndScrollToNode({ rootNodes, flatItems, expandNode, virtualizer, }) {
|
|
88
|
+
const expandToNode = (nodePredicate) => {
|
|
89
|
+
const pathToNode = findPathToNode(rootNodes, nodePredicate);
|
|
90
|
+
if (!pathToNode) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
const targetNode = pathToNode.pop();
|
|
94
|
+
const collapsedNodes = pathToNode.filter((pathNode) => !pathNode.isExpanded);
|
|
95
|
+
collapsedNodes.forEach((node) => expandNode(node.id, true));
|
|
96
|
+
return { targetNode, didExpand: collapsedNodes.length > 0 };
|
|
97
|
+
};
|
|
98
|
+
const scrollToNode = useRef(undefined);
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (scrollToNode.current === undefined) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const targetNodeId = scrollToNode.current.id;
|
|
104
|
+
const index = flatItems.findIndex((flatItem) => flatItem.id === targetNodeId);
|
|
105
|
+
if (index === -1) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
virtualizer.scrollToIndex(index, { align: "auto" });
|
|
109
|
+
scrollToNode.current.onScrollComplete?.();
|
|
110
|
+
scrollToNode.current = undefined;
|
|
111
|
+
}, [flatItems, virtualizer]);
|
|
112
|
+
return ({ nodePredicate, onComplete }) => {
|
|
113
|
+
const expandResult = expandToNode(nodePredicate);
|
|
114
|
+
if (!expandResult) {
|
|
115
|
+
return "node-not-found";
|
|
116
|
+
}
|
|
117
|
+
const { targetNode, didExpand } = expandResult;
|
|
118
|
+
if (didExpand) {
|
|
119
|
+
scrollToNode.current = {
|
|
120
|
+
id: targetNode.id,
|
|
121
|
+
onScrollComplete: onComplete ? () => onComplete(targetNode) : undefined,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
const index = flatItems.findIndex((flatItem) => flatItem.id === targetNode.id);
|
|
126
|
+
virtualizer.scrollToIndex(index, { align: "auto" });
|
|
127
|
+
onComplete?.(targetNode);
|
|
128
|
+
}
|
|
129
|
+
return "success";
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function findPathToNode(rootNodes, nodePredicate) {
|
|
133
|
+
for (const parent of rootNodes) {
|
|
134
|
+
if (nodePredicate(parent)) {
|
|
135
|
+
return [parent];
|
|
136
|
+
}
|
|
137
|
+
if (parent.children && parent.children !== true) {
|
|
138
|
+
const childPath = findPathToNode(parent.children, nodePredicate);
|
|
139
|
+
if (childPath) {
|
|
140
|
+
return [parent, ...childPath];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
128
146
|
const VirtualTreeItem = memo(forwardRef(function VirtualTreeItem({ start, item, ...props }, forwardedRef) {
|
|
129
147
|
const style = useMemo(() => ({
|
|
130
148
|
position: "absolute",
|
|
@@ -139,7 +157,7 @@ const VirtualTreeItem = memo(forwardRef(function VirtualTreeItem({ start, item,
|
|
|
139
157
|
}
|
|
140
158
|
return _jsx(HierarchyNodeItem, { ...props, ref: forwardedRef, style: style, item: item });
|
|
141
159
|
}));
|
|
142
|
-
const HierarchyNodeItem = memo(forwardRef(function HierarchyNodeItem({ item, selected, getTreeItemProps,
|
|
160
|
+
const HierarchyNodeItem = memo(forwardRef(function HierarchyNodeItem({ item, selected, getTreeItemProps, handleNodeSelect, getSelectedNodes, getMenuActions, getInlineActions, getContextMenuActions, ...rest }, forwardedRef) {
|
|
143
161
|
const nodeRef = useRef(null);
|
|
144
162
|
const node = item.node;
|
|
145
163
|
const treeItemProps = getTreeItemProps?.(node);
|
|
@@ -153,23 +171,23 @@ const HierarchyNodeItem = memo(forwardRef(function HierarchyNodeItem({ item, sel
|
|
|
153
171
|
if (treeItemProps?.onClick) {
|
|
154
172
|
treeItemProps.onClick(e);
|
|
155
173
|
}
|
|
156
|
-
if
|
|
174
|
+
// ignore if this is double click
|
|
175
|
+
if (isDisabled || e.detail > 1) {
|
|
157
176
|
return;
|
|
158
177
|
}
|
|
159
|
-
|
|
178
|
+
handleNodeSelect({ nodeId: node.id, isSelected: selected ?? false, shiftDown: e.shiftKey, ctrlDown: e.ctrlKey });
|
|
160
179
|
});
|
|
161
|
-
const
|
|
162
|
-
if (treeItemProps?.
|
|
163
|
-
treeItemProps.
|
|
180
|
+
const onMouseDown = useEvent((e) => {
|
|
181
|
+
if (treeItemProps?.onMouseDown) {
|
|
182
|
+
treeItemProps.onMouseDown(e);
|
|
164
183
|
}
|
|
165
|
-
//
|
|
166
|
-
if (
|
|
167
|
-
|
|
184
|
+
// prevent text selection on shift+click
|
|
185
|
+
if (e.shiftKey) {
|
|
186
|
+
e.preventDefault();
|
|
168
187
|
}
|
|
169
|
-
onNodeKeyDown?.(node, !selected, e);
|
|
170
188
|
});
|
|
171
189
|
const ref = useMergedRefs(forwardedRef, nodeRef);
|
|
172
|
-
return (_jsx(StrataKitTreeNodeRenderer, { ...treeItemProps, ...rest, ...nodeActions, ref: ref, "aria-level": item.level, "aria-posinset": item.posInLevel, "aria-setsize": item.levelSize, node: item.node, selected: selected, onClick: onClick,
|
|
190
|
+
return (_jsx(StrataKitTreeNodeRenderer, { ...treeItemProps, ...rest, ...nodeActions, ref: ref, "aria-level": item.level, "aria-posinset": item.posInLevel, "aria-setsize": item.levelSize, node: item.node, selected: selected, onClick: onClick, onMouseDown: onMouseDown }));
|
|
173
191
|
}));
|
|
174
192
|
function noopSelectNodes() { }
|
|
175
193
|
//# sourceMappingURL=TreeRenderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAKL,UAAU,EACV,IAAI,EAKJ,WAAW,EACX,SAAS,EACT,mBAAmB,EACnB,OAAO,EACP,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAiB,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAa,cAAc,EAAkC,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACjJ,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAA0B,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAwB,6BAA6B,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAC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,EAAE,GAAG,gBACI,IAAI,CAAC,KAAK,mBACP,IAAI,CAAC,UAAU,kBAChB,IAAI,CAAC,SAAS,EAC5B,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,SAAS,GACpB,CACH,CAAC;AACJ,CAAC,CAAC,CACH,CAAC;AAEF,SAAS,eAAe,KAAI,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport {\n ComponentProps,\n ComponentPropsWithoutRef,\n CSSProperties,\n FC,\n forwardRef,\n memo,\n PropsWithoutRef,\n ReactElement,\n ReactNode,\n RefAttributes,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n} from \"react\";\nimport { Tree } from \"@stratakit/structures\";\nimport { useVirtualizer } from \"@tanstack/react-virtual\";\nimport { TreeRendererProps } from \"../Renderers.js\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { SelectionMode, useSelectionHandler } from \"../UseSelectionHandler.js\";\nimport { useEvent, useMergedRefs } from \"../Utils.js\";\nimport { ErrorItem, findPathToNode, FlatTreeItem, FlatTreeNodeItem, isPlaceholderItem, useErrorList, useFlatTreeItems } from \"./FlatTreeNode.js\";\nimport { LocalizationContextProvider } from \"./LocalizationContext.js\";\nimport { TreeErrorRenderer, TreeErrorRendererProps } from \"./TreeErrorRenderer.js\";\nimport { TreeNodeEditingProps, TreeNodeRenameContextProvider, useTreeNodeRenameContextValue } from \"./TreeNodeRenameAction.js\";\nimport { PlaceholderNode, StrataKitTreeItemProps, StrataKitTreeNodeRenderer, TreeNodeRendererProps } from \"./TreeNodeRenderer.js\";\n\n/** @alpha */\ninterface TreeRendererOwnProps {\n id?: string;\n /**\n * A user friendly display label of the tree. Should be unique within the consuming application,\n * as it's used for accessibility purposes.\n */\n treeLabel: string;\n /** Active selection mode used by the tree. Defaults to `\"single\"`. */\n selectionMode?: SelectionMode;\n /** A render function for errors' display component. Defaults to `<TreeErrorRenderer />`. */\n errorRenderer?: (props: TreeErrorRendererProps) => ReactElement;\n /** Props that defines if current node supports editing. */\n getEditingProps?: (node: PresentationHierarchyNode) => TreeNodeEditingProps | undefined;\n\n /** Custom props for the root Tree component. */\n treeRootProps?: Partial<Omit<ComponentProps<typeof Tree.Root>, \"style\">>;\n\n /** A callback that returns tree item props for specific node. */\n getTreeItemProps?: (node: PresentationHierarchyNode) => Partial<Omit<StrataKitTreeItemProps, \"selected\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\">>;\n\n /**\n * Callback that returns menu actions for tree item.\n * Must return an array of `<TreeActionBase />` or `<Divider />` elements.\n */\n getMenuActions?: (props: { targetNode: PresentationHierarchyNode; selectedNodes: PresentationHierarchyNode[] }) => ReactNode[];\n /**\n * Callback that returns inline actions for tree item.\n * Must return an array of `<TreeActionBase />` elements.\n * Max 2 items.\n */\n getInlineActions?: (props: { targetNode: PresentationHierarchyNode; selectedNodes: PresentationHierarchyNode[] }) => ReactNode[];\n /**\n * Callback that returns actions for tree item context menu.\n * Must return an array of `<TreeActionBase />` or `<Divider />` elements.\n */\n getContextMenuActions?: (props: { targetNode: PresentationHierarchyNode; selectedNodes: PresentationHierarchyNode[] }) => ReactNode[];\n}\n\n/** @alpha */\nexport interface StrataKitTreeRendererAttributes {\n /**\n * Opens rename mode for the first node that matches the given predicate. Node must be already loaded in the tree.\n * If the node is not visible (because its parent is collapsed), all parents will be expanded to make it visible and node will be scrolled into view.\n *\n * Returns \"node-not-found\" if no node matches the predicate, \"success\" if rename was initiated.\n */\n renameNode: (predicate: (node: PresentationHierarchyNode) => boolean) => \"node-not-found\" | \"success\";\n}\n\n/** @alpha */\ntype StrataKitTreeRendererProps = TreeRendererProps &\n Pick<TreeErrorRendererProps, \"onFilterClick\"> &\n TreeRendererOwnProps &\n ComponentPropsWithoutRef<typeof LocalizationContextProvider>;\n\n/**\n * A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes\n * are rendered using `TreeNodeRenderer` component from this package.\n *\n * @see https://itwinui.bentley.com/docs/tree\n * @alpha\n */\nexport const StrataKitTreeRenderer: FC<PropsWithoutRef<StrataKitTreeRendererProps> & RefAttributes<StrataKitTreeRendererAttributes>> = forwardRef<\n StrataKitTreeRendererAttributes,\n StrataKitTreeRendererProps\n>(function StrataKitTreeRenderer(props, forwardedRef) {\n const {\n id,\n rootNodes,\n selectNodes,\n selectionMode,\n expandNode,\n treeLabel,\n localizedStrings,\n getHierarchyLevelDetails,\n onFilterClick,\n reloadTree,\n isNodeSelected,\n errorRenderer,\n treeRootProps,\n getContextMenuActions,\n getEditingProps,\n getInlineActions,\n getMenuActions,\n getTreeItemProps,\n } = props;\n const { onNodeClick, onNodeKeyDown } = useSelectionHandler({\n rootNodes,\n selectNodes: selectNodes ?? noopSelectNodes,\n selectionMode: selectionMode ?? \"single\",\n });\n const flatItems = useFlatTreeItems(rootNodes);\n const errorList = useErrorList(rootNodes);\n\n const scrollToNode = useRef<{ id: string; action?: () => void } | undefined>(undefined);\n const parentRef = useRef<HTMLDivElement>(null);\n\n const virtualizer = useVirtualizer({\n count: flatItems.length,\n getScrollElement: () => parentRef.current,\n getItemKey: useCallback((index: number) => flatItems[index].id, [flatItems]),\n estimateSize: () => 28,\n overscan: 10,\n });\n\n const items = virtualizer.getVirtualItems();\n\n const renameContext = useTreeNodeRenameContextValue({\n getEditingProps,\n });\n\n const scrollToElement = useCallback(\n ({ errorNode, expandTo }: ErrorItem) => {\n const index = flatItems.findIndex((flatItem) => flatItem.id === errorNode.id);\n if (index === -1) {\n expandTo((nodeId) => expandNode(nodeId, true));\n scrollToNode.current = { id: errorNode.id };\n return;\n }\n virtualizer.scrollToIndex(index, { align: \"end\" });\n },\n [expandNode, flatItems, virtualizer],\n );\n\n useEffect(() => {\n if (scrollToNode.current === undefined) {\n return;\n }\n const targetNodeId = scrollToNode.current.id;\n const index = flatItems.findIndex((flatItem) => flatItem.id === targetNodeId);\n if (index === -1) {\n return;\n }\n virtualizer.scrollToIndex(index, { align: \"auto\" });\n scrollToNode.current.action?.();\n scrollToNode.current = undefined;\n }, [flatItems, virtualizer]);\n\n useImperativeHandle(forwardedRef, () => ({\n renameNode: (predicate) => {\n const pathToNode = findPathToNode(rootNodes, predicate);\n if (!pathToNode) {\n return \"node-not-found\";\n }\n const targetNode = pathToNode.pop()!;\n const collapsedNodes = pathToNode.filter((pathNode) => !pathNode.isExpanded);\n\n const handleRename = () => {\n // give time to scroll node into view before starting rename\n requestAnimationFrame(() => {\n renameContext.startRename(targetNode);\n });\n };\n\n if (collapsedNodes.length > 0) {\n collapsedNodes.forEach((node) => expandNode(node.id, true));\n scrollToNode.current = {\n id: targetNode.id,\n action: handleRename,\n };\n return \"success\";\n }\n\n const index = flatItems.findIndex((flatItem) => flatItem.id === targetNode.id);\n virtualizer.scrollToIndex(index, { align: \"auto\" });\n handleRename();\n return \"success\";\n },\n }));\n\n const cancelRename = renameContext.cancelRename;\n const isScrolling = virtualizer.isScrolling;\n useEffect(() => {\n if (isScrolling) {\n // cancel rename when scroll is initiated\n cancelRename();\n }\n }, [isScrolling, cancelRename]);\n\n const errorRendererProps: TreeErrorRendererProps = {\n treeLabel,\n errorList,\n scrollToElement,\n getHierarchyLevelDetails,\n onFilterClick,\n reloadTree,\n };\n\n const getSelectedNodes = useMemo(() => {\n let calculatedSelectedNodes: PresentationHierarchyNode[];\n return () => {\n if (calculatedSelectedNodes === undefined) {\n calculatedSelectedNodes = flatItems\n .filter((item): item is FlatTreeNodeItem => !isPlaceholderItem(item) && isNodeSelected?.(item.id))\n .map((item) => item.node);\n }\n return calculatedSelectedNodes;\n };\n }, [flatItems, isNodeSelected]);\n\n return (\n <LocalizationContextProvider localizedStrings={localizedStrings}>\n {errorRenderer ? errorRenderer(errorRendererProps) : <TreeErrorRenderer {...errorRendererProps} />}\n <div id={id} style={{ height: \"100%\", width: \"100%\", overflowY: \"auto\" }} ref={parentRef}>\n <Tree.Root\n {...treeRootProps}\n style={{ height: virtualizer.getTotalSize(), minHeight: \"100%\", width: \"100%\", position: \"relative\", overflow: \"hidden\" }}\n >\n <TreeNodeRenameContextProvider value={renameContext}>\n {items.map((virtualizedItem) => {\n const item = flatItems[virtualizedItem.index];\n const selected = isNodeSelected?.(item.id) ?? false;\n return (\n <VirtualTreeItem\n ref={virtualizer.measureElement}\n key={virtualizedItem.key}\n data-index={virtualizedItem.index}\n start={virtualizedItem.start}\n item={item}\n selected={selected}\n expandNode={expandNode}\n reloadTree={reloadTree}\n onNodeClick={onNodeClick}\n onNodeKeyDown={onNodeKeyDown}\n getSelectedNodes={getSelectedNodes}\n getContextMenuActions={getContextMenuActions}\n getInlineActions={getInlineActions}\n getMenuActions={getMenuActions}\n getTreeItemProps={getTreeItemProps}\n />\n );\n })}\n </TreeNodeRenameContextProvider>\n </Tree.Root>\n </div>\n </LocalizationContextProvider>\n );\n});\n\ntype VirtualTreeItemProps = Omit<HierarchyNodeItemProps, \"item\"> & {\n start: number;\n \"data-index\": number;\n item: FlatTreeItem;\n};\n\nconst VirtualTreeItem = memo(\n forwardRef<HTMLElement, VirtualTreeItemProps>(function VirtualTreeItem({ start, item, ...props }, forwardedRef) {\n const style: CSSProperties = useMemo(\n () => ({\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n transform: `translateY(${start}px)`,\n willChange: \"transform\",\n }),\n [start],\n );\n\n if (isPlaceholderItem(item)) {\n return <PlaceholderNode ref={forwardedRef} data-index={props[\"data-index\"]} style={style} aria-level={item.level} aria-posinset={1} aria-setsize={1} />;\n }\n\n return <HierarchyNodeItem {...props} ref={forwardedRef} style={style} item={item} />;\n }),\n);\n\ntype HierarchyNodeItemProps = {\n item: FlatTreeNodeItem;\n style?: CSSProperties;\n getSelectedNodes: () => PresentationHierarchyNode[];\n} & Pick<TreeNodeRendererProps, \"expandNode\" | \"reloadTree\" | \"selected\"> &\n Pick<TreeRendererOwnProps, \"getContextMenuActions\" | \"getInlineActions\" | \"getMenuActions\" | \"getTreeItemProps\"> &\n Pick<ReturnType<typeof useSelectionHandler>, \"onNodeClick\" | \"onNodeKeyDown\">;\n\nconst HierarchyNodeItem = memo(\n forwardRef<HTMLElement, HierarchyNodeItemProps>(function HierarchyNodeItem(\n { item, selected, getTreeItemProps, onNodeClick, onNodeKeyDown, getSelectedNodes, getMenuActions, getInlineActions, getContextMenuActions, ...rest },\n forwardedRef,\n ) {\n const nodeRef = useRef<HTMLElement>(null);\n const node = item.node;\n const treeItemProps = getTreeItemProps?.(node);\n\n const isDisabled = treeItemProps?.[\"aria-disabled\"] === true;\n const nodeActions = useMemo(\n () => ({\n menuActions: getMenuActions ? getMenuActions({ targetNode: node, selectedNodes: getSelectedNodes() }) : undefined,\n inlineActions: getInlineActions ? getInlineActions({ targetNode: node, selectedNodes: getSelectedNodes() }) : undefined,\n contextMenuActions: getContextMenuActions ? getContextMenuActions({ targetNode: node, selectedNodes: getSelectedNodes() }) : undefined,\n }),\n [node, getMenuActions, getInlineActions, getContextMenuActions, getSelectedNodes],\n );\n\n const onClick = useEvent<Required<TreeNodeRendererProps>[\"onClick\"]>((e) => {\n if (treeItemProps?.onClick) {\n treeItemProps.onClick(e);\n }\n if (isDisabled) {\n return;\n }\n onNodeClick?.(node, !selected, e);\n });\n const onKeyDown = useEvent<Required<TreeNodeRendererProps>[\"onKeyDown\"]>((e) => {\n if (treeItemProps?.onKeyDown) {\n treeItemProps.onKeyDown(e);\n }\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (isDisabled || e.target !== nodeRef.current) {\n return;\n }\n onNodeKeyDown?.(node, !selected, e);\n });\n\n const ref = useMergedRefs(forwardedRef, nodeRef);\n return (\n <StrataKitTreeNodeRenderer\n {...treeItemProps}\n {...rest}\n {...nodeActions}\n ref={ref}\n aria-level={item.level}\n aria-posinset={item.posInLevel}\n aria-setsize={item.levelSize}\n node={item.node}\n selected={selected}\n onClick={onClick}\n onKeyDown={onKeyDown}\n />\n );\n }),\n);\n\nfunction noopSelectNodes() {}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAKL,UAAU,EACV,IAAI,EAKJ,WAAW,EACX,SAAS,EACT,mBAAmB,EACnB,OAAO,EACP,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAiB,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAkC,iBAAiB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACvH,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAA0B,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAwB,6BAA6B,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAC/H,OAAO,EAAE,eAAe,EAA0B,yBAAyB,EAAyB,MAAM,uBAAuB,CAAC;AA0DlI;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAqG,UAAU,CAG/I,SAAS,qBAAqB,CAAC,KAAK,EAAE,YAAY;IAClD,MAAM,EACJ,EAAE,EACF,SAAS,EACT,WAAW,EACX,aAAa,EACb,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,wBAAwB,EACxB,oBAAoB,EACpB,UAAU,EACV,cAAc,EACd,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,gBAAgB,GACjB,GA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AAC,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IACnH,CAAC,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,QAAQ,CAAiD,CAAC,CAAC,EAAE,EAAE;QACjF,IAAI,aAAa,EAAE,WAAW,EAAE,CAAC;YAC/B,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC;QACD,wCAAwC;QACxC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;YACf,CAAC,CAAC,cAAc,EAAE,CAAC;QACrB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,aAAa,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACjD,OAAO,CACL,KAAC,yBAAyB,OACpB,aAAa,KACb,IAAI,KACJ,WAAW,EACf,GAAG,EAAE,GAAG,gBACI,IAAI,CAAC,KAAK,mBACP,IAAI,CAAC,UAAU,kBAChB,IAAI,CAAC,SAAS,EAC5B,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,WAAW,GACxB,CACH,CAAC;AACJ,CAAC,CAAC,CACH,CAAC;AAEF,SAAS,eAAe,KAAI,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport {\n ComponentProps,\n ComponentPropsWithoutRef,\n CSSProperties,\n FC,\n forwardRef,\n memo,\n PropsWithoutRef,\n ReactElement,\n ReactNode,\n RefAttributes,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n} from \"react\";\nimport { Tree } from \"@stratakit/structures\";\nimport { useVirtualizer } from \"@tanstack/react-virtual\";\nimport { TreeRendererProps } from \"../Renderers.js\";\nimport { TreeNode } from \"../TreeNode.js\";\nimport { SelectionMode, useSelectionHandler } from \"../UseSelectionHandler.js\";\nimport { useEvent, useMergedRefs } from \"../Utils.js\";\nimport { FlatTreeItem, FlatTreeNodeItem, isPlaceholderItem, useErrorNodes, useFlatTreeItems } from \"./FlatTreeNode.js\";\nimport { LocalizationContextProvider } from \"./LocalizationContext.js\";\nimport { TreeErrorRenderer, TreeErrorRendererProps } from \"./TreeErrorRenderer.js\";\nimport { TreeNodeEditingProps, TreeNodeRenameContextProvider, useTreeNodeRenameContextValue } from \"./TreeNodeRenameAction.js\";\nimport { PlaceholderNode, StrataKitTreeItemProps, StrataKitTreeNodeRenderer, TreeNodeRendererProps } from \"./TreeNodeRenderer.js\";\n\n/** @alpha */\ninterface TreeRendererOwnProps {\n id?: string;\n /**\n * A user friendly display label of the tree. Should be unique within the consuming application,\n * as it's used for accessibility purposes.\n */\n treeLabel: string;\n /** Active selection mode used by the tree. Defaults to `\"single\"`. */\n selectionMode?: SelectionMode;\n /** A render function for errors' display component. Defaults to `<TreeErrorRenderer />`. */\n errorRenderer?: (props: TreeErrorRendererProps) => ReactElement;\n /** Props that defines if current node supports editing. */\n getEditingProps?: (node: TreeNode) => TreeNodeEditingProps | undefined;\n\n /** Custom props for the root Tree component. */\n treeRootProps?: Partial<Omit<ComponentProps<typeof Tree.Root>, \"style\">>;\n\n /** A callback that returns tree item props for specific node. */\n getTreeItemProps?: (node: TreeNode) => Partial<Omit<StrataKitTreeItemProps, \"selected\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\">>;\n\n /**\n * Callback that returns menu actions for tree item.\n * Must return an array of `<TreeActionBase />` or `<Divider />` elements.\n */\n getMenuActions?: (props: { targetNode: TreeNode; selectedNodes: TreeNode[] }) => ReactNode[];\n /**\n * Callback that returns inline actions for tree item.\n * Must return an array of `<TreeActionBase />` elements.\n * Max 2 items.\n */\n getInlineActions?: (props: { targetNode: TreeNode; selectedNodes: TreeNode[] }) => ReactNode[];\n /**\n * Callback that returns actions for tree item context menu.\n * Must return an array of `<TreeActionBase />` or `<Divider />` elements.\n */\n getContextMenuActions?: (props: { targetNode: TreeNode; selectedNodes: TreeNode[] }) => ReactNode[];\n}\n\n/** @alpha */\nexport interface StrataKitTreeRendererAttributes {\n /**\n * Opens rename mode for the first node that matches the given predicate. Node must be already loaded in the tree.\n * If the node is not visible (because its parent is collapsed), all parents will be expanded to make it visible and node will be scrolled into view.\n *\n * Returns \"node-not-found\" if no node matches the predicate, \"success\" if rename was initiated.\n */\n renameNode: (nodePredicate: (node: TreeNode) => boolean) => \"node-not-found\" | \"success\";\n}\n\n/** @alpha */\ntype StrataKitTreeRendererProps = TreeRendererProps &\n Pick<TreeErrorRendererProps, \"filterHierarchyLevel\"> &\n TreeRendererOwnProps &\n ComponentPropsWithoutRef<typeof LocalizationContextProvider>;\n\n/**\n * A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes\n * are rendered using `TreeNodeRenderer` component from this package.\n *\n * @see https://itwinui.bentley.com/docs/tree\n * @alpha\n */\nexport const StrataKitTreeRenderer: FC<PropsWithoutRef<StrataKitTreeRendererProps> & RefAttributes<StrataKitTreeRendererAttributes>> = forwardRef<\n StrataKitTreeRendererAttributes,\n StrataKitTreeRendererProps\n>(function StrataKitTreeRenderer(props, forwardedRef) {\n const {\n id,\n rootNodes,\n selectNodes,\n selectionMode,\n expandNode,\n treeLabel,\n localizedStrings,\n getHierarchyLevelDetails,\n filterHierarchyLevel,\n reloadTree,\n isNodeSelected,\n errorRenderer,\n treeRootProps,\n getContextMenuActions,\n getEditingProps,\n getInlineActions,\n getMenuActions,\n getTreeItemProps,\n } = props;\n const { handleNodeSelect } = useSelectionHandler({\n rootNodes,\n selectNodes: selectNodes ?? noopSelectNodes,\n selectionMode: selectionMode ?? \"single\",\n });\n const flatItems = useFlatTreeItems(rootNodes);\n const errorNodes = useErrorNodes(rootNodes);\n\n const parentRef = useRef<HTMLDivElement>(null);\n\n const virtualizer = useVirtualizer({\n count: flatItems.length,\n getScrollElement: () => parentRef.current,\n getItemKey: useCallback((index: number) => flatItems[index].id, [flatItems]),\n estimateSize: () => 28,\n overscan: 10,\n });\n const items = virtualizer.getVirtualItems();\n const expandAndScrollToNode = useExpandAndScrollToNode({ rootNodes, flatItems, expandNode, virtualizer });\n\n const renameContext = useTreeNodeRenameContextValue({\n getEditingProps,\n });\n useImperativeHandle(forwardedRef, () => ({\n renameNode: (nodePredicate) =>\n expandAndScrollToNode({\n nodePredicate,\n onComplete: (targetNode) => {\n // give time to scroll node into view before starting rename\n requestAnimationFrame(() => renameContext.startRename(targetNode));\n },\n }),\n }));\n\n const cancelRename = renameContext.cancelRename;\n const isScrolling = virtualizer.isScrolling;\n useEffect(() => {\n if (isScrolling) {\n // cancel rename when scroll is initiated\n cancelRename();\n }\n }, [isScrolling, cancelRename]);\n\n const errorRendererProps: TreeErrorRendererProps = {\n treeLabel,\n errorNodes,\n scrollToNode: (node) => expandAndScrollToNode({ nodePredicate: (n) => n.id === node.id }),\n getHierarchyLevelDetails,\n filterHierarchyLevel,\n reloadTree: useCallback<TreeErrorRendererProps[\"reloadTree\"]>(({ parentNodeId }) => reloadTree({ parentNodeId, state: \"reset\" }), [reloadTree]),\n };\n\n const getSelectedNodes = useMemo(() => {\n let calculatedSelectedNodes: TreeNode[];\n return () => {\n if (calculatedSelectedNodes === undefined) {\n calculatedSelectedNodes = flatItems\n .filter((item): item is FlatTreeNodeItem => !isPlaceholderItem(item) && isNodeSelected?.(item.id))\n .map((item) => item.node);\n }\n return calculatedSelectedNodes;\n };\n }, [flatItems, isNodeSelected]);\n\n return (\n <LocalizationContextProvider localizedStrings={localizedStrings}>\n {errorRenderer ? errorRenderer(errorRendererProps) : <TreeErrorRenderer {...errorRendererProps} />}\n <div id={id} style={{ height: \"100%\", width: \"100%\", overflowY: \"auto\" }} ref={parentRef}>\n <Tree.Root\n {...treeRootProps}\n style={{ height: virtualizer.getTotalSize(), minHeight: \"100%\", width: \"100%\", position: \"relative\", overflow: \"hidden\" }}\n >\n <TreeNodeRenameContextProvider value={renameContext}>\n {items.map((virtualizedItem) => {\n const item = flatItems[virtualizedItem.index];\n const selected = isNodeSelected?.(item.id) ?? false;\n return (\n <VirtualTreeItem\n ref={virtualizer.measureElement}\n key={virtualizedItem.key}\n data-index={virtualizedItem.index}\n start={virtualizedItem.start}\n item={item}\n selected={selected}\n expandNode={expandNode}\n reloadTree={reloadTree}\n handleNodeSelect={handleNodeSelect}\n getSelectedNodes={getSelectedNodes}\n getContextMenuActions={getContextMenuActions}\n getInlineActions={getInlineActions}\n getMenuActions={getMenuActions}\n getTreeItemProps={getTreeItemProps}\n />\n );\n })}\n </TreeNodeRenameContextProvider>\n </Tree.Root>\n </div>\n </LocalizationContextProvider>\n );\n});\n\nfunction useExpandAndScrollToNode({\n rootNodes,\n flatItems,\n expandNode,\n virtualizer,\n}: Pick<StrataKitTreeRendererProps, \"rootNodes\" | \"expandNode\"> & {\n flatItems: ReturnType<typeof useFlatTreeItems>;\n virtualizer: Pick<ReturnType<typeof useVirtualizer>, \"scrollToIndex\">;\n}) {\n const expandToNode = (nodePredicate: (node: TreeNode) => boolean) => {\n const pathToNode = findPathToNode(rootNodes, nodePredicate);\n if (!pathToNode) {\n return undefined;\n }\n const targetNode = pathToNode.pop()!;\n const collapsedNodes = pathToNode.filter((pathNode) => !pathNode.isExpanded);\n collapsedNodes.forEach((node) => expandNode(node.id, true));\n return { targetNode, didExpand: collapsedNodes.length > 0 };\n };\n\n const scrollToNode = useRef<{ id: string; onScrollComplete?: () => void } | undefined>(undefined);\n useEffect(() => {\n if (scrollToNode.current === undefined) {\n return;\n }\n const targetNodeId = scrollToNode.current.id;\n const index = flatItems.findIndex((flatItem) => flatItem.id === targetNodeId);\n if (index === -1) {\n return;\n }\n virtualizer.scrollToIndex(index, { align: \"auto\" });\n scrollToNode.current.onScrollComplete?.();\n scrollToNode.current = undefined;\n }, [flatItems, virtualizer]);\n\n return ({ nodePredicate, onComplete }: { nodePredicate: (node: TreeNode) => boolean; onComplete?: (targetNode: TreeNode) => void }) => {\n const expandResult = expandToNode(nodePredicate);\n if (!expandResult) {\n return \"node-not-found\";\n }\n\n const { targetNode, didExpand } = expandResult;\n if (didExpand) {\n scrollToNode.current = {\n id: targetNode.id,\n onScrollComplete: onComplete ? () => onComplete(targetNode) : undefined,\n };\n } else {\n const index = flatItems.findIndex((flatItem) => flatItem.id === targetNode.id);\n virtualizer.scrollToIndex(index, { align: \"auto\" });\n onComplete?.(targetNode);\n }\n return \"success\";\n };\n}\n\nfunction findPathToNode(rootNodes: TreeNode[], nodePredicate: (node: TreeNode) => boolean): TreeNode[] | undefined {\n for (const parent of rootNodes) {\n if (nodePredicate(parent)) {\n return [parent];\n }\n if (parent.children && parent.children !== true) {\n const childPath = findPathToNode(parent.children, nodePredicate);\n if (childPath) {\n return [parent, ...childPath];\n }\n }\n }\n return undefined;\n}\n\ntype VirtualTreeItemProps = Omit<HierarchyNodeItemProps, \"item\"> & {\n start: number;\n \"data-index\": number;\n item: FlatTreeItem;\n};\n\nconst VirtualTreeItem = memo(\n forwardRef<HTMLElement, VirtualTreeItemProps>(function VirtualTreeItem({ start, item, ...props }, forwardedRef) {\n const style: CSSProperties = useMemo(\n () => ({\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n transform: `translateY(${start}px)`,\n willChange: \"transform\",\n }),\n [start],\n );\n\n if (isPlaceholderItem(item)) {\n return <PlaceholderNode ref={forwardedRef} data-index={props[\"data-index\"]} style={style} aria-level={item.level} aria-posinset={1} aria-setsize={1} />;\n }\n\n return <HierarchyNodeItem {...props} ref={forwardedRef} style={style} item={item} />;\n }),\n);\n\ntype HierarchyNodeItemProps = {\n item: FlatTreeNodeItem;\n style?: CSSProperties;\n getSelectedNodes: () => TreeNode[];\n} & Pick<TreeNodeRendererProps, \"expandNode\" | \"reloadTree\" | \"selected\"> &\n Pick<TreeRendererOwnProps, \"getContextMenuActions\" | \"getInlineActions\" | \"getMenuActions\" | \"getTreeItemProps\"> &\n Pick<ReturnType<typeof useSelectionHandler>, \"handleNodeSelect\">;\n\nconst HierarchyNodeItem = memo(\n forwardRef<HTMLElement, HierarchyNodeItemProps>(function HierarchyNodeItem(\n { item, selected, getTreeItemProps, handleNodeSelect, getSelectedNodes, getMenuActions, getInlineActions, getContextMenuActions, ...rest },\n forwardedRef,\n ) {\n const nodeRef = useRef<HTMLElement>(null);\n const node = item.node;\n const treeItemProps = getTreeItemProps?.(node);\n\n const isDisabled = treeItemProps?.[\"aria-disabled\"] === true;\n const nodeActions = useMemo(\n () => ({\n menuActions: getMenuActions ? getMenuActions({ targetNode: node, selectedNodes: getSelectedNodes() }) : undefined,\n inlineActions: getInlineActions ? getInlineActions({ targetNode: node, selectedNodes: getSelectedNodes() }) : undefined,\n contextMenuActions: getContextMenuActions ? getContextMenuActions({ targetNode: node, selectedNodes: getSelectedNodes() }) : undefined,\n }),\n [node, getMenuActions, getInlineActions, getContextMenuActions, getSelectedNodes],\n );\n\n const onClick = useEvent<Required<TreeNodeRendererProps>[\"onClick\"]>((e) => {\n if (treeItemProps?.onClick) {\n treeItemProps.onClick(e);\n }\n // ignore if this is double click\n if (isDisabled || e.detail > 1) {\n return;\n }\n handleNodeSelect({ nodeId: node.id, isSelected: selected ?? false, shiftDown: e.shiftKey, ctrlDown: e.ctrlKey });\n });\n\n const onMouseDown = useEvent<Required<TreeNodeRendererProps>[\"onMouseDown\"]>((e) => {\n if (treeItemProps?.onMouseDown) {\n treeItemProps.onMouseDown(e);\n }\n // prevent text selection on shift+click\n if (e.shiftKey) {\n e.preventDefault();\n }\n });\n\n const ref = useMergedRefs(forwardedRef, nodeRef);\n return (\n <StrataKitTreeNodeRenderer\n {...treeItemProps}\n {...rest}\n {...nodeActions}\n ref={ref}\n aria-level={item.level}\n aria-posinset={item.posInLevel}\n aria-setsize={item.levelSize}\n node={item.node}\n selected={selected}\n onClick={onClick}\n onMouseDown={onMouseDown}\n />\n );\n }),\n);\n\nfunction noopSelectNodes() {}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export { GenericErrorInfo,
|
|
2
|
-
export { useSelectionHandler } from "./presentation-hierarchies-react/UseSelectionHandler.js";
|
|
1
|
+
export { GenericErrorInfo, TreeNode, ErrorInfo, ResultSetTooLargeErrorInfo } from "./presentation-hierarchies-react/TreeNode.js";
|
|
3
2
|
export { useTree, useUnifiedSelectionTree } from "./presentation-hierarchies-react/UseTree.js";
|
|
4
3
|
export { useNodeHighlighting } from "./presentation-hierarchies-react/UseNodeHighlighting.js";
|
|
5
4
|
export { HierarchyLevelDetails, TreeRendererProps } from "./presentation-hierarchies-react/Renderers.js";
|
|
@@ -11,7 +10,7 @@ export { StrataKitTreeRenderer, StrataKitTreeRendererAttributes } from "./presen
|
|
|
11
10
|
export { StrataKitRootErrorRenderer } from "./presentation-hierarchies-react/stratakit/RootErrorRenderer.js";
|
|
12
11
|
export { TreeErrorRenderer } from "./presentation-hierarchies-react/stratakit/TreeErrorRenderer.js";
|
|
13
12
|
export { ErrorItemRenderer } from "./presentation-hierarchies-react/stratakit/ErrorItemRenderer.js";
|
|
14
|
-
export { useFlatTreeItems,
|
|
13
|
+
export { useFlatTreeItems, useErrorNodes, FlatTreeItem } from "./presentation-hierarchies-react/stratakit/FlatTreeNode.js";
|
|
15
14
|
export { LocalizationContextProvider } from "./presentation-hierarchies-react/stratakit/LocalizationContext.js";
|
|
16
15
|
export { GenericInstanceFilter, HierarchyNode, HierarchyProvider, getLogger, setLogger } from "@itwin/presentation-hierarchies";
|
|
17
16
|
export { SelectionStorage } from "@itwin/unified-selection";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation-hierarchies-react.d.ts","sourceRoot":"","sources":["../../src/presentation-hierarchies-react.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"presentation-hierarchies-react.d.ts","sourceRoot":"","sources":["../../src/presentation-hierarchies-react.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,SAAS,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AACjI,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AAC/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,yDAAyD,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AACzG,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AACjH,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,0DAA0D,CAAC;AACpH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oEAAoE,CAAC;AAC1G,OAAO,EAAE,oBAAoB,EAAE,MAAM,oEAAoE,CAAC;AAC1G,OAAO,EAAE,qBAAqB,EAAE,+BAA+B,EAAE,MAAM,4DAA4D,CAAC;AACpI,OAAO,EAAE,0BAA0B,EAAE,MAAM,iEAAiE,CAAC;AAC7G,OAAO,EAAE,iBAAiB,EAAE,MAAM,iEAAiE,CAAC;AACpG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iEAAiE,CAAC;AACpG,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,4DAA4D,CAAC;AAC3H,OAAO,EAAE,2BAA2B,EAAE,MAAM,mEAAmE,CAAC;AAEhH,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,iBAAiB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAChI,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
export { useSelectionHandler } from "./presentation-hierarchies-react/UseSelectionHandler.js";
|
|
6
5
|
export { useTree, useUnifiedSelectionTree } from "./presentation-hierarchies-react/UseTree.js";
|
|
7
6
|
export { useNodeHighlighting } from "./presentation-hierarchies-react/UseNodeHighlighting.js";
|
|
8
7
|
export { useIModelTree, useIModelUnifiedSelectionTree } from "./presentation-hierarchies-react/UseIModelTree.js";
|
|
@@ -13,7 +12,7 @@ export { StrataKitTreeRenderer } from "./presentation-hierarchies-react/strataki
|
|
|
13
12
|
export { StrataKitRootErrorRenderer } from "./presentation-hierarchies-react/stratakit/RootErrorRenderer.js";
|
|
14
13
|
export { TreeErrorRenderer } from "./presentation-hierarchies-react/stratakit/TreeErrorRenderer.js";
|
|
15
14
|
export { ErrorItemRenderer } from "./presentation-hierarchies-react/stratakit/ErrorItemRenderer.js";
|
|
16
|
-
export { useFlatTreeItems,
|
|
15
|
+
export { useFlatTreeItems, useErrorNodes } from "./presentation-hierarchies-react/stratakit/FlatTreeNode.js";
|
|
17
16
|
export { LocalizationContextProvider } from "./presentation-hierarchies-react/stratakit/LocalizationContext.js";
|
|
18
17
|
export { GenericInstanceFilter, HierarchyNode, getLogger, setLogger } from "@itwin/presentation-hierarchies";
|
|
19
18
|
//# sourceMappingURL=presentation-hierarchies-react.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation-hierarchies-react.js","sourceRoot":"","sources":["../../src/presentation-hierarchies-react.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAGhG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"presentation-hierarchies-react.js","sourceRoot":"","sources":["../../src/presentation-hierarchies-react.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAGhG,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AAC/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,yDAAyD,CAAC;AAE9F,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AACjH,OAAO,EAAE,cAAc,EAA4B,MAAM,0DAA0D,CAAC;AACpH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oEAAoE,CAAC;AAC1G,OAAO,EAAE,oBAAoB,EAAE,MAAM,oEAAoE,CAAC;AAC1G,OAAO,EAAE,qBAAqB,EAAmC,MAAM,4DAA4D,CAAC;AACpI,OAAO,EAAE,0BAA0B,EAAE,MAAM,iEAAiE,CAAC;AAC7G,OAAO,EAAE,iBAAiB,EAAE,MAAM,iEAAiE,CAAC;AACpG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iEAAiE,CAAC;AACpG,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAgB,MAAM,4DAA4D,CAAC;AAC3H,OAAO,EAAE,2BAA2B,EAAE,MAAM,mEAAmE,CAAC;AAEhH,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAqB,SAAS,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nexport { GenericErrorInfo, TreeNode, ErrorInfo, ResultSetTooLargeErrorInfo } from \"./presentation-hierarchies-react/TreeNode.js\";\nexport { useTree, useUnifiedSelectionTree } from \"./presentation-hierarchies-react/UseTree.js\";\nexport { useNodeHighlighting } from \"./presentation-hierarchies-react/UseNodeHighlighting.js\";\nexport { HierarchyLevelDetails, TreeRendererProps } from \"./presentation-hierarchies-react/Renderers.js\";\nexport { useIModelTree, useIModelUnifiedSelectionTree } from \"./presentation-hierarchies-react/UseIModelTree.js\";\nexport { TreeActionBase, TreeActionBaseAttributes } from \"./presentation-hierarchies-react/stratakit/TreeAction.js\";\nexport { TreeNodeFilterAction } from \"./presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js\";\nexport { TreeNodeRenameAction } from \"./presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js\";\nexport { StrataKitTreeRenderer, StrataKitTreeRendererAttributes } from \"./presentation-hierarchies-react/stratakit/TreeRenderer.js\";\nexport { StrataKitRootErrorRenderer } from \"./presentation-hierarchies-react/stratakit/RootErrorRenderer.js\";\nexport { TreeErrorRenderer } from \"./presentation-hierarchies-react/stratakit/TreeErrorRenderer.js\";\nexport { ErrorItemRenderer } from \"./presentation-hierarchies-react/stratakit/ErrorItemRenderer.js\";\nexport { useFlatTreeItems, useErrorNodes, FlatTreeItem } from \"./presentation-hierarchies-react/stratakit/FlatTreeNode.js\";\nexport { LocalizationContextProvider } from \"./presentation-hierarchies-react/stratakit/LocalizationContext.js\";\n\nexport { GenericInstanceFilter, HierarchyNode, HierarchyProvider, getLogger, setLogger } from \"@itwin/presentation-hierarchies\";\nexport { SelectionStorage } from \"@itwin/unified-selection\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/presentation-hierarchies-react",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.50",
|
|
4
4
|
"description": "React components based on `@itwin/presentation-hierarchies`",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"immer": "^10.2.0",
|
|
44
44
|
"react-error-boundary": "^4.1.2",
|
|
45
45
|
"rxjs": "^7.8.2",
|
|
46
|
-
"@itwin/
|
|
46
|
+
"@itwin/unified-selection": "^1.6.6-alpha.0",
|
|
47
47
|
"@itwin/presentation-shared": "^2.0.0-alpha.6",
|
|
48
|
-
"@itwin/
|
|
48
|
+
"@itwin/presentation-hierarchies": "^2.0.0-alpha.10"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@stratakit/bricks": "^0.5",
|