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,76 +0,0 @@
1
- /**
2
- * Unit tests for tooltip state management hook
3
- *
4
- * @vitest-environment jsdom
5
- */
6
-
7
- import { act, renderHook } from '@testing-library/react'
8
- import { describe, expect, it, vi } from 'vitest'
9
- import { useTooltipState } from './use-tooltip-state.js'
10
-
11
- describe('useTooltipState', () => {
12
- it('shows tooltip after hover delay', () => {
13
- vi.useFakeTimers()
14
- const { result } = renderHook(() => useTooltipState({ showDelay: 300 }))
15
-
16
- act(() => {
17
- result.current.onHoverStart('field-1')
18
- })
19
- expect(result.current.isOpen('field-1')).toBe(false)
20
-
21
- act(() => {
22
- vi.advanceTimersByTime(300)
23
- })
24
- expect(result.current.isOpen('field-1')).toBe(true)
25
- vi.useRealTimers()
26
- })
27
-
28
- it('hides tooltip after hover end delay', () => {
29
- vi.useFakeTimers()
30
- const { result } = renderHook(() => useTooltipState())
31
-
32
- // Show tooltip
33
- act(() => {
34
- result.current.onHoverStart('field-1')
35
- vi.advanceTimersByTime(300)
36
- })
37
-
38
- // Trigger hide
39
- act(() => {
40
- result.current.onHoverEnd('field-1')
41
- })
42
- expect(result.current.isOpen('field-1')).toBe(true) // Still open during delay
43
-
44
- act(() => {
45
- vi.advanceTimersByTime(200)
46
- })
47
- expect(result.current.isOpen('field-1')).toBe(false)
48
- vi.useRealTimers()
49
- })
50
-
51
- it('pins and unpins tooltip on toggle', () => {
52
- const { result } = renderHook(() => useTooltipState())
53
-
54
- act(() => {
55
- result.current.onTogglePin('field-1')
56
- })
57
- expect(result.current.isPinned('field-1')).toBe(true)
58
-
59
- act(() => {
60
- result.current.onTogglePin('field-1')
61
- })
62
- expect(result.current.isPinned('field-1')).toBe(false)
63
- })
64
-
65
- it('allows multiple pins when enabled', () => {
66
- const { result } = renderHook(() => useTooltipState())
67
-
68
- act(() => {
69
- result.current.onTogglePin('field-1')
70
- result.current.onTogglePin('field-2')
71
- })
72
-
73
- expect(result.current.isPinned('field-1')).toBe(true)
74
- expect(result.current.isPinned('field-2')).toBe(true)
75
- })
76
- })
@@ -1,191 +0,0 @@
1
- /**
2
- * State management for GraphQL document tooltips
3
- *
4
- * Handles hover delays, pinning, and multiple tooltip coordination
5
- */
6
-
7
- import { React } from '#dep/react/index'
8
-
9
- export interface TooltipState {
10
- /** Currently visible tooltip (via hover) */
11
- hoveredId: string | null
12
- /** Set of pinned tooltip IDs */
13
- pinnedIds: Set<string>
14
- /** ID pending show (waiting for delay) */
15
- pendingShowId: string | null
16
- /** ID pending hide (waiting for grace period) */
17
- pendingHideId: string | null
18
- }
19
-
20
- export interface UseTooltipStateOptions {
21
- /** Delay before showing tooltip on hover (ms) */
22
- showDelay?: number
23
- /** Delay before hiding tooltip on mouse leave (ms) */
24
- hideDelay?: number
25
- /** Whether to allow multiple pinned tooltips */
26
- allowMultiplePins?: boolean
27
- }
28
-
29
- export interface UseTooltipStateReturn {
30
- /** Check if a tooltip should be visible */
31
- isOpen: (id: string) => boolean
32
- /** Check if a tooltip is pinned */
33
- isPinned: (id: string) => boolean
34
- /** Handle hover start */
35
- onHoverStart: (id: string) => void
36
- /** Handle hover end */
37
- onHoverEnd: (id: string) => void
38
- /** Handle click (toggle pin) */
39
- onTogglePin: (id: string) => void
40
- /** Handle tooltip content hover (cancels hide) */
41
- onTooltipHover: (id: string) => void
42
- /** Unpin a specific tooltip */
43
- unpin: (id: string) => void
44
- /** Unpin all tooltips */
45
- unpinAll: () => void
46
- }
47
-
48
- export const useTooltipState = (options: UseTooltipStateOptions = {}): UseTooltipStateReturn => {
49
- const {
50
- showDelay = 300,
51
- hideDelay = 200,
52
- allowMultiplePins = true,
53
- } = options
54
-
55
- const [hoveredId, setHoveredId] = React.useState<string | null>(null)
56
- const [pinnedIds, setPinnedIds] = React.useState<Set<string>>(new Set())
57
- const [pendingShowId, setPendingShowId] = React.useState<string | null>(null)
58
- const [pendingHideId, setPendingHideId] = React.useState<string | null>(null)
59
-
60
- // Timer refs
61
- const showTimerRef = React.useRef<NodeJS.Timeout | null>(null)
62
- const hideTimerRef = React.useRef<NodeJS.Timeout | null>(null)
63
-
64
- // Clear any pending timers
65
- const clearTimers = React.useCallback(() => {
66
- if (showTimerRef.current) {
67
- clearTimeout(showTimerRef.current)
68
- showTimerRef.current = null
69
- }
70
- if (hideTimerRef.current) {
71
- clearTimeout(hideTimerRef.current)
72
- hideTimerRef.current = null
73
- }
74
- setPendingShowId(null)
75
- setPendingHideId(null)
76
- }, [])
77
-
78
- // Check if tooltip should be visible
79
- const isOpen = React.useCallback((id: string): boolean => {
80
- return hoveredId === id || pinnedIds.has(id)
81
- }, [hoveredId, pinnedIds])
82
-
83
- // Check if tooltip is pinned
84
- const isPinned = React.useCallback((id: string): boolean => {
85
- return pinnedIds.has(id)
86
- }, [pinnedIds])
87
-
88
- // Handle hover start
89
- const onHoverStart = React.useCallback((id: string) => {
90
- // Don't show if already pinned
91
- if (pinnedIds.has(id)) return
92
-
93
- // Cancel any pending hide for this ID
94
- if (pendingHideId === id) {
95
- clearTimeout(hideTimerRef.current!)
96
- hideTimerRef.current = null
97
- setPendingHideId(null)
98
- return
99
- }
100
-
101
- // Clear any other pending operations
102
- clearTimers()
103
-
104
- // Schedule show
105
- setPendingShowId(id)
106
- showTimerRef.current = setTimeout(() => {
107
- setHoveredId(id)
108
- setPendingShowId(null)
109
- }, showDelay)
110
- }, [pinnedIds, pendingHideId, clearTimers, showDelay])
111
-
112
- // Handle hover end
113
- const onHoverEnd = React.useCallback((id: string) => {
114
- // Don't hide if pinned
115
- if (pinnedIds.has(id)) return
116
-
117
- // Cancel pending show if still waiting
118
- if (pendingShowId === id) {
119
- clearTimeout(showTimerRef.current!)
120
- showTimerRef.current = null
121
- setPendingShowId(null)
122
- return
123
- }
124
-
125
- // Only hide if currently showing this tooltip
126
- if (hoveredId === id) {
127
- setPendingHideId(id)
128
- hideTimerRef.current = setTimeout(() => {
129
- // First set hovered to null to trigger close animation
130
- setHoveredId(null)
131
- setPendingHideId(null)
132
- }, hideDelay)
133
- }
134
- }, [pinnedIds, pendingShowId, hoveredId, hideDelay])
135
-
136
- // Handle tooltip content hover (cancels hide)
137
- const onTooltipHover = React.useCallback((id: string) => {
138
- if (pendingHideId === id) {
139
- clearTimeout(hideTimerRef.current!)
140
- hideTimerRef.current = null
141
- setPendingHideId(null)
142
- }
143
- }, [pendingHideId])
144
-
145
- // Toggle pin state
146
- const onTogglePin = React.useCallback((id: string) => {
147
- clearTimers()
148
-
149
- setPinnedIds((prev: Set<string>) => {
150
- const next = new Set(prev)
151
- if (next.has(id)) {
152
- // Unpin
153
- next.delete(id)
154
- setHoveredId(null) // Also clear hover state
155
- } else {
156
- // Pin
157
- if (!allowMultiplePins) {
158
- next.clear() // Clear other pins
159
- }
160
- next.add(id)
161
- setHoveredId(null) // Clear hover state since it's now pinned
162
- }
163
- return next
164
- })
165
- }, [clearTimers, allowMultiplePins])
166
-
167
- // Unpin specific tooltip
168
- const unpin = React.useCallback((id: string) => {
169
- setPinnedIds((prev: Set<string>) => {
170
- const next = new Set(prev)
171
- next.delete(id)
172
- return next
173
- })
174
- }, [])
175
-
176
- // Unpin all tooltips
177
- const unpinAll = React.useCallback(() => {
178
- setPinnedIds(new Set())
179
- }, [])
180
-
181
- return {
182
- isOpen,
183
- isPinned,
184
- onHoverStart,
185
- onHoverEnd,
186
- onTogglePin,
187
- onTooltipHover,
188
- unpin,
189
- unpinAll,
190
- }
191
- }
@@ -1,248 +0,0 @@
1
- /**
2
- * @vitest-environment jsdom
3
- */
4
-
5
- import { describe, expect, it } from 'vitest'
6
- import { createSimpleOverlay, createSimplePositionCalculator } from './positioning-simple.js'
7
- import type { Identifier } from './types.js'
8
-
9
- // Helper to create test identifier
10
- const createTestIdentifier = (
11
- name: string,
12
- line: number,
13
- column: number,
14
- kind: Identifier['kind'] = 'Field',
15
- ): Identifier => ({
16
- name,
17
- kind,
18
- position: {
19
- start: column - 1,
20
- end: column - 1 + name.length,
21
- line,
22
- column,
23
- },
24
- schemaPath: [name],
25
- context: { selectionPath: [] },
26
- })
27
-
28
- describe('Simple Positioning Engine', () => {
29
- describe('SimplePositionCalculator', () => {
30
- const calculator = createSimplePositionCalculator()
31
-
32
- it('should wrap identifiers in spans', () => {
33
- const container = document.createElement('div')
34
- container.innerHTML = `
35
- <pre class="code-block">
36
- <code>query GetUser {
37
- user {
38
- name
39
- }
40
- }</code>
41
- </pre>
42
- `
43
-
44
- const identifiers = [
45
- createTestIdentifier('query', 1, 1),
46
- createTestIdentifier('user', 2, 3, 'Field'),
47
- createTestIdentifier('name', 3, 5, 'Field'),
48
- ]
49
-
50
- const codeElement = container.querySelector('code')!
51
- calculator.prepareCodeBlock(codeElement, identifiers)
52
-
53
- // Check that identifiers were wrapped
54
- const wrappedElements = container.querySelectorAll('[data-graphql-id]')
55
- expect(wrappedElements.length).toBe(3)
56
-
57
- // Check first wrapped element
58
- const firstWrapped = wrappedElements[0] as HTMLElement
59
- expect(firstWrapped.textContent).toBe('query')
60
- expect(firstWrapped.getAttribute('data-graphql-name')).toBe('query')
61
- expect(firstWrapped.getAttribute('data-graphql-kind')).toBe('Field')
62
- })
63
-
64
- it('should handle multiple identifiers in same line', () => {
65
- const container = document.createElement('div')
66
- container.innerHTML = `
67
- <pre class="code-block">
68
- <code>query GetUserById($id: ID!) {</code>
69
- </pre>
70
- `
71
-
72
- const identifiers = [
73
- createTestIdentifier('query', 1, 1),
74
- createTestIdentifier('GetUserById', 1, 7),
75
- createTestIdentifier('$id', 1, 19, 'Variable'),
76
- createTestIdentifier('ID', 1, 24, 'Type'),
77
- ]
78
-
79
- const codeElement = container.querySelector('code')!
80
- calculator.prepareCodeBlock(codeElement, identifiers)
81
-
82
- const wrappedElements = container.querySelectorAll('[data-graphql-id]')
83
- expect(wrappedElements.length).toBe(4)
84
- })
85
-
86
- it('should get positions of wrapped identifiers', () => {
87
- const container = document.createElement('div')
88
- container.innerHTML = `
89
- <pre class="code-block">
90
- <code>
91
- <span class="line"><span data-graphql-id="0-user-Field" data-graphql-name="user" data-graphql-kind="Field" data-graphql-start="0" data-graphql-end="4" data-graphql-line="1" data-graphql-column="1" data-graphql-path="user">user</span> {</span>
92
- </code>
93
- </pre>
94
- `
95
-
96
- // Mock getBoundingClientRect
97
- container.getBoundingClientRect = () => ({
98
- top: 0,
99
- left: 0,
100
- right: 100,
101
- bottom: 100,
102
- width: 100,
103
- height: 100,
104
- x: 0,
105
- y: 0,
106
- toJSON: () => ({}),
107
- })
108
-
109
- const userSpan = container.querySelector('[data-graphql-id]')!
110
- userSpan.getBoundingClientRect = () => ({
111
- top: 10,
112
- left: 20,
113
- right: 60,
114
- bottom: 30,
115
- width: 40,
116
- height: 20,
117
- x: 20,
118
- y: 10,
119
- toJSON: () => ({}),
120
- })
121
-
122
- const positions = calculator.getIdentifierPositions(container)
123
-
124
- expect(positions.size).toBe(1)
125
- const result = positions.get('0-user-Field')
126
- expect(result).toBeDefined()
127
- expect(result!.position).toEqual({
128
- top: 10,
129
- left: 20,
130
- width: 40,
131
- height: 20,
132
- })
133
- expect(result!.identifier.name).toBe('user')
134
- expect(result!.identifier.kind).toBe('Field')
135
- })
136
-
137
- it('should skip already wrapped identifiers', () => {
138
- const container = document.createElement('div')
139
- container.innerHTML = `
140
- <pre class="code-block">
141
- <code><span data-graphql-id="existing">user</span> {</code>
142
- </pre>
143
- `
144
-
145
- const identifiers = [
146
- createTestIdentifier('user', 1, 1),
147
- ]
148
-
149
- const codeElement = container.querySelector('code')!
150
- calculator.prepareCodeBlock(codeElement, identifiers)
151
-
152
- // Should still only have one wrapped element
153
- const wrappedElements = container.querySelectorAll('[data-graphql-id]')
154
- expect(wrappedElements.length).toBe(1)
155
- expect(wrappedElements[0]!.getAttribute('data-graphql-id')).toBe('existing')
156
- })
157
-
158
- it('should handle empty lines gracefully', () => {
159
- const container = document.createElement('div')
160
- container.innerHTML = `
161
- <pre class="code-block">
162
- <code>query {
163
-
164
- user</code>
165
- </pre>
166
- `
167
-
168
- const identifiers = [
169
- createTestIdentifier('query', 1, 1),
170
- createTestIdentifier('user', 3, 3),
171
- ]
172
-
173
- const codeElement = container.querySelector('code')!
174
- expect(() => {
175
- calculator.prepareCodeBlock(codeElement, identifiers)
176
- }).not.toThrow()
177
-
178
- const wrappedElements = container.querySelectorAll('[data-graphql-id]')
179
- expect(wrappedElements.length).toBe(2)
180
- })
181
- })
182
-
183
- describe('createSimpleOverlay', () => {
184
- it('should create positioned overlay element', () => {
185
- const position = { top: 10, left: 20, width: 40, height: 20 }
186
- const identifier = createTestIdentifier('user', 1, 1)
187
-
188
- const overlay = createSimpleOverlay(position, identifier)
189
-
190
- expect(overlay.style.position).toBe('absolute')
191
- expect(overlay.style.top).toBe('10px')
192
- expect(overlay.style.left).toBe('20px')
193
- expect(overlay.style.width).toBe('40px')
194
- expect(overlay.style.height).toBe('20px')
195
- expect(overlay.style.cursor).toBe('pointer')
196
- expect(overlay.getAttribute('data-graphql-overlay')).toBe('true')
197
- expect(overlay.getAttribute('data-graphql-name')).toBe('user')
198
- expect(overlay.getAttribute('data-graphql-kind')).toBe('Field')
199
- })
200
-
201
- it('should handle click events', () => {
202
- const position = { top: 10, left: 20, width: 40, height: 20 }
203
- const identifier = createTestIdentifier('user', 1, 1)
204
- let clickedIdentifier: Identifier | null = null
205
-
206
- const overlay = createSimpleOverlay(position, identifier, {
207
- onClick: (id) => {
208
- clickedIdentifier = id
209
- },
210
- })
211
-
212
- // Simulate click
213
- const event = new MouseEvent('click')
214
- overlay.dispatchEvent(event)
215
-
216
- expect(clickedIdentifier).toBe(identifier)
217
- })
218
-
219
- it('should handle hover events', () => {
220
- const position = { top: 10, left: 20, width: 40, height: 20 }
221
- const identifier = createTestIdentifier('user', 1, 1)
222
- let hoveredIdentifier: Identifier | null = null
223
-
224
- const overlay = createSimpleOverlay(position, identifier, {
225
- onHover: (id) => {
226
- hoveredIdentifier = id
227
- },
228
- })
229
-
230
- // Simulate hover
231
- const event = new MouseEvent('mouseenter')
232
- overlay.dispatchEvent(event)
233
-
234
- expect(hoveredIdentifier).toBe(identifier)
235
- })
236
-
237
- it('should apply custom className', () => {
238
- const position = { top: 10, left: 20, width: 40, height: 20 }
239
- const identifier = createTestIdentifier('user', 1, 1)
240
-
241
- const overlay = createSimpleOverlay(position, identifier, {
242
- className: 'custom-overlay-class',
243
- })
244
-
245
- expect(overlay.className).toBe('custom-overlay-class')
246
- })
247
- })
248
- })