@frontify/fondue 12.0.0-beta.234 → 12.0.0-beta.235
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.
|
@@ -11,7 +11,7 @@ const A = ({ previousNode: e }) => e ? e.props.level + 1 : 0, E = ({ nextNode: e
|
|
|
11
11
|
}, y = (t) => {
|
|
12
12
|
var c;
|
|
13
13
|
return t ? (c = e.find(({ props: f }) => f.id === t)) == null ? void 0 : c.props : null;
|
|
14
|
-
}, s = T(), o = y(s), v = d.filter(({ props: t }) => t.parentId === s), g = v.findIndex(({ props: t }) => t.id === D), h = g >= 0 ? g : v.findIndex(({ props: t }) => t.id === x), O = l < p && i.props.parentId
|
|
14
|
+
}, s = T(), o = y(s), v = d.filter(({ props: t }) => t.parentId === s), g = v.findIndex(({ props: t }) => t.id === D), h = g >= 0 ? g : v.findIndex(({ props: t }) => t.id === x), O = l < p && i.props.parentId !== s ? 1 : 0;
|
|
15
15
|
return {
|
|
16
16
|
depth: r,
|
|
17
17
|
maxDepth: I,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projection.es.js","sources":["../../../../src/components/Tree/helpers/projection.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { ReactElement } from 'react';\nimport { arrayMove } from '@dnd-kit/sortable';\n\nimport { INDENTATION_WIDTH, ROOT_ID } from '../Tree';\nimport type { InternalTreeItemProps } from '../TreeItem';\n\nexport type ProjectionArgs = {\n nodes: ReactElement<InternalTreeItemProps>[];\n activeId: string;\n overId: string;\n dragOffset: number;\n};\n\nexport type Projection = {\n depth: number;\n maxDepth: number;\n minDepth: number;\n position: number;\n type?: string;\n accepts?: string;\n parentId: Nullable<string>;\n};\n\nconst getMaxDepth = ({ previousNode }: { previousNode: ReactElement }) => {\n return previousNode ? previousNode.props.level + 1 : 0;\n};\n\nconst getMinDepth = ({ nextNode }: { nextNode: ReactElement }) => {\n return nextNode ? nextNode.props.level : 0;\n};\n\nconst getDragDepth = (offset: number) => {\n return Math.round(offset / INDENTATION_WIDTH);\n};\n\nexport const getProjection = ({ nodes, activeId, overId, dragOffset }: ProjectionArgs): Projection => {\n const overNodeIndex = nodes.findIndex(({ props }) => props.id === overId);\n const activeNodeIndex = nodes.findIndex(({ props }) => props.id === activeId);\n\n const activeNode = nodes[activeNodeIndex];\n const newNodes = arrayMove(nodes, activeNodeIndex, overNodeIndex);\n\n const previousNode = newNodes[overNodeIndex - 1];\n const nextNode = newNodes[overNodeIndex + 1];\n\n const dragDepth = getDragDepth(dragOffset);\n const projectedDepth = (activeNode?.props?.level ?? 0) + dragDepth;\n\n const maxDepth = getMaxDepth({ previousNode });\n const minDepth = getMinDepth({ nextNode });\n let depth = projectedDepth;\n if (projectedDepth >= maxDepth) {\n depth = maxDepth;\n } else if (projectedDepth < minDepth) {\n depth = minDepth;\n }\n\n const getParentId = () => {\n if (depth === 0 || !previousNode) {\n return ROOT_ID;\n }\n\n if (previousNode.props.parentId && depth === previousNode.props.level) {\n return previousNode.props.parentId ?? null;\n }\n\n if (previousNode.props.level !== undefined && depth > previousNode.props.level) {\n return previousNode.props.id;\n }\n\n const newParent = newNodes\n .slice(0, overNodeIndex)\n .reverse()\n .find((item) => item.props.level === depth)?.props.parentId;\n\n return newParent ?? null;\n };\n\n const getParent = (parentId: Nullable<string>) => {\n if (!parentId) {\n return null;\n }\n return nodes.find(({ props }) => props.id === parentId)?.props;\n };\n\n const parentId = getParentId();\n const parent = getParent(parentId);\n\n const nodesInParent = newNodes.filter(({ props }) => props.parentId === parentId);\n const activeNewIndex = nodesInParent.findIndex(({ props }) => props.id === activeId);\n const dropIndexInParent =\n activeNewIndex >= 0 ? activeNewIndex : nodesInParent.findIndex(({ props }) => props.id === overId);\n\n // whether we are moving down there is a +1 offset, unless we are in the same document\n const correctionDueDragDirection =\n activeNodeIndex < overNodeIndex && activeNode.props.parentId
|
|
1
|
+
{"version":3,"file":"projection.es.js","sources":["../../../../src/components/Tree/helpers/projection.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { ReactElement } from 'react';\nimport { arrayMove } from '@dnd-kit/sortable';\n\nimport { INDENTATION_WIDTH, ROOT_ID } from '../Tree';\nimport type { InternalTreeItemProps } from '../TreeItem';\n\nexport type ProjectionArgs = {\n nodes: ReactElement<InternalTreeItemProps>[];\n activeId: string;\n overId: string;\n dragOffset: number;\n};\n\nexport type Projection = {\n depth: number;\n maxDepth: number;\n minDepth: number;\n position: number;\n type?: string;\n accepts?: string;\n parentId: Nullable<string>;\n};\n\nconst getMaxDepth = ({ previousNode }: { previousNode: ReactElement }) => {\n return previousNode ? previousNode.props.level + 1 : 0;\n};\n\nconst getMinDepth = ({ nextNode }: { nextNode: ReactElement }) => {\n return nextNode ? nextNode.props.level : 0;\n};\n\nconst getDragDepth = (offset: number) => {\n return Math.round(offset / INDENTATION_WIDTH);\n};\n\nexport const getProjection = ({ nodes, activeId, overId, dragOffset }: ProjectionArgs): Projection => {\n const overNodeIndex = nodes.findIndex(({ props }) => props.id === overId);\n const activeNodeIndex = nodes.findIndex(({ props }) => props.id === activeId);\n\n const activeNode = nodes[activeNodeIndex];\n const newNodes = arrayMove(nodes, activeNodeIndex, overNodeIndex);\n\n const previousNode = newNodes[overNodeIndex - 1];\n const nextNode = newNodes[overNodeIndex + 1];\n\n const dragDepth = getDragDepth(dragOffset);\n const projectedDepth = (activeNode?.props?.level ?? 0) + dragDepth;\n\n const maxDepth = getMaxDepth({ previousNode });\n const minDepth = getMinDepth({ nextNode });\n let depth = projectedDepth;\n if (projectedDepth >= maxDepth) {\n depth = maxDepth;\n } else if (projectedDepth < minDepth) {\n depth = minDepth;\n }\n\n const getParentId = () => {\n if (depth === 0 || !previousNode) {\n return ROOT_ID;\n }\n\n if (previousNode.props.parentId && depth === previousNode.props.level) {\n return previousNode.props.parentId ?? null;\n }\n\n if (previousNode.props.level !== undefined && depth > previousNode.props.level) {\n return previousNode.props.id;\n }\n\n const newParent = newNodes\n .slice(0, overNodeIndex)\n .reverse()\n .find((item) => item.props.level === depth)?.props.parentId;\n\n return newParent ?? null;\n };\n\n const getParent = (parentId: Nullable<string>) => {\n if (!parentId) {\n return null;\n }\n return nodes.find(({ props }) => props.id === parentId)?.props;\n };\n\n const parentId = getParentId();\n const parent = getParent(parentId);\n\n const nodesInParent = newNodes.filter(({ props }) => props.parentId === parentId);\n const activeNewIndex = nodesInParent.findIndex(({ props }) => props.id === activeId);\n const dropIndexInParent =\n activeNewIndex >= 0 ? activeNewIndex : nodesInParent.findIndex(({ props }) => props.id === overId);\n\n // whether we are moving down there is a +1 offset, unless we are in the same document\n const correctionDueDragDirection =\n activeNodeIndex < overNodeIndex && activeNode.props.parentId !== parentId ? 1 : 0;\n\n return {\n depth,\n maxDepth,\n minDepth,\n parentId: parentId !== ROOT_ID ? parentId : null,\n type: parent?.type,\n accepts: parent?.accepts,\n position: (dropIndexInParent >= 0 ? dropIndexInParent : 0) + correctionDueDragDirection,\n };\n};\n"],"names":["getMaxDepth","previousNode","getMinDepth","nextNode","getDragDepth","offset","INDENTATION_WIDTH","getProjection","nodes","activeId","overId","dragOffset","overNodeIndex","props","activeNodeIndex","activeNode","newNodes","arrayMove","dragDepth","projectedDepth","_a","maxDepth","minDepth","depth","getParentId","ROOT_ID","item","getParent","parentId","parent","nodesInParent","activeNewIndex","dropIndexInParent","correctionDueDragDirection"],"mappings":";;AAyBA,MAAMA,IAAc,CAAC,EAAE,cAAAC,QACZA,IAAeA,EAAa,MAAM,QAAQ,IAAI,GAGnDC,IAAc,CAAC,EAAE,UAAAC,QACZA,IAAWA,EAAS,MAAM,QAAQ,GAGvCC,IAAe,CAACC,MACX,KAAK,MAAMA,IAASC,CAAiB,GAGnCC,IAAgB,CAAC,EAAE,OAAAC,GAAO,UAAAC,GAAU,QAAAC,GAAQ,YAAAC,QAA6C;;AAC5F,QAAAC,IAAgBJ,EAAM,UAAU,CAAC,EAAE,OAAAK,EAAM,MAAMA,EAAM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