@riebeckite/plugin-share 0.0.16 → 0.0.17
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/README.md +2 -4
- package/README_ja.md +2 -4
- package/dist/index.d.ts +3 -3
- package/dist/index.js +12 -28
- package/dist/src/render.d.ts +1 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -122,7 +122,6 @@ optional `className` is added to the root without replacing them.
|
|
|
122
122
|
- `buildShareUrl(service, target, instance?)` — build one service URL
|
|
123
123
|
- `buildShareLinks(options, target)` — build every link-bearing service
|
|
124
124
|
- `renderShareControls(options, target)` — render the controls HTML
|
|
125
|
-
- `injectShareControls(html, block, placement)` — insert into a note fragment
|
|
126
125
|
- `initShare()` — client initializer (also via
|
|
127
126
|
`@riebeckite/plugin-share/client`)
|
|
128
127
|
- Constants: `SHARE_SERVICES`, `SHARE_ATTRIBUTE`, `SHARE_ROOT_CLASS`,
|
|
@@ -134,10 +133,9 @@ optional `className` is added to the root without replacing them.
|
|
|
134
133
|
|
|
135
134
|
- Share URLs are fixed at build time. A full rebuild always recomputes them.
|
|
136
135
|
- Mastodon cannot be enabled without a concrete instance.
|
|
137
|
-
- The plugin
|
|
138
|
-
|
|
136
|
+
- The plugin contributes controls to `article.before-content` for `top` and
|
|
137
|
+
`article.footer` for `bottom`; a Site places those semantic slots in its layout.
|
|
139
138
|
|
|
140
139
|
## See also
|
|
141
140
|
|
|
142
141
|
- [Plugin guide](../../../docs/en/docs/reference/plugin-api.md)
|
|
143
|
-
|
package/README_ja.md
CHANGED
|
@@ -122,7 +122,6 @@ import "@riebeckite/plugin-share/style.css";
|
|
|
122
122
|
- `buildShareUrl(service, target, instance?)` — 1 サービスの URL を組み立てる
|
|
123
123
|
- `buildShareLinks(options, target)` — リンクを持つサービスをすべて組み立てる
|
|
124
124
|
- `renderShareControls(options, target)` — コントロールの HTML を生成する
|
|
125
|
-
- `injectShareControls(html, block, placement)` — ノート断片に挿入する
|
|
126
125
|
- `initShare()` — ブラウザ初期化関数(`@riebeckite/plugin-share/client` からも
|
|
127
126
|
読み込める)
|
|
128
127
|
- 定数: `SHARE_SERVICES`, `SHARE_ATTRIBUTE`, `SHARE_ROOT_CLASS`,
|
|
@@ -134,10 +133,9 @@ import "@riebeckite/plugin-share/style.css";
|
|
|
134
133
|
|
|
135
134
|
- 共有 URL はビルド時に確定します。再ビルドすれば常に正しく再計算されます。
|
|
136
135
|
- Mastodon は具体的なインスタンスなしには有効化できません。
|
|
137
|
-
-
|
|
138
|
-
|
|
136
|
+
- `top` は `article.before-content`、`bottom` は `article.footer` にコントロールを
|
|
137
|
+
提供します。Site は layout でその semantic slot を配置します。
|
|
139
138
|
|
|
140
139
|
## 関連
|
|
141
140
|
|
|
142
141
|
- [プラグインガイド](../../../docs/ja/docs/reference/plugin-api.md)
|
|
143
|
-
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ShareOptions } from "./src/types.js";
|
|
2
2
|
export { initShare } from "./src/client.js";
|
|
3
3
|
export { DEFAULT_SHARE_ARIA_LABEL, DEFAULT_SHARE_COPIED_LABEL, DEFAULT_SHARE_COPY_FAILED_LABEL, DEFAULT_SHARE_LABELS, DEFAULT_SHARE_PLACEMENT, DEFAULT_SHARE_SERVICES, resolveShareOptions, validateShareOptions, } from "./src/options.js";
|
|
4
|
-
export {
|
|
4
|
+
export { renderShareControls, SHARE_ATTRIBUTE, SHARE_ROOT_CLASS, } from "./src/render.js";
|
|
5
5
|
export { buildAbsoluteUrl, buildShareLinks, buildShareUrl, normalizeMastodonInstance, type ShareTarget, } from "./src/services.js";
|
|
6
6
|
export type { ResolvedShareOptions, ShareLink, ShareOptions, SharePlacement, ShareService, } from "./src/types.js";
|
|
7
7
|
export { SHARE_SERVICES } from "./src/types.js";
|
|
@@ -10,8 +10,8 @@ export declare const SHARE_PLUGIN_NAME = "share";
|
|
|
10
10
|
* Per-article share controls.
|
|
11
11
|
*
|
|
12
12
|
* For every entry the plugin builds absolute share URLs for the configured
|
|
13
|
-
* services and
|
|
14
|
-
*
|
|
13
|
+
* services and contributes the controls to an article layout slot. The links
|
|
14
|
+
* are ordinary anchors, so they work without
|
|
15
15
|
* JavaScript; only the copy-link action is enhanced at runtime.
|
|
16
16
|
*/
|
|
17
17
|
export declare function share(options?: ShareOptions): import("@riebeckite/core").RiebeckitePlugin<ShareOptions>;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// index.ts
|
|
2
2
|
import {
|
|
3
|
+
appendContentBodySlot,
|
|
3
4
|
createClientEntry,
|
|
4
5
|
createStyleAsset,
|
|
5
6
|
definePlugin
|
|
@@ -228,30 +229,6 @@ function renderShareControls(options, target) {
|
|
|
228
229
|
const ariaLabel = escapeHtmlAttribute(options.ariaLabel);
|
|
229
230
|
return `<div class="${escapeHtmlAttribute(rootClass)}" ${SHARE_ATTRIBUTE} data-rr-share-placement="${escapeHtmlAttribute(options.placement)}" role="group" aria-label="${ariaLabel}"><ul class="${SHARE_ROOT_CLASS}__list">${items}${copyItem}</ul><p class="${SHARE_ROOT_CLASS}__status" role="status" aria-live="polite"></p></div>`;
|
|
230
231
|
}
|
|
231
|
-
function injectShareControls(html, block, placement) {
|
|
232
|
-
if (block === "" || html.includes(SHARE_ATTRIBUTE)) return html;
|
|
233
|
-
if (placement === "top") {
|
|
234
|
-
const article = /<article\b[^>]*>/i.exec(html);
|
|
235
|
-
if (article) {
|
|
236
|
-
const end = article.index + article[0].length;
|
|
237
|
-
return `${html.slice(0, end)}${block}${html.slice(end)}`;
|
|
238
|
-
}
|
|
239
|
-
const body = /<body\b[^>]*>/i.exec(html);
|
|
240
|
-
if (body) {
|
|
241
|
-
const end = body.index + body[0].length;
|
|
242
|
-
return `${html.slice(0, end)}${block}${html.slice(end)}`;
|
|
243
|
-
}
|
|
244
|
-
return `${block}
|
|
245
|
-
${html}`;
|
|
246
|
-
}
|
|
247
|
-
const closeIndex = html.toLowerCase().lastIndexOf("</article>");
|
|
248
|
-
if (closeIndex !== -1) {
|
|
249
|
-
const articleEnd = closeIndex + "</article>".length;
|
|
250
|
-
return `${html.slice(0, articleEnd)}${block}${html.slice(articleEnd)}`;
|
|
251
|
-
}
|
|
252
|
-
return `${html}
|
|
253
|
-
${block}`;
|
|
254
|
-
}
|
|
255
232
|
function renderLinkItem(link) {
|
|
256
233
|
const modifier = `${SHARE_ROOT_CLASS}__link--${link.service}`;
|
|
257
234
|
return `<li class="${SHARE_ROOT_CLASS}__item"><a class="${SHARE_ROOT_CLASS}__link ${modifier}" href="${escapeHtmlAttribute(link.url)}" target="_blank" rel="noopener noreferrer" data-share-service="${escapeHtmlAttribute(link.service)}">${escapeHtml(link.label)}</a></li>`;
|
|
@@ -340,14 +317,15 @@ function share(options = {}) {
|
|
|
340
317
|
const { manifest, config } = context;
|
|
341
318
|
if (!config) return;
|
|
342
319
|
for (const entry of manifest.entries) {
|
|
343
|
-
if (!entry.html || entry.html.includes(SHARE_ATTRIBUTE)) continue;
|
|
344
320
|
const block = renderShareControls(resolved, {
|
|
345
321
|
url: buildAbsoluteUrl(config, entry.permalink),
|
|
346
322
|
title: entry.title
|
|
347
323
|
});
|
|
348
324
|
if (block === "") continue;
|
|
349
|
-
const
|
|
350
|
-
entry.
|
|
325
|
+
const slot = resolved.placement === "top" ? "article.before-content" : "article.footer";
|
|
326
|
+
if (!hasSlotFragment(entry.bodySlots?.[slot], block)) {
|
|
327
|
+
appendContentBodySlot(entry, slot, block);
|
|
328
|
+
}
|
|
351
329
|
}
|
|
352
330
|
},
|
|
353
331
|
assets: [createStyleAsset(SHARE_PLUGIN_NAME)],
|
|
@@ -355,6 +333,13 @@ function share(options = {}) {
|
|
|
355
333
|
});
|
|
356
334
|
}
|
|
357
335
|
var sharePlugin = share;
|
|
336
|
+
function hasSlotFragment(slot, fragment) {
|
|
337
|
+
return slot === fragment || slot?.startsWith(`${fragment}
|
|
338
|
+
`) || slot?.endsWith(`
|
|
339
|
+
${fragment}`) || slot?.includes(`
|
|
340
|
+
${fragment}
|
|
341
|
+
`) || false;
|
|
342
|
+
}
|
|
358
343
|
export {
|
|
359
344
|
DEFAULT_SHARE_ARIA_LABEL,
|
|
360
345
|
DEFAULT_SHARE_COPIED_LABEL,
|
|
@@ -370,7 +355,6 @@ export {
|
|
|
370
355
|
buildShareLinks,
|
|
371
356
|
buildShareUrl,
|
|
372
357
|
initShare,
|
|
373
|
-
injectShareControls,
|
|
374
358
|
normalizeMastodonInstance,
|
|
375
359
|
renderShareControls,
|
|
376
360
|
resolveShareOptions,
|
package/dist/src/render.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ShareTarget } from "./services.js";
|
|
2
|
-
import type { ResolvedShareOptions
|
|
2
|
+
import type { ResolvedShareOptions } from "./types.js";
|
|
3
3
|
/** Attribute that marks the generated controls for tests, CSS, and JS. */
|
|
4
4
|
export declare const SHARE_ATTRIBUTE = "data-rr-share";
|
|
5
5
|
/** Stable root hook every rendered set carries, even with a custom class. */
|
|
@@ -9,9 +9,3 @@ export declare const SHARE_ROOT_CLASS = "rr-share";
|
|
|
9
9
|
* service can be rendered, so callers can leave the HTML untouched.
|
|
10
10
|
*/
|
|
11
11
|
export declare function renderShareControls(options: ResolvedShareOptions, target: ShareTarget): string;
|
|
12
|
-
/**
|
|
13
|
-
* Inserts the rendered controls into a note fragment. Top placement lands
|
|
14
|
-
* after the opening `<article>` (or at the start) and bottom placement lands
|
|
15
|
-
* before the closing `</article>` (or at the end).
|
|
16
|
-
*/
|
|
17
|
-
export declare function injectShareControls(html: string, block: string, placement: SharePlacement): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-share",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"./style.css": "./style.css"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@riebeckite/core": "0.0.
|
|
24
|
+
"@riebeckite/core": "0.0.17"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"tsx": "^4.22.4"
|