@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.
Files changed (252) hide show
  1. package/README.md +97 -0
  2. package/docs/api-reference/index.md +341 -0
  3. package/docs/best-practices/error-handling.md +462 -0
  4. package/docs/best-practices/naming-conventions.md +495 -0
  5. package/docs/best-practices/performance.md +532 -0
  6. package/docs/best-practices/security.md +620 -0
  7. package/docs/faq.md +323 -0
  8. package/docs/getting-started/first-plugin.md +358 -0
  9. package/docs/getting-started/installation.md +244 -0
  10. package/docs/getting-started/quick-start.md +174 -0
  11. package/docs/guides/client-module.md +598 -0
  12. package/docs/guides/data-persistence.md +536 -0
  13. package/docs/guides/permissions.md +440 -0
  14. package/docs/guides/server-module.md +371 -0
  15. package/docs/guides/ui-slots.md +475 -0
  16. package/docs/migration/v0-to-v1.md +354 -0
  17. package/examples/analytics-plugin/README.md +416 -0
  18. package/examples/analytics-plugin/dist/client/index.d.ts +36 -0
  19. package/examples/analytics-plugin/dist/client/index.js +173 -0
  20. package/examples/analytics-plugin/dist/index.d.ts +64 -0
  21. package/examples/analytics-plugin/dist/index.js +72 -0
  22. package/examples/analytics-plugin/dist/server/index.d.ts +119 -0
  23. package/examples/analytics-plugin/dist/server/index.js +313 -0
  24. package/examples/analytics-plugin/package.json +28 -0
  25. package/examples/analytics-plugin/src/client/index.tsx +410 -0
  26. package/examples/analytics-plugin/src/index.ts +71 -0
  27. package/examples/analytics-plugin/src/server/index.ts +348 -0
  28. package/examples/analytics-plugin/tsconfig.json +21 -0
  29. package/examples/blog-plugin/README.md +316 -0
  30. package/examples/blog-plugin/dist/client/index.d.ts +22 -0
  31. package/examples/blog-plugin/dist/client/index.js +197 -0
  32. package/examples/blog-plugin/dist/server/index.d.ts +5 -0
  33. package/examples/blog-plugin/dist/server/index.js +220 -0
  34. package/examples/blog-plugin/package.json +24 -0
  35. package/examples/blog-plugin/src/client/index.tsx +405 -0
  36. package/examples/blog-plugin/src/server/index.ts +240 -0
  37. package/examples/blog-plugin/tsconfig.json +16 -0
  38. package/examples/hello-world/README.md +101 -0
  39. package/examples/hello-world/dist/client/index.d.ts +5 -0
  40. package/examples/hello-world/dist/client/index.js +80 -0
  41. package/examples/hello-world/dist/server/index.d.ts +5 -0
  42. package/examples/hello-world/dist/server/index.js +38 -0
  43. package/examples/hello-world/node_modules/.package-lock.json +61 -0
  44. package/examples/hello-world/node_modules/@linyjs/client-module-interface/HOOKS_USAGE.md +281 -0
  45. package/examples/hello-world/node_modules/@linyjs/client-module-interface/IMPLEMENTATION_SUMMARY.md +166 -0
  46. package/examples/hello-world/node_modules/@linyjs/client-module-interface/QUICK_REFERENCE.md +130 -0
  47. package/examples/hello-world/node_modules/@linyjs/client-module-interface/README.md +214 -0
  48. package/examples/hello-world/node_modules/@linyjs/client-module-interface/package.json +26 -0
  49. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/application.ts +50 -0
  50. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/comparison-example.tsx +229 -0
  51. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/di.ts +127 -0
  52. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/domain.ts +52 -0
  53. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/hooks-example.tsx +275 -0
  54. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/hooks.ts +175 -0
  55. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/index.ts +87 -0
  56. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/interfaces.ts +117 -0
  57. package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/router.ts +49 -0
  58. package/examples/hello-world/node_modules/@linyjs/client-module-interface/tsconfig.json +10 -0
  59. package/examples/hello-world/node_modules/@linyjs/server-module-interface/package.json +21 -0
  60. package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/application.ts +21 -0
  61. package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/di.ts +127 -0
  62. package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/domain.ts +75 -0
  63. package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/index.ts +55 -0
  64. package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/interfaces.ts +58 -0
  65. package/examples/hello-world/node_modules/@linyjs/server-module-interface/tsconfig.json +8 -0
  66. package/examples/hello-world/node_modules/@types/react/LICENSE +21 -0
  67. package/examples/hello-world/node_modules/@types/react/README.md +15 -0
  68. package/examples/hello-world/node_modules/@types/react/canary.d.ts +129 -0
  69. package/examples/hello-world/node_modules/@types/react/compiler-runtime.d.ts +4 -0
  70. package/examples/hello-world/node_modules/@types/react/experimental.d.ts +184 -0
  71. package/examples/hello-world/node_modules/@types/react/global.d.ts +166 -0
  72. package/examples/hello-world/node_modules/@types/react/index.d.ts +4369 -0
  73. package/examples/hello-world/node_modules/@types/react/jsx-dev-runtime.d.ts +33 -0
  74. package/examples/hello-world/node_modules/@types/react/jsx-runtime.d.ts +24 -0
  75. package/examples/hello-world/node_modules/@types/react/package.json +210 -0
  76. package/examples/hello-world/node_modules/@types/react/ts5.0/canary.d.ts +129 -0
  77. package/examples/hello-world/node_modules/@types/react/ts5.0/experimental.d.ts +184 -0
  78. package/examples/hello-world/node_modules/@types/react/ts5.0/global.d.ts +166 -0
  79. package/examples/hello-world/node_modules/@types/react/ts5.0/index.d.ts +4356 -0
  80. package/examples/hello-world/node_modules/@types/react/ts5.0/jsx-dev-runtime.d.ts +33 -0
  81. package/examples/hello-world/node_modules/@types/react/ts5.0/jsx-runtime.d.ts +24 -0
  82. package/examples/hello-world/node_modules/csstype/LICENSE +19 -0
  83. package/examples/hello-world/node_modules/csstype/README.md +291 -0
  84. package/examples/hello-world/node_modules/csstype/index.d.ts +22569 -0
  85. package/examples/hello-world/node_modules/csstype/index.js.flow +6863 -0
  86. package/examples/hello-world/node_modules/csstype/package.json +70 -0
  87. package/examples/hello-world/node_modules/react/LICENSE +21 -0
  88. package/examples/hello-world/node_modules/react/README.md +37 -0
  89. package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.development.js +24 -0
  90. package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.production.js +16 -0
  91. package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.profiling.js +16 -0
  92. package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.development.js +338 -0
  93. package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.production.js +14 -0
  94. package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.profiling.js +14 -0
  95. package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.react-server.development.js +370 -0
  96. package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.react-server.production.js +40 -0
  97. package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.development.js +352 -0
  98. package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.production.js +34 -0
  99. package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.profiling.js +34 -0
  100. package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.react-server.development.js +370 -0
  101. package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.react-server.production.js +40 -0
  102. package/examples/hello-world/node_modules/react/cjs/react.development.js +1284 -0
  103. package/examples/hello-world/node_modules/react/cjs/react.production.js +542 -0
  104. package/examples/hello-world/node_modules/react/cjs/react.react-server.development.js +848 -0
  105. package/examples/hello-world/node_modules/react/cjs/react.react-server.production.js +423 -0
  106. package/examples/hello-world/node_modules/react/compiler-runtime.js +14 -0
  107. package/examples/hello-world/node_modules/react/index.js +7 -0
  108. package/examples/hello-world/node_modules/react/jsx-dev-runtime.js +7 -0
  109. package/examples/hello-world/node_modules/react/jsx-dev-runtime.react-server.js +7 -0
  110. package/examples/hello-world/node_modules/react/jsx-runtime.js +7 -0
  111. package/examples/hello-world/node_modules/react/jsx-runtime.react-server.js +7 -0
  112. package/examples/hello-world/node_modules/react/package.json +51 -0
  113. package/examples/hello-world/node_modules/react/react.react-server.js +7 -0
  114. package/examples/hello-world/node_modules/typescript/LICENSE.txt +55 -0
  115. package/examples/hello-world/node_modules/typescript/README.md +50 -0
  116. package/examples/hello-world/node_modules/typescript/SECURITY.md +41 -0
  117. package/examples/hello-world/node_modules/typescript/ThirdPartyNoticeText.txt +193 -0
  118. package/examples/hello-world/node_modules/typescript/bin/tsc +2 -0
  119. package/examples/hello-world/node_modules/typescript/bin/tsserver +2 -0
  120. package/examples/hello-world/node_modules/typescript/lib/_tsc.js +133818 -0
  121. package/examples/hello-world/node_modules/typescript/lib/_tsserver.js +659 -0
  122. package/examples/hello-world/node_modules/typescript/lib/_typingsInstaller.js +222 -0
  123. package/examples/hello-world/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +2122 -0
  124. package/examples/hello-world/node_modules/typescript/lib/de/diagnosticMessages.generated.json +2122 -0
  125. package/examples/hello-world/node_modules/typescript/lib/es/diagnosticMessages.generated.json +2122 -0
  126. package/examples/hello-world/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +2122 -0
  127. package/examples/hello-world/node_modules/typescript/lib/it/diagnosticMessages.generated.json +2122 -0
  128. package/examples/hello-world/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +2122 -0
  129. package/examples/hello-world/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +2122 -0
  130. package/examples/hello-world/node_modules/typescript/lib/lib.d.ts +22 -0
  131. package/examples/hello-world/node_modules/typescript/lib/lib.decorators.d.ts +384 -0
  132. package/examples/hello-world/node_modules/typescript/lib/lib.decorators.legacy.d.ts +22 -0
  133. package/examples/hello-world/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +41 -0
  134. package/examples/hello-world/node_modules/typescript/lib/lib.dom.d.ts +39429 -0
  135. package/examples/hello-world/node_modules/typescript/lib/lib.dom.iterable.d.ts +571 -0
  136. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.collection.d.ts +147 -0
  137. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.core.d.ts +597 -0
  138. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.d.ts +28 -0
  139. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.generator.d.ts +77 -0
  140. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.iterable.d.ts +605 -0
  141. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.promise.d.ts +81 -0
  142. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.proxy.d.ts +128 -0
  143. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.reflect.d.ts +144 -0
  144. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.symbol.d.ts +46 -0
  145. package/examples/hello-world/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +326 -0
  146. package/examples/hello-world/node_modules/typescript/lib/lib.es2016.array.include.d.ts +116 -0
  147. package/examples/hello-world/node_modules/typescript/lib/lib.es2016.d.ts +21 -0
  148. package/examples/hello-world/node_modules/typescript/lib/lib.es2016.full.d.ts +23 -0
  149. package/examples/hello-world/node_modules/typescript/lib/lib.es2016.intl.d.ts +31 -0
  150. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +21 -0
  151. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.d.ts +26 -0
  152. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.date.d.ts +31 -0
  153. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.full.d.ts +23 -0
  154. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.intl.d.ts +44 -0
  155. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.object.d.ts +49 -0
  156. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +135 -0
  157. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.string.d.ts +45 -0
  158. package/examples/hello-world/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +53 -0
  159. package/examples/hello-world/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +77 -0
  160. package/examples/hello-world/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +53 -0
  161. package/examples/hello-world/node_modules/typescript/lib/lib.es2018.d.ts +24 -0
  162. package/examples/hello-world/node_modules/typescript/lib/lib.es2018.full.d.ts +24 -0
  163. package/examples/hello-world/node_modules/typescript/lib/lib.es2018.intl.d.ts +83 -0
  164. package/examples/hello-world/node_modules/typescript/lib/lib.es2018.promise.d.ts +30 -0
  165. package/examples/hello-world/node_modules/typescript/lib/lib.es2018.regexp.d.ts +37 -0
  166. package/examples/hello-world/node_modules/typescript/lib/lib.es2019.array.d.ts +79 -0
  167. package/examples/hello-world/node_modules/typescript/lib/lib.es2019.d.ts +24 -0
  168. package/examples/hello-world/node_modules/typescript/lib/lib.es2019.full.d.ts +24 -0
  169. package/examples/hello-world/node_modules/typescript/lib/lib.es2019.intl.d.ts +23 -0
  170. package/examples/hello-world/node_modules/typescript/lib/lib.es2019.object.d.ts +33 -0
  171. package/examples/hello-world/node_modules/typescript/lib/lib.es2019.string.d.ts +37 -0
  172. package/examples/hello-world/node_modules/typescript/lib/lib.es2019.symbol.d.ts +24 -0
  173. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.bigint.d.ts +765 -0
  174. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.d.ts +27 -0
  175. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.date.d.ts +42 -0
  176. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.full.d.ts +24 -0
  177. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.intl.d.ts +474 -0
  178. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.number.d.ts +28 -0
  179. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.promise.d.ts +47 -0
  180. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +99 -0
  181. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.string.d.ts +44 -0
  182. package/examples/hello-world/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +41 -0
  183. package/examples/hello-world/node_modules/typescript/lib/lib.es2021.d.ts +23 -0
  184. package/examples/hello-world/node_modules/typescript/lib/lib.es2021.full.d.ts +24 -0
  185. package/examples/hello-world/node_modules/typescript/lib/lib.es2021.intl.d.ts +166 -0
  186. package/examples/hello-world/node_modules/typescript/lib/lib.es2021.promise.d.ts +48 -0
  187. package/examples/hello-world/node_modules/typescript/lib/lib.es2021.string.d.ts +33 -0
  188. package/examples/hello-world/node_modules/typescript/lib/lib.es2021.weakref.d.ts +78 -0
  189. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.array.d.ts +121 -0
  190. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.d.ts +25 -0
  191. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.error.d.ts +75 -0
  192. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.full.d.ts +24 -0
  193. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.intl.d.ts +145 -0
  194. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.object.d.ts +26 -0
  195. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.regexp.d.ts +39 -0
  196. package/examples/hello-world/node_modules/typescript/lib/lib.es2022.string.d.ts +25 -0
  197. package/examples/hello-world/node_modules/typescript/lib/lib.es2023.array.d.ts +924 -0
  198. package/examples/hello-world/node_modules/typescript/lib/lib.es2023.collection.d.ts +21 -0
  199. package/examples/hello-world/node_modules/typescript/lib/lib.es2023.d.ts +22 -0
  200. package/examples/hello-world/node_modules/typescript/lib/lib.es2023.full.d.ts +24 -0
  201. package/examples/hello-world/node_modules/typescript/lib/lib.es2023.intl.d.ts +56 -0
  202. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +65 -0
  203. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.collection.d.ts +29 -0
  204. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.d.ts +26 -0
  205. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.full.d.ts +24 -0
  206. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.object.d.ts +29 -0
  207. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.promise.d.ts +35 -0
  208. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.regexp.d.ts +25 -0
  209. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +68 -0
  210. package/examples/hello-world/node_modules/typescript/lib/lib.es2024.string.d.ts +29 -0
  211. package/examples/hello-world/node_modules/typescript/lib/lib.es5.d.ts +4601 -0
  212. package/examples/hello-world/node_modules/typescript/lib/lib.es6.d.ts +23 -0
  213. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.array.d.ts +35 -0
  214. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.collection.d.ts +96 -0
  215. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.d.ts +29 -0
  216. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.decorators.d.ts +28 -0
  217. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.disposable.d.ts +193 -0
  218. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.error.d.ts +24 -0
  219. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.float16.d.ts +445 -0
  220. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.full.d.ts +24 -0
  221. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.intl.d.ts +21 -0
  222. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.iterator.d.ts +148 -0
  223. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.promise.d.ts +34 -0
  224. package/examples/hello-world/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +25 -0
  225. package/examples/hello-world/node_modules/typescript/lib/lib.scripthost.d.ts +322 -0
  226. package/examples/hello-world/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +41 -0
  227. package/examples/hello-world/node_modules/typescript/lib/lib.webworker.d.ts +13150 -0
  228. package/examples/hello-world/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +23 -0
  229. package/examples/hello-world/node_modules/typescript/lib/lib.webworker.iterable.d.ts +340 -0
  230. package/examples/hello-world/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +2122 -0
  231. package/examples/hello-world/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +2122 -0
  232. package/examples/hello-world/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +2122 -0
  233. package/examples/hello-world/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +2122 -0
  234. package/examples/hello-world/node_modules/typescript/lib/tsc.js +8 -0
  235. package/examples/hello-world/node_modules/typescript/lib/tsserver.js +8 -0
  236. package/examples/hello-world/node_modules/typescript/lib/tsserverlibrary.d.ts +17 -0
  237. package/examples/hello-world/node_modules/typescript/lib/tsserverlibrary.js +21 -0
  238. package/examples/hello-world/node_modules/typescript/lib/typesMap.json +497 -0
  239. package/examples/hello-world/node_modules/typescript/lib/typescript.d.ts +11437 -0
  240. package/examples/hello-world/node_modules/typescript/lib/typescript.js +200276 -0
  241. package/examples/hello-world/node_modules/typescript/lib/typingsInstaller.js +8 -0
  242. package/examples/hello-world/node_modules/typescript/lib/watchGuard.js +53 -0
  243. package/examples/hello-world/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +2122 -0
  244. package/examples/hello-world/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +2122 -0
  245. package/examples/hello-world/node_modules/typescript/package.json +120 -0
  246. package/examples/hello-world/package-lock.json +74 -0
  247. package/examples/hello-world/package.json +23 -0
  248. package/examples/hello-world/src/client/index.tsx +110 -0
  249. package/examples/hello-world/src/server/index.ts +42 -0
  250. package/examples/hello-world/tsconfig.json +16 -0
  251. package/package.json +42 -0
  252. package/src/cli.ts +321 -0
@@ -0,0 +1,197 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ const API_BASE = '/api/articles';
4
+ /**
5
+ * 文章列表组件
6
+ */
7
+ function ArticleList() {
8
+ const [articles, setArticles] = React.useState([]);
9
+ const [loading, setLoading] = React.useState(true);
10
+ const [error, setError] = React.useState(null);
11
+ React.useEffect(() => {
12
+ loadArticles();
13
+ }, []);
14
+ const loadArticles = async () => {
15
+ try {
16
+ setLoading(true);
17
+ const response = await fetch(API_BASE);
18
+ const result = await response.json();
19
+ setArticles(result.data || result);
20
+ }
21
+ catch (err) {
22
+ setError(err.message || 'Failed to load articles');
23
+ }
24
+ finally {
25
+ setLoading(false);
26
+ }
27
+ };
28
+ if (loading)
29
+ return _jsx("div", { className: "text-center py-8", children: "\u52A0\u8F7D\u4E2D..." });
30
+ if (error)
31
+ return _jsxs("div", { className: "text-red-500 text-center py-8", children: ["\u9519\u8BEF: ", error] });
32
+ return (_jsxs("div", { className: "max-w-4xl mx-auto px-4 py-8", children: [_jsxs("div", { className: "flex justify-between items-center mb-8", children: [_jsx("h1", { className: "text-3xl font-bold text-gray-900", children: "\u6587\u7AE0\u5217\u8868" }), _jsx("button", { onClick: () => window.location.href = '/blog/new', className: "bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700", children: "\u5199\u6587\u7AE0" })] }), articles.length === 0 ? (_jsxs("div", { className: "text-center py-12", children: [_jsx("p", { className: "text-gray-500 mb-4", children: "\u6682\u65E0\u6587\u7AE0" }), _jsx("button", { onClick: () => window.location.href = '/blog/new', className: "text-blue-600 hover:underline", children: "\u5199\u7B2C\u4E00\u7BC7\u6587\u7AE0" })] })) : (_jsx("div", { className: "grid gap-6 md:grid-cols-2 lg:grid-cols-3", children: articles.map((article) => (_jsxs("div", { className: "bg-white rounded-lg shadow-md p-6 hover:shadow-lg transition-shadow", children: [_jsx("h2", { className: "text-xl font-semibold mb-2 text-gray-900", children: _jsx("a", { href: `/blog/${article.id}`, className: "hover:text-blue-600", children: article.title }) }), _jsxs("p", { className: "text-gray-600 mb-4 line-clamp-3", children: [article.content?.substring(0, 120), "..."] }), _jsxs("div", { className: "flex justify-between items-center text-sm text-gray-500", children: [_jsx("span", { className: "font-medium", children: article.author || '匿名' }), _jsx("span", { children: new Date(article.createdAt).toLocaleDateString() })] })] }, article.id))) }))] }));
33
+ }
34
+ /**
35
+ * 文章详情组件
36
+ */
37
+ function ArticleDetail() {
38
+ const [article, setArticle] = React.useState(null);
39
+ const [loading, setLoading] = React.useState(true);
40
+ const [error, setError] = React.useState(null);
41
+ // 获取URL参数
42
+ const urlParams = new URLSearchParams(window.location.search);
43
+ const id = urlParams.get('id');
44
+ React.useEffect(() => {
45
+ if (id) {
46
+ loadArticle(id);
47
+ }
48
+ }, [id]);
49
+ const loadArticle = async (articleId) => {
50
+ try {
51
+ setLoading(true);
52
+ const response = await fetch(`${API_BASE}/${articleId}`);
53
+ const result = await response.json();
54
+ setArticle(result);
55
+ }
56
+ catch (err) {
57
+ setError(err.message || 'Failed to load article');
58
+ }
59
+ finally {
60
+ setLoading(false);
61
+ }
62
+ };
63
+ if (loading)
64
+ return _jsx("div", { className: "text-center py-8", children: "\u52A0\u8F7D\u4E2D..." });
65
+ if (error)
66
+ return _jsxs("div", { className: "text-red-500 text-center py-8", children: ["\u9519\u8BEF: ", error] });
67
+ if (!article)
68
+ return _jsx("div", { className: "text-center py-8", children: "\u6587\u7AE0\u4E0D\u5B58\u5728" });
69
+ return (_jsxs("div", { className: "max-w-4xl mx-auto px-4 py-8", children: [_jsx("button", { onClick: () => window.history.back(), className: "mb-4 text-blue-600 hover:underline", children: "\u2190 \u8FD4\u56DE\u5217\u8868" }), _jsxs("article", { className: "bg-white rounded-lg shadow-md p-8", children: [_jsx("h1", { className: "text-4xl font-bold mb-4 text-gray-900", children: article.title }), _jsxs("div", { className: "flex justify-between items-center mb-8 pb-4 border-b", children: [_jsx("div", { className: "text-gray-600", children: _jsxs("span", { className: "font-medium", children: ["\u4F5C\u8005: ", article.author || '匿名'] }) }), _jsx("div", { className: "text-gray-500", children: _jsxs("span", { children: ["\u53D1\u5E03\u4E8E ", new Date(article.createdAt).toLocaleString()] }) })] }), _jsx("div", { className: "prose prose-lg max-w-none", children: _jsx("div", { dangerouslySetInnerHTML: { __html: formatContent(article.content) } }) }), article.updatedAt && article.updatedAt !== article.createdAt && (_jsx("div", { className: "mt-8 pt-4 border-t text-sm text-gray-500", children: _jsxs("span", { children: ["\u6700\u540E\u7F16\u8F91\u4E8E ", new Date(article.updatedAt).toLocaleString()] }) }))] })] }));
70
+ }
71
+ /**
72
+ * 文章编辑表单组件
73
+ */
74
+ function ArticleForm() {
75
+ const [title, setTitle] = React.useState('');
76
+ const [content, setContent] = React.useState('');
77
+ const [author, setAuthor] = React.useState('');
78
+ const [loading, setLoading] = React.useState(false);
79
+ const [error, setError] = React.useState(null);
80
+ // 检查是否为编辑模式
81
+ const urlParams = new URLSearchParams(window.location.search);
82
+ const editId = urlParams.get('edit');
83
+ const isEdit = Boolean(editId);
84
+ React.useEffect(() => {
85
+ if (isEdit && editId) {
86
+ loadArticleForEdit(editId);
87
+ }
88
+ }, [isEdit, editId]);
89
+ const loadArticleForEdit = async (articleId) => {
90
+ try {
91
+ const response = await fetch(`${API_BASE}/${articleId}`);
92
+ const article = await response.json();
93
+ setTitle(article.title || '');
94
+ setContent(article.content || '');
95
+ setAuthor(article.author || '');
96
+ }
97
+ catch (err) {
98
+ setError('加载文章失败: ' + err.message);
99
+ }
100
+ };
101
+ const handleSubmit = async (e) => {
102
+ e.preventDefault();
103
+ if (!title.trim() || !content.trim()) {
104
+ setError('标题和内容不能为空');
105
+ return;
106
+ }
107
+ setLoading(true);
108
+ setError(null);
109
+ try {
110
+ const method = isEdit ? 'PUT' : 'POST';
111
+ const url = isEdit ? `${API_BASE}/${editId}` : API_BASE;
112
+ const response = await fetch(url, {
113
+ method,
114
+ headers: { 'Content-Type': 'application/json' },
115
+ body: JSON.stringify({ title, content, author })
116
+ });
117
+ const result = await response.json();
118
+ if (result.success) {
119
+ // 重定向到文章列表
120
+ window.location.href = '/blog';
121
+ }
122
+ else {
123
+ throw new Error(result.data?.error || '保存失败');
124
+ }
125
+ }
126
+ catch (err) {
127
+ setError(err.message);
128
+ }
129
+ finally {
130
+ setLoading(false);
131
+ }
132
+ };
133
+ return (_jsxs("div", { className: "max-w-4xl mx-auto px-4 py-8", children: [_jsx("button", { onClick: () => window.history.back(), className: "mb-4 text-blue-600 hover:underline", children: "\u2190 \u8FD4\u56DE" }), _jsxs("div", { className: "bg-white rounded-lg shadow-md p-8", children: [_jsx("h1", { className: "text-3xl font-bold mb-8 text-gray-900", children: isEdit ? '编辑文章' : '写新文章' }), error && (_jsx("div", { className: "mb-4 p-3 bg-red-100 text-red-700 rounded", children: error })), _jsxs("form", { onSubmit: handleSubmit, className: "space-y-6", children: [_jsxs("div", { children: [_jsx("label", { className: "block text-sm font-medium text-gray-700 mb-2", children: "\u6807\u9898 *" }), _jsx("input", { type: "text", value: title, onChange: (e) => setTitle(e.target.value), className: "w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500", placeholder: "\u8F93\u5165\u6587\u7AE0\u6807\u9898", required: true })] }), _jsxs("div", { children: [_jsx("label", { className: "block text-sm font-medium text-gray-700 mb-2", children: "\u4F5C\u8005" }), _jsx("input", { type: "text", value: author, onChange: (e) => setAuthor(e.target.value), className: "w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500", placeholder: "\u4F5C\u8005\u59D3\u540D (\u53EF\u9009)" })] }), _jsxs("div", { children: [_jsx("label", { className: "block text-sm font-medium text-gray-700 mb-2", children: "\u5185\u5BB9 *" }), _jsx("textarea", { value: content, onChange: (e) => setContent(e.target.value), rows: 12, className: "w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500", placeholder: "\u5728\u8FD9\u91CC\u5199\u4E0B\u4F60\u7684\u6587\u7AE0\u5185\u5BB9...", required: true })] }), _jsxs("div", { className: "flex justify-end space-x-4", children: [_jsx("button", { type: "button", onClick: () => window.history.back(), className: "px-6 py-2 border border-gray-300 text-gray-700 rounded-md hover:bg-gray-50", children: "\u53D6\u6D88" }), _jsx("button", { type: "submit", disabled: loading, className: "px-6 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 disabled:opacity-50", children: loading ? '保存中...' : (isEdit ? '更新' : '发布') })] })] })] })] }));
134
+ }
135
+ /**
136
+ * 博客主页组件
137
+ */
138
+ function BlogHome() {
139
+ return (_jsxs("div", { className: "min-h-screen bg-gray-50", children: [_jsx("nav", { className: "bg-white shadow-sm", children: _jsx("div", { className: "max-w-4xl mx-auto px-4 py-4", children: _jsxs("div", { className: "flex justify-between items-center", children: [_jsx("h1", { className: "text-2xl font-bold text-gray-900", children: _jsx("a", { href: "/blog", className: "hover:text-blue-600", children: "\u6211\u7684\u535A\u5BA2" }) }), _jsxs("div", { className: "flex space-x-4", children: [_jsx("a", { href: "/blog", className: "text-gray-600 hover:text-blue-600", children: "\u6587\u7AE0\u5217\u8868" }), _jsx("a", { href: "/blog/new", className: "text-gray-600 hover:text-blue-600", children: "\u5199\u6587\u7AE0" })] })] }) }) }), _jsx("main", { children: _jsx("div", { id: "blog-content", children: window.location.search.includes('id=') ? (_jsx(ArticleDetail, {})) : window.location.pathname.includes('/new') || window.location.search.includes('edit=') ? (_jsx(ArticleForm, {})) : (_jsx(ArticleList, {})) }) })] }));
140
+ }
141
+ /**
142
+ * 简单的markdown格式化(支持基本的HTML标签)
143
+ */
144
+ function formatContent(content) {
145
+ return content
146
+ .replace(/\n/g, '<br>')
147
+ .replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
148
+ .replace(/\*(.*?)\*/g, '<em>$1</em>')
149
+ .replace(/`(.*?)`/g, '<code>$1</code>');
150
+ }
151
+ /**
152
+ * 客户端模块定义
153
+ */
154
+ export const blogClientModule = {
155
+ name: 'blogClient',
156
+ serviceDefs: [
157
+ {
158
+ serviceTag: 'blogRoute',
159
+ serviceImpl: class BlogRouteService {
160
+ constructor() {
161
+ this.basePath = '/blog';
162
+ }
163
+ getRoutes() {
164
+ return [
165
+ {
166
+ path: '/',
167
+ component: BlogHome,
168
+ key: 'blog-home',
169
+ meta: {
170
+ title: '博客首页 - linyjs示例',
171
+ description: '一个简单的博客示例,展示linyjs插件开发'
172
+ }
173
+ }
174
+ ];
175
+ }
176
+ },
177
+ meta: { usageType: 'route' }
178
+ },
179
+ {
180
+ serviceTag: 'blogComponent',
181
+ serviceImpl: class BlogComponentService {
182
+ // 注册全局组件
183
+ getComponents() {
184
+ return {
185
+ BlogHome,
186
+ ArticleList,
187
+ ArticleDetail,
188
+ ArticleForm
189
+ };
190
+ }
191
+ },
192
+ meta: { usageType: 'component' }
193
+ }
194
+ ]
195
+ };
196
+ // 导出组件方便其他模块使用
197
+ export { BlogHome, ArticleList, ArticleDetail, ArticleForm };
@@ -0,0 +1,5 @@
1
+ import type { IModule } from '@linyjs/server-module-interface';
2
+ /**
3
+ * 服务端模块定义
4
+ */
5
+ export declare const blogServerModule: IModule;
@@ -0,0 +1,220 @@
1
+ /**
2
+ * 文章服务 - 处理文章的业务逻辑
3
+ */
4
+ class ArticleService {
5
+ constructor() {
6
+ this.articles = [];
7
+ this.nextId = 1;
8
+ }
9
+ /**
10
+ * 获取所有文章(支持分页)
11
+ */
12
+ async getArticles(page = 1, limit = 10) {
13
+ const skip = (page - 1) * limit;
14
+ const total = this.articles.length;
15
+ const items = this.articles.slice(skip, skip + limit);
16
+ return {
17
+ data: items,
18
+ total,
19
+ page,
20
+ limit,
21
+ totalPages: Math.ceil(total / limit)
22
+ };
23
+ }
24
+ /**
25
+ * 根据ID获取文章
26
+ */
27
+ async getArticleById(id) {
28
+ const article = this.articles.find(a => a.id === id);
29
+ if (!article) {
30
+ throw new Error('Article not found');
31
+ }
32
+ return article;
33
+ }
34
+ /**
35
+ * 创建文章
36
+ */
37
+ async createArticle(data) {
38
+ const article = {
39
+ id: this.nextId++,
40
+ title: data.title,
41
+ content: data.content,
42
+ author: data.author || 'Anonymous',
43
+ createdAt: new Date().toISOString(),
44
+ updatedAt: new Date().toISOString()
45
+ };
46
+ this.articles.push(article);
47
+ return article;
48
+ }
49
+ /**
50
+ * 更新文章
51
+ */
52
+ async updateArticle(id, data) {
53
+ const index = this.articles.findIndex(a => a.id === id);
54
+ if (index === -1) {
55
+ throw new Error('Article not found');
56
+ }
57
+ this.articles[index] = {
58
+ ...this.articles[index],
59
+ ...data,
60
+ updatedAt: new Date().toISOString()
61
+ };
62
+ return this.articles[index];
63
+ }
64
+ /**
65
+ * 删除文章
66
+ */
67
+ async deleteArticle(id) {
68
+ const index = this.articles.findIndex(a => a.id === id);
69
+ if (index === -1) {
70
+ throw new Error('Article not found');
71
+ }
72
+ this.articles.splice(index, 1);
73
+ return { success: true };
74
+ }
75
+ }
76
+ /**
77
+ * 文章控制器 - 定义API路由
78
+ */
79
+ class ArticleController {
80
+ constructor() {
81
+ this.articleService = new ArticleService();
82
+ }
83
+ getRoutes() {
84
+ return [
85
+ // GET /api/articles - 获取文章列表
86
+ {
87
+ method: 'GET',
88
+ path: '/api/articles',
89
+ middlewares: [],
90
+ responseType: 'json',
91
+ handler: async (params, ctx) => {
92
+ const page = parseInt(params.query?.page || '1');
93
+ const limit = parseInt(params.query?.limit || '10');
94
+ try {
95
+ const result = await this.articleService.getArticles(page, limit);
96
+ return result;
97
+ }
98
+ catch (error) {
99
+ return {
100
+ status: 500,
101
+ data: { error: error.message }
102
+ };
103
+ }
104
+ }
105
+ },
106
+ // GET /api/articles/:id - 获取单篇文章
107
+ {
108
+ method: 'GET',
109
+ path: '/api/articles/:id',
110
+ middlewares: [],
111
+ responseType: 'json',
112
+ handler: async (params, ctx) => {
113
+ try {
114
+ const id = parseInt(params.id);
115
+ const article = await this.articleService.getArticleById(id);
116
+ return article;
117
+ }
118
+ catch (error) {
119
+ return {
120
+ status: 404,
121
+ data: { error: error.message }
122
+ };
123
+ }
124
+ }
125
+ },
126
+ // POST /api/articles - 创建文章
127
+ {
128
+ method: 'POST',
129
+ path: '/api/articles',
130
+ middlewares: [],
131
+ responseType: 'json',
132
+ handler: async (params, ctx) => {
133
+ try {
134
+ const { title, content, author } = params.body;
135
+ if (!title || !content) {
136
+ return {
137
+ status: 400,
138
+ data: { error: 'Title and content are required' }
139
+ };
140
+ }
141
+ const article = await this.articleService.createArticle({
142
+ title,
143
+ content,
144
+ author
145
+ });
146
+ return {
147
+ success: true,
148
+ data: article
149
+ };
150
+ }
151
+ catch (error) {
152
+ return {
153
+ status: 500,
154
+ data: { error: error.message }
155
+ };
156
+ }
157
+ }
158
+ },
159
+ // PUT /api/articles/:id - 更新文章
160
+ {
161
+ method: 'PUT',
162
+ path: '/api/articles/:id',
163
+ middlewares: [],
164
+ responseType: 'json',
165
+ handler: async (params, ctx) => {
166
+ try {
167
+ const id = parseInt(params.id);
168
+ const article = await this.articleService.updateArticle(id, params.body);
169
+ return {
170
+ success: true,
171
+ data: article
172
+ };
173
+ }
174
+ catch (error) {
175
+ return {
176
+ status: 404,
177
+ data: { error: error.message }
178
+ };
179
+ }
180
+ }
181
+ },
182
+ // DELETE /api/articles/:id - 删除文章
183
+ {
184
+ method: 'DELETE',
185
+ path: '/api/articles/:id',
186
+ middlewares: [],
187
+ responseType: 'json',
188
+ handler: async (params, ctx) => {
189
+ try {
190
+ const id = parseInt(params.id);
191
+ await this.articleService.deleteArticle(id);
192
+ return {
193
+ success: true,
194
+ message: 'Article deleted successfully'
195
+ };
196
+ }
197
+ catch (error) {
198
+ return {
199
+ status: 404,
200
+ data: { error: error.message }
201
+ };
202
+ }
203
+ }
204
+ }
205
+ ];
206
+ }
207
+ }
208
+ /**
209
+ * 服务端模块定义
210
+ */
211
+ export const blogServerModule = {
212
+ name: 'blogServer',
213
+ serviceDefs: [
214
+ {
215
+ serviceTag: 'articleController',
216
+ serviceImpl: ArticleController,
217
+ meta: { usageType: 'controller' }
218
+ }
219
+ ]
220
+ };
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@linyjs/example-blog-plugin",
3
+ "version": "1.0.0",
4
+ "description": "Blog plugin example with CRUD operations for linyjs framework",
5
+ "type": "module",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "dev": "tsc --watch",
9
+ "pack": "npx @linyjs/cli pack"
10
+ },
11
+ "dependencies": {
12
+ "@linyjs/server-module-interface": "^0.0.1",
13
+ "@linyjs/client-module-interface": "^0.0.1",
14
+ "@linyjs/mongodb": "^0.0.1",
15
+ "react": "^19.0.0"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "^5.7.0",
19
+ "@types/react": "^19.0.0"
20
+ },
21
+ "linyjs": {
22
+ "compatibleVersions": ">=0.0.1 <1.0.0"
23
+ }
24
+ }