@tldraw/editor 5.3.0-next.299378752aaf → 5.3.0-next.2fa9c61a8de6

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 (87) hide show
  1. package/dist-cjs/index.d.ts +76 -0
  2. package/dist-cjs/index.js +10 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/components/LiveCollaborators.js +98 -0
  5. package/dist-cjs/lib/components/LiveCollaborators.js.map +7 -0
  6. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +4 -10
  7. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +3 -3
  8. package/dist-cjs/lib/components/default-components/DefaultCursor.js +59 -0
  9. package/dist-cjs/lib/components/default-components/DefaultCursor.js.map +7 -0
  10. package/dist-cjs/lib/editor/Editor.js +7 -2
  11. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  12. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +3 -0
  13. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
  14. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  15. package/dist-cjs/lib/hooks/EditorComponentsContext.js.map +2 -2
  16. package/dist-cjs/lib/hooks/useCursor.js +1 -0
  17. package/dist-cjs/lib/hooks/useCursor.js.map +2 -2
  18. package/dist-cjs/lib/hooks/useEditorComponents.js +2 -0
  19. package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
  20. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +25 -1
  21. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
  22. package/dist-cjs/lib/hooks/useTransform.js +45 -0
  23. package/dist-cjs/lib/hooks/useTransform.js.map +7 -0
  24. package/dist-cjs/lib/license/LicenseManager.js +62 -7
  25. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  26. package/dist-cjs/lib/license/useLicenseManagerState.js +7 -0
  27. package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
  28. package/dist-cjs/lib/utils/collaborators.js +27 -0
  29. package/dist-cjs/lib/utils/collaborators.js.map +7 -0
  30. package/dist-cjs/lib/utils/getHtmlLayerTransform.js +33 -0
  31. package/dist-cjs/lib/utils/getHtmlLayerTransform.js.map +7 -0
  32. package/dist-cjs/version.js +3 -3
  33. package/dist-cjs/version.js.map +1 -1
  34. package/dist-esm/index.d.mts +76 -0
  35. package/dist-esm/index.mjs +13 -2
  36. package/dist-esm/index.mjs.map +2 -2
  37. package/dist-esm/lib/components/LiveCollaborators.mjs +78 -0
  38. package/dist-esm/lib/components/LiveCollaborators.mjs.map +7 -0
  39. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +5 -11
  40. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  41. package/dist-esm/lib/components/default-components/DefaultCursor.mjs +29 -0
  42. package/dist-esm/lib/components/default-components/DefaultCursor.mjs.map +7 -0
  43. package/dist-esm/lib/editor/Editor.mjs +7 -2
  44. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  45. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +3 -0
  46. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
  47. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  48. package/dist-esm/lib/hooks/EditorComponentsContext.mjs.map +2 -2
  49. package/dist-esm/lib/hooks/useCursor.mjs +1 -0
  50. package/dist-esm/lib/hooks/useCursor.mjs.map +2 -2
  51. package/dist-esm/lib/hooks/useEditorComponents.mjs +2 -0
  52. package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
  53. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +25 -1
  54. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
  55. package/dist-esm/lib/hooks/useTransform.mjs +25 -0
  56. package/dist-esm/lib/hooks/useTransform.mjs.map +7 -0
  57. package/dist-esm/lib/license/LicenseManager.mjs +63 -8
  58. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  59. package/dist-esm/lib/license/useLicenseManagerState.mjs +7 -0
  60. package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
  61. package/dist-esm/lib/utils/collaborators.mjs +7 -0
  62. package/dist-esm/lib/utils/collaborators.mjs.map +7 -0
  63. package/dist-esm/lib/utils/getHtmlLayerTransform.mjs +13 -0
  64. package/dist-esm/lib/utils/getHtmlLayerTransform.mjs.map +7 -0
  65. package/dist-esm/version.mjs +3 -3
  66. package/dist-esm/version.mjs.map +1 -1
  67. package/editor.css +47 -4
  68. package/package.json +7 -7
  69. package/src/index.ts +9 -1
  70. package/src/lib/components/LiveCollaborators.tsx +119 -0
  71. package/src/lib/components/default-components/DefaultCanvas.tsx +5 -17
  72. package/src/lib/components/default-components/DefaultCursor.tsx +65 -0
  73. package/src/lib/editor/Editor.ts +14 -2
  74. package/src/lib/editor/managers/TextManager/TextManager.ts +3 -0
  75. package/src/lib/editor/shapes/ShapeUtil.ts +24 -0
  76. package/src/lib/hooks/EditorComponentsContext.tsx +2 -0
  77. package/src/lib/hooks/useCursor.ts +1 -0
  78. package/src/lib/hooks/useEditorComponents.tsx +2 -0
  79. package/src/lib/hooks/usePassThroughWheelEvents.ts +44 -2
  80. package/src/lib/hooks/useTransform.ts +38 -0
  81. package/src/lib/license/LicenseManager.test.ts +220 -29
  82. package/src/lib/license/LicenseManager.ts +107 -6
  83. package/src/lib/license/useLicenseManagerState.ts +17 -1
  84. package/src/lib/utils/collaborators.test.ts +34 -0
  85. package/src/lib/utils/collaborators.ts +25 -0
  86. package/src/lib/utils/getHtmlLayerTransform.ts +22 -0
  87. package/src/version.ts +3 -3
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var DefaultCursor_exports = {};
30
+ __export(DefaultCursor_exports, {
31
+ DefaultCursor: () => DefaultCursor
32
+ });
33
+ module.exports = __toCommonJS(DefaultCursor_exports);
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var import_classnames = __toESM(require("classnames"), 1);
36
+ var import_react = require("react");
37
+ var import_useSafeId = require("../../hooks/useSafeId");
38
+ var import_useTransform = require("../../hooks/useTransform");
39
+ const DefaultCursor = (0, import_react.memo)(function DefaultCursor2({
40
+ className,
41
+ zoom,
42
+ point,
43
+ color,
44
+ name,
45
+ chatMessage
46
+ }) {
47
+ const rCursor = (0, import_react.useRef)(null);
48
+ (0, import_useTransform.useTransform)(rCursor, point?.x, point?.y, 1 / zoom);
49
+ const cursorId = (0, import_useSafeId.useSharedSafeId)("cursor");
50
+ if (!point) return null;
51
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ref: rCursor, className: (0, import_classnames.default)("tl-collaborators__item", className), children: [
52
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: "tl-cursor", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("use", { href: `#${cursorId}`, color }) }),
53
+ chatMessage ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
54
+ name && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tl-nametag-title", style: { color }, children: name }),
55
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tl-nametag-chat", style: { backgroundColor: color }, children: chatMessage })
56
+ ] }) : name && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "tl-nametag", style: { backgroundColor: color }, children: name })
57
+ ] });
58
+ });
59
+ //# sourceMappingURL=DefaultCursor.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/lib/components/default-components/DefaultCursor.tsx"],
4
+ "sourcesContent": ["import { VecModel } from '@tldraw/tlschema'\nimport classNames from 'classnames'\nimport { memo, useRef } from 'react'\nimport { useSharedSafeId } from '../../hooks/useSafeId'\nimport { useTransform } from '../../hooks/useTransform'\n\n/** @public */\nexport interface TLCursorProps {\n\tuserId: string\n\tclassName?: string\n\tpoint: VecModel | null\n\tzoom: number\n\tcolor?: string\n\tname: string | null\n\tchatMessage: string\n}\n\n/**\n * The default collaborator cursor: the arrow glyph plus a name tag or chat bubble. The arrow is a\n * `<use>` of a shared `<defs>` symbol that `LiveCollaborators` renders, so a `DefaultCursor`\n * used outside that layer draws no arrow.\n *\n * @public @react\n */\nexport const DefaultCursor = memo(function DefaultCursor({\n\tclassName,\n\tzoom,\n\tpoint,\n\tcolor,\n\tname,\n\tchatMessage,\n}: TLCursorProps) {\n\tconst rCursor = useRef<HTMLDivElement>(null)\n\tuseTransform(rCursor, point?.x, point?.y, 1 / zoom)\n\n\tconst cursorId = useSharedSafeId('cursor')\n\n\tif (!point) return null\n\n\treturn (\n\t\t<div ref={rCursor} className={classNames('tl-collaborators__item', className)}>\n\t\t\t<svg className=\"tl-cursor\" aria-hidden=\"true\">\n\t\t\t\t<use href={`#${cursorId}`} color={color} />\n\t\t\t</svg>\n\t\t\t{chatMessage ? (\n\t\t\t\t<>\n\t\t\t\t\t{name && (\n\t\t\t\t\t\t<div className=\"tl-nametag-title\" style={{ color }}>\n\t\t\t\t\t\t\t{name}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t)}\n\t\t\t\t\t<div className=\"tl-nametag-chat\" style={{ backgroundColor: color }}>\n\t\t\t\t\t\t{chatMessage}\n\t\t\t\t\t</div>\n\t\t\t\t</>\n\t\t\t) : (\n\t\t\t\tname && (\n\t\t\t\t\t<div className=\"tl-nametag\" style={{ backgroundColor: color }}>\n\t\t\t\t\t\t{name}\n\t\t\t\t\t</div>\n\t\t\t\t)\n\t\t\t)}\n\t\t</div>\n\t)\n})\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0CI;AAzCJ,wBAAuB;AACvB,mBAA6B;AAC7B,uBAAgC;AAChC,0BAA6B;AAoBtB,MAAM,oBAAgB,mBAAK,SAASA,eAAc;AAAA,EACxD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAkB;AACjB,QAAM,cAAU,qBAAuB,IAAI;AAC3C,wCAAa,SAAS,OAAO,GAAG,OAAO,GAAG,IAAI,IAAI;AAElD,QAAM,eAAW,kCAAgB,QAAQ;AAEzC,MAAI,CAAC,MAAO,QAAO;AAEnB,SACC,6CAAC,SAAI,KAAK,SAAS,eAAW,kBAAAC,SAAW,0BAA0B,SAAS,GAC3E;AAAA,gDAAC,SAAI,WAAU,aAAY,eAAY,QACtC,sDAAC,SAAI,MAAM,IAAI,QAAQ,IAAI,OAAc,GAC1C;AAAA,IACC,cACA,4EACE;AAAA,cACA,4CAAC,SAAI,WAAU,oBAAmB,OAAO,EAAE,MAAM,GAC/C,gBACF;AAAA,MAED,4CAAC,SAAI,WAAU,mBAAkB,OAAO,EAAE,iBAAiB,MAAM,GAC/D,uBACF;AAAA,OACD,IAEA,QACC,4CAAC,SAAI,WAAU,cAAa,OAAO,EAAE,iBAAiB,MAAM,GAC1D,gBACF;AAAA,KAGH;AAEF,CAAC;",
6
+ "names": ["DefaultCursor", "classNames"]
7
+ }
@@ -5171,7 +5171,9 @@ class Editor extends import_eventemitter3.default {
5171
5171
  const index = (0, import_utils.getIndexBetween)(originalShape.index, siblingAbove?.index);
5172
5172
  shape.index = index;
5173
5173
  });
5174
- const shapesToCreate = shapesToCreateWithOriginals.map(({ shape }) => shape);
5174
+ const shapesToCreate = shapesToCreateWithOriginals.map(({ shape, originalShape }) => {
5175
+ return this.getShapeUtil(shape).onBeforeDuplicate?.(originalShape, shape) ?? shape;
5176
+ });
5175
5177
  if (!this.canCreateShapes(shapesToCreate)) {
5176
5178
  alertMaxShapes(this);
5177
5179
  return;
@@ -7197,7 +7199,10 @@ class Editor extends import_eventemitter3.default {
7197
7199
  const rootShapes = [];
7198
7200
  const newShapes = shapes.map((oldShape) => {
7199
7201
  const newId = shapeIdMap.get(oldShape.id);
7200
- const newShape = { ...oldShape, id: newId };
7202
+ let newShape = { ...oldShape, id: newId };
7203
+ if (!preserveIds) {
7204
+ newShape = this.getShapeUtil(newShape).onBeforeDuplicate?.(oldShape, newShape) ?? newShape;
7205
+ }
7201
7206
  if (rootShapeIds.includes(oldShape.id)) {
7202
7207
  newShape.parentId = currentPageId;
7203
7208
  rootShapes.push(newShape);