@tldraw/editor 3.15.0 → 3.16.0-canary.0a84defb63a4
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 +101 -0
- package/dist-cjs/index.js +3 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +2 -0
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/Shape.js +4 -26
- package/dist-cjs/lib/components/Shape.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js +53 -0
- package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js.map +7 -0
- package/dist-cjs/lib/editor/Editor.js +64 -35
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
- package/dist-cjs/lib/hooks/useEditorComponents.js +2 -0
- package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
- package/dist-cjs/lib/hooks/useStateAttribute.js +35 -0
- package/dist-cjs/lib/hooks/useStateAttribute.js.map +7 -0
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +101 -0
- package/dist-esm/index.mjs +5 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +2 -0
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/Shape.mjs +4 -26
- package/dist-esm/lib/components/Shape.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeWrapper.mjs +23 -0
- package/dist-esm/lib/components/default-components/DefaultShapeWrapper.mjs.map +7 -0
- package/dist-esm/lib/editor/Editor.mjs +64 -35
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEditorComponents.mjs +4 -0
- package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useStateAttribute.mjs +15 -0
- package/dist-esm/lib/hooks/useStateAttribute.mjs.map +7 -0
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +4 -23
- package/package.json +7 -7
- package/src/index.ts +5 -0
- package/src/lib/TldrawEditor.tsx +2 -0
- package/src/lib/components/Shape.tsx +6 -21
- package/src/lib/components/default-components/DefaultShapeWrapper.tsx +35 -0
- package/src/lib/editor/Editor.ts +71 -35
- package/src/lib/editor/shapes/ShapeUtil.ts +57 -0
- package/src/lib/editor/types/misc-types.ts +19 -0
- package/src/lib/hooks/useEditorComponents.tsx +7 -1
- package/src/lib/hooks/useStateAttribute.ts +15 -0
- package/src/version.ts +3 -3
|
@@ -0,0 +1,53 @@
|
|
|
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 DefaultShapeWrapper_exports = {};
|
|
30
|
+
__export(DefaultShapeWrapper_exports, {
|
|
31
|
+
DefaultShapeWrapper: () => DefaultShapeWrapper
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(DefaultShapeWrapper_exports);
|
|
34
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
+
var import_classnames = __toESM(require("classnames"));
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
const DefaultShapeWrapper = (0, import_react.forwardRef)(function DefaultShapeWrapper2({ children, shape, isBackground, ...props }, ref) {
|
|
38
|
+
const isFilledShape = "fill" in shape.props && shape.props.fill !== "none";
|
|
39
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
40
|
+
"div",
|
|
41
|
+
{
|
|
42
|
+
ref,
|
|
43
|
+
"data-shape-type": shape.type,
|
|
44
|
+
"data-shape-is-filled": isBackground ? void 0 : isFilledShape,
|
|
45
|
+
"data-shape-id": shape.id,
|
|
46
|
+
draggable: false,
|
|
47
|
+
...props,
|
|
48
|
+
className: (0, import_classnames.default)("tl-shape", isBackground && "tl-shape-background", props.className),
|
|
49
|
+
children
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=DefaultShapeWrapper.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/lib/components/default-components/DefaultShapeWrapper.tsx"],
|
|
4
|
+
"sourcesContent": ["import { TLShape } from '@tldraw/tlschema'\nimport classNames from 'classnames'\nimport { forwardRef, ReactNode } from 'react'\n\n/** @public */\nexport interface TLShapeWrapperProps extends React.HTMLAttributes<HTMLDivElement> {\n\t/** The shape being rendered. */\n\tshape: TLShape\n\t/** Whether this is the shapes regular, or background component. */\n\tisBackground: boolean\n\t/** The shape's rendered component. */\n\tchildren: ReactNode\n}\n\n/** @public @react */\nexport const DefaultShapeWrapper = forwardRef(function DefaultShapeWrapper(\n\t{ children, shape, isBackground, ...props }: TLShapeWrapperProps,\n\tref: React.Ref<HTMLDivElement>\n) {\n\tconst isFilledShape = 'fill' in shape.props && shape.props.fill !== 'none'\n\n\treturn (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tdata-shape-type={shape.type}\n\t\t\tdata-shape-is-filled={isBackground ? undefined : isFilledShape}\n\t\t\tdata-shape-id={shape.id}\n\t\t\tdraggable={false}\n\t\t\t{...props}\n\t\t\tclassName={classNames('tl-shape', isBackground && 'tl-shape-background', props.className)}\n\t\t>\n\t\t\t{children}\n\t\t</div>\n\t)\n})\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBE;AArBF,wBAAuB;AACvB,mBAAsC;AAa/B,MAAM,0BAAsB,yBAAW,SAASA,qBACtD,EAAE,UAAU,OAAO,cAAc,GAAG,MAAM,GAC1C,KACC;AACD,QAAM,gBAAgB,UAAU,MAAM,SAAS,MAAM,MAAM,SAAS;AAEpE,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA,mBAAiB,MAAM;AAAA,MACvB,wBAAsB,eAAe,SAAY;AAAA,MACjD,iBAAe,MAAM;AAAA,MACrB,WAAW;AAAA,MACV,GAAG;AAAA,MACJ,eAAW,kBAAAC,SAAW,YAAY,gBAAgB,uBAAuB,MAAM,SAAS;AAAA,MAEvF;AAAA;AAAA,EACF;AAEF,CAAC;",
|
|
6
|
+
"names": ["DefaultShapeWrapper", "classNames"]
|
|
7
|
+
}
|
|
@@ -2323,28 +2323,11 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
2323
2323
|
{ history: "ignore" }
|
|
2324
2324
|
);
|
|
2325
2325
|
const { currentScreenPoint, currentPagePoint } = this.inputs;
|
|
2326
|
-
const { screenBounds } = this.store.unsafeGetWithoutCapture(import_tlschema.TLINSTANCE_ID);
|
|
2327
2326
|
if (currentScreenPoint.x / z - x !== currentPagePoint.x || currentScreenPoint.y / z - y !== currentPagePoint.y) {
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
// weird but true: we need to put the screen point back into client space
|
|
2333
|
-
point: import_Vec.Vec.AddXY(currentScreenPoint, screenBounds.x, screenBounds.y),
|
|
2334
|
-
pointerId: import_constants.INTERNAL_POINTER_IDS.CAMERA_MOVE,
|
|
2335
|
-
ctrlKey: this.inputs.ctrlKey,
|
|
2336
|
-
altKey: this.inputs.altKey,
|
|
2337
|
-
shiftKey: this.inputs.shiftKey,
|
|
2338
|
-
metaKey: this.inputs.metaKey,
|
|
2339
|
-
accelKey: (0, import_keyboard.isAccelKey)(this.inputs),
|
|
2340
|
-
button: 0,
|
|
2341
|
-
isPen: this.getInstanceState().isPenMode ?? false
|
|
2342
|
-
};
|
|
2343
|
-
if (opts?.immediate) {
|
|
2344
|
-
this._flushEventForTick(event);
|
|
2345
|
-
} else {
|
|
2346
|
-
this.dispatch(event);
|
|
2347
|
-
}
|
|
2327
|
+
this.updatePointer({
|
|
2328
|
+
immediate: opts?.immediate,
|
|
2329
|
+
pointerId: import_constants.INTERNAL_POINTER_IDS.CAMERA_MOVE
|
|
2330
|
+
});
|
|
2348
2331
|
}
|
|
2349
2332
|
this._tickCameraState();
|
|
2350
2333
|
});
|
|
@@ -3313,19 +3296,24 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3313
3296
|
*/
|
|
3314
3297
|
deletePage(page) {
|
|
3315
3298
|
const id = typeof page === "string" ? page : page.id;
|
|
3316
|
-
this.run(
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3299
|
+
this.run(
|
|
3300
|
+
() => {
|
|
3301
|
+
if (this.getIsReadonly()) return;
|
|
3302
|
+
const pages = this.getPages();
|
|
3303
|
+
if (pages.length === 1) return;
|
|
3304
|
+
const deletedPage = this.getPage(id);
|
|
3305
|
+
if (!deletedPage) return;
|
|
3306
|
+
if (id === this.getCurrentPageId()) {
|
|
3307
|
+
const index = pages.findIndex((page2) => page2.id === id);
|
|
3308
|
+
const next = pages[index - 1] ?? pages[index + 1];
|
|
3309
|
+
this.setCurrentPage(next.id);
|
|
3310
|
+
}
|
|
3311
|
+
const shapes = this.getSortedChildIdsForParent(deletedPage.id);
|
|
3312
|
+
this.deleteShapes(shapes);
|
|
3313
|
+
this.store.remove([deletedPage.id]);
|
|
3314
|
+
},
|
|
3315
|
+
{ ignoreShapeLock: true }
|
|
3316
|
+
);
|
|
3329
3317
|
return this;
|
|
3330
3318
|
}
|
|
3331
3319
|
/**
|
|
@@ -3939,7 +3927,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3939
3927
|
const geometry = this.getShapeGeometry(shape);
|
|
3940
3928
|
const isGroup = geometry instanceof import_Group2d.Group2d;
|
|
3941
3929
|
const pointInShapeSpace = this.getPointInShapeSpace(shape, point);
|
|
3942
|
-
if (this.isShapeOfType(shape, "frame") || this.isShapeOfType(shape, "
|
|
3930
|
+
if (this.isShapeOfType(shape, "frame") || (this.isShapeOfType(shape, "note") || this.isShapeOfType(shape, "arrow") || this.isShapeOfType(shape, "geo") && shape.props.fill === "none") && this.getShapeUtil(shape).getText(shape)?.trim()) {
|
|
3943
3931
|
for (const childGeometry of geometry.children) {
|
|
3944
3932
|
if (childGeometry.isLabel && childGeometry.isPointInBounds(pointInShapeSpace)) {
|
|
3945
3933
|
return shape;
|
|
@@ -7028,6 +7016,47 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7028
7016
|
this.dispatch({ type: "misc", name: "complete" });
|
|
7029
7017
|
return this;
|
|
7030
7018
|
}
|
|
7019
|
+
/**
|
|
7020
|
+
* Dispatch a pointer move event in the current position of the pointer. This is useful when
|
|
7021
|
+
* external circumstances have changed (e.g. the camera moved or a shape was moved) and you want
|
|
7022
|
+
* the current interaction to respond to that change.
|
|
7023
|
+
*
|
|
7024
|
+
* @example
|
|
7025
|
+
* ```ts
|
|
7026
|
+
* editor.updatePointer()
|
|
7027
|
+
* ```
|
|
7028
|
+
*
|
|
7029
|
+
* @param options - The options for updating the pointer.
|
|
7030
|
+
* @returns The editor instance.
|
|
7031
|
+
* @public
|
|
7032
|
+
*/
|
|
7033
|
+
updatePointer(options) {
|
|
7034
|
+
const event = {
|
|
7035
|
+
type: "pointer",
|
|
7036
|
+
target: "canvas",
|
|
7037
|
+
name: "pointer_move",
|
|
7038
|
+
point: options?.point ?? // weird but true: what `inputs` calls screen-space is actually viewport space. so
|
|
7039
|
+
// we need to convert back into true screen space first. we should fix this...
|
|
7040
|
+
import_Vec.Vec.Add(
|
|
7041
|
+
this.inputs.currentScreenPoint,
|
|
7042
|
+
this.store.unsafeGetWithoutCapture(import_tlschema.TLINSTANCE_ID).screenBounds
|
|
7043
|
+
),
|
|
7044
|
+
pointerId: options?.pointerId ?? 0,
|
|
7045
|
+
button: options?.button ?? 0,
|
|
7046
|
+
isPen: options?.isPen ?? this.inputs.isPen,
|
|
7047
|
+
shiftKey: options?.shiftKey ?? this.inputs.shiftKey,
|
|
7048
|
+
altKey: options?.altKey ?? this.inputs.altKey,
|
|
7049
|
+
ctrlKey: options?.ctrlKey ?? this.inputs.ctrlKey,
|
|
7050
|
+
metaKey: options?.metaKey ?? this.inputs.metaKey,
|
|
7051
|
+
accelKey: options?.accelKey ?? (0, import_keyboard.isAccelKey)(this.inputs)
|
|
7052
|
+
};
|
|
7053
|
+
if (options?.immediate) {
|
|
7054
|
+
this._flushEventForTick(event);
|
|
7055
|
+
} else {
|
|
7056
|
+
this.dispatch(event);
|
|
7057
|
+
}
|
|
7058
|
+
return this;
|
|
7059
|
+
}
|
|
7031
7060
|
/**
|
|
7032
7061
|
* Puts the editor into focused mode.
|
|
7033
7062
|
*
|