@aglyn/besigner-ui 1.15.1 → 1.16.0
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 +17 -17
- package/src/lib/components/dnd/draggable-droppable.js +13 -3
- package/src/lib/components/dnd/draggable-droppable.js.map +1 -1
- package/src/lib/components/inline-text-editor.component.js +105 -14
- package/src/lib/components/inline-text-editor.component.js.map +1 -1
- package/src/lib/components/node-context-menu.js +8 -0
- package/src/lib/components/node-context-menu.js.map +1 -1
- package/src/lib/components/table-menu-items.d.ts +38 -0
- package/src/lib/components/table-menu-items.js +132 -0
- package/src/lib/components/table-menu-items.js.map +1 -0
- package/src/lib/utils/canvas-context-menu.d.ts +33 -2
- package/src/lib/utils/canvas-context-menu.js +18 -19
- package/src/lib/utils/canvas-context-menu.js.map +1 -1
- package/src/lib/utils/inline-text-edit.store.d.ts +6 -3
- package/src/lib/utils/inline-text-edit.store.js.map +1 -1
- package/src/lib/utils/sanitize-rich-text.d.ts +2 -0
- package/src/lib/utils/sanitize-rich-text.js +9 -1
- package/src/lib/utils/sanitize-rich-text.js.map +1 -1
- package/src/lib/utils/table-cell-edit.d.ts +44 -0
- package/src/lib/utils/table-cell-edit.js +130 -2
- package/src/lib/utils/table-cell-edit.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/besigner/feature/designer/src/lib/utils/sanitize-rich-text.ts"],"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\n// The one escaper (AGL-2706). The local `escapeAttribute` this replaces\n// omitted `'`, which single-quoted attributes delimit just as double quotes\n// do — the omission was survivable only because every value here lands in a\n// double-quoted slot, and a rule that holds by where its callers happen to\n// put it is the kind that stops holding quietly. `escapeText` below stays\n// local: it is the TEXT half, and a text node has no quote to break.\nimport { escapeHtml } from '@aglyn/shared-util-tools/escape-html'\n\n/** Tags the inline rich-text editor may persist (AGL-54). */\nconst ALLOWED_TAGS = new Set([\n 'b',\n 'strong',\n 'i',\n 'em',\n 'u',\n 'a',\n 'ul',\n 'ol',\n 'li',\n 'br',\n 'p',\n 'div',\n 'span',\n])\n\n/**\n * The subset a PHRASING-ONLY surface may persist (AGL-2557) — the label of a\n * Button, a Screen Link or an Accordion Summary, which ships inside a\n * `<button>` or an `<a>`.\n *\n * Neither element may contain a block or a second control. A `<div>` here is\n * not merely untidy: the parser closes the control on that start tag and\n * promotes the rest to a sibling, which reaches the browser as a React\n * hydration mismatch on the published page. The renderer enforces the same\n * narrowing on the way out (`INLINE_AUTHOR_HTML_ELEMENTS`); this end of the\n * round trip means what is STORED is what will be drawn, so the Attributes\n * panel and the plain-text fallback describe the same element as the canvas.\n *\n * `br` stays: it is phrasing content, and Shift+Enter is the one line break\n * these surfaces still offer.\n */\nconst PHRASING_TAGS = new Set(['b', 'strong', 'i', 'em', 'u', 'br', 'span'])\n\n/** How much markup one commit may keep — see {@link PHRASING_TAGS}. */\nexport interface SanitizeRichTextOptions {\n phrasingOnly?: boolean\n}\n\nconst SAFE_HREF = /^(https?:\\/\\/|mailto:|tel:|sms:|\\/)/i\n\n/**\n * Allowlist HTML sanitizer for inline rich text: keeps basic formatting\n * tags, strips every attribute except a safe `href` on links (which gains\n * `rel=\"noopener noreferrer\"`), and unwraps disallowed elements to their\n * text content (so nothing script-capable survives). Runs at commit time in\n * the editor (browser DOM available).\n *\n * `options.phrasingOnly` narrows the allowlist for a surface that ships\n * inside a control (AGL-2557); omitted, every existing caller is unchanged.\n */\nexport function sanitizeRichText(\n html: string,\n options?: SanitizeRichTextOptions,\n): string {\n if (typeof document === 'undefined') return ''\n const allowed = options?.phrasingOnly ? PHRASING_TAGS : ALLOWED_TAGS\n const template = document.createElement('template')\n template.innerHTML = html\n\n const sanitizeNode = (node: Node): string => {\n if (node.nodeType === Node.TEXT_NODE) {\n return escapeText(node.textContent ?? '')\n }\n if (node.nodeType !== Node.ELEMENT_NODE) return ''\n const element = node as Element\n const tag = element.tagName.toLowerCase()\n const inner = Array.from(element.childNodes).map(sanitizeNode).join('')\n if (!allowed.has(tag)) return inner\n // A bare `span` is INERT and is unwrapped (AGL-2486). Every attribute is\n // stripped here, so a surviving `<span>` carries no styling, no class and\n // no binding — it renders exactly as its own text. Keeping it would be\n // dead weight with a cost: `html` is what marks a node as \"formatted\", so\n // an inert wrapper left behind by a contentEditable merge would pin the\n // Attributes Text field read-only forever over markup that does nothing.\n // Measured on test-org: deleting the line break out of\n // `About <div>us</div>` left Chrome with `About<span>us</span>`.\n if (tag === 'span') return inner\n if (tag === 'br') return '<br>'\n if (tag === 'a') {\n const href = element.getAttribute('href') ?? ''\n if (!SAFE_HREF.test(href)) return inner\n return `<a href=\"${escapeHtml(href)}\" rel=\"noopener noreferrer\">${inner}</a>`\n }\n return `<${tag}>${inner}</${tag}>`\n }\n\n return Array.from(template.content.childNodes).map(sanitizeNode).join('')\n}\n\nfunction escapeText(text: string): string {\n return text\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n}\n\n/**\n * Tags that end the line they are on. `br` is the explicit one; the rest are\n * the block-level members of {@link ALLOWED_TAGS}, which a contentEditable\n * produces on its own — pressing Enter in the rich surface forks the DOM\n * into `div`s, and that fork IS the author's line break.\n */\nconst LINE_BREAKING_TAGS = new Set(['BR', 'DIV', 'P', 'LI', 'UL', 'OL'])\n\n/**\n * Plain-text projection of markup, for the `children` fallback prop.\n *\n * Line breaks SURVIVE (AGL-2486). A node that carries one stores\n * `html: \"Your entire web <div>presence. </div>\"` beside\n * `children: \"Your entire web presence. \"`. The canvas renders `html` and\n * shows two lines; the Attributes panel renders `children`. Projected with\n * `template.content.textContent` the panel shows one, because `textContent`\n * concatenates across every element boundary — a `<div>` fork and a `<br>`\n * both vanish into nothing.\n *\n * That is a real break silently dropped by the projection, not the soft wrap\n * a bounding box misreports. `children` is not a display detail either: it is\n * what every\n * plain renderer, the SSR fallback and the panel field all read, so the\n * break was being lost to all three.\n *\n * Only the trailing newline is trimmed — a block element closes at the end\n * of the string and that boundary separates nothing.\n */\nexport function richTextToPlain(html: string): string {\n if (typeof document === 'undefined') return html\n const template = document.createElement('template')\n template.innerHTML = html\n const parts: string[] = []\n const endsOpen = () =>\n parts.length > 0 && !parts[parts.length - 1]!.endsWith('\\n')\n\n const walk = (parent: Node): void => {\n for (const child of Array.from(parent.childNodes)) {\n if (child.nodeType === 3 /* TEXT_NODE */) {\n parts.push(child.nodeValue ?? '')\n continue\n }\n if (child.nodeType !== 1 /* ELEMENT_NODE */) continue\n const element = child as Element\n if (element.tagName === 'BR') {\n parts.push('\\n')\n continue\n }\n const breaks = LINE_BREAKING_TAGS.has(element.tagName)\n // A block that FOLLOWS content starts its own line; one that opens the\n // string, or already sits after a break, does not add an empty one.\n if (breaks && endsOpen()) parts.push('\\n')\n walk(element)\n if (breaks && endsOpen()) parts.push('\\n')\n }\n }\n\n walk(template.content)\n return parts.join('').replace(/\\n+$/, '')\n}\n\n/**\n * Plain text as the markup that renders it, newlines included.\n *\n * Named for what it does rather than `escapeHtml`, which it is not: the\n * `<br>` is a CONVERSION, and a reader who takes this for the escaper will\n * eventually reach for it somewhere a line break must stay literal. The\n * escaping half is the shared one.\n */\nexport function textToHtml(text: string): string {\n return escapeHtml(text).replace(/\\n/g, '<br>')\n}\n"],"names":["escapeHtml","ALLOWED_TAGS","Set","PHRASING_TAGS","SAFE_HREF","sanitizeRichText","html","options","document","allowed","phrasingOnly","template","createElement","innerHTML","sanitizeNode","node","nodeType","Node","TEXT_NODE","escapeText","textContent","ELEMENT_NODE","element","tag","tagName","toLowerCase","inner","Array","from","childNodes","map","join","has","href","getAttribute","test","content","text","replace","LINE_BREAKING_TAGS","richTextToPlain","parts","endsOpen","length","endsWith","walk","parent","child","push","nodeValue","breaks","textToHtml"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,wEAAwE;AACxE,4EAA4E;AAC5E,4EAA4E;AAC5E,2EAA2E;AAC3E,0EAA0E;AAC1E,qEAAqE;AACrE,SAASA,UAAU,QAAQ,uCAAsC;AAEjE,2DAA2D,GAC3D,MAAMC,eAAe,IAAIC,IAAI;IAC3B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED;;;;;;;;;;;;;;;CAeC,GACD,MAAMC,gBAAgB,IAAID,IAAI;IAAC;IAAK;IAAU;IAAK;IAAM;IAAK;IAAM;CAAO;AAO3E,MAAME,YAAY;AAElB;;;;;;;;;CASC,GACD,OAAO,SAASC,iBACdC,IAAY,EACZC,OAAiC;IAEjC,IAAI,OAAOC,aAAa,aAAa,OAAO;IAC5C,MAAMC,UAAUF,CAAAA,2BAAAA,QAASG,YAAY,IAAGP,gBAAgBF;IACxD,MAAMU,WAAWH,SAASI,aAAa,CAAC;IACxCD,SAASE,SAAS,GAAGP;IAErB,MAAMQ,eAAe,CAACC;QACpB,IAAIA,KAAKC,QAAQ,KAAKC,KAAKC,SAAS,EAAE;gBAClBH;YAAlB,OAAOI,YAAWJ,oBAAAA,KAAKK,WAAW,YAAhBL,oBAAoB;QACxC;QACA,IAAIA,KAAKC,QAAQ,KAAKC,KAAKI,YAAY,EAAE,OAAO;QAChD,MAAMC,UAAUP;QAChB,MAAMQ,MAAMD,QAAQE,OAAO,CAACC,WAAW;QACvC,MAAMC,QAAQC,MAAMC,IAAI,CAACN,QAAQO,UAAU,EAAEC,GAAG,CAAChB,cAAciB,IAAI,CAAC;QACpE,IAAI,CAACtB,QAAQuB,GAAG,CAACT,MAAM,OAAOG;QAC9B,yEAAyE;QACzE,0EAA0E;QAC1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MAAM/B,QAAQ,KAAK,EAAE,aAAa,KAAI;oBAC7B+B;gBAAXN,MAAMO,IAAI,EAACD,mBAAAA,MAAME,SAAS,YAAfF,mBAAmB;gBAC9B;YACF;YACA,IAAIA,MAAM/B,QAAQ,KAAK,EAAE,gBAAgB,KAAI;YAC7C,MAAMM,UAAUyB;YAChB,IAAIzB,QAAQE,OAAO,KAAK,MAAM;gBAC5BiB,MAAMO,IAAI,CAAC;gBACX;YACF;YACA,MAAME,SAASX,mBAAmBP,GAAG,CAACV,QAAQE,OAAO;YACrD,uEAAuE;YACvE,oEAAoE;YACpE,IAAI0B,UAAUR,YAAYD,MAAMO,IAAI,CAAC;YACrCH,KAAKvB;YACL,IAAI4B,UAAUR,YAAYD,MAAMO,IAAI,CAAC;QACvC;IACF;IAEAH,KAAKlC,SAASyB,OAAO;IACrB,OAAOK,MAAMV,IAAI,CAAC,IAAIO,OAAO,CAAC,QAAQ;AACxC;AAEA;;;;;;;CAOC,GACD,OAAO,SAASa,WAAWd,IAAY;IACrC,OAAOrC,WAAWqC,MAAMC,OAAO,CAAC,OAAO;AACzC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/besigner/feature/designer/src/lib/utils/sanitize-rich-text.ts"],"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\n// The one escaper (AGL-2706). The local `escapeAttribute` this replaces\n// omitted `'`, which single-quoted attributes delimit just as double quotes\n// do — the omission was survivable only because every value here lands in a\n// double-quoted slot, and a rule that holds by where its callers happen to\n// put it is the kind that stops holding quietly. `escapeText` below stays\n// local: it is the TEXT half, and a text node has no quote to break.\nimport { escapeHtml } from '@aglyn/shared-util-tools/escape-html'\n\n/** Tags the inline rich-text editor may persist (AGL-54). */\nconst ALLOWED_TAGS = new Set([\n 'b',\n 'strong',\n 'i',\n 'em',\n 'u',\n 'a',\n 'ul',\n 'ol',\n 'li',\n 'br',\n 'p',\n 'div',\n 'span',\n])\n\n/**\n * The subset a PHRASING-ONLY surface may persist (AGL-2557) — the label of a\n * Button, a Screen Link or an Accordion Summary, which ships inside a\n * `<button>` or an `<a>`.\n *\n * Neither element may contain a block or a second control. A `<div>` here is\n * not merely untidy: the parser closes the control on that start tag and\n * promotes the rest to a sibling, which reaches the browser as a React\n * hydration mismatch on the published page. The renderer enforces the same\n * narrowing on the way out (`INLINE_AUTHOR_HTML_ELEMENTS`); this end of the\n * round trip means what is STORED is what will be drawn, so the Attributes\n * panel and the plain-text fallback describe the same element as the canvas.\n *\n * `br` stays: it is phrasing content, and Shift+Enter is the one line break\n * these surfaces still offer.\n */\nconst PHRASING_TAGS = new Set(['b', 'strong', 'i', 'em', 'u', 'br', 'span'])\n\n/**\n * Phrasing content plus links (AGL-4203) — a Table cell. A cell is one line\n * of a pipe grid, so it takes no block; but unlike a control's label it is\n * not itself a control, so an anchor inside it is valid.\n */\nconst PHRASING_AND_LINK_TAGS = new Set([...PHRASING_TAGS, 'a'])\n\n/** How much markup one commit may keep — see {@link PHRASING_TAGS}. */\nexport interface SanitizeRichTextOptions {\n phrasingOnly?: boolean\n /** With `phrasingOnly`: keep links too (a Table cell). */\n links?: boolean\n}\n\nconst SAFE_HREF = /^(https?:\\/\\/|mailto:|tel:|sms:|\\/)/i\n\n/**\n * Allowlist HTML sanitizer for inline rich text: keeps basic formatting\n * tags, strips every attribute except a safe `href` on links (which gains\n * `rel=\"noopener noreferrer\"`), and unwraps disallowed elements to their\n * text content (so nothing script-capable survives). Runs at commit time in\n * the editor (browser DOM available).\n *\n * `options.phrasingOnly` narrows the allowlist for a surface that ships\n * inside a control (AGL-2557); omitted, every existing caller is unchanged.\n */\nexport function sanitizeRichText(\n html: string,\n options?: SanitizeRichTextOptions,\n): string {\n if (typeof document === 'undefined') return ''\n const allowed = options?.phrasingOnly\n ? options.links\n ? PHRASING_AND_LINK_TAGS\n : PHRASING_TAGS\n : ALLOWED_TAGS\n const template = document.createElement('template')\n template.innerHTML = html\n\n const sanitizeNode = (node: Node): string => {\n if (node.nodeType === Node.TEXT_NODE) {\n return escapeText(node.textContent ?? '')\n }\n if (node.nodeType !== Node.ELEMENT_NODE) return ''\n const element = node as Element\n const tag = element.tagName.toLowerCase()\n const inner = Array.from(element.childNodes).map(sanitizeNode).join('')\n if (!allowed.has(tag)) return inner\n // A bare `span` is INERT and is unwrapped (AGL-2486). Every attribute is\n // stripped here, so a surviving `<span>` carries no styling, no class and\n // no binding — it renders exactly as its own text. Keeping it would be\n // dead weight with a cost: `html` is what marks a node as \"formatted\", so\n // an inert wrapper left behind by a contentEditable merge would pin the\n // Attributes Text field read-only forever over markup that does nothing.\n // Measured on test-org: deleting the line break out of\n // `About <div>us</div>` left Chrome with `About<span>us</span>`.\n if (tag === 'span') return inner\n if (tag === 'br') return '<br>'\n if (tag === 'a') {\n const href = element.getAttribute('href') ?? ''\n if (!SAFE_HREF.test(href)) return inner\n return `<a href=\"${escapeHtml(href)}\" rel=\"noopener noreferrer\">${inner}</a>`\n }\n return `<${tag}>${inner}</${tag}>`\n }\n\n return Array.from(template.content.childNodes).map(sanitizeNode).join('')\n}\n\nfunction escapeText(text: string): string {\n return text\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n}\n\n/**\n * Tags that end the line they are on. `br` is the explicit one; the rest are\n * the block-level members of {@link ALLOWED_TAGS}, which a contentEditable\n * produces on its own — pressing Enter in the rich surface forks the DOM\n * into `div`s, and that fork IS the author's line break.\n */\nconst LINE_BREAKING_TAGS = new Set(['BR', 'DIV', 'P', 'LI', 'UL', 'OL'])\n\n/**\n * Plain-text projection of markup, for the `children` fallback prop.\n *\n * Line breaks SURVIVE (AGL-2486). A node that carries one stores\n * `html: \"Your entire web <div>presence. </div>\"` beside\n * `children: \"Your entire web presence. \"`. The canvas renders `html` and\n * shows two lines; the Attributes panel renders `children`. Projected with\n * `template.content.textContent` the panel shows one, because `textContent`\n * concatenates across every element boundary — a `<div>` fork and a `<br>`\n * both vanish into nothing.\n *\n * That is a real break silently dropped by the projection, not the soft wrap\n * a bounding box misreports. `children` is not a display detail either: it is\n * what every\n * plain renderer, the SSR fallback and the panel field all read, so the\n * break was being lost to all three.\n *\n * Only the trailing newline is trimmed — a block element closes at the end\n * of the string and that boundary separates nothing.\n */\nexport function richTextToPlain(html: string): string {\n if (typeof document === 'undefined') return html\n const template = document.createElement('template')\n template.innerHTML = html\n const parts: string[] = []\n const endsOpen = () =>\n parts.length > 0 && !parts[parts.length - 1]!.endsWith('\\n')\n\n const walk = (parent: Node): void => {\n for (const child of Array.from(parent.childNodes)) {\n if (child.nodeType === 3 /* TEXT_NODE */) {\n parts.push(child.nodeValue ?? '')\n continue\n }\n if (child.nodeType !== 1 /* ELEMENT_NODE */) continue\n const element = child as Element\n if (element.tagName === 'BR') {\n parts.push('\\n')\n continue\n }\n const breaks = LINE_BREAKING_TAGS.has(element.tagName)\n // A block that FOLLOWS content starts its own line; one that opens the\n // string, or already sits after a break, does not add an empty one.\n if (breaks && endsOpen()) parts.push('\\n')\n walk(element)\n if (breaks && endsOpen()) parts.push('\\n')\n }\n }\n\n walk(template.content)\n return parts.join('').replace(/\\n+$/, '')\n}\n\n/**\n * Plain text as the markup that renders it, newlines included.\n *\n * Named for what it does rather than `escapeHtml`, which it is not: the\n * `<br>` is a CONVERSION, and a reader who takes this for the escaper will\n * eventually reach for it somewhere a line break must stay literal. The\n * escaping half is the shared one.\n */\nexport function textToHtml(text: string): string {\n return escapeHtml(text).replace(/\\n/g, '<br>')\n}\n"],"names":["escapeHtml","ALLOWED_TAGS","Set","PHRASING_TAGS","PHRASING_AND_LINK_TAGS","SAFE_HREF","sanitizeRichText","html","options","document","allowed","phrasingOnly","links","template","createElement","innerHTML","sanitizeNode","node","nodeType","Node","TEXT_NODE","escapeText","textContent","ELEMENT_NODE","element","tag","tagName","toLowerCase","inner","Array","from","childNodes","map","join","has","href","getAttribute","test","content","text","replace","LINE_BREAKING_TAGS","richTextToPlain","parts","endsOpen","length","endsWith","walk","parent","child","push","nodeValue","breaks","textToHtml"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,wEAAwE;AACxE,4EAA4E;AAC5E,4EAA4E;AAC5E,2EAA2E;AAC3E,0EAA0E;AAC1E,qEAAqE;AACrE,SAASA,UAAU,QAAQ,uCAAsC;AAEjE,2DAA2D,GAC3D,MAAMC,eAAe,IAAIC,IAAI;IAC3B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED;;;;;;;;;;;;;;;CAeC,GACD,MAAMC,gBAAgB,IAAID,IAAI;IAAC;IAAK;IAAU;IAAK;IAAM;IAAK;IAAM;CAAO;AAE3E;;;;CAIC,GACD,MAAME,yBAAyB,IAAIF,IAAI;OAAIC;IAAe;CAAI;AAS9D,MAAME,YAAY;AAElB;;;;;;;;;CASC,GACD,OAAO,SAASC,iBACdC,IAAY,EACZC,OAAiC;IAEjC,IAAI,OAAOC,aAAa,aAAa,OAAO;IAC5C,MAAMC,UAAUF,CAAAA,2BAAAA,QAASG,YAAY,IACjCH,QAAQI,KAAK,GACXR,yBACAD,gBACFF;IACJ,MAAMY,WAAWJ,SAASK,aAAa,CAAC;IACxCD,SAASE,SAAS,GAAGR;IAErB,MAAMS,eAAe,CAACC;QACpB,IAAIA,KAAKC,QAAQ,KAAKC,KAAKC,SAAS,EAAE;gBAClBH;YAAlB,OAAOI,YAAWJ,oBAAAA,KAAKK,WAAW,YAAhBL,oBAAoB;QACxC;QACA,IAAIA,KAAKC,QAAQ,KAAKC,KAAKI,YAAY,EAAE,OAAO;QAChD,MAAMC,UAAUP;QAChB,MA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AC1B,MAAMC,WAAW,IACfD,MAAME,MAAM,GAAG,KAAK,CAACF,KAAK,CAACA,MAAME,MAAM,GAAG,EAAE,CAAEC,QAAQ,CAAC;IAEzD,MAAMC,OAAO,CAACC;QACZ,KAAK,MAAMC,SAASpB,MAAMC,IAAI,CAACkB,OAAOjB,UAAU,EAAG;YACjD,IAAIkB,MAAM/B,QAAQ,KAAK,EAAE,aAAa,KAAI;oBAC7B+B;gBAAXN,MAAMO,IAAI,EAACD,mBAAAA,MAAME,SAAS,YAAfF,mBAAmB;gBAC9B;YACF;YACA,IAAIA,MAAM/B,QAAQ,KAAK,EAAE,gBAAgB,KAAI;YAC7C,MAAMM,UAAUyB;YAChB,IAAIzB,QAAQE,OAAO,KAAK,MAAM;gBAC5BiB,MAAMO,IAAI,CAAC;gBACX;YACF;YACA,MAAME,SAASX,mBAAmBP,GAAG,CAACV,QAAQE,OAAO;YACrD,uEAAuE;YACvE,oEAAoE;YACpE,IAAI0B,UAAUR,YAAYD,MAAMO,IAAI,CAAC;YACrCH,KAAKvB;YACL,IAAI4B,UAAUR,YAAYD,MAAMO,IAAI,CAAC;QACvC;IACF;IAEAH,KAAKlC,SAASyB,OAAO;IACrB,OAAOK,MAAMV,IAAI,CAAC,IAAIO,OAAO,CAAC,QAAQ;AACxC;AAEA;;;;;;;CAOC,GACD,OAAO,SAASa,WAAWd,IAAY;IACrC,OAAOvC,WAAWuC,MAAMC,OAAO,CAAC,OAAO;AACzC"}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import type * as Aglyn from '@aglyn/aglyn';
|
|
18
|
+
import { type DataTableShapeEdit } from '@aglyn/shared-data-enums';
|
|
18
19
|
/**
|
|
19
20
|
* In-place editing of one Table cell on the canvas.
|
|
20
21
|
*
|
|
@@ -64,3 +65,46 @@ export declare function readDataTableCell(value: unknown, row: number, column: n
|
|
|
64
65
|
* read back out and written again with the grid.
|
|
65
66
|
*/
|
|
66
67
|
export declare function writeDataTableCell(value: unknown, row: number, column: number, text: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* What the cell editor opens with (AGL-4203): the cell's words, and its
|
|
70
|
+
* markup when it was formatted. A plain cell has no markup, and the editor
|
|
71
|
+
* builds its surface from the words as it does for unformatted text.
|
|
72
|
+
*/
|
|
73
|
+
export declare function readDataTableCellForEdit(value: unknown, row: number, column: number): {
|
|
74
|
+
text: string;
|
|
75
|
+
html: string;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* What a cell edit stores (AGL-4203): the sanitized markup when the author
|
|
79
|
+
* formatted something, the plain words otherwise — so a table nobody formats
|
|
80
|
+
* stays the plain grid it always was.
|
|
81
|
+
*
|
|
82
|
+
* One case keeps the markup without any formatting: plain words that would
|
|
83
|
+
* READ as markup (`a < b` typed out literally, or a tag spelled in text).
|
|
84
|
+
* Stored plain, the renderer would draw them as a tag; stored escaped, they
|
|
85
|
+
* draw as typed.
|
|
86
|
+
*/
|
|
87
|
+
export declare function dataTableCellValueFromEdit(plain: string, sanitized: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* `props` after one change to the table's shape: the grid, and the
|
|
90
|
+
* emphasized column moved with its column (AGL-4203). The emphasis is
|
|
91
|
+
* written only when it moves, so a row edit never touches it.
|
|
92
|
+
*/
|
|
93
|
+
export declare function withDataTableShapeEdit(props: Record<string, unknown>, attribute: string, edit: DataTableShapeEdit): Record<string, unknown>;
|
|
94
|
+
/** `props` with an empty table started — the same starter the Attributes grid writes. */
|
|
95
|
+
export declare function withDataTableStarted(props: Record<string, unknown>, attribute: string): Record<string, unknown>;
|
|
96
|
+
/** One row or column action offered on a cell. */
|
|
97
|
+
export interface DataTableCellAction {
|
|
98
|
+
key: string;
|
|
99
|
+
label: string;
|
|
100
|
+
icon: string;
|
|
101
|
+
edit: DataTableShapeEdit;
|
|
102
|
+
disabled: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The row and column actions for one cell, in the order both the right-click
|
|
106
|
+
* menu and the cell editor's toolbar list them (AGL-4203). Deleting the last
|
|
107
|
+
* row or the last column is offered but disabled, as the Attributes grid
|
|
108
|
+
* does: a table with no cells left has nothing to click to get one back.
|
|
109
|
+
*/
|
|
110
|
+
export declare function dataTableCellActions(value: unknown, row: number, column: number): DataTableCellAction[];
|
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/ import {
|
|
17
|
-
import {
|
|
16
|
+
*/ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
17
|
+
import { FieldComponentType } from "@aglyn/aglyn";
|
|
18
|
+
import { DATA_TABLE_EMPHASIS_PROP, dataTableCellText, dataTableStarterValue, editDataTableShape, emphasisAfterShapeEdit, isDataTableCellMarkup, normalizeEmphasisColumn, parseDataTableRows, readDataTableAlignments, serializeDataTable, withCellSet } from "@aglyn/shared-data-enums";
|
|
19
|
+
import { mdiTableColumnPlusAfter, mdiTableColumnPlusBefore, mdiTableColumnRemove, mdiTableRowPlusAfter, mdiTableRowPlusBefore, mdiTableRowRemove } from "@aglyn/shared-data-mdi";
|
|
18
20
|
/**
|
|
19
21
|
* In-place editing of one Table cell on the canvas.
|
|
20
22
|
*
|
|
@@ -89,5 +91,131 @@ import { parseDataTableRows, readDataTableAlignments, serializeDataTable, withCe
|
|
|
89
91
|
const cell = text.replace(/\s*\r?\n\s*/g, ' ').trim();
|
|
90
92
|
return serializeDataTable(withCellSet(grid, row, column, cell), alignments);
|
|
91
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* What the cell editor opens with (AGL-4203): the cell's words, and its
|
|
96
|
+
* markup when it was formatted. A plain cell has no markup, and the editor
|
|
97
|
+
* builds its surface from the words as it does for unformatted text.
|
|
98
|
+
*/ export function readDataTableCellForEdit(value, row, column) {
|
|
99
|
+
const raw = readDataTableCell(value, row, column);
|
|
100
|
+
return isDataTableCellMarkup(raw) ? {
|
|
101
|
+
text: dataTableCellText(raw),
|
|
102
|
+
html: raw
|
|
103
|
+
} : {
|
|
104
|
+
text: raw,
|
|
105
|
+
html: ''
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* What a cell edit stores (AGL-4203): the sanitized markup when the author
|
|
110
|
+
* formatted something, the plain words otherwise — so a table nobody formats
|
|
111
|
+
* stays the plain grid it always was.
|
|
112
|
+
*
|
|
113
|
+
* One case keeps the markup without any formatting: plain words that would
|
|
114
|
+
* READ as markup (`a < b` typed out literally, or a tag spelled in text).
|
|
115
|
+
* Stored plain, the renderer would draw them as a tag; stored escaped, they
|
|
116
|
+
* draw as typed.
|
|
117
|
+
*/ export function dataTableCellValueFromEdit(plain, sanitized) {
|
|
118
|
+
if (/<[a-z]/i.test(sanitized)) return sanitized;
|
|
119
|
+
if (isDataTableCellMarkup(plain)) return sanitized;
|
|
120
|
+
return plain;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* `props` after one change to the table's shape: the grid, and the
|
|
124
|
+
* emphasized column moved with its column (AGL-4203). The emphasis is
|
|
125
|
+
* written only when it moves, so a row edit never touches it.
|
|
126
|
+
*/ export function withDataTableShapeEdit(props, attribute, edit) {
|
|
127
|
+
var _ref;
|
|
128
|
+
var _parseDataTableRows_;
|
|
129
|
+
const stored = props[attribute];
|
|
130
|
+
const width = (_ref = (_parseDataTableRows_ = parseDataTableRows(stored)[0]) == null ? void 0 : _parseDataTableRows_.length) != null ? _ref : 0;
|
|
131
|
+
const next = _extends({}, props, {
|
|
132
|
+
[attribute]: editDataTableShape(stored, edit)
|
|
133
|
+
});
|
|
134
|
+
if (DATA_TABLE_EMPHASIS_PROP in props) {
|
|
135
|
+
const before = normalizeEmphasisColumn(props[DATA_TABLE_EMPHASIS_PROP], width);
|
|
136
|
+
const after = emphasisAfterShapeEdit(props[DATA_TABLE_EMPHASIS_PROP], width, edit);
|
|
137
|
+
if (after !== before) next[DATA_TABLE_EMPHASIS_PROP] = after;
|
|
138
|
+
}
|
|
139
|
+
return next;
|
|
140
|
+
}
|
|
141
|
+
/** `props` with an empty table started — the same starter the Attributes grid writes. */ export function withDataTableStarted(props, attribute) {
|
|
142
|
+
return _extends({}, props, {
|
|
143
|
+
[attribute]: dataTableStarterValue()
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The row and column actions for one cell, in the order both the right-click
|
|
148
|
+
* menu and the cell editor's toolbar list them (AGL-4203). Deleting the last
|
|
149
|
+
* row or the last column is offered but disabled, as the Attributes grid
|
|
150
|
+
* does: a table with no cells left has nothing to click to get one back.
|
|
151
|
+
*/ export function dataTableCellActions(value, row, column) {
|
|
152
|
+
var _ref;
|
|
153
|
+
var _grid_;
|
|
154
|
+
const grid = parseDataTableRows(value);
|
|
155
|
+
const rows = grid.length;
|
|
156
|
+
const columns = (_ref = (_grid_ = grid[0]) == null ? void 0 : _grid_.length) != null ? _ref : 0;
|
|
157
|
+
return [
|
|
158
|
+
{
|
|
159
|
+
key: 'row-above',
|
|
160
|
+
label: 'Insert row above',
|
|
161
|
+
icon: mdiTableRowPlusBefore.path,
|
|
162
|
+
edit: {
|
|
163
|
+
kind: 'insertRow',
|
|
164
|
+
at: row
|
|
165
|
+
},
|
|
166
|
+
disabled: false
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
key: 'row-below',
|
|
170
|
+
label: 'Insert row below',
|
|
171
|
+
icon: mdiTableRowPlusAfter.path,
|
|
172
|
+
edit: {
|
|
173
|
+
kind: 'insertRow',
|
|
174
|
+
at: row + 1
|
|
175
|
+
},
|
|
176
|
+
disabled: false
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
key: 'column-left',
|
|
180
|
+
label: 'Insert column left',
|
|
181
|
+
icon: mdiTableColumnPlusBefore.path,
|
|
182
|
+
edit: {
|
|
183
|
+
kind: 'insertColumn',
|
|
184
|
+
at: column
|
|
185
|
+
},
|
|
186
|
+
disabled: false
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
key: 'column-right',
|
|
190
|
+
label: 'Insert column right',
|
|
191
|
+
icon: mdiTableColumnPlusAfter.path,
|
|
192
|
+
edit: {
|
|
193
|
+
kind: 'insertColumn',
|
|
194
|
+
at: column + 1
|
|
195
|
+
},
|
|
196
|
+
disabled: false
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
key: 'row-delete',
|
|
200
|
+
label: 'Delete row',
|
|
201
|
+
icon: mdiTableRowRemove.path,
|
|
202
|
+
edit: {
|
|
203
|
+
kind: 'removeRow',
|
|
204
|
+
at: row
|
|
205
|
+
},
|
|
206
|
+
disabled: rows <= 1
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
key: 'column-delete',
|
|
210
|
+
label: 'Delete column',
|
|
211
|
+
icon: mdiTableColumnRemove.path,
|
|
212
|
+
edit: {
|
|
213
|
+
kind: 'removeColumn',
|
|
214
|
+
at: column
|
|
215
|
+
},
|
|
216
|
+
disabled: columns <= 1
|
|
217
|
+
}
|
|
218
|
+
];
|
|
219
|
+
}
|
|
92
220
|
|
|
93
221
|
//# sourceMappingURL=table-cell-edit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/besigner/feature/designer/src/lib/utils/table-cell-edit.ts"],"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\nimport type * as Aglyn from '@aglyn/aglyn'\nimport { FieldComponentType } from '@aglyn/aglyn'\nimport {\n parseDataTableRows,\n readDataTableAlignments,\n serializeDataTable,\n withCellSet,\n} from '@aglyn/shared-data-enums'\n\n/**\n * In-place editing of one Table cell on the canvas.\n *\n * The Table element stores its whole grid as ONE string attribute (see\n * `@aglyn/shared-data-enums`'s `data-table`), so a cell is not a canvas node\n * and has no `children` of its own to edit. A double-click on a cell opens\n * the same in-place text editor every text element uses, anchored on the\n * cell, and the commit rewrites that one cell inside the stored string —\n * through the same parser and serializer the attributes-panel grid uses, so\n * the two surfaces can never disagree about what a table string means.\n */\n\n/**\n * The attribute holding the grid, or `undefined` when the component declares\n * none. Keyed on the schema's own `DATA_TABLE` field declaration — the same\n * declaration that gives the attributes panel its grid — rather than on a\n * component id, so any element that stores a grid this way is editable on\n * the canvas too.\n */\nexport function findDataTableAttributeName(\n node: Aglyn.NodeSchema<any> | undefined,\n): string | undefined {\n for (const attribute of node?.componentSchema?.attributes ?? []) {\n if (attribute?.component === FieldComponentType.DATA_TABLE) {\n return attribute.name\n }\n }\n return undefined\n}\n\n/** The cell a point falls in, and where it sits in the stored grid. */\nexport interface DataTableCellHit {\n element: HTMLElement\n /** Row in the parsed grid — the header row, when there is one, is row 0. */\n row: number\n column: number\n}\n\n/**\n * The rendered cell under a client point inside `root`, if any.\n *\n * Geometric rather than `elementFromPoint`, for the reason instance leaves\n * are hit-tested that way: the canvas is a closed shadow root and the point\n * may come from a touch, so the event target is not something to rely on.\n *\n * The grid row is the cell's `<tr>` index across the whole table. The\n * renderer draws exactly one `<tr>` per parsed row, header included, so the\n * two indexes are the same thing.\n */\nexport function findDataTableCellAtPoint(\n root: Element,\n clientX: number,\n clientY: number,\n): DataTableCellHit | undefined {\n const rows = Array.from(root.querySelectorAll('tr'))\n for (let row = 0; row < rows.length; row++) {\n const cells = Array.from(rows[row].children).filter(\n (cell): cell is HTMLElement =>\n cell.tagName === 'TD' || cell.tagName === 'TH',\n )\n for (let column = 0; column < cells.length; column++) {\n const rect = cells[column].getBoundingClientRect()\n if (\n clientX >= rect.left &&\n clientX <= rect.right &&\n clientY >= rect.top &&\n clientY <= rect.bottom\n ) {\n return { element: cells[column], row, column }\n }\n }\n }\n return undefined\n}\n\n/** The text a stored grid holds at one cell, or `''` when it is outside it. */\nexport function readDataTableCell(\n value: unknown,\n row: number,\n column: number,\n): string {\n return parseDataTableRows(value)[row]?.[column] ?? ''\n}\n\n/**\n * The stored grid with one cell replaced.\n *\n * A cell is one line — the storage is one row per line — so a line break\n * typed into the cell becomes a space instead of splitting the row. Column\n * alignments survive: they ride the same string as a divider row, and are\n * read back out and written again with the grid.\n */\nexport function writeDataTableCell(\n value: unknown,\n row: number,\n column: number,\n text: string,\n): string {\n const grid = parseDataTableRows(value)\n const width = grid[0]?.length ?? 0\n const alignments = readDataTableAlignments(value, width)\n const cell = text.replace(/\\s*\\r?\\n\\s*/g, ' ').trim()\n return serializeDataTable(withCellSet(grid, row, column, cell), alignments)\n}\n"],"names":["FieldComponentType","parseDataTableRows","readDataTableAlignments","serializeDataTable","withCellSet","findDataTableAttributeName","node","attribute","componentSchema","attributes","component","DATA_TABLE","name","undefined","findDataTableCellAtPoint","root","clientX","clientY","rows","Array","from","querySelectorAll","row","length","cells","children","filter","cell","tagName","column","rect","getBoundingClientRect","left","right","top","bottom","element","readDataTableCell","value","writeDataTableCell","text","grid","width","alignments","replace","trim"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SAASA,kBAAkB,QAAQ,eAAc;AACjD,SACEC,kBAAkB,EAClBC,uBAAuB,EACvBC,kBAAkB,EAClBC,WAAW,QACN,2BAA0B;AAEjC;;;;;;;;;;CAUC,GAED;;;;;;CAMC,GACD,OAAO,SAASC,2BACdC,IAAuC;;QAEfA;IAAxB,KAAK,MAAMC,qBAAaD,yBAAAA,wBAAAA,KAAME,eAAe,qBAArBF,sBAAuBG,UAAU,mBAAI,EAAE,CAAE;QAC/D,IAAIF,CAAAA,6BAAAA,UAAWG,SAAS,MAAKV,mBAAmBW,UAAU,EAAE;YAC1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,IAAI;IACnD,OAAO1C,mBAAmBC,YAAYqC,MAAMnB,KAAKO,QAAQF,OAAOgB;AAClE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/besigner/feature/designer/src/lib/utils/table-cell-edit.ts"],"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\nimport type * as Aglyn from '@aglyn/aglyn'\nimport { FieldComponentType } from '@aglyn/aglyn'\nimport {\n DATA_TABLE_EMPHASIS_PROP,\n type DataTableShapeEdit,\n dataTableCellText,\n dataTableStarterValue,\n editDataTableShape,\n emphasisAfterShapeEdit,\n isDataTableCellMarkup,\n normalizeEmphasisColumn,\n parseDataTableRows,\n readDataTableAlignments,\n serializeDataTable,\n withCellSet,\n} from '@aglyn/shared-data-enums'\nimport {\n mdiTableColumnPlusAfter,\n mdiTableColumnPlusBefore,\n mdiTableColumnRemove,\n mdiTableRowPlusAfter,\n mdiTableRowPlusBefore,\n mdiTableRowRemove,\n} from '@aglyn/shared-data-mdi'\n\n/**\n * In-place editing of one Table cell on the canvas.\n *\n * The Table element stores its whole grid as ONE string attribute (see\n * `@aglyn/shared-data-enums`'s `data-table`), so a cell is not a canvas node\n * and has no `children` of its own to edit. A double-click on a cell opens\n * the same in-place text editor every text element uses, anchored on the\n * cell, and the commit rewrites that one cell inside the stored string —\n * through the same parser and serializer the attributes-panel grid uses, so\n * the two surfaces can never disagree about what a table string means.\n */\n\n/**\n * The attribute holding the grid, or `undefined` when the component declares\n * none. Keyed on the schema's own `DATA_TABLE` field declaration — the same\n * declaration that gives the attributes panel its grid — rather than on a\n * component id, so any element that stores a grid this way is editable on\n * the canvas too.\n */\nexport function findDataTableAttributeName(\n node: Aglyn.NodeSchema<any> | undefined,\n): string | undefined {\n for (const attribute of node?.componentSchema?.attributes ?? []) {\n if (attribute?.component === FieldComponentType.DATA_TABLE) {\n return attribute.name\n }\n }\n return undefined\n}\n\n/** The cell a point falls in, and where it sits in the stored grid. */\nexport interface DataTableCellHit {\n element: HTMLElement\n /** Row in the parsed grid — the header row, when there is one, is row 0. */\n row: number\n column: number\n}\n\n/**\n * The rendered cell under a client point inside `root`, if any.\n *\n * Geometric rather than `elementFromPoint`, for the reason instance leaves\n * are hit-tested that way: the canvas is a closed shadow root and the point\n * may come from a touch, so the event target is not something to rely on.\n *\n * The grid row is the cell's `<tr>` index across the whole table. The\n * renderer draws exactly one `<tr>` per parsed row, header included, so the\n * two indexes are the same thing.\n */\nexport function findDataTableCellAtPoint(\n root: Element,\n clientX: number,\n clientY: number,\n): DataTableCellHit | undefined {\n const rows = Array.from(root.querySelectorAll('tr'))\n for (let row = 0; row < rows.length; row++) {\n const cells = Array.from(rows[row].children).filter(\n (cell): cell is HTMLElement =>\n cell.tagName === 'TD' || cell.tagName === 'TH',\n )\n for (let column = 0; column < cells.length; column++) {\n const rect = cells[column].getBoundingClientRect()\n if (\n clientX >= rect.left &&\n clientX <= rect.right &&\n clientY >= rect.top &&\n clientY <= rect.bottom\n ) {\n return { element: cells[column], row, column }\n }\n }\n }\n return undefined\n}\n\n/** The text a stored grid holds at one cell, or `''` when it is outside it. */\nexport function readDataTableCell(\n value: unknown,\n row: number,\n column: number,\n): string {\n return parseDataTableRows(value)[row]?.[column] ?? ''\n}\n\n/**\n * The stored grid with one cell replaced.\n *\n * A cell is one line — the storage is one row per line — so a line break\n * typed into the cell becomes a space instead of splitting the row. Column\n * alignments survive: they ride the same string as a divider row, and are\n * read back out and written again with the grid.\n */\nexport function writeDataTableCell(\n value: unknown,\n row: number,\n column: number,\n text: string,\n): string {\n const grid = parseDataTableRows(value)\n const width = grid[0]?.length ?? 0\n const alignments = readDataTableAlignments(value, width)\n const cell = text.replace(/\\s*\\r?\\n\\s*/g, ' ').trim()\n return serializeDataTable(withCellSet(grid, row, column, cell), alignments)\n}\n\n/**\n * What the cell editor opens with (AGL-4203): the cell's words, and its\n * markup when it was formatted. A plain cell has no markup, and the editor\n * builds its surface from the words as it does for unformatted text.\n */\nexport function readDataTableCellForEdit(\n value: unknown,\n row: number,\n column: number,\n): { text: string; html: string } {\n const raw = readDataTableCell(value, row, column)\n return isDataTableCellMarkup(raw)\n ? { text: dataTableCellText(raw), html: raw }\n : { text: raw, html: '' }\n}\n\n/**\n * What a cell edit stores (AGL-4203): the sanitized markup when the author\n * formatted something, the plain words otherwise — so a table nobody formats\n * stays the plain grid it always was.\n *\n * One case keeps the markup without any formatting: plain words that would\n * READ as markup (`a < b` typed out literally, or a tag spelled in text).\n * Stored plain, the renderer would draw them as a tag; stored escaped, they\n * draw as typed.\n */\nexport function dataTableCellValueFromEdit(\n plain: string,\n sanitized: string,\n): string {\n if (/<[a-z]/i.test(sanitized)) return sanitized\n if (isDataTableCellMarkup(plain)) return sanitized\n return plain\n}\n\n/**\n * `props` after one change to the table's shape: the grid, and the\n * emphasized column moved with its column (AGL-4203). The emphasis is\n * written only when it moves, so a row edit never touches it.\n */\nexport function withDataTableShapeEdit(\n props: Record<string, unknown>,\n attribute: string,\n edit: DataTableShapeEdit,\n): Record<string, unknown> {\n const stored = props[attribute]\n const width = parseDataTableRows(stored)[0]?.length ?? 0\n const next: Record<string, unknown> = {\n ...props,\n [attribute]: editDataTableShape(stored, edit),\n }\n if (DATA_TABLE_EMPHASIS_PROP in props) {\n const before = normalizeEmphasisColumn(props[DATA_TABLE_EMPHASIS_PROP], width)\n const after = emphasisAfterShapeEdit(\n props[DATA_TABLE_EMPHASIS_PROP],\n width,\n edit,\n )\n if (after !== before) next[DATA_TABLE_EMPHASIS_PROP] = after\n }\n return next\n}\n\n/** `props` with an empty table started — the same starter the Attributes grid writes. */\nexport function withDataTableStarted(\n props: Record<string, unknown>,\n attribute: string,\n): Record<string, unknown> {\n return { ...props, [attribute]: dataTableStarterValue() }\n}\n\n/** One row or column action offered on a cell. */\nexport interface DataTableCellAction {\n key: string\n label: string\n icon: string\n edit: DataTableShapeEdit\n disabled: boolean\n}\n\n/**\n * The row and column actions for one cell, in the order both the right-click\n * menu and the cell editor's toolbar list them (AGL-4203). Deleting the last\n * row or the last column is offered but disabled, as the Attributes grid\n * does: a table with no cells left has nothing to click to get one back.\n */\nexport function dataTableCellActions(\n value: unknown,\n row: number,\n column: number,\n): DataTableCellAction[] {\n const grid = parseDataTableRows(value)\n const rows = grid.length\n const columns = grid[0]?.length ?? 0\n return [\n {\n key: 'row-above',\n label: 'Insert row above',\n icon: mdiTableRowPlusBefore.path,\n edit: { kind: 'insertRow', at: row },\n disabled: false,\n },\n {\n key: 'row-below',\n label: 'Insert row below',\n icon: mdiTableRowPlusAfter.path,\n edit: { kind: 'insertRow', at: row + 1 },\n disabled: false,\n },\n {\n key: 'column-left',\n label: 'Insert column left',\n icon: mdiTableColumnPlusBefore.path,\n edit: { kind: 'insertColumn', at: column },\n disabled: false,\n },\n {\n key: 'column-right',\n label: 'Insert column right',\n icon: mdiTableColumnPlusAfter.path,\n edit: { kind: 'insertColumn', at: column + 1 },\n disabled: false,\n },\n {\n key: 'row-delete',\n label: 'Delete row',\n icon: mdiTableRowRemove.path,\n edit: { kind: 'removeRow', at: row },\n disabled: rows <= 1,\n },\n {\n key: 'column-delete',\n label: 'Delete column',\n icon: mdiTableColumnRemove.path,\n edit: { kind: 'removeColumn', at: column },\n disabled: columns <= 1,\n },\n ]\n}\n"],"names":["FieldComponentType","DATA_TABLE_EMPHASIS_PROP","dataTableCellText","dataTableStarterValue","editDataTableShape","emphasisAfterShapeEdit","isDataTableCellMarkup","normalizeEmphasisColumn","parseDataTableRows","readDataTableAlignments","serializeDataTable","withCellSet","mdiTableColumnPlusAfter","mdiTableColumnPlusBefore","mdiTableColumnRemove","mdiTableRowPlusAfter","mdiTableRowPlusBefore","mdiTableRowRemove","findDataTableAttributeName","node","attribute","componentSchema","attributes","component","DATA_TABLE","name","undefined","findDataTableCellAtPoint","root","clientX","clientY","rows","Array","from","querySelectorAll","row","length","cells","children","filter","cell","tagName","column","rect","getBoundingClientRect","left","right","top","bottom","element","readDataTableCell","value","writeDataTableCell","text","grid","width","alignments","replace","trim","readDataTableCellForEdit","raw","html","dataTableCellValueFromEdit","plain","sanitized","test","withDataTableShapeEdit","props","edit","stored","next","before","after","withDataTableStarted","dataTableCellActions","columns","key","label","icon","path","kind","at","disabled"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SAASA,kBAAkB,QAAQ,eAAc;AACjD,SACEC,wBAAwB,EAExBC,iBAAiB,EACjBC,qBAAqB,EACrBC,kBAAkB,EAClBC,sBAAsB,EACtBC,qBAAqB,EACrBC,uBAAuB,EACvBC,kBAAkB,EAClBC,uBAAuB,EACvBC,kBAAkB,EAClBC,WAAW,QACN,2BAA0B;AACjC,SACEC,uBAAuB,EACvBC,wBAAwB,EACxBC,oBAAoB,EACpBC,oBAAoB,EACpBC,qBAAqB,EACrBC,iBAAiB,QACZ,yBAAwB;AAE/B;;;;;;;;;;CAUC,GAED;;;;;;CAMC,GACD,OAAO,SAASC,2BACdC,IAAuC;;QAEfA;IAAxB,KAAK,MAAMC,qBAAaD,yBAAAA,wBAAAA,KAAME,eAAe,qBAArBF,sBAAuBG,UAAU,mBAAI,EAAE,CAAE;QAC/D,IAAIF,CAAAA,6BAAAA,UAAWG,SAAS,MAAKvB,mBAAmBwB,UAAU,EAAE;YAC1D,OAAOJ,UAAUK,IAAI;QACvB;IACF;IACA,OAAOC;AACT;AAUA;;;;;;;;;;CAUC,GACD,OAAO,SAASC,yBACdC,IAAa,EACbC,OAAe,EACfC,OAAe;IAEf,MAAMC,OAAOC,MAAMC,IAAI,CAACL,KAAKM,gBAAgB,CAAC;IAC9C,IAAK,IAAIC,MAAM,GAA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