polen 0.10.0 → 0.11.0-next.2

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 (332) hide show
  1. package/build/api/api.d.ts +1 -0
  2. package/build/api/api.d.ts.map +1 -1
  3. package/build/api/api.js +1 -0
  4. package/build/api/api.js.map +1 -1
  5. package/build/api/config/configurator.d.ts +20 -22
  6. package/build/api/config/configurator.d.ts.map +1 -1
  7. package/build/api/config/configurator.js +27 -9
  8. package/build/api/config/configurator.js.map +1 -1
  9. package/build/api/config/merge.d.ts.map +1 -1
  10. package/build/api/config/merge.js +0 -11
  11. package/build/api/config/merge.js.map +1 -1
  12. package/build/api/content/metadata.d.ts +8 -2
  13. package/build/api/content/metadata.d.ts.map +1 -1
  14. package/build/api/content/metadata.js +1 -1
  15. package/build/api/content/metadata.js.map +1 -1
  16. package/build/api/schema/data-sources/memory/memory.d.ts +2 -2
  17. package/build/api/schema/data-sources/memory/memory.d.ts.map +1 -1
  18. package/build/api/schema/data-sources/memory/memory.js +1 -3
  19. package/build/api/schema/data-sources/memory/memory.js.map +1 -1
  20. package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.d.ts +7 -3
  21. package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.d.ts.map +1 -1
  22. package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.js +15 -11
  23. package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.js.map +1 -1
  24. package/build/api/schema/data-sources/schema-directory/schema-directory.d.ts +16 -7
  25. package/build/api/schema/data-sources/schema-directory/schema-directory.d.ts.map +1 -1
  26. package/build/api/schema/data-sources/schema-directory/schema-directory.js +26 -7
  27. package/build/api/schema/data-sources/schema-directory/schema-directory.js.map +1 -1
  28. package/build/api/schema/data-sources/schema-file/schema-file.d.ts +7 -2
  29. package/build/api/schema/data-sources/schema-file/schema-file.d.ts.map +1 -1
  30. package/build/api/schema/data-sources/schema-file/schema-file.js +13 -5
  31. package/build/api/schema/data-sources/schema-file/schema-file.js.map +1 -1
  32. package/build/api/schema/metadata.d.ts +16 -0
  33. package/build/api/schema/metadata.d.ts.map +1 -0
  34. package/build/api/schema/metadata.js +19 -0
  35. package/build/api/schema/metadata.js.map +1 -0
  36. package/build/api/schema/read.d.ts +3 -3
  37. package/build/api/schema/read.d.ts.map +1 -1
  38. package/build/api/schema/read.js.map +1 -1
  39. package/build/api/schema/schema.d.ts +33 -2
  40. package/build/api/schema/schema.d.ts.map +1 -1
  41. package/build/api/schema/schema.js +42 -0
  42. package/build/api/schema/schema.js.map +1 -1
  43. package/build/api/schema-source/index.d.ts +2 -0
  44. package/build/api/schema-source/index.d.ts.map +1 -0
  45. package/build/api/schema-source/index.js +2 -0
  46. package/build/api/schema-source/index.js.map +1 -0
  47. package/build/api/schema-source/schema-source.d.ts +33 -0
  48. package/build/api/schema-source/schema-source.d.ts.map +1 -0
  49. package/build/api/schema-source/schema-source.js +137 -0
  50. package/build/api/schema-source/schema-source.js.map +1 -0
  51. package/build/api/static/manifest.d.ts +1 -2
  52. package/build/api/static/manifest.d.ts.map +1 -1
  53. package/build/api/static/manifest.js +1 -1
  54. package/build/api/static/manifest.js.map +1 -1
  55. package/build/api/vite/plugins/core.d.ts +1 -0
  56. package/build/api/vite/plugins/core.d.ts.map +1 -1
  57. package/build/api/vite/plugins/core.js +21 -18
  58. package/build/api/vite/plugins/core.js.map +1 -1
  59. package/build/api/vite/plugins/main.d.ts.map +1 -1
  60. package/build/api/vite/plugins/main.js +1 -8
  61. package/build/api/vite/plugins/main.js.map +1 -1
  62. package/build/api/vite/plugins/schema-assets.d.ts +22 -0
  63. package/build/api/vite/plugins/schema-assets.d.ts.map +1 -0
  64. package/build/api/vite/plugins/schema-assets.js +269 -0
  65. package/build/api/vite/plugins/schema-assets.js.map +1 -0
  66. package/build/api/vite/plugins/serve.d.ts.map +1 -1
  67. package/build/api/vite/plugins/serve.js +11 -0
  68. package/build/api/vite/plugins/serve.js.map +1 -1
  69. package/build/lib/graphql-change/change-groups.d.ts +2 -0
  70. package/build/lib/graphql-change/change-groups.d.ts.map +1 -1
  71. package/build/lib/graphql-change/change-groups.js +54 -0
  72. package/build/lib/graphql-change/change-groups.js.map +1 -1
  73. package/build/lib/kit-temp.d.ts +9 -0
  74. package/build/lib/kit-temp.d.ts.map +1 -1
  75. package/build/lib/kit-temp.js +12 -0
  76. package/build/lib/kit-temp.js.map +1 -1
  77. package/build/lib/path-map/path-map.d.ts.map +1 -1
  78. package/build/lib/path-map/path-map.js +3 -1
  79. package/build/lib/path-map/path-map.js.map +1 -1
  80. package/build/project-data.d.ts +3 -11
  81. package/build/project-data.d.ts.map +1 -1
  82. package/build/template/components/Changelog.d.ts +3 -3
  83. package/build/template/components/Changelog.d.ts.map +1 -1
  84. package/build/template/components/Changelog.js +8 -84
  85. package/build/template/components/Changelog.js.map +1 -1
  86. package/build/template/components/CodeBlock.d.ts +2 -0
  87. package/build/template/components/CodeBlock.d.ts.map +1 -1
  88. package/build/template/components/CodeBlock.js +1 -4
  89. package/build/template/components/CodeBlock.js.map +1 -1
  90. package/build/template/components/ComponentDispatch.d.ts +34 -0
  91. package/build/template/components/ComponentDispatch.d.ts.map +1 -0
  92. package/build/template/components/ComponentDispatch.js +33 -0
  93. package/build/template/components/ComponentDispatch.js.map +1 -0
  94. package/build/template/components/ReferenceLink.d.ts +19 -0
  95. package/build/template/components/ReferenceLink.d.ts.map +1 -0
  96. package/build/template/components/ReferenceLink.js +19 -0
  97. package/build/template/components/ReferenceLink.js.map +1 -0
  98. package/build/template/components/TypeAnnotation.d.ts.map +1 -1
  99. package/build/template/components/TypeAnnotation.js +3 -3
  100. package/build/template/components/TypeAnnotation.js.map +1 -1
  101. package/build/template/components/TypeFieldsLinkList.d.ts.map +1 -1
  102. package/build/template/components/TypeFieldsLinkList.js +4 -4
  103. package/build/template/components/TypeFieldsLinkList.js.map +1 -1
  104. package/build/template/components/TypeIndex.js +2 -2
  105. package/build/template/components/TypeIndex.js.map +1 -1
  106. package/build/template/components/VersionSelector.d.ts +7 -0
  107. package/build/template/components/VersionSelector.d.ts.map +1 -0
  108. package/build/template/components/VersionSelector.js +30 -0
  109. package/build/template/components/VersionSelector.js.map +1 -0
  110. package/build/template/components/graphql/type-link.d.ts.map +1 -1
  111. package/build/template/components/graphql/type-link.js +2 -2
  112. package/build/template/components/graphql/type-link.js.map +1 -1
  113. package/build/template/hooks/useVersionPath.d.ts +6 -0
  114. package/build/template/hooks/useVersionPath.d.ts.map +1 -0
  115. package/build/template/hooks/useVersionPath.js +10 -0
  116. package/build/template/hooks/useVersionPath.js.map +1 -0
  117. package/build/template/layouts/ChangelogLayout.d.ts.map +1 -0
  118. package/build/template/{components → layouts}/ChangelogLayout.js +1 -1
  119. package/build/template/layouts/ChangelogLayout.js.map +1 -0
  120. package/build/template/layouts/index.d.ts +1 -0
  121. package/build/template/layouts/index.d.ts.map +1 -1
  122. package/build/template/layouts/index.js +1 -0
  123. package/build/template/layouts/index.js.map +1 -1
  124. package/build/template/lib/fetch-text.d.ts +8 -0
  125. package/build/template/lib/fetch-text.d.ts.map +1 -0
  126. package/build/template/lib/fetch-text.js +14 -0
  127. package/build/template/lib/fetch-text.js.map +1 -0
  128. package/build/template/lib/polen-url.d.ts +14 -0
  129. package/build/template/lib/polen-url.d.ts.map +1 -1
  130. package/build/template/lib/polen-url.js +16 -0
  131. package/build/template/lib/polen-url.js.map +1 -1
  132. package/build/template/lib/schema-utils/constants.d.ts +5 -0
  133. package/build/template/lib/schema-utils/constants.d.ts.map +1 -0
  134. package/build/template/lib/schema-utils/constants.js +5 -0
  135. package/build/template/lib/schema-utils/constants.js.map +1 -0
  136. package/build/template/lib/schema-utils/schema-utils.d.ts +15 -0
  137. package/build/template/lib/schema-utils/schema-utils.d.ts.map +1 -0
  138. package/build/template/lib/schema-utils/schema-utils.js +37 -0
  139. package/build/template/lib/schema-utils/schema-utils.js.map +1 -0
  140. package/build/template/routes/changelog.d.ts +4 -3
  141. package/build/template/routes/changelog.d.ts.map +1 -1
  142. package/build/template/routes/changelog.js +13 -7
  143. package/build/template/routes/changelog.js.map +1 -1
  144. package/build/template/routes/pages.d.ts +10 -0
  145. package/build/template/routes/pages.d.ts.map +1 -0
  146. package/build/template/routes/pages.js +76 -0
  147. package/build/template/routes/pages.js.map +1 -0
  148. package/build/template/routes/reference.$type.$field.js +1 -1
  149. package/build/template/routes/reference.$type.$field.js.map +1 -1
  150. package/build/template/routes/reference.$type.d.ts +4 -0
  151. package/build/template/routes/reference.$type.d.ts.map +1 -1
  152. package/build/template/routes/reference.$type.js +2 -0
  153. package/build/template/routes/reference.$type.js.map +1 -1
  154. package/build/template/routes/reference.d.ts +9 -3
  155. package/build/template/routes/reference.d.ts.map +1 -1
  156. package/build/template/routes/reference.js +30 -8
  157. package/build/template/routes/reference.js.map +1 -1
  158. package/build/template/routes/reference.version.$version.$type.$field.d.ts +6 -0
  159. package/build/template/routes/reference.version.$version.$type.$field.d.ts.map +1 -0
  160. package/build/template/routes/reference.version.$version.$type.$field.js +32 -0
  161. package/build/template/routes/reference.version.$version.$type.$field.js.map +1 -0
  162. package/build/template/routes/reference.version.$version.$type.d.ts +11 -0
  163. package/build/template/routes/reference.version.$version.$type.d.ts.map +1 -0
  164. package/build/template/routes/reference.version.$version.$type.js +26 -0
  165. package/build/template/routes/reference.version.$version.$type.js.map +1 -0
  166. package/build/template/routes/root.d.ts.map +1 -1
  167. package/build/template/routes/root.js +8 -72
  168. package/build/template/routes/root.js.map +1 -1
  169. package/build/template/server/app.d.ts +22 -1
  170. package/build/template/server/app.d.ts.map +1 -1
  171. package/build/template/server/app.js +19 -9
  172. package/build/template/server/app.js.map +1 -1
  173. package/build/template/server/main.js +9 -1
  174. package/build/template/server/main.js.map +1 -1
  175. package/build/template/server/ssg/generate.js +2 -2
  176. package/build/template/server/ssg/generate.js.map +1 -1
  177. package/build/template/server/ssg/get-route-paths.d.ts +1 -1
  178. package/build/template/server/ssg/get-route-paths.d.ts.map +1 -1
  179. package/build/template/server/ssg/get-route-paths.js +51 -27
  180. package/build/template/server/ssg/get-route-paths.js.map +1 -1
  181. package/build/template/sources/schema-source.d.ts +15 -0
  182. package/build/template/sources/schema-source.d.ts.map +1 -0
  183. package/build/template/sources/schema-source.js +63 -0
  184. package/build/template/sources/schema-source.js.map +1 -0
  185. package/package.json +16 -17
  186. package/src/api/api.ts +1 -0
  187. package/src/api/config/configurator.ts +51 -32
  188. package/src/api/config/merge.ts +0 -16
  189. package/src/api/content/metadata.ts +1 -1
  190. package/src/api/schema/data-sources/memory/memory.ts +3 -5
  191. package/src/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.ts +29 -13
  192. package/src/api/schema/data-sources/schema-directory/schema-directory.ts +56 -16
  193. package/src/api/schema/data-sources/schema-file/schema-file.ts +16 -7
  194. package/src/api/schema/metadata.ts +23 -0
  195. package/src/api/schema/read.ts +3 -3
  196. package/src/api/schema/schema.ts +62 -2
  197. package/src/api/schema-source/index.ts +1 -0
  198. package/src/api/schema-source/schema-source.ts +189 -0
  199. package/src/api/static/manifest.ts +1 -1
  200. package/src/api/vite/plugins/core.ts +23 -18
  201. package/src/api/vite/plugins/main.ts +1 -9
  202. package/src/api/vite/plugins/schema-assets.ts +317 -0
  203. package/src/api/vite/plugins/serve.ts +15 -8
  204. package/src/lib/graphql-change/change-groups.ts +57 -0
  205. package/src/lib/kit-temp.ts +13 -0
  206. package/src/lib/path-map/$.test.ts +22 -19
  207. package/src/lib/path-map/path-map.ts +3 -1
  208. package/src/project-data.ts +3 -11
  209. package/src/template/components/Changelog.tsx +16 -67
  210. package/src/template/components/CodeBlock.tsx +3 -5
  211. package/src/template/components/ComponentDispatch.tsx +42 -0
  212. package/src/template/components/ReferenceLink.tsx +34 -0
  213. package/src/template/components/TypeAnnotation.tsx +5 -7
  214. package/src/template/components/TypeFieldsLinkList.tsx +20 -23
  215. package/src/template/components/TypeIndex.tsx +10 -12
  216. package/src/template/components/VersionSelector.tsx +50 -0
  217. package/src/template/components/graphql/type-link.tsx +4 -3
  218. package/src/template/hooks/useVersionPath.ts +10 -0
  219. package/src/template/{components → layouts}/ChangelogLayout.tsx +1 -1
  220. package/src/template/layouts/index.ts +1 -0
  221. package/src/template/lib/fetch-text.ts +13 -0
  222. package/src/template/lib/polen-url.ts +20 -0
  223. package/src/template/lib/schema-utils/constants.ts +4 -0
  224. package/src/template/lib/schema-utils/schema-utils.ts +42 -0
  225. package/src/template/routes/changelog.tsx +17 -8
  226. package/src/template/routes/pages.tsx +109 -0
  227. package/src/template/routes/reference.$type.$field.tsx +1 -1
  228. package/src/template/routes/reference.$type.tsx +2 -0
  229. package/src/template/routes/reference.tsx +38 -6
  230. package/src/template/routes/reference.version.$version.$type.$field.tsx +35 -0
  231. package/src/template/routes/reference.version.$version.$type.tsx +30 -0
  232. package/src/template/routes/root.tsx +8 -109
  233. package/src/template/server/app.ts +47 -14
  234. package/src/template/server/main.ts +9 -1
  235. package/src/template/server/ssg/generate.ts +2 -2
  236. package/src/template/server/ssg/get-route-paths.ts +53 -27
  237. package/src/template/sources/schema-source.ts +68 -0
  238. package/build/lib/graphql-document/$$.d.ts +0 -5
  239. package/build/lib/graphql-document/$$.d.ts.map +0 -1
  240. package/build/lib/graphql-document/$$.js +0 -5
  241. package/build/lib/graphql-document/$$.js.map +0 -1
  242. package/build/lib/graphql-document/$.d.ts +0 -2
  243. package/build/lib/graphql-document/$.d.ts.map +0 -1
  244. package/build/lib/graphql-document/$.js +0 -2
  245. package/build/lib/graphql-document/$.js.map +0 -1
  246. package/build/lib/graphql-document/analysis.d.ts +0 -44
  247. package/build/lib/graphql-document/analysis.d.ts.map +0 -1
  248. package/build/lib/graphql-document/analysis.js +0 -361
  249. package/build/lib/graphql-document/analysis.js.map +0 -1
  250. package/build/lib/graphql-document/components/GraphQLDocument.d.ts +0 -38
  251. package/build/lib/graphql-document/components/GraphQLDocument.d.ts.map +0 -1
  252. package/build/lib/graphql-document/components/GraphQLDocument.js +0 -151
  253. package/build/lib/graphql-document/components/GraphQLDocument.js.map +0 -1
  254. package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.d.ts +0 -7
  255. package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.d.ts.map +0 -1
  256. package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.js +0 -27
  257. package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.js.map +0 -1
  258. package/build/lib/graphql-document/components/GraphQLIdentifierPopover.d.ts +0 -33
  259. package/build/lib/graphql-document/components/GraphQLIdentifierPopover.d.ts.map +0 -1
  260. package/build/lib/graphql-document/components/GraphQLIdentifierPopover.js +0 -50
  261. package/build/lib/graphql-document/components/GraphQLIdentifierPopover.js.map +0 -1
  262. package/build/lib/graphql-document/components/IdentifierLink.d.ts +0 -39
  263. package/build/lib/graphql-document/components/IdentifierLink.d.ts.map +0 -1
  264. package/build/lib/graphql-document/components/IdentifierLink.js +0 -75
  265. package/build/lib/graphql-document/components/IdentifierLink.js.map +0 -1
  266. package/build/lib/graphql-document/components/graphql-document-styles.d.ts +0 -5
  267. package/build/lib/graphql-document/components/graphql-document-styles.d.ts.map +0 -1
  268. package/build/lib/graphql-document/components/graphql-document-styles.js +0 -144
  269. package/build/lib/graphql-document/components/graphql-document-styles.js.map +0 -1
  270. package/build/lib/graphql-document/components/index.d.ts +0 -5
  271. package/build/lib/graphql-document/components/index.d.ts.map +0 -1
  272. package/build/lib/graphql-document/components/index.js +0 -5
  273. package/build/lib/graphql-document/components/index.js.map +0 -1
  274. package/build/lib/graphql-document/example.d.ts +0 -25
  275. package/build/lib/graphql-document/example.d.ts.map +0 -1
  276. package/build/lib/graphql-document/example.js +0 -140
  277. package/build/lib/graphql-document/example.js.map +0 -1
  278. package/build/lib/graphql-document/graphql-document.d.ts +0 -35
  279. package/build/lib/graphql-document/graphql-document.d.ts.map +0 -1
  280. package/build/lib/graphql-document/graphql-document.js +0 -36
  281. package/build/lib/graphql-document/graphql-document.js.map +0 -1
  282. package/build/lib/graphql-document/hooks/use-tooltip-state.d.ts +0 -43
  283. package/build/lib/graphql-document/hooks/use-tooltip-state.d.ts.map +0 -1
  284. package/build/lib/graphql-document/hooks/use-tooltip-state.js +0 -132
  285. package/build/lib/graphql-document/hooks/use-tooltip-state.js.map +0 -1
  286. package/build/lib/graphql-document/positioning-simple.d.ts +0 -63
  287. package/build/lib/graphql-document/positioning-simple.d.ts.map +0 -1
  288. package/build/lib/graphql-document/positioning-simple.js +0 -185
  289. package/build/lib/graphql-document/positioning-simple.js.map +0 -1
  290. package/build/lib/graphql-document/schema-context.d.ts +0 -8
  291. package/build/lib/graphql-document/schema-context.d.ts.map +0 -1
  292. package/build/lib/graphql-document/schema-context.js +0 -11
  293. package/build/lib/graphql-document/schema-context.js.map +0 -1
  294. package/build/lib/graphql-document/schema-integration.d.ts +0 -135
  295. package/build/lib/graphql-document/schema-integration.d.ts.map +0 -1
  296. package/build/lib/graphql-document/schema-integration.js +0 -328
  297. package/build/lib/graphql-document/schema-integration.js.map +0 -1
  298. package/build/lib/graphql-document/types.d.ts +0 -117
  299. package/build/lib/graphql-document/types.d.ts.map +0 -1
  300. package/build/lib/graphql-document/types.js +0 -2
  301. package/build/lib/graphql-document/types.js.map +0 -1
  302. package/build/template/components/ChangelogLayout.d.ts.map +0 -1
  303. package/build/template/components/ChangelogLayout.js.map +0 -1
  304. package/build/template/components/CodeHikePre.d.ts +0 -16
  305. package/build/template/components/CodeHikePre.d.ts.map +0 -1
  306. package/build/template/components/CodeHikePre.js +0 -37
  307. package/build/template/components/CodeHikePre.js.map +0 -1
  308. package/src/lib/graphql-document/$$.ts +0 -4
  309. package/src/lib/graphql-document/$.test.ts +0 -132
  310. package/src/lib/graphql-document/$.ts +0 -1
  311. package/src/lib/graphql-document/README.md +0 -102
  312. package/src/lib/graphql-document/analysis.ts +0 -415
  313. package/src/lib/graphql-document/components/GraphQLDocument.tsx +0 -265
  314. package/src/lib/graphql-document/components/GraphQLDocument.unit.test.ts +0 -188
  315. package/src/lib/graphql-document/components/GraphQLDocumentWithSchema.tsx +0 -46
  316. package/src/lib/graphql-document/components/GraphQLIdentifierPopover.tsx +0 -199
  317. package/src/lib/graphql-document/components/IdentifierLink.tsx +0 -160
  318. package/src/lib/graphql-document/components/graphql-document-styles.ts +0 -144
  319. package/src/lib/graphql-document/components/index.ts +0 -4
  320. package/src/lib/graphql-document/demo.md +0 -155
  321. package/src/lib/graphql-document/example.ts +0 -163
  322. package/src/lib/graphql-document/graphql-document.ts +0 -37
  323. package/src/lib/graphql-document/hooks/use-tooltip-state.test.ts +0 -76
  324. package/src/lib/graphql-document/hooks/use-tooltip-state.ts +0 -191
  325. package/src/lib/graphql-document/positioning-simple.test.ts +0 -248
  326. package/src/lib/graphql-document/positioning-simple.ts +0 -260
  327. package/src/lib/graphql-document/schema-context.tsx +0 -20
  328. package/src/lib/graphql-document/schema-integration.test.ts +0 -365
  329. package/src/lib/graphql-document/schema-integration.ts +0 -488
  330. package/src/lib/graphql-document/types.ts +0 -129
  331. package/src/template/components/CodeHikePre.tsx +0 -51
  332. /package/build/template/{components → layouts}/ChangelogLayout.d.ts +0 -0
@@ -1,265 +0,0 @@
1
- import type { React } from '#dep/react/index'
2
- import { React as ReactHooks } from '#dep/react/index'
3
- import type { GraphQLSchema } from 'graphql'
4
- import { useNavigate } from 'react-router'
5
- import { analyze } from '../analysis.js'
6
- import { useTooltipState } from '../hooks/use-tooltip-state.js'
7
- import { createSimplePositionCalculator } from '../positioning-simple.js'
8
- import { createPolenSchemaResolver } from '../schema-integration.js'
9
- import type { Identifier } from '../types.js'
10
- import { graphqlDocumentStyles } from './graphql-document-styles.js'
11
- import { IdentifierLink } from './IdentifierLink.js'
12
-
13
- /**
14
- * Options for the GraphQL document component
15
- */
16
- export interface GraphQLDocumentOptions {
17
- /** Whether to show debug overlays */
18
- debug?: boolean
19
- /** Whether to disable interactive features */
20
- plain?: boolean
21
- /** Custom navigation handler */
22
- onNavigate?: (url: string) => void
23
- /** Whether to validate against schema */
24
- validate?: boolean
25
- /** Custom class name for the container */
26
- className?: string
27
- /** Custom render function for the code block */
28
- renderCode?: () => React.ReactNode
29
- }
30
-
31
- /**
32
- * Props for the GraphQL document component
33
- */
34
- export interface GraphQLDocumentProps {
35
- /** The GraphQL document source code */
36
- children: string
37
- /** GraphQL schema for validation and linking */
38
- schema?: GraphQLSchema
39
- /** Component options */
40
- options?: GraphQLDocumentOptions
41
- }
42
-
43
- /**
44
- * Interactive GraphQL document component
45
- *
46
- * Transforms static GraphQL code blocks into interactive documentation
47
- * with hyperlinks, tooltips, and schema validation.
48
- */
49
- export const GraphQLDocument: React.FC<GraphQLDocumentProps> = ({
50
- children,
51
- schema,
52
- options = {},
53
- }) => {
54
- const {
55
- debug = false,
56
- plain = false,
57
- onNavigate,
58
- validate = true,
59
- className = ``,
60
- renderCode,
61
- } = options
62
-
63
- const navigate = useNavigate()
64
- const handleNavigate = onNavigate || ((url: string) => navigate(url))
65
-
66
- // Container ref for positioning calculations
67
- const containerRef = ReactHooks.useRef<HTMLDivElement>(null)
68
- const [isReady, setIsReady] = ReactHooks.useState(false)
69
-
70
- // Use tooltip state management
71
- const tooltipState = useTooltipState({
72
- showDelay: 300,
73
- hideDelay: 200, // Increased for smoother experience
74
- allowMultiplePins: true,
75
- })
76
-
77
- // Handle escape key to unpin all
78
- ReactHooks.useEffect(() => {
79
- const handleKeyDown = (event: KeyboardEvent) => {
80
- if (event.key === `Escape`) {
81
- tooltipState.unpinAll()
82
- }
83
- }
84
-
85
- document.addEventListener(`keydown`, handleKeyDown)
86
- return () => {
87
- document.removeEventListener(`keydown`, handleKeyDown)
88
- }
89
- }, [tooltipState])
90
-
91
- // Layer 1: Parse and analyze
92
- const analysisResult = ReactHooks.useMemo(() => {
93
- if (plain) return null
94
- const result = analyze(children, { schema })
95
- // Debug logging handled by debug prop
96
- return result
97
- }, [children, plain, schema, debug])
98
-
99
- // Layer 2: Schema resolution
100
- const resolver = ReactHooks.useMemo(() => {
101
- if (!schema || plain) return null
102
- return createPolenSchemaResolver(schema)
103
- }, [schema, plain])
104
-
105
- const resolutions = ReactHooks.useMemo(() => {
106
- if (!analysisResult || !resolver) {
107
- return new Map()
108
- }
109
-
110
- const results = new Map()
111
- for (const [position, identifier] of analysisResult.identifiers.byPosition) {
112
- const resolution = resolver.resolveIdentifier(identifier)
113
- if (resolution) {
114
- results.set(position, resolution)
115
- }
116
- }
117
- return results
118
- }, [analysisResult, resolver])
119
-
120
- // Layer 3: Position calculation
121
- const positionCalculator = ReactHooks.useMemo(() => {
122
- if (plain) return null
123
- return createSimplePositionCalculator()
124
- }, [plain])
125
-
126
- const [positions, setPositions] = ReactHooks.useState<Map<string, { position: any; identifier: Identifier }>>(
127
- new Map(),
128
- )
129
-
130
- // Prepare code block and calculate positions after render
131
- ReactHooks.useEffect(() => {
132
- if (!containerRef.current || !analysisResult || !positionCalculator || plain) {
133
- // Skip position calculation - debug handled by debug prop
134
- return
135
- }
136
-
137
- // Get the code element within the container
138
- const codeElement = containerRef.current.querySelector(`pre.code-block code`)
139
- || containerRef.current.querySelector(`pre code`)
140
- || containerRef.current.querySelector(`code`)
141
- if (!codeElement) {
142
- // No code element found - skip
143
- return
144
- }
145
-
146
- // Prepare the code block (wrap identifiers)
147
- const identifiers = Array.from(analysisResult.identifiers.byPosition.values())
148
- // Prepare code block with identifiers
149
- positionCalculator.prepareCodeBlock(codeElement, identifiers)
150
-
151
- // Get positions after DOM update
152
- requestAnimationFrame(() => {
153
- // Pass containerRef.current as the reference element for positioning
154
- if (containerRef.current) {
155
- const newPositions = positionCalculator.getIdentifierPositions(codeElement, containerRef.current)
156
- // Position calculation complete
157
- setPositions(newPositions)
158
- setIsReady(true)
159
- }
160
- })
161
- }, [analysisResult, positionCalculator, plain])
162
-
163
- // Handle resize events with debouncing
164
- ReactHooks.useEffect(() => {
165
- if (!containerRef.current || !positionCalculator || plain) return
166
-
167
- let resizeTimer: NodeJS.Timeout
168
- const handleResize = () => {
169
- clearTimeout(resizeTimer)
170
- resizeTimer = setTimeout(() => {
171
- const codeElement = containerRef.current?.querySelector(`pre.code-block code`)
172
- || containerRef.current?.querySelector(`pre code`)
173
- || containerRef.current?.querySelector(`code`)
174
- if (codeElement && containerRef.current) {
175
- const newPositions = positionCalculator.getIdentifierPositions(codeElement, containerRef.current)
176
- setPositions(newPositions)
177
- }
178
- }, 100) // Debounce resize events
179
- }
180
-
181
- window.addEventListener(`resize`, handleResize)
182
- return () => {
183
- clearTimeout(resizeTimer)
184
- window.removeEventListener(`resize`, handleResize)
185
- }
186
- }, [positionCalculator, plain])
187
-
188
- // Validation errors
189
- const validationErrors = ReactHooks.useMemo(() => {
190
- if (!validate || !analysisResult || !schema) return []
191
- return analysisResult.errors
192
- }, [validate, analysisResult, schema])
193
-
194
- return (
195
- <>
196
- <style dangerouslySetInnerHTML={{ __html: graphqlDocumentStyles }} />
197
- <div
198
- ref={containerRef}
199
- className={`graphql-document ${className} ${debug ? `graphql-debug-mode` : ``} ${
200
- !isReady && !plain ? `graphql-loading` : ``
201
- }`}
202
- data-testid='graphql-document'
203
- >
204
- {/* Base code block */}
205
- {renderCode
206
- ? (
207
- renderCode()
208
- )
209
- : (
210
- <pre className='code-block'>
211
- <code>{children}</code>
212
- </pre>
213
- )}
214
-
215
- {/* Interactive overlay layer */}
216
- {!plain && isReady && (
217
- <div className='graphql-interaction-layer' style={{ pointerEvents: `none` }}>
218
- {Array.from(positions.entries()).map(([id, { position, identifier }]) => {
219
- const startPos = identifier.position.start
220
- const resolution = resolutions.get(startPos)
221
-
222
- if (!resolution) return null
223
-
224
- return (
225
- <IdentifierLink
226
- key={id}
227
- identifier={identifier}
228
- resolution={resolution}
229
- position={position}
230
- onNavigate={handleNavigate}
231
- debug={debug}
232
- isOpen={tooltipState.isOpen(id)}
233
- isPinned={tooltipState.isPinned(id)}
234
- onHoverStart={() => {
235
- tooltipState.onHoverStart(id)
236
- }}
237
- onHoverEnd={() => {
238
- tooltipState.onHoverEnd(id)
239
- }}
240
- onTogglePin={() => {
241
- tooltipState.onTogglePin(id)
242
- }}
243
- onTooltipHover={() => {
244
- tooltipState.onTooltipHover(id)
245
- }}
246
- />
247
- )
248
- })}
249
- </div>
250
- )}
251
-
252
- {/* Validation errors overlay */}
253
- {validationErrors.length > 0 && (
254
- <div className='graphql-validation-errors'>
255
- {validationErrors.map((error: any, index: number) => (
256
- <div key={index} className='graphql-error'>
257
- {error.message}
258
- </div>
259
- ))}
260
- </div>
261
- )}
262
- </div>
263
- </>
264
- )
265
- }
@@ -1,188 +0,0 @@
1
- /**
2
- * Unit tests for GraphQL Document component logic
3
- *
4
- * Tests the core functionality without rendering React components
5
- */
6
-
7
- import { buildSchema } from 'graphql'
8
- import { describe, expect, it } from 'vitest'
9
- import { analyze } from '../analysis.js'
10
- import { createSimplePositionCalculator } from '../positioning-simple.js'
11
- import { analyzeWithSchema, createPolenSchemaResolver } from '../schema-integration.js'
12
-
13
- describe('GraphQLDocument logic', () => {
14
- const testSchema = buildSchema(`
15
- type Query {
16
- user(id: ID!): User
17
- users: [User!]!
18
- }
19
-
20
- type User {
21
- id: ID!
22
- name: String!
23
- email: String!
24
- posts: [Post!]!
25
- }
26
-
27
- type Post {
28
- id: ID!
29
- title: String!
30
- content: String!
31
- author: User!
32
- }
33
- `)
34
-
35
- const testQuery = `
36
- query GetUser($id: ID!) {
37
- user(id: $id) {
38
- id
39
- name
40
- email
41
- posts {
42
- title
43
- }
44
- }
45
- }`
46
-
47
- describe('analysis integration', () => {
48
- it('should analyze GraphQL document and extract identifiers', () => {
49
- const result = analyze(testQuery)
50
-
51
- expect(result.identifiers.byKind.get('Field')).toBeDefined()
52
- expect(result.identifiers.byKind.get('Variable')).toBeDefined()
53
- expect(result.identifiers.byKind.get('Type')).toBeDefined()
54
-
55
- // Check specific identifiers
56
- const fields = result.identifiers.byKind.get('Field') || []
57
- const fieldNames = fields.map(f => f.name)
58
- expect(fieldNames).toContain('user')
59
- expect(fieldNames).toContain('id')
60
- expect(fieldNames).toContain('name')
61
- expect(fieldNames).toContain('email')
62
- expect(fieldNames).toContain('posts')
63
- expect(fieldNames).toContain('title')
64
- })
65
-
66
- it('should handle empty document', () => {
67
- const result = analyze('')
68
- expect(result.identifiers.byPosition.size).toBe(0)
69
- // Empty string is technically parseable as an empty document
70
- expect(result.ast).toBeDefined()
71
- })
72
- })
73
-
74
- describe('schema resolution integration', () => {
75
- it('should resolve identifiers against schema', () => {
76
- // Use analyzeWithSchema for proper schema-aware analysis
77
- const { analysis, resolutions } = analyzeWithSchema(testQuery, testSchema)
78
-
79
- // Check that analysis found identifiers
80
- expect(analysis.identifiers.all.length).toBeGreaterThan(0)
81
-
82
- // Check that we have resolutions
83
- expect(resolutions.size).toBeGreaterThan(0)
84
-
85
- // Check that analysis is valid
86
- expect(analysis.isValid).toBe(true)
87
-
88
- // Basic check that resolutions were created
89
- const hasValidResolutions = Array.from(resolutions.values()).some(
90
- res => res.exists && res.referenceUrl.includes('/reference/'),
91
- )
92
- expect(hasValidResolutions).toBe(true)
93
- })
94
-
95
- it('should detect non-existent fields', () => {
96
- const invalidQuery = 'query { nonExistentField }'
97
- const result = analyze(invalidQuery)
98
- const resolver = createPolenSchemaResolver(testSchema)
99
-
100
- const field = Array.from(result.identifiers.byPosition.values())[0]
101
- const resolution = resolver.resolveIdentifier(field!)
102
-
103
- expect(resolution).toBeDefined()
104
- expect(resolution!.exists).toBe(false)
105
- })
106
- })
107
-
108
- describe('position calculation', () => {
109
- it('should create position calculator', () => {
110
- const calculator = createSimplePositionCalculator()
111
- expect(calculator).toBeDefined()
112
- expect(calculator.prepareCodeBlock).toBeDefined()
113
- expect(calculator.getIdentifierPositions).toBeDefined()
114
- })
115
- })
116
-
117
- describe('options handling', () => {
118
- it('should skip analysis when plain option is true', () => {
119
- const options = { plain: true }
120
- // When plain is true, no analysis should be performed
121
- expect(options.plain).toBe(true)
122
- })
123
-
124
- it('should enable debug mode', () => {
125
- const options = { debug: true }
126
- expect(options.debug).toBe(true)
127
- })
128
-
129
- it('should handle custom navigation', () => {
130
- const onNavigate = (url: string) => {
131
- expect(url).toContain('/reference/')
132
- }
133
- const options = { onNavigate }
134
- expect(options.onNavigate).toBeDefined()
135
- })
136
-
137
- it('should handle validation option', () => {
138
- const options = { validate: true }
139
- expect(options.validate).toBe(true)
140
- })
141
-
142
- it('should handle custom className', () => {
143
- const options = { className: 'custom-graphql-block' }
144
- expect(options.className).toBe('custom-graphql-block')
145
- })
146
- })
147
-
148
- describe('validation', () => {
149
- it('should validate valid queries', () => {
150
- const { analysis, resolutions } = analyzeWithSchema(testQuery, testSchema)
151
-
152
- // Check that validation passed
153
- expect(analysis.isValid).toBe(true)
154
-
155
- // Check that we have resolutions
156
- expect(resolutions.size).toBeGreaterThan(0)
157
-
158
- // Check that the user field resolved correctly
159
- const userResolution = Array.from(resolutions.values()).find(
160
- res => res.referenceUrl.includes('query') && res.referenceUrl.includes('user'),
161
- )
162
-
163
- if (userResolution) {
164
- expect(userResolution.exists).toBe(true)
165
- }
166
- })
167
-
168
- it('should detect validation errors', () => {
169
- const invalidQuery = `
170
- query {
171
- user {
172
- nonExistentField
173
- }
174
- }
175
- `
176
-
177
- const result = analyze(invalidQuery)
178
- const resolver = createPolenSchemaResolver(testSchema)
179
-
180
- const resolutions = Array.from(result.identifiers.byPosition.values())
181
- .map(id => ({ id, resolution: resolver.resolveIdentifier(id) }))
182
-
183
- const invalidField = resolutions.find(r => r.id.name === 'nonExistentField')
184
- expect(invalidField).toBeDefined()
185
- expect(invalidField!.resolution!.exists).toBe(false)
186
- })
187
- })
188
- })
@@ -1,46 +0,0 @@
1
- import type { React } from '#dep/react/index'
2
- import { useEffect, useState } from 'react'
3
- import { useGraphQLSchema } from '../schema-context.js'
4
- import { GraphQLDocument, type GraphQLDocumentProps } from './GraphQLDocument.js'
5
-
6
- /**
7
- * GraphQL Document component that uses the schema context
8
- */
9
- export const GraphQLDocumentWithSchema: React.FC<Omit<GraphQLDocumentProps, `schema`>> = (
10
- props,
11
- ) => {
12
- const schema = useGraphQLSchema()
13
- const [mounted, setMounted] = useState(false)
14
-
15
- useEffect(() => {
16
- setMounted(true)
17
- }, [])
18
-
19
- // Always render the same structure to avoid hydration issues
20
- const isInteractive = mounted && schema
21
-
22
- if (!isInteractive) {
23
- // Static fallback
24
- return (
25
- <div className='graphql-document graphql-document-static' data-testid='graphql-document'>
26
- <pre
27
- style={{
28
- backgroundColor: `var(--gray-a2)`,
29
- color: `var(--gray-12)`,
30
- padding: `var(--space-3)`,
31
- borderRadius: `var(--radius-3)`,
32
- }}
33
- >
34
- <code className="language-graphql">{props.children}</code>
35
- </pre>
36
- </div>
37
- )
38
- }
39
-
40
- return (
41
- <GraphQLDocument
42
- {...props}
43
- schema={schema}
44
- />
45
- )
46
- }
@@ -1,199 +0,0 @@
1
- /**
2
- * GraphQL Identifier Popover using Radix Themes
3
- *
4
- * Displays rich information about GraphQL identifiers on hover/click
5
- */
6
-
7
- import type { React } from '#dep/react/index'
8
- import { Cross2Icon } from '@radix-ui/react-icons'
9
- import { Badge, Box, Flex, IconButton, Link, Popover, Text } from '@radix-ui/themes'
10
- import type { Documentation } from '../schema-integration.js'
11
- import type { Identifier } from '../types.js'
12
-
13
- export interface GraphQLIdentifierPopoverProps {
14
- /** The identifier being shown */
15
- identifier: Identifier
16
- /** Documentation from schema */
17
- documentation: Documentation
18
- /** Whether this identifier has an error */
19
- hasError?: boolean
20
- /** Reference URL for "View docs" link */
21
- referenceUrl: string
22
- /** Whether popover is open */
23
- open: boolean
24
- /** Whether popover is pinned */
25
- isPinned: boolean
26
- /** Callback when open state changes */
27
- onOpenChange: (open: boolean) => void
28
- /** Callback to navigate to docs */
29
- onNavigate?: (url: string) => void
30
- /** The trigger element */
31
- children: React.ReactNode
32
- }
33
-
34
- /**
35
- * Popover content for GraphQL identifiers
36
- */
37
- export const GraphQLIdentifierPopover: React.FC<GraphQLIdentifierPopoverProps> = ({
38
- identifier,
39
- documentation,
40
- hasError = false,
41
- referenceUrl,
42
- open,
43
- isPinned,
44
- onOpenChange,
45
- onNavigate,
46
- children,
47
- }) => {
48
- // Determine badge color based on identifier kind
49
- const getBadgeColor = () => {
50
- switch (identifier.kind) {
51
- case `Type`:
52
- return `blue`
53
- case `Field`:
54
- return `green`
55
- case `Argument`:
56
- return `orange`
57
- case `Variable`:
58
- return `purple`
59
- case `Directive`:
60
- return `amber`
61
- case `Fragment`:
62
- return `cyan`
63
- default:
64
- return `gray`
65
- }
66
- }
67
-
68
- return (
69
- <Popover.Root open={open} onOpenChange={onOpenChange}>
70
- <Popover.Trigger>
71
- {children}
72
- </Popover.Trigger>
73
-
74
- <Popover.Content
75
- className='graphql-identifier-popover'
76
- style={{ maxWidth: 400 }}
77
- onInteractOutside={(e) => {
78
- // Prevent closing when clicking inside popover if pinned
79
- if (isPinned) {
80
- e.preventDefault()
81
- }
82
- }}
83
- >
84
- <Flex direction='column' gap='2'>
85
- {/* Header with name, kind, and close button */}
86
- <Flex justify='between' align='center'>
87
- <Flex align='center' gap='2'>
88
- <Text size='2' weight='bold'>
89
- {identifier.name}
90
- </Text>
91
- <Badge color={getBadgeColor()} size='1'>
92
- {identifier.kind}
93
- </Badge>
94
- </Flex>
95
- {isPinned && (
96
- <IconButton
97
- size='1'
98
- variant='ghost'
99
- onClick={() => {
100
- onOpenChange(false)
101
- }}
102
- aria-label='Close popover'
103
- >
104
- <Cross2Icon />
105
- </IconButton>
106
- )}
107
- </Flex>
108
-
109
- {/* Type signature */}
110
- <Box>
111
- <Text size='1' color='gray'>
112
- Type: <Text as='span' size='1' style={{ fontFamily: `monospace` }}>{documentation.typeInfo}</Text>
113
- </Text>
114
- </Box>
115
-
116
- {/* Description */}
117
- {documentation.description && (
118
- <Box>
119
- <Text size='1'>
120
- {documentation.description}
121
- </Text>
122
- </Box>
123
- )}
124
-
125
- {/* Default value for arguments */}
126
- {documentation.defaultValue && (
127
- <Box>
128
- <Text size='1' color='gray'>
129
- Default:{` `}
130
- <Text as='span' size='1' style={{ fontFamily: `monospace` }}>{documentation.defaultValue}</Text>
131
- </Text>
132
- </Box>
133
- )}
134
-
135
- {/* Deprecation warning */}
136
- {documentation.deprecated && (
137
- <Box
138
- style={{
139
- padding: `8px`,
140
- backgroundColor: `var(--amber-2)`,
141
- borderRadius: `4px`,
142
- border: `1px solid var(--amber-6)`,
143
- }}
144
- >
145
- <Text size='1' color='amber'>
146
- ⚠️ Deprecated: {documentation.deprecated.reason}
147
- </Text>
148
- {documentation.deprecated.replacement && (
149
- <Text size='1' color='amber'>
150
- Use {documentation.deprecated.replacement} instead.
151
- </Text>
152
- )}
153
- </Box>
154
- )}
155
-
156
- {/* Error message */}
157
- {hasError && (
158
- <Box
159
- style={{
160
- padding: `8px`,
161
- backgroundColor: `var(--red-2)`,
162
- borderRadius: `4px`,
163
- border: `1px solid var(--red-6)`,
164
- }}
165
- >
166
- <Text size='1' color='red'>
167
- ❌ {identifier.kind} not found in schema
168
- </Text>
169
- </Box>
170
- )}
171
-
172
- {/* Schema path */}
173
- <Box>
174
- <Text size='1' color='gray'>
175
- Path: {identifier.schemaPath.join(` → `)}
176
- </Text>
177
- </Box>
178
-
179
- {/* View docs link */}
180
- {onNavigate && !hasError && (
181
- <Box>
182
- <Link
183
- size='1'
184
- href={referenceUrl}
185
- onClick={(e: React.MouseEvent) => {
186
- e.preventDefault()
187
- onNavigate(referenceUrl)
188
- onOpenChange(false)
189
- }}
190
- >
191
- View full documentation →
192
- </Link>
193
- </Box>
194
- )}
195
- </Flex>
196
- </Popover.Content>
197
- </Popover.Root>
198
- )
199
- }