@asup/tree-of-nodes 1.0.8 → 2.0.1
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/README.md +71 -56
- package/dist/cjs/main.css +49 -2
- package/dist/cjs/main.css.map +1 -1
- package/dist/cjs/main.js +142 -60
- package/dist/cjs/main.js.map +1 -1
- package/dist/main.css +49 -2
- package/dist/main.css.map +1 -1
- package/dist/main.js +125 -57
- package/dist/main.js.map +1 -1
- package/dist/tree-of-nodes.d.ts +7 -5
- package/dist/tree-of-nodes.d.ts.map +1 -1
- package/package.json +2 -1
package/dist/cjs/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AGGO,IAAM,4CAAe,SAC1B,IACA,UACA;IAEA,mBAAmB;IACnB,IAAM,UAAU,eAAe,KAAK,SAAC;eAAM,EAAE,OAAO;;IACpD,IAAI,YAAY,WAAW,OAAO,EAAE;IACpC,kBAAkB;IAClB,IAAM,SAAS,eAAe,KAAK,SAAC;eAAM,EAAE,OAAO,QAAQ;;IAC3D,0BAA0B;IAC1B,OAAO,WAAW,YACd,WACA,0CACE,OAAO,IACP,AAAC,mDAAG,SAAS,OAAO,SAAC;eAAM,EAAE,OAAO,OAAO;eAA3C;QAAgD;KAAO,GACvD;AAER;;;;ACJO,IAAM,4CAAqB,CAAA,GAAA,0BAAY,EAC5C;;;;;;;;ACLK,IAAM,0DAAY,CAAA,GAAA,sCAAI,EAAE,WAC7B,gBAA8D;QAA3D,WAAA,IAAI,cAAA,OAAO,gBAAA,SAAS,eAAA,QAAQ,iBAAA,UAAU,mBAAA,YAAY,cAAA;IACnD,0CAAU,cAAc;IACxB,IAAM,eAAe,CAAA,GAAA,oBAAM,EAAuB;QAChD,OAAO;YACL,SAAS;YACT,SAAS;YACT,aAAa;YACb,cAAc;YACd,QAAQ;YACR,cAAc;WACX;IAEP,GA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C,cAApB,mBAAoB;IAC1C,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,YAAY;YACd,6CAA6C;YAC7C,IAAM,eAAe,CAAA,GAAA,yCAAiB,EAAE,UAAU,YAAY;YAC9D,aAAa,OAAO,SAAC;uBAAM,CAAC,cAAc,SAAS;eAAI,SAAS,KAC9D,iBAAiB;QACrB;IACF,GAAG;QAAC;QAAe;QAAU;KAAW;IAExC,uCAAuC;IACvC,IAAM,eAAe,CAAA,GAAA,wBAAU,EAC7B,SAAC,MAAW;QACV,IAAM,mBAAoB,mDAAG;QAC7B,IAAM,KAAK,iBAAiB,UAAU,SAAC;mBAAS,SAAS;;QACzD,IAAI,AAAC,OAAO,MAAM,UAAU,aAAc,UAAU,MAAM,iBAAiB,KAAK;aAC3E,iBAAiB,OAAO,IAAI;QACjC,iBAAiB;IACnB,GACA;QAAC;KAAc;IAGjB,qBACE,gCAAC,CAAA,GAAA,yCAAiB,EAAE;QAClB,OAAO;YACL,IAAI;YACJ,UAAA;YACA,YAAA;YACA,cAAA;YACA,eAAA;YACA,mBAAmB,SAAC,GAAG;uBAAM,aAAa,GAAG;;YAC7C,YAAY;YACZ,UAAA;YACA,UAAA;YACA,eAAA;YACA,eAAA;QACF;kBAEC,MAAM,IAAI,SAAC;iCACV,gCAAC,CAAA,GAAA,yCAAO;gBAEN,IAAI;gBACJ,WAAW;gBACX,gBAAgB;gBAChB,WAAW;gBACX,mBAAmB;gBACnB,mBAAmB;eANd;;;AAWf;AAEA,0CAAY,cAAc;;;;;;;;;;;","sources":["src/main.ts","src/components/index.ts","src/components/TreeNode.tsx","src/functions/getAncestors.tsx","src/components/TreeOfNodesContext.ts","src/components/WordEntry.tsx","src/components/TreeOfNodes.tsx","src/functions/checkExpandedNodes.ts","src/functions/index.ts"],"sourcesContent":["export * from './components';\nexport * from './functions';\n","import { TreeNode } from './TreeNode';\nimport { TreeOfNodes } from './TreeOfNodes';\nimport { iNodeUpdate, TreeNodeBase, TreeNodeData } from './interface';\nimport { WordEntry } from './WordEntry';\n\nexport { TreeNode, TreeOfNodes, WordEntry };\nexport type { TreeNodeBase, TreeNodeData, iNodeUpdate };\n","import { ContextMenuHandler, iMenuItem } from '@asup/context-menu';\nimport { Key, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n CaretDownFill,\n CaretRight,\n CaretRightFill,\n ExclamationCircleFill,\n} from 'react-bootstrap-icons';\nimport { getAncestors } from '../functions/getAncestors';\nimport { iNodeUpdate } from './interface';\nimport { TreeOfNodesContext } from './TreeOfNodesContext';\nimport { WordEntry } from './WordEntry';\n\ninterface TreeNodeProps {\n id: Key;\n indentLevel?: number;\n canRemove?: boolean;\n canRename?: boolean;\n canAddChildren?: boolean;\n canRemoveChildren?: boolean;\n canRenameChildren?: boolean;\n refresh?: () => void;\n}\n\nexport const TreeNode = ({\n id,\n canRemove,\n canRename,\n canAddChildren,\n canRemoveChildren,\n canRenameChildren,\n}: TreeNodeProps): JSX.Element => {\n // Contexts\n const treeContext = useContext(TreeOfNodesContext);\n\n // Node information\n const thisNode = useMemo(\n () => treeContext?.nodeList.find((n) => n.id === id),\n [id, treeContext?.nodeList],\n );\n const childNodes = useMemo(\n () => treeContext?.nodeList.filter((n) => n.parentId === id),\n [id, treeContext?.nodeList],\n );\n\n // State\n const [error, setError] = useState<boolean>(false);\n const [errorText, setErrotText] = useState<string | null>(null);\n const expanded = useMemo(() => {\n return (treeContext?.expandedNodes.findIndex((e) => e === id) ?? -1) > -1;\n }, [id, treeContext?.expandedNodes]);\n\n // // Apply selected borer\n const currentBorder = useMemo<string>(() => {\n return id === treeContext?.selectedId ? '1px solid black' : '';\n }, [id, treeContext?.selectedId]);\n const nodeColour = useMemo<string | undefined>(() => {\n if (treeContext && treeContext.selectedId) {\n const anc = getAncestors(treeContext.selectedId, [], treeContext?.nodeList).map((n) => n.id);\n if ([...anc, treeContext.selectedId].includes(id)) return treeContext.nodeHighlight;\n }\n return;\n }, [id, treeContext]);\n\n // New node parameters\n const newNameRef = useRef<HTMLInputElement | null>(null);\n const [showNewNode, setShowNewNode] = useState<boolean>(false);\n const [savingNewNode, setSavingNewNode] = useState<boolean>(false);\n\n // Rename parameters\n const currentNameRef = useRef<HTMLInputElement | null>(null);\n const [renaming, setRenaming] = useState<boolean>(false);\n const [updatingNode, setUpdatingNode] = useState<boolean>(false);\n\n // Context functions\n const handleReturn = useCallback((ret: iNodeUpdate) => {\n if (!ret.success) {\n setError(true);\n setErrotText(ret.ErrorText ?? 'An unknown error has occured');\n } else {\n setError(false);\n setErrotText(null);\n }\n }, []);\n\n const confirmNewNode = useCallback(\n async (label: string) => {\n setSavingNewNode(true);\n if (treeContext?.onAddChild) {\n handleReturn(await treeContext.onAddChild(id, label));\n }\n setSavingNewNode(false);\n setShowNewNode(false);\n },\n [handleReturn, id, treeContext],\n );\n\n const renameNode = useCallback(\n async (newLabel: string) => {\n setRenaming(false);\n if (treeContext?.onRename) {\n setUpdatingNode(true);\n handleReturn(await treeContext.onRename(id, newLabel));\n setUpdatingNode(false);\n }\n },\n [handleReturn, id, treeContext],\n );\n\n const deleteThis = useCallback(async () => {\n if (treeContext?.onRemove) {\n setUpdatingNode(true);\n handleReturn(await treeContext.onRemove(id));\n setUpdatingNode(false);\n }\n }, [handleReturn, id, treeContext]);\n\n // Context actions\n const addChild = useCallback(() => {\n setShowNewNode(true);\n treeContext && treeContext.handleExpandClick(id, true);\n }, [id, treeContext]);\n useEffect(() => {\n if (showNewNode === true && newNameRef.current) newNameRef.current.focus();\n }, [showNewNode]);\n const renameThis = useCallback(() => {\n setRenaming(true);\n treeContext?.handleSelect(id);\n }, [id, treeContext]);\n\n // Context menu\n const menuItems = useMemo(() => {\n const menuItems: iMenuItem[] = [];\n if (canAddChildren) {\n menuItems.push({ label: 'Add', action: addChild });\n }\n if (canRename) {\n menuItems.push({ label: 'Rename', action: renameThis });\n }\n if (canRemove && (childNodes === undefined || childNodes.length === 0)) {\n menuItems.push({ label: 'Delete', action: deleteThis });\n }\n return menuItems;\n }, [addChild, canAddChildren, canRemove, canRename, childNodes, deleteThis, renameThis]);\n\n // Return node\n if (!treeContext) return <></>;\n return (\n <ContextMenuHandler menuItems={menuItems}>\n <div\n id={`${treeContext.id}-treenode-${id}`}\n className='treenode'\n >\n {error ? (\n <>\n <ExclamationCircleFill color='var(--bs-danger)' />{' '}\n {errorText && errorText !== '' ? errorText : 'An unknown error has occured'}\n </>\n ) : (\n <span>\n {childNodes !== undefined && childNodes.length > 0 ? (\n !expanded ? (\n <CaretRightFill\n id={`${treeContext.id}-treenode-caret-${id}`}\n role='button'\n color={nodeColour}\n aria-expanded={false}\n onClick={() => treeContext.handleExpandClick(id)}\n />\n ) : (\n <CaretDownFill\n id={`${treeContext.id}-treenode-caret-${id}`}\n role='button'\n aria-expanded={true}\n color={nodeColour}\n onClick={() => {\n treeContext.handleExpandClick(id);\n }}\n />\n )\n ) : (\n <CaretRight\n id={`${treeContext.id}-treenode-caret-${id}`}\n role='button'\n color={nodeColour}\n aria-expanded={false}\n aria-disabled={true}\n />\n )}\n {thisNode && (\n <div\n style={{ display: 'inline-block' }}\n onContextMenuCapture={() => treeContext.handleSelect(id)}\n onClickCapture={() => treeContext.handleSelect(id)}\n onFocusCapture={() => treeContext.handleSelect(id)}\n >\n <WordEntry\n id={`${treeContext.id}-treenode-entry-${id}`}\n ref={currentNameRef}\n value={thisNode.label}\n editing={renaming}\n saving={updatingNode}\n setValue={(ret) => renameNode(ret)}\n sendEscape={() => setRenaming(false)}\n style={{\n border: currentBorder,\n margin: currentBorder === '' ? '1px' : '',\n backgroundColor: currentBorder === '' ? '' : treeContext.textHighlight,\n }}\n />\n </div>\n )}\n </span>\n )}\n {childNodes !== undefined &&\n childNodes.map((h) => (\n <span\n key={h.id}\n id={`${treeContext.id}-treenode-child-${h.id}`}\n style={{\n marginLeft: '16px',\n display: 'block',\n maxHeight: expanded ? '99999px' : '0px',\n height: expanded ? 'auto' : '0px',\n overflowY: 'hidden',\n visibility: expanded ? 'inherit' : 'hidden',\n opacity: expanded ? 1 : 0,\n transition: 'visibility .3s, opacity .3s ease-in-out, max-height 0.3s ease-in-out',\n }}\n >\n <TreeNode\n id={h.id}\n canRemove={canRemoveChildren}\n canRename={canRenameChildren}\n canAddChildren={canAddChildren}\n canRemoveChildren={canRemoveChildren}\n canRenameChildren={canRenameChildren}\n />\n </span>\n ))}\n {showNewNode && (\n <div>\n <WordEntry\n style={{ marginLeft: '14px' }}\n id={`treenode-new-${id}`}\n ref={newNameRef}\n editing={true}\n setValue={(ret) => {\n confirmNewNode(ret);\n }}\n saving={savingNewNode}\n sendEscape={() => {\n setShowNewNode(false);\n }}\n />\n </div>\n )}\n </div>\n </ContextMenuHandler>\n );\n};\n\nTreeNode.displayName = 'TreeNode';\n","import { Key } from 'react';\nimport { TreeNodeBase } from '../components/interface';\n\nexport const getAncestors = (\n id: Key,\n included: TreeNodeBase[],\n hierarchyNodes: TreeNodeBase[],\n): TreeNodeBase[] => {\n // Get current node\n const current = hierarchyNodes.find((h) => h.id === id);\n if (current === undefined) return [];\n // Get parent node\n const parent = hierarchyNodes.find((h) => h.id === current.parentId);\n // Stop if no more parents\n return parent === undefined\n ? included\n : getAncestors(\n parent.id,\n [...included.filter((i) => i.id !== parent.id), parent],\n hierarchyNodes,\n );\n};\n","import { createContext, Key } from 'react';\nimport { iNodeUpdate, TreeNodeData } from './interface';\n\nexport interface TreeOfNodesContextProps<T> {\n id: string;\n nodeList: TreeNodeData<T>[];\n selectedId?: Key;\n handleSelect: (ret: Key) => void;\n expandedNodes: Key[];\n handleExpandClick: (ret: Key, force?: boolean) => void;\n onAddChild?: (parentId: Key, newName: string) => Promise<iNodeUpdate>;\n onRename?: (id: Key, newName: string) => Promise<iNodeUpdate>;\n onRemove?: (id: Key) => Promise<iNodeUpdate>;\n nodeHighlight: string;\n textHighlight: string;\n}\n\nexport const TreeOfNodesContext = createContext<TreeOfNodesContextProps<unknown> | undefined>(\n undefined,\n);\n","import React, { Key, useCallback, useEffect, useMemo, useState } from 'react';\nimport { Spinner } from 'react-bootstrap';\n\ninterface WordEntryProps {\n id: Key;\n value?: string;\n editing?: boolean;\n saving?: boolean;\n setValue?: (ret: string) => void;\n sendEscape?: () => void;\n style?: React.CSSProperties;\n}\n\nexport const WordEntry = React.forwardRef<HTMLInputElement, WordEntryProps>(\n ({ id, value, editing, saving, setValue, sendEscape, style }, ref): JSX.Element => {\n WordEntry.displayName = 'WordEntry';\n const currentStyle = useMemo<React.CSSProperties>(() => {\n return {\n display: 'inline-block',\n padding: '1px',\n paddingLeft: '3px',\n paddingRight: '3px',\n border: '1px',\n borderRadius: '3px',\n ...style,\n };\n }, [style]);\n\n const [currentValue, setCurrentValue] = useState<string>(value ?? '');\n useEffect(() => {\n setCurrentValue(value ?? '');\n }, [value]);\n\n const returnData = useCallback(() => {\n setValue && setValue(currentValue);\n }, [currentValue, setValue]);\n\n const keyPress = useCallback(\n (e: React.KeyboardEvent) => {\n if (e.code === 'Escape') {\n setCurrentValue(value ?? '');\n sendEscape && sendEscape();\n } else if (e.code === 'Enter') {\n returnData();\n }\n },\n [returnData, sendEscape, value],\n );\n\n // Simple if not editing\n if (!editing) {\n return (\n <span\n style={currentStyle}\n id={String(id)}\n >\n {value}\n </span>\n );\n }\n\n return (\n <div\n style={currentStyle}\n id={`${id}-holder`}\n >\n {saving && (\n <Spinner\n id={`${id}-spinner`}\n size='sm'\n animation='border'\n />\n )}\n <input\n autoFocus\n id={String(id)}\n ref={ref}\n type='text'\n style={{\n lineHeight: '0.75rem',\n border: '1px dotted black',\n width: 'auto',\n minWidth: '0',\n }}\n value={currentValue}\n disabled={saving}\n onChange={(e) => setCurrentValue(e.currentTarget.value)}\n onBlur={returnData}\n onKeyDownCapture={keyPress}\n />\n </div>\n );\n },\n);\n\nWordEntry.displayName = 'WordEntry';\n","import { Key, useCallback, useEffect, useState } from 'react';\nimport { checkExpandedNodes } from '../functions/checkExpandedNodes';\nimport { iNodeUpdate, TreeNodeData } from './interface';\nimport { TreeNode } from './TreeNode';\nimport { TreeOfNodesContext } from './TreeOfNodesContext';\n\ninterface TreeOfNodesProps<T> {\n id: string;\n nodeList: TreeNodeData<T>[];\n roots: Key[];\n selectedId?: Key;\n handleSelect?: (ret: Key) => void;\n onAdd?: (parentId: Key, newName: string) => Promise<iNodeUpdate>;\n onRename?: (childId: Key, newName: string) => Promise<iNodeUpdate>;\n onRemove?: (childId: Key) => Promise<iNodeUpdate>;\n canAddRoot?: boolean;\n canRemoveRoot?: boolean;\n canRenameRoot?: boolean;\n canAddChildren?: boolean;\n canRemoveChildren?: boolean;\n canRenameChildren?: boolean;\n nodeHighlight?: string;\n textHighlight?: string;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint\nexport const TreeOfNodes = <T extends unknown>({\n id,\n nodeList,\n roots,\n // canAddRoot = false,\n canRemoveRoot = false,\n canRenameRoot = false,\n canAddChildren = false,\n canRemoveChildren = false,\n canRenameChildren = false,\n selectedId,\n handleSelect = () => {\n return;\n },\n onAdd,\n onRename,\n onRemove,\n nodeHighlight = 'red',\n textHighlight = 'rgba(255, 0, 0, 0.2)',\n}: TreeOfNodesProps<T>) => {\n const [expandedNodes, setExpandedNodes] = useState<Key[]>([]);\n useEffect(() => {\n if (selectedId) {\n // Check all nodes are showing that should be\n const shouldExpand = checkExpandedNodes(nodeList, selectedId, expandedNodes);\n shouldExpand.filter((n) => !expandedNodes.includes(n)).length > 0 &&\n setExpandedNodes(shouldExpand);\n }\n }, [expandedNodes, nodeList, selectedId]);\n\n // Change expansion and update contexts\n const changeExpand = useCallback(\n (eKey: Key, force?: boolean) => {\n const newExpandedNodes = [...expandedNodes];\n const ix = newExpandedNodes.findIndex((nKey) => nKey === eKey);\n if ((ix === -1 && force === undefined) || force === true) newExpandedNodes.push(eKey);\n else newExpandedNodes.splice(ix, 1);\n setExpandedNodes(newExpandedNodes);\n },\n [expandedNodes],\n );\n\n return (\n <TreeOfNodesContext.Provider\n value={{\n id: id,\n nodeList,\n selectedId,\n handleSelect,\n expandedNodes,\n handleExpandClick: (r, f) => changeExpand(r, f),\n onAddChild: onAdd,\n onRename,\n onRemove,\n nodeHighlight,\n textHighlight,\n }}\n >\n {roots.map((r) => (\n <TreeNode\n key={r}\n id={r}\n canRemove={canRemoveRoot}\n canAddChildren={canAddChildren}\n canRename={canRenameRoot}\n canRemoveChildren={canRemoveChildren}\n canRenameChildren={canRenameChildren}\n />\n ))}\n </TreeOfNodesContext.Provider>\n );\n};\n\nTreeOfNodes.displayName = 'TreeOfNodes';\n","import { TreeNodeBase } from 'components';\nimport { Key } from 'react';\nimport { getAncestors } from './getAncestors';\n\nexport const checkExpandedNodes = (\n nodeList: TreeNodeBase[],\n selectedId: Key,\n expandedNodes: Key[],\n): Key[] => {\n return [\n ...expandedNodes,\n ...getAncestors(selectedId, [], nodeList)\n .map((n) => n.id)\n .filter((k) => !expandedNodes.includes(k)),\n ].sort((a, b) => `${a}`.localeCompare(`${b}`));\n};\n","import { getAncestors } from './getAncestors';\n\nexport { getAncestors as getParents };\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AGGO,IAAM,4CAAe,SAC1B,IACA,UACA;IAEA,IAAM,aAAa,MAAM,QAAQ,MAAM,KAAK;QAAC;KAAG;IAEhD,IAAM,UAAU,WACb,IAAI,SAAC;eAAM,eAAe,KAAK,SAAC;mBAAM,EAAE,OAAO;;OAC/C,OAAO,SAAC;eAAM,MAAM;;IACvB,IAAI,QAAQ,WAAW,GAAG,OAAO;IAEjC,IAAM,UAAU,AACd,QACG,IAAI,SAAC;eAAM,EAAE;OACb,IAAI,SAAC;eAAQ,eAAe,KAAK,SAAC;mBAAM,QAAQ,EAAE;;OACrD,OAAO,SAAC;eAAM,MAAM;;IACtB,IAAI,QAAQ,WAAW,GAAG,OAAO;SAE/B,OAAO,0CACL,QAAQ,IAAI,SAAC;eAAM,EAAE;QACrB,AAA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qBACE,gCAAC,CAAA,GAAA,yCAAiB,EAAE;QAClB,OAAO;YACL,IAAI;YACJ,UAAA;YACA,UAAU;YACV,cAAA;YACA,cAAA;YACA,eAAA;YACA,mBAAmB,SAAC,GAAG;uBAAM,aAAa,GAAG;;YAC7C,YAAY;YACZ,UAAA;YACA,UAAA;YACA,eAAA;YACA,eAAA;YACA,YAAA;QACF;kBAEC,MAAM,IAAI,SAAC;iCACV,gCAAC,CAAA,GAAA,yCAAO;gBAEN,IAAI;gBACJ,WAAW;gBACX,gBAAgB;gBAChB,WAAW;gBACX,mBAAmB;gBACnB,mBAAmB;eANd;;;AAWf;AAEA,0CAAY,cAAc;;;;;;;;;;;","sources":["src/main.ts","src/components/index.ts","src/components/TreeNode.tsx","src/functions/getAncestors.tsx","src/functions/getDescendentIds.ts","src/components/TreeOfNodesContext.ts","src/components/WordEntry.tsx","src/components/TreeOfNodes.tsx","src/functions/checkExpandedNodes.ts","src/functions/index.ts"],"sourcesContent":["export * from './components';\nexport * from './functions';\n","import { TreeNode } from './TreeNode';\nimport { TreeOfNodes } from './TreeOfNodes';\nimport { iNodeUpdate, TreeNodeBase, TreeNodeData } from './interface';\nimport { WordEntry } from './WordEntry';\n\nexport { TreeNode, TreeOfNodes, WordEntry };\nexport type { TreeNodeBase, TreeNodeData, iNodeUpdate };\n","import { ContextMenuHandler, iMenuItem } from '@asup/context-menu';\nimport { Key, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n CaretDownFill,\n CaretRight,\n CaretRightFill,\n ExclamationCircleFill,\n} from 'react-bootstrap-icons';\nimport { getAncestors } from '../functions/getAncestors';\nimport { getDescendentIds } from '../functions/getDescendentIds';\nimport './TreeNode.css';\nimport { TreeOfNodesContext } from './TreeOfNodesContext';\nimport { WordEntry } from './WordEntry';\nimport { iNodeUpdate } from './interface';\n\ninterface TreeNodeProps {\n id: Key;\n indentLevel?: number;\n canRemove?: boolean;\n canRename?: boolean;\n canAddChildren?: boolean;\n canRemoveChildren?: boolean;\n canRenameChildren?: boolean;\n refresh?: () => void;\n}\n\nexport const TreeNode = ({\n id,\n canRemove,\n canRename,\n canAddChildren,\n canRemoveChildren,\n canRenameChildren,\n}: TreeNodeProps): JSX.Element => {\n // Contexts\n const treeContext = useContext(TreeOfNodesContext);\n\n // Node information\n const thisNode = useMemo(\n () => treeContext?.nodeList.find((n) => n.id === id),\n [id, treeContext?.nodeList],\n );\n const childNodes = useMemo(\n () => treeContext?.nodeList.filter((n) => n.parentId === id),\n [id, treeContext?.nodeList],\n );\n const descendents = useMemo(\n () => getDescendentIds(id, treeContext?.nodeList ?? []),\n [id, treeContext],\n );\n\n // State\n const [error, setError] = useState<boolean>(false);\n const [errorText, setErrotText] = useState<string>('');\n const expanded = useMemo(() => {\n return (treeContext?.expandedNodes.findIndex((e) => e === id) ?? -1) > -1;\n }, [id, treeContext?.expandedNodes]);\n\n // Checkbox\n const checkRef = useRef<HTMLInputElement | null>(null);\n useEffect(() => {\n if (checkRef.current) {\n if (treeContext?.selected.includes(id)) {\n checkRef.current.checked = true;\n checkRef.current.indeterminate = false;\n } else if (descendents.some((d) => treeContext?.selected.includes(d))) {\n checkRef.current.checked = false;\n checkRef.current.indeterminate = true;\n } else {\n checkRef.current.checked = false;\n checkRef.current.indeterminate = false;\n }\n }\n }, [descendents, id, treeContext?.selected]);\n\n // Apply selected border\n const currentBorder = useMemo<string>(() => {\n return treeContext?.selected.includes(id) ? '1px solid black' : '';\n }, [id, treeContext?.selected]);\n const nodeColour = useMemo<string | undefined>(() => {\n if (treeContext && treeContext.selected) {\n const anc = getAncestors(treeContext.selected, [], treeContext?.nodeList).map((n) => n.id);\n if ([...anc, treeContext.selected].includes(id)) return treeContext.nodeHighlight;\n }\n return;\n }, [id, treeContext]);\n\n // New node parameters\n const newNameRef = useRef<HTMLInputElement | null>(null);\n const [showNewNode, setShowNewNode] = useState<boolean>(false);\n const [savingNewNode, setSavingNewNode] = useState<boolean>(false);\n\n // Rename parameters\n const currentNameRef = useRef<HTMLInputElement | null>(null);\n const [renaming, setRenaming] = useState<boolean>(false);\n const [updatingNode, setUpdatingNode] = useState<boolean>(false);\n\n // Context functions\n const handleReturn = useCallback((ret: iNodeUpdate) => {\n if (!ret.success) {\n setError(true);\n setErrotText(ret.ErrorText ?? 'An unknown error has occured');\n } else {\n setError(false);\n setErrotText('');\n }\n }, []);\n\n const confirmNewNode = useCallback(\n async (label: string) => {\n setSavingNewNode(true);\n if (treeContext?.onAddChild) {\n handleReturn(await treeContext.onAddChild(id, label));\n }\n setSavingNewNode(false);\n setShowNewNode(false);\n },\n [handleReturn, id, treeContext],\n );\n\n const renameNode = useCallback(\n async (newLabel: string) => {\n setRenaming(false);\n if (treeContext?.onRename) {\n setUpdatingNode(true);\n handleReturn(await treeContext.onRename(id, newLabel));\n setUpdatingNode(false);\n }\n },\n [handleReturn, id, treeContext],\n );\n\n const deleteThis = useCallback(async () => {\n if (treeContext?.onRemove) {\n setUpdatingNode(true);\n handleReturn(await treeContext.onRemove(id));\n setUpdatingNode(false);\n }\n }, [handleReturn, id, treeContext]);\n\n // Context actions\n const addChild = useCallback(() => {\n setShowNewNode(true);\n treeContext && treeContext.handleExpandClick(id, true);\n }, [id, treeContext]);\n useEffect(() => {\n if (showNewNode === true && newNameRef.current) newNameRef.current.focus();\n }, [showNewNode]);\n const renameThis = useCallback(() => {\n setRenaming(true);\n treeContext?.handleSelect(id);\n }, [id, treeContext]);\n\n // Context menu\n const menuItems = useMemo(() => {\n const menuItems: iMenuItem[] = [];\n if (canAddChildren) {\n menuItems.push({ label: 'Add', action: addChild });\n }\n if (canRename) {\n menuItems.push({ label: 'Rename', action: renameThis });\n }\n if (canRemove && (childNodes === undefined || childNodes.length === 0)) {\n menuItems.push({ label: 'Delete', action: deleteThis });\n }\n return menuItems;\n }, [addChild, canAddChildren, canRemove, canRename, childNodes, deleteThis, renameThis]);\n\n // Return node\n if (!treeContext) return <></>;\n return (\n <ContextMenuHandler menuItems={menuItems}>\n <div\n id={`${treeContext.id}-treenode-${id}`}\n className='treenode'\n >\n {error ? (\n <>\n <ExclamationCircleFill color='var(--bs-danger)' /> {errorText}\n </>\n ) : (\n <div className='ton-node'>\n {treeContext.showCheckBox && (\n <input\n ref={checkRef}\n type='checkbox'\n role='checkbox'\n className='ton-checkbox'\n id={`${treeContext.id}-treenode-checkbox-${id}`}\n onClick={() => {\n treeContext.handleSelect(descendents);\n }}\n />\n )}\n {childNodes !== undefined && childNodes.length > 0 ? (\n !expanded ? (\n <CaretRightFill\n id={`${treeContext.id}-treenode-caret-${id}`}\n className='ton-expander'\n role='button'\n color={nodeColour}\n aria-expanded={false}\n aria-label='Expander'\n onClick={() => treeContext.handleExpandClick(id)}\n />\n ) : (\n <CaretDownFill\n id={`${treeContext.id}-treenode-caret-${id}`}\n className='ton-expander'\n role='button'\n aria-expanded={true}\n aria-label='Expander'\n color={nodeColour}\n onClick={() => {\n treeContext.handleExpandClick(id);\n }}\n />\n )\n ) : (\n <CaretRight\n id={`${treeContext.id}-treenode-caret-${id}`}\n className='ton-expander'\n role='button'\n color={nodeColour}\n aria-expanded={false}\n aria-label='Disabled expander'\n aria-disabled={true}\n />\n )}\n {thisNode && (\n <div\n style={{ display: 'inline-block' }}\n onContextMenuCapture={() => treeContext.handleSelect(id)}\n onClickCapture={() => treeContext.handleSelect(id)}\n onFocusCapture={() => treeContext.handleSelect(id)}\n >\n <WordEntry\n id={`${treeContext.id}-treenode-entry-${id}`}\n ref={currentNameRef}\n value={thisNode.label}\n editing={renaming}\n saving={updatingNode}\n setValue={(ret) => renameNode(ret)}\n sendEscape={() => setRenaming(false)}\n style={{\n border: currentBorder,\n margin: currentBorder === '' ? '1px' : '',\n backgroundColor: currentBorder === '' ? '' : treeContext.textHighlight,\n }}\n spellCheck={treeContext.spellCheck}\n />\n </div>\n )}\n </div>\n )}\n {childNodes !== undefined && (\n <div className={`ton-collapsible-wrapper ${expanded ? '' : 'collapsed'}`}>\n <div className='ton-collapsible'>\n {childNodes.map((h) => (\n <span\n key={h.id}\n id={`${treeContext.id}-treenode-child-${h.id}`}\n className='ton-child'\n >\n <TreeNode\n id={h.id}\n canRemove={canRemoveChildren}\n canRename={canRenameChildren}\n canAddChildren={canAddChildren}\n canRemoveChildren={canRemoveChildren}\n canRenameChildren={canRenameChildren}\n />\n </span>\n ))}\n </div>\n </div>\n )}\n {showNewNode && (\n <div>\n <WordEntry\n style={{ marginLeft: '14px' }}\n id={`treenode-new-${id}`}\n ref={newNameRef}\n editing={true}\n setValue={(ret) => {\n confirmNewNode(ret);\n }}\n saving={savingNewNode}\n sendEscape={() => {\n setShowNewNode(false);\n }}\n spellCheck={treeContext.spellCheck}\n />\n </div>\n )}\n </div>\n </ContextMenuHandler>\n );\n};\n\nTreeNode.displayName = 'TreeNode';\n","import { Key } from 'react';\nimport { TreeNodeBase } from '../components/interface';\n\nexport const getAncestors = (\n id: Key | Key[],\n included: TreeNodeBase[],\n hierarchyNodes: TreeNodeBase[],\n): TreeNodeBase[] => {\n const processIds = Array.isArray(id) ? id : [id];\n\n const current = processIds\n .map((i) => hierarchyNodes.find((h) => h.id === i))\n .filter((h) => h !== undefined) as TreeNodeBase[];\n if (current.length === 0) return included;\n\n const parents = (\n current\n .map((h) => h.parentId)\n .map((pid) => hierarchyNodes.find((h) => pid === h.id)) as TreeNodeBase[]\n ).filter((p) => p !== undefined) as TreeNodeBase[];\n if (parents.length === 0) return included;\n else\n return getAncestors(\n parents.map((p) => p.id),\n [...included, ...parents.filter((p) => !included.includes(p))],\n hierarchyNodes,\n );\n};\n","import { Key } from 'react';\nimport { TreeNodeBase } from '../components/interface';\n\nexport const getDescendentIds = (id: Key | Key[], hierarchyNodes: TreeNodeBase[]): Key[] => {\n const processIds = Array.isArray(id) ? id : [id];\n const newChildren = hierarchyNodes\n .filter(\n (h) =>\n h.parentId !== undefined && processIds.includes(h.parentId) && !processIds.includes(h.id),\n )\n .map((h) => h.id);\n return newChildren.length === 0\n ? processIds\n : getDescendentIds([...processIds, ...newChildren], hierarchyNodes);\n};\n","import { createContext, Key } from 'react';\nimport { iNodeUpdate, TreeNodeData } from './interface';\n\nexport interface TreeOfNodesContextProps<T> {\n id: string;\n nodeList: TreeNodeData<T>[];\n selected: Key[];\n showCheckBox: boolean;\n handleSelect: (ret: Key | Key[]) => void;\n expandedNodes: Key[];\n handleExpandClick: (ret: Key, force?: boolean) => void;\n onAddChild?: (parentId: Key, newName: string) => Promise<iNodeUpdate>;\n onRename?: (id: Key, newName: string) => Promise<iNodeUpdate>;\n onRemove?: (id: Key) => Promise<iNodeUpdate>;\n nodeHighlight: string;\n textHighlight: string;\n spellCheck?: 'true' | 'false';\n}\n\nexport const TreeOfNodesContext = createContext<TreeOfNodesContextProps<unknown> | undefined>(\n undefined,\n);\n","import React, { Key, useCallback, useEffect, useMemo, useState } from 'react';\nimport { Spinner } from 'react-bootstrap';\n\ninterface WordEntryProps {\n id: Key;\n value?: string;\n editing?: boolean;\n saving?: boolean;\n setValue?: (ret: string) => void;\n sendEscape?: () => void;\n style?: React.CSSProperties;\n spellCheck?: 'true' | 'false';\n}\n\nexport const WordEntry = React.forwardRef<HTMLInputElement, WordEntryProps>(\n (\n { id, value, editing, saving, setValue, sendEscape, style, spellCheck = 'true' },\n ref,\n ): JSX.Element => {\n WordEntry.displayName = 'WordEntry';\n const currentStyle = useMemo<React.CSSProperties>(() => {\n return {\n display: 'inline-block',\n padding: '1px',\n paddingLeft: '3px',\n paddingRight: '3px',\n border: '1px',\n borderRadius: '3px',\n ...style,\n };\n }, [style]);\n\n const [currentValue, setCurrentValue] = useState<string>(value ?? '');\n useEffect(() => {\n setCurrentValue(value ?? '');\n }, [value]);\n\n const returnData = useCallback(() => {\n setValue && setValue(currentValue);\n }, [currentValue, setValue]);\n\n const keyPress = useCallback(\n (e: React.KeyboardEvent) => {\n if (e.code === 'Escape') {\n setCurrentValue(value ?? '');\n sendEscape && sendEscape();\n } else if (e.code === 'Enter') {\n returnData();\n }\n },\n [returnData, sendEscape, value],\n );\n\n // Simple if not editing\n if (!editing) {\n return (\n <span\n style={currentStyle}\n id={`${id}`}\n >\n {value ? value : <> </>}\n </span>\n );\n }\n\n return (\n <div\n style={currentStyle}\n id={`${id}-holder`}\n >\n {saving && (\n <Spinner\n id={`${id}-spinner`}\n size='sm'\n animation='border'\n />\n )}\n <input\n autoFocus\n spellCheck={spellCheck}\n id={String(id)}\n ref={ref}\n type='text'\n style={{\n lineHeight: '0.75rem',\n border: '1px dotted black',\n width: 'auto',\n minWidth: '0',\n }}\n value={currentValue}\n disabled={saving}\n onChange={(e) => setCurrentValue(e.currentTarget.value)}\n onBlur={returnData}\n onKeyDownCapture={keyPress}\n />\n </div>\n );\n },\n);\n","import { Key, useCallback, useEffect, useMemo, useState } from 'react';\nimport { checkExpandedNodes } from '../functions/checkExpandedNodes';\nimport { iNodeUpdate, TreeNodeData } from './interface';\nimport { TreeNode } from './TreeNode';\nimport { TreeOfNodesContext } from './TreeOfNodesContext';\n\ninterface TreeOfNodesProps<T> {\n id: string;\n nodeList: TreeNodeData<T>[];\n roots: Key[];\n showCheckBox?: boolean;\n selected?: Key | Key[];\n handleSelect?: (ret: Key | Key[]) => void;\n onAdd?: (parentId: Key, newName: string) => Promise<iNodeUpdate>;\n onRename?: (childId: Key, newName: string) => Promise<iNodeUpdate>;\n onRemove?: (childId: Key) => Promise<iNodeUpdate>;\n canRemoveRoot?: boolean;\n canRenameRoot?: boolean;\n canAddChildren?: boolean;\n canRemoveChildren?: boolean;\n canRenameChildren?: boolean;\n nodeHighlight?: string;\n textHighlight?: string;\n spellCheck?: 'true' | 'false';\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint\nexport const TreeOfNodes = <T extends unknown>({\n id,\n nodeList,\n roots,\n selected = [],\n showCheckBox = false,\n handleSelect = () => {\n return;\n },\n onAdd,\n onRename,\n onRemove,\n canRemoveRoot = false,\n canRenameRoot = false,\n canAddChildren = false,\n canRemoveChildren = false,\n canRenameChildren = false,\n nodeHighlight = 'red',\n textHighlight = 'rgba(255, 0, 0, 0.2)',\n spellCheck = 'true',\n}: TreeOfNodesProps<T>) => {\n const [expandedNodes, setExpandedNodes] = useState<Key[]>([]);\n const selectedArray = useMemo(\n () => (Array.isArray(selected) ? selected : [selected]),\n [selected],\n );\n useEffect(() => {\n if (selectedArray.length > 0) {\n // Check all nodes are showing that should be\n const shouldExpand = checkExpandedNodes(nodeList, selectedArray, expandedNodes);\n shouldExpand.filter((n) => !expandedNodes.includes(n)).length > 0 &&\n setExpandedNodes(shouldExpand);\n }\n }, [expandedNodes, nodeList, selectedArray]);\n\n // Change expansion and update contexts\n const changeExpand = useCallback(\n (eKey: Key, force?: boolean) => {\n const newExpandedNodes = [...expandedNodes];\n const ix = newExpandedNodes.findIndex((nKey) => nKey === eKey);\n if ((ix === -1 && force === undefined) || force === true) newExpandedNodes.push(eKey);\n else newExpandedNodes.splice(ix, 1);\n setExpandedNodes(newExpandedNodes);\n },\n [expandedNodes],\n );\n\n return (\n <TreeOfNodesContext.Provider\n value={{\n id: id,\n nodeList,\n selected: selectedArray,\n showCheckBox,\n handleSelect,\n expandedNodes,\n handleExpandClick: (r, f) => changeExpand(r, f),\n onAddChild: onAdd,\n onRename,\n onRemove,\n nodeHighlight,\n textHighlight,\n spellCheck,\n }}\n >\n {roots.map((r) => (\n <TreeNode\n key={r}\n id={r}\n canRemove={canRemoveRoot}\n canAddChildren={canAddChildren}\n canRename={canRenameRoot}\n canRemoveChildren={canRemoveChildren}\n canRenameChildren={canRenameChildren}\n />\n ))}\n </TreeOfNodesContext.Provider>\n );\n};\n\nTreeOfNodes.displayName = 'TreeOfNodes';\n","import { TreeNodeBase } from 'components';\nimport { Key } from 'react';\nimport { getAncestors } from './getAncestors';\n\nexport const checkExpandedNodes = (\n nodeList: TreeNodeBase[],\n selected: Key | Key[],\n expandedNodes: Key[],\n): Key[] => {\n return [\n ...expandedNodes,\n ...getAncestors(selected, [], nodeList)\n .map((n) => n.id)\n .filter((k) => !expandedNodes.includes(k)),\n ].sort((a, b) => `${a}`.localeCompare(`${b}`));\n};\n","import { getAncestors } from './getAncestors';\n\nexport { getAncestors as getParents };\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/main.css
CHANGED
|
@@ -1,10 +1,57 @@
|
|
|
1
|
-
.
|
|
1
|
+
.ton-checkbox {
|
|
2
2
|
margin-top: 3px;
|
|
3
3
|
margin-right: 3px;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
.
|
|
6
|
+
.ton-expander {
|
|
7
7
|
margin-bottom: 4px;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
.ton-child {
|
|
11
|
+
opacity: 1;
|
|
12
|
+
margin-left: 16px;
|
|
13
|
+
transition: opacity .6s linear;
|
|
14
|
+
display: block;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.ton-collapsible-wrapper {
|
|
18
|
+
display: flex;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.ton-collapsible-wrapper:after {
|
|
23
|
+
content: "";
|
|
24
|
+
height: 20px;
|
|
25
|
+
max-height: 0;
|
|
26
|
+
transition: height .3s linear, max-height 0s linear .3s;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.ton-collapsible {
|
|
30
|
+
max-height: 10000px;
|
|
31
|
+
margin-bottom: 0;
|
|
32
|
+
transition: margin-bottom .3s cubic-bezier(0, 0, 0, 1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.ton-collapsible-wrapper.collapsed > .ton-collapsible {
|
|
36
|
+
visibility: hidden;
|
|
37
|
+
max-height: 0;
|
|
38
|
+
margin-bottom: -2000px;
|
|
39
|
+
transition: margin-bottom .3s cubic-bezier(1, 0, 1, 1), visibility 0s .3s, max-height 0s .3s;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.ton-collapsible-wrapper.collapsed:after {
|
|
43
|
+
height: 0;
|
|
44
|
+
max-height: 20px;
|
|
45
|
+
transition: height .3s linear;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.ton-collapsible-wrapper.collapsed {
|
|
49
|
+
visibility: hidden;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.ton-collapsible-wrapper.collapsed .ton-child {
|
|
53
|
+
opacity: 0;
|
|
54
|
+
transition: opacity .6s linear;
|
|
55
|
+
}
|
|
56
|
+
|
|
10
57
|
/*# sourceMappingURL=main.css.map */
|
package/dist/main.css.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA;;;;;AAKA","sources":["src/components/TreeNode.css"],"sourcesContent":[".
|
|
1
|
+
{"mappings":"AAAA;;;;;AAKA;;;;AAIA;;;;;;;AAOA;;;;;AAIA;;;;;;;AAMA;;;;;;AAKA;;;;;;;AAMA;;;;;;AAKA;;;;AAGA","sources":["src/components/TreeNode.css"],"sourcesContent":[".ton-checkbox {\n margin-right: 3px;\n margin-top: 3px;\n}\n\n.ton-expander {\n margin-bottom: 4px;\n}\n\n.ton-child {\n margin-left: 16px;\n display: block;\n opacity: 1;\n transition: opacity 0.6s linear;\n}\n\n.ton-collapsible-wrapper {\n display: flex;\n overflow: hidden;\n}\n.ton-collapsible-wrapper:after {\n content: '';\n height: 20px;\n transition: height 0.3s linear, max-height 0s 0.3s linear;\n max-height: 0px;\n}\n.ton-collapsible {\n transition: margin-bottom 0.3s cubic-bezier(0, 0, 0, 1);\n margin-bottom: 0;\n max-height: 10000px;\n}\n.ton-collapsible-wrapper.collapsed > .ton-collapsible {\n margin-bottom: -2000px;\n transition: margin-bottom 0.3s cubic-bezier(1, 0, 1, 1), visibility 0s 0.3s, max-height 0s 0.3s;\n visibility: hidden;\n max-height: 0;\n}\n.ton-collapsible-wrapper.collapsed:after {\n height: 0;\n transition: height 0.3s linear;\n max-height: 20px;\n}\n.ton-collapsible-wrapper.collapsed {\n visibility: hidden;\n}\n.ton-collapsible-wrapper.collapsed .ton-child {\n opacity: 0;\n transition: opacity 0.6s linear;\n}\n"],"names":[],"version":3,"file":"main.css.map"}
|
package/dist/main.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import "./main.css";
|
|
1
2
|
import {jsx as $duWW8$jsx, Fragment as $duWW8$Fragment, jsxs as $duWW8$jsxs} from "react/jsx-runtime";
|
|
2
3
|
import {ContextMenuHandler as $duWW8$ContextMenuHandler} from "@asup/context-menu";
|
|
3
|
-
import $duWW8$react, {useContext as $duWW8$useContext, useMemo as $duWW8$useMemo, useState as $duWW8$useState, useRef as $duWW8$useRef,
|
|
4
|
+
import $duWW8$react, {useContext as $duWW8$useContext, useMemo as $duWW8$useMemo, useState as $duWW8$useState, useRef as $duWW8$useRef, useEffect as $duWW8$useEffect, useCallback as $duWW8$useCallback, createContext as $duWW8$createContext} from "react";
|
|
4
5
|
import {ExclamationCircleFill as $duWW8$ExclamationCircleFill, CaretRightFill as $duWW8$CaretRightFill, CaretDownFill as $duWW8$CaretDownFill, CaretRight as $duWW8$CaretRight} from "react-bootstrap-icons";
|
|
5
6
|
import {Spinner as $duWW8$Spinner} from "react-bootstrap";
|
|
6
7
|
|
|
@@ -17,27 +18,41 @@ $parcel$export($b65191f6d0a0a991$exports, "WordEntry", function () { return $847
|
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
const $6303f0814ed0ce8b$export$c6fd3ab3f44300d0 = (id, included, hierarchyNodes)=>{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
const processIds = Array.isArray(id) ? id : [
|
|
22
|
+
id
|
|
23
|
+
];
|
|
24
|
+
const current = processIds.map((i)=>hierarchyNodes.find((h)=>h.id === i)).filter((h)=>h !== undefined);
|
|
25
|
+
if (current.length === 0) return included;
|
|
26
|
+
const parents = current.map((h)=>h.parentId).map((pid)=>hierarchyNodes.find((h)=>pid === h.id)).filter((p)=>p !== undefined);
|
|
27
|
+
if (parents.length === 0) return included;
|
|
28
|
+
else return $6303f0814ed0ce8b$export$c6fd3ab3f44300d0(parents.map((p)=>p.id), [
|
|
29
|
+
...included,
|
|
30
|
+
...parents.filter((p)=>!included.includes(p))
|
|
31
|
+
], hierarchyNodes);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
const $33abc00b1ca5c55c$export$bd923365b402cb04 = (id, hierarchyNodes)=>{
|
|
36
|
+
const processIds = Array.isArray(id) ? id : [
|
|
37
|
+
id
|
|
38
|
+
];
|
|
39
|
+
const newChildren = hierarchyNodes.filter((h)=>h.parentId !== undefined && processIds.includes(h.parentId) && !processIds.includes(h.id)).map((h)=>h.id);
|
|
40
|
+
return newChildren.length === 0 ? processIds : $33abc00b1ca5c55c$export$bd923365b402cb04([
|
|
41
|
+
...processIds,
|
|
42
|
+
...newChildren
|
|
29
43
|
], hierarchyNodes);
|
|
30
44
|
};
|
|
31
45
|
|
|
32
46
|
|
|
33
47
|
|
|
48
|
+
|
|
34
49
|
const $886f402bccb0fd30$export$29ec378200e05207 = (0, $duWW8$createContext)(undefined);
|
|
35
50
|
|
|
36
51
|
|
|
37
52
|
|
|
38
53
|
|
|
39
54
|
|
|
40
|
-
const $84765747a8c6bfe2$export$14f190ac910bde69 = /*#__PURE__*/ (0, $duWW8$react).forwardRef(({ id: id, value: value, editing: editing, saving: saving, setValue: setValue, sendEscape: sendEscape, style: style }, ref)=>{
|
|
55
|
+
const $84765747a8c6bfe2$export$14f190ac910bde69 = /*#__PURE__*/ (0, $duWW8$react).forwardRef(({ id: id, value: value, editing: editing, saving: saving, setValue: setValue, sendEscape: sendEscape, style: style, spellCheck: spellCheck = "true" }, ref)=>{
|
|
41
56
|
$84765747a8c6bfe2$export$14f190ac910bde69.displayName = "WordEntry";
|
|
42
57
|
const currentStyle = (0, $duWW8$useMemo)(()=>{
|
|
43
58
|
return {
|
|
@@ -77,8 +92,10 @@ const $84765747a8c6bfe2$export$14f190ac910bde69 = /*#__PURE__*/ (0, $duWW8$react
|
|
|
77
92
|
// Simple if not editing
|
|
78
93
|
if (!editing) return /*#__PURE__*/ (0, $duWW8$jsx)("span", {
|
|
79
94
|
style: currentStyle,
|
|
80
|
-
id:
|
|
81
|
-
children: value
|
|
95
|
+
id: `${id}`,
|
|
96
|
+
children: value ? value : /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$Fragment), {
|
|
97
|
+
children: "\xa0"
|
|
98
|
+
})
|
|
82
99
|
});
|
|
83
100
|
return /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
|
|
84
101
|
style: currentStyle,
|
|
@@ -91,6 +108,7 @@ const $84765747a8c6bfe2$export$14f190ac910bde69 = /*#__PURE__*/ (0, $duWW8$react
|
|
|
91
108
|
}),
|
|
92
109
|
/*#__PURE__*/ (0, $duWW8$jsx)("input", {
|
|
93
110
|
autoFocus: true,
|
|
111
|
+
spellCheck: spellCheck,
|
|
94
112
|
id: String(id),
|
|
95
113
|
ref: ref,
|
|
96
114
|
type: "text",
|
|
@@ -109,7 +127,6 @@ const $84765747a8c6bfe2$export$14f190ac910bde69 = /*#__PURE__*/ (0, $duWW8$react
|
|
|
109
127
|
]
|
|
110
128
|
});
|
|
111
129
|
});
|
|
112
|
-
$84765747a8c6bfe2$export$14f190ac910bde69.displayName = "WordEntry";
|
|
113
130
|
|
|
114
131
|
|
|
115
132
|
const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemove, canRename: canRename, canAddChildren: canAddChildren, canRemoveChildren: canRemoveChildren, canRenameChildren: canRenameChildren })=>{
|
|
@@ -128,9 +145,16 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
|
|
|
128
145
|
id,
|
|
129
146
|
treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList
|
|
130
147
|
]);
|
|
148
|
+
var _treeContext_nodeList;
|
|
149
|
+
const descendents = (0, $duWW8$useMemo)(()=>{
|
|
150
|
+
return (0, $33abc00b1ca5c55c$export$bd923365b402cb04)(id, (_treeContext_nodeList = treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList) !== null && _treeContext_nodeList !== void 0 ? _treeContext_nodeList : []);
|
|
151
|
+
}, [
|
|
152
|
+
id,
|
|
153
|
+
treeContext
|
|
154
|
+
]);
|
|
131
155
|
// State
|
|
132
156
|
const [error, setError] = (0, $duWW8$useState)(false);
|
|
133
|
-
const [errorText, setErrotText] = (0, $duWW8$useState)(
|
|
157
|
+
const [errorText, setErrotText] = (0, $duWW8$useState)("");
|
|
134
158
|
const expanded = (0, $duWW8$useMemo)(()=>{
|
|
135
159
|
var _treeContext_expandedNodes_findIndex;
|
|
136
160
|
return ((_treeContext_expandedNodes_findIndex = treeContext === null || treeContext === void 0 ? void 0 : treeContext.expandedNodes.findIndex((e)=>e === id)) !== null && _treeContext_expandedNodes_findIndex !== void 0 ? _treeContext_expandedNodes_findIndex : -1) > -1;
|
|
@@ -138,19 +162,41 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
|
|
|
138
162
|
id,
|
|
139
163
|
treeContext === null || treeContext === void 0 ? void 0 : treeContext.expandedNodes
|
|
140
164
|
]);
|
|
141
|
-
//
|
|
165
|
+
// Checkbox
|
|
166
|
+
const checkRef = (0, $duWW8$useRef)(null);
|
|
167
|
+
(0, $duWW8$useEffect)(()=>{
|
|
168
|
+
if (checkRef.current) {
|
|
169
|
+
if (treeContext === null || treeContext === void 0 ? void 0 : treeContext.selected.includes(id)) {
|
|
170
|
+
checkRef.current.checked = true;
|
|
171
|
+
checkRef.current.indeterminate = false;
|
|
172
|
+
} else if (descendents.some((d)=>{
|
|
173
|
+
return treeContext === null || treeContext === void 0 ? void 0 : treeContext.selected.includes(d);
|
|
174
|
+
})) {
|
|
175
|
+
checkRef.current.checked = false;
|
|
176
|
+
checkRef.current.indeterminate = true;
|
|
177
|
+
} else {
|
|
178
|
+
checkRef.current.checked = false;
|
|
179
|
+
checkRef.current.indeterminate = false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}, [
|
|
183
|
+
descendents,
|
|
184
|
+
id,
|
|
185
|
+
treeContext === null || treeContext === void 0 ? void 0 : treeContext.selected
|
|
186
|
+
]);
|
|
187
|
+
// Apply selected border
|
|
142
188
|
const currentBorder = (0, $duWW8$useMemo)(()=>{
|
|
143
|
-
return
|
|
189
|
+
return (treeContext === null || treeContext === void 0 ? void 0 : treeContext.selected.includes(id)) ? "1px solid black" : "";
|
|
144
190
|
}, [
|
|
145
191
|
id,
|
|
146
|
-
treeContext === null || treeContext === void 0 ? void 0 : treeContext.
|
|
192
|
+
treeContext === null || treeContext === void 0 ? void 0 : treeContext.selected
|
|
147
193
|
]);
|
|
148
194
|
const nodeColour = (0, $duWW8$useMemo)(()=>{
|
|
149
|
-
if (treeContext && treeContext.
|
|
150
|
-
const anc = (0, $6303f0814ed0ce8b$export$c6fd3ab3f44300d0)(treeContext.
|
|
195
|
+
if (treeContext && treeContext.selected) {
|
|
196
|
+
const anc = (0, $6303f0814ed0ce8b$export$c6fd3ab3f44300d0)(treeContext.selected, [], treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList).map((n)=>n.id);
|
|
151
197
|
if ([
|
|
152
198
|
...anc,
|
|
153
|
-
treeContext.
|
|
199
|
+
treeContext.selected
|
|
154
200
|
].includes(id)) return treeContext.nodeHighlight;
|
|
155
201
|
}
|
|
156
202
|
return;
|
|
@@ -174,7 +220,7 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
|
|
|
174
220
|
setErrotText((_ret_ErrorText = ret.ErrorText) !== null && _ret_ErrorText !== void 0 ? _ret_ErrorText : "An unknown error has occured");
|
|
175
221
|
} else {
|
|
176
222
|
setError(false);
|
|
177
|
-
setErrotText(
|
|
223
|
+
setErrotText("");
|
|
178
224
|
}
|
|
179
225
|
}, []);
|
|
180
226
|
const confirmNewNode = (0, $duWW8$useCallback)(async (label)=>{
|
|
@@ -269,29 +315,46 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
|
|
|
269
315
|
color: "var(--bs-danger)"
|
|
270
316
|
}),
|
|
271
317
|
" ",
|
|
272
|
-
errorText
|
|
318
|
+
errorText
|
|
273
319
|
]
|
|
274
|
-
}) : /*#__PURE__*/ (0, $duWW8$jsxs)("
|
|
320
|
+
}) : /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
|
|
321
|
+
className: "ton-node",
|
|
275
322
|
children: [
|
|
323
|
+
treeContext.showCheckBox && /*#__PURE__*/ (0, $duWW8$jsx)("input", {
|
|
324
|
+
ref: checkRef,
|
|
325
|
+
type: "checkbox",
|
|
326
|
+
role: "checkbox",
|
|
327
|
+
className: "ton-checkbox",
|
|
328
|
+
id: `${treeContext.id}-treenode-checkbox-${id}`,
|
|
329
|
+
onClick: ()=>{
|
|
330
|
+
treeContext.handleSelect(descendents);
|
|
331
|
+
}
|
|
332
|
+
}),
|
|
276
333
|
childNodes !== undefined && childNodes.length > 0 ? !expanded ? /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretRightFill), {
|
|
277
334
|
id: `${treeContext.id}-treenode-caret-${id}`,
|
|
335
|
+
className: "ton-expander",
|
|
278
336
|
role: "button",
|
|
279
337
|
color: nodeColour,
|
|
280
338
|
"aria-expanded": false,
|
|
339
|
+
"aria-label": "Expander",
|
|
281
340
|
onClick: ()=>treeContext.handleExpandClick(id)
|
|
282
341
|
}) : /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretDownFill), {
|
|
283
342
|
id: `${treeContext.id}-treenode-caret-${id}`,
|
|
343
|
+
className: "ton-expander",
|
|
284
344
|
role: "button",
|
|
285
345
|
"aria-expanded": true,
|
|
346
|
+
"aria-label": "Expander",
|
|
286
347
|
color: nodeColour,
|
|
287
348
|
onClick: ()=>{
|
|
288
349
|
treeContext.handleExpandClick(id);
|
|
289
350
|
}
|
|
290
351
|
}) : /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretRight), {
|
|
291
352
|
id: `${treeContext.id}-treenode-caret-${id}`,
|
|
353
|
+
className: "ton-expander",
|
|
292
354
|
role: "button",
|
|
293
355
|
color: nodeColour,
|
|
294
356
|
"aria-expanded": false,
|
|
357
|
+
"aria-label": "Disabled expander",
|
|
295
358
|
"aria-disabled": true
|
|
296
359
|
}),
|
|
297
360
|
thisNode && /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
@@ -313,32 +376,30 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
|
|
|
313
376
|
border: currentBorder,
|
|
314
377
|
margin: currentBorder === "" ? "1px" : "",
|
|
315
378
|
backgroundColor: currentBorder === "" ? "" : treeContext.textHighlight
|
|
316
|
-
}
|
|
379
|
+
},
|
|
380
|
+
spellCheck: treeContext.spellCheck
|
|
317
381
|
})
|
|
318
382
|
})
|
|
319
383
|
]
|
|
320
384
|
}),
|
|
321
|
-
childNodes !== undefined &&
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
canRenameChildren: canRenameChildren
|
|
340
|
-
})
|
|
341
|
-
}, h.id)),
|
|
385
|
+
childNodes !== undefined && /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
386
|
+
className: `ton-collapsible-wrapper ${expanded ? "" : "collapsed"}`,
|
|
387
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
388
|
+
className: "ton-collapsible",
|
|
389
|
+
children: childNodes.map((h)=>/*#__PURE__*/ (0, $duWW8$jsx)("span", {
|
|
390
|
+
id: `${treeContext.id}-treenode-child-${h.id}`,
|
|
391
|
+
className: "ton-child",
|
|
392
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)($47c36cf4281201f5$export$2eba8ec3a333fdbb, {
|
|
393
|
+
id: h.id,
|
|
394
|
+
canRemove: canRemoveChildren,
|
|
395
|
+
canRename: canRenameChildren,
|
|
396
|
+
canAddChildren: canAddChildren,
|
|
397
|
+
canRemoveChildren: canRemoveChildren,
|
|
398
|
+
canRenameChildren: canRenameChildren
|
|
399
|
+
})
|
|
400
|
+
}, h.id))
|
|
401
|
+
})
|
|
402
|
+
}),
|
|
342
403
|
showNewNode && /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
343
404
|
children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $84765747a8c6bfe2$export$14f190ac910bde69), {
|
|
344
405
|
style: {
|
|
@@ -353,7 +414,8 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
|
|
|
353
414
|
saving: savingNewNode,
|
|
354
415
|
sendEscape: ()=>{
|
|
355
416
|
setShowNewNode(false);
|
|
356
|
-
}
|
|
417
|
+
},
|
|
418
|
+
spellCheck: treeContext.spellCheck
|
|
357
419
|
})
|
|
358
420
|
})
|
|
359
421
|
]
|
|
@@ -366,31 +428,35 @@ $47c36cf4281201f5$export$2eba8ec3a333fdbb.displayName = "TreeNode";
|
|
|
366
428
|
|
|
367
429
|
|
|
368
430
|
|
|
369
|
-
const $c7008d808d3e1c7a$export$40c47a7ac5f85aba = (nodeList,
|
|
431
|
+
const $c7008d808d3e1c7a$export$40c47a7ac5f85aba = (nodeList, selected, expandedNodes)=>{
|
|
370
432
|
return [
|
|
371
433
|
...expandedNodes,
|
|
372
|
-
...(0, $6303f0814ed0ce8b$export$c6fd3ab3f44300d0)(
|
|
434
|
+
...(0, $6303f0814ed0ce8b$export$c6fd3ab3f44300d0)(selected, [], nodeList).map((n)=>n.id).filter((k)=>!expandedNodes.includes(k))
|
|
373
435
|
].sort((a, b)=>`${a}`.localeCompare(`${b}`));
|
|
374
436
|
};
|
|
375
437
|
|
|
376
438
|
|
|
377
439
|
|
|
378
440
|
|
|
379
|
-
const $ba47aaf387735a90$export$5580fff3e08a8be5 = ({ id: id, nodeList: nodeList, roots: roots,
|
|
380
|
-
canRemoveRoot = false, canRenameRoot: canRenameRoot = false, canAddChildren: canAddChildren = false, canRemoveChildren: canRemoveChildren = false, canRenameChildren: canRenameChildren = false, selectedId: selectedId, handleSelect: handleSelect = ()=>{
|
|
441
|
+
const $ba47aaf387735a90$export$5580fff3e08a8be5 = ({ id: id, nodeList: nodeList, roots: roots, selected: selected = [], showCheckBox: showCheckBox = false, handleSelect: handleSelect = ()=>{
|
|
381
442
|
return;
|
|
382
|
-
}, onAdd: onAdd, onRename: onRename, onRemove: onRemove, nodeHighlight: nodeHighlight = "red", textHighlight: textHighlight = "rgba(255, 0, 0, 0.2)" })=>{
|
|
443
|
+
}, onAdd: onAdd, onRename: onRename, onRemove: onRemove, canRemoveRoot: canRemoveRoot = false, canRenameRoot: canRenameRoot = false, canAddChildren: canAddChildren = false, canRemoveChildren: canRemoveChildren = false, canRenameChildren: canRenameChildren = false, nodeHighlight: nodeHighlight = "red", textHighlight: textHighlight = "rgba(255, 0, 0, 0.2)", spellCheck: spellCheck = "true" })=>{
|
|
383
444
|
const [expandedNodes, setExpandedNodes] = (0, $duWW8$useState)([]);
|
|
445
|
+
const selectedArray = (0, $duWW8$useMemo)(()=>Array.isArray(selected) ? selected : [
|
|
446
|
+
selected
|
|
447
|
+
], [
|
|
448
|
+
selected
|
|
449
|
+
]);
|
|
384
450
|
(0, $duWW8$useEffect)(()=>{
|
|
385
|
-
if (
|
|
451
|
+
if (selectedArray.length > 0) {
|
|
386
452
|
// Check all nodes are showing that should be
|
|
387
|
-
const shouldExpand = (0, $c7008d808d3e1c7a$export$40c47a7ac5f85aba)(nodeList,
|
|
453
|
+
const shouldExpand = (0, $c7008d808d3e1c7a$export$40c47a7ac5f85aba)(nodeList, selectedArray, expandedNodes);
|
|
388
454
|
shouldExpand.filter((n)=>!expandedNodes.includes(n)).length > 0 && setExpandedNodes(shouldExpand);
|
|
389
455
|
}
|
|
390
456
|
}, [
|
|
391
457
|
expandedNodes,
|
|
392
458
|
nodeList,
|
|
393
|
-
|
|
459
|
+
selectedArray
|
|
394
460
|
]);
|
|
395
461
|
// Change expansion and update contexts
|
|
396
462
|
const changeExpand = (0, $duWW8$useCallback)((eKey, force)=>{
|
|
@@ -408,7 +474,8 @@ canRemoveRoot = false, canRenameRoot: canRenameRoot = false, canAddChildren: can
|
|
|
408
474
|
value: {
|
|
409
475
|
id: id,
|
|
410
476
|
nodeList: nodeList,
|
|
411
|
-
|
|
477
|
+
selected: selectedArray,
|
|
478
|
+
showCheckBox: showCheckBox,
|
|
412
479
|
handleSelect: handleSelect,
|
|
413
480
|
expandedNodes: expandedNodes,
|
|
414
481
|
handleExpandClick: (r, f)=>changeExpand(r, f),
|
|
@@ -416,7 +483,8 @@ canRemoveRoot = false, canRenameRoot: canRenameRoot = false, canAddChildren: can
|
|
|
416
483
|
onRename: onRename,
|
|
417
484
|
onRemove: onRemove,
|
|
418
485
|
nodeHighlight: nodeHighlight,
|
|
419
|
-
textHighlight: textHighlight
|
|
486
|
+
textHighlight: textHighlight,
|
|
487
|
+
spellCheck: spellCheck
|
|
420
488
|
},
|
|
421
489
|
children: roots.map((r)=>/*#__PURE__*/ (0, $duWW8$jsx)((0, $47c36cf4281201f5$export$2eba8ec3a333fdbb), {
|
|
422
490
|
id: r,
|