@yuzhouu/canvas-kit 0.1.2
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/README.md +145 -0
- package/_vendor/canvas-core/bindings/BindingUtil.ts +92 -0
- package/_vendor/canvas-core/bindings/BindingUtilRegistry.ts +22 -0
- package/_vendor/canvas-core/bindings/arrow/arrowBindingHelpers.ts +52 -0
- package/_vendor/canvas-core/contextMenu.ts +85 -0
- package/_vendor/canvas-core/editor/Editor.ts +2614 -0
- package/_vendor/canvas-core/editor/HistoryManager.ts +83 -0
- package/_vendor/canvas-core/editor/StateNode.ts +162 -0
- package/_vendor/canvas-core/editor/camera.ts +6 -0
- package/_vendor/canvas-core/editor/clipboard.ts +478 -0
- package/_vendor/canvas-core/editor/commands.ts +833 -0
- package/_vendor/canvas-core/editor/edgeScroll.ts +37 -0
- package/_vendor/canvas-core/editor/editorComputedHelpers.ts +257 -0
- package/_vendor/canvas-core/editor/editorSelectionTransforms.ts +116 -0
- package/_vendor/canvas-core/editor/events.ts +93 -0
- package/_vendor/canvas-core/editor/index.ts +12 -0
- package/_vendor/canvas-core/editor/interactions.ts +101 -0
- package/_vendor/canvas-core/editor/internal.ts +22 -0
- package/_vendor/canvas-core/editor/managers/BindingManager.ts +262 -0
- package/_vendor/canvas-core/editor/managers/CameraManager.ts +147 -0
- package/_vendor/canvas-core/editor/managers/ClipboardManager.ts +32 -0
- package/_vendor/canvas-core/editor/managers/DocumentSnapshotManager.ts +256 -0
- package/_vendor/canvas-core/editor/managers/InputsManager.ts +319 -0
- package/_vendor/canvas-core/editor/managers/InteractionTransientManager.ts +218 -0
- package/_vendor/canvas-core/editor/managers/QueryManager.ts +837 -0
- package/_vendor/canvas-core/editor/managers/RenderWindowManager.ts +347 -0
- package/_vendor/canvas-core/editor/managers/SelectionLayoutManager.ts +196 -0
- package/_vendor/canvas-core/editor/managers/SelectionManager.ts +98 -0
- package/_vendor/canvas-core/editor/managers/SelectionOverlayManager.ts +308 -0
- package/_vendor/canvas-core/editor/managers/ShapeEditingManager.ts +226 -0
- package/_vendor/canvas-core/editor/managers/ShapeGeometryManager.ts +162 -0
- package/_vendor/canvas-core/editor/managers/ShapeHierarchyManager.ts +797 -0
- package/_vendor/canvas-core/editor/managers/SideEffectManager.ts +83 -0
- package/_vendor/canvas-core/editor/managers/SnapManager.ts +433 -0
- package/_vendor/canvas-core/editor/managers/SnapSnapshotBuilder.ts +430 -0
- package/_vendor/canvas-core/editor/managers/SpatialIndexManager.ts +354 -0
- package/_vendor/canvas-core/editor/managers/ToolManager.ts +81 -0
- package/_vendor/canvas-core/editor/managers/queryState.ts +583 -0
- package/_vendor/canvas-core/editor/managers/selectionGeometry.ts +287 -0
- package/_vendor/canvas-core/editor/managers/shapeOrder.ts +350 -0
- package/_vendor/canvas-core/editor/managers/shapeReparenting.ts +160 -0
- package/_vendor/canvas-core/editor/managers/snapCalculations.ts +412 -0
- package/_vendor/canvas-core/editor/managers/snapGeometry.ts +202 -0
- package/_vendor/canvas-core/editor/managers/snapIndicators.ts +403 -0
- package/_vendor/canvas-core/editor/managers/snapTypes.ts +122 -0
- package/_vendor/canvas-core/editor/queries/shapeTransforms.ts +171 -0
- package/_vendor/canvas-core/editor/renderWindow.ts +439 -0
- package/_vendor/canvas-core/editor/resizeGeometry.ts +654 -0
- package/_vendor/canvas-core/editor/selection.ts +489 -0
- package/_vendor/canvas-core/editor/selectionHandleInteractions.ts +43 -0
- package/_vendor/canvas-core/editor/selectionOverlay.ts +567 -0
- package/_vendor/canvas-core/exports/integrity.ts +174 -0
- package/_vendor/canvas-core/exports/svg.ts +494 -0
- package/_vendor/canvas-core/geometry/Box.ts +80 -0
- package/_vendor/canvas-core/geometry/Ellipse2d.ts +67 -0
- package/_vendor/canvas-core/geometry/Geometry2d.ts +52 -0
- package/_vendor/canvas-core/geometry/Mat.ts +92 -0
- package/_vendor/canvas-core/geometry/Polyline2d.ts +63 -0
- package/_vendor/canvas-core/geometry/Rectangle2d.ts +64 -0
- package/_vendor/canvas-core/geometry/Vec.ts +123 -0
- package/_vendor/canvas-core/geometry/index.ts +13 -0
- package/_vendor/canvas-core/geometry/segments.ts +65 -0
- package/_vendor/canvas-core/index.ts +391 -0
- package/_vendor/canvas-core/plugins/index.ts +5 -0
- package/_vendor/canvas-core/plugins/types.ts +53 -0
- package/_vendor/canvas-core/reactivity.ts +16 -0
- package/_vendor/canvas-core/schema/records.ts +221 -0
- package/_vendor/canvas-core/schema/snapshots.ts +527 -0
- package/_vendor/canvas-core/shapes/ShapeUtil.ts +516 -0
- package/_vendor/canvas-core/shapes/ShapeUtilRegistry.ts +26 -0
- package/_vendor/canvas-core/shapes/capabilities.ts +67 -0
- package/_vendor/canvas-core/shapes/types.ts +20 -0
- package/_vendor/canvas-core/toolbar.ts +148 -0
- package/_vendor/canvas-core/tools/hand/HandTool.ts +75 -0
- package/_vendor/canvas-core/tools/index.ts +2 -0
- package/_vendor/canvas-core/tools/select/SelectTool.ts +33 -0
- package/_vendor/canvas-core/tools/select/selectContainment.ts +104 -0
- package/_vendor/canvas-core/tools/select/selectToolHelpers.ts +801 -0
- package/_vendor/canvas-core/tools/select/states/BrushingState.ts +145 -0
- package/_vendor/canvas-core/tools/select/states/DraggingSelectionHandleInteractionState.ts +116 -0
- package/_vendor/canvas-core/tools/select/states/IdleState.ts +159 -0
- package/_vendor/canvas-core/tools/select/states/PointingCanvasState.ts +41 -0
- package/_vendor/canvas-core/tools/select/states/PointingResizeHandleState.ts +78 -0
- package/_vendor/canvas-core/tools/select/states/PointingRotateHandleState.ts +64 -0
- package/_vendor/canvas-core/tools/select/states/PointingSelectionHandleInteractionState.ts +34 -0
- package/_vendor/canvas-core/tools/select/states/PointingShapeState.ts +140 -0
- package/_vendor/canvas-core/tools/select/states/ResizingState.ts +171 -0
- package/_vendor/canvas-core/tools/select/states/RotatingState.ts +124 -0
- package/_vendor/canvas-core/tools/select/states/SelectStateNode.ts +128 -0
- package/_vendor/canvas-core/tools/select/states/TranslatingState.ts +139 -0
- package/_vendor/canvas-core/tools/select/states/index.ts +11 -0
- package/_vendor/canvas-plugin-api/feature.ts +204 -0
- package/_vendor/canvas-plugin-api/index.ts +142 -0
- package/_vendor/canvas-product-react/api/apiRegistry.ts +35 -0
- package/_vendor/canvas-product-react/api/canvasProductApi.ts +422 -0
- package/_vendor/canvas-product-react/api/index.ts +31 -0
- package/_vendor/canvas-product-react/capabilities/clipboard/clipboardService.ts +36 -0
- package/_vendor/canvas-product-react/capabilities/clipboard/systemClipboard.ts +245 -0
- package/_vendor/canvas-product-react/capabilities/context-menu/systemContextMenu.ts +396 -0
- package/_vendor/canvas-product-react/capabilities/context-menu/useContextMenuSurface.ts +59 -0
- package/_vendor/canvas-product-react/capabilities/export/useSvgExport.ts +156 -0
- package/_vendor/canvas-product-react/capabilities/history/useHistoryControls.ts +23 -0
- package/_vendor/canvas-product-react/capabilities/pages/usePageControls.ts +41 -0
- package/_vendor/canvas-product-react/capabilities/toolbar/systemToolbar.ts +490 -0
- package/_vendor/canvas-product-react/capabilities/toolbar/useToolbarSurfaces.ts +92 -0
- package/_vendor/canvas-product-react/capabilities/zoom/useZoomControls.ts +27 -0
- package/_vendor/canvas-product-react/index.ts +84 -0
- package/_vendor/canvas-product-react/persistence/index.ts +18 -0
- package/_vendor/canvas-product-react/persistence/localSnapshotPersistence.ts +294 -0
- package/_vendor/canvas-product-react/runtime/CanvasProductRoot.tsx +250 -0
- package/_vendor/canvas-product-react/runtime/productDefinition.ts +72 -0
- package/_vendor/canvas-product-react/runtime/productServices.ts +96 -0
- package/_vendor/canvas-react/components/CanvasView.tsx +796 -0
- package/_vendor/canvas-react/components/OverlayLayer.tsx +879 -0
- package/_vendor/canvas-react/components/PageSpace.tsx +34 -0
- package/_vendor/canvas-react/components/ShapeLayer.tsx +428 -0
- package/_vendor/canvas-react/components/index.ts +4 -0
- package/_vendor/canvas-react/hooks/useEditor.ts +11 -0
- package/_vendor/canvas-react/hooks/useValue.ts +14 -0
- package/_vendor/canvas-react/host/CanvasRendererRegistryContext.tsx +14 -0
- package/_vendor/canvas-react/host/contextMenuRegistry.ts +61 -0
- package/_vendor/canvas-react/host/domEventGuards.ts +61 -0
- package/_vendor/canvas-react/host/index.ts +38 -0
- package/_vendor/canvas-react/host/pluginHost.ts +635 -0
- package/_vendor/canvas-react/host/rendererRegistry.tsx +58 -0
- package/_vendor/canvas-react/host/toolbarRegistry.ts +100 -0
- package/_vendor/canvas-react/index.ts +3 -0
- package/_vendor/plugin-arrow/ArrowBindingUtil.ts +239 -0
- package/_vendor/plugin-arrow/ArrowShapeUtil.ts +311 -0
- package/_vendor/plugin-arrow/ArrowTool.ts +208 -0
- package/_vendor/plugin-arrow/arrowGeometry.ts +441 -0
- package/_vendor/plugin-arrow/arrowTerminalBindingResolver.ts +253 -0
- package/_vendor/plugin-arrow/arrowTerminalCommands.ts +230 -0
- package/_vendor/plugin-arrow/canvas.tsx +92 -0
- package/_vendor/plugin-arrow/core.ts +409 -0
- package/_vendor/plugin-arrow/feature.ts +20 -0
- package/_vendor/plugin-arrow/index.ts +28 -0
- package/_vendor/plugin-arrow/selectionHandleInteractions.ts +154 -0
- package/_vendor/plugin-arrow/types.ts +63 -0
- package/_vendor/plugin-draw/DrawShapeRenderer.tsx +60 -0
- package/_vendor/plugin-draw/DrawShapeUtil.ts +372 -0
- package/_vendor/plugin-draw/DrawTool.ts +444 -0
- package/_vendor/plugin-draw/canvas.tsx +24 -0
- package/_vendor/plugin-draw/core.ts +515 -0
- package/_vendor/plugin-draw/drawGeometry.ts +491 -0
- package/_vendor/plugin-draw/drawHitTest.ts +271 -0
- package/_vendor/plugin-draw/drawInterpolation.ts +250 -0
- package/_vendor/plugin-draw/drawPath.ts +550 -0
- package/_vendor/plugin-draw/drawSegments.ts +106 -0
- package/_vendor/plugin-draw/drawSelectionTransform.ts +67 -0
- package/_vendor/plugin-draw/drawShapeGeometry.ts +307 -0
- package/_vendor/plugin-draw/drawStrokeGeometry.ts +454 -0
- package/_vendor/plugin-draw/feature.ts +20 -0
- package/_vendor/plugin-draw/index.ts +31 -0
- package/_vendor/plugin-draw/types.ts +36 -0
- package/_vendor/plugin-eraser/EraserTool.ts +297 -0
- package/_vendor/plugin-eraser/canvas.tsx +616 -0
- package/_vendor/plugin-eraser/core.ts +49 -0
- package/_vendor/plugin-eraser/feature.ts +20 -0
- package/_vendor/plugin-eraser/index.ts +4 -0
- package/_vendor/plugin-frame/FrameShapeUtil.ts +173 -0
- package/_vendor/plugin-frame/FrameTool.ts +225 -0
- package/_vendor/plugin-frame/canvas.tsx +75 -0
- package/_vendor/plugin-frame/core.ts +534 -0
- package/_vendor/plugin-frame/feature.ts +20 -0
- package/_vendor/plugin-frame/index.ts +6 -0
- package/_vendor/plugin-geo/GeoShapeUtil.ts +463 -0
- package/_vendor/plugin-geo/GeoTools.ts +247 -0
- package/_vendor/plugin-geo/canvas.tsx +90 -0
- package/_vendor/plugin-geo/core.ts +495 -0
- package/_vendor/plugin-geo/feature.ts +20 -0
- package/_vendor/plugin-geo/index.ts +7 -0
- package/_vendor/plugin-geo/types.ts +27 -0
- package/_vendor/plugin-group/GroupShapeUtil.ts +59 -0
- package/_vendor/plugin-group/canvas.tsx +59 -0
- package/_vendor/plugin-group/core.ts +40 -0
- package/_vendor/plugin-group/feature.ts +20 -0
- package/_vendor/plugin-group/index.ts +5 -0
- package/_vendor/plugin-image/ImageShapeUtil.ts +95 -0
- package/_vendor/plugin-image/canvas.tsx +212 -0
- package/_vendor/plugin-image/core.ts +542 -0
- package/_vendor/plugin-image/crop.ts +770 -0
- package/_vendor/plugin-image/cropInteractions.ts +350 -0
- package/_vendor/plugin-image/cropSession.ts +38 -0
- package/_vendor/plugin-image/feature.ts +20 -0
- package/_vendor/plugin-image/index.ts +29 -0
- package/_vendor/plugin-image/types.ts +55 -0
- package/_vendor/plugin-image-product-react/ImageImportController.tsx +143 -0
- package/_vendor/plugin-image-product-react/imageAssetService.ts +52 -0
- package/_vendor/plugin-image-product-react/imageBlobStore.ts +315 -0
- package/_vendor/plugin-image-product-react/imageHostActions.ts +438 -0
- package/_vendor/plugin-image-product-react/imageProductApi.ts +88 -0
- package/_vendor/plugin-image-product-react/imageToolbarHostBridge.ts +48 -0
- package/_vendor/plugin-image-product-react/imageToolbarRuntime.ts +21 -0
- package/_vendor/plugin-image-product-react/index.ts +60 -0
- package/_vendor/plugin-image-product-react/snapshotGuards.ts +33 -0
- package/_vendor/plugin-image-product-react/svgImageAssetInliner.ts +54 -0
- package/_vendor/plugin-image-product-react/useImageImport.ts +64 -0
- package/_vendor/plugin-laser/LaserTool.ts +154 -0
- package/_vendor/plugin-laser/canvas.tsx +645 -0
- package/_vendor/plugin-laser/core.ts +49 -0
- package/_vendor/plugin-laser/feature.ts +20 -0
- package/_vendor/plugin-laser/index.ts +4 -0
- package/_vendor/plugin-text/ArrowLabelBindingUtil.ts +336 -0
- package/_vendor/plugin-text/GeoLabelBindingUtil.ts +391 -0
- package/_vendor/plugin-text/TextShapeSvgExporter.ts +101 -0
- package/_vendor/plugin-text/TextShapeUtil.ts +284 -0
- package/_vendor/plugin-text/TextTool.ts +228 -0
- package/_vendor/plugin-text/canvas.tsx +115 -0
- package/_vendor/plugin-text/core.ts +422 -0
- package/_vendor/plugin-text/feature.ts +20 -0
- package/_vendor/plugin-text/host/RichTextEditingBox.tsx +144 -0
- package/_vendor/plugin-text/host/RichTextToolbar.tsx +266 -0
- package/_vendor/plugin-text/host/TiptapTextEditor.tsx +191 -0
- package/_vendor/plugin-text/host/richTextRendering.tsx +49 -0
- package/_vendor/plugin-text/host/textDomSelection.ts +93 -0
- package/_vendor/plugin-text/host/textEditingBoxStyle.ts +36 -0
- package/_vendor/plugin-text/host/textEntryFocus.ts +307 -0
- package/_vendor/plugin-text/host/textFontLoader.ts +149 -0
- package/_vendor/plugin-text/host/textMeasurement.ts +258 -0
- package/_vendor/plugin-text/host/textMeasurementSync.ts +77 -0
- package/_vendor/plugin-text/host/textRangeSelection.ts +134 -0
- package/_vendor/plugin-text/host/textShapeRendererRuntime.tsx +89 -0
- package/_vendor/plugin-text/host/textShapeSync.ts +173 -0
- package/_vendor/plugin-text/host/tiptapTextEditorController.ts +148 -0
- package/_vendor/plugin-text/index.ts +18 -0
- package/_vendor/plugin-text/richTextUtils.ts +259 -0
- package/_vendor/plugin-text/textInteractions.ts +366 -0
- package/_vendor/plugin-text/textLabelHelpers.ts +235 -0
- package/_vendor/plugin-text/textShapeHelpers.ts +123 -0
- package/_vendor/plugin-text/textStyle.ts +96 -0
- package/_vendor/plugin-text/textTypes.ts +48 -0
- package/_vendor/signals/atom.ts +74 -0
- package/_vendor/signals/computed.ts +132 -0
- package/_vendor/signals/core.ts +130 -0
- package/_vendor/signals/effect.ts +117 -0
- package/_vendor/signals/index.ts +9 -0
- package/_vendor/signals/types.ts +17 -0
- package/_vendor/store/Store.ts +171 -0
- package/_vendor/store/diff.ts +229 -0
- package/_vendor/store/history.ts +177 -0
- package/_vendor/store/index.ts +32 -0
- package/_vendor/store/types.ts +37 -0
- package/api/canvasKitApi.d.ts +29 -0
- package/index.css +3 -0
- package/index.d.ts +16 -0
- package/index.mjs +1 -0
- package/internal-modules.d.ts +187 -0
- package/package.json +48 -0
- package/product/Shell.d.ts +19 -0
- package/product/chromeContext.d.ts +70 -0
- package/product/createCanvasKitEditor.d.ts +6 -0
- package/product/index.d.ts +7 -0
- package/product/persistence.d.ts +3 -0
- package/product/product.d.ts +22 -0
- package/product/useCanvasClipboardShortcuts.d.ts +6 -0
- package/product-iyBbEPIs.mjs +4 -0
- package/product.mjs +1 -0
- package/standard/extensions.d.ts +1 -0
- package/standard/index.d.ts +3 -0
- package/standard/standardApi.d.ts +91 -0
- package/standard-BmrxwqpJ.mjs +44 -0
- package/standard.mjs +1 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import type { JSONContent } from "@tiptap/core";
|
|
2
|
+
import type { RichTextDocument, RichTextJsonValue } from "./textTypes";
|
|
3
|
+
|
|
4
|
+
export type RichTextTextNode = JSONContent & { type: "text"; text: string };
|
|
5
|
+
|
|
6
|
+
export interface RichTextMarkStyle {
|
|
7
|
+
fontWeight?: number;
|
|
8
|
+
fontStyle?: "italic";
|
|
9
|
+
textDecorationLine?: "line-through";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function createRichTextFromPlainText(text: string): RichTextDocument {
|
|
13
|
+
const lines = text.split("\n");
|
|
14
|
+
return {
|
|
15
|
+
type: "doc",
|
|
16
|
+
content: lines.map((line) => ({
|
|
17
|
+
type: "paragraph",
|
|
18
|
+
content: line.length > 0 ? [{ type: "text", text: line }] : [],
|
|
19
|
+
})),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getPlainTextFromRichText(
|
|
24
|
+
richTextDocument: RichTextDocument,
|
|
25
|
+
): string {
|
|
26
|
+
return richTextDocument.content
|
|
27
|
+
.map((node) => getPlainTextFromNode(node))
|
|
28
|
+
.join("\n");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function validateRichTextDocument(value: unknown): RichTextDocument {
|
|
32
|
+
if (!value || typeof value !== "object") {
|
|
33
|
+
return createRichTextFromPlainText("");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const candidate = value as Partial<RichTextDocument>;
|
|
37
|
+
const content = Array.isArray(candidate.content)
|
|
38
|
+
? candidate.content
|
|
39
|
+
.map((node) => sanitizeElementNode(node, 0))
|
|
40
|
+
.filter((node): node is JSONContent => node !== null)
|
|
41
|
+
: [];
|
|
42
|
+
|
|
43
|
+
return { type: "doc", attrs: sanitizeAttrs(candidate.attrs), content };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function renderRichTextDocumentToHtml(
|
|
47
|
+
richText: RichTextDocument,
|
|
48
|
+
): string {
|
|
49
|
+
return richText.content
|
|
50
|
+
.map((node) => renderRichTextBlockToHtml(node))
|
|
51
|
+
.join("");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function isRichTextTextNode(
|
|
55
|
+
node: JSONContent,
|
|
56
|
+
): node is RichTextTextNode {
|
|
57
|
+
return node.type === "text" && typeof node.text === "string";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function getRichTextTextNodeStyle(
|
|
61
|
+
node: RichTextTextNode,
|
|
62
|
+
): string | undefined {
|
|
63
|
+
const style = getRichTextMarkStyle(node.marks);
|
|
64
|
+
return style ? renderRichTextMarkStyle(style) : undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function getRichTextMarkStyle(
|
|
68
|
+
marks: JSONContent["marks"],
|
|
69
|
+
): RichTextMarkStyle | undefined {
|
|
70
|
+
if (!marks || marks.length === 0) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const style: RichTextMarkStyle = {};
|
|
75
|
+
for (const mark of marks) {
|
|
76
|
+
switch (mark.type) {
|
|
77
|
+
case "bold":
|
|
78
|
+
case "strong":
|
|
79
|
+
style.fontWeight = 700;
|
|
80
|
+
break;
|
|
81
|
+
case "italic":
|
|
82
|
+
case "em":
|
|
83
|
+
style.fontStyle = "italic";
|
|
84
|
+
break;
|
|
85
|
+
case "strike":
|
|
86
|
+
case "s":
|
|
87
|
+
style.textDecorationLine = "line-through";
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return Object.keys(style).length > 0 ? style : undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function getPlainTextFromNode(node: JSONContent): string {
|
|
96
|
+
if (isRichTextTextNode(node)) {
|
|
97
|
+
return node.text;
|
|
98
|
+
}
|
|
99
|
+
return (
|
|
100
|
+
node.content?.map((child) => getPlainTextFromNode(child)).join("") ?? ""
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function renderRichTextMarkStyle(style: RichTextMarkStyle): string {
|
|
105
|
+
const declarations: string[] = [];
|
|
106
|
+
if (style.fontWeight !== undefined) {
|
|
107
|
+
declarations.push(`font-weight:${String(style.fontWeight)}`);
|
|
108
|
+
}
|
|
109
|
+
if (style.fontStyle !== undefined) {
|
|
110
|
+
declarations.push(`font-style:${style.fontStyle}`);
|
|
111
|
+
}
|
|
112
|
+
if (style.textDecorationLine !== undefined) {
|
|
113
|
+
declarations.push(`text-decoration-line:${style.textDecorationLine}`);
|
|
114
|
+
}
|
|
115
|
+
return declarations.join(";");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function renderRichTextBlockToHtml(node: JSONContent): string {
|
|
119
|
+
const children =
|
|
120
|
+
node.content?.map((child) => renderRichTextNodeToHtml(child)).join("") ?? "";
|
|
121
|
+
return `<p style="margin:0">${children.length > 0 ? children : "<br>"}</p>`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function renderRichTextNodeToHtml(node: JSONContent): string {
|
|
125
|
+
if (isRichTextTextNode(node)) {
|
|
126
|
+
const style = getRichTextMarkStyle(node.marks);
|
|
127
|
+
const text = escapeHtml(node.text);
|
|
128
|
+
if (!style) {
|
|
129
|
+
return text;
|
|
130
|
+
}
|
|
131
|
+
return `<span style="${renderRichTextMarkStyle(style)}">${text}</span>`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return node.content?.map((child) => renderRichTextNodeToHtml(child)).join("") ?? "";
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function escapeHtml(value: string): string {
|
|
138
|
+
return value
|
|
139
|
+
.replaceAll("&", "&")
|
|
140
|
+
.replaceAll("<", "<")
|
|
141
|
+
.replaceAll(">", ">");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function sanitizeNode(value: unknown, depth: number): JSONContent | null {
|
|
145
|
+
if (!value || typeof value !== "object" || depth > 8) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
const candidate = value as Record<string, unknown>;
|
|
149
|
+
if (candidate.type === "text") {
|
|
150
|
+
const text = sanitizeTextNode(candidate);
|
|
151
|
+
return text.text.length > 0 ? text : null;
|
|
152
|
+
}
|
|
153
|
+
return sanitizeElementNode(candidate, depth);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function sanitizeElementNode(
|
|
157
|
+
value: unknown,
|
|
158
|
+
depth: number,
|
|
159
|
+
): JSONContent | null {
|
|
160
|
+
if (!value || typeof value !== "object") {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
const candidate = value as Record<string, unknown>;
|
|
164
|
+
const type =
|
|
165
|
+
typeof candidate.type === "string" ? candidate.type : "paragraph";
|
|
166
|
+
const content = Array.isArray(candidate.content)
|
|
167
|
+
? candidate.content
|
|
168
|
+
.map((node) => sanitizeNode(node, depth + 1))
|
|
169
|
+
.filter((node): node is JSONContent => node !== null)
|
|
170
|
+
: [];
|
|
171
|
+
|
|
172
|
+
return { type, attrs: sanitizeAttrs(candidate.attrs), content };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function sanitizeTextNode(value: Record<string, unknown>): JSONContent & {
|
|
176
|
+
type: "text";
|
|
177
|
+
text: string;
|
|
178
|
+
} {
|
|
179
|
+
return {
|
|
180
|
+
type: "text",
|
|
181
|
+
text: typeof value.text === "string" ? value.text : "",
|
|
182
|
+
marks: Array.isArray(value.marks)
|
|
183
|
+
? value.marks
|
|
184
|
+
.map(sanitizeMark)
|
|
185
|
+
.filter((mark): mark is NonNullable<JSONContent["marks"]>[number] =>
|
|
186
|
+
mark !== null,
|
|
187
|
+
)
|
|
188
|
+
: undefined,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function sanitizeMark(
|
|
193
|
+
value: unknown,
|
|
194
|
+
): NonNullable<JSONContent["marks"]>[number] | null {
|
|
195
|
+
if (!value || typeof value !== "object") {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
const candidate = value as Record<string, unknown>;
|
|
199
|
+
if (typeof candidate.type !== "string") {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
return { type: candidate.type, attrs: sanitizeAttrs(candidate.attrs) };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function sanitizeAttrs(
|
|
206
|
+
attrs: unknown,
|
|
207
|
+
): Record<string, RichTextJsonValue> | undefined {
|
|
208
|
+
if (!attrs || typeof attrs !== "object") {
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
const entries = Object.entries(attrs)
|
|
212
|
+
.map(
|
|
213
|
+
([key, value]) => [key, sanitizeRichTextAttributeValue(value)] as const,
|
|
214
|
+
)
|
|
215
|
+
.filter(
|
|
216
|
+
(entry): entry is readonly [string, RichTextJsonValue] =>
|
|
217
|
+
entry[1] !== undefined,
|
|
218
|
+
);
|
|
219
|
+
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function sanitizeRichTextAttributeValue(
|
|
223
|
+
value: unknown,
|
|
224
|
+
depth = 0,
|
|
225
|
+
): RichTextJsonValue | undefined {
|
|
226
|
+
if (
|
|
227
|
+
value === null ||
|
|
228
|
+
typeof value === "string" ||
|
|
229
|
+
typeof value === "number" ||
|
|
230
|
+
typeof value === "boolean"
|
|
231
|
+
) {
|
|
232
|
+
return value;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (depth > 8) {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (Array.isArray(value)) {
|
|
240
|
+
return value
|
|
241
|
+
.map((item) => sanitizeRichTextAttributeValue(item, depth + 1))
|
|
242
|
+
.filter((item): item is RichTextJsonValue => item !== undefined);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (value && typeof value === "object") {
|
|
246
|
+
const entries = Object.entries(value)
|
|
247
|
+
.map(
|
|
248
|
+
([key, item]) =>
|
|
249
|
+
[key, sanitizeRichTextAttributeValue(item, depth + 1)] as const,
|
|
250
|
+
)
|
|
251
|
+
.filter(
|
|
252
|
+
(entry): entry is readonly [string, RichTextJsonValue] =>
|
|
253
|
+
entry[1] !== undefined,
|
|
254
|
+
);
|
|
255
|
+
return Object.fromEntries(entries);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ClickEditorEvent,
|
|
3
|
+
type Editor,
|
|
4
|
+
type ShapeRecord,
|
|
5
|
+
type LandInteractionHandler,
|
|
6
|
+
type PointerEditorEvent,
|
|
7
|
+
} from "@land/canvas-core";
|
|
8
|
+
import type { TextShapeRecord } from "./textTypes";
|
|
9
|
+
import { getDefaultTextShapeProps, isTextShapeRecord } from "./textShapeHelpers";
|
|
10
|
+
import {
|
|
11
|
+
ARROW_LABEL_INDEX_SUFFIX,
|
|
12
|
+
getArrowLabelLayout,
|
|
13
|
+
} from "./ArrowLabelBindingUtil";
|
|
14
|
+
import {
|
|
15
|
+
GEO_LABEL_INDEX_SUFFIX,
|
|
16
|
+
getGeoLabelLayout,
|
|
17
|
+
} from "./GeoLabelBindingUtil";
|
|
18
|
+
import {
|
|
19
|
+
ARROW_LABEL_BINDING_TYPE,
|
|
20
|
+
GEO_LABEL_BINDING_TYPE,
|
|
21
|
+
canPlaceCaretInTextShapeFromSelection,
|
|
22
|
+
createBoundTextLabelShape,
|
|
23
|
+
getTextLabelShapeForOwner,
|
|
24
|
+
startEditingTextLabel,
|
|
25
|
+
} from "./textLabelHelpers";
|
|
26
|
+
|
|
27
|
+
const TEXT_EDIT_HISTORY_MARK = "text.edit";
|
|
28
|
+
const ARROW_LABEL_EDIT_HISTORY_MARK = "arrow-label.edit";
|
|
29
|
+
const ARROW_LABEL_CREATE_HISTORY_MARK = "arrow-label.create";
|
|
30
|
+
const GEO_LABEL_EDIT_HISTORY_MARK = "geo-label.edit";
|
|
31
|
+
const GEO_LABEL_CREATE_HISTORY_MARK = "geo-label.create";
|
|
32
|
+
const TEXT_CARET_CLICK_MAX_DISTANCE_SQUARED = 9;
|
|
33
|
+
|
|
34
|
+
export function createTextInteractionHandler(): LandInteractionHandler {
|
|
35
|
+
let pendingCaretPointer: {
|
|
36
|
+
pointerId: number;
|
|
37
|
+
shapeId: TextShapeRecord["id"];
|
|
38
|
+
originPagePoint: { x: number; y: number };
|
|
39
|
+
} | null = null;
|
|
40
|
+
|
|
41
|
+
const clearPendingCaretPointer = (): void => {
|
|
42
|
+
pendingCaretPointer = null;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
id: "land.text.interactions",
|
|
47
|
+
editorEvent: {
|
|
48
|
+
handleEvent(editor, event) {
|
|
49
|
+
if (editor.getActiveToolId() !== "select") {
|
|
50
|
+
return "continue";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (event.type === "pointer" && event.name === "pointer_up") {
|
|
54
|
+
return handleTextPointerUp(editor, event, pendingCaretPointer, () => {
|
|
55
|
+
pendingCaretPointer = null;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (event.type === "pointer" && event.name === "pointer_cancel") {
|
|
60
|
+
clearPendingCaretPointer();
|
|
61
|
+
return "continue";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!editor.isActiveToolInInitialState()) {
|
|
65
|
+
return "continue";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (event.type === "keyboard" && event.name === "key_down") {
|
|
69
|
+
if (editor.getShapeEditingSession()) {
|
|
70
|
+
return "continue";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (event.key !== "Enter" || event.altKey || event.accelKey) {
|
|
74
|
+
return "continue";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const selectedShapeIds = editor.getSelectedShapeIds();
|
|
78
|
+
const [selectedShape] = editor.getSelectedShapes();
|
|
79
|
+
if (
|
|
80
|
+
selectedShapeIds.length !== 1 ||
|
|
81
|
+
!selectedShape ||
|
|
82
|
+
!isTextShapeRecord(selectedShape) ||
|
|
83
|
+
!editor.canEditShape(selectedShape)
|
|
84
|
+
) {
|
|
85
|
+
return "continue";
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
editor.startEditingShape(
|
|
89
|
+
{
|
|
90
|
+
shapeId: selectedShape.id,
|
|
91
|
+
entryMode: "selectAll",
|
|
92
|
+
markId: TEXT_EDIT_HISTORY_MARK,
|
|
93
|
+
},
|
|
94
|
+
"user",
|
|
95
|
+
);
|
|
96
|
+
return "handled";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (event.type === "click" && event.name === "double_click") {
|
|
100
|
+
clearPendingCaretPointer();
|
|
101
|
+
return handleTextDoubleClick(editor, event);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (event.type === "pointer" && event.name === "pointer_down") {
|
|
105
|
+
clearPendingCaretPointer();
|
|
106
|
+
return handleTextPointerDown(editor, event, (pending) => {
|
|
107
|
+
pendingCaretPointer = pending;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return "continue";
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function handleTextDoubleClick(
|
|
118
|
+
editor: Editor,
|
|
119
|
+
event: ClickEditorEvent,
|
|
120
|
+
): "continue" | "handled" {
|
|
121
|
+
const hit = editor.hitTestShape(event.pagePoint);
|
|
122
|
+
if (!hit) {
|
|
123
|
+
return "continue";
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (isTextShapeRecord(hit)) {
|
|
127
|
+
if (!editor.canEditShape(hit)) {
|
|
128
|
+
return "continue";
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
editor.startEditingShape(
|
|
132
|
+
{
|
|
133
|
+
shapeId: hit.id,
|
|
134
|
+
entryMode: "selectAll",
|
|
135
|
+
markId: TEXT_EDIT_HISTORY_MARK,
|
|
136
|
+
},
|
|
137
|
+
"user",
|
|
138
|
+
);
|
|
139
|
+
return "handled";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (isGeoShapeRecord(hit)) {
|
|
143
|
+
return handleGeoLabelDoubleClick(editor, hit);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (isArrowShapeRecord(hit)) {
|
|
147
|
+
return handleArrowLabelDoubleClick(editor, hit);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return "continue";
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function handleArrowLabelDoubleClick(
|
|
154
|
+
editor: Editor,
|
|
155
|
+
owner: ShapeRecord,
|
|
156
|
+
): "continue" | "handled" {
|
|
157
|
+
if (owner.isLocked) {
|
|
158
|
+
return "continue";
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const existing = getTextLabelShapeForOwner(
|
|
162
|
+
editor,
|
|
163
|
+
owner.id,
|
|
164
|
+
ARROW_LABEL_BINDING_TYPE,
|
|
165
|
+
);
|
|
166
|
+
const label = existing ?? createArrowLabelTextShape(editor, owner);
|
|
167
|
+
startEditingTextLabel(editor, label, {
|
|
168
|
+
editMarkId: ARROW_LABEL_EDIT_HISTORY_MARK,
|
|
169
|
+
createMarkId: ARROW_LABEL_CREATE_HISTORY_MARK,
|
|
170
|
+
isExisting: !!existing,
|
|
171
|
+
});
|
|
172
|
+
return "handled";
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function handleGeoLabelDoubleClick(
|
|
176
|
+
editor: Editor,
|
|
177
|
+
owner: ShapeRecord,
|
|
178
|
+
): "continue" | "handled" {
|
|
179
|
+
if (owner.isLocked) {
|
|
180
|
+
return "continue";
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const existing = getTextLabelShapeForOwner(
|
|
184
|
+
editor,
|
|
185
|
+
owner.id,
|
|
186
|
+
GEO_LABEL_BINDING_TYPE,
|
|
187
|
+
);
|
|
188
|
+
const label = existing ?? createGeoLabelTextShape(editor, owner);
|
|
189
|
+
startEditingTextLabel(editor, label, {
|
|
190
|
+
editMarkId: GEO_LABEL_EDIT_HISTORY_MARK,
|
|
191
|
+
createMarkId: GEO_LABEL_CREATE_HISTORY_MARK,
|
|
192
|
+
isExisting: !!existing,
|
|
193
|
+
});
|
|
194
|
+
return "handled";
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function handleTextPointerDown(
|
|
198
|
+
editor: Editor,
|
|
199
|
+
event: PointerEditorEvent,
|
|
200
|
+
setPendingCaretPointer: (pending: {
|
|
201
|
+
pointerId: number;
|
|
202
|
+
shapeId: TextShapeRecord["id"];
|
|
203
|
+
originPagePoint: { x: number; y: number };
|
|
204
|
+
}) => void,
|
|
205
|
+
): "continue" | "handled" {
|
|
206
|
+
const hit = editor.hitTestShape(event.pagePoint);
|
|
207
|
+
if (!hit || !isTextShapeRecord(hit) || !editor.canEditShape(hit)) {
|
|
208
|
+
return "continue";
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const activeEditingSession = editor.getShapeEditingSession();
|
|
212
|
+
if (activeEditingSession && activeEditingSession.shapeId !== hit.id) {
|
|
213
|
+
if (!editor.completeEditing("user")) {
|
|
214
|
+
return "handled";
|
|
215
|
+
}
|
|
216
|
+
editor.startEditingShape(
|
|
217
|
+
{
|
|
218
|
+
shapeId: hit.id,
|
|
219
|
+
entryMode: "placeCaret",
|
|
220
|
+
caretPagePoint: event.pagePoint,
|
|
221
|
+
markId: TEXT_EDIT_HISTORY_MARK,
|
|
222
|
+
preserveInteraction: true,
|
|
223
|
+
},
|
|
224
|
+
"user",
|
|
225
|
+
);
|
|
226
|
+
return "handled";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (
|
|
230
|
+
!activeEditingSession &&
|
|
231
|
+
(event.clickCount ?? 1) < 2 &&
|
|
232
|
+
canPlaceCaretInTextShapeFromSelection(editor, hit.id)
|
|
233
|
+
) {
|
|
234
|
+
setPendingCaretPointer({
|
|
235
|
+
pointerId: event.pointerId,
|
|
236
|
+
shapeId: hit.id,
|
|
237
|
+
originPagePoint: { x: event.pagePoint.x, y: event.pagePoint.y },
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return "continue";
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function isGeoShapeRecord(shape: ShapeRecord): boolean {
|
|
245
|
+
return shape.type === "geo";
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function isArrowShapeRecord(shape: ShapeRecord): boolean {
|
|
249
|
+
return shape.type === "arrow";
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function createArrowLabelTextShape(
|
|
253
|
+
editor: Editor,
|
|
254
|
+
owner: ShapeRecord,
|
|
255
|
+
): TextShapeRecord {
|
|
256
|
+
const defaults = getDefaultTextShapeProps(editor);
|
|
257
|
+
const draftLabel = createDraftLabel(owner, {
|
|
258
|
+
...defaults,
|
|
259
|
+
autoSize: false,
|
|
260
|
+
textAlign: "middle",
|
|
261
|
+
});
|
|
262
|
+
const layout = getArrowLabelLayout(editor, draftLabel, owner);
|
|
263
|
+
|
|
264
|
+
return createBoundTextLabelShape(editor, {
|
|
265
|
+
bindingType: ARROW_LABEL_BINDING_TYPE,
|
|
266
|
+
owner,
|
|
267
|
+
historyMarkId: ARROW_LABEL_CREATE_HISTORY_MARK,
|
|
268
|
+
index: `${owner.index}${ARROW_LABEL_INDEX_SUFFIX}`,
|
|
269
|
+
layout,
|
|
270
|
+
bindingProps: {
|
|
271
|
+
labelPosition: 0.5,
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function createGeoLabelTextShape(
|
|
277
|
+
editor: Editor,
|
|
278
|
+
owner: ShapeRecord,
|
|
279
|
+
): TextShapeRecord {
|
|
280
|
+
const defaults = getDefaultTextShapeProps(editor);
|
|
281
|
+
const draftLabel = createDraftLabel(owner, {
|
|
282
|
+
...defaults,
|
|
283
|
+
autoSize: false,
|
|
284
|
+
textAlign: "middle",
|
|
285
|
+
});
|
|
286
|
+
const layout = getGeoLabelLayout(editor, draftLabel, owner);
|
|
287
|
+
|
|
288
|
+
return createBoundTextLabelShape(editor, {
|
|
289
|
+
bindingType: GEO_LABEL_BINDING_TYPE,
|
|
290
|
+
owner,
|
|
291
|
+
historyMarkId: GEO_LABEL_CREATE_HISTORY_MARK,
|
|
292
|
+
index: `${owner.index}${GEO_LABEL_INDEX_SUFFIX}`,
|
|
293
|
+
layout,
|
|
294
|
+
bindingProps: {
|
|
295
|
+
normalizedAnchor: { x: 0.5, y: 0.5 },
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function createDraftLabel(
|
|
301
|
+
owner: ShapeRecord,
|
|
302
|
+
props: TextShapeRecord["props"],
|
|
303
|
+
): TextShapeRecord {
|
|
304
|
+
return {
|
|
305
|
+
id: "shape:draft",
|
|
306
|
+
typeName: "shape",
|
|
307
|
+
scope: "document",
|
|
308
|
+
type: "text",
|
|
309
|
+
parentId: owner.parentId,
|
|
310
|
+
index: `${owner.index}.label`,
|
|
311
|
+
x: 0,
|
|
312
|
+
y: 0,
|
|
313
|
+
rotation: 0,
|
|
314
|
+
scaleX: 1,
|
|
315
|
+
scaleY: 1,
|
|
316
|
+
opacity: 1,
|
|
317
|
+
isHidden: false,
|
|
318
|
+
isLocked: false,
|
|
319
|
+
meta: {},
|
|
320
|
+
props,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function handleTextPointerUp(
|
|
325
|
+
editor: Editor,
|
|
326
|
+
event: PointerEditorEvent,
|
|
327
|
+
pendingCaretPointer: {
|
|
328
|
+
pointerId: number;
|
|
329
|
+
shapeId: TextShapeRecord["id"];
|
|
330
|
+
originPagePoint: { x: number; y: number };
|
|
331
|
+
} | null,
|
|
332
|
+
clearPendingCaretPointer: () => void,
|
|
333
|
+
): "continue" | "handled" {
|
|
334
|
+
if (!pendingCaretPointer || pendingCaretPointer.pointerId !== event.pointerId) {
|
|
335
|
+
clearPendingCaretPointer();
|
|
336
|
+
return "continue";
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
clearPendingCaretPointer();
|
|
340
|
+
if ((event.clickCount ?? 1) >= 2) {
|
|
341
|
+
return "continue";
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const dx = event.pagePoint.x - pendingCaretPointer.originPagePoint.x;
|
|
345
|
+
const dy = event.pagePoint.y - pendingCaretPointer.originPagePoint.y;
|
|
346
|
+
if (dx * dx + dy * dy > TEXT_CARET_CLICK_MAX_DISTANCE_SQUARED) {
|
|
347
|
+
return "continue";
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const shape = editor.getShape(pendingCaretPointer.shapeId);
|
|
351
|
+
if (!shape || !isTextShapeRecord(shape) || !editor.canEditShape(shape)) {
|
|
352
|
+
return "continue";
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
editor.startEditingShape(
|
|
356
|
+
{
|
|
357
|
+
shapeId: shape.id,
|
|
358
|
+
entryMode: "placeCaret",
|
|
359
|
+
caretPagePoint: event.pagePoint,
|
|
360
|
+
markId: TEXT_EDIT_HISTORY_MARK,
|
|
361
|
+
preserveInteraction: true,
|
|
362
|
+
},
|
|
363
|
+
"user",
|
|
364
|
+
);
|
|
365
|
+
return "continue";
|
|
366
|
+
}
|