@linyjs/plugin-docs 0.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/README.md +97 -0
- package/docs/api-reference/index.md +341 -0
- package/docs/best-practices/error-handling.md +462 -0
- package/docs/best-practices/naming-conventions.md +495 -0
- package/docs/best-practices/performance.md +532 -0
- package/docs/best-practices/security.md +620 -0
- package/docs/faq.md +323 -0
- package/docs/getting-started/first-plugin.md +358 -0
- package/docs/getting-started/installation.md +244 -0
- package/docs/getting-started/quick-start.md +174 -0
- package/docs/guides/client-module.md +598 -0
- package/docs/guides/data-persistence.md +536 -0
- package/docs/guides/permissions.md +440 -0
- package/docs/guides/server-module.md +371 -0
- package/docs/guides/ui-slots.md +475 -0
- package/docs/migration/v0-to-v1.md +354 -0
- package/examples/analytics-plugin/README.md +416 -0
- package/examples/analytics-plugin/dist/client/index.d.ts +36 -0
- package/examples/analytics-plugin/dist/client/index.js +173 -0
- package/examples/analytics-plugin/dist/index.d.ts +64 -0
- package/examples/analytics-plugin/dist/index.js +72 -0
- package/examples/analytics-plugin/dist/server/index.d.ts +119 -0
- package/examples/analytics-plugin/dist/server/index.js +313 -0
- package/examples/analytics-plugin/package.json +28 -0
- package/examples/analytics-plugin/src/client/index.tsx +410 -0
- package/examples/analytics-plugin/src/index.ts +71 -0
- package/examples/analytics-plugin/src/server/index.ts +348 -0
- package/examples/analytics-plugin/tsconfig.json +21 -0
- package/examples/blog-plugin/README.md +316 -0
- package/examples/blog-plugin/dist/client/index.d.ts +22 -0
- package/examples/blog-plugin/dist/client/index.js +197 -0
- package/examples/blog-plugin/dist/server/index.d.ts +5 -0
- package/examples/blog-plugin/dist/server/index.js +220 -0
- package/examples/blog-plugin/package.json +24 -0
- package/examples/blog-plugin/src/client/index.tsx +405 -0
- package/examples/blog-plugin/src/server/index.ts +240 -0
- package/examples/blog-plugin/tsconfig.json +16 -0
- package/examples/hello-world/README.md +101 -0
- package/examples/hello-world/dist/client/index.d.ts +5 -0
- package/examples/hello-world/dist/client/index.js +80 -0
- package/examples/hello-world/dist/server/index.d.ts +5 -0
- package/examples/hello-world/dist/server/index.js +38 -0
- package/examples/hello-world/node_modules/.package-lock.json +61 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/HOOKS_USAGE.md +281 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/IMPLEMENTATION_SUMMARY.md +166 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/QUICK_REFERENCE.md +130 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/README.md +214 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/package.json +26 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/application.ts +50 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/comparison-example.tsx +229 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/di.ts +127 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/domain.ts +52 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/hooks-example.tsx +275 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/hooks.ts +175 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/index.ts +87 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/interfaces.ts +117 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/router.ts +49 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/tsconfig.json +10 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/package.json +21 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/application.ts +21 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/di.ts +127 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/domain.ts +75 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/index.ts +55 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/interfaces.ts +58 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/tsconfig.json +8 -0
- package/examples/hello-world/node_modules/@types/react/LICENSE +21 -0
- package/examples/hello-world/node_modules/@types/react/README.md +15 -0
- package/examples/hello-world/node_modules/@types/react/canary.d.ts +129 -0
- package/examples/hello-world/node_modules/@types/react/compiler-runtime.d.ts +4 -0
- package/examples/hello-world/node_modules/@types/react/experimental.d.ts +184 -0
- package/examples/hello-world/node_modules/@types/react/global.d.ts +166 -0
- package/examples/hello-world/node_modules/@types/react/index.d.ts +4369 -0
- package/examples/hello-world/node_modules/@types/react/jsx-dev-runtime.d.ts +33 -0
- package/examples/hello-world/node_modules/@types/react/jsx-runtime.d.ts +24 -0
- package/examples/hello-world/node_modules/@types/react/package.json +210 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/canary.d.ts +129 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/experimental.d.ts +184 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/global.d.ts +166 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/index.d.ts +4356 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/jsx-dev-runtime.d.ts +33 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/jsx-runtime.d.ts +24 -0
- package/examples/hello-world/node_modules/csstype/LICENSE +19 -0
- package/examples/hello-world/node_modules/csstype/README.md +291 -0
- package/examples/hello-world/node_modules/csstype/index.d.ts +22569 -0
- package/examples/hello-world/node_modules/csstype/index.js.flow +6863 -0
- package/examples/hello-world/node_modules/csstype/package.json +70 -0
- package/examples/hello-world/node_modules/react/LICENSE +21 -0
- package/examples/hello-world/node_modules/react/README.md +37 -0
- package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.development.js +24 -0
- package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.production.js +16 -0
- package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.profiling.js +16 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.development.js +338 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.production.js +14 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.profiling.js +14 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.react-server.development.js +370 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.react-server.production.js +40 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.development.js +352 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.production.js +34 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.profiling.js +34 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.react-server.development.js +370 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.react-server.production.js +40 -0
- package/examples/hello-world/node_modules/react/cjs/react.development.js +1284 -0
- package/examples/hello-world/node_modules/react/cjs/react.production.js +542 -0
- package/examples/hello-world/node_modules/react/cjs/react.react-server.development.js +848 -0
- package/examples/hello-world/node_modules/react/cjs/react.react-server.production.js +423 -0
- package/examples/hello-world/node_modules/react/compiler-runtime.js +14 -0
- package/examples/hello-world/node_modules/react/index.js +7 -0
- package/examples/hello-world/node_modules/react/jsx-dev-runtime.js +7 -0
- package/examples/hello-world/node_modules/react/jsx-dev-runtime.react-server.js +7 -0
- package/examples/hello-world/node_modules/react/jsx-runtime.js +7 -0
- package/examples/hello-world/node_modules/react/jsx-runtime.react-server.js +7 -0
- package/examples/hello-world/node_modules/react/package.json +51 -0
- package/examples/hello-world/node_modules/react/react.react-server.js +7 -0
- package/examples/hello-world/node_modules/typescript/LICENSE.txt +55 -0
- package/examples/hello-world/node_modules/typescript/README.md +50 -0
- package/examples/hello-world/node_modules/typescript/SECURITY.md +41 -0
- package/examples/hello-world/node_modules/typescript/ThirdPartyNoticeText.txt +193 -0
- package/examples/hello-world/node_modules/typescript/bin/tsc +2 -0
- package/examples/hello-world/node_modules/typescript/bin/tsserver +2 -0
- package/examples/hello-world/node_modules/typescript/lib/_tsc.js +133818 -0
- package/examples/hello-world/node_modules/typescript/lib/_tsserver.js +659 -0
- package/examples/hello-world/node_modules/typescript/lib/_typingsInstaller.js +222 -0
- package/examples/hello-world/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/de/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/es/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/it/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.d.ts +22 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.decorators.d.ts +384 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.decorators.legacy.d.ts +22 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +41 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.dom.d.ts +39429 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.dom.iterable.d.ts +571 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.collection.d.ts +147 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.core.d.ts +597 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.d.ts +28 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.generator.d.ts +77 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.iterable.d.ts +605 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.promise.d.ts +81 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.proxy.d.ts +128 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.reflect.d.ts +144 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.symbol.d.ts +46 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +326 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2016.array.include.d.ts +116 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2016.d.ts +21 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2016.full.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2016.intl.d.ts +31 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +21 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.d.ts +26 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.date.d.ts +31 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.full.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.intl.d.ts +44 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.object.d.ts +49 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +135 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.string.d.ts +45 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +53 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +77 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +53 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.intl.d.ts +83 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.promise.d.ts +30 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.regexp.d.ts +37 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.array.d.ts +79 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.intl.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.object.d.ts +33 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.string.d.ts +37 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.symbol.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.bigint.d.ts +765 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.d.ts +27 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.date.d.ts +42 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.intl.d.ts +474 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.number.d.ts +28 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.promise.d.ts +47 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +99 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.string.d.ts +44 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +41 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.intl.d.ts +166 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.promise.d.ts +48 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.string.d.ts +33 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.weakref.d.ts +78 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.array.d.ts +121 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.d.ts +25 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.error.d.ts +75 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.intl.d.ts +145 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.object.d.ts +26 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.regexp.d.ts +39 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.string.d.ts +25 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.array.d.ts +924 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.collection.d.ts +21 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.d.ts +22 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.intl.d.ts +56 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +65 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.collection.d.ts +29 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.d.ts +26 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.object.d.ts +29 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.promise.d.ts +35 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.regexp.d.ts +25 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +68 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.string.d.ts +29 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es5.d.ts +4601 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es6.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.array.d.ts +35 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.collection.d.ts +96 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.d.ts +29 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.decorators.d.ts +28 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.disposable.d.ts +193 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.error.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.float16.d.ts +445 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.intl.d.ts +21 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.iterator.d.ts +148 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.promise.d.ts +34 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +25 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.scripthost.d.ts +322 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +41 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.webworker.d.ts +13150 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.webworker.iterable.d.ts +340 -0
- package/examples/hello-world/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/tsc.js +8 -0
- package/examples/hello-world/node_modules/typescript/lib/tsserver.js +8 -0
- package/examples/hello-world/node_modules/typescript/lib/tsserverlibrary.d.ts +17 -0
- package/examples/hello-world/node_modules/typescript/lib/tsserverlibrary.js +21 -0
- package/examples/hello-world/node_modules/typescript/lib/typesMap.json +497 -0
- package/examples/hello-world/node_modules/typescript/lib/typescript.d.ts +11437 -0
- package/examples/hello-world/node_modules/typescript/lib/typescript.js +200276 -0
- package/examples/hello-world/node_modules/typescript/lib/typingsInstaller.js +8 -0
- package/examples/hello-world/node_modules/typescript/lib/watchGuard.js +53 -0
- package/examples/hello-world/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/package.json +120 -0
- package/examples/hello-world/package-lock.json +74 -0
- package/examples/hello-world/package.json +23 -0
- package/examples/hello-world/src/client/index.tsx +110 -0
- package/examples/hello-world/src/server/index.ts +42 -0
- package/examples/hello-world/tsconfig.json +16 -0
- package/package.json +42 -0
- package/src/cli.ts +321 -0
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
# UI 扩展插槽
|
|
2
|
+
|
|
3
|
+
本指南介绍如何使用 linyjs 的 UI 扩展插槽(Slot)机制来注入自定义 UI 组件。
|
|
4
|
+
|
|
5
|
+
## 什么是 Slot?
|
|
6
|
+
|
|
7
|
+
Slot 是一种 UI 扩展机制,允许插件向预定义的位置注入自定义组件,而无需修改核心代码。
|
|
8
|
+
|
|
9
|
+
### 使用场景
|
|
10
|
+
|
|
11
|
+
- 🎯 在管理后台添加自定义菜单项
|
|
12
|
+
- 📊 在仪表盘注入统计图表
|
|
13
|
+
- 🔧 在设置页面添加配置选项
|
|
14
|
+
- 🎨 自定义用户界面的任何部分
|
|
15
|
+
|
|
16
|
+
## 可用的 Slot 位置
|
|
17
|
+
|
|
18
|
+
### 管理后台
|
|
19
|
+
|
|
20
|
+
| Slot 位置 | 说明 | 示例用途 |
|
|
21
|
+
|-----------|------|----------|
|
|
22
|
+
| `admin-sidebar` | 侧边栏菜单 | 添加新功能入口 |
|
|
23
|
+
| `admin-header` | 顶部导航 | 添加通知、用户菜单 |
|
|
24
|
+
| `admin-dashboard` | 仪表盘 | 添加统计卡片、图表 |
|
|
25
|
+
| `admin-settings` | 设置页面 | 添加自定义配置项 |
|
|
26
|
+
| `admin-user-list` | 用户列表操作列 | 添加自定义操作按钮 |
|
|
27
|
+
|
|
28
|
+
### 个人后台
|
|
29
|
+
|
|
30
|
+
| Slot 位置 | 说明 | 示例用途 |
|
|
31
|
+
|-----------|------|----------|
|
|
32
|
+
| `personal-dashboard` | 个人仪表盘 | 添加个人信息卡片 |
|
|
33
|
+
| `personal-header` | 个人顶部导航 | 添加快捷操作 |
|
|
34
|
+
|
|
35
|
+
### 插件市场
|
|
36
|
+
|
|
37
|
+
| Slot 位置 | 说明 | 示例用途 |
|
|
38
|
+
|-----------|------|----------|
|
|
39
|
+
| `plugin-marketplace` | 插件市场页面 | 添加推荐插件 |
|
|
40
|
+
|
|
41
|
+
## 注册 Slot 组件
|
|
42
|
+
|
|
43
|
+
### 基本用法
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import type { ISlotComponent } from '@linyjs/ui-slots-interface';
|
|
47
|
+
import { getSlotRegistry } from '@linyjs/admin';
|
|
48
|
+
import React from 'react';
|
|
49
|
+
|
|
50
|
+
// 1. 创建组件
|
|
51
|
+
function AnalyticsMenu() {
|
|
52
|
+
return (
|
|
53
|
+
<a href="/admin/analytics" style={{ padding: '10px' }}>
|
|
54
|
+
📊 数据分析
|
|
55
|
+
</a>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 2. 在插件初始化时注册
|
|
60
|
+
export function initPlugin() {
|
|
61
|
+
const registry = getSlotRegistry();
|
|
62
|
+
|
|
63
|
+
registry.register({
|
|
64
|
+
id: 'analytics-menu',
|
|
65
|
+
position: 'admin-sidebar',
|
|
66
|
+
component: AnalyticsMenu,
|
|
67
|
+
priority: 50,
|
|
68
|
+
packageName: 'analytics-plugin'
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 条件渲染
|
|
74
|
+
|
|
75
|
+
根据用户权限或状态决定是否显示:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
registry.register({
|
|
79
|
+
id: 'premium-feature',
|
|
80
|
+
position: 'admin-dashboard',
|
|
81
|
+
component: PremiumWidget,
|
|
82
|
+
priority: 100,
|
|
83
|
+
shouldRender: (context) => {
|
|
84
|
+
// 只有高级用户可见
|
|
85
|
+
return context.user?.isPremium === true;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 动态内容
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
function NotificationBadge() {
|
|
94
|
+
const [count, setCount] = React.useState(0);
|
|
95
|
+
|
|
96
|
+
React.useEffect(() => {
|
|
97
|
+
// 获取通知数量
|
|
98
|
+
fetch('/api/notifications/count')
|
|
99
|
+
.then(res => res.json())
|
|
100
|
+
.then(data => setCount(data.count));
|
|
101
|
+
}, []);
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<div style={{ position: 'relative' }}>
|
|
105
|
+
🔔
|
|
106
|
+
{count > 0 && (
|
|
107
|
+
<span style={{
|
|
108
|
+
position: 'absolute',
|
|
109
|
+
top: '-5px',
|
|
110
|
+
right: '-5px',
|
|
111
|
+
backgroundColor: 'red',
|
|
112
|
+
color: 'white',
|
|
113
|
+
borderRadius: '50%',
|
|
114
|
+
padding: '2px 6px',
|
|
115
|
+
fontSize: '12px'
|
|
116
|
+
}}>
|
|
117
|
+
{count}
|
|
118
|
+
</span>
|
|
119
|
+
)}
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
registry.register({
|
|
125
|
+
id: 'notification-badge',
|
|
126
|
+
position: 'admin-header',
|
|
127
|
+
component: NotificationBadge,
|
|
128
|
+
priority: 90
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Slot 优先级
|
|
133
|
+
|
|
134
|
+
优先级决定组件的渲染顺序(数字越大越靠前):
|
|
135
|
+
|
|
136
|
+
| 优先级范围 | 用途 | 示例 |
|
|
137
|
+
|-----------|------|------|
|
|
138
|
+
| 0-10 | 基础功能 | 默认菜单项 |
|
|
139
|
+
| 10-50 | 常用扩展 | 普通功能入口 |
|
|
140
|
+
| 50-100 | 重要扩展 | 核心功能入口 |
|
|
141
|
+
| 100+ | 核心功能 | 系统级功能 |
|
|
142
|
+
|
|
143
|
+
### 优先级示例
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
// 低优先级 - 显示在后面
|
|
147
|
+
registry.register({
|
|
148
|
+
id: 'help-link',
|
|
149
|
+
position: 'admin-sidebar',
|
|
150
|
+
component: HelpLink,
|
|
151
|
+
priority: 5
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// 中优先级 - 显示在中间
|
|
155
|
+
registry.register({
|
|
156
|
+
id: 'analytics-link',
|
|
157
|
+
position: 'admin-sidebar',
|
|
158
|
+
component: AnalyticsLink,
|
|
159
|
+
priority: 50
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// 高优先级 - 显示在前面
|
|
163
|
+
registry.register({
|
|
164
|
+
id: 'dashboard-link',
|
|
165
|
+
position: 'admin-sidebar',
|
|
166
|
+
component: DashboardLink,
|
|
167
|
+
priority: 100
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Slot Context
|
|
172
|
+
|
|
173
|
+
注册时可以访问上下文信息:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
interface SlotContext {
|
|
177
|
+
user?: {
|
|
178
|
+
id: number;
|
|
179
|
+
name: string;
|
|
180
|
+
roles: string[];
|
|
181
|
+
isPremium?: boolean;
|
|
182
|
+
};
|
|
183
|
+
location?: {
|
|
184
|
+
pathname: string;
|
|
185
|
+
search: string;
|
|
186
|
+
};
|
|
187
|
+
theme?: 'light' | 'dark';
|
|
188
|
+
// ... 其他上下文信息
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
registry.register({
|
|
192
|
+
id: 'user-specific-widget',
|
|
193
|
+
position: 'admin-dashboard',
|
|
194
|
+
component: UserWidget,
|
|
195
|
+
shouldRender: (context: SlotContext) => {
|
|
196
|
+
// 根据用户角色决定
|
|
197
|
+
return context.user?.roles?.includes('admin');
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## 移除 Slot
|
|
203
|
+
|
|
204
|
+
如果需要动态移除已注册的 Slot:
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
// 注册时保存引用
|
|
208
|
+
const slotId = registry.register({
|
|
209
|
+
id: 'temp-widget',
|
|
210
|
+
position: 'admin-dashboard',
|
|
211
|
+
component: TempWidget
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// 稍后移除
|
|
215
|
+
registry.unregister(slotId);
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## 完整示例
|
|
219
|
+
|
|
220
|
+
### 示例 1: 添加侧边栏菜单
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import React from 'react';
|
|
224
|
+
import { getSlotRegistry } from '@linyjs/admin';
|
|
225
|
+
|
|
226
|
+
function BlogMenu() {
|
|
227
|
+
return (
|
|
228
|
+
<div style={{
|
|
229
|
+
padding: '12px 16px',
|
|
230
|
+
cursor: 'pointer',
|
|
231
|
+
'&:hover': { backgroundColor: '#f5f5f5' }
|
|
232
|
+
}}>
|
|
233
|
+
<span style={{ marginRight: '8px' }}>📝</span>
|
|
234
|
+
<span>博客管理</span>
|
|
235
|
+
</div>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function initBlogPlugin() {
|
|
240
|
+
const registry = getSlotRegistry();
|
|
241
|
+
|
|
242
|
+
registry.register({
|
|
243
|
+
id: 'blog-menu',
|
|
244
|
+
position: 'admin-sidebar',
|
|
245
|
+
component: BlogMenu,
|
|
246
|
+
priority: 60,
|
|
247
|
+
shouldRender: (context) => {
|
|
248
|
+
// 仅管理员和编辑可见
|
|
249
|
+
return context.user?.roles?.includes('admin') ||
|
|
250
|
+
context.user?.roles?.includes('editor');
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### 示例 2: 仪表盘统计卡片
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
import React, { useState, useEffect } from 'react';
|
|
260
|
+
|
|
261
|
+
function StatsCard({ title, value, icon }: {
|
|
262
|
+
title: string;
|
|
263
|
+
value: number;
|
|
264
|
+
icon: string
|
|
265
|
+
}) {
|
|
266
|
+
return (
|
|
267
|
+
<div style={{
|
|
268
|
+
padding: '20px',
|
|
269
|
+
backgroundColor: 'white',
|
|
270
|
+
borderRadius: '8px',
|
|
271
|
+
boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
|
|
272
|
+
textAlign: 'center'
|
|
273
|
+
}}>
|
|
274
|
+
<div style={{ fontSize: '32px', marginBottom: '8px' }}>{icon}</div>
|
|
275
|
+
<div style={{ fontSize: '24px', fontWeight: 'bold', color: '#333' }}>
|
|
276
|
+
{value}
|
|
277
|
+
</div>
|
|
278
|
+
<div style={{ color: '#666', marginTop: '4px' }}>{title}</div>
|
|
279
|
+
</div>
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function DashboardStats() {
|
|
284
|
+
const [stats, setStats] = useState({
|
|
285
|
+
users: 0,
|
|
286
|
+
articles: 0,
|
|
287
|
+
comments: 0
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
useEffect(() => {
|
|
291
|
+
fetch('/api/stats')
|
|
292
|
+
.then(res => res.json())
|
|
293
|
+
.then(setStats);
|
|
294
|
+
}, []);
|
|
295
|
+
|
|
296
|
+
return (
|
|
297
|
+
<div style={{
|
|
298
|
+
display: 'grid',
|
|
299
|
+
gridTemplateColumns: 'repeat(3, 1fr)',
|
|
300
|
+
gap: '16px',
|
|
301
|
+
padding: '20px'
|
|
302
|
+
}}>
|
|
303
|
+
<StatsCard title="用户数" value={stats.users} icon="👥" />
|
|
304
|
+
<StatsCard title="文章数" value={stats.articles} icon="📝" />
|
|
305
|
+
<StatsCard title="评论数" value={stats.comments} icon="💬" />
|
|
306
|
+
</div>
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export function initStatsPlugin() {
|
|
311
|
+
const registry = getSlotRegistry();
|
|
312
|
+
|
|
313
|
+
registry.register({
|
|
314
|
+
id: 'dashboard-stats',
|
|
315
|
+
position: 'admin-dashboard',
|
|
316
|
+
component: DashboardStats,
|
|
317
|
+
priority: 100
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### 示例 3: 用户列表操作按钮
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
import React from 'react';
|
|
326
|
+
|
|
327
|
+
function UserActionButtons({ userId }: { userId: number }) {
|
|
328
|
+
const handleBan = async () => {
|
|
329
|
+
if (confirm('确定要封禁此用户吗?')) {
|
|
330
|
+
await fetch(`/api/users/${userId}/ban`, { method: 'POST' });
|
|
331
|
+
alert('用户已封禁');
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
return (
|
|
336
|
+
<div style={{ display: 'flex', gap: '8px' }}>
|
|
337
|
+
<button onClick={() => alert(`编辑用户 ${userId}`)}>
|
|
338
|
+
✏️ 编辑
|
|
339
|
+
</button>
|
|
340
|
+
<button onClick={handleBan} style={{ color: 'red' }}>
|
|
341
|
+
🚫 封禁
|
|
342
|
+
</button>
|
|
343
|
+
</div>
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export function initUserActionsPlugin() {
|
|
348
|
+
const registry = getSlotRegistry();
|
|
349
|
+
|
|
350
|
+
registry.register({
|
|
351
|
+
id: 'user-actions',
|
|
352
|
+
position: 'admin-user-list',
|
|
353
|
+
component: UserActionButtons,
|
|
354
|
+
priority: 50
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
## 最佳实践
|
|
360
|
+
|
|
361
|
+
### 1. 组件轻量化
|
|
362
|
+
|
|
363
|
+
Slot 组件应该轻量,避免复杂逻辑:
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
// ✅ 好的做法 - 轻量组件
|
|
367
|
+
function SimpleMenu() {
|
|
368
|
+
return <a href="/page">Page</a>;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// ❌ 避免 - 过重逻辑
|
|
372
|
+
function ComplexMenu() {
|
|
373
|
+
// 大量状态管理、副作用等
|
|
374
|
+
const [state1, setState1] = useState(...);
|
|
375
|
+
const [state2, setState2] = useState(...);
|
|
376
|
+
// ...
|
|
377
|
+
}
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
### 2. 错误边界
|
|
381
|
+
|
|
382
|
+
为 Slot 组件添加错误处理:
|
|
383
|
+
|
|
384
|
+
```typescript
|
|
385
|
+
function SafeSlotComponent() {
|
|
386
|
+
const [error, setError] = useState<string | null>(null);
|
|
387
|
+
|
|
388
|
+
try {
|
|
389
|
+
// 组件逻辑
|
|
390
|
+
return <div>Content</div>;
|
|
391
|
+
} catch (err) {
|
|
392
|
+
setError(err.message);
|
|
393
|
+
return <div>Error loading component</div>;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### 3. 懒加载
|
|
399
|
+
|
|
400
|
+
对于重型组件,使用懒加载:
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
function LazySlotComponent() {
|
|
404
|
+
const HeavyComponent = React.lazy(() => import('./HeavyComponent'));
|
|
405
|
+
|
|
406
|
+
return (
|
|
407
|
+
<React.Suspense fallback={<div>Loading...</div>}>
|
|
408
|
+
<HeavyComponent />
|
|
409
|
+
</React.Suspense>
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
registry.register({
|
|
414
|
+
id: 'heavy-widget',
|
|
415
|
+
position: 'admin-dashboard',
|
|
416
|
+
component: LazySlotComponent,
|
|
417
|
+
priority: 50
|
|
418
|
+
});
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
### 4. 唯一 ID
|
|
422
|
+
|
|
423
|
+
确保每个 Slot 的 ID 唯一:
|
|
424
|
+
|
|
425
|
+
```typescript
|
|
426
|
+
// ✅ 好的做法 - 使用包名作为前缀
|
|
427
|
+
registry.register({
|
|
428
|
+
id: 'my-plugin.analytics-menu',
|
|
429
|
+
position: 'admin-sidebar',
|
|
430
|
+
component: AnalyticsMenu
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// ❌ 避免 - ID 可能冲突
|
|
434
|
+
registry.register({
|
|
435
|
+
id: 'analytics-menu',
|
|
436
|
+
position: 'admin-sidebar',
|
|
437
|
+
component: AnalyticsMenu
|
|
438
|
+
});
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
## 调试技巧
|
|
442
|
+
|
|
443
|
+
### 查看已注册的 Slots
|
|
444
|
+
|
|
445
|
+
```typescript
|
|
446
|
+
const registry = getSlotRegistry();
|
|
447
|
+
const slots = registry.getAll();
|
|
448
|
+
console.log('Registered slots:', slots);
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### 测试条件渲染
|
|
452
|
+
|
|
453
|
+
```typescript
|
|
454
|
+
registry.register({
|
|
455
|
+
id: 'debug-widget',
|
|
456
|
+
position: 'admin-dashboard',
|
|
457
|
+
component: () => {
|
|
458
|
+
console.log('Rendering debug widget');
|
|
459
|
+
return <div>Debug</div>;
|
|
460
|
+
},
|
|
461
|
+
shouldRender: (context) => {
|
|
462
|
+
console.log('Context:', context);
|
|
463
|
+
return true;
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
## 相关文档
|
|
469
|
+
|
|
470
|
+
- 📖 [客户端模块开发](./client-module.md)
|
|
471
|
+
- 🔒 [权限管理](./permissions.md)
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
475
|
+
**上一篇**: [客户端模块开发](./client-module.md) | **下一篇**: [权限管理](./permissions.md)
|