docblocks-react-ui 0.21.0 → 0.23.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.
@@ -6,7 +6,7 @@ import { I18nextProvider, initReactI18next, useTranslation } from "react-i18next
6
6
  import { Slot } from "@radix-ui/react-slot";
7
7
  import { cva } from "class-variance-authority";
8
8
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
9
- import { ATTRIBUTE_TYPES, BLOCK_REGISTRY, CALLOUT_ICONS, DEFAULT_TABLE_COLUMN_WIDTH, DetachedBlockError, InvalidAttributeError, InvalidAttrsError, InvalidMarkError, InvalidOperationError, createSelection, isHexColor, isSafeEmbedSrc, isSafeLinkHref, linkHrefKindOf, presenceSelectionOf } from "docblocks-core";
9
+ import { ATTRIBUTE_TYPES, BLOCK_REGISTRY, CALLOUT_ICONS, DEFAULT_TABLE_COLUMN_WIDTH, DetachedBlockError, InvalidAttributeError, InvalidAttrsError, InvalidMarkError, InvalidOperationError, createSelection, isHexColor, isMergeableRect, isSafeEmbedSrc, isSafeLinkHref, linkHrefKindOf, presenceSelectionOf, resolveTableGrid } from "docblocks-core";
10
10
  import { createInstance } from "i18next";
11
11
  import { createStore as createStore$1 } from "zustand/vanilla";
12
12
  import { DayPicker, getDefaultClassNames } from "react-day-picker";
@@ -750,7 +750,11 @@ const INIT_OPTIONS = {
750
750
  "column": "Add column",
751
751
  "row": "Add row"
752
752
  },
753
- cell: { "options": "Cell options" }
753
+ cell: {
754
+ "options": "Cell options",
755
+ "merge": "Merge cells",
756
+ "split": "Split cells"
757
+ }
754
758
  }
755
759
  },
756
760
  ru: {
@@ -1289,7 +1293,11 @@ const INIT_OPTIONS = {
1289
1293
  "column": "Добавить столбец",
1290
1294
  "row": "Добавить строку"
1291
1295
  },
1292
- cell: { "options": "Настройки ячейки" }
1296
+ cell: {
1297
+ "options": "Настройки ячейки",
1298
+ "merge": "Объединить ячейки",
1299
+ "split": "Разъединить ячейки"
1300
+ }
1293
1301
  }
1294
1302
  }
1295
1303
  },
@@ -12335,25 +12343,29 @@ function useInView(options = {}) {
12335
12343
  * on (a document of images resolves its first screen only).
12336
12344
  *
12337
12345
  * With a `getMeta` member the non-renderable MIME (the predicate) stands
12338
- * the meta-only view when the store supplies a `downloadUrl`; the
12339
- * renderable MIME (and the absent `downloadUrl`) resolves the bytes over
12340
- * `get` as before. Without `getMeta` the resolution stands the legacy
12341
- * path's phases: no metadata before the bytes, the bytes over `get` once
12342
- * the block is in view. A store change re-resolves over the current band,
12343
- * and a view that already resolved never falls back to the placeholder
12344
- * outside it.
12346
+ * the meta-only view when the store supplies a `downloadUrl`; a renderable
12347
+ * MIME the `rendersFromUrl` predicate claims stands the direct-URL view (the
12348
+ * image's own `<img>` subrequest, no bytes in the JS heap) over the same
12349
+ * store member; the remaining renderable MIME (and the absent
12350
+ * `downloadUrl`) resolves the bytes over `get` as before. Without `getMeta`
12351
+ * the resolution stands the legacy path's phases: no metadata before the
12352
+ * bytes, the bytes over `get` once the block is in view. A store change
12353
+ * re-resolves over the current band, and a view that already resolved never
12354
+ * falls back to the placeholder outside it. An empty `fileId` stands the
12355
+ * missing stand without a store read (an absent cover's row).
12345
12356
  */
12346
12357
  function useBlobFile(fileId, rendersBytes, options = {}) {
12347
12358
  const { blobStore, scrollContainer } = useEditorContext();
12348
12359
  const getMeta = blobStore.getMeta;
12360
+ const rendersFromUrl = options.rendersFromUrl;
12349
12361
  const [ref, setRef] = useState(null);
12350
- const [metaView, setMetaView] = useState(null);
12362
+ const [urlView, setUrlView] = useState(null);
12351
12363
  /** The head's metadata (the loading stand's aspect-ratio input). */
12352
12364
  const [headMeta, setHeadMeta] = useState(null);
12353
12365
  /** The resolution's rejection (the missing stand) — a resolve clears it. */
12354
12366
  const [failed, setFailed] = useState(false);
12355
12367
  const [view, setView] = useState(null);
12356
- const headSettled = options.eager === true || blobStore.getMeta === void 0 || headMeta !== null || metaView !== null || failed;
12368
+ const headSettled = options.eager === true || blobStore.getMeta === void 0 || headMeta !== null || urlView !== null || failed;
12357
12369
  const { ref: observeRef, inView } = useInView({
12358
12370
  disabled: options.eager === true,
12359
12371
  ready: headSettled,
@@ -12369,19 +12381,24 @@ function useBlobFile(fileId, rendersBytes, options = {}) {
12369
12381
  let alive = true;
12370
12382
  let sequence = 0;
12371
12383
  setRef(null);
12372
- setMetaView(null);
12384
+ setUrlView(null);
12373
12385
  setHeadMeta(null);
12374
12386
  setFailed(false);
12375
12387
  loadedRef.current = false;
12388
+ if (fileId === "") {
12389
+ setFailed(true);
12390
+ return;
12391
+ }
12376
12392
  /** The head's resolved stand over this resolution's lifetime: the
12377
12393
  * band's entry reuses it (the store's change re-reads it fresh). */
12378
12394
  let head = null;
12379
12395
  /** The head's in-flight request: a non-fresh load joins it instead of
12380
12396
  * issuing a second lookup while one is pending. */
12381
12397
  let headRequest = null;
12382
- /** The head decided the meta-only card (no bytes stand over any band). */
12383
- let metaOnly = false;
12398
+ /** The head decided a store-URL stand (no bytes stand over any band). */
12399
+ let urlOnly = false;
12384
12400
  const load = async (freshHead) => {
12401
+ if (fileId === "") return;
12385
12402
  const request = ++sequence;
12386
12403
  const current = () => alive && request === sequence;
12387
12404
  try {
@@ -12394,29 +12411,43 @@ function useBlobFile(fileId, rendersBytes, options = {}) {
12394
12411
  head = meta;
12395
12412
  setHeadMeta(meta);
12396
12413
  const downloadUrl = blobStore.downloadUrl;
12397
- if (downloadUrl !== void 0 && rendersBytes !== void 0 && !rendersBytes(meta.mimeType)) {
12398
- metaOnly = true;
12414
+ const url = downloadUrl === void 0 ? null : downloadUrl(fileId);
12415
+ urlOnly = false;
12416
+ if (url !== null && rendersBytes !== void 0 && !rendersBytes(meta.mimeType)) {
12417
+ urlOnly = true;
12418
+ setRef(null);
12419
+ setUrlView({
12420
+ status: "ready-meta",
12421
+ meta,
12422
+ url
12423
+ });
12424
+ setFailed(false);
12425
+ return;
12426
+ }
12427
+ if (url !== null && rendersFromUrl !== void 0 && rendersFromUrl(meta.mimeType) && isSafeDownloadHref(url)) {
12428
+ urlOnly = true;
12399
12429
  setRef(null);
12400
- setMetaView({
12430
+ setUrlView({
12431
+ status: "ready-url",
12401
12432
  meta,
12402
- url: downloadUrl(fileId)
12433
+ url
12403
12434
  });
12404
12435
  setFailed(false);
12405
12436
  return;
12406
12437
  }
12407
- } else if (metaOnly) return;
12438
+ } else if (urlOnly) return;
12408
12439
  }
12409
12440
  if (!inViewRef.current) return;
12410
12441
  const next = await blobStore.get(fileId);
12411
12442
  if (!current()) return;
12412
12443
  loadedRef.current = true;
12413
12444
  setRef(next);
12414
- setMetaView(null);
12445
+ setUrlView(null);
12415
12446
  setFailed(false);
12416
12447
  } catch {
12417
12448
  if (!current()) return;
12418
12449
  setRef(null);
12419
- setMetaView(null);
12450
+ setUrlView(null);
12420
12451
  setFailed(true);
12421
12452
  }
12422
12453
  };
@@ -12434,7 +12465,8 @@ function useBlobFile(fileId, rendersBytes, options = {}) {
12434
12465
  }, [
12435
12466
  blobStore,
12436
12467
  fileId,
12437
- rendersBytes
12468
+ rendersBytes,
12469
+ rendersFromUrl
12438
12470
  ]);
12439
12471
  useEffect(() => {
12440
12472
  inViewRef.current = inView;
@@ -12464,11 +12496,8 @@ function useBlobFile(fileId, rendersBytes, options = {}) {
12464
12496
  },
12465
12497
  ref: observeRef
12466
12498
  };
12467
- if (metaView !== null) return {
12468
- state: {
12469
- status: "ready-meta",
12470
- ...metaView
12471
- },
12499
+ if (urlView !== null) return {
12500
+ state: urlView,
12472
12501
  ref: observeRef
12473
12502
  };
12474
12503
  if (failed) return {
@@ -18795,6 +18824,163 @@ function useSlashMenuApi() {
18795
18824
  return useContext(SlashMenuContext);
18796
18825
  }
18797
18826
  //#endregion
18827
+ //#region src/editing/slash/helpers.ts
18828
+ /** The block snapshot's indent: a non-negative integer attr; absent is 0. */
18829
+ function indentOf$1(block) {
18830
+ if (!("attrs" in block)) return 0;
18831
+ const indent = block.attrs?.indent;
18832
+ return typeof indent === "number" && Number.isInteger(indent) && indent >= 0 ? indent : 0;
18833
+ }
18834
+ /**
18835
+ * Hold the editor root's focus across a structural rebuild: the focused
18836
+ * inner editable unmounts during the store-driven re-render, and the
18837
+ * browser drops the focus to <body> until the next-frame caret re-seating
18838
+ * lands. Focusing the (tabIndex -1) root before the rebuild keeps the
18839
+ * focus — and the keyboard scope — inside the editor while the gap lasts
18840
+ * (the root's keydown handler still owns the hotkeys).
18841
+ */
18842
+ function holdFocus(scope) {
18843
+ if (scope instanceof HTMLElement && scope.isConnected) scope.focus({ preventScroll: true });
18844
+ }
18845
+ /** The table's first cell (the caret's seat after the slash Table lands). */
18846
+ function firstCellOf(doc, tableId) {
18847
+ const firstRow = doc.getChildren(tableId)[0];
18848
+ return firstRow === void 0 ? void 0 : doc.getChildren(firstRow)[0];
18849
+ }
18850
+ /** Insert the command's block with its default attrs (type-safe per type), keeping the trigger's attach level (a subtree view's root level may sit deeper than 0 — the same position and indent were valid before, so the sequence's jump rule holds at the landing). */
18851
+ function insertCommand(doc, command, at, indent = 0) {
18852
+ const ind = indent !== 0 ? { indent } : {};
18853
+ switch (command.type) {
18854
+ case "paragraph": return doc.insertBlock("paragraph", ind.indent === void 0 ? void 0 : { ...ind }, at);
18855
+ case "heading": return doc.insertBlock("heading", {
18856
+ level: command.attrs.level,
18857
+ ...ind
18858
+ }, at);
18859
+ case "list-item": return doc.insertBlock("list-item", {
18860
+ list: command.attrs.list,
18861
+ ...ind
18862
+ }, at);
18863
+ case "quote": return doc.insertBlock("quote", ind.indent === void 0 ? void 0 : { ...ind }, at);
18864
+ case "callout": return doc.insertBlock("callout", ind.indent === void 0 ? void 0 : { ...ind }, at);
18865
+ case "code": return doc.insertBlock("code", command.attrs?.language === void 0 ? ind.indent === void 0 ? void 0 : { ...ind } : {
18866
+ language: command.attrs.language,
18867
+ ...ind
18868
+ }, at);
18869
+ case "divider": return doc.insertBlock("divider", ind.indent === void 0 ? void 0 : { ...ind }, at);
18870
+ case "table": {
18871
+ const tableId = doc.insertBlock("table", {
18872
+ cols: 2,
18873
+ columnWidths: [DEFAULT_TABLE_COLUMN_WIDTH, DEFAULT_TABLE_COLUMN_WIDTH],
18874
+ ...ind
18875
+ }, at);
18876
+ for (let row = 0; row < 2; row++) {
18877
+ const rowId = doc.insertBlock("table-row", void 0, { parent: tableId });
18878
+ for (let col = 0; col < 2; col++) doc.insertBlock("table-cell", void 0, { parent: rowId });
18879
+ }
18880
+ return tableId;
18881
+ }
18882
+ default: throw new UnknownSlashCommandError(`Unknown slash command type "${command.type}".`);
18883
+ }
18884
+ }
18885
+ //#endregion
18886
+ //#region src/editing/slash/apply.ts
18887
+ /**
18888
+ * Execute the apply plan (one transaction for the non-replace kinds —
18889
+ * one undo step, one wire update). The validation-first ordering stands:
18890
+ * the type change / the attrs patch validate before the text deletion
18891
+ * runs, so a rejected plan commits nothing.
18892
+ */
18893
+ function applySlashPlan(doc, plan, command, blockId, parentId, indent, scope) {
18894
+ switch (plan.kind) {
18895
+ case "noop": return;
18896
+ case "replace": {
18897
+ let tableId = null;
18898
+ let caretId = null;
18899
+ doc.transact(() => {
18900
+ const siblings = doc.getChildren(parentId);
18901
+ const index = siblings.indexOf(blockId);
18902
+ const after = index > 0 ? siblings[index - 1] : void 0;
18903
+ doc.removeBlock(blockId);
18904
+ const newId = insertCommand(doc, command, after === void 0 ? void 0 : {
18905
+ parent: parentId,
18906
+ after
18907
+ }, indent);
18908
+ if (command.type === "table") {
18909
+ tableId = newId;
18910
+ return;
18911
+ }
18912
+ caretId = newId;
18913
+ if (!BLOCK_REGISTRY[command.type].content && doc.getChildren(parentId).at(-1) === newId) caretId = doc.insertBlock("paragraph", void 0, {
18914
+ parent: parentId,
18915
+ after: newId
18916
+ });
18917
+ });
18918
+ holdFocus(scope);
18919
+ if (tableId !== null) {
18920
+ const firstCell = firstCellOf(doc, tableId);
18921
+ if (firstCell !== void 0) {
18922
+ focusCellActivation(firstCell, scope);
18923
+ return;
18924
+ }
18925
+ }
18926
+ if (caretId !== null) focusCaretIn(caretId, 0, scope);
18927
+ return;
18928
+ }
18929
+ case "update":
18930
+ case "convert": {
18931
+ const attrs = "attrs" in command && command.attrs !== void 0 ? command.attrs : void 0;
18932
+ let tableId = null;
18933
+ try {
18934
+ doc.transact(() => {
18935
+ if (plan.kind === "convert") switch (command.type) {
18936
+ case "paragraph":
18937
+ doc.changeBlockType(blockId, "paragraph");
18938
+ break;
18939
+ case "heading":
18940
+ doc.changeBlockType(blockId, "heading", command.attrs);
18941
+ break;
18942
+ case "list-item":
18943
+ doc.changeBlockType(blockId, "list-item", command.attrs);
18944
+ break;
18945
+ case "quote":
18946
+ doc.changeBlockType(blockId, "quote");
18947
+ break;
18948
+ case "callout":
18949
+ doc.changeBlockType(blockId, "callout");
18950
+ break;
18951
+ case "code": doc.changeBlockType(blockId, "code", command.attrs);
18952
+ }
18953
+ else if (attrs !== void 0) doc.updateBlock(blockId, attrs);
18954
+ doc.deleteText(blockId, plan.deleteFrom, plan.deleteTo);
18955
+ if (command.type === "table") tableId = insertCommand(doc, command, {
18956
+ parent: parentId,
18957
+ after: blockId
18958
+ }, indent);
18959
+ else if (command.type === "divider") insertCommand(doc, command, {
18960
+ parent: parentId,
18961
+ after: blockId
18962
+ }, indent);
18963
+ });
18964
+ } catch (error) {
18965
+ if (error instanceof InvalidAttrsError || error instanceof InvalidOperationError) return;
18966
+ throw error;
18967
+ }
18968
+ if (tableId !== null) {
18969
+ const firstCell = firstCellOf(doc, tableId);
18970
+ if (firstCell !== void 0) {
18971
+ holdFocus(scope);
18972
+ focusCellActivation(firstCell, scope);
18973
+ return;
18974
+ }
18975
+ }
18976
+ if (plan.kind === "convert") holdFocus(scope);
18977
+ focusCaretIn(blockId, plan.deleteFrom, scope);
18978
+ return;
18979
+ }
18980
+ default: return assertNever(plan);
18981
+ }
18982
+ }
18983
+ //#endregion
18798
18984
  //#region src/editing/slash/DatabaseSlashPicker.tsx
18799
18985
  /**
18800
18986
  * The slash `Database` picker: the create-new form (a `New table` button that stands the
@@ -19315,12 +19501,13 @@ function sameAttrs(block, command) {
19315
19501
  function planSlashApply(command, block, text, slashOffset, hasFollowers) {
19316
19502
  if (sameAttrs(block, command)) return { kind: "noop" };
19317
19503
  const queryEnd = deriveSlash(text, slashOffset, text.length).queryEnd;
19318
- if (command.type === "table") return {
19504
+ const stripped = text.slice(0, slashOffset) + text.slice(queryEnd);
19505
+ if (command.type === "table") return stripped === "" && !hasFollowers ? { kind: "replace" } : {
19319
19506
  kind: "update",
19320
19507
  deleteFrom: slashOffset,
19321
19508
  deleteTo: queryEnd
19322
19509
  };
19323
- if (text.slice(0, slashOffset) + text.slice(queryEnd) === "" && !hasFollowers && command.type !== block.type) return { kind: "replace" };
19510
+ if (stripped === "" && !hasFollowers && command.type !== block.type) return { kind: "replace" };
19324
19511
  if (command.type === "divider") return {
19325
19512
  kind: "update",
19326
19513
  deleteFrom: slashOffset,
@@ -19337,144 +19524,6 @@ function planSlashApply(command, block, text, slashOffset, hasFollowers) {
19337
19524
  deleteTo: queryEnd
19338
19525
  };
19339
19526
  }
19340
- /** Insert the command's block with its default attrs (type-safe per type), keeping the trigger's attach level (a subtree view's root level may sit deeper than 0 — the same position and indent were valid before, so the sequence's jump rule holds at the landing). */
19341
- function insertCommand(doc, command, at, indent = 0) {
19342
- const ind = indent !== 0 ? { indent } : {};
19343
- switch (command.type) {
19344
- case "paragraph": return doc.insertBlock("paragraph", ind.indent === void 0 ? void 0 : { ...ind }, at);
19345
- case "heading": return doc.insertBlock("heading", {
19346
- level: command.attrs.level,
19347
- ...ind
19348
- }, at);
19349
- case "list-item": return doc.insertBlock("list-item", {
19350
- list: command.attrs.list,
19351
- ...ind
19352
- }, at);
19353
- case "quote": return doc.insertBlock("quote", ind.indent === void 0 ? void 0 : { ...ind }, at);
19354
- case "callout": return doc.insertBlock("callout", ind.indent === void 0 ? void 0 : { ...ind }, at);
19355
- case "code": return doc.insertBlock("code", command.attrs?.language === void 0 ? ind.indent === void 0 ? void 0 : { ...ind } : {
19356
- language: command.attrs.language,
19357
- ...ind
19358
- }, at);
19359
- case "divider": return doc.insertBlock("divider", ind.indent === void 0 ? void 0 : { ...ind }, at);
19360
- case "table": {
19361
- const tableId = doc.insertBlock("table", {
19362
- cols: 2,
19363
- columnWidths: [DEFAULT_TABLE_COLUMN_WIDTH, DEFAULT_TABLE_COLUMN_WIDTH],
19364
- ...ind
19365
- }, at);
19366
- for (let row = 0; row < 2; row++) {
19367
- const rowId = doc.insertBlock("table-row", void 0, { parent: tableId });
19368
- for (let col = 0; col < 2; col++) doc.insertBlock("table-cell", void 0, { parent: rowId });
19369
- }
19370
- return tableId;
19371
- }
19372
- default: throw new UnknownSlashCommandError(`Unknown slash command type "${command.type}".`);
19373
- }
19374
- }
19375
- /** The block snapshot's indent: a non-negative integer attr; absent is 0. */
19376
- function indentOf$1(block) {
19377
- if (!("attrs" in block)) return 0;
19378
- const indent = block.attrs?.indent;
19379
- return typeof indent === "number" && Number.isInteger(indent) && indent >= 0 ? indent : 0;
19380
- }
19381
- /**
19382
- * Hold the editor root's focus across a structural rebuild: the focused
19383
- * inner editable unmounts during the store-driven re-render, and the
19384
- * browser drops the focus to <body> until the next-frame caret re-seating
19385
- * lands. Focusing the (tabIndex -1) root before the rebuild keeps the
19386
- * focus — and the keyboard scope — inside the editor while the gap lasts
19387
- * (the root's keydown handler still owns the hotkeys).
19388
- */
19389
- function holdFocus(scope) {
19390
- if (scope instanceof HTMLElement && scope.isConnected) scope.focus({ preventScroll: true });
19391
- }
19392
- /**
19393
- * Execute the apply plan (one transaction for the non-replace kinds —
19394
- * one undo step, one wire update). The validation-first ordering stands:
19395
- * the type change / the attrs patch validate before the text deletion
19396
- * runs, so a rejected plan commits nothing.
19397
- */
19398
- function applySlashPlan(doc, plan, command, blockId, parentId, indent, scope) {
19399
- switch (plan.kind) {
19400
- case "noop": return;
19401
- case "replace":
19402
- doc.transact(() => {
19403
- const siblings = doc.getChildren(parentId);
19404
- const index = siblings.indexOf(blockId);
19405
- const after = index > 0 ? siblings[index - 1] : void 0;
19406
- doc.removeBlock(blockId);
19407
- const newId = insertCommand(doc, command, after === void 0 ? void 0 : {
19408
- parent: parentId,
19409
- after
19410
- }, indent);
19411
- let caretId = newId;
19412
- if (!BLOCK_REGISTRY[command.type].content) {
19413
- const sequence = doc.getChildren(parentId);
19414
- if (sequence[sequence.length - 1] === newId) caretId = doc.insertBlock("paragraph", void 0, {
19415
- parent: parentId,
19416
- after: newId
19417
- });
19418
- }
19419
- focusCaretIn(caretId, 0, scope);
19420
- });
19421
- holdFocus(scope);
19422
- return;
19423
- case "update":
19424
- case "convert": {
19425
- const attrs = "attrs" in command && command.attrs !== void 0 ? command.attrs : void 0;
19426
- let tableId = null;
19427
- try {
19428
- doc.transact(() => {
19429
- if (plan.kind === "convert") switch (command.type) {
19430
- case "paragraph":
19431
- doc.changeBlockType(blockId, "paragraph");
19432
- break;
19433
- case "heading":
19434
- doc.changeBlockType(blockId, "heading", command.attrs);
19435
- break;
19436
- case "list-item":
19437
- doc.changeBlockType(blockId, "list-item", command.attrs);
19438
- break;
19439
- case "quote":
19440
- doc.changeBlockType(blockId, "quote");
19441
- break;
19442
- case "callout":
19443
- doc.changeBlockType(blockId, "callout");
19444
- break;
19445
- case "code": doc.changeBlockType(blockId, "code", command.attrs);
19446
- }
19447
- else if (attrs !== void 0) doc.updateBlock(blockId, attrs);
19448
- doc.deleteText(blockId, plan.deleteFrom, plan.deleteTo);
19449
- if (command.type === "table") tableId = insertCommand(doc, command, {
19450
- parent: parentId,
19451
- after: blockId
19452
- }, indent);
19453
- else if (command.type === "divider") insertCommand(doc, command, {
19454
- parent: parentId,
19455
- after: blockId
19456
- }, indent);
19457
- });
19458
- } catch (error) {
19459
- if (error instanceof InvalidAttrsError || error instanceof InvalidOperationError) return;
19460
- throw error;
19461
- }
19462
- if (tableId !== null) {
19463
- const firstRow = doc.getChildren(tableId)[0];
19464
- const firstCell = firstRow === void 0 ? void 0 : doc.getChildren(firstRow)[0];
19465
- if (firstCell !== void 0) {
19466
- holdFocus(scope);
19467
- focusCellActivation(firstCell, scope);
19468
- return;
19469
- }
19470
- }
19471
- if (plan.kind === "convert") holdFocus(scope);
19472
- focusCaretIn(blockId, plan.deleteFrom, scope);
19473
- return;
19474
- }
19475
- default: return assertNever(plan);
19476
- }
19477
- }
19478
19527
  //#endregion
19479
19528
  //#region src/editing/slash/SlashMenu.tsx
19480
19529
  /** The slash menu's floating command list: a plain absolutely-positioned
@@ -28983,19 +29032,30 @@ function ImageFigure({ id, block, url, name, width, height }) {
28983
29032
  * `downloadUrl`). A module-level const keeps the predicate's identity
28984
29033
  * stable (the resolution's effect's dep). */
28985
29034
  const IMAGE_RENDERS_BYTES = (mimeType) => mimeType.startsWith("image/") || mimeType === "application/pdf";
29035
+ /** The MIME the `<img>` renders straight from the store's `downloadUrl`: the
29036
+ * browser's own cacheable subrequest over the consumer's URL. The PDF keeps
29037
+ * the bytes' path (the preview and the iframe read the payload). A
29038
+ * module-level const keeps the predicate's identity stable (the
29039
+ * resolution's effect's dep). */
29040
+ const IMAGE_RENDERS_URL = (mimeType) => mimeType.startsWith("image/");
28986
29041
  /**
28987
29042
  * An image: the <img> src comes from the consumer's blob store (the key is
28988
29043
  * opaque; resolution is a consumer-side concern). The store's MIME metadata
28989
29044
  * decides the rendering: images stand the <img>, PDF an iframe viewer, and
28990
- * legacy non-image payloads the download card. While the id is unknown or
28991
- * the get is in flight the block renders
28992
- * a structural placeholder card instead of a broken <img>.
29045
+ * legacy non-image payloads the download card. An image resolves from the
29046
+ * store's `downloadUrl` when it supplies one — the browser fetches and
29047
+ * caches it natively instead of the library's `get` + object URL. While the
29048
+ * id is unknown or the get is in flight the block renders a structural
29049
+ * placeholder card instead of a broken <img>.
28993
29050
  */
28994
29051
  function ImageBlock({ id, block }) {
28995
29052
  const { t } = useTranslation("blocks");
28996
29053
  const { pdfPreview, blobLoading } = useEditorContext();
28997
29054
  const src = block.attrs.src;
28998
- const { state: file, ref: placeholderRef } = useBlobFile(src, IMAGE_RENDERS_BYTES, blobLoading === "eager" ? { eager: true } : {});
29055
+ const { state: file, ref: placeholderRef } = useBlobFile(src, IMAGE_RENDERS_BYTES, {
29056
+ eager: blobLoading === "eager",
29057
+ rendersFromUrl: IMAGE_RENDERS_URL
29058
+ });
28999
29059
  if (file.status === "loading" || file.status === "missing") return /* @__PURE__ */ jsx(Card, {
29000
29060
  ref: placeholderRef,
29001
29061
  "data-slot": "docblocks/image-placeholder",
@@ -29010,6 +29070,14 @@ function ImageBlock({ id, block }) {
29010
29070
  children: [file.status === "loading" ? /* @__PURE__ */ jsx(LoaderCircle, { className: "size-6 animate-spin" }) : /* @__PURE__ */ jsx(Image$1, { className: "size-6" }), t("image.placeholder")]
29011
29071
  })
29012
29072
  });
29073
+ if (file.status === "ready-url") return /* @__PURE__ */ jsx(ImageFigure, {
29074
+ id,
29075
+ block,
29076
+ url: file.url,
29077
+ name: file.meta.name,
29078
+ width: file.meta.width,
29079
+ height: file.meta.height
29080
+ });
29013
29081
  if (file.status === "ready-meta") return /* @__PURE__ */ jsx(FileCard, {
29014
29082
  id,
29015
29083
  fileId: src,
@@ -29545,10 +29613,7 @@ function CodeHeader({ id, block, center }) {
29545
29613
  }
29546
29614
  //#endregion
29547
29615
  //#region src/blocks/table/constants.ts
29548
- /** The table block's constants (the handle / add-chip geometry, the drag
29549
- * thresholds and steps, the column-width floor). */
29550
29616
  const EMPTY_IDS = [];
29551
- const ADD_COLUMN_DRAG_STEP_PX = DEFAULT_TABLE_COLUMN_WIDTH;
29552
29617
  const ADD_BUTTON_CLASSES = "pointer-events-none opacity-0 transition-opacity group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100";
29553
29618
  /** The table element's selector (the live DOM read — the commit and the
29554
29619
  * hover math, the row metrics' measurement). */
@@ -29565,7 +29630,7 @@ const HANDLE_DRAG_TRANSITION = "left 120ms ease-out, top 120ms ease-out";
29565
29630
  * the content anchors to the cursor, like a native context menu). The
29566
29631
  * gesture + the doc's commands stand over `use-table-cell-menu` +
29567
29632
  * `use-table-add-chips`. */
29568
- function TableFrameChrome({ viewMode, insertTableRow, onAddChipPointerDown, onAddChipPointerMove, onAddChipPointerUp, onAddChipPointerCancel, rowButtonLeft, addPreview, columnCount, rowCount, cellMenu }) {
29633
+ function TableFrameChrome({ tableWidth, rowMetrics, viewMode, insertTableRow, onAddChipPointerDown, onAddChipPointerMove, onAddChipPointerUp, onAddChipPointerCancel, rowButtonLeft, addPreview, columnCount, rowCount, cellMenu }) {
29569
29634
  const { t } = useTranslation("table");
29570
29635
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
29571
29636
  !viewMode && /* @__PURE__ */ jsx(Button, {
@@ -29583,11 +29648,26 @@ function TableFrameChrome({ viewMode, insertTableRow, onAddChipPointerDown, onAd
29583
29648
  style: { left: rowButtonLeft },
29584
29649
  children: /* @__PURE__ */ jsx(Plus, {})
29585
29650
  }),
29651
+ addPreview !== null && addPreview.kind === "row" && addPreview.count < 0 ? Array.from({ length: -addPreview.count }, (_, offset) => {
29652
+ const metrics = rowMetrics[rowCount - 1 - offset];
29653
+ if (metrics === void 0) return null;
29654
+ return /* @__PURE__ */ jsx("div", {
29655
+ "data-slot": "docblocks/table-row-remove",
29656
+ "aria-hidden": true,
29657
+ className: "pointer-events-none absolute bg-(--muted-foreground)/30",
29658
+ style: {
29659
+ left: 20,
29660
+ top: 20 + metrics.top,
29661
+ width: tableWidth,
29662
+ height: metrics.height
29663
+ }
29664
+ }, `remove-row-${offset}`);
29665
+ }) : null,
29586
29666
  addPreview !== null && addPreview.count !== 0 ? /* @__PURE__ */ jsx("div", {
29587
29667
  "data-slot": "docblocks/table-size",
29588
29668
  "aria-hidden": true,
29589
29669
  className: "pointer-events-none absolute top-0.5 left-1.5 text-xs text-(--muted-foreground) select-none",
29590
- children: `${addPreview.kind === "column" ? columnCount + addPreview.count : columnCount} × ${addPreview.kind === "row" ? rowCount + addPreview.count : rowCount}`
29670
+ children: `${addPreview.kind === "column" ? columnCount + addPreview.count : columnCount} × ${addPreview.kind === "row" ? rowCount + addPreview.count : rowCount} ${addPreview.count > 0 ? `+ ${addPreview.count}` : `− ${-addPreview.count}`}`
29591
29671
  }) : null,
29592
29672
  /* @__PURE__ */ jsxs(DropdownMenu, {
29593
29673
  modal: false,
@@ -29609,6 +29689,16 @@ function TableFrameChrome({ viewMode, insertTableRow, onAddChipPointerDown, onAd
29609
29689
  sideOffset: 4,
29610
29690
  onFocusOutside: preventDefault,
29611
29691
  children: [
29692
+ /* @__PURE__ */ jsx(DropdownMenuItem, {
29693
+ disabled: !cellMenu.canMerge,
29694
+ onSelect: cellMenu.onMergeCells,
29695
+ children: t("cell.merge")
29696
+ }),
29697
+ /* @__PURE__ */ jsx(DropdownMenuItem, {
29698
+ disabled: !cellMenu.canSplit,
29699
+ onSelect: cellMenu.onSplitCells,
29700
+ children: t("cell.split")
29701
+ }),
29612
29702
  /* @__PURE__ */ jsx(DropdownMenuItem, {
29613
29703
  onSelect: cellMenu.onCopy,
29614
29704
  children: t("common:copy")
@@ -29760,17 +29850,33 @@ function clampColumnWidth(width) {
29760
29850
  return Math.max(Math.round(width), 50);
29761
29851
  }
29762
29852
  /**
29763
- * The add chip's drag delta -> the count (positive = the add, negative =
29764
- * the remove): the nearest step's count (the rows' step 24 px, the
29765
- * columns' the base width 100 px); the floor clamps the removal to keep
29766
- * at least one row / column (the full removal is the handle's menu
29767
- * delete only — the paragraph conversion), the add stands unclamped (the
29768
- * travel's count is the intent).
29853
+ * The add chip's drag delta -> the count (positive = the add, negative = the
29854
+ * remove). The travel is measured in the ITEMS the reader sees: an add step
29855
+ * is one expected item's size, and a removal counts the items whose midpoint
29856
+ * the travel passed (so one row's worth of drag removes exactly one row,
29857
+ * whatever the rows' heights are). The removal keeps at least one row /
29858
+ * column (the full removal is the handle's menu delete only — the paragraph
29859
+ * conversion); the add stands unclamped (the travel's count is the intent).
29769
29860
  */
29770
- function addDragCount(kind, total, delta) {
29771
- const raw = Math.round(delta / (kind === "row" ? 24 : ADD_COLUMN_DRAG_STEP_PX));
29772
- if (raw >= 0) return raw;
29773
- return Math.max(1 - total, raw);
29861
+ function addDragCount(total, delta, steps) {
29862
+ const sizeOf = (index) => {
29863
+ const size = steps.sizes[index];
29864
+ return size !== void 0 && size > 0 ? size : steps.fallback;
29865
+ };
29866
+ if (delta >= 0) {
29867
+ const step = sizeOf(total - 1) > 0 ? sizeOf(total - 1) : steps.fallback;
29868
+ return step > 0 ? Math.round(delta / step) : 0;
29869
+ }
29870
+ const travelled = -delta;
29871
+ let passed = 0;
29872
+ let count = 0;
29873
+ for (let index = total - 1; index >= 0 && total - count > 1; index -= 1) {
29874
+ const size = sizeOf(index);
29875
+ if (travelled <= passed + size / 2) break;
29876
+ passed += size;
29877
+ count += 1;
29878
+ }
29879
+ return count === 0 ? 0 : -count;
29774
29880
  }
29775
29881
  //#endregion
29776
29882
  //#region src/blocks/table/HandleMenu.tsx
@@ -29984,8 +30090,8 @@ function seamXsOf(widths) {
29984
30090
  }
29985
30091
  //#endregion
29986
30092
  //#region src/blocks/table/TableHandles.tsx
29987
- function TableHandles({ tableId, widths, rows, rowMetrics, hover, menu, preview, columnCenters, onHandlePointerDown, onHandlePointerMove, onHandlePointerUp, onHandlePointerCancel, openHandleMenu, onMenuOpenChange, onColumnHandleAction, onRowHandleAction, onColumnHandleColor, onRowHandleColor, palette }) {
29988
- return /* @__PURE__ */ jsxs(Fragment$1, { children: [widths.map((_, index) => /* @__PURE__ */ jsx(HandleMenu, {
30093
+ function TableHandles({ lockedColumns, lockedRows, tableId, widths, rows, rowMetrics, hover, menu, preview, columnCenters, onHandlePointerDown, onHandlePointerMove, onHandlePointerUp, onHandlePointerCancel, openHandleMenu, onMenuOpenChange, onColumnHandleAction, onRowHandleAction, onColumnHandleColor, onRowHandleColor, palette }) {
30094
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [widths.map((_, index) => lockedColumns.has(index) ? null : /* @__PURE__ */ jsx(HandleMenu, {
29989
30095
  kind: "column",
29990
30096
  index,
29991
30097
  visible: isTablePreview(preview, "column", index) || hover?.col === index || menu !== null && menu.kind === "column" && menu.index === index,
@@ -30012,7 +30118,7 @@ function TableHandles({ tableId, widths, rows, rowMetrics, hover, menu, preview,
30012
30118
  onAction: onColumnHandleAction(index),
30013
30119
  onColor: onColumnHandleColor(index)
30014
30120
  })
30015
- }, `col-${index}`)), rows.map((rowId, rowIndex) => /* @__PURE__ */ jsx(HandleMenu, {
30121
+ }, `col-${index}`)), rows.map((rowId, rowIndex) => lockedRows.has(rowIndex) ? null : /* @__PURE__ */ jsx(HandleMenu, {
30016
30122
  kind: "row",
30017
30123
  index: rowIndex,
30018
30124
  visible: isTablePreview(preview, "row", rowIndex) || hover?.row === rowIndex || menu !== null && menu.kind === "row" && menu.index === rowIndex,
@@ -30150,6 +30256,247 @@ function CellActivation({ cellId }) {
30150
30256
  });
30151
30257
  }
30152
30258
  //#endregion
30259
+ //#region src/blocks/table/table-range-context.tsx
30260
+ /**
30261
+ * The table cell range's handlers over the table's subtree: the cells render
30262
+ * the corner grip and hand its pointer events to the table-level session
30263
+ * (`useTableCellRange`), so a cell needs no session state of its own.
30264
+ */
30265
+ const TableCellRangeContext = createContext(null);
30266
+ /** The table's range handlers; null outside a table (the grip never renders). */
30267
+ function useTableCellRangeHandlers() {
30268
+ return useContext(TableCellRangeContext);
30269
+ }
30270
+ //#endregion
30271
+ //#region src/blocks/table/use-table-cell-range.ts
30272
+ /**
30273
+ * The table cell range's session: the grip drag that selects a rectangle of
30274
+ * cells (the merge / split gesture's stand, the cell's text selection is
30275
+ * untouched). The range is view state — the store's `tableRange` slice — not
30276
+ * document data: it never travels the wire and the doc commands read it, not
30277
+ * the other way round.
30278
+ *
30279
+ * The gesture: a press on the hovered cell's corner grip starts the range at
30280
+ * that cell, the drag extends it over the cells under the pointer, the
30281
+ * release keeps it. Escape clears it. Every coordinate comes from the grid
30282
+ * resolver (a merged region stands one cell over several coordinates).
30283
+ */
30284
+ /** The anchor of the cell in the resolved grid (null for an unknown id). */
30285
+ function anchorOfId(doc, tableId, cellId) {
30286
+ const grid = resolveTableGrid(doc.raw, tableId);
30287
+ if (grid === null) return null;
30288
+ for (const line of grid.rows) for (const anchor of line) if (anchor.id === cellId) return anchor;
30289
+ return null;
30290
+ }
30291
+ /**
30292
+ * The range between two anchor cells: their rectangles' union. A region the
30293
+ * union touches joins it WHOLE (a selection never cuts a merged cell — a
30294
+ * cut rectangle would show a frame in the middle of a region and a merge
30295
+ * over it would take cells the reader did not select).
30296
+ */
30297
+ function rangeOfAnchors(doc, tableId, from, to) {
30298
+ const grid = resolveTableGrid(doc.raw, tableId);
30299
+ if (grid === null) return null;
30300
+ let top = Math.min(from.row, to.row);
30301
+ let left = Math.min(from.col, to.col);
30302
+ let bottom = Math.max(from.row + from.rowspan - 1, to.row + to.rowspan - 1);
30303
+ let right = Math.max(from.col + from.colspan - 1, to.col + to.colspan - 1);
30304
+ for (let guard = 0; guard < 8; guard += 1) {
30305
+ let grew = false;
30306
+ for (const anchor of grid.anchorsIn(top, left, bottom, right)) {
30307
+ if (anchor.row < top) {
30308
+ top = anchor.row;
30309
+ grew = true;
30310
+ }
30311
+ if (anchor.col < left) {
30312
+ left = anchor.col;
30313
+ grew = true;
30314
+ }
30315
+ if (anchor.row + anchor.rowspan - 1 > bottom) {
30316
+ bottom = anchor.row + anchor.rowspan - 1;
30317
+ grew = true;
30318
+ }
30319
+ if (anchor.col + anchor.colspan - 1 > right) {
30320
+ right = anchor.col + anchor.colspan - 1;
30321
+ grew = true;
30322
+ }
30323
+ }
30324
+ if (!grew) break;
30325
+ }
30326
+ const anchors = grid.anchorsIn(top, left, bottom, right);
30327
+ if (anchors.length === 0) return null;
30328
+ const cells = {};
30329
+ for (const anchor of anchors) cells[anchor.id] = {
30330
+ row: anchor.row,
30331
+ col: anchor.col,
30332
+ colspan: anchor.colspan,
30333
+ rowspan: anchor.rowspan
30334
+ };
30335
+ return {
30336
+ tableId,
30337
+ top,
30338
+ left,
30339
+ bottom,
30340
+ right,
30341
+ cellIds: anchors.map((anchor) => anchor.id),
30342
+ cells
30343
+ };
30344
+ }
30345
+ /**
30346
+ * The cell whose BOX holds the point: the geometry's stand, never the
30347
+ * top-most element — the table's chrome (the seams, the handles, the chips)
30348
+ * overlays the grid, and a covered region's interior boundary stands no cell
30349
+ * to hit. `null` when the point stands outside the cells.
30350
+ */
30351
+ function cellAtPoint(table, clientX, clientY) {
30352
+ if (table === null) return null;
30353
+ for (const td of table.querySelectorAll("td[data-block-id]")) {
30354
+ const box = td.getBoundingClientRect();
30355
+ if (box.width === 0 || box.height === 0) continue;
30356
+ if (clientX >= box.left && clientX <= box.right && clientY >= box.top && clientY <= box.bottom) return td.dataset.blockId ?? null;
30357
+ }
30358
+ return null;
30359
+ }
30360
+ /** The table cell range's slice for one table (null when the range stands elsewhere / nowhere). */
30361
+ function useTableRangeOf(tableId) {
30362
+ const { store } = useEditorContext();
30363
+ return useStore(store, (state) => state.tableRange?.tableId === tableId ? state.tableRange : null);
30364
+ }
30365
+ /**
30366
+ * The cell's range stand as a bitmask (a primitive — the selector keeps the
30367
+ * cells' re-render scope to their own membership / edges): the membership bit
30368
+ * and the frame's edges the cell stands on the rectangle's boundary.
30369
+ */
30370
+ function useTableCellRangeMask(cellId) {
30371
+ const { store } = useEditorContext();
30372
+ return useStore(store, (state) => {
30373
+ const range = state.tableRange;
30374
+ if (range === null) return 0;
30375
+ const rect = range.cells[cellId];
30376
+ if (rect === void 0) return 0;
30377
+ let mask = 1;
30378
+ if (rect.row === range.top) mask |= 2;
30379
+ if (rect.col === range.left) mask |= 16;
30380
+ if (rect.row + rect.rowspan - 1 === range.bottom) mask |= 8;
30381
+ if (rect.col + rect.colspan - 1 === range.right) mask |= 4;
30382
+ return mask;
30383
+ });
30384
+ }
30385
+ /** The range's setter (the clear stands `null`). */
30386
+ function useSetTableCellRange() {
30387
+ const { store } = useEditorContext();
30388
+ return useStore(store, (state) => state.setTableCellRange);
30389
+ }
30390
+ /** The grip's drag session over one table. */
30391
+ function useTableCellRange({ doc, tableId, tableEl }) {
30392
+ const setRange = useSetTableCellRange();
30393
+ const sessionRef = useRef(null);
30394
+ return {
30395
+ onGripPointerDown: useCallback((cellId) => (event) => {
30396
+ const anchor = anchorOfId(doc, tableId, cellId);
30397
+ if (anchor === null) return;
30398
+ event.preventDefault();
30399
+ event.stopPropagation();
30400
+ event.currentTarget.setPointerCapture(event.pointerId);
30401
+ sessionRef.current = {
30402
+ pointerId: event.pointerId,
30403
+ origin: anchor
30404
+ };
30405
+ setRange(rangeOfAnchors(doc, tableId, anchor, anchor));
30406
+ }, [
30407
+ doc,
30408
+ tableId,
30409
+ setRange
30410
+ ]),
30411
+ onGripPointerMove: useCallback((event) => {
30412
+ const session = sessionRef.current;
30413
+ if (session === null || session.pointerId !== event.pointerId) return;
30414
+ const cellId = cellAtPoint(tableEl(), event.clientX, event.clientY);
30415
+ if (cellId === null) return;
30416
+ const anchor = anchorOfId(doc, tableId, cellId);
30417
+ if (anchor === null) return;
30418
+ setRange(rangeOfAnchors(doc, tableId, session.origin, anchor));
30419
+ }, [
30420
+ doc,
30421
+ tableId,
30422
+ setRange,
30423
+ tableEl
30424
+ ]),
30425
+ onGripPointerUp: useCallback((event) => {
30426
+ const session = sessionRef.current;
30427
+ if (session === null || session.pointerId !== event.pointerId) return;
30428
+ sessionRef.current = null;
30429
+ if (event.currentTarget.hasPointerCapture(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId);
30430
+ }, []),
30431
+ clearRange: useCallback(() => setRange(null), [setRange])
30432
+ };
30433
+ }
30434
+ /**
30435
+ * The table's range wiring: the grip's handlers (the context value) and the
30436
+ * Escape cancel. The table component hands the handlers to the cells and
30437
+ * keeps the range's own read for the menu's stand.
30438
+ */
30439
+ function useTableCellRangeWiring({ doc, tableId, tableEl }) {
30440
+ const session = useTableCellRange({
30441
+ doc,
30442
+ tableId,
30443
+ tableEl
30444
+ });
30445
+ const rangeHandlers = useMemo(() => ({
30446
+ onGripPointerDown: session.onGripPointerDown,
30447
+ onGripPointerMove: session.onGripPointerMove,
30448
+ onGripPointerUp: session.onGripPointerUp
30449
+ }), [
30450
+ session.onGripPointerDown,
30451
+ session.onGripPointerMove,
30452
+ session.onGripPointerUp
30453
+ ]);
30454
+ const range = useTableRangeOf(tableId);
30455
+ const { clearRange } = session;
30456
+ const { store } = useEditorContext();
30457
+ const chromeStamp = useStore(store, (state) => state.chromeStamp);
30458
+ const stampRef = useRef(chromeStamp);
30459
+ useEffect(() => {
30460
+ if (stampRef.current === chromeStamp) return;
30461
+ stampRef.current = chromeStamp;
30462
+ if (range !== null && range.tableId === tableId) clearRange();
30463
+ }, [
30464
+ chromeStamp,
30465
+ range,
30466
+ tableId,
30467
+ clearRange
30468
+ ]);
30469
+ useEffect(() => {
30470
+ if (range === null) return;
30471
+ const onKeyDown = (event) => {
30472
+ if (event.key === "Escape") clearRange();
30473
+ };
30474
+ const onPointerDown = (event) => {
30475
+ const target = event.target;
30476
+ if (!(target instanceof Element)) return;
30477
+ const cell = target.closest("td[data-block-id]");
30478
+ if (cell !== null && cell.closest(`[data-block-id="${tableId}"]`) !== null) return;
30479
+ if (target.closest("[data-slot=\"docblocks/editor\"]") === null) return;
30480
+ if (cell === null && target.closest(`[data-block-id="${tableId}"]`) !== null) return;
30481
+ clearRange();
30482
+ };
30483
+ window.addEventListener("keydown", onKeyDown);
30484
+ document.addEventListener("pointerdown", onPointerDown);
30485
+ return () => {
30486
+ window.removeEventListener("keydown", onKeyDown);
30487
+ document.removeEventListener("pointerdown", onPointerDown);
30488
+ };
30489
+ }, [
30490
+ range,
30491
+ tableId,
30492
+ clearRange
30493
+ ]);
30494
+ return {
30495
+ rangeHandlers,
30496
+ range
30497
+ };
30498
+ }
30499
+ //#endregion
30153
30500
  //#region src/blocks/table/TableCell.tsx
30154
30501
  /** The table's cell renderer (the row / column drag's transform — the cell
30155
30502
  * is the transform's element: the `<tr>` is not a CSS transformable
@@ -30160,6 +30507,9 @@ function CellActivation({ cellId }) {
30160
30507
  const TableCell = memo(function TableCell({ id, dragX, dragShifted, rowDy, rowShifted }) {
30161
30508
  const cell = useBlock(id);
30162
30509
  const { viewMode } = useEditorContext();
30510
+ const rangeHandlers = useTableCellRangeHandlers();
30511
+ const rangeMask = useTableCellRangeMask(id);
30512
+ const selected = (rangeMask & 1) !== 0;
30163
30513
  const children = cell !== void 0 && cell.type === "table-cell" ? cell.children ?? EMPTY_IDS : EMPTY_IDS;
30164
30514
  const contextValue = useBlockContextValue(id, children, "table-cell");
30165
30515
  if (cell === void 0 || cell.type !== "table-cell") return null;
@@ -30168,6 +30518,7 @@ const TableCell = memo(function TableCell({ id, dragX, dragShifted, rowDy, rowSh
30168
30518
  const dragged = hasDrag && !dragShifted && !rowShifted;
30169
30519
  const style = {
30170
30520
  ...background !== void 0 ? { background } : {},
30521
+ ...selected && !dragged ? { background: "var(--docblocks-table-range-background)" } : {},
30171
30522
  ...dragged && background === void 0 ? { background: "var(--docblocks-table-drag-background, transparent)" } : {},
30172
30523
  ...dragged ? { boxShadow: "var(--docblocks-table-drag-shadow, none), inset 0 0 0 var(--docblocks-table-border-width) var(--docblocks-table-border-color)" } : {},
30173
30524
  ...hasDrag ? {
@@ -30177,23 +30528,47 @@ const TableCell = memo(function TableCell({ id, dragX, dragShifted, rowDy, rowSh
30177
30528
  transition: dragged ? void 0 : DRAG_TRANSITION
30178
30529
  } : {}
30179
30530
  };
30531
+ const frameEdges = [
30532
+ ...(rangeMask & 2) !== 0 ? [`inset 0 var(--docblocks-table-range-border-width) 0 0 var(--docblocks-table-range-border-color)`] : [],
30533
+ ...(rangeMask & 8) !== 0 ? [`inset 0 calc(-1 * var(--docblocks-table-range-border-width)) 0 0 var(--docblocks-table-range-border-color)`] : [],
30534
+ ...(rangeMask & 16) !== 0 ? [`inset var(--docblocks-table-range-border-width) 0 0 0 var(--docblocks-table-range-border-color)`] : [],
30535
+ ...(rangeMask & 4) !== 0 ? [`inset calc(-1 * var(--docblocks-table-range-border-width)) 0 0 0 var(--docblocks-table-range-border-color)`] : []
30536
+ ];
30537
+ if (frameEdges.length > 0) style.boxShadow = [style.boxShadow, ...frameEdges].filter((part) => part !== void 0 && part !== "").join(", ");
30180
30538
  const hasOwnText = (cell.content ?? []).some((run) => run.text !== "");
30539
+ const colspan = cell.attrs?.colspan;
30540
+ const rowspan = cell.attrs?.rowspan;
30181
30541
  return /* @__PURE__ */ jsx("td", {
30182
30542
  "data-slot": "docblocks/table-cell",
30183
30543
  "data-block-id": id,
30184
- className: "\n border-(length:--docblocks-table-border-width) border-(--docblocks-table-border-color)\n p-(--docblocks-table-cell-padding) align-top\n ",
30544
+ colSpan: colspan !== void 0 && colspan > 1 ? colspan : void 0,
30545
+ rowSpan: rowspan !== void 0 && rowspan > 1 ? rowspan : void 0,
30546
+ "data-range": selected ? "true" : void 0,
30547
+ className: "\n group/cell relative border-(length:--docblocks-table-border-width) border-(--docblocks-table-border-color)\n p-(--docblocks-table-cell-padding) align-top\n ",
30185
30548
  style,
30186
30549
  children: /* @__PURE__ */ jsxs(BlockContext.Provider, {
30187
30550
  value: contextValue,
30188
- children: [hasOwnText ? /* @__PURE__ */ jsx(CellContent, {
30189
- id,
30190
- block: cell
30191
- }) : null, children.length === 0 && !hasOwnText ? viewMode ? /* @__PURE__ */ jsx("span", {
30192
- "aria-hidden": true,
30193
- "data-slot": "docblocks/cell-empty",
30194
- className: "my-(--docblocks-block-spacing) block whitespace-pre-wrap",
30195
- children: "​"
30196
- }) : /* @__PURE__ */ jsx(CellActivation, { cellId: id }) : /* @__PURE__ */ jsx(BlockGroups, { ids: children })]
30551
+ children: [
30552
+ hasOwnText ? /* @__PURE__ */ jsx(CellContent, {
30553
+ id,
30554
+ block: cell
30555
+ }) : null,
30556
+ children.length === 0 && !hasOwnText ? viewMode ? /* @__PURE__ */ jsx("span", {
30557
+ "aria-hidden": true,
30558
+ "data-slot": "docblocks/cell-empty",
30559
+ className: "my-(--docblocks-block-spacing) block whitespace-pre-wrap",
30560
+ children: "​"
30561
+ }) : /* @__PURE__ */ jsx(CellActivation, { cellId: id }) : /* @__PURE__ */ jsx(BlockGroups, { ids: children }),
30562
+ rangeHandlers !== null && !viewMode ? /* @__PURE__ */ jsx("span", {
30563
+ "aria-hidden": true,
30564
+ "data-slot": "docblocks/table-cell-range-grip",
30565
+ className: "\n absolute top-1 right-1 size-2 cursor-crosshair rounded-full bg-(--docblocks-table-border-color) opacity-0\n transition-opacity\n group-hover/cell:opacity-100\n ",
30566
+ onPointerDown: rangeHandlers.onGripPointerDown(id),
30567
+ onPointerMove: rangeHandlers.onGripPointerMove,
30568
+ onPointerUp: rangeHandlers.onGripPointerUp,
30569
+ onPointerCancel: rangeHandlers.onGripPointerUp
30570
+ }) : null
30571
+ ]
30197
30572
  })
30198
30573
  });
30199
30574
  });
@@ -30288,11 +30663,12 @@ const TableRow = memo(function TableRow({ id, rowTransform, columnTransforms, di
30288
30663
  * and the add-column chip (the table's right edge). The add-row chip and
30289
30664
  * the size's stand stand at the frame's level (they stay pinned while the
30290
30665
  * content scrolls) — over the entry. */
30291
- function TableSeams({ widths, tableWidth, tableHeight, seamXs, resizePreview, addPreview, onSeamPointerDown, onSeamPointerMove, onSeamPointerUp, onSeamPointerCancel, onSeamKeyDown, onAddChipPointerDown, onAddChipPointerMove, onAddChipPointerUp, onAddChipPointerCancel, insertTableColumn }) {
30666
+ function TableSeams({ blockedSeams, widths, tableWidth, tableHeight, seamXs, resizePreview, addPreview, onSeamPointerDown, onSeamPointerMove, onSeamPointerUp, onSeamPointerCancel, onSeamKeyDown, onAddChipPointerDown, onAddChipPointerMove, onAddChipPointerUp, onAddChipPointerCancel, insertTableColumn }) {
30292
30667
  const { t } = useTranslation("table");
30293
30668
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
30294
30669
  widths.map((_, col) => {
30295
30670
  const seamIndex = col + 1;
30671
+ if (blockedSeams.has(seamIndex)) return null;
30296
30672
  const x = col + 1 < widths.length ? seamXs[seamIndex] ?? 20 + tableWidth : 20 + tableWidth;
30297
30673
  return /* @__PURE__ */ jsx("div", {
30298
30674
  "data-slot": "docblocks/table-col-resize",
@@ -30371,7 +30747,19 @@ function TableSeams({ widths, tableWidth, tableHeight, seamXs, resizePreview, ad
30371
30747
  }
30372
30748
  //#endregion
30373
30749
  //#region src/blocks/table/use-table-add-chips.ts
30374
- function useTableAddChips({ addSessionRef, sessionRef, resizeSessionRef, addDragClickRef, setAddPreview, doc, rows, block, id }) {
30750
+ function useTableAddChips({ rowHeights, columnWidths, addSessionRef, sessionRef, resizeSessionRef, addDragClickRef, setAddPreview, doc, rows, block, id }) {
30751
+ /** The drag's count over the session's kind: the rows' heights / the columns' widths drive the steps. */
30752
+ const dragCount = (session, dy, dx) => {
30753
+ const total = session.kind === "row" ? session.rows.length : session.cols;
30754
+ const steps = session.kind === "row" ? {
30755
+ sizes: rowHeights,
30756
+ fallback: 28
30757
+ } : {
30758
+ sizes: columnWidths,
30759
+ fallback: DEFAULT_TABLE_COLUMN_WIDTH
30760
+ };
30761
+ return addDragCount(total, session.kind === "row" ? dy : dx, steps);
30762
+ };
30375
30763
  const onAddChipPointerDown = (kind) => (event) => {
30376
30764
  if (event.button !== 0 || addSessionRef.current !== null || sessionRef.current !== null || resizeSessionRef.current !== null) return;
30377
30765
  event.currentTarget.setPointerCapture?.(event.pointerId);
@@ -30392,11 +30780,9 @@ function useTableAddChips({ addSessionRef, sessionRef, resizeSessionRef, addDrag
30392
30780
  const dy = event.clientY - session.startY;
30393
30781
  if (!session.dragging && (Math.abs(dx) > 4 || Math.abs(dy) > 4)) session.dragging = true;
30394
30782
  if (!session.dragging) return;
30395
- const total = session.kind === "row" ? session.rows.length : session.cols;
30396
- const delta = session.kind === "row" ? dy : dx;
30397
30783
  setAddPreview({
30398
30784
  kind: session.kind,
30399
- count: addDragCount(session.kind, total, delta)
30785
+ count: dragCount(session, dy, dx)
30400
30786
  });
30401
30787
  };
30402
30788
  const onAddChipPointerUp = (event) => {
@@ -30420,9 +30806,7 @@ function useTableAddChips({ addSessionRef, sessionRef, resizeSessionRef, addDrag
30420
30806
  * stale guard, the handle's contract) — no command, the rows resync.
30421
30807
  */
30422
30808
  const commitAddDrag = (session, clientX, clientY) => {
30423
- const total = session.kind === "row" ? session.rows.length : session.cols;
30424
- const delta = session.kind === "row" ? clientY - session.startY : clientX - session.startX;
30425
- const count = addDragCount(session.kind, total, delta);
30809
+ const count = dragCount(session, clientY - session.startY, clientX - session.startX);
30426
30810
  if (count === 0) return;
30427
30811
  const live = doc.getBlock(id);
30428
30812
  if (live === null || live.type !== "table") return;
@@ -30472,7 +30856,7 @@ function useTableAddChips({ addSessionRef, sessionRef, resizeSessionRef, addDrag
30472
30856
  * pointerup) and the menu's doc commands (the copy over the cell's plain
30473
30857
  * text, the paste over the clipboard's plain text, the clear over the
30474
30858
  * cell's own content + the children cascade). */
30475
- function useTableCellMenu({ doc, viewMode, frameRef }) {
30859
+ function useTableCellMenu({ doc, tableId, viewMode, frameRef }) {
30476
30860
  const [ctx, setCtx] = useState(null);
30477
30861
  const pendingCtxRef = useRef(null);
30478
30862
  /**
@@ -30525,6 +30909,47 @@ function useTableCellMenu({ doc, viewMode, frameRef }) {
30525
30909
  };
30526
30910
  };
30527
30911
  const cellScope = () => frameRef.current?.closest("[data-slot=\"docblocks/editor\"]") ?? document;
30912
+ const range = useTableRangeOf(tableId);
30913
+ const setRange = useSetTableCellRange();
30914
+ /** The clicked cell's merged region stand (`colspan`/`rowspan` over 1). */
30915
+ const clicked = ctx === null ? null : doc.getBlock(ctx.cellId);
30916
+ const clickedSpan = clicked !== null && clicked.type === "table-cell" ? Math.max(clicked.attrs?.colspan ?? 1, clicked.attrs?.rowspan ?? 1) : 1;
30917
+ /**
30918
+ * The merge stands over a rectangle the command accepts — the same
30919
+ * predicate the core reads, so the menu never offers a merge that would be
30920
+ * rejected (or, worse, would take cells outside the selection).
30921
+ */
30922
+ const canMerge = (() => {
30923
+ if (range === null || range.tableId !== tableId) return false;
30924
+ const grid = resolveTableGrid(doc.raw, tableId);
30925
+ return grid !== null && isMergeableRect(grid, range);
30926
+ })();
30927
+ /** The split stands over a merged cell (the clicked one or the range's). */
30928
+ const canSplit = clickedSpan > 1 || range !== null && range.cellIds.length === 1 && clickedSpan > 1;
30929
+ /** The merge: the selected rectangle folds into its top-left cell (one undo step); the range clears. */
30930
+ const onMergeCells = () => {
30931
+ if (!canMerge || range === null) return;
30932
+ try {
30933
+ doc.mergeTableCells(range.tableId, {
30934
+ row: range.top,
30935
+ col: range.left
30936
+ }, {
30937
+ row: range.bottom,
30938
+ col: range.right
30939
+ });
30940
+ } catch {}
30941
+ setRange(null);
30942
+ };
30943
+ /** The split: the merged region containing the clicked cell (or the range's cell) expands. */
30944
+ const onSplitCells = () => {
30945
+ if (ctx === null) return;
30946
+ const anchor = anchorOfId(doc, tableId, ctx.cellId);
30947
+ if (anchor === null) return;
30948
+ try {
30949
+ doc.splitTableCells(tableId, anchor.row, anchor.col);
30950
+ } catch {}
30951
+ setRange(null);
30952
+ };
30528
30953
  /** The copy: the cell's plain text to the clipboard (the blocks joined
30529
30954
  * with the line break); an unreadable clipboard stands a no-op (v1). */
30530
30955
  const onCellCopy = async () => {
@@ -30569,10 +30994,14 @@ function useTableCellMenu({ doc, viewMode, frameRef }) {
30569
30994
  }, []);
30570
30995
  return {
30571
30996
  ctx,
30572
- closeCtx,
30573
- onCellClear,
30574
- onCellCopy,
30575
- onCellPaste,
30997
+ canMerge,
30998
+ canSplit,
30999
+ onMergeCells,
31000
+ onSplitCells,
31001
+ onOpenChange: closeCtx,
31002
+ onCopy: onCellCopy,
31003
+ onPaste: onCellPaste,
31004
+ onClear: onCellClear,
30576
31005
  onTableContextMenu
30577
31006
  };
30578
31007
  }
@@ -30775,6 +31204,39 @@ function useTableHandleDrag({ sessionRef, setHover, setMenu, tableEl, doc, rows,
30775
31204
  };
30776
31205
  }
30777
31206
  //#endregion
31207
+ //#region src/blocks/table/use-table-hover.ts
31208
+ /**
31209
+ * The table's pointer hover: the grid coordinate of the cell under the
31210
+ * pointer (the handle zones read it — the row / column highlight and the
31211
+ * hover-revealed affordances). The coordinate comes from the grid resolver,
31212
+ * not the DOM: a merged cell stands one `<td>` over several columns, so
31213
+ * `cellIndex` would count the drawn cells instead of the grid's columns.
31214
+ */
31215
+ function useTableHover({ doc, tableId }) {
31216
+ const [hover, setHover] = useState(null);
31217
+ return {
31218
+ hover,
31219
+ onContentPointerMove: useCallback((event) => {
31220
+ const cell = event.target.closest("td[data-block-id]");
31221
+ if (cell === null) return;
31222
+ const row = cell.closest("tr[data-block-id]");
31223
+ if (row === null) return;
31224
+ const cellId = cell.dataset.blockId;
31225
+ const grid = cellId === void 0 ? null : resolveTableGrid(doc.raw, tableId);
31226
+ const anchor = grid === null || cellId === void 0 ? null : grid.rows.flat().find((candidate) => candidate.id === cellId) ?? null;
31227
+ const next = anchor !== null ? {
31228
+ row: anchor.row,
31229
+ col: anchor.col
31230
+ } : {
31231
+ row: row.rowIndex,
31232
+ col: cell.cellIndex
31233
+ };
31234
+ setHover((prev) => prev !== null && prev.row === next.row && prev.col === next.col ? prev : next);
31235
+ }, [doc, tableId]),
31236
+ setHover
31237
+ };
31238
+ }
31239
+ //#endregion
30778
31240
  //#region src/blocks/table/use-table-metrics.ts
30779
31241
  /** The table's live DOM metrics: the add-row chip's left offset (the
30780
31242
  * center of the visible part of the table) and the row handles' vertical
@@ -30788,7 +31250,10 @@ function useTableMetrics({ scrollRef, tableWidth, rows }) {
30788
31250
  useLayoutEffect(() => {
30789
31251
  const el = scrollRef.current;
30790
31252
  if (el === null) return;
30791
- const update = () => setRowButtonLeft(Math.max(0, Math.min(tableWidth, el.clientWidth) / 2 - 12));
31253
+ const update = () => {
31254
+ const visible = Math.max(0, Math.min(tableWidth, el.clientWidth - 20));
31255
+ setRowButtonLeft(20 + visible / 2 - 12);
31256
+ };
30792
31257
  update();
30793
31258
  if (typeof ResizeObserver === "function") {
30794
31259
  const observer = new ResizeObserver(update);
@@ -30817,10 +31282,53 @@ function useTableMetrics({ scrollRef, tableWidth, rows }) {
30817
31282
  ]);
30818
31283
  return {
30819
31284
  rowButtonLeft,
30820
- rowMetrics
31285
+ rowMetrics,
31286
+ tableHeight: rowMetrics.length > 0 ? rowMetrics[rowMetrics.length - 1].top + rowMetrics[rowMetrics.length - 1].height : 0,
31287
+ ghostRowHeight: rowMetrics[rowMetrics.length - 1]?.height ?? 28
30821
31288
  };
30822
31289
  }
30823
31290
  //#endregion
31291
+ //#region src/blocks/table/use-table-regions.ts
31292
+ /**
31293
+ * The table's merged regions over the renderer's chrome: the stands the chrome
31294
+ * must honour — no resize seam and no reorder handle on a region's interior,
31295
+ * and no handle to drag at all for a column / row the region spans (a reorder
31296
+ * through a region would shift its rectangle; the core rejects it, and the
31297
+ * chrome simply offers nothing).
31298
+ */
31299
+ /**
31300
+ * The region-derived chrome stands. The chrome stamp re-reads the grid over
31301
+ * any structural change: a merge moves the cells' attrs and the rows'
31302
+ * children, not the table's own block, so the table's snapshot alone would
31303
+ * not re-render this.
31304
+ */
31305
+ function useTableRegions({ doc, tableId }) {
31306
+ const { store } = useEditorContext();
31307
+ const chromeStamp = useStore(store, (state) => state.chromeStamp);
31308
+ return useMemo(() => {
31309
+ const grid = resolveTableGrid(doc.raw, tableId);
31310
+ const blockedSeams = /* @__PURE__ */ new Set();
31311
+ const lockedColumns = /* @__PURE__ */ new Set();
31312
+ const lockedRows = /* @__PURE__ */ new Set();
31313
+ for (const anchor of grid?.rows.flat() ?? []) {
31314
+ if (anchor.colspan > 1) {
31315
+ for (let col = anchor.col + 1; col < anchor.col + anchor.colspan; col += 1) blockedSeams.add(col);
31316
+ for (let col = anchor.col; col < anchor.col + anchor.colspan; col += 1) lockedColumns.add(col);
31317
+ }
31318
+ if (anchor.rowspan > 1) for (let row = anchor.row; row < anchor.row + anchor.rowspan; row += 1) lockedRows.add(row);
31319
+ }
31320
+ return {
31321
+ blockedSeams,
31322
+ lockedColumns,
31323
+ lockedRows
31324
+ };
31325
+ }, [
31326
+ doc,
31327
+ tableId,
31328
+ chromeStamp
31329
+ ]);
31330
+ }
31331
+ //#endregion
30824
31332
  //#region src/blocks/table/use-table-seam-resize.ts
30825
31333
  /** The table's column-seam resize: the seam's press + drag (the live
30826
31334
  * preview overrides the dragged column's width — no wire traffic until the
@@ -30901,6 +31409,26 @@ function useTableSeamResize({ docWidths, doc, id, resizeSessionRef }) {
30901
31409
  };
30902
31410
  }
30903
31411
  //#endregion
31412
+ //#region src/blocks/table/use-table-structure-guard.ts
31413
+ /**
31414
+ * The open menu's structural guard: a concurrent structural change (a peer's
31415
+ * insert / remove / move) invalidates the menu's index-based anchor, so the
31416
+ * menu closes (a re-anchored chip would act on the wrong target; a local
31417
+ * action closes the menu before the doc changes, so this fires on concurrent
31418
+ * changes only).
31419
+ */
31420
+ function useTableStructureGuard(structureKey, open, close) {
31421
+ const previous = useRef(structureKey);
31422
+ useLayoutEffect(() => {
31423
+ if (open && previous.current !== structureKey) close();
31424
+ previous.current = structureKey;
31425
+ }, [
31426
+ structureKey,
31427
+ open,
31428
+ close
31429
+ ]);
31430
+ }
31431
+ //#endregion
30904
31432
  //#region src/blocks/table/TableBlock.tsx
30905
31433
  /**
30906
31434
  * A table: one <tr> per row block, one <td> per cell; each cell renders
@@ -30941,29 +31469,35 @@ function TableBlock({ id, block }) {
30941
31469
  const widths = resizePreview !== null ? docWidths.map((width, i) => i === resizePreview.col - 1 ? resizePreview.width : width) : docWidths;
30942
31470
  const tableWidth = widths.reduce((sum, width) => sum + width, 0);
30943
31471
  const scrollRef = useRef(null);
30944
- const [hover, setHover] = useState(null);
30945
31472
  const [menu, setMenu] = useState(null);
30946
31473
  const sessionRef = useRef(null);
30947
31474
  const frameRef = useRef(null);
30948
31475
  const addSessionRef = useRef(null);
30949
31476
  const [addPreview, setAddPreview] = useState(null);
31477
+ const addDragClickRef = useRef(false);
31478
+ const { rowButtonLeft, rowMetrics, tableHeight, ghostRowHeight } = useTableMetrics({
31479
+ scrollRef,
31480
+ tableWidth,
31481
+ rows
31482
+ });
30950
31483
  const { insertTableColumn, insertTableRow, onAddChipPointerDown, onAddChipPointerMove, onAddChipPointerUp, onAddChipPointerCancel } = useTableAddChips({
31484
+ rowHeights: rowMetrics.map((row) => row.height),
31485
+ columnWidths: widths,
30951
31486
  addSessionRef,
30952
31487
  sessionRef,
30953
31488
  resizeSessionRef,
30954
- addDragClickRef: useRef(false),
31489
+ addDragClickRef,
30955
31490
  setAddPreview,
30956
31491
  doc,
30957
31492
  rows,
30958
31493
  block,
30959
31494
  id
30960
31495
  });
30961
- const { rowButtonLeft, rowMetrics } = useTableMetrics({
30962
- scrollRef,
30963
- tableWidth,
30964
- rows
30965
- });
30966
31496
  const tableEl = () => scrollRef.current?.querySelector("table[data-slot=\"docblocks/table\"]") ?? null;
31497
+ const { hover, onContentPointerMove, setHover } = useTableHover({
31498
+ doc,
31499
+ tableId: id
31500
+ });
30967
31501
  const { preview, onHandlePointerDown, onHandlePointerMove, onHandlePointerUp, onHandlePointerCancel } = useTableHandleDrag({
30968
31502
  sessionRef,
30969
31503
  setHover,
@@ -30974,19 +31508,14 @@ function TableBlock({ id, block }) {
30974
31508
  block,
30975
31509
  id
30976
31510
  });
30977
- const onContentPointerMove = (event) => {
30978
- const cell = event.target.closest("td[data-block-id]");
30979
- if (cell === null) return;
30980
- const row = cell.closest("tr[data-block-id]");
30981
- if (row === null) return;
30982
- const next = {
30983
- row: row.rowIndex,
30984
- col: cell.cellIndex
30985
- };
30986
- setHover((prev) => prev !== null && prev.row === next.row && prev.col === next.col ? prev : next);
30987
- };
30988
- const { ctx, closeCtx, onCellClear, onCellCopy, onCellPaste, onTableContextMenu } = useTableCellMenu({
31511
+ const { rangeHandlers } = useTableCellRangeWiring({
31512
+ doc,
31513
+ tableId: id,
31514
+ tableEl
31515
+ });
31516
+ const cellMenu = useTableCellMenu({
30989
31517
  doc,
31518
+ tableId: id,
30990
31519
  viewMode,
30991
31520
  frameRef
30992
31521
  });
@@ -30999,13 +31528,12 @@ function TableBlock({ id, block }) {
30999
31528
  });
31000
31529
  const columnCenters = columnCentersOf(widths);
31001
31530
  const seamXs = seamXsOf(widths);
31002
- const structureKey = `${block.columnOrder.length}:${rows.join(",")}`;
31003
- const prevStructureKey = useRef(structureKey);
31004
- useLayoutEffect(() => {
31005
- if (menu !== null && prevStructureKey.current !== structureKey) setMenu(null);
31006
- prevStructureKey.current = structureKey;
31007
- }, [structureKey, menu]);
31008
- const tableHeight = rowMetrics.length > 0 ? rowMetrics[rowMetrics.length - 1].top + rowMetrics[rowMetrics.length - 1].height : 0;
31531
+ const { blockedSeams, lockedColumns, lockedRows } = useTableRegions({
31532
+ doc,
31533
+ tableId: id
31534
+ });
31535
+ const closeMenuRef = () => setMenu(null);
31536
+ useTableStructureGuard(`${block.columnOrder.length}:${rows.join(",")}`, menu !== null, closeMenuRef);
31009
31537
  const columnTransforms = widths.map((_, index) => columnDragTransformOf(preview, index));
31010
31538
  const clearHover = () => setHover(null);
31011
31539
  const closeMenu = (open) => {
@@ -31033,25 +31561,30 @@ function TableBlock({ id, block }) {
31033
31561
  "data-block-id": id,
31034
31562
  className: "relative m-0 table-fixed border-collapse",
31035
31563
  style: { width: tableWidth },
31036
- onContextMenu: onTableContextMenu,
31037
- children: [/* @__PURE__ */ jsx("colgroup", { children: widths.map((width, index) => /* @__PURE__ */ jsx("col", { style: { width } }, index)) }), /* @__PURE__ */ jsx("tbody", { children: /* @__PURE__ */ jsxs(BlockContext.Provider, {
31038
- value: contextValue,
31039
- children: [rows.map((rowId, rowIndex) => /* @__PURE__ */ jsx(TableRow, {
31040
- id: rowId,
31041
- rowTransform: rowDragTransformOf(preview, rowIndex),
31042
- columnTransforms,
31043
- dimmed: addPreview !== null && addPreview.kind === "row" && addPreview.count < 0 && rowIndex >= rows.length + addPreview.count
31044
- }, rowId)), addPreview !== null && addPreview.kind === "row" && addPreview.count > 0 ? Array.from({ length: addPreview.count }, (_, i) => /* @__PURE__ */ jsx("tr", {
31045
- "aria-hidden": true,
31046
- "data-slot": "docblocks/table-ghost-row",
31047
- children: /* @__PURE__ */ jsx("td", {
31048
- colSpan: block.columnOrder.length,
31049
- className: "\n border-(length:--docblocks-table-border-width) border-dashed\n border-(--docblocks-table-border-color) bg-muted/40\n ",
31050
- style: { height: 28 }
31051
- })
31052
- }, `ghost-row-${i}`)) : null]
31564
+ onContextMenu: cellMenu.onTableContextMenu,
31565
+ children: [/* @__PURE__ */ jsx("colgroup", { children: widths.map((width, index) => /* @__PURE__ */ jsx("col", { style: { width } }, index)) }), /* @__PURE__ */ jsx("tbody", { children: /* @__PURE__ */ jsx(TableCellRangeContext.Provider, {
31566
+ value: rangeHandlers,
31567
+ children: /* @__PURE__ */ jsxs(BlockContext.Provider, {
31568
+ value: contextValue,
31569
+ children: [rows.map((rowId, rowIndex) => /* @__PURE__ */ jsx(TableRow, {
31570
+ id: rowId,
31571
+ rowTransform: rowDragTransformOf(preview, rowIndex),
31572
+ columnTransforms,
31573
+ dimmed: addPreview !== null && addPreview.kind === "row" && addPreview.count < 0 && rowIndex >= rows.length + addPreview.count
31574
+ }, rowId)), addPreview !== null && addPreview.kind === "row" && addPreview.count > 0 ? Array.from({ length: addPreview.count }, (_, i) => /* @__PURE__ */ jsx("tr", {
31575
+ "aria-hidden": true,
31576
+ "data-slot": "docblocks/table-ghost-row",
31577
+ children: /* @__PURE__ */ jsx("td", {
31578
+ colSpan: block.columnOrder.length,
31579
+ className: "\n border-(length:--docblocks-table-border-width) border-dashed\n border-(--docblocks-table-border-color) bg-muted/40\n ",
31580
+ style: { height: ghostRowHeight }
31581
+ })
31582
+ }, `ghost-row-${i}`)) : null]
31583
+ })
31053
31584
  }) })]
31054
31585
  }), !viewMode && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(TableHandles, {
31586
+ lockedColumns,
31587
+ lockedRows,
31055
31588
  tableId: id,
31056
31589
  widths,
31057
31590
  rows,
@@ -31072,6 +31605,7 @@ function TableBlock({ id, block }) {
31072
31605
  onRowHandleColor,
31073
31606
  palette
31074
31607
  }), /* @__PURE__ */ jsx(TableSeams, {
31608
+ blockedSeams,
31075
31609
  widths,
31076
31610
  tableWidth,
31077
31611
  tableHeight,
@@ -31099,15 +31633,11 @@ function TableBlock({ id, block }) {
31099
31633
  onAddChipPointerCancel,
31100
31634
  rowButtonLeft,
31101
31635
  addPreview,
31636
+ tableWidth,
31637
+ rowMetrics,
31102
31638
  columnCount: block.columnOrder.length,
31103
31639
  rowCount: rows.length,
31104
- cellMenu: {
31105
- ctx,
31106
- onOpenChange: closeCtx,
31107
- onCopy: onCellCopy,
31108
- onPaste: onCellPaste,
31109
- onClear: onCellClear
31110
- }
31640
+ cellMenu
31111
31641
  })]
31112
31642
  });
31113
31643
  }
@@ -34571,6 +35101,7 @@ function createEditorStore(doc, rootId) {
34571
35101
  presence: [],
34572
35102
  sharing: "off",
34573
35103
  canvasClipboard: null,
35104
+ tableRange: null,
34574
35105
  fileUpload: null,
34575
35106
  changeStamp: 0,
34576
35107
  chromeStamp: 0,
@@ -34583,6 +35114,7 @@ function createEditorStore(doc, rootId) {
34583
35114
  store.setState({ collapsedIds: collapsed ? [...ids.includes(id) ? ids : [...ids, id]] : ids.filter((x) => x !== id) });
34584
35115
  },
34585
35116
  setCanvasClipboard: (clipboard) => store.setState({ canvasClipboard: clipboard }),
35117
+ setTableCellRange: (range) => store.setState({ tableRange: range }),
34586
35118
  setFileUpload: (stand) => store.setState({ fileUpload: stand })
34587
35119
  }));
34588
35120
  return store;
@@ -36039,18 +36571,20 @@ const COVER_ACCEPTED_MIME_TYPES = [
36039
36571
  "image/jpeg",
36040
36572
  "image/webp"
36041
36573
  ];
36042
- /** The cover's renderable-MIME's predicate. A module-level const keeps the
36043
- * predicate's identity stable (the resolution's effect's dep — an inline
36044
- * arrow re-runs the effect on every render). The lenient's `image/*`'s
36045
- * stand: the legacy's covers may stand a format outside the upload's
36046
- * strict's gate. */
36047
- const COVER_RENDERS_BYTES = (mimeType) => mimeType.startsWith("image/");
36574
+ /** The cover's renderable-MIME's predicate (both the bytes' path and the
36575
+ * store's direct URL render an image the same way). A module-level const
36576
+ * keeps the predicate's identity stable (the resolution's effect's dep —
36577
+ * an inline arrow re-runs the effect on every render). The lenient's
36578
+ * `image/*`'s stand: the legacy's covers may stand a format outside the
36579
+ * upload's strict's gate. */
36580
+ const COVER_RENDERS_IMAGE = (mimeType) => mimeType.startsWith("image/");
36048
36581
  /** The cover mode's ordered options (the tile's stand stands first — the
36049
36582
  * selector's default's stand). */
36050
36583
  const COVER_MODE_ORDER = ["tile", "center"];
36051
36584
  /**
36052
36585
  * The intrinsic dimensions over a decodable image blob (the
36053
- * `createImageBitmap` decode probe — the bytes are never rendered).
36586
+ * `createImageBitmap` decode probe — the bytes are never rendered). The
36587
+ * picked file's upload validation reads them before a store exists.
36054
36588
  * `null` over an undecodable payload (the fail-open: the consumer's
36055
36589
  * renderer may accept a format the browser cannot probe).
36056
36590
  */
@@ -36069,82 +36603,82 @@ async function readImageDimensions(file) {
36069
36603
  return null;
36070
36604
  }
36071
36605
  }
36606
+ /**
36607
+ * The browser's decode over an image url: the store's direct URL or the
36608
+ * library's own object URL. The element carries the intrinsic dimensions,
36609
+ * and the tint draws it into the sample's canvas — a `blob:` url stays
36610
+ * same-origin, so that read never taints. `null` over an undecodable
36611
+ * payload.
36612
+ */
36613
+ async function decodeImageUrl(url) {
36614
+ const img = new Image();
36615
+ img.src = url;
36616
+ try {
36617
+ await img.decode();
36618
+ return img;
36619
+ } catch {
36620
+ return null;
36621
+ }
36622
+ }
36623
+ /**
36624
+ * The intrinsic dimensions over a resolved image url (the display path's
36625
+ * probe — the browser decodes the very image the cover renders, so its own
36626
+ * cache serves the payload). `null` over an undecodable payload or a
36627
+ * zero-sized element (the fail-open stands the caller's own rendering).
36628
+ */
36629
+ async function readUrlDimensions(url) {
36630
+ const img = await decodeImageUrl(url);
36631
+ if (img === null || img.naturalWidth === 0 || img.naturalHeight === 0) return null;
36632
+ return {
36633
+ width: img.naturalWidth,
36634
+ height: img.naturalHeight
36635
+ };
36636
+ }
36072
36637
  /** The frame's tint's CSS variable (the cover's average color's stand
36073
36638
  * over the card's element — the border's mix's input). */
36074
36639
  const COVER_TINT_VARIABLE = "--docblocks-cover-tint-color";
36075
36640
  /** The tint's average's sample's size (the pixel's count per side — the
36076
36641
  * grid's area's mean over the image's downscale). */
36077
36642
  const TINT_SAMPLE_PX = 8;
36078
- /** The image's decode over the `<img>`'s element (the SVG's stand — the
36079
- * `createImageBitmap`'s rejection's parity: the engine refuses the SVG's
36080
- * blob over the bitmap's API, while the image's decode accepts it over
36081
- * the raster's formats' parity). The object URL's lifecycle stands the
36082
- * decode's completion (the pixels' in-memory's stand over the revoke —
36083
- * the draw's source is the decoded's image, not the url). */
36084
- async function decodeToImage(file) {
36085
- const url = URL.createObjectURL(file);
36086
- const img = new Image();
36087
- img.src = url;
36643
+ /**
36644
+ * The alpha-weighted average color over a resolved image url (the frame's
36645
+ * tint's / the consumer's glow's data's source): the image stands
36646
+ * downscaled to the sample's grid over a canvas, and the mean stands the
36647
+ * premultiplied's accumulation (the alpha's share per pixel) — the
36648
+ * transparent's stand no gray's pull (the alpha fade's cover stands its
36649
+ * solid's hue, not the fade's average). The `rgb(...)`'s string over the
36650
+ * computed's stand; `null` over an undecodable payload, the canvas's
36651
+ * absence, or a tainted read (a cross-origin url without CORS — the caller
36652
+ * stands the bytes' same-origin object URL as the fallback).
36653
+ */
36654
+ async function averageColorOfUrl(url) {
36655
+ const img = await decodeImageUrl(url);
36656
+ if (img === null) return null;
36088
36657
  try {
36089
- await img.decode();
36090
- return img;
36658
+ const canvas = document.createElement("canvas");
36659
+ canvas.width = TINT_SAMPLE_PX;
36660
+ canvas.height = TINT_SAMPLE_PX;
36661
+ const ctx = canvas.getContext("2d");
36662
+ if (ctx === null) return null;
36663
+ ctx.drawImage(img, 0, 0, TINT_SAMPLE_PX, TINT_SAMPLE_PX);
36664
+ const data = ctx.getImageData(0, 0, TINT_SAMPLE_PX, TINT_SAMPLE_PX).data;
36665
+ let r = 0;
36666
+ let g = 0;
36667
+ let b = 0;
36668
+ let alphaSum = 0;
36669
+ for (let i = 0; i < data.length; i += 4) {
36670
+ const alpha = (data[i + 3] ?? 0) / 255;
36671
+ r += (data[i] ?? 0) * alpha;
36672
+ g += (data[i + 1] ?? 0) * alpha;
36673
+ b += (data[i + 2] ?? 0) * alpha;
36674
+ alphaSum += alpha;
36675
+ }
36676
+ if (alphaSum === 0) return null;
36677
+ const mean = (sum) => Math.round(sum / alphaSum);
36678
+ return `rgb(${mean(r)}, ${mean(g)}, ${mean(b)})`;
36091
36679
  } catch {
36092
36680
  return null;
36093
- } finally {
36094
- URL.revokeObjectURL(url);
36095
- }
36096
- }
36097
- /** The average's color's cache over the blob's identity (the re-resolution's
36098
- * no re-compute's stand; the store's change's new blob stands a fresh
36099
- * entry — the weak key's stand keeps the dead blobs' garbage's parity).
36100
- */
36101
- const tintColorCache = /* @__PURE__ */ new WeakMap();
36102
- /**
36103
- * The alpha-weighted average color over a decodable image blob (the
36104
- * frame's tint's / the consumer's glow's data's source): the image stands
36105
- * downscaled to the sample's grid over a canvas (the `img`'s decode — the
36106
- * SVG's parity), and the mean stands the premultiplied's accumulation
36107
- * (the alpha's share per pixel) — the transparent's stand no gray's pull
36108
- * (the alpha fade's cover stands its solid's hue, not the fade's
36109
- * average). The `rgb(...)`'s string over the computed's stand; `null`
36110
- * over an undecodable payload or the canvas's absence (the jsdom's
36111
- * fail-open's stand — the plain border's parity).
36112
- */
36113
- async function averageColorOfBlob(file) {
36114
- let cached = tintColorCache.get(file);
36115
- if (cached === void 0) {
36116
- cached = (async () => {
36117
- const img = await decodeToImage(file);
36118
- if (img === null) return null;
36119
- try {
36120
- const canvas = document.createElement("canvas");
36121
- canvas.width = TINT_SAMPLE_PX;
36122
- canvas.height = TINT_SAMPLE_PX;
36123
- const ctx = canvas.getContext("2d");
36124
- if (ctx === null) return null;
36125
- ctx.drawImage(img, 0, 0, TINT_SAMPLE_PX, TINT_SAMPLE_PX);
36126
- const data = ctx.getImageData(0, 0, TINT_SAMPLE_PX, TINT_SAMPLE_PX).data;
36127
- let r = 0;
36128
- let g = 0;
36129
- let b = 0;
36130
- let alphaSum = 0;
36131
- for (let i = 0; i < data.length; i += 4) {
36132
- const alpha = (data[i + 3] ?? 0) / 255;
36133
- r += (data[i] ?? 0) * alpha;
36134
- g += (data[i + 1] ?? 0) * alpha;
36135
- b += (data[i + 2] ?? 0) * alpha;
36136
- alphaSum += alpha;
36137
- }
36138
- if (alphaSum === 0) return null;
36139
- const mean = (sum) => Math.round(sum / alphaSum);
36140
- return `rgb(${mean(r)}, ${mean(g)}, ${mean(b)})`;
36141
- } catch {
36142
- return null;
36143
- }
36144
- })();
36145
- tintColorCache.set(file, cached);
36146
36681
  }
36147
- return cached;
36148
36682
  }
36149
36683
  /**
36150
36684
  * The banner's bottom fade-out's mask (the last pixels' smooth stand into
@@ -36240,6 +36774,72 @@ function centerBackgroundStyle(dimensions, containerWidthPx, url) {
36240
36774
  };
36241
36775
  }
36242
36776
  //#endregion
36777
+ //#region src/attributes/use-cover-image.ts
36778
+ /**
36779
+ * The cover's resolved image over the editor's blob store: the renderable
36780
+ * url, where it came from, and — on demand — the intrinsic dimensions. The
36781
+ * cover renders the store's own `downloadUrl` when it supplies one (the
36782
+ * browser's cacheable subrequest, as the image block does), the fetched
36783
+ * bytes' object URL otherwise.
36784
+ */
36785
+ /** The status over the blob file's resolution state. */
36786
+ function coverStatusOf(state) {
36787
+ switch (state.status) {
36788
+ case "loading":
36789
+ case "missing": return state.status;
36790
+ case "ready":
36791
+ case "ready-url": return "ready";
36792
+ case "ready-meta": return "unrenderable";
36793
+ }
36794
+ }
36795
+ /**
36796
+ * The intrinsic dimensions over the resolved stand: the bytes' own decode
36797
+ * probe over the blob, or the browser's decode of the rendered url (the
36798
+ * store's direct URL — its own cache serves the payload).
36799
+ */
36800
+ function useImageDimensions(blob, url, measure) {
36801
+ const [dimensions, setDimensions] = useState(null);
36802
+ useEffect(() => {
36803
+ if (!measure || url === null) {
36804
+ setDimensions(null);
36805
+ return;
36806
+ }
36807
+ let alive = true;
36808
+ (blob === null ? readUrlDimensions(url) : readImageDimensions(blob)).then((next) => {
36809
+ if (alive) setDimensions(next);
36810
+ });
36811
+ return () => {
36812
+ alive = false;
36813
+ };
36814
+ }, [
36815
+ blob,
36816
+ url,
36817
+ measure
36818
+ ]);
36819
+ return dimensions;
36820
+ }
36821
+ /**
36822
+ * The stored cover's image: the blob store's resolution (the metadata's head
36823
+ * lookup decides the renderable MIME and the store's direct URL's stand), and
36824
+ * the intrinsic dimensions over the requested measure.
36825
+ */
36826
+ function useCoverImage(fileId, options = {}) {
36827
+ const { state } = useBlobFile(fileId, COVER_RENDERS_IMAGE, {
36828
+ eager: options.eager,
36829
+ rendersFromUrl: COVER_RENDERS_IMAGE
36830
+ });
36831
+ const blob = state.status === "ready" ? state.blob : null;
36832
+ const url = state.status === "ready" || state.status === "ready-url" ? state.url : null;
36833
+ const source = state.status === "ready" ? "bytes" : state.status === "ready-url" ? "url" : null;
36834
+ const dimensions = useImageDimensions(blob, url, options.measure === true);
36835
+ return {
36836
+ status: coverStatusOf(state),
36837
+ url,
36838
+ source,
36839
+ dimensions
36840
+ };
36841
+ }
36842
+ //#endregion
36243
36843
  //#region src/attributes/CoverPresets.tsx
36244
36844
  /** The cover modal's preset's surface (the modal's subcomponent over the
36245
36845
  * `cover.ts`'s contract): the preset's cell (the consumer's store's
@@ -36262,7 +36862,7 @@ function editorWidthOf(anchor) {
36262
36862
  * caller's mode (the upload's no stand — the consumer's catalog's curation
36263
36863
  * is the gate's stand over the presets). */
36264
36864
  function CoverPresetCell({ fileId, label, busy, onPick }) {
36265
- const { state: file } = useBlobFile(fileId, COVER_RENDERS_BYTES, { eager: true });
36865
+ const { status, url } = useCoverImage(fileId, { eager: true });
36266
36866
  return /* @__PURE__ */ jsx("button", {
36267
36867
  type: "button",
36268
36868
  "data-slot": "docblocks/cover-preset",
@@ -36272,8 +36872,8 @@ function CoverPresetCell({ fileId, label, busy, onPick }) {
36272
36872
  disabled: busy,
36273
36873
  onClick: onPick,
36274
36874
  className: "\n flex h-18 w-full items-center justify-center overflow-hidden rounded-md border border-border bg-muted\n text-muted-foreground\n hover:border-primary\n disabled:opacity-60\n ",
36275
- children: file.status === "ready" ? /* @__PURE__ */ jsx("img", {
36276
- src: file.url,
36875
+ children: status === "ready" && url !== null ? /* @__PURE__ */ jsx("img", {
36876
+ src: url,
36277
36877
  alt: "",
36278
36878
  className: "size-full object-cover"
36279
36879
  }) : /* @__PURE__ */ jsx(Image$1, { className: "size-4" })
@@ -36515,22 +37115,25 @@ function CoverUploadModal({ anchorRef, initialMode, onCommit, onClose }) {
36515
37115
  /** The cover's row's control (the file id's thumbnail / the upload's
36516
37116
  * entry / the remove; the read-only stand stands the thumbnail
36517
37117
  * display-only). The upload's entry opens the modal (the mode's
36518
- * selector + the drop zone + the gate's stands live over it). */
37118
+ * selector + the drop zone + the gate's stands live over it). The
37119
+ * thumbnail stands the store's direct URL when it supplies one, the
37120
+ * bytes' object URL otherwise. */
36519
37121
  function CoverEditor({ fileId, mode, readOnly, onCommit, onClear }) {
36520
37122
  const { t } = useTranslation("editor");
36521
- const { state: file } = useBlobFile(fileId ?? "", COVER_RENDERS_BYTES, { eager: true });
37123
+ const { status, url } = useCoverImage(fileId ?? "", { eager: true });
36522
37124
  const [open, setOpen] = useState(false);
36523
37125
  const anchorRef = useRef(null);
37126
+ const thumbnail = status === "ready" && url !== null;
36524
37127
  return /* @__PURE__ */ jsxs("div", {
36525
37128
  ref: anchorRef,
36526
37129
  tabIndex: -1,
36527
37130
  className: "flex min-w-0 items-center gap-2 outline-none",
36528
37131
  children: [
36529
- fileId !== void 0 && (file.status === "ready" || file.status === "ready-meta") ? /* @__PURE__ */ jsx("span", {
37132
+ fileId !== void 0 && (thumbnail || status === "unrenderable") ? /* @__PURE__ */ jsx("span", {
36530
37133
  "data-slot": "docblocks/attributes-cover",
36531
37134
  className: "block size-10 shrink-0 overflow-hidden rounded-md border bg-muted",
36532
- children: file.status === "ready" ? /* @__PURE__ */ jsx("img", {
36533
- src: file.url,
37135
+ children: thumbnail ? /* @__PURE__ */ jsx("img", {
37136
+ src: url,
36534
37137
  alt: "",
36535
37138
  className: "size-full object-cover"
36536
37139
  }) : null
@@ -36581,24 +37184,10 @@ function CoverEditor({ fileId, mode, readOnly, onCommit, onClear }) {
36581
37184
  const EDITOR_SELECTOR = "[data-slot=\"docblocks/editor\"]";
36582
37185
  function CoverModeSelector({ coverId, mode, readOnly, onChange }) {
36583
37186
  const { t } = useTranslation("editor");
36584
- const { state: file } = useBlobFile(coverId, COVER_RENDERS_BYTES, { eager: true });
36585
- const blob = file.status === "ready" ? file.blob : null;
36586
- /** The intrinsic dimensions' probe (the gate's input — the undecodable's
36587
- * payload keeps the gate's fail-open stand). */
36588
- const [dimensions, setDimensions] = useState(null);
36589
- useLayoutEffect(() => {
36590
- if (blob === null) {
36591
- setDimensions(null);
36592
- return;
36593
- }
36594
- let alive = true;
36595
- readImageDimensions(blob).then((next) => {
36596
- if (alive) setDimensions(next);
36597
- });
36598
- return () => {
36599
- alive = false;
36600
- };
36601
- }, [blob]);
37187
+ const { dimensions } = useCoverImage(coverId, {
37188
+ eager: true,
37189
+ measure: true
37190
+ });
36602
37191
  /** The editor frame's live width (the centering's gate's input): the
36603
37192
  * anchor's nearest editor frame's box over the mount's measure + the
36604
37193
  * resize's watch (the jsdom's no-layout's stand keeps the zero's value
@@ -37061,7 +37650,9 @@ function AttributesPanel() {
37061
37650
  * over the scaled height). The banner is decoration only: the pointer's
37062
37651
  * transparent stand keeps the page's selection and the cross-drag's
37063
37652
  * stands untouched. The bottom's last pixels stand the fade-out's smooth
37064
- * stand into the page's content. */
37653
+ * stand into the page's content. The image stands the store's direct URL
37654
+ * when it supplies one (the browser's cacheable subrequest), the bytes'
37655
+ * object URL otherwise. */
37065
37656
  function CoverBanner() {
37066
37657
  const { store } = useEditorContext();
37067
37658
  const attributes = useStore(store, (state) => state.meta).attributes;
@@ -37073,28 +37664,15 @@ function CoverBanner() {
37073
37664
  });
37074
37665
  }
37075
37666
  /** The banner's body (the hooks' stand — the mount only over the cover's
37076
- * presence, so the resolution's hook never sees the empty's id). */
37667
+ * presence, so the resolution's hook never sees the empty's id). The
37668
+ * dimensions' probe runs over the centering only (the tile's fixed strip
37669
+ * needs no intrinsic size) — the store's direct URL serves the probe as it
37670
+ * serves the render. */
37077
37671
  function CoverBannerBody({ coverId, mode }) {
37078
- const { state: file } = useBlobFile(coverId, COVER_RENDERS_BYTES, { eager: true });
37079
- const blob = file.status === "ready" ? file.blob : null;
37080
- /** The intrinsic dimensions' probe (the centering's slice's input — the
37081
- * width's scale over the container; the undecodable's payload stands
37082
- * the fallback's plain image's stand). The tile's stand needs no probe
37083
- * (the fixed's strip's height is the layout's constant). */
37084
- const [dimensions, setDimensions] = useState(null);
37085
- useLayoutEffect(() => {
37086
- if (blob === null || mode === "tile") {
37087
- setDimensions(null);
37088
- return;
37089
- }
37090
- let alive = true;
37091
- readImageDimensions(blob).then((next) => {
37092
- if (alive) setDimensions(next);
37093
- });
37094
- return () => {
37095
- alive = false;
37096
- };
37097
- }, [blob, mode]);
37672
+ const { url, dimensions } = useCoverImage(coverId, {
37673
+ eager: true,
37674
+ measure: mode === "center"
37675
+ });
37098
37676
  /** The frame's live width (the centering's slice's height's input): the
37099
37677
  * wrapper's own box (the full frame's width's stand) over the mount's
37100
37678
  * measure + the resize's watch (the jsdom's no-layout's stand keeps the
@@ -37114,8 +37692,8 @@ function CoverBannerBody({ coverId, mode }) {
37114
37692
  const observer = new ResizeObserver(measure);
37115
37693
  observer.observe(el);
37116
37694
  return () => observer.disconnect();
37117
- }, [file.status === "ready"]);
37118
- if (file.status !== "ready") return null;
37695
+ }, [url !== null]);
37696
+ if (url === null) return null;
37119
37697
  return /* @__PURE__ */ jsx("div", {
37120
37698
  ref: wrapperRef,
37121
37699
  "data-slot": "docblocks/cover-banner",
@@ -37128,18 +37706,18 @@ function CoverBannerBody({ coverId, mode }) {
37128
37706
  },
37129
37707
  children: mode === "tile" ? /* @__PURE__ */ jsx("div", {
37130
37708
  className: "w-full",
37131
- style: tileBackgroundStyle(file.url)
37709
+ style: tileBackgroundStyle(url)
37132
37710
  }) : dimensions === null ? /* @__PURE__ */ jsx("div", {
37133
37711
  className: "flex w-full justify-center",
37134
37712
  children: /* @__PURE__ */ jsx("img", {
37135
- src: file.url,
37713
+ src: url,
37136
37714
  alt: "",
37137
37715
  className: "max-w-full",
37138
37716
  style: { maxHeight: 150 }
37139
37717
  })
37140
37718
  }) : /* @__PURE__ */ jsx("div", {
37141
37719
  className: "w-full",
37142
- style: centerBackgroundStyle(dimensions, width, file.url)
37720
+ style: centerBackgroundStyle(dimensions, width, url)
37143
37721
  })
37144
37722
  });
37145
37723
  }
@@ -37147,20 +37725,21 @@ function CoverBannerBody({ coverId, mode }) {
37147
37725
  //#region src/attributes/cover-tint.tsx
37148
37726
  /**
37149
37727
  * The stored cover's average color (the frame's tint's / the consumer's
37150
- * glow's data's source): the cover's blob resolved over the editor's blob
37151
- * store, and the alpha-weighted average read from it — the `rgb(...)`'s
37152
- * string or `null` over the absent's id / the unresolved's / the
37153
- * undecodable's stand. The blob's identity's cache stands the
37154
- * re-resolution's no re-compute (the store's change's new blob stands the
37155
- * fresh entry).
37728
+ * glow's data's source): the cover's resolved url drawn into the sample's
37729
+ * canvas — the `rgb(...)`'s string or `null` over the absent's id / the
37730
+ * unresolved's / the undecodable's stand. The resolved url is the store's
37731
+ * direct URL when it supplies one; a cross-origin URL without CORS taints
37732
+ * the canvas, so that read falls back to the fetched bytes' same-origin
37733
+ * object URL (the library's own read).
37156
37734
  */
37157
37735
  function useCoverAverageColor() {
37158
37736
  const { store, blobStore } = useEditorContext();
37159
37737
  const attributes = useStore(store, (state) => state.meta.attributes);
37160
37738
  const coverId = typeof attributes?.cover === "string" ? attributes.cover : void 0;
37739
+ const { url, source } = useCoverImage(coverId ?? "", { eager: true });
37161
37740
  const [color, setColor] = useState(null);
37162
37741
  useEffect(() => {
37163
- if (coverId === void 0) {
37742
+ if (url === null) {
37164
37743
  setColor(null);
37165
37744
  return;
37166
37745
  }
@@ -37168,15 +37747,36 @@ function useCoverAverageColor() {
37168
37747
  const settle = (next) => {
37169
37748
  if (alive) setColor(next);
37170
37749
  };
37171
- const load = async () => {
37750
+ /**
37751
+ * The bytes' read: the same-origin object URL (a `blob:` url never
37752
+ * taints the canvas) — the fallback over a store URL the canvas cannot
37753
+ * read, and the legacy resolution's own stand.
37754
+ */
37755
+ const readBytes = async () => {
37756
+ if (coverId === void 0) {
37757
+ settle(null);
37758
+ return;
37759
+ }
37760
+ let blobUrl = null;
37172
37761
  try {
37173
37762
  const ref = await blobStore.get(coverId);
37174
- settle(await averageColorOfBlob(ref.blob));
37763
+ blobUrl = URL.createObjectURL(ref.blob);
37764
+ settle(await averageColorOfUrl(blobUrl));
37175
37765
  } catch {
37176
37766
  settle(null);
37767
+ } finally {
37768
+ if (blobUrl !== null) URL.revokeObjectURL(blobUrl);
37177
37769
  }
37178
37770
  };
37179
- const unsubscribe = blobStore.subscribe(coverId, () => {
37771
+ const load = async () => {
37772
+ const direct = await averageColorOfUrl(url);
37773
+ if (direct !== null || source !== "url") {
37774
+ settle(direct);
37775
+ return;
37776
+ }
37777
+ await readBytes();
37778
+ };
37779
+ const unsubscribe = blobStore.subscribe(coverId ?? "", () => {
37180
37780
  load();
37181
37781
  });
37182
37782
  load();
@@ -37184,7 +37784,12 @@ function useCoverAverageColor() {
37184
37784
  alive = false;
37185
37785
  unsubscribe();
37186
37786
  };
37187
- }, [blobStore, coverId]);
37787
+ }, [
37788
+ blobStore,
37789
+ coverId,
37790
+ url,
37791
+ source
37792
+ ]);
37188
37793
  return color;
37189
37794
  }
37190
37795
  /**