@bendyline/squisq-editor-react 1.5.3 → 1.6.1
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 +57 -10
- package/dist/index.d.ts +1114 -52
- package/dist/index.js +18446 -8050
- package/dist/index.js.map +1 -1
- package/dist/styles/fa-brands-400-AHOAZHCU.woff2 +0 -0
- package/dist/styles/fa-regular-400-VRZYIBIZ.woff2 +0 -0
- package/dist/styles/fa-solid-900-MDEYK55F.woff2 +0 -0
- package/dist/styles/fa-v4compatibility-ETEVP6IB.woff2 +0 -0
- package/dist/styles/index.css +13867 -0
- package/package.json +15 -7
- package/src/BlockCardView.tsx +121 -0
- package/src/BlockPreviewPanel.tsx +69 -0
- package/src/BlockPropertiesPopover.tsx +191 -0
- package/src/EditorContext.tsx +165 -16
- package/src/EditorShell.tsx +265 -144
- package/src/FolderView.tsx +131 -0
- package/src/Icon.tsx +26 -0
- package/src/ImageEditor.tsx +69 -22
- package/src/OutlinePanel.tsx +64 -7
- package/src/PlainHtmlPreview.tsx +30 -3
- package/src/PreviewControls.tsx +491 -122
- package/src/PreviewPanel.tsx +15 -9
- package/src/RawEditor.tsx +179 -17
- package/src/RecorderEntry.tsx +9 -16
- package/src/TemplateAnnotation.ts +44 -0
- package/src/TemplatePicker.tsx +329 -54
- package/src/ThemeCustomizerPanel.tsx +30 -336
- package/src/ThemePicker.tsx +112 -3
- package/src/TimelineBlockPreview.tsx +37 -0
- package/src/TimelineTrack.tsx +671 -0
- package/src/Toolbar.tsx +544 -180
- package/src/Tooltip.tsx +22 -4
- package/src/TransitionPicker.tsx +351 -0
- package/src/VersionHistoryPanel.tsx +4 -16
- package/src/ViewMenuPanel.tsx +17 -14
- package/src/WysiwygEditor.tsx +161 -65
- package/src/__tests__/blockProperties.test.ts +92 -0
- package/src/__tests__/blockRange.test.ts +105 -0
- package/src/__tests__/buildPreviewDocTransition.test.ts +73 -0
- package/src/__tests__/codeContextSectionView.test.tsx +95 -0
- package/src/__tests__/codeContextZoneManager.test.ts +127 -0
- package/src/__tests__/createShapeLayer.test.ts +46 -0
- package/src/__tests__/diffContextSections.test.ts +39 -0
- package/src/__tests__/drawingShapeRoundTrip.test.ts +49 -0
- package/src/__tests__/editorShellCodeContext.test.tsx +86 -0
- package/src/__tests__/editorShellProps.test.tsx +96 -0
- package/src/__tests__/embeddedMedia.test.ts +48 -0
- package/src/__tests__/headingTransition.test.ts +138 -0
- package/src/__tests__/layoutChildRoundTrip.test.ts +71 -0
- package/src/__tests__/plainHtmlPreview.test.tsx +10 -8
- package/src/__tests__/previewControls.test.tsx +70 -0
- package/src/__tests__/recorderMediaInsert.test.ts +86 -0
- package/src/__tests__/templateAnnotationRoundTrip.test.ts +18 -0
- package/src/__tests__/templatePickerMetadata.test.ts +32 -0
- package/src/__tests__/timelineSource.test.ts +134 -0
- package/src/__tests__/tiptapBridge.test.ts +92 -0
- package/src/__tests__/tiptapBridgeConformance.test.ts +47 -0
- package/src/__tests__/tooltip.test.tsx +72 -0
- package/src/__tests__/transitionCatalog.test.ts +64 -0
- package/src/__tests__/useBlockNavigator.test.tsx +67 -0
- package/src/__tests__/useJsonEditorTokens.test.ts +59 -0
- package/src/__tests__/useMediaRecorder.test.ts +41 -0
- package/src/__tests__/useTimelineClock.test.ts +21 -0
- package/src/blockProperties.ts +88 -0
- package/src/blockRange.ts +132 -0
- package/src/buildPreviewDoc.ts +98 -9
- package/src/codeContext/CodeContextSectionView.tsx +124 -0
- package/src/codeContext/CodeContextZoneManager.ts +149 -0
- package/src/codeContext/CodeContextZones.tsx +121 -0
- package/src/codeContext/diffContextSections.ts +38 -0
- package/src/codeContext/types.ts +75 -0
- package/src/customTemplates/AddBin.tsx +126 -0
- package/src/customTemplates/CustomLayoutManager.tsx +233 -0
- package/src/customTemplates/CustomTemplateContext.tsx +182 -0
- package/src/customTemplates/LayerToolbar.tsx +580 -0
- package/src/customTemplates/ShapeGlyph.tsx +47 -0
- package/src/customTemplates/TemplateDesigner.tsx +430 -0
- package/src/customTemplates/__tests__/library.test.ts +88 -0
- package/src/customTemplates/__tests__/normalizePositions.test.ts +109 -0
- package/src/customTemplates/__tests__/shapeDefs.test.ts +49 -0
- package/src/customTemplates/__tests__/useMemoryLayerAdapter.test.ts +95 -0
- package/src/customTemplates/designer.css +673 -0
- package/src/customTemplates/index.ts +31 -0
- package/src/customTemplates/library.ts +97 -0
- package/src/customTemplates/normalizePositions.ts +75 -0
- package/src/customTemplates/shapeDefs.ts +131 -0
- package/src/customTemplates/thumbnail.tsx +63 -0
- package/src/customTemplates/tokenDefs.ts +60 -0
- package/src/customTemplates/useDocCustomTemplates.ts +52 -0
- package/src/customTemplates/useMemoryLayerAdapter.ts +123 -0
- package/src/customThemes/CustomThemeContext.tsx +179 -0
- package/src/customThemes/CustomThemeDialog.tsx +286 -0
- package/src/customThemes/__tests__/CustomThemeContext.test.tsx +64 -0
- package/src/customThemes/__tests__/CustomThemeDialog.test.tsx +47 -0
- package/src/customThemes/__tests__/customThemeLibrary.test.ts +51 -0
- package/src/customThemes/customThemeLibrary.ts +97 -0
- package/src/customThemes/index.ts +31 -0
- package/src/customThemes/themeControls.tsx +229 -0
- package/src/customThemes/themeDraft.ts +272 -0
- package/src/customThemes/useDocCustomThemes.ts +49 -0
- package/src/diagram/DiagramCanvas.tsx +240 -0
- package/src/diagram/DiagramExtension.ts +209 -0
- package/src/diagram/DiagramMaximizedOverlay.tsx +46 -0
- package/src/diagram/DiagramWidget.tsx +270 -0
- package/src/diagram/diagramCommands.ts +604 -0
- package/src/diagram/diagramConstants.ts +17 -0
- package/src/diagram/useDiagramData.ts +126 -0
- package/src/embeddedMedia.ts +78 -0
- package/src/frontmatter.ts +29 -0
- package/src/headingTransition.ts +231 -0
- package/src/imageEditor/CanvasSurface.tsx +383 -88
- package/src/imageEditor/PropertiesPanel.tsx +47 -1
- package/src/imageEditor/Toolbar.tsx +229 -16
- package/src/imageEditor/createShapeLayer.ts +280 -0
- package/src/imageEditor/icons.tsx +34 -114
- package/src/imageEditor/image-editor.css +54 -5
- package/src/imageEditor/state.ts +23 -3
- package/src/index.ts +109 -1
- package/src/jsonEditor/useJsonEditorTokens.ts +13 -43
- package/src/recorder/RecorderModal.tsx +120 -53
- package/src/recorder/RecorderPanel.tsx +2 -26
- package/src/recorder/hooks/useMediaRecorder.ts +17 -11
- package/src/recorder/insertMediaBlock.ts +30 -0
- package/src/resolveBlockVisual.ts +33 -0
- package/src/scene/Scene.tsx +540 -0
- package/src/scene/SceneBlockExtension.ts +198 -0
- package/src/scene/SceneBlockToolbar.tsx +201 -0
- package/src/scene/SceneBlockWidget.tsx +434 -0
- package/src/scene/ScenePropsBar.tsx +85 -0
- package/src/scene/SceneSelection.tsx +107 -0
- package/src/scene/SceneViewport.tsx +102 -0
- package/src/scene/ShapePalette.tsx +181 -0
- package/src/scene/__tests__/DiagramAdapter.test.ts +56 -0
- package/src/scene/__tests__/bezierEdit.test.ts +85 -0
- package/src/scene/__tests__/blockLayers.test.ts +57 -0
- package/src/scene/__tests__/shapeLayers.test.ts +106 -0
- package/src/scene/__tests__/useSceneHitTest.test.ts +90 -0
- package/src/scene/__tests__/useScenePanZoom.test.ts +103 -0
- package/src/scene/adapters/DiagramAdapter.ts +168 -0
- package/src/scene/adapters/DrawingAdapter.ts +415 -0
- package/src/scene/adapters/LayoutAdapter.ts +310 -0
- package/src/scene/adapters/blockLayers.ts +159 -0
- package/src/scene/commands/SceneCommand.ts +70 -0
- package/src/scene/commands/drawingCommands.ts +318 -0
- package/src/scene/commands/layoutCommands.ts +301 -0
- package/src/scene/hooks/useSceneHitTest.ts +105 -0
- package/src/scene/hooks/useScenePanZoom.ts +147 -0
- package/src/scene/hooks/useSceneSelection.ts +62 -0
- package/src/scene/index.ts +95 -0
- package/src/scene/layers/DiagramEdges.tsx +127 -0
- package/src/scene/layers/edgeGeometry.ts +77 -0
- package/src/scene/layers/nodeCard.tsx +145 -0
- package/src/scene/layers/renderLayer.tsx +70 -0
- package/src/scene/layers/shapeLayers.ts +201 -0
- package/src/scene/paths/bezierEdit.ts +208 -0
- package/src/scene/scene.css +649 -0
- package/src/scene/text/SceneTextOverlay.tsx +161 -0
- package/src/scene/text/sceneTextChannel.ts +40 -0
- package/src/scene/text/sceneTextConfig.ts +27 -0
- package/src/scene/text/sceneTiptap.ts +36 -0
- package/src/scene/text/useSceneTextEditing.ts +39 -0
- package/src/scene/tools/ConnectTool.ts +111 -0
- package/src/scene/tools/DrawingConnectTool.ts +161 -0
- package/src/scene/tools/PathTool.ts +158 -0
- package/src/scene/tools/PlaceTool.ts +47 -0
- package/src/scene/tools/SceneTool.ts +75 -0
- package/src/scene/tools/SelectTool.ts +284 -0
- package/src/scene/tools/ShapeTool.ts +144 -0
- package/src/scene/tools/TextTool.ts +72 -0
- package/src/scene/tools/TokenTool.ts +95 -0
- package/src/scene/tools/createDrawShapeTool.ts +82 -0
- package/src/styles/code-context.css +155 -0
- package/src/styles/diagram.css +183 -0
- package/src/styles/editor.css +1708 -150
- package/src/styles/folder-view.css +210 -0
- package/src/styles/image-edit-affordance.css +2 -2
- package/src/styles/index.css +5 -0
- package/src/timelineSource.ts +244 -0
- package/src/tiptapBridge.ts +115 -34
- package/src/tooltipPlacement.ts +13 -0
- package/src/transitionCatalog.ts +159 -0
- package/src/types/monaco-shims.d.ts +10 -0
- package/src/useBlockNavigator.ts +153 -0
- package/src/useMonacoLoader.ts +23 -1
- package/src/useTimelineClock.ts +76 -0
- package/src/utils/dropUtils.ts +1 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ShapeTool — drag to draw a rectangle or circle as a new ShapeLayer.
|
|
3
|
+
*
|
|
4
|
+
* Exposed as a factory so a host can pre-bind the shape kind and
|
|
5
|
+
* stroke/fill defaults. Returns a fresh SceneTool instance — the
|
|
6
|
+
* factory pattern lets multiple Scene instances coexist without
|
|
7
|
+
* sharing module-level drag state.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { createElement, type JSX } from 'react';
|
|
11
|
+
import type { ShapeLayer } from '@bendyline/squisq/schemas';
|
|
12
|
+
import type { SceneTool } from './SceneTool';
|
|
13
|
+
|
|
14
|
+
interface ShapeToolOptions {
|
|
15
|
+
/** Shape kind. Default 'rect'. */
|
|
16
|
+
shape?: 'rect' | 'circle' | 'line';
|
|
17
|
+
/** Stroke color. Default '#1e293b'. */
|
|
18
|
+
stroke?: string;
|
|
19
|
+
/** Fill color (or 'none' for an outline-only shape). Default 'none'. */
|
|
20
|
+
fill?: string;
|
|
21
|
+
/** Stroke width in viewport units. Default 2. */
|
|
22
|
+
strokeWidth?: number;
|
|
23
|
+
/** Corner radius for rects. Default 6. */
|
|
24
|
+
borderRadius?: number;
|
|
25
|
+
/** Override the tool id (default 'shape'). */
|
|
26
|
+
id?: string;
|
|
27
|
+
/** Override the tool label. */
|
|
28
|
+
label?: string;
|
|
29
|
+
/** Keyboard shortcut (single char, lowercase). */
|
|
30
|
+
shortcut?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function createShapeTool(options: ShapeToolOptions = {}): SceneTool {
|
|
34
|
+
const shape = options.shape ?? 'rect';
|
|
35
|
+
const stroke = options.stroke ?? '#1e293b';
|
|
36
|
+
const fill = options.fill ?? 'none';
|
|
37
|
+
const strokeWidth = options.strokeWidth ?? 2;
|
|
38
|
+
const borderRadius = options.borderRadius ?? 6;
|
|
39
|
+
|
|
40
|
+
interface DragState {
|
|
41
|
+
startV: { x: number; y: number };
|
|
42
|
+
currentV: { x: number; y: number };
|
|
43
|
+
}
|
|
44
|
+
let drag: DragState | null = null;
|
|
45
|
+
|
|
46
|
+
function pointer(e: React.PointerEvent): { sx: number; sy: number } {
|
|
47
|
+
const rect = (e.currentTarget as Element).getBoundingClientRect();
|
|
48
|
+
return { sx: e.clientX - rect.left, sy: e.clientY - rect.top };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
id: options.id ?? `shape-${shape}`,
|
|
53
|
+
label: options.label ?? `${shape[0].toUpperCase()}${shape.slice(1)}`,
|
|
54
|
+
cursor: 'crosshair',
|
|
55
|
+
shortcut: options.shortcut,
|
|
56
|
+
|
|
57
|
+
onPointerDown(e, ctx) {
|
|
58
|
+
if (e.button !== 0) return;
|
|
59
|
+
const { sx, sy } = pointer(e);
|
|
60
|
+
const v = ctx.screenToViewport(sx, sy);
|
|
61
|
+
drag = { startV: v, currentV: v };
|
|
62
|
+
(e.currentTarget as Element).setPointerCapture?.(e.pointerId);
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
onPointerMove(e, ctx) {
|
|
66
|
+
if (!drag) return;
|
|
67
|
+
const { sx, sy } = pointer(e);
|
|
68
|
+
drag.currentV = ctx.screenToViewport(sx, sy);
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
onPointerUp(e, ctx) {
|
|
72
|
+
if (!drag) return;
|
|
73
|
+
const box = boxFromCorners(drag.startV, drag.currentV);
|
|
74
|
+
drag = null;
|
|
75
|
+
(e.currentTarget as Element).releasePointerCapture?.(e.pointerId);
|
|
76
|
+
// Ignore micro-drags that are probably an accidental click.
|
|
77
|
+
if (box.width < 4 || box.height < 4) return;
|
|
78
|
+
const layer: ShapeLayer = {
|
|
79
|
+
id: `shape-${Date.now().toString(36)}-${Math.floor(Math.random() * 1e6).toString(36)}`,
|
|
80
|
+
type: 'shape',
|
|
81
|
+
position: { x: box.x, y: box.y, width: box.width, height: box.height },
|
|
82
|
+
content: {
|
|
83
|
+
shape,
|
|
84
|
+
fill,
|
|
85
|
+
stroke,
|
|
86
|
+
strokeWidth,
|
|
87
|
+
...(shape === 'rect' ? { borderRadius } : {}),
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
ctx.dispatch({ kind: 'addLayer', layer });
|
|
91
|
+
// Switch back to Select so the user can immediately move the new shape.
|
|
92
|
+
ctx.setActiveTool?.('select');
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
renderOverlay(): JSX.Element | null {
|
|
96
|
+
if (!drag) return null;
|
|
97
|
+
const box = boxFromCorners(drag.startV, drag.currentV);
|
|
98
|
+
if (shape === 'circle') {
|
|
99
|
+
const r = Math.min(box.width, box.height) / 2;
|
|
100
|
+
return createElement('circle', {
|
|
101
|
+
key: 'shape-preview',
|
|
102
|
+
cx: box.x + box.width / 2,
|
|
103
|
+
cy: box.y + box.height / 2,
|
|
104
|
+
r,
|
|
105
|
+
className: 'squisq-scene-connect-preview',
|
|
106
|
+
fill: 'none',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (shape === 'line') {
|
|
110
|
+
return createElement('line', {
|
|
111
|
+
key: 'shape-preview',
|
|
112
|
+
x1: drag.startV.x,
|
|
113
|
+
y1: drag.startV.y,
|
|
114
|
+
x2: drag.currentV.x,
|
|
115
|
+
y2: drag.currentV.y,
|
|
116
|
+
className: 'squisq-scene-connect-preview',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return createElement('rect', {
|
|
120
|
+
key: 'shape-preview',
|
|
121
|
+
x: box.x,
|
|
122
|
+
y: box.y,
|
|
123
|
+
width: box.width,
|
|
124
|
+
height: box.height,
|
|
125
|
+
rx: borderRadius,
|
|
126
|
+
ry: borderRadius,
|
|
127
|
+
className: 'squisq-scene-connect-preview',
|
|
128
|
+
fill: 'none',
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function boxFromCorners(
|
|
135
|
+
a: { x: number; y: number },
|
|
136
|
+
b: { x: number; y: number },
|
|
137
|
+
): { x: number; y: number; width: number; height: number } {
|
|
138
|
+
return {
|
|
139
|
+
x: Math.min(a.x, b.x),
|
|
140
|
+
y: Math.min(a.y, b.y),
|
|
141
|
+
width: Math.abs(b.x - a.x),
|
|
142
|
+
height: Math.abs(b.y - a.y),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TextTool — click to place a new TextLayer; the host can hook the
|
|
3
|
+
* `prompt` option to swap the default `window.prompt` for an inline
|
|
4
|
+
* editing UI (Tiptap, contenteditable, etc.) when one is available.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { TextLayer } from '@bendyline/squisq/schemas';
|
|
8
|
+
import type { SceneTool } from './SceneTool';
|
|
9
|
+
|
|
10
|
+
interface TextToolOptions {
|
|
11
|
+
/** Default font size in viewport units. Default 24. */
|
|
12
|
+
fontSize?: number;
|
|
13
|
+
/** Default text color. Default '#1e293b'. */
|
|
14
|
+
color?: string;
|
|
15
|
+
/** Default text alignment. Default 'left'. */
|
|
16
|
+
textAlign?: 'left' | 'center' | 'right';
|
|
17
|
+
/**
|
|
18
|
+
* Prompt the user for the text content. Returns null to cancel.
|
|
19
|
+
* Default uses `window.prompt`.
|
|
20
|
+
*/
|
|
21
|
+
prompt?: () => string | null;
|
|
22
|
+
/** Override id / label / shortcut. */
|
|
23
|
+
id?: string;
|
|
24
|
+
label?: string;
|
|
25
|
+
shortcut?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createTextTool(options: TextToolOptions = {}): SceneTool {
|
|
29
|
+
const fontSize = options.fontSize ?? 24;
|
|
30
|
+
const color = options.color ?? '#1e293b';
|
|
31
|
+
const textAlign = options.textAlign ?? 'left';
|
|
32
|
+
const prompt = options.prompt ?? (() => window.prompt('Text:'));
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
id: options.id ?? 'text',
|
|
36
|
+
label: options.label ?? 'Text',
|
|
37
|
+
cursor: 'text',
|
|
38
|
+
shortcut: options.shortcut ?? 't',
|
|
39
|
+
|
|
40
|
+
onPointerDown(e, ctx) {
|
|
41
|
+
if (e.button !== 0) return;
|
|
42
|
+
const rect = (e.currentTarget as Element).getBoundingClientRect();
|
|
43
|
+
const sx = e.clientX - rect.left;
|
|
44
|
+
const sy = e.clientY - rect.top;
|
|
45
|
+
const v = ctx.screenToViewport(sx, sy);
|
|
46
|
+
const text = prompt();
|
|
47
|
+
if (text == null || text.length === 0) {
|
|
48
|
+
ctx.setActiveTool?.('select');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const layer: TextLayer = {
|
|
52
|
+
id: `text-${Date.now().toString(36)}-${Math.floor(Math.random() * 1e6).toString(36)}`,
|
|
53
|
+
type: 'text',
|
|
54
|
+
position: {
|
|
55
|
+
x: v.x,
|
|
56
|
+
y: v.y,
|
|
57
|
+
// No explicit width — hit-test will treat the bounding box as
|
|
58
|
+
// measured at render time. Provide a generous default so the
|
|
59
|
+
// hit-test stub finds something.
|
|
60
|
+
width: Math.max(fontSize * text.length * 0.6, 80),
|
|
61
|
+
height: fontSize * 1.4,
|
|
62
|
+
},
|
|
63
|
+
content: {
|
|
64
|
+
text,
|
|
65
|
+
style: { fontSize, color, textAlign },
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
ctx.dispatch({ kind: 'addLayer', layer });
|
|
69
|
+
ctx.setActiveTool?.('select');
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TokenTool — pointer-down on the canvas drops a pre-filled
|
|
3
|
+
* placeholder layer at the click position. Used by the template
|
|
4
|
+
* designer's Add bin so the user can place `{title}`,
|
|
5
|
+
* `{content}`, `{children}`, or `{image:N}` in a single click instead
|
|
6
|
+
* of typing the placeholder string into a generic TextTool.
|
|
7
|
+
*
|
|
8
|
+
* Factory pattern (`createTokenTool`) lets the palette build a
|
|
9
|
+
* separate tool instance per token, each with its own id / label /
|
|
10
|
+
* default layer shape.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { ImageLayer, TextLayer } from '@bendyline/squisq/schemas';
|
|
14
|
+
import type { SceneTool } from './SceneTool';
|
|
15
|
+
import { createPlaceTool } from './PlaceTool';
|
|
16
|
+
|
|
17
|
+
export type TokenKind = 'text' | 'image';
|
|
18
|
+
|
|
19
|
+
export interface TokenToolOptions {
|
|
20
|
+
/** Stable tool id (e.g. `'token-title'`). */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Label shown in the toolbar / palette button. */
|
|
23
|
+
label: string;
|
|
24
|
+
/** Optional keyboard shortcut. */
|
|
25
|
+
shortcut?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The placeholder string to substitute at render time, e.g.
|
|
28
|
+
* `'{title}'` or `'{image:0}'`. The designer drops this literal
|
|
29
|
+
* value into the new layer; the resolver replaces it later.
|
|
30
|
+
*/
|
|
31
|
+
token: string;
|
|
32
|
+
/**
|
|
33
|
+
* Which layer kind to insert. `'text'` creates a TextLayer with
|
|
34
|
+
* `content.text = token`; `'image'` creates an ImageLayer with
|
|
35
|
+
* `content.src = token`.
|
|
36
|
+
*/
|
|
37
|
+
kind: TokenKind;
|
|
38
|
+
/** Default font size for text tokens. Default 36. */
|
|
39
|
+
fontSize?: number;
|
|
40
|
+
/** Default text color for text tokens. Default '#0f172a'. */
|
|
41
|
+
color?: string;
|
|
42
|
+
/** Default width (pixels) for the placed layer. Default 480. */
|
|
43
|
+
width?: number;
|
|
44
|
+
/** Default height (pixels) for the placed layer. Default for text: 72; for image: 320. */
|
|
45
|
+
height?: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Build a placeholder layer for `options` with its top-left corner at
|
|
50
|
+
* the given viewport point. Shared by the click-to-place TokenTool and
|
|
51
|
+
* the template designer's drag-and-drop drop handler so both produce
|
|
52
|
+
* identical layers.
|
|
53
|
+
*/
|
|
54
|
+
export function buildTokenLayer(
|
|
55
|
+
options: TokenToolOptions,
|
|
56
|
+
point: { x: number; y: number },
|
|
57
|
+
): TextLayer | ImageLayer {
|
|
58
|
+
const width = options.width ?? 480;
|
|
59
|
+
const height = options.height ?? (options.kind === 'image' ? 320 : 72);
|
|
60
|
+
const fontSize = options.fontSize ?? 36;
|
|
61
|
+
const color = options.color ?? '#0f172a';
|
|
62
|
+
const id = nextLayerId(options.kind);
|
|
63
|
+
if (options.kind === 'text') {
|
|
64
|
+
return {
|
|
65
|
+
id,
|
|
66
|
+
type: 'text',
|
|
67
|
+
position: { x: point.x, y: point.y, width, height },
|
|
68
|
+
content: {
|
|
69
|
+
text: options.token,
|
|
70
|
+
style: { fontSize, color, textAlign: 'left' },
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
id,
|
|
76
|
+
type: 'image',
|
|
77
|
+
position: { x: point.x, y: point.y, width, height },
|
|
78
|
+
content: { src: options.token, alt: 'Placeholder image', fit: 'cover' },
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function createTokenTool(options: TokenToolOptions): SceneTool {
|
|
83
|
+
return createPlaceTool({
|
|
84
|
+
id: options.id,
|
|
85
|
+
label: options.label,
|
|
86
|
+
shortcut: options.shortcut,
|
|
87
|
+
build: (point) => buildTokenLayer(options, point),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let counter = 0;
|
|
92
|
+
function nextLayerId(kind: TokenKind): string {
|
|
93
|
+
counter += 1;
|
|
94
|
+
return `${kind}-token-${Date.now().toString(36)}-${counter}`;
|
|
95
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createDrawShapeTool — drag to draw the currently-pending shape kind.
|
|
3
|
+
*
|
|
4
|
+
* Generalizes `ShapeTool` to any kind in the drawing vocabulary. The pending
|
|
5
|
+
* kind is read on demand (set by the ShapePalette), and committing calls back
|
|
6
|
+
* to the host with the kind + bounding box so the adapter can insert a
|
|
7
|
+
* `{[kind …]}` heading. The live preview renders the actual shape geometry.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { createElement, type JSX } from 'react';
|
|
11
|
+
import { shapePath } from '@bendyline/squisq/doc';
|
|
12
|
+
import type { SceneTool } from './SceneTool';
|
|
13
|
+
|
|
14
|
+
export interface DrawShapeOptions {
|
|
15
|
+
/** The kind to draw, or null when none is pending (tool is inert). */
|
|
16
|
+
getKind: () => string | null;
|
|
17
|
+
/** Commit a drawn shape. */
|
|
18
|
+
onDraw: (kind: string, box: { x: number; y: number; width: number; height: number }) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function createDrawShapeTool(options: DrawShapeOptions): SceneTool {
|
|
22
|
+
let drag: { start: { x: number; y: number }; current: { x: number; y: number } } | null = null;
|
|
23
|
+
|
|
24
|
+
function pointer(e: React.PointerEvent): { sx: number; sy: number } {
|
|
25
|
+
const rect = (e.currentTarget as Element).getBoundingClientRect();
|
|
26
|
+
return { sx: e.clientX - rect.left, sy: e.clientY - rect.top };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function box(): { x: number; y: number; width: number; height: number } {
|
|
30
|
+
const a = drag!.start;
|
|
31
|
+
const b = drag!.current;
|
|
32
|
+
return {
|
|
33
|
+
x: Math.min(a.x, b.x),
|
|
34
|
+
y: Math.min(a.y, b.y),
|
|
35
|
+
width: Math.abs(b.x - a.x),
|
|
36
|
+
height: Math.abs(b.y - a.y),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
id: 'draw',
|
|
42
|
+
label: 'Shape',
|
|
43
|
+
cursor: 'crosshair',
|
|
44
|
+
|
|
45
|
+
onPointerDown(e, ctx) {
|
|
46
|
+
if (e.button !== 0 || !options.getKind()) return;
|
|
47
|
+
const { sx, sy } = pointer(e);
|
|
48
|
+
const v = ctx.screenToViewport(sx, sy);
|
|
49
|
+
drag = { start: v, current: v };
|
|
50
|
+
(e.currentTarget as Element).setPointerCapture?.(e.pointerId);
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
onPointerMove(e, ctx) {
|
|
54
|
+
if (!drag) return;
|
|
55
|
+
const { sx, sy } = pointer(e);
|
|
56
|
+
drag.current = ctx.screenToViewport(sx, sy);
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
onPointerUp(e, ctx) {
|
|
60
|
+
if (!drag) return;
|
|
61
|
+
const b = box();
|
|
62
|
+
const kind = options.getKind();
|
|
63
|
+
drag = null;
|
|
64
|
+
(e.currentTarget as Element).releasePointerCapture?.(e.pointerId);
|
|
65
|
+
if (kind && b.width >= 4 && b.height >= 4) options.onDraw(kind, b);
|
|
66
|
+
ctx.setActiveTool?.('select');
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
renderOverlay(): JSX.Element | null {
|
|
70
|
+
if (!drag) return null;
|
|
71
|
+
const b = box();
|
|
72
|
+
const kind = options.getKind();
|
|
73
|
+
const d = kind ? shapePath(kind, b.x, b.y, b.width, b.height) : null;
|
|
74
|
+
return createElement('path', {
|
|
75
|
+
key: 'draw-preview',
|
|
76
|
+
d: d ?? `M ${b.x} ${b.y} h ${b.width} v ${b.height} h ${-b.width} Z`,
|
|
77
|
+
className: 'squisq-scene-connect-preview',
|
|
78
|
+
fill: 'none',
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code-context sections — host-supplied markdown blurbs rendered inside
|
|
3
|
+
* Monaco view zones above anchor lines (see src/codeContext/).
|
|
4
|
+
*
|
|
5
|
+
* The zone dom node lives in Monaco's `.view-zones` layer, which sits below
|
|
6
|
+
* `.view-lines` in hit-test order. Raising the zone's z-index inside that
|
|
7
|
+
* shared stacking context is what makes section content clickable; Monaco's
|
|
8
|
+
* own `suppressMouseDown` keeps the cursor from jumping.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
.squisq-ccx-zone {
|
|
12
|
+
z-index: 10;
|
|
13
|
+
pointer-events: auto;
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.squisq-ccx-section {
|
|
18
|
+
--ccx-fg: #57606a;
|
|
19
|
+
--ccx-fg-strong: #24292f;
|
|
20
|
+
--ccx-bg: rgba(175, 184, 193, 0.12);
|
|
21
|
+
--ccx-bg-hover: rgba(175, 184, 193, 0.22);
|
|
22
|
+
--ccx-border: rgba(140, 149, 159, 0.35);
|
|
23
|
+
--ccx-accent: #0969da;
|
|
24
|
+
font-family: var(--squisq-ux-font, system-ui, -apple-system, sans-serif);
|
|
25
|
+
font-size: 12px;
|
|
26
|
+
line-height: 1.45;
|
|
27
|
+
color: var(--ccx-fg);
|
|
28
|
+
border-left: 2px solid var(--ccx-border);
|
|
29
|
+
background: var(--ccx-bg);
|
|
30
|
+
margin: 2px 8px 2px 4px;
|
|
31
|
+
border-radius: 4px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.squisq-editor-shell[data-theme='dark'] .squisq-ccx-section {
|
|
35
|
+
--ccx-fg: #9198a1;
|
|
36
|
+
--ccx-fg-strong: #e6edf3;
|
|
37
|
+
--ccx-bg: rgba(110, 118, 129, 0.14);
|
|
38
|
+
--ccx-bg-hover: rgba(110, 118, 129, 0.26);
|
|
39
|
+
--ccx-border: rgba(110, 118, 129, 0.45);
|
|
40
|
+
--ccx-accent: #4493f8;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* ── Collapsed strip ─────────────────────────────────────────────── */
|
|
44
|
+
|
|
45
|
+
.squisq-ccx-strip {
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
gap: 6px;
|
|
49
|
+
width: 100%;
|
|
50
|
+
padding: 3px 10px;
|
|
51
|
+
border: none;
|
|
52
|
+
background: transparent;
|
|
53
|
+
color: inherit;
|
|
54
|
+
font: inherit;
|
|
55
|
+
text-align: left;
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
border-radius: 4px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.squisq-ccx-strip:hover {
|
|
61
|
+
background: var(--ccx-bg-hover);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.squisq-ccx-chevron {
|
|
65
|
+
flex: 0 0 auto;
|
|
66
|
+
font-size: 9px;
|
|
67
|
+
opacity: 0.7;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.squisq-ccx-strip-text {
|
|
71
|
+
flex: 1 1 auto;
|
|
72
|
+
min-width: 0;
|
|
73
|
+
white-space: nowrap;
|
|
74
|
+
overflow: hidden;
|
|
75
|
+
text-overflow: ellipsis;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* Flatten the strip's markdown to a single inline line. */
|
|
79
|
+
.squisq-ccx-strip-text .squisq-md,
|
|
80
|
+
.squisq-ccx-strip-text .squisq-md-p {
|
|
81
|
+
display: inline;
|
|
82
|
+
margin: 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.squisq-ccx-strip-text .squisq-md-strong {
|
|
86
|
+
color: var(--ccx-fg-strong);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* ── Expanded body ───────────────────────────────────────────────── */
|
|
90
|
+
|
|
91
|
+
.squisq-ccx-body {
|
|
92
|
+
padding: 2px 12px 8px 24px;
|
|
93
|
+
font-size: 12px;
|
|
94
|
+
user-select: text;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.squisq-ccx-body--loading {
|
|
98
|
+
opacity: 0.6;
|
|
99
|
+
font-style: italic;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.squisq-ccx-body .squisq-md-p {
|
|
103
|
+
margin: 4px 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.squisq-ccx-body .squisq-md-strong {
|
|
107
|
+
color: var(--ccx-fg-strong);
|
|
108
|
+
font-size: 11px;
|
|
109
|
+
text-transform: none;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.squisq-ccx-body .squisq-md-list {
|
|
113
|
+
margin: 2px 0 6px;
|
|
114
|
+
padding-left: 18px;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.squisq-ccx-body .squisq-md-li {
|
|
118
|
+
margin: 1px 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.squisq-ccx-body .squisq-md-link {
|
|
122
|
+
color: var(--ccx-accent);
|
|
123
|
+
text-decoration: none;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.squisq-ccx-body .squisq-md-link:hover {
|
|
127
|
+
text-decoration: underline;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.squisq-ccx-body .squisq-md-inline-code,
|
|
131
|
+
.squisq-ccx-body .squisq-md-link .squisq-md-inline-code {
|
|
132
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
133
|
+
font-size: 11px;
|
|
134
|
+
padding: 0 3px;
|
|
135
|
+
border-radius: 3px;
|
|
136
|
+
background: rgba(140, 149, 159, 0.18);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.squisq-ccx-body .squisq-md-link .squisq-md-inline-code {
|
|
140
|
+
color: var(--ccx-accent);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.squisq-ccx-body .squisq-md-code-block {
|
|
144
|
+
margin: 4px 0;
|
|
145
|
+
padding: 6px 8px;
|
|
146
|
+
border-radius: 4px;
|
|
147
|
+
background: rgba(140, 149, 159, 0.14);
|
|
148
|
+
overflow-x: auto;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.squisq-ccx-body .squisq-md-code-block code {
|
|
152
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
153
|
+
font-size: 11px;
|
|
154
|
+
white-space: pre;
|
|
155
|
+
}
|