@ai-matrx/office 0.8.27 → 0.8.29

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.
@@ -796,6 +796,13 @@ interface UniverSheetsOtPortOptions {
796
796
  get(): SheetSelection[] | null | undefined;
797
797
  set(selections: SheetSelection[]): void;
798
798
  };
799
+ /**
800
+ * The sheet's filter range (`SheetsFilterService.getFilterModel(unitId, subUnitId)?.getRange()`), or null. Univer's
801
+ * filter grows its own range when a value lands in the first row under it, with no mutation (SheetsFilterController,
802
+ * 1.0.4): the port sends that growth as a `set-filter-range`, and keeps a peer's value from growing it a second
803
+ * time on this seat. Without it a seat with a filter diverges from its peers on that write.
804
+ */
805
+ filterRange?(unitId: string, subUnitId: string): SheetRange | null | undefined;
799
806
  /** Replace the workbook's whole content, keeping its unit id. */
800
807
  load(snapshot: unknown): void;
801
808
  markDirty(): void;
@@ -796,6 +796,13 @@ interface UniverSheetsOtPortOptions {
796
796
  get(): SheetSelection[] | null | undefined;
797
797
  set(selections: SheetSelection[]): void;
798
798
  };
799
+ /**
800
+ * The sheet's filter range (`SheetsFilterService.getFilterModel(unitId, subUnitId)?.getRange()`), or null. Univer's
801
+ * filter grows its own range when a value lands in the first row under it, with no mutation (SheetsFilterController,
802
+ * 1.0.4): the port sends that growth as a `set-filter-range`, and keeps a peer's value from growing it a second
803
+ * time on this seat. Without it a seat with a filter diverges from its peers on that write.
804
+ */
805
+ filterRange?(unitId: string, subUnitId: string): SheetRange | null | undefined;
799
806
  /** Replace the workbook's whole content, keeping its unit id. */
800
807
  load(snapshot: unknown): void;
801
808
  markDirty(): void;
@@ -4045,6 +4045,7 @@ var ADD_MERGE = "sheet.mutation.add-worksheet-merge";
4045
4045
  var REMOVE_MERGE = "sheet.mutation.remove-worksheet-merge";
4046
4046
  var SHEET_NAME = "sheet.mutation.set-worksheet-name";
4047
4047
  var INSERT_SHEET = "sheet.mutation.insert-sheet";
4048
+ var FILTER_RANGE = "sheet.mutation.set-filter-range";
4048
4049
  var RESHAPE = /* @__PURE__ */ new Set(["sheet.mutation.set-worksheet-row-count", "sheet.mutation.set-worksheet-column-count", "sheet.mutation.remove-sheet", INSERT_SHEET]);
4049
4050
  var UNDO = "univer.command.undo";
4050
4051
  var REDO = "univer.command.redo";
@@ -4086,6 +4087,17 @@ function univerSheetsOtPort(o) {
4086
4087
  return out;
4087
4088
  };
4088
4089
  const sheetOrder = () => (o.workbook()?.getSheets() ?? []).map((ws) => ws.getSheetId());
4090
+ const filterOf = (sheet) => {
4091
+ const u = unitId();
4092
+ if (!u || !o.filterRange) return null;
4093
+ try {
4094
+ const r = o.filterRange(u, sheet);
4095
+ return r ? { startRow: r.startRow, endRow: r.endRow, startColumn: r.startColumn, endColumn: r.endColumn } : null;
4096
+ } catch {
4097
+ return null;
4098
+ }
4099
+ };
4100
+ const sameRange = (a, b) => !a && !b || !!a && !!b && a.startRow === b.startRow && a.endRow === b.endRow && a.startColumn === b.startColumn && a.endColumn === b.endColumn;
4089
4101
  const openGroup = (label2) => ({ label: label2, order: sheetOrder(), sheets: sheetNames(), names: definedNames(), mutations: [], inverses: [], notShared: null });
4090
4102
  const emit = (e) => {
4091
4103
  for (const l of [...listeners]) {
@@ -4135,6 +4147,7 @@ function univerSheetsOtPort(o) {
4135
4147
  if (copy && "s" in copy) copy.s = styleObject(copy.s);
4136
4148
  record.cells.set(`${r}:${c}`, copy);
4137
4149
  }
4150
+ record.filter = filterOf(String(p.subUnitId ?? ""));
4138
4151
  }
4139
4152
  if (info.id === SHEET_NAME) record.name = ws.getName();
4140
4153
  pre.set(p, record);
@@ -4288,6 +4301,15 @@ function univerSheetsOtPort(o) {
4288
4301
  g.mutations.push(r.m);
4289
4302
  g.inverses.push(r.inverse);
4290
4303
  }
4304
+ const was = info.id === VALUES ? pre.get(info.params)?.filter : void 0;
4305
+ if (was && !g.notShared) {
4306
+ const sheet = String(info.params.subUnitId ?? "");
4307
+ const now = filterOf(sheet);
4308
+ if (now && !sameRange(was, now)) {
4309
+ g.mutations.push({ id: FILTER_RANGE, params: { subUnitId: sheet, range: json(now), derived: true } });
4310
+ g.inverses.push([{ id: FILTER_RANGE, params: { subUnitId: sheet, range: json(was) } }]);
4311
+ }
4312
+ }
4291
4313
  }
4292
4314
  const owedAdd = pre.get(info.params)?.addAfter;
4293
4315
  if (owedAdd?.length) runOwn(ADD_MERGE, String(info.params.subUnitId ?? ""), owedAdd, REMOVE_MERGE);
@@ -4343,8 +4365,14 @@ function univerSheetsOtPort(o) {
4343
4365
  const a = forApply(m);
4344
4366
  applying = true;
4345
4367
  try {
4368
+ const sheet = String(a.params.subUnitId ?? "");
4369
+ const filterWas = a.id === VALUES ? filterOf(sheet) : null;
4346
4370
  const ok3 = cs.syncExecuteCommand(a.id, { ...json(a.params), unitId: u }, { fromCollab: true });
4347
4371
  if (ok3 === false) throw new Error(`"${m.id}" was refused by the editor`);
4372
+ if (filterWas) {
4373
+ const now = filterOf(sheet);
4374
+ if (now && !sameRange(filterWas, now)) cs.syncExecuteCommand(FILTER_RANGE, { unitId: u, subUnitId: sheet, range: filterWas }, { onlyLocal: true });
4375
+ }
4348
4376
  if (a.id.startsWith("sheet.mutation.set-filter") || isStructuralMutation(a)) {
4349
4377
  try {
4350
4378
  cs.syncExecuteCommand("sheet.mutation.re-calc-filter", { unitId: u, subUnitId: a.params.subUnitId }, { onlyLocal: true });