@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.
- package/dist/module.json +1 -1
- package/dist/runtime/components/ADocRenderer.d.vue.ts +12 -0
- package/dist/runtime/components/ADocRenderer.vue +20 -19
- package/dist/runtime/components/ADocRenderer.vue.d.ts +12 -0
- package/dist/runtime/components/ADocumentTree.d.vue.ts +10 -0
- package/dist/runtime/components/ADocumentTree.vue +33 -8
- package/dist/runtime/components/ADocumentTree.vue.d.ts +10 -0
- package/dist/runtime/components/AEditor.d.vue.ts +2 -2
- package/dist/runtime/components/AEditor.vue +12 -5
- package/dist/runtime/components/AEditor.vue.d.ts +2 -2
- package/dist/runtime/components/AEmailVerifyConfirmModal.d.vue.ts +1 -1
- package/dist/runtime/components/AEmailVerifyConfirmModal.vue.d.ts +1 -1
- package/dist/runtime/components/ANodePanel.vue +11 -3
- package/dist/runtime/components/ASetPasswordCard.d.vue.ts +1 -1
- package/dist/runtime/components/ASetPasswordCard.vue.d.ts +1 -1
- package/dist/runtime/components/aware/AMedia.d.vue.ts +1 -1
- package/dist/runtime/components/aware/AMedia.vue.d.ts +1 -1
- package/dist/runtime/components/renderers/AProseRenderer.d.vue.ts +2 -2
- package/dist/runtime/components/renderers/AProseRenderer.vue.d.ts +2 -2
- package/dist/runtime/composables/useConnectionStatus.d.ts +1 -1
- package/dist/runtime/composables/useDocTree.d.ts +8 -1
- package/dist/runtime/composables/useDocTree.js +24 -4
- package/dist/runtime/composables/useEditor.js +8 -51
- package/dist/runtime/composables/useSpaceConnections.d.ts +75 -18
- package/dist/runtime/composables/useSpaceConnections.js +244 -61
- package/dist/runtime/middleware/abracadabra-auth.d.ts +1 -1
- package/dist/runtime/plugin-abracadabra.client.d.ts +1 -1
- package/dist/runtime/plugin-abracadabra.client.js +19 -0
- package/dist/runtime/plugin-abracadabra.server.d.ts +1 -1
- package/dist/runtime/plugin-shared-globals.client.d.ts +1 -1
- package/dist/runtime/utils/enforceDocumentShape.d.ts +30 -0
- package/dist/runtime/utils/enforceDocumentShape.js +228 -0
- package/package.json +1 -1
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { XmlElement } from "yjs";
|
|
2
|
+
export function enforceDocumentShape(fragment, ydoc) {
|
|
3
|
+
if (!fragment || !ydoc) return;
|
|
4
|
+
const children = fragment.toArray();
|
|
5
|
+
if (children.length === 0) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const headers = [];
|
|
9
|
+
const metas = [];
|
|
10
|
+
children.forEach((c, idx) => {
|
|
11
|
+
if (!(c instanceof XmlElement)) return;
|
|
12
|
+
if (c.nodeName === "documentHeader") {
|
|
13
|
+
headers.push({
|
|
14
|
+
idx,
|
|
15
|
+
el: c,
|
|
16
|
+
hasContent: hasHeaderText(c),
|
|
17
|
+
weight: weighElement(c)
|
|
18
|
+
});
|
|
19
|
+
} else if (c.nodeName === "documentMeta") {
|
|
20
|
+
metas.push({
|
|
21
|
+
idx,
|
|
22
|
+
el: c,
|
|
23
|
+
hasContent: hasMetaFields(c),
|
|
24
|
+
weight: weighElement(c)
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const canonicalHeader = pickCanonical(headers);
|
|
29
|
+
const canonicalMeta = pickCanonical(metas);
|
|
30
|
+
const headerExtras = canonicalHeader ? headers.filter((h) => h !== canonicalHeader) : [];
|
|
31
|
+
const metaExtras = canonicalMeta ? metas.filter((m) => m !== canonicalMeta) : [];
|
|
32
|
+
const headerMissing = !canonicalHeader;
|
|
33
|
+
const metaMissing = !canonicalMeta;
|
|
34
|
+
const headerMisplaced = !!canonicalHeader && canonicalHeader.idx !== 0;
|
|
35
|
+
const metaMisplaced = !!canonicalMeta && (canonicalHeader ? canonicalMeta.idx !== (headerMisplaced ? 1 : canonicalHeader.idx + 1) : canonicalMeta.idx !== 0);
|
|
36
|
+
const hasDupes = headerExtras.length > 0 || metaExtras.length > 0;
|
|
37
|
+
if (!headerMissing && !metaMissing && !headerMisplaced && !metaMisplaced && !hasDupes) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const canonicalMetaKeys = /* @__PURE__ */ new Set();
|
|
41
|
+
if (canonicalMeta) {
|
|
42
|
+
forEachChild(canonicalMeta.el, (child) => {
|
|
43
|
+
if (child instanceof XmlElement && child.nodeName === "metaField") {
|
|
44
|
+
const id = metaFieldIdentity(child);
|
|
45
|
+
if (id) canonicalMetaKeys.add(id);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const metaFieldsToMerge = [];
|
|
50
|
+
for (const extra of metaExtras) {
|
|
51
|
+
forEachChild(extra.el, (child) => {
|
|
52
|
+
if (!(child instanceof XmlElement) || child.nodeName !== "metaField") return;
|
|
53
|
+
const id = metaFieldIdentity(child);
|
|
54
|
+
if (id && canonicalMetaKeys.has(id)) return;
|
|
55
|
+
if (id) canonicalMetaKeys.add(id);
|
|
56
|
+
const cloned = cloneMetaFieldElement(child);
|
|
57
|
+
if (cloned) metaFieldsToMerge.push(cloned);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
ydoc.transact(() => {
|
|
61
|
+
if (metaFieldsToMerge.length > 0 && canonicalMeta?.el) {
|
|
62
|
+
try {
|
|
63
|
+
canonicalMeta.el.insert(canonicalMeta.el.length, metaFieldsToMerge);
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const childrenSnap = fragment.toArray();
|
|
68
|
+
const protectedIdx = /* @__PURE__ */ new Set();
|
|
69
|
+
if (canonicalHeader) protectedIdx.add(canonicalHeader.idx);
|
|
70
|
+
if (canonicalMeta) protectedIdx.add(canonicalMeta.idx);
|
|
71
|
+
const toDelete = /* @__PURE__ */ new Set();
|
|
72
|
+
const queueAdjacentEmpty = (anchor) => {
|
|
73
|
+
const after = anchor + 1;
|
|
74
|
+
if (after < childrenSnap.length && childrenSnap[after]?.nodeName === "paragraph" && (childrenSnap[after]?.length ?? 0) === 0 && !protectedIdx.has(after) && !toDelete.has(after))
|
|
75
|
+
toDelete.add(after);
|
|
76
|
+
};
|
|
77
|
+
for (const h of headerExtras) {
|
|
78
|
+
toDelete.add(h.idx);
|
|
79
|
+
queueAdjacentEmpty(h.idx);
|
|
80
|
+
}
|
|
81
|
+
for (const m of metaExtras) {
|
|
82
|
+
toDelete.add(m.idx);
|
|
83
|
+
queueAdjacentEmpty(m.idx);
|
|
84
|
+
}
|
|
85
|
+
const sorted = [...toDelete].sort((a, b) => b - a);
|
|
86
|
+
for (const idx of sorted) {
|
|
87
|
+
try {
|
|
88
|
+
fragment.delete(idx, 1);
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
let curHeaderIdx = findFirst(fragment, "documentHeader");
|
|
93
|
+
if (curHeaderIdx > 0) {
|
|
94
|
+
const headerEl = fragment.toArray()[curHeaderIdx];
|
|
95
|
+
const cloned = headerEl ? safeClone(headerEl) : null;
|
|
96
|
+
if (cloned) {
|
|
97
|
+
fragment.delete(curHeaderIdx, 1);
|
|
98
|
+
fragment.insert(0, [cloned]);
|
|
99
|
+
curHeaderIdx = 0;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const expectedMetaIdx = curHeaderIdx >= 0 ? curHeaderIdx + 1 : 0;
|
|
103
|
+
const curMetaIdx = findFirst(fragment, "documentMeta");
|
|
104
|
+
if (curMetaIdx >= 0 && curMetaIdx !== expectedMetaIdx) {
|
|
105
|
+
const metaEl = fragment.toArray()[curMetaIdx];
|
|
106
|
+
const cloned = metaEl ? safeClone(metaEl) : null;
|
|
107
|
+
if (cloned) {
|
|
108
|
+
fragment.delete(curMetaIdx, 1);
|
|
109
|
+
const finalLen = fragment.length;
|
|
110
|
+
const target = Math.min(expectedMetaIdx, finalLen);
|
|
111
|
+
fragment.insert(target, [cloned]);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (findFirst(fragment, "documentHeader") === -1) {
|
|
115
|
+
fragment.insert(0, [new XmlElement("documentHeader")]);
|
|
116
|
+
}
|
|
117
|
+
if (findFirst(fragment, "documentMeta") === -1) {
|
|
118
|
+
const hIdx = findFirst(fragment, "documentHeader");
|
|
119
|
+
fragment.insert(hIdx >= 0 ? hIdx + 1 : 0, [new XmlElement("documentMeta")]);
|
|
120
|
+
}
|
|
121
|
+
}, "shape-enforcer");
|
|
122
|
+
}
|
|
123
|
+
function weighElement(el) {
|
|
124
|
+
let w = 0;
|
|
125
|
+
try {
|
|
126
|
+
w = (typeof el?.toString === "function" ? el.toString() : "").length;
|
|
127
|
+
} catch {
|
|
128
|
+
}
|
|
129
|
+
if (typeof el?.length === "number") w = Math.max(w, el.length);
|
|
130
|
+
return w;
|
|
131
|
+
}
|
|
132
|
+
function hasHeaderText(el) {
|
|
133
|
+
try {
|
|
134
|
+
const arr = el?.toArray?.();
|
|
135
|
+
if (!Array.isArray(arr)) return false;
|
|
136
|
+
for (const child of arr) {
|
|
137
|
+
const len = typeof child?.length === "number" ? child.length : typeof child?.toString === "function" ? child.toString().length : 0;
|
|
138
|
+
if (len > 0) return true;
|
|
139
|
+
}
|
|
140
|
+
} catch {
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
function hasMetaFields(el) {
|
|
145
|
+
try {
|
|
146
|
+
const arr = el?.toArray?.();
|
|
147
|
+
if (!Array.isArray(arr)) return false;
|
|
148
|
+
for (const child of arr) {
|
|
149
|
+
if (child instanceof XmlElement && child.nodeName === "metaField") return true;
|
|
150
|
+
}
|
|
151
|
+
} catch {
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
function pickCanonical(arr) {
|
|
156
|
+
if (arr.length === 0) return null;
|
|
157
|
+
let best = arr[0];
|
|
158
|
+
for (let i = 1; i < arr.length; i++) {
|
|
159
|
+
const c = arr[i];
|
|
160
|
+
if (c.hasContent && !best.hasContent) {
|
|
161
|
+
best = c;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (!c.hasContent && best.hasContent) continue;
|
|
165
|
+
if (c.weight > best.weight || c.weight === best.weight && c.idx < best.idx)
|
|
166
|
+
best = c;
|
|
167
|
+
}
|
|
168
|
+
return best;
|
|
169
|
+
}
|
|
170
|
+
function forEachChild(el, fn) {
|
|
171
|
+
try {
|
|
172
|
+
const arr = el?.toArray?.();
|
|
173
|
+
if (!Array.isArray(arr)) return;
|
|
174
|
+
for (const c of arr) fn(c);
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function metaFieldIdentity(mf) {
|
|
179
|
+
try {
|
|
180
|
+
const attrs = typeof mf?.getAttributes === "function" ? mf.getAttributes() : {};
|
|
181
|
+
const metaKey = String(attrs.metaKey ?? "");
|
|
182
|
+
if (metaKey) return `mk:${metaKey}`;
|
|
183
|
+
const startKey = String(attrs.startKey ?? "");
|
|
184
|
+
const endKey = String(attrs.endKey ?? "");
|
|
185
|
+
const latKey = String(attrs.latKey ?? "");
|
|
186
|
+
const lngKey = String(attrs.lngKey ?? "");
|
|
187
|
+
const allDayKey = String(attrs.allDayKey ?? "");
|
|
188
|
+
const composite = `${startKey}:${endKey}:${latKey}:${lngKey}:${allDayKey}`;
|
|
189
|
+
if (composite === "::::") return "";
|
|
190
|
+
return `c:${composite}`;
|
|
191
|
+
} catch {
|
|
192
|
+
return "";
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function cloneMetaFieldElement(src) {
|
|
196
|
+
try {
|
|
197
|
+
if (typeof src?.clone === "function") {
|
|
198
|
+
const c = src.clone();
|
|
199
|
+
if (c) return c;
|
|
200
|
+
}
|
|
201
|
+
const clone = new XmlElement("metaField");
|
|
202
|
+
const attrs = src.getAttributes();
|
|
203
|
+
for (const [k, v] of Object.entries(attrs)) clone.setAttribute(k, v);
|
|
204
|
+
return clone;
|
|
205
|
+
} catch {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function safeClone(src) {
|
|
210
|
+
try {
|
|
211
|
+
if (typeof src?.clone === "function") {
|
|
212
|
+
const c = src.clone();
|
|
213
|
+
if (c) return c;
|
|
214
|
+
}
|
|
215
|
+
} catch {
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
function findFirst(fragment, nodeName) {
|
|
220
|
+
try {
|
|
221
|
+
const arr = fragment.toArray();
|
|
222
|
+
for (let i = 0; i < arr.length; i++) {
|
|
223
|
+
if (arr[i]?.nodeName === nodeName) return i;
|
|
224
|
+
}
|
|
225
|
+
} catch {
|
|
226
|
+
}
|
|
227
|
+
return -1;
|
|
228
|
+
}
|