@tldraw/editor 3.11.0-canary.be7c870ecadb → 3.11.0-canary.bf79438b7304

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/dist-cjs/index.d.ts +16 -8
  3. package/dist-cjs/index.js +1 -1
  4. package/dist-cjs/index.js.map +2 -2
  5. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +4 -4
  6. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
  7. package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js +37 -25
  8. package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js.map +2 -2
  9. package/dist-cjs/lib/constants.js +1 -1
  10. package/dist-cjs/lib/constants.js.map +2 -2
  11. package/dist-cjs/lib/editor/Editor.js +11 -9
  12. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  13. package/dist-cjs/lib/exports/exportToSvg.js.map +1 -1
  14. package/dist-cjs/version.js +3 -3
  15. package/dist-cjs/version.js.map +1 -1
  16. package/dist-esm/index.d.mts +16 -8
  17. package/dist-esm/index.mjs +4 -2
  18. package/dist-esm/index.mjs.map +2 -2
  19. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +4 -4
  20. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
  21. package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs +37 -25
  22. package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs.map +2 -2
  23. package/dist-esm/lib/constants.mjs +1 -1
  24. package/dist-esm/lib/constants.mjs.map +2 -2
  25. package/dist-esm/lib/editor/Editor.mjs +11 -9
  26. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  27. package/dist-esm/lib/exports/exportToSvg.mjs.map +1 -1
  28. package/dist-esm/version.mjs +3 -3
  29. package/dist-esm/version.mjs.map +1 -1
  30. package/package.json +7 -7
  31. package/src/index.ts +4 -1
  32. package/src/lib/components/default-components/DefaultShapeIndicator.tsx +4 -4
  33. package/src/lib/components/default-components/DefaultShapeIndicators.tsx +51 -28
  34. package/src/lib/constants.ts +1 -1
  35. package/src/lib/editor/Editor.ts +13 -10
  36. package/src/lib/exports/exportToSvg.tsx +1 -1
  37. package/src/version.ts +3 -3
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/exports/exportToSvg.tsx"],
4
- "sourcesContent": ["import { TLShapeId } from '@tldraw/tlschema'\nimport { assert } from '@tldraw/utils'\nimport { flushSync } from 'react-dom'\nimport { createRoot } from 'react-dom/client'\nimport { Editor } from '../editor/Editor'\nimport { TLSvgExportOptions } from '../editor/types/misc-types'\nimport { SVG_EXPORT_CLASSNAME } from './FontEmbedder'\nimport { StyleEmbedder } from './StyleEmbedder'\nimport { embedMedia } from './embedMedia'\nimport { getSvgJsx } from './getSvgJsx'\n\nlet idCounter = 1\n\nexport async function exportToSvg(\n\teditor: Editor,\n\tshapeIds: TLShapeId[],\n\topts: TLSvgExportOptions = {}\n) {\n\t// when rendering to SVG, we start by creating a JSX representation of the SVG that we can\n\t// render with react. Hopefully elements will have a `toSvg` method that renders them to SVG,\n\t// but if they don't we'll render their normal HTML content into an svg <foreignObject> element.\n\tconst result = getSvgJsx(editor, shapeIds, opts)\n\tif (!result) return undefined\n\n\t// we need to render that SVG into a real DOM element that's actually laid out in the document.\n\t// without this CSS and layout aren't computed correctly, which we need to make sure any\n\t// <foreignObject> elements have their styles and content inlined correctly.\n\tconst container = editor.getContainer()\n\tconst renderTarget = document.createElement('div')\n\trenderTarget.className = SVG_EXPORT_CLASSNAME\n\t// we hide the element visually, but we don't want it to be focusable or interactive in any way either\n\trenderTarget.inert = true\n\trenderTarget.tabIndex = -1\n\tObject.assign(renderTarget.style, {\n\t\tposition: 'absolute',\n\t\ttop: '0px',\n\t\tleft: '0px',\n\t\twidth: result.width + 'px',\n\t\theight: result.height + 'px',\n\t\tpointerEvents: 'none',\n\t\topacity: 0,\n\t})\n\t// we have to add the element to the document as otherwise styles won't be computed correctly.\n\tcontainer.appendChild(renderTarget)\n\n\t// create a react root...\n\tconst root = createRoot(renderTarget, { identifierPrefix: `export_${idCounter++}_` })\n\ttry {\n\t\t// ...wait for a tick so we know we're not in e.g. a react lifecycle method...\n\t\tawait Promise.resolve()\n\n\t\t// ...and render the SVG into it.\n\t\tflushSync(() => {\n\t\t\troot.render(result.jsx)\n\t\t})\n\n\t\t// Some operations take a while - for example, waiting for an asset to load in. We give\n\t\t// shape authors a way to delay snap-shotting the export until they're ready.\n\t\tawait result.exportDelay.resolve()\n\n\t\t// Extract the rendered SVG element from the react root\n\t\tconst svg = renderTarget.firstElementChild\n\t\tassert(svg instanceof SVGSVGElement, 'Expected an SVG element')\n\n\t\t// And apply any changes to <foreignObject> elements that we need to make. Whilst we're in\n\t\t// the document, these elements work exactly as we'd expect from other dom elements - they\n\t\t// can load external resources, and any stylesheets in the document apply to them as we\n\t\t// would expect them to. But when we pull the SVG into its own file or draw it to a canvas\n\t\t// though, it has to be completely self-contained. We embed any external resources, and\n\t\t// apply any styles directly to the elements themselves.\n\t\tawait applyChangesToForeignObjects(svg)\n\n\t\treturn { svg, width: result.width, height: result.height }\n\t} finally {\n\t\t// eslint-disable-next-line no-restricted-globals\n\t\tsetTimeout(() => {\n\t\t\t// we wait for a cycle of the event loop to allow the svg to be cloned etc. before\n\t\t\t// unmounting\n\t\t\troot.unmount()\n\t\t\tcontainer.removeChild(renderTarget)\n\t\t}, 0)\n\t}\n}\n\nasync function applyChangesToForeignObjects(svg: SVGSVGElement) {\n\t// If any shapes have their own <foreignObject> elements, we don't want to mess with them. Our\n\t// ones that we need to embed will have a class of `tl-export-embed-styles`.\n\tconst foreignObjectChildren = [\n\t\t...svg.querySelectorAll('foreignObject.tl-export-embed-styles > *'),\n\t]\n\tif (!foreignObjectChildren.length) return\n\n\t// StyleEmbedder embeds any CSS - including resources like fonts and images.\n\tconst styleEmbedder = new StyleEmbedder(svg)\n\n\ttry {\n\t\t// begin traversing stylesheets to find @font-face declarations we might need to embed\n\t\tstyleEmbedder.fonts.startFindingCurrentDocumentFontFaces()\n\n\t\t// embed any media elements in the foreignObject children. images will get converted to data\n\t\t// urls, and things like videos will be converted to images.\n\t\tawait Promise.all(foreignObjectChildren.map((el) => embedMedia(el as HTMLElement)))\n\n\t\t// read the computed styles of every element (+ it's children & pseudo-elements) in the\n\t\t// document. we do this in a single pass before we start embedding any CSS stuff to avoid\n\t\t// constantly forcing the browser to recompute styles & layout.\n\t\tfor (const el of foreignObjectChildren) {\n\t\t\tstyleEmbedder.readRootElementStyles(el as HTMLElement)\n\t\t}\n\n\t\t// fetch any resources that we need to embed in the CSS, like background images.\n\t\tawait styleEmbedder.fetchResources()\n\t\tconst fontCss = await styleEmbedder.getFontFaceCss()\n\n\t\t// custom elements that make use of the shadow dom won't be serialized correctly by default:\n\t\t// the contents of the shadow dom will be ignored. once we've read the styles from the\n\t\t// document, we go through and replace any custom elements with plain `<div>`s. as we do so,\n\t\t// we traverse the shadow dom and clone it into the new plain div. any scoped stylesheets\n\t\t// are removed, as we've already read all the computed styles above.\n\t\tstyleEmbedder.unwrapCustomElements()\n\n\t\t// apply the computed styles (with their embedded resources) directly to the elements with\n\t\t// their `style` attribute. Anything that can't be done this way (pseudo-elements) will be\n\t\t// returned as a string of CSS.\n\t\tconst pseudoCss = styleEmbedder.embedStyles()\n\n\t\t// add the CSS to the SVG\n\t\tif (fontCss || pseudoCss) {\n\t\t\tconst style = document.createElementNS('http://www.w3.org/2000/svg', 'style')\n\t\t\tstyle.textContent = `${fontCss}\\n${pseudoCss}`\n\t\t\tsvg.prepend(style)\n\t\t}\n\t} finally {\n\t\tstyleEmbedder.dispose()\n\t}\n}\n"],
4
+ "sourcesContent": ["import { TLShapeId } from '@tldraw/tlschema'\nimport { assert } from '@tldraw/utils'\nimport { flushSync } from 'react-dom'\nimport { createRoot } from 'react-dom/client'\nimport { Editor } from '../editor/Editor'\nimport { TLSvgExportOptions } from '../editor/types/misc-types'\nimport { SVG_EXPORT_CLASSNAME } from './FontEmbedder'\nimport { StyleEmbedder } from './StyleEmbedder'\nimport { embedMedia } from './embedMedia'\nimport { getSvgJsx } from './getSvgJsx'\n\nlet idCounter = 1\n\nexport async function exportToSvg(\n\teditor: Editor,\n\tshapeIds: TLShapeId[],\n\topts: TLSvgExportOptions = {}\n) {\n\t// when rendering to SVG, we start by creating a JSX representation of the SVG that we can\n\t// render with react. Hopefully elements will have a `toSvg` method that renders them to SVG,\n\t// but if they don't we'll render their normal HTML content into an svg <foreignObject> element.\n\tconst result = getSvgJsx(editor, shapeIds, opts)\n\tif (!result) return undefined\n\n\t// we need to render that SVG into a real DOM element that's actually laid out in the document.\n\t// without this CSS and layout aren't computed correctly, which we need to make sure any\n\t// <foreignObject> elements have their styles and content inlined correctly.\n\tconst container = editor.getContainer()\n\tconst renderTarget = document.createElement('div')\n\trenderTarget.className = SVG_EXPORT_CLASSNAME\n\t// we hide the element visually, but we don't want it to be focusable or interactive in any way either\n\trenderTarget.inert = true\n\trenderTarget.tabIndex = -1\n\tObject.assign(renderTarget.style, {\n\t\tposition: 'absolute',\n\t\ttop: '0px',\n\t\tleft: '0px',\n\t\twidth: result.width + 'px',\n\t\theight: result.height + 'px',\n\t\tpointerEvents: 'none',\n\t\topacity: 0,\n\t})\n\t// we have to add the element to the document as otherwise styles won't be computed correctly.\n\tcontainer.appendChild(renderTarget)\n\n\t// create a react root...\n\tconst root = createRoot(renderTarget, { identifierPrefix: `export_${idCounter++}_` })\n\ttry {\n\t\t// ...wait for a tick so we know we're not in e.g. a react lifecycle method...\n\t\tawait Promise.resolve()\n\n\t\t// ...and render the SVG into it.\n\t\tflushSync(() => {\n\t\t\troot.render(result.jsx)\n\t\t})\n\n\t\t// Some operations take a while - for example, waiting for an asset to load in. We give\n\t\t// shape authors a way to delay snap-shotting the export until they're ready.\n\t\tawait result.exportDelay.resolve()\n\n\t\t// Extract the rendered SVG element from the react root\n\t\tconst svg = renderTarget.firstElementChild\n\t\tassert(svg instanceof SVGSVGElement, 'Expected an SVG element')\n\n\t\t// And apply any changes to <foreignObject> elements that we need to make. while we're in\n\t\t// the document, these elements work exactly as we'd expect from other dom elements - they\n\t\t// can load external resources, and any stylesheets in the document apply to them as we\n\t\t// would expect them to. But when we pull the SVG into its own file or draw it to a canvas\n\t\t// though, it has to be completely self-contained. We embed any external resources, and\n\t\t// apply any styles directly to the elements themselves.\n\t\tawait applyChangesToForeignObjects(svg)\n\n\t\treturn { svg, width: result.width, height: result.height }\n\t} finally {\n\t\t// eslint-disable-next-line no-restricted-globals\n\t\tsetTimeout(() => {\n\t\t\t// we wait for a cycle of the event loop to allow the svg to be cloned etc. before\n\t\t\t// unmounting\n\t\t\troot.unmount()\n\t\t\tcontainer.removeChild(renderTarget)\n\t\t}, 0)\n\t}\n}\n\nasync function applyChangesToForeignObjects(svg: SVGSVGElement) {\n\t// If any shapes have their own <foreignObject> elements, we don't want to mess with them. Our\n\t// ones that we need to embed will have a class of `tl-export-embed-styles`.\n\tconst foreignObjectChildren = [\n\t\t...svg.querySelectorAll('foreignObject.tl-export-embed-styles > *'),\n\t]\n\tif (!foreignObjectChildren.length) return\n\n\t// StyleEmbedder embeds any CSS - including resources like fonts and images.\n\tconst styleEmbedder = new StyleEmbedder(svg)\n\n\ttry {\n\t\t// begin traversing stylesheets to find @font-face declarations we might need to embed\n\t\tstyleEmbedder.fonts.startFindingCurrentDocumentFontFaces()\n\n\t\t// embed any media elements in the foreignObject children. images will get converted to data\n\t\t// urls, and things like videos will be converted to images.\n\t\tawait Promise.all(foreignObjectChildren.map((el) => embedMedia(el as HTMLElement)))\n\n\t\t// read the computed styles of every element (+ it's children & pseudo-elements) in the\n\t\t// document. we do this in a single pass before we start embedding any CSS stuff to avoid\n\t\t// constantly forcing the browser to recompute styles & layout.\n\t\tfor (const el of foreignObjectChildren) {\n\t\t\tstyleEmbedder.readRootElementStyles(el as HTMLElement)\n\t\t}\n\n\t\t// fetch any resources that we need to embed in the CSS, like background images.\n\t\tawait styleEmbedder.fetchResources()\n\t\tconst fontCss = await styleEmbedder.getFontFaceCss()\n\n\t\t// custom elements that make use of the shadow dom won't be serialized correctly by default:\n\t\t// the contents of the shadow dom will be ignored. once we've read the styles from the\n\t\t// document, we go through and replace any custom elements with plain `<div>`s. as we do so,\n\t\t// we traverse the shadow dom and clone it into the new plain div. any scoped stylesheets\n\t\t// are removed, as we've already read all the computed styles above.\n\t\tstyleEmbedder.unwrapCustomElements()\n\n\t\t// apply the computed styles (with their embedded resources) directly to the elements with\n\t\t// their `style` attribute. Anything that can't be done this way (pseudo-elements) will be\n\t\t// returned as a string of CSS.\n\t\tconst pseudoCss = styleEmbedder.embedStyles()\n\n\t\t// add the CSS to the SVG\n\t\tif (fontCss || pseudoCss) {\n\t\t\tconst style = document.createElementNS('http://www.w3.org/2000/svg', 'style')\n\t\t\tstyle.textContent = `${fontCss}\\n${pseudoCss}`\n\t\t\tsvg.prepend(style)\n\t\t}\n\t} finally {\n\t\tstyleEmbedder.dispose()\n\t}\n}\n"],
5
5
  "mappings": "AACA,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAG3B,SAAS,4BAA4B;AACrC,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAE1B,IAAI,YAAY;AAEhB,eAAsB,YACrB,QACA,UACA,OAA2B,CAAC,GAC3B;AAID,QAAM,SAAS,UAAU,QAAQ,UAAU,IAAI;AAC/C,MAAI,CAAC,OAAQ,QAAO;AAKpB,QAAM,YAAY,OAAO,aAAa;AACtC,QAAM,eAAe,SAAS,cAAc,KAAK;AACjD,eAAa,YAAY;AAEzB,eAAa,QAAQ;AACrB,eAAa,WAAW;AACxB,SAAO,OAAO,aAAa,OAAO;AAAA,IACjC,UAAU;AAAA,IACV,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO,OAAO,QAAQ;AAAA,IACtB,QAAQ,OAAO,SAAS;AAAA,IACxB,eAAe;AAAA,IACf,SAAS;AAAA,EACV,CAAC;AAED,YAAU,YAAY,YAAY;AAGlC,QAAM,OAAO,WAAW,cAAc,EAAE,kBAAkB,UAAU,WAAW,IAAI,CAAC;AACpF,MAAI;AAEH,UAAM,QAAQ,QAAQ;AAGtB,cAAU,MAAM;AACf,WAAK,OAAO,OAAO,GAAG;AAAA,IACvB,CAAC;AAID,UAAM,OAAO,YAAY,QAAQ;AAGjC,UAAM,MAAM,aAAa;AACzB,WAAO,eAAe,eAAe,yBAAyB;AAQ9D,UAAM,6BAA6B,GAAG;AAEtC,WAAO,EAAE,KAAK,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO;AAAA,EAC1D,UAAE;AAED,eAAW,MAAM;AAGhB,WAAK,QAAQ;AACb,gBAAU,YAAY,YAAY;AAAA,IACnC,GAAG,CAAC;AAAA,EACL;AACD;AAEA,eAAe,6BAA6B,KAAoB;AAG/D,QAAM,wBAAwB;AAAA,IAC7B,GAAG,IAAI,iBAAiB,0CAA0C;AAAA,EACnE;AACA,MAAI,CAAC,sBAAsB,OAAQ;AAGnC,QAAM,gBAAgB,IAAI,cAAc,GAAG;AAE3C,MAAI;AAEH,kBAAc,MAAM,qCAAqC;AAIzD,UAAM,QAAQ,IAAI,sBAAsB,IAAI,CAAC,OAAO,WAAW,EAAiB,CAAC,CAAC;AAKlF,eAAW,MAAM,uBAAuB;AACvC,oBAAc,sBAAsB,EAAiB;AAAA,IACtD;AAGA,UAAM,cAAc,eAAe;AACnC,UAAM,UAAU,MAAM,cAAc,eAAe;AAOnD,kBAAc,qBAAqB;AAKnC,UAAM,YAAY,cAAc,YAAY;AAG5C,QAAI,WAAW,WAAW;AACzB,YAAM,QAAQ,SAAS,gBAAgB,8BAA8B,OAAO;AAC5E,YAAM,cAAc,GAAG,OAAO;AAAA,EAAK,SAAS;AAC5C,UAAI,QAAQ,KAAK;AAAA,IAClB;AAAA,EACD,UAAE;AACD,kBAAc,QAAQ;AAAA,EACvB;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,8 +1,8 @@
1
- const version = "3.11.0-canary.be7c870ecadb";
1
+ const version = "3.11.0-canary.bf79438b7304";
2
2
  const publishDates = {
3
3
  major: "2024-09-13T14:36:29.063Z",
4
- minor: "2025-03-13T15:33:43.856Z",
5
- patch: "2025-03-13T15:33:43.856Z"
4
+ minor: "2025-03-15T15:11:29.447Z",
5
+ patch: "2025-03-15T15:11:29.447Z"
6
6
  };
7
7
  export {
8
8
  publishDates,
@@ -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.11.0-canary.be7c870ecadb'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-03-13T15:33:43.856Z',\n\tpatch: '2025-03-13T15:33:43.856Z',\n}\n"],
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.11.0-canary.bf79438b7304'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-03-15T15:11:29.447Z',\n\tpatch: '2025-03-15T15:11:29.447Z',\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.11.0-canary.be7c870ecadb",
4
+ "version": "3.11.0-canary.bf79438b7304",
5
5
  "author": {
6
6
  "name": "tldraw Inc.",
7
7
  "email": "hello@tldraw.com"
@@ -48,12 +48,12 @@
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.11.0-canary.be7c870ecadb",
52
- "@tldraw/state-react": "3.11.0-canary.be7c870ecadb",
53
- "@tldraw/store": "3.11.0-canary.be7c870ecadb",
54
- "@tldraw/tlschema": "3.11.0-canary.be7c870ecadb",
55
- "@tldraw/utils": "3.11.0-canary.be7c870ecadb",
56
- "@tldraw/validate": "3.11.0-canary.be7c870ecadb",
51
+ "@tldraw/state": "3.11.0-canary.bf79438b7304",
52
+ "@tldraw/state-react": "3.11.0-canary.bf79438b7304",
53
+ "@tldraw/store": "3.11.0-canary.bf79438b7304",
54
+ "@tldraw/tlschema": "3.11.0-canary.bf79438b7304",
55
+ "@tldraw/utils": "3.11.0-canary.bf79438b7304",
56
+ "@tldraw/validate": "3.11.0-canary.bf79438b7304",
57
57
  "@types/core-js": "^2.5.8",
58
58
  "@use-gesture/react": "^10.3.1",
59
59
  "classnames": "^2.5.1",
package/src/index.ts CHANGED
@@ -109,7 +109,10 @@ export {
109
109
  type TLShapeIndicatorProps,
110
110
  } from './lib/components/default-components/DefaultShapeIndicator'
111
111
  export { type TLShapeIndicatorErrorFallbackComponent } from './lib/components/default-components/DefaultShapeIndicatorErrorFallback'
112
- export { DefaultShapeIndicators } from './lib/components/default-components/DefaultShapeIndicators'
112
+ export {
113
+ DefaultShapeIndicators,
114
+ type TLShapeIndicatorsProps,
115
+ } from './lib/components/default-components/DefaultShapeIndicators'
113
116
  export {
114
117
  DefaultSnapIndicator,
115
118
  type TLSnapIndicatorProps,
@@ -9,15 +9,15 @@ import { useEditorComponents } from '../../hooks/useEditorComponents'
9
9
  import { OptionalErrorBoundary } from '../ErrorBoundary'
10
10
 
11
11
  // need an extra layer of indirection here to allow hooks to be used inside the indicator render
12
- const EvenInnererIndicator = ({ shape, util }: { shape: TLShape; util: ShapeUtil<any> }) => {
12
+ const EvenInnererIndicator = memo(({ shape, util }: { shape: TLShape; util: ShapeUtil<any> }) => {
13
13
  return useStateTracking('Indicator: ' + shape.type, () =>
14
14
  // always fetch the latest shape from the store even if the props/meta have not changed, to avoid
15
15
  // calling the render method with stale data.
16
16
  util.indicator(util.editor.store.unsafeGetWithoutCapture(shape.id) as TLShape)
17
17
  )
18
- }
18
+ })
19
19
 
20
- const InnerIndicator = ({ editor, id }: { editor: Editor; id: TLShapeId }) => {
20
+ const InnerIndicator = memo(({ editor, id }: { editor: Editor; id: TLShapeId }) => {
21
21
  const shape = useValue('shape for indicator', () => editor.store.get(id), [editor, id])
22
22
 
23
23
  const { ShapeIndicatorErrorFallback } = useEditorComponents()
@@ -34,7 +34,7 @@ const InnerIndicator = ({ editor, id }: { editor: Editor; id: TLShapeId }) => {
34
34
  <EvenInnererIndicator key={shape.id} shape={shape} util={editor.getShapeUtil(shape)} />
35
35
  </OptionalErrorBoundary>
36
36
  )
37
- }
37
+ })
38
38
 
39
39
  /** @public */
40
40
  export interface TLShapeIndicatorProps {
@@ -4,10 +4,24 @@ import { memo, useRef } from 'react'
4
4
  import { useEditor } from '../../hooks/useEditor'
5
5
  import { useEditorComponents } from '../../hooks/useEditorComponents'
6
6
 
7
+ /** @public */
8
+ export interface TLShapeIndicatorsProps {
9
+ /** Whether to hide all of the indicators */
10
+ hideAll?: boolean
11
+ /** Whether to show all of the indicators */
12
+ showAll?: boolean
13
+ }
14
+
7
15
  /** @public @react */
8
- export const DefaultShapeIndicators = memo(function DefaultShapeIndicators() {
16
+ export const DefaultShapeIndicators = memo(function DefaultShapeIndicators({
17
+ hideAll,
18
+ showAll,
19
+ }: TLShapeIndicatorsProps) {
9
20
  const editor = useEditor()
10
21
 
22
+ if (hideAll && showAll)
23
+ throw Error('You cannot set both hideAll and showAll props to true, cmon now')
24
+
11
25
  const rPreviousSelectedShapeIds = useRef<Set<TLShapeId>>(new Set())
12
26
 
13
27
  const idsToDisplay = useValue(
@@ -16,33 +30,38 @@ export const DefaultShapeIndicators = memo(function DefaultShapeIndicators() {
16
30
  const prev = rPreviousSelectedShapeIds.current
17
31
  const next = new Set<TLShapeId>()
18
32
 
19
- if (
20
- // We only show indicators when in the following states...
21
- editor.isInAny(
22
- 'select.idle',
23
- 'select.brushing',
24
- 'select.scribble_brushing',
25
- 'select.editing_shape',
26
- 'select.pointing_shape',
27
- 'select.pointing_selection',
28
- 'select.pointing_handle'
29
- ) &&
30
- // ...but we hide indicators when we've just changed a style (so that the user can see the change)
31
- !editor.getInstanceState().isChangingStyle
32
- ) {
33
- // We always want to show indicators for the selected shapes, if any
34
- const selected = editor.getSelectedShapeIds()
35
- for (const id of selected) {
36
- next.add(id)
37
- }
33
+ const isChangingStyle = editor.getInstanceState().isChangingStyle
34
+
35
+ // todo: this is tldraw specific and is duplicated at the tldraw layer. What should we do here instead?
36
+ const isInSelectState = editor.isInAny(
37
+ 'select.idle',
38
+ 'select.brushing',
39
+ 'select.scribble_brushing',
40
+ 'select.editing_shape',
41
+ 'select.pointing_shape',
42
+ 'select.pointing_selection',
43
+ 'select.pointing_handle'
44
+ )
45
+
46
+ // We hide all indicators if we're changing style or in certain interactions
47
+ // todo: move this to some kind of Tool.hideIndicators property
48
+ if (isChangingStyle || !isInSelectState) {
49
+ rPreviousSelectedShapeIds.current = next
50
+ return next
51
+ }
52
+
53
+ // We always want to show indicators for the selected shapes, if any
54
+ const selected = editor.getSelectedShapeIds()
55
+ for (const id of selected) {
56
+ next.add(id)
57
+ }
38
58
 
39
- // If we're idle or editing a shape, we want to also show an indicator for the hovered shape, if any
40
- if (editor.isInAny('select.idle', 'select.editing_shape')) {
41
- const instanceState = editor.getInstanceState()
42
- if (instanceState.isHoveringCanvas && !instanceState.isCoarsePointer) {
43
- const hovered = editor.getHoveredShapeId()
44
- if (hovered) next.add(hovered)
45
- }
59
+ // If we're idle or editing a shape, we want to also show an indicator for the hovered shape, if any
60
+ if (editor.isInAny('select.idle', 'select.editing_shape')) {
61
+ const instanceState = editor.getInstanceState()
62
+ if (instanceState.isHoveringCanvas && !instanceState.isCoarsePointer) {
63
+ const hovered = editor.getHoveredShapeId()
64
+ if (hovered) next.add(hovered)
46
65
  }
47
66
  }
48
67
 
@@ -75,6 +94,10 @@ export const DefaultShapeIndicators = memo(function DefaultShapeIndicators() {
75
94
  if (!ShapeIndicator) return null
76
95
 
77
96
  return renderingShapes.map(({ id }) => (
78
- <ShapeIndicator key={id + '_indicator'} shapeId={id} hidden={!idsToDisplay.has(id)} />
97
+ <ShapeIndicator
98
+ key={id + '_indicator'}
99
+ shapeId={id}
100
+ hidden={!showAll && (hideAll || !idsToDisplay.has(id))}
101
+ />
79
102
  ))
80
103
  })
@@ -7,7 +7,7 @@ export const DEFAULT_CAMERA_OPTIONS: TLCameraOptions = {
7
7
  wheelBehavior: 'pan',
8
8
  panSpeed: 1,
9
9
  zoomSpeed: 1,
10
- zoomSteps: [0.1, 0.25, 0.5, 1, 2, 4, 8],
10
+ zoomSteps: [0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8],
11
11
  }
12
12
 
13
13
  /** @internal */
@@ -6328,21 +6328,22 @@ export class Editor extends EventEmitter<TLEventMap> {
6328
6328
  *
6329
6329
  * @example
6330
6330
  * ```ts
6331
- * editor.stackShapes([box1, box2], 'horizontal', 32)
6332
- * editor.stackShapes(editor.getSelectedShapeIds(), 'horizontal', 32)
6331
+ * editor.stackShapes([box1, box2], 'horizontal')
6332
+ * editor.stackShapes(editor.getSelectedShapeIds(), 'horizontal')
6333
6333
  * ```
6334
6334
  *
6335
6335
  * @param shapes - The shapes (or shape ids) to stack.
6336
6336
  * @param operation - Whether to stack horizontally or vertically.
6337
- * @param gap - The gap to leave between shapes.
6337
+ * @param gap - The gap to leave between shapes. By default, uses the editor's `adjacentShapeMargin` option.
6338
6338
  *
6339
6339
  * @public
6340
6340
  */
6341
6341
  stackShapes(
6342
6342
  shapes: TLShapeId[] | TLShape[],
6343
6343
  operation: 'horizontal' | 'vertical',
6344
- gap: number
6344
+ gap?: number
6345
6345
  ): this {
6346
+ const _gap = gap ?? this.options.adjacentShapeMargin
6346
6347
  const ids =
6347
6348
  typeof shapes[0] === 'string'
6348
6349
  ? (shapes as TLShapeId[])
@@ -6400,7 +6401,7 @@ export class Editor extends EventEmitter<TLEventMap> {
6400
6401
  }
6401
6402
 
6402
6403
  const len = shapeClustersToStack.length
6403
- if ((gap === 0 && len < 3) || len < 2) return this
6404
+ if ((_gap === 0 && len < 3) || len < 2) return this
6404
6405
 
6405
6406
  let val: 'x' | 'y'
6406
6407
  let min: 'minX' | 'minY'
@@ -6421,7 +6422,7 @@ export class Editor extends EventEmitter<TLEventMap> {
6421
6422
 
6422
6423
  let shapeGap: number = 0
6423
6424
 
6424
- if (gap === 0) {
6425
+ if (_gap === 0) {
6425
6426
  // note: this is not used in the current tldraw.com; there we use a specified stack
6426
6427
 
6427
6428
  const gaps: Record<number, number> = {}
@@ -6461,7 +6462,7 @@ export class Editor extends EventEmitter<TLEventMap> {
6461
6462
  }
6462
6463
  } else {
6463
6464
  // If a gap was provided, then use that instead.
6464
- shapeGap = gap
6465
+ shapeGap = _gap
6465
6466
  }
6466
6467
 
6467
6468
  const changes: TLShapePartial[] = []
@@ -6500,17 +6501,19 @@ export class Editor extends EventEmitter<TLEventMap> {
6500
6501
  *
6501
6502
  * @example
6502
6503
  * ```ts
6503
- * editor.packShapes([box1, box2], 32)
6504
+ * editor.packShapes([box1, box2])
6504
6505
  * editor.packShapes(editor.getSelectedShapeIds(), 32)
6505
6506
  * ```
6506
6507
  *
6507
6508
  *
6508
6509
  * @param shapes - The shapes (or shape ids) to pack.
6509
- * @param gap - The padding to apply to the packed shapes. Defaults to 16.
6510
+ * @param gap - The padding to apply to the packed shapes. Defaults to the editor's `adjacentShapeMargin` option.
6510
6511
  */
6511
- packShapes(shapes: TLShapeId[] | TLShape[], gap: number): this {
6512
+ packShapes(shapes: TLShapeId[] | TLShape[], _gap?: number): this {
6512
6513
  if (this.getIsReadonly()) return this
6513
6514
 
6515
+ const gap = _gap ?? this.options.adjacentShapeMargin
6516
+
6514
6517
  const ids =
6515
6518
  typeof shapes[0] === 'string'
6516
6519
  ? (shapes as TLShapeId[])
@@ -62,7 +62,7 @@ export async function exportToSvg(
62
62
  const svg = renderTarget.firstElementChild
63
63
  assert(svg instanceof SVGSVGElement, 'Expected an SVG element')
64
64
 
65
- // And apply any changes to <foreignObject> elements that we need to make. Whilst we're in
65
+ // And apply any changes to <foreignObject> elements that we need to make. while we're in
66
66
  // the document, these elements work exactly as we'd expect from other dom elements - they
67
67
  // can load external resources, and any stylesheets in the document apply to them as we
68
68
  // would expect them to. But when we pull the SVG into its own file or draw it to a canvas
package/src/version.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  // This file is automatically generated by internal/scripts/refresh-assets.ts.
2
2
  // Do not edit manually. Or do, I'm a comment, not a cop.
3
3
 
4
- export const version = '3.11.0-canary.be7c870ecadb'
4
+ export const version = '3.11.0-canary.bf79438b7304'
5
5
  export const publishDates = {
6
6
  major: '2024-09-13T14:36:29.063Z',
7
- minor: '2025-03-13T15:33:43.856Z',
8
- patch: '2025-03-13T15:33:43.856Z',
7
+ minor: '2025-03-15T15:11:29.447Z',
8
+ patch: '2025-03-15T15:11:29.447Z',
9
9
  }