@aglyn/besigner-ui 1.20.1 → 1.20.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/besigner-ui",
3
- "version": "1.20.1",
3
+ "version": "1.20.3",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,22 +25,22 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/aglyn": "1.20.1",
29
- "@aglyn/aglyn-markdown-editor": "1.20.1",
30
- "@aglyn/aglyn-node-renderer": "1.20.1",
31
- "@aglyn/besigner": "1.20.1",
32
- "@aglyn/shared-data-enums": "1.20.1",
33
- "@aglyn/shared-data-mdi": "1.20.1",
34
- "@aglyn/shared-data-types": "1.20.1",
35
- "@aglyn/shared-svg-icons": "1.20.1",
36
- "@aglyn/shared-ui-json-editor": "1.20.1",
37
- "@aglyn/shared-ui-jsx": "1.20.1",
38
- "@aglyn/shared-ui-jsx-forms": "1.20.1",
39
- "@aglyn/shared-ui-snackstack": "1.20.1",
40
- "@aglyn/shared-ui-theme": "1.20.1",
41
- "@aglyn/shared-util-dom": "1.20.1",
42
- "@aglyn/shared-util-tools": "1.20.1",
43
- "@aglyn/shared-util-vendor": "1.20.1",
28
+ "@aglyn/aglyn": "1.20.3",
29
+ "@aglyn/aglyn-markdown-editor": "1.20.3",
30
+ "@aglyn/aglyn-node-renderer": "1.20.3",
31
+ "@aglyn/besigner": "1.20.3",
32
+ "@aglyn/shared-data-enums": "1.20.3",
33
+ "@aglyn/shared-data-mdi": "1.20.3",
34
+ "@aglyn/shared-data-types": "1.20.3",
35
+ "@aglyn/shared-svg-icons": "1.20.3",
36
+ "@aglyn/shared-ui-json-editor": "1.20.3",
37
+ "@aglyn/shared-ui-jsx": "1.20.3",
38
+ "@aglyn/shared-ui-jsx-forms": "1.20.3",
39
+ "@aglyn/shared-ui-snackstack": "1.20.3",
40
+ "@aglyn/shared-ui-theme": "1.20.3",
41
+ "@aglyn/shared-util-dom": "1.20.3",
42
+ "@aglyn/shared-util-tools": "1.20.3",
43
+ "@aglyn/shared-util-vendor": "1.20.3",
44
44
  "@dnd-kit/core": "^6.3.1",
45
45
  "@dnd-kit/utilities": "^3.2.2",
46
46
  "@react-aria/utils": "^3.34.1",
@@ -21,11 +21,54 @@ import { MarkdownField } from "@aglyn/aglyn-markdown-editor";
21
21
  import * as Besigner from "@aglyn/besigner";
22
22
  import { Box, Button, Paper, Typography } from "@mui/material";
23
23
  import { observer } from "mobx-react-lite";
24
- import { useCallback, useEffect, useRef, useState } from "react";
24
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
25
25
  import { clampToViewport, useAnchoredRect } from "../hooks/use-anchored-rect.js";
26
26
  import { useDebouncedCommit } from "../hooks/use-debounced-commit.js";
27
27
  import { useMarkdownMediaPicker } from "../hooks/use-markdown-media-picker.js";
28
28
  import { inlineMarkdownEdit } from "../utils/inline-markdown-edit.store.js";
29
+ /** The canvas scroller: the box the editor is clipped to and scrolls. */ const CANVAS_VIEWPORT_ID = 'aglyn:viewport-canvas';
30
+ const NO_RECT = {
31
+ left: 0,
32
+ top: 0,
33
+ width: 0,
34
+ height: 0
35
+ };
36
+ /** The editor box's padding, `p: 1`. */ const PAPER_PADDING = 8;
37
+ /** An element's height, kept current as it resizes. */ function useMeasuredHeight() {
38
+ const [element, setElement] = useState(null);
39
+ const [height, setHeight] = useState(0);
40
+ useLayoutEffect(()=>{
41
+ if (!element) return undefined;
42
+ const update = ()=>setHeight(element.offsetHeight);
43
+ update();
44
+ const observer = typeof ResizeObserver === 'function' ? new ResizeObserver(update) : null;
45
+ observer == null ? void 0 : observer.observe(element);
46
+ return ()=>observer == null ? void 0 : observer.disconnect();
47
+ }, [
48
+ element
49
+ ]);
50
+ return [
51
+ setElement,
52
+ height
53
+ ];
54
+ }
55
+ /**
56
+ * Whether something between the wheel's target and the editor will scroll
57
+ * on its own in this direction: a wide table, a long snippet. Those keep the
58
+ * wheel; everything else hands it to the canvas.
59
+ */ function scrollsInside(target, root, deltaX, deltaY) {
60
+ let element = target instanceof Element ? target : null;
61
+ while(element && element !== root){
62
+ if (element instanceof HTMLElement) {
63
+ const style = getComputedStyle(element);
64
+ const canY = /auto|scroll/.test(style.overflowY) && element.scrollHeight > element.clientHeight && (deltaY > 0 ? element.scrollTop + element.clientHeight < element.scrollHeight : element.scrollTop > 0);
65
+ const canX = /auto|scroll/.test(style.overflowX) && element.scrollWidth > element.clientWidth && (deltaX > 0 ? element.scrollLeft + element.clientWidth < element.scrollWidth : element.scrollLeft > 0);
66
+ if (deltaY !== 0 && canY || deltaX !== 0 && canX) return true;
67
+ }
68
+ element = element.parentElement;
69
+ }
70
+ return false;
71
+ }
29
72
  /**
30
73
  * The mounted half. Everything that can lose an author's work lives here, and
31
74
  * it is deliberately the same machinery the attributes panel uses.
@@ -111,6 +154,7 @@ import { inlineMarkdownEdit } from "../utils/inline-markdown-edit.store.js";
111
154
  const handleDone = useCallback(()=>{
112
155
  inlineMarkdownEdit.close();
113
156
  }, []);
157
+ const label = String((_ref = node == null ? void 0 : (_node_componentSchema = node.componentSchema) == null ? void 0 : (_node_componentSchema_attributes = _node_componentSchema.attributes) == null ? void 0 : (_node_componentSchema_attributes_find = _node_componentSchema_attributes.find((attribute)=>(attribute == null ? void 0 : attribute.name) === attributeName)) == null ? void 0 : _node_componentSchema_attributes_find.label) != null ? _ref : 'Content');
114
158
  // A double-click inside the editor selects a word. It must never reach the
115
159
  // canvas, whose panning surface treats a double-click as zoom-in
116
160
  // (`ZoomablePanningComponent`). Node double-clicks are already consumed at
@@ -118,72 +162,155 @@ import { inlineMarkdownEdit } from "../utils/inline-markdown-edit.store.js";
118
162
  const stop = useCallback((event)=>{
119
163
  event.stopPropagation();
120
164
  }, []);
121
- // Read at render, which `useAnchoredRect` makes safe: it re-renders on every
122
- // scroll and resize, so these are never a stale snapshot.
123
- const viewportWidth = typeof window === 'undefined' ? Infinity : window.innerWidth;
124
- const viewportHeight = typeof window === 'undefined' ? Infinity : window.innerHeight;
125
- const width = Math.max(live.width, 360);
126
- // A long document is usually TALLER than the viewport, so the element's top
127
- // edge is frequently scrolled off the top of the screen while it is being
128
- // edited. The editor waits at the nearest edge until the element comes back
129
- // rather than following it out of sight; KEEP_VISIBLE is how much of it has
130
- // to remain reachable at the bottom.
131
- const KEEP_VISIBLE = 160;
165
+ /**
166
+ * The editor covers the element, all of it, and the canvas scrolls it
167
+ * (AGL-4216).
168
+ *
169
+ * It used to be a box capped at 75% of the screen that scrolled inside
170
+ * itself, inside an editor that also scrolled itself past 480px. Two scrolls
171
+ * deep, the toolbar was gone the moment the author scrolled to the part
172
+ * they wanted to change. Now the field grows with the document and lies
173
+ * over the element as it renders; the header and toolbar pin to the top of
174
+ * the canvas while any of it is in view and leave with its bottom edge, as
175
+ * a sticky header does on a page.
176
+ *
177
+ * It cannot be CSS sticky: the editor sits over the canvas in the overlay
178
+ * layer, not inside the scroller (whose artboard clips with `overflow:
179
+ * hidden`, which would switch sticky off anyway), so the offset is worked
180
+ * out from where the element is against the canvas's own top edge.
181
+ */ const [scroller, setScroller] = useState(null);
182
+ useEffect(()=>{
183
+ setScroller(document.getElementById(CANVAS_VIEWPORT_ID));
184
+ }, []);
185
+ const viewport = useAnchoredRect(scroller != null ? scroller : undefined, NO_RECT);
186
+ const [measureBox, boxHeight] = useMeasuredHeight();
187
+ const [measureGroup, groupHeight] = useMeasuredHeight();
188
+ // Scrolling over the editor scrolls the canvas under it. The editor is a
189
+ // fixed overlay, so the browser hands its wheel to the page instead: the
190
+ // document sat still and the designer's own chrome scrolled out of place.
191
+ // A native listener, because React registers wheel as passive and a
192
+ // passive listener cannot stop the page scrolling as well.
193
+ const [editorEl, setEditorEl] = useState(null);
194
+ useEffect(()=>{
195
+ if (!editorEl || !scroller) return undefined;
196
+ const onWheel = (event)=>{
197
+ if (event.ctrlKey) return;
198
+ if (scrollsInside(event.target, editorEl, event.deltaX, event.deltaY)) {
199
+ return;
200
+ }
201
+ event.preventDefault();
202
+ scroller.scrollBy({
203
+ left: event.deltaX,
204
+ top: event.deltaY
205
+ });
206
+ };
207
+ editorEl.addEventListener('wheel', onWheel, {
208
+ passive: false
209
+ });
210
+ return ()=>editorEl.removeEventListener('wheel', onWheel);
211
+ }, [
212
+ editorEl,
213
+ scroller
214
+ ]);
215
+ const clip = viewport.width > 0 ? viewport : null;
216
+ const area = clip != null ? clip : {
217
+ left: 0,
218
+ top: 0,
219
+ width: typeof window === 'undefined' ? Infinity : window.innerWidth,
220
+ height: typeof window === 'undefined' ? Infinity : window.innerHeight
221
+ };
222
+ const width = Math.min(Math.max(live.width, 360), area.width - 16);
223
+ const left = clampToViewport(live.left - area.left, width, area.width);
224
+ const top = live.top - area.top;
225
+ // Pinned flush with the canvas's top edge while the element's top is above
226
+ // it (the group rests 8px into the box, under its padding), and never past
227
+ // the element's bottom, where the box's bottom padding stays below it.
228
+ const toolbarOffset = Math.max(0, Math.min(-top - PAPER_PADDING, boxHeight - groupHeight - PAPER_PADDING * 2));
132
229
  return /*#__PURE__*/ _jsx(Box, {
133
- "data-aglyn": "overlay:inline-markdown-editor",
134
- "data-testid": "inline-markdown-editor",
135
- onKeyDown: handleKeyDown,
136
- onMouseDown: stop,
137
- onDoubleClick: stop,
230
+ "data-aglyn": "overlay:inline-markdown-clip",
138
231
  sx: {
139
232
  position: 'fixed',
140
- left: clampToViewport(live.left, width, viewportWidth),
141
- top: clampToViewport(live.top, KEEP_VISIBLE, viewportHeight),
142
- width,
143
- maxWidth: '90vw',
233
+ left: area.left,
234
+ top: area.top,
235
+ width: area.width,
236
+ height: area.height,
237
+ // The canvas's own edges: the part of the editor scrolled above the
238
+ // canvas must not paint over the designer's app bar.
239
+ overflow: 'hidden',
240
+ pointerEvents: 'none',
144
241
  zIndex: (theme)=>theme.zIndex.modal
145
242
  },
146
- children: /*#__PURE__*/ _jsxs(Paper, {
147
- elevation: 8,
243
+ children: /*#__PURE__*/ _jsx(Box, {
244
+ "data-aglyn": "overlay:inline-markdown-editor",
245
+ "data-testid": "inline-markdown-editor",
246
+ onKeyDown: handleKeyDown,
247
+ onMouseDown: stop,
248
+ onDoubleClick: stop,
249
+ ref: setEditorEl,
148
250
  sx: {
149
- p: 1,
150
- maxHeight: '75vh',
151
- overflowY: 'auto'
251
+ position: 'absolute',
252
+ left,
253
+ top,
254
+ width,
255
+ maxWidth: '90vw',
256
+ pointerEvents: 'auto'
152
257
  },
153
- children: [
154
- /*#__PURE__*/ _jsxs(Box, {
155
- sx: {
156
- display: 'flex',
157
- alignItems: 'center',
158
- justifyContent: 'space-between',
159
- mb: 0.5
160
- },
161
- children: [
162
- /*#__PURE__*/ _jsx(Typography, {
163
- variant: "caption",
164
- color: "text.secondary",
165
- children: 'Editing on the canvas — changes are kept as you type'
166
- }),
167
- /*#__PURE__*/ _jsx(Button, {
168
- size: "small",
169
- color: "primary",
170
- onClick: handleDone,
171
- children: 'Done'
172
- })
173
- ]
174
- }),
175
- /*#__PURE__*/ _jsx(MarkdownField, {
176
- label: String((_ref = node == null ? void 0 : (_node_componentSchema = node.componentSchema) == null ? void 0 : (_node_componentSchema_attributes = _node_componentSchema.attributes) == null ? void 0 : (_node_componentSchema_attributes_find = _node_componentSchema_attributes.find((attribute)=>(attribute == null ? void 0 : attribute.name) === attributeName)) == null ? void 0 : _node_componentSchema_attributes_find.label) != null ? _ref : 'Content'),
258
+ children: /*#__PURE__*/ _jsx(Paper, {
259
+ ref: measureBox,
260
+ elevation: 8,
261
+ sx: {
262
+ p: 1
263
+ },
264
+ children: /*#__PURE__*/ _jsx(MarkdownField, {
265
+ label: label,
177
266
  value: value,
178
267
  onChange: handleChange,
179
268
  editorRef: editorRef,
180
269
  onPickImageFromMedia: onPickImageFromMedia,
181
- // The OPEN rect, deliberately, not the live one: position follows the
182
- // element, but the editor's own height must not change under the
183
- // author mid-sentence just because the canvas relaid out.
184
- minHeight: Math.min(Math.max(rect.height, 200), 520)
270
+ toolbarOffset: toolbarOffset,
271
+ toolbarGroupRef: measureGroup,
272
+ toolbarHeader: /*#__PURE__*/ _jsxs(Box, {
273
+ sx: {
274
+ display: 'flex',
275
+ alignItems: 'center',
276
+ justifyContent: 'space-between',
277
+ gap: 1,
278
+ pb: 0.5
279
+ },
280
+ children: [
281
+ /*#__PURE__*/ _jsxs(Typography, {
282
+ variant: "caption",
283
+ color: "text.secondary",
284
+ noWrap: true,
285
+ children: [
286
+ /*#__PURE__*/ _jsx(Box, {
287
+ component: "span",
288
+ sx: {
289
+ color: 'text.primary',
290
+ fontWeight: 600
291
+ },
292
+ children: label
293
+ }),
294
+ ' · editing on the canvas — changes are kept as you type'
295
+ ]
296
+ }),
297
+ /*#__PURE__*/ _jsx(Button, {
298
+ size: "small",
299
+ color: "primary",
300
+ onClick: handleDone,
301
+ children: 'Done'
302
+ })
303
+ ]
304
+ }),
305
+ // The editor grows with the document instead of scrolling inside
306
+ // itself, and starts at least as tall as the element it covers so
307
+ // nothing of the rendered element shows around it. The OPEN rect,
308
+ // deliberately: the height must not change under the author
309
+ // mid-sentence just because the canvas relaid out.
310
+ maxHeight: "none",
311
+ minHeight: Math.max(rect.height - groupHeight - 24, 200)
185
312
  })
186
- ]
313
+ })
187
314
  })
188
315
  });
189
316
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/besigner/feature/designer/src/lib/components/inline-markdown-editor.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport type * as Aglyn from '@aglyn/aglyn'\nimport { canvas } from '@aglyn/aglyn'\nimport { MarkdownField } from '@aglyn/aglyn-markdown-editor'\nimport * as Besigner from '@aglyn/besigner'\nimport { Box, Button, Paper, Typography } from '@mui/material'\nimport { observer } from 'mobx-react-lite'\nimport {\n type KeyboardEvent,\n type MouseEvent,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react'\nimport {\n clampToViewport,\n useAnchoredRect,\n} from '../hooks/use-anchored-rect'\nimport { useDebouncedCommit } from '../hooks/use-debounced-commit'\nimport { useMarkdownMediaPicker } from '../hooks/use-markdown-media-picker'\nimport {\n inlineMarkdownEdit,\n type InlineMarkdownEditRect,\n} from '../utils/inline-markdown-edit.store'\n\ninterface SurfaceProps {\n node: Aglyn.NodeSchema<any>\n rect: InlineMarkdownEditRect\n /** The element `rect` was measured from, re-measured as the canvas moves. */\n anchor?: Element\n attributeName: string\n initialValue: string\n /** Whether the canvas selection still names the node being edited. */\n selected: boolean\n}\n\n/**\n * The mounted half. Everything that can lose an author's work lives here, and\n * it is deliberately the same machinery the attributes panel uses.\n *\n * ## When the edit reaches the model\n *\n * `MarkdownVisualEditor` emits on every input event, so the newest string is\n * always in hand. From there this is `useDebouncedCommit` (AGL-567), exactly as\n * the panel wires it: a 250 ms trailing debounce, plus the hook's own\n * flush-on-unmount. Every way of leaving the editor unmounts this component —\n * Done, Escape, the selection moving to another node, the screen changing, the\n * designer closing — so every exit path flushes. There is NO discard path, and\n * that is the point: with a debounced commit a \"cancel\" could only ever throw\n * away the last 250 ms of a document that is otherwise already written, which\n * is a worse lie than committing and leaving Cmd+Z to do the undoing.\n *\n * What is deliberately NOT here is a commit on blur. The toolbar, the link\n * popover and the URL dialog all move focus (two of them into a portal), so a\n * blur-committed local draft would strand everything typed since the previous\n * focus change — silently, with the canvas still showing the right text. The\n * panel's wrapper learned this the same way (AGL-1616).\n *\n * ## Why the value is not re-derived\n *\n * `initialValue` seeds local state once and the node's props are never read\n * back into the editor. The editor re-parses its row model whenever the\n * incoming value differs from the string it last emitted, resetting undo and\n * the caret; feeding a commit — or a co-editing peer's write — back in would do\n * that mid-sentence.\n */\nconst InlineMarkdownEditorSurface = observer(function InlineMarkdownEditorSurface(\n props: SurfaceProps,\n) {\n const { node, rect, anchor, attributeName, initialValue, selected } = props\n // Follows the element as the canvas scrolls or resizes (AGL-1644).\n const live = useAnchoredRect(anchor, rect)\n const [value, setValue] = useState(initialValue)\n const latestRef = useRef(initialValue)\n const committedRef = useRef(initialValue)\n // The toolbar's image action opens the host's media library rather than a\n // \"paste a URL\" prompt (AGL-1645). The picker is a modal that takes focus,\n // which is exactly what a blur-committed editor cannot survive — and the\n // reason this one commits on a debounce instead is written out above.\n const { editorRef, onPickImageFromMedia } = useMarkdownMediaPicker()\n\n const commit = useCallback(() => {\n const current = inlineMarkdownEdit.node ?? node\n if (!current) return\n if (latestRef.current === committedRef.current) return\n committedRef.current = latestRef.current\n // Read the node's props at commit time, not at open: `updateNodeProps`\n // REPLACES the props object, so anything a peer or the panel changed while\n // the editor was open has to be spread from the live node.\n canvas.updateNodeProps(current, {\n ...current.props,\n [attributeName]: latestRef.current,\n })\n }, [attributeName, node])\n\n const { schedule } = useDebouncedCommit(commit)\n\n const handleChange = useCallback(\n (next: string) => {\n latestRef.current = next\n setValue(next)\n schedule()\n },\n [schedule],\n )\n\n // The edit follows the selection: the double-click's own mousedown selected\n // this node, so the selection moving off it (another node, the hierarchy\n // tree, a click on empty canvas) means the author is done here. Closing\n // unmounts this surface, which flushes.\n useEffect(() => {\n if (!selected) inlineMarkdownEdit.close()\n }, [selected])\n\n const handleKeyDown = useCallback((event: KeyboardEvent<HTMLDivElement>) => {\n if (event.key !== 'Escape') return\n // Escape CLOSES and keeps. It is not a cancel — see the commit note above.\n event.stopPropagation()\n inlineMarkdownEdit.close()\n }, [])\n\n const handleDone = useCallback(() => {\n inlineMarkdownEdit.close()\n }, [])\n\n // A double-click inside the editor selects a word. It must never reach the\n // canvas, whose panning surface treats a double-click as zoom-in\n // (`ZoomablePanningComponent`). Node double-clicks are already consumed at\n // the leaf; this covers the overlay that sits on top of it.\n const stop = useCallback((event: MouseEvent) => {\n event.stopPropagation()\n }, [])\n\n // Read at render, which `useAnchoredRect` makes safe: it re-renders on every\n // scroll and resize, so these are never a stale snapshot.\n const viewportWidth =\n typeof window === 'undefined' ? Infinity : window.innerWidth\n const viewportHeight =\n typeof window === 'undefined' ? Infinity : window.innerHeight\n const width = Math.max(live.width, 360)\n // A long document is usually TALLER than the viewport, so the element's top\n // edge is frequently scrolled off the top of the screen while it is being\n // edited. The editor waits at the nearest edge until the element comes back\n // rather than following it out of sight; KEEP_VISIBLE is how much of it has\n // to remain reachable at the bottom.\n const KEEP_VISIBLE = 160\n\n return (\n <Box\n data-aglyn=\"overlay:inline-markdown-editor\"\n data-testid=\"inline-markdown-editor\"\n onKeyDown={handleKeyDown}\n onMouseDown={stop}\n onDoubleClick={stop}\n sx={{\n position: 'fixed',\n left: clampToViewport(live.left, width, viewportWidth),\n top: clampToViewport(live.top, KEEP_VISIBLE, viewportHeight),\n width,\n maxWidth: '90vw',\n zIndex: (theme) => theme.zIndex.modal,\n }}\n >\n <Paper elevation={8} sx={{ p: 1, maxHeight: '75vh', overflowY: 'auto' }}>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n mb: 0.5,\n }}\n >\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Editing on the canvas — changes are kept as you type'}\n </Typography>\n <Button size=\"small\" color=\"primary\" onClick={handleDone}>\n {'Done'}\n </Button>\n </Box>\n <MarkdownField\n label={String(\n node?.componentSchema?.attributes?.find(\n (attribute) => attribute?.name === attributeName,\n )?.label ?? 'Content',\n )}\n value={value}\n onChange={handleChange}\n editorRef={editorRef}\n onPickImageFromMedia={onPickImageFromMedia}\n // The OPEN rect, deliberately, not the live one: position follows the\n // element, but the editor's own height must not change under the\n // author mid-sentence just because the canvas relaid out.\n minHeight={Math.min(Math.max(rect.height, 200), 520)}\n />\n </Paper>\n </Box>\n )\n})\nInlineMarkdownEditorSurface.displayName = 'InlineMarkdownEditorSurface'\n\n/**\n * In-place markdown editing on the besigner canvas (AGL-1624).\n *\n * Double-clicking a component whose schema declares a `FieldComponentType\n * .MARKDOWN` attribute opens the WYSIWYG over the element instead of sending\n * the author to the attributes panel — the canvas half of AGL-1616, which\n * shipped the panel half.\n *\n * Mounted once next to `InlineTextEditorComponent` in the viewport overlays,\n * outside the closed canvas shadow root, so it positions in screen\n * coordinates. `key`ed on the node so switching nodes remounts the surface,\n * which is what turns every close into a flush.\n */\nexport const InlineMarkdownEditorComponent = observer(\n function InlineMarkdownEditorComponent() {\n const node = inlineMarkdownEdit.node\n const rect = inlineMarkdownEdit.rect\n const attributeName = inlineMarkdownEdit.attributeName\n if (!node || !rect || !attributeName) return null\n return (\n <InlineMarkdownEditorSurface\n key={`${node.$id}:${attributeName}`}\n node={node}\n rect={rect}\n anchor={inlineMarkdownEdit.anchor}\n attributeName={attributeName}\n initialValue={inlineMarkdownEdit.initialValue}\n selected={Besigner.focus.isNodeSelected(node)}\n />\n )\n },\n)\nInlineMarkdownEditorComponent.displayName = 'InlineMarkdownEditorComponent'\n\nexport default InlineMarkdownEditorComponent\n"],"names":["canvas","MarkdownField","Besigner","Box","Button","Paper","Typography","observer","useCallback","useEffect","useRef","useState","clampToViewport","useAnchoredRect","useDebouncedCommit","useMarkdownMediaPicker","inlineMarkdownEdit","InlineMarkdownEditorSurface","props","node","rect","anchor","attributeName","initialValue","selected","live","value","setValue","latestRef","committedRef","editorRef","onPickImageFromMedia","commit","current","updateNodeProps","schedule","handleChange","next","close","handleKeyDown","event","key","stopPropagation","handleDone","stop","viewportWidth","window","Infinity","innerWidth","viewportHeight","innerHeight","width","Math","max","KEEP_VISIBLE","data-aglyn","data-testid","onKeyDown","onMouseDown","onDoubleClick","sx","position","left","top","maxWidth","zIndex","theme","modal","elevation","p","maxHeight","overflowY","display","alignItems","justifyContent","mb","variant","color","size","onClick","label","String","componentSchema","attributes","find","attribute","name","onChange","minHeight","min","height","displayName","InlineMarkdownEditorComponent","focus","isNodeSelected","$id"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAGA,SAASA,MAAM,QAAQ,eAAc;AACrC,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,YAAYC,cAAc,kBAAiB;AAC3C,SAASC,GAAG,EAAEC,MAAM,EAAEC,KAAK,EAAEC,UAAU,QAAQ,gBAAe;AAC9D,SAASC,QAAQ,QAAQ,kBAAiB;AAC1C,SAGEC,WAAW,EACXC,SAAS,EACTC,MAAM,EACNC,QAAQ,QACH,QAAO;AACd,SACEC,eAAe,EACfC,eAAe,QACV,gCAA4B;AACnC,SAASC,kBAAkB,QAAQ,mCAA+B;AAClE,SAASC,sBAAsB,QAAQ,wCAAoC;AAC3E,SACEC,kBAAkB,QAEb,yCAAqC;AAa5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BC,GACD,MAAMC,8BAA8BV,SAAS,SAASU,4BACpDC,KAAmB;;QAkHTC,uCAAAA,kCAAAA;IAhHV,MAAM,EAAEA,IAAI,EAAEC,IAAI,EAAEC,MAAM,EAAEC,aAAa,EAAEC,YAAY,EAAEC,QAAQ,EAAE,GAAGN;IACtE,mEAAmE;IACnE,MAAMO,OAAOZ,gBAAgBQ,QAAQD;IACrC,MAAM,CAACM,OAAOC,SAAS,GAAGhB,SAASY;IACnC,MAAMK,YAAYlB,OAAOa;IACzB,MAAMM,eAAenB,OAAOa;IAC5B,0EAA0E;IAC1E,2EAA2E;IAC3E,yEAAyE;IACzE,sEAAsE;IACtE,MAAM,EAAEO,SAAS,EAAEC,oBAAoB,EAAE,GAAGhB;IAE5C,MAAMiB,SAASxB,YAAY;YACTQ;QAAhB,MAAMiB,WAAUjB,2BAAAA,mBAAmBG,IAAI,YAAvBH,2BAA2BG;QAC3C,IAAI,CAACc,SAAS;QACd,IAAIL,UAAUK,OAAO,KAAKJ,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aAAa;IACtD,IAAI,CAACH,QAAQ,CAACC,QAAQ,CAACE,eAAe,OAAO;IAC7C,qBACE,KAACL;QAECE,MAAMA;QACNC,MAAMA;QACNC,QAAQL,mBAAmBK,MAAM;QACjCC,eAAeA;QACfC,cAAcP,mBAAmBO,YAAY;QAC7CC,UAAUtB,SAAS2F,KAAK,CAACC,cAAc,CAAC3E;OANnC,GAAGA,KAAK4E,GAAG,CAAC,CAAC,EAAEzE,eAAe;AASzC,GACD;AACDsE,8BAA8BD,WAAW,GAAG;AAE5C,eAAeC,8BAA6B"}
1
+ {"version":3,"sources":["../../../../../../../../libs/besigner/feature/designer/src/lib/components/inline-markdown-editor.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport type * as Aglyn from '@aglyn/aglyn'\nimport { canvas } from '@aglyn/aglyn'\nimport { MarkdownField } from '@aglyn/aglyn-markdown-editor'\nimport * as Besigner from '@aglyn/besigner'\nimport { Box, Button, Paper, Typography } from '@mui/material'\nimport { observer } from 'mobx-react-lite'\nimport {\n type KeyboardEvent,\n type MouseEvent,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react'\nimport {\n clampToViewport,\n useAnchoredRect,\n} from '../hooks/use-anchored-rect'\nimport { useDebouncedCommit } from '../hooks/use-debounced-commit'\nimport { useMarkdownMediaPicker } from '../hooks/use-markdown-media-picker'\nimport {\n inlineMarkdownEdit,\n type InlineMarkdownEditRect,\n} from '../utils/inline-markdown-edit.store'\n\n/** The canvas scroller: the box the editor is clipped to and scrolls. */\nconst CANVAS_VIEWPORT_ID = 'aglyn:viewport-canvas'\nconst NO_RECT = { left: 0, top: 0, width: 0, height: 0 }\n/** The editor box's padding, `p: 1`. */\nconst PAPER_PADDING = 8\n\n/** An element's height, kept current as it resizes. */\nfunction useMeasuredHeight(): [(element: HTMLElement | null) => void, number] {\n const [element, setElement] = useState<HTMLElement | null>(null)\n const [height, setHeight] = useState(0)\n useLayoutEffect(() => {\n if (!element) return undefined\n const update = () => setHeight(element.offsetHeight)\n update()\n const observer =\n typeof ResizeObserver === 'function' ? new ResizeObserver(update) : null\n observer?.observe(element)\n return () => observer?.disconnect()\n }, [element])\n return [setElement, height]\n}\n\n/**\n * Whether something between the wheel's target and the editor will scroll\n * on its own in this direction: a wide table, a long snippet. Those keep the\n * wheel; everything else hands it to the canvas.\n */\nfunction scrollsInside(\n target: EventTarget | null,\n root: Element,\n deltaX: number,\n deltaY: number,\n): boolean {\n let element = target instanceof Element ? target : null\n while (element && element !== root) {\n if (element instanceof HTMLElement) {\n const style = getComputedStyle(element)\n const canY =\n /auto|scroll/.test(style.overflowY) &&\n element.scrollHeight > element.clientHeight &&\n (deltaY > 0\n ? element.scrollTop + element.clientHeight < element.scrollHeight\n : element.scrollTop > 0)\n const canX =\n /auto|scroll/.test(style.overflowX) &&\n element.scrollWidth > element.clientWidth &&\n (deltaX > 0\n ? element.scrollLeft + element.clientWidth < element.scrollWidth\n : element.scrollLeft > 0)\n if ((deltaY !== 0 && canY) || (deltaX !== 0 && canX)) return true\n }\n element = element.parentElement\n }\n return false\n}\n\ninterface SurfaceProps {\n node: Aglyn.NodeSchema<any>\n rect: InlineMarkdownEditRect\n /** The element `rect` was measured from, re-measured as the canvas moves. */\n anchor?: Element\n attributeName: string\n initialValue: string\n /** Whether the canvas selection still names the node being edited. */\n selected: boolean\n}\n\n/**\n * The mounted half. Everything that can lose an author's work lives here, and\n * it is deliberately the same machinery the attributes panel uses.\n *\n * ## When the edit reaches the model\n *\n * `MarkdownVisualEditor` emits on every input event, so the newest string is\n * always in hand. From there this is `useDebouncedCommit` (AGL-567), exactly as\n * the panel wires it: a 250 ms trailing debounce, plus the hook's own\n * flush-on-unmount. Every way of leaving the editor unmounts this component —\n * Done, Escape, the selection moving to another node, the screen changing, the\n * designer closing — so every exit path flushes. There is NO discard path, and\n * that is the point: with a debounced commit a \"cancel\" could only ever throw\n * away the last 250 ms of a document that is otherwise already written, which\n * is a worse lie than committing and leaving Cmd+Z to do the undoing.\n *\n * What is deliberately NOT here is a commit on blur. The toolbar, the link\n * popover and the URL dialog all move focus (two of them into a portal), so a\n * blur-committed local draft would strand everything typed since the previous\n * focus change — silently, with the canvas still showing the right text. The\n * panel's wrapper learned this the same way (AGL-1616).\n *\n * ## Why the value is not re-derived\n *\n * `initialValue` seeds local state once and the node's props are never read\n * back into the editor. The editor re-parses its row model whenever the\n * incoming value differs from the string it last emitted, resetting undo and\n * the caret; feeding a commit — or a co-editing peer's write — back in would do\n * that mid-sentence.\n */\nconst InlineMarkdownEditorSurface = observer(function InlineMarkdownEditorSurface(\n props: SurfaceProps,\n) {\n const { node, rect, anchor, attributeName, initialValue, selected } = props\n // Follows the element as the canvas scrolls or resizes (AGL-1644).\n const live = useAnchoredRect(anchor, rect)\n const [value, setValue] = useState(initialValue)\n const latestRef = useRef(initialValue)\n const committedRef = useRef(initialValue)\n // The toolbar's image action opens the host's media library rather than a\n // \"paste a URL\" prompt (AGL-1645). The picker is a modal that takes focus,\n // which is exactly what a blur-committed editor cannot survive — and the\n // reason this one commits on a debounce instead is written out above.\n const { editorRef, onPickImageFromMedia } = useMarkdownMediaPicker()\n\n const commit = useCallback(() => {\n const current = inlineMarkdownEdit.node ?? node\n if (!current) return\n if (latestRef.current === committedRef.current) return\n committedRef.current = latestRef.current\n // Read the node's props at commit time, not at open: `updateNodeProps`\n // REPLACES the props object, so anything a peer or the panel changed while\n // the editor was open has to be spread from the live node.\n canvas.updateNodeProps(current, {\n ...current.props,\n [attributeName]: latestRef.current,\n })\n }, [attributeName, node])\n\n const { schedule } = useDebouncedCommit(commit)\n\n const handleChange = useCallback(\n (next: string) => {\n latestRef.current = next\n setValue(next)\n schedule()\n },\n [schedule],\n )\n\n // The edit follows the selection: the double-click's own mousedown selected\n // this node, so the selection moving off it (another node, the hierarchy\n // tree, a click on empty canvas) means the author is done here. Closing\n // unmounts this surface, which flushes.\n useEffect(() => {\n if (!selected) inlineMarkdownEdit.close()\n }, [selected])\n\n const handleKeyDown = useCallback((event: KeyboardEvent<HTMLDivElement>) => {\n if (event.key !== 'Escape') return\n // Escape CLOSES and keeps. It is not a cancel — see the commit note above.\n event.stopPropagation()\n inlineMarkdownEdit.close()\n }, [])\n\n const handleDone = useCallback(() => {\n inlineMarkdownEdit.close()\n }, [])\n\n const label = String(\n node?.componentSchema?.attributes?.find(\n (attribute) => attribute?.name === attributeName,\n )?.label ?? 'Content',\n )\n\n // A double-click inside the editor selects a word. It must never reach the\n // canvas, whose panning surface treats a double-click as zoom-in\n // (`ZoomablePanningComponent`). Node double-clicks are already consumed at\n // the leaf; this covers the overlay that sits on top of it.\n const stop = useCallback((event: MouseEvent) => {\n event.stopPropagation()\n }, [])\n\n /**\n * The editor covers the element, all of it, and the canvas scrolls it\n * (AGL-4216).\n *\n * It used to be a box capped at 75% of the screen that scrolled inside\n * itself, inside an editor that also scrolled itself past 480px. Two scrolls\n * deep, the toolbar was gone the moment the author scrolled to the part\n * they wanted to change. Now the field grows with the document and lies\n * over the element as it renders; the header and toolbar pin to the top of\n * the canvas while any of it is in view and leave with its bottom edge, as\n * a sticky header does on a page.\n *\n * It cannot be CSS sticky: the editor sits over the canvas in the overlay\n * layer, not inside the scroller (whose artboard clips with `overflow:\n * hidden`, which would switch sticky off anyway), so the offset is worked\n * out from where the element is against the canvas's own top edge.\n */\n const [scroller, setScroller] = useState<HTMLElement | null>(null)\n useEffect(() => {\n setScroller(document.getElementById(CANVAS_VIEWPORT_ID))\n }, [])\n const viewport = useAnchoredRect(scroller ?? undefined, NO_RECT)\n const [measureBox, boxHeight] = useMeasuredHeight()\n const [measureGroup, groupHeight] = useMeasuredHeight()\n\n // Scrolling over the editor scrolls the canvas under it. The editor is a\n // fixed overlay, so the browser hands its wheel to the page instead: the\n // document sat still and the designer's own chrome scrolled out of place.\n // A native listener, because React registers wheel as passive and a\n // passive listener cannot stop the page scrolling as well.\n const [editorEl, setEditorEl] = useState<HTMLDivElement | null>(null)\n useEffect(() => {\n if (!editorEl || !scroller) return undefined\n const onWheel = (event: globalThis.WheelEvent) => {\n if (event.ctrlKey) return\n if (scrollsInside(event.target, editorEl, event.deltaX, event.deltaY)) {\n return\n }\n event.preventDefault()\n scroller.scrollBy({ left: event.deltaX, top: event.deltaY })\n }\n editorEl.addEventListener('wheel', onWheel, { passive: false })\n return () => editorEl.removeEventListener('wheel', onWheel)\n }, [editorEl, scroller])\n\n const clip = viewport.width > 0 ? viewport : null\n const area = clip ?? {\n left: 0,\n top: 0,\n width: typeof window === 'undefined' ? Infinity : window.innerWidth,\n height: typeof window === 'undefined' ? Infinity : window.innerHeight,\n }\n const width = Math.min(Math.max(live.width, 360), area.width - 16)\n const left = clampToViewport(live.left - area.left, width, area.width)\n const top = live.top - area.top\n // Pinned flush with the canvas's top edge while the element's top is above\n // it (the group rests 8px into the box, under its padding), and never past\n // the element's bottom, where the box's bottom padding stays below it.\n const toolbarOffset = Math.max(\n 0,\n Math.min(-top - PAPER_PADDING, boxHeight - groupHeight - PAPER_PADDING * 2),\n )\n\n return (\n <Box\n data-aglyn=\"overlay:inline-markdown-clip\"\n sx={{\n position: 'fixed',\n left: area.left,\n top: area.top,\n width: area.width,\n height: area.height,\n // The canvas's own edges: the part of the editor scrolled above the\n // canvas must not paint over the designer's app bar.\n overflow: 'hidden',\n pointerEvents: 'none',\n zIndex: (theme) => theme.zIndex.modal,\n }}\n >\n <Box\n data-aglyn=\"overlay:inline-markdown-editor\"\n data-testid=\"inline-markdown-editor\"\n onKeyDown={handleKeyDown}\n onMouseDown={stop}\n onDoubleClick={stop}\n ref={setEditorEl}\n sx={{\n position: 'absolute',\n left,\n top,\n width,\n maxWidth: '90vw',\n pointerEvents: 'auto',\n }}\n >\n <Paper ref={measureBox} elevation={8} sx={{ p: 1 }}>\n <MarkdownField\n label={label}\n value={value}\n onChange={handleChange}\n editorRef={editorRef}\n onPickImageFromMedia={onPickImageFromMedia}\n toolbarOffset={toolbarOffset}\n toolbarGroupRef={measureGroup}\n toolbarHeader={\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: 1,\n pb: 0.5,\n }}\n >\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap>\n <Box component=\"span\" sx={{ color: 'text.primary', fontWeight: 600 }}>\n {label}\n </Box>\n {' · editing on the canvas — changes are kept as you type'}\n </Typography>\n <Button size=\"small\" color=\"primary\" onClick={handleDone}>\n {'Done'}\n </Button>\n </Box>\n }\n // The editor grows with the document instead of scrolling inside\n // itself, and starts at least as tall as the element it covers so\n // nothing of the rendered element shows around it. The OPEN rect,\n // deliberately: the height must not change under the author\n // mid-sentence just because the canvas relaid out.\n maxHeight=\"none\"\n minHeight={Math.max(rect.height - groupHeight - 24, 200)}\n />\n </Paper>\n </Box>\n </Box>\n )\n})\nInlineMarkdownEditorSurface.displayName = 'InlineMarkdownEditorSurface'\n\n/**\n * In-place markdown editing on the besigner canvas (AGL-1624).\n *\n * Double-clicking a component whose schema declares a `FieldComponentType\n * .MARKDOWN` attribute opens the WYSIWYG over the element instead of sending\n * the author to the attributes panel — the canvas half of AGL-1616, which\n * shipped the panel half.\n *\n * Mounted once next to `InlineTextEditorComponent` in the viewport overlays,\n * outside the closed canvas shadow root, so it positions in screen\n * coordinates. `key`ed on the node so switching nodes remounts the surface,\n * which is what turns every close into a flush.\n */\nexport const InlineMarkdownEditorComponent = observer(\n function InlineMarkdownEditorComponent() {\n const node = inlineMarkdownEdit.node\n const rect = inlineMarkdownEdit.rect\n const attributeName = inlineMarkdownEdit.attributeName\n if (!node || !rect || !attributeName) return null\n return (\n <InlineMarkdownEditorSurface\n key={`${node.$id}:${attributeName}`}\n node={node}\n rect={rect}\n anchor={inlineMarkdownEdit.anchor}\n attributeName={attributeName}\n initialValue={inlineMarkdownEdit.initialValue}\n selected={Besigner.focus.isNodeSelected(node)}\n />\n )\n },\n)\nInlineMarkdownEditorComponent.displayName = 'InlineMarkdownEditorComponent'\n\nexport default InlineMarkdownEditorComponent\n"],"names":["canvas","MarkdownField","Besigner","Box","Button","Paper","Typography","observer","useCallback","useEffect","useLayoutEffect","useRef","useState","clampToViewport","useAnchoredRect","useDebouncedCommit","useMarkdownMediaPicker","inlineMarkdownEdit","CANVAS_VIEWPORT_ID","NO_RECT","left","top","width","height","PAPER_PADDING","useMeasuredHeight","element","setElement","setHeight","undefined","update","offsetHeight","ResizeObserver","observe","disconnect","scrollsInside","target","root","deltaX","deltaY","Element","HTMLElement","style","getComputedStyle","canY","test","overflowY","scrollHeight","clientHeight","scrollTop","canX","overflowX","scrollWidth","clientWidth","scrollLeft","parentElement","InlineMarkdownEditorSurface","props","node","rect","anchor","attributeName","initialValue","selected","live","value","setValue","latestRef","committedRef","editorRef","onPickImageFromMedia","commit","current","updateNodeProps","schedule","handleChange","next","close","handleKeyDown","event","key","stopPropagation","handleDone","label","String","componentSchema","attributes","find","attribute","name","stop","scroller","setScroller","document","getElementById","viewport","measureBox","boxHeight","measureGroup","groupHeight","editorEl","setEditorEl","onWheel","ctrlKey","preventDefault","scrollBy","addEventListener","passive","removeEventListener","clip","area","window","Infinity","innerWidth","innerHeight","Math","min","max","toolbarOffset","data-aglyn","sx","position","overflow","pointerEvents","zIndex","theme","modal","data-testid","onKeyDown","onMouseDown","onDoubleClick","ref","maxWidth","elevation","p","onChange","toolbarGroupRef","toolbarHeader","display","alignItems","justifyContent","gap","pb","variant","color","noWrap","component","fontWeight","size","onClick","maxHeight","minHeight","displayName","InlineMarkdownEditorComponent","focus","isNodeSelected","$id"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,G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AEF;;;0CAEH,KAAC/E;gCAAOgJ,MAAK;gCAAQJ,OAAM;gCAAUK,SAASnE;0CAC3C;;;;oBAIP,iEAAiE;oBACjE,kEAAkE;oBAClE,kEAAkE;oBAClE,4DAA4D;oBAC5D,mDAAmD;oBACnDoE,WAAU;oBACVC,WAAWpC,KAAKE,GAAG,CAAC1D,KAAKpC,MAAM,GAAG4E,cAAc,IAAI;;;;;AAMhE;AACA3C,4BAA4BgG,WAAW,GAAG;AAE1C;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,gCAAgClJ,SAC3C,SAASkJ;IACP,MAAM/F,OAAOzC,mBAAmByC,IAAI;IACpC,MAAMC,OAAO1C,mBAAmB0C,IAAI;IACpC,MAAME,gBAAgB5C,mBAAmB4C,aAAa;IACtD,IAAI,CAACH,QAAQ,CAACC,QAAQ,CAACE,eAAe,OAAO;IAC7C,qBACE,KAACL;QAECE,MAAMA;QACNC,MAAMA;QACNC,QAAQ3C,mBAAmB2C,MAAM;QACjCC,eAAeA;QACfC,cAAc7C,mBAAmB6C,YAAY;QAC7CC,UAAU7D,SAASwJ,KAAK,CAACC,cAAc,CAACjG;OANnC,GAAGA,KAAKkG,GAAG,CAAC,CAAC,EAAE/F,eAAe;AASzC,GACD;AACD4F,8BAA8BD,WAAW,GAAG;AAE5C,eAAeC,8BAA6B"}
@@ -27,6 +27,7 @@ import { clampToViewport, useAnchoredRect } from "../hooks/use-anchored-rect.js"
27
27
  import useInsertTokenOptions from "../hooks/use-insert-token-options.js";
28
28
  import { addCaretStops, beginInPlaceEdit, selectionOf, withoutCaretStops } from "../utils/in-place-edit-surface.js";
29
29
  import { inlineTextEdit } from "../utils/inline-text-edit.store.js";
30
+ import { EDIT_COMPANION_SELECTOR, registerCellEditShapeHandler } from "./table-edge-controls.component.js";
30
31
  import { dataTableCellActions, dataTableCellValueFromEdit, withDataTableShapeEdit, writeDataTableCell } from "../utils/table-cell-edit.js";
31
32
  import { RICH_COMMANDS, richTextCommandGroups } from "../utils/rich-text-commands.js";
32
33
  import { richTextToPlain, sanitizeRichText, textToHtml } from "../utils/sanitize-rich-text.js";
@@ -697,7 +698,12 @@ const BOXED_SURFACE_SX = {
697
698
  const live = (_inPlaceRef_current = inPlaceRef.current) == null ? void 0 : _inPlaceRef_current.element;
698
699
  if (live == null ? void 0 : live.contains(target)) return true;
699
700
  const overlay = overlayRef.current;
700
- return Boolean(overlay == null ? void 0 : overlay.contains(target));
701
+ if (overlay == null ? void 0 : overlay.contains(target)) return true;
702
+ // Controls that act ON the edit from outside the toolbar, such as
703
+ // the "+" bars along a table cell's table (AGL-4216). A press on one
704
+ // is the author still working, and ending the edit there would write
705
+ // the cell and close before the press could add the row.
706
+ return Boolean(target instanceof Element && target.closest(EDIT_COMPANION_SELECTOR));
701
707
  };
702
708
  /** The touch being followed, and what a tap would mean for it. */ const press = new TouchPressTracker();
703
709
  let pressOnEditedLeaf = false;
@@ -967,6 +973,15 @@ const BOXED_SURFACE_SX = {
967
973
  }, [
968
974
  commit
969
975
  ]);
976
+ // The "+" bars along the table's edges go through the same one commit
977
+ // while a cell is open, so the text typed so far rides with the new row.
978
+ useEffect(()=>{
979
+ if (!cellTarget) return undefined;
980
+ return registerCellEditShapeHandler(pickShapeEdit);
981
+ }, [
982
+ cellTarget,
983
+ pickShapeEdit
984
+ ]);
970
985
  const handleInsertPick = useCallback((token)=>{
971
986
  var _ref;
972
987
  const editable = activeEditable();