docblocks-react-ui 0.26.0 → 0.28.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.
@@ -453,6 +453,10 @@ const INIT_OPTIONS = {
453
453
  rowCount_few: "rows",
454
454
  rowCount_many: "rows",
455
455
  rowCount_other: "rows",
456
+ visibleRowCount_one: "{count} shown",
457
+ visibleRowCount_few: "{count} shown",
458
+ visibleRowCount_many: "{count} shown",
459
+ visibleRowCount_other: "{count} shown",
456
460
  toolbar: {
457
461
  "undo": "Undo",
458
462
  "redo": "Redo",
@@ -460,7 +464,10 @@ const INIT_OPTIONS = {
460
464
  "columns": "Columns",
461
465
  "apply": "Apply"
462
466
  },
467
+ rename: { "aria": "Rename {name}" },
468
+ renameTable: { "aria": "Rename table {name}" },
463
469
  columns: {
470
+ "empty": "No columns yet.",
464
471
  "move": "Move {name}",
465
472
  "visibility": "Show {name}"
466
473
  },
@@ -503,11 +510,17 @@ const INIT_OPTIONS = {
503
510
  "delete": "Delete column",
504
511
  "resizeHeight": "Resize the header row"
505
512
  },
513
+ resizeHeight: "Resize the database block",
506
514
  row: {
507
515
  "moveUp": "Move up",
508
516
  "moveDown": "Move down",
509
517
  "delete": "Delete row"
510
518
  },
519
+ range: {
520
+ "options": "Selected range",
521
+ "clear": "Clear range",
522
+ "deleteRows": "Delete rows"
523
+ },
511
524
  rows: {
512
525
  "loadMore": "Load more rows",
513
526
  "none": "No rows.",
@@ -526,7 +539,26 @@ const INIT_OPTIONS = {
526
539
  "group": "+ Group",
527
540
  "groupHeader": "Group {index}",
528
541
  "removeCondition": "Remove condition",
529
- "valuePlaceholder": "value, value"
542
+ "valuePlaceholder": "value, value",
543
+ "operators": {
544
+ "is": "is",
545
+ "is not": "is not",
546
+ "contains": "contains",
547
+ "not contains": "not contains",
548
+ "starts with": "starts with",
549
+ "ends with": "ends with",
550
+ "empty": "empty",
551
+ "not empty": "not empty",
552
+ "<": "<",
553
+ "<=": "<=",
554
+ ">": ">",
555
+ ">=": ">=",
556
+ "between": "between",
557
+ "before": "before",
558
+ "after": "after",
559
+ "in": "in",
560
+ "not in": "not in"
561
+ }
530
562
  },
531
563
  picker: {
532
564
  "searchOptions": "Search options",
@@ -997,6 +1029,10 @@ const INIT_OPTIONS = {
997
1029
  rowCount_few: "строки",
998
1030
  rowCount_many: "строк",
999
1031
  rowCount_other: "строк",
1032
+ visibleRowCount_one: "Показана {count} строка",
1033
+ visibleRowCount_few: "Показано {count} строки",
1034
+ visibleRowCount_many: "Показано {count} строк",
1035
+ visibleRowCount_other: "Показано {count} строк",
1000
1036
  toolbar: {
1001
1037
  "undo": "Отменить",
1002
1038
  "redo": "Повторить",
@@ -1004,7 +1040,10 @@ const INIT_OPTIONS = {
1004
1040
  "columns": "Колонки",
1005
1041
  "apply": "Применить"
1006
1042
  },
1043
+ rename: { "aria": "Переименовать {name}" },
1044
+ renameTable: { "aria": "Переименовать таблицу {name}" },
1007
1045
  columns: {
1046
+ "empty": "Колонок пока нет.",
1008
1047
  "move": "Переместить {name}",
1009
1048
  "visibility": "Показать {name}"
1010
1049
  },
@@ -1047,11 +1086,17 @@ const INIT_OPTIONS = {
1047
1086
  "delete": "Удалить столбец",
1048
1087
  "resizeHeight": "Изменить высоту заголовка"
1049
1088
  },
1089
+ resizeHeight: "Изменить высоту блока базы данных",
1050
1090
  row: {
1051
1091
  "moveUp": "Переместить вверх",
1052
1092
  "moveDown": "Переместить вниз",
1053
1093
  "delete": "Удалить строку"
1054
1094
  },
1095
+ range: {
1096
+ "options": "Выделенный диапазон",
1097
+ "clear": "Очистить диапазон",
1098
+ "deleteRows": "Удалить строки"
1099
+ },
1055
1100
  rows: {
1056
1101
  "loadMore": "Загрузить ещё строки",
1057
1102
  "none": "Нет строк.",
@@ -1070,7 +1115,26 @@ const INIT_OPTIONS = {
1070
1115
  "group": "+ Группа",
1071
1116
  "groupHeader": "Группа {index}",
1072
1117
  "removeCondition": "Удалить условие",
1073
- "valuePlaceholder": "значение, значение"
1118
+ "valuePlaceholder": "значение, значение",
1119
+ "operators": {
1120
+ "is": "равно",
1121
+ "is not": "не равно",
1122
+ "contains": "содержит",
1123
+ "not contains": "не содержит",
1124
+ "starts with": "начинается с",
1125
+ "ends with": "завершается на",
1126
+ "empty": "не заполнено",
1127
+ "not empty": "заполнено",
1128
+ "<": "меньше",
1129
+ "<=": "меньше или равно",
1130
+ ">": "больше",
1131
+ ">=": "больше или равно",
1132
+ "between": "между",
1133
+ "before": "ранее",
1134
+ "after": "позднее",
1135
+ "in": "в списке",
1136
+ "not in": "не в списке"
1137
+ }
1074
1138
  },
1075
1139
  picker: {
1076
1140
  "searchOptions": "Поиск вариантов",
@@ -3072,6 +3136,23 @@ function Quote(props) {
3072
3136
  });
3073
3137
  }
3074
3138
  //#endregion
3139
+ //#region src/shared/ui/icons/Redo.tsx
3140
+ function Redo(props) {
3141
+ return /* @__PURE__ */ jsxs("svg", {
3142
+ xmlns: "http://www.w3.org/2000/svg",
3143
+ width: 24,
3144
+ height: 24,
3145
+ viewBox: "0 0 24 24",
3146
+ fill: "none",
3147
+ stroke: "currentColor",
3148
+ strokeWidth: 2,
3149
+ strokeLinecap: "round",
3150
+ strokeLinejoin: "round",
3151
+ ...props,
3152
+ children: [/* @__PURE__ */ jsx("path", { d: "M21 7v6h-6" }), /* @__PURE__ */ jsx("path", { d: "M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7" })]
3153
+ });
3154
+ }
3155
+ //#endregion
3075
3156
  //#region src/shared/ui/icons/RotateCcw.tsx
3076
3157
  function RotateCcw(props) {
3077
3158
  return /* @__PURE__ */ jsxs("svg", {
@@ -3588,6 +3669,23 @@ function Underline(props) {
3588
3669
  });
3589
3670
  }
3590
3671
  //#endregion
3672
+ //#region src/shared/ui/icons/Undo.tsx
3673
+ function Undo(props) {
3674
+ return /* @__PURE__ */ jsxs("svg", {
3675
+ xmlns: "http://www.w3.org/2000/svg",
3676
+ width: 24,
3677
+ height: 24,
3678
+ viewBox: "0 0 24 24",
3679
+ fill: "none",
3680
+ stroke: "currentColor",
3681
+ strokeWidth: 2,
3682
+ strokeLinecap: "round",
3683
+ strokeLinejoin: "round",
3684
+ ...props,
3685
+ children: [/* @__PURE__ */ jsx("path", { d: "M3 7v6h6" }), /* @__PURE__ */ jsx("path", { d: "M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13" })]
3686
+ });
3687
+ }
3688
+ //#endregion
3591
3689
  //#region src/shared/ui/icons/User.tsx
3592
3690
  function User(props) {
3593
3691
  return /* @__PURE__ */ jsxs("svg", {
@@ -4135,14 +4233,18 @@ const NUMBER_OPERATORS = [
4135
4233
  "<=",
4136
4234
  ">",
4137
4235
  ">=",
4138
- "between"
4236
+ "between",
4237
+ "empty",
4238
+ "not empty"
4139
4239
  ];
4140
4240
  /** The date / datetime operators. */
4141
4241
  const DATE_OPERATORS = [
4142
4242
  "is",
4143
4243
  "before",
4144
4244
  "after",
4145
- "between"
4245
+ "between",
4246
+ "empty",
4247
+ "not empty"
4146
4248
  ];
4147
4249
  /** The time-of-day operators. */
4148
4250
  const TIME_OPERATORS = [
@@ -4150,9 +4252,18 @@ const TIME_OPERATORS = [
4150
4252
  "is not",
4151
4253
  "before",
4152
4254
  "after",
4153
- "between"
4255
+ "between",
4256
+ "empty",
4257
+ "not empty"
4258
+ ];
4259
+ /** The boolean operators (the emptiness's checks stand the null's cell). */
4260
+ const BOOLEAN_OPERATORS = [
4261
+ "is",
4262
+ "is not",
4263
+ "empty",
4264
+ "not empty"
4154
4265
  ];
4155
- /** The equality-only operators (the boolean / interval / unknown). */
4266
+ /** The equality-only operators (the interval / unknown). */
4156
4267
  const EQUALITY_OPERATORS = ["is", "is not"];
4157
4268
  /** The standard PostgreSQL type names per operator / input group. The contract
4158
4269
  * is type-agnostic — this is the package's DEFAULT catalog; a non-standard
@@ -4218,7 +4329,8 @@ function operatorCatalog(type) {
4218
4329
  const base = baseType(type);
4219
4330
  if (TEXT_TYPES.has(base)) return TEXT_OPERATORS;
4220
4331
  if (NUMBER_TYPES.has(base)) return NUMBER_OPERATORS;
4221
- if (BOOLEAN_TYPES.has(base) || INTERVAL_TYPES.has(base)) return EQUALITY_OPERATORS;
4332
+ if (BOOLEAN_TYPES.has(base)) return BOOLEAN_OPERATORS;
4333
+ if (INTERVAL_TYPES.has(base)) return EQUALITY_OPERATORS;
4222
4334
  if (DATE_TYPES.has(base) || DATETIME_TYPES.has(base)) return DATE_OPERATORS;
4223
4335
  if (TIME_TYPES.has(base)) return TIME_OPERATORS;
4224
4336
  }
@@ -4243,12 +4355,12 @@ function valueInputFor(type) {
4243
4355
  function columnAnnotation(column) {
4244
4356
  let operators;
4245
4357
  if (column.operators !== void 0) operators = [...column.operators];
4246
- else if (column.refKind === "enum" || column.refKind === "row") operators = column.refMany ? [
4358
+ else if (column.refKind === "enum" || column.refKind === "row") operators = [
4247
4359
  "is",
4248
4360
  "is not",
4249
4361
  "empty",
4250
4362
  "not empty"
4251
- ] : ["is", "is not"];
4363
+ ];
4252
4364
  else operators = operatorCatalog(column.type) ?? ["is", "is not"];
4253
4365
  let valueInput;
4254
4366
  if (column.refKind === "enum") valueInput = "enum";
@@ -5730,7 +5842,7 @@ function Input({ className, size, variant, type, ...props }) {
5730
5842
  * user's text is never clobbered mid-edit — the input wins until the
5731
5843
  * commit or the cancel).
5732
5844
  */
5733
- function InlineEditInput({ initial, ariaLabel, slot, className, placeholder, invalid, variant, selectOnMount, onCommit, onCancel }) {
5845
+ function InlineEditInput({ initial, ariaLabel, slot, className, placeholder, invalid, size, variant, selectOnMount, onCommit, onCancel }) {
5734
5846
  const inputRef = useRef(null);
5735
5847
  const committedRef = useRef(false);
5736
5848
  const [value, setValue] = useState(initial);
@@ -5776,6 +5888,7 @@ function InlineEditInput({ initial, ariaLabel, slot, className, placeholder, inv
5776
5888
  };
5777
5889
  const onInputBlur = (event) => commit(event.target.value);
5778
5890
  const onInputKeyDown = (event) => {
5891
+ event.stopPropagation();
5779
5892
  if (event.key === "Enter") {
5780
5893
  event.preventDefault();
5781
5894
  commit(event.currentTarget.value);
@@ -5789,6 +5902,7 @@ function InlineEditInput({ initial, ariaLabel, slot, className, placeholder, inv
5789
5902
  "data-slot": slot,
5790
5903
  "aria-label": ariaLabel,
5791
5904
  "aria-invalid": invalid ? true : void 0,
5905
+ size,
5792
5906
  variant,
5793
5907
  placeholder,
5794
5908
  value,
@@ -6069,6 +6183,57 @@ function Textarea({ className, ...props }) {
6069
6183
  });
6070
6184
  }
6071
6185
  //#endregion
6186
+ //#region src/database/filter-builder/FilterOperatorPicker.tsx
6187
+ /**
6188
+ * The filter's operator's picker: the popover's option list over the column
6189
+ * annotation's catalog (the trigger stands the selected operator's localized
6190
+ * label, the list stands the catalog over its declared order with the active
6191
+ * option marked). The pick commits the wire's op — the display label never
6192
+ * reaches the payload (the op's contract), and a consumer's custom operator
6193
+ * (the `operators` override) stands its raw form when the catalog has no
6194
+ * label for it.
6195
+ */
6196
+ function FilterOperatorPicker({ operators, value, onPick }) {
6197
+ const { t } = useTranslation("database");
6198
+ const [open, setOpen] = useState(false);
6199
+ const label = (operator) => t(`filter.operators.${operator}`, operator);
6200
+ const pick = (operator) => {
6201
+ setOpen(false);
6202
+ onPick(operator);
6203
+ };
6204
+ const pickOption = (operator) => () => pick(operator);
6205
+ return /* @__PURE__ */ jsxs(Popover, {
6206
+ open,
6207
+ onOpenChange: setOpen,
6208
+ children: [/* @__PURE__ */ jsx(PopoverTrigger, {
6209
+ asChild: true,
6210
+ children: /* @__PURE__ */ jsx(Button, {
6211
+ type: "button",
6212
+ variant: "outline",
6213
+ size: "sm",
6214
+ "data-slot": "docblocks/filter-operator",
6215
+ "data-operator": value,
6216
+ className: "\n h-8 max-w-45 truncate rounded-md border border-input bg-transparent px-2 text-sm text-foreground\n outline-none\n focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50\n dark:bg-input/30\n ",
6217
+ children: label(value)
6218
+ })
6219
+ }), /* @__PURE__ */ jsx(PopoverContent, {
6220
+ align: "start",
6221
+ className: "w-48 gap-0.5 p-1.5",
6222
+ children: operators.map((operator) => /* @__PURE__ */ jsx(Button, {
6223
+ type: "button",
6224
+ variant: "ghost",
6225
+ size: "sm",
6226
+ "data-slot": "docblocks/filter-operator-option",
6227
+ "data-operator": operator,
6228
+ "data-active": operator === value ? "true" : void 0,
6229
+ className: cn("w-full cursor-pointer justify-start rounded-md px-2 py-1.5 font-normal", operator === value && "bg-muted"),
6230
+ onClick: pickOption(operator),
6231
+ children: label(operator)
6232
+ }, operator))
6233
+ })]
6234
+ });
6235
+ }
6236
+ //#endregion
6072
6237
  //#region src/database/grid/use-ref-tables.ts
6073
6238
  /**
6074
6239
  * The ref-table data provider for the grid: one page of the ref table's
@@ -6280,6 +6445,17 @@ function reorderItems(items, fromIndex, toIndex) {
6280
6445
  next.splice(toIndex, 0, moved);
6281
6446
  return next;
6282
6447
  }
6448
+ /** The pointer's Y (the pointer / mouse's `clientY`; the touch's last
6449
+ * changed touch's `clientY`) — the drag's release's commit input (the
6450
+ * native event's coordinate over the drag's tracked position's stand). */
6451
+ function pointerYOf$1(event) {
6452
+ if ("changedTouches" in event) {
6453
+ const touches = event.changedTouches;
6454
+ const touch = touches[touches.length - 1];
6455
+ return touch === null || touch === void 0 ? null : touch.clientY;
6456
+ }
6457
+ return event.clientY;
6458
+ }
6283
6459
  /** A visible header drop mapped into the full order without moving hidden ids over an anchor. */
6284
6460
  function moveVisibleColumn(columns, columnOrder, hiddenColumns, columnId, toIndex) {
6285
6461
  const fullOrder = normalizeColumnOrder(columns, columnOrder);
@@ -6383,13 +6559,12 @@ function formatCellDateTime(value) {
6383
6559
  const time = format(value, "HH:mm");
6384
6560
  return value.getSeconds() !== 0 ? `${base}T${time}:${format(value, "ss")}` : `${base}T${time}`;
6385
6561
  }
6386
- /** The form draft over a catalog entry (the name prefills the type's
6387
- * label — the create's commit takes the input's name). */
6388
- function emptyColumnForm(entry) {
6562
+ /** The form draft over a catalog entry and its localized display name. */
6563
+ function emptyColumnForm(entry, name) {
6389
6564
  return {
6390
6565
  key: entry.key,
6391
6566
  type: entry.type,
6392
- name: entry.label,
6567
+ name,
6393
6568
  numberKind: entry.numberKind,
6394
6569
  decimals: entry.numberKind === "decimal" ? 2 : 0,
6395
6570
  thousands: false,
@@ -6533,11 +6708,6 @@ function FilterConditionRow({ condition, columns, onChange, onRemove, refTableDa
6533
6708
  value: void 0
6534
6709
  });
6535
6710
  };
6536
- const onOperatorChange = (event) => onChange({
6537
- ...condition,
6538
- op: event.target.value,
6539
- value: void 0
6540
- });
6541
6711
  const onValueChange = (value) => onChange({
6542
6712
  ...condition,
6543
6713
  op: operator,
@@ -6567,14 +6737,14 @@ function FilterConditionRow({ condition, columns, onChange, onRemove, refTableDa
6567
6737
  children: entry.name
6568
6738
  }, entry.id))
6569
6739
  }),
6570
- /* @__PURE__ */ jsx(BareSelect, {
6571
- "data-slot": "docblocks/filter-operator",
6740
+ /* @__PURE__ */ jsx(FilterOperatorPicker, {
6741
+ operators: annotation.operators,
6572
6742
  value: operator,
6573
- onChange: onOperatorChange,
6574
- children: annotation.operators.map((entry) => /* @__PURE__ */ jsx("option", {
6575
- value: entry,
6576
- children: entry
6577
- }, entry))
6743
+ onPick: (nextOperator) => onChange({
6744
+ ...condition,
6745
+ op: nextOperator,
6746
+ value: void 0
6747
+ })
6578
6748
  }),
6579
6749
  needsValue && /* @__PURE__ */ jsx(ValueInput, {
6580
6750
  column,
@@ -7247,6 +7417,48 @@ function useTableHistory({ bridge, tableId, noteError, clearError, refresh, clea
7247
7417
  };
7248
7418
  }
7249
7419
  //#endregion
7420
+ //#region src/database/use-database-table/load-more.ts
7421
+ /** The next page's continuation (the `nextCursor`'s stand over the
7422
+ * cursor's snapshot boundary). */
7423
+ function createLoadMore(ctx) {
7424
+ const { bridge, tableId, nextCursor, loadTokenRef, pageRef, revisionsRef, setRows, setNextCursor } = ctx;
7425
+ const { noteError, refresh } = ctx;
7426
+ return async () => {
7427
+ if (nextCursor === null) return;
7428
+ const token = loadTokenRef.current;
7429
+ const { asOfSeq, fingerprint } = pageRef.current;
7430
+ try {
7431
+ const page = await bridge.queryNextPage(tableId, {
7432
+ cursor: nextCursor,
7433
+ asOfSeq,
7434
+ queryFingerprint: fingerprint
7435
+ });
7436
+ if (token !== loadTokenRef.current) return;
7437
+ pageRef.current = {
7438
+ asOfSeq: page.asOfSeq,
7439
+ fingerprint: page.queryFingerprint
7440
+ };
7441
+ for (const row of page.rows) revisionsRef.current.set(row.id, row.revision);
7442
+ setRows((rows) => {
7443
+ const known = new Set(rows.map((row) => row.rowId));
7444
+ const appended = page.rows.filter((row) => !known.has(row.id)).map((row) => ({
7445
+ rowId: row.id,
7446
+ cells: { ...row.cells }
7447
+ }));
7448
+ return [...rows, ...appended];
7449
+ });
7450
+ setNextCursor(page.nextCursor);
7451
+ } catch (operationError) {
7452
+ if (token !== loadTokenRef.current) return;
7453
+ if (isBridgeError(operationError) && operationError.code === "cursor_expired") {
7454
+ refresh();
7455
+ return;
7456
+ }
7457
+ noteError(operationError);
7458
+ }
7459
+ };
7460
+ }
7461
+ //#endregion
7250
7462
  //#region src/database/use-database-table/row-write-ops.ts
7251
7463
  /**
7252
7464
  * The single-row's cell writes (the insert / the update) over the bridge:
@@ -7615,40 +7827,45 @@ function restorePatchesOf(before, cleaned) {
7615
7827
  function createRowStructureOps(ctx) {
7616
7828
  const { bridge, tableId, rowsRef, pendingRowRef, capabilitiesRef, setRows, setPendingRow } = ctx;
7617
7829
  const { pushUndo, refresh, noteError, casOf, sameIdentity } = ctx;
7618
- const removeRow = async (rowId) => {
7830
+ const removeRows = async (rowIds) => {
7831
+ const ids = [...new Set(rowIds)].filter((rowId) => rowOf(rowsRef, pendingRowRef, rowId) !== void 0);
7832
+ if (ids.length === 0) return;
7833
+ const removed = new Set(ids);
7619
7834
  const snapshot = rowsRef.current;
7620
- const row = rowOf(rowsRef, pendingRowRef, rowId);
7621
- setRows((rows) => rows.filter((entry) => entry.rowId !== rowId));
7835
+ const pendingSnapshot = pendingRowRef.current;
7836
+ setRows((rows) => rows.filter((entry) => !removed.has(entry.rowId)));
7622
7837
  try {
7623
- await bridge.batchRows(tableId, { ops: [{
7838
+ await bridge.batchRows(tableId, { ops: ids.map((rowId) => ({
7624
7839
  op: "delete",
7625
7840
  rowId,
7626
7841
  ...casOf(rowId)
7627
- }] }, newMutationContext());
7842
+ })) }, newMutationContext());
7628
7843
  if (!sameIdentity()) return;
7629
- setPendingRow((current) => current?.rowId === rowId ? null : current);
7630
- if (row !== void 0 && capabilitiesRef.current.includes("rowRestore")) pushUndo({
7631
- label: `remove row ${rowId}`,
7844
+ setPendingRow((current) => current !== null && removed.has(current.rowId) ? null : current);
7845
+ if (capabilitiesRef.current.includes("rowRestore")) pushUndo({
7846
+ label: `remove rows ${ids.join(", ")}`,
7632
7847
  forward: async () => {
7633
- await bridge.batchRows(tableId, { ops: [{
7848
+ await bridge.batchRows(tableId, { ops: ids.map((rowId) => ({
7634
7849
  op: "delete",
7635
7850
  rowId
7636
- }] }, newMutationContext());
7851
+ })) }, newMutationContext());
7637
7852
  },
7638
7853
  inverse: async () => {
7639
- await bridge.undeleteRows(tableId, { rowIds: [rowId] }, newMutationContext());
7854
+ await bridge.undeleteRows(tableId, { rowIds: ids }, newMutationContext());
7640
7855
  }
7641
7856
  }, bridge, tableId);
7642
7857
  refresh();
7643
7858
  } catch (operationError) {
7644
7859
  if (sameIdentity()) {
7645
7860
  setRows(snapshot);
7861
+ setPendingRow(pendingSnapshot);
7646
7862
  noteError(operationError);
7647
7863
  refresh();
7648
7864
  }
7649
7865
  throw toBridgeError(operationError);
7650
7866
  }
7651
7867
  };
7868
+ const removeRow = async (rowId) => removeRows([rowId]);
7652
7869
  const moveRow = async (rowId, beforeRowId) => {
7653
7870
  const snapshot = rowsRef.current.map((row) => ({
7654
7871
  rowId: row.rowId,
@@ -7702,6 +7919,7 @@ function createRowStructureOps(ctx) {
7702
7919
  };
7703
7920
  return {
7704
7921
  removeRow,
7922
+ removeRows,
7705
7923
  moveRow
7706
7924
  };
7707
7925
  }
@@ -7752,9 +7970,19 @@ function applySnapshotState(state, snapshot, clearError = false) {
7752
7970
  function useTableStream(ctx) {
7753
7971
  const { bridge, tableId, filter, filterKey, loadVersion, state, noteError } = ctx;
7754
7972
  const { loadTokenRef, subGenRef } = state;
7973
+ const loadedIdentityRef = useRef(null);
7755
7974
  const applySnapshot = (snapshot, clearError = false) => applySnapshotState(state, snapshot, clearError);
7756
7975
  useEffect(() => {
7976
+ const loadedIdentity = loadedIdentityRef.current;
7977
+ const sameIdentity = loadedIdentity?.bridge === bridge && loadedIdentity.tableId === tableId;
7757
7978
  state.setPendingRow(null);
7979
+ state.setNextCursor(null);
7980
+ if (!sameIdentity) {
7981
+ loadedIdentityRef.current = null;
7982
+ state.setTable(null);
7983
+ state.setRows([]);
7984
+ state.revisionsRef.current = /* @__PURE__ */ new Map();
7985
+ }
7758
7986
  let disposed = false;
7759
7987
  let handle = null;
7760
7988
  let lastSeenSeq = null;
@@ -7765,6 +7993,7 @@ function useTableStream(ctx) {
7765
7993
  state.setNextCursor(null);
7766
7994
  state.revisionsRef.current = /* @__PURE__ */ new Map();
7767
7995
  if (handle !== null) handle.unsubscribe();
7996
+ loadedIdentityRef.current = null;
7768
7997
  state.setPhase("broken");
7769
7998
  noteError(operationError);
7770
7999
  };
@@ -7785,7 +8014,7 @@ function useTableStream(ctx) {
7785
8014
  const myGen = ++subGenRef.current;
7786
8015
  const token = ++loadTokenRef.current;
7787
8016
  handle?.unsubscribe();
7788
- if (!disposed) state.setPhase("loading");
8017
+ if (!disposed && !sameIdentity) state.setPhase("loading");
7789
8018
  try {
7790
8019
  const descriptor = await bridge.describeProtocol();
7791
8020
  if (disposed || token !== loadTokenRef.current) return;
@@ -7799,6 +8028,10 @@ function useTableStream(ctx) {
7799
8028
  lastSeenSeq = snapshot.page.asOfSeq;
7800
8029
  seenSeqs.clear();
7801
8030
  applySnapshot(snapshot, true);
8031
+ loadedIdentityRef.current = {
8032
+ bridge,
8033
+ tableId
8034
+ };
7802
8035
  handle = bridge.subscribeTable(tableId, { afterSeq: snapshot.page.asOfSeq }, {
7803
8036
  ready: () => void 0,
7804
8037
  event: (envelope) => {
@@ -7854,46 +8087,6 @@ function useTableStream(ctx) {
7854
8087
  loadVersion
7855
8088
  ]);
7856
8089
  }
7857
- /** The next page's continuation (the `nextCursor`'s stand over the
7858
- * cursor's snapshot boundary). */
7859
- function createLoadMore(ctx) {
7860
- const { bridge, tableId, nextCursor, loadTokenRef, pageRef, revisionsRef, setRows, setNextCursor } = ctx;
7861
- const { noteError, refresh } = ctx;
7862
- return async () => {
7863
- if (nextCursor === null) return;
7864
- const token = loadTokenRef.current;
7865
- const { asOfSeq, fingerprint } = pageRef.current;
7866
- try {
7867
- const page = await bridge.queryNextPage(tableId, {
7868
- cursor: nextCursor,
7869
- asOfSeq,
7870
- queryFingerprint: fingerprint
7871
- });
7872
- if (token !== loadTokenRef.current) return;
7873
- pageRef.current = {
7874
- asOfSeq: page.asOfSeq,
7875
- fingerprint: page.queryFingerprint
7876
- };
7877
- for (const row of page.rows) revisionsRef.current.set(row.id, row.revision);
7878
- setRows((rows) => {
7879
- const known = new Set(rows.map((row) => row.rowId));
7880
- const appended = page.rows.filter((row) => !known.has(row.id)).map((row) => ({
7881
- rowId: row.id,
7882
- cells: { ...row.cells }
7883
- }));
7884
- return [...rows, ...appended];
7885
- });
7886
- setNextCursor(page.nextCursor);
7887
- } catch (operationError) {
7888
- if (token !== loadTokenRef.current) return;
7889
- if (isBridgeError(operationError) && operationError.code === "cursor_expired") {
7890
- refresh();
7891
- return;
7892
- }
7893
- noteError(operationError);
7894
- }
7895
- };
7896
- }
7897
8090
  //#endregion
7898
8091
  //#region src/database/use-database-table/use-database-table.ts
7899
8092
  /**
@@ -8094,6 +8287,7 @@ function useDatabaseTable(bridge, tableId, filter) {
8094
8287
  updateRows: rowBatch.updateRows,
8095
8288
  pasteRows: rowBatch.pasteRows,
8096
8289
  removeRow: rowStructure.removeRow,
8290
+ removeRows: rowStructure.removeRows,
8097
8291
  moveRow: rowStructure.moveRow,
8098
8292
  addColumn: column.addColumn,
8099
8293
  updateColumn: column.updateColumn,
@@ -8111,6 +8305,63 @@ function useDatabaseTable(bridge, tableId, filter) {
8111
8305
  };
8112
8306
  }
8113
8307
  //#endregion
8308
+ //#region src/database/grid/DatabaseRangeMenu.tsx
8309
+ function DatabaseRangeMenu({ anchor, onOpenChange, onClear, onDelete }) {
8310
+ const { t } = useTranslation("database");
8311
+ return /* @__PURE__ */ jsxs(DropdownMenu, {
8312
+ modal: false,
8313
+ open: anchor !== null,
8314
+ onOpenChange,
8315
+ children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
8316
+ asChild: true,
8317
+ children: /* @__PURE__ */ jsx("div", {
8318
+ "aria-hidden": true,
8319
+ className: "pointer-events-none fixed size-0",
8320
+ style: {
8321
+ left: anchor?.x ?? 0,
8322
+ top: anchor?.y ?? 0
8323
+ }
8324
+ })
8325
+ }), /* @__PURE__ */ jsxs(DropdownMenuContent, {
8326
+ "data-slot": "docblocks/database-context-menu",
8327
+ "aria-label": t("range.options"),
8328
+ sideOffset: 4,
8329
+ children: [/* @__PURE__ */ jsx(DropdownMenuItem, {
8330
+ "data-slot": "docblocks/database-context-clear",
8331
+ onSelect: onClear,
8332
+ children: t("range.clear")
8333
+ }), /* @__PURE__ */ jsx(DropdownMenuItem, {
8334
+ "data-slot": "docblocks/database-context-delete",
8335
+ variant: "destructive",
8336
+ onSelect: onDelete,
8337
+ children: t("range.deleteRows")
8338
+ })]
8339
+ })]
8340
+ });
8341
+ }
8342
+ //#endregion
8343
+ //#region src/database/grid/DatabaseResizeHandle.tsx
8344
+ /** The database block's bottom-edge height handle. */
8345
+ function DatabaseResizeHandle({ height, minHeight, onPointerDown, onPointerMove, onPointerUp, onPointerCancel, onKeyDown }) {
8346
+ const { t } = useTranslation("database");
8347
+ return /* @__PURE__ */ jsx("div", {
8348
+ "data-slot": "docblocks/database-resize",
8349
+ role: "slider",
8350
+ "aria-orientation": "vertical",
8351
+ "aria-valuemin": minHeight,
8352
+ "aria-valuenow": Math.round(height),
8353
+ "aria-label": t("resizeHeight"),
8354
+ tabIndex: 0,
8355
+ className: "\n absolute inset-x-0 bottom-0 z-10 flex h-2 cursor-row-resize items-end justify-center opacity-0\n transition-opacity outline-none\n group-hover:opacity-100\n focus-visible:opacity-100\n ",
8356
+ onPointerDown,
8357
+ onPointerMove,
8358
+ onPointerUp,
8359
+ onPointerCancel,
8360
+ onKeyDown,
8361
+ children: /* @__PURE__ */ jsx("div", { className: "mb-0.5 h-0.5 w-10 rounded-full bg-(--docblocks-divider-border-color)" })
8362
+ });
8363
+ }
8364
+ //#endregion
8114
8365
  //#region src/database/grid/EnumOptionsEditor.tsx
8115
8366
  /** The enum's options editor (the create / the edit's form stand): the
8116
8367
  * option's rows over the draft (the grip's press-drag stands the live
@@ -8254,59 +8505,50 @@ function EnumOptionsEditor({ options, onChange }) {
8254
8505
  }
8255
8506
  //#endregion
8256
8507
  //#region src/database/grid/constants.ts
8257
- /** The add-column type catalog (the `label` is the form's `name` prefill —
8258
- * the document data; the `labelKey` is the menu's i18n key, the
8259
- * `database` namespace's `columnTypes.*`). */
8508
+ /** The add-column type catalog; `labelKey` supplies the localized menu
8509
+ * label and the create form's name prefill. */
8260
8510
  const ADD_COLUMN_TYPES = [
8261
8511
  {
8262
8512
  key: "text",
8263
8513
  type: "text",
8264
- label: "Text",
8265
8514
  labelKey: "columnTypes.text"
8266
8515
  },
8267
8516
  {
8268
8517
  key: "integer",
8269
8518
  type: "integer",
8270
- label: "Integer",
8271
8519
  labelKey: "columnTypes.integer",
8272
8520
  numberKind: "integer"
8273
8521
  },
8274
8522
  {
8275
8523
  key: "decimal",
8276
8524
  type: "numeric",
8277
- label: "Decimal",
8278
8525
  labelKey: "columnTypes.decimal",
8279
8526
  numberKind: "decimal"
8280
8527
  },
8281
8528
  {
8282
8529
  key: "checkbox",
8283
8530
  type: "boolean",
8284
- label: "Checkbox",
8285
8531
  labelKey: "columnTypes.checkbox"
8286
8532
  },
8287
8533
  {
8288
8534
  key: "date",
8289
8535
  type: "date",
8290
- label: "Date",
8291
8536
  labelKey: "columnTypes.date"
8292
8537
  },
8293
8538
  {
8294
8539
  key: "datetime",
8295
8540
  type: "timestamptz",
8296
- label: "Date & time",
8297
8541
  labelKey: "columnTypes.datetime"
8298
8542
  },
8299
8543
  {
8300
8544
  key: "enum",
8301
8545
  type: "text",
8302
- label: "Enum",
8303
8546
  labelKey: "columnTypes.enum",
8304
8547
  refKind: "enum"
8305
8548
  },
8306
8549
  {
8307
8550
  key: "multi-enum",
8308
8551
  type: "text",
8309
- label: "Multi-enum",
8310
8552
  labelKey: "columnTypes.multiEnum",
8311
8553
  refKind: "enum",
8312
8554
  refMany: true
@@ -8314,19 +8556,18 @@ const ADD_COLUMN_TYPES = [
8314
8556
  {
8315
8557
  key: "row-link",
8316
8558
  type: "text",
8317
- label: "Row link",
8318
8559
  labelKey: "columnTypes.rowLink",
8319
8560
  refKind: "row"
8320
8561
  },
8321
8562
  {
8322
8563
  key: "row-links",
8323
8564
  type: "text",
8324
- label: "Row links",
8325
8565
  labelKey: "columnTypes.rowLinks",
8326
8566
  refKind: "row",
8327
8567
  refMany: true
8328
8568
  }
8329
8569
  ];
8570
+ const DATABASE_HEADER_WRAP_ATTR = "data-header-wrap";
8330
8571
  /** The shared cell wrapper classes (the left border + the padding). */
8331
8572
  const CELL_WRAP = "flex min-h-6 min-w-0 items-center overflow-hidden border-(--docblocks-table-border-color) p-(--docblocks-table-cell-padding)";
8332
8573
  /** The input's shared classes over the `Input` primitive's sm base: no
@@ -8339,92 +8580,30 @@ const GRID_DRAG_TRANSITION = "transform 120ms ease-out";
8339
8580
  const GRID_CHROME_FRAME = "rounded-(--docblocks-radius) border-(length:--docblocks-table-border-width) border-(--docblocks-table-border-color) bg-transparent dark:border-(--docblocks-table-border-color) dark:bg-transparent";
8340
8581
  const GRID_BUTTON_HOVER = "cursor-pointer hover:opacity-70 hover:bg-transparent hover:text-inherit dark:hover:bg-transparent";
8341
8582
  //#endregion
8342
- //#region src/database/grid/GridStateCards.tsx
8583
+ //#region src/database/grid/AddColumnForm.tsx
8343
8584
  /**
8344
- * The grid's non-ready state's surfaces: the loading's stand (the
8345
- * placeholder's text) and the broken's stand (the table's death / the
8346
- * fatal read's error surface + the reload's entry). The frames stand the
8347
- * block's data attributes (the inspector's / the e2e's locators).
8585
+ * The add-column's create form (the popover over the add-column track's
8586
+ * anchor): the name input + the type-specific block (the number's display
8587
+ * attributes / the enum's options' editor / the row-link's table pick +
8588
+ * the new-table creation) + the create / save button. The commit stands
8589
+ * the button's press only (the outside press / the Escape close without
8590
+ * the commit — the draft's loss). The focus's stand: the menu's entry
8591
+ * stands the form (the menu's close restores the focus to the plus
8592
+ * trigger — the focus-outside would close the form the very tick it
8593
+ * opens); the nested popovers' portals (the color's palette / the
8594
+ * select's content) stand outside the form's content — an away-click on
8595
+ * one of them stands no dismiss.
8348
8596
  */
8349
- function GridStateCard({ blockId, children, className }) {
8350
- return /* @__PURE__ */ jsx(Card, {
8351
- "data-slot": "docblocks/block",
8352
- "data-block-type": "database",
8353
- "data-block-id": blockId,
8354
- className: cn("min-h-0 flex-1", className),
8355
- children
8356
- });
8357
- }
8358
- function GridLoadingCard({ blockId }) {
8597
+ function AddColumnForm({ open, onOpenChange, form, formNumber, formRef, error, bridgeTables, OptionsEditor, onCommit, onNameChange, onDecimalsChange, onThousandsChange, onPrefixChange, onSuffixChange, onAllowNegativeChange, onEnumOptionsChange, onRefPickChange, onNewTableNameChange }) {
8359
8598
  const { t } = useTranslation("database");
8360
- return /* @__PURE__ */ jsx(GridStateCard, {
8361
- blockId,
8362
- children: /* @__PURE__ */ jsx(CardContent, {
8363
- "data-slot": "docblocks/database",
8364
- "data-state": "loading",
8365
- className: "p-(--docblocks-block-spacing)",
8599
+ return /* @__PURE__ */ jsxs(Popover, {
8600
+ open: open && form !== null,
8601
+ onOpenChange,
8602
+ children: [/* @__PURE__ */ jsx(PopoverTrigger, {
8603
+ asChild: true,
8366
8604
  children: /* @__PURE__ */ jsx("span", {
8367
- className: "text-(length:--docblocks-font-size) text-(--docblocks-placeholder-color)",
8368
- children: t("state.loading")
8369
- })
8370
- })
8371
- });
8372
- }
8373
- function GridBrokenCard({ blockId, tableId, error, onRetry }) {
8374
- const { t } = useTranslation("database");
8375
- return /* @__PURE__ */ jsx(GridStateCard, {
8376
- blockId,
8377
- className: "\n my-(--docblocks-block-spacing) rounded-(--docblocks-radius) border-(length:--docblocks-table-border-width)\n border-(--docblocks-table-border-color) outline-none\n ",
8378
- children: /* @__PURE__ */ jsxs(CardContent, {
8379
- "data-slot": "docblocks/database",
8380
- "data-state": "broken",
8381
- className: "flex items-center justify-between gap-(--docblocks-block-spacing) p-(--docblocks-block-spacing)",
8382
- children: [/* @__PURE__ */ jsxs("div", {
8383
- className: "flex flex-col",
8384
- children: [/* @__PURE__ */ jsx("span", {
8385
- "data-slot": "docblocks/database-broken",
8386
- className: "text-(length:--docblocks-font-size) font-(--docblocks-heading-font-weight)",
8387
- children: t("state.notFound")
8388
- }), /* @__PURE__ */ jsx("span", {
8389
- className: "text-(length:--docblocks-font-size) text-(--docblocks-placeholder-color)",
8390
- children: error ?? t("state.unknownTable", { tableId })
8391
- })]
8392
- }), /* @__PURE__ */ jsx(Button, {
8393
- "data-slot": "docblocks/database-retry",
8394
- variant: "outline",
8395
- size: "sm",
8396
- className: cn(GRID_CHROME_FRAME, GRID_BUTTON_HOVER, "h-auto px-2 py-1 text-(length:--docblocks-font-size) font-normal shadow-none"),
8397
- onClick: onRetry,
8398
- children: t("state.retry")
8399
- })]
8400
- })
8401
- });
8402
- }
8403
- //#endregion
8404
- //#region src/database/grid/AddColumnForm.tsx
8405
- /**
8406
- * The add-column's create form (the popover over the add-column track's
8407
- * anchor): the name input + the type-specific block (the number's display
8408
- * attributes / the enum's options' editor / the row-link's table pick +
8409
- * the new-table creation) + the create / save button. The commit stands
8410
- * the button's press only (the outside press / the Escape close without
8411
- * the commit — the draft's loss). The focus's stand: the menu's entry
8412
- * stands the form (the menu's close restores the focus to the plus
8413
- * trigger — the focus-outside would close the form the very tick it
8414
- * opens); the nested popovers' portals (the color's palette / the
8415
- * select's content) stand outside the form's content — an away-click on
8416
- * one of them stands no dismiss.
8417
- */
8418
- function AddColumnForm({ open, onOpenChange, form, formNumber, formRef, error, bridgeTables, OptionsEditor, onCommit, onNameChange, onDecimalsChange, onThousandsChange, onPrefixChange, onSuffixChange, onAllowNegativeChange, onEnumOptionsChange, onRefPickChange, onNewTableNameChange }) {
8419
- const { t } = useTranslation("database");
8420
- return /* @__PURE__ */ jsxs(Popover, {
8421
- open: open && form !== null,
8422
- onOpenChange,
8423
- children: [/* @__PURE__ */ jsx(PopoverTrigger, {
8424
- asChild: true,
8425
- children: /* @__PURE__ */ jsx("span", {
8426
- "data-slot": "docblocks/database-add-column-form-anchor",
8427
- className: "absolute size-0"
8605
+ "data-slot": "docblocks/database-add-column-form-anchor",
8606
+ className: "absolute size-0"
8428
8607
  })
8429
8608
  }), /* @__PURE__ */ jsx(PopoverContent, {
8430
8609
  align: "end",
@@ -8558,63 +8737,149 @@ function columnTypeIcon(type, refKind, refMany) {
8558
8737
  return Type;
8559
8738
  }
8560
8739
  //#endregion
8561
- //#region src/database/grid/AddColumnCell.tsx
8562
- /** The grid's header-row "add column" cell: the plus chip (the type's menu)
8563
- * and the create form over it. The cell carries its own explicit grid
8564
- * placement (the header row's track after the last column) — the header's
8565
- * resize strip occupies the same row across all tracks. The read-only
8566
- * modes render the empty track (the primitive's stand: no chip, no form). */
8567
- function AddColumnCell({ gridColumn, readOnly, form, OptionsEditor }) {
8740
+ //#region src/database/grid/AddColumnControl.tsx
8741
+ /** The add-column type menu and its create/edit form. */
8742
+ function AddColumnControl({ form, OptionsEditor, className, withLabel = false }) {
8743
+ const { t } = useTranslation("database");
8744
+ const openEntry = (entry) => () => form.openCreateForm(entry);
8745
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs(DropdownMenu, {
8746
+ modal: false,
8747
+ open: form.addingColumn,
8748
+ onOpenChange: form.setAddingColumn,
8749
+ children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
8750
+ asChild: true,
8751
+ children: /* @__PURE__ */ jsxs(Button, {
8752
+ "data-slot": "docblocks/database-add-column-trigger",
8753
+ variant: withLabel ? "outline" : "ghost",
8754
+ size: withLabel ? "sm" : "icon",
8755
+ "aria-label": t("form.addColumn"),
8756
+ className,
8757
+ children: [/* @__PURE__ */ jsx(Plus, { className: "size-4" }), withLabel ? t("form.addColumn") : null]
8758
+ })
8759
+ }), /* @__PURE__ */ jsx(DropdownMenuContent, {
8760
+ align: "end",
8761
+ className: "min-w-32",
8762
+ children: ADD_COLUMN_TYPES.map((entry) => {
8763
+ const EntryIcon = columnTypeIcon(entry.type, entry.refKind, entry.refMany);
8764
+ return /* @__PURE__ */ jsxs(DropdownMenuItem, {
8765
+ "data-column-entry": entry.key,
8766
+ onClick: openEntry(entry),
8767
+ children: [/* @__PURE__ */ jsx(EntryIcon, { className: "size-4 shrink-0 text-muted-foreground" }), t(entry.labelKey)]
8768
+ }, entry.key);
8769
+ })
8770
+ })]
8771
+ }), /* @__PURE__ */ jsx(AddColumnForm, {
8772
+ open: form.columnFormOpen,
8773
+ onOpenChange: form.onColumnFormOpenChange,
8774
+ form: form.columnForm,
8775
+ formNumber: form.columnFormNumber,
8776
+ formRef: form.columnFormRef,
8777
+ error: form.columnFormError,
8778
+ bridgeTables: form.bridgeTables,
8779
+ OptionsEditor,
8780
+ onCommit: form.commitColumnForm,
8781
+ onNameChange: form.onColumnNameChange,
8782
+ onDecimalsChange: form.onColumnDecimalsChange,
8783
+ onThousandsChange: form.onColumnThousandsChange,
8784
+ onPrefixChange: form.onColumnPrefixChange,
8785
+ onSuffixChange: form.onColumnSuffixChange,
8786
+ onAllowNegativeChange: form.onColumnAllowNegativeChange,
8787
+ onEnumOptionsChange: form.onColumnEnumOptionsChange,
8788
+ onRefPickChange: form.onColumnRefPickChange,
8789
+ onNewTableNameChange: form.onColumnNewTableNameChange
8790
+ })] });
8791
+ }
8792
+ //#endregion
8793
+ //#region src/database/grid/GridEmptyState.tsx
8794
+ /** The schema-less grid's empty state and its first-column entry. */
8795
+ function GridEmptyState({ form, OptionsEditor, readOnly }) {
8568
8796
  const { t } = useTranslation("database");
8569
8797
  return /* @__PURE__ */ jsxs("div", {
8798
+ "data-slot": "docblocks/database-empty",
8799
+ className: `relative flex min-h-28 flex-1 flex-col items-center justify-center gap-2 text-sm text-muted-foreground ${GRID_CHROME_FRAME}`,
8800
+ children: [/* @__PURE__ */ jsx("span", { children: t("columns.empty") }), !readOnly && /* @__PURE__ */ jsx(AddColumnControl, {
8801
+ form,
8802
+ OptionsEditor,
8803
+ withLabel: true,
8804
+ className: "cursor-pointer"
8805
+ })]
8806
+ });
8807
+ }
8808
+ //#endregion
8809
+ //#region src/database/grid/GridStateCards.tsx
8810
+ /**
8811
+ * The grid's non-ready state's surfaces: the loading's stand (the
8812
+ * placeholder's text) and the broken's stand (the table's death / the
8813
+ * fatal read's error surface + the reload's entry). The frames stand the
8814
+ * block's data attributes (the inspector's / the e2e's locators).
8815
+ */
8816
+ function GridStateCard({ blockId, children, className }) {
8817
+ return /* @__PURE__ */ jsx(Card, {
8818
+ "data-slot": "docblocks/block",
8819
+ "data-block-type": "database",
8820
+ "data-block-id": blockId,
8821
+ className: cn("min-h-0 flex-1", className),
8822
+ children
8823
+ });
8824
+ }
8825
+ function GridLoadingCard({ blockId }) {
8826
+ const { t } = useTranslation("database");
8827
+ return /* @__PURE__ */ jsx(GridStateCard, {
8828
+ blockId,
8829
+ children: /* @__PURE__ */ jsx(CardContent, {
8830
+ "data-slot": "docblocks/database",
8831
+ "data-state": "loading",
8832
+ className: "p-(--docblocks-block-spacing)",
8833
+ children: /* @__PURE__ */ jsx("span", {
8834
+ className: "text-(length:--docblocks-font-size) text-(--docblocks-placeholder-color)",
8835
+ children: t("state.loading")
8836
+ })
8837
+ })
8838
+ });
8839
+ }
8840
+ function GridBrokenCard({ blockId, tableId, error, onRetry }) {
8841
+ const { t } = useTranslation("database");
8842
+ return /* @__PURE__ */ jsx(GridStateCard, {
8843
+ blockId,
8844
+ className: "\n my-(--docblocks-block-spacing) rounded-(--docblocks-radius) border-(length:--docblocks-table-border-width)\n border-(--docblocks-table-border-color) outline-none\n ",
8845
+ children: /* @__PURE__ */ jsxs(CardContent, {
8846
+ "data-slot": "docblocks/database",
8847
+ "data-state": "broken",
8848
+ className: "flex items-center justify-between gap-(--docblocks-block-spacing) p-(--docblocks-block-spacing)",
8849
+ children: [/* @__PURE__ */ jsxs("div", {
8850
+ className: "flex flex-col",
8851
+ children: [/* @__PURE__ */ jsx("span", {
8852
+ "data-slot": "docblocks/database-broken",
8853
+ className: "text-(length:--docblocks-font-size) font-(--docblocks-heading-font-weight)",
8854
+ children: t("state.notFound")
8855
+ }), /* @__PURE__ */ jsx("span", {
8856
+ className: "text-(length:--docblocks-font-size) text-(--docblocks-placeholder-color)",
8857
+ children: error ?? t("state.unknownTable", { tableId })
8858
+ })]
8859
+ }), /* @__PURE__ */ jsx(Button, {
8860
+ "data-slot": "docblocks/database-retry",
8861
+ variant: "outline",
8862
+ size: "sm",
8863
+ className: cn(GRID_CHROME_FRAME, GRID_BUTTON_HOVER, "h-auto px-2 py-1 text-(length:--docblocks-font-size) font-normal shadow-none"),
8864
+ onClick: onRetry,
8865
+ children: t("state.retry")
8866
+ })]
8867
+ })
8868
+ });
8869
+ }
8870
+ //#endregion
8871
+ //#region src/database/grid/AddColumnCell.tsx
8872
+ /** The header-row cell hosting the add-column control and its form. */
8873
+ function AddColumnCell({ gridColumn, readOnly, form, OptionsEditor }) {
8874
+ return /* @__PURE__ */ jsx("div", {
8570
8875
  "data-slot": "docblocks/database-add-column",
8571
- className: "\n relative row-start-1 flex items-center justify-center border-b-(length:--docblocks-table-border-width)\n border-(--docblocks-table-border-color)\n ",
8876
+ className: "\n relative row-start-1 flex items-center justify-center rounded-tr-(--docblocks-radius)\n border-b-(length:--docblocks-table-border-width) border-(--docblocks-table-border-color)\n ",
8572
8877
  style: { gridColumn },
8573
- children: [!readOnly && /* @__PURE__ */ jsxs(DropdownMenu, {
8574
- modal: false,
8575
- open: form.addingColumn,
8576
- onOpenChange: form.setAddingColumn,
8577
- children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
8578
- asChild: true,
8579
- children: /* @__PURE__ */ jsx(Button, {
8580
- "data-slot": "docblocks/database-add-column-trigger",
8581
- variant: "ghost",
8582
- size: "icon",
8583
- className: cn("rounded-(--docblocks-radius) border-(length:--docblocks-table-border-width) border-(--docblocks-table-border-color) bg-transparent dark:border-(--docblocks-table-border-color) dark:bg-transparent", "size-6 cursor-pointer p-1 text-(--docblocks-placeholder-color) hover:bg-transparent", "hover:text-(--docblocks-text-color) dark:hover:bg-transparent"),
8584
- children: /* @__PURE__ */ jsx(Plus, { className: "size-4" })
8585
- })
8586
- }), /* @__PURE__ */ jsx(DropdownMenuContent, {
8587
- align: "end",
8588
- className: "min-w-32",
8589
- children: ADD_COLUMN_TYPES.map((entry) => {
8590
- const EntryIcon = columnTypeIcon(entry.type, entry.refKind, entry.refMany);
8591
- return /* @__PURE__ */ jsxs(DropdownMenuItem, {
8592
- "data-column-entry": entry.key,
8593
- onClick: () => form.openCreateForm(entry),
8594
- children: [/* @__PURE__ */ jsx(EntryIcon, { className: "size-4 shrink-0 text-muted-foreground" }), t(entry.labelKey)]
8595
- }, entry.key);
8596
- })
8597
- })]
8598
- }), /* @__PURE__ */ jsx(AddColumnForm, {
8599
- open: form.columnFormOpen,
8600
- onOpenChange: form.onColumnFormOpenChange,
8601
- form: form.columnForm,
8602
- formNumber: form.columnFormNumber,
8603
- formRef: form.columnFormRef,
8604
- error: form.columnFormError,
8605
- bridgeTables: form.bridgeTables,
8878
+ children: !readOnly && /* @__PURE__ */ jsx(AddColumnControl, {
8879
+ form,
8606
8880
  OptionsEditor,
8607
- onCommit: form.commitColumnForm,
8608
- onNameChange: form.onColumnNameChange,
8609
- onDecimalsChange: form.onColumnDecimalsChange,
8610
- onThousandsChange: form.onColumnThousandsChange,
8611
- onPrefixChange: form.onColumnPrefixChange,
8612
- onSuffixChange: form.onColumnSuffixChange,
8613
- onAllowNegativeChange: form.onColumnAllowNegativeChange,
8614
- onEnumOptionsChange: form.onColumnEnumOptionsChange,
8615
- onRefPickChange: form.onColumnRefPickChange,
8616
- onNewTableNameChange: form.onColumnNewTableNameChange
8617
- })]
8881
+ className: cn("rounded-(--docblocks-radius) border-(length:--docblocks-table-border-width) border-(--docblocks-table-border-color) bg-transparent dark:border-(--docblocks-table-border-color) dark:bg-transparent", "size-6 cursor-pointer p-1 text-(--docblocks-placeholder-color) hover:bg-transparent", "hover:text-(--docblocks-text-color) dark:hover:bg-transparent")
8882
+ })
8618
8883
  });
8619
8884
  }
8620
8885
  //#endregion
@@ -9467,7 +9732,7 @@ function useCellEditSession({ editing, isText, isNumber, isDateTime, rawValue, r
9467
9732
  * placeholder, no trigger chrome): the pickers open on the double press
9468
9733
  * over the cell itself.
9469
9734
  */
9470
- function DatabaseCell({ rowId, column, value, revision, rowIndex, colIndex, first, lastRow, filterPending, dragDx, dragShifted, selected, singleSelected, editing, onChange, onPointerDown, onEditStart, onEditEnd, booleanPress, refTableData }) {
9735
+ function DatabaseCell({ rowId, column, value, revision, rowIndex, colIndex, first, lastRow, filterPending, dragDx, dragShifted, selected, pasteHighlighted, singleSelected, editing, onChange, onPointerDown, onEditStart, onEditEnd, booleanPress, refTableData }) {
9471
9736
  const annotation = columnAnnotation(column);
9472
9737
  const empty = value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
9473
9738
  const isDate = annotation.valueInput === "date";
@@ -9546,7 +9811,7 @@ function DatabaseCell({ rowId, column, value, revision, rowIndex, colIndex, firs
9546
9811
  }
9547
9812
  onEditStart();
9548
9813
  };
9549
- const cell = /* @__PURE__ */ jsx("div", {
9814
+ const cell = /* @__PURE__ */ jsxs("div", {
9550
9815
  "data-slot": "docblocks/database-cell",
9551
9816
  "data-key": cellKeyOf(rowId, column.id),
9552
9817
  "data-row-id": rowId,
@@ -9558,12 +9823,16 @@ function DatabaseCell({ rowId, column, value, revision, rowIndex, colIndex, firs
9558
9823
  "data-empty": empty ? "true" : void 0,
9559
9824
  "data-selected": selected ? "true" : void 0,
9560
9825
  "data-editing": editing ? "true" : void 0,
9561
- className: cn(CELL_WRAP, !first && "border-l-(length:--docblocks-table-border-width)", !lastRow && "border-b-(length:--docblocks-table-border-width)", selected && (singleSelected ? "bg-(--docblocks-selected-background) outline-(length:--docblocks-canvas-selection-border-width) outline-offset-[-1px] outline-(--docblocks-canvas-selection-border-color) outline-solid" : "bg-(--docblocks-canvas-selection-fill)")),
9826
+ className: cn(CELL_WRAP, pasteHighlighted && "relative", !first && "border-l-(length:--docblocks-table-border-width)", !lastRow && "border-b-(length:--docblocks-table-border-width)", first && lastRow && "rounded-bl-(--docblocks-radius)", selected && (singleSelected ? "bg-(--docblocks-selected-background) outline-(length:--docblocks-canvas-selection-border-width) outline-offset-[-1px] outline-(--docblocks-canvas-selection-border-color) outline-solid" : "bg-(--docblocks-canvas-selection-fill)")),
9562
9827
  style: dragStyle,
9563
9828
  onPointerDown,
9564
9829
  onClick: onCellClick,
9565
9830
  onDoubleClick: onCellDoubleClick,
9566
- children: content
9831
+ children: [content, pasteHighlighted && /* @__PURE__ */ jsx("span", {
9832
+ "aria-hidden": true,
9833
+ "data-slot": "docblocks/database-paste-range",
9834
+ className: "pointer-events-none absolute inset-0 outline-(length:--docblocks-database-paste-range-border-width) outline-offset-[-1px] outline-(--docblocks-database-paste-range-border-color) outline-solid"
9835
+ })]
9567
9836
  });
9568
9837
  if (isText) return /* @__PURE__ */ jsx(DatabaseCellText, {
9569
9838
  cell,
@@ -9593,7 +9862,7 @@ function RowMenuCell({ row, rowMenu, setRowMenu, canMoveUp, canMoveDown, onMoveU
9593
9862
  className: cn(`
9594
9863
  flex w-10 items-center justify-center border-l-(length:--docblocks-table-border-width)
9595
9864
  border-(--docblocks-table-border-color)
9596
- `, !lastRow && "border-b-(length:--docblocks-table-border-width)"),
9865
+ `, !lastRow && "border-b-(length:--docblocks-table-border-width)", lastRow && "rounded-br-(--docblocks-radius)"),
9597
9866
  children: /* @__PURE__ */ jsxs(DropdownMenu, {
9598
9867
  modal: false,
9599
9868
  open: rowMenu === row.rowId,
@@ -9642,7 +9911,7 @@ function RowMenuCell({ row, rowMenu, setRowMenu, canMoveUp, canMoveDown, onMoveU
9642
9911
  * the rejection's no-rethrow (the cell's commit has no caller to handle
9643
9912
  * it).
9644
9913
  */
9645
- function GridRows({ rows, columns, data, selectedCells, editingCell, setEditingCell, onCellPointerDown, booleanPressRef, drag, dragShiftOf, pendingRowId, refTableData, filter, readOnly = false }) {
9914
+ function GridRows({ rows, columns, data, selectedCells, pasteRange, editingCell, setEditingCell, onCellPointerDown, booleanPressRef, drag, dragShiftOf, pendingRowId, refTableData, filter, readOnly = false }) {
9646
9915
  const { t } = useTranslation("database");
9647
9916
  const [rowMenu, setRowMenu] = useState(null);
9648
9917
  const lastRowId = rows.length > 0 ? rows[rows.length - 1].rowId : null;
@@ -9680,6 +9949,7 @@ function GridRows({ rows, columns, data, selectedCells, editingCell, setEditingC
9680
9949
  dragDx: drag !== null && drag.id === column.id ? drag.dx : dragShiftOf(index),
9681
9950
  dragShifted: drag !== null && drag.id !== column.id,
9682
9951
  selected: selectedCells.has(key),
9952
+ pasteHighlighted: pasteRange.has(key),
9683
9953
  singleSelected: selectedCells.has(key) && selectedCells.size === 1,
9684
9954
  editing: editingCell === key,
9685
9955
  onChange: cellChange(row, column),
@@ -9698,7 +9968,7 @@ function GridRows({ rows, columns, data, selectedCells, editingCell, setEditingC
9698
9968
  className: cn(`
9699
9969
  flex w-10 items-center justify-center border-l-(length:--docblocks-table-border-width)
9700
9970
  border-(--docblocks-table-border-color)
9701
- `, row.rowId !== lastRowId && "border-b-(length:--docblocks-table-border-width)")
9971
+ `, row.rowId !== lastRowId && "border-b-(length:--docblocks-table-border-width)", row.rowId === lastRowId && "rounded-br-(--docblocks-radius)")
9702
9972
  }) : /* @__PURE__ */ jsx(RowMenuCell, {
9703
9973
  row,
9704
9974
  rowMenu,
@@ -9739,11 +10009,16 @@ function GridRows({ rows, columns, data, selectedCells, editingCell, setEditingC
9739
10009
  * drag, the Ellipsis's press stands the menu). The right-edge seam resizes
9740
10010
  * the column (the table block's seam idiom: the 6 px strip, the 50 px
9741
10011
  * floor, the live preview, the one `updateBlock` on the release). The menu
9742
- * content: the editable name line (the rename commits on the blur / the
9743
- * Enter), the type line (read-only), and the show / hide / delete items. */
9744
- function HeaderCell({ readOnly = false, column, colIndex, first, resizing, dragDx, dragShifted, menuOpen, onMenuChange, onRename, onEditOptions, onHide, onShow, onDelete, hidden, onPointerDown, onPointerMove, onPointerUp, onResizePointerDown, onResizePointerMove, onResizePointerUp, onResizePointerCancel }) {
10012
+ * content: the rename's line (the `InlineEditInput`'s contract — the
10013
+ * mount's focus + the select-all over the rename's replace, the reseed
10014
+ * over an open edit (a pristine field stands the live column's name — a
10015
+ * peer's rename, the own commit's settle — a typed draft stands until the
10016
+ * next open), the commit over the Enter / the blur (one write — the
10017
+ * committed-once's guard), the Escape's cancel without a write; the
10018
+ * empty / the unchanged's trimmed stand the no-write), the type line
10019
+ * (read-only), and the show / hide / delete items. */
10020
+ function HeaderCell({ readOnly = false, onDoubleClickReset, column, colIndex, first, resizing, dragDx, dragShifted, menuOpen, onMenuChange, onRename, onEditOptions, onHide, onShow, onDelete, hidden, onPointerDown, onPointerMove, onPointerUp, onResizePointerDown, onResizePointerMove, onResizePointerUp, onResizePointerCancel }) {
9745
10021
  const { t } = useTranslation("database");
9746
- const [nameDraft, setNameDraft] = useState(column.name);
9747
10022
  const ColumnIcon = columnTypeIcon(column.type, column.refKind, column.refMany);
9748
10023
  const dragStyle = dragDx !== 0 ? {
9749
10024
  transform: `translateX(${dragDx}px)`,
@@ -9751,19 +10026,13 @@ function HeaderCell({ readOnly = false, column, colIndex, first, resizing, dragD
9751
10026
  zIndex: dragShifted ? void 0 : 10,
9752
10027
  transition: dragShifted ? GRID_DRAG_TRANSITION : void 0
9753
10028
  } : null;
9754
- const commitRename = () => {
9755
- const trimmed = nameDraft.trim();
9756
- if (trimmed !== "" && trimmed !== column.name) onRename(trimmed);
9757
- setNameDraft(column.name);
10029
+ const commitRename = (value) => {
10030
+ const trimmed = value.trim();
10031
+ if (trimmed === "" || trimmed === column.name) return;
10032
+ onRename(trimmed);
9758
10033
  };
9759
- const onNameChange = (event) => setNameDraft(event.target.value);
9760
- const focusName = () => setNameDraft(column.name);
9761
- const onNameKeyDown = (event) => {
9762
- if (event.key === "Enter") event.target.blur();
9763
- if (event.key === "Escape") {
9764
- setNameDraft(column.name);
9765
- onMenuChange(false);
9766
- }
10034
+ const stopDoubleClick = (event) => {
10035
+ event.stopPropagation();
9767
10036
  };
9768
10037
  const onEditOptionsPress = () => {
9769
10038
  if (onEditOptions === void 0) return;
@@ -9785,18 +10054,24 @@ function HeaderCell({ readOnly = false, column, colIndex, first, resizing, dragD
9785
10054
  className: cn(`
9786
10055
  relative flex min-w-0 items-center gap-1 border-b-(length:--docblocks-table-border-width)
9787
10056
  border-(--docblocks-table-border-color) bg-muted/40 px-2 py-1 select-none
9788
- `, !readOnly && "cursor-grab active:cursor-grabbing", !first && "border-l-(length:--docblocks-table-border-width)"),
10057
+ `, !readOnly && "cursor-grab active:cursor-grabbing", first && "rounded-tl-(--docblocks-radius)", !first && "border-l-(length:--docblocks-table-border-width)"),
9789
10058
  onPointerDown: readOnly ? void 0 : onPointerDown,
9790
10059
  onPointerMove: readOnly ? void 0 : onPointerMove,
9791
10060
  onPointerUp: readOnly ? void 0 : onPointerUp,
10061
+ onDoubleClick: onDoubleClickReset,
9792
10062
  children: [
9793
10063
  /* @__PURE__ */ jsx(ColumnIcon, { className: "size-4 shrink-0 text-muted-foreground" }),
9794
10064
  /* @__PURE__ */ jsx("span", {
9795
- className: "\n min-w-0 flex-1 truncate px-1 text-(length:--docblocks-font-size) font-(--docblocks-heading-font-weight)\n ",
10065
+ "data-slot": "docblocks/database-header-name",
10066
+ className: `
10067
+ max-h-full min-w-0 flex-1 overflow-hidden px-1 text-(length:--docblocks-font-size)
10068
+ font-(--docblocks-heading-font-weight)
10069
+ `,
9796
10070
  children: column.name
9797
10071
  }),
9798
10072
  !readOnly && /* @__PURE__ */ jsx("div", {
9799
10073
  className: "ml-auto flex shrink-0 items-center",
10074
+ onDoubleClick: stopDoubleClick,
9800
10075
  children: /* @__PURE__ */ jsxs(DropdownMenu, {
9801
10076
  modal: false,
9802
10077
  open: menuOpen,
@@ -9817,15 +10092,15 @@ function HeaderCell({ readOnly = false, column, colIndex, first, resizing, dragD
9817
10092
  children: [
9818
10093
  /* @__PURE__ */ jsxs("div", {
9819
10094
  className: "flex flex-col gap-1",
9820
- children: [/* @__PURE__ */ jsx(Input, {
10095
+ children: [/* @__PURE__ */ jsx(InlineEditInput, {
9821
10096
  size: "sm",
9822
- "data-slot": "docblocks/database-rename-input",
10097
+ initial: column.name,
10098
+ selectOnMount: true,
10099
+ ariaLabel: t("rename.aria", { name: column.name }),
10100
+ slot: "docblocks/database-rename-input",
9823
10101
  className: "border-0 bg-muted/60 px-2 py-1 text-foreground select-text focus:bg-muted",
9824
- value: nameDraft,
9825
- onChange: onNameChange,
9826
- onFocus: focusName,
9827
- onBlur: commitRename,
9828
- onKeyDown: onNameKeyDown
10102
+ onCommit: commitRename,
10103
+ onCancel: () => onMenuChange(false)
9829
10104
  }), /* @__PURE__ */ jsxs("span", {
9830
10105
  "data-slot": "docblocks/database-column-type",
9831
10106
  className: "flex items-center gap-1 px-1.5 text-xs text-muted-foreground",
@@ -9854,6 +10129,7 @@ function HeaderCell({ readOnly = false, column, colIndex, first, resizing, dragD
9854
10129
  !readOnly && /* @__PURE__ */ jsx("div", {
9855
10130
  "data-slot": "docblocks/database-col-resize",
9856
10131
  "data-index": colIndex,
10132
+ onDoubleClick: stopDoubleClick,
9857
10133
  className: cn(`
9858
10134
  absolute top-0 -right-0.75 z-10 h-full w-1.5 cursor-col-resize opacity-0 transition-opacity
9859
10135
  hover:opacity-100
@@ -9879,8 +10155,10 @@ function HeaderCell({ readOnly = false, column, colIndex, first, resizing, dragD
9879
10155
  * the read-only modes render no handle (the height itself still
9880
10156
  * applies). */
9881
10157
  /** The header's bottom edge: the 6 px strip straddles the border (the
9882
- * seam idiom — the pointer over the edge stands the stable row-resize). */
9883
- function HeaderResizeHandle({ resizing, onPointerDown, onPointerMove, onPointerUp, onPointerCancel }) {
10158
+ * seam idiom — the pointer over the edge stands the stable row-resize).
10159
+ * The double click over the strip stands the height's reset (the default
10160
+ * height's return — the press's no-op's parity over the drag's release). */
10161
+ function HeaderResizeHandle({ resizing, onDoubleClickReset, onPointerDown, onPointerMove, onPointerUp, onPointerCancel }) {
9884
10162
  const { t } = useTranslation("database");
9885
10163
  return /* @__PURE__ */ jsx("div", {
9886
10164
  role: "separator",
@@ -9896,6 +10174,7 @@ function HeaderResizeHandle({ resizing, onPointerDown, onPointerMove, onPointerU
9896
10174
  onPointerMove,
9897
10175
  onPointerUp,
9898
10176
  onPointerCancel,
10177
+ onDoubleClick: onDoubleClickReset,
9899
10178
  children: /* @__PURE__ */ jsx("div", {
9900
10179
  "data-slot": "docblocks/database-header-resize-line",
9901
10180
  className: "h-0.5 w-full rounded bg-(--muted-foreground)"
@@ -10014,10 +10293,13 @@ function clampDatabaseHeaderHeight(requested, natural) {
10014
10293
  function measureDatabaseHeaderHeight(grid) {
10015
10294
  if (grid === null) return 0;
10016
10295
  const previous = grid.style.gridTemplateRows;
10296
+ const wrapped = grid.hasAttribute(DATABASE_HEADER_WRAP_ATTR);
10297
+ grid.removeAttribute(DATABASE_HEADER_WRAP_ATTR);
10017
10298
  grid.style.gridTemplateRows = "auto";
10018
10299
  let natural = 0;
10019
10300
  for (const cell of grid.querySelectorAll("[data-slot=\"docblocks/database-header-cell\"]")) natural = Math.max(natural, cell.offsetHeight);
10020
10301
  grid.style.gridTemplateRows = previous;
10302
+ if (wrapped) grid.setAttribute(DATABASE_HEADER_WRAP_ATTR, "true");
10021
10303
  return natural;
10022
10304
  }
10023
10305
  //#endregion
@@ -10172,6 +10454,35 @@ function useGridSeamResize({ columns, columnWidths, updateView }) {
10172
10454
  };
10173
10455
  }
10174
10456
  //#endregion
10457
+ //#region src/database/grid/use-single-line-header-height.ts
10458
+ /** The grid's header row's single-line (auto) height, tracked live over
10459
+ * the laid-out grid. The stand is the stretch's decision's threshold (the
10460
+ * names' wrap over the height's stand) and the drag's clamp's floor's
10461
+ * source (the one-line fallback over the unmeasured's stand). The read
10462
+ * stands the single-line's stand over the current's wrap (the
10463
+ * measurement's suppression's parity), so the value is the auto height
10464
+ * regardless of the stretch. A detached / unlaid-out grid (no layout in
10465
+ * the runtime) stands 0. */
10466
+ /** The grid's header row's single-line (auto) height in px (the live
10467
+ * stand over the column's widths / the theme's font's changes). */
10468
+ function useSingleLineHeaderHeight(tableRef) {
10469
+ const [height, setHeight] = useState(0);
10470
+ useLayoutEffect(() => {
10471
+ const grid = tableRef.current;
10472
+ if (grid === null) return;
10473
+ const measure = () => {
10474
+ const next = measureDatabaseHeaderHeight(grid);
10475
+ setHeight((current) => current === next ? current : next);
10476
+ };
10477
+ measure();
10478
+ if (typeof ResizeObserver === "undefined") return;
10479
+ const observer = new ResizeObserver(measure);
10480
+ observer.observe(grid);
10481
+ return () => observer.disconnect();
10482
+ }, [tableRef]);
10483
+ return height;
10484
+ }
10485
+ //#endregion
10175
10486
  //#region src/database/grid/GridTable.tsx
10176
10487
  /**
10177
10488
  * The grid's table: the column tracks (the header cells — the menu / the
@@ -10181,7 +10492,7 @@ function useGridSeamResize({ columns, columnWidths, updateView }) {
10181
10492
  * model (the cell / column selection — the native text selection over the
10182
10493
  * drag is suppressed).
10183
10494
  */
10184
- function GridTable({ columns, allColumns, columnOrder, hiddenColumns, columnWidths, onViewChange, data, rows, selectedCells, editingCell, setEditingCell, onCellPointerDown, booleanPressRef, pendingRowId, refTableData, filter, readOnly = false, headerHeight, onHeaderHeightChange, tableRef, onTableKeyDown, onTablePaste, onTableBlur, form, OptionsEditor }) {
10495
+ function GridTable({ columns, allColumns, columnOrder, hiddenColumns, columnWidths, onViewChange, data, rows, selectedCells, pasteRange, editingCell, setEditingCell, onCellPointerDown, booleanPressRef, pendingRowId, refTableData, filter, readOnly = false, headerHeight, onHeaderHeightChange, onHeaderHeightReset, tableRef, onTableKeyDown, onTablePaste, onTableContextMenu, onTableBlur, form, OptionsEditor }) {
10185
10496
  const [columnMenu, setColumnMenu] = useState(null);
10186
10497
  const { resizePreview, onSeamPointerDown, onSeamPointerMove, onSeamPointerUp, onSeamPointerCancel } = useGridSeamResize({
10187
10498
  columns,
@@ -10203,6 +10514,11 @@ function GridTable({ columns, allColumns, columnOrder, hiddenColumns, columnWidt
10203
10514
  onCommit: onHeaderHeightChange ?? (() => void 0)
10204
10515
  });
10205
10516
  const headerRowHeight = headerPreview ?? headerHeight;
10517
+ const naturalHeaderHeight = useSingleLineHeaderHeight(tableRef);
10518
+ const headerWrap = headerRowHeight !== void 0 && headerRowHeight > naturalHeaderHeight;
10519
+ const resetHeaderHeight = () => {
10520
+ onHeaderHeightReset?.();
10521
+ };
10206
10522
  const dragFrom = drag === null ? -1 : columns.findIndex((entry) => entry.id === drag.id);
10207
10523
  const dragShiftOf = (index) => {
10208
10524
  if (drag === null || drag.toIndex === null || index === dragFrom) return 0;
@@ -10230,10 +10546,12 @@ function GridTable({ columns, allColumns, columnOrder, hiddenColumns, columnWidt
10230
10546
  return /* @__PURE__ */ jsxs("div", {
10231
10547
  ref: tableRef,
10232
10548
  "data-slot": "docblocks/database-table",
10549
+ "data-header-wrap": headerWrap ? "true" : void 0,
10233
10550
  tabIndex: 0,
10234
- className: "grid w-full outline-none select-none",
10551
+ className: cn(GRID_CHROME_FRAME, "grid w-full overflow-hidden outline-none select-none"),
10235
10552
  onKeyDown: onTableKeyDown,
10236
10553
  onPaste: onTablePaste,
10554
+ onContextMenu: onTableContextMenu,
10237
10555
  onBlur: onTableBlur,
10238
10556
  style: {
10239
10557
  gridTemplateRows: headerRowHeight !== void 0 ? `${headerRowHeight}px` : "auto",
@@ -10253,6 +10571,7 @@ function GridTable({ columns, allColumns, columnOrder, hiddenColumns, columnWidt
10253
10571
  dragDx: drag !== null && drag.id === column.id ? drag.dx : dragShiftOf(index),
10254
10572
  dragShifted: drag !== null && drag.id !== column.id,
10255
10573
  menuOpen: columnMenu === column.id,
10574
+ onDoubleClickReset: !readOnly && onHeaderHeightReset !== void 0 ? resetHeaderHeight : void 0,
10256
10575
  onMenuChange: readOnly ? () => void 0 : columnMenuChange(column),
10257
10576
  onRename: columnRename(column),
10258
10577
  onEditOptions: columnEditOptions(column),
@@ -10270,6 +10589,7 @@ function GridTable({ columns, allColumns, columnOrder, hiddenColumns, columnWidt
10270
10589
  }, column.id)),
10271
10590
  !readOnly && onHeaderHeightChange !== void 0 && /* @__PURE__ */ jsx(HeaderResizeHandle, {
10272
10591
  resizing: headerPreview !== null,
10592
+ onDoubleClickReset: !readOnly && onHeaderHeightReset !== void 0 ? resetHeaderHeight : void 0,
10273
10593
  onPointerDown: onHeaderPointerDown,
10274
10594
  onPointerMove: onHeaderPointerMove,
10275
10595
  onPointerUp: onHeaderPointerUp,
@@ -10286,6 +10606,7 @@ function GridTable({ columns, allColumns, columnOrder, hiddenColumns, columnWidt
10286
10606
  columns,
10287
10607
  data,
10288
10608
  selectedCells,
10609
+ pasteRange,
10289
10610
  editingCell,
10290
10611
  setEditingCell,
10291
10612
  onCellPointerDown,
@@ -10302,7 +10623,7 @@ function GridTable({ columns, allColumns, columnOrder, hiddenColumns, columnWidt
10302
10623
  }
10303
10624
  //#endregion
10304
10625
  //#region src/database/grid/ColumnManager.tsx
10305
- function ColumnRow({ column, hidden, hideDisabled, onToggle, onMove, onDragStart, onDragEnd }) {
10626
+ function ColumnRow({ column, hidden, hideDisabled, onToggle, onMove, onDragEnd }) {
10306
10627
  const { t } = useTranslation("database");
10307
10628
  const dragControls = useDragControls();
10308
10629
  const onGripPointerDown = (event) => {
@@ -10316,13 +10637,12 @@ function ColumnRow({ column, hidden, hideDisabled, onToggle, onMove, onDragStart
10316
10637
  onMove(column.id, event.key === "ArrowUp" ? -1 : 1);
10317
10638
  };
10318
10639
  const onVisibilityChange = () => onToggle(column.id);
10319
- const onReorderEnd = () => onDragEnd(column.id);
10640
+ const onReorderEnd = (event) => onDragEnd(column.id, event);
10320
10641
  return /* @__PURE__ */ jsxs(Reorder.Item, {
10321
10642
  as: "div",
10322
10643
  value: column.id,
10323
10644
  dragListener: false,
10324
10645
  dragControls,
10325
- onDragStart,
10326
10646
  onDragEnd: onReorderEnd,
10327
10647
  className: "flex items-center gap-1 rounded-sm px-1 py-0.5 text-sm",
10328
10648
  children: [
@@ -10357,7 +10677,7 @@ function ColumnManager({ columns, columnOrder, hiddenColumns, columnWidths, trig
10357
10677
  const { t } = useTranslation("database");
10358
10678
  const [open, setOpen] = useState(false);
10359
10679
  const [draftOrder, setDraftOrder] = useState(null);
10360
- const dragStartOrderRef = useRef(null);
10680
+ const groupRef = useRef(null);
10361
10681
  const normalizedOrder = normalizeColumnOrder(columns, columnOrder);
10362
10682
  const order = draftOrder ?? normalizedOrder;
10363
10683
  const hidden = new Set(hiddenColumns ?? []);
@@ -10379,13 +10699,46 @@ function ColumnManager({ columns, columnOrder, hiddenColumns, columnWidths, trig
10379
10699
  });
10380
10700
  setDraftOrder(nextOrder);
10381
10701
  };
10382
- const onDragStart = () => {
10383
- dragStartOrderRef.current = order;
10702
+ const commitAtPointer = (columnId, clientY) => {
10703
+ const group = groupRef.current;
10704
+ if (group === null) return;
10705
+ const rows = Array.from(group.children).filter((row) => row instanceof HTMLElement);
10706
+ const displayed = rows.map((row) => row.querySelector("[data-slot='docblocks/database-column-move']")?.getAttribute("data-column-id")).filter((id) => id !== null);
10707
+ if (displayed.length === 0 || displayed.includes(columnId) === false) return;
10708
+ const previousOrder = normalizedOrder;
10709
+ const others = displayed.filter((id) => id !== columnId);
10710
+ let insertAt = 0;
10711
+ for (const row of rows) {
10712
+ const id = row.querySelector("[data-slot='docblocks/database-column-move']")?.getAttribute("data-column-id");
10713
+ if (id === null || id === columnId) continue;
10714
+ const rect = row.getBoundingClientRect();
10715
+ if (clientY > rect.top + rect.height / 2) insertAt += 1;
10716
+ }
10717
+ const newVisible = [
10718
+ ...others.slice(0, insertAt),
10719
+ columnId,
10720
+ ...others.slice(insertAt)
10721
+ ];
10722
+ const visibleIds = new Set(newVisible);
10723
+ const visibleSlots = normalizedOrder.map((id, index) => visibleIds.has(id) ? index : -1).filter((index) => index >= 0);
10724
+ const nextOrder = [...normalizedOrder];
10725
+ newVisible.forEach((id, slot) => {
10726
+ const target = visibleSlots[slot];
10727
+ if (target !== void 0) nextOrder[target] = id;
10728
+ });
10729
+ if (nextOrder.every((id, index) => id === previousOrder[index])) {
10730
+ setDraftOrder(null);
10731
+ return;
10732
+ }
10733
+ commitOrder(columnId, nextOrder, previousOrder);
10384
10734
  };
10385
- const onDragEnd = (columnId) => {
10386
- const previousOrder = dragStartOrderRef.current ?? order;
10387
- dragStartOrderRef.current = null;
10388
- if (draftOrder !== null) commitOrder(columnId, draftOrder, previousOrder);
10735
+ const onDragEnd = (columnId, event) => {
10736
+ const pointerY = pointerYOf$1(event);
10737
+ if (pointerY === null) {
10738
+ setDraftOrder(null);
10739
+ return;
10740
+ }
10741
+ commitAtPointer(columnId, pointerY);
10389
10742
  };
10390
10743
  const onMove = (columnId, delta) => {
10391
10744
  const fromIndex = order.indexOf(columnId);
@@ -10408,6 +10761,8 @@ function ColumnManager({ columns, columnOrder, hiddenColumns, columnWidths, trig
10408
10761
  variant: "outline",
10409
10762
  size: "sm",
10410
10763
  "data-active": hiddenCount > 0 ? "true" : void 0,
10764
+ "data-disabled": columns.length === 0 ? true : void 0,
10765
+ disabled: columns.length === 0,
10411
10766
  className: triggerClassName,
10412
10767
  children: [t("toolbar.columns"), hiddenCount > 0 ? " •" : ""]
10413
10768
  })
@@ -10418,6 +10773,7 @@ function ColumnManager({ columns, columnOrder, hiddenColumns, columnWidths, trig
10418
10773
  className: "w-72 p-2",
10419
10774
  children: /* @__PURE__ */ jsx(Reorder.Group, {
10420
10775
  as: "div",
10776
+ ref: groupRef,
10421
10777
  axis: "y",
10422
10778
  values: order,
10423
10779
  onReorder: setDraftOrder,
@@ -10431,7 +10787,6 @@ function ColumnManager({ columns, columnOrder, hiddenColumns, columnWidths, trig
10431
10787
  hideDisabled: !hidden.has(column.id) && visibleCount === 1,
10432
10788
  onToggle,
10433
10789
  onMove,
10434
- onDragStart,
10435
10790
  onDragEnd
10436
10791
  }, column.id);
10437
10792
  })
@@ -10440,6 +10795,54 @@ function ColumnManager({ columns, columnOrder, hiddenColumns, columnWidths, trig
10440
10795
  });
10441
10796
  }
10442
10797
  //#endregion
10798
+ //#region src/database/grid/GridHistoryButtons.tsx
10799
+ /** The bridge history's icon controls. */
10800
+ function GridHistoryButtons({ canUndo, canRedo, onUndo, onRedo }) {
10801
+ const { t } = useTranslation("database");
10802
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Button, {
10803
+ "data-slot": "docblocks/database-undo",
10804
+ variant: "outline",
10805
+ size: "icon",
10806
+ className: "size-8",
10807
+ "data-disabled": canUndo ? void 0 : true,
10808
+ disabled: !canUndo,
10809
+ title: t("toolbar.undo"),
10810
+ "aria-label": t("toolbar.undo"),
10811
+ onClick: onUndo,
10812
+ children: /* @__PURE__ */ jsx(Undo, {})
10813
+ }), /* @__PURE__ */ jsx(Button, {
10814
+ "data-slot": "docblocks/database-redo",
10815
+ variant: "outline",
10816
+ size: "icon",
10817
+ className: "size-8",
10818
+ "data-disabled": canRedo ? void 0 : true,
10819
+ disabled: !canRedo,
10820
+ title: t("toolbar.redo"),
10821
+ "aria-label": t("toolbar.redo"),
10822
+ onClick: onRedo,
10823
+ children: /* @__PURE__ */ jsx(Redo, {})
10824
+ })] });
10825
+ }
10826
+ //#endregion
10827
+ //#region src/database/grid/GridRowCount.tsx
10828
+ /** The consumer's total row count and the loaded filtered-window count. */
10829
+ function GridRowCount({ total, visible, filtered }) {
10830
+ const { t } = useTranslation("database");
10831
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs(Badge, {
10832
+ "data-slot": "docblocks/database-count",
10833
+ variant: "secondary",
10834
+ children: [
10835
+ total,
10836
+ " ",
10837
+ t("rowCount", { count: total })
10838
+ ]
10839
+ }), filtered && /* @__PURE__ */ jsx(Badge, {
10840
+ "data-slot": "docblocks/database-visible-count",
10841
+ variant: "outline",
10842
+ children: t("visibleRowCount", { count: visible })
10843
+ })] });
10844
+ }
10845
+ //#endregion
10443
10846
  //#region src/database/grid/GridToolbar.tsx
10444
10847
  /**
10445
10848
  * The grid's toolbar: the table's display name (the bridge's table name —
@@ -10450,25 +10853,20 @@ function ColumnManager({ columns, columnOrder, hiddenColumns, columnWidths, trig
10450
10853
  * column manager, and the filter popover (the draft stands the apply's
10451
10854
  * press — the close stands no write).
10452
10855
  */
10453
- function GridToolbar({ tableId, table, data, filter, columnOrder, hiddenColumns, columnWidths, onViewChange, refTableData, showName, readOnly = false }) {
10856
+ function GridToolbar({ tableId, table, data, totalRows, filter, columnOrder, hiddenColumns, columnWidths, onViewChange, refTableData, showName, readOnly = false }) {
10454
10857
  const { t } = useTranslation("database");
10455
- const [nameDraft, setNameDraft] = useState(null);
10858
+ const [nameEditing, setNameEditing] = useState(false);
10456
10859
  const [filterOpen, setFilterOpen] = useState(false);
10457
10860
  const [filterDraft, setFilterDraft] = useState(filter ?? null);
10458
10861
  const displayName = data.table?.name ?? tableId;
10862
+ const resolvedRowCount = totalRows ?? data.rows.length;
10863
+ const hasActiveFilter = filter !== void 0 && filter.conditions.length > 0;
10459
10864
  const commitName = (draft) => {
10460
- setNameDraft(null);
10865
+ setNameEditing(false);
10461
10866
  const trimmed = draft.trim();
10462
10867
  if (trimmed === "" || trimmed === data.table?.name) return;
10463
10868
  data.renameTable(trimmed).catch(() => void 0);
10464
10869
  };
10465
- const onNameChange = (event) => setNameDraft(event.target.value);
10466
- const onNameBlur = (event) => commitName(event.target.value);
10467
- const onNameKeyDown = (event) => {
10468
- if (event.key === "Enter") event.target.blur();
10469
- if (event.key === "Escape") setNameDraft(null);
10470
- };
10471
- const beginNameEdit = () => setNameDraft(displayName);
10472
10870
  const undoStep = () => void data.undo().catch(() => void 0);
10473
10871
  const redoStep = () => void data.redo().catch(() => void 0);
10474
10872
  const applyFilter = () => {
@@ -10480,19 +10878,20 @@ function GridToolbar({ tableId, table, data, filter, columnOrder, hiddenColumns,
10480
10878
  if (open) setFilterDraft(filter ?? null);
10481
10879
  };
10482
10880
  const resetFilterDraft = () => setFilterDraft(emptyFilter());
10881
+ const insertEmptyRow = () => void data.insertRow({}).catch(() => void 0);
10483
10882
  return /* @__PURE__ */ jsxs("div", {
10484
10883
  "data-slot": "docblocks/database-toolbar",
10485
10884
  className: "flex flex-wrap items-center gap-2",
10486
10885
  children: [
10487
- showName && (nameDraft !== null ? /* @__PURE__ */ jsx(Input, {
10886
+ showName && (nameEditing ? /* @__PURE__ */ jsx(InlineEditInput, {
10488
10887
  size: "sm",
10489
- "data-slot": "docblocks/database-name-input",
10888
+ initial: displayName,
10889
+ selectOnMount: true,
10890
+ ariaLabel: t("renameTable.aria", { name: displayName }),
10891
+ slot: "docblocks/database-name-input",
10490
10892
  className: cn("rounded-(--docblocks-radius) border-(length:--docblocks-table-border-width) border-(--docblocks-table-border-color) bg-transparent dark:border-(--docblocks-table-border-color) dark:bg-transparent", `h-auto min-w-32 px-1 py-0.5 text-(length:--docblocks-font-size) font-(--docblocks-heading-font-weight)`),
10491
- value: nameDraft,
10492
- autoFocus: true,
10493
- onChange: onNameChange,
10494
- onBlur: onNameBlur,
10495
- onKeyDown: onNameKeyDown
10893
+ onCommit: commitName,
10894
+ onCancel: () => setNameEditing(false)
10496
10895
  }) : readOnly ? /* @__PURE__ */ jsx("span", {
10497
10896
  "data-slot": "docblocks/database-name",
10498
10897
  className: "font-(--docblocks-heading-font-weight)",
@@ -10503,38 +10902,31 @@ function GridToolbar({ tableId, table, data, filter, columnOrder, hiddenColumns,
10503
10902
  size: "sm",
10504
10903
  title: t("common:rename"),
10505
10904
  className: " h-auto cursor-text border-0 bg-transparent px-1 text-(length:--docblocks-font-size) font-(--docblocks-heading-font-weight) hover:bg-transparent hover:opacity-70 hover:text-inherit dark:bg-transparent dark:hover:bg-transparent",
10506
- onClick: beginNameEdit,
10905
+ onClick: () => setNameEditing(true),
10507
10906
  children: displayName
10508
10907
  })),
10509
- /* @__PURE__ */ jsxs(Badge, {
10510
- "data-slot": "docblocks/database-count",
10511
- variant: "secondary",
10512
- children: [
10513
- data.rows.length,
10514
- " ",
10515
- t("rowCount", { count: data.rows.length })
10516
- ]
10908
+ /* @__PURE__ */ jsx(GridRowCount, {
10909
+ total: resolvedRowCount,
10910
+ visible: data.rows.length,
10911
+ filtered: hasActiveFilter
10912
+ }),
10913
+ !readOnly && /* @__PURE__ */ jsx(Button, {
10914
+ "data-slot": "docblocks/database-add-row",
10915
+ variant: "outline",
10916
+ size: "sm",
10917
+ className: "bg-accent text-accent-foreground select-none",
10918
+ onClick: insertEmptyRow,
10919
+ children: t("rows.add")
10517
10920
  }),
10518
10921
  /* @__PURE__ */ jsxs("div", {
10519
10922
  className: "ml-auto flex items-center gap-2",
10520
10923
  children: [
10521
- readOnly ? null : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Button, {
10522
- "data-slot": "docblocks/database-undo",
10523
- variant: "outline",
10524
- size: "sm",
10525
- "data-disabled": data.canUndo ? void 0 : true,
10526
- disabled: !data.canUndo,
10527
- onClick: undoStep,
10528
- children: t("toolbar.undo")
10529
- }), /* @__PURE__ */ jsx(Button, {
10530
- "data-slot": "docblocks/database-redo",
10531
- variant: "outline",
10532
- size: "sm",
10533
- "data-disabled": data.canRedo ? void 0 : true,
10534
- disabled: !data.canRedo,
10535
- onClick: redoStep,
10536
- children: t("toolbar.redo")
10537
- })] }),
10924
+ readOnly ? null : /* @__PURE__ */ jsx(GridHistoryButtons, {
10925
+ canUndo: data.canUndo,
10926
+ canRedo: data.canRedo,
10927
+ onUndo: undoStep,
10928
+ onRedo: redoStep
10929
+ }),
10538
10930
  readOnly ? null : /* @__PURE__ */ jsx(ColumnManager, {
10539
10931
  columns: table.columns,
10540
10932
  columnOrder,
@@ -10551,8 +10943,10 @@ function GridToolbar({ tableId, table, data, filter, columnOrder, hiddenColumns,
10551
10943
  "data-slot": "docblocks/database-filter",
10552
10944
  variant: "outline",
10553
10945
  size: "sm",
10554
- "data-active": filter !== void 0 && filter.conditions.length > 0 ? "true" : void 0,
10555
- children: [t("toolbar.filter"), filter !== void 0 && filter.conditions.length > 0 ? " •" : ""]
10946
+ "data-active": hasActiveFilter ? "true" : void 0,
10947
+ "data-disabled": resolvedRowCount === 0 ? true : void 0,
10948
+ disabled: resolvedRowCount === 0,
10949
+ children: [t("toolbar.filter"), hasActiveFilter ? " •" : ""]
10556
10950
  })
10557
10951
  }), /* @__PURE__ */ jsx(PopoverContent, {
10558
10952
  align: "end",
@@ -10829,6 +11223,7 @@ function useBridgeTables(bridge, refreshKey) {
10829
11223
  * commit).
10830
11224
  */
10831
11225
  function useColumnForm({ bridge, tableId, data, refTableData, readColumnOrder, onViewChange }) {
11226
+ const { t } = useTranslation("database");
10832
11227
  const [addingColumn, setAddingColumn] = useState(false);
10833
11228
  const [columnFormOpen, setColumnFormOpen] = useState(false);
10834
11229
  const [columnForm, setColumnForm] = useState(null);
@@ -10875,7 +11270,7 @@ function useColumnForm({ bridge, tableId, data, refTableData, readColumnOrder, o
10875
11270
  * the create form (the name input + the type-specific block over it) —
10876
11271
  * the create commits on the form's button only. */
10877
11272
  const openCreateForm = (entry) => {
10878
- setColumnForm(emptyColumnForm(entry));
11273
+ setColumnForm(emptyColumnForm(entry, t(entry.labelKey)));
10879
11274
  setAddingColumn(false);
10880
11275
  setColumnFormError(null);
10881
11276
  setColumnFormOpen(true);
@@ -10968,6 +11363,140 @@ function useColumnForm({ bridge, tableId, data, refTableData, readColumnOrder, o
10968
11363
  };
10969
11364
  }
10970
11365
  //#endregion
11366
+ //#region src/database/grid/block-height.ts
11367
+ /** The document database block's measured auto height and resize floor. */
11368
+ function cssPixels(value) {
11369
+ const parsed = Number.parseFloat(value);
11370
+ return Number.isFinite(parsed) ? parsed : 0;
11371
+ }
11372
+ function positivePixels(value, fallback) {
11373
+ const parsed = cssPixels(value);
11374
+ return parsed > 0 ? parsed : fallback;
11375
+ }
11376
+ /** Measures the fixed chrome around the scrolling grid, so the block's
11377
+ * explicit height leaves the toolbar visible and the floor stays usable. */
11378
+ function measureDatabaseBlockMetrics(card, table, scroller, headerHeight) {
11379
+ const header = headerHeight ?? Math.max(measureDatabaseHeaderHeight(table), 28);
11380
+ const rowHeight = positivePixels(card === null ? "" : getComputedStyle(card).getPropertyValue("--docblocks-database-row-height"), 32);
11381
+ let chrome = 0;
11382
+ if (card !== null) {
11383
+ const cardStyle = getComputedStyle(card);
11384
+ chrome += cssPixels(cardStyle.borderTopWidth) + cssPixels(cardStyle.borderBottomWidth);
11385
+ const content = card.querySelector(":scope > [data-slot='docblocks/database']");
11386
+ const toolbar = card.querySelector("[data-slot='docblocks/database-toolbar']");
11387
+ chrome += toolbar?.offsetHeight ?? 0;
11388
+ if (content !== null) {
11389
+ const style = getComputedStyle(content);
11390
+ chrome += cssPixels(style.paddingTop) + cssPixels(style.paddingBottom) + cssPixels(style.rowGap);
11391
+ }
11392
+ if (table !== null) {
11393
+ const style = getComputedStyle(table);
11394
+ chrome += cssPixels(style.borderTopWidth) + cssPixels(style.borderBottomWidth);
11395
+ }
11396
+ if (scroller !== null) chrome += Math.max(0, scroller.offsetHeight - scroller.clientHeight);
11397
+ }
11398
+ return {
11399
+ auto: Math.round(chrome + header + 10 * rowHeight),
11400
+ min: Math.round(chrome + header + 3 * rowHeight)
11401
+ };
11402
+ }
11403
+ //#endregion
11404
+ //#region src/database/grid/use-database-block-height.ts
11405
+ /** The document database block's bottom-edge resize session. */
11406
+ const INITIAL_METRICS = {
11407
+ auto: 348,
11408
+ min: 124
11409
+ };
11410
+ function useDatabaseBlockHeight({ enabled, ready, height, headerHeight, cardRef, tableRef, scrollerRef, onCommit }) {
11411
+ const [metrics, setMetrics] = useState(INITIAL_METRICS);
11412
+ const [preview, setPreview] = useState(null);
11413
+ const session = useRef(null);
11414
+ useLayoutEffect(() => {
11415
+ if (!enabled || !ready) return;
11416
+ const measure = () => {
11417
+ const next = measureDatabaseBlockMetrics(cardRef.current, tableRef.current, scrollerRef.current, headerHeight);
11418
+ setMetrics((current) => current.auto === next.auto && current.min === next.min ? current : next);
11419
+ };
11420
+ measure();
11421
+ if (typeof ResizeObserver === "undefined") return;
11422
+ const observer = new ResizeObserver(measure);
11423
+ const toolbar = cardRef.current?.querySelector("[data-slot='docblocks/database-toolbar']");
11424
+ if (toolbar !== null && toolbar !== void 0) observer.observe(toolbar);
11425
+ if (tableRef.current !== null) observer.observe(tableRef.current);
11426
+ return () => observer.disconnect();
11427
+ }, [
11428
+ cardRef,
11429
+ enabled,
11430
+ headerHeight,
11431
+ ready,
11432
+ scrollerRef,
11433
+ tableRef
11434
+ ]);
11435
+ const currentHeight = preview ?? height;
11436
+ const style = enabled ? {
11437
+ height: currentHeight,
11438
+ maxHeight: currentHeight === void 0 ? metrics.auto : void 0
11439
+ } : void 0;
11440
+ const onPointerDown = (event) => {
11441
+ if (!enabled || event.button !== 0 || session.current !== null) return;
11442
+ const card = cardRef.current;
11443
+ if (card === null) return;
11444
+ event.preventDefault();
11445
+ event.stopPropagation();
11446
+ event.currentTarget.setPointerCapture?.(event.pointerId);
11447
+ const nextMetrics = measureDatabaseBlockMetrics(card, tableRef.current, scrollerRef.current, headerHeight);
11448
+ setMetrics(nextMetrics);
11449
+ const measured = card.getBoundingClientRect().height;
11450
+ const startHeight = height ?? (measured > 0 ? measured : nextMetrics.auto);
11451
+ session.current = {
11452
+ pointerId: event.pointerId,
11453
+ startY: event.clientY,
11454
+ startHeight,
11455
+ min: nextMetrics.min,
11456
+ height: startHeight
11457
+ };
11458
+ setPreview(startHeight);
11459
+ };
11460
+ const onPointerMove = (event) => {
11461
+ const live = session.current;
11462
+ if (live === null || live.pointerId !== event.pointerId) return;
11463
+ live.height = Math.max(live.min, live.startHeight + event.clientY - live.startY);
11464
+ setPreview(live.height);
11465
+ };
11466
+ const onPointerUp = (event) => {
11467
+ const live = session.current;
11468
+ if (live === null || live.pointerId !== event.pointerId) return;
11469
+ event.currentTarget.releasePointerCapture?.(event.pointerId);
11470
+ session.current = null;
11471
+ setPreview(null);
11472
+ const committed = Math.round(live.height);
11473
+ if (committed !== Math.round(live.startHeight) && committed !== height) onCommit?.(committed);
11474
+ };
11475
+ const onPointerCancel = () => {
11476
+ session.current = null;
11477
+ setPreview(null);
11478
+ };
11479
+ const onKeyDown = (event) => {
11480
+ if (!enabled) return;
11481
+ const delta = event.key === "ArrowDown" ? 16 : event.key === "ArrowUp" ? -16 : null;
11482
+ if (delta === null) return;
11483
+ event.preventDefault();
11484
+ const current = Math.round(currentHeight ?? metrics.auto);
11485
+ const next = Math.max(metrics.min, current + delta);
11486
+ if (next !== current) onCommit?.(next);
11487
+ };
11488
+ return {
11489
+ style,
11490
+ currentHeight: currentHeight ?? metrics.auto,
11491
+ minHeight: metrics.min,
11492
+ onPointerDown,
11493
+ onPointerMove,
11494
+ onPointerUp,
11495
+ onPointerCancel,
11496
+ onKeyDown
11497
+ };
11498
+ }
11499
+ //#endregion
10971
11500
  //#region src/database/grid/use-enum-options-motion.ts
10972
11501
  /** The enum's options editor's motion's slot: the framer-wired editor
10973
11502
  * (the Reorder's rows) provides the motion's variant here; the renderer
@@ -10978,33 +11507,193 @@ function useEnumOptionsMotion() {
10978
11507
  return useContext(EnumOptionsMotionSlot);
10979
11508
  }
10980
11509
  //#endregion
11510
+ //#region src/database/grid/grid-cell-actions.ts
11511
+ /** Clears every selected cell in one bridge batch and one history entry. */
11512
+ function clearGridCells(selectedCells, data) {
11513
+ const byRow = /* @__PURE__ */ new Map();
11514
+ selectedCells.forEach((key) => {
11515
+ const [rowId, colId] = key.split("\0");
11516
+ if (rowId === void 0 || colId === void 0) return;
11517
+ const cells = byRow.get(rowId) ?? Object.create(null);
11518
+ cells[colId] = null;
11519
+ byRow.set(rowId, cells);
11520
+ });
11521
+ return data.updateRows([...byRow.entries()].map(([rowId, cells]) => ({
11522
+ rowId,
11523
+ cells
11524
+ })));
11525
+ }
11526
+ /** Returns the selected row ids once, in the selection's row-major order. */
11527
+ function selectedGridRowIds(selectedCells) {
11528
+ const ids = /* @__PURE__ */ new Set();
11529
+ selectedCells.forEach((key) => {
11530
+ const [rowId] = key.split("\0");
11531
+ if (rowId !== void 0) ids.add(rowId);
11532
+ });
11533
+ return [...ids];
11534
+ }
11535
+ //#endregion
11536
+ //#region src/database/grid/grid-cell-clipboard.ts
11537
+ const DATABASE_GRID_MIME = "application/x-docblocks-database-grid";
11538
+ const DATABASE_GRID_PAYLOAD_VERSION = 1;
11539
+ function refDataOf(column, refs) {
11540
+ if (column.refTableId === void 0) return void 0;
11541
+ return refs[refEntryKey({
11542
+ tableId: column.refTableId,
11543
+ displayColumn: column.refDisplayColumn
11544
+ })];
11545
+ }
11546
+ function displayTextOf$1(column, value, refs) {
11547
+ if (column.refKind === void 0) return cellTextOf(value);
11548
+ const data = refDataOf(column, refs);
11549
+ const display = (entry) => {
11550
+ const raw = cellTextOf(entry);
11551
+ return data?.displays[raw] ?? raw;
11552
+ };
11553
+ return Array.isArray(value) ? value.map(display).join(",") : display(value);
11554
+ }
11555
+ /** Builds the standard display TSV and the same-table raw-value payload. */
11556
+ function buildDatabaseGridClipboard(ctx) {
11557
+ const { tableId, rows, columns, selectionFrame, refTableData } = ctx;
11558
+ const rMin = Math.min(selectionFrame.anchorR, selectionFrame.cursorR);
11559
+ const rMax = Math.max(selectionFrame.anchorR, selectionFrame.cursorR);
11560
+ const cMin = Math.min(selectionFrame.anchorC, selectionFrame.cursorC);
11561
+ const cMax = Math.max(selectionFrame.anchorC, selectionFrame.cursorC);
11562
+ const textRows = [];
11563
+ const rawRows = [];
11564
+ for (let r = rMin; r <= rMax; r += 1) {
11565
+ const textCells = [];
11566
+ const rawCells = [];
11567
+ for (let c = cMin; c <= cMax; c += 1) {
11568
+ const row = rows[r];
11569
+ const column = columns[c];
11570
+ const value = row === void 0 || column === void 0 ? null : row.cells[column.id];
11571
+ rawCells.push(value ?? null);
11572
+ textCells.push(column === void 0 ? "" : displayTextOf$1(column, value, refTableData));
11573
+ }
11574
+ textRows.push(textCells.join(" "));
11575
+ rawRows.push(rawCells);
11576
+ }
11577
+ return {
11578
+ mime: DATABASE_GRID_MIME,
11579
+ text: textRows.join("\n"),
11580
+ payload: JSON.stringify({
11581
+ v: DATABASE_GRID_PAYLOAD_VERSION,
11582
+ tableId,
11583
+ cells: rawRows
11584
+ })
11585
+ };
11586
+ }
11587
+ /** Parses only the versioned payload issued for the current table. */
11588
+ function parseDatabaseGridPayload(raw, tableId) {
11589
+ if (raw === "") return null;
11590
+ try {
11591
+ const parsed = JSON.parse(raw);
11592
+ if (typeof parsed !== "object" || parsed === null) return null;
11593
+ const candidate = parsed;
11594
+ if (candidate.v !== DATABASE_GRID_PAYLOAD_VERSION || candidate.tableId !== tableId) return null;
11595
+ if (!Array.isArray(candidate.cells) || !candidate.cells.every((row) => Array.isArray(row))) return null;
11596
+ return candidate.cells;
11597
+ } catch {
11598
+ return null;
11599
+ }
11600
+ }
11601
+ function invalid(error) {
11602
+ return {
11603
+ ok: false,
11604
+ error
11605
+ };
11606
+ }
11607
+ /** Resolves display text against a reference column's loaded catalog. */
11608
+ function resolveReferenceText(column, raw, refs) {
11609
+ if (raw === "") return {
11610
+ ok: true,
11611
+ value: null
11612
+ };
11613
+ if (refs === void 0) return invalid("The reference catalog is unavailable");
11614
+ const labels = column.refMany === true ? raw.split(",").map((entry) => entry.trim()) : [raw.trim()];
11615
+ const values = [];
11616
+ for (const label of labels) {
11617
+ const matches = refs.rowIds.filter((rowId) => refs.displays[rowId] === label);
11618
+ if (matches.length === 0 || column.refKind === "row" && matches.length !== 1) return invalid("The reference label is unknown or ambiguous");
11619
+ values.push(matches[0]);
11620
+ }
11621
+ return {
11622
+ ok: true,
11623
+ value: column.refMany === true ? values : values[0]
11624
+ };
11625
+ }
11626
+ /** Resolves external TSV text into one target cell. */
11627
+ function resolveTextGridCell(column, raw, refs) {
11628
+ const input = columnAnnotation(column).valueInput;
11629
+ if (input === "none") return invalid("The column does not accept values");
11630
+ if (input === "enum" || input === "row-link") return resolveReferenceText(column, raw, refs);
11631
+ return parseCellValue(input, raw);
11632
+ }
11633
+ /** Validates raw structured clipboard values against the target column. */
11634
+ function resolveStructuredGridCell(column, raw) {
11635
+ const input = columnAnnotation(column).valueInput;
11636
+ if (input === "none") return invalid("The column does not accept values");
11637
+ if (raw === null) return {
11638
+ ok: true,
11639
+ value: null
11640
+ };
11641
+ if (input === "enum" || input === "row-link") {
11642
+ if (column.refMany === true) return Array.isArray(raw) && raw.every((entry) => typeof entry === "string") ? {
11643
+ ok: true,
11644
+ value: [...raw]
11645
+ } : invalid("The reference list is invalid");
11646
+ return typeof raw === "string" ? {
11647
+ ok: true,
11648
+ value: raw
11649
+ } : invalid("The reference is invalid");
11650
+ }
11651
+ if (input === "number") return typeof raw === "number" && Number.isFinite(raw) ? {
11652
+ ok: true,
11653
+ value: raw
11654
+ } : invalid("The number is invalid");
11655
+ if (input === "boolean") return typeof raw === "boolean" ? {
11656
+ ok: true,
11657
+ value: raw
11658
+ } : invalid("The boolean is invalid");
11659
+ if (typeof raw !== "string") return invalid("The text value is invalid");
11660
+ return parseCellValue(input, raw);
11661
+ }
11662
+ /** Writes both clipboard flavors, retaining TSV when custom MIME is unavailable. */
11663
+ async function writeDatabaseGridClipboard(clipboard) {
11664
+ if (typeof navigator === "undefined" || navigator.clipboard === void 0) return;
11665
+ if (typeof navigator.clipboard.write === "function" && typeof ClipboardItem !== "undefined") try {
11666
+ const item = new ClipboardItem({
11667
+ "text/plain": new Blob([clipboard.text], { type: "text/plain" }),
11668
+ [clipboard.mime]: new Blob([clipboard.payload], { type: clipboard.mime })
11669
+ });
11670
+ await navigator.clipboard.write([item]);
11671
+ return;
11672
+ } catch {}
11673
+ try {
11674
+ await navigator.clipboard.writeText(clipboard.text);
11675
+ } catch {}
11676
+ }
11677
+ //#endregion
10981
11678
  //#region src/database/grid/grid-cell-keyboard.ts
10982
11679
  /** The table's keydown stand (the grid's own gestures over the table's
10983
11680
  * focus — the editor root's blocks-selection gestures must not fire). */
10984
11681
  function handleGridCellKeyDown(event, ctx) {
10985
- const { readOnly, rows, columns, data, selectionFrame, editingCell, selectedCells, setSelectionFrame, setEditingCell } = ctx;
11682
+ const { tableId, refTableData, readOnly, rows, columns, data, selectionFrame, editingCell, selectedCells, setSelectionFrame, setEditingCell } = ctx;
10986
11683
  if (readOnly) return;
10987
11684
  if ((event.metaKey || event.ctrlKey) && !event.shiftKey && event.key.toLowerCase() === "c") {
10988
11685
  if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) return;
10989
11686
  if (selectionFrame === null) return;
10990
11687
  event.preventDefault();
10991
11688
  event.stopPropagation();
10992
- const rMin = Math.min(selectionFrame.anchorR, selectionFrame.cursorR);
10993
- const rMax = Math.max(selectionFrame.anchorR, selectionFrame.cursorR);
10994
- const cMin = Math.min(selectionFrame.anchorC, selectionFrame.cursorC);
10995
- const cMax = Math.max(selectionFrame.anchorC, selectionFrame.cursorC);
10996
- const lines = [];
10997
- for (let r = rMin; r <= rMax; r += 1) {
10998
- const cells = [];
10999
- for (let c = cMin; c <= cMax; c += 1) {
11000
- const row = rows[r];
11001
- const column = columns[c];
11002
- cells.push(row === void 0 || column === void 0 ? "" : cellTextOf(row.cells[column.id]));
11003
- }
11004
- lines.push(cells.join(" "));
11005
- }
11006
- const tsv = lines.join("\n");
11007
- if (typeof navigator !== "undefined" && navigator.clipboard !== void 0) navigator.clipboard.writeText(tsv).catch(() => void 0);
11689
+ const clipboard = buildDatabaseGridClipboard({
11690
+ tableId,
11691
+ rows,
11692
+ columns,
11693
+ selectionFrame,
11694
+ refTableData
11695
+ });
11696
+ if (clipboard !== null) writeDatabaseGridClipboard(clipboard);
11008
11697
  return;
11009
11698
  }
11010
11699
  if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "z") {
@@ -11066,34 +11755,24 @@ function handleGridCellKeyDown(event, ctx) {
11066
11755
  if (selectedCells.size === 0) return;
11067
11756
  event.preventDefault();
11068
11757
  event.stopPropagation();
11069
- const byRow = /* @__PURE__ */ new Map();
11070
- selectedCells.forEach((key) => {
11071
- const [rowId, colId] = key.split("\0");
11072
- const cells = byRow.get(rowId) ?? Object.create(null);
11073
- cells[colId] = null;
11074
- byRow.set(rowId, cells);
11075
- });
11076
- data.updateRows([...byRow.entries()].map(([rowId, cells]) => ({
11077
- rowId,
11078
- cells
11079
- }))).catch(() => void 0);
11758
+ clearGridCells(selectedCells, data).catch(() => void 0);
11080
11759
  }
11081
11760
  //#endregion
11082
11761
  //#region src/database/grid/grid-cell-paste.ts
11083
- /** The table's clipboard's paste (the mixed batch's commit). */
11084
- function handleGridCellPaste(event, ctx) {
11085
- const { readOnly, rows, columns, data, selectionFrame } = ctx;
11086
- if (readOnly) return;
11087
- if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) return;
11088
- const frame = selectionFrame;
11089
- if (frame === null) return;
11762
+ /** Commits one paste and returns its changed cells for the transient frame. */
11763
+ async function handleGridCellPaste(event, ctx) {
11764
+ const { readOnly, tableId, rows, columns, data, selectionFrame, refTableData } = ctx;
11765
+ if (readOnly) return null;
11766
+ if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) return null;
11767
+ if (selectionFrame === null) return null;
11768
+ const structured = parseDatabaseGridPayload(event.clipboardData.getData(DATABASE_GRID_MIME), tableId);
11090
11769
  const text = event.clipboardData.getData("text/plain");
11091
- if (text === "") return;
11770
+ if (structured === null && text === "") return null;
11092
11771
  event.preventDefault();
11093
- const grid = parseClipboardTsv(text);
11094
- if (grid.length === 0 || rows.length === 0 || columns.length === 0) return;
11095
- const r0 = frame.anchorR;
11096
- const c0 = frame.anchorC;
11772
+ const grid = structured ?? parseClipboardTsv(text);
11773
+ if (grid.length === 0 || rows.length === 0 || columns.length === 0) return null;
11774
+ const r0 = selectionFrame.anchorR;
11775
+ const c0 = selectionFrame.anchorC;
11097
11776
  const updates = [];
11098
11777
  const creates = [];
11099
11778
  for (let i = 0; i < grid.length; i += 1) {
@@ -11102,29 +11781,110 @@ function handleGridCellPaste(event, ctx) {
11102
11781
  const cells = Object.create(null);
11103
11782
  for (let j = 0; j < line.length; j += 1) {
11104
11783
  const column = columns[c0 + j];
11105
- if (column === void 0) continue;
11106
- const input = columnAnnotation(column).valueInput;
11107
- if (input === "enum" || input === "row-link" || input === "none") continue;
11108
11784
  const raw = line[j];
11109
- if (raw === void 0) continue;
11110
- const parsed = parseCellValue(input, raw);
11111
- if (!parsed.ok) continue;
11112
- cells[column.id] = parsed.value;
11785
+ if (column === void 0 || raw === void 0) continue;
11786
+ const resolved = structured !== null ? resolveStructuredGridCell(column, raw) : resolveTextGridCell(column, String(raw), refDataOf(column, refTableData));
11787
+ if (resolved.ok) cells[column.id] = resolved.value;
11113
11788
  }
11114
11789
  const rowAt = rows[r0 + i];
11790
+ if (rowAt !== void 0) {
11791
+ for (const [columnId, value] of Object.entries(cells)) if (cellValueEqual(rowAt.cells[columnId], value)) delete cells[columnId];
11792
+ }
11793
+ if (Object.keys(cells).length === 0) continue;
11115
11794
  if (rowAt !== void 0) updates.push({
11116
11795
  rowId: rowAt.rowId,
11117
11796
  cells
11118
11797
  });
11119
11798
  else creates.push(cells);
11120
11799
  }
11121
- if (updates.length === 0 && creates.length === 0) return;
11122
- const successor = rows[r0 + updates.length - 1 + 1];
11123
- data.pasteRows({
11800
+ if (updates.length === 0 && creates.length === 0) return null;
11801
+ const lastUpdated = updates.at(-1);
11802
+ const successor = rows[(lastUpdated === void 0 ? -1 : rows.findIndex((row) => row.rowId === lastUpdated.rowId)) + 1];
11803
+ const createdRowIds = await data.pasteRows({
11124
11804
  updates,
11125
11805
  creates,
11126
11806
  beforeRowId: successor?.rowId ?? null
11127
- }).catch(() => void 0);
11807
+ });
11808
+ const updatedHighlights = updates.map(({ rowId, cells }) => ({
11809
+ rowId,
11810
+ columnIds: Object.keys(cells)
11811
+ }));
11812
+ const createdHighlights = createdRowIds.flatMap((rowId, index) => {
11813
+ const cells = creates[index];
11814
+ return cells === void 0 ? [] : [{
11815
+ rowId,
11816
+ columnIds: Object.keys(cells)
11817
+ }];
11818
+ });
11819
+ return [...updatedHighlights, ...createdHighlights];
11820
+ }
11821
+ //#endregion
11822
+ //#region src/database/grid/use-grid-range-menu.ts
11823
+ /** Opens the selected range's menu at the right-click release point. */
11824
+ function useGridRangeMenu({ selectedCells, data, readOnly, onAction }) {
11825
+ const [anchor, setAnchor] = useState(null);
11826
+ const pendingOpenRef = useRef(null);
11827
+ const onTableContextMenu = (event) => {
11828
+ if (readOnly || selectedCells.size <= 1) return;
11829
+ const cell = (event.target instanceof Element ? event.target : null)?.closest("[data-slot='docblocks/database-cell'][data-key]");
11830
+ if (cell == null || !selectedCells.has(cell.dataset.key ?? "")) return;
11831
+ event.preventDefault();
11832
+ pendingOpenRef.current?.();
11833
+ const open = (x, y) => setAnchor({
11834
+ x,
11835
+ y
11836
+ });
11837
+ if (event.buttons === 0) {
11838
+ const task = window.setTimeout(() => {
11839
+ pendingOpenRef.current = null;
11840
+ open(event.clientX, event.clientY);
11841
+ }, 0);
11842
+ pendingOpenRef.current = () => window.clearTimeout(task);
11843
+ return;
11844
+ }
11845
+ const onUp = (up) => {
11846
+ if (up.button !== 2) {
11847
+ window.addEventListener("pointerup", onUp, { once: true });
11848
+ return;
11849
+ }
11850
+ pendingOpenRef.current = null;
11851
+ open(up.clientX, up.clientY);
11852
+ };
11853
+ window.addEventListener("pointerup", onUp, { once: true });
11854
+ window.addEventListener("pointercancel", onUp, { once: true });
11855
+ pendingOpenRef.current = () => {
11856
+ window.removeEventListener("pointerup", onUp);
11857
+ window.removeEventListener("pointercancel", onUp);
11858
+ };
11859
+ };
11860
+ const clearRange = () => {
11861
+ onAction?.();
11862
+ clearGridCells(selectedCells, data).catch(() => void 0);
11863
+ };
11864
+ const deleteRows = () => {
11865
+ onAction?.();
11866
+ data.removeRows(selectedGridRowIds(selectedCells)).catch(() => void 0);
11867
+ };
11868
+ const onOpenChange = (open) => {
11869
+ if (!open) setAnchor(null);
11870
+ };
11871
+ useEffect(() => {
11872
+ if (selectedCells.size > 1) return;
11873
+ pendingOpenRef.current?.();
11874
+ pendingOpenRef.current = null;
11875
+ setAnchor(null);
11876
+ }, [selectedCells]);
11877
+ useEffect(() => () => {
11878
+ pendingOpenRef.current?.();
11879
+ pendingOpenRef.current = null;
11880
+ }, []);
11881
+ return {
11882
+ anchor,
11883
+ clearRange,
11884
+ deleteRows,
11885
+ onOpenChange,
11886
+ onTableContextMenu
11887
+ };
11128
11888
  }
11129
11889
  //#endregion
11130
11890
  //#region src/database/grid/use-grid-cell-interaction.ts
@@ -11138,9 +11898,21 @@ function handleGridCellPaste(event, ctx) {
11138
11898
  * and the press-outside's teardown (the view state resets, the edit session
11139
11899
  * closes). The selection's set + the frame's state + the editing cell's
11140
11900
  * state + the boolean press's stand stand in the hook. */
11141
- function useGridCellInteraction({ rows, columns, data, tableRef, readOnly = false }) {
11901
+ function useGridCellInteraction({ tableId, refTableData, rows, columns, data, tableRef, readOnly = false }) {
11142
11902
  const [selectionFrame, setSelectionFrame] = useState(null);
11143
11903
  const [editingCell, setEditingCell] = useState(null);
11904
+ const [pasteRange, setPasteRange] = useState(/* @__PURE__ */ new Set());
11905
+ const clearPasteRange = useCallback(() => {
11906
+ setPasteRange((current) => current.size === 0 ? current : /* @__PURE__ */ new Set());
11907
+ }, []);
11908
+ const updateSelectionFrame = useCallback((value) => {
11909
+ clearPasteRange();
11910
+ setSelectionFrame(value);
11911
+ }, [clearPasteRange]);
11912
+ const updateEditingCell = useCallback((value) => {
11913
+ if (value !== null) clearPasteRange();
11914
+ setEditingCell(value);
11915
+ }, [clearPasteRange]);
11144
11916
  const selectedCells = useMemo(() => {
11145
11917
  const keys = /* @__PURE__ */ new Set();
11146
11918
  if (selectionFrame === null) return keys;
@@ -11174,6 +11946,7 @@ function useGridCellInteraction({ rows, columns, data, tableRef, readOnly = fals
11174
11946
  const onCellPointerDown = (rowId, colId, r, c) => (event) => {
11175
11947
  if (readOnly) return;
11176
11948
  if (event.button !== 0) return;
11949
+ clearPasteRange();
11177
11950
  if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) return;
11178
11951
  if (event.target instanceof Element && event.target.closest("[data-radix-popper-content-wrapper]") !== null) return;
11179
11952
  const key = cellKeyOf(rowId, colId);
@@ -11232,29 +12005,44 @@ function useGridCellInteraction({ rows, columns, data, tableRef, readOnly = fals
11232
12005
  * focus — the editor root's blocks-selection gestures must not fire
11233
12006
  * over the stand). */
11234
12007
  const onTableKeyDown = (event) => {
12008
+ clearPasteRange();
11235
12009
  handleGridCellKeyDown(event, {
11236
12010
  readOnly,
11237
12011
  rows,
11238
12012
  columns,
11239
12013
  data,
12014
+ tableId,
12015
+ refTableData,
11240
12016
  selectionFrame,
11241
12017
  editingCell,
11242
12018
  selectedCells,
11243
- setSelectionFrame,
11244
- setEditingCell
12019
+ setSelectionFrame: updateSelectionFrame,
12020
+ setEditingCell: updateEditingCell
11245
12021
  });
11246
12022
  };
11247
12023
  /** The clipboard's paste (the mixed batch: the TSV's grid stands from
11248
12024
  * the selection's anchor cell over the grid's own columns — the
11249
12025
  * updates + the creates over one `batchRows`). */
12026
+ const commitPaste = async (event) => {
12027
+ try {
12028
+ const highlights = await handleGridCellPaste(event, {
12029
+ readOnly,
12030
+ tableId,
12031
+ rows,
12032
+ columns,
12033
+ data,
12034
+ selectionFrame,
12035
+ refTableData
12036
+ });
12037
+ if (highlights === null) return;
12038
+ const keys = /* @__PURE__ */ new Set();
12039
+ for (const highlight of highlights) for (const columnId of highlight.columnIds) keys.add(cellKeyOf(highlight.rowId, columnId));
12040
+ setPasteRange(keys);
12041
+ } catch {}
12042
+ };
11250
12043
  const onTablePaste = (event) => {
11251
- handleGridCellPaste(event, {
11252
- readOnly,
11253
- rows,
11254
- columns,
11255
- data,
11256
- selectionFrame
11257
- });
12044
+ clearPasteRange();
12045
+ commitPaste(event);
11258
12046
  };
11259
12047
  useEffect(() => {
11260
12048
  if (selectionFrame === null) return;
@@ -11264,6 +12052,7 @@ function useGridCellInteraction({ rows, columns, data, tableRef, readOnly = fals
11264
12052
  if (tableRef.current === null || !tableRef.current.contains(event.target)) {
11265
12053
  setSelectionFrame(null);
11266
12054
  setEditingCell(null);
12055
+ clearPasteRange();
11267
12056
  }
11268
12057
  };
11269
12058
  document.addEventListener("pointerdown", onDown, true);
@@ -11271,12 +12060,19 @@ function useGridCellInteraction({ rows, columns, data, tableRef, readOnly = fals
11271
12060
  }, [selectionFrame]);
11272
12061
  return {
11273
12062
  editingCell,
11274
- setEditingCell,
12063
+ setEditingCell: updateEditingCell,
12064
+ pasteRange,
11275
12065
  selectedCells,
11276
12066
  booleanPressRef,
11277
12067
  onCellPointerDown,
11278
12068
  onTableKeyDown,
11279
- onTablePaste
12069
+ onTablePaste,
12070
+ rangeMenu: useGridRangeMenu({
12071
+ selectedCells,
12072
+ data,
12073
+ readOnly,
12074
+ onAction: clearPasteRange
12075
+ })
11280
12076
  };
11281
12077
  }
11282
12078
  //#endregion
@@ -11351,10 +12147,12 @@ function useGridPendingRow({ pendingRow, data, columns, tableRef, setEditingCell
11351
12147
  * toolbar over `GridToolbar`, the table over `GridTable` (+ `GridRows`),
11352
12148
  * the pending row's lifecycle over `use-grid-pending-row`, the state's
11353
12149
  * surfaces over `GridStateCards`. */
11354
- function GridBody({ blockId, bridge, tableId, filter, columnOrder, hiddenColumns, columnWidths, headerHeight, sectionHeaderHeight, onHeaderHeightChange, onViewChange, readColumnOrder, readOnly = false }) {
11355
- const { t } = useTranslation("database");
12150
+ function GridBody({ blockId, bridge, tableId, filter, columnOrder, hiddenColumns, columnWidths, height, headerHeight, sectionHeaderHeight, getRowCount, onHeightChange, onHeaderHeightChange, onHeaderHeightReset, onViewChange, readColumnOrder, readOnly = false }) {
11356
12151
  const data = useDatabaseTable(bridge, tableId, filter);
12152
+ const sectionRowCount = getRowCount?.(tableId);
11357
12153
  const tableRef = useRef(null);
12154
+ const cardRef = useRef(null);
12155
+ const scrollerRef = useRef(null);
11358
12156
  const refTableData = useRefTables(bridge, useMemo(() => {
11359
12157
  const map = /* @__PURE__ */ new Map();
11360
12158
  for (const column of data.table?.columns ?? []) {
@@ -11378,12 +12176,24 @@ function GridBody({ blockId, bridge, tableId, filter, columnOrder, hiddenColumns
11378
12176
  });
11379
12177
  const columns = visibleColumns(data.table?.columns, columnOrder, hiddenColumns);
11380
12178
  const resolvedHeaderHeight = resolveDatabaseHeaderHeight(headerHeight, sectionHeaderHeight);
12179
+ const blockHeight = useDatabaseBlockHeight({
12180
+ enabled: blockId !== void 0 && onHeightChange !== void 0,
12181
+ ready: data.phase === "ready",
12182
+ height,
12183
+ headerHeight: resolvedHeaderHeight,
12184
+ cardRef,
12185
+ tableRef,
12186
+ scrollerRef,
12187
+ onCommit: onHeightChange
12188
+ });
11381
12189
  const updateView = (patch) => {
11382
12190
  onViewChange(patch);
11383
12191
  };
11384
12192
  const pendingRow = data.pendingRow !== null && !data.rows.some((row) => row.rowId === data.pendingRow?.rowId) ? data.pendingRow : null;
11385
12193
  const rows = pendingRow === null ? data.rows : [...data.rows, pendingRow];
11386
- const { editingCell, setEditingCell, selectedCells, booleanPressRef, onCellPointerDown, onTableKeyDown, onTablePaste } = useGridCellInteraction({
12194
+ const { editingCell, setEditingCell, pasteRange, selectedCells, booleanPressRef, onCellPointerDown, onTableKeyDown, onTablePaste, rangeMenu } = useGridCellInteraction({
12195
+ tableId,
12196
+ refTableData,
11387
12197
  rows,
11388
12198
  columns,
11389
12199
  data,
@@ -11404,22 +12214,24 @@ function GridBody({ blockId, bridge, tableId, filter, columnOrder, hiddenColumns
11404
12214
  error: data.error,
11405
12215
  onRetry: () => data.retry()
11406
12216
  });
11407
- const insertEmptyRow = () => void data.insertRow({}).catch(() => void 0);
11408
- return /* @__PURE__ */ jsx(Card, {
12217
+ return /* @__PURE__ */ jsxs(Card, {
12218
+ ref: cardRef,
11409
12219
  "data-slot": "docblocks/block",
11410
12220
  "data-block-type": "database",
11411
12221
  "data-block-id": blockId,
11412
12222
  "data-state": "ready",
11413
12223
  contentEditable: false,
11414
- className: "\n my-(--docblocks-block-spacing) flex min-h-0 flex-1 flex-col rounded-(--docblocks-radius)\n border-(length:--docblocks-table-border-width) border-(--docblocks-table-border-color) outline-none\n ",
11415
- children: /* @__PURE__ */ jsxs(CardContent, {
11416
- "data-slot": "docblocks/database",
11417
- className: "flex min-h-0 flex-1 flex-col gap-(--docblocks-block-spacing) p-(--docblocks-block-spacing)",
11418
- children: [
11419
- /* @__PURE__ */ jsx(GridToolbar, {
12224
+ style: blockHeight.style,
12225
+ className: "\n group relative my-(--docblocks-block-spacing) flex min-h-0 flex-1 flex-col rounded-(--docblocks-radius)\n border-(length:--docblocks-table-border-width) border-(--docblocks-table-border-color) outline-none\n ",
12226
+ children: [
12227
+ /* @__PURE__ */ jsxs(CardContent, {
12228
+ "data-slot": "docblocks/database",
12229
+ className: "flex min-h-0 flex-1 flex-col gap-(--docblocks-block-spacing) p-(--docblocks-block-spacing)",
12230
+ children: [/* @__PURE__ */ jsx(GridToolbar, {
11420
12231
  tableId,
11421
12232
  table: data.table,
11422
12233
  data,
12234
+ totalRows: sectionRowCount,
11423
12235
  filter,
11424
12236
  columnOrder,
11425
12237
  hiddenColumns,
@@ -11428,8 +12240,12 @@ function GridBody({ blockId, bridge, tableId, filter, columnOrder, hiddenColumns
11428
12240
  refTableData,
11429
12241
  showName: blockId !== void 0,
11430
12242
  readOnly
11431
- }),
11432
- /* @__PURE__ */ jsx(ScrollArea, {
12243
+ }), data.table.columns.length === 0 ? /* @__PURE__ */ jsx(GridEmptyState, {
12244
+ form,
12245
+ OptionsEditor,
12246
+ readOnly
12247
+ }) : /* @__PURE__ */ jsx(ScrollArea, {
12248
+ ref: scrollerRef,
11433
12249
  "data-slot": "docblocks/database-grid",
11434
12250
  className: "min-h-0 flex-1",
11435
12251
  children: /* @__PURE__ */ jsx(GridTable, {
@@ -11442,6 +12258,7 @@ function GridBody({ blockId, bridge, tableId, filter, columnOrder, hiddenColumns
11442
12258
  data,
11443
12259
  rows,
11444
12260
  selectedCells,
12261
+ pasteRange,
11445
12262
  editingCell,
11446
12263
  setEditingCell,
11447
12264
  onCellPointerDown,
@@ -11452,27 +12269,33 @@ function GridBody({ blockId, bridge, tableId, filter, columnOrder, hiddenColumns
11452
12269
  readOnly,
11453
12270
  headerHeight: resolvedHeaderHeight,
11454
12271
  onHeaderHeightChange,
12272
+ onHeaderHeightReset,
11455
12273
  tableRef,
11456
12274
  onTableKeyDown,
11457
12275
  onTablePaste,
12276
+ onTableContextMenu: rangeMenu.onTableContextMenu,
11458
12277
  onTableBlur,
11459
12278
  form,
11460
12279
  OptionsEditor
11461
12280
  })
11462
- }),
11463
- readOnly ? null : /* @__PURE__ */ jsx(Button, {
11464
- "data-slot": "docblocks/database-add-row",
11465
- variant: "outline",
11466
- size: "sm",
11467
- className: cn(GRID_CHROME_FRAME, `
11468
- h-auto cursor-pointer self-start px-2 py-1 text-(length:--docblocks-font-size) font-normal shadow-none
11469
- select-none
11470
- `, "text-(--docblocks-placeholder-color) hover:bg-transparent", "hover:text-(--docblocks-text-color) dark:hover:bg-transparent"),
11471
- onClick: insertEmptyRow,
11472
- children: t("rows.add")
11473
- })
11474
- ]
11475
- })
12281
+ })]
12282
+ }),
12283
+ /* @__PURE__ */ jsx(DatabaseRangeMenu, {
12284
+ anchor: rangeMenu.anchor,
12285
+ onOpenChange: rangeMenu.onOpenChange,
12286
+ onClear: rangeMenu.clearRange,
12287
+ onDelete: rangeMenu.deleteRows
12288
+ }),
12289
+ blockId !== void 0 && onHeightChange !== void 0 && !readOnly && /* @__PURE__ */ jsx(DatabaseResizeHandle, {
12290
+ height: blockHeight.currentHeight,
12291
+ minHeight: blockHeight.minHeight,
12292
+ onPointerDown: blockHeight.onPointerDown,
12293
+ onPointerMove: blockHeight.onPointerMove,
12294
+ onPointerUp: blockHeight.onPointerUp,
12295
+ onPointerCancel: blockHeight.onPointerCancel,
12296
+ onKeyDown: blockHeight.onKeyDown
12297
+ })
12298
+ ]
11476
12299
  });
11477
12300
  }
11478
12301
  //#endregion
@@ -11539,9 +12362,18 @@ function DatabaseGrid({ id, block }) {
11539
12362
  columnOrder: block.attrs.columnOrder,
11540
12363
  hiddenColumns: block.attrs.hiddenColumns,
11541
12364
  columnWidths: block.attrs.columnWidths,
12365
+ height: block.attrs.height,
11542
12366
  headerHeight: block.attrs.headerHeight,
11543
12367
  sectionHeaderHeight: databaseTableSection?.getHeaderHeight?.(tableId),
12368
+ getRowCount: databaseTableSection?.getRowCount,
12369
+ onHeightChange: (height) => doc.updateBlock(id, { height }),
11544
12370
  onHeaderHeightChange: (height) => doc.updateBlock(id, { headerHeight: height }),
12371
+ onHeaderHeightReset: () => {
12372
+ const current = doc.getBlock(id);
12373
+ if (current === null || current.type !== "database") return;
12374
+ if (current.attrs.headerHeight !== void 0) doc.removeBlockAttr(id, "headerHeight");
12375
+ else if (databaseTableSection?.getHeaderHeight?.(tableId) !== void 0) databaseTableSection.setHeaderHeight?.(tableId, void 0);
12376
+ },
11545
12377
  onViewChange: (patch) => doc.updateBlock(id, patch),
11546
12378
  readColumnOrder: () => {
11547
12379
  const current = doc.getBlock(id);