@aglyn/shared-data-enums 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/shared-data-enums",
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,8 +25,8 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/shared-data-mdi": "1.20.1",
29
- "@aglyn/shared-util-tools": "1.20.1",
28
+ "@aglyn/shared-data-mdi": "1.20.3",
29
+ "@aglyn/shared-util-tools": "1.20.3",
30
30
  "@swc/helpers": "0.5.23"
31
31
  },
32
32
  "peerDependencies": {
@@ -154,7 +154,18 @@ function isDividerRow(cells) {
154
154
  */ export function serializeDataTable(rows, alignments) {
155
155
  var _ref, _ref1;
156
156
  var _rows_;
157
- const body = (rows != null ? rows : []).map((row)=>(row != null ? row : []).map((cell)=>String(cell != null ? cell : '').replace(/\|/g, '\\|')).join(' | '));
157
+ const body = (rows != null ? rows : []).map((row)=>{
158
+ const cells = (row != null ? row : []).map((cell)=>String(cell != null ? cell : '').replace(/\|/g, '\\|'));
159
+ const line = cells.join(' | ');
160
+ // An empty first or last cell needs the outer pipes (AGL-4216). Without
161
+ // them `Feature | Us | ` trims to `Feature | Us |`, whose last pipe reads
162
+ // as an optional outer one, and the empty column is gone on the next
163
+ // parse. That is exactly the column "Add column" appends, so appending
164
+ // one did nothing. Rows that do not need them keep the plain form, so
165
+ // stored tables do not change.
166
+ const edgeEmpty = cells.length > 0 && (cells[0].trim() === '' || cells[cells.length - 1].trim() === '');
167
+ return edgeEmpty ? `| ${line} |` : line;
168
+ });
158
169
  const meaningful = (_ref = alignments == null ? void 0 : alignments.some((alignment)=>alignment && alignment !== DATA_TABLE_ALIGNMENT_DEFAULT)) != null ? _ref : false;
159
170
  if (!meaningful || body.length === 0) return body.join('\n');
160
171
  const width = (_ref1 = (_rows_ = rows[0]) == null ? void 0 : _rows_.length) != null ? _ref1 : 0;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/shared/data/enums/src/lib/data-table.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/**\n * The grid behind the Table element (AGL-2543).\n *\n * ONE parser, shared by the renderer and the attributes-panel editor. Two\n * implementations of \"what does this string mean\" is how a table comes to\n * look right in the canvas and wrong on the page, and the two are written by\n * different people months apart.\n *\n * The persisted prop is a single string, following the house pattern used by\n * `CSS_DIMENSION` and `CSS_GRADIENT`: the rich editor is an input affordance,\n * not a shape change, so nothing downstream has to learn a new type and a\n * value the editor cannot model is never clobbered.\n *\n * Pipe-delimited, one row per line — deliberately the markdown table body's\n * own syntax, so the comparison tables already authored in Markdown elements\n * paste straight in. A leading and trailing pipe are optional, which is what\n * a copied markdown table has.\n */\n\n/**\n * The Table element's 1-based \"emphasize column\" prop. Named here because a\n * shape edit made outside the element (the canvas) has to move it with its\n * column — see {@link emphasisAfterShapeEdit}.\n */\nexport const DATA_TABLE_EMPHASIS_PROP = 'emphasizeColumn'\n\n/** Column alignments the editor offers and the renderer honours. */\nexport const DATA_TABLE_ALIGNMENTS = ['left', 'center', 'right'] as const\n\nexport type DataTableAlignment = (typeof DATA_TABLE_ALIGNMENTS)[number]\n\nexport const DATA_TABLE_ALIGNMENT_DEFAULT: DataTableAlignment = 'left'\n\n/**\n * A markdown alignment divider — `|---|:--:|---:|`.\n *\n * Dropped rather than rendered as a row of dashes. It carries no content, and\n * an author pasting a markdown table has no reason to expect it to survive as\n * data; its alignment intent is read out separately by\n * {@link alignmentsFromDivider}.\n */\nconst DIVIDER_CELL = /^:?-{2,}:?$/\n\nfunction splitRow(line: string): string[] {\n // `\\|` is a literal pipe, so a cell may contain one. Split on unescaped\n // pipes only, then unescape — doing it in the other order would turn an\n // escaped pipe into a column break.\n const cells = line\n .replace(/^\\s*\\|/, '')\n .replace(/\\|\\s*$/, '')\n .split(/(?<!\\\\)\\|/)\n .map((cell) => cell.replace(/\\\\\\|/g, '|').trim())\n return cells\n}\n\nfunction isDividerRow(cells: string[]): boolean {\n return cells.length > 0 && cells.every((cell) => DIVIDER_CELL.test(cell))\n}\n\n/**\n * The alignments a pasted markdown divider row encodes, or `null` when the\n * line is not one. `:--` is left, `:-:` centre, `--:` right.\n */\nexport function alignmentsFromDivider(\n line: string,\n): DataTableAlignment[] | null {\n const cells = splitRow(String(line ?? ''))\n if (!isDividerRow(cells)) return null\n return cells.map((cell) => {\n const left = cell.startsWith(':')\n const right = cell.endsWith(':')\n if (left && right) return 'center'\n if (right) return 'right'\n return 'left'\n })\n}\n\n/**\n * The grid a stored value describes.\n *\n * Rows are padded to the widest one so the renderer and the editor always see\n * a rectangle: a short row is an authoring accident, and a table that renders\n * with a missing cell is harder to fix than one with an empty one.\n */\nexport function parseDataTableRows(value: unknown): string[][] {\n const text = typeof value === 'string' ? value : ''\n const rows = text\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .filter((line) => line.length > 0)\n .map(splitRow)\n .filter((cells) => !isDividerRow(cells))\n const width = rows.reduce((widest, row) => Math.max(widest, row.length), 0)\n return rows.map((row) => [\n ...row,\n ...Array.from({ length: width - row.length }, () => ''),\n ])\n}\n\n/**\n * The alignments a stored value carries, padded to the table's width.\n *\n * Alignment lives in the SAME string as the grid, as a markdown divider row,\n * rather than in a prop of its own. A field editor is handed one prop, so a\n * second prop could not be reached from the grid's own per-column controls —\n * and encoding it the way markdown already does means a pasted table keeps\n * the alignment it was authored with instead of silently flattening to left.\n */\nexport function readDataTableAlignments(\n value: unknown,\n columnCount: number,\n): DataTableAlignment[] {\n const found = String(value ?? '')\n .split(/\\r?\\n/)\n .map((line) => alignmentsFromDivider(line))\n .find((alignments) => alignments !== null)\n return Array.from({ length: Math.max(0, columnCount) }, (_, index) => {\n const candidate = found?.[index]\n return candidate ?? DATA_TABLE_ALIGNMENT_DEFAULT\n })\n}\n\n/** A row of a table the author pasted, and the alignments it carried. */\nexport interface PastedDataTable {\n rows: string[][]\n alignments: DataTableAlignment[]\n}\n\n/** A pipe that breaks a column, as opposed to a `\\|` inside a cell. */\nfunction hasUnescapedPipe(line: string): boolean {\n return /(?<!\\\\)\\|/.test(line)\n}\n\n/**\n * The table a pasted string describes, or `null` when it is not one\n * (AGL-2568).\n *\n * Reading it is the migration path off the Markdown workaround: the tables\n * this element replaces are already authored as pipe syntax, and the\n * alternative to importing them is retyping thirty cells of dated competitor\n * pricing by hand, which is the content least safe to retype.\n *\n * `null` rather than a best effort is the important half. This runs on every\n * paste into every cell, and an author pasting `Pro | Business` as a cell\n * VALUE must get those characters, not a two-column table. So a paste is only\n * read as a table when it could not sensibly be anything else: more than one\n * line, every one of them carrying an unescaped pipe, and at least two\n * columns once parsed. A single line never qualifies, however many pipes it\n * has.\n */\nexport function readPastedDataTable(value: unknown): PastedDataTable | null {\n const text = typeof value === 'string' ? value : ''\n const lines = text\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .filter((line) => line.length > 0)\n if (lines.length < 2 || !lines.every(hasUnescapedPipe)) return null\n const rows = parseDataTableRows(text)\n const width = rows[0]?.length ?? 0\n if (rows.length === 0 || width < 2) return null\n return { rows, alignments: readDataTableAlignments(text, width) }\n}\n\n/** The markdown divider encoding one column's alignment. */\nfunction dividerCell(alignment: DataTableAlignment): string {\n if (alignment === 'center') return ':---:'\n if (alignment === 'right') return '---:'\n return '---'\n}\n\n/**\n * The stored form of a grid plus its alignments.\n *\n * The divider is written after the first row, where markdown puts it, and\n * only when some column is not the default — an all-left table stays a plain\n * pipe grid rather than growing a row of dashes nobody asked for.\n */\nexport function serializeDataTable(\n rows: string[][],\n alignments?: readonly DataTableAlignment[],\n): string {\n const body = (rows ?? []).map((row) =>\n (row ?? [])\n .map((cell) => String(cell ?? '').replace(/\\|/g, '\\\\|'))\n .join(' | '),\n )\n const meaningful =\n alignments?.some(\n (alignment) => alignment && alignment !== DATA_TABLE_ALIGNMENT_DEFAULT,\n ) ?? false\n if (!meaningful || body.length === 0) return body.join('\\n')\n const width = rows[0]?.length ?? 0\n const divider = Array.from({ length: width }, (_, index) =>\n dividerCell(alignments?.[index] ?? DATA_TABLE_ALIGNMENT_DEFAULT),\n ).join(' | ')\n return [body[0], divider, ...body.slice(1)].join('\\n')\n}\n\n/**\n * The 1-based column to emphasise, or `0` for none.\n *\n * 1-based because the control says \"column 3\" to an author who is looking at\n * the third column; `0` rather than `null` so \"none\" survives a form field\n * that only speaks numbers. Out-of-range values mean none, so deleting a\n * column cannot leave a table pointing at one that is gone.\n */\nexport function normalizeEmphasisColumn(\n value: unknown,\n columnCount: number,\n): number {\n const parsed = Math.trunc(Number(value))\n if (!Number.isFinite(parsed) || parsed < 1 || parsed > columnCount) return 0\n return parsed\n}\n\n/** A grid with `count` empty columns appended to every row. */\nexport function withColumnAdded(rows: string[][], at?: number): string[][] {\n const width = rows[0]?.length ?? 0\n const index = at == null ? width : Math.max(0, Math.min(at, width))\n return (rows.length ? rows : [[]]).map((row) => {\n const next = [...row]\n next.splice(index, 0, '')\n return next\n })\n}\n\nexport function withColumnRemoved(rows: string[][], at: number): string[][] {\n const width = rows[0]?.length ?? 0\n // Never leave a table with no columns: a zero-column grid cannot be typed\n // back into through the editor, so the last column is not removable.\n if (width <= 1) return rows\n return rows.map((row) => row.filter((_, index) => index !== at))\n}\n\nexport function withRowAdded(rows: string[][], at?: number): string[][] {\n const width = rows[0]?.length ?? 1\n const blank = Array.from({ length: width }, () => '')\n const next = [...rows]\n next.splice(at == null ? rows.length : Math.max(0, Math.min(at, rows.length)), 0, blank)\n return next\n}\n\nexport function withRowRemoved(rows: string[][], at: number): string[][] {\n if (rows.length <= 1) return rows\n return rows.filter((_, index) => index !== at)\n}\n\nexport function withCellSet(\n rows: string[][],\n rowIndex: number,\n columnIndex: number,\n value: string,\n): string[][] {\n return rows.map((row, r) =>\n r === rowIndex\n ? row.map((cell, c) => (c === columnIndex ? value : cell))\n : row,\n )\n}\n\n/**\n * A cell that holds FORMATTED text: inline markup (bold, italic, underline,\n * a link, a line break), written by the canvas's in-place cell editor.\n *\n * A cell is otherwise plain text, and both kinds live in the same pipe grid:\n * nothing about the storage changes, and a table nobody formats is\n * byte-for-byte what it always was. The test is \"starts a tag or spells a\n * character reference\", which is what the editor writes for ANY cell whose\n * text could be misread as markup (it stores `a &lt; b` rather than `a < b`\n * when the text happens to spell a tag), so the reading is never a guess\n * about what an author meant.\n */\nexport function isDataTableCellMarkup(cell: unknown): boolean {\n return (\n typeof cell === 'string' &&\n /<[a-z/!]|&(#\\d+|#x[0-9a-f]+|[a-z][a-z0-9]*);/i.test(cell)\n )\n}\n\nconst CELL_ENTITIES: Record<string, string> = {\n amp: '&',\n lt: '<',\n gt: '>',\n quot: '\"',\n apos: \"'\",\n nbsp: ' ',\n}\n\n/**\n * The words a cell shows, without its formatting — what a field that can\n * only hold plain text (the Attributes grid) displays for a formatted cell.\n */\nexport function dataTableCellText(cell: unknown): string {\n const text = typeof cell === 'string' ? cell : ''\n if (!isDataTableCellMarkup(text)) return text\n return text\n .replace(/<br\\s*\\/?>/gi, ' ')\n .replace(/<[^>]*>/g, '')\n .replace(/&(#\\d+|#x[0-9a-f]+|[a-z][a-z0-9]*);/gi, (whole, name: string) => {\n if (name[0] === '#') {\n const code =\n name[1] === 'x' || name[1] === 'X'\n ? parseInt(name.slice(2), 16)\n : parseInt(name.slice(1), 10)\n return Number.isFinite(code) ? String.fromCodePoint(code) : whole\n }\n return CELL_ENTITIES[name.toLowerCase()] ?? whole\n })\n .replace(/\\s+/g, ' ')\n .trim()\n}\n\n/** One change to a table's shape, as the canvas and the Attributes grid make it. */\nexport type DataTableShapeEdit =\n | { kind: 'insertRow'; at: number }\n | { kind: 'removeRow'; at: number }\n | { kind: 'insertColumn'; at: number }\n | { kind: 'removeColumn'; at: number }\n\n/**\n * The stored value after one shape edit, with each column's ALIGNMENT moving\n * with its column.\n *\n * Inserting or removing a column by rows alone leaves the alignments where\n * they were by index, so every column after the edit takes its neighbour's\n * alignment: a centred \"Us\" column turns left-aligned the moment a column is\n * inserted before it. The alignment is spliced at the same index as the\n * cells, and a new column starts at the default.\n */\nexport function editDataTableShape(\n value: unknown,\n edit: DataTableShapeEdit,\n): string {\n const rows = parseDataTableRows(value)\n const width = rows[0]?.length ?? 0\n const alignments = readDataTableAlignments(value, width)\n switch (edit.kind) {\n case 'insertRow':\n return serializeDataTable(withRowAdded(rows, edit.at), alignments)\n case 'removeRow':\n return serializeDataTable(withRowRemoved(rows, edit.at), alignments)\n case 'insertColumn': {\n const at = Math.max(0, Math.min(edit.at, width))\n const next = [...alignments]\n next.splice(at, 0, DATA_TABLE_ALIGNMENT_DEFAULT)\n return serializeDataTable(withColumnAdded(rows, at), next)\n }\n case 'removeColumn': {\n if (width <= 1) return serializeDataTable(rows, alignments)\n return serializeDataTable(\n withColumnRemoved(rows, edit.at),\n alignments.filter((_, index) => index !== edit.at),\n )\n }\n }\n}\n\n/**\n * The emphasised column after a shape edit, so the highlight stays on the\n * column it was put on (1-based, `0` for none — see\n * {@link normalizeEmphasisColumn}).\n *\n * Inserting a column before \"Us\" moves \"Us\" one to the right, and the\n * highlight goes with it. Removing the emphasised column removes the\n * highlight rather than handing it to whichever column slid into the gap.\n */\nexport function emphasisAfterShapeEdit(\n emphasis: unknown,\n columnCount: number,\n edit: DataTableShapeEdit,\n): number {\n const current = normalizeEmphasisColumn(emphasis, columnCount)\n if (current === 0) return 0\n const index = current - 1\n if (edit.kind === 'insertColumn') {\n return edit.at <= index ? current + 1 : current\n }\n if (edit.kind === 'removeColumn') {\n if (columnCount <= 1) return current\n if (edit.at === index) return 0\n return edit.at < index ? current - 1 : current\n }\n return current\n}\n\n/**\n * What \"Start a table\" writes into an empty Table, wherever it is offered:\n * a header row and one blank row, with the two comparison columns centred.\n */\nexport const DATA_TABLE_STARTER = {\n rows: [\n ['Feature', 'Us', 'Them'],\n ['', '', ''],\n ],\n alignments: ['left', 'center', 'center'] as DataTableAlignment[],\n}\n\n/** {@link DATA_TABLE_STARTER} in its stored form. */\nexport function dataTableStarterValue(): string {\n return serializeDataTable(\n DATA_TABLE_STARTER.rows,\n DATA_TABLE_STARTER.alignments,\n )\n}\n"],"names":["DATA_TABLE_EMPHASIS_PROP","DATA_TABLE_ALIGNMENTS","DATA_TABLE_ALIGNMENT_DEFAULT","DIVIDER_CELL","splitRow","line","cells","replace","split","map","cell","trim","isDividerRow","length","every","test","alignmentsFromDivider","String","left","startsWith","right","endsWith","parseDataTableRows","value","text","rows","filter","width","reduce","widest","row","Math","max","Array","from","readDataTableAlignments","columnCount","found","find","alignments","_","index","candidate","hasUnescapedPipe","readPastedDataTable","lines","dividerCell","alignment","serializeDataTable","body","join","meaningful","some","divider","slice","normalizeEmphasisColumn","parsed","trunc","Number","isFinite","withColumnAdded","at","min","next","splice","withColumnRemoved","withRowAdded","blank","withRowRemoved","withCellSet","rowIndex","columnIndex","r","c","isDataTableCellMarkup","CELL_ENTITIES","amp","lt","gt","quot","apos","nbsp","dataTableCellText","whole","name","code","parseInt","fromCodePoint","toLowerCase","editDataTableShape","edit","kind","emphasisAfterShapeEdit","emphasis","current","DATA_TABLE_STARTER","dataTableStarterValue"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;CAiBC,GAED;;;;CAIC,GACD,OAAO,MAAMA,2BAA2B,kBAAiB;AAEzD,kEAAkE,GAClE,OAAO,MAAMC,wBAAwB;IAAC;IAAQ;IAAU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IAChCtE,MAAM;QACJ;YAAC;YAAW;YAAM;SAAO;QACzB;YAAC;YAAI;YAAI;SAAG;KACb;IACDc,YAAY;QAAC;QAAQ;QAAU;KAAS;AAC1C,EAAC;AAED,mDAAmD,GACnD,OAAO,SAASyD;IACd,OAAOhD,mBACL+C,mBAAmBtE,IAAI,EACvBsE,mBAAmBxD,UAAU;AAEjC"}
1
+ {"version":3,"sources":["../../../../../../../libs/shared/data/enums/src/lib/data-table.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/**\n * The grid behind the Table element (AGL-2543).\n *\n * ONE parser, shared by the renderer and the attributes-panel editor. Two\n * implementations of \"what does this string mean\" is how a table comes to\n * look right in the canvas and wrong on the page, and the two are written by\n * different people months apart.\n *\n * The persisted prop is a single string, following the house pattern used by\n * `CSS_DIMENSION` and `CSS_GRADIENT`: the rich editor is an input affordance,\n * not a shape change, so nothing downstream has to learn a new type and a\n * value the editor cannot model is never clobbered.\n *\n * Pipe-delimited, one row per line — deliberately the markdown table body's\n * own syntax, so the comparison tables already authored in Markdown elements\n * paste straight in. A leading and trailing pipe are optional, which is what\n * a copied markdown table has.\n */\n\n/**\n * The Table element's 1-based \"emphasize column\" prop. Named here because a\n * shape edit made outside the element (the canvas) has to move it with its\n * column — see {@link emphasisAfterShapeEdit}.\n */\nexport const DATA_TABLE_EMPHASIS_PROP = 'emphasizeColumn'\n\n/** Column alignments the editor offers and the renderer honours. */\nexport const DATA_TABLE_ALIGNMENTS = ['left', 'center', 'right'] as const\n\nexport type DataTableAlignment = (typeof DATA_TABLE_ALIGNMENTS)[number]\n\nexport const DATA_TABLE_ALIGNMENT_DEFAULT: DataTableAlignment = 'left'\n\n/**\n * A markdown alignment divider — `|---|:--:|---:|`.\n *\n * Dropped rather than rendered as a row of dashes. It carries no content, and\n * an author pasting a markdown table has no reason to expect it to survive as\n * data; its alignment intent is read out separately by\n * {@link alignmentsFromDivider}.\n */\nconst DIVIDER_CELL = /^:?-{2,}:?$/\n\nfunction splitRow(line: string): string[] {\n // `\\|` is a literal pipe, so a cell may contain one. Split on unescaped\n // pipes only, then unescape — doing it in the other order would turn an\n // escaped pipe into a column break.\n const cells = line\n .replace(/^\\s*\\|/, '')\n .replace(/\\|\\s*$/, '')\n .split(/(?<!\\\\)\\|/)\n .map((cell) => cell.replace(/\\\\\\|/g, '|').trim())\n return cells\n}\n\nfunction isDividerRow(cells: string[]): boolean {\n return cells.length > 0 && cells.every((cell) => DIVIDER_CELL.test(cell))\n}\n\n/**\n * The alignments a pasted markdown divider row encodes, or `null` when the\n * line is not one. `:--` is left, `:-:` centre, `--:` right.\n */\nexport function alignmentsFromDivider(\n line: string,\n): DataTableAlignment[] | null {\n const cells = splitRow(String(line ?? ''))\n if (!isDividerRow(cells)) return null\n return cells.map((cell) => {\n const left = cell.startsWith(':')\n const right = cell.endsWith(':')\n if (left && right) return 'center'\n if (right) return 'right'\n return 'left'\n })\n}\n\n/**\n * The grid a stored value describes.\n *\n * Rows are padded to the widest one so the renderer and the editor always see\n * a rectangle: a short row is an authoring accident, and a table that renders\n * with a missing cell is harder to fix than one with an empty one.\n */\nexport function parseDataTableRows(value: unknown): string[][] {\n const text = typeof value === 'string' ? value : ''\n const rows = text\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .filter((line) => line.length > 0)\n .map(splitRow)\n .filter((cells) => !isDividerRow(cells))\n const width = rows.reduce((widest, row) => Math.max(widest, row.length), 0)\n return rows.map((row) => [\n ...row,\n ...Array.from({ length: width - row.length }, () => ''),\n ])\n}\n\n/**\n * The alignments a stored value carries, padded to the table's width.\n *\n * Alignment lives in the SAME string as the grid, as a markdown divider row,\n * rather than in a prop of its own. A field editor is handed one prop, so a\n * second prop could not be reached from the grid's own per-column controls —\n * and encoding it the way markdown already does means a pasted table keeps\n * the alignment it was authored with instead of silently flattening to left.\n */\nexport function readDataTableAlignments(\n value: unknown,\n columnCount: number,\n): DataTableAlignment[] {\n const found = String(value ?? '')\n .split(/\\r?\\n/)\n .map((line) => alignmentsFromDivider(line))\n .find((alignments) => alignments !== null)\n return Array.from({ length: Math.max(0, columnCount) }, (_, index) => {\n const candidate = found?.[index]\n return candidate ?? DATA_TABLE_ALIGNMENT_DEFAULT\n })\n}\n\n/** A row of a table the author pasted, and the alignments it carried. */\nexport interface PastedDataTable {\n rows: string[][]\n alignments: DataTableAlignment[]\n}\n\n/** A pipe that breaks a column, as opposed to a `\\|` inside a cell. */\nfunction hasUnescapedPipe(line: string): boolean {\n return /(?<!\\\\)\\|/.test(line)\n}\n\n/**\n * The table a pasted string describes, or `null` when it is not one\n * (AGL-2568).\n *\n * Reading it is the migration path off the Markdown workaround: the tables\n * this element replaces are already authored as pipe syntax, and the\n * alternative to importing them is retyping thirty cells of dated competitor\n * pricing by hand, which is the content least safe to retype.\n *\n * `null` rather than a best effort is the important half. This runs on every\n * paste into every cell, and an author pasting `Pro | Business` as a cell\n * VALUE must get those characters, not a two-column table. So a paste is only\n * read as a table when it could not sensibly be anything else: more than one\n * line, every one of them carrying an unescaped pipe, and at least two\n * columns once parsed. A single line never qualifies, however many pipes it\n * has.\n */\nexport function readPastedDataTable(value: unknown): PastedDataTable | null {\n const text = typeof value === 'string' ? value : ''\n const lines = text\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .filter((line) => line.length > 0)\n if (lines.length < 2 || !lines.every(hasUnescapedPipe)) return null\n const rows = parseDataTableRows(text)\n const width = rows[0]?.length ?? 0\n if (rows.length === 0 || width < 2) return null\n return { rows, alignments: readDataTableAlignments(text, width) }\n}\n\n/** The markdown divider encoding one column's alignment. */\nfunction dividerCell(alignment: DataTableAlignment): string {\n if (alignment === 'center') return ':---:'\n if (alignment === 'right') return '---:'\n return '---'\n}\n\n/**\n * The stored form of a grid plus its alignments.\n *\n * The divider is written after the first row, where markdown puts it, and\n * only when some column is not the default — an all-left table stays a plain\n * pipe grid rather than growing a row of dashes nobody asked for.\n */\nexport function serializeDataTable(\n rows: string[][],\n alignments?: readonly DataTableAlignment[],\n): string {\n const body = (rows ?? []).map((row) => {\n const cells = (row ?? []).map((cell) =>\n String(cell ?? '').replace(/\\|/g, '\\\\|'),\n )\n const line = cells.join(' | ')\n // An empty first or last cell needs the outer pipes (AGL-4216). Without\n // them `Feature | Us | ` trims to `Feature | Us |`, whose last pipe reads\n // as an optional outer one, and the empty column is gone on the next\n // parse. That is exactly the column \"Add column\" appends, so appending\n // one did nothing. Rows that do not need them keep the plain form, so\n // stored tables do not change.\n const edgeEmpty =\n cells.length > 0 &&\n (cells[0]!.trim() === '' || cells[cells.length - 1]!.trim() === '')\n return edgeEmpty ? `| ${line} |` : line\n })\n const meaningful =\n alignments?.some(\n (alignment) => alignment && alignment !== DATA_TABLE_ALIGNMENT_DEFAULT,\n ) ?? false\n if (!meaningful || body.length === 0) return body.join('\\n')\n const width = rows[0]?.length ?? 0\n const divider = Array.from({ length: width }, (_, index) =>\n dividerCell(alignments?.[index] ?? DATA_TABLE_ALIGNMENT_DEFAULT),\n ).join(' | ')\n return [body[0], divider, ...body.slice(1)].join('\\n')\n}\n\n/**\n * The 1-based column to emphasise, or `0` for none.\n *\n * 1-based because the control says \"column 3\" to an author who is looking at\n * the third column; `0` rather than `null` so \"none\" survives a form field\n * that only speaks numbers. Out-of-range values mean none, so deleting a\n * column cannot leave a table pointing at one that is gone.\n */\nexport function normalizeEmphasisColumn(\n value: unknown,\n columnCount: number,\n): number {\n const parsed = Math.trunc(Number(value))\n if (!Number.isFinite(parsed) || parsed < 1 || parsed > columnCount) return 0\n return parsed\n}\n\n/** A grid with `count` empty columns appended to every row. */\nexport function withColumnAdded(rows: string[][], at?: number): string[][] {\n const width = rows[0]?.length ?? 0\n const index = at == null ? width : Math.max(0, Math.min(at, width))\n return (rows.length ? rows : [[]]).map((row) => {\n const next = [...row]\n next.splice(index, 0, '')\n return next\n })\n}\n\nexport function withColumnRemoved(rows: string[][], at: number): string[][] {\n const width = rows[0]?.length ?? 0\n // Never leave a table with no columns: a zero-column grid cannot be typed\n // back into through the editor, so the last column is not removable.\n if (width <= 1) return rows\n return rows.map((row) => row.filter((_, index) => index !== at))\n}\n\nexport function withRowAdded(rows: string[][], at?: number): string[][] {\n const width = rows[0]?.length ?? 1\n const blank = Array.from({ length: width }, () => '')\n const next = [...rows]\n next.splice(at == null ? rows.length : Math.max(0, Math.min(at, rows.length)), 0, blank)\n return next\n}\n\nexport function withRowRemoved(rows: string[][], at: number): string[][] {\n if (rows.length <= 1) return rows\n return rows.filter((_, index) => index !== at)\n}\n\nexport function withCellSet(\n rows: string[][],\n rowIndex: number,\n columnIndex: number,\n value: string,\n): string[][] {\n return rows.map((row, r) =>\n r === rowIndex\n ? row.map((cell, c) => (c === columnIndex ? value : cell))\n : row,\n )\n}\n\n/**\n * A cell that holds FORMATTED text: inline markup (bold, italic, underline,\n * a link, a line break), written by the canvas's in-place cell editor.\n *\n * A cell is otherwise plain text, and both kinds live in the same pipe grid:\n * nothing about the storage changes, and a table nobody formats is\n * byte-for-byte what it always was. The test is \"starts a tag or spells a\n * character reference\", which is what the editor writes for ANY cell whose\n * text could be misread as markup (it stores `a &lt; b` rather than `a < b`\n * when the text happens to spell a tag), so the reading is never a guess\n * about what an author meant.\n */\nexport function isDataTableCellMarkup(cell: unknown): boolean {\n return (\n typeof cell === 'string' &&\n /<[a-z/!]|&(#\\d+|#x[0-9a-f]+|[a-z][a-z0-9]*);/i.test(cell)\n )\n}\n\nconst CELL_ENTITIES: Record<string, string> = {\n amp: '&',\n lt: '<',\n gt: '>',\n quot: '\"',\n apos: \"'\",\n nbsp: ' ',\n}\n\n/**\n * The words a cell shows, without its formatting — what a field that can\n * only hold plain text (the Attributes grid) displays for a formatted cell.\n */\nexport function dataTableCellText(cell: unknown): string {\n const text = typeof cell === 'string' ? cell : ''\n if (!isDataTableCellMarkup(text)) return text\n return text\n .replace(/<br\\s*\\/?>/gi, ' ')\n .replace(/<[^>]*>/g, '')\n .replace(/&(#\\d+|#x[0-9a-f]+|[a-z][a-z0-9]*);/gi, (whole, name: string) => {\n if (name[0] === '#') {\n const code =\n name[1] === 'x' || name[1] === 'X'\n ? parseInt(name.slice(2), 16)\n : parseInt(name.slice(1), 10)\n return Number.isFinite(code) ? String.fromCodePoint(code) : whole\n }\n return CELL_ENTITIES[name.toLowerCase()] ?? whole\n })\n .replace(/\\s+/g, ' ')\n .trim()\n}\n\n/** One change to a table's shape, as the canvas and the Attributes grid make it. */\nexport type DataTableShapeEdit =\n | { kind: 'insertRow'; at: number }\n | { kind: 'removeRow'; at: number }\n | { kind: 'insertColumn'; at: number }\n | { kind: 'removeColumn'; at: number }\n\n/**\n * The stored value after one shape edit, with each column's ALIGNMENT moving\n * with its column.\n *\n * Inserting or removing a column by rows alone leaves the alignments where\n * they were by index, so every column after the edit takes its neighbour's\n * alignment: a centred \"Us\" column turns left-aligned the moment a column is\n * inserted before it. The alignment is spliced at the same index as the\n * cells, and a new column starts at the default.\n */\nexport function editDataTableShape(\n value: unknown,\n edit: DataTableShapeEdit,\n): string {\n const rows = parseDataTableRows(value)\n const width = rows[0]?.length ?? 0\n const alignments = readDataTableAlignments(value, width)\n switch (edit.kind) {\n case 'insertRow':\n return serializeDataTable(withRowAdded(rows, edit.at), alignments)\n case 'removeRow':\n return serializeDataTable(withRowRemoved(rows, edit.at), alignments)\n case 'insertColumn': {\n const at = Math.max(0, Math.min(edit.at, width))\n const next = [...alignments]\n next.splice(at, 0, DATA_TABLE_ALIGNMENT_DEFAULT)\n return serializeDataTable(withColumnAdded(rows, at), next)\n }\n case 'removeColumn': {\n if (width <= 1) return serializeDataTable(rows, alignments)\n return serializeDataTable(\n withColumnRemoved(rows, edit.at),\n alignments.filter((_, index) => index !== edit.at),\n )\n }\n }\n}\n\n/**\n * The emphasised column after a shape edit, so the highlight stays on the\n * column it was put on (1-based, `0` for none — see\n * {@link normalizeEmphasisColumn}).\n *\n * Inserting a column before \"Us\" moves \"Us\" one to the right, and the\n * highlight goes with it. Removing the emphasised column removes the\n * highlight rather than handing it to whichever column slid into the gap.\n */\nexport function emphasisAfterShapeEdit(\n emphasis: unknown,\n columnCount: number,\n edit: DataTableShapeEdit,\n): number {\n const current = normalizeEmphasisColumn(emphasis, columnCount)\n if (current === 0) return 0\n const index = current - 1\n if (edit.kind === 'insertColumn') {\n return edit.at <= index ? current + 1 : current\n }\n if (edit.kind === 'removeColumn') {\n if (columnCount <= 1) return current\n if (edit.at === index) return 0\n return edit.at < index ? current - 1 : current\n }\n return current\n}\n\n/**\n * What \"Start a table\" writes into an empty Table, wherever it is offered:\n * a header row and one blank row, with the two comparison columns centred.\n */\nexport const DATA_TABLE_STARTER = {\n rows: [\n ['Feature', 'Us', 'Them'],\n ['', '', ''],\n ],\n alignments: ['left', 'center', 'center'] as DataTableAlignment[],\n}\n\n/** {@link DATA_TABLE_STARTER} in its stored form. */\nexport function dataTableStarterValue(): string {\n return serializeDataTable(\n DATA_TABLE_STARTER.rows,\n DATA_TABLE_STARTER.alignments,\n )\n}\n"],"names":["DATA_TABLE_EMPHASIS_PROP","DATA_TABLE_ALIGNMENTS","DATA_TABLE_ALIGNMENT_DEFAULT","DIVIDER_CELL","splitRow","line","cells","replace","split","map","cell","trim","isDividerRow","length","every","test","alignmentsFromDivider","String","left","startsWith","right","endsWith","parseDataTableRows","value","text","rows","filter","width","reduce","widest","row","Math","max","Array","from","readDataTableAlignments","columnCount","found","find","alignments","_","index","candidate","hasUnescapedPipe","readPastedDataTable","lines","dividerCell","alignment","serializeDataTable","body","join","edgeEmpty","meaningful","some","divider","slice","normalizeEmphasisColumn","parsed","trunc","Number","isFinite","withColumnAdded","at","min","next","splice","withColumnRemoved","withRowAdded","blank","withRowRemoved","withCellSet","rowIndex","columnIndex","r","c","isDataTableCellMarkup","CELL_ENTITIES","amp","lt","gt","quot","apos","nbsp","dataTableCellText","whole","name","code","parseInt","fromCodePoint","toLowerCase","editDataTableShape","edit","kind","emphasisAfterShapeEdit","emphasis","current","DATA_TABLE_STARTER","dataTableStarterValue"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;CAiBC,GAED;;;;CAIC,GACD,OAAO,MAAMA,2BAA2B,kBAAiB;AAEzD,kEAAkE,GAClE,OAAO,MAAMC,wBAAwB;IAAC;IAAQ;IAAU;CAAQ,CAAS;AAIzE,OAAO,MAAMC,+BAAmD,OAAM;AAEtE;;;;;;;CAOC,GACD,MAAMC,eAAe;AAErB,SAASC,SAASC,IAAY;IAC5B,wEAAwE;IACxE,wEAAwE;IACxE,oCAAoC;IACpC,MAAMC,QAAQD,KACXE,OAAO,CAAC,UAAU,IAClBA,OAAO,CAAC,UAAU,IAClBC,KAAK,CAAC,aACNC,GAAG,CAAC,CAACC,OAASA,KAAKH,OAAO,CAAC,SAAS,KAAKI,IAAI;IAChD,OAAOL;AACT;AAEA,SAASM,aAAaN,KAAe;IACnC,OAAOA,MAAMO,MAAM,GAAG,KAAKP,MAAMQ,KAAK,CAAC,CAACJ,OAASP,aAAaY,IAAI,CAACL;AACrE;AAEA;;;CAGC,GACD,OAAO,SAASM,sBACdX,IAAY;IAEZ,MAAMC,QAAQF,SAASa,OAAOZ,eAAAA,OAAQ;IACtC,IAAI,CAACO,aAAaN,QAAQ,OAAO;IACjC,OAAOA,MAAMG,GAAG,CAAC,CAACC;QAChB,MAAMQ,OAAOR,KAAKS,UAAU,CAAC;QAC7B,MAAMC,QAAQV,KAAKW,QAAQ,CAAC;QAC5B,IAAIH,QAAQE,OAAO,OAAO;QAC1B,IAAIA,OAAO,OAAO;QAClB,OAAO;IACT;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SA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