@show-docs/docusaurus-theme-copy-button 0.1.0 → 0.2.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/README.md CHANGED
@@ -5,8 +5,11 @@
5
5
 
6
6
  ## 安装
7
7
 
8
+ `@theme-prev/*` 的别名由解析器插件提供;theme-iframe 只在构建期提供一条共享函数,装上即可,
9
+ 不必注册成插件。三个包一起安装:
10
+
8
11
  ```bash
9
- pnpm add @show-docs/docusaurus-theme-copy-button
12
+ pnpm add @show-docs/docusaurus-plugin-prev-layer-resolver @show-docs/docusaurus-theme-iframe @show-docs/docusaurus-theme-copy-button
10
13
  ```
11
14
 
12
15
  ## 使用
@@ -16,7 +19,10 @@ pnpm add @show-docs/docusaurus-theme-copy-button
16
19
  ```js
17
20
  // docusaurus.config.mjs
18
21
  export default {
19
- plugins: ['@show-docs/docusaurus-theme-copy-button']
22
+ plugins: [
23
+ '@show-docs/docusaurus-plugin-prev-layer-resolver',
24
+ '@show-docs/docusaurus-theme-copy-button'
25
+ ]
20
26
  };
21
27
  ```
22
28
 
@@ -32,7 +38,7 @@ export default {
32
38
  这一层不读 frontmatter,也没有插件选项。
33
39
 
34
40
  层栈怎么推导、谁能盖住谁,是核心解析器那一格的事,见
35
- [`plugin-prev-layer-resolver` 的 README](../../plugins/plugin-prev-layer-resolver/README.md);
41
+ [`plugin-prev-layer-resolver` 的 README](../plugin-prev-layer-resolver/README.md);
36
42
  这一层自己只负责「挂在哪一格」。
37
43
 
38
44
  ## 工作方式
@@ -58,5 +64,5 @@ export default {
58
64
 
59
65
  ## 相关文档
60
66
 
61
- - [`plugin-prev-layer-resolver` 的 README](../../plugins/plugin-prev-layer-resolver/README.md):`@theme-prev/*` 的语义与层栈。
67
+ - [`plugin-prev-layer-resolver` 的 README](../plugin-prev-layer-resolver/README.md):`@theme-prev/*` 的语义与层栈。
62
68
  - [`sonner` 文档](https://sonner.emilkowal.ski/):提示条的选项与样式。
@@ -9,6 +9,10 @@ const FAILURE_MESSAGE = '复制失败';
9
9
 
10
10
  `navigator.clipboard` 只在这个页面是安全上下文(https,或 localhost)时才存在,
11
11
  用 http 打开的站点拿到的就是 `undefined` —— 这一格要单独判,不能只靠 `catch`。
12
+
13
+ `location.href` 本身已经是百分号编码过的,**原样复制**:解码一遍会把 `%2F` 还原成 `/`,
14
+ 把地址改样;地址末尾有一个裸 `%`(`?q=100%`)时 `decodeURIComponent` 还会抛 `URIError`,
15
+ 按下去只会得到一句「复制失败」。
12
16
  */
13
17
  async function copyPageUrl(): Promise<void> {
14
18
  if (!navigator.clipboard) {
@@ -16,9 +20,7 @@ async function copyPageUrl(): Promise<void> {
16
20
  return;
17
21
  }
18
22
  try {
19
- await navigator.clipboard.writeText(
20
- decodeURIComponent(window.location.href),
21
- );
23
+ await navigator.clipboard.writeText(window.location.href);
22
24
  toast.success(SUCCESS_MESSAGE);
23
25
  } catch (error) {
24
26
  toast.error(FAILURE_MESSAGE);
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import type { Plugin } from '@docusaurus/types';
2
- export default function theme(): Plugin;
1
+ import type { LoadContext, Plugin } from '@docusaurus/types';
2
+ export default function theme(context: LoadContext): Plugin;
package/dist/index.mjs CHANGED
@@ -1,12 +1,23 @@
1
1
  import { dirname, resolve } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
+ import { assertThemePrerequisites } from '@show-docs/docusaurus-theme-iframe/lib/prerequisites.ts';
3
4
  // 包出口是 `dist/`,所以这里的路径都相对**产物**目录算,不是相对 `src/`。
4
5
  const thisDir = dirname(fileURLToPath(import.meta.url));
5
- export default function theme() {
6
+ export default function theme(context) {
6
7
  return {
7
8
  name: '@show-docs/docusaurus-theme-copy-button',
9
+ loadContent() {
10
+ // 本层只在构建期引 theme-iframe 的一条纯函数,不需要它的插件规则;但 `@theme-prev/*`
11
+ // 的别名仍由解析器插件提供,缺了它同样是构建期才炸。
12
+ assertThemePrerequisites(context, {
13
+ namespace: '@show-docs/docusaurus-theme-copy-button',
14
+ });
15
+ },
8
16
  // 主题层与 `components/` 是**源码**,站在包根上,不经 `tsc`:用本包的 Docusaurus
9
17
  // 项目会用自己的 babel 编译它们。这里只编译 `src/` 那一份入口。
18
+ //
19
+ // 「谁来编」归 `@show-docs/docusaurus-plugin-prev-layer-resolver`(它按 `@show-docs`
20
+ // 这个 scope 认领 `node_modules` 里的 TS 源码),本包不自己补 babel 规则。
10
21
  getThemePath() {
11
22
  return resolve(thisDir, '../theme');
12
23
  },
@@ -19,21 +30,5 @@ export default function theme() {
19
30
  getClientModules() {
20
31
  return [resolve(thisDir, '../styles/copy-button.css')];
21
32
  },
22
- configureWebpack(_config, isServer, utils) {
23
- return {
24
- module: {
25
- rules: [
26
- {
27
- // 官方那条 babel 规则排除整个 node_modules、只放行 `docusaurus*.js`,本包从
28
- // npm 安装后的 `.tsx` 会报 `Module parse failed`。补一条只覆盖本包的规则
29
- //(理由与代价见 theme-iframe 的 `lib/api-frame-theme.mts` 里同一条)。
30
- test: /\.tsx?$/,
31
- include: [resolve(thisDir, '..')],
32
- use: [utils.getJSLoader({ isServer })],
33
- },
34
- ],
35
- },
36
- };
37
- },
38
33
  };
39
34
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@show-docs/docusaurus-theme-copy-button",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "页脚版权那一格右边加一颗按钮,点一下把当前页地址写进剪贴板",
5
5
  "keywords": [],
6
- "homepage": "https://github.com/show-docs/docusaurus/tree/master/theme/theme-copy-button",
6
+ "homepage": "https://github.com/show-docs/docusaurus/tree/master/packages/theme-copy-button",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/show-docs/docusaurus.git",
10
- "directory": "theme/theme-copy-button"
10
+ "directory": "packages/theme-copy-button"
11
11
  },
12
12
  "bugs": {
13
13
  "url": "https://github.com/show-docs/docusaurus/issues"
@@ -27,11 +27,17 @@
27
27
  "theme"
28
28
  ],
29
29
  "type": "module",
30
+ "scripts": {
31
+ "build": "tsc -p tsconfig.build.json",
32
+ "prepublishOnly": "pnpm run build"
33
+ },
30
34
  "dependencies": {
31
35
  "sonner": "^2.0.8"
32
36
  },
33
37
  "peerDependencies": {
34
38
  "@docusaurus/types": "^3.9.2",
39
+ "@show-docs/docusaurus-plugin-prev-layer-resolver": "workspace:^",
40
+ "@show-docs/docusaurus-theme-iframe": "workspace:^",
35
41
  "react": "~18.3.1"
36
42
  },
37
43
  "peerDependenciesMeta": {
@@ -45,8 +51,5 @@
45
51
  "publishConfig": {
46
52
  "access": "public",
47
53
  "registry": "https://registry.npmjs.org/"
48
- },
49
- "scripts": {
50
- "build": "tsc -p tsconfig.build.json"
51
54
  }
52
- }
55
+ }