@abraca/junis 2.97.0 → 2.99.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 +13 -0
- package/dist/runtime/components/JunBreadcrumbs.vue +4 -4
- package/dist/runtime/components/JunDocMenuHost.vue +2 -0
- package/dist/runtime/components/JunServiceCard.vue +3 -1
- package/dist/runtime/composables/useJunProseLinkMenu.d.ts +1 -0
- package/dist/runtime/composables/useJunProseLinkMenu.js +132 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -684,6 +684,17 @@ function nuxtOptionsRecord(nuxt) {
|
|
|
684
684
|
function asRecord(value) {
|
|
685
685
|
return value && typeof value === "object" ? value : void 0;
|
|
686
686
|
}
|
|
687
|
+
function handOverMapboxToken(nuxt, token) {
|
|
688
|
+
if (!token) return;
|
|
689
|
+
const abra = siblingOptions(nuxt, "abracadabra");
|
|
690
|
+
if (!abra.mapboxToken) abra.mapboxToken = token;
|
|
691
|
+
const pub = nuxt.options.runtimeConfig.public;
|
|
692
|
+
const resolved = pub.abracadabra;
|
|
693
|
+
if (resolved && typeof resolved === "object") {
|
|
694
|
+
const record = resolved;
|
|
695
|
+
if (!record.mapboxToken) record.mapboxToken = token;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
687
698
|
function siblingOptions(nuxt, key) {
|
|
688
699
|
const all = nuxtOptionsRecord(nuxt);
|
|
689
700
|
const existing = all[key];
|
|
@@ -847,6 +858,7 @@ const module$1 = defineNuxtModule({
|
|
|
847
858
|
if (options.fonts !== false && !hasNuxtModule("@nuxt/fonts")) await installModule("@nuxt/fonts");
|
|
848
859
|
if (!hasNuxtModule("@vueuse/motion/nuxt")) await installModule("@vueuse/motion/nuxt");
|
|
849
860
|
registerFreshServerGuard();
|
|
861
|
+
handOverMapboxToken(nuxt, options.mapboxToken);
|
|
850
862
|
if (!hasNuxtModule("@abraca/nuxt")) await installModule("@abraca/nuxt");
|
|
851
863
|
} else if (!hasNuxtModule("@abraca/nuxt")) {
|
|
852
864
|
throw new Error(
|
|
@@ -1059,6 +1071,7 @@ Switch them off with \`jun.pageTypes: { ${missing.map((e) => `${e.key}: false`).
|
|
|
1059
1071
|
const abraFeatures = asRecord(abra.features) ?? {};
|
|
1060
1072
|
abraFeatures.backgroundSync ??= runtime.offline.docSync;
|
|
1061
1073
|
abra.features = abraFeatures;
|
|
1074
|
+
handOverMapboxToken(nuxt, options.mapboxToken);
|
|
1062
1075
|
if (options.fonts !== false) {
|
|
1063
1076
|
const fonts = siblingOptions(nuxt, "fonts");
|
|
1064
1077
|
const families = Array.isArray(fonts.families) ? fonts.families : [];
|
|
@@ -26,7 +26,7 @@ const items = computed(() => {
|
|
|
26
26
|
icon: docIcon(entry.type, entry.meta?.icon),
|
|
27
27
|
to: getDocUrl(entry.id),
|
|
28
28
|
docId: entry.id,
|
|
29
|
-
|
|
29
|
+
docType: entry.type,
|
|
30
30
|
meta: entry.meta
|
|
31
31
|
});
|
|
32
32
|
parentId = entry.parentId ?? null;
|
|
@@ -36,7 +36,7 @@ const items = computed(() => {
|
|
|
36
36
|
label: cursor.label || "Untitled",
|
|
37
37
|
icon: docIcon(cursor.type, cursor.meta?.icon),
|
|
38
38
|
docId: cursor.id,
|
|
39
|
-
|
|
39
|
+
docType: cursor.type,
|
|
40
40
|
meta: cursor.meta
|
|
41
41
|
});
|
|
42
42
|
}
|
|
@@ -59,7 +59,7 @@ const menu = useJunDocLinkMenu({ surface: "breadcrumb", noOpen: false });
|
|
|
59
59
|
<template #item="{ item }">
|
|
60
60
|
<span
|
|
61
61
|
class="inline-flex items-center gap-1.5"
|
|
62
|
-
v-bind="menu.bindFor({ id: item.docId, label: item.label, type: item.
|
|
62
|
+
v-bind="menu.bindFor({ id: item.docId, label: item.label, type: item.docType, meta: item.meta })"
|
|
63
63
|
>
|
|
64
64
|
<UIcon
|
|
65
65
|
v-if="item.icon"
|
|
@@ -84,7 +84,7 @@ const menu = useJunDocLinkMenu({ surface: "breadcrumb", noOpen: false });
|
|
|
84
84
|
<template #item="{ item }">
|
|
85
85
|
<span
|
|
86
86
|
class="inline-flex items-center gap-1.5"
|
|
87
|
-
v-bind="menu.bindFor({ id: item.docId, label: item.label, type: item.
|
|
87
|
+
v-bind="menu.bindFor({ id: item.docId, label: item.label, type: item.docType, meta: item.meta })"
|
|
88
88
|
>
|
|
89
89
|
<UIcon
|
|
90
90
|
v-if="item.icon"
|
|
@@ -3,11 +3,13 @@ import { computed, onMounted, watch } from "vue";
|
|
|
3
3
|
import { useRoute } from "vue-router";
|
|
4
4
|
import { useAbracadabra, useChildTree } from "#imports";
|
|
5
5
|
import { provideJunMenuTree, useJunDocMenuHost } from "../composables/useJunDocMenuHost";
|
|
6
|
+
import { useJunProseLinkMenu } from "../composables/useJunProseLinkMenu";
|
|
6
7
|
const { at, hide } = useJunDocMenuHost();
|
|
7
8
|
const route = useRoute();
|
|
8
9
|
const abra = useAbracadabra();
|
|
9
10
|
const tree = useChildTree(abra.doc, "jun-doc-menu");
|
|
10
11
|
onMounted(() => provideJunMenuTree(tree));
|
|
12
|
+
useJunProseLinkMenu();
|
|
11
13
|
watch(() => route.fullPath, hide);
|
|
12
14
|
const content = computed(() => ({
|
|
13
15
|
align: "start",
|
|
@@ -10,11 +10,13 @@ const props = defineProps({
|
|
|
10
10
|
});
|
|
11
11
|
const opts = useJunOptions();
|
|
12
12
|
const configured = computed(() => !!props.provider && !!props.serviceRef);
|
|
13
|
+
const providerQuery = computed(() => props.provider);
|
|
14
|
+
const refQuery = computed(() => props.serviceRef);
|
|
13
15
|
const { data, pending } = await useFetch(`${opts.apiBase}/service`, {
|
|
14
16
|
// Keyed by what it fetches, so two cards pointing at the same repository
|
|
15
17
|
// share one payload entry instead of racing each other.
|
|
16
18
|
key: `jun-service:${props.provider}:${props.serviceRef}`,
|
|
17
|
-
query: { provider:
|
|
19
|
+
query: { provider: providerQuery, ref: refQuery },
|
|
18
20
|
// A card with no provider yet (just created, not configured) must not fire a
|
|
19
21
|
// request that can only fail.
|
|
20
22
|
immediate: configured.value,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useJunProseLinkMenu(): void;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { onBeforeUnmount, onMounted } from "vue";
|
|
2
|
+
import { useDocSlugs, useDocTree, useRuntimeConfig } from "#imports";
|
|
3
|
+
import { useJunDocMenuHost, useJunMenuTree } from "./useJunDocMenuHost.js";
|
|
4
|
+
import { useJunDocMenu } from "./useJunDocMenu.js";
|
|
5
|
+
import { useJunStudio } from "./useJunStudio.js";
|
|
6
|
+
const PRESS_SLOP_PX = 8;
|
|
7
|
+
const PRESS_MS = 500;
|
|
8
|
+
const CLICK_GUARD_MS = 700;
|
|
9
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
10
|
+
export function useJunProseLinkMenu() {
|
|
11
|
+
if (!import.meta.client) return;
|
|
12
|
+
const { show, hide } = useJunDocMenuHost();
|
|
13
|
+
const { itemsFor } = useJunDocMenu();
|
|
14
|
+
const { getDocId } = useDocSlugs();
|
|
15
|
+
const { getEntry } = useDocTree();
|
|
16
|
+
const { editing } = useJunStudio();
|
|
17
|
+
const siteTree = useJunMenuTree();
|
|
18
|
+
const config = useRuntimeConfig();
|
|
19
|
+
const docBasePath = config.public.abracadabra?.docBasePath ?? "/doc";
|
|
20
|
+
function docIdAt(target) {
|
|
21
|
+
if (!(target instanceof Element)) return null;
|
|
22
|
+
const el = target.closest("a[href], [data-doc-id]");
|
|
23
|
+
if (!el) return null;
|
|
24
|
+
const stated = el.getAttribute("data-doc-id");
|
|
25
|
+
if (stated && getEntry(stated)) return stated;
|
|
26
|
+
const href = el.getAttribute("href");
|
|
27
|
+
if (!href) return null;
|
|
28
|
+
let url;
|
|
29
|
+
try {
|
|
30
|
+
url = new URL(href, window.location.href);
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (url.origin !== window.location.origin) return null;
|
|
35
|
+
if (!url.pathname || url.pathname === window.location.pathname) {
|
|
36
|
+
if (url.hash) return null;
|
|
37
|
+
}
|
|
38
|
+
const path = url.pathname.replace(/^\/+|\/+$/g, "");
|
|
39
|
+
if (!path) return null;
|
|
40
|
+
const base = docBasePath.replace(/^\/+|\/+$/g, "");
|
|
41
|
+
if (base && path.startsWith(`${base}/`)) {
|
|
42
|
+
const rest = path.slice(base.length + 1);
|
|
43
|
+
if (UUID.test(rest) && getEntry(rest)) return rest;
|
|
44
|
+
const viaSlug = getDocId(rest);
|
|
45
|
+
return viaSlug && getEntry(viaSlug) ? viaSlug : null;
|
|
46
|
+
}
|
|
47
|
+
if (UUID.test(path) && getEntry(path)) return path;
|
|
48
|
+
const id = getDocId(path);
|
|
49
|
+
return id && getEntry(id) ? id : null;
|
|
50
|
+
}
|
|
51
|
+
function itemsForDoc(docId) {
|
|
52
|
+
const entry = getEntry(docId);
|
|
53
|
+
return itemsFor(
|
|
54
|
+
{
|
|
55
|
+
docId,
|
|
56
|
+
label: entry?.label || "Untitled",
|
|
57
|
+
type: entry?.type,
|
|
58
|
+
meta: entry?.meta,
|
|
59
|
+
// Its own surface, so a `registerJunMenuItems()` builder can tell a
|
|
60
|
+
// link inside somebody's writing from a card in a list.
|
|
61
|
+
surface: "page",
|
|
62
|
+
editing: editing.value
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
tree: siteTree(),
|
|
66
|
+
// The prose link IS the way there, so "Open" would be a second copy of
|
|
67
|
+
// the thing you just pressed.
|
|
68
|
+
noOpen: true
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
function onContextmenu(e) {
|
|
73
|
+
if (e.defaultPrevented) return;
|
|
74
|
+
const docId = docIdAt(e.target);
|
|
75
|
+
if (!docId) return;
|
|
76
|
+
const items = itemsForDoc(docId);
|
|
77
|
+
if (!items.length) return;
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
show(items, e.clientX, e.clientY);
|
|
80
|
+
}
|
|
81
|
+
let timer = null;
|
|
82
|
+
let start = null;
|
|
83
|
+
let suppressClickUntil = 0;
|
|
84
|
+
function cancel() {
|
|
85
|
+
if (timer) clearTimeout(timer);
|
|
86
|
+
timer = null;
|
|
87
|
+
start = null;
|
|
88
|
+
}
|
|
89
|
+
function onPointerdown(e) {
|
|
90
|
+
if (e.pointerType === "mouse" || e.defaultPrevented) return;
|
|
91
|
+
cancel();
|
|
92
|
+
const docId = docIdAt(e.target);
|
|
93
|
+
if (!docId) return;
|
|
94
|
+
start = { x: e.clientX, y: e.clientY };
|
|
95
|
+
const at = { x: e.clientX, y: e.clientY };
|
|
96
|
+
timer = setTimeout(() => {
|
|
97
|
+
timer = null;
|
|
98
|
+
const items = itemsForDoc(docId);
|
|
99
|
+
if (!items.length) return;
|
|
100
|
+
suppressClickUntil = performance.now() + CLICK_GUARD_MS;
|
|
101
|
+
show(items, at.x, at.y);
|
|
102
|
+
}, PRESS_MS);
|
|
103
|
+
}
|
|
104
|
+
function onPointermove(e) {
|
|
105
|
+
if (!start) return;
|
|
106
|
+
if (Math.hypot(e.clientX - start.x, e.clientY - start.y) <= PRESS_SLOP_PX) return;
|
|
107
|
+
cancel();
|
|
108
|
+
hide();
|
|
109
|
+
}
|
|
110
|
+
function onClickCapture(e) {
|
|
111
|
+
if (performance.now() >= suppressClickUntil) return;
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
e.stopPropagation();
|
|
114
|
+
}
|
|
115
|
+
onMounted(() => {
|
|
116
|
+
document.addEventListener("contextmenu", onContextmenu);
|
|
117
|
+
document.addEventListener("pointerdown", onPointerdown);
|
|
118
|
+
document.addEventListener("pointermove", onPointermove, { passive: true });
|
|
119
|
+
document.addEventListener("pointerup", cancel);
|
|
120
|
+
document.addEventListener("pointercancel", cancel);
|
|
121
|
+
document.addEventListener("click", onClickCapture, { capture: true });
|
|
122
|
+
});
|
|
123
|
+
onBeforeUnmount(() => {
|
|
124
|
+
cancel();
|
|
125
|
+
document.removeEventListener("contextmenu", onContextmenu);
|
|
126
|
+
document.removeEventListener("pointerdown", onPointerdown);
|
|
127
|
+
document.removeEventListener("pointermove", onPointermove);
|
|
128
|
+
document.removeEventListener("pointerup", cancel);
|
|
129
|
+
document.removeEventListener("pointercancel", cancel);
|
|
130
|
+
document.removeEventListener("click", onClickCapture, { capture: true });
|
|
131
|
+
});
|
|
132
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abraca/junis",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.99.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",
|