@tldraw/editor 3.14.0-canary.f6a0206007b3 → 3.14.0-canary.f907ed7d9ee5
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 +17 -26
- package/dist-cjs/index.js +8 -10
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/config/TLSessionStateSnapshot.js +1 -12
- package/dist-cjs/lib/config/TLSessionStateSnapshot.js.map +3 -3
- package/dist-cjs/lib/editor/Editor.js +50 -76
- 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 +22 -22
- package/dist-cjs/lib/editor/derivations/bindingsIndex.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/parentsToChildren.js +16 -16
- package/dist-cjs/lib/editor/derivations/parentsToChildren.js.map +2 -2
- package/dist-cjs/lib/editor/managers/{ClickManager.js → ClickManager/ClickManager.js} +1 -1
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/{EdgeScrollManager.js → EdgeScrollManager/EdgeScrollManager.js} +2 -2
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/{FontManager.js → FontManager/FontManager.js} +4 -1
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/{HistoryManager.js → HistoryManager/HistoryManager.js} +64 -6
- package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/{ScribbleManager.js → ScribbleManager/ScribbleManager.js} +1 -1
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/{TickManager.js → TickManager/TickManager.js} +1 -1
- package/dist-cjs/lib/editor/managers/TickManager/TickManager.js.map +7 -0
- package/dist-cjs/lib/editor/managers/{UserPreferencesManager.js → UserPreferencesManager/UserPreferencesManager.js} +1 -1
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +7 -0
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +1 -1
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +1 -1
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +1 -1
- package/dist-cjs/lib/exports/getSvgJsx.js.map +1 -1
- package/dist-cjs/lib/primitives/Box.js +33 -39
- package/dist-cjs/lib/primitives/Box.js.map +2 -2
- package/dist-cjs/lib/utils/areShapesContentEqual.js +1 -1
- package/dist-cjs/lib/utils/areShapesContentEqual.js.map +2 -2
- package/dist-cjs/lib/utils/reorderShapes.js +11 -10
- package/dist-cjs/lib/utils/reorderShapes.js.map +2 -2
- package/dist-cjs/lib/utils/richText.js +7 -2
- package/dist-cjs/lib/utils/richText.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 +17 -26
- package/dist-esm/index.mjs +12 -10
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/config/TLSessionStateSnapshot.mjs +1 -1
- package/dist-esm/lib/config/TLSessionStateSnapshot.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +50 -76
- 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 +22 -22
- package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/parentsToChildren.mjs +16 -16
- package/dist-esm/lib/editor/derivations/parentsToChildren.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/{ClickManager.mjs → ClickManager/ClickManager.mjs} +1 -1
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/{EdgeScrollManager.mjs → EdgeScrollManager/EdgeScrollManager.mjs} +2 -2
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/{FontManager.mjs → FontManager/FontManager.mjs} +4 -1
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/{HistoryManager.mjs → HistoryManager/HistoryManager.mjs} +60 -2
- package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/{ScribbleManager.mjs → ScribbleManager/ScribbleManager.mjs} +1 -1
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/{TickManager.mjs → TickManager/TickManager.mjs} +1 -1
- package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs.map +7 -0
- package/dist-esm/lib/editor/managers/{UserPreferencesManager.mjs → UserPreferencesManager/UserPreferencesManager.mjs} +1 -1
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +7 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +1 -1
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +1 -1
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +1 -1
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +1 -1
- package/dist-esm/lib/primitives/Box.mjs +33 -39
- package/dist-esm/lib/primitives/Box.mjs.map +2 -2
- package/dist-esm/lib/utils/areShapesContentEqual.mjs +1 -1
- package/dist-esm/lib/utils/areShapesContentEqual.mjs.map +2 -2
- package/dist-esm/lib/utils/reorderShapes.mjs +11 -10
- package/dist-esm/lib/utils/reorderShapes.mjs.map +2 -2
- package/dist-esm/lib/utils/richText.mjs +8 -3
- package/dist-esm/lib/utils/richText.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +8 -9
- package/src/index.ts +13 -8
- package/src/lib/config/TLSessionStateSnapshot.ts +1 -1
- package/src/lib/editor/Editor.test.ts +252 -3
- package/src/lib/editor/Editor.ts +48 -75
- package/src/lib/editor/bindings/BindingUtil.ts +6 -0
- package/src/lib/editor/derivations/bindingsIndex.ts +27 -26
- package/src/lib/editor/derivations/parentsToChildren.ts +28 -25
- package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +442 -0
- package/src/lib/editor/managers/{ClickManager.ts → ClickManager/ClickManager.ts} +3 -3
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +374 -0
- package/src/lib/editor/managers/{EdgeScrollManager.ts → EdgeScrollManager/EdgeScrollManager.ts} +3 -3
- package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +455 -0
- package/src/lib/editor/managers/{FocusManager.ts → FocusManager/FocusManager.ts} +1 -1
- package/src/lib/editor/managers/FontManager/FontManager.test.ts +263 -0
- package/src/lib/editor/managers/{FontManager.ts → FontManager/FontManager.ts} +5 -2
- package/src/lib/editor/managers/{HistoryManager.test.ts → HistoryManager/HistoryManager.test.ts} +388 -1
- package/src/lib/editor/managers/{HistoryManager.ts → HistoryManager/HistoryManager.ts} +73 -2
- package/src/lib/editor/managers/ScribbleManager/ScribbleManager.test.ts +624 -0
- package/src/lib/editor/managers/{ScribbleManager.ts → ScribbleManager/ScribbleManager.ts} +2 -2
- package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +485 -0
- package/src/lib/editor/managers/TextManager/TextManager.test.ts +411 -0
- package/src/lib/editor/managers/{TextManager.ts → TextManager/TextManager.ts} +1 -1
- package/src/lib/editor/managers/TickManager/TickManager.test.ts +314 -0
- package/src/lib/editor/managers/{TickManager.ts → TickManager/TickManager.ts} +2 -2
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +591 -0
- package/src/lib/editor/managers/{UserPreferencesManager.ts → UserPreferencesManager/UserPreferencesManager.ts} +2 -2
- package/src/lib/editor/shapes/ShapeUtil.ts +1 -1
- package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +1 -1
- package/src/lib/exports/getSvgJsx.tsx +1 -1
- package/src/lib/primitives/Box.test.ts +588 -7
- package/src/lib/primitives/Box.ts +33 -41
- package/src/lib/utils/areShapesContentEqual.ts +1 -2
- package/src/lib/utils/reorderShapes.ts +10 -13
- package/src/lib/utils/richText.ts +10 -4
- package/src/version.ts +3 -3
- package/dist-cjs/lib/editor/managers/ClickManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/EdgeScrollManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/FocusManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/FontManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/HistoryManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/ScribbleManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/Stack.js +0 -82
- package/dist-cjs/lib/editor/managers/Stack.js.map +0 -7
- package/dist-cjs/lib/editor/managers/TextManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/TickManager.js.map +0 -7
- package/dist-cjs/lib/editor/managers/UserPreferencesManager.js.map +0 -7
- package/dist-esm/lib/editor/managers/ClickManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/EdgeScrollManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/FocusManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/FontManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/HistoryManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/ScribbleManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/Stack.mjs +0 -62
- package/dist-esm/lib/editor/managers/Stack.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/TextManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/TickManager.mjs.map +0 -7
- package/dist-esm/lib/editor/managers/UserPreferencesManager.mjs.map +0 -7
- package/src/lib/editor/managers/ScribbleManager.test.ts +0 -32
- package/src/lib/editor/managers/Stack.ts +0 -71
- /package/dist-cjs/lib/editor/managers/{FocusManager.js → FocusManager/FocusManager.js} +0 -0
- /package/dist-cjs/lib/editor/managers/{TextManager.js → TextManager/TextManager.js} +0 -0
- /package/dist-esm/lib/editor/managers/{FocusManager.mjs → FocusManager/FocusManager.mjs} +0 -0
- /package/dist-esm/lib/editor/managers/{TextManager.mjs → TextManager/TextManager.mjs} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/utils/areShapesContentEqual.ts"],
|
|
4
|
-
"sourcesContent": ["import { TLShape } from '@tldraw/tlschema'\n\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { TLShape } from '@tldraw/tlschema'\n\nexport const areShapesContentEqual = (a: TLShape, b: TLShape) =>\n\ta.props === b.props && a.meta === b.meta\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,wBAAwB,CAAC,GAAY,MACjD,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { compact, getIndicesBetween, sortByIndex } from "@tldraw/utils";
|
|
2
|
-
import { polygonsIntersect } from "../primitives/intersect.mjs";
|
|
3
2
|
function getReorderingShapesChanges(editor, operation, ids, opts) {
|
|
4
3
|
if (ids.length === 0) return [];
|
|
5
4
|
const parents = /* @__PURE__ */ new Map();
|
|
@@ -89,16 +88,18 @@ function reorderToFront(moving, children, changes) {
|
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
90
|
function getOverlapChecker(editor, moving) {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
const movingBounds = compact(
|
|
92
|
+
Array.from(moving).map((shape) => {
|
|
93
|
+
const bounds = editor.getShapePageBounds(shape);
|
|
94
|
+
if (!bounds) return null;
|
|
95
|
+
return { shape, bounds };
|
|
96
|
+
})
|
|
97
|
+
);
|
|
97
98
|
const isOverlapping = (child) => {
|
|
98
|
-
const
|
|
99
|
-
if (!
|
|
100
|
-
return
|
|
101
|
-
return
|
|
99
|
+
const bounds = editor.getShapePageBounds(child);
|
|
100
|
+
if (!bounds) return false;
|
|
101
|
+
return movingBounds.some((other) => {
|
|
102
|
+
return other.bounds.includes(bounds);
|
|
102
103
|
});
|
|
103
104
|
};
|
|
104
105
|
return isOverlapping;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/utils/reorderShapes.ts"],
|
|
4
|
-
"sourcesContent": ["import { TLParentId, TLShape, TLShapeId, TLShapePartial } from '@tldraw/tlschema'\nimport { IndexKey, compact, getIndicesBetween, sortByIndex } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\
|
|
5
|
-
"mappings": "AACA,SAAmB,SAAS,mBAAmB,mBAAmB;
|
|
4
|
+
"sourcesContent": ["import { TLParentId, TLShape, TLShapeId, TLShapePartial } from '@tldraw/tlschema'\nimport { IndexKey, compact, getIndicesBetween, sortByIndex } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\n\nexport function getReorderingShapesChanges(\n\teditor: Editor,\n\toperation: 'toBack' | 'toFront' | 'forward' | 'backward',\n\tids: TLShapeId[],\n\topts?: { considerAllShapes?: boolean }\n) {\n\tif (ids.length === 0) return []\n\n\t// From the ids that are moving, collect the parents, their children, and which of those children are moving\n\tconst parents = new Map<TLParentId, { moving: Set<TLShape>; children: TLShape[] }>()\n\n\tfor (const shape of compact(ids.map((id) => editor.getShape(id)))) {\n\t\tconst { parentId } = shape\n\t\tif (!parents.has(parentId)) {\n\t\t\tparents.set(parentId, {\n\t\t\t\tchildren: compact(\n\t\t\t\t\teditor.getSortedChildIdsForParent(parentId).map((id) => editor.getShape(id))\n\t\t\t\t),\n\t\t\t\tmoving: new Set(),\n\t\t\t})\n\t\t}\n\t\tparents.get(parentId)!.moving.add(shape)\n\t}\n\n\tconst changes: TLShapePartial[] = []\n\n\tswitch (operation) {\n\t\tcase 'toBack': {\n\t\t\tparents.forEach(({ moving, children }) => reorderToBack(moving, children, changes))\n\t\t\tbreak\n\t\t}\n\t\tcase 'toFront': {\n\t\t\tparents.forEach(({ moving, children }) => reorderToFront(moving, children, changes))\n\t\t\tbreak\n\t\t}\n\t\tcase 'forward': {\n\t\t\tparents.forEach(({ moving, children }) =>\n\t\t\t\treorderForward(editor, moving, children, changes, opts)\n\t\t\t)\n\t\t\tbreak\n\t\t}\n\t\tcase 'backward': {\n\t\t\tparents.forEach(({ moving, children }) =>\n\t\t\t\treorderBackward(editor, moving, children, changes, opts)\n\t\t\t)\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn changes\n}\n\n/**\n * Reorders the moving shapes to the back of the parent's children.\n *\n * @param moving The set of shapes that are moving\n * @param children The parent's children\n * @param changes The changes array to push changes to\n */\nfunction reorderToBack(moving: Set<TLShape>, children: TLShape[], changes: TLShapePartial[]) {\n\tconst len = children.length\n\n\t// If all of the children are moving, there's nothing to do\n\tif (moving.size === len) return\n\n\tlet below: IndexKey | undefined\n\tlet above: IndexKey | undefined\n\n\t// Starting at the bottom of this parent's children...\n\tfor (let i = 0; i < len; i++) {\n\t\tconst shape = children[i]\n\n\t\tif (moving.has(shape)) {\n\t\t\t// If we've found a moving shape before we've found a non-moving shape,\n\t\t\t// then that shape is already at the back; we can remove it from the\n\t\t\t// moving set and mark it as the shape that will be below the moved shapes.\n\t\t\tbelow = shape.index\n\t\t\tmoving.delete(shape)\n\t\t} else {\n\t\t\t// The first non-moving shape we find will be above our moved shapes; we'll\n\t\t\t// put our moving shapes between it and the shape marked as below (if any).\n\t\t\tabove = shape.index\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif (moving.size === 0) {\n\t\t// If our moving set is empty, there's nothing to do; all of our shapes were\n\t\t// already at the back of the parent's children.\n\t\treturn\n\t} else {\n\t\t// Sort the moving shapes by their current index, then apply the new indices\n\t\tconst indices = getIndicesBetween(below, above, moving.size)\n\t\tchanges.push(\n\t\t\t...Array.from(moving.values())\n\t\t\t\t.sort(sortByIndex)\n\t\t\t\t.map((shape, i) => ({ ...shape, index: indices[i] }))\n\t\t)\n\t}\n}\n\n/**\n * Reorders the moving shapes to the front of the parent's children.\n *\n * @param moving The set of shapes that are moving\n * @param children The parent's children\n * @param changes The changes array to push changes to\n */\nfunction reorderToFront(moving: Set<TLShape>, children: TLShape[], changes: TLShapePartial[]) {\n\tconst len = children.length\n\n\t// If all of the children are moving, there's nothing to do\n\tif (moving.size === len) return\n\n\tlet below: IndexKey | undefined\n\tlet above: IndexKey | undefined\n\n\t// Starting at the top of this parent's children...\n\tfor (let i = len - 1; i > -1; i--) {\n\t\tconst shape = children[i]\n\n\t\tif (moving.has(shape)) {\n\t\t\t// If we've found a moving shape before we've found a non-moving shape,\n\t\t\t// then that shape is already at the front; we can remove it from the\n\t\t\t// moving set and mark it as the shape that will be above the moved shapes.\n\t\t\tabove = shape.index\n\t\t\tmoving.delete(shape)\n\t\t} else {\n\t\t\t// The first non-moving shape we find will be below our moved shapes; we'll\n\t\t\t// put our moving shapes between it and the shape marked as above (if any).\n\t\t\tbelow = shape.index\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif (moving.size === 0) {\n\t\t// If our moving set is empty, there's nothing to do; all of our shapes were\n\t\t// already at the front of the parent's children.\n\t\treturn\n\t} else {\n\t\t// Sort the moving shapes by their current index, then apply the new indices\n\t\tconst indices = getIndicesBetween(below, above, moving.size)\n\t\tchanges.push(\n\t\t\t...Array.from(moving.values())\n\t\t\t\t.sort(sortByIndex)\n\t\t\t\t.map((shape, i) => ({ ...shape, index: indices[i] }))\n\t\t)\n\t}\n}\n\nfunction getOverlapChecker(editor: Editor, moving: Set<TLShape>) {\n\tconst movingBounds = compact(\n\t\tArray.from(moving).map((shape) => {\n\t\t\tconst bounds = editor.getShapePageBounds(shape)\n\t\t\tif (!bounds) return null\n\t\t\treturn { shape, bounds }\n\t\t})\n\t)\n\tconst isOverlapping = (child: TLShape) => {\n\t\tconst bounds = editor.getShapePageBounds(child)\n\t\tif (!bounds) return false\n\t\treturn movingBounds.some((other) => {\n\t\t\treturn other.bounds.includes(bounds)\n\t\t})\n\t}\n\n\treturn isOverlapping\n}\n\n/**\n * Reorders the moving shapes forward in the parent's children.\n *\n * @param editor The editor\n * @param moving The set of shapes that are moving\n * @param children The parent's children\n * @param changes The changes array to push changes to\n * @param opts The options\n */\nfunction reorderForward(\n\teditor: Editor,\n\tmoving: Set<TLShape>,\n\tchildren: TLShape[],\n\tchanges: TLShapePartial[],\n\topts?: { considerAllShapes?: boolean }\n) {\n\tconst isOverlapping = getOverlapChecker(editor, moving)\n\n\tconst len = children.length\n\n\t// If all of the children are moving, there's nothing to do\n\tif (moving.size === len) return\n\n\tlet state = { name: 'skipping' } as\n\t\t| { name: 'skipping' }\n\t\t| { name: 'selecting'; selectIndex: number }\n\n\t// Starting at the bottom of this parent's children...\n\tfor (let i = 0; i < len; i++) {\n\t\tconst isMoving = moving.has(children[i])\n\n\t\tswitch (state.name) {\n\t\t\tcase 'skipping': {\n\t\t\t\tif (!isMoving) continue\n\t\t\t\t// If we find a moving shape while skipping, start selecting\n\t\t\t\tstate = { name: 'selecting', selectIndex: i }\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'selecting': {\n\t\t\t\tif (isMoving) continue\n\t\t\t\tif (!opts?.considerAllShapes && !isOverlapping(children[i])) continue\n\t\t\t\t// if we find a non-moving and overlapping shape while selecting, move all selected\n\t\t\t\t// shapes in front of the not moving shape; and start skipping\n\t\t\t\tconst { selectIndex } = state\n\t\t\t\tgetIndicesBetween(children[i].index, children[i + 1]?.index, i - selectIndex).forEach(\n\t\t\t\t\t(index, k) => {\n\t\t\t\t\t\tconst child = children[selectIndex + k]\n\t\t\t\t\t\t// If the shape is not moving (therefore also not overlapping), skip it\n\t\t\t\t\t\tif (!moving.has(child)) return\n\t\t\t\t\t\tchanges.push({ ...child, index })\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t\tstate = { name: 'skipping' }\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Reorders the moving shapes backward in the parent's children.\n *\n * @param editor The editor\n * @param moving The set of shapes that are moving\n * @param children The parent's children\n * @param changes The changes array to push changes to\n * @param opts The options\n */\nfunction reorderBackward(\n\teditor: Editor,\n\tmoving: Set<TLShape>,\n\tchildren: TLShape[],\n\tchanges: TLShapePartial[],\n\topts?: { considerAllShapes?: boolean }\n) {\n\tconst isOverlapping = getOverlapChecker(editor, moving)\n\n\tconst len = children.length\n\n\tif (moving.size === len) return\n\n\tlet state = { name: 'skipping' } as\n\t\t| { name: 'skipping' }\n\t\t| { name: 'selecting'; selectIndex: number }\n\n\t// Starting at the top of this parent's children...\n\tfor (let i = len - 1; i > -1; i--) {\n\t\tconst isMoving = moving.has(children[i])\n\n\t\tswitch (state.name) {\n\t\t\tcase 'skipping': {\n\t\t\t\tif (!isMoving) continue\n\t\t\t\t// If we find a moving shape while skipping, start selecting\n\t\t\t\tstate = { name: 'selecting', selectIndex: i }\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'selecting': {\n\t\t\t\tif (isMoving) continue\n\t\t\t\tif (!opts?.considerAllShapes && !isOverlapping(children[i])) continue\n\t\t\t\t// if we find a non-moving and overlapping shape while selecting, move all selected\n\t\t\t\t// shapes in behind of the not moving shape; and start skipping\n\t\t\t\tgetIndicesBetween(children[i - 1]?.index, children[i].index, state.selectIndex - i).forEach(\n\t\t\t\t\t(index, k) => {\n\t\t\t\t\t\tconst child = children[i + k + 1]\n\t\t\t\t\t\t// If the shape is not moving (therefore also not overlapping), skip it\n\t\t\t\t\t\tif (!moving.has(child)) return\n\t\t\t\t\t\tchanges.push({ ...child, index })\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t\tstate = { name: 'skipping' }\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAmB,SAAS,mBAAmB,mBAAmB;AAG3D,SAAS,2BACf,QACA,WACA,KACA,MACC;AACD,MAAI,IAAI,WAAW,EAAG,QAAO,CAAC;AAG9B,QAAM,UAAU,oBAAI,IAA+D;AAEnF,aAAW,SAAS,QAAQ,IAAI,IAAI,CAAC,OAAO,OAAO,SAAS,EAAE,CAAC,CAAC,GAAG;AAClE,UAAM,EAAE,SAAS,IAAI;AACrB,QAAI,CAAC,QAAQ,IAAI,QAAQ,GAAG;AAC3B,cAAQ,IAAI,UAAU;AAAA,QACrB,UAAU;AAAA,UACT,OAAO,2BAA2B,QAAQ,EAAE,IAAI,CAAC,OAAO,OAAO,SAAS,EAAE,CAAC;AAAA,QAC5E;AAAA,QACA,QAAQ,oBAAI,IAAI;AAAA,MACjB,CAAC;AAAA,IACF;AACA,YAAQ,IAAI,QAAQ,EAAG,OAAO,IAAI,KAAK;AAAA,EACxC;AAEA,QAAM,UAA4B,CAAC;AAEnC,UAAQ,WAAW;AAAA,IAClB,KAAK,UAAU;AACd,cAAQ,QAAQ,CAAC,EAAE,QAAQ,SAAS,MAAM,cAAc,QAAQ,UAAU,OAAO,CAAC;AAClF;AAAA,IACD;AAAA,IACA,KAAK,WAAW;AACf,cAAQ,QAAQ,CAAC,EAAE,QAAQ,SAAS,MAAM,eAAe,QAAQ,UAAU,OAAO,CAAC;AACnF;AAAA,IACD;AAAA,IACA,KAAK,WAAW;AACf,cAAQ;AAAA,QAAQ,CAAC,EAAE,QAAQ,SAAS,MACnC,eAAe,QAAQ,QAAQ,UAAU,SAAS,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AAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { getSchema } from "@tiptap/core";
|
|
2
2
|
import { Node } from "@tiptap/pm/model";
|
|
3
|
-
import { assert } from "@tldraw/utils";
|
|
3
|
+
import { assert, WeakCache } from "@tldraw/utils";
|
|
4
|
+
const schemaCache = new WeakCache();
|
|
5
|
+
function getTipTapSchema(tipTapConfig) {
|
|
6
|
+
return schemaCache.get(tipTapConfig, () => getSchema(tipTapConfig.extensions ?? []));
|
|
7
|
+
}
|
|
4
8
|
function getFontsFromRichText(editor, richText, initialState) {
|
|
5
9
|
const { tipTapConfig, addFontsFromNode } = editor.getTextOptions();
|
|
6
10
|
assert(tipTapConfig, "textOptions.tipTapConfig must be set to use rich text");
|
|
7
11
|
assert(addFontsFromNode, "textOptions.addFontsFromNode must be set to use rich text");
|
|
8
|
-
const schema =
|
|
12
|
+
const schema = getTipTapSchema(tipTapConfig);
|
|
9
13
|
const rootNode = Node.fromJSON(schema, richText);
|
|
10
14
|
const fonts = /* @__PURE__ */ new Set();
|
|
11
15
|
function addFont(font) {
|
|
@@ -21,6 +25,7 @@ function getFontsFromRichText(editor, richText, initialState) {
|
|
|
21
25
|
return Array.from(fonts);
|
|
22
26
|
}
|
|
23
27
|
export {
|
|
24
|
-
getFontsFromRichText
|
|
28
|
+
getFontsFromRichText,
|
|
29
|
+
getTipTapSchema
|
|
25
30
|
};
|
|
26
31
|
//# sourceMappingURL=richText.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/utils/richText.ts"],
|
|
4
|
-
"sourcesContent": ["import { getSchema, JSONContent, Editor as TTEditor } from '@tiptap/core'\nimport { Node } from '@tiptap/pm/model'\nimport { EditorProviderProps } from '@tiptap/react'\nimport { TLRichText } from '@tldraw/tlschema'\nimport { assert } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\nimport { TLFontFace } from '../editor/managers/FontManager'\n\n/**\n * This is the TipTap editor! Docs are {@link https://tiptap.dev/docs}.\n *\n * @public\n */\nexport type TiptapEditor = TTEditor\n\n/**\n * A TipTap node. See {@link https://tiptap.dev/docs}.\n * @public\n */\nexport type TiptapNode = Node\n\n/** @public */\nexport interface TLTextOptions {\n\ttipTapConfig?: EditorProviderProps\n\taddFontsFromNode?: RichTextFontVisitor\n}\n\n/** @public */\nexport interface RichTextFontVisitorState {\n\treadonly family: string\n\treadonly weight: string\n\treadonly style: string\n}\n\n/** @public */\nexport type RichTextFontVisitor = (\n\tnode: TiptapNode,\n\tstate: RichTextFontVisitorState,\n\taddFont: (font: TLFontFace) => void\n) => RichTextFontVisitorState\n\n/** @public */\nexport function getFontsFromRichText(\n\teditor: Editor,\n\trichText: TLRichText,\n\tinitialState: RichTextFontVisitorState\n) {\n\tconst { tipTapConfig, addFontsFromNode } = editor.getTextOptions()\n\tassert(tipTapConfig, 'textOptions.tipTapConfig must be set to use rich text')\n\tassert(addFontsFromNode, 'textOptions.addFontsFromNode must be set to use rich text')\n\n\tconst schema =
|
|
5
|
-
"mappings": "AAAA,SAAS,iBAAkD;AAC3D,SAAS,
|
|
4
|
+
"sourcesContent": ["import { getSchema, JSONContent, Editor as TTEditor } from '@tiptap/core'\nimport { Node, Schema } from '@tiptap/pm/model'\nimport { EditorProviderProps } from '@tiptap/react'\nimport { TLRichText } from '@tldraw/tlschema'\nimport { assert, WeakCache } from '@tldraw/utils'\nimport { Editor } from '../editor/Editor'\nimport { TLFontFace } from '../editor/managers/FontManager/FontManager'\n\n/**\n * This is the TipTap editor! Docs are {@link https://tiptap.dev/docs}.\n *\n * @public\n */\nexport type TiptapEditor = TTEditor\n\n/**\n * A TipTap node. See {@link https://tiptap.dev/docs}.\n * @public\n */\nexport type TiptapNode = Node\n\n/** @public */\nexport interface TLTextOptions {\n\ttipTapConfig?: EditorProviderProps\n\taddFontsFromNode?: RichTextFontVisitor\n}\n\n/** @public */\nexport interface RichTextFontVisitorState {\n\treadonly family: string\n\treadonly weight: string\n\treadonly style: string\n}\n\n/** @public */\nexport type RichTextFontVisitor = (\n\tnode: TiptapNode,\n\tstate: RichTextFontVisitorState,\n\taddFont: (font: TLFontFace) => void\n) => RichTextFontVisitorState\n\nconst schemaCache = new WeakCache<EditorProviderProps, Schema>()\nexport function getTipTapSchema(tipTapConfig: EditorProviderProps) {\n\treturn schemaCache.get(tipTapConfig, () => getSchema(tipTapConfig.extensions ?? []))\n}\n\n/** @public */\nexport function getFontsFromRichText(\n\teditor: Editor,\n\trichText: TLRichText,\n\tinitialState: RichTextFontVisitorState\n) {\n\tconst { tipTapConfig, addFontsFromNode } = editor.getTextOptions()\n\tassert(tipTapConfig, 'textOptions.tipTapConfig must be set to use rich text')\n\tassert(addFontsFromNode, 'textOptions.addFontsFromNode must be set to use rich text')\n\n\tconst schema = getTipTapSchema(tipTapConfig)\n\n\tconst rootNode = Node.fromJSON(schema, richText as JSONContent)\n\n\tconst fonts = new Set<TLFontFace>()\n\n\tfunction addFont(font: TLFontFace) {\n\t\tfonts.add(font)\n\t}\n\n\tfunction visit(node: TiptapNode, state: RichTextFontVisitorState) {\n\t\tstate = addFontsFromNode!(node, state, addFont)\n\n\t\tfor (const child of node.children) {\n\t\t\tvisit(child, state)\n\t\t}\n\t}\n\n\tvisit(rootNode, initialState)\n\n\treturn Array.from(fonts)\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAkD;AAC3D,SAAS,YAAoB;AAG7B,SAAS,QAAQ,iBAAiB;AAqClC,MAAM,cAAc,IAAI,UAAuC;AACxD,SAAS,gBAAgB,cAAmC;AAClE,SAAO,YAAY,IAAI,cAAc,MAAM,UAAU,aAAa,cAAc,CAAC,CAAC,CAAC;AACpF;AAGO,SAAS,qBACf,QACA,UACA,cACC;AACD,QAAM,EAAE,cAAc,iBAAiB,IAAI,OAAO,eAAe;AACjE,SAAO,cAAc,uDAAuD;AAC5E,SAAO,kBAAkB,2DAA2D;AAEpF,QAAM,SAAS,gBAAgB,YAAY;AAE3C,QAAM,WAAW,KAAK,SAAS,QAAQ,QAAuB;AAE9D,QAAM,QAAQ,oBAAI,IAAgB;AAElC,WAAS,QAAQ,MAAkB;AAClC,UAAM,IAAI,IAAI;AAAA,EACf;AAEA,WAAS,MAAM,MAAkB,OAAiC;AACjE,YAAQ,iBAAkB,MAAM,OAAO,OAAO;AAE9C,eAAW,SAAS,KAAK,UAAU;AAClC,YAAM,OAAO,KAAK;AAAA,IACnB;AAAA,EACD;AAEA,QAAM,UAAU,YAAY;AAE5B,SAAO,MAAM,KAAK,KAAK;AACxB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist-esm/version.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const version = "3.14.0-canary.
|
|
1
|
+
const version = "3.14.0-canary.f907ed7d9ee5";
|
|
2
2
|
const publishDates = {
|
|
3
3
|
major: "2024-09-13T14:36:29.063Z",
|
|
4
|
-
minor: "2025-06-
|
|
5
|
-
patch: "2025-06-
|
|
4
|
+
minor: "2025-06-13T07:34:19.323Z",
|
|
5
|
+
patch: "2025-06-13T07:34:19.323Z"
|
|
6
6
|
};
|
|
7
7
|
export {
|
|
8
8
|
publishDates,
|
package/dist-esm/version.mjs.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 = '3.14.0-canary.
|
|
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 = '3.14.0-canary.f907ed7d9ee5'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-06-13T07:34:19.323Z',\n\tpatch: '2025-06-13T07:34:19.323Z',\n}\n"],
|
|
5
5
|
"mappings": "AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tldraw/editor",
|
|
3
3
|
"description": "A tiny little drawing app (editor).",
|
|
4
|
-
"version": "3.14.0-canary.
|
|
4
|
+
"version": "3.14.0-canary.f907ed7d9ee5",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tldraw Inc.",
|
|
7
7
|
"email": "hello@tldraw.com"
|
|
@@ -48,20 +48,19 @@
|
|
|
48
48
|
"@tiptap/core": "^2.9.1",
|
|
49
49
|
"@tiptap/pm": "^2.9.1",
|
|
50
50
|
"@tiptap/react": "^2.9.1",
|
|
51
|
-
"@tldraw/state": "3.14.0-canary.
|
|
52
|
-
"@tldraw/state-react": "3.14.0-canary.
|
|
53
|
-
"@tldraw/store": "3.14.0-canary.
|
|
54
|
-
"@tldraw/tlschema": "3.14.0-canary.
|
|
55
|
-
"@tldraw/utils": "3.14.0-canary.
|
|
56
|
-
"@tldraw/validate": "3.14.0-canary.
|
|
51
|
+
"@tldraw/state": "3.14.0-canary.f907ed7d9ee5",
|
|
52
|
+
"@tldraw/state-react": "3.14.0-canary.f907ed7d9ee5",
|
|
53
|
+
"@tldraw/store": "3.14.0-canary.f907ed7d9ee5",
|
|
54
|
+
"@tldraw/tlschema": "3.14.0-canary.f907ed7d9ee5",
|
|
55
|
+
"@tldraw/utils": "3.14.0-canary.f907ed7d9ee5",
|
|
56
|
+
"@tldraw/validate": "3.14.0-canary.f907ed7d9ee5",
|
|
57
57
|
"@types/core-js": "^2.5.8",
|
|
58
58
|
"@use-gesture/react": "^10.3.1",
|
|
59
59
|
"classnames": "^2.5.1",
|
|
60
60
|
"core-js": "^3.40.0",
|
|
61
61
|
"eventemitter3": "^4.0.7",
|
|
62
62
|
"idb": "^7.1.1",
|
|
63
|
-
"is-plain-object": "^5.0.0"
|
|
64
|
-
"lodash.isequal": "^4.5.0"
|
|
63
|
+
"is-plain-object": "^5.0.0"
|
|
65
64
|
},
|
|
66
65
|
"peerDependencies": {
|
|
67
66
|
"react": "^18.2.0 || ^19.0.0",
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,6 @@ import 'core-js/stable/array/flat-map.js'
|
|
|
4
4
|
import 'core-js/stable/array/flat.js'
|
|
5
5
|
import 'core-js/stable/string/at.js'
|
|
6
6
|
import 'core-js/stable/string/replace-all.js'
|
|
7
|
-
export { areShapesContentEqual } from './lib/utils/areShapesContentEqual'
|
|
8
7
|
|
|
9
8
|
// eslint-disable-next-line local/no-export-star
|
|
10
9
|
export * from '@tldraw/state'
|
|
@@ -148,15 +147,18 @@ export {
|
|
|
148
147
|
type BindingOnShapeIsolateOptions,
|
|
149
148
|
type TLBindingUtilConstructor,
|
|
150
149
|
} from './lib/editor/bindings/BindingUtil'
|
|
151
|
-
export { ClickManager, type TLClickState } from './lib/editor/managers/ClickManager'
|
|
152
|
-
export { EdgeScrollManager } from './lib/editor/managers/EdgeScrollManager'
|
|
150
|
+
export { ClickManager, type TLClickState } from './lib/editor/managers/ClickManager/ClickManager'
|
|
151
|
+
export { EdgeScrollManager } from './lib/editor/managers/EdgeScrollManager/EdgeScrollManager'
|
|
153
152
|
export {
|
|
154
153
|
FontManager,
|
|
155
154
|
type TLFontFace,
|
|
156
155
|
type TLFontFaceSource,
|
|
157
|
-
} from './lib/editor/managers/FontManager'
|
|
158
|
-
export { HistoryManager } from './lib/editor/managers/HistoryManager'
|
|
159
|
-
export {
|
|
156
|
+
} from './lib/editor/managers/FontManager/FontManager'
|
|
157
|
+
export { HistoryManager } from './lib/editor/managers/HistoryManager/HistoryManager'
|
|
158
|
+
export {
|
|
159
|
+
ScribbleManager,
|
|
160
|
+
type ScribbleItem,
|
|
161
|
+
} from './lib/editor/managers/ScribbleManager/ScribbleManager'
|
|
160
162
|
export {
|
|
161
163
|
BoundsSnaps,
|
|
162
164
|
type BoundsSnapGeometry,
|
|
@@ -170,8 +172,11 @@ export {
|
|
|
170
172
|
type SnapData,
|
|
171
173
|
type SnapIndicator,
|
|
172
174
|
} from './lib/editor/managers/SnapManager/SnapManager'
|
|
173
|
-
export {
|
|
174
|
-
|
|
175
|
+
export {
|
|
176
|
+
TextManager,
|
|
177
|
+
type TLMeasureTextSpanOpts,
|
|
178
|
+
} from './lib/editor/managers/TextManager/TextManager'
|
|
179
|
+
export { UserPreferencesManager } from './lib/editor/managers/UserPreferencesManager/UserPreferencesManager'
|
|
175
180
|
export { BaseBoxShapeUtil, type TLBaseBoxShape } from './lib/editor/shapes/BaseBoxShapeUtil'
|
|
176
181
|
export {
|
|
177
182
|
ShapeUtil,
|
|
@@ -14,12 +14,12 @@ import {
|
|
|
14
14
|
import {
|
|
15
15
|
deleteFromSessionStorage,
|
|
16
16
|
getFromSessionStorage,
|
|
17
|
+
isEqual,
|
|
17
18
|
setInSessionStorage,
|
|
18
19
|
structuredClone,
|
|
19
20
|
uniqueId,
|
|
20
21
|
} from '@tldraw/utils'
|
|
21
22
|
import { T } from '@tldraw/validate'
|
|
22
|
-
import isEqual from 'lodash.isequal'
|
|
23
23
|
import { tlenv } from '../globals/environment'
|
|
24
24
|
|
|
25
25
|
const tabIdKey = 'TLDRAW_TAB_ID_v2' as const
|
|
@@ -17,6 +17,7 @@ type ICustomShape = TLBaseShape<
|
|
|
17
17
|
w: number
|
|
18
18
|
h: number
|
|
19
19
|
text: string | undefined
|
|
20
|
+
isFilled: boolean
|
|
20
21
|
}
|
|
21
22
|
>
|
|
22
23
|
|
|
@@ -26,19 +27,21 @@ class CustomShape extends ShapeUtil<ICustomShape> {
|
|
|
26
27
|
w: T.number,
|
|
27
28
|
h: T.number,
|
|
28
29
|
text: T.string.optional(),
|
|
30
|
+
isFilled: T.boolean,
|
|
29
31
|
}
|
|
30
32
|
getDefaultProps(): ICustomShape['props'] {
|
|
31
33
|
return {
|
|
32
34
|
w: 200,
|
|
33
35
|
h: 200,
|
|
34
36
|
text: '',
|
|
37
|
+
isFilled: false,
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
getGeometry(shape: ICustomShape): Geometry2d {
|
|
38
41
|
return new Rectangle2d({
|
|
39
42
|
width: shape.props.w,
|
|
40
43
|
height: shape.props.h,
|
|
41
|
-
isFilled:
|
|
44
|
+
isFilled: shape.props.isFilled,
|
|
42
45
|
})
|
|
43
46
|
}
|
|
44
47
|
indicator() {}
|
|
@@ -81,11 +84,11 @@ describe('updateShape', () => {
|
|
|
81
84
|
props: { w: 100, h: 100, text: 'Hello' },
|
|
82
85
|
})
|
|
83
86
|
const shape = editor.getShape(id) as ICustomShape
|
|
84
|
-
expect(shape.props).toEqual({ w: 100, h: 100, text: 'Hello' })
|
|
87
|
+
expect(shape.props).toEqual({ w: 100, h: 100, text: 'Hello', isFilled: false })
|
|
85
88
|
|
|
86
89
|
editor.updateShape({ ...shape, props: { ...shape.props, text: undefined } })
|
|
87
90
|
const updatedShape = editor.getShape(id) as ICustomShape
|
|
88
|
-
expect(updatedShape.props).toEqual({ w: 100, h: 100, text: undefined })
|
|
91
|
+
expect(updatedShape.props).toEqual({ w: 100, h: 100, text: undefined, isFilled: false })
|
|
89
92
|
})
|
|
90
93
|
})
|
|
91
94
|
|
|
@@ -176,3 +179,249 @@ describe('zoomToBounds', () => {
|
|
|
176
179
|
expect(editor.setCamera).toHaveBeenCalled()
|
|
177
180
|
})
|
|
178
181
|
})
|
|
182
|
+
|
|
183
|
+
describe('getShapesAtPoint', () => {
|
|
184
|
+
const ids = {
|
|
185
|
+
shape1: createShapeId('shape1'),
|
|
186
|
+
shape2: createShapeId('shape2'),
|
|
187
|
+
shape3: createShapeId('shape3'),
|
|
188
|
+
shape4: createShapeId('shape4'),
|
|
189
|
+
shape5: createShapeId('shape5'),
|
|
190
|
+
overlap1: createShapeId('overlap1'),
|
|
191
|
+
overlap2: createShapeId('overlap2'),
|
|
192
|
+
filledShape: createShapeId('filledShape'),
|
|
193
|
+
hollowShape: createShapeId('hollowShape'),
|
|
194
|
+
hiddenShape: createShapeId('hiddenShape'),
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
beforeEach(() => {
|
|
198
|
+
// Create test shapes with different z-index positions
|
|
199
|
+
// Shape 1: Bottom layer, large square
|
|
200
|
+
editor.createShape({
|
|
201
|
+
id: ids.shape1,
|
|
202
|
+
type: 'my-custom-shape',
|
|
203
|
+
x: 0,
|
|
204
|
+
y: 0,
|
|
205
|
+
props: { w: 200, h: 200, text: 'Bottom' },
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
// Shape 2: Middle layer, overlapping square
|
|
209
|
+
editor.createShape({
|
|
210
|
+
id: ids.shape2,
|
|
211
|
+
type: 'my-custom-shape',
|
|
212
|
+
x: 100,
|
|
213
|
+
y: 0,
|
|
214
|
+
props: { w: 200, h: 200, text: 'Middle' },
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
// Shape 3: Top layer, small square
|
|
218
|
+
editor.createShape({
|
|
219
|
+
id: ids.shape3,
|
|
220
|
+
type: 'my-custom-shape',
|
|
221
|
+
x: 50,
|
|
222
|
+
y: 50,
|
|
223
|
+
props: { w: 100, h: 100, text: 'Top' },
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
// Shape 4: Separate area, no overlap
|
|
227
|
+
editor.createShape({
|
|
228
|
+
id: ids.shape4,
|
|
229
|
+
type: 'my-custom-shape',
|
|
230
|
+
x: 50,
|
|
231
|
+
y: 100,
|
|
232
|
+
props: { w: 100, h: 100, text: 'Separate' },
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it('returns shapes at a point in reverse z-index order', () => {
|
|
237
|
+
// Point at (50, 50) should hit shape3's edge (since it's at 50,50 with size 100x100)
|
|
238
|
+
// This point is exactly at the top-left corner of shape3
|
|
239
|
+
const shapes = editor.getShapesAtPoint({ x: 50, y: 50 })
|
|
240
|
+
const shapeIds = shapes.map((s) => s.id)
|
|
241
|
+
|
|
242
|
+
expect(shapeIds).toEqual([ids.shape3])
|
|
243
|
+
expect(shapes).toHaveLength(1)
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
it('returns empty array when no shapes at point', () => {
|
|
247
|
+
const shapes = editor.getShapesAtPoint({ x: 1000, y: 1000 })
|
|
248
|
+
expect(shapes).toEqual([])
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
it('returns single shape when point hits only one shape', () => {
|
|
252
|
+
// Point at right edge of shape2 where it doesn't overlap with other shapes
|
|
253
|
+
// Shape2 is at (100,0) with size 200x200, so right edge is at x=300
|
|
254
|
+
const shapes = editor.getShapesAtPoint({ x: 300, y: 100 })
|
|
255
|
+
expect(shapes).toHaveLength(1)
|
|
256
|
+
expect(shapes[0].id).toBe(ids.shape2)
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
it('returns shapes on edge when point is exactly on boundary', () => {
|
|
260
|
+
// Point at exact edge of shape1
|
|
261
|
+
const shapes = editor.getShapesAtPoint({ x: 0, y: 0 })
|
|
262
|
+
expect(shapes).toHaveLength(1)
|
|
263
|
+
expect(shapes[0].id).toBe(ids.shape1)
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
it('respects hitInside option when false (default)', () => {
|
|
267
|
+
// Point inside shape1 (at 0,0 with size 200x200) but with hitInside false should not hit
|
|
268
|
+
const shapes = editor.getShapesAtPoint({ x: 25, y: 25 }, { hitInside: false })
|
|
269
|
+
expect(shapes).toEqual([])
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
it('respects hitInside option when true', () => {
|
|
273
|
+
// Point inside shape1 (at 0,0 with size 200x200) with hitInside true should hit
|
|
274
|
+
const shapes = editor.getShapesAtPoint({ x: 25, y: 25 }, { hitInside: true })
|
|
275
|
+
expect(shapes).toHaveLength(1)
|
|
276
|
+
expect(shapes[0].id).toBe(ids.shape1)
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
it('respects margin option', () => {
|
|
280
|
+
// Point slightly outside shape1 at bottom edge but within margin should hit only shape1
|
|
281
|
+
// Shape1 is at (0,0) with size 200x200, shape2 goes to (300,200) so avoid overlap at (200,200)
|
|
282
|
+
const shapes = editor.getShapesAtPoint({ x: 205, y: 100 }, { margin: 10 })
|
|
283
|
+
expect(shapes).toHaveLength(1)
|
|
284
|
+
expect(shapes[0].id).toBe(ids.shape1)
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
it('filters out hidden shapes', () => {
|
|
288
|
+
// Create a spy to mock isShapeHidden
|
|
289
|
+
const isShapeHiddenSpy = jest.spyOn(editor, 'isShapeHidden')
|
|
290
|
+
isShapeHiddenSpy.mockImplementation((shape) => {
|
|
291
|
+
return typeof shape === 'string' ? shape === ids.shape3 : shape.id === ids.shape3
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
const shapes = editor.getShapesAtPoint({ x: 50, y: 50 })
|
|
295
|
+
const shapeIds = shapes.map((s) => s.id)
|
|
296
|
+
|
|
297
|
+
// Should not include shape3 since it's hidden, and no other shapes are at this point
|
|
298
|
+
expect(shapeIds).toEqual([])
|
|
299
|
+
expect(shapes).toHaveLength(0)
|
|
300
|
+
|
|
301
|
+
isShapeHiddenSpy.mockRestore()
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
it('handles point exactly at shape corner', () => {
|
|
305
|
+
// Point at bottom-left corner of shape1 where it doesn't overlap with other shapes
|
|
306
|
+
const shapes = editor.getShapesAtPoint({ x: 0, y: 200 })
|
|
307
|
+
expect(shapes).toHaveLength(1)
|
|
308
|
+
expect(shapes[0].id).toBe(ids.shape1)
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
it('handles overlapping shapes with different hit areas', () => {
|
|
312
|
+
// Point that hits both shape1 and shape2 edges (they overlap at x=100,y=0)
|
|
313
|
+
const shapes = editor.getShapesAtPoint({ x: 100, y: 0 })
|
|
314
|
+
const shapeIds = shapes.map((s) => s.id)
|
|
315
|
+
|
|
316
|
+
// Both shapes should be detected at this overlapping point (reversed order - top-most first)
|
|
317
|
+
expect(shapeIds).toEqual([ids.shape2, ids.shape1])
|
|
318
|
+
expect(shapes).toHaveLength(2)
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
it('maintains reverse shape order and responds to z-index changes', () => {
|
|
322
|
+
// Create filled shape that overlaps with shape2
|
|
323
|
+
editor.createShape({
|
|
324
|
+
id: ids.shape5,
|
|
325
|
+
type: 'my-custom-shape',
|
|
326
|
+
x: 110,
|
|
327
|
+
y: 110,
|
|
328
|
+
props: { w: 200, h: 200, isFilled: true, text: 'Shape5' },
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
// Test with hitInside to detect multiple shapes
|
|
332
|
+
// Point (120,120) will hit shape1, shape2, shape3, shape4, and shape5 with hitInside: true
|
|
333
|
+
const shapes = editor.getShapesAtPoint({ x: 120, y: 120 }, { hitInside: true })
|
|
334
|
+
const shapeIds = shapes.map((s) => s.id)
|
|
335
|
+
|
|
336
|
+
// All shapes that contain this point should be returned in reverse z-index order (top-most first)
|
|
337
|
+
expect(shapeIds).toEqual([ids.shape5, ids.shape4, ids.shape3, ids.shape2, ids.shape1])
|
|
338
|
+
|
|
339
|
+
// After bringing shape2 to front, order should change (shape2 becomes top-most)
|
|
340
|
+
editor.bringToFront([ids.shape2])
|
|
341
|
+
const shapes2 = editor.getShapesAtPoint({ x: 120, y: 120 }, { hitInside: true })
|
|
342
|
+
const shapeIds2 = shapes2.map((s) => s.id)
|
|
343
|
+
expect(shapeIds2).toEqual([ids.shape2, ids.shape5, ids.shape4, ids.shape3, ids.shape1])
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
it('combines hitInside and margin options', () => {
|
|
347
|
+
// Point inside shape1 (at 0,0 with size 200x200) with hitInside and margin
|
|
348
|
+
const shapes = editor.getShapesAtPoint({ x: 25, y: 25 }, { hitInside: true, margin: 5 })
|
|
349
|
+
expect(shapes).toHaveLength(1)
|
|
350
|
+
expect(shapes[0].id).toBe(ids.shape1)
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
it('returns empty array when all shapes are hidden', () => {
|
|
354
|
+
// Mock all shapes as hidden
|
|
355
|
+
const isShapeHiddenSpy = jest.spyOn(editor, 'isShapeHidden')
|
|
356
|
+
isShapeHiddenSpy.mockReturnValue(true)
|
|
357
|
+
|
|
358
|
+
const shapes = editor.getShapesAtPoint({ x: 50, y: 50 })
|
|
359
|
+
expect(shapes).toEqual([])
|
|
360
|
+
|
|
361
|
+
isShapeHiddenSpy.mockRestore()
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
it('returns multiple shapes at same point in reverse z-index order', () => {
|
|
365
|
+
// Create two shapes at exactly the same position (away from existing shapes)
|
|
366
|
+
editor.createShape({
|
|
367
|
+
id: ids.overlap1,
|
|
368
|
+
type: 'my-custom-shape',
|
|
369
|
+
x: 600,
|
|
370
|
+
y: 600,
|
|
371
|
+
props: { w: 100, h: 100, text: 'First' },
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
editor.createShape({
|
|
375
|
+
id: ids.overlap2,
|
|
376
|
+
type: 'my-custom-shape',
|
|
377
|
+
x: 600,
|
|
378
|
+
y: 600,
|
|
379
|
+
props: { w: 100, h: 100, text: 'Second' },
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
// Test at corner where both shapes' edges meet
|
|
383
|
+
const shapes = editor.getShapesAtPoint({ x: 600, y: 600 })
|
|
384
|
+
const shapeIds = shapes.map((s) => s.id)
|
|
385
|
+
|
|
386
|
+
// Should return both shapes in reverse z-index order (top-most first)
|
|
387
|
+
expect(shapeIds).toEqual([ids.overlap2, ids.overlap1])
|
|
388
|
+
expect(shapes).toHaveLength(2)
|
|
389
|
+
})
|
|
390
|
+
|
|
391
|
+
it('respects isFilled property for hit detection', () => {
|
|
392
|
+
// Create a filled shape
|
|
393
|
+
editor.createShape({
|
|
394
|
+
id: ids.filledShape,
|
|
395
|
+
type: 'my-custom-shape',
|
|
396
|
+
x: 300,
|
|
397
|
+
y: 300,
|
|
398
|
+
props: { w: 100, h: 100, isFilled: true, text: 'Filled' },
|
|
399
|
+
})
|
|
400
|
+
|
|
401
|
+
// Create a hollow shape at the same position
|
|
402
|
+
editor.createShape({
|
|
403
|
+
id: ids.hollowShape,
|
|
404
|
+
type: 'my-custom-shape',
|
|
405
|
+
x: 400,
|
|
406
|
+
y: 300,
|
|
407
|
+
props: { w: 100, h: 100, isFilled: false, text: 'Hollow' },
|
|
408
|
+
})
|
|
409
|
+
|
|
410
|
+
// Test point inside filled shape - should hit without hitInside option
|
|
411
|
+
const filledShapes = editor.getShapesAtPoint({ x: 350, y: 350 })
|
|
412
|
+
expect(filledShapes).toHaveLength(1)
|
|
413
|
+
expect(filledShapes[0].id).toBe(ids.filledShape)
|
|
414
|
+
|
|
415
|
+
// Test point inside hollow shape - should not hit without hitInside option
|
|
416
|
+
const hollowShapes = editor.getShapesAtPoint({ x: 450, y: 350 })
|
|
417
|
+
expect(hollowShapes).toHaveLength(0)
|
|
418
|
+
|
|
419
|
+
// Test point inside hollow shape with hitInside - should hit
|
|
420
|
+
const hollowShapesWithHitInside = editor.getShapesAtPoint(
|
|
421
|
+
{ x: 450, y: 350 },
|
|
422
|
+
{ hitInside: true }
|
|
423
|
+
)
|
|
424
|
+
expect(hollowShapesWithHitInside).toHaveLength(1)
|
|
425
|
+
expect(hollowShapesWithHitInside[0].id).toBe(ids.hollowShape)
|
|
426
|
+
})
|
|
427
|
+
})
|