@tldraw/editor 4.3.0-canary.fd6b7f2a8adc → 4.3.0-next.2b3bfbba757b
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/dist-cjs/index.d.ts +35 -55
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/editor/Editor.js +12 -1
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/bindings/BindingUtil.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/bindingsIndex.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/BaseBoxShapeUtil.js.map +1 -1
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/BaseBoxShapeTool.js.map +2 -2
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +2 -2
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/utils/reparenting.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +35 -55
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/editor/Editor.mjs +12 -1
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/bindings/BindingUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/BaseBoxShapeUtil.mjs.map +1 -1
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/BaseBoxShapeTool.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +10 -10
- package/src/lib/editor/Editor.test.ts +10 -10
- package/src/lib/editor/Editor.ts +59 -82
- package/src/lib/editor/bindings/BindingUtil.ts +9 -15
- package/src/lib/editor/derivations/bindingsIndex.ts +2 -2
- package/src/lib/editor/managers/FontManager/FontManager.test.ts +4 -14
- package/src/lib/editor/managers/SnapManager/SnapManager.ts +3 -3
- package/src/lib/editor/shapes/BaseBoxShapeUtil.tsx +2 -2
- package/src/lib/editor/shapes/ShapeUtil.ts +8 -5
- package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +3 -1
- package/src/lib/editor/tools/BaseBoxShapeTool/BaseBoxShapeTool.ts +1 -2
- package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +3 -3
- package/src/lib/exports/getSvgJsx.test.ts +19 -10
- package/src/lib/exports/getSvgJsx.tsx +5 -2
- package/src/lib/utils/reparenting.ts +5 -5
- package/src/version.ts +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/utils/reparenting.ts"],
|
|
4
|
-
"sourcesContent": ["import { EMPTY_ARRAY } from '@tldraw/state'\nimport { TLGroupShape, TLParentId, TLShape, TLShapeId } from '@tldraw/tlschema'\nimport { IndexKey, compact, getIndexAbove, getIndexBetween } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\nimport { intersectPolygonPolygon } from '../primitives/intersect'\n\n/**\n * Reparents shapes that are no longer contained within their parent shapes.\n * todo: rename me to something more descriptive, like `reparentOccludedShapes` or `reparentAutoDroppedShapes`\n *\n * @param editor - The editor instance.\n * @param shapeIds - The IDs of the shapes to reparent.\n * @param opts - Optional options, including a callback to filter out certain parents, such as when removing a frame.\n *\n * @public\n */\nexport function kickoutOccludedShapes(\n\teditor: Editor,\n\tshapeIds: TLShapeId[],\n\topts?: { filter?(parent: TLShape): boolean }\n) {\n\tconst parentsToCheck = new Set<TLShape>()\n\n\tfor (const id of shapeIds) {\n\t\tconst shape = editor.getShape(id)\n\n\t\tif (!shape) continue\n\t\tparentsToCheck.add(shape)\n\n\t\tconst parent = editor.getShape(shape.parentId)\n\t\tif (!parent) continue\n\t\tparentsToCheck.add(parent)\n\t}\n\n\t// Check all of the parents and gather up parents who have lost children\n\tconst parentsToLostChildren = new Map<TLShape, TLShapeId[]>()\n\n\tfor (const parent of parentsToCheck) {\n\t\tconst childIds = editor.getSortedChildIdsForParent(parent)\n\t\tif (opts?.filter && !opts.filter(parent)) {\n\t\t\t// If the shape is filtered out, we kick out all of its children\n\t\t\tparentsToLostChildren.set(parent, childIds)\n\t\t} else {\n\t\t\tconst overlappingChildren = getOverlappingShapes(editor, parent.id, childIds)\n\t\t\tif (overlappingChildren.length < childIds.length) {\n\t\t\t\tparentsToLostChildren.set(\n\t\t\t\t\tparent,\n\t\t\t\t\tchildIds.filter((id) => !overlappingChildren.includes(id))\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Get all of the shapes on the current page, sorted by their index\n\tconst sortedShapeIds = editor.getCurrentPageShapesSorted().map((s) => s.id)\n\n\tconst parentsToNewChildren: Record<\n\t\tTLParentId,\n\t\t{ parentId: TLParentId; shapeIds: TLShapeId[]; index?: IndexKey }\n\t> = {}\n\n\tfor (const [prevParent, lostChildrenIds] of parentsToLostChildren) {\n\t\tconst lostChildren = compact(lostChildrenIds.map((id) => editor.getShape(id)))\n\n\t\t// Don't fall \"up\" into frames in front of the shape\n\t\t// if (pageShapes.indexOf(shape) < frameSortPosition) continue shapeCheck\n\n\t\t// Otherwise, we have no next dropping shape under the cursor, so go find\n\t\t// all the frames on the page where the moving shapes will fall into\n\t\tconst { reparenting, remainingShapesToReparent } = getDroppedShapesToNewParents(\n\t\t\teditor,\n\t\t\tlostChildren,\n\t\t\t(shape, maybeNewParent) => {\n\t\t\t\t// If we're filtering out a potential parent, don't reparent shapes to the filtered out shape\n\t\t\t\tif (opts?.filter && !opts.filter(maybeNewParent)) return false\n\t\t\t\treturn (\n\t\t\t\t\tmaybeNewParent.id !== prevParent.id &&\n\t\t\t\t\tsortedShapeIds.indexOf(maybeNewParent.id) < sortedShapeIds.indexOf(shape.id)\n\t\t\t\t)\n\t\t\t}\n\t\t)\n\n\t\treparenting.forEach((childrenToReparent, newParentId) => {\n\t\t\tif (childrenToReparent.length === 0) return\n\t\t\tif (!parentsToNewChildren[newParentId]) {\n\t\t\t\tparentsToNewChildren[newParentId] = {\n\t\t\t\t\tparentId: newParentId,\n\t\t\t\t\tshapeIds: [],\n\t\t\t\t}\n\t\t\t}\n\t\t\tparentsToNewChildren[newParentId].shapeIds.push(...childrenToReparent.map((s) => s.id))\n\t\t})\n\n\t\t// Reparent the rest to the page (or containing group)\n\t\tif (remainingShapesToReparent.size > 0) {\n\t\t\t// The remaining shapes are going to be reparented to the old parent's containing group, if there was one, or else to the page\n\t\t\tconst newParentId =\n\t\t\t\teditor.findShapeAncestor(prevParent, (s) => editor.isShapeOfType(s, 'group'))?.id ??\n\t\t\t\teditor.getCurrentPageId()\n\n\t\t\tremainingShapesToReparent.forEach((shape) => {\n\t\t\t\tif (!parentsToNewChildren[newParentId]) {\n\t\t\t\t\tlet insertIndexKey: IndexKey | undefined\n\n\t\t\t\t\tconst oldParentSiblingIds = editor.getSortedChildIdsForParent(newParentId)\n\t\t\t\t\tconst oldParentIndex = oldParentSiblingIds.indexOf(prevParent.id)\n\t\t\t\t\tif (oldParentIndex > -1) {\n\t\t\t\t\t\t// If the old parent is a direct child of the new parent, then we'll add them above the old parent but below the next sibling.\n\t\t\t\t\t\tconst siblingsIndexAbove = oldParentSiblingIds[oldParentIndex + 1]\n\t\t\t\t\t\tconst indexKeyAbove = siblingsIndexAbove\n\t\t\t\t\t\t\t? editor.getShape(siblingsIndexAbove)!.index\n\t\t\t\t\t\t\t: getIndexAbove(prevParent.index)\n\t\t\t\t\t\tinsertIndexKey = getIndexBetween(prevParent.index, indexKeyAbove)\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the old parent is not a direct child of the new parent, then we'll add them to the \"top\" of the new parent's children.\n\t\t\t\t\t\t// This is done automatically if we leave the index undefined, so let's do that.\n\t\t\t\t\t}\n\n\t\t\t\t\tparentsToNewChildren[newParentId] = {\n\t\t\t\t\t\tparentId: newParentId,\n\t\t\t\t\t\tshapeIds: [],\n\t\t\t\t\t\tindex: insertIndexKey,\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tparentsToNewChildren[newParentId].shapeIds.push(shape.id)\n\t\t\t})\n\t\t}\n\t}\n\n\teditor.run(() => {\n\t\tObject.values(parentsToNewChildren).forEach(({ parentId, shapeIds, index }) => {\n\t\t\tif (shapeIds.length === 0) return\n\t\t\t// Before we reparent, sort the new shape ids by their place in the original absolute order on the page\n\t\t\tshapeIds.sort((a, b) => (sortedShapeIds.indexOf(a) < sortedShapeIds.indexOf(b) ? -1 : 1))\n\t\t\teditor.reparentShapes(shapeIds, parentId, index)\n\t\t})\n\t})\n}\n\n/**\n * Get the shapes that overlap with a given shape.\n *\n * @param editor - The editor instance.\n * @param shape - The shapes or shape IDs to check against.\n * @param otherShapes - The shapes or shape IDs to check for overlap.\n * @returns An array of shapes or shape IDs that overlap with the given shape.\n */\nfunction getOverlappingShapes<T extends TLShape[] | TLShapeId[]>(\n\teditor: Editor,\n\tshape: T[number],\n\totherShapes: T\n) {\n\tif (otherShapes.length === 0) {\n\t\treturn EMPTY_ARRAY\n\t}\n\n\tconst parentPageBounds = editor.getShapePageBounds(shape)\n\tif (!parentPageBounds) return EMPTY_ARRAY\n\n\tconst parentGeometry = editor.getShapeGeometry(shape)\n\tconst parentPageTransform = editor.getShapePageTransform(shape)\n\tconst parentPageCorners = parentPageTransform.applyToPoints(parentGeometry.vertices)\n\n\tconst _shape = editor.getShape(shape)\n\tif (!_shape) return EMPTY_ARRAY\n\n\tconst pageTransform = editor.getShapePageTransform(shape)\n\tconst clipPath = editor.getShapeUtil(_shape.type).getClipPath?.(_shape)\n\n\tconst parentPageMaskVertices = clipPath ? pageTransform.applyToPoints(clipPath) : undefined\n\tconst parentPagePolygon = parentPageMaskVertices\n\t\t? intersectPolygonPolygon(parentPageMaskVertices, parentPageCorners)\n\t\t: parentPageCorners\n\n\tif (!parentPagePolygon) return EMPTY_ARRAY\n\n\treturn otherShapes.filter((childId) => {\n\t\tconst shapePageBounds = editor.getShapePageBounds(childId)\n\t\tif (!shapePageBounds || !parentPageBounds.includes(shapePageBounds)) return false\n\n\t\tconst parentPolygonInShapeShape = editor\n\t\t\t.getShapePageTransform(childId)\n\t\t\t.clone()\n\t\t\t.invert()\n\t\t\t.applyToPoints(parentPagePolygon)\n\n\t\tconst geometry = editor.getShapeGeometry(childId)\n\n\t\treturn geometry.overlapsPolygon(parentPolygonInShapeShape)\n\t})\n}\n\n/**\n * Get the shapes that will be reparented to new parents when the shapes are dropped.\n *\n * @param editor - The editor instance.\n * @param shapes - The shapes to check.\n * @param cb - A callback to filter out certain shapes.\n * @returns An object with the shapes that will be reparented to new parents and the shapes that will be reparented to the page or their ancestral group.\n *\n * @public\n */\nexport function getDroppedShapesToNewParents(\n\teditor: Editor,\n\tshapes: Set<TLShape> | TLShape[],\n\tcb?: (shape: TLShape, parent: TLShape) => boolean\n) {\n\tconst shapesToActuallyCheck = new Set<TLShape>(shapes)\n\tconst movingGroups = new Set<TLGroupShape>()\n\n\tfor (const shape of shapes) {\n\t\tconst parent = editor.getShapeParent(shape)\n\t\tif (parent && editor.isShapeOfType(parent, 'group')) {\n\t\t\tif (!movingGroups.has(parent)) {\n\t\t\t\tmovingGroups.add(parent)\n\t\t\t}\n\t\t}\n\t}\n\n\t// If all of a group's children are moving, then move the group instead\n\tfor (const movingGroup of movingGroups) {\n\t\tconst children = compact(\n\t\t\teditor.getSortedChildIdsForParent(movingGroup).map((id) => editor.getShape(id))\n\t\t)\n\t\tfor (const child of children) {\n\t\t\tshapesToActuallyCheck.delete(child)\n\t\t}\n\t\tshapesToActuallyCheck.add(movingGroup)\n\t}\n\n\t// this could be cached and passed in\n\tconst shapeGroupIds = new Map<TLShapeId, TLShapeId | undefined>()\n\n\tconst reparenting = new Map<TLShapeId, TLShape[]>()\n\n\tconst remainingShapesToReparent = new Set(shapesToActuallyCheck)\n\n\tconst potentialParentShapes = editor\n\t\t.getCurrentPageShapesSorted()\n\t\t// filter out any shapes that aren't frames or that are included among the provided shapes\n\t\t.filter(\n\t\t\t(s) =>\n\t\t\t\teditor.getShapeUtil(s).canReceiveNewChildrenOfType?.(s, s.type) &&\n\t\t\t\t!remainingShapesToReparent.has(s)\n\t\t)\n\n\tparentCheck: for (let i = potentialParentShapes.length - 1; i >= 0; i--) {\n\t\tconst parentShape = potentialParentShapes[i]\n\t\tconst parentShapeContainingGroupId = editor.findShapeAncestor(parentShape, (s) =>\n\t\t\teditor.isShapeOfType(s, 'group')\n\t\t)?.id\n\n\t\tconst parentGeometry = editor.getShapeGeometry(parentShape)\n\t\tconst parentPageTransform = editor.getShapePageTransform(parentShape)\n\t\tconst parentPageMaskVertices = editor.getShapeMask(parentShape)\n\t\tconst parentPageCorners = parentPageTransform.applyToPoints(parentGeometry.vertices)\n\t\tconst parentPagePolygon = parentPageMaskVertices\n\t\t\t? intersectPolygonPolygon(parentPageMaskVertices, parentPageCorners)\n\t\t\t: parentPageCorners\n\n\t\tif (!parentPagePolygon) continue parentCheck\n\n\t\tconst childrenToReparent = []\n\n\t\t// For each of the dropping shapes...\n\t\tshapeCheck: for (const shape of remainingShapesToReparent) {\n\t\t\t// Don't reparent a frame to itself\n\t\t\tif (parentShape.id === shape.id) continue shapeCheck\n\n\t\t\t// Use the callback to filter out certain shapes\n\t\t\tif (cb && !cb(shape, parentShape)) continue shapeCheck\n\n\t\t\tif (!shapeGroupIds.has(shape.id)) {\n\t\t\t\tshapeGroupIds.set(\n\t\t\t\t\tshape.id,\n\t\t\t\t\teditor.findShapeAncestor(shape, (s) => editor.isShapeOfType(s, 'group'))?.id\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tconst shapeGroupId = shapeGroupIds.get(shape.id)\n\n\t\t\t// Are the shape and the parent part of different groups?\n\t\t\tif (shapeGroupId !== parentShapeContainingGroupId) continue shapeCheck\n\n\t\t\t// Is the shape is actually the ancestor of the parent?\n\t\t\tif (editor.findShapeAncestor(parentShape, (s) => shape.id === s.id)) continue shapeCheck\n\n\t\t\t// Convert the parent polygon to the shape's space\n\t\t\tconst parentPolygonInShapeSpace = editor\n\t\t\t\t.getShapePageTransform(shape)\n\t\t\t\t.clone()\n\t\t\t\t.invert()\n\t\t\t\t.applyToPoints(parentPagePolygon)\n\n\t\t\t// If the shape overlaps the parent polygon, reparent it to that parent\n\t\t\tif (editor.getShapeGeometry(shape).overlapsPolygon(parentPolygonInShapeSpace)) {\n\t\t\t\t// Use the util to check if the shape can be reparented to the parent\n\t\t\t\tif (\n\t\t\t\t\t!editor.getShapeUtil(parentShape).canReceiveNewChildrenOfType?.(parentShape, shape.type)\n\t\t\t\t)\n\t\t\t\t\tcontinue shapeCheck\n\n\t\t\t\tif (shape.parentId !== parentShape.id) {\n\t\t\t\t\tchildrenToReparent.push(shape)\n\t\t\t\t}\n\t\t\t\tremainingShapesToReparent.delete(shape)\n\t\t\t\tcontinue shapeCheck\n\t\t\t}\n\t\t}\n\n\t\tif (childrenToReparent.length) {\n\t\t\treparenting.set(parentShape.id, childrenToReparent)\n\t\t}\n\t}\n\n\treturn {\n\t\t// these are the shapes that will be reparented to new parents\n\t\treparenting,\n\t\t// these are the shapes that will be reparented to the page or their ancestral group\n\t\tremainingShapesToReparent,\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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Q,MAAM,EAAE;AAAA,MAE7E;AAAA,IACD;AAEA,gBAAY,QAAQ,CAAC,oBAAoB,gBAAgB;AACxD,UAAI,mBAAmB,WAAW,EAAG;AACrC,UAAI,CAAC,qBAAqB,WAAW,GAAG;AACvC,6BAAqB,WAAW,IAAI;AAAA,UACnC,UAAU;AAAA,UACV,UAAU,CAAC;AAAA,QACZ;AAAA,MACD;AACA,2BAAqB,WAAW,EAAE,SAAS,KAAK,GAAG,mBAAmB,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;AAAA,IACvF,CAAC;AAGD,QAAI,0BAA0B,OAAO,GAAG;AAEvC,YAAM,cACL,OAAO,kBAAkB,YAAY,CAAC,MAAM,OAAO,
|
|
4
|
+
"sourcesContent": ["import { EMPTY_ARRAY } from '@tldraw/state'\nimport { TLGroupShape, TLParentId, TLShape, TLShapeId } from '@tldraw/tlschema'\nimport { IndexKey, compact, getIndexAbove, getIndexBetween } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\nimport { intersectPolygonPolygon } from '../primitives/intersect'\n\n/**\n * Reparents shapes that are no longer contained within their parent shapes.\n * todo: rename me to something more descriptive, like `reparentOccludedShapes` or `reparentAutoDroppedShapes`\n *\n * @param editor - The editor instance.\n * @param shapeIds - The IDs of the shapes to reparent.\n * @param opts - Optional options, including a callback to filter out certain parents, such as when removing a frame.\n *\n * @public\n */\nexport function kickoutOccludedShapes(\n\teditor: Editor,\n\tshapeIds: TLShapeId[],\n\topts?: { filter?(parent: TLShape): boolean }\n) {\n\tconst parentsToCheck = new Set<TLShape>()\n\n\tfor (const id of shapeIds) {\n\t\tconst shape = editor.getShape(id)\n\n\t\tif (!shape) continue\n\t\tparentsToCheck.add(shape)\n\n\t\tconst parent = editor.getShape(shape.parentId)\n\t\tif (!parent) continue\n\t\tparentsToCheck.add(parent)\n\t}\n\n\t// Check all of the parents and gather up parents who have lost children\n\tconst parentsToLostChildren = new Map<TLShape, TLShapeId[]>()\n\n\tfor (const parent of parentsToCheck) {\n\t\tconst childIds = editor.getSortedChildIdsForParent(parent)\n\t\tif (opts?.filter && !opts.filter(parent)) {\n\t\t\t// If the shape is filtered out, we kick out all of its children\n\t\t\tparentsToLostChildren.set(parent, childIds)\n\t\t} else {\n\t\t\tconst overlappingChildren = getOverlappingShapes(editor, parent.id, childIds)\n\t\t\tif (overlappingChildren.length < childIds.length) {\n\t\t\t\tparentsToLostChildren.set(\n\t\t\t\t\tparent,\n\t\t\t\t\tchildIds.filter((id) => !overlappingChildren.includes(id))\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Get all of the shapes on the current page, sorted by their index\n\tconst sortedShapeIds = editor.getCurrentPageShapesSorted().map((s) => s.id)\n\n\tconst parentsToNewChildren: Record<\n\t\tTLParentId,\n\t\t{ parentId: TLParentId; shapeIds: TLShapeId[]; index?: IndexKey }\n\t> = {}\n\n\tfor (const [prevParent, lostChildrenIds] of parentsToLostChildren) {\n\t\tconst lostChildren = compact(lostChildrenIds.map((id) => editor.getShape(id)))\n\n\t\t// Don't fall \"up\" into frames in front of the shape\n\t\t// if (pageShapes.indexOf(shape) < frameSortPosition) continue shapeCheck\n\n\t\t// Otherwise, we have no next dropping shape under the cursor, so go find\n\t\t// all the frames on the page where the moving shapes will fall into\n\t\tconst { reparenting, remainingShapesToReparent } = getDroppedShapesToNewParents(\n\t\t\teditor,\n\t\t\tlostChildren,\n\t\t\t(shape, maybeNewParent) => {\n\t\t\t\t// If we're filtering out a potential parent, don't reparent shapes to the filtered out shape\n\t\t\t\tif (opts?.filter && !opts.filter(maybeNewParent)) return false\n\t\t\t\treturn (\n\t\t\t\t\tmaybeNewParent.id !== prevParent.id &&\n\t\t\t\t\tsortedShapeIds.indexOf(maybeNewParent.id) < sortedShapeIds.indexOf(shape.id)\n\t\t\t\t)\n\t\t\t}\n\t\t)\n\n\t\treparenting.forEach((childrenToReparent, newParentId) => {\n\t\t\tif (childrenToReparent.length === 0) return\n\t\t\tif (!parentsToNewChildren[newParentId]) {\n\t\t\t\tparentsToNewChildren[newParentId] = {\n\t\t\t\t\tparentId: newParentId,\n\t\t\t\t\tshapeIds: [],\n\t\t\t\t}\n\t\t\t}\n\t\t\tparentsToNewChildren[newParentId].shapeIds.push(...childrenToReparent.map((s) => s.id))\n\t\t})\n\n\t\t// Reparent the rest to the page (or containing group)\n\t\tif (remainingShapesToReparent.size > 0) {\n\t\t\t// The remaining shapes are going to be reparented to the old parent's containing group, if there was one, or else to the page\n\t\t\tconst newParentId =\n\t\t\t\teditor.findShapeAncestor(prevParent, (s) => editor.isShapeOfType<TLGroupShape>(s, 'group'))\n\t\t\t\t\t?.id ?? editor.getCurrentPageId()\n\n\t\t\tremainingShapesToReparent.forEach((shape) => {\n\t\t\t\tif (!parentsToNewChildren[newParentId]) {\n\t\t\t\t\tlet insertIndexKey: IndexKey | undefined\n\n\t\t\t\t\tconst oldParentSiblingIds = editor.getSortedChildIdsForParent(newParentId)\n\t\t\t\t\tconst oldParentIndex = oldParentSiblingIds.indexOf(prevParent.id)\n\t\t\t\t\tif (oldParentIndex > -1) {\n\t\t\t\t\t\t// If the old parent is a direct child of the new parent, then we'll add them above the old parent but below the next sibling.\n\t\t\t\t\t\tconst siblingsIndexAbove = oldParentSiblingIds[oldParentIndex + 1]\n\t\t\t\t\t\tconst indexKeyAbove = siblingsIndexAbove\n\t\t\t\t\t\t\t? editor.getShape(siblingsIndexAbove)!.index\n\t\t\t\t\t\t\t: getIndexAbove(prevParent.index)\n\t\t\t\t\t\tinsertIndexKey = getIndexBetween(prevParent.index, indexKeyAbove)\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the old parent is not a direct child of the new parent, then we'll add them to the \"top\" of the new parent's children.\n\t\t\t\t\t\t// This is done automatically if we leave the index undefined, so let's do that.\n\t\t\t\t\t}\n\n\t\t\t\t\tparentsToNewChildren[newParentId] = {\n\t\t\t\t\t\tparentId: newParentId,\n\t\t\t\t\t\tshapeIds: [],\n\t\t\t\t\t\tindex: insertIndexKey,\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tparentsToNewChildren[newParentId].shapeIds.push(shape.id)\n\t\t\t})\n\t\t}\n\t}\n\n\teditor.run(() => {\n\t\tObject.values(parentsToNewChildren).forEach(({ parentId, shapeIds, index }) => {\n\t\t\tif (shapeIds.length === 0) return\n\t\t\t// Before we reparent, sort the new shape ids by their place in the original absolute order on the page\n\t\t\tshapeIds.sort((a, b) => (sortedShapeIds.indexOf(a) < sortedShapeIds.indexOf(b) ? -1 : 1))\n\t\t\teditor.reparentShapes(shapeIds, parentId, index)\n\t\t})\n\t})\n}\n\n/**\n * Get the shapes that overlap with a given shape.\n *\n * @param editor - The editor instance.\n * @param shape - The shapes or shape IDs to check against.\n * @param otherShapes - The shapes or shape IDs to check for overlap.\n * @returns An array of shapes or shape IDs that overlap with the given shape.\n */\nfunction getOverlappingShapes<T extends TLShape[] | TLShapeId[]>(\n\teditor: Editor,\n\tshape: T[number],\n\totherShapes: T\n) {\n\tif (otherShapes.length === 0) {\n\t\treturn EMPTY_ARRAY\n\t}\n\n\tconst parentPageBounds = editor.getShapePageBounds(shape)\n\tif (!parentPageBounds) return EMPTY_ARRAY\n\n\tconst parentGeometry = editor.getShapeGeometry(shape)\n\tconst parentPageTransform = editor.getShapePageTransform(shape)\n\tconst parentPageCorners = parentPageTransform.applyToPoints(parentGeometry.vertices)\n\n\tconst _shape = editor.getShape(shape)\n\tif (!_shape) return EMPTY_ARRAY\n\n\tconst pageTransform = editor.getShapePageTransform(shape)\n\tconst clipPath = editor.getShapeUtil(_shape.type).getClipPath?.(_shape)\n\n\tconst parentPageMaskVertices = clipPath ? pageTransform.applyToPoints(clipPath) : undefined\n\tconst parentPagePolygon = parentPageMaskVertices\n\t\t? intersectPolygonPolygon(parentPageMaskVertices, parentPageCorners)\n\t\t: parentPageCorners\n\n\tif (!parentPagePolygon) return EMPTY_ARRAY\n\n\treturn otherShapes.filter((childId) => {\n\t\tconst shapePageBounds = editor.getShapePageBounds(childId)\n\t\tif (!shapePageBounds || !parentPageBounds.includes(shapePageBounds)) return false\n\n\t\tconst parentPolygonInShapeShape = editor\n\t\t\t.getShapePageTransform(childId)\n\t\t\t.clone()\n\t\t\t.invert()\n\t\t\t.applyToPoints(parentPagePolygon)\n\n\t\tconst geometry = editor.getShapeGeometry(childId)\n\n\t\treturn geometry.overlapsPolygon(parentPolygonInShapeShape)\n\t})\n}\n\n/**\n * Get the shapes that will be reparented to new parents when the shapes are dropped.\n *\n * @param editor - The editor instance.\n * @param shapes - The shapes to check.\n * @param cb - A callback to filter out certain shapes.\n * @returns An object with the shapes that will be reparented to new parents and the shapes that will be reparented to the page or their ancestral group.\n *\n * @public\n */\nexport function getDroppedShapesToNewParents(\n\teditor: Editor,\n\tshapes: Set<TLShape> | TLShape[],\n\tcb?: (shape: TLShape, parent: TLShape) => boolean\n) {\n\tconst shapesToActuallyCheck = new Set<TLShape>(shapes)\n\tconst movingGroups = new Set<TLGroupShape>()\n\n\tfor (const shape of shapes) {\n\t\tconst parent = editor.getShapeParent(shape)\n\t\tif (parent && editor.isShapeOfType<TLGroupShape>(parent, 'group')) {\n\t\t\tif (!movingGroups.has(parent)) {\n\t\t\t\tmovingGroups.add(parent)\n\t\t\t}\n\t\t}\n\t}\n\n\t// If all of a group's children are moving, then move the group instead\n\tfor (const movingGroup of movingGroups) {\n\t\tconst children = compact(\n\t\t\teditor.getSortedChildIdsForParent(movingGroup).map((id) => editor.getShape(id))\n\t\t)\n\t\tfor (const child of children) {\n\t\t\tshapesToActuallyCheck.delete(child)\n\t\t}\n\t\tshapesToActuallyCheck.add(movingGroup)\n\t}\n\n\t// this could be cached and passed in\n\tconst shapeGroupIds = new Map<TLShapeId, TLShapeId | undefined>()\n\n\tconst reparenting = new Map<TLShapeId, TLShape[]>()\n\n\tconst remainingShapesToReparent = new Set(shapesToActuallyCheck)\n\n\tconst potentialParentShapes = editor\n\t\t.getCurrentPageShapesSorted()\n\t\t// filter out any shapes that aren't frames or that are included among the provided shapes\n\t\t.filter(\n\t\t\t(s) =>\n\t\t\t\teditor.getShapeUtil(s).canReceiveNewChildrenOfType?.(s, s.type) &&\n\t\t\t\t!remainingShapesToReparent.has(s)\n\t\t)\n\n\tparentCheck: for (let i = potentialParentShapes.length - 1; i >= 0; i--) {\n\t\tconst parentShape = potentialParentShapes[i]\n\t\tconst parentShapeContainingGroupId = editor.findShapeAncestor(parentShape, (s) =>\n\t\t\teditor.isShapeOfType<TLGroupShape>(s, 'group')\n\t\t)?.id\n\n\t\tconst parentGeometry = editor.getShapeGeometry(parentShape)\n\t\tconst parentPageTransform = editor.getShapePageTransform(parentShape)\n\t\tconst parentPageMaskVertices = editor.getShapeMask(parentShape)\n\t\tconst parentPageCorners = parentPageTransform.applyToPoints(parentGeometry.vertices)\n\t\tconst parentPagePolygon = parentPageMaskVertices\n\t\t\t? intersectPolygonPolygon(parentPageMaskVertices, parentPageCorners)\n\t\t\t: parentPageCorners\n\n\t\tif (!parentPagePolygon) continue parentCheck\n\n\t\tconst childrenToReparent = []\n\n\t\t// For each of the dropping shapes...\n\t\tshapeCheck: for (const shape of remainingShapesToReparent) {\n\t\t\t// Don't reparent a frame to itself\n\t\t\tif (parentShape.id === shape.id) continue shapeCheck\n\n\t\t\t// Use the callback to filter out certain shapes\n\t\t\tif (cb && !cb(shape, parentShape)) continue shapeCheck\n\n\t\t\tif (!shapeGroupIds.has(shape.id)) {\n\t\t\t\tshapeGroupIds.set(\n\t\t\t\t\tshape.id,\n\t\t\t\t\teditor.findShapeAncestor(shape, (s) => editor.isShapeOfType<TLGroupShape>(s, 'group'))?.id\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tconst shapeGroupId = shapeGroupIds.get(shape.id)\n\n\t\t\t// Are the shape and the parent part of different groups?\n\t\t\tif (shapeGroupId !== parentShapeContainingGroupId) continue shapeCheck\n\n\t\t\t// Is the shape is actually the ancestor of the parent?\n\t\t\tif (editor.findShapeAncestor(parentShape, (s) => shape.id === s.id)) continue shapeCheck\n\n\t\t\t// Convert the parent polygon to the shape's space\n\t\t\tconst parentPolygonInShapeSpace = editor\n\t\t\t\t.getShapePageTransform(shape)\n\t\t\t\t.clone()\n\t\t\t\t.invert()\n\t\t\t\t.applyToPoints(parentPagePolygon)\n\n\t\t\t// If the shape overlaps the parent polygon, reparent it to that parent\n\t\t\tif (editor.getShapeGeometry(shape).overlapsPolygon(parentPolygonInShapeSpace)) {\n\t\t\t\t// Use the util to check if the shape can be reparented to the parent\n\t\t\t\tif (\n\t\t\t\t\t!editor.getShapeUtil(parentShape).canReceiveNewChildrenOfType?.(parentShape, shape.type)\n\t\t\t\t)\n\t\t\t\t\tcontinue shapeCheck\n\n\t\t\t\tif (shape.parentId !== parentShape.id) {\n\t\t\t\t\tchildrenToReparent.push(shape)\n\t\t\t\t}\n\t\t\t\tremainingShapesToReparent.delete(shape)\n\t\t\t\tcontinue shapeCheck\n\t\t\t}\n\t\t}\n\n\t\tif (childrenToReparent.length) {\n\t\t\treparenting.set(parentShape.id, childrenToReparent)\n\t\t}\n\t}\n\n\treturn {\n\t\t// these are the shapes that will be reparented to new parents\n\t\treparenting,\n\t\t// these are the shapes that will be reparented to the page or their ancestral group\n\t\tremainingShapesToReparent,\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA4B;AAE5B,mBAAkE;AAElE,uBAAwC;AAYjC,SAAS,sBACf,QACA,UACA,MACC;AACD,QAAM,iBAAiB,oBAAI,IAAa;AAExC,aAAW,MAAM,UAAU;AAC1B,UAAM,QAAQ,OAAO,SAAS,EAAE;AAEhC,QAAI,CAAC,MAAO;AACZ,mBAAe,IAAI,KAAK;AAExB,UAAM,SAAS,OAAO,SAAS,MAAM,QAAQ;AAC7C,QAAI,CAAC,OAAQ;AACb,mBAAe,IAAI,MAAM;AAAA,EAC1B;AAGA,QAAM,wBAAwB,oBAAI,IAA0B;AAE5D,aAAW,UAAU,gBAAgB;AACp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Aa,CAAC,MAAM,MAAM,OAAO,EAAE,EAAE,EAAG,UAAS;AAG9E,YAAM,4BAA4B,OAChC,sBAAsB,KAAK,EAC3B,MAAM,EACN,OAAO,EACP,cAAc,iBAAiB;AAGjC,UAAI,OAAO,iBAAiB,KAAK,EAAE,gBAAgB,yBAAyB,GAAG;AAE9E,YACC,CAAC,OAAO,aAAa,WAAW,EAAE,8BAA8B,aAAa,MAAM,IAAI;AAEvF,mBAAS;AAEV,YAAI,MAAM,aAAa,YAAY,IAAI;AACtC,6BAAmB,KAAK,KAAK;AAAA,QAC9B;AACA,kCAA0B,OAAO,KAAK;AACtC,iBAAS;AAAA,MACV;AAAA,IACD;AAEA,QAAI,mBAAmB,QAAQ;AAC9B,kBAAY,IAAI,YAAY,IAAI,kBAAkB;AAAA,IACnD;AAAA,EACD;AAEA,SAAO;AAAA;AAAA,IAEN;AAAA;AAAA,IAEA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["shapeIds"]
|
|
7
7
|
}
|
package/dist-cjs/version.js
CHANGED
|
@@ -22,10 +22,10 @@ __export(version_exports, {
|
|
|
22
22
|
version: () => version
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(version_exports);
|
|
25
|
-
const version = "4.3.0-
|
|
25
|
+
const version = "4.3.0-next.2b3bfbba757b";
|
|
26
26
|
const publishDates = {
|
|
27
27
|
major: "2025-09-18T14:39:22.803Z",
|
|
28
|
-
minor: "2025-11-
|
|
29
|
-
patch: "2025-11-
|
|
28
|
+
minor: "2025-11-25T08:43:48.918Z",
|
|
29
|
+
patch: "2025-11-25T08:43:48.918Z"
|
|
30
30
|
};
|
|
31
31
|
//# sourceMappingURL=version.js.map
|
package/dist-cjs/version.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/version.ts"],
|
|
4
|
-
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '4.3.0-
|
|
4
|
+
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '4.3.0-next.2b3bfbba757b'\nexport const publishDates = {\n\tmajor: '2025-09-18T14:39:22.803Z',\n\tminor: '2025-11-25T08:43:48.918Z',\n\tpatch: '2025-11-25T08:43:48.918Z',\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist-esm/index.d.mts
CHANGED
|
@@ -7,7 +7,6 @@ import { Editor as Editor_2 } from '@tiptap/core';
|
|
|
7
7
|
import { EditorProviderProps as EditorProviderProps_2 } from '@tiptap/react';
|
|
8
8
|
import EventEmitter from 'eventemitter3';
|
|
9
9
|
import { ExoticComponent } from 'react';
|
|
10
|
-
import { ExtractShapeByProps } from '@tldraw/tlschema';
|
|
11
10
|
import { ForwardRefExoticComponent } from 'react';
|
|
12
11
|
import { HistoryEntry } from '@tldraw/store';
|
|
13
12
|
import { IndexKey } from '@tldraw/utils';
|
|
@@ -49,7 +48,6 @@ import { TLBindingId } from '@tldraw/tlschema';
|
|
|
49
48
|
import { TLBindingUpdate } from '@tldraw/tlschema';
|
|
50
49
|
import { TLBookmarkAsset } from '@tldraw/tlschema';
|
|
51
50
|
import { TLCamera } from '@tldraw/tlschema';
|
|
52
|
-
import { TLCreateShapePartial } from '@tldraw/tlschema';
|
|
53
51
|
import { TLCursor } from '@tldraw/tlschema';
|
|
54
52
|
import { TLCursorType } from '@tldraw/tlschema';
|
|
55
53
|
import { TLDefaultDashStyle } from '@tldraw/tlschema';
|
|
@@ -149,7 +147,7 @@ export declare abstract class BaseBoxShapeTool extends StateNode {
|
|
|
149
147
|
static id: string;
|
|
150
148
|
static initial: string;
|
|
151
149
|
static children(): TLStateNodeConstructor[];
|
|
152
|
-
abstract shapeType:
|
|
150
|
+
abstract shapeType: string;
|
|
153
151
|
onCreate?(_shape: null | TLShape): null | void;
|
|
154
152
|
}
|
|
155
153
|
|
|
@@ -167,7 +165,7 @@ export declare abstract class BaseBoxShapeUtil<Shape extends TLBaseBoxShape> ext
|
|
|
167
165
|
*
|
|
168
166
|
* @public
|
|
169
167
|
*/
|
|
170
|
-
export declare interface BindingOnChangeOptions<Binding extends
|
|
168
|
+
export declare interface BindingOnChangeOptions<Binding extends TLUnknownBinding> {
|
|
171
169
|
/** The binding record before the change is made. */
|
|
172
170
|
bindingBefore: Binding;
|
|
173
171
|
/** The binding record after the change is made. */
|
|
@@ -180,7 +178,7 @@ export declare interface BindingOnChangeOptions<Binding extends TLBinding = TLBi
|
|
|
180
178
|
*
|
|
181
179
|
* @public
|
|
182
180
|
*/
|
|
183
|
-
export declare interface BindingOnCreateOptions<Binding extends
|
|
181
|
+
export declare interface BindingOnCreateOptions<Binding extends TLUnknownBinding> {
|
|
184
182
|
/** The binding being created. */
|
|
185
183
|
binding: Binding;
|
|
186
184
|
}
|
|
@@ -191,7 +189,7 @@ export declare interface BindingOnCreateOptions<Binding extends TLBinding = TLBi
|
|
|
191
189
|
*
|
|
192
190
|
* @public
|
|
193
191
|
*/
|
|
194
|
-
export declare interface BindingOnDeleteOptions<Binding extends
|
|
192
|
+
export declare interface BindingOnDeleteOptions<Binding extends TLUnknownBinding> {
|
|
195
193
|
/** The binding being deleted. */
|
|
196
194
|
binding: Binding;
|
|
197
195
|
}
|
|
@@ -202,7 +200,7 @@ export declare interface BindingOnDeleteOptions<Binding extends TLBinding = TLBi
|
|
|
202
200
|
*
|
|
203
201
|
* @public
|
|
204
202
|
*/
|
|
205
|
-
export declare interface BindingOnShapeChangeOptions<Binding extends
|
|
203
|
+
export declare interface BindingOnShapeChangeOptions<Binding extends TLUnknownBinding> {
|
|
206
204
|
/** The binding record linking these two shapes. */
|
|
207
205
|
binding: Binding;
|
|
208
206
|
/** The shape record before the change is made. */
|
|
@@ -226,7 +224,7 @@ export declare interface BindingOnShapeChangeOptions<Binding extends TLBinding =
|
|
|
226
224
|
*
|
|
227
225
|
* @public
|
|
228
226
|
*/
|
|
229
|
-
export declare interface BindingOnShapeDeleteOptions<Binding extends
|
|
227
|
+
export declare interface BindingOnShapeDeleteOptions<Binding extends TLUnknownBinding> {
|
|
230
228
|
/** The binding record that refers to the shape in question. */
|
|
231
229
|
binding: Binding;
|
|
232
230
|
/** The shape that is about to be deleted. */
|
|
@@ -258,7 +256,7 @@ export declare interface BindingOnShapeDeleteOptions<Binding extends TLBinding =
|
|
|
258
256
|
*
|
|
259
257
|
* @public
|
|
260
258
|
*/
|
|
261
|
-
export declare interface BindingOnShapeIsolateOptions<Binding extends
|
|
259
|
+
export declare interface BindingOnShapeIsolateOptions<Binding extends TLUnknownBinding> {
|
|
262
260
|
/** The binding record that refers to the shape in question. */
|
|
263
261
|
binding: Binding;
|
|
264
262
|
/**
|
|
@@ -269,7 +267,7 @@ export declare interface BindingOnShapeIsolateOptions<Binding extends TLBinding
|
|
|
269
267
|
}
|
|
270
268
|
|
|
271
269
|
/** @public */
|
|
272
|
-
export declare abstract class BindingUtil<Binding extends
|
|
270
|
+
export declare abstract class BindingUtil<Binding extends TLUnknownBinding = TLUnknownBinding> {
|
|
273
271
|
editor: Editor;
|
|
274
272
|
constructor(editor: Editor);
|
|
275
273
|
static props?: RecordProps<TLUnknownBinding>;
|
|
@@ -1131,7 +1129,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
1131
1129
|
* @public
|
|
1132
1130
|
*/
|
|
1133
1131
|
shapeUtils: {
|
|
1134
|
-
readonly [K in string]?: ShapeUtil<
|
|
1132
|
+
readonly [K in string]?: ShapeUtil<TLUnknownShape>;
|
|
1135
1133
|
};
|
|
1136
1134
|
styleProps: {
|
|
1137
1135
|
[key: string]: Map<StyleProp<any>, string>;
|
|
@@ -1151,18 +1149,16 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
1151
1149
|
*
|
|
1152
1150
|
* @public
|
|
1153
1151
|
*/
|
|
1154
|
-
getShapeUtil<
|
|
1155
|
-
|
|
1156
|
-
}>>;
|
|
1157
|
-
getShapeUtil<S extends TLShape>(shape: S | S['type'] | TLShapePartial<S>): ShapeUtil<S>;
|
|
1152
|
+
getShapeUtil<S extends TLUnknownShape>(shape: S | TLShapePartial<S>): ShapeUtil<S>;
|
|
1153
|
+
getShapeUtil<S extends TLUnknownShape>(type: S['type']): ShapeUtil<S>;
|
|
1158
1154
|
getShapeUtil<T extends ShapeUtil>(type: T extends ShapeUtil<infer R> ? R['type'] : string): T;
|
|
1159
1155
|
/**
|
|
1160
1156
|
* Returns true if the editor has a shape util for the given shape / shape type.
|
|
1161
1157
|
*
|
|
1162
1158
|
* @param shape - A shape, shape partial, or shape type.
|
|
1163
1159
|
*/
|
|
1164
|
-
hasShapeUtil(shape:
|
|
1165
|
-
hasShapeUtil(type:
|
|
1160
|
+
hasShapeUtil<S extends TLUnknownShape>(shape: S | TLShapePartial<S>): boolean;
|
|
1161
|
+
hasShapeUtil<S extends TLUnknownShape>(type: S['type']): boolean;
|
|
1166
1162
|
hasShapeUtil<T extends ShapeUtil>(type: T extends ShapeUtil<infer R> ? R['type'] : string): boolean;
|
|
1167
1163
|
/**
|
|
1168
1164
|
* A map of shape utility classes (TLShapeUtils) by shape type.
|
|
@@ -1170,7 +1166,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
1170
1166
|
* @public
|
|
1171
1167
|
*/
|
|
1172
1168
|
bindingUtils: {
|
|
1173
|
-
readonly [K in string]?: BindingUtil<
|
|
1169
|
+
readonly [K in string]?: BindingUtil<TLUnknownBinding>;
|
|
1174
1170
|
};
|
|
1175
1171
|
/**
|
|
1176
1172
|
* Get a binding util from a binding itself.
|
|
@@ -1187,12 +1183,10 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
1187
1183
|
*
|
|
1188
1184
|
* @public
|
|
1189
1185
|
*/
|
|
1190
|
-
getBindingUtil<
|
|
1191
|
-
type: K;
|
|
1192
|
-
}>>;
|
|
1193
|
-
getBindingUtil<S extends TLBinding>(binding: {
|
|
1186
|
+
getBindingUtil<S extends TLUnknownBinding>(binding: {
|
|
1194
1187
|
type: S['type'];
|
|
1195
1188
|
} | S): BindingUtil<S>;
|
|
1189
|
+
getBindingUtil<S extends TLUnknownBinding>(type: S['type']): BindingUtil<S>;
|
|
1196
1190
|
getBindingUtil<T extends BindingUtil>(type: T extends BindingUtil<infer R> ? R['type'] : string): T;
|
|
1197
1191
|
/**
|
|
1198
1192
|
* A manager for the app's history.
|
|
@@ -2771,7 +2765,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
2771
2765
|
*
|
|
2772
2766
|
* @example
|
|
2773
2767
|
* ```ts
|
|
2774
|
-
* const isArrowShape = isShapeOfType(someShape, 'arrow')
|
|
2768
|
+
* const isArrowShape = isShapeOfType<TLArrowShape>(someShape, 'arrow')
|
|
2775
2769
|
* ```
|
|
2776
2770
|
*
|
|
2777
2771
|
* @param util - the TLShapeUtil constructor to test against
|
|
@@ -2779,13 +2773,8 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
2779
2773
|
*
|
|
2780
2774
|
* @public
|
|
2781
2775
|
*/
|
|
2782
|
-
isShapeOfType<
|
|
2783
|
-
|
|
2784
|
-
}>;
|
|
2785
|
-
isShapeOfType<T extends TLShape>(shape: TLShape, type: T['type']): shape is Extract<TLShape, {
|
|
2786
|
-
type: T['type'];
|
|
2787
|
-
}>;
|
|
2788
|
-
isShapeOfType<T extends TLShape = TLShape>(shapeId: TLShapeId, type: T['type']): boolean;
|
|
2776
|
+
isShapeOfType<T extends TLUnknownShape>(shape: TLUnknownShape, type: T['type']): shape is T;
|
|
2777
|
+
isShapeOfType<T extends TLUnknownShape>(shapeId: TLUnknownShape['id'], type: T['type']): shapeId is T['id'];
|
|
2789
2778
|
/**
|
|
2790
2779
|
* Get a shape by its id.
|
|
2791
2780
|
*
|
|
@@ -2936,26 +2925,17 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
2936
2925
|
* Get all bindings of a certain type _from_ a particular shape. These are the bindings whose
|
|
2937
2926
|
* `fromId` matched the shape's ID.
|
|
2938
2927
|
*/
|
|
2939
|
-
getBindingsFromShape<
|
|
2940
|
-
type: K;
|
|
2941
|
-
}>[];
|
|
2942
|
-
getBindingsFromShape<Binding extends TLBinding = TLBinding>(shape: TLShape | TLShapeId, type: Binding['type']): Binding[];
|
|
2928
|
+
getBindingsFromShape<Binding extends TLUnknownBinding = TLBinding>(shape: TLShape | TLShapeId, type: Binding['type']): Binding[];
|
|
2943
2929
|
/**
|
|
2944
2930
|
* Get all bindings of a certain type _to_ a particular shape. These are the bindings whose
|
|
2945
2931
|
* `toId` matches the shape's ID.
|
|
2946
2932
|
*/
|
|
2947
|
-
getBindingsToShape<
|
|
2948
|
-
type: K;
|
|
2949
|
-
}>[];
|
|
2950
|
-
getBindingsToShape<Binding extends TLBinding = TLBinding>(shape: TLShape | TLShapeId, type: Binding['type']): Binding[];
|
|
2933
|
+
getBindingsToShape<Binding extends TLUnknownBinding = TLBinding>(shape: TLShape | TLShapeId, type: Binding['type']): Binding[];
|
|
2951
2934
|
/**
|
|
2952
2935
|
* Get all bindings involving a particular shape. This includes bindings where the shape is the
|
|
2953
2936
|
* `fromId` or `toId`. If a type is provided, only bindings of that type are returned.
|
|
2954
2937
|
*/
|
|
2955
|
-
getBindingsInvolvingShape<
|
|
2956
|
-
type: K;
|
|
2957
|
-
}>[];
|
|
2958
|
-
getBindingsInvolvingShape<Binding extends TLBinding = TLBinding>(shape: TLShape | TLShapeId, type?: Binding['type']): Binding[];
|
|
2938
|
+
getBindingsInvolvingShape<Binding extends TLUnknownBinding = TLBinding>(shape: TLShape | TLShapeId, type?: Binding['type']): Binding[];
|
|
2959
2939
|
/**
|
|
2960
2940
|
* Create bindings from a list of partial bindings. You can omit the ID and most props of a
|
|
2961
2941
|
* binding, but the `type`, `toId`, and `fromId` must all be provided.
|
|
@@ -3270,7 +3250,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
3270
3250
|
*
|
|
3271
3251
|
* @public
|
|
3272
3252
|
*/
|
|
3273
|
-
canCreateShape(shape: OptionalKeys<TLShapePartial<
|
|
3253
|
+
canCreateShape<T extends TLUnknownShape>(shape: OptionalKeys<TLShapePartial<T>, 'id'> | T['id']): boolean;
|
|
3274
3254
|
/**
|
|
3275
3255
|
* Get whether the provided shapes can be created.
|
|
3276
3256
|
*
|
|
@@ -3278,7 +3258,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
3278
3258
|
*
|
|
3279
3259
|
* @public
|
|
3280
3260
|
*/
|
|
3281
|
-
canCreateShapes(shapes: (OptionalKeys<TLShapePartial<
|
|
3261
|
+
canCreateShapes<T extends TLUnknownShape>(shapes: (OptionalKeys<TLShapePartial<T>, 'id'> | T['id'])[]): boolean;
|
|
3282
3262
|
/**
|
|
3283
3263
|
* Create a single shape.
|
|
3284
3264
|
*
|
|
@@ -3292,7 +3272,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
3292
3272
|
*
|
|
3293
3273
|
* @public
|
|
3294
3274
|
*/
|
|
3295
|
-
createShape<
|
|
3275
|
+
createShape<T extends TLUnknownShape>(shape: OptionalKeys<TLShapePartial<T>, 'id'>): this;
|
|
3296
3276
|
/**
|
|
3297
3277
|
* Create shapes.
|
|
3298
3278
|
*
|
|
@@ -3306,7 +3286,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
3306
3286
|
*
|
|
3307
3287
|
* @public
|
|
3308
3288
|
*/
|
|
3309
|
-
createShapes<
|
|
3289
|
+
createShapes<T extends TLUnknownShape>(shapes: OptionalKeys<TLShapePartial<T>, 'id'>[]): this;
|
|
3310
3290
|
private animatingShapes;
|
|
3311
3291
|
/**
|
|
3312
3292
|
* Animate a shape.
|
|
@@ -3392,7 +3372,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
3392
3372
|
*
|
|
3393
3373
|
* @public
|
|
3394
3374
|
*/
|
|
3395
|
-
updateShape<T extends
|
|
3375
|
+
updateShape<T extends TLUnknownShape>(partial: null | TLShapePartial<T> | undefined): this;
|
|
3396
3376
|
/**
|
|
3397
3377
|
* Update shapes using partials of each shape.
|
|
3398
3378
|
*
|
|
@@ -3405,7 +3385,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
3405
3385
|
*
|
|
3406
3386
|
* @public
|
|
3407
3387
|
*/
|
|
3408
|
-
updateShapes<T extends
|
|
3388
|
+
updateShapes<T extends TLUnknownShape>(partials: (null | TLShapePartial<T> | undefined)[]): this;
|
|
3409
3389
|
/* Excluded from this release type: _updateShapes */
|
|
3410
3390
|
/* Excluded from this release type: _getUnlockedShapeIds */
|
|
3411
3391
|
/**
|
|
@@ -5136,7 +5116,7 @@ export declare function setRuntimeOverrides(input: Partial<typeof runtime>): voi
|
|
|
5136
5116
|
export declare function setUserPreferences(user: TLUserPreferences): void;
|
|
5137
5117
|
|
|
5138
5118
|
/** @public */
|
|
5139
|
-
export declare abstract class ShapeUtil<Shape extends
|
|
5119
|
+
export declare abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
5140
5120
|
editor: Editor;
|
|
5141
5121
|
/** Configure this shape utils {@link ShapeUtil.options | `options`}. */
|
|
5142
5122
|
static configure<T extends TLShapeUtilConstructor<any, any>>(this: T, options: T extends new (...args: any[]) => {
|
|
@@ -6061,7 +6041,7 @@ export declare type TLAnyBindingUtilConstructor = TLBindingUtilConstructor<any>;
|
|
|
6061
6041
|
export declare type TLAnyShapeUtilConstructor = TLShapeUtilConstructor<any>;
|
|
6062
6042
|
|
|
6063
6043
|
/** @public */
|
|
6064
|
-
export declare type TLBaseBoxShape =
|
|
6044
|
+
export declare type TLBaseBoxShape = TLBaseShape<string, {
|
|
6065
6045
|
h: number;
|
|
6066
6046
|
w: number;
|
|
6067
6047
|
}>;
|
|
@@ -6083,7 +6063,7 @@ export declare interface TLBaseExternalContent {
|
|
|
6083
6063
|
}
|
|
6084
6064
|
|
|
6085
6065
|
/** @public */
|
|
6086
|
-
export declare interface TLBindingUtilConstructor<T extends
|
|
6066
|
+
export declare interface TLBindingUtilConstructor<T extends TLUnknownBinding, U extends BindingUtil<T> = BindingUtil<T>> {
|
|
6087
6067
|
new (editor: Editor): U;
|
|
6088
6068
|
type: T['type'];
|
|
6089
6069
|
/** Validations for this binding's props. */
|
|
@@ -7517,11 +7497,11 @@ export declare interface TLShapeUtilCanBeLaidOutOpts {
|
|
|
7517
7497
|
*
|
|
7518
7498
|
* @public
|
|
7519
7499
|
*/
|
|
7520
|
-
export declare interface TLShapeUtilCanBindOpts<Shape extends
|
|
7500
|
+
export declare interface TLShapeUtilCanBindOpts<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
7521
7501
|
/** The type of shape referenced by the `fromId` of the binding. */
|
|
7522
|
-
fromShapeType:
|
|
7502
|
+
fromShapeType: string;
|
|
7523
7503
|
/** The type of shape referenced by the `toId` of the binding. */
|
|
7524
|
-
toShapeType:
|
|
7504
|
+
toShapeType: string;
|
|
7525
7505
|
/** The type of binding. */
|
|
7526
7506
|
bindingType: string;
|
|
7527
7507
|
}
|
|
@@ -7533,7 +7513,7 @@ export declare interface TLShapeUtilCanvasSvgDef {
|
|
|
7533
7513
|
}
|
|
7534
7514
|
|
|
7535
7515
|
/** @public */
|
|
7536
|
-
export declare interface TLShapeUtilConstructor<T extends
|
|
7516
|
+
export declare interface TLShapeUtilConstructor<T extends TLUnknownShape, U extends ShapeUtil<T> = ShapeUtil<T>> {
|
|
7537
7517
|
new (editor: Editor): U;
|
|
7538
7518
|
type: T['type'];
|
|
7539
7519
|
props?: RecordProps<T>;
|
package/dist-esm/index.mjs
CHANGED
|
@@ -302,7 +302,7 @@ import { uniq } from "./lib/utils/uniq.mjs";
|
|
|
302
302
|
import { openWindow } from "./lib/utils/window-open.mjs";
|
|
303
303
|
registerTldrawLibraryVersion(
|
|
304
304
|
"@tldraw/editor",
|
|
305
|
-
"4.3.0-
|
|
305
|
+
"4.3.0-next.2b3bfbba757b",
|
|
306
306
|
"esm"
|
|
307
307
|
);
|
|
308
308
|
export {
|
|
@@ -4435,18 +4435,30 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
4435
4435
|
getBinding(id) {
|
|
4436
4436
|
return this.store.get(id);
|
|
4437
4437
|
}
|
|
4438
|
+
/**
|
|
4439
|
+
* Get all bindings of a certain type _from_ a particular shape. These are the bindings whose
|
|
4440
|
+
* `fromId` matched the shape's ID.
|
|
4441
|
+
*/
|
|
4438
4442
|
getBindingsFromShape(shape, type) {
|
|
4439
4443
|
const id = typeof shape === "string" ? shape : shape.id;
|
|
4440
4444
|
return this.getBindingsInvolvingShape(id).filter(
|
|
4441
4445
|
(b) => b.fromId === id && b.type === type
|
|
4442
4446
|
);
|
|
4443
4447
|
}
|
|
4448
|
+
/**
|
|
4449
|
+
* Get all bindings of a certain type _to_ a particular shape. These are the bindings whose
|
|
4450
|
+
* `toId` matches the shape's ID.
|
|
4451
|
+
*/
|
|
4444
4452
|
getBindingsToShape(shape, type) {
|
|
4445
4453
|
const id = typeof shape === "string" ? shape : shape.id;
|
|
4446
4454
|
return this.getBindingsInvolvingShape(id).filter(
|
|
4447
4455
|
(b) => b.toId === id && b.type === type
|
|
4448
4456
|
);
|
|
4449
4457
|
}
|
|
4458
|
+
/**
|
|
4459
|
+
* Get all bindings involving a particular shape. This includes bindings where the shape is the
|
|
4460
|
+
* `fromId` or `toId`. If a type is provided, only bindings of that type are returned.
|
|
4461
|
+
*/
|
|
4450
4462
|
getBindingsInvolvingShape(shape, type) {
|
|
4451
4463
|
const id = typeof shape === "string" ? shape : shape.id;
|
|
4452
4464
|
const result = this._getBindingsIndexCache().get(id) ?? EMPTY_ARRAY;
|
|
@@ -7504,7 +7516,6 @@ class Editor extends (_a = EventEmitter, _getIsShapeHiddenCache_dec = [computed]
|
|
|
7504
7516
|
this.setCursor({ type: this._prevCursor, rotation: 0 });
|
|
7505
7517
|
}
|
|
7506
7518
|
}
|
|
7507
|
-
this.emit("event", info);
|
|
7508
7519
|
this.root.handleEvent(info);
|
|
7509
7520
|
return;
|
|
7510
7521
|
}
|