@abraca/nuxt 2.101.0 → 2.103.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/module.mjs +89 -3
- package/dist/runtime/components/ADocRenderer.vue +3 -3
- package/dist/runtime/components/shell/AUserMenu.d.vue.ts +2 -2
- package/dist/runtime/components/shell/AUserMenu.vue.d.ts +2 -2
- package/dist/runtime/composables/useAbracadabraSchema.d.ts +13 -0
- package/dist/runtime/composables/useAwareness.js +1 -1
- package/dist/runtime/composables/useChat.js +25 -9
- package/dist/runtime/composables/useChildTree.js +10 -7
- package/dist/runtime/composables/useDevicePairing.js +3 -3
- package/dist/runtime/composables/useDocPermissions.js +1 -1
- package/dist/runtime/composables/useDocSeo.js +3 -2
- package/dist/runtime/composables/useDocSlugs.d.ts +11 -1
- package/dist/runtime/composables/useDocSlugs.js +19 -7
- package/dist/runtime/composables/useDocTree.js +43 -16
- package/dist/runtime/composables/useIdentityDoc.js +1 -1
- package/dist/runtime/composables/useSearchIndex.js +1 -1
- package/dist/runtime/composables/useServerInfo.js +0 -1
- package/dist/runtime/composables/useTrash.js +5 -3
- package/dist/runtime/composables/useWebRTC.js +2 -2
- package/dist/runtime/composables/useWorkspace.js +2 -2
- package/dist/runtime/composables/useYDoc.d.ts +1 -0
- package/dist/runtime/composables/useYDoc.js +18 -2
- package/dist/runtime/extensions/views/DocEmbedView.vue +2 -2
- package/dist/runtime/plugin-abracadabra.client.js +66 -39
- package/dist/runtime/plugins/core.plugin.js +22 -1
- package/dist/runtime/utils/docTypes.js +10 -3
- package/dist/runtime/utils/sdkBackground.d.ts +5 -0
- package/dist/runtime/utils/sdkBackground.js +1 -0
- package/dist/runtime/utils/sdkCore.d.ts +18 -0
- package/dist/runtime/utils/sdkCore.js +10 -0
- package/dist/runtime/utils/sdkCrypto.d.ts +11 -0
- package/dist/runtime/utils/sdkCrypto.js +1 -0
- package/dist/runtime/utils/sdkExtras.d.ts +7 -0
- package/dist/runtime/utils/sdkExtras.js +6 -0
- package/dist/runtime/utils/sdkIdentity.d.ts +5 -0
- package/dist/runtime/utils/sdkIdentity.js +1 -0
- package/dist/runtime/utils/sdkRef.d.ts +9 -7
- package/dist/runtime/utils/sdkRef.js +8 -0
- package/dist/runtime/utils/slugify.d.ts +0 -10
- package/dist/runtime/utils/slugify.js +10 -0
- package/dist/runtime/utils/ssrMemo.d.ts +34 -0
- package/dist/runtime/utils/ssrMemo.js +11 -0
- package/package.json +5 -5
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
|
-
import { defineNuxtModule, createResolver, addPlugin, addPluginTemplate, addImportsDir, addImports, addComponentsDir, addServerHandler, addRouteMiddleware, addServerPlugin, addServerImportsDir } from '@nuxt/kit';
|
|
2
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
3
|
+
import { defineNuxtModule, createResolver, tryResolveModule, addPlugin, addPluginTemplate, addImportsDir, addImports, addComponentsDir, addServerHandler, addRouteMiddleware, addServerPlugin, addServerImportsDir } from '@nuxt/kit';
|
|
4
4
|
import { defu } from 'defu';
|
|
5
5
|
export { buildSlugMap, isUUID, slugify } from '../dist/runtime/utils/slugify.js';
|
|
6
6
|
export { avatarBorderStyle, avatarGradient, avatarStyleFromName } from '../dist/runtime/utils/avatarStyle.js';
|
|
@@ -12,6 +12,71 @@ export { renderNotificationDescription } from '../dist/runtime/utils/notificatio
|
|
|
12
12
|
export { scanDocReferences } from '../dist/runtime/utils/docReferenceEdges.js';
|
|
13
13
|
export { duplicateDocContent, duplicateDocTree } from '../dist/runtime/utils/duplicateDocContent.js';
|
|
14
14
|
|
|
15
|
+
const VIRTUAL = "virtual:abra-reka-ns/";
|
|
16
|
+
const RESOLVED = "\0abra-reka-ns:";
|
|
17
|
+
function parseRekaNamespaced(source) {
|
|
18
|
+
const objects = /* @__PURE__ */ new Map();
|
|
19
|
+
for (const m of source.matchAll(/^const (\w+) = \{([^}]*)\};/gm)) {
|
|
20
|
+
const members = [];
|
|
21
|
+
for (const line of m[2].split(",")) {
|
|
22
|
+
const kv = line.trim().match(/^(\w+):\s*(\w+)$/);
|
|
23
|
+
if (kv) members.push([kv[1], kv[2]]);
|
|
24
|
+
}
|
|
25
|
+
if (members.length) objects.set(m[1], members);
|
|
26
|
+
}
|
|
27
|
+
const direct = /* @__PURE__ */ new Set();
|
|
28
|
+
const re = source.match(/^export \{([^}]*)\} from 'reka-ui';/m);
|
|
29
|
+
if (re) {
|
|
30
|
+
for (const n of re[1].split(",")) if (n.trim()) direct.add(n.trim());
|
|
31
|
+
}
|
|
32
|
+
return { objects, direct };
|
|
33
|
+
}
|
|
34
|
+
function rekaNamespacedPlugin(namespacedFile) {
|
|
35
|
+
let map;
|
|
36
|
+
try {
|
|
37
|
+
map = parseRekaNamespaced(readFileSync(namespacedFile, "utf8"));
|
|
38
|
+
} catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
if (map.objects.size === 0) return null;
|
|
42
|
+
const IMPORT_RE = /import\s*\{([^}]+)\}\s*from\s*["']reka-ui\/namespaced["'];?/g;
|
|
43
|
+
return {
|
|
44
|
+
name: "abra:reka-namespaced-split",
|
|
45
|
+
enforce: "pre",
|
|
46
|
+
resolveId(id) {
|
|
47
|
+
if (id.startsWith(VIRTUAL)) return RESOLVED + id.slice(VIRTUAL.length);
|
|
48
|
+
return null;
|
|
49
|
+
},
|
|
50
|
+
load(id) {
|
|
51
|
+
if (!id.startsWith(RESOLVED)) return null;
|
|
52
|
+
const members = map.objects.get(id.slice(RESOLVED.length));
|
|
53
|
+
if (!members) return null;
|
|
54
|
+
return `export { ${members.map(([k, v]) => `${v} as ${k}`).join(", ")} } from 'reka-ui'
|
|
55
|
+
`;
|
|
56
|
+
},
|
|
57
|
+
transform(code, id) {
|
|
58
|
+
if (!code.includes("reka-ui/namespaced")) return null;
|
|
59
|
+
if (id.startsWith("\0")) return null;
|
|
60
|
+
let touched = false;
|
|
61
|
+
const out = code.replace(IMPORT_RE, (whole, spec) => {
|
|
62
|
+
const parts = spec.split(",").map((s) => s.trim()).filter(Boolean);
|
|
63
|
+
const lines = [];
|
|
64
|
+
for (const part of parts) {
|
|
65
|
+
const m = part.match(/^(\w+)(?:\s+as\s+(\w+))?$/);
|
|
66
|
+
if (!m) return whole;
|
|
67
|
+
const [, name, local = name] = m;
|
|
68
|
+
if (map.objects.has(name)) lines.push(`import * as ${local} from "${VIRTUAL}${name}";`);
|
|
69
|
+
else if (map.direct.has(name)) lines.push(`import { ${name} as ${local} } from "reka-ui";`);
|
|
70
|
+
else return whole;
|
|
71
|
+
}
|
|
72
|
+
touched = true;
|
|
73
|
+
return lines.join("\n");
|
|
74
|
+
});
|
|
75
|
+
return touched ? { code: out, map: null } : null;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
15
80
|
const module$1 = defineNuxtModule({
|
|
16
81
|
meta: {
|
|
17
82
|
name: "abracadabra-nuxt",
|
|
@@ -188,6 +253,20 @@ const module$1 = defineNuxtModule({
|
|
|
188
253
|
});
|
|
189
254
|
} catch {
|
|
190
255
|
}
|
|
256
|
+
{
|
|
257
|
+
let rekaPlugin = null;
|
|
258
|
+
nuxt.hook("vite:extendConfig", async (config) => {
|
|
259
|
+
rekaPlugin ??= (async () => {
|
|
260
|
+
const ui = await tryResolveModule("@nuxt/ui", `${nuxt.options.rootDir}/`);
|
|
261
|
+
const namespaced = ui ? await tryResolveModule("reka-ui/namespaced", ui) : void 0;
|
|
262
|
+
return namespaced ? rekaNamespacedPlugin(namespaced) : null;
|
|
263
|
+
})();
|
|
264
|
+
const plugin = await rekaPlugin;
|
|
265
|
+
if (!plugin) return;
|
|
266
|
+
const plugins = config.plugins ??= [];
|
|
267
|
+
plugins.unshift(plugin);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
191
270
|
if (options.addViteDedupe) {
|
|
192
271
|
const dedupePackages = [
|
|
193
272
|
"prosemirror-view",
|
|
@@ -224,7 +303,14 @@ const module$1 = defineNuxtModule({
|
|
|
224
303
|
// lowlight + highlight.js to one root copy so the runtime dynamic
|
|
225
304
|
// `import("lowlight")` and the optimizer agree on a single instance.
|
|
226
305
|
"lowlight",
|
|
227
|
-
"highlight.js"
|
|
306
|
+
"highlight.js",
|
|
307
|
+
// VueUse holds module-level state (shared composables, storage event
|
|
308
|
+
// buses) and is imported by this module, by jun-is and by the app. A
|
|
309
|
+
// workspace-linked checkout resolves one copy per package root — the
|
|
310
|
+
// playground build shipped two full copies of @vueuse/core, the second
|
|
311
|
+
// on the critical path of every page.
|
|
312
|
+
"@vueuse/core",
|
|
313
|
+
"@vueuse/shared"
|
|
228
314
|
];
|
|
229
315
|
nuxt.options.vite = defu(nuxt.options.vite, { resolve: { dedupe: [] } });
|
|
230
316
|
const existing = nuxt.options.vite.resolve?.dedupe ?? [];
|
|
@@ -28,13 +28,13 @@ const snapshotEntry = computed(
|
|
|
28
28
|
() => snapshot.value?.entries?.[props.docId]
|
|
29
29
|
);
|
|
30
30
|
const docTitle = computed(
|
|
31
|
-
() => props.entry?.label ??
|
|
31
|
+
() => props.entry?.label ?? resolvedEntry.value?.label ?? snapshotEntry.value?.label ?? "Untitled"
|
|
32
32
|
);
|
|
33
33
|
const docType = computed(
|
|
34
|
-
() => props.entry?.type ??
|
|
34
|
+
() => props.entry?.type ?? resolvedEntry.value?.type ?? snapshotEntry.value?.type ?? "doc"
|
|
35
35
|
);
|
|
36
36
|
const docMeta = computed(
|
|
37
|
-
() => props.entry?.meta ??
|
|
37
|
+
() => props.entry?.meta ?? resolvedEntry.value?.meta ?? snapshotEntry.value?.meta ?? {}
|
|
38
38
|
);
|
|
39
39
|
const canRenderOffline = computed(() => !!(props.entry?.type ?? snapshotEntry.value?.type));
|
|
40
40
|
const registry = usePluginRegistry();
|
|
@@ -14,13 +14,13 @@ type __VLS_Props = {
|
|
|
14
14
|
extraItems?: DropdownMenuItem[][];
|
|
15
15
|
};
|
|
16
16
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
17
|
-
logout: () => any;
|
|
18
17
|
"open-settings": () => any;
|
|
19
18
|
"open-account": () => any;
|
|
19
|
+
logout: () => any;
|
|
20
20
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
21
|
-
onLogout?: (() => any) | undefined;
|
|
22
21
|
"onOpen-settings"?: (() => any) | undefined;
|
|
23
22
|
"onOpen-account"?: (() => any) | undefined;
|
|
23
|
+
onLogout?: (() => any) | undefined;
|
|
24
24
|
}>, {
|
|
25
25
|
color: string;
|
|
26
26
|
collapsed: boolean;
|
|
@@ -14,13 +14,13 @@ type __VLS_Props = {
|
|
|
14
14
|
extraItems?: DropdownMenuItem[][];
|
|
15
15
|
};
|
|
16
16
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
17
|
-
logout: () => any;
|
|
18
17
|
"open-settings": () => any;
|
|
19
18
|
"open-account": () => any;
|
|
19
|
+
logout: () => any;
|
|
20
20
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
21
|
-
onLogout?: (() => any) | undefined;
|
|
22
21
|
"onOpen-settings"?: (() => any) | undefined;
|
|
23
22
|
"onOpen-account"?: (() => any) | undefined;
|
|
23
|
+
onLogout?: (() => any) | undefined;
|
|
24
24
|
}>, {
|
|
25
25
|
color: string;
|
|
26
26
|
collapsed: boolean;
|
|
@@ -44,6 +44,19 @@ export interface BeforeBootCtx {
|
|
|
44
44
|
declare module '#app' {
|
|
45
45
|
interface RuntimeNuxtHooks {
|
|
46
46
|
'abracadabra:before-boot': (ctx: BeforeBootCtx) => void | Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Awaited by the client plugin's `init()` immediately before it opens the
|
|
49
|
+
* WebSocket and the first provider — i.e. before any server-scoped
|
|
50
|
+
* IndexedDB store is opened. The place for work that must precede local
|
|
51
|
+
* CRDT state (dropping caches of a replaced server database) WITHOUT
|
|
52
|
+
* holding up hydration the way an async plugin does: `init()` runs after
|
|
53
|
+
* the app is interactive, and by the time it gets here the SDK import and
|
|
54
|
+
* the auth round trips have already happened, so a check started at
|
|
55
|
+
* plugin time usually costs nothing.
|
|
56
|
+
*/
|
|
57
|
+
'abracadabra:before-connect': (ctx: {
|
|
58
|
+
serverUrl: string;
|
|
59
|
+
}) => void | Promise<void>;
|
|
47
60
|
}
|
|
48
61
|
}
|
|
49
62
|
/**
|
|
@@ -19,7 +19,7 @@ export function useAwareness() {
|
|
|
19
19
|
_detach();
|
|
20
20
|
const awareness = provider.value?.awareness;
|
|
21
21
|
if (!awareness) {
|
|
22
|
-
states.value = /* @__PURE__ */ new Map();
|
|
22
|
+
if (states.value.size) states.value = /* @__PURE__ */ new Map();
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
const view = acquireAwarenessView(awareness);
|
|
@@ -2,23 +2,38 @@ import { ref, computed, watch } from "vue";
|
|
|
2
2
|
import { useAbracadabra } from "./useAbracadabra.js";
|
|
3
3
|
import { tsToMs } from "../utils/time.js";
|
|
4
4
|
import {
|
|
5
|
-
ChannelKeyResolver,
|
|
6
|
-
DocKeyManager,
|
|
7
|
-
decryptChatContent,
|
|
8
5
|
deriveDmDocId,
|
|
9
6
|
foldRecords,
|
|
10
7
|
isEncryptedContent,
|
|
11
8
|
recordFromYAny
|
|
12
9
|
} from "@abraca/dabra";
|
|
13
|
-
|
|
10
|
+
let _crypto = null;
|
|
11
|
+
function _loadCrypto() {
|
|
12
|
+
_crypto ??= import("../utils/sdkCrypto.js").catch((e) => {
|
|
13
|
+
_crypto = null;
|
|
14
|
+
throw e;
|
|
15
|
+
});
|
|
16
|
+
return _crypto;
|
|
17
|
+
}
|
|
18
|
+
let _docKeys = null;
|
|
19
|
+
async function _getDocKeys() {
|
|
20
|
+
if (!_docKeys) {
|
|
21
|
+
const { DocKeyManager } = await _loadCrypto();
|
|
22
|
+
_docKeys ??= new DocKeyManager();
|
|
23
|
+
}
|
|
24
|
+
return _docKeys;
|
|
25
|
+
}
|
|
14
26
|
const _resolverByClient = /* @__PURE__ */ new WeakMap();
|
|
15
|
-
function _resolveChannelKey(client) {
|
|
27
|
+
async function _resolveChannelKey(client) {
|
|
16
28
|
if (!client) return null;
|
|
17
29
|
const cached = _resolverByClient.get(client);
|
|
18
30
|
if (cached) return cached;
|
|
19
31
|
const { keystore } = useAbracadabra();
|
|
20
32
|
if (!keystore.value) return null;
|
|
21
|
-
const
|
|
33
|
+
const [{ ChannelKeyResolver }, docKeys] = await Promise.all([_loadCrypto(), _getDocKeys()]);
|
|
34
|
+
const existing = _resolverByClient.get(client);
|
|
35
|
+
if (existing) return existing;
|
|
36
|
+
const resolver = new ChannelKeyResolver(client, docKeys, keystore.value);
|
|
22
37
|
_resolverByClient.set(client, resolver);
|
|
23
38
|
return resolver;
|
|
24
39
|
}
|
|
@@ -287,7 +302,7 @@ export function _handleStatelessChat(payload) {
|
|
|
287
302
|
const { client } = useAbracadabra();
|
|
288
303
|
if (!client?.value) return;
|
|
289
304
|
try {
|
|
290
|
-
const resolver = _resolveChannelKey(client.value);
|
|
305
|
+
const resolver = await _resolveChannelKey(client.value);
|
|
291
306
|
if (!resolver) return;
|
|
292
307
|
const docKey = await resolver.docKeyFor(docId);
|
|
293
308
|
if (!docKey) return;
|
|
@@ -299,7 +314,7 @@ export function _handleStatelessChat(payload) {
|
|
|
299
314
|
atob(granteeKey.x25519Key.replace(/-/g, "+").replace(/_/g, "/")),
|
|
300
315
|
(c) => c.charCodeAt(0)
|
|
301
316
|
);
|
|
302
|
-
const wrapped = await
|
|
317
|
+
const wrapped = await (await _getDocKeys()).wrapKeyForRecipient(docKey, x25519Pub, docId);
|
|
303
318
|
const b64 = btoa(String.fromCharCode(...wrapped));
|
|
304
319
|
await client.value.uploadKeyEnvelopes(docId, {
|
|
305
320
|
key_epoch: 1,
|
|
@@ -390,7 +405,7 @@ async function _attachPeriodProvider(channel, rootProv, periodId) {
|
|
|
390
405
|
const arr = periodChild.document.getArray("messages");
|
|
391
406
|
const channelDocIdRaw = channel.startsWith("group:") ? channel.slice("group:".length) : channel;
|
|
392
407
|
const { client } = useAbracadabra();
|
|
393
|
-
const resolver = _resolveChannelKey(client?.value);
|
|
408
|
+
const resolver = await _resolveChannelKey(client?.value);
|
|
394
409
|
let channelDocKey = null;
|
|
395
410
|
let docKeyError = null;
|
|
396
411
|
if (resolver) {
|
|
@@ -408,6 +423,7 @@ async function _attachPeriodProvider(channel, rootProv, periodId) {
|
|
|
408
423
|
let content = f.content;
|
|
409
424
|
if (isEncryptedContent(content)) {
|
|
410
425
|
if (channelDocKey) {
|
|
426
|
+
const { decryptChatContent } = await _loadCrypto();
|
|
411
427
|
const decrypted = await decryptChatContent(content, channelDocKey);
|
|
412
428
|
content = decrypted ?? "[decryption failed]";
|
|
413
429
|
} else {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
|
-
import {
|
|
2
|
+
import { useSharedSyncedMap } from "./useYDoc.js";
|
|
3
3
|
import { useAbracadabra } from "./useAbracadabra.js";
|
|
4
4
|
import { useDocTreeSnapshot } from "./useDocTreeSnapshot.js";
|
|
5
5
|
import { isDescendantInMap } from "../utils/docDragDrop.js";
|
|
6
|
+
import { ssrMemo } from "../utils/ssrMemo.js";
|
|
6
7
|
export function useChildTree(rootDoc, parentDocId, options) {
|
|
7
8
|
const abraState = (() => {
|
|
8
9
|
try {
|
|
@@ -11,17 +12,17 @@ export function useChildTree(rootDoc, parentDocId, options) {
|
|
|
11
12
|
return null;
|
|
12
13
|
}
|
|
13
14
|
})();
|
|
14
|
-
const treeMap =
|
|
15
|
-
const trashMap =
|
|
15
|
+
const treeMap = useSharedSyncedMap(rootDoc, "doc-tree");
|
|
16
|
+
const trashMap = useSharedSyncedMap(rootDoc, "doc-trash");
|
|
16
17
|
const snapshot = useDocTreeSnapshot();
|
|
17
18
|
const source = computed(() => {
|
|
18
19
|
const live = treeMap.data;
|
|
19
20
|
if (live && Object.keys(live).length > 0) return live;
|
|
20
21
|
return snapshot.value?.entries ?? {};
|
|
21
22
|
});
|
|
22
|
-
const
|
|
23
|
+
const entriesOf = ssrMemo((src) => {
|
|
23
24
|
const result = [];
|
|
24
|
-
for (const [id, v] of Object.entries(
|
|
25
|
+
for (const [id, v] of Object.entries(src)) {
|
|
25
26
|
if (id === parentDocId && options?.isSpaceRoot) continue;
|
|
26
27
|
let pid = v.parentId ?? null;
|
|
27
28
|
if (options?.isSpaceRoot && pid === null) pid = parentDocId;
|
|
@@ -38,9 +39,10 @@ export function useChildTree(rootDoc, parentDocId, options) {
|
|
|
38
39
|
}
|
|
39
40
|
return result;
|
|
40
41
|
});
|
|
41
|
-
const
|
|
42
|
+
const entries = computed(() => entriesOf(source.value));
|
|
43
|
+
const indexOf = ssrMemo((all) => {
|
|
42
44
|
const map = /* @__PURE__ */ new Map();
|
|
43
|
-
for (const e of
|
|
45
|
+
for (const e of all) {
|
|
44
46
|
let arr = map.get(e.parentId);
|
|
45
47
|
if (!arr) {
|
|
46
48
|
arr = [];
|
|
@@ -51,6 +53,7 @@ export function useChildTree(rootDoc, parentDocId, options) {
|
|
|
51
53
|
for (const arr of map.values()) arr.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
52
54
|
return map;
|
|
53
55
|
});
|
|
56
|
+
const childrenByParent = computed(() => indexOf(entries.value));
|
|
54
57
|
function childrenOf(parentId) {
|
|
55
58
|
const target = parentId === null ? parentDocId : parentId;
|
|
56
59
|
const bucket = childrenByParent.value.get(target);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ref, shallowRef } from "vue";
|
|
2
|
-
import {
|
|
2
|
+
import { loadSdkExtras } from "../utils/sdkRef.js";
|
|
3
3
|
import { useRuntimeConfig } from "#imports";
|
|
4
4
|
import { useAbracadabra } from "./useAbracadabra.js";
|
|
5
5
|
const pairingRole = ref("idle");
|
|
@@ -24,7 +24,7 @@ async function _resolveIceServers() {
|
|
|
24
24
|
}
|
|
25
25
|
async function createOffer() {
|
|
26
26
|
cancelPairing();
|
|
27
|
-
const sdk =
|
|
27
|
+
const sdk = await loadSdkExtras().catch(() => null);
|
|
28
28
|
if (!sdk?.ManualSignaling) throw new Error("SDK not loaded \u2014 cannot create pairing");
|
|
29
29
|
const { ManualSignaling } = sdk;
|
|
30
30
|
const iceServers = await _resolveIceServers();
|
|
@@ -44,7 +44,7 @@ async function createOffer() {
|
|
|
44
44
|
}
|
|
45
45
|
async function acceptOffer(blob) {
|
|
46
46
|
cancelPairing();
|
|
47
|
-
const sdk =
|
|
47
|
+
const sdk = await loadSdkExtras().catch(() => null);
|
|
48
48
|
if (!sdk?.ManualSignaling) throw new Error("SDK not loaded \u2014 cannot create pairing");
|
|
49
49
|
const { ManualSignaling } = sdk;
|
|
50
50
|
const iceServers = await _resolveIceServers();
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { computed, ref, shallowRef, toValue } from "vue";
|
|
2
2
|
import {
|
|
3
|
-
DocKeyManager,
|
|
4
3
|
toPlain
|
|
5
4
|
} from "@abraca/dabra";
|
|
6
5
|
import { deriveColorFromPubKey } from "../types.js";
|
|
@@ -168,6 +167,7 @@ export function useDocPermissions(docId, options) {
|
|
|
168
167
|
if (!granteeKeys.length) throw new Error("grantee has no registered keys");
|
|
169
168
|
const granteeKey = granteeKeys[0];
|
|
170
169
|
if (!granteeKey.x25519Key) throw new Error("grantee has no x25519 pubkey on their primary key");
|
|
170
|
+
const { DocKeyManager } = await import("../utils/sdkCrypto.js");
|
|
171
171
|
const dkm = new DocKeyManager();
|
|
172
172
|
const docKey = await dkm.getDocKey(targetDocId, client.value, keystore.value);
|
|
173
173
|
if (!docKey) throw new Error("granter has no key envelope for this doc \u2014 cannot rewrap");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { computed, unref } from "vue";
|
|
2
|
-
import { useAbracadabra,
|
|
2
|
+
import { useAbracadabra, useFetch, useHead, useSeoMeta } from "#imports";
|
|
3
|
+
import { useSharedSyncedMap } from "./useYDoc.js";
|
|
3
4
|
function extractFirstParagraph(html) {
|
|
4
5
|
if (!html) return void 0;
|
|
5
6
|
const strip = (raw) => raw.replace(/<[^>]+>/g, "").replace(/&[a-z]+;/gi, " ").trim();
|
|
@@ -16,7 +17,7 @@ function extractFirstImage(html) {
|
|
|
16
17
|
}
|
|
17
18
|
export function useDocSeo(docId, options) {
|
|
18
19
|
const abra = useAbracadabra();
|
|
19
|
-
const treeMap =
|
|
20
|
+
const treeMap = useSharedSyncedMap(abra.doc, "doc-tree");
|
|
20
21
|
const resolvedId = computed(() => unref(docId) ?? "");
|
|
21
22
|
const entry = computed(() => resolvedId.value ? treeMap.data[resolvedId.value] : void 0);
|
|
22
23
|
const { data: renderData } = useFetch(
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { type SlugMap } from '../utils/slugify.js';
|
|
2
|
-
|
|
2
|
+
type DocSlugsReturn = ReturnType<typeof createDocSlugs>;
|
|
3
|
+
/**
|
|
4
|
+
* One instance per app. It reads only app-global state, and every caller used
|
|
5
|
+
* to build its own copy — a Y.Map observer, a reactive copy of the whole tree
|
|
6
|
+
* and a full slug-map rebuild on every tree change, times 58 call sites in a
|
|
7
|
+
* jun-is site (profiled at ~330 ms of main thread on one page load, 4× CPU).
|
|
8
|
+
* Same arrangement as `useDocTree()`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useDocSlugs(): DocSlugsReturn;
|
|
11
|
+
declare function createDocSlugs(): {
|
|
3
12
|
slugMap: import("vue").ComputedRef<SlugMap>;
|
|
4
13
|
getSlug: (docId: string) => string;
|
|
5
14
|
getDocId: (slug: string) => string | null;
|
|
6
15
|
getDocUrl: (docId: string) => string;
|
|
7
16
|
};
|
|
17
|
+
export {};
|
|
@@ -1,25 +1,37 @@
|
|
|
1
|
-
import { computed } from "vue";
|
|
1
|
+
import { computed, effectScope } from "vue";
|
|
2
2
|
import { buildSlugMap } from "../utils/slugify.js";
|
|
3
|
-
import {
|
|
3
|
+
import { ssrMemo } from "../utils/ssrMemo.js";
|
|
4
|
+
import { useNuxtApp, useRuntimeConfig } from "#imports";
|
|
4
5
|
import { useAbracadabra } from "./useAbracadabra.js";
|
|
5
|
-
import {
|
|
6
|
+
import { useSharedSyncedMap } from "./useYDoc.js";
|
|
6
7
|
import { useDocTreeSnapshot } from "./useDocTreeSnapshot.js";
|
|
7
8
|
export function useDocSlugs() {
|
|
9
|
+
const nuxtApp = useNuxtApp();
|
|
10
|
+
let slugs = nuxtApp._abraDocSlugs;
|
|
11
|
+
if (!slugs) {
|
|
12
|
+
slugs = effectScope(true).run(() => createDocSlugs());
|
|
13
|
+
nuxtApp._abraDocSlugs = slugs;
|
|
14
|
+
}
|
|
15
|
+
return slugs;
|
|
16
|
+
}
|
|
17
|
+
function createDocSlugs() {
|
|
8
18
|
const abra = useAbracadabra();
|
|
9
19
|
const config = useRuntimeConfig();
|
|
10
20
|
const docBasePath = config.public?.abracadabra?.docBasePath ?? "/doc";
|
|
11
|
-
const treeMap =
|
|
21
|
+
const treeMap = useSharedSyncedMap(abra.doc, "doc-tree");
|
|
12
22
|
const snapshot = useDocTreeSnapshot();
|
|
13
23
|
const source = computed(() => {
|
|
14
24
|
const live = treeMap.data;
|
|
15
25
|
if (live && Object.keys(live).length > 0) return live;
|
|
16
26
|
return snapshot.value?.entries ?? {};
|
|
17
27
|
});
|
|
18
|
-
const
|
|
19
|
-
() => Object.entries(
|
|
28
|
+
const entriesOf = ssrMemo(
|
|
29
|
+
(src) => Object.entries(src).map(([id, entry]) => ({ id, ...entry }))
|
|
20
30
|
);
|
|
31
|
+
const slugMapOf = ssrMemo(buildSlugMap);
|
|
32
|
+
const entries = computed(() => entriesOf(source.value));
|
|
21
33
|
const slugMap = computed(
|
|
22
|
-
() =>
|
|
34
|
+
() => slugMapOf(entries.value, abra.spaceDocId?.value ?? snapshot.value?.rootId ?? null)
|
|
23
35
|
);
|
|
24
36
|
const getSlug = (docId) => slugMap.value.idToSlug[docId] ?? docId;
|
|
25
37
|
const getDocId = (slug) => slugMap.value.slugToId[slug] ?? null;
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
import { computed, shallowRef, watch } from "vue";
|
|
1
|
+
import { computed, effectScope, shallowRef, watch } from "vue";
|
|
2
2
|
import { resolveDocType } from "../utils/docTypes.js";
|
|
3
3
|
import { buildSlugMap } from "../utils/slugify.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ssrMemo } from "../utils/ssrMemo.js";
|
|
5
|
+
import { useNuxtApp, useRuntimeConfig } from "#imports";
|
|
5
6
|
import { useDocTreeSnapshot } from "./useDocTreeSnapshot.js";
|
|
6
7
|
import { useAbracadabra } from "./useAbracadabra.js";
|
|
7
8
|
import { useSpaceConnections } from "./useSpaceConnections.js";
|
|
8
9
|
import { useSyncedMap } from "./useYDoc.js";
|
|
9
10
|
export function useDocTree(docId) {
|
|
11
|
+
if (docId) return createDocTree(docId);
|
|
12
|
+
const nuxtApp = useNuxtApp();
|
|
13
|
+
let tree = nuxtApp._abraDocTree;
|
|
14
|
+
if (!tree) {
|
|
15
|
+
const scope = effectScope(true);
|
|
16
|
+
tree = scope.run(() => createDocTree(null));
|
|
17
|
+
nuxtApp._abraDocTree = tree;
|
|
18
|
+
}
|
|
19
|
+
return tree;
|
|
20
|
+
}
|
|
21
|
+
function createDocTree(docId) {
|
|
10
22
|
const abra = useAbracadabra();
|
|
11
23
|
const { connections, getDocForDoc, findDocSpaceId } = useSpaceConnections();
|
|
12
24
|
const config = useRuntimeConfig();
|
|
@@ -37,23 +49,18 @@ export function useDocTree(docId) {
|
|
|
37
49
|
const spaceDocId = computed(
|
|
38
50
|
() => (docId ? findDocSpaceId(docId) ?? abra.spaceDocId.value : abra.spaceDocId.value) ?? snapshot.value?.rootId ?? null
|
|
39
51
|
);
|
|
40
|
-
const
|
|
41
|
-
() => Object.entries(
|
|
52
|
+
const entriesOf = ssrMemo(
|
|
53
|
+
(src, rootId) => Object.entries(src).filter(([id]) => id !== rootId).map(([id, entry]) => ({ id, ...entry }))
|
|
42
54
|
);
|
|
43
|
-
const
|
|
44
|
-
() =>
|
|
45
|
-
(e) => (!e.parentId || e.parentId ===
|
|
55
|
+
const topLevelOf = ssrMemo(
|
|
56
|
+
(all, rootId) => all.filter(
|
|
57
|
+
(e) => (!e.parentId || e.parentId === rootId) && !e.trashed && e.id !== rootId
|
|
46
58
|
).sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
|
47
59
|
);
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
const slugMap = computed(() => buildSlugMap(entries.value, spaceDocId.value ?? null));
|
|
54
|
-
const navigationItems = computed(
|
|
55
|
-
() => topLevelDocs.value.filter((e) => e.meta?.hidden !== true).map((e) => {
|
|
56
|
-
const slug = slugMap.value.idToSlug[e.id];
|
|
60
|
+
const slugMapOf = ssrMemo(buildSlugMap);
|
|
61
|
+
const navigationOf = ssrMemo(
|
|
62
|
+
(top, slugs) => top.filter((e) => e.meta?.hidden !== true).map((e) => {
|
|
63
|
+
const slug = slugs.idToSlug[e.id];
|
|
57
64
|
const path = slug ?? e.id;
|
|
58
65
|
return {
|
|
59
66
|
id: e.id,
|
|
@@ -64,5 +71,25 @@ export function useDocTree(docId) {
|
|
|
64
71
|
};
|
|
65
72
|
})
|
|
66
73
|
);
|
|
74
|
+
const entries = computed(() => entriesOf(source.value, spaceDocId.value));
|
|
75
|
+
const topLevelDocs = computed(() => topLevelOf(entries.value, spaceDocId.value));
|
|
76
|
+
const firstDocId = computed(() => topLevelDocs.value[0]?.id ?? null);
|
|
77
|
+
let entryCacheSource;
|
|
78
|
+
const entryCache = /* @__PURE__ */ new Map();
|
|
79
|
+
const getEntry = (id) => {
|
|
80
|
+
const src = source.value;
|
|
81
|
+
const raw = src[id];
|
|
82
|
+
if (!raw) return void 0;
|
|
83
|
+
if (!import.meta.server) return { id, ...raw };
|
|
84
|
+
if (entryCacheSource !== src) {
|
|
85
|
+
entryCacheSource = src;
|
|
86
|
+
entryCache.clear();
|
|
87
|
+
}
|
|
88
|
+
let entry = entryCache.get(id);
|
|
89
|
+
if (!entry) entryCache.set(id, entry = { id, ...raw });
|
|
90
|
+
return entry;
|
|
91
|
+
};
|
|
92
|
+
const slugMap = computed(() => slugMapOf(entries.value, spaceDocId.value ?? null));
|
|
93
|
+
const navigationItems = computed(() => navigationOf(topLevelDocs.value, slugMap.value));
|
|
67
94
|
return { entries, topLevelDocs, firstDocId, getEntry, navigationItems, raw: treeMap };
|
|
68
95
|
}
|
|
@@ -26,7 +26,7 @@ async function init(publicKeyB64, signChallenge, opts) {
|
|
|
26
26
|
}
|
|
27
27
|
async function _doInit(publicKeyB64, opts) {
|
|
28
28
|
if (typeof window === "undefined") return;
|
|
29
|
-
const { IdentityDocProvider } = await import("
|
|
29
|
+
const { IdentityDocProvider } = await import("../utils/sdkIdentity.js");
|
|
30
30
|
const providerConfig = {
|
|
31
31
|
publicKey: publicKeyB64,
|
|
32
32
|
autoConnect: false,
|
|
@@ -49,7 +49,7 @@ function extractDocTexts(ydoc, label, meta) {
|
|
|
49
49
|
return texts;
|
|
50
50
|
}
|
|
51
51
|
export function _initSearchIndex(serverOrigin) {
|
|
52
|
-
import("
|
|
52
|
+
import("../utils/sdkBackground.js").then(({ SearchIndex }) => {
|
|
53
53
|
_searchIndex = new SearchIndex(serverOrigin);
|
|
54
54
|
_isReady.value = true;
|
|
55
55
|
_indexedVersions.clear();
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { computed, ref } from "vue";
|
|
2
|
-
import { useSyncedMap } from "./useYDoc.js";
|
|
2
|
+
import { useSharedSyncedMap, useSyncedMap } from "./useYDoc.js";
|
|
3
3
|
import { useAbracadabra } from "./useAbracadabra.js";
|
|
4
4
|
const TRASH_SETTINGS_KEY = "abracadabra_trash_settings";
|
|
5
5
|
function loadTrashSettings() {
|
|
6
|
+
if (import.meta.server) return { autoPurgeDays: 30 };
|
|
6
7
|
try {
|
|
7
8
|
const raw = localStorage.getItem(TRASH_SETTINGS_KEY);
|
|
8
9
|
if (raw) return JSON.parse(raw);
|
|
@@ -21,8 +22,9 @@ function saveTrashSettings(settings) {
|
|
|
21
22
|
export function useTrash(rootDoc) {
|
|
22
23
|
const { doc: globalDoc, userName } = useAbracadabra();
|
|
23
24
|
const _doc = rootDoc ?? globalDoc;
|
|
24
|
-
const
|
|
25
|
-
const
|
|
25
|
+
const shared = _doc === globalDoc;
|
|
26
|
+
const trashMap = shared ? useSharedSyncedMap(_doc, "doc-trash") : useSyncedMap(_doc, "doc-trash");
|
|
27
|
+
const treeMap = shared ? useSharedSyncedMap(_doc, "doc-tree") : useSyncedMap(_doc, "doc-tree");
|
|
26
28
|
const autoPurgeDays = ref(loadTrashSettings().autoPurgeDays);
|
|
27
29
|
function setAutoPurgeDays(days) {
|
|
28
30
|
autoPurgeDays.value = days;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ref, shallowRef, computed } from "vue";
|
|
2
|
-
import {
|
|
2
|
+
import { loadSdkExtras } from "../utils/sdkRef.js";
|
|
3
3
|
import { useToast, useRuntimeConfig } from "#imports";
|
|
4
4
|
import { useAbracadabra } from "./useAbracadabra.js";
|
|
5
5
|
import { _wireFileTransferEvents, _destroyFileTransfer } from "./useFileTransfer.js";
|
|
@@ -134,7 +134,7 @@ async function connect(options) {
|
|
|
134
134
|
if (!provider.value) return;
|
|
135
135
|
const config = useRuntimeConfig();
|
|
136
136
|
const webrtcConfig = config.public.abracadabra?.webrtc ?? {};
|
|
137
|
-
const sdk =
|
|
137
|
+
const sdk = await loadSdkExtras().catch(() => null);
|
|
138
138
|
if (!sdk?.AbracadabraWebRTC) {
|
|
139
139
|
console.error("[abracadabra] SDK not loaded \u2014 cannot connect WebRTC");
|
|
140
140
|
return;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { computed, unref } from "vue";
|
|
2
2
|
import { useAbracadabra } from "./useAbracadabra.js";
|
|
3
|
-
import {
|
|
3
|
+
import { useSharedSyncedMap } from "./useYDoc.js";
|
|
4
4
|
export function useWorkspace(root) {
|
|
5
5
|
const abra = useAbracadabra();
|
|
6
|
-
const treeMap =
|
|
6
|
+
const treeMap = useSharedSyncedMap(abra.doc, "doc-tree");
|
|
7
7
|
const rootDocId = computed(() => {
|
|
8
8
|
const r = typeof root === "function" ? root() : unref(root);
|
|
9
9
|
return r || "";
|
|
@@ -21,6 +21,7 @@ export declare function useSyncedMap<T = any>(doc: ShallowRef<Y.Doc | null>, map
|
|
|
21
21
|
get: (key: string) => T | undefined;
|
|
22
22
|
yMap: import("vue").ComputedRef<Y.Map<T> | null>;
|
|
23
23
|
};
|
|
24
|
+
export declare function useSharedSyncedMap<T = any>(doc: ShallowRef<Y.Doc | null>, mapName: string): ReturnType<typeof useSyncedMap<T>>;
|
|
24
25
|
export declare function useSyncedArray<T = any>(doc: ShallowRef<Y.Doc | null>, arrayName: string): {
|
|
25
26
|
list: Ref<T[], T[]>;
|
|
26
27
|
push: (item: T) => void | undefined;
|
|
@@ -6,7 +6,9 @@ import {
|
|
|
6
6
|
watch,
|
|
7
7
|
nextTick,
|
|
8
8
|
onMounted,
|
|
9
|
-
onBeforeUnmount
|
|
9
|
+
onBeforeUnmount,
|
|
10
|
+
onScopeDispose,
|
|
11
|
+
effectScope
|
|
10
12
|
} from "vue";
|
|
11
13
|
import { acquireAwarenessView, releaseAwarenessView } from "./awarenessView.js";
|
|
12
14
|
export function useSyncedMap(doc, mapName) {
|
|
@@ -47,7 +49,7 @@ export function useSyncedMap(doc, mapName) {
|
|
|
47
49
|
});
|
|
48
50
|
};
|
|
49
51
|
watch(doc, (d) => d && init(d), { immediate: true });
|
|
50
|
-
|
|
52
|
+
onScopeDispose(() => {
|
|
51
53
|
if (ymap.value) ymap.value.unobserve(observer);
|
|
52
54
|
});
|
|
53
55
|
return {
|
|
@@ -60,6 +62,20 @@ export function useSyncedMap(doc, mapName) {
|
|
|
60
62
|
yMap: computed(() => ymap.value)
|
|
61
63
|
};
|
|
62
64
|
}
|
|
65
|
+
const _sharedMaps = /* @__PURE__ */ new WeakMap();
|
|
66
|
+
export function useSharedSyncedMap(doc, mapName) {
|
|
67
|
+
let byName = _sharedMaps.get(doc);
|
|
68
|
+
if (!byName) {
|
|
69
|
+
byName = /* @__PURE__ */ new Map();
|
|
70
|
+
_sharedMaps.set(doc, byName);
|
|
71
|
+
}
|
|
72
|
+
let shared = byName.get(mapName);
|
|
73
|
+
if (!shared) {
|
|
74
|
+
shared = effectScope(true).run(() => useSyncedMap(doc, mapName));
|
|
75
|
+
byName.set(mapName, shared);
|
|
76
|
+
}
|
|
77
|
+
return shared;
|
|
78
|
+
}
|
|
63
79
|
export function useSyncedArray(doc, arrayName) {
|
|
64
80
|
const list = ref([]);
|
|
65
81
|
const yarray = shallowRef(null);
|
|
@@ -4,7 +4,7 @@ import { NodeViewWrapper } from "@tiptap/vue-3";
|
|
|
4
4
|
import { computed, ref, shallowRef, watch } from "vue";
|
|
5
5
|
import { navigateTo } from "#imports";
|
|
6
6
|
import { useAbracadabra } from "../../composables/useAbracadabra";
|
|
7
|
-
import {
|
|
7
|
+
import { useSharedSyncedMap } from "../../composables/useYDoc";
|
|
8
8
|
import { useDocSlugs } from "../../composables/useDocSlugs";
|
|
9
9
|
import { usePluginRegistry } from "../../composables/usePluginRegistry";
|
|
10
10
|
import { resolveDocType } from "../../utils/docTypes";
|
|
@@ -24,7 +24,7 @@ const props = defineProps({
|
|
|
24
24
|
const editable = useNodeViewEditable(props);
|
|
25
25
|
const { doc: rootDoc, provider } = useAbracadabra();
|
|
26
26
|
const { getDocUrl } = useDocSlugs();
|
|
27
|
-
const treeMap =
|
|
27
|
+
const treeMap = useSharedSyncedMap(
|
|
28
28
|
rootDoc,
|
|
29
29
|
"doc-tree"
|
|
30
30
|
);
|
|
@@ -53,7 +53,8 @@ import {
|
|
|
53
53
|
_initSpaceConnections,
|
|
54
54
|
_resetSpaceConnections
|
|
55
55
|
} from "./composables/useSpaceConnections.js";
|
|
56
|
-
import { setSdkModule,
|
|
56
|
+
import { setSdkModule, loadSdkExtras } from "./utils/sdkRef.js";
|
|
57
|
+
import { _collectSchemaRegistries } from "./composables/useAbracadabraSchema.js";
|
|
57
58
|
const NUXT_UI_PRIMARY_COLORS = /* @__PURE__ */ new Set([
|
|
58
59
|
"red",
|
|
59
60
|
"orange",
|
|
@@ -154,8 +155,10 @@ function randomName(abraConfig) {
|
|
|
154
155
|
const nouns = abraConfig.guestName?.nouns?.length ? abraConfig.guestName.nouns : DEFAULT_NOUNS;
|
|
155
156
|
return `${adjs[Math.floor(Math.random() * adjs.length)]}-${nouns[Math.floor(Math.random() * nouns.length)]}`;
|
|
156
157
|
}
|
|
158
|
+
let _logTimeFormat = null;
|
|
157
159
|
function ts() {
|
|
158
|
-
|
|
160
|
+
_logTimeFormat ??= new Intl.DateTimeFormat("en-US", { hour12: false, hour: "2-digit", minute: "2-digit", second: "2-digit" });
|
|
161
|
+
return _logTimeFormat.format(/* @__PURE__ */ new Date());
|
|
159
162
|
}
|
|
160
163
|
function toBase64Url(bytes) {
|
|
161
164
|
let b = "";
|
|
@@ -240,13 +243,14 @@ export default defineNuxtPlugin({
|
|
|
240
243
|
const storedExternal = JSON.parse(
|
|
241
244
|
localStorage.getItem(STORAGE_KEY_EXTERNAL_PLUGINS) ?? "[]"
|
|
242
245
|
);
|
|
246
|
+
const enabledExternal = storedExternal.filter((p) => p.enabled);
|
|
243
247
|
const [
|
|
244
248
|
{ _resolveIdbPluginUrl },
|
|
245
249
|
{ _enqueueLoadTimePending, _clearLoadTimePending }
|
|
246
|
-
] = await Promise.all([
|
|
250
|
+
] = enabledExternal.length > 0 ? await Promise.all([
|
|
247
251
|
import("./composables/useUploadedPluginStore.js"),
|
|
248
252
|
import("./composables/useLoadTimePending.js")
|
|
249
|
-
]);
|
|
253
|
+
]) : [{ _resolveIdbPluginUrl: null }, { _enqueueLoadTimePending: null, _clearLoadTimePending: null }];
|
|
250
254
|
async function refetchManifest(url) {
|
|
251
255
|
try {
|
|
252
256
|
const manifestUrl = url.replace(/\/[^/]+$/, (m2) => `${m2.replace(/\.[^.]+$/, "")}.manifest.json`);
|
|
@@ -259,7 +263,7 @@ export default defineNuxtPlugin({
|
|
|
259
263
|
return null;
|
|
260
264
|
}
|
|
261
265
|
}
|
|
262
|
-
for (const entry of
|
|
266
|
+
for (const entry of enabledExternal) {
|
|
263
267
|
try {
|
|
264
268
|
const origin = entry.origin ?? "url";
|
|
265
269
|
if (origin !== "registry" && origin !== "upload" && !entry.url.startsWith("idb-plugin:")) {
|
|
@@ -310,7 +314,6 @@ export default defineNuxtPlugin({
|
|
|
310
314
|
localStorage.setItem(STORAGE_KEY_EXTERNAL_PLUGINS, JSON.stringify(updated));
|
|
311
315
|
}
|
|
312
316
|
}
|
|
313
|
-
const { _collectSchemaRegistries } = await import("./composables/useAbracadabraSchema.js");
|
|
314
317
|
const { schemas: schemaRegistries, plugins: inlinePlugins } = await _collectSchemaRegistries(nuxtApp);
|
|
315
318
|
for (const plugin of inlinePlugins) {
|
|
316
319
|
registry.register(plugin);
|
|
@@ -861,9 +864,7 @@ export default defineNuxtPlugin({
|
|
|
861
864
|
}
|
|
862
865
|
}
|
|
863
866
|
async function loginWithMnemonic(opts) {
|
|
864
|
-
const
|
|
865
|
-
if (!sdk) throw new Error("SDK not initialized");
|
|
866
|
-
const { mnemonicToKeyPair, validateMnemonic } = sdk;
|
|
867
|
+
const { mnemonicToKeyPair, validateMnemonic } = await loadSdkExtras();
|
|
867
868
|
if (!validateMnemonic(opts.mnemonic)) throw new Error("Invalid recovery phrase");
|
|
868
869
|
const kp = await mnemonicToKeyPair(opts.mnemonic, opts.passphrase);
|
|
869
870
|
const pubKey = kp.publicKeyB64;
|
|
@@ -1059,15 +1060,20 @@ export default defineNuxtPlugin({
|
|
|
1059
1060
|
addLog(`Invite code found in URL: ${pendingInviteCode.value}`, "auth");
|
|
1060
1061
|
}
|
|
1061
1062
|
}
|
|
1063
|
+
const infoPromise = fetchServerInfo(serverUrl);
|
|
1062
1064
|
try {
|
|
1063
1065
|
const [
|
|
1064
1066
|
sdkModule,
|
|
1065
1067
|
edModule,
|
|
1066
|
-
{ sha512 }
|
|
1068
|
+
{ sha512 },
|
|
1069
|
+
softKeystoreModule
|
|
1067
1070
|
] = await Promise.all([
|
|
1068
|
-
import("
|
|
1071
|
+
import("./utils/sdkCore.js"),
|
|
1069
1072
|
import("@noble/ed25519"),
|
|
1070
|
-
import("@noble/hashes/sha2.js")
|
|
1073
|
+
import("@noble/hashes/sha2.js"),
|
|
1074
|
+
// Was imported serially AFTER the three above — one more chunk
|
|
1075
|
+
// round trip on the connect path of every page load.
|
|
1076
|
+
import("./utils/softKeystore.js")
|
|
1071
1077
|
]);
|
|
1072
1078
|
setSdkModule(sdkModule);
|
|
1073
1079
|
const { AbracadabraClient, AbracadabraProvider, AbracadabraWS, CryptoIdentityKeystore, TokenManager, LocalStorageDeviceSessionStorage } = sdkModule;
|
|
@@ -1087,7 +1093,7 @@ export default defineNuxtPlugin({
|
|
|
1087
1093
|
const wasPreviouslyClaimed = localStorage.getItem(CLAIMED_FLAG_KEY) === "1";
|
|
1088
1094
|
const storedPubKey = localStorage.getItem(PUBKEY_KEY);
|
|
1089
1095
|
requirePasskeyOnLogin.value = localStorage.getItem(REQUIRE_PASSKEY_KEY) === "1";
|
|
1090
|
-
const { softKeystoreAvailable, getOrCreateSoftKey, getSoftKeyPublicKey, importSoftKeyFromSeed, signWithSoftKey } =
|
|
1096
|
+
const { softKeystoreAvailable, getOrCreateSoftKey, getSoftKeyPublicKey, importSoftKeyFromSeed, signWithSoftKey } = softKeystoreModule;
|
|
1091
1097
|
if (_ephemeralSeed) {
|
|
1092
1098
|
pubKey = toBase64Url(ed.getPublicKey(_ephemeralSeed));
|
|
1093
1099
|
identityState.value = "claimed";
|
|
@@ -1310,8 +1316,10 @@ export default defineNuxtPlugin({
|
|
|
1310
1316
|
const seededRole = jwtRoleClaim(_client.token);
|
|
1311
1317
|
if (seededRole) effectiveRole.value = seededRole;
|
|
1312
1318
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1319
|
+
if (!resumedMe || (resumedMe.displayName ?? null) !== userName.value) {
|
|
1320
|
+
_client.updateMe({ displayName: userName.value }).catch(() => {
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1315
1323
|
if (_client.isTokenValid() && !tm.hasSession) {
|
|
1316
1324
|
try {
|
|
1317
1325
|
const sess = await _client.requestDeviceSession({
|
|
@@ -1329,29 +1337,39 @@ export default defineNuxtPlugin({
|
|
|
1329
1337
|
addLog(`Device session unavailable: ${msg.slice(0, 80)}`, "auth");
|
|
1330
1338
|
}
|
|
1331
1339
|
}
|
|
1332
|
-
const
|
|
1333
|
-
|
|
1340
|
+
const refreshServerEntry = Promise.all([
|
|
1341
|
+
infoPromise,
|
|
1334
1342
|
_client.listSpaces().catch((e) => {
|
|
1335
1343
|
if (import.meta.dev) console.warn("[abracadabra] init: client.listSpaces failed", e);
|
|
1336
1344
|
return null;
|
|
1337
1345
|
})
|
|
1338
|
-
])
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1346
|
+
]).then(([info, spaceDocs]) => {
|
|
1347
|
+
const spacesInfo = spaceDocs ? { spaces: spaceDocs.map(spaceMetaFromDoc) } : null;
|
|
1348
|
+
const idx = savedServers.value.findIndex((s) => s.url === serverUrl);
|
|
1349
|
+
if (idx >= 0) {
|
|
1350
|
+
const updates = {};
|
|
1351
|
+
if (info.name && info.name !== savedServers.value[idx].label) updates.label = info.name;
|
|
1352
|
+
if (spacesInfo) {
|
|
1353
|
+
updates.cachedSpaces = spacesInfo.spaces;
|
|
1354
|
+
}
|
|
1355
|
+
if (Object.keys(updates).length) {
|
|
1356
|
+
savedServers.value[idx] = { ...savedServers.value[idx], ...updates };
|
|
1357
|
+
persistServers();
|
|
1358
|
+
}
|
|
1350
1359
|
}
|
|
1360
|
+
return { info, spacesInfo };
|
|
1361
|
+
});
|
|
1362
|
+
const serverBefore = savedServers.value.find((s) => s.url === serverUrl);
|
|
1363
|
+
let resolvedDocId = serverBefore?.entryDocId ?? configEntryDocId ?? serverBefore?.cachedSpaces?.[0]?.id;
|
|
1364
|
+
if (resolvedDocId) {
|
|
1365
|
+
refreshServerEntry.catch(() => {
|
|
1366
|
+
});
|
|
1367
|
+
} else {
|
|
1368
|
+
const { info, spacesInfo } = await refreshServerEntry;
|
|
1369
|
+
const server = savedServers.value.find((s) => s.url === serverUrl);
|
|
1370
|
+
resolvedDocId = server?.entryDocId ?? server?.cachedSpaces?.[0]?.id ?? spacesInfo?.spaces?.[0]?.id ?? info?.root_doc_id ?? void 0;
|
|
1351
1371
|
}
|
|
1352
|
-
|
|
1353
|
-
const docId = server?.entryDocId ?? configEntryDocId ?? server?.cachedSpaces?.[0]?.id ?? spacesInfo?.spaces?.[0]?.id ?? info?.root_doc_id ?? void 0;
|
|
1354
|
-
if (!docId) {
|
|
1372
|
+
if (!resolvedDocId) {
|
|
1355
1373
|
connectionError.value = "No entry document found. Configure entryDocId or ensure the server has spaces.";
|
|
1356
1374
|
addLog("No entry document \u2014 cannot connect", "system");
|
|
1357
1375
|
try {
|
|
@@ -1361,8 +1379,14 @@ export default defineNuxtPlugin({
|
|
|
1361
1379
|
}
|
|
1362
1380
|
return;
|
|
1363
1381
|
}
|
|
1382
|
+
const docId = resolvedDocId;
|
|
1364
1383
|
addLog(`Using document: ${docId}`, "data");
|
|
1365
1384
|
spaceDocId.value = docId;
|
|
1385
|
+
try {
|
|
1386
|
+
await nuxtApp.callHook("abracadabra:before-connect", { serverUrl });
|
|
1387
|
+
} catch (e) {
|
|
1388
|
+
console.warn("[abracadabra] before-connect hook failed:", e);
|
|
1389
|
+
}
|
|
1366
1390
|
const wsUrl = _client.wsUrl;
|
|
1367
1391
|
addLog(`WebSocket: ${wsUrl}`, "connection");
|
|
1368
1392
|
const wsp = new AbracadabraWS({
|
|
@@ -1425,7 +1449,7 @@ export default defineNuxtPlugin({
|
|
|
1425
1449
|
}
|
|
1426
1450
|
wasConnected = true;
|
|
1427
1451
|
if (!wasSynced && features.backgroundSync !== false) {
|
|
1428
|
-
import("
|
|
1452
|
+
import("./utils/sdkBackground.js").then(({ BackgroundSyncManager }) => {
|
|
1429
1453
|
if (_client && _provider) {
|
|
1430
1454
|
const manager = new BackgroundSyncManager(_provider, _client, _getFileBlobStore());
|
|
1431
1455
|
_initBackgroundSync(manager);
|
|
@@ -1501,12 +1525,15 @@ export default defineNuxtPlugin({
|
|
|
1501
1525
|
}
|
|
1502
1526
|
},
|
|
1503
1527
|
onAwarenessChange({ states }) {
|
|
1504
|
-
const currentIds = new Set(
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
const
|
|
1528
|
+
const currentIds = /* @__PURE__ */ new Set();
|
|
1529
|
+
const selfId = _provider?.peekAwareness?.()?.clientID;
|
|
1530
|
+
for (const state of states) {
|
|
1531
|
+
const id = state.clientId;
|
|
1532
|
+
if (currentIds.has(id)) continue;
|
|
1533
|
+
currentIds.add(id);
|
|
1534
|
+
const name = state.user?.name || "Anonymous";
|
|
1508
1535
|
clientNameCache.set(id, name);
|
|
1509
|
-
if (!lastClientIds.has(id) && id !==
|
|
1536
|
+
if (!lastClientIds.has(id) && id !== selfId) {
|
|
1510
1537
|
addLog(`${name} joined (${states.length} online)`, "user");
|
|
1511
1538
|
}
|
|
1512
1539
|
}
|
|
@@ -1556,7 +1583,7 @@ export default defineNuxtPlugin({
|
|
|
1556
1583
|
}
|
|
1557
1584
|
});
|
|
1558
1585
|
try {
|
|
1559
|
-
const { FileBlobStore } =
|
|
1586
|
+
const { FileBlobStore } = sdkModule;
|
|
1560
1587
|
const blobStore = new FileBlobStore(serverUrl, _client);
|
|
1561
1588
|
_initFileBlobStore(blobStore);
|
|
1562
1589
|
} catch {
|
|
@@ -225,11 +225,32 @@ async function loadClientExtensions() {
|
|
|
225
225
|
];
|
|
226
226
|
try {
|
|
227
227
|
const { Emoji } = await import("@tiptap/extension-emoji");
|
|
228
|
-
if (Emoji) extensions.push(Emoji);
|
|
228
|
+
if (Emoji) extensions.push(lazyEmojiStorage(Emoji));
|
|
229
229
|
} catch {
|
|
230
230
|
}
|
|
231
231
|
return extensions.filter(Boolean);
|
|
232
232
|
}
|
|
233
|
+
const _emojiStorageCache = /* @__PURE__ */ new WeakMap();
|
|
234
|
+
function lazyEmojiStorage(Emoji) {
|
|
235
|
+
return Emoji.extend({
|
|
236
|
+
addStorage() {
|
|
237
|
+
const ctx = this;
|
|
238
|
+
const emojis = ctx.options.emojis;
|
|
239
|
+
const parent = ctx.parent;
|
|
240
|
+
return {
|
|
241
|
+
emojis,
|
|
242
|
+
isSupported: (item) => {
|
|
243
|
+
let upstream = _emojiStorageCache.get(emojis);
|
|
244
|
+
if (!upstream && parent) {
|
|
245
|
+
upstream = parent();
|
|
246
|
+
_emojiStorageCache.set(emojis, upstream);
|
|
247
|
+
}
|
|
248
|
+
return upstream ? upstream.isSupported(item) : false;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
233
254
|
async function loadServerExtensions() {
|
|
234
255
|
const [
|
|
235
256
|
{ default: StarterKit },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineAsyncComponent } from "vue";
|
|
1
|
+
import { defineAsyncComponent, hydrateOnIdle } from "vue";
|
|
2
2
|
import ADocLoadingSkeleton from "../components/renderers/ADocLoadingSkeleton.vue";
|
|
3
3
|
import ADocLoadError from "../components/renderers/ADocLoadError.vue";
|
|
4
4
|
function defineDocComponent(loader) {
|
|
@@ -16,6 +16,13 @@ function defineDocComponent(loader) {
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
+
function defineIdleDocComponent(loader) {
|
|
20
|
+
const inner = defineDocComponent(loader);
|
|
21
|
+
return defineAsyncComponent({
|
|
22
|
+
loader: () => Promise.resolve(inner),
|
|
23
|
+
hydrate: hydrateOnIdle(2e3)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
19
26
|
const GEO_COLOR_PRESETS = ["#3b82f6", "#f97316", "#22c55e", "#ef4444", "#a855f7"];
|
|
20
27
|
const GEO_ICON_OPTIONS = [
|
|
21
28
|
"map-pin",
|
|
@@ -63,7 +70,7 @@ export const DOC_TYPES = {
|
|
|
63
70
|
available: true,
|
|
64
71
|
hasEditor: true,
|
|
65
72
|
supportsChildren: true,
|
|
66
|
-
component:
|
|
73
|
+
component: defineIdleDocComponent(
|
|
67
74
|
() => import("../components/AEditor.vue")
|
|
68
75
|
)
|
|
69
76
|
},
|
|
@@ -77,7 +84,7 @@ export const DOC_TYPES = {
|
|
|
77
84
|
supportsChildren: true,
|
|
78
85
|
childLabel: "Item",
|
|
79
86
|
defaultDepth: -1,
|
|
80
|
-
component:
|
|
87
|
+
component: defineIdleDocComponent(
|
|
81
88
|
() => import("../components/renderers/AProseRenderer.vue")
|
|
82
89
|
)
|
|
83
90
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BackgroundSyncManager, SearchIndex } from "@abraca/dabra";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The @abraca/dabra classes the client plugin boots with — and nothing else.
|
|
3
|
+
*
|
|
4
|
+
* A dynamic import of a whole package namespace cannot be tree-shaken: Rollup
|
|
5
|
+
* cannot prove which properties of the module object will be read, so every
|
|
6
|
+
* export survives (the lesson `lowlightCommon.ts` learned with 238 grammars).
|
|
7
|
+
* `import('@abraca/dabra')` in the plugin therefore shipped the ENTIRE SDK —
|
|
8
|
+
* WebRTC, E2E, device pairing, BIP-39, doc converters — in the entry chunk of
|
|
9
|
+
* every page: 52.8 KB brotli, against 21.1 KB for what boot actually uses.
|
|
10
|
+
*
|
|
11
|
+
* Importing THIS module instead gives Rollup a namespace whose exports are
|
|
12
|
+
* static named re-exports it can follow. Anything rarer lives in
|
|
13
|
+
* `sdkExtras.ts` or its own narrow module, loaded on first use.
|
|
14
|
+
*
|
|
15
|
+
* Rule: never write `import('@abraca/dabra')` in client code. Add the name
|
|
16
|
+
* here (boot path) or to a narrow module (anything else).
|
|
17
|
+
*/
|
|
18
|
+
export { AbracadabraClient, AbracadabraProvider, AbracadabraWS, CryptoIdentityKeystore, TokenManager, LocalStorageDeviceSessionStorage, FileBlobStore, BroadcastChannelSync, } from '@abraca/dabra';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The E2E chat/document crypto (X25519 key wrapping, AES channel keys) —
|
|
3
|
+
* loaded when an encrypted channel or a key grant actually needs it.
|
|
4
|
+
*
|
|
5
|
+
* `useChat` is wired by the client plugin at boot, and it used to import these
|
|
6
|
+
* statically and build a `DocKeyManager` at module load, which put the whole
|
|
7
|
+
* crypto path (and `@noble/curves`) in the entry chunk of every page, for
|
|
8
|
+
* every visitor, on sites that have never had an encrypted channel. Narrow on
|
|
9
|
+
* purpose; see `sdkCore.ts`.
|
|
10
|
+
*/
|
|
11
|
+
export { ChannelKeyResolver, DocKeyManager, decryptChatContent } from '@abraca/dabra';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ChannelKeyResolver, DocKeyManager, decryptChatContent } from "@abraca/dabra";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @abraca/dabra features no page needs to boot — WebRTC, device pairing and
|
|
3
|
+
* recovery-phrase login. Loaded on first use via `loadSdkExtras()`; see
|
|
4
|
+
* `sdkCore.ts` for why this is a separate module rather than a namespace
|
|
5
|
+
* import of the package.
|
|
6
|
+
*/
|
|
7
|
+
export { AbracadabraWebRTC, ManualSignaling, mnemonicToKeyPair, validateMnemonic, } from '@abraca/dabra';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IdentityDocProvider } from "@abraca/dabra";
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared reference to the lazily-loaded @abraca/dabra
|
|
2
|
+
* Shared reference to the lazily-loaded @abraca/dabra boot classes.
|
|
3
3
|
*
|
|
4
|
-
* The main client plugin imports
|
|
5
|
-
* the module here.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* The main client plugin imports `./sdkCore` once during init() and stashes
|
|
5
|
+
* the module here. Rarer SDK features (WebRTC, device pairing, mnemonic
|
|
6
|
+
* login) come from `loadSdkExtras()`, a narrow module loaded on first use —
|
|
7
|
+
* never from a namespace import of the package, which would defeat
|
|
8
|
+
* tree-shaking for the whole SDK (see `sdkCore.ts`).
|
|
9
9
|
*/
|
|
10
|
-
export type SdkModule = typeof import('
|
|
10
|
+
export type SdkModule = typeof import('./sdkCore');
|
|
11
|
+
export type SdkExtras = typeof import('./sdkExtras');
|
|
11
12
|
export declare function setSdkModule(mod: SdkModule): void;
|
|
12
13
|
export declare function getSdkModule(): SdkModule | null;
|
|
14
|
+
export declare function loadSdkExtras(): Promise<SdkExtras>;
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
let _sdk = null;
|
|
2
|
+
let _extras = null;
|
|
2
3
|
export function setSdkModule(mod) {
|
|
3
4
|
_sdk = mod;
|
|
4
5
|
}
|
|
5
6
|
export function getSdkModule() {
|
|
6
7
|
return _sdk;
|
|
7
8
|
}
|
|
9
|
+
export function loadSdkExtras() {
|
|
10
|
+
_extras ??= import("./sdkExtras.js").catch((e) => {
|
|
11
|
+
_extras = null;
|
|
12
|
+
throw e;
|
|
13
|
+
});
|
|
14
|
+
return _extras;
|
|
15
|
+
}
|
|
@@ -4,16 +4,6 @@
|
|
|
4
4
|
* Generates deterministic, hierarchical, human-readable URL slugs from the
|
|
5
5
|
* doc-tree. Same tree always produces the same slug map.
|
|
6
6
|
*/
|
|
7
|
-
/**
|
|
8
|
-
* Convert a label to a URL-safe slug.
|
|
9
|
-
*
|
|
10
|
-
* - Lowercases
|
|
11
|
-
* - Normalizes unicode (NFD, strip diacritics)
|
|
12
|
-
* - Replaces non-alphanumeric with hyphens
|
|
13
|
-
* - Collapses consecutive hyphens
|
|
14
|
-
* - Trims leading/trailing hyphens
|
|
15
|
-
* - Returns 'untitled' for empty input
|
|
16
|
-
*/
|
|
17
7
|
export declare function slugify(label: string): string;
|
|
18
8
|
/** Check whether a string is a valid UUID v4 (case-insensitive). */
|
|
19
9
|
export declare const isUUID: (s: string) => boolean;
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
const _slugCache = /* @__PURE__ */ new Map();
|
|
2
|
+
const SLUG_CACHE_MAX = 5e3;
|
|
1
3
|
export function slugify(label) {
|
|
4
|
+
const hit = _slugCache.get(label);
|
|
5
|
+
if (hit !== void 0) return hit;
|
|
6
|
+
const out = _slugify(label);
|
|
7
|
+
if (_slugCache.size >= SLUG_CACHE_MAX) _slugCache.clear();
|
|
8
|
+
_slugCache.set(label, out);
|
|
9
|
+
return out;
|
|
10
|
+
}
|
|
11
|
+
function _slugify(label) {
|
|
2
12
|
const slug = label.normalize("NFD").replace(/[\u0300-\u036F]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/-{2,}/g, "-").replace(/^-|-$/g, "");
|
|
3
13
|
return slug || "untitled";
|
|
4
14
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ssrMemo(fn)` — remember `fn`'s last result for the same arguments, on the
|
|
3
|
+
* server only.
|
|
4
|
+
*
|
|
5
|
+
* ## Why this exists
|
|
6
|
+
*
|
|
7
|
+
* A `computed()` created during SSR does not cache the way it does in the
|
|
8
|
+
* browser. With no render effect subscribed, Vue (3.5, `refreshComputed`)
|
|
9
|
+
* keeps an SSR computed's value only while the PROCESS-GLOBAL reactive version
|
|
10
|
+
* is unchanged — and any ref write anywhere bumps it: a component's own
|
|
11
|
+
* `ref()` assignments, a `useState`, a concurrent request. So during a render
|
|
12
|
+
* an SSR computed re-runs on nearly every `.value` read.
|
|
13
|
+
*
|
|
14
|
+
* That is harmless for a cheap getter and ruinous for a derivation over the
|
|
15
|
+
* whole tree read once per link: `useDocSlugs().getDocUrl(id)` rebuilt the
|
|
16
|
+
* site's slug map on every call — 63 full rebuilds of a 144-entry tree to
|
|
17
|
+
* render one jun-is front page, the largest single item in its SSR profile.
|
|
18
|
+
*
|
|
19
|
+
* ## Why identity is exact here, and why only on the server
|
|
20
|
+
*
|
|
21
|
+
* Wrap the heavy step of a computed so it takes its inputs as ARGUMENTS:
|
|
22
|
+
*
|
|
23
|
+
* const slugMap = computed(() => slugMapOf(entries.value, rootId.value))
|
|
24
|
+
* const slugMapOf = ssrMemo((entries, rootId) => buildSlugMap(entries, rootId))
|
|
25
|
+
*
|
|
26
|
+
* On the server a tree source is the request's snapshot, which is only ever
|
|
27
|
+
* REPLACED (`state.value = …`), never mutated in place — so the same object
|
|
28
|
+
* means the same content, and a replacement is a new object and a miss.
|
|
29
|
+
*
|
|
30
|
+
* In the browser the live source is a `reactive()` object mutated in place, so
|
|
31
|
+
* identity says nothing there; `computed()`'s own dependency tracking is exact
|
|
32
|
+
* and cheap. The browser therefore gets `fn` back untouched.
|
|
33
|
+
*/
|
|
34
|
+
export declare function ssrMemo<A extends readonly unknown[], R>(fn: (...args: A) => R): (...args: A) => R;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function ssrMemo(fn) {
|
|
2
|
+
if (!import.meta.server) return fn;
|
|
3
|
+
let last;
|
|
4
|
+
let value;
|
|
5
|
+
return (...args) => {
|
|
6
|
+
if (last && last.length === args.length && last.every((a, i) => a === args[i])) return value;
|
|
7
|
+
value = fn(...args);
|
|
8
|
+
last = args;
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abraca/nuxt",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.103.0",
|
|
4
4
|
"description": "First-class Nuxt module for the Abracadabra CRDT collaboration platform",
|
|
5
5
|
"repository": "abracadabra/abracadabra-nuxt",
|
|
6
6
|
"license": "MIT",
|
|
@@ -173,10 +173,10 @@
|
|
|
173
173
|
}
|
|
174
174
|
},
|
|
175
175
|
"devDependencies": {
|
|
176
|
-
"@abraca/convert": "^2.
|
|
177
|
-
"@abraca/dabra": "^2.
|
|
178
|
-
"@abraca/plugin": "^2.
|
|
179
|
-
"@abraca/schema": "^2.
|
|
176
|
+
"@abraca/convert": "^2.102.0",
|
|
177
|
+
"@abraca/dabra": "^2.102.0",
|
|
178
|
+
"@abraca/plugin": "^2.102.0",
|
|
179
|
+
"@abraca/schema": "^2.102.0",
|
|
180
180
|
"@codemirror/autocomplete": "^6.18.0",
|
|
181
181
|
"@codemirror/commands": "^6.7.0",
|
|
182
182
|
"@codemirror/lang-css": "^6.3.1",
|