@abraca/nuxt 2.43.0 → 2.46.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.
Files changed (33) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/runtime/components/ADocRenderer.d.vue.ts +12 -0
  3. package/dist/runtime/components/ADocRenderer.vue +20 -19
  4. package/dist/runtime/components/ADocRenderer.vue.d.ts +12 -0
  5. package/dist/runtime/components/ADocumentTree.d.vue.ts +10 -0
  6. package/dist/runtime/components/ADocumentTree.vue +33 -8
  7. package/dist/runtime/components/ADocumentTree.vue.d.ts +10 -0
  8. package/dist/runtime/components/AEditor.d.vue.ts +2 -2
  9. package/dist/runtime/components/AEditor.vue +12 -5
  10. package/dist/runtime/components/AEditor.vue.d.ts +2 -2
  11. package/dist/runtime/components/AEmailVerifyConfirmModal.d.vue.ts +1 -1
  12. package/dist/runtime/components/AEmailVerifyConfirmModal.vue.d.ts +1 -1
  13. package/dist/runtime/components/ANodePanel.vue +11 -3
  14. package/dist/runtime/components/ASetPasswordCard.d.vue.ts +1 -1
  15. package/dist/runtime/components/ASetPasswordCard.vue.d.ts +1 -1
  16. package/dist/runtime/components/aware/AMedia.d.vue.ts +1 -1
  17. package/dist/runtime/components/aware/AMedia.vue.d.ts +1 -1
  18. package/dist/runtime/components/renderers/AProseRenderer.d.vue.ts +2 -2
  19. package/dist/runtime/components/renderers/AProseRenderer.vue.d.ts +2 -2
  20. package/dist/runtime/composables/useConnectionStatus.d.ts +1 -1
  21. package/dist/runtime/composables/useDocTree.d.ts +8 -1
  22. package/dist/runtime/composables/useDocTree.js +24 -4
  23. package/dist/runtime/composables/useEditor.js +8 -51
  24. package/dist/runtime/composables/useSpaceConnections.d.ts +75 -18
  25. package/dist/runtime/composables/useSpaceConnections.js +244 -61
  26. package/dist/runtime/middleware/abracadabra-auth.d.ts +1 -1
  27. package/dist/runtime/plugin-abracadabra.client.d.ts +1 -1
  28. package/dist/runtime/plugin-abracadabra.client.js +19 -0
  29. package/dist/runtime/plugin-abracadabra.server.d.ts +1 -1
  30. package/dist/runtime/plugin-shared-globals.client.d.ts +1 -1
  31. package/dist/runtime/utils/enforceDocumentShape.d.ts +30 -0
  32. package/dist/runtime/utils/enforceDocumentShape.js +228 -0
  33. package/package.json +1 -1
@@ -1,22 +1,36 @@
1
1
  /**
2
- * useSpaceConnections — Single-space adapter.
2
+ * useSpaceConnections — per-space provider manager (module-native, lean port).
3
3
  *
4
- * cou-sh has a multi-space `useSpaceConnections` (1073 LOC) that manages
5
- * one provider per connected space. The Nuxt module is single-space — we
6
- * always have exactly one active provider tied to `spaceDocId`.
4
+ * Replaces the module's single-root-provider + `loadChild` model: alongside the
5
+ * always-bound ACTIVE space (which reuses the singleton provider/doc), any other
6
+ * space can be connected on demand as its OWN connection (own Y.Doc +
7
+ * AbracadabraProvider + live `treeData`), all multiplexed over the one shared
8
+ * server WebSocket. A document then resolves to its *owning space's* provider +
9
+ * tree — so doc type/label/meta and every mutation target the correct tree.
7
10
  *
8
- * This adapter wraps that single connection in the same `Map<spaceId, conn>`
9
- * shape, so consumers like `useDocLookup` and `useAggregatedPresence` can
10
- * iterate it the same way as in cou-sh. When (if ever) the module gains
11
- * multi-space, swap the implementation; the API stays.
11
+ * This is a deliberately lean adaptation of `cou-sh/app/composables/
12
+ * useSpaceConnections.ts`: it keeps the `SpaceConnection { doc, provider,
13
+ * treeData }` shape, connect/disconnect lifecycle, and the `findDocSpaceId` /
14
+ * `getProviderForDoc` / `resolveEntry` resolvers, but drops cou-sh's LRU
15
+ * eviction, WebRTC P2P, local/offline spaces, background sync, file-blob
16
+ * caching, and search indexing — none of which the module needs.
12
17
  *
13
- * Why a Map for a single entry? It keeps the cou-sh ports near-1:1 — they
14
- * iterate `for (const [, conn] of connections)` and read
15
- * `conn.provider?.awareness`. Forcing them to special-case "single space"
16
- * adds noise without changing behavior.
18
+ * Back-compat: the previous single-space adapter exposed `{ connections }` with
19
+ * exactly one entry (the active space), consumed by `useDocLookup` and
20
+ * `useAggregatedPresence`. That entry is preserved — the active-space binding
21
+ * below keeps it auto-populated, so those consumers are unaffected.
22
+ *
23
+ * Socket reuse: the module already owns one `AbracadabraWS` + `AbracadabraClient`.
24
+ * The client plugin injects a `createProvider(spaceId, ydoc)` factory via
25
+ * `_initSpaceConnections(...)` that builds a new `AbracadabraProvider` on that
26
+ * SAME `wsp`/`client`, so connecting a non-active space adds no new socket.
27
+ * Until that ctx is injected, only the active space is available (dormant mode).
28
+ *
29
+ * A space's id IS its root document id (see plugin `switchSpace`).
17
30
  */
18
31
  import { type Ref } from 'vue';
19
32
  import * as Y from 'yjs';
33
+ type AnyProvider = any;
20
34
  export interface SpaceTreeEntry {
21
35
  label: string;
22
36
  parentId: string | null;
@@ -27,17 +41,60 @@ export interface SpaceTreeEntry {
27
41
  updatedAt?: number;
28
42
  }
29
43
  export interface SpaceConnection {
44
+ /** Space id === space root document id. */
30
45
  spaceId: string;
31
46
  doc: Y.Doc;
32
- provider: unknown | null;
33
- client: unknown | null;
47
+ provider: AnyProvider | null;
48
+ client: AnyProvider | null;
49
+ /** Live snapshot of the space root's `doc-tree` Y.Map (deep-observed). */
34
50
  treeData: Ref<Record<string, SpaceTreeEntry>>;
35
- trashData: Ref<Record<string, unknown>>;
36
51
  status: Ref<'disconnected' | 'connecting' | 'connected'>;
37
52
  isReady: Ref<boolean>;
53
+ /** Cleanup functions to call on disconnect. */
54
+ _cleanups: Array<() => void>;
55
+ /** True for the singleton-backed active-space binding (never provider-destroyed). */
56
+ _isActive?: boolean;
38
57
  }
39
- interface SpaceConnectionsApi {
40
- connections: Map<string, SpaceConnection>;
58
+ /**
59
+ * Plugin-injected context. The client plugin owns the shared `wsp`/`client`,
60
+ * so it supplies the provider factory used to connect NON-active spaces.
61
+ * Set once at boot via `_initSpaceConnections`.
62
+ */
63
+ export interface SpaceConnectionsCtx {
64
+ /** Build a provider for `spaceId` (its root doc) on the shared socket. */
65
+ createProvider: (spaceId: string, ydoc: Y.Doc) => AnyProvider;
41
66
  }
42
- export declare function useSpaceConnections(): SpaceConnectionsApi;
67
+ /** Wire the shared socket factory. Called once from the client plugin. */
68
+ export declare function _initSpaceConnections(ctx: SpaceConnectionsCtx): void;
69
+ /** Tear down non-active connections + clear injected ctx (server/space switch). */
70
+ export declare function _resetSpaceConnections(): void;
71
+ /**
72
+ * Connect to a space (its root doc). Reuses the active binding when `spaceId`
73
+ * is the active space; otherwise creates a provider on the shared socket via
74
+ * the injected ctx, mirrors the tree, and registers the connection. Idempotent.
75
+ */
76
+ export declare function connectSpace(spaceId: string): Promise<SpaceConnection>;
77
+ /**
78
+ * Disconnect a single space: stop observers and destroy its provider. The
79
+ * active-space binding is singleton-backed (`_isActive`) and is NOT destroyed
80
+ * here — call this only for explicitly connected non-active spaces.
81
+ */
82
+ export declare function disconnectSpace(spaceId: string): void;
83
+ /** Disconnect every non-active space. */
84
+ export declare function disconnectAllSpaces(): void;
85
+ export declare function getSpaceConnection(spaceId: string): SpaceConnection | undefined;
86
+ /** Look up the connection that owns a given Y.Doc (used by child-tree views). */
87
+ export declare function findSpaceConnectionByDoc(doc: Y.Doc): SpaceConnection | undefined;
88
+ export declare function useSpaceConnections(): {
89
+ connections: import("vue").ShallowReactive<Map<string, SpaceConnection>>;
90
+ connectSpace: typeof connectSpace;
91
+ disconnectSpace: typeof disconnectSpace;
92
+ disconnectAllSpaces: typeof disconnectAllSpaces;
93
+ getSpaceConnection: typeof getSpaceConnection;
94
+ findSpaceConnectionByDoc: typeof findSpaceConnectionByDoc;
95
+ findDocSpaceId: (docId: string) => string | undefined;
96
+ getProviderForDoc: (docId: string) => AnyProvider | null;
97
+ getDocForDoc: (docId: string) => Y.Doc | null;
98
+ resolveEntry: (docId: string) => SpaceTreeEntry | undefined;
99
+ };
43
100
  export {};
@@ -1,72 +1,255 @@
1
- import { shallowReactive, ref, watch } from "vue";
1
+ import { ref, shallowReactive, watch } from "vue";
2
2
  import * as Y from "yjs";
3
3
  import { useAbracadabra } from "./useAbracadabra.js";
4
- let _singleton = null;
5
- function _build() {
6
- const state = useAbracadabra();
7
- const connections = shallowReactive(/* @__PURE__ */ new Map());
8
- const treeData = ref({});
9
- const trashData = ref({});
10
- let detachTree = null;
11
- let detachTrash = null;
12
- function syncMap(map, target) {
4
+ let _ctx = null;
5
+ export function _initSpaceConnections(ctx) {
6
+ _ctx = ctx;
7
+ }
8
+ export function _resetSpaceConnections() {
9
+ for (const id of [...connections.keys()]) {
10
+ const conn = connections.get(id);
11
+ if (conn && !conn._isActive) disconnectSpace(id);
12
+ }
13
+ _connectPromises.clear();
14
+ _ctx = null;
15
+ }
16
+ const connections = shallowReactive(/* @__PURE__ */ new Map());
17
+ const _connectPromises = /* @__PURE__ */ new Map();
18
+ function observeYMap(doc, mapName) {
19
+ const ymap = doc.getMap(mapName);
20
+ const data = ref({});
21
+ const snapshot = () => {
13
22
  const obj = {};
14
- map.forEach((val, key) => {
23
+ ymap.forEach((val, key) => {
15
24
  obj[key] = val instanceof Y.Map ? val.toJSON() : val;
16
25
  });
17
- target.value = obj;
18
- }
19
- function attachObservers(doc) {
20
- detachTree?.();
21
- detachTrash?.();
22
- const tree = doc.getMap("doc-tree");
23
- const trash = doc.getMap("doc-trash");
24
- syncMap(tree, treeData);
25
- syncMap(trash, trashData);
26
- const onTree = () => syncMap(tree, treeData);
27
- const onTrash = () => syncMap(trash, trashData);
28
- tree.observe(onTree);
29
- trash.observe(onTrash);
30
- detachTree = () => tree.unobserve(onTree);
31
- detachTrash = () => trash.unobserve(onTrash);
26
+ return obj;
27
+ };
28
+ data.value = snapshot();
29
+ let rafId = null;
30
+ const flush = () => {
31
+ rafId = null;
32
+ data.value = snapshot();
33
+ };
34
+ const observer = (_events, transaction) => {
35
+ if (transaction.local) {
36
+ if (rafId !== null) {
37
+ cancelAnimationFrame(rafId);
38
+ rafId = null;
39
+ }
40
+ data.value = snapshot();
41
+ } else if (typeof requestAnimationFrame !== "undefined") {
42
+ if (rafId === null) rafId = requestAnimationFrame(flush);
43
+ } else {
44
+ data.value = snapshot();
45
+ }
46
+ };
47
+ ymap.observeDeep(observer);
48
+ const onVisibilityChange = () => {
49
+ if (typeof document !== "undefined" && !document.hidden) {
50
+ if (rafId !== null) {
51
+ cancelAnimationFrame(rafId);
52
+ rafId = null;
53
+ }
54
+ data.value = snapshot();
55
+ }
56
+ };
57
+ if (typeof document !== "undefined") {
58
+ document.addEventListener("visibilitychange", onVisibilityChange);
32
59
  }
33
- if (import.meta.client) {
34
- watch(
35
- () => [
36
- state.spaceDocId.value,
37
- state.doc.value,
38
- state.provider.value,
39
- state.client.value
40
- ],
41
- ([spaceId, doc, provider, client]) => {
42
- connections.clear();
43
- if (!spaceId || !doc) {
44
- detachTree?.();
45
- detachTrash?.();
46
- detachTree = null;
47
- detachTrash = null;
48
- treeData.value = {};
49
- trashData.value = {};
50
- return;
60
+ queueMicrotask(() => {
61
+ data.value = snapshot();
62
+ });
63
+ const cleanup = () => {
64
+ try {
65
+ ymap.unobserveDeep(observer);
66
+ } catch {
67
+ }
68
+ if (rafId !== null) {
69
+ cancelAnimationFrame(rafId);
70
+ rafId = null;
71
+ }
72
+ if (typeof document !== "undefined") {
73
+ document.removeEventListener("visibilitychange", onVisibilityChange);
74
+ }
75
+ };
76
+ return { data, cleanup };
77
+ }
78
+ let _activeBound = false;
79
+ let _activeSpaceId = null;
80
+ function _ensureActiveBinding() {
81
+ if (_activeBound || !import.meta.client) return;
82
+ _activeBound = true;
83
+ const state = useAbracadabra();
84
+ watch(
85
+ () => [state.spaceDocId.value, state.doc.value, state.provider.value, state.client.value],
86
+ ([spaceId, doc, provider, client]) => {
87
+ if (_activeSpaceId && _activeSpaceId !== spaceId) {
88
+ const prev = connections.get(_activeSpaceId);
89
+ if (prev?._isActive) {
90
+ for (const fn of prev._cleanups) {
91
+ try {
92
+ fn();
93
+ } catch {
94
+ }
95
+ }
96
+ connections.delete(_activeSpaceId);
51
97
  }
52
- attachObservers(doc);
53
- connections.set(spaceId, {
54
- spaceId,
55
- doc,
56
- provider,
57
- client,
58
- treeData,
59
- trashData,
60
- status: state.status,
61
- isReady: state.isReady
62
- });
63
- },
64
- { immediate: true }
65
- );
98
+ }
99
+ _activeSpaceId = spaceId ?? null;
100
+ if (!spaceId || !doc) return;
101
+ if (connections.has(spaceId)) {
102
+ const c = connections.get(spaceId);
103
+ c._isActive = true;
104
+ return;
105
+ }
106
+ const { data: treeData, cleanup } = observeYMap(doc, "doc-tree");
107
+ connections.set(spaceId, {
108
+ spaceId,
109
+ doc,
110
+ provider,
111
+ client,
112
+ treeData,
113
+ status: state.status,
114
+ isReady: state.isReady,
115
+ _cleanups: [cleanup],
116
+ _isActive: true
117
+ });
118
+ },
119
+ { immediate: true }
120
+ );
121
+ }
122
+ export function connectSpace(spaceId) {
123
+ _ensureActiveBinding();
124
+ const existing = connections.get(spaceId);
125
+ if (existing) return Promise.resolve(existing);
126
+ const inflight = _connectPromises.get(spaceId);
127
+ if (inflight) return inflight;
128
+ const p = _connectSpace(spaceId).finally(() => {
129
+ _connectPromises.delete(spaceId);
130
+ });
131
+ _connectPromises.set(spaceId, p);
132
+ return p;
133
+ }
134
+ async function _connectSpace(spaceId) {
135
+ if (!_ctx) {
136
+ throw new Error("[useSpaceConnections] no provider factory \u2014 only the active space is available until the client plugin calls _initSpaceConnections()");
137
+ }
138
+ const ydoc = new Y.Doc();
139
+ const status = ref("connecting");
140
+ const isReady = ref(false);
141
+ const { data: treeData, cleanup: treeCleanup } = observeYMap(ydoc, "doc-tree");
142
+ const provider = _ctx.createProvider(spaceId, ydoc);
143
+ const conn = {
144
+ spaceId,
145
+ doc: ydoc,
146
+ provider,
147
+ client: null,
148
+ treeData,
149
+ status,
150
+ isReady,
151
+ _cleanups: [treeCleanup]
152
+ };
153
+ connections.set(spaceId, conn);
154
+ try {
155
+ if (provider?.ready) await provider.ready;
156
+ isReady.value = true;
157
+ status.value = "connected";
158
+ } catch (e) {
159
+ status.value = "disconnected";
160
+ console.error(`[useSpaceConnections] connect failed for ${spaceId}:`, e);
161
+ }
162
+ return conn;
163
+ }
164
+ export function disconnectSpace(spaceId) {
165
+ const conn = connections.get(spaceId);
166
+ if (!conn) return;
167
+ for (const fn of conn._cleanups) {
168
+ try {
169
+ fn();
170
+ } catch {
171
+ }
172
+ }
173
+ if (!conn._isActive) {
174
+ try {
175
+ conn.provider?.destroy?.();
176
+ } catch {
177
+ }
178
+ try {
179
+ conn.doc.destroy();
180
+ } catch {
181
+ }
182
+ }
183
+ connections.delete(spaceId);
184
+ }
185
+ export function disconnectAllSpaces() {
186
+ for (const spaceId of [...connections.keys()]) {
187
+ const conn = connections.get(spaceId);
188
+ if (conn && !conn._isActive) disconnectSpace(spaceId);
66
189
  }
67
- return { connections };
190
+ }
191
+ export function getSpaceConnection(spaceId) {
192
+ return connections.get(spaceId);
193
+ }
194
+ export function findSpaceConnectionByDoc(doc) {
195
+ for (const conn of connections.values()) {
196
+ if (conn.doc === doc) return conn;
197
+ }
198
+ return void 0;
68
199
  }
69
200
  export function useSpaceConnections() {
70
- if (!_singleton) _singleton = _build();
71
- return _singleton;
201
+ const abra = useAbracadabra();
202
+ _ensureActiveBinding();
203
+ function findDocSpaceId(docId) {
204
+ const current = abra.spaceDocId.value;
205
+ if (current === docId) return current;
206
+ for (const s of abra.currentServerSpaces.value) {
207
+ if (s.id === docId) return s.id;
208
+ }
209
+ for (const [spaceId, conn] of connections) {
210
+ if (conn.treeData.value[docId]) return spaceId;
211
+ }
212
+ return void 0;
213
+ }
214
+ function getProviderForDoc(docId) {
215
+ const spaceId = findDocSpaceId(docId);
216
+ if (spaceId) {
217
+ const conn = connections.get(spaceId);
218
+ if (conn?.provider) return conn.provider;
219
+ }
220
+ return abra.provider.value;
221
+ }
222
+ function getDocForDoc(docId) {
223
+ const spaceId = findDocSpaceId(docId);
224
+ if (spaceId) {
225
+ const conn = connections.get(spaceId);
226
+ if (conn?.doc) return conn.doc;
227
+ }
228
+ return abra.doc.value;
229
+ }
230
+ function resolveEntry(docId) {
231
+ const spaceId = findDocSpaceId(docId);
232
+ const conn = spaceId ? connections.get(spaceId) : void 0;
233
+ const fromConn = conn?.treeData.value[docId];
234
+ if (fromConn) return fromConn;
235
+ try {
236
+ const raw = abra.doc.value?.getMap("doc-tree")?.get(docId);
237
+ if (!raw) return void 0;
238
+ return raw instanceof Y.Map ? raw.toJSON() : raw;
239
+ } catch {
240
+ return void 0;
241
+ }
242
+ }
243
+ return {
244
+ connections,
245
+ connectSpace,
246
+ disconnectSpace,
247
+ disconnectAllSpaces,
248
+ getSpaceConnection,
249
+ findSpaceConnectionByDoc,
250
+ findDocSpaceId,
251
+ getProviderForDoc,
252
+ getDocForDoc,
253
+ resolveEntry
254
+ };
72
255
  }
@@ -1,2 +1,2 @@
1
- declare const _default: any;
1
+ declare const _default: import("#app").RouteMiddleware;
2
2
  export default _default;
@@ -1,4 +1,4 @@
1
- declare const _default: any;
1
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
2
  export default _default;
3
3
  declare module '#app' {
4
4
  interface NuxtApp {
@@ -48,6 +48,10 @@ import {
48
48
  _initServerInfo,
49
49
  _destroyServerInfo
50
50
  } from "./composables/useServerInfo.js";
51
+ import {
52
+ _initSpaceConnections,
53
+ _resetSpaceConnections
54
+ } from "./composables/useSpaceConnections.js";
51
55
  import { setSdkModule, getSdkModule } from "./utils/sdkRef.js";
52
56
  const NUXT_UI_PRIMARY_COLORS = /* @__PURE__ */ new Set([
53
57
  "red",
@@ -596,6 +600,7 @@ export default defineNuxtPlugin({
596
600
  lastClientIds = /* @__PURE__ */ new Set();
597
601
  clientNameCache.clear();
598
602
  doc.value = new Y.Doc();
603
+ _resetSpaceConnections();
599
604
  _destroyBackgroundSync();
600
605
  _destroyFileBlobStore();
601
606
  _destroySearchIndex();
@@ -1512,6 +1517,20 @@ export default defineNuxtPlugin({
1512
1517
  });
1513
1518
  _provider.attach();
1514
1519
  provider.value = _provider;
1520
+ _initSpaceConnections({
1521
+ createProvider: (spaceId, ydoc) => {
1522
+ const p = new AbracadabraProvider({
1523
+ name: spaceId,
1524
+ document: ydoc,
1525
+ websocketProvider: wsp,
1526
+ client: _client,
1527
+ forceSyncInterval: 3e4,
1528
+ token: () => tm.getValidToken()
1529
+ });
1530
+ p.attach();
1531
+ return p;
1532
+ }
1533
+ });
1515
1534
  try {
1516
1535
  const { FileBlobStore } = await import("@abraca/dabra");
1517
1536
  const blobStore = new FileBlobStore(serverUrl, _client);
@@ -1,2 +1,2 @@
1
- declare const _default: any;
1
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: any;
1
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
2
  export default _default;
@@ -0,0 +1,30 @@
1
+ import type { XmlFragment, Doc as YDoc } from 'yjs';
2
+ /**
3
+ * enforceDocumentShape — bulletproofs the structural invariant
4
+ * `documentHeader@0 + documentMeta@1 + block+` directly on the Y.XmlFragment.
5
+ *
6
+ * Operates *below* y-prosemirror so PM never sees a damaged shape (which would
7
+ * trigger PM's schema corrector to insert synthetic empty nodes — the root
8
+ * cause of "title moves down a few lines" and "metadata vanishes").
9
+ *
10
+ * Repairs performed, all inside a single `ydoc.transact(_, 'shape-enforcer')`:
11
+ * 1. Pick the *canonical* documentHeader by text weight (longer-text-wins).
12
+ * Tie → earliest. All other documentHeaders are deleted.
13
+ * 2. Pick the canonical documentMeta by child count. Tie → earliest.
14
+ * Before deleting extras, clone their metaField children into the
15
+ * canonical (deduped by metaKey/startKey/latKey identity) so no
16
+ * property chips are ever lost to a merge.
17
+ * 3. Delete any empty paragraph immediately adjacent to a deleted
18
+ * header/meta (legacy seed cleanup — pairs created during concurrent
19
+ * empty-seeding).
20
+ * 4. If canonical documentHeader is not at index 0, clone+reinsert at 0.
21
+ * 5. If canonical documentMeta is not at index 1 (or directly after the
22
+ * header), clone+reinsert at the correct slot.
23
+ * 6. If documentHeader is missing entirely, insert empty at index 0.
24
+ * 7. If documentMeta is missing entirely, insert empty after header.
25
+ *
26
+ * Idempotent. Safe to call on every observe event (no-op when healthy).
27
+ *
28
+ * Ported from cou-sh/app/utils/enforceDocumentShape.ts.
29
+ */
30
+ export declare function enforceDocumentShape(fragment: XmlFragment, ydoc: YDoc): void;