@nivaro/react 0.3.102 → 0.3.104

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.
@@ -1,17 +1,18 @@
1
1
  var V = Object.defineProperty;
2
- var B = (n, e, t) => e in n ? V(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var c = (n, e, t) => B(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { useQueryClient as P, useQuery as z } from "@tanstack/react-query";
5
- import { useState as Q, useRef as Y, useSyncExternalStore as G, useEffect as b, useCallback as p } from "react";
2
+ var z = (i, e, t) => e in i ? V(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var h = (i, e, t) => z(i, typeof e != "symbol" ? e + "" : e, t);
4
+ import { useQueryClient as B, useQuery as P } from "@tanstack/react-query";
5
+ import { useState as Q, useRef as Y, useSyncExternalStore as G, useEffect as w, useCallback as p } from "react";
6
6
  import { toast as H } from "sonner";
7
- import { useNivaroClient as M } from "../../context.js";
7
+ import { useNivaroClient as C } from "../../context.js";
8
8
  import { get as J, post as X } from "../../lib/commands.js";
9
9
  import { applyLayoutOps as f, isCanvasSlot as Z, GROUP_PATCH_KEYS as ee, PLACEMENT_PATCH_KEYS as te } from "../../lib/layout-ops.js";
10
- import { plainErrorText as se } from "../../lib/safe-error.js";
11
- const C = {
12
- bundle: (n) => ["layout-editor", "bundle", n],
13
- versions: (n) => ["layout-editor", "versions", n]
14
- }, re = /* @__PURE__ */ new Set([
10
+ import { withAutoOwnersTile as se, rewriteOwnersRemove as re, materializeOwnersOps as ie } from "../../lib/owners-header-tile.js";
11
+ import { plainErrorText as ne } from "../../lib/safe-error.js";
12
+ const F = {
13
+ bundle: (i) => ["layout-editor", "bundle", i],
14
+ versions: (i) => ["layout-editor", "versions", i]
15
+ }, oe = /* @__PURE__ */ new Set([
15
16
  "name",
16
17
  "slug",
17
18
  "create_label",
@@ -24,59 +25,59 @@ const C = {
24
25
  "parent_layout_id",
25
26
  "tab_mode"
26
27
  ]);
27
- function Ee(n) {
28
- return n ? n.some(
29
- (e) => e.op === "layout_update" && Object.keys(e.patch ?? {}).some((t) => re.has(t))
28
+ function Me(i) {
29
+ return i ? i.some(
30
+ (e) => e.op === "layout_update" && Object.keys(e.patch ?? {}).some((t) => oe.has(t))
30
31
  ) : !0;
31
32
  }
32
- const ne = 600, ie = "Someone else changed this layout — reloaded", oe = (n) => `Someone else saved — your ${n} ${n === 1 ? "change was" : "changes were"} kept on top; Save again`, ae = "Someone else saved this layout and some of your changes no longer fit", ue = (n) => `Someone else saved — your ${n === 1 ? "change was" : `${n} changes were`} replayed on top of theirs`, E = (n, e) => `Someone else saved — ${n} of your changes kept, ${e} no longer ${e === 1 ? "fits" : "fit"}: redo ${e === 1 ? "it" : "them"} by hand`, w = 250;
33
- function $(n) {
34
- if (n.length === 0) return "Save";
35
- if (n.length === 1) return n[0].slice(0, w);
36
- const e = `${n.length} changes: ${n.join(", ")}`;
37
- return e.length > w ? `${e.slice(0, w - 1)}…` : e;
33
+ const ae = 600, ue = "Someone else changed this layout — reloaded", he = (i) => `Someone else saved — your ${i} ${i === 1 ? "change was" : "changes were"} kept on top; Save again`, ce = "Someone else saved this layout and some of your changes no longer fit", de = (i) => `Someone else saved — your ${i === 1 ? "change was" : `${i} changes were`} replayed on top of theirs`, $ = (i, e) => `Someone else saved — ${i} of your changes kept, ${e} no longer ${e === 1 ? "fits" : "fit"}: redo ${e === 1 ? "it" : "them"} by hand`, T = 250;
34
+ function A(i) {
35
+ if (i.length === 0) return "Save";
36
+ if (i.length === 1) return i[0].slice(0, T);
37
+ const e = `${i.length} changes: ${i.join(", ")}`;
38
+ return e.length > T ? `${e.slice(0, T - 1)}…` : e;
38
39
  }
39
- const he = 100;
40
- function q(n) {
40
+ const le = 100;
41
+ function q(i) {
41
42
  const e = (s) => !!s && typeof s == "object" && Array.isArray(s.groups) && Array.isArray(s.placements) && typeof s.rev == "string";
42
- if (e(n)) return n;
43
- const t = n == null ? void 0 : n.data;
43
+ if (e(i)) return i;
44
+ const t = i == null ? void 0 : i.data;
44
45
  return e(t) ? t : null;
45
46
  }
46
- function ce(n) {
47
- return /^No group "/.test(n) ? "That section is no longer on this form" : /^"[^"]*" is not placed in /.test(n) ? "That field is no longer where it was" : /^"[^"]*" is already in /.test(n) ? "That field is already there" : /^"[^"]*" is not on this form/.test(n) ? "That item is no longer on this form" : /^"[^"]*" is not a container/.test(n) ? "Tabs can only go inside a tab group" : /^"[^"]*" is a reserved name/.test(n) ? "That name is reserved" : /^A group "[^"]*" already exists/.test(n) ? "A section with that key already exists" : /^Unknown setting "/.test(n) ? "That setting can’t be saved on this form" : n;
47
+ function pe(i) {
48
+ return /^No group "/.test(i) ? "That section is no longer on this form" : /^"[^"]*" is not placed in /.test(i) ? "That field is no longer where it was" : /^"[^"]*" is already in /.test(i) ? "That field is already there" : /^"[^"]*" is not on this form/.test(i) ? "That item is no longer on this form" : /^"[^"]*" is not a container/.test(i) ? "Tabs can only go inside a tab group" : /^"[^"]*" is a reserved name/.test(i) ? "That name is reserved" : /^A group "[^"]*" already exists/.test(i) ? "A section with that key already exists" : /^Unknown setting "/.test(i) ? "That setting can’t be saved on this form" : i;
48
49
  }
49
- function F(n, e = "The layout could not be saved") {
50
+ function K(i, e = "The layout could not be saved") {
50
51
  var o, u;
51
- const t = n, s = (t == null ? void 0 : t.status) ?? ((o = t == null ? void 0 : t.response) == null ? void 0 : o.status) ?? null, r = ((u = t == null ? void 0 : t.response) == null ? void 0 : u.data) ?? (t == null ? void 0 : t.response), a = typeof (r == null ? void 0 : r.error) == "string" && r.error || typeof (r == null ? void 0 : r.message) == "string" && r.message || typeof (t == null ? void 0 : t.message) == "string" && t.message || e;
52
+ const t = i, s = (t == null ? void 0 : t.status) ?? ((o = t == null ? void 0 : t.response) == null ? void 0 : o.status) ?? null, r = ((u = t == null ? void 0 : t.response) == null ? void 0 : u.data) ?? (t == null ? void 0 : t.response), a = typeof (r == null ? void 0 : r.error) == "string" && r.error || typeof (r == null ? void 0 : r.message) == "string" && r.message || typeof (t == null ? void 0 : t.message) == "string" && t.message || e;
52
53
  return {
53
54
  status: s,
54
- message: se(ce(a), e, s),
55
+ message: ne(pe(a), e, s),
55
56
  bundle: q(r == null ? void 0 : r.bundle)
56
57
  };
57
58
  }
58
- const de = (n) => f(n, [{ op: "layout_update", patch: {} }]), S = (n, e) => n.placements.find((t) => t.field === e.field && t.group_key === (e.group_key ?? null));
59
- function A(n) {
59
+ const fe = (i) => f(i, [{ op: "layout_update", patch: {} }]), _ = (i, e) => i.placements.find((t) => t.field === e.field && t.group_key === (e.group_key ?? null));
60
+ function I(i) {
60
61
  const e = {};
61
- for (const t of te) e[t] = n[t];
62
+ for (const t of te) e[t] = i[t];
62
63
  return e;
63
64
  }
64
- function le(n) {
65
+ function ve(i) {
65
66
  const e = {};
66
- for (const t of ee) e[t] = n[t];
67
+ for (const t of ee) e[t] = i[t];
67
68
  return e;
68
69
  }
69
- function x(n, e) {
70
+ function x(i, e) {
70
71
  const t = {};
71
- for (const s of Object.keys(e)) t[s] = n[s] === void 0 ? null : n[s];
72
+ for (const s of Object.keys(e)) t[s] = i[s] === void 0 ? null : i[s];
72
73
  return t;
73
74
  }
74
- function pe(n, e) {
75
+ function ke(i, e) {
75
76
  switch (e.op) {
76
77
  case "place":
77
78
  return [{ op: "remove", at: { field: e.field, group_key: e.group_key ?? null } }];
78
79
  case "move": {
79
- const t = S(n, e.from);
80
+ const t = _(i, e.from);
80
81
  return t ? [
81
82
  {
82
83
  op: "move",
@@ -87,7 +88,7 @@ function pe(n, e) {
87
88
  ] : [];
88
89
  }
89
90
  case "update_placement": {
90
- const t = S(n, e.at);
91
+ const t = _(i, e.at);
91
92
  return t ? [
92
93
  {
93
94
  op: "update_placement",
@@ -97,21 +98,21 @@ function pe(n, e) {
97
98
  ] : [];
98
99
  }
99
100
  case "remove": {
100
- const t = S(n, e.at);
101
+ const t = _(i, e.at);
101
102
  return t ? [
102
103
  {
103
104
  op: "place",
104
105
  field: t.field,
105
106
  group_key: t.group_key,
106
107
  index: t.sort,
107
- patch: A(t)
108
+ patch: I(t)
108
109
  }
109
110
  ] : [];
110
111
  }
111
112
  case "group_create":
112
113
  return [{ op: "group_remove", key: e.key, placements: "delete" }];
113
114
  case "group_update": {
114
- const t = n.groups.find((s) => s.key === e.key);
115
+ const t = i.groups.find((s) => s.key === e.key);
115
116
  return t ? [
116
117
  {
117
118
  op: "group_update",
@@ -121,13 +122,13 @@ function pe(n, e) {
121
122
  ] : [];
122
123
  }
123
124
  case "group_move": {
124
- const t = n.groups.find((r) => r.key === e.key);
125
+ const t = i.groups.find((r) => r.key === e.key);
125
126
  if (t) return [{ op: "group_move", key: e.key, parent_key: t.parent_key, index: t.sort }];
126
- const s = n.placements.find((r) => r.field === e.key && Z(r));
127
+ const s = i.placements.find((r) => r.field === e.key && Z(r));
127
128
  return s ? [{ op: "group_move", key: e.key, parent_key: null, index: s.sort }] : [];
128
129
  }
129
130
  case "group_remove": {
130
- const t = n.groups.find((o) => o.key === e.key);
131
+ const t = i.groups.find((o) => o.key === e.key);
131
132
  if (!t) return [];
132
133
  const s = [
133
134
  {
@@ -137,52 +138,52 @@ function pe(n, e) {
137
138
  group_type: t.type,
138
139
  parent_key: t.parent_key,
139
140
  index: t.sort,
140
- patch: le(t)
141
+ patch: ve(t)
141
142
  }
142
143
  ];
143
- return n.groups.filter((o) => o.parent_key === t.key).sort((o, u) => o.sort - u.sort).forEach((o, u) => {
144
+ return i.groups.filter((o) => o.parent_key === t.key).sort((o, u) => o.sort - u.sort).forEach((o, u) => {
144
145
  s.push({ op: "group_move", key: o.key, parent_key: t.key, index: u });
145
- }), n.placements.filter((o) => o.group_key === t.key).sort((o, u) => o.sort - u.sort).forEach((o, u) => {
146
- const i = e.placements === "ungroup" && !n.placements.some((h) => h.field === o.field && h.group_key === null);
146
+ }), i.placements.filter((o) => o.group_key === t.key).sort((o, u) => o.sort - u.sort).forEach((o, u) => {
147
+ const n = e.placements === "ungroup" && !i.placements.some((c) => c.field === o.field && c.group_key === null);
147
148
  s.push(
148
- i ? {
149
+ n ? {
149
150
  op: "move",
150
151
  from: { field: o.field, group_key: null },
151
152
  to_group_key: t.key,
152
153
  index: u
153
- } : { op: "place", field: o.field, group_key: t.key, index: u, patch: A(o) }
154
+ } : { op: "place", field: o.field, group_key: t.key, index: u, patch: I(o) }
154
155
  );
155
156
  }), s;
156
157
  }
157
158
  case "layout_update":
158
- return [{ op: "layout_update", patch: x(n.layout, e.patch ?? {}) }];
159
+ return [{ op: "layout_update", patch: x(i.layout, e.patch ?? {}) }];
159
160
  default:
160
161
  return [];
161
162
  }
162
163
  }
163
- const fe = (n, e) => JSON.stringify(n ?? null) === JSON.stringify(e ?? null), T = (n, e) => Object.entries(e ?? {}).every(([t, s]) => fe(n[t], s));
164
- function ve(n, e) {
164
+ const ye = (i, e) => JSON.stringify(i ?? null) === JSON.stringify(e ?? null), O = (i, e) => Object.entries(e ?? {}).every(([t, s]) => ye(i[t], s));
165
+ function ge(i, e) {
165
166
  return e.length === 0 ? !1 : e.every((t) => {
166
167
  if (t.op === "update_placement") {
167
- const s = S(n, t.at);
168
- return !!s && T(s, t.patch);
168
+ const s = _(i, t.at);
169
+ return !!s && O(s, t.patch);
169
170
  }
170
171
  if (t.op === "group_update") {
171
- const s = n.groups.find((r) => r.key === t.key);
172
- return !!s && T(s, t.patch);
172
+ const s = i.groups.find((r) => r.key === t.key);
173
+ return !!s && O(s, t.patch);
173
174
  }
174
- return t.op === "layout_update" ? T(n.layout, t.patch) : !1;
175
+ return t.op === "layout_update" ? O(i.layout, t.patch) : !1;
175
176
  });
176
177
  }
177
- function g(n, e) {
178
- let t = de(n), s = [];
178
+ function m(i, e) {
179
+ let t = fe(i), s = [];
179
180
  for (const r of e)
180
- s = [...pe(t, r), ...s], t = f(t, [r]);
181
+ s = [...ke(t, r), ...s], t = f(t, [r]);
181
182
  return s;
182
183
  }
183
- function ke(n) {
184
+ function me(i) {
184
185
  const e = [];
185
- for (const t of n)
186
+ for (const t of i)
186
187
  if (t.op === "update_placement")
187
188
  for (const [s, r] of Object.entries(t.patch ?? {}))
188
189
  e.push({
@@ -201,34 +202,36 @@ function ke(n) {
201
202
  else return null;
202
203
  return e;
203
204
  }
204
- const y = (n) => n instanceof Error ? n.message : String(n);
205
- class ye {
205
+ const y = (i) => i instanceof Error ? i.message : String(i);
206
+ class Se {
206
207
  constructor(e, t = {}) {
207
- c(this, "server", null);
208
- c(this, "draft", null);
209
- c(this, "queue", []);
208
+ h(this, "server", null);
209
+ h(this, "draft", null);
210
+ h(this, "queue", []);
210
211
  /** Manual mode: steps folded into the draft, not sent yet (oldest first). */
211
- c(this, "unsaved", []);
212
- c(this, "inFlight", !1);
213
- c(this, "text", /* @__PURE__ */ new Map());
214
- c(this, "undoStack", []);
215
- c(this, "redoStack", []);
216
- c(this, "outcome", "idle");
217
- c(this, "error", null);
212
+ h(this, "unsaved", []);
213
+ h(this, "inFlight", !1);
214
+ h(this, "text", /* @__PURE__ */ new Map());
215
+ h(this, "undoStack", []);
216
+ h(this, "redoStack", []);
217
+ h(this, "outcome", "idle");
218
+ h(this, "error", null);
218
219
  /** Undo / redo as they were when the first unsaved step was made: Discard puts them back. */
219
- c(this, "checkpoint", null);
220
+ h(this, "checkpoint", null);
220
221
  /** Labels of steps a rebase could not replay (#2652). */
221
- c(this, "dropped", []);
222
- c(this, "autosave");
223
- c(this, "nextId", 1);
224
- c(this, "listeners", /* @__PURE__ */ new Set());
225
- c(this, "idleWaiters", []);
226
- c(this, "view");
227
- c(this, "subscribe", (e) => (this.listeners.add(e), () => {
222
+ h(this, "dropped", []);
223
+ h(this, "autosave");
224
+ /** The automatic Owners header tile rides the draft as a placement (lib/owners-header-tile.ts). */
225
+ h(this, "autoOwners");
226
+ h(this, "nextId", 1);
227
+ h(this, "listeners", /* @__PURE__ */ new Set());
228
+ h(this, "idleWaiters", []);
229
+ h(this, "view");
230
+ h(this, "subscribe", (e) => (this.listeners.add(e), () => {
228
231
  this.listeners.delete(e);
229
232
  }));
230
- c(this, "getView", () => this.view);
231
- this.transport = e, this.autosave = t.autosave ?? !1, this.view = this.buildView();
233
+ h(this, "getView", () => this.view);
234
+ this.transport = e, this.autosave = t.autosave ?? !1, this.autoOwners = t.autoOwnersTile ?? !1, this.view = this.buildView();
232
235
  }
233
236
  /**
234
237
  * A fetched bundle. Ignored while anything is pending or unsaved, so typing
@@ -238,19 +241,24 @@ class ye {
238
241
  * state) would undo over their change — so the history goes.
239
242
  */
240
243
  receive(e) {
241
- this.isBusy() || this.server && this.server.rev === e.rev || (this.server && (this.undoStack = [], this.redoStack = []), this.server = e, this.draft = e, this.emit());
244
+ this.isBusy() || this.server && this.server.rev === e.rev || (this.server && (this.undoStack = [], this.redoStack = []), this.server = this.based(e), this.draft = this.server, this.emit());
245
+ }
246
+ /** A server bundle as the draft's base: with the automatic Owners tile when it applies. */
247
+ based(e) {
248
+ return this.autoOwners ? se(e) : e;
242
249
  }
243
250
  apply(e, t) {
244
251
  if (!this.draft || e.length === 0) return;
245
- const s = (t == null ? void 0 : t.label) ?? "Edit", r = t != null && t.text ? ke(e) : null;
252
+ this.autoOwners && (e = re(this.draft, e));
253
+ const s = (t == null ? void 0 : t.label) ?? "Edit", r = t != null && t.text ? me(e) : null;
246
254
  if (r) return this.autosave ? this.applyText(r, s) : this.stageText(r, s);
247
255
  this.flushText(), this.markCheckpoint();
248
256
  const a = this.draft;
249
257
  let o;
250
258
  try {
251
- f(a, e), o = g(a, e);
252
- } catch (i) {
253
- this.fail(y(i));
259
+ f(a, e), o = m(a, e);
260
+ } catch (n) {
261
+ this.fail(y(n));
254
262
  return;
255
263
  }
256
264
  this.clearOutcome();
@@ -281,7 +289,7 @@ class ye {
281
289
  const e = this.redoStack.pop();
282
290
  if (!(!e || !this.draft)) {
283
291
  try {
284
- f(this.draft, e.forward), e.inverse = g(this.draft, e.forward);
292
+ f(this.draft, e.forward), e.inverse = m(this.draft, e.forward);
285
293
  } catch (t) {
286
294
  this.fail(`Could not redo: ${y(t)}`);
287
295
  return;
@@ -322,13 +330,13 @@ class ye {
322
330
  const s = this.queue.length > (this.inFlight ? 1 : 0) ? this.queue[this.queue.length - 1] : void 0;
323
331
  if ((s == null ? void 0 : s.kind) === "save") {
324
332
  const r = [...s.parts ?? [], ...t];
325
- s.parts = r, s.ops = r.flatMap((a) => a.ops), s.note = $(r.map((a) => a.note)), e && (s.meta = e);
333
+ s.parts = r, s.ops = r.flatMap((a) => a.ops), s.note = A(r.map((a) => a.note)), e && (s.meta = e);
326
334
  } else
327
335
  this.queue.push({
328
336
  id: this.nextId++,
329
337
  kind: "save",
330
338
  ops: t.flatMap((r) => r.ops),
331
- note: $(t.map((r) => r.note)),
339
+ note: A(t.map((r) => r.note)),
332
340
  parts: t,
333
341
  meta: e
334
342
  });
@@ -393,8 +401,8 @@ class ye {
393
401
  for (const { key: r, op: a } of e) {
394
402
  const o = this.text.get(r);
395
403
  o && clearTimeout(o.timer);
396
- const u = setTimeout(() => this.flushTextKey(r), ne), i = (o == null ? void 0 : o.inverse) ?? g(s, [a])[0];
397
- this.text.set(r, { op: a, inverse: i, label: t, timer: u });
404
+ const u = setTimeout(() => this.flushTextKey(r), ae), n = (o == null ? void 0 : o.inverse) ?? m(s, [a])[0];
405
+ this.text.set(r, { op: a, inverse: n, label: t, timer: u });
398
406
  }
399
407
  this.redoStack = [], this.refresh();
400
408
  }
@@ -404,13 +412,13 @@ class ye {
404
412
  * back to the value before its first keystroke.
405
413
  */
406
414
  stageText(e, t) {
407
- const s = this.draft, r = e.map((i) => i.op);
415
+ const s = this.draft, r = e.map((n) => n.op);
408
416
  this.markCheckpoint();
409
- const a = e.map((i) => i.key).join("");
417
+ const a = e.map((n) => n.key).join("");
410
418
  try {
411
419
  f(s, r);
412
- } catch (i) {
413
- this.fail(y(i));
420
+ } catch (n) {
421
+ this.fail(y(n));
414
422
  return;
415
423
  }
416
424
  this.clearOutcome();
@@ -419,8 +427,8 @@ class ye {
419
427
  o.ops = r, u.forward = r;
420
428
  else {
421
429
  this.closeText();
422
- const i = this.add("do", r, t);
423
- i.textKey = a, this.pushUndo({ label: t, forward: r, inverse: g(s, r), batchId: i.id });
430
+ const n = this.add("do", r, t);
431
+ n.textKey = a, this.pushUndo({ label: t, forward: r, inverse: m(s, r), batchId: n.id });
424
432
  }
425
433
  this.redoStack = [], this.refresh();
426
434
  }
@@ -458,7 +466,7 @@ class ye {
458
466
  return this.queue.push(r), r;
459
467
  }
460
468
  pushUndo(e) {
461
- this.undoStack.push(e), this.undoStack.length > he && this.undoStack.shift();
469
+ this.undoStack.push(e), this.undoStack.length > le && this.undoStack.shift();
462
470
  }
463
471
  pending() {
464
472
  return this.inFlight || this.queue.length > 0 || this.text.size > 0;
@@ -497,8 +505,8 @@ class ye {
497
505
  let o = e;
498
506
  for (const u of t)
499
507
  try {
500
- const i = g(o, u.ops);
501
- o = f(o, u.ops), a.set(u.id, i), s.push(u);
508
+ const n = m(o, u.ops);
509
+ o = f(o, u.ops), a.set(u.id, n), s.push(u);
502
510
  } catch {
503
511
  r.push(u);
504
512
  }
@@ -511,7 +519,7 @@ class ye {
511
519
  */
512
520
  rebaseUndo(e, t, s) {
513
521
  this.undoStack = this.undoStack.filter(
514
- (r) => t.has(r.batchId) || !s.has(r.batchId) && ve(e, r.forward)
522
+ (r) => t.has(r.batchId) || !s.has(r.batchId) && ge(e, r.forward)
515
523
  );
516
524
  for (const r of this.undoStack) r.inverse = t.get(r.batchId) ?? r.inverse;
517
525
  this.redoStack = [];
@@ -523,13 +531,13 @@ class ye {
523
531
  */
524
532
  conflict(e) {
525
533
  if (!e) {
526
- for (const s of this.text.values()) clearTimeout(s.timer);
527
- this.text.clear(), this.queue = [], this.undoStack = [], this.redoStack = [], this.transport.reload(), this.outcome = "conflict", this.error = null, this.transport.notify(ie);
534
+ for (const r of this.text.values()) clearTimeout(r.timer);
535
+ this.text.clear(), this.queue = [], this.undoStack = [], this.redoStack = [], this.transport.reload(), this.outcome = "conflict", this.error = null, this.transport.notify(ue);
528
536
  return;
529
537
  }
530
- const t = this.refold(e, this.queue);
531
- this.queue = t.kept, this.server = e, this.transport.saved(e, null), this.rebaseUndo(e, t.inverses, new Set(t.dropped.map((s) => s.id))), this.dropped = [...this.dropped, ...t.dropped.map((s) => s.note)], this.outcome = "idle", this.error = null, this.transport.notify(
532
- t.dropped.length === 0 ? ue(t.kept.length) : E(t.kept.length, t.dropped.length)
538
+ const t = this.based(e), s = this.refold(t, this.queue);
539
+ this.queue = s.kept, this.server = t, this.transport.saved(e, null), this.rebaseUndo(t, s.inverses, new Set(s.dropped.map((r) => r.id))), this.dropped = [...this.dropped, ...s.dropped.map((r) => r.note)], this.outcome = "idle", this.error = null, this.transport.notify(
540
+ s.dropped.length === 0 ? de(s.kept.length) : $(s.kept.length, s.dropped.length)
533
541
  );
534
542
  }
535
543
  /**
@@ -540,16 +548,16 @@ class ye {
540
548
  */
541
549
  rebase(e) {
542
550
  const t = [
543
- ...this.queue.flatMap((r) => r.kind === "save" ? r.parts ?? [] : [r]),
551
+ ...this.queue.flatMap((a) => a.kind === "save" ? a.parts ?? [] : [a]),
544
552
  ...this.unsaved
545
553
  ];
546
554
  if (this.queue = [], this.unsaved = t, this.checkpoint = null, this.closeText(), !e) {
547
- this.transport.reload(), this.outcome = "conflict", this.error = ae;
555
+ this.transport.reload(), this.outcome = "conflict", this.error = ce;
548
556
  return;
549
557
  }
550
- const s = this.refold(e, t);
551
- this.unsaved = s.kept, this.server = e, this.transport.saved(e, null), this.rebaseUndo(e, s.inverses, new Set(s.dropped.map((r) => r.id))), this.dropped = [...this.dropped, ...s.dropped.map((r) => r.note)], this.outcome = "idle", this.error = null, this.transport.notify(
552
- s.dropped.length === 0 ? oe(s.kept.length) : E(s.kept.length, s.dropped.length)
558
+ const s = this.based(e), r = this.refold(s, t);
559
+ this.unsaved = r.kept, this.server = s, this.transport.saved(e, null), this.rebaseUndo(s, r.inverses, new Set(r.dropped.map((a) => a.id))), this.dropped = [...this.dropped, ...r.dropped.map((a) => a.note)], this.outcome = "idle", this.error = null, this.transport.notify(
560
+ r.dropped.length === 0 ? he(r.kept.length) : $(r.kept.length, r.dropped.length)
553
561
  );
554
562
  }
555
563
  /** Draft = server bundle + queued batches + unsaved steps + typed text; then send the next batch. */
@@ -561,11 +569,11 @@ class ye {
561
569
  let e = this.server;
562
570
  const t = (r, a) => {
563
571
  const o = [], u = [];
564
- for (const [i, h] of r.entries())
572
+ for (const [n, c] of r.entries())
565
573
  try {
566
- e = f(e, h.ops), o.push(h);
574
+ e = f(e, c.ops), o.push(c);
567
575
  } catch (v) {
568
- i === 0 && a ? o.push(h) : h.kind === "save" ? u.push(...h.parts ?? []) : (this.rollback(h), this.error ?? (this.error = y(v)), this.outcome = "error");
576
+ n === 0 && a ? o.push(c) : c.kind === "save" ? u.push(...c.parts ?? []) : (this.rollback(c), this.error ?? (this.error = y(v)), this.outcome = "error");
569
577
  }
570
578
  return { kept: o, restored: u };
571
579
  }, s = t(this.queue, this.inFlight);
@@ -581,11 +589,13 @@ class ye {
581
589
  pump() {
582
590
  if (this.inFlight || !this.server || this.queue.length === 0) return;
583
591
  const e = this.queue[0];
584
- this.inFlight = !0, this.transport.send(e.ops, this.server.rev, e.note, e.meta).then((t) => {
585
- this.server = t, this.queue.shift(), this.transport.saved(t, e.ops), this.outcome !== "error" && (this.outcome = "saved");
586
- }).catch((t) => {
587
- const s = F(t);
588
- s.status === 409 && e.kind === "save" ? this.rebase(s.bundle) : s.status === 409 ? this.conflict(s.bundle) : e.kind === "save" ? (this.queue.shift(), this.unsaved = [...e.parts ?? [], ...this.unsaved], this.error = s.message, this.outcome = "error") : (this.queue.shift(), this.rollback(e), this.error = s.message, this.outcome = "error");
592
+ this.inFlight = !0;
593
+ const t = this.autoOwners ? ie(this.server, e.ops) : e.ops;
594
+ this.transport.send(t, this.server.rev, e.note, e.meta).then((s) => {
595
+ this.server = this.based(s), this.queue.shift(), this.transport.saved(s, e.ops), this.outcome !== "error" && (this.outcome = "saved");
596
+ }).catch((s) => {
597
+ const r = K(s);
598
+ r.status === 409 && e.kind === "save" ? this.rebase(r.bundle) : r.status === 409 ? this.conflict(r.bundle) : e.kind === "save" ? (this.queue.shift(), this.unsaved = [...e.parts ?? [], ...this.unsaved], this.error = r.message, this.outcome = "error") : (this.queue.shift(), this.rollback(e), this.error = r.message, this.outcome = "error");
589
599
  }).finally(() => {
590
600
  this.inFlight = !1, this.refresh();
591
601
  });
@@ -634,113 +644,118 @@ class ye {
634
644
  }
635
645
  }
636
646
  }
637
- const I = /* @__PURE__ */ new WeakMap();
638
- function ge(n, e, t) {
639
- let s = I.get(e.qc);
640
- s || (s = /* @__PURE__ */ new Map(), I.set(e.qc, s));
641
- const r = s.get(n);
642
- if (r != null && r.engine.isBusy()) return r;
643
- const a = C.bundle(n), o = { current: e }, i = { engine: new ye(
647
+ const M = /* @__PURE__ */ new WeakMap();
648
+ function _e(i, e, t, s = !1) {
649
+ let r = M.get(e.qc);
650
+ r || (r = /* @__PURE__ */ new Map(), M.set(e.qc, r));
651
+ const a = r.get(i);
652
+ if (a != null && a.engine.isBusy()) return a;
653
+ const o = F.bundle(i), u = { current: e }, c = { engine: new Se(
644
654
  {
645
- send: async (h, v, k, d) => {
646
- const _ = await o.current.client.request(
647
- X(`/collection-layouts/${n}/ops`, {
648
- ops: h,
649
- base_rev: v,
655
+ send: async (v, g, k, d) => {
656
+ const b = await u.current.client.request(
657
+ X(`/collection-layouts/${i}/ops`, {
658
+ ops: v,
659
+ base_rev: g,
650
660
  note: k,
651
661
  ...d ? { reason: d.reason, ticket: d.ticket ?? null } : {},
652
662
  ...d != null && d.freeze_override ? { freeze_override: d.freeze_override } : {}
653
663
  })
654
- ), m = q(_);
655
- if (!m) throw new Error("The server answered without the saved layout");
656
- return m;
664
+ ), S = q(b);
665
+ if (!S) throw new Error("The server answered without the saved layout");
666
+ return S;
657
667
  },
658
- saved: (h, v) => {
668
+ saved: (v, g) => {
659
669
  var k, d;
660
- o.current.qc.setQueryData(a, h), (d = (k = o.current).onSaved) == null || d.call(k, h, v);
670
+ u.current.qc.setQueryData(o, v), (d = (k = u.current).onSaved) == null || d.call(k, v, g);
661
671
  },
662
672
  reload: () => {
663
- o.current.qc.invalidateQueries({ queryKey: a });
673
+ u.current.qc.invalidateQueries({ queryKey: o });
664
674
  },
665
- notify: (h) => {
666
- H.warning(h);
675
+ notify: (v) => {
676
+ H.warning(v);
667
677
  }
668
678
  },
669
- { autosave: t }
670
- ), live: o };
671
- return s.set(n, i), i;
679
+ { autosave: t, autoOwnersTile: s }
680
+ ), live: u };
681
+ return r.set(i, c), c;
672
682
  }
673
- function me(n, e = !0) {
674
- const t = M();
675
- return z({
676
- queryKey: C.bundle(n ?? 0),
683
+ function be(i, e = !0) {
684
+ const t = C();
685
+ return P({
686
+ queryKey: F.bundle(i ?? 0),
677
687
  queryFn: async () => {
678
- const s = await t.request(J(`/collection-layouts/${n}/bundle`)), r = q(s);
688
+ const s = await t.request(J(`/collection-layouts/${i}/bundle`)), r = q(s);
679
689
  if (!r) throw new Error("The layout could not be read");
680
690
  return r;
681
691
  },
682
- enabled: e && n != null,
692
+ enabled: e && i != null,
683
693
  staleTime: 15e3,
684
694
  refetchOnWindowFocus: !1
685
695
  });
686
696
  }
687
- function $e(n, e = {}) {
688
- const t = M(), s = P(), r = me(n), [a, o] = Q(e.autosave ?? !1), u = Y(null);
689
- (!u.current || u.current.id !== n || u.current.qc !== s) && (u.current = {
690
- id: n,
697
+ function Ce(i, e = {}) {
698
+ const t = C(), s = B(), r = be(i), [a, o] = Q(e.autosave ?? !1), u = Y(null);
699
+ (!u.current || u.current.id !== i || u.current.qc !== s) && (u.current = {
700
+ id: i,
691
701
  qc: s,
692
- ...ge(n, { client: t, qc: s, onSaved: e.onSaved }, a)
702
+ ..._e(
703
+ i,
704
+ { client: t, qc: s, onSaved: e.onSaved },
705
+ a,
706
+ e.autoOwnersTile === !0
707
+ )
693
708
  }), u.current.live.current = { client: t, qc: s, onSaved: e.onSaved };
694
- const i = u.current.engine, h = G(i.subscribe, i.getView, i.getView);
695
- b(() => {
696
- r.data && i.receive(r.data);
697
- }, [i, r.data]), b(() => {
698
- i.setAutosave(a);
699
- }, [i, a]), b(() => () => i.flushText(), [i]);
709
+ const n = u.current.engine, c = G(n.subscribe, n.getView, n.getView);
710
+ w(() => {
711
+ r.data && n.receive(r.data);
712
+ }, [n, r.data]), w(() => {
713
+ n.setAutosave(a);
714
+ }, [n, a]), w(() => () => n.flushText(), [n]);
700
715
  const v = p(
701
- (l, W) => i.apply(l, W),
702
- [i]
703
- ), k = p(() => i.undo(), [i]), d = p(() => i.redo(), [i]), _ = p(() => i.flushText(), [i]), m = p((l) => i.whenIdle(l), [i]), K = p(
716
+ (l, W) => n.apply(l, W),
717
+ [n]
718
+ ), g = p(() => n.undo(), [n]), k = p(() => n.redo(), [n]), d = p(() => n.flushText(), [n]), b = p((l) => n.whenIdle(l), [n]), S = p(
704
719
  (l) => {
705
- o(l), i.setAutosave(l);
720
+ o(l), n.setAutosave(l);
706
721
  },
707
- [i]
708
- ), U = p(() => i.unsavedOps(), [i]), L = p((l) => i.save(l), [i]), j = p(() => i.discard(), [i]), D = p(() => i.clearDropped(), [i]), N = p((l) => i.restore(l), [i]), R = p((l) => i.jump(l), [i]), O = !h.bundle && r.error != null;
722
+ [n]
723
+ ), U = p(() => n.unsavedOps(), [n]), L = p((l) => n.save(l), [n]), j = p(() => n.discard(), [n]), R = p(() => n.clearDropped(), [n]), D = p((l) => n.restore(l), [n]), N = p((l) => n.jump(l), [n]), E = !c.bundle && r.error != null;
709
724
  return {
710
- ...h,
711
- status: O ? "error" : h.status,
712
- error: h.error ?? (O ? F(r.error, "The layout could not be read").message : null),
725
+ ...c,
726
+ status: E ? "error" : c.status,
727
+ error: c.error ?? (E ? K(r.error, "The layout could not be read").message : null),
713
728
  apply: v,
714
- undo: k,
715
- redo: d,
716
- flush: _,
717
- whenIdle: m,
718
- setAutosave: K,
729
+ undo: g,
730
+ redo: k,
731
+ flush: d,
732
+ whenIdle: b,
733
+ setAutosave: S,
719
734
  unsavedOps: U,
720
735
  save: L,
721
736
  discard: j,
722
- clearDropped: D,
723
- restore: N,
724
- jump: R,
737
+ clearDropped: R,
738
+ restore: D,
739
+ jump: N,
725
740
  isLoading: r.isLoading
726
741
  };
727
742
  }
728
743
  export {
729
- ie as CONFLICT_MESSAGE,
730
- ye as LayoutDraftEngine,
731
- ae as REBASE_FAILED_MESSAGE,
732
- ne as TEXT_DEBOUNCE_MS,
733
- ce as humanizeOpError,
734
- g as inverseOps,
735
- C as layoutDraftKeys,
744
+ ue as CONFLICT_MESSAGE,
745
+ Se as LayoutDraftEngine,
746
+ ce as REBASE_FAILED_MESSAGE,
747
+ ae as TEXT_DEBOUNCE_MS,
748
+ pe as humanizeOpError,
749
+ m as inverseOps,
750
+ F as layoutDraftKeys,
736
751
  q as parseBundle,
737
- F as parseSaveFailure,
738
- E as partlyRebasedMessage,
739
- oe as rebasedMessage,
740
- ue as replayedMessage,
741
- $ as saveNote,
742
- ve as stillMine,
743
- Ee as touchesOverview,
744
- me as useLayoutBundle,
745
- $e as useLayoutDraft
752
+ K as parseSaveFailure,
753
+ $ as partlyRebasedMessage,
754
+ he as rebasedMessage,
755
+ de as replayedMessage,
756
+ A as saveNote,
757
+ ge as stillMine,
758
+ Me as touchesOverview,
759
+ be as useLayoutBundle,
760
+ Ce as useLayoutDraft
746
761
  };