@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,266 @@
|
|
|
1
|
+
import { useMemo, useRef } from "react";
|
|
2
|
+
import type { Editor as TiptapEditor } from "@tiptap/react";
|
|
3
|
+
import { BubbleMenu } from "@tiptap/react/menus";
|
|
4
|
+
|
|
5
|
+
const RICH_TEXT_FORMATS: Array<{
|
|
6
|
+
id: "bold" | "italic" | "strike";
|
|
7
|
+
label: string;
|
|
8
|
+
shortcut: string;
|
|
9
|
+
dataUi: string;
|
|
10
|
+
content: string;
|
|
11
|
+
}> = [
|
|
12
|
+
{
|
|
13
|
+
id: "bold",
|
|
14
|
+
label: "Bold",
|
|
15
|
+
shortcut: "B",
|
|
16
|
+
dataUi: "text-bold-button",
|
|
17
|
+
content: "B",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: "italic",
|
|
21
|
+
label: "Italic",
|
|
22
|
+
shortcut: "I",
|
|
23
|
+
dataUi: "text-italic-button",
|
|
24
|
+
content: "I",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: "strike",
|
|
28
|
+
label: "Strikethrough",
|
|
29
|
+
shortcut: "S",
|
|
30
|
+
dataUi: "text-strike-button",
|
|
31
|
+
content: "S",
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
function getCssPixelVariable(name: string, fallback: number): number {
|
|
36
|
+
if (typeof document === "undefined") return fallback;
|
|
37
|
+
const rawValue = getComputedStyle(document.documentElement)
|
|
38
|
+
.getPropertyValue(name)
|
|
39
|
+
.trim();
|
|
40
|
+
if (!rawValue) return fallback;
|
|
41
|
+
const numericValue = Number.parseFloat(rawValue);
|
|
42
|
+
if (!Number.isFinite(numericValue)) return fallback;
|
|
43
|
+
return rawValue.endsWith("rem") ? numericValue * 16 : numericValue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getRichTextBubbleMenuOptions() {
|
|
47
|
+
const offset = getCssPixelVariable("--toolbar-floating-offset", 8);
|
|
48
|
+
const shiftPadding = getCssPixelVariable("--toolbar-floating-shift-padding", 8);
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
strategy: "fixed" as const,
|
|
52
|
+
placement: "top" as const,
|
|
53
|
+
offset,
|
|
54
|
+
flip: true,
|
|
55
|
+
shift: { padding: shiftPadding },
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function isRichTextToolbarTarget(target: EventTarget | null): boolean {
|
|
60
|
+
return (
|
|
61
|
+
target instanceof Element &&
|
|
62
|
+
target.closest('[data-ui="rich-text-formatting-toolbar"]') !== null
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function RichTextToolbar({
|
|
67
|
+
editor,
|
|
68
|
+
version: _version,
|
|
69
|
+
}: {
|
|
70
|
+
editor: TiptapEditor;
|
|
71
|
+
version: number;
|
|
72
|
+
}) {
|
|
73
|
+
const bubbleMenuOptions = useMemo(() => getRichTextBubbleMenuOptions(), []);
|
|
74
|
+
|
|
75
|
+
if (editor.isDestroyed) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<BubbleMenu
|
|
81
|
+
editor={editor}
|
|
82
|
+
updateDelay={0}
|
|
83
|
+
resizeDelay={0}
|
|
84
|
+
appendTo={appendRichTextBubbleMenuToBody}
|
|
85
|
+
shouldShow={shouldShowRichTextBubbleMenu}
|
|
86
|
+
options={bubbleMenuOptions}
|
|
87
|
+
data-ui="rich-text-formatting-toolbar"
|
|
88
|
+
onPointerDown={(event) => {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
event.stopPropagation();
|
|
91
|
+
}}
|
|
92
|
+
onMouseDown={(event) => {
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
event.stopPropagation();
|
|
95
|
+
}}
|
|
96
|
+
onClick={(event) => {
|
|
97
|
+
event.stopPropagation();
|
|
98
|
+
}}
|
|
99
|
+
style={{
|
|
100
|
+
zIndex: 2,
|
|
101
|
+
display: "flex",
|
|
102
|
+
alignItems: "center",
|
|
103
|
+
gap: "var(--chrome-spacing)",
|
|
104
|
+
padding: "var(--chrome-spacing)",
|
|
105
|
+
border: "var(--chrome-border-width) solid var(--chrome-border)",
|
|
106
|
+
borderRadius: "var(--chrome-radius)",
|
|
107
|
+
background: "var(--chrome-background)",
|
|
108
|
+
color: "var(--chrome-foreground)",
|
|
109
|
+
boxShadow: "var(--shadow-chrome)",
|
|
110
|
+
pointerEvents: "auto",
|
|
111
|
+
userSelect: "none",
|
|
112
|
+
WebkitUserSelect: "none",
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
<div
|
|
116
|
+
data-ui="rich-text-formatting-toolbar-title"
|
|
117
|
+
style={{
|
|
118
|
+
padding: "0 var(--toolbar-title-padding-inline)",
|
|
119
|
+
color: "var(--chrome-foreground)",
|
|
120
|
+
fontFamily:
|
|
121
|
+
'ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
|
|
122
|
+
fontSize: "var(--toolbar-title-font-size)",
|
|
123
|
+
fontWeight: 500,
|
|
124
|
+
lineHeight: "var(--toolbar-title-line-height)",
|
|
125
|
+
whiteSpace: "nowrap",
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
128
|
+
Text
|
|
129
|
+
</div>
|
|
130
|
+
<div
|
|
131
|
+
aria-hidden="true"
|
|
132
|
+
style={{
|
|
133
|
+
width: "var(--toolbar-separator-width)",
|
|
134
|
+
height: "var(--toolbar-separator-height)",
|
|
135
|
+
background: "var(--border)",
|
|
136
|
+
margin: "0 var(--toolbar-separator-margin-inline)",
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
{RICH_TEXT_FORMATS.map((format) => (
|
|
140
|
+
<RichTextToolbarButton
|
|
141
|
+
key={format.id}
|
|
142
|
+
editor={editor}
|
|
143
|
+
format={format.id}
|
|
144
|
+
label={format.label}
|
|
145
|
+
shortcut={format.shortcut}
|
|
146
|
+
dataUi={format.dataUi}
|
|
147
|
+
>
|
|
148
|
+
{format.content}
|
|
149
|
+
</RichTextToolbarButton>
|
|
150
|
+
))}
|
|
151
|
+
</BubbleMenu>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function appendRichTextBubbleMenuToBody(): HTMLElement {
|
|
156
|
+
return document.body;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function shouldShowRichTextBubbleMenu({
|
|
160
|
+
editor,
|
|
161
|
+
element,
|
|
162
|
+
view,
|
|
163
|
+
}: {
|
|
164
|
+
editor: TiptapEditor;
|
|
165
|
+
element: HTMLElement;
|
|
166
|
+
view: { hasFocus(): boolean };
|
|
167
|
+
}): boolean {
|
|
168
|
+
const hasTextRangeSelection = !editor.state.selection.empty;
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
editor.isEditable &&
|
|
172
|
+
!editor.isDestroyed &&
|
|
173
|
+
hasTextRangeSelection &&
|
|
174
|
+
(view.hasFocus() || element.contains(document.activeElement))
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function RichTextToolbarButton({
|
|
179
|
+
editor,
|
|
180
|
+
format,
|
|
181
|
+
label,
|
|
182
|
+
shortcut,
|
|
183
|
+
dataUi,
|
|
184
|
+
children,
|
|
185
|
+
}: {
|
|
186
|
+
editor: TiptapEditor;
|
|
187
|
+
format: "bold" | "italic" | "strike";
|
|
188
|
+
label: string;
|
|
189
|
+
shortcut: string;
|
|
190
|
+
dataUi: string;
|
|
191
|
+
children: string;
|
|
192
|
+
}) {
|
|
193
|
+
const didToggleOnPointerDownRef = useRef(false);
|
|
194
|
+
const active = editor.isActive(format);
|
|
195
|
+
const disabled = editor.isDestroyed || editor.schema.marks[format] === undefined;
|
|
196
|
+
const toggle = () => {
|
|
197
|
+
if (disabled) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
switch (format) {
|
|
201
|
+
case "bold":
|
|
202
|
+
editor.chain().focus().toggleBold().run();
|
|
203
|
+
return;
|
|
204
|
+
case "italic":
|
|
205
|
+
editor.chain().focus().toggleItalic().run();
|
|
206
|
+
return;
|
|
207
|
+
case "strike":
|
|
208
|
+
editor.chain().focus().toggleStrike().run();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
return (
|
|
213
|
+
<button
|
|
214
|
+
type="button"
|
|
215
|
+
aria-label={label}
|
|
216
|
+
aria-pressed={active}
|
|
217
|
+
title={`${label} (${shortcut})`}
|
|
218
|
+
disabled={disabled}
|
|
219
|
+
data-ui={dataUi}
|
|
220
|
+
onPointerDown={(event) => {
|
|
221
|
+
event.preventDefault();
|
|
222
|
+
event.stopPropagation();
|
|
223
|
+
if (event.isTrusted) {
|
|
224
|
+
toggle();
|
|
225
|
+
didToggleOnPointerDownRef.current = true;
|
|
226
|
+
}
|
|
227
|
+
}}
|
|
228
|
+
onMouseDown={(event) => {
|
|
229
|
+
event.preventDefault();
|
|
230
|
+
event.stopPropagation();
|
|
231
|
+
}}
|
|
232
|
+
onClick={(event) => {
|
|
233
|
+
event.preventDefault();
|
|
234
|
+
event.stopPropagation();
|
|
235
|
+
if (didToggleOnPointerDownRef.current) {
|
|
236
|
+
didToggleOnPointerDownRef.current = false;
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
toggle();
|
|
240
|
+
}}
|
|
241
|
+
style={{
|
|
242
|
+
display: "inline-flex",
|
|
243
|
+
alignItems: "center",
|
|
244
|
+
justifyContent: "center",
|
|
245
|
+
width: "var(--toolbar-control-size)",
|
|
246
|
+
height: "var(--toolbar-control-size)",
|
|
247
|
+
border: "var(--chrome-control-border-width) solid transparent",
|
|
248
|
+
borderRadius: "var(--chrome-control-radius)",
|
|
249
|
+
background: active ? "var(--accent)" : "transparent",
|
|
250
|
+
color: active ? "var(--accent-foreground)" : "var(--muted-foreground)",
|
|
251
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
252
|
+
fontFamily:
|
|
253
|
+
'ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
|
|
254
|
+
fontSize: "var(--toolbar-button-font-size)",
|
|
255
|
+
fontStyle: format === "italic" ? "italic" : undefined,
|
|
256
|
+
fontWeight: format === "bold" ? 700 : 600,
|
|
257
|
+
lineHeight: 1,
|
|
258
|
+
opacity: disabled ? 0.45 : 1,
|
|
259
|
+
pointerEvents: "auto",
|
|
260
|
+
textDecoration: format === "strike" ? "line-through" : undefined,
|
|
261
|
+
}}
|
|
262
|
+
>
|
|
263
|
+
{children}
|
|
264
|
+
</button>
|
|
265
|
+
);
|
|
266
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useRef,
|
|
5
|
+
useState,
|
|
6
|
+
type CSSProperties,
|
|
7
|
+
} from "react";
|
|
8
|
+
import {
|
|
9
|
+
EditorContent,
|
|
10
|
+
useEditor as useTiptapEditor,
|
|
11
|
+
type Editor as TiptapEditor,
|
|
12
|
+
} from "@tiptap/react";
|
|
13
|
+
import type { JSONContent } from "@tiptap/core";
|
|
14
|
+
import { Bold } from "@tiptap/extension-bold";
|
|
15
|
+
import { Italic } from "@tiptap/extension-italic";
|
|
16
|
+
import { Strike } from "@tiptap/extension-strike";
|
|
17
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
18
|
+
import type { Editor as LandEditor } from "@land/canvas-core";
|
|
19
|
+
import type { RichTextDocument, TextShapeRecord } from "../textTypes";
|
|
20
|
+
import {
|
|
21
|
+
createTiptapTextEditorController,
|
|
22
|
+
type TiptapTextEditorController,
|
|
23
|
+
} from "./tiptapTextEditorController";
|
|
24
|
+
import { RichTextToolbar } from "./RichTextToolbar";
|
|
25
|
+
|
|
26
|
+
const RICH_TEXT_EXTENSIONS = [
|
|
27
|
+
StarterKit.configure({
|
|
28
|
+
bold: false,
|
|
29
|
+
italic: false,
|
|
30
|
+
strike: false,
|
|
31
|
+
}),
|
|
32
|
+
Bold.extend({ keepOnSplit: true }),
|
|
33
|
+
Italic.extend({ keepOnSplit: true }),
|
|
34
|
+
Strike.extend({ keepOnSplit: true }),
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
export interface TiptapTextEditorHandle {
|
|
38
|
+
readonly editor: TiptapEditor;
|
|
39
|
+
readonly controller: TiptapTextEditorController;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface TiptapTextEditorProps {
|
|
43
|
+
landEditor: LandEditor;
|
|
44
|
+
shape: TextShapeRecord;
|
|
45
|
+
initialRichText: RichTextDocument;
|
|
46
|
+
className: string;
|
|
47
|
+
editorStyle: CSSProperties;
|
|
48
|
+
onReady(handle: TiptapTextEditorHandle): void;
|
|
49
|
+
onDispose(handle: TiptapTextEditorHandle): void;
|
|
50
|
+
onRichTextChange(input: {
|
|
51
|
+
editor: TiptapEditor;
|
|
52
|
+
controller: TiptapTextEditorController;
|
|
53
|
+
richText: RichTextDocument;
|
|
54
|
+
}): void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function TiptapTextEditor({
|
|
58
|
+
landEditor,
|
|
59
|
+
shape,
|
|
60
|
+
initialRichText,
|
|
61
|
+
className,
|
|
62
|
+
editorStyle,
|
|
63
|
+
onReady,
|
|
64
|
+
onDispose,
|
|
65
|
+
onRichTextChange,
|
|
66
|
+
}: TiptapTextEditorProps) {
|
|
67
|
+
const [formatToolbarVersion, setFormatToolbarVersion] = useState(0);
|
|
68
|
+
const controllerRef = useRef<{
|
|
69
|
+
editor: TiptapEditor;
|
|
70
|
+
controller: TiptapTextEditorController;
|
|
71
|
+
} | null>(null);
|
|
72
|
+
|
|
73
|
+
const getController = useCallback(
|
|
74
|
+
(textEditor: TiptapEditor): TiptapTextEditorController => {
|
|
75
|
+
const existing = controllerRef.current;
|
|
76
|
+
if (existing?.editor === textEditor) {
|
|
77
|
+
return existing.controller;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const controller = createTiptapTextEditorController({
|
|
81
|
+
shapeId: shape.id,
|
|
82
|
+
editor: textEditor,
|
|
83
|
+
});
|
|
84
|
+
controllerRef.current = { editor: textEditor, controller };
|
|
85
|
+
return controller;
|
|
86
|
+
},
|
|
87
|
+
[shape.id],
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const tiptapEditor = useTiptapEditor(
|
|
91
|
+
{
|
|
92
|
+
extensions: RICH_TEXT_EXTENSIONS,
|
|
93
|
+
content: initialRichText as JSONContent,
|
|
94
|
+
autofocus: false,
|
|
95
|
+
editable: true,
|
|
96
|
+
immediatelyRender: true,
|
|
97
|
+
shouldRerenderOnTransaction: false,
|
|
98
|
+
editorProps: {
|
|
99
|
+
attributes: {
|
|
100
|
+
"data-ui": "rich-text-editor",
|
|
101
|
+
class:
|
|
102
|
+
"land-rich-text-editor h-full min-h-full w-full outline-none whitespace-pre-wrap break-words",
|
|
103
|
+
dir: "auto",
|
|
104
|
+
},
|
|
105
|
+
handleKeyDown: (_view, event): boolean => {
|
|
106
|
+
event.stopPropagation();
|
|
107
|
+
|
|
108
|
+
if (event.isComposing) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (event.key === "Escape") {
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
landEditor.cancelEditing("user");
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
landEditor.completeEditing("user");
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return false;
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
onUpdate: ({ editor }) => {
|
|
128
|
+
const controller = getController(editor);
|
|
129
|
+
onRichTextChange({
|
|
130
|
+
editor,
|
|
131
|
+
controller,
|
|
132
|
+
richText: controller.getValue(),
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
[shape.id],
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
if (!tiptapEditor || tiptapEditor.isDestroyed) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const controller = getController(tiptapEditor);
|
|
145
|
+
const handle = { editor: tiptapEditor, controller };
|
|
146
|
+
onReady(handle);
|
|
147
|
+
return () => {
|
|
148
|
+
if (controllerRef.current?.editor === tiptapEditor) {
|
|
149
|
+
controllerRef.current = null;
|
|
150
|
+
}
|
|
151
|
+
onDispose(handle);
|
|
152
|
+
};
|
|
153
|
+
}, [getController, onDispose, onReady, tiptapEditor]);
|
|
154
|
+
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
if (!tiptapEditor || tiptapEditor.isDestroyed) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const refresh = () => {
|
|
161
|
+
setFormatToolbarVersion((version) => version + 1);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
tiptapEditor.on("selectionUpdate", refresh);
|
|
165
|
+
tiptapEditor.on("update", refresh);
|
|
166
|
+
tiptapEditor.on("focus", refresh);
|
|
167
|
+
tiptapEditor.on("blur", refresh);
|
|
168
|
+
return () => {
|
|
169
|
+
tiptapEditor.off("selectionUpdate", refresh);
|
|
170
|
+
tiptapEditor.off("update", refresh);
|
|
171
|
+
tiptapEditor.off("focus", refresh);
|
|
172
|
+
tiptapEditor.off("blur", refresh);
|
|
173
|
+
};
|
|
174
|
+
}, [tiptapEditor]);
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<>
|
|
178
|
+
{tiptapEditor ? (
|
|
179
|
+
<RichTextToolbar
|
|
180
|
+
editor={tiptapEditor}
|
|
181
|
+
version={formatToolbarVersion}
|
|
182
|
+
/>
|
|
183
|
+
) : null}
|
|
184
|
+
<EditorContent
|
|
185
|
+
editor={tiptapEditor}
|
|
186
|
+
className={className}
|
|
187
|
+
style={editorStyle}
|
|
188
|
+
/>
|
|
189
|
+
</>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { JSONContent } from "@tiptap/core";
|
|
3
|
+
import type { RichTextDocument } from "../textTypes";
|
|
4
|
+
import {
|
|
5
|
+
getRichTextMarkStyle,
|
|
6
|
+
isRichTextTextNode,
|
|
7
|
+
} from "../richTextUtils";
|
|
8
|
+
|
|
9
|
+
export function renderRichTextDocument(richText: RichTextDocument): ReactNode {
|
|
10
|
+
return richText.content.map((node, index) =>
|
|
11
|
+
renderRichTextBlock(node, `block:${index}`),
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function renderRichTextBlock(
|
|
16
|
+
node: JSONContent,
|
|
17
|
+
key: string,
|
|
18
|
+
): ReactNode {
|
|
19
|
+
const children = renderRichTextChildren(node, key);
|
|
20
|
+
return (
|
|
21
|
+
<p key={key} style={{ margin: 0 }}>
|
|
22
|
+
{children.length > 0 ? children : <br />}
|
|
23
|
+
</p>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function renderRichTextChildren(
|
|
28
|
+
node: JSONContent,
|
|
29
|
+
keyPrefix: string,
|
|
30
|
+
): ReactNode[] {
|
|
31
|
+
return (
|
|
32
|
+
node.content?.map((child, index) =>
|
|
33
|
+
renderRichTextNode(child, `${keyPrefix}:${index}`),
|
|
34
|
+
) ?? []
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function renderRichTextNode(node: JSONContent, key: string): ReactNode {
|
|
39
|
+
if (isRichTextTextNode(node)) {
|
|
40
|
+
const style = getRichTextMarkStyle(node.marks);
|
|
41
|
+
return (
|
|
42
|
+
<span key={key} style={style}>
|
|
43
|
+
{node.text}
|
|
44
|
+
</span>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return renderRichTextChildren(node, key);
|
|
49
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Editor as TiptapEditor } from "@tiptap/react";
|
|
2
|
+
import type { TiptapTextSelectionSnapshot } from "./tiptapTextEditorController";
|
|
3
|
+
|
|
4
|
+
export function hasMountedTextEditorView(textEditor: TiptapEditor): boolean {
|
|
5
|
+
try {
|
|
6
|
+
return textEditor.view.dom.isConnected;
|
|
7
|
+
} catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function ensureTextEditorFocused(textEditor: TiptapEditor): void {
|
|
13
|
+
if (textEditor.isDestroyed || !hasMountedTextEditorView(textEditor)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
textEditor.view.dom.focus();
|
|
17
|
+
textEditor.view.focus();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function placeCaretInTextEditorAtClientPoint(
|
|
21
|
+
textEditor: TiptapEditor,
|
|
22
|
+
clientX: number,
|
|
23
|
+
clientY: number,
|
|
24
|
+
): void {
|
|
25
|
+
if (textEditor.isDestroyed || !hasMountedTextEditorView(textEditor)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const pos = textEditor.view.posAtCoords({
|
|
30
|
+
left: clientX,
|
|
31
|
+
top: clientY,
|
|
32
|
+
})?.pos;
|
|
33
|
+
|
|
34
|
+
if (typeof pos === "number") {
|
|
35
|
+
textEditor.chain().focus().setTextSelection(pos).run();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
textEditor.commands.focus("end");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function isDomSelectionRangeInsideTextEditor(
|
|
43
|
+
textEditor: TiptapEditor,
|
|
44
|
+
): boolean {
|
|
45
|
+
return getTextEditorSelectionSnapshot(textEditor).type === "Range";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getTextEditorSelectionSnapshot(
|
|
49
|
+
textEditor: TiptapEditor,
|
|
50
|
+
): TiptapTextSelectionSnapshot {
|
|
51
|
+
if (!hasMountedTextEditorView(textEditor)) {
|
|
52
|
+
return { type: null, text: null };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const domSnapshot = getDomSelectionSnapshot(textEditor.view.dom);
|
|
56
|
+
if (domSnapshot.type !== null) {
|
|
57
|
+
return domSnapshot;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const selection = textEditor.state.selection;
|
|
61
|
+
return {
|
|
62
|
+
type: selection.empty ? "Caret" : "Range",
|
|
63
|
+
text: selection.empty
|
|
64
|
+
? ""
|
|
65
|
+
: textEditor.state.doc.textBetween(selection.from, selection.to, "\n"),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function getDomSelectionSnapshot(root: Node | null): TiptapTextSelectionSnapshot {
|
|
70
|
+
if (!root) {
|
|
71
|
+
return { type: null, text: null };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const selection = window.getSelection();
|
|
75
|
+
if (!selection || selection.rangeCount === 0) {
|
|
76
|
+
return { type: selection?.type ?? null, text: null };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const anchorNode = selection.anchorNode;
|
|
80
|
+
const focusNode = selection.focusNode;
|
|
81
|
+
const rootElement = root instanceof HTMLElement ? root : root.parentElement;
|
|
82
|
+
const isInside =
|
|
83
|
+
!!anchorNode &&
|
|
84
|
+
!!focusNode &&
|
|
85
|
+
rootElement !== null &&
|
|
86
|
+
rootElement.contains(anchorNode) &&
|
|
87
|
+
rootElement.contains(focusNode);
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
type: isInside ? selection.type : null,
|
|
91
|
+
text: isInside ? selection.toString() : null,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useMemo,
|
|
3
|
+
type CSSProperties,
|
|
4
|
+
} from "react";
|
|
5
|
+
import type { TextShapeRecord } from "../textTypes";
|
|
6
|
+
import {
|
|
7
|
+
getTextAlign,
|
|
8
|
+
getTextFontFamily,
|
|
9
|
+
getTextFontSize,
|
|
10
|
+
getTextLineHeight,
|
|
11
|
+
} from "../textStyle";
|
|
12
|
+
|
|
13
|
+
export function useTextEditingBoxStyle(shape: TextShapeRecord): CSSProperties {
|
|
14
|
+
return useMemo(
|
|
15
|
+
() => ({
|
|
16
|
+
color: shape.props.color,
|
|
17
|
+
fontFamily: getTextFontFamily(shape.props.font),
|
|
18
|
+
fontSize: getTextFontSize(shape.props.size),
|
|
19
|
+
lineHeight: `${getTextLineHeight(shape.props.size)}px`,
|
|
20
|
+
textAlign: getTextAlign(shape.props.textAlign),
|
|
21
|
+
pointerEvents: "auto",
|
|
22
|
+
userSelect: "text",
|
|
23
|
+
cursor: "text",
|
|
24
|
+
position: "absolute",
|
|
25
|
+
inset: 0,
|
|
26
|
+
width: "100%",
|
|
27
|
+
height: "100%",
|
|
28
|
+
}),
|
|
29
|
+
[
|
|
30
|
+
shape.props.color,
|
|
31
|
+
shape.props.font,
|
|
32
|
+
shape.props.size,
|
|
33
|
+
shape.props.textAlign,
|
|
34
|
+
],
|
|
35
|
+
);
|
|
36
|
+
}
|