@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,115 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import type { TextShapeRecord } from "./textTypes";
|
|
3
|
+
import {
|
|
4
|
+
renderRichTextDocument,
|
|
5
|
+
} from "./host/richTextRendering";
|
|
6
|
+
import { ensureTextFontLoaded } from "./host/textFontLoader";
|
|
7
|
+
import { useTextShapeRendererRuntime } from "./host/textShapeRendererRuntime";
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_TEXT_FONT,
|
|
10
|
+
getTextAlign,
|
|
11
|
+
getTextFontFamily,
|
|
12
|
+
getTextFontSize,
|
|
13
|
+
getTextLineHeight,
|
|
14
|
+
} from "./textStyle";
|
|
15
|
+
import type {
|
|
16
|
+
CanvasDomEventGuard,
|
|
17
|
+
LandCanvasPlugin,
|
|
18
|
+
ShapeRendererProps,
|
|
19
|
+
} from "@land/canvas-plugin-api";
|
|
20
|
+
|
|
21
|
+
const textEditingDomEventGuard: CanvasDomEventGuard = {
|
|
22
|
+
id: "land.text.dom-events",
|
|
23
|
+
handle({ event }) {
|
|
24
|
+
const target = event.target;
|
|
25
|
+
if (!(target instanceof HTMLElement)) {
|
|
26
|
+
return "continue";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return target.closest('[data-ui="text-editing-box"]') ? "handled" : "continue";
|
|
30
|
+
},
|
|
31
|
+
getCursor({ element }) {
|
|
32
|
+
return element?.closest('[data-ui="text-editing-box"]') ? "text" : undefined;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function createTextCanvasPlugin(): LandCanvasPlugin {
|
|
37
|
+
return {
|
|
38
|
+
id: "land.text.react",
|
|
39
|
+
domEventGuards: [textEditingDomEventGuard],
|
|
40
|
+
canvasComponents: [
|
|
41
|
+
{
|
|
42
|
+
id: "land.text.default-font-preload",
|
|
43
|
+
component: TextDefaultFontPreload,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
setup(registerShapeRenderer) {
|
|
47
|
+
registerShapeRenderer({
|
|
48
|
+
type: "text",
|
|
49
|
+
component: TextShapeRenderer,
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function TextDefaultFontPreload() {
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
void ensureTextFontLoaded(DEFAULT_TEXT_FONT);
|
|
58
|
+
}, []);
|
|
59
|
+
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function TextShapeRenderer({
|
|
64
|
+
shape,
|
|
65
|
+
editor,
|
|
66
|
+
}: ShapeRendererProps<TextShapeRecord>) {
|
|
67
|
+
const { isEditingThisShape, editingHost } = useTextShapeRendererRuntime(
|
|
68
|
+
editor,
|
|
69
|
+
shape,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<div
|
|
74
|
+
data-editing-hidden={isEditingThisShape ? "true" : undefined}
|
|
75
|
+
style={{
|
|
76
|
+
position: "relative",
|
|
77
|
+
boxSizing: "border-box",
|
|
78
|
+
width: shape.props.w,
|
|
79
|
+
minHeight: shape.props.h,
|
|
80
|
+
transform: `scale(${shape.props.scale})`,
|
|
81
|
+
transformOrigin: "top left",
|
|
82
|
+
color: shape.props.color,
|
|
83
|
+
fontFamily: getTextFontFamily(shape.props.font),
|
|
84
|
+
fontSize: getTextFontSize(shape.props.size),
|
|
85
|
+
lineHeight: `${getTextLineHeight(shape.props.size)}px`,
|
|
86
|
+
textAlign: getTextAlign(shape.props.textAlign),
|
|
87
|
+
whiteSpace: "pre-wrap",
|
|
88
|
+
overflowWrap: "break-word",
|
|
89
|
+
userSelect: "none",
|
|
90
|
+
pointerEvents: "none",
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
<div
|
|
94
|
+
style={{
|
|
95
|
+
opacity: isEditingThisShape ? 0 : undefined,
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
{renderRichTextDocument(shape.props.richText)}
|
|
99
|
+
</div>
|
|
100
|
+
<div
|
|
101
|
+
data-ui="text-editor-host-slot"
|
|
102
|
+
data-shape-id={shape.id}
|
|
103
|
+
data-active={isEditingThisShape ? "true" : "false"}
|
|
104
|
+
aria-hidden="true"
|
|
105
|
+
style={{
|
|
106
|
+
position: "absolute",
|
|
107
|
+
inset: 0,
|
|
108
|
+
pointerEvents: "none",
|
|
109
|
+
}}
|
|
110
|
+
>
|
|
111
|
+
{editingHost}
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SET_ACTIVE_TOOL_TOOLBAR_ACTION_ID,
|
|
3
|
+
type ContextMenuContribution,
|
|
4
|
+
type LandCorePlugin,
|
|
5
|
+
type ToolbarAction,
|
|
6
|
+
type ToolbarActionValue,
|
|
7
|
+
type ToolbarContribution,
|
|
8
|
+
} from "@land/canvas-core";
|
|
9
|
+
import { TextTool } from "./TextTool";
|
|
10
|
+
import { TextShapeUtil } from "./TextShapeUtil";
|
|
11
|
+
import { TextShapeSvgExporter } from "./TextShapeSvgExporter";
|
|
12
|
+
import { ArrowLabelBindingUtil } from "./ArrowLabelBindingUtil";
|
|
13
|
+
import { GeoLabelBindingUtil } from "./GeoLabelBindingUtil";
|
|
14
|
+
import { createTextInteractionHandler } from "./textInteractions";
|
|
15
|
+
import type {
|
|
16
|
+
TextShapeAlign,
|
|
17
|
+
TextShapeFont,
|
|
18
|
+
TextShapeProps,
|
|
19
|
+
TextShapeRecord,
|
|
20
|
+
TextShapeSize,
|
|
21
|
+
} from "./textTypes";
|
|
22
|
+
|
|
23
|
+
export function createTextCorePlugin(): LandCorePlugin {
|
|
24
|
+
return {
|
|
25
|
+
id: "land.text",
|
|
26
|
+
shapeCapabilities: [
|
|
27
|
+
{
|
|
28
|
+
type: "text",
|
|
29
|
+
schemaProps: [
|
|
30
|
+
"richText",
|
|
31
|
+
"w",
|
|
32
|
+
"h",
|
|
33
|
+
"autoSize",
|
|
34
|
+
"scale",
|
|
35
|
+
"font",
|
|
36
|
+
"size",
|
|
37
|
+
"color",
|
|
38
|
+
"textAlign",
|
|
39
|
+
],
|
|
40
|
+
reactRenderer: "partial",
|
|
41
|
+
toolbarEntry: "supported",
|
|
42
|
+
notes: [
|
|
43
|
+
"Text shape util, SVG fallback, React renderer, rich editing runtime, creation tool, and selected-text style toolbar live in the text plugin package. React rendering remains partial while product-grade rich text rendering and measurement continue to mature.",
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
shapeUtils: [new TextShapeUtil()],
|
|
48
|
+
shapeSvgExporters: [new TextShapeSvgExporter()],
|
|
49
|
+
bindingUtils: [new GeoLabelBindingUtil(), new ArrowLabelBindingUtil()],
|
|
50
|
+
interactionHandlers: [createTextInteractionHandler()],
|
|
51
|
+
toolbarActions: [
|
|
52
|
+
createEditTextAction(),
|
|
53
|
+
createSetTextStyleToolbarAction("color"),
|
|
54
|
+
createSetTextStyleToolbarAction("font"),
|
|
55
|
+
createSetTextStyleToolbarAction("size"),
|
|
56
|
+
createSetTextStyleToolbarAction("textAlign"),
|
|
57
|
+
createSetTextDefaultStyleToolbarAction("color"),
|
|
58
|
+
createSetTextDefaultStyleToolbarAction("font"),
|
|
59
|
+
createSetTextDefaultStyleToolbarAction("size"),
|
|
60
|
+
createSetTextDefaultStyleToolbarAction("textAlign"),
|
|
61
|
+
],
|
|
62
|
+
toolbarContributions: [
|
|
63
|
+
createTextToolToolbarContribution(),
|
|
64
|
+
createTextDefaultStyleToolbarContribution(),
|
|
65
|
+
createTextSelectionToolbarContribution(),
|
|
66
|
+
],
|
|
67
|
+
contextMenuContributions: [createTextContextMenuContribution()],
|
|
68
|
+
setup(editor) {
|
|
69
|
+
editor.tools.register(
|
|
70
|
+
"text",
|
|
71
|
+
(currentEditor) => new TextTool(currentEditor),
|
|
72
|
+
{ shortcut: "t" },
|
|
73
|
+
);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function createTextContextMenuContribution(): ContextMenuContribution {
|
|
79
|
+
return {
|
|
80
|
+
id: "text.shape-context-menu",
|
|
81
|
+
target: "selection",
|
|
82
|
+
order: 35,
|
|
83
|
+
actionIds: ["text.edit"],
|
|
84
|
+
when(context) {
|
|
85
|
+
return (
|
|
86
|
+
context.selection.count === 1 &&
|
|
87
|
+
context.selection.singleShapeType === "text"
|
|
88
|
+
);
|
|
89
|
+
},
|
|
90
|
+
getSections() {
|
|
91
|
+
return [
|
|
92
|
+
{
|
|
93
|
+
id: "text.context-menu",
|
|
94
|
+
title: "Text",
|
|
95
|
+
items: [
|
|
96
|
+
{
|
|
97
|
+
kind: "command",
|
|
98
|
+
id: "text.edit",
|
|
99
|
+
actionId: "text.edit",
|
|
100
|
+
label: "Edit text",
|
|
101
|
+
icon: "type",
|
|
102
|
+
dataUi: "context-menu-edit-text-button",
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function createEditTextAction(): ToolbarAction {
|
|
112
|
+
return {
|
|
113
|
+
id: "text.edit",
|
|
114
|
+
isVisible(context) {
|
|
115
|
+
return (
|
|
116
|
+
context.selection.count === 1 &&
|
|
117
|
+
context.selection.singleShapeType === "text"
|
|
118
|
+
);
|
|
119
|
+
},
|
|
120
|
+
isEnabled(context) {
|
|
121
|
+
const [shape] = context.selection.selectedShapes;
|
|
122
|
+
return shape?.type === "text" && !shape.isLocked;
|
|
123
|
+
},
|
|
124
|
+
run({ context }) {
|
|
125
|
+
const [shape] = context.selection.selectedShapes;
|
|
126
|
+
if (shape?.type !== "text" || shape.isLocked) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
context.editor.startEditingShape(
|
|
130
|
+
{
|
|
131
|
+
shapeId: shape.id,
|
|
132
|
+
entryMode: "focusEnd",
|
|
133
|
+
},
|
|
134
|
+
"user",
|
|
135
|
+
);
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const TEXT_COLOR_SWATCHES = [
|
|
141
|
+
{ value: "#0f172a", label: "Slate", color: "#0f172a" },
|
|
142
|
+
{ value: "#1d4ed8", label: "Blue", color: "#1d4ed8" },
|
|
143
|
+
{ value: "#15803d", label: "Green", color: "#15803d" },
|
|
144
|
+
{ value: "#dc2626", label: "Red", color: "#dc2626" },
|
|
145
|
+
] as const;
|
|
146
|
+
|
|
147
|
+
const TEXT_FONT_OPTIONS = [
|
|
148
|
+
{ value: "noto-sans-sc", label: "Noto SC" },
|
|
149
|
+
{ value: "noto-serif-sc", label: "Serif SC" },
|
|
150
|
+
{ value: "noto-sans-mono", label: "Mono" },
|
|
151
|
+
{ value: "ma-shan-zheng", label: "Ma Shan" },
|
|
152
|
+
] as const satisfies readonly {
|
|
153
|
+
value: TextShapeFont;
|
|
154
|
+
label: string;
|
|
155
|
+
}[];
|
|
156
|
+
|
|
157
|
+
const TEXT_SIZE_OPTIONS = [
|
|
158
|
+
{ value: "s", label: "S" },
|
|
159
|
+
{ value: "m", label: "M" },
|
|
160
|
+
{ value: "l", label: "L" },
|
|
161
|
+
{ value: "xl", label: "XL" },
|
|
162
|
+
] as const satisfies readonly { value: TextShapeSize; label: string }[];
|
|
163
|
+
|
|
164
|
+
const TEXT_ALIGN_OPTIONS = [
|
|
165
|
+
{ value: "start", label: "Align left", icon: "align-left" },
|
|
166
|
+
{ value: "middle", label: "Align center", icon: "align-center" },
|
|
167
|
+
{ value: "end", label: "Align right", icon: "align-right" },
|
|
168
|
+
] as const satisfies readonly {
|
|
169
|
+
value: TextShapeAlign;
|
|
170
|
+
label: string;
|
|
171
|
+
icon: string;
|
|
172
|
+
}[];
|
|
173
|
+
|
|
174
|
+
function createTextToolToolbarContribution(): ToolbarContribution {
|
|
175
|
+
return {
|
|
176
|
+
id: "text.tool-toolbar",
|
|
177
|
+
surface: "tool",
|
|
178
|
+
placement: "chrome",
|
|
179
|
+
order: 50,
|
|
180
|
+
actionIds: [SET_ACTIVE_TOOL_TOOLBAR_ACTION_ID],
|
|
181
|
+
getGroups() {
|
|
182
|
+
return [
|
|
183
|
+
{
|
|
184
|
+
id: "text.tools",
|
|
185
|
+
items: [
|
|
186
|
+
{
|
|
187
|
+
kind: "button",
|
|
188
|
+
id: "text.tool.text",
|
|
189
|
+
actionId: SET_ACTIVE_TOOL_TOOLBAR_ACTION_ID,
|
|
190
|
+
value: "text",
|
|
191
|
+
label: "Text",
|
|
192
|
+
shortcut: "T",
|
|
193
|
+
icon: "type",
|
|
194
|
+
dataUi: "text-tool-button",
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
},
|
|
198
|
+
];
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function createTextSelectionToolbarContribution(): ToolbarContribution {
|
|
204
|
+
return {
|
|
205
|
+
id: "text.selection-toolbar",
|
|
206
|
+
surface: "selection",
|
|
207
|
+
order: 20,
|
|
208
|
+
actionIds: [
|
|
209
|
+
"text.set-color",
|
|
210
|
+
"text.set-font",
|
|
211
|
+
"text.set-size",
|
|
212
|
+
"text.set-textAlign",
|
|
213
|
+
],
|
|
214
|
+
when(context) {
|
|
215
|
+
return context.selection.commonShapeType === "text";
|
|
216
|
+
},
|
|
217
|
+
getGroups() {
|
|
218
|
+
return getTextStyleToolbarGroups({
|
|
219
|
+
colorActionId: "text.set-color",
|
|
220
|
+
fontActionId: "text.set-font",
|
|
221
|
+
sizeActionId: "text.set-size",
|
|
222
|
+
textAlignActionId: "text.set-textAlign",
|
|
223
|
+
dataUiPrefix: "text",
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function createTextDefaultStyleToolbarContribution(): ToolbarContribution {
|
|
230
|
+
return {
|
|
231
|
+
id: "text.default-style.tool-toolbar",
|
|
232
|
+
surface: "tool",
|
|
233
|
+
order: 51,
|
|
234
|
+
actionIds: [
|
|
235
|
+
"text.default-color",
|
|
236
|
+
"text.default-font",
|
|
237
|
+
"text.default-size",
|
|
238
|
+
"text.default-textAlign",
|
|
239
|
+
],
|
|
240
|
+
when(context) {
|
|
241
|
+
return context.tool.activeToolId === "text";
|
|
242
|
+
},
|
|
243
|
+
getGroups() {
|
|
244
|
+
return getTextStyleToolbarGroups({
|
|
245
|
+
colorActionId: "text.default-color",
|
|
246
|
+
fontActionId: "text.default-font",
|
|
247
|
+
sizeActionId: "text.default-size",
|
|
248
|
+
textAlignActionId: "text.default-textAlign",
|
|
249
|
+
dataUiPrefix: "text-default",
|
|
250
|
+
});
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function getTextStyleToolbarGroups({
|
|
256
|
+
colorActionId,
|
|
257
|
+
fontActionId,
|
|
258
|
+
sizeActionId,
|
|
259
|
+
textAlignActionId,
|
|
260
|
+
dataUiPrefix,
|
|
261
|
+
}: {
|
|
262
|
+
colorActionId: string;
|
|
263
|
+
fontActionId: string;
|
|
264
|
+
sizeActionId: string;
|
|
265
|
+
textAlignActionId: string;
|
|
266
|
+
dataUiPrefix: string;
|
|
267
|
+
}) {
|
|
268
|
+
return [
|
|
269
|
+
{
|
|
270
|
+
id: `${dataUiPrefix}.style-color`,
|
|
271
|
+
items: [
|
|
272
|
+
{
|
|
273
|
+
kind: "swatches" as const,
|
|
274
|
+
id: `${dataUiPrefix}.color`,
|
|
275
|
+
actionId: colorActionId,
|
|
276
|
+
label: "Color",
|
|
277
|
+
options: TEXT_COLOR_SWATCHES.map((option) => ({
|
|
278
|
+
...option,
|
|
279
|
+
dataUi: `${dataUiPrefix}-color-${option.label.toLowerCase()}-button`,
|
|
280
|
+
})),
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
id: `${dataUiPrefix}.style-font`,
|
|
286
|
+
items: [
|
|
287
|
+
{
|
|
288
|
+
kind: "segmented" as const,
|
|
289
|
+
id: `${dataUiPrefix}.font`,
|
|
290
|
+
actionId: fontActionId,
|
|
291
|
+
options: TEXT_FONT_OPTIONS.map((option) => ({
|
|
292
|
+
...option,
|
|
293
|
+
dataUi: `${dataUiPrefix}-font-${option.value}-button`,
|
|
294
|
+
})),
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
id: `${dataUiPrefix}.style-size`,
|
|
300
|
+
items: [
|
|
301
|
+
{
|
|
302
|
+
kind: "segmented" as const,
|
|
303
|
+
id: `${dataUiPrefix}.size`,
|
|
304
|
+
actionId: sizeActionId,
|
|
305
|
+
options: TEXT_SIZE_OPTIONS.map((option) => ({
|
|
306
|
+
...option,
|
|
307
|
+
dataUi: `${dataUiPrefix}-size-${option.value}-button`,
|
|
308
|
+
})),
|
|
309
|
+
},
|
|
310
|
+
],
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
id: `${dataUiPrefix}.style-align`,
|
|
314
|
+
items: [
|
|
315
|
+
{
|
|
316
|
+
kind: "segmented" as const,
|
|
317
|
+
id: `${dataUiPrefix}.align`,
|
|
318
|
+
actionId: textAlignActionId,
|
|
319
|
+
options: TEXT_ALIGN_OPTIONS.map((option) => ({
|
|
320
|
+
...option,
|
|
321
|
+
dataUi: `${dataUiPrefix}-align-${option.value}-button`,
|
|
322
|
+
})),
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
},
|
|
326
|
+
];
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function createSetTextStyleToolbarAction(
|
|
330
|
+
prop: "color" | "font" | "size" | "textAlign",
|
|
331
|
+
): ToolbarAction<string | null> {
|
|
332
|
+
return {
|
|
333
|
+
id: `text.set-${prop}`,
|
|
334
|
+
isVisible(context) {
|
|
335
|
+
return context.selection.commonShapeType === "text";
|
|
336
|
+
},
|
|
337
|
+
isEnabled(context) {
|
|
338
|
+
return context.selection.count > 0;
|
|
339
|
+
},
|
|
340
|
+
getValue(context) {
|
|
341
|
+
return getCommonTextPropValue(context.selection.selectedShapes, prop);
|
|
342
|
+
},
|
|
343
|
+
run({ context, value }) {
|
|
344
|
+
if (!isValidTextStyleValue(prop, value)) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const updates = context.selection.selectedShapes
|
|
348
|
+
.filter((shape): shape is TextShapeRecord => shape.type === "text")
|
|
349
|
+
.filter((shape) => !shape.isLocked)
|
|
350
|
+
.map((shape) => ({
|
|
351
|
+
id: shape.id,
|
|
352
|
+
props: {
|
|
353
|
+
[prop]: value,
|
|
354
|
+
},
|
|
355
|
+
}));
|
|
356
|
+
if (updates.length === 0) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
context.editor.commands.updateShapes(updates, { source: "user" });
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function createSetTextDefaultStyleToolbarAction(
|
|
365
|
+
prop: "color" | "font" | "size" | "textAlign",
|
|
366
|
+
): ToolbarAction<string | null> {
|
|
367
|
+
return {
|
|
368
|
+
id: `text.default-${prop}`,
|
|
369
|
+
isVisible(context) {
|
|
370
|
+
return context.tool.activeToolId === "text";
|
|
371
|
+
},
|
|
372
|
+
getValue(context) {
|
|
373
|
+
return context.editor.getDefaultShapeProps<TextShapeProps>("text")[prop];
|
|
374
|
+
},
|
|
375
|
+
run({ context, value }) {
|
|
376
|
+
if (!isValidTextStyleValue(prop, value)) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
context.editor.updateDefaultShapeProps("text", { [prop]: value });
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function getCommonTextPropValue(
|
|
385
|
+
selectedShapes: readonly { type: string; props: object }[],
|
|
386
|
+
prop: "color" | "font" | "size" | "textAlign",
|
|
387
|
+
): string | null {
|
|
388
|
+
let value: string | undefined;
|
|
389
|
+
for (const shape of selectedShapes) {
|
|
390
|
+
if (shape.type !== "text") {
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
const nextValue = (shape.props as TextShapeProps)[prop];
|
|
394
|
+
if (value === undefined) {
|
|
395
|
+
value = nextValue;
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
if (value !== nextValue) {
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return value ?? null;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function isValidTextStyleValue(
|
|
406
|
+
prop: "color" | "font" | "size" | "textAlign",
|
|
407
|
+
value: ToolbarActionValue,
|
|
408
|
+
): value is string {
|
|
409
|
+
if (typeof value !== "string") {
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
if (prop === "color") {
|
|
413
|
+
return TEXT_COLOR_SWATCHES.some((option) => option.value === value);
|
|
414
|
+
}
|
|
415
|
+
if (prop === "font") {
|
|
416
|
+
return TEXT_FONT_OPTIONS.some((option) => option.value === value);
|
|
417
|
+
}
|
|
418
|
+
if (prop === "size") {
|
|
419
|
+
return TEXT_SIZE_OPTIONS.some((option) => option.value === value);
|
|
420
|
+
}
|
|
421
|
+
return TEXT_ALIGN_OPTIONS.some((option) => option.value === value);
|
|
422
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineLandExtension,
|
|
3
|
+
type LandFeatureBundle,
|
|
4
|
+
} from "@land/canvas-plugin-api";
|
|
5
|
+
import { createTextCanvasPlugin } from "./canvas";
|
|
6
|
+
import { createTextCorePlugin } from "./core";
|
|
7
|
+
|
|
8
|
+
export function createTextFeatureBundle(): LandFeatureBundle {
|
|
9
|
+
return {
|
|
10
|
+
id: "land.text.bundle",
|
|
11
|
+
corePlugins: [createTextCorePlugin()],
|
|
12
|
+
canvasPlugins: [createTextCanvasPlugin()],
|
|
13
|
+
shapeTypes: ["text"],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const Text = defineLandExtension({
|
|
18
|
+
name: "text",
|
|
19
|
+
createFeature: createTextFeatureBundle,
|
|
20
|
+
});
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCallback,
|
|
3
|
+
useRef,
|
|
4
|
+
useState,
|
|
5
|
+
} from "react";
|
|
6
|
+
import { type ShapeEditingSession } from "@land/canvas-core";
|
|
7
|
+
import { useEditor, useValue } from "@land/canvas-react";
|
|
8
|
+
import type { TextShapeRecord } from "../textTypes";
|
|
9
|
+
import { isTextShapeRecord } from "../textShapeHelpers";
|
|
10
|
+
import {
|
|
11
|
+
TiptapTextEditor,
|
|
12
|
+
type TiptapTextEditorHandle,
|
|
13
|
+
} from "./TiptapTextEditor";
|
|
14
|
+
import { useTextEditingBoxStyle } from "./textEditingBoxStyle";
|
|
15
|
+
import { useTextEditingEntryFocus } from "./textEntryFocus";
|
|
16
|
+
import { useRangeClickCollapse } from "./textRangeSelection";
|
|
17
|
+
import {
|
|
18
|
+
useLatestTextShapeRef,
|
|
19
|
+
useRichTextShapeSync,
|
|
20
|
+
} from "./textShapeSync";
|
|
21
|
+
|
|
22
|
+
export function ShapeEditingSessionBox({
|
|
23
|
+
shapeId,
|
|
24
|
+
markId,
|
|
25
|
+
}: {
|
|
26
|
+
shapeId: TextShapeRecord["id"];
|
|
27
|
+
markId: string;
|
|
28
|
+
}) {
|
|
29
|
+
const editor = useEditor();
|
|
30
|
+
const shape = useValue(editor.getShapeSignal(shapeId));
|
|
31
|
+
const session = useValue(editor.shapeEditingStateSignal).session;
|
|
32
|
+
|
|
33
|
+
if (!isTextShapeRecord(shape) || session?.shapeId !== shape.id) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<RichTextEditingBox
|
|
39
|
+
key={`${shape.id}:${markId}`}
|
|
40
|
+
shape={shape}
|
|
41
|
+
session={session}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function RichTextEditingBox({
|
|
47
|
+
shape,
|
|
48
|
+
session,
|
|
49
|
+
}: {
|
|
50
|
+
shape: TextShapeRecord;
|
|
51
|
+
session: ShapeEditingSession;
|
|
52
|
+
}) {
|
|
53
|
+
const editor = useEditor();
|
|
54
|
+
const initialRichTextRef = useRef(shape.props.richText);
|
|
55
|
+
const latestShapeRef = useLatestTextShapeRef(shape);
|
|
56
|
+
const entryRequest = useValue(editor.shapeEditingEntryRequestSignal);
|
|
57
|
+
const consumedEntryRequestIdRef = useRef<number | null>(null);
|
|
58
|
+
const [tiptapEditor, setTiptapEditor] = useState<
|
|
59
|
+
TiptapTextEditorHandle["editor"] | null
|
|
60
|
+
>(null);
|
|
61
|
+
const [richTextController, setRichTextController] = useState<
|
|
62
|
+
TiptapTextEditorHandle["controller"] | null
|
|
63
|
+
>(null);
|
|
64
|
+
|
|
65
|
+
const handleTiptapReady = useCallback(
|
|
66
|
+
({ editor: readyEditor, controller }: TiptapTextEditorHandle) => {
|
|
67
|
+
setTiptapEditor(readyEditor.isDestroyed ? null : readyEditor);
|
|
68
|
+
setRichTextController(controller);
|
|
69
|
+
},
|
|
70
|
+
[],
|
|
71
|
+
);
|
|
72
|
+
const handleTiptapDispose = useCallback(
|
|
73
|
+
({ editor: disposedEditor, controller }: TiptapTextEditorHandle) => {
|
|
74
|
+
setTiptapEditor((current) =>
|
|
75
|
+
current === disposedEditor ? null : current,
|
|
76
|
+
);
|
|
77
|
+
setRichTextController((current) =>
|
|
78
|
+
current === controller ? null : current,
|
|
79
|
+
);
|
|
80
|
+
},
|
|
81
|
+
[],
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const handleRichTextChange = useRichTextShapeSync({
|
|
85
|
+
editor,
|
|
86
|
+
shape,
|
|
87
|
+
tiptapEditor,
|
|
88
|
+
richTextController,
|
|
89
|
+
latestShapeRef,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
useTextEditingEntryFocus({
|
|
93
|
+
editor,
|
|
94
|
+
shapeId: shape.id,
|
|
95
|
+
session,
|
|
96
|
+
tiptapEditor,
|
|
97
|
+
richTextController,
|
|
98
|
+
entryRequest,
|
|
99
|
+
consumedEntryRequestIdRef,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const rangeClickCollapse = useRangeClickCollapse({
|
|
103
|
+
editor,
|
|
104
|
+
shapeId: shape.id,
|
|
105
|
+
richTextController,
|
|
106
|
+
});
|
|
107
|
+
const style = useTextEditingBoxStyle(shape);
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<div
|
|
111
|
+
data-ui="text-editing-box"
|
|
112
|
+
data-shape-id={shape.id}
|
|
113
|
+
data-mount-target-kind="shape"
|
|
114
|
+
onPointerDown={(event) => {
|
|
115
|
+
event.stopPropagation();
|
|
116
|
+
}}
|
|
117
|
+
onPointerDownCapture={rangeClickCollapse.onPointerDownCapture}
|
|
118
|
+
onPointerMoveCapture={rangeClickCollapse.onPointerMoveCapture}
|
|
119
|
+
onPointerUpCapture={rangeClickCollapse.onPointerUpCapture}
|
|
120
|
+
onPointerCancel={rangeClickCollapse.onPointerCancel}
|
|
121
|
+
onContextMenu={(event) => {
|
|
122
|
+
event.stopPropagation();
|
|
123
|
+
}}
|
|
124
|
+
onDragStart={(event) => {
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
}}
|
|
127
|
+
style={style}
|
|
128
|
+
>
|
|
129
|
+
<TiptapTextEditor
|
|
130
|
+
landEditor={editor}
|
|
131
|
+
shape={shape}
|
|
132
|
+
initialRichText={initialRichTextRef.current}
|
|
133
|
+
className="h-full min-h-full w-full"
|
|
134
|
+
editorStyle={{
|
|
135
|
+
height: "100%",
|
|
136
|
+
minHeight: "100%",
|
|
137
|
+
}}
|
|
138
|
+
onReady={handleTiptapReady}
|
|
139
|
+
onDispose={handleTiptapDispose}
|
|
140
|
+
onRichTextChange={handleRichTextChange}
|
|
141
|
+
/>
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
}
|