@jant/core 1.0.1 → 1.1.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/{app-Gt7_skt6.js → app-CKQ9PqAr.js} +791 -89
- package/dist/client/.vite/manifest.json +115 -75
- package/dist/client/_assets/chunks/{confirm-D7GrwsCN.js → confirm-CMe01lne.js} +1 -1
- package/dist/client/_assets/chunks/{create-editor-5Y49x7h5.js → create-editor-BQkrw8Ax.js} +4 -4
- package/dist/client/_assets/chunks/footnote-rail-B08scyhW.js +2 -0
- package/dist/client/_assets/chunks/{jant-locale-picker-DL6mIOT5.js → jant-locale-picker-2L4rkDaz.js} +1 -1
- package/dist/client/_assets/chunks/lit-Bw_voPoW.js +2 -0
- package/dist/client/_assets/chunks/preload-helper-Czpn1I53.js +1 -0
- package/dist/client/_assets/chunks/runtime-paths-y0_gHowM.js +1 -0
- package/dist/client/_assets/chunks/{settings-paths-h6RjIe3C.js → settings-paths-B0bNUaih.js} +1 -1
- package/dist/client/_assets/chunks/slug-format-CYmQE5ln.js +1 -0
- package/dist/client/_assets/chunks/{sortable-list-DWNKv782.js → sortable-list-t11Ma1Ek.js} +1 -1
- package/dist/client/_assets/chunks/{unsafe-html-B5ZEXaxg.js → unsafe-html-CWos3v6N.js} +1 -1
- package/dist/client/_assets/chunks/unsafe-svg-DZl-yjas.js +1 -0
- package/dist/client/_assets/client-B0-s9sqx.css +2 -0
- package/dist/client/_assets/client-Dp46QSht.js +354 -0
- package/dist/client/_assets/client-auth-CG55rWb5.js +859 -0
- package/dist/client/_assets/{client-compose-oxzPb3SS.js → client-compose-DkUTuavR.js} +261 -261
- package/dist/client/_assets/{client-manage-C1eDB1Rc.js → client-manage-DnYdQAhf.js} +176 -176
- package/dist/client/_assets/{client-settings-DIM44Zqh.js → client-settings-CHgsIqXJ.js} +166 -166
- package/dist/client/_assets/client-share-0DICJjAc.css +1 -0
- package/dist/client/_assets/client-share-C59mOLJ1.js +149 -0
- package/dist/index.js +1 -1
- package/dist/node.js +2 -2
- package/package.json +2 -1
- package/src/client/components/jant-post-menu.ts +80 -13
- package/src/client/components/jant-share-dialog.ts +422 -0
- package/src/client/components/jant-share-menu.ts +188 -0
- package/src/client/lazy-entries.ts +21 -1
- package/src/client/post-menu-shared.ts +100 -0
- package/src/client/share-capture.ts +443 -0
- package/src/client/share-launch.ts +133 -0
- package/src/client-share.ts +8 -0
- package/src/client.ts +1 -0
- package/src/lib/discover.ts +31 -0
- package/src/lib/share-card.ts +653 -0
- package/src/lib/version.ts +2 -0
- package/src/routes/auth/setup.tsx +37 -1
- package/src/routes/pages/partials.tsx +23 -0
- package/src/style-share.css +16 -0
- package/src/styles/components.css +14 -0
- package/src/styles/share.css +1103 -0
- package/src/styles/ui.css +6 -0
- package/src/ui/layouts/BaseLayout.tsx +7 -0
- package/src/ui/layouts/SiteLayout.tsx +1 -0
- package/src/ui/share/ShareCard.tsx +298 -0
- package/src/ui/shared/Icon.tsx +23 -3
- package/src/ui/shared/MediaGallery.tsx +12 -1
- package/src/ui/shared/PostFooter.tsx +20 -4
- package/src/ui/shared/icon-collector.ts +28 -0
- package/src/ui/shared/post-article-attributes.ts +3 -0
- package/dist/client/_assets/chunks/footnote-rail-BJwswtVQ.js +0 -1
- package/dist/client/_assets/chunks/lit-DW8VmJAT.js +0 -2
- package/dist/client/_assets/chunks/slug-format-Dsi0e9Xn.js +0 -1
- package/dist/client/_assets/chunks/unsafe-svg-DTZZEvLU.js +0 -2
- package/dist/client/_assets/client-BaqmpPQ-.css +0 -2
- package/dist/client/_assets/client-C6melOtG.js +0 -296
- package/dist/client/_assets/client-auth-Ccq8kSqq.js +0 -828
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Share Menu
|
|
3
|
+
*
|
|
4
|
+
* A reader's post menu: the "More" button in a post's footer on a page
|
|
5
|
+
* nobody is signed in to, with what a reader can do with a post — copy its
|
|
6
|
+
* link, or share it as an image. One element per page (`SiteLayout` mounts
|
|
7
|
+
* it), opened from any post's `[data-share-menu-trigger]`; the author's menu
|
|
8
|
+
* is `jant-post-menu`, and this one wears its classes so the two read as one
|
|
9
|
+
* control. Light DOM.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { LitElement, html, nothing } from "lit";
|
|
13
|
+
import {
|
|
14
|
+
copyPostLink,
|
|
15
|
+
iconImage,
|
|
16
|
+
iconLink,
|
|
17
|
+
menuOpensAbove,
|
|
18
|
+
} from "../post-menu-shared.js";
|
|
19
|
+
import { openShareImage, warmShareImage } from "../share-launch.js";
|
|
20
|
+
|
|
21
|
+
/** Two items, about 52 px each, inside the panel's padding. */
|
|
22
|
+
const ESTIMATED_MENU_HEIGHT = 130;
|
|
23
|
+
|
|
24
|
+
/** The post a menu is open for, from its article. */
|
|
25
|
+
interface SharedPost {
|
|
26
|
+
id: string;
|
|
27
|
+
permalink: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class JantShareMenu extends LitElement {
|
|
31
|
+
static properties = {
|
|
32
|
+
_post: { state: true },
|
|
33
|
+
_x: { state: true },
|
|
34
|
+
_y: { state: true },
|
|
35
|
+
_openAbove: { state: true },
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
declare _post: SharedPost | null;
|
|
39
|
+
declare _x: number;
|
|
40
|
+
declare _y: number;
|
|
41
|
+
declare _openAbove: boolean;
|
|
42
|
+
|
|
43
|
+
#trigger: HTMLElement | null = null;
|
|
44
|
+
|
|
45
|
+
constructor() {
|
|
46
|
+
super();
|
|
47
|
+
this._post = null;
|
|
48
|
+
this._x = 0;
|
|
49
|
+
this._y = 0;
|
|
50
|
+
this._openAbove = false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
createRenderRoot() {
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
connectedCallback() {
|
|
58
|
+
super.connectedCallback();
|
|
59
|
+
document.addEventListener("click", this.#handleDocumentClick);
|
|
60
|
+
document.addEventListener("keydown", this.#handleKeydown);
|
|
61
|
+
window.addEventListener("resize", this.#place);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
disconnectedCallback() {
|
|
65
|
+
super.disconnectedCallback();
|
|
66
|
+
document.removeEventListener("click", this.#handleDocumentClick);
|
|
67
|
+
document.removeEventListener("keydown", this.#handleKeydown);
|
|
68
|
+
window.removeEventListener("resize", this.#place);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#handleDocumentClick = (event: Event) => {
|
|
72
|
+
const trigger = (event.target as globalThis.Element).closest?.<HTMLElement>(
|
|
73
|
+
"[data-share-menu-trigger]",
|
|
74
|
+
);
|
|
75
|
+
if (!trigger) return;
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
|
|
78
|
+
if (this._post && trigger === this.#trigger) {
|
|
79
|
+
this.#close();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const article = trigger.closest<HTMLElement>("article[data-post-id]");
|
|
84
|
+
const id = article?.dataset.postId;
|
|
85
|
+
const permalink = article?.dataset.postPermalink;
|
|
86
|
+
if (!id || !permalink) return;
|
|
87
|
+
|
|
88
|
+
this.#trigger?.setAttribute("aria-expanded", "false");
|
|
89
|
+
this.#trigger = trigger;
|
|
90
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
91
|
+
this._post = { id, permalink };
|
|
92
|
+
this.#place();
|
|
93
|
+
warmShareImage();
|
|
94
|
+
void this.updateComplete.then(() => {
|
|
95
|
+
this.querySelector<HTMLElement>("[role='menuitem']")?.focus();
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
#handleKeydown = (event: Event) => {
|
|
100
|
+
const key = event as globalThis.KeyboardEvent;
|
|
101
|
+
if (key.key !== "Escape" || !this._post) return;
|
|
102
|
+
key.preventDefault();
|
|
103
|
+
this.#close();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/** Right-aligned to the trigger, above it when there is no room below. */
|
|
107
|
+
#place = () => {
|
|
108
|
+
const trigger = this.#trigger;
|
|
109
|
+
if (!this._post || !trigger) return;
|
|
110
|
+
if (!trigger.isConnected) {
|
|
111
|
+
this.#close({ restoreFocus: false });
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const rect = trigger.getBoundingClientRect();
|
|
115
|
+
this._openAbove = menuOpensAbove(rect, ESTIMATED_MENU_HEIGHT);
|
|
116
|
+
this._x = window.scrollX + rect.right;
|
|
117
|
+
this._y =
|
|
118
|
+
window.scrollY + (this._openAbove ? rect.top - 6 : rect.bottom + 6);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
#close({ restoreFocus = true }: { restoreFocus?: boolean } = {}) {
|
|
122
|
+
const trigger = this.#trigger;
|
|
123
|
+
trigger?.setAttribute("aria-expanded", "false");
|
|
124
|
+
this.#trigger = null;
|
|
125
|
+
this._post = null;
|
|
126
|
+
if (restoreFocus) trigger?.focus();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#copyLink() {
|
|
130
|
+
const permalink = this._post?.permalink;
|
|
131
|
+
this.#close();
|
|
132
|
+
if (permalink) void copyPostLink(permalink);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
#shareImage() {
|
|
136
|
+
const id = this._post?.id;
|
|
137
|
+
const trigger = this.#trigger;
|
|
138
|
+
// The dialog takes focus, and gives it back to the trigger on close.
|
|
139
|
+
this.#close({ restoreFocus: false });
|
|
140
|
+
if (id) void openShareImage(id, trigger);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
render() {
|
|
144
|
+
if (!this._post) return nothing;
|
|
145
|
+
const transform = this._openAbove
|
|
146
|
+
? "transform:translate(-100%, -100%);"
|
|
147
|
+
: "transform:translateX(-100%);";
|
|
148
|
+
const style = `position:absolute;z-index:100;left:${Math.round(this._x)}px;top:${Math.round(this._y)}px;${transform}`;
|
|
149
|
+
return html`
|
|
150
|
+
<div
|
|
151
|
+
class="post-menu-backdrop"
|
|
152
|
+
@click=${() => this.#close({ restoreFocus: false })}
|
|
153
|
+
></div>
|
|
154
|
+
<div class="dropdown-menu" style=${style}>
|
|
155
|
+
<div data-popover aria-hidden="false" class="!static post-menu-panel">
|
|
156
|
+
<div class="post-menu-view post-menu-main">
|
|
157
|
+
<div role="menu" class="post-menu-list">
|
|
158
|
+
<div class="post-menu-section">
|
|
159
|
+
<button
|
|
160
|
+
type="button"
|
|
161
|
+
role="menuitem"
|
|
162
|
+
class="post-menu-item"
|
|
163
|
+
data-share-menu-copy-link
|
|
164
|
+
@click=${() => this.#copyLink()}
|
|
165
|
+
>
|
|
166
|
+
<span class="post-menu-item-label">Copy link</span>
|
|
167
|
+
<span class="post-menu-item-trailing">${iconLink()}</span>
|
|
168
|
+
</button>
|
|
169
|
+
<button
|
|
170
|
+
type="button"
|
|
171
|
+
role="menuitem"
|
|
172
|
+
class="post-menu-item"
|
|
173
|
+
data-share-menu-share-image
|
|
174
|
+
@click=${() => this.#shareImage()}
|
|
175
|
+
>
|
|
176
|
+
<span class="post-menu-item-label">Share as image</span>
|
|
177
|
+
<span class="post-menu-item-trailing">${iconImage()}</span>
|
|
178
|
+
</button>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
`;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
customElements.define("jant-share-menu", JantShareMenu);
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
* - `client-settings.ts` — the settings pages' components.
|
|
13
13
|
* - `client-manage.ts` — navigation manager, collection directory, and the
|
|
14
14
|
* collection page menus.
|
|
15
|
+
* - `client-share.ts` — the "Share as image" dialog and snapdom. Loaded
|
|
16
|
+
* when a post menu that offers it opens (`share-launch.ts`), so picking
|
|
17
|
+
* the item has nothing left to wait for; no page needs it up front.
|
|
15
18
|
*
|
|
16
19
|
* The page decides: {@link loadEntriesForPage} looks for the elements and
|
|
17
20
|
* hooks the server renders only where an entry is needed, and keeps looking
|
|
@@ -19,9 +22,20 @@
|
|
|
19
22
|
* `docs/internal/lit-guide.md` says which entry a new component belongs in.
|
|
20
23
|
*/
|
|
21
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Share one load between callers. A load that fails is forgotten, so the
|
|
27
|
+
* next call tries again instead of repeating the failure until a reload.
|
|
28
|
+
*/
|
|
22
29
|
function once(load: () => Promise<unknown>): () => Promise<void> {
|
|
23
30
|
let loading: Promise<void> | undefined;
|
|
24
|
-
return () =>
|
|
31
|
+
return () =>
|
|
32
|
+
(loading ??= load().then(
|
|
33
|
+
() => undefined,
|
|
34
|
+
(error: unknown) => {
|
|
35
|
+
loading = undefined;
|
|
36
|
+
throw error;
|
|
37
|
+
},
|
|
38
|
+
));
|
|
25
39
|
}
|
|
26
40
|
|
|
27
41
|
/** Load the composer entry; resolves once its elements are defined. */
|
|
@@ -33,6 +47,12 @@ export const ensureSettings = once(() => import("../client-settings.js"));
|
|
|
33
47
|
/** Load the management entry; resolves once its elements are defined. */
|
|
34
48
|
export const ensureManage = once(() => import("../client-manage.js"));
|
|
35
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Load the share entry — the "Share as image" dialog and snapdom — the first
|
|
52
|
+
* time a post menu offers it.
|
|
53
|
+
*/
|
|
54
|
+
export const ensureShare = once(() => import("../client-share.js"));
|
|
55
|
+
|
|
36
56
|
/**
|
|
37
57
|
* Markup the server renders only on pages that need an entry. A selector
|
|
38
58
|
* matching means the page cannot work without that entry, so it loads at
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the author's post menu (`jant-post-menu`) and a reader's
|
|
3
|
+
* (`jant-share-menu`) share: where the menu opens, the icons of the two items
|
|
4
|
+
* both offer, and copying a post's link.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { html } from "lit";
|
|
8
|
+
import { showToast } from "./toast.js";
|
|
9
|
+
|
|
10
|
+
/** The trigger's box, as `getBoundingClientRect()` gives it. */
|
|
11
|
+
export interface MenuTriggerRect {
|
|
12
|
+
top: number;
|
|
13
|
+
bottom: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const MENU_VIEWPORT_MARGIN = 12;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether a menu should open above its trigger: when it would not fit below
|
|
20
|
+
* and there is more room above.
|
|
21
|
+
*
|
|
22
|
+
* @param rect - The trigger's box
|
|
23
|
+
* @param menuHeight - The menu's height, estimated before it renders
|
|
24
|
+
* @returns True to open above the trigger
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* menuOpensAbove(trigger.getBoundingClientRect(), 360);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function menuOpensAbove(
|
|
32
|
+
rect: MenuTriggerRect,
|
|
33
|
+
menuHeight: number,
|
|
34
|
+
): boolean {
|
|
35
|
+
const spaceBelow = window.innerHeight - rect.bottom - MENU_VIEWPORT_MARGIN;
|
|
36
|
+
const spaceAbove = rect.top - MENU_VIEWPORT_MARGIN;
|
|
37
|
+
return spaceBelow < menuHeight && spaceAbove > spaceBelow;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Copy a post's own address and say whether it worked. The address is the
|
|
42
|
+
* article's `data-post-permalink`, where the post's date links to, made
|
|
43
|
+
* absolute: the post's own wherever it is listed, never the page's.
|
|
44
|
+
*
|
|
45
|
+
* @param permalink - The post's permalink, as the article carries it
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* await copyPostLink(article.dataset.postPermalink);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export async function copyPostLink(permalink: string): Promise<void> {
|
|
53
|
+
const url = new URL(permalink, globalThis.location.href).href;
|
|
54
|
+
try {
|
|
55
|
+
// Absent on an insecure origin, and the browser may refuse it.
|
|
56
|
+
if (!globalThis.navigator.clipboard?.writeText) {
|
|
57
|
+
throw new Error("Clipboard unavailable");
|
|
58
|
+
}
|
|
59
|
+
await globalThis.navigator.clipboard.writeText(url);
|
|
60
|
+
showToast("Link copied.");
|
|
61
|
+
} catch {
|
|
62
|
+
showToast(
|
|
63
|
+
"Could not copy the link. Open the post and copy it from the address bar.",
|
|
64
|
+
"error",
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Lucide "link", for Copy link. */
|
|
70
|
+
export function iconLink() {
|
|
71
|
+
return html`<svg
|
|
72
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
73
|
+
viewBox="0 0 24 24"
|
|
74
|
+
fill="none"
|
|
75
|
+
stroke="currentColor"
|
|
76
|
+
stroke-width="1.75"
|
|
77
|
+
stroke-linecap="round"
|
|
78
|
+
stroke-linejoin="round"
|
|
79
|
+
>
|
|
80
|
+
<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" />
|
|
81
|
+
<path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" />
|
|
82
|
+
</svg>`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Lucide "image", for Share as image. */
|
|
86
|
+
export function iconImage() {
|
|
87
|
+
return html`<svg
|
|
88
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
89
|
+
viewBox="0 0 24 24"
|
|
90
|
+
fill="none"
|
|
91
|
+
stroke="currentColor"
|
|
92
|
+
stroke-width="1.75"
|
|
93
|
+
stroke-linecap="round"
|
|
94
|
+
stroke-linejoin="round"
|
|
95
|
+
>
|
|
96
|
+
<rect width="18" height="18" x="3" y="3" rx="2" />
|
|
97
|
+
<circle cx="9" cy="9" r="2" />
|
|
98
|
+
<path d="m21 15-3.09-3.09a2 2 0 0 0-2.82 0L6 21" />
|
|
99
|
+
</svg>`;
|
|
100
|
+
}
|