@lupinum/ginko-editor 0.1.0 → 0.18.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.
- package/CHANGELOG.md +7 -73
- package/LICENSE +1 -1
- package/README.md +15 -340
- package/dist/assets.d.ts +70 -0
- package/dist/assets.js +31 -0
- package/dist/core/component-props.d.ts +87 -0
- package/dist/core/component-props.js +134 -0
- package/dist/core/convert.d.ts +24 -0
- package/dist/core/convert.js +278 -0
- package/dist/core/editor.d.ts +60 -0
- package/dist/core/editor.js +85 -0
- package/dist/core/extensions.d.ts +38 -0
- package/dist/core/extensions.js +444 -0
- package/dist/core/file-images.d.ts +9 -0
- package/dist/core/file-images.js +54 -0
- package/dist/core/image-frame.d.ts +23 -0
- package/dist/core/image-frame.js +24 -0
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.js +17 -0
- package/dist/core/link-card.d.ts +20 -0
- package/dist/core/link-card.js +70 -0
- package/dist/core/link.d.ts +3 -0
- package/dist/core/link.js +8 -0
- package/dist/core/move.d.ts +11 -0
- package/dist/core/move.js +37 -0
- package/dist/core/paste-html.d.ts +6 -0
- package/dist/core/paste-html.js +384 -0
- package/dist/core/paste.d.ts +21 -0
- package/dist/core/paste.js +108 -0
- package/dist/core/problems.d.ts +31 -0
- package/dist/core/problems.js +54 -0
- package/dist/core/search.d.ts +47 -0
- package/dist/core/search.js +148 -0
- package/dist/core/slash.d.ts +93 -0
- package/dist/core/slash.js +215 -0
- package/dist/core/table.d.ts +34 -0
- package/dist/core/table.js +141 -0
- package/dist/core/uploads.d.ts +23 -0
- package/dist/core/uploads.js +71 -0
- package/dist/core/use-editor.d.ts +19 -0
- package/dist/core/use-editor.js +53 -0
- package/dist/index.d.ts +6 -15
- package/dist/index.js +6 -5668
- package/dist/issues.d.ts +49 -0
- package/dist/issues.js +9 -0
- package/dist/today.d.ts +6 -0
- package/dist/today.js +19 -0
- package/dist/useUpload.d.ts +48 -0
- package/dist/useUpload.js +59 -0
- package/dist/values.d.ts +14 -0
- package/dist/values.js +36 -0
- package/package.json +35 -95
- package/dist/GinkoEditor.vue.d.ts +0 -96
- package/dist/GinkoImagePicker.vue.d.ts +0 -36
- package/dist/agent/AGENTS.md +0 -13
- package/dist/agent/pages/docs/getting-started/collaboration.md +0 -435
- package/dist/agent/pages/docs/getting-started/component-coverage.md +0 -107
- package/dist/agent/pages/docs/getting-started/customize.md +0 -384
- package/dist/agent/pages/docs/getting-started/images.md +0 -188
- package/dist/agent/pages/docs/getting-started/in-place-editing.md +0 -110
- package/dist/agent/pages/docs/getting-started/layout-blocks.md +0 -148
- package/dist/agent/pages/docs/getting-started/runtime.md +0 -111
- package/dist/agent/pages/docs/getting-started.md +0 -128
- package/dist/authoring-D7MJezVG.js +0 -1780
- package/dist/authoring-D7MJezVG.js.map +0 -1
- package/dist/authoring.d.ts +0 -122
- package/dist/authoring.js +0 -2
- package/dist/collaboration.d.ts +0 -14
- package/dist/collaboration.js +0 -907
- package/dist/collaboration.js.map +0 -1
- package/dist/composables/useAssetRequests.d.ts +0 -44
- package/dist/composables/useCollaborationBinding.d.ts +0 -59
- package/dist/composables/useDevice.d.ts +0 -10
- package/dist/composables/useInsertMenu.d.ts +0 -67
- package/dist/composables/useMarkdownSync.d.ts +0 -96
- package/dist/composables/useStableAuthoringKit.d.ts +0 -16
- package/dist/documentConfig-Z6LdrWZj.js +0 -2360
- package/dist/documentConfig-Z6LdrWZj.js.map +0 -1
- package/dist/editorProps.d.ts +0 -124
- package/dist/index.js.map +0 -1
- package/dist/layout-kit.d.ts +0 -922
- package/dist/lib/collaboration/presence-record.d.ts +0 -18
- package/dist/lib/collaboration/presence.d.ts +0 -103
- package/dist/lib/collaboration/protocol.d.ts +0 -133
- package/dist/lib/collaboration/recovery.d.ts +0 -45
- package/dist/lib/collaboration/session.d.ts +0 -163
- package/dist/lib/collaboration/validation.d.ts +0 -42
- package/dist/lib/component-converters.d.ts +0 -119
- package/dist/lib/config/documentConfig.d.ts +0 -19
- package/dist/lib/config/editorConfig.d.ts +0 -38
- package/dist/lib/container-items.d.ts +0 -55
- package/dist/lib/conversionInvariants.d.ts +0 -3
- package/dist/lib/conversionLogger.d.ts +0 -10
- package/dist/lib/conversionPipeline.d.ts +0 -17
- package/dist/lib/conversionState.d.ts +0 -10
- package/dist/lib/conversionTypes.d.ts +0 -50
- package/dist/lib/editor-operations.d.ts +0 -39
- package/dist/lib/environment.d.ts +0 -6
- package/dist/lib/extensions/code-block.d.ts +0 -18
- package/dist/lib/extensions/component-boundary.d.ts +0 -9
- package/dist/lib/extensions/container-items.d.ts +0 -29
- package/dist/lib/extensions/element.d.ts +0 -19
- package/dist/lib/extensions/file.d.ts +0 -24
- package/dist/lib/extensions/heading.d.ts +0 -5
- package/dist/lib/extensions/image-upload.d.ts +0 -39
- package/dist/lib/extensions/image.d.ts +0 -39
- package/dist/lib/extensions/index.d.ts +0 -10
- package/dist/lib/extensions/inline-element.d.ts +0 -13
- package/dist/lib/extensions/markdown-clipboard.d.ts +0 -21
- package/dist/lib/extensions/profile.d.ts +0 -11
- package/dist/lib/extensions/slot.d.ts +0 -16
- package/dist/lib/extensions/span-style.d.ts +0 -15
- package/dist/lib/extensions/video.d.ts +0 -15
- package/dist/lib/image-properties.d.ts +0 -20
- package/dist/lib/input-rules.d.ts +0 -7
- package/dist/lib/markdown.d.ts +0 -11
- package/dist/lib/marks.d.ts +0 -7
- package/dist/lib/mdcToTiptap.d.ts +0 -20
- package/dist/lib/mdcTypes.d.ts +0 -20
- package/dist/lib/nodes.d.ts +0 -57
- package/dist/lib/nodeviews/block-actions.d.ts +0 -7
- package/dist/lib/nodeviews/code.d.ts +0 -4
- package/dist/lib/nodeviews/columns.d.ts +0 -17
- package/dist/lib/nodeviews/component.d.ts +0 -6
- package/dist/lib/nodeviews/icons.d.ts +0 -26
- package/dist/lib/nodeviews/image.d.ts +0 -9
- package/dist/lib/nodeviews/items.d.ts +0 -15
- package/dist/lib/nodeviews/lifecycle.d.ts +0 -45
- package/dist/lib/nodeviews/popover.d.ts +0 -15
- package/dist/lib/nodeviews/settings.d.ts +0 -11
- package/dist/lib/nodeviews/table-operations.d.ts +0 -50
- package/dist/lib/nodeviews/table.d.ts +0 -4
- package/dist/lib/profiles.d.ts +0 -62
- package/dist/lib/property-input.d.ts +0 -10
- package/dist/lib/property-step.d.ts +0 -77
- package/dist/lib/props.d.ts +0 -13
- package/dist/lib/stripStyleNodes.d.ts +0 -2
- package/dist/lib/tiptapToMdc.d.ts +0 -18
- package/dist/presence-record-CLdPZWKC.js +0 -291
- package/dist/presence-record-CLdPZWKC.js.map +0 -1
- package/dist/runtime.d.ts +0 -13
- package/dist/runtime.js +0 -3
- package/dist/style.css +0 -2
- package/dist/types.d.ts +0 -126
- package/dist/ui/GinkoActionButton.vue.d.ts +0 -8
- package/dist/ui/GinkoInsertMenu.vue.d.ts +0 -49
- package/dist/ui/GinkoKeyboardDock.vue.d.ts +0 -15
- package/dist/ui/GinkoNodePopover.vue.d.ts +0 -21
- package/dist/ui/GinkoRecipeIcon.vue.d.ts +0 -6
- package/dist/ui/GinkoSelectionToolbar.vue.d.ts +0 -10
- package/dist/ui/GinkoToolbar.vue.d.ts +0 -26
- package/dist/ui/GinkoToolbarIcon.vue.d.ts +0 -6
- package/dist/ui/block-shortcuts.d.ts +0 -6
- package/dist/ui/commands.d.ts +0 -78
- package/dist/ui/context.d.ts +0 -23
- package/dist/ui/editor-keyboard.d.ts +0 -15
- package/dist/ui/messages.d.ts +0 -214
- package/dist/ui/messages.de.d.ts +0 -6
- package/dist/ui/recipe-command.d.ts +0 -14
- package/dist/ui/recipe-search.d.ts +0 -47
- package/dist/ui/slash-command.d.ts +0 -17
- package/dist/ui/writingRecipes.d.ts +0 -13
- package/skills/ginko-editor/SKILL.md +0 -40
- package/skills/ginko-editor/agents/openai.yaml +0 -4
- package/skills/ginko-editor/references/in-place-editing.md +0 -50
- package/skills/ginko-editor/references/quickstart.md +0 -55
package/dist/collaboration.js
DELETED
|
@@ -1,907 +0,0 @@
|
|
|
1
|
-
import { a as e, g as t, n } from "./documentConfig-Z6LdrWZj.js";
|
|
2
|
-
import { c as r, d as i, l as a, m as o, n as s, o as c, r as l, s as u, t as d, u as f } from "./presence-record-CLdPZWKC.js";
|
|
3
|
-
import { Mapping as p, ReplaceStep as m, Transform as h } from "@tiptap/pm/transform";
|
|
4
|
-
import { Plugin as g, PluginKey as _ } from "@tiptap/pm/state";
|
|
5
|
-
import { Extension as v } from "@tiptap/core";
|
|
6
|
-
import { Decoration as y, DecorationSet as b } from "@tiptap/pm/view";
|
|
7
|
-
import { collab as x, getVersion as S, receiveTransaction as C, sendableSteps as w } from "prosemirror-collab";
|
|
8
|
-
//#region src/lib/collaboration/presence.ts
|
|
9
|
-
var T = class {
|
|
10
|
-
start;
|
|
11
|
-
limit;
|
|
12
|
-
maps = [];
|
|
13
|
-
constructor(e, t = 512) {
|
|
14
|
-
this.start = e, this.limit = t;
|
|
15
|
-
}
|
|
16
|
-
get end() {
|
|
17
|
-
return this.start + this.maps.length;
|
|
18
|
-
}
|
|
19
|
-
append(e, t) {
|
|
20
|
-
if (e !== this.end && (this.start = e, this.maps = []), this.maps.push(...t), this.maps.length > this.limit) {
|
|
21
|
-
let e = this.maps.length - this.limit;
|
|
22
|
-
this.maps.splice(0, e), this.start += e;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
reset(e) {
|
|
26
|
-
this.start = e, this.maps = [];
|
|
27
|
-
}
|
|
28
|
-
mapping(e, t) {
|
|
29
|
-
return e < this.start || t > this.end || e > t ? null : new p(this.maps.slice(e - this.start, t - this.start));
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
function E(e, t) {
|
|
33
|
-
let { anchor: n, head: r } = e.selection, i = w(e);
|
|
34
|
-
if (i) {
|
|
35
|
-
let e = new p(i.steps.map((e) => e.getMap())).invert();
|
|
36
|
-
n = e.map(n, -1), r = e.map(r, -1);
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
anchor: D(n, t),
|
|
40
|
-
head: D(r, t)
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function D(e, t) {
|
|
44
|
-
return Math.max(0, Math.min(t, e));
|
|
45
|
-
}
|
|
46
|
-
function O(e, t, n, r, i) {
|
|
47
|
-
let a = S(e);
|
|
48
|
-
if (r > a || a - r > i) return null;
|
|
49
|
-
let o = new p();
|
|
50
|
-
if (r < a) {
|
|
51
|
-
let e = t.mapping(r, a);
|
|
52
|
-
if (!e) return null;
|
|
53
|
-
o.appendMapping(e);
|
|
54
|
-
}
|
|
55
|
-
let s = w(e);
|
|
56
|
-
if (s) for (let e of s.steps) o.appendMap(e.getMap());
|
|
57
|
-
let c = e.doc.content.size;
|
|
58
|
-
return {
|
|
59
|
-
anchor: D(o.map(n.anchor), c),
|
|
60
|
-
head: D(o.map(n.head), c)
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function k(e) {
|
|
64
|
-
return () => {
|
|
65
|
-
let t = document.createElement("span");
|
|
66
|
-
if (t.className = "ginko-collab-caret", t.setAttribute("aria-hidden", "true"), t.setAttribute("contenteditable", "false"), t.style.setProperty("--ginko-collab-color", e.user.color), e.user.name) {
|
|
67
|
-
let n = document.createElement("span");
|
|
68
|
-
n.className = "ginko-collab-caret__label", n.textContent = e.user.name, t.append(n);
|
|
69
|
-
}
|
|
70
|
-
return t;
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
function A(e, t) {
|
|
74
|
-
let n = [];
|
|
75
|
-
for (let e of t) {
|
|
76
|
-
if (!e.selection) continue;
|
|
77
|
-
let { anchor: t, head: r } = e.selection, i = Math.min(t, r), a = Math.max(t, r);
|
|
78
|
-
i !== a && n.push(y.inline(i, a, {
|
|
79
|
-
class: "ginko-collab-selection",
|
|
80
|
-
style: `--ginko-collab-color: ${e.user.color}`
|
|
81
|
-
}, { peer: e.clientId })), n.push(y.widget(r, k(e), {
|
|
82
|
-
side: 10,
|
|
83
|
-
ignoreSelection: !0,
|
|
84
|
-
key: `ginko-collab:${e.clientId}:${e.user.color}:${e.user.name}`
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
87
|
-
return b.create(e, n);
|
|
88
|
-
}
|
|
89
|
-
var j = class {
|
|
90
|
-
options;
|
|
91
|
-
peersById = /* @__PURE__ */ new Map();
|
|
92
|
-
listeners = /* @__PURE__ */ new Set();
|
|
93
|
-
user;
|
|
94
|
-
mapped = Object.freeze([]);
|
|
95
|
-
cache;
|
|
96
|
-
revision = 0;
|
|
97
|
-
unsubscribe;
|
|
98
|
-
publishTimer;
|
|
99
|
-
heartbeat;
|
|
100
|
-
expiry;
|
|
101
|
-
dirty = !1;
|
|
102
|
-
lastPublishedAt = -Infinity;
|
|
103
|
-
lastSent;
|
|
104
|
-
stopped = !1;
|
|
105
|
-
constructor(e) {
|
|
106
|
-
this.options = e, e.user && (this.user = l(e.user, e.clientId));
|
|
107
|
-
}
|
|
108
|
-
get throttleMs() {
|
|
109
|
-
return this.options.throttleMs ?? 100;
|
|
110
|
-
}
|
|
111
|
-
get heartbeatMs() {
|
|
112
|
-
return this.options.heartbeatMs ?? 1e4;
|
|
113
|
-
}
|
|
114
|
-
get expiryMs() {
|
|
115
|
-
return this.options.expiryMs ?? 3e4;
|
|
116
|
-
}
|
|
117
|
-
get maxVersionLag() {
|
|
118
|
-
return this.options.maxVersionLag ?? 256;
|
|
119
|
-
}
|
|
120
|
-
start() {
|
|
121
|
-
try {
|
|
122
|
-
this.unsubscribe = this.options.channel.subscribe((e) => {
|
|
123
|
-
this.receive(e);
|
|
124
|
-
});
|
|
125
|
-
} catch {}
|
|
126
|
-
this.user && (this.heartbeat = setInterval(() => {
|
|
127
|
-
this.publish(!0);
|
|
128
|
-
}, this.heartbeatMs), this.changed()), this.expiry = setInterval(() => {
|
|
129
|
-
this.expire();
|
|
130
|
-
}, Math.max(250, Math.min(5e3, this.expiryMs / 3)));
|
|
131
|
-
}
|
|
132
|
-
stop(e = !1) {
|
|
133
|
-
if (!this.stopped) {
|
|
134
|
-
this.stopped = !0, clearTimeout(this.publishTimer), clearInterval(this.heartbeat), clearInterval(this.expiry);
|
|
135
|
-
try {
|
|
136
|
-
this.unsubscribe?.();
|
|
137
|
-
} catch {}
|
|
138
|
-
if (this.user) try {
|
|
139
|
-
Promise.resolve(this.options.channel.leave?.(this.options.clientId)).catch(() => {});
|
|
140
|
-
} catch {}
|
|
141
|
-
this.peersById.clear(), this.update(), this.listeners.clear(), e && this.options.redraw();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
get peers() {
|
|
145
|
-
return this.mapped;
|
|
146
|
-
}
|
|
147
|
-
onPeersChange(e) {
|
|
148
|
-
return this.listeners.add(e), e(this.mapped), () => {
|
|
149
|
-
this.listeners.delete(e);
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
changed() {
|
|
153
|
-
if (!this.user || this.stopped || (this.dirty = !0, this.publishTimer)) return;
|
|
154
|
-
let e = Math.max(0, this.lastPublishedAt + this.throttleMs - Date.now());
|
|
155
|
-
this.publishTimer = setTimeout(() => {
|
|
156
|
-
this.publishTimer = void 0, this.dirty && this.publish(!1);
|
|
157
|
-
}, e);
|
|
158
|
-
}
|
|
159
|
-
publish(e) {
|
|
160
|
-
let t = this.options.getState();
|
|
161
|
-
if (!this.user || this.stopped || !t) return;
|
|
162
|
-
this.dirty = !1;
|
|
163
|
-
let n = E(t, this.options.getConfirmedSize()), r = {
|
|
164
|
-
protocolVersion: 1,
|
|
165
|
-
clientId: this.options.clientId,
|
|
166
|
-
user: this.user,
|
|
167
|
-
epoch: this.options.epoch,
|
|
168
|
-
version: S(t),
|
|
169
|
-
selection: n,
|
|
170
|
-
updatedAt: Date.now()
|
|
171
|
-
}, i = JSON.stringify([
|
|
172
|
-
r.version,
|
|
173
|
-
n,
|
|
174
|
-
this.user
|
|
175
|
-
]);
|
|
176
|
-
if (!(!e && i === this.lastSent)) {
|
|
177
|
-
this.lastSent = i, this.lastPublishedAt = r.updatedAt;
|
|
178
|
-
try {
|
|
179
|
-
Promise.resolve(this.options.channel.publish(r)).catch(() => {});
|
|
180
|
-
} catch {}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
receive(e) {
|
|
184
|
-
if (this.stopped || !Array.isArray(e)) return;
|
|
185
|
-
let t = Date.now(), n = /* @__PURE__ */ new Set();
|
|
186
|
-
for (let r of e.slice(0, 256)) {
|
|
187
|
-
let e = s(r);
|
|
188
|
-
if (!e || e.clientId === this.options.clientId || e.epoch !== this.options.epoch || n.has(e.clientId)) continue;
|
|
189
|
-
n.add(e.clientId);
|
|
190
|
-
let i = this.peersById.get(e.clientId), a = !i || i.update.updatedAt !== e.updatedAt || JSON.stringify(i.update) !== JSON.stringify(e);
|
|
191
|
-
this.peersById.set(e.clientId, {
|
|
192
|
-
update: e,
|
|
193
|
-
receivedAt: a ? t : i.receivedAt
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
for (let e of [...this.peersById.keys()]) n.has(e) || this.peersById.delete(e);
|
|
197
|
-
this.expire(t, !0);
|
|
198
|
-
}
|
|
199
|
-
expire(e = Date.now(), t = !1) {
|
|
200
|
-
let n = !1;
|
|
201
|
-
for (let [t, r] of this.peersById) e - r.receivedAt > this.expiryMs && (this.peersById.delete(t), n = !0);
|
|
202
|
-
(n || t) && this.update();
|
|
203
|
-
}
|
|
204
|
-
update() {
|
|
205
|
-
this.revision += 1, this.mapped = this.map(this.options.getState());
|
|
206
|
-
for (let e of this.listeners) e(this.mapped);
|
|
207
|
-
this.stopped || this.options.redraw();
|
|
208
|
-
}
|
|
209
|
-
map(e) {
|
|
210
|
-
return Object.freeze([...this.peersById.values()].map(({ update: t }) => Object.freeze({
|
|
211
|
-
clientId: t.clientId,
|
|
212
|
-
user: t.user,
|
|
213
|
-
version: t.version,
|
|
214
|
-
updatedAt: t.updatedAt,
|
|
215
|
-
selection: e && t.selection ? O(e, this.options.history, t.selection, t.version, this.maxVersionLag) : null
|
|
216
|
-
})));
|
|
217
|
-
}
|
|
218
|
-
decorations(e) {
|
|
219
|
-
let t = S(e), n = this.cache;
|
|
220
|
-
if (n && n.doc === e.doc && n.version === t && n.revision === this.revision) return n.set;
|
|
221
|
-
let r = this.map(e), i = A(e.doc, r);
|
|
222
|
-
return this.cache = {
|
|
223
|
-
doc: e.doc,
|
|
224
|
-
version: t,
|
|
225
|
-
revision: this.revision,
|
|
226
|
-
peers: r,
|
|
227
|
-
set: i
|
|
228
|
-
}, i;
|
|
229
|
-
}
|
|
230
|
-
}, M = new _("ginkoCollaborationRemote"), N = new _("ginkoCollaborationPresence"), P = 2048, ee = 2 * 1024 * 1024, F = 4 * 1024 * 1024, I = 16 * 1024 * 1024, L = .5, R = 64, z = new TextEncoder();
|
|
231
|
-
function B(e) {
|
|
232
|
-
let t = [];
|
|
233
|
-
for (let n = 0; n < e.steps.length; n++) (n === 0 || e.origins[n] !== e.origins[n - 1]) && t.push([]), t.at(-1).push(JSON.stringify(e.steps[n].toJSON()));
|
|
234
|
-
return t;
|
|
235
|
-
}
|
|
236
|
-
var V = class extends a {
|
|
237
|
-
constructor(e = "Connection lost. Your changes are kept in this editor.") {
|
|
238
|
-
super("unavailable", e), this.name = "CollaborationConnectionError";
|
|
239
|
-
}
|
|
240
|
-
}, H = class extends V {
|
|
241
|
-
constructor() {
|
|
242
|
-
super("The server did not answer in time. Your changes are kept in this editor."), this.name = "CollaborationTimeoutError";
|
|
243
|
-
}
|
|
244
|
-
}, U = class extends a {
|
|
245
|
-
stateCode;
|
|
246
|
-
constructor(e, t, n) {
|
|
247
|
-
super(e, n), this.stateCode = t;
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
function W(e) {
|
|
251
|
-
if (z.encode(e).byteLength > I) throw new a("limit", "The editor recovery copy is too large.");
|
|
252
|
-
let t;
|
|
253
|
-
try {
|
|
254
|
-
t = JSON.parse(e);
|
|
255
|
-
} catch {
|
|
256
|
-
throw new a("invalid", "Invalid editor recovery copy.");
|
|
257
|
-
}
|
|
258
|
-
if (!t || typeof t != "object" || !("format" in t) || t.format !== 1 || !("clientId" in t) || typeof t.clientId != "string" || !("document" in t) || typeof t.document != "string" || !("steps" in t) || !Array.isArray(t.steps) || !t.steps.every((e) => typeof e == "string") || !("groups" in t) || !Array.isArray(t.groups) || !t.groups.every((e) => typeof e == "number") || !("base" in t) || !t.base || typeof t.base != "object") throw new a("invalid", "Invalid editor recovery copy.");
|
|
259
|
-
let n = t.base;
|
|
260
|
-
if (!("epoch" in n) || typeof n.epoch != "string" || !("schemaRevision" in n) || typeof n.schemaRevision != "string" || !("policyRevision" in n) || typeof n.policyRevision != "string" || !("version" in n) || typeof n.version != "number" || !("document" in n) || typeof n.document != "string") throw new a("invalid", "Invalid editor recovery base.");
|
|
261
|
-
return {
|
|
262
|
-
format: 1,
|
|
263
|
-
clientId: t.clientId,
|
|
264
|
-
document: t.document,
|
|
265
|
-
steps: t.steps,
|
|
266
|
-
groups: t.groups,
|
|
267
|
-
base: {
|
|
268
|
-
epoch: n.epoch,
|
|
269
|
-
schemaRevision: n.schemaRevision,
|
|
270
|
-
policyRevision: n.policyRevision,
|
|
271
|
-
version: n.version,
|
|
272
|
-
document: n.document
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
var G = {
|
|
277
|
-
offline: "unavailable",
|
|
278
|
-
timeout: "unavailable",
|
|
279
|
-
unavailable: "unavailable",
|
|
280
|
-
rejected: "content",
|
|
281
|
-
forbidden: "forbidden",
|
|
282
|
-
schema_mismatch: "schema",
|
|
283
|
-
policy_mismatch: "policy",
|
|
284
|
-
replaced: "epoch",
|
|
285
|
-
history_expired: "version",
|
|
286
|
-
conflict: "version",
|
|
287
|
-
storage: "limit",
|
|
288
|
-
limit: "limit",
|
|
289
|
-
internal: "invalid"
|
|
290
|
-
}, K = {
|
|
291
|
-
epoch: "replaced",
|
|
292
|
-
schema: "schema_mismatch",
|
|
293
|
-
policy: "policy_mismatch",
|
|
294
|
-
history: "history_expired"
|
|
295
|
-
}, q = /network|timed? ?out|timeout|temporarily|unavailable|ECONN|EPIPE|ENOTFOUND|EAI_AGAIN|socket|fetch failed|failed to fetch/i;
|
|
296
|
-
function J(e) {
|
|
297
|
-
if ("code" in e && typeof e.code == "string") return e.code;
|
|
298
|
-
if ("data" in e && e.data && typeof e.data == "object" && "code" in e.data) return e.data.code;
|
|
299
|
-
}
|
|
300
|
-
function Y(e) {
|
|
301
|
-
for (let t of ["status", "statusCode"]) if (t in e && typeof e[t] == "number") return e[t];
|
|
302
|
-
}
|
|
303
|
-
function X(e, t = !1) {
|
|
304
|
-
let n = e instanceof Error && e.message ? e.message : "Synchronization failed. Keep this editor open and retry.";
|
|
305
|
-
if (e instanceof U) return {
|
|
306
|
-
status: [
|
|
307
|
-
"schema_mismatch",
|
|
308
|
-
"policy_mismatch",
|
|
309
|
-
"replaced"
|
|
310
|
-
].includes(e.stateCode) ? "stale" : "error",
|
|
311
|
-
code: e.stateCode,
|
|
312
|
-
message: n
|
|
313
|
-
};
|
|
314
|
-
if (e instanceof H) return {
|
|
315
|
-
status: "offline",
|
|
316
|
-
code: "timeout",
|
|
317
|
-
message: n
|
|
318
|
-
};
|
|
319
|
-
if (e instanceof V) return {
|
|
320
|
-
status: "offline",
|
|
321
|
-
code: "offline",
|
|
322
|
-
message: n
|
|
323
|
-
};
|
|
324
|
-
if (e && typeof e == "object") {
|
|
325
|
-
let r = J(e), i = Y(e);
|
|
326
|
-
if (r === "unavailable" || i !== void 0 && (i >= 500 || [
|
|
327
|
-
408,
|
|
328
|
-
425,
|
|
329
|
-
429
|
|
330
|
-
].includes(i))) return {
|
|
331
|
-
status: "offline",
|
|
332
|
-
code: "unavailable",
|
|
333
|
-
message: n
|
|
334
|
-
};
|
|
335
|
-
if ([
|
|
336
|
-
"forbidden",
|
|
337
|
-
"unauthenticated",
|
|
338
|
-
"unauthorized"
|
|
339
|
-
].includes(String(r)) || i === 401 || i === 403) return {
|
|
340
|
-
status: "error",
|
|
341
|
-
code: "forbidden",
|
|
342
|
-
message: n
|
|
343
|
-
};
|
|
344
|
-
if (r === "schema" || r === "protocol") return {
|
|
345
|
-
status: "stale",
|
|
346
|
-
code: "schema_mismatch",
|
|
347
|
-
message: n
|
|
348
|
-
};
|
|
349
|
-
if (r === "policy") return {
|
|
350
|
-
status: "stale",
|
|
351
|
-
code: "policy_mismatch",
|
|
352
|
-
message: n
|
|
353
|
-
};
|
|
354
|
-
if (r === "epoch") return {
|
|
355
|
-
status: "stale",
|
|
356
|
-
code: "replaced",
|
|
357
|
-
message: n
|
|
358
|
-
};
|
|
359
|
-
if (r === "version") return {
|
|
360
|
-
status: "error",
|
|
361
|
-
code: "conflict",
|
|
362
|
-
message: n
|
|
363
|
-
};
|
|
364
|
-
if ([
|
|
365
|
-
"content",
|
|
366
|
-
"invalid",
|
|
367
|
-
"limit"
|
|
368
|
-
].includes(String(r))) return {
|
|
369
|
-
status: "error",
|
|
370
|
-
code: t ? "rejected" : "internal",
|
|
371
|
-
message: n
|
|
372
|
-
};
|
|
373
|
-
if (e instanceof Error && ([
|
|
374
|
-
"AbortError",
|
|
375
|
-
"TimeoutError",
|
|
376
|
-
"NetworkError"
|
|
377
|
-
].includes(e.name) || q.test(e.message))) return {
|
|
378
|
-
status: "offline",
|
|
379
|
-
code: e.name === "TimeoutError" ? "timeout" : "unavailable",
|
|
380
|
-
message: n
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
return {
|
|
384
|
-
status: "error",
|
|
385
|
-
code: t ? "rejected" : "internal",
|
|
386
|
-
message: n
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
var Z = class {
|
|
390
|
-
options;
|
|
391
|
-
extension;
|
|
392
|
-
initialDocument;
|
|
393
|
-
initial;
|
|
394
|
-
clientId;
|
|
395
|
-
collabPlugin;
|
|
396
|
-
history;
|
|
397
|
-
presence;
|
|
398
|
-
instance;
|
|
399
|
-
confirmed;
|
|
400
|
-
current;
|
|
401
|
-
listeners = /* @__PURE__ */ new Set();
|
|
402
|
-
unsubscribe;
|
|
403
|
-
timer;
|
|
404
|
-
timerDue = Infinity;
|
|
405
|
-
busy = !1;
|
|
406
|
-
requested = !1;
|
|
407
|
-
generation = 0;
|
|
408
|
-
observedVersion;
|
|
409
|
-
attempt = 0;
|
|
410
|
-
restored = !1;
|
|
411
|
-
restoring = !1;
|
|
412
|
-
orphanOwnSteps = !1;
|
|
413
|
-
recoveryTimer;
|
|
414
|
-
recoveryDirty = !1;
|
|
415
|
-
recoveryStored;
|
|
416
|
-
stepSizes = /* @__PURE__ */ new WeakMap();
|
|
417
|
-
docSizes = /* @__PURE__ */ new WeakMap();
|
|
418
|
-
estimate;
|
|
419
|
-
removeWindowListeners;
|
|
420
|
-
constructor(e) {
|
|
421
|
-
this.options = e, Object.defineProperty(this, "__v_skip", { value: !0 }), f(e.snapshot);
|
|
422
|
-
let t = e.recovery;
|
|
423
|
-
if (t) {
|
|
424
|
-
if (t.format !== 1 || !Array.isArray(t.steps) || t.steps.length > P || !Array.isArray(t.groups) || t.groups.some((e) => !Number.isSafeInteger(e) || e <= 0 || e > i.stepsPerBatch) || t.groups.reduce((e, t) => e + t, 0) !== t.steps.length || z.encode(JSON.stringify(t)).byteLength > I) throw new a("invalid", "Invalid editor recovery copy.");
|
|
425
|
-
f(t.base);
|
|
426
|
-
let n = o(t.base, e.snapshot);
|
|
427
|
-
if (n) throw new a(n, "This recovery copy belongs to an older document. Keep it before reopening.");
|
|
428
|
-
if (t.base.version > e.snapshot.version) throw new a("version", "The server is older than this recovery copy.");
|
|
429
|
-
}
|
|
430
|
-
if (this.initial = { ...t?.base ?? e.snapshot }, delete this.initial.protocolVersion, this.clientId = t?.clientId ?? e.clientId, typeof this.clientId != "string" || !this.clientId || this.clientId.length > 200) throw new a("invalid", "Invalid editor client ID.");
|
|
431
|
-
if (this.confirmed = c(this.initial.document), t) {
|
|
432
|
-
let e = new h(this.confirmed), n = 0;
|
|
433
|
-
for (let r of t.groups) {
|
|
434
|
-
for (let i of u(t.steps.slice(n, n + r), this.confirmed.type.schema)) e.step(i);
|
|
435
|
-
n += r;
|
|
436
|
-
}
|
|
437
|
-
if (JSON.stringify(e.doc.toJSON()) !== t.document) throw new a("invalid", "The recovery copy does not match its pending steps.");
|
|
438
|
-
}
|
|
439
|
-
this.recoveryStored = !!t?.steps.length, this.initialDocument = this.confirmed.toJSON(), this.observedVersion = e.snapshot.version, this.history = new T(this.initial.version), this.current = {
|
|
440
|
-
status: "connecting",
|
|
441
|
-
version: this.initial.version,
|
|
442
|
-
pendingSteps: t?.steps.length ?? 0
|
|
443
|
-
}, this.collabPlugin = x({
|
|
444
|
-
version: this.initial.version,
|
|
445
|
-
clientID: this.clientId
|
|
446
|
-
});
|
|
447
|
-
let n = e.presence === !1 ? void 0 : e.transport.presence;
|
|
448
|
-
n && (this.presence = new j({
|
|
449
|
-
...e.presence || {},
|
|
450
|
-
clientId: this.clientId,
|
|
451
|
-
epoch: this.initial.epoch,
|
|
452
|
-
channel: n,
|
|
453
|
-
user: e.user,
|
|
454
|
-
history: this.history,
|
|
455
|
-
getState: () => this.instance?.isDestroyed === !1 ? this.instance.state : void 0,
|
|
456
|
-
getConfirmedSize: () => this.confirmed.content.size,
|
|
457
|
-
redraw: () => {
|
|
458
|
-
let e = this.instance;
|
|
459
|
-
e && !e.isDestroyed && e.view.dispatch(e.state.tr.setMeta(N, !0).setMeta("addToHistory", !1));
|
|
460
|
-
}
|
|
461
|
-
}));
|
|
462
|
-
let r = this.presence;
|
|
463
|
-
this.extension = v.create({
|
|
464
|
-
name: "ginkoCollaboration",
|
|
465
|
-
priority: 1e3,
|
|
466
|
-
addProseMirrorPlugins: () => [
|
|
467
|
-
this.collabPlugin,
|
|
468
|
-
new g({ filterTransaction: (e, t) => this.filterLocal(e, t) }),
|
|
469
|
-
...r ? [new g({
|
|
470
|
-
key: N,
|
|
471
|
-
props: { decorations: (e) => r.decorations(e) }
|
|
472
|
-
})] : []
|
|
473
|
-
],
|
|
474
|
-
onCreate: ({ editor: e }) => {
|
|
475
|
-
this.attach(e);
|
|
476
|
-
},
|
|
477
|
-
onTransaction: ({ transaction: e }) => {
|
|
478
|
-
(e.docChanged || e.getMeta(M)) && this.changed(), !e.getMeta(N) && (e.docChanged || e.selectionSet || e.getMeta(M)) && this.presence?.changed();
|
|
479
|
-
},
|
|
480
|
-
onDestroy: () => {
|
|
481
|
-
this.close();
|
|
482
|
-
}
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
get state() {
|
|
486
|
-
return this.current;
|
|
487
|
-
}
|
|
488
|
-
get canEdit() {
|
|
489
|
-
return ![
|
|
490
|
-
"error",
|
|
491
|
-
"stale",
|
|
492
|
-
"closed"
|
|
493
|
-
].includes(this.current.status) && this.current.pendingSteps < P;
|
|
494
|
-
}
|
|
495
|
-
get peers() {
|
|
496
|
-
return this.presence?.peers ?? [];
|
|
497
|
-
}
|
|
498
|
-
onPeersChange(e) {
|
|
499
|
-
return this.presence ? this.presence.onPeersChange(e) : (e([]), () => {});
|
|
500
|
-
}
|
|
501
|
-
subscribe(e) {
|
|
502
|
-
return this.listeners.add(e), e(this.current), () => {
|
|
503
|
-
this.listeners.delete(e);
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
setState(e, t, n) {
|
|
507
|
-
let r = {
|
|
508
|
-
status: e,
|
|
509
|
-
version: this.instance ? S(this.instance.state) : this.initial.version,
|
|
510
|
-
pendingSteps: this.instance ? w(this.instance.state)?.steps.length ?? 0 : this.current.pendingSteps
|
|
511
|
-
};
|
|
512
|
-
r.pendingSteps >= P ? (r.message = "Reconnect to continue writing. This editor has reached its unsent change limit.", r.code = "limit") : (t && (r.message = t), n && (r.code = n)), this.current = Object.freeze(r);
|
|
513
|
-
for (let e of this.listeners) e(this.current);
|
|
514
|
-
}
|
|
515
|
-
refuse(e) {
|
|
516
|
-
return this.setState(this.current.status, e, "limit"), !1;
|
|
517
|
-
}
|
|
518
|
-
stepSize(e) {
|
|
519
|
-
let t = this.stepSizes.get(e);
|
|
520
|
-
return t === void 0 && (t = z.encode(JSON.stringify(e.toJSON())).byteLength, this.stepSizes.set(e, t)), t;
|
|
521
|
-
}
|
|
522
|
-
docSize(e) {
|
|
523
|
-
let t = this.docSizes.get(e);
|
|
524
|
-
return t === void 0 && (t = z.encode(JSON.stringify(e.toJSON())).byteLength, this.docSizes.set(e, t)), t;
|
|
525
|
-
}
|
|
526
|
-
nextDocumentSize(e, t, n, r) {
|
|
527
|
-
let a = this.docSizes.get(e) ?? (this.estimate?.doc === e ? this.estimate.bytes : void 0), o = this.estimate?.doc === e ? this.estimate.count : 0;
|
|
528
|
-
if (a !== void 0 && o < R && n.every((e) => e instanceof m)) {
|
|
529
|
-
let e = a + 2 * r;
|
|
530
|
-
if (e < i.documentBytes * L) return this.estimate = {
|
|
531
|
-
doc: t,
|
|
532
|
-
bytes: e,
|
|
533
|
-
count: o + 1
|
|
534
|
-
}, e;
|
|
535
|
-
}
|
|
536
|
-
let s = this.docSize(t);
|
|
537
|
-
return this.estimate = {
|
|
538
|
-
doc: t,
|
|
539
|
-
bytes: s,
|
|
540
|
-
count: 0
|
|
541
|
-
}, s;
|
|
542
|
-
}
|
|
543
|
-
filterLocal(e, t) {
|
|
544
|
-
if (!e.docChanged || e.getMeta(M)) return !0;
|
|
545
|
-
if (!this.canEdit) return !1;
|
|
546
|
-
let n = e.steps.reduce((e, t) => e + this.stepSize(t), 0);
|
|
547
|
-
if (e.steps.length > i.stepsPerBatch || n > i.batchBytes) return this.refuse("This change is too large. Insert a smaller part of the content.");
|
|
548
|
-
let r = w(t);
|
|
549
|
-
if ((r?.steps.length ?? 0) + e.steps.length > P) return !1;
|
|
550
|
-
let a = r?.steps.reduce((e, t) => e + this.stepSize(t), 0) ?? 0, o = "Reconnect before adding more changes. The recovery copy has reached its size limit.";
|
|
551
|
-
if (a + n > ee) return this.refuse(o);
|
|
552
|
-
let s = this.nextDocumentSize(t.doc, e.doc, e.steps, n);
|
|
553
|
-
if (s > i.documentBytes) return this.refuse("This change is too large. Insert a smaller part of the content.");
|
|
554
|
-
let c = (r?.steps.length ?? 0) + e.steps.length;
|
|
555
|
-
if (2 * (this.docSize(this.confirmed) + s + a + n) + 16 * c + 4096 <= F) return !0;
|
|
556
|
-
if (this.docSize(e.doc) > i.documentBytes) return this.refuse("This change is too large. Insert a smaller part of the content.");
|
|
557
|
-
let l = r?.steps.map((e) => JSON.stringify(e.toJSON())) ?? [], u = e.steps.map((e) => JSON.stringify(e.toJSON())), d = {
|
|
558
|
-
format: 1,
|
|
559
|
-
clientId: this.clientId,
|
|
560
|
-
base: {
|
|
561
|
-
...this.initial,
|
|
562
|
-
version: S(t),
|
|
563
|
-
document: JSON.stringify(this.confirmed.toJSON())
|
|
564
|
-
},
|
|
565
|
-
steps: [...l, ...u],
|
|
566
|
-
groups: [...r ? B(r).map((e) => e.length) : [], u.length],
|
|
567
|
-
document: JSON.stringify(e.doc.toJSON())
|
|
568
|
-
};
|
|
569
|
-
return z.encode(JSON.stringify(d)).byteLength > F ? this.refuse(o) : !0;
|
|
570
|
-
}
|
|
571
|
-
attach(e) {
|
|
572
|
-
if (this.instance || this.current.status === "closed") throw Error("A collaboration session can only mount once.");
|
|
573
|
-
let n = c(this.initial.document, e.schema);
|
|
574
|
-
if (!e.state.doc.eq(n)) {
|
|
575
|
-
let e = new a("content", "The editor must start from the session document.");
|
|
576
|
-
throw this.fail(e), e;
|
|
577
|
-
}
|
|
578
|
-
this.instance = e, this.confirmed = n;
|
|
579
|
-
let r = this.options.recovery;
|
|
580
|
-
if (r?.steps.length && !this.restored) {
|
|
581
|
-
this.restored = !0, this.restoring = !0;
|
|
582
|
-
let n = 0;
|
|
583
|
-
for (let i of r.groups) {
|
|
584
|
-
let a = e.state.tr.setMeta(M, !0).setMeta(t, !0);
|
|
585
|
-
for (let t of u(r.steps.slice(n, n + i), e.schema)) a.step(t);
|
|
586
|
-
e.view.dispatch(a), n += i;
|
|
587
|
-
}
|
|
588
|
-
this.restoring = !1, this.changed();
|
|
589
|
-
}
|
|
590
|
-
this.listenToPage(), this.startSubscription(), this.presence?.start(), this.schedule(0);
|
|
591
|
-
}
|
|
592
|
-
listenToPage() {
|
|
593
|
-
if (typeof window > "u" || typeof document > "u") return;
|
|
594
|
-
let e = () => {
|
|
595
|
-
this.flushRecovery();
|
|
596
|
-
}, t = () => {
|
|
597
|
-
document.visibilityState === "hidden" && this.flushRecovery();
|
|
598
|
-
}, n = () => {
|
|
599
|
-
this.current.status === "offline" && this.schedule(0);
|
|
600
|
-
};
|
|
601
|
-
window.addEventListener("pagehide", e), window.addEventListener("online", n), document.addEventListener("visibilitychange", t), this.removeWindowListeners = () => {
|
|
602
|
-
window.removeEventListener("pagehide", e), window.removeEventListener("online", n), document.removeEventListener("visibilitychange", t);
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
startSubscription() {
|
|
606
|
-
this.unsubscribe?.();
|
|
607
|
-
let e = this.generation;
|
|
608
|
-
this.unsubscribe = this.options.transport.subscribe((t) => {
|
|
609
|
-
if (e === this.generation && !(this.current.status === "closed" || this.current.status === "stale")) try {
|
|
610
|
-
let e = o(this.initial, t);
|
|
611
|
-
if (e) {
|
|
612
|
-
this.setState("stale", "This document was replaced or its policy changed. Keep your recovery copy and reopen it.", K[e]), this.presence?.stop(!0);
|
|
613
|
-
return;
|
|
614
|
-
}
|
|
615
|
-
if (f(t), this.observedVersion = Math.max(this.observedVersion, t.version), this.current.status === "error") return;
|
|
616
|
-
this.schedule(0);
|
|
617
|
-
} catch (e) {
|
|
618
|
-
this.fail(e);
|
|
619
|
-
}
|
|
620
|
-
}, (t) => {
|
|
621
|
-
e === this.generation && this.fail(t);
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
changed() {
|
|
625
|
-
if (!(!this.instance || this.restoring || this.current.status === "closed")) {
|
|
626
|
-
if (this.queueRecovery(), ["error", "stale"].includes(this.current.status)) {
|
|
627
|
-
this.setState(this.current.status, this.current.message, this.current.code);
|
|
628
|
-
return;
|
|
629
|
-
}
|
|
630
|
-
if (this.current.status === "offline") {
|
|
631
|
-
this.setState("offline", this.current.message, this.current.code), this.timer || this.schedule(40);
|
|
632
|
-
return;
|
|
633
|
-
}
|
|
634
|
-
this.setState("syncing", this.current.message, this.current.code === "limit" ? "limit" : void 0), this.schedule(40);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
queueRecovery() {
|
|
638
|
-
if (!this.options.onRecovery || !this.instance || !this.recoveryStored && !w(this.instance.state)) return;
|
|
639
|
-
this.recoveryDirty = !0;
|
|
640
|
-
let e = this.options.recoveryDelayMs ?? 300;
|
|
641
|
-
if (e <= 0) {
|
|
642
|
-
this.flushRecovery();
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
this.recoveryTimer ??= setTimeout(() => {
|
|
646
|
-
this.recoveryTimer = void 0, this.flushRecovery();
|
|
647
|
-
}, e);
|
|
648
|
-
}
|
|
649
|
-
flushRecovery() {
|
|
650
|
-
if (clearTimeout(this.recoveryTimer), this.recoveryTimer = void 0, !this.recoveryDirty || !this.options.onRecovery || !this.instance) return !0;
|
|
651
|
-
this.recoveryDirty = !1;
|
|
652
|
-
let e = this.getRecovery();
|
|
653
|
-
try {
|
|
654
|
-
return this.options.onRecovery(e), this.recoveryStored = e !== null, !0;
|
|
655
|
-
} catch {
|
|
656
|
-
return this.recoveryDirty = !0, this.current.status !== "closed" && this.setState("error", "The recovery copy could not be saved. Keep this editor open and retry after freeing storage.", "storage"), !1;
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
getRecovery() {
|
|
660
|
-
if (!this.instance) return this.options.recovery ? structuredClone(this.options.recovery) : null;
|
|
661
|
-
let e = w(this.instance.state);
|
|
662
|
-
return e ? {
|
|
663
|
-
format: 1,
|
|
664
|
-
clientId: this.clientId,
|
|
665
|
-
base: {
|
|
666
|
-
...this.initial,
|
|
667
|
-
version: S(this.instance.state),
|
|
668
|
-
document: JSON.stringify(this.confirmed.toJSON())
|
|
669
|
-
},
|
|
670
|
-
steps: e.steps.map((e) => JSON.stringify(e.toJSON())),
|
|
671
|
-
groups: B(e).map((e) => e.length),
|
|
672
|
-
document: JSON.stringify(this.instance.state.doc.toJSON())
|
|
673
|
-
} : null;
|
|
674
|
-
}
|
|
675
|
-
schedule(e) {
|
|
676
|
-
if (!this.instance || [
|
|
677
|
-
"error",
|
|
678
|
-
"stale",
|
|
679
|
-
"closed"
|
|
680
|
-
].includes(this.current.status) || (this.requested = !0, this.busy)) return;
|
|
681
|
-
let t = Date.now() + e;
|
|
682
|
-
this.timer && this.timerDue <= t || (clearTimeout(this.timer), this.timerDue = t, this.timer = setTimeout(() => {
|
|
683
|
-
this.timer = void 0, this.timerDue = Infinity, this.pump();
|
|
684
|
-
}, e));
|
|
685
|
-
}
|
|
686
|
-
backoffDelay() {
|
|
687
|
-
let e = this.options.backoff?.initialMs ?? 1e3, t = this.options.backoff?.maxMs ?? 3e4, n = Math.min(t, e * 2 ** Math.min(this.attempt, 30));
|
|
688
|
-
return Math.round(Math.random() * n);
|
|
689
|
-
}
|
|
690
|
-
head() {
|
|
691
|
-
return {
|
|
692
|
-
epoch: this.initial.epoch,
|
|
693
|
-
schemaRevision: this.initial.schemaRevision,
|
|
694
|
-
policyRevision: this.initial.policyRevision,
|
|
695
|
-
version: S(this.instance.state),
|
|
696
|
-
protocolVersion: 1
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
request(e) {
|
|
700
|
-
let t = this.options.requestTimeoutMs ?? 15e3;
|
|
701
|
-
return new Promise((n, r) => {
|
|
702
|
-
let i = setTimeout(() => {
|
|
703
|
-
r(new H());
|
|
704
|
-
}, t);
|
|
705
|
-
Promise.resolve().then(e).then((e) => {
|
|
706
|
-
clearTimeout(i), n(e);
|
|
707
|
-
}, (e) => {
|
|
708
|
-
clearTimeout(i), r(e);
|
|
709
|
-
});
|
|
710
|
-
});
|
|
711
|
-
}
|
|
712
|
-
apply(e) {
|
|
713
|
-
if (!e || typeof e != "object") throw new U("invalid", "internal", "The server returned an invalid reply.");
|
|
714
|
-
if (e.status === "stale") {
|
|
715
|
-
let t = K[e.reason] ?? "replaced";
|
|
716
|
-
return this.setState("stale", "The server cannot merge this editing session. Keep your recovery copy and reopen the document.", t), this.presence?.stop(!0), !1;
|
|
717
|
-
}
|
|
718
|
-
let n = this.instance, i = e.update;
|
|
719
|
-
if (f(i), o(this.initial, i)) throw new U("epoch", "replaced", "The server returned a different document generation.");
|
|
720
|
-
if (i.fromVersion !== S(n.state) || !Array.isArray(i.steps) || !Array.isArray(i.clientIds) || i.version !== i.fromVersion + i.steps.length || i.steps.length !== i.clientIds.length || i.clientIds.some((e) => typeof e != "string" || !e || e.length > 200)) throw new U("invalid", "internal", "The server returned an inconsistent editor history.");
|
|
721
|
-
if (this.observedVersion = Math.max(this.observedVersion, i.version), !i.steps.length) return !0;
|
|
722
|
-
let a = u(i.steps, n.schema), s = w(n.state), c = [...i.clientIds], l = !0;
|
|
723
|
-
for (let e = 0; e < a.length; e++) {
|
|
724
|
-
if (c[e] !== this.clientId) {
|
|
725
|
-
l = !1;
|
|
726
|
-
continue;
|
|
727
|
-
}
|
|
728
|
-
if (!l || !s?.steps[e] || r(a[e].toJSON()) !== r(s.steps[e].toJSON())) {
|
|
729
|
-
if (this.orphanOwnSteps) {
|
|
730
|
-
c[e] = `\u0000discarded:${this.clientId}`, l = !1;
|
|
731
|
-
continue;
|
|
732
|
-
}
|
|
733
|
-
throw new U("version", "conflict", "Another editor is using this client ID. Keep this recovery copy and reopen with a unique session.");
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
let d = new h(this.confirmed);
|
|
737
|
-
for (let e of a) d.step(e);
|
|
738
|
-
d.doc.check();
|
|
739
|
-
let p = C(n.state, a, c, { mapSelectionBackward: !0 }).setMeta(M, !0).setMeta(t, !0);
|
|
740
|
-
return this.history.append(i.fromVersion, d.mapping.maps), this.confirmed = d.doc, n.view.dispatch(p), !0;
|
|
741
|
-
}
|
|
742
|
-
async pump() {
|
|
743
|
-
if (!this.instance || this.busy || [
|
|
744
|
-
"error",
|
|
745
|
-
"stale",
|
|
746
|
-
"closed"
|
|
747
|
-
].includes(this.current.status)) return;
|
|
748
|
-
this.busy = !0;
|
|
749
|
-
let e = this.generation, t = !1;
|
|
750
|
-
this.setState("syncing");
|
|
751
|
-
try {
|
|
752
|
-
do {
|
|
753
|
-
this.requested = !1;
|
|
754
|
-
let n = S(this.instance.state), r = await this.request(() => this.options.transport.pull(this.head()));
|
|
755
|
-
if (e !== this.generation || [
|
|
756
|
-
"error",
|
|
757
|
-
"stale",
|
|
758
|
-
"closed"
|
|
759
|
-
].includes(this.current.status) || !this.apply(r)) return;
|
|
760
|
-
if (S(this.instance.state) < this.observedVersion) {
|
|
761
|
-
if (S(this.instance.state) === n) throw new U("version", "conflict", "The server did not return the missing editor history.");
|
|
762
|
-
this.requested = !0;
|
|
763
|
-
continue;
|
|
764
|
-
}
|
|
765
|
-
let a = w(this.instance.state);
|
|
766
|
-
if (a) {
|
|
767
|
-
let n = [], r = 0;
|
|
768
|
-
for (let e of B(a)) {
|
|
769
|
-
let t = e.reduce((e, t) => e + z.encode(t).byteLength, 0);
|
|
770
|
-
if (n.length + e.length > i.stepsPerBatch || r + t > i.batchBytes) break;
|
|
771
|
-
r += t, n.push(...e);
|
|
772
|
-
}
|
|
773
|
-
if (!n.length) throw new U("limit", "rejected", "A pending edit is too large to send. Keep a recovery copy before changing it.");
|
|
774
|
-
t = !0;
|
|
775
|
-
let o = await this.request(() => this.options.transport.push({
|
|
776
|
-
...this.head(),
|
|
777
|
-
clientId: this.clientId,
|
|
778
|
-
steps: n
|
|
779
|
-
}));
|
|
780
|
-
if (t = !1, e !== this.generation || [
|
|
781
|
-
"error",
|
|
782
|
-
"stale",
|
|
783
|
-
"closed"
|
|
784
|
-
].includes(this.current.status) || !this.apply(o)) return;
|
|
785
|
-
if (S(this.instance.state) === a.version) throw new U("version", "conflict", "The server did not acknowledge the submitted changes.");
|
|
786
|
-
(w(this.instance.state)?.steps.length ?? 0) < a.steps.length && (this.orphanOwnSteps = !1), this.requested = !0;
|
|
787
|
-
}
|
|
788
|
-
} while (this.requested && ![
|
|
789
|
-
"error",
|
|
790
|
-
"stale",
|
|
791
|
-
"closed"
|
|
792
|
-
].includes(this.current.status));
|
|
793
|
-
[
|
|
794
|
-
"error",
|
|
795
|
-
"stale",
|
|
796
|
-
"closed"
|
|
797
|
-
].includes(this.current.status) || (this.attempt = 0, this.setState("synced"));
|
|
798
|
-
} catch (n) {
|
|
799
|
-
e === this.generation && this.fail(n, t);
|
|
800
|
-
} finally {
|
|
801
|
-
e === this.generation && (this.busy = !1, this.current.status === "offline" ? this.schedule(this.backoffDelay()) : this.requested && this.schedule(0));
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
fail(e, t = !1) {
|
|
805
|
-
if (["closed", "stale"].includes(this.current.status)) return;
|
|
806
|
-
let n = X(e, t);
|
|
807
|
-
this.setState(n.status, n.message, n.code), n.status === "stale" && this.presence?.stop(!0), n.status === "offline" && (this.attempt += 1, this.schedule(this.backoffDelay()));
|
|
808
|
-
}
|
|
809
|
-
retry() {
|
|
810
|
-
["closed", "stale"].includes(this.current.status) || (this.generation += 1, this.busy = !1, clearTimeout(this.timer), this.timer = void 0, this.timerDue = Infinity, this.setState("connecting"), this.startSubscription(), this.schedule(0));
|
|
811
|
-
}
|
|
812
|
-
discardPendingAndResync() {
|
|
813
|
-
let e = this.instance;
|
|
814
|
-
if (!e || e.isDestroyed || ["closed", "stale"].includes(this.current.status)) return null;
|
|
815
|
-
let n = this.getRecovery();
|
|
816
|
-
if (n && this.options.onDiscard?.(structuredClone(n)), this.generation += 1, this.busy = !1, clearTimeout(this.timer), this.timer = void 0, this.timerDue = Infinity, n) {
|
|
817
|
-
let n = {
|
|
818
|
-
version: S(e.state),
|
|
819
|
-
unconfirmed: []
|
|
820
|
-
};
|
|
821
|
-
this.orphanOwnSteps = !0, e.view.dispatch(e.state.tr.replaceWith(0, e.state.doc.content.size, this.confirmed.content).setMeta(M, !0).setMeta(t, !0).setMeta("addToHistory", !1).setMeta(this.collabPlugin, n));
|
|
822
|
-
}
|
|
823
|
-
return this.recoveryDirty = !0, this.flushRecovery(), this.attempt = 0, this.setState("connecting"), this.startSubscription(), this.schedule(0), n;
|
|
824
|
-
}
|
|
825
|
-
flush(e = 1e4) {
|
|
826
|
-
if (this.flushRecovery(), !Number.isFinite(e) || e <= 0) return Promise.reject(/* @__PURE__ */ RangeError("Flush timeout must be positive."));
|
|
827
|
-
let t = () => {
|
|
828
|
-
this.flushRecovery();
|
|
829
|
-
let e = this.head();
|
|
830
|
-
return delete e.protocolVersion, e;
|
|
831
|
-
}, n = (e) => new a(e.code ? G[e.code] : "invalid", e.message ?? "The editing session is closed.");
|
|
832
|
-
return this.current.status === "synced" && !this.busy && !this.current.pendingSteps ? Promise.resolve(t()) : [
|
|
833
|
-
"error",
|
|
834
|
-
"stale",
|
|
835
|
-
"closed"
|
|
836
|
-
].includes(this.current.status) ? Promise.reject(n(this.current)) : new Promise((r, i) => {
|
|
837
|
-
let a = setTimeout(() => {
|
|
838
|
-
s(), i(new V("Changes are still waiting for the server. Keep this editor open."));
|
|
839
|
-
}, e), o = (e) => {
|
|
840
|
-
e.status === "synced" && !e.pendingSteps ? (clearTimeout(a), s(), r(t())) : [
|
|
841
|
-
"error",
|
|
842
|
-
"stale",
|
|
843
|
-
"closed"
|
|
844
|
-
].includes(e.status) && (clearTimeout(a), s(), i(n(e)));
|
|
845
|
-
}, s = () => {
|
|
846
|
-
this.listeners.delete(o);
|
|
847
|
-
};
|
|
848
|
-
this.listeners.add(o), this.schedule(0);
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
close() {
|
|
852
|
-
this.current.status !== "closed" && (this.flushRecovery(), this.generation += 1, clearTimeout(this.timer), clearTimeout(this.recoveryTimer), this.unsubscribe?.(), this.removeWindowListeners?.(), this.presence?.stop(), this.setState("closed", this.current.pendingSteps ? "Unsent changes remain in the host recovery copy." : void 0), this.listeners.clear());
|
|
853
|
-
}
|
|
854
|
-
};
|
|
855
|
-
function Q(e) {
|
|
856
|
-
return new Z(e);
|
|
857
|
-
}
|
|
858
|
-
//#endregion
|
|
859
|
-
//#region src/lib/collaboration/recovery.ts
|
|
860
|
-
async function $(t, r) {
|
|
861
|
-
let i = {
|
|
862
|
-
ok: !1,
|
|
863
|
-
message: "This recovery copy cannot be converted to Markdown by this editor version. Keep the file."
|
|
864
|
-
};
|
|
865
|
-
try {
|
|
866
|
-
let a = n().nodeFromJSON(JSON.parse(t.document));
|
|
867
|
-
a.check();
|
|
868
|
-
let o = await e(a.toJSON(), r);
|
|
869
|
-
return o.ok && o.value !== void 0 ? {
|
|
870
|
-
ok: !0,
|
|
871
|
-
markdown: o.value
|
|
872
|
-
} : i;
|
|
873
|
-
} catch {
|
|
874
|
-
return i;
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
async function te(e, t = {}) {
|
|
878
|
-
let n;
|
|
879
|
-
try {
|
|
880
|
-
n = W(e);
|
|
881
|
-
} catch (e) {
|
|
882
|
-
return {
|
|
883
|
-
status: "unreadable",
|
|
884
|
-
reason: "format",
|
|
885
|
-
message: e instanceof a ? e.message : "Invalid editor recovery copy."
|
|
886
|
-
};
|
|
887
|
-
}
|
|
888
|
-
if (n.base.schemaRevision === "ginko-editor-2") return {
|
|
889
|
-
status: "current",
|
|
890
|
-
recovery: n
|
|
891
|
-
};
|
|
892
|
-
let r = await $(n, t.output);
|
|
893
|
-
return r.ok ? {
|
|
894
|
-
status: "converted",
|
|
895
|
-
schemaRevision: n.base.schemaRevision,
|
|
896
|
-
recovery: n,
|
|
897
|
-
markdown: r.markdown
|
|
898
|
-
} : {
|
|
899
|
-
status: "unreadable",
|
|
900
|
-
reason: "content",
|
|
901
|
-
message: r.message
|
|
902
|
-
};
|
|
903
|
-
}
|
|
904
|
-
//#endregion
|
|
905
|
-
export { V as CollaborationConnectionError, a as CollaborationError, Z as EditorCollaborationSession, d as collaborationColor, $ as collaborationRecoveryToMarkdown, Q as createEditorCollaboration, W as parseCollaborationRecovery, te as readCollaborationRecovery };
|
|
906
|
-
|
|
907
|
-
//# sourceMappingURL=collaboration.js.map
|