docblocks-react-ui 0.23.0 → 0.24.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # docblocks-react-ui
2
2
 
3
+ ## 0.24.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bcb2bb4: An HTML table's `colspan` / `rowspan` survives the import: `importDocument`
8
+ with `kind: "html"` and the rich `text/html` paste land the merged regions as
9
+ the data model's own merged cells — the anchor cell carries the spans, the
10
+ cells a region covers stand absent from their rows, and the grid matches the
11
+ source table. The cells are placed by the browser's table model (a cell takes
12
+ the first free column of its row, a row span reserves the coordinates below),
13
+ so a row shifted by a span above keeps its columns.
14
+
15
+ A malformed span degrades to the span the grid fits — a non-integer or a value
16
+ below 1 stands 1, a span running onto a covered coordinate or past the last
17
+ row is clamped — so the parse never throws on arbitrary markup and the same
18
+ payload always imports the same document. The markdown kind carries no merged
19
+ cells (GFM cannot express them).
20
+
3
21
  ## 0.23.0
4
22
 
5
23
  ### Minor Changes
package/README.md CHANGED
@@ -296,6 +296,13 @@ attach(doc, provider);
296
296
 
297
297
  - `kind: "markdown" | "html"` — the paste parsers' shared materialization
298
298
  (the same typed block / table / runs writes the paste pipeline uses);
299
+ - an HTML table's `colspan` / `rowspan` lands as the data model's merged
300
+ regions — the anchor cell carries the spans, the cells a region covers
301
+ stand absent from their rows. A malformed span (a non-integer, below 1,
302
+ an overlap with another region, a span past the last row) degrades to the
303
+ span the grid fits; the parse never throws and the same payload always
304
+ imports the same document. The markdown path carries no merged cells (GFM
305
+ cannot express them);
299
306
  - an empty or whitespace-only payload is a no-op (no transaction);
300
307
  - a non-fresh document (the root has children) throws the typed
301
308
  `ImportDocumentError` — the import fills the root, it never appends;
@@ -21407,9 +21407,9 @@ function decodeBlockEntities(block) {
21407
21407
  /**
21408
21408
  * The materialized block's typed insertion (the `materializePaste`'s
21409
21409
  * helpers): the type's insertion over the core's per-type attrs (the
21410
- * table + its rows + the cells — the ragged rows are padded at the
21411
- * parse), the empty block's in-place conversion (the typed attrs), and
21412
- * the runs' insertion (the per-run marks).
21410
+ * table + its rows + the cells + the merged regions), the empty block's
21411
+ * in-place conversion (the typed attrs), and the runs' insertion (the
21412
+ * per-run marks).
21413
21413
  */
21414
21414
  /** The registry's content flag: the block types that hold editable text. */
21415
21415
  function isTextType(type) {
@@ -21497,9 +21497,47 @@ function insertBlockWithIndent(doc, type, parent, after, indent) {
21497
21497
  after
21498
21498
  });
21499
21499
  }
21500
- /** The table + its rows + the cells (the ragged rows are padded at the parse). */
21500
+ /**
21501
+ * The columns a merged region covers in the given row: the anchor's own row
21502
+ * keeps the anchor's column, the rows below lose the region's whole width.
21503
+ */
21504
+ function coveredColumnsOf(merges, row) {
21505
+ return (merges ?? []).flatMap((rect) => {
21506
+ if (row < rect.row || row >= rect.row + rect.rowspan) return [];
21507
+ const first = row === rect.row ? rect.col + 1 : rect.col;
21508
+ return Array.from({ length: rect.col + rect.colspan - first }, (_, index) => first + index);
21509
+ });
21510
+ }
21511
+ /**
21512
+ * The table's row as a plain paragraph (the demotion over a parent that takes
21513
+ * no table): the cells' runs joined by the cell separator. The coordinates a
21514
+ * merged region covers hold no cell of their own, so they are not text either.
21515
+ */
21516
+ function demotedTableRow(p, row) {
21517
+ const covered = coveredColumnsOf(p.merges, row);
21518
+ const cells = p.rows[row].filter((_, col) => !covered.includes(col));
21519
+ return {
21520
+ type: "paragraph",
21521
+ indent: p.indent,
21522
+ attrs: {},
21523
+ runs: cells.flatMap((cell, index) => index === 0 ? cell : [{
21524
+ text: " | ",
21525
+ marks: {}
21526
+ }, ...cell])
21527
+ };
21528
+ }
21529
+ /**
21530
+ * The table + its rows + the anchor cells: the merged regions stand the
21531
+ * anchor's own `colspan`/`rowspan` attrs and the coordinates they cover hold
21532
+ * no cell at all (the model's contract — the grid resolver derives the
21533
+ * placement). The cells of a row a region covers are bound to their grid
21534
+ * column explicitly: the insert's automatic binding is the row position, which
21535
+ * only matches while the row is full.
21536
+ */
21501
21537
  function insertTable(doc, m, parent, after, indent) {
21502
- const cols = m.rows[0].length;
21538
+ const rows = m.rows;
21539
+ const cols = rows[0].length;
21540
+ const merges = m.merges ?? [];
21503
21541
  const tableId = doc.insertBlock("table", {
21504
21542
  cols,
21505
21543
  indent
@@ -21507,24 +21545,41 @@ function insertTable(doc, m, parent, after, indent) {
21507
21545
  parent,
21508
21546
  after
21509
21547
  });
21548
+ const table = doc.getBlock(tableId);
21549
+ const columnIds = table !== null && table.type === "table" ? table.columnOrder : [];
21550
+ const spans = [];
21510
21551
  let prevRow = null;
21511
- for (const row of m.rows) {
21552
+ rows.forEach((line, row) => {
21512
21553
  const rowId = doc.insertBlock("table-row", void 0, {
21513
21554
  parent: tableId,
21514
21555
  after: prevRow ?? void 0
21515
21556
  });
21557
+ prevRow = rowId;
21558
+ const covered = coveredColumnsOf(merges, row);
21559
+ const anchorColumns = line.map((_, col) => col).filter((col) => !covered.includes(col));
21516
21560
  let prevCell = null;
21517
- for (const cell of row) {
21561
+ anchorColumns.forEach((col, position) => {
21518
21562
  const cellId = doc.insertBlock("table-cell", void 0, {
21519
21563
  parent: rowId,
21520
21564
  after: prevCell ?? void 0
21521
21565
  });
21522
- const paraId = doc.insertBlock("paragraph", void 0, { parent: cellId });
21523
- if (cell.length > 0) insertRuns(doc, paraId, 0, cell);
21524
21566
  prevCell = cellId;
21525
- }
21526
- prevRow = rowId;
21527
- }
21567
+ const columnId = columnIds[col];
21568
+ if (position !== col && columnId !== void 0) doc.updateBlock(cellId, { columnId });
21569
+ const rect = merges.find((merge) => merge.row === row && merge.col === col);
21570
+ if (rect !== void 0) spans.push({
21571
+ cellId,
21572
+ rect
21573
+ });
21574
+ const paraId = doc.insertBlock("paragraph", void 0, { parent: cellId });
21575
+ const runs = line[col];
21576
+ if (runs.length > 0) insertRuns(doc, paraId, 0, runs);
21577
+ });
21578
+ });
21579
+ for (const { cellId, rect } of spans) doc.updateBlock(cellId, {
21580
+ ...rect.colspan > 1 ? { colspan: rect.colspan } : {},
21581
+ ...rect.rowspan > 1 ? { rowspan: rect.rowspan } : {}
21582
+ });
21528
21583
  return tableId;
21529
21584
  }
21530
21585
  //#endregion
@@ -21564,21 +21619,14 @@ function materializePaste(doc, seatId, from, to, parsed, opts) {
21564
21619
  return spec.childrenTypes === void 0 || spec.childrenTypes.includes(type);
21565
21620
  };
21566
21621
  const material = parsed.flatMap((p) => {
21567
- if (p.type === "table" && !eligible("table")) return p.rows.map((cells) => ({
21568
- type: "paragraph",
21569
- indent: p.indent,
21570
- attrs: {},
21571
- runs: cells.flatMap((cell, index) => index === 0 ? cell : [{
21572
- text: " | ",
21573
- marks: {}
21574
- }, ...cell])
21575
- }));
21622
+ if (p.type === "table" && !eligible("table")) return p.rows.map((_, row) => demotedTableRow(p, row));
21576
21623
  return [{
21577
21624
  type: (p.type === "list-item" || p.type === "quote" ? !eligible(p.type) : false) ? "paragraph" : p.type,
21578
21625
  indent: p.indent,
21579
21626
  attrs: p.attrs,
21580
21627
  runs: p.runs,
21581
- rows: p.rows
21628
+ rows: p.rows,
21629
+ merges: p.merges
21582
21630
  }];
21583
21631
  });
21584
21632
  const delta = seatIndent - parsed[0].indent;
@@ -21895,6 +21943,92 @@ function languageClassOf(element) {
21895
21943
  for (const cls of Array.from(element.classList)) if (cls.startsWith("language-") && cls.length > 9) return cls.slice(9);
21896
21944
  }
21897
21945
  //#endregion
21946
+ //#region src/editing/clipboard/utils/html-table.ts
21947
+ /** The grid's width ceiling: the per-cell spans never grow it past this. */
21948
+ const TABLE_COLUMNS_MAX = 100;
21949
+ /** The grid's coordinate budget: a taller table stands fewer columns (rows x cols). */
21950
+ const TABLE_CELLS_MAX = 1e4;
21951
+ /** The span attribute's value: a non-negative integer >= 1, otherwise 1 (the invalid forms' stand). */
21952
+ function spanAttrOf(cell, name) {
21953
+ const raw = (cell.getAttribute(name) ?? "").trim();
21954
+ const value = /^\d+$/.test(raw) ? Number(raw) : 0;
21955
+ return Number.isInteger(value) && value >= 1 ? value : 1;
21956
+ }
21957
+ /** The row's `td`/`th` cells (everything else in a row is not a cell). */
21958
+ function cellInputsOf(row) {
21959
+ const cells = [];
21960
+ for (const cell of Array.from(row.children)) {
21961
+ const tag = cell.nodeName.toUpperCase();
21962
+ if (tag !== "TD" && tag !== "TH") continue;
21963
+ cells.push({
21964
+ runs: runsOf$1(cell, {}, false),
21965
+ colspan: spanAttrOf(cell, "colspan"),
21966
+ rowspan: spanAttrOf(cell, "rowspan")
21967
+ });
21968
+ }
21969
+ return cells;
21970
+ }
21971
+ /**
21972
+ * Places the parsed rows over the grid: the anchors take the first free
21973
+ * column of their row, the effective spans grow over the free coordinates
21974
+ * only (within the table's column budget), and the covered coordinates are
21975
+ * marked. The matrix is padded to the grid's width; the regions a single-cell
21976
+ * anchor does not need are dropped.
21977
+ */
21978
+ function tableGridOf(rowElements) {
21979
+ const inputs = rowElements.map(cellInputsOf).filter((cells) => cells.length > 0);
21980
+ const rowCount = inputs.length;
21981
+ if (rowCount === 0) return null;
21982
+ const columnBudget = Math.max(1, Math.min(TABLE_COLUMNS_MAX, Math.floor(TABLE_CELLS_MAX / rowCount)));
21983
+ const occupied = [];
21984
+ const isOccupied = (row, col) => occupied[row]?.[col] === true;
21985
+ const markCovered = (row, col) => {
21986
+ while (occupied.length <= row) occupied.push([]);
21987
+ const line = occupied[row];
21988
+ while (line.length <= col) line.push(false);
21989
+ line[col] = true;
21990
+ };
21991
+ const anchors = [];
21992
+ inputs.forEach((cells, row) => {
21993
+ for (const cell of cells) {
21994
+ let col = 0;
21995
+ while (isOccupied(row, col)) col += 1;
21996
+ let colspan = 1;
21997
+ while (colspan < cell.colspan && col + colspan < columnBudget && !isOccupied(row, col + colspan)) colspan += 1;
21998
+ let rowspan = 1;
21999
+ while (rowspan < cell.rowspan && row + rowspan < rowCount) {
22000
+ let free = true;
22001
+ for (let c = 0; c < colspan; c += 1) if (isOccupied(row + rowspan, col + c)) {
22002
+ free = false;
22003
+ break;
22004
+ }
22005
+ if (!free) break;
22006
+ rowspan += 1;
22007
+ }
22008
+ for (let r = row; r < row + rowspan; r += 1) for (let c = col; c < col + colspan; c += 1) markCovered(r, c);
22009
+ anchors.push({
22010
+ row,
22011
+ col,
22012
+ colspan,
22013
+ rowspan,
22014
+ runs: cell.runs
22015
+ });
22016
+ }
22017
+ });
22018
+ const cols = Math.max(...occupied.map((line) => line.length));
22019
+ const rows = inputs.map(() => Array.from({ length: cols }, () => []));
22020
+ for (const anchor of anchors) rows[anchor.row][anchor.col] = anchor.runs;
22021
+ return {
22022
+ rows,
22023
+ merges: anchors.filter((anchor) => anchor.colspan > 1 || anchor.rowspan > 1).map(({ row, col, colspan, rowspan }) => ({
22024
+ row,
22025
+ col,
22026
+ colspan,
22027
+ rowspan
22028
+ }))
22029
+ };
22030
+ }
22031
+ //#endregion
21898
22032
  //#region src/editing/clipboard/utils/html-blocks.ts
21899
22033
  /**
21900
22034
  * Parses a list element into list-item materials (the indent is the
@@ -22026,25 +22160,15 @@ function htmlToBlocks(html) {
22026
22160
  listMaterialsOf(element, indent, blocks);
22027
22161
  return;
22028
22162
  case "TABLE": {
22029
- const rows = [];
22030
- for (const tr of tableRowsOf(element)) {
22031
- const cells = [];
22032
- for (const cell of Array.from(tr.children)) {
22033
- const cellTag = cell.nodeName.toUpperCase();
22034
- if (cellTag !== "TD" && cellTag !== "TH") continue;
22035
- cells.push(runsOf$1(cell, {}, false));
22036
- }
22037
- if (cells.length > 0) rows.push(cells);
22038
- }
22039
- if (rows.length === 0) return;
22040
- const cols = Math.max(...rows.map((row) => row.length));
22041
- for (const row of rows) while (row.length < cols) row.push([]);
22163
+ const grid = tableGridOf(tableRowsOf(element));
22164
+ if (grid === null) return;
22042
22165
  blocks.push({
22043
22166
  type: "table",
22044
22167
  indent,
22045
- attrs: { cols },
22168
+ attrs: { cols: grid.rows[0].length },
22046
22169
  runs: [],
22047
- rows
22170
+ rows: grid.rows,
22171
+ merges: grid.merges
22048
22172
  });
22049
22173
  return;
22050
22174
  }
package/dist/index.d.mts CHANGED
@@ -427,7 +427,7 @@ declare function AlertDescription({ className, ...props }: React$1.ComponentProp
427
427
  //#endregion
428
428
  //#region src/shared/ui/Badge.d.ts
429
429
  declare const badgeVariants: (props?: ({
430
- variant?: "default" | "destructive" | "custom" | "secondary" | "outline" | null | undefined;
430
+ variant?: "default" | "custom" | "secondary" | "destructive" | "outline" | null | undefined;
431
431
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
432
432
  declare function Badge({ className, variant, asChild, ...props }: React$1.ComponentProps<"span"> & VariantProps<typeof badgeVariants> & {
433
433
  asChild?: boolean;
@@ -438,7 +438,7 @@ declare function BareSelect({ className, children, ...props }: React$1.Component
438
438
  //#endregion
439
439
  //#region src/shared/ui/Button.d.ts
440
440
  declare const buttonVariants: (props?: ({
441
- variant?: "link" | "default" | "destructive" | "secondary" | "outline" | "ghost" | null | undefined;
441
+ variant?: "link" | "default" | "secondary" | "destructive" | "outline" | "ghost" | null | undefined;
442
442
  size?: "default" | "icon" | "sm" | "lg" | "xl" | null | undefined;
443
443
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
444
444
  declare function Button({ className, variant, size, asChild, type, ...props }: React$1.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { C as UnknownSlashCommandError, S as UnhandledValueError, _ as CanvasPasteError, b as HookMisuseError, g as BlobNotFoundError, s as preventDefault, v as DocBlocksUiError, w as cn, x as PdfFetchError, y as EditorProviderError } from "./constants-D_3p65rk.mjs";
2
- import { $ as DropdownMenuShortcut, $t as DocblocksI18nProvider, A as Select, B as Label, Bt as CardFooter, C as cellValueEqual, Ct as isBridgeError, D as filterIsComplete, Dt as parseCellValue, E as emptyFilter, Et as conditionMatches, F as SelectScrollDownButton, Ft as Skeleton, G as DropdownMenuContent, Gt as useBlock, H as Input, Ht as CardTitle, I as SelectScrollUpButton, It as Card, J as DropdownMenuLabel, Jt as usePresence, K as DropdownMenuGroup, Kt as useDoc, L as SelectSeparator, Lt as CardAction, M as SelectGroup, Mt as Eye, N as SelectItem, O as SegmentSelector, Ot as TEXT_TYPES, P as SelectLabel, Pt as BookOpen, Q as DropdownMenuSeparator, Qt as useText, R as SelectTrigger, Rt as CardContent, S as useDatabaseTable, St as BridgeError, T as FilterBuilder, Tt as toBridgeError, U as DropdownMenu, Ut as Badge, V as InlineEditInput, Vt as CardHeader, W as DropdownMenuCheckboxItem, Wt as badgeVariants, X as DropdownMenuRadioGroup, Xt as useSelection, Y as DropdownMenuPortal, Yt as usePresenceSharing, Z as DropdownMenuRadioItem, Zt as useSelectionView, _ as mapFrontmatter, _t as BASELINE_CAPABILITIES, a as DEFAULT_EMBED_SANDBOX, at as Popover, b as renderRuns, bt as validateProtocolDescriptor, c as SHAPE_FONT_OPTIONS, ct as PopoverDescription, d as FORMAT_PALETTE, dt as PopoverTrigger, en as createMemoryBlobStore, et as DropdownMenuSub, ft as Checkbox, g as parseFrontmatter, gt as AlertTitle, h as mdToBlocks, ht as AlertDescription, i as useEditorContext, it as Separator, j as SelectContent, jt as Pen, k as ScrollArea, kt as columnAnnotation, l as SHAPE_FONT_STACKS, lt as PopoverHeader, m as insertNative, mt as Alert, n as useCoverAverageColor, nn as Button, nt as DropdownMenuSubTrigger, ot as PopoverAnchor, p as htmlToBlocks, pt as BareSelect, q as DropdownMenuItem, qt as useMeta, r as EditorProvider, rn as buttonVariants, rt as DropdownMenuTrigger, st as PopoverContent, t as Editor, tn as EditorErrorBoundary, tt as DropdownMenuSubContent, ut as PopoverTitle, v as markToggleAction, vt as PROTOCOL_VERSION, w as newMutationContext, wt as isBridgeErrorCode, x as GridBody, xt as BRIDGE_ERROR_CODES, yt as isDatabaseBridge, z as SelectValue, zt as CardDescription } from "./Editor-CfH9kgta.mjs";
2
+ import { $ as DropdownMenuShortcut, $t as DocblocksI18nProvider, A as Select, B as Label, Bt as CardFooter, C as cellValueEqual, Ct as isBridgeError, D as filterIsComplete, Dt as parseCellValue, E as emptyFilter, Et as conditionMatches, F as SelectScrollDownButton, Ft as Skeleton, G as DropdownMenuContent, Gt as useBlock, H as Input, Ht as CardTitle, I as SelectScrollUpButton, It as Card, J as DropdownMenuLabel, Jt as usePresence, K as DropdownMenuGroup, Kt as useDoc, L as SelectSeparator, Lt as CardAction, M as SelectGroup, Mt as Eye, N as SelectItem, O as SegmentSelector, Ot as TEXT_TYPES, P as SelectLabel, Pt as BookOpen, Q as DropdownMenuSeparator, Qt as useText, R as SelectTrigger, Rt as CardContent, S as useDatabaseTable, St as BridgeError, T as FilterBuilder, Tt as toBridgeError, U as DropdownMenu, Ut as Badge, V as InlineEditInput, Vt as CardHeader, W as DropdownMenuCheckboxItem, Wt as badgeVariants, X as DropdownMenuRadioGroup, Xt as useSelection, Y as DropdownMenuPortal, Yt as usePresenceSharing, Z as DropdownMenuRadioItem, Zt as useSelectionView, _ as mapFrontmatter, _t as BASELINE_CAPABILITIES, a as DEFAULT_EMBED_SANDBOX, at as Popover, b as renderRuns, bt as validateProtocolDescriptor, c as SHAPE_FONT_OPTIONS, ct as PopoverDescription, d as FORMAT_PALETTE, dt as PopoverTrigger, en as createMemoryBlobStore, et as DropdownMenuSub, ft as Checkbox, g as parseFrontmatter, gt as AlertTitle, h as mdToBlocks, ht as AlertDescription, i as useEditorContext, it as Separator, j as SelectContent, jt as Pen, k as ScrollArea, kt as columnAnnotation, l as SHAPE_FONT_STACKS, lt as PopoverHeader, m as insertNative, mt as Alert, n as useCoverAverageColor, nn as Button, nt as DropdownMenuSubTrigger, ot as PopoverAnchor, p as htmlToBlocks, pt as BareSelect, q as DropdownMenuItem, qt as useMeta, r as EditorProvider, rn as buttonVariants, rt as DropdownMenuTrigger, st as PopoverContent, t as Editor, tn as EditorErrorBoundary, tt as DropdownMenuSubContent, ut as PopoverTitle, v as markToggleAction, vt as PROTOCOL_VERSION, w as newMutationContext, wt as isBridgeErrorCode, x as GridBody, xt as BRIDGE_ERROR_CODES, yt as isDatabaseBridge, z as SelectValue, zt as CardDescription } from "./Editor-CDZqsAHh.mjs";
3
3
  import { useCallback, useEffect, useRef, useState } from "react";
4
4
  import { useTranslation } from "react-i18next";
5
5
  import { cva } from "class-variance-authority";
@@ -1,5 +1,5 @@
1
1
  import { a as clamp, d as Plus, f as Minus, p as LoaderCircle, s as preventDefault, u as TriangleAlert } from "../constants-D_3p65rk.mjs";
2
- import { At as RotateCcw, Ft as Skeleton, Mt as Eye, Nt as CodeXml, O as SegmentSelector, f as textOf, gt as AlertTitle, ht as AlertDescription, i as useEditorContext, mt as Alert, nn as Button, o as childrenSlot, s as CodeHeader, u as TextBlock, y as INLINE_CODE_CLASS } from "../Editor-CfH9kgta.mjs";
2
+ import { At as RotateCcw, Ft as Skeleton, Mt as Eye, Nt as CodeXml, O as SegmentSelector, f as textOf, gt as AlertTitle, ht as AlertDescription, i as useEditorContext, mt as Alert, nn as Button, o as childrenSlot, s as CodeHeader, u as TextBlock, y as INLINE_CODE_CLASS } from "../Editor-CDZqsAHh.mjs";
3
3
  import { t as Maximize } from "../Maximize-BBHnCDWL.mjs";
4
4
  import { useEffect, useRef, useState } from "react";
5
5
  import { useTranslation } from "react-i18next";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docblocks-react-ui",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "React rendering + editing layer for docblocks: hooks, block renderers, caret/selection, keyboard, clipboard.",
5
5
  "type": "module",
6
6
  "license": "MIT",