@abraca/junis 2.80.0 → 2.81.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 +5 -0
- package/dist/runtime/assets/css/jun.css +1 -1
- package/dist/runtime/components/JunSettings.client.d.vue.ts +3 -0
- package/dist/runtime/components/JunSettings.client.vue +195 -0
- package/dist/runtime/components/JunSettings.client.vue.d.ts +3 -0
- package/dist/runtime/components/JunStudioBar.client.vue +11 -23
- package/dist/runtime/components/renderers/JunConfigRenderer.d.vue.ts +13 -0
- package/dist/runtime/components/renderers/JunConfigRenderer.vue +54 -21
- package/dist/runtime/components/renderers/JunConfigRenderer.vue.d.ts +13 -0
- package/dist/runtime/composables/useJunCommands.js +15 -12
- package/dist/runtime/composables/useJunDocPage.d.ts +8 -1
- package/dist/runtime/composables/useJunDocPage.js +6 -4
- package/dist/runtime/composables/useJunRename.js +6 -5
- package/dist/runtime/composables/useJunSettings.d.ts +24 -0
- package/dist/runtime/composables/useJunSettings.js +48 -0
- package/dist/runtime/composables/useJunSiteConfig.d.ts +69 -27
- package/dist/runtime/composables/useJunSiteConfig.js +62 -53
- package/dist/runtime/layouts/jun.vue +18 -2
- package/dist/runtime/pages/index.vue +18 -8
- package/dist/runtime/plugins/jun-site-config.d.ts +17 -0
- package/dist/runtime/plugins/jun-site-config.js +26 -0
- package/dist/runtime/server/api/resolve/[...slug].get.d.ts +15 -1
- package/dist/runtime/server/api/resolve/[...slug].get.js +24 -2
- package/dist/runtime/server/utils/junCache.d.ts +15 -12
- package/dist/runtime/server/utils/junCache.js +4 -2
- package/dist/runtime/server/utils/junSlugAlias.d.ts +42 -0
- package/dist/runtime/server/utils/junSlugAlias.js +14 -0
- package/package.json +1 -1
|
@@ -1,17 +1,39 @@
|
|
|
1
1
|
import { defineEventHandler, getRouterParam } from "h3";
|
|
2
2
|
import { junDocHtml, junDocTree, junSlugMap } from "../../utils/junCache.js";
|
|
3
|
+
import { junDocIdForAlias } from "../../utils/junSlugAlias.js";
|
|
4
|
+
import { isJunOwnerOnlyDoc } from "../../utils/junVisibility.js";
|
|
3
5
|
export default defineEventHandler(async (event) => {
|
|
4
6
|
const raw = getRouterParam(event, "slug") ?? getRouterParam(event, "_") ?? "";
|
|
5
7
|
const slug = raw.replace(/^\/+|\/+$/g, "");
|
|
6
8
|
const [tree, idToSlug] = await Promise.all([junDocTree(), junSlugMap()]);
|
|
7
9
|
const cacheReady = Object.keys(tree).length > 0;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
let docId = Object.entries(idToSlug).find(([, s]) => s === slug)?.[0];
|
|
11
|
+
let canonical = null;
|
|
12
|
+
if (!docId) {
|
|
13
|
+
const aliasId = junDocIdForAlias(tree, slug);
|
|
14
|
+
if (!aliasId) return { found: false, cacheReady };
|
|
15
|
+
docId = aliasId;
|
|
16
|
+
canonical = idToSlug[aliasId] ?? null;
|
|
17
|
+
}
|
|
10
18
|
const entry = tree[docId];
|
|
19
|
+
if (isJunOwnerOnlyDoc(entry)) {
|
|
20
|
+
return {
|
|
21
|
+
found: true,
|
|
22
|
+
cacheReady,
|
|
23
|
+
docId,
|
|
24
|
+
canonical,
|
|
25
|
+
ownerOnly: true,
|
|
26
|
+
type: entry?.type ?? "doc",
|
|
27
|
+
title: null,
|
|
28
|
+
meta: {},
|
|
29
|
+
html: null
|
|
30
|
+
};
|
|
31
|
+
}
|
|
11
32
|
return {
|
|
12
33
|
found: true,
|
|
13
34
|
cacheReady,
|
|
14
35
|
docId,
|
|
36
|
+
canonical,
|
|
15
37
|
title: entry?.label ?? null,
|
|
16
38
|
type: entry?.type ?? "doc",
|
|
17
39
|
meta: entry?.meta ?? {},
|
|
@@ -23,19 +23,22 @@ export declare function junSlugMap(): Promise<Record<string, string>>;
|
|
|
23
23
|
/** A document's cached HTML body, or `null` if it has not been rendered yet. */
|
|
24
24
|
export declare function junDocHtml(docId: string): Promise<string | null>;
|
|
25
25
|
/**
|
|
26
|
-
* The
|
|
26
|
+
* The site's runtime configuration.
|
|
27
27
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* document so it has not bitten yet, but the moment a site has two, the two
|
|
33
|
-
* sides read different ones and the server's SSR disagrees with the client
|
|
34
|
-
* for reasons nothing on screen explains. That is exactly how the campfire
|
|
35
|
-
* channel broke.
|
|
28
|
+
* It lives under `meta.junSite` on the SPACE DOCUMENT's tree entry — the
|
|
29
|
+
* self-descriptor entry whose id IS the root id, which also carries the root
|
|
30
|
+
* page's label and page type. **`useJunSiteConfig` reads the same key off the
|
|
31
|
+
* same entry**; the two sides must never disagree about where the values are.
|
|
36
32
|
*
|
|
37
|
-
* The
|
|
38
|
-
*
|
|
39
|
-
*
|
|
33
|
+
* The legacy path is still read and still merged UNDER the space document's
|
|
34
|
+
* values: a site whose owner has not signed in since the move has never run
|
|
35
|
+
* `useJunSiteConfigMigration()`, and its visitors must keep seeing the settings
|
|
36
|
+
* it was configured with. Legacy candidates are picked by the rule both sides
|
|
37
|
+
* have always shared — untrashed `meta.siteConfig`, preferring the ones
|
|
38
|
+
* actually parented to the space root, then the OLDEST by `createdAt` with ties
|
|
39
|
+
* broken on the id. Before that rule existed this returned whichever candidate
|
|
40
|
+
* came first out of `Object.values(tree)`, which is Y.Map iteration order:
|
|
41
|
+
* unstable, and nothing like the client's rule. Two config documents would then
|
|
42
|
+
* have put the two sides on different ones — exactly how the campfire broke.
|
|
40
43
|
*/
|
|
41
44
|
export declare function junSiteConfigMeta(): Promise<Record<string, unknown>>;
|
|
@@ -23,10 +23,12 @@ export async function junDocHtml(docId) {
|
|
|
23
23
|
export async function junSiteConfigMeta() {
|
|
24
24
|
const tree = await junDocTree();
|
|
25
25
|
const root = junRootDocId();
|
|
26
|
+
const nested = root ? tree[root]?.meta?.junSite : void 0;
|
|
27
|
+
const spaceConfig = nested && typeof nested === "object" ? nested : {};
|
|
26
28
|
const candidates = Object.entries(tree).filter(([, e]) => e?.meta?.siteConfig === true && !e.trashed).map(([id, entry]) => ({ id, entry }));
|
|
27
|
-
if (!candidates.length) return
|
|
29
|
+
if (!candidates.length) return spaceConfig;
|
|
28
30
|
const parented = candidates.filter((c) => c.entry.parentId === root);
|
|
29
31
|
const pool = parented.length ? parented : candidates;
|
|
30
32
|
pool.sort((a, b) => (a.entry.createdAt ?? 0) - (b.entry.createdAt ?? 0) || (a.id < b.id ? -1 : 1));
|
|
31
|
-
return pool[0].entry.meta ?? {};
|
|
33
|
+
return { ...pool[0].entry.meta ?? {}, ...spaceConfig };
|
|
32
34
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolving a slug a document used to live at.
|
|
3
|
+
*
|
|
4
|
+
* Slugs are DERIVED from labels, so renaming a page moves it. `useJunRename`
|
|
5
|
+
* records the vacated slug on the entry's `meta.slugAliases`; this is the
|
|
6
|
+
* server's half of reading that list back, and it is what lets the resolve
|
|
7
|
+
* endpoint answer a cold load of an old URL with a real 301 instead of a 404.
|
|
8
|
+
*
|
|
9
|
+
* Its own file, with NO Nitro imports, so it is reachable from `pnpm test` —
|
|
10
|
+
* the endpoint that uses it cannot be, since importing it pulls in
|
|
11
|
+
* `nitropack/runtime` and a storage layer that only exists inside a running
|
|
12
|
+
* server. The alias rule is the part with a decision in it; the handler around
|
|
13
|
+
* it is plumbing.
|
|
14
|
+
*
|
|
15
|
+
* > **`useJunRename().docIdForAlias` applies the SAME rule** and must keep
|
|
16
|
+
* > doing so. Nitro server utils and the app's auto-imports are separate
|
|
17
|
+
* > bundles — the same split that already forces `isJunOwnerOnlyDoc` to exist
|
|
18
|
+
* > twice — and the two operate on different shapes (a record here, the tree's
|
|
19
|
+
* > entry array there), so this is duplicated deliberately rather than shared.
|
|
20
|
+
* > **Keep them in step.**
|
|
21
|
+
*/
|
|
22
|
+
export interface JunAliasEntry {
|
|
23
|
+
trashed?: boolean;
|
|
24
|
+
createdAt?: number;
|
|
25
|
+
meta?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The document that used to live at `slug`, or `null` when nothing claims it.
|
|
29
|
+
*
|
|
30
|
+
* Deterministic on purpose. Two documents claiming one alias is not a healthy
|
|
31
|
+
* state, but "unhealthy" must not mean "answers differently per request" — an
|
|
32
|
+
* unstable pick is how the client and the server end up on different documents,
|
|
33
|
+
* which is the shape of the campfire bug, where half the visitors ended up in a
|
|
34
|
+
* room the other half could not see. Oldest `createdAt`, ties broken on the id:
|
|
35
|
+
* the same tie-break every other canonical pick in this codebase uses.
|
|
36
|
+
*
|
|
37
|
+
* The CALLER must consult the canonical slug map first. `renameDoc` cannot
|
|
38
|
+
* compute a document's new slug at the moment it records the old one, so an
|
|
39
|
+
* alias may well name a slug some other document now holds — checking the live
|
|
40
|
+
* map first is what makes a stale alias inert rather than a shadow.
|
|
41
|
+
*/
|
|
42
|
+
export declare function junDocIdForAlias(entries: Record<string, JunAliasEntry | undefined>, slug: string): string | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function junDocIdForAlias(entries, slug) {
|
|
2
|
+
if (!slug) return null;
|
|
3
|
+
const claimants = [];
|
|
4
|
+
for (const [id, entry] of Object.entries(entries)) {
|
|
5
|
+
if (!entry || entry.trashed) continue;
|
|
6
|
+
const aliases = entry.meta?.slugAliases;
|
|
7
|
+
if (Array.isArray(aliases) && aliases.includes(slug)) {
|
|
8
|
+
claimants.push({ id, createdAt: entry.createdAt ?? 0 });
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
if (!claimants.length) return null;
|
|
12
|
+
claimants.sort((a, b) => a.createdAt - b.createdAt || (a.id < b.id ? -1 : 1));
|
|
13
|
+
return claimants[0].id;
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abraca/junis",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.81.0",
|
|
4
4
|
"description": "Website-builder Nuxt module for the Abracadabra CRDT platform — page-type renderers, presence chrome, studio editing and SSR, all driven by documents",
|
|
5
5
|
"repository": "abracadabra/jun-is",
|
|
6
6
|
"license": "MIT",
|