@nivaro/react 0.3.103 → 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.
- package/dist/full.css +1 -1
- package/dist/hooks/useSessionRecorder.js +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/shared/components/ItemEditForm.js +2867 -2845
- package/dist/shared/components/imports/CollectionImportPanel.js +483 -459
- package/dist/shared/components/integrations/IntegrationStatusLines.js +71 -68
- package/dist/shared/components/item-edit/UserChip.js +38 -38
- package/dist/shared/components/layout-editor/DesignNode.js +16 -14
- package/dist/shared/components/layout-editor/LayoutEditor.js +445 -441
- package/dist/shared/components/layout-editor/inspector/Inspector.js +18 -18
- package/dist/shared/components/layout-editor/inspector/SlotInspector.js +80 -52
- package/dist/shared/components/layout-editor/parity-keys.json.js +1 -1
- package/dist/shared/components/layout-editor/settings/ButtonsSection.js +54 -26
- package/dist/shared/components/layout-editor/settings/settings-registry.js +23 -15
- package/dist/shared/components/layout-editor/useLayoutDraft.js +211 -196
- package/dist/shared/components/panels/ExternalRequestsChip.js +141 -122
- package/dist/shared/lib/entry-config.js +7 -7
- package/dist/shared/lib/integration-chip.js +10 -6
- package/dist/shared/lib/owners-header-tile.js +63 -0
- package/package.json +1 -1
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
var V = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { useQueryClient as
|
|
5
|
-
import { useState as Q, useRef as Y, useSyncExternalStore as G, useEffect as
|
|
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
|
|
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 {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
|
28
|
-
return
|
|
29
|
-
(e) => e.op === "layout_update" && Object.keys(e.patch ?? {}).some((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
|
|
33
|
-
function
|
|
34
|
-
if (
|
|
35
|
-
if (
|
|
36
|
-
const e = `${
|
|
37
|
-
return e.length >
|
|
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
|
|
40
|
-
function q(
|
|
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(
|
|
43
|
-
const t =
|
|
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
|
|
47
|
-
return /^No group "/.test(
|
|
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
|
|
50
|
+
function K(i, e = "The layout could not be saved") {
|
|
50
51
|
var o, u;
|
|
51
|
-
const t =
|
|
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:
|
|
55
|
+
message: ne(pe(a), e, s),
|
|
55
56
|
bundle: q(r == null ? void 0 : r.bundle)
|
|
56
57
|
};
|
|
57
58
|
}
|
|
58
|
-
const
|
|
59
|
-
function
|
|
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] =
|
|
62
|
+
for (const t of te) e[t] = i[t];
|
|
62
63
|
return e;
|
|
63
64
|
}
|
|
64
|
-
function
|
|
65
|
+
function ve(i) {
|
|
65
66
|
const e = {};
|
|
66
|
-
for (const t of ee) e[t] =
|
|
67
|
+
for (const t of ee) e[t] = i[t];
|
|
67
68
|
return e;
|
|
68
69
|
}
|
|
69
|
-
function x(
|
|
70
|
+
function x(i, e) {
|
|
70
71
|
const t = {};
|
|
71
|
-
for (const s of Object.keys(e)) t[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
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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:
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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:
|
|
141
|
+
patch: ve(t)
|
|
141
142
|
}
|
|
142
143
|
];
|
|
143
|
-
return
|
|
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
|
-
}),
|
|
146
|
-
const
|
|
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
|
-
|
|
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:
|
|
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(
|
|
159
|
+
return [{ op: "layout_update", patch: x(i.layout, e.patch ?? {}) }];
|
|
159
160
|
default:
|
|
160
161
|
return [];
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
|
-
const
|
|
164
|
-
function
|
|
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 =
|
|
168
|
-
return !!s &&
|
|
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 =
|
|
172
|
-
return !!s &&
|
|
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" ?
|
|
175
|
+
return t.op === "layout_update" ? O(i.layout, t.patch) : !1;
|
|
175
176
|
});
|
|
176
177
|
}
|
|
177
|
-
function
|
|
178
|
-
let t =
|
|
178
|
+
function m(i, e) {
|
|
179
|
+
let t = fe(i), s = [];
|
|
179
180
|
for (const r of e)
|
|
180
|
-
s = [...
|
|
181
|
+
s = [...ke(t, r), ...s], t = f(t, [r]);
|
|
181
182
|
return s;
|
|
182
183
|
}
|
|
183
|
-
function
|
|
184
|
+
function me(i) {
|
|
184
185
|
const e = [];
|
|
185
|
-
for (const t of
|
|
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 = (
|
|
205
|
-
class
|
|
205
|
+
const y = (i) => i instanceof Error ? i.message : String(i);
|
|
206
|
+
class Se {
|
|
206
207
|
constructor(e, t = {}) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
220
|
+
h(this, "checkpoint", null);
|
|
220
221
|
/** Labels of steps a rebase could not replay (#2652). */
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
252
|
-
} catch (
|
|
253
|
-
this.fail(y(
|
|
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 =
|
|
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 =
|
|
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:
|
|
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),
|
|
397
|
-
this.text.set(r, { op: a, inverse:
|
|
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((
|
|
415
|
+
const s = this.draft, r = e.map((n) => n.op);
|
|
408
416
|
this.markCheckpoint();
|
|
409
|
-
const a = e.map((
|
|
417
|
+
const a = e.map((n) => n.key).join("");
|
|
410
418
|
try {
|
|
411
419
|
f(s, r);
|
|
412
|
-
} catch (
|
|
413
|
-
this.fail(y(
|
|
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
|
|
423
|
-
|
|
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 >
|
|
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
|
|
501
|
-
o = f(o, u.ops), a.set(u.id,
|
|
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) &&
|
|
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
|
|
527
|
-
this.text.clear(), this.queue = [], this.undoStack = [], this.redoStack = [], this.transport.reload(), this.outcome = "conflict", this.error = null, this.transport.notify(
|
|
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.
|
|
531
|
-
this.queue =
|
|
532
|
-
|
|
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((
|
|
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 =
|
|
555
|
+
this.transport.reload(), this.outcome = "conflict", this.error = ce;
|
|
548
556
|
return;
|
|
549
557
|
}
|
|
550
|
-
const s = this.
|
|
551
|
-
this.unsaved =
|
|
552
|
-
|
|
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 [
|
|
572
|
+
for (const [n, c] of r.entries())
|
|
565
573
|
try {
|
|
566
|
-
e = f(e,
|
|
574
|
+
e = f(e, c.ops), o.push(c);
|
|
567
575
|
} catch (v) {
|
|
568
|
-
|
|
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
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
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
|
|
638
|
-
function
|
|
639
|
-
let
|
|
640
|
-
|
|
641
|
-
const
|
|
642
|
-
if (
|
|
643
|
-
const
|
|
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 (
|
|
646
|
-
const
|
|
647
|
-
X(`/collection-layouts/${
|
|
648
|
-
ops:
|
|
649
|
-
base_rev:
|
|
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
|
-
),
|
|
655
|
-
if (!
|
|
656
|
-
return
|
|
664
|
+
), S = q(b);
|
|
665
|
+
if (!S) throw new Error("The server answered without the saved layout");
|
|
666
|
+
return S;
|
|
657
667
|
},
|
|
658
|
-
saved: (
|
|
668
|
+
saved: (v, g) => {
|
|
659
669
|
var k, d;
|
|
660
|
-
|
|
670
|
+
u.current.qc.setQueryData(o, v), (d = (k = u.current).onSaved) == null || d.call(k, v, g);
|
|
661
671
|
},
|
|
662
672
|
reload: () => {
|
|
663
|
-
|
|
673
|
+
u.current.qc.invalidateQueries({ queryKey: o });
|
|
664
674
|
},
|
|
665
|
-
notify: (
|
|
666
|
-
H.warning(
|
|
675
|
+
notify: (v) => {
|
|
676
|
+
H.warning(v);
|
|
667
677
|
}
|
|
668
678
|
},
|
|
669
|
-
{ autosave: t }
|
|
670
|
-
), live:
|
|
671
|
-
return
|
|
679
|
+
{ autosave: t, autoOwnersTile: s }
|
|
680
|
+
), live: u };
|
|
681
|
+
return r.set(i, c), c;
|
|
672
682
|
}
|
|
673
|
-
function
|
|
674
|
-
const t =
|
|
675
|
-
return
|
|
676
|
-
queryKey:
|
|
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/${
|
|
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 &&
|
|
692
|
+
enabled: e && i != null,
|
|
683
693
|
staleTime: 15e3,
|
|
684
694
|
refetchOnWindowFocus: !1
|
|
685
695
|
});
|
|
686
696
|
}
|
|
687
|
-
function
|
|
688
|
-
const t =
|
|
689
|
-
(!u.current || u.current.id !==
|
|
690
|
-
id:
|
|
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
|
-
...
|
|
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
|
|
695
|
-
|
|
696
|
-
r.data &&
|
|
697
|
-
}, [
|
|
698
|
-
|
|
699
|
-
}, [
|
|
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) =>
|
|
702
|
-
[
|
|
703
|
-
),
|
|
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),
|
|
720
|
+
o(l), n.setAutosave(l);
|
|
706
721
|
},
|
|
707
|
-
[
|
|
708
|
-
), U = p(() =>
|
|
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
|
-
...
|
|
711
|
-
status:
|
|
712
|
-
error:
|
|
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:
|
|
715
|
-
redo:
|
|
716
|
-
flush:
|
|
717
|
-
whenIdle:
|
|
718
|
-
setAutosave:
|
|
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:
|
|
723
|
-
restore:
|
|
724
|
-
jump:
|
|
737
|
+
clearDropped: R,
|
|
738
|
+
restore: D,
|
|
739
|
+
jump: N,
|
|
725
740
|
isLoading: r.isLoading
|
|
726
741
|
};
|
|
727
742
|
}
|
|
728
743
|
export {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
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
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
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
|
};
|