polen 0.10.0 → 0.11.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/api/api.d.ts +1 -0
- package/build/api/api.d.ts.map +1 -1
- package/build/api/api.js +1 -0
- package/build/api/api.js.map +1 -1
- package/build/api/config/configurator.d.ts +20 -3
- package/build/api/config/configurator.d.ts.map +1 -1
- package/build/api/config/configurator.js +27 -3
- package/build/api/config/configurator.js.map +1 -1
- package/build/api/schema/data-sources/memory/memory.d.ts +2 -2
- package/build/api/schema/data-sources/memory/memory.d.ts.map +1 -1
- package/build/api/schema/data-sources/memory/memory.js +1 -3
- package/build/api/schema/data-sources/memory/memory.js.map +1 -1
- package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.d.ts +7 -3
- package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.d.ts.map +1 -1
- package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.js +15 -11
- package/build/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.js.map +1 -1
- package/build/api/schema/data-sources/schema-directory/schema-directory.d.ts +16 -7
- package/build/api/schema/data-sources/schema-directory/schema-directory.d.ts.map +1 -1
- package/build/api/schema/data-sources/schema-directory/schema-directory.js +26 -7
- package/build/api/schema/data-sources/schema-directory/schema-directory.js.map +1 -1
- package/build/api/schema/data-sources/schema-file/schema-file.d.ts +7 -2
- package/build/api/schema/data-sources/schema-file/schema-file.d.ts.map +1 -1
- package/build/api/schema/data-sources/schema-file/schema-file.js +13 -5
- package/build/api/schema/data-sources/schema-file/schema-file.js.map +1 -1
- package/build/api/schema/metadata.d.ts +8 -0
- package/build/api/schema/metadata.d.ts.map +1 -0
- package/build/api/schema/metadata.js +19 -0
- package/build/api/schema/metadata.js.map +1 -0
- package/build/api/schema/read.d.ts +3 -3
- package/build/api/schema/read.d.ts.map +1 -1
- package/build/api/schema/read.js.map +1 -1
- package/build/api/schema/schema.d.ts +33 -2
- package/build/api/schema/schema.d.ts.map +1 -1
- package/build/api/schema/schema.js +42 -0
- package/build/api/schema/schema.js.map +1 -1
- package/build/api/schema-source/index.d.ts +2 -0
- package/build/api/schema-source/index.d.ts.map +1 -0
- package/build/api/schema-source/index.js +2 -0
- package/build/api/schema-source/index.js.map +1 -0
- package/build/api/schema-source/schema-source.d.ts +33 -0
- package/build/api/schema-source/schema-source.d.ts.map +1 -0
- package/build/api/schema-source/schema-source.js +137 -0
- package/build/api/schema-source/schema-source.js.map +1 -0
- package/build/api/vite/plugins/core.d.ts +1 -0
- package/build/api/vite/plugins/core.d.ts.map +1 -1
- package/build/api/vite/plugins/core.js +21 -18
- package/build/api/vite/plugins/core.js.map +1 -1
- package/build/api/vite/plugins/schema-assets.d.ts +22 -0
- package/build/api/vite/plugins/schema-assets.d.ts.map +1 -0
- package/build/api/vite/plugins/schema-assets.js +269 -0
- package/build/api/vite/plugins/schema-assets.js.map +1 -0
- package/build/api/vite/plugins/serve.d.ts.map +1 -1
- package/build/api/vite/plugins/serve.js +11 -0
- package/build/api/vite/plugins/serve.js.map +1 -1
- package/build/lib/graphql-change/change-groups.d.ts +2 -0
- package/build/lib/graphql-change/change-groups.d.ts.map +1 -1
- package/build/lib/graphql-change/change-groups.js +54 -0
- package/build/lib/graphql-change/change-groups.js.map +1 -1
- package/build/lib/kit-temp.d.ts +9 -0
- package/build/lib/kit-temp.d.ts.map +1 -1
- package/build/lib/kit-temp.js +12 -0
- package/build/lib/kit-temp.js.map +1 -1
- package/build/lib/path-map/path-map.d.ts.map +1 -1
- package/build/lib/path-map/path-map.js +3 -1
- package/build/lib/path-map/path-map.js.map +1 -1
- package/build/project-data.d.ts +3 -11
- package/build/project-data.d.ts.map +1 -1
- package/build/template/components/Changelog.d.ts +3 -3
- package/build/template/components/Changelog.d.ts.map +1 -1
- package/build/template/components/Changelog.js +8 -84
- package/build/template/components/Changelog.js.map +1 -1
- package/build/template/components/CodeBlock.d.ts +2 -0
- package/build/template/components/CodeBlock.d.ts.map +1 -1
- package/build/template/components/CodeBlock.js +1 -4
- package/build/template/components/CodeBlock.js.map +1 -1
- package/build/template/components/ComponentDispatch.d.ts +34 -0
- package/build/template/components/ComponentDispatch.d.ts.map +1 -0
- package/build/template/components/ComponentDispatch.js +33 -0
- package/build/template/components/ComponentDispatch.js.map +1 -0
- package/build/template/components/ReferenceLink.d.ts +19 -0
- package/build/template/components/ReferenceLink.d.ts.map +1 -0
- package/build/template/components/ReferenceLink.js +19 -0
- package/build/template/components/ReferenceLink.js.map +1 -0
- package/build/template/components/TypeAnnotation.d.ts.map +1 -1
- package/build/template/components/TypeAnnotation.js +3 -3
- package/build/template/components/TypeAnnotation.js.map +1 -1
- package/build/template/components/TypeFieldsLinkList.d.ts.map +1 -1
- package/build/template/components/TypeFieldsLinkList.js +4 -4
- package/build/template/components/TypeFieldsLinkList.js.map +1 -1
- package/build/template/components/TypeIndex.js +2 -2
- package/build/template/components/TypeIndex.js.map +1 -1
- package/build/template/components/VersionSelector.d.ts +7 -0
- package/build/template/components/VersionSelector.d.ts.map +1 -0
- package/build/template/components/VersionSelector.js +30 -0
- package/build/template/components/VersionSelector.js.map +1 -0
- package/build/template/components/graphql/type-link.d.ts.map +1 -1
- package/build/template/components/graphql/type-link.js +2 -2
- package/build/template/components/graphql/type-link.js.map +1 -1
- package/build/template/hooks/useVersionPath.d.ts +6 -0
- package/build/template/hooks/useVersionPath.d.ts.map +1 -0
- package/build/template/hooks/useVersionPath.js +10 -0
- package/build/template/hooks/useVersionPath.js.map +1 -0
- package/build/template/layouts/ChangelogLayout.d.ts.map +1 -0
- package/build/template/{components → layouts}/ChangelogLayout.js +1 -1
- package/build/template/layouts/ChangelogLayout.js.map +1 -0
- package/build/template/layouts/index.d.ts +1 -0
- package/build/template/layouts/index.d.ts.map +1 -1
- package/build/template/layouts/index.js +1 -0
- package/build/template/layouts/index.js.map +1 -1
- package/build/template/lib/fetch-text.d.ts +8 -0
- package/build/template/lib/fetch-text.d.ts.map +1 -0
- package/build/template/lib/fetch-text.js +14 -0
- package/build/template/lib/fetch-text.js.map +1 -0
- package/build/template/lib/polen-url.d.ts +14 -0
- package/build/template/lib/polen-url.d.ts.map +1 -1
- package/build/template/lib/polen-url.js +16 -0
- package/build/template/lib/polen-url.js.map +1 -1
- package/build/template/lib/schema-utils/constants.d.ts +5 -0
- package/build/template/lib/schema-utils/constants.d.ts.map +1 -0
- package/build/template/lib/schema-utils/constants.js +5 -0
- package/build/template/lib/schema-utils/constants.js.map +1 -0
- package/build/template/lib/schema-utils/schema-utils.d.ts +15 -0
- package/build/template/lib/schema-utils/schema-utils.d.ts.map +1 -0
- package/build/template/lib/schema-utils/schema-utils.js +37 -0
- package/build/template/lib/schema-utils/schema-utils.js.map +1 -0
- package/build/template/routes/changelog.d.ts +4 -3
- package/build/template/routes/changelog.d.ts.map +1 -1
- package/build/template/routes/changelog.js +13 -7
- package/build/template/routes/changelog.js.map +1 -1
- package/build/template/routes/pages.d.ts +10 -0
- package/build/template/routes/pages.d.ts.map +1 -0
- package/build/template/routes/pages.js +76 -0
- package/build/template/routes/pages.js.map +1 -0
- package/build/template/routes/reference.$type.$field.js +1 -1
- package/build/template/routes/reference.$type.$field.js.map +1 -1
- package/build/template/routes/reference.$type.d.ts +4 -0
- package/build/template/routes/reference.$type.d.ts.map +1 -1
- package/build/template/routes/reference.$type.js +2 -0
- package/build/template/routes/reference.$type.js.map +1 -1
- package/build/template/routes/reference.d.ts +9 -3
- package/build/template/routes/reference.d.ts.map +1 -1
- package/build/template/routes/reference.js +30 -8
- package/build/template/routes/reference.js.map +1 -1
- package/build/template/routes/reference.version.$version.$type.$field.d.ts +6 -0
- package/build/template/routes/reference.version.$version.$type.$field.d.ts.map +1 -0
- package/build/template/routes/reference.version.$version.$type.$field.js +32 -0
- package/build/template/routes/reference.version.$version.$type.$field.js.map +1 -0
- package/build/template/routes/reference.version.$version.$type.d.ts +11 -0
- package/build/template/routes/reference.version.$version.$type.d.ts.map +1 -0
- package/build/template/routes/reference.version.$version.$type.js +26 -0
- package/build/template/routes/reference.version.$version.$type.js.map +1 -0
- package/build/template/routes/root.d.ts.map +1 -1
- package/build/template/routes/root.js +8 -72
- package/build/template/routes/root.js.map +1 -1
- package/build/template/server/app.d.ts +22 -1
- package/build/template/server/app.d.ts.map +1 -1
- package/build/template/server/app.js +19 -9
- package/build/template/server/app.js.map +1 -1
- package/build/template/server/main.js +9 -1
- package/build/template/server/main.js.map +1 -1
- package/build/template/server/ssg/generate.js +2 -2
- package/build/template/server/ssg/generate.js.map +1 -1
- package/build/template/server/ssg/get-route-paths.d.ts +1 -1
- package/build/template/server/ssg/get-route-paths.d.ts.map +1 -1
- package/build/template/server/ssg/get-route-paths.js +51 -27
- package/build/template/server/ssg/get-route-paths.js.map +1 -1
- package/build/template/sources/schema-source.d.ts +15 -0
- package/build/template/sources/schema-source.d.ts.map +1 -0
- package/build/template/sources/schema-source.js +63 -0
- package/build/template/sources/schema-source.js.map +1 -0
- package/package.json +1 -1
- package/src/api/api.ts +1 -0
- package/src/api/config/configurator.ts +51 -6
- package/src/api/schema/data-sources/memory/memory.ts +3 -5
- package/src/api/schema/data-sources/schema-directory/file-name-expression/file-name-expression.ts +29 -13
- package/src/api/schema/data-sources/schema-directory/schema-directory.ts +56 -16
- package/src/api/schema/data-sources/schema-file/schema-file.ts +16 -7
- package/src/api/schema/metadata.ts +23 -0
- package/src/api/schema/read.ts +3 -3
- package/src/api/schema/schema.ts +62 -2
- package/src/api/schema-source/index.ts +1 -0
- package/src/api/schema-source/schema-source.ts +189 -0
- package/src/api/vite/plugins/core.ts +23 -18
- package/src/api/vite/plugins/schema-assets.ts +317 -0
- package/src/api/vite/plugins/serve.ts +15 -8
- package/src/lib/graphql-change/change-groups.ts +57 -0
- package/src/lib/kit-temp.ts +13 -0
- package/src/lib/path-map/$.test.ts +22 -19
- package/src/lib/path-map/path-map.ts +3 -1
- package/src/project-data.ts +3 -11
- package/src/template/components/Changelog.tsx +16 -67
- package/src/template/components/CodeBlock.tsx +3 -5
- package/src/template/components/ComponentDispatch.tsx +42 -0
- package/src/template/components/ReferenceLink.tsx +34 -0
- package/src/template/components/TypeAnnotation.tsx +5 -7
- package/src/template/components/TypeFieldsLinkList.tsx +20 -23
- package/src/template/components/TypeIndex.tsx +10 -12
- package/src/template/components/VersionSelector.tsx +50 -0
- package/src/template/components/graphql/type-link.tsx +4 -3
- package/src/template/hooks/useVersionPath.ts +10 -0
- package/src/template/{components → layouts}/ChangelogLayout.tsx +1 -1
- package/src/template/layouts/index.ts +1 -0
- package/src/template/lib/fetch-text.ts +13 -0
- package/src/template/lib/polen-url.ts +20 -0
- package/src/template/lib/schema-utils/constants.ts +4 -0
- package/src/template/lib/schema-utils/schema-utils.ts +42 -0
- package/src/template/routes/changelog.tsx +17 -8
- package/src/template/routes/pages.tsx +109 -0
- package/src/template/routes/reference.$type.$field.tsx +1 -1
- package/src/template/routes/reference.$type.tsx +2 -0
- package/src/template/routes/reference.tsx +38 -6
- package/src/template/routes/reference.version.$version.$type.$field.tsx +35 -0
- package/src/template/routes/reference.version.$version.$type.tsx +30 -0
- package/src/template/routes/root.tsx +8 -109
- package/src/template/server/app.ts +47 -14
- package/src/template/server/main.ts +9 -1
- package/src/template/server/ssg/generate.ts +2 -2
- package/src/template/server/ssg/get-route-paths.ts +53 -27
- package/src/template/sources/schema-source.ts +68 -0
- package/build/lib/graphql-document/$$.d.ts +0 -5
- package/build/lib/graphql-document/$$.d.ts.map +0 -1
- package/build/lib/graphql-document/$$.js +0 -5
- package/build/lib/graphql-document/$$.js.map +0 -1
- package/build/lib/graphql-document/$.d.ts +0 -2
- package/build/lib/graphql-document/$.d.ts.map +0 -1
- package/build/lib/graphql-document/$.js +0 -2
- package/build/lib/graphql-document/$.js.map +0 -1
- package/build/lib/graphql-document/analysis.d.ts +0 -44
- package/build/lib/graphql-document/analysis.d.ts.map +0 -1
- package/build/lib/graphql-document/analysis.js +0 -361
- package/build/lib/graphql-document/analysis.js.map +0 -1
- package/build/lib/graphql-document/components/GraphQLDocument.d.ts +0 -38
- package/build/lib/graphql-document/components/GraphQLDocument.d.ts.map +0 -1
- package/build/lib/graphql-document/components/GraphQLDocument.js +0 -151
- package/build/lib/graphql-document/components/GraphQLDocument.js.map +0 -1
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.d.ts +0 -7
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.d.ts.map +0 -1
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.js +0 -27
- package/build/lib/graphql-document/components/GraphQLDocumentWithSchema.js.map +0 -1
- package/build/lib/graphql-document/components/GraphQLIdentifierPopover.d.ts +0 -33
- package/build/lib/graphql-document/components/GraphQLIdentifierPopover.d.ts.map +0 -1
- package/build/lib/graphql-document/components/GraphQLIdentifierPopover.js +0 -50
- package/build/lib/graphql-document/components/GraphQLIdentifierPopover.js.map +0 -1
- package/build/lib/graphql-document/components/IdentifierLink.d.ts +0 -39
- package/build/lib/graphql-document/components/IdentifierLink.d.ts.map +0 -1
- package/build/lib/graphql-document/components/IdentifierLink.js +0 -75
- package/build/lib/graphql-document/components/IdentifierLink.js.map +0 -1
- package/build/lib/graphql-document/components/graphql-document-styles.d.ts +0 -5
- package/build/lib/graphql-document/components/graphql-document-styles.d.ts.map +0 -1
- package/build/lib/graphql-document/components/graphql-document-styles.js +0 -144
- package/build/lib/graphql-document/components/graphql-document-styles.js.map +0 -1
- package/build/lib/graphql-document/components/index.d.ts +0 -5
- package/build/lib/graphql-document/components/index.d.ts.map +0 -1
- package/build/lib/graphql-document/components/index.js +0 -5
- package/build/lib/graphql-document/components/index.js.map +0 -1
- package/build/lib/graphql-document/example.d.ts +0 -25
- package/build/lib/graphql-document/example.d.ts.map +0 -1
- package/build/lib/graphql-document/example.js +0 -140
- package/build/lib/graphql-document/example.js.map +0 -1
- package/build/lib/graphql-document/graphql-document.d.ts +0 -35
- package/build/lib/graphql-document/graphql-document.d.ts.map +0 -1
- package/build/lib/graphql-document/graphql-document.js +0 -36
- package/build/lib/graphql-document/graphql-document.js.map +0 -1
- package/build/lib/graphql-document/hooks/use-tooltip-state.d.ts +0 -43
- package/build/lib/graphql-document/hooks/use-tooltip-state.d.ts.map +0 -1
- package/build/lib/graphql-document/hooks/use-tooltip-state.js +0 -132
- package/build/lib/graphql-document/hooks/use-tooltip-state.js.map +0 -1
- package/build/lib/graphql-document/positioning-simple.d.ts +0 -63
- package/build/lib/graphql-document/positioning-simple.d.ts.map +0 -1
- package/build/lib/graphql-document/positioning-simple.js +0 -185
- package/build/lib/graphql-document/positioning-simple.js.map +0 -1
- package/build/lib/graphql-document/schema-context.d.ts +0 -8
- package/build/lib/graphql-document/schema-context.d.ts.map +0 -1
- package/build/lib/graphql-document/schema-context.js +0 -11
- package/build/lib/graphql-document/schema-context.js.map +0 -1
- package/build/lib/graphql-document/schema-integration.d.ts +0 -135
- package/build/lib/graphql-document/schema-integration.d.ts.map +0 -1
- package/build/lib/graphql-document/schema-integration.js +0 -328
- package/build/lib/graphql-document/schema-integration.js.map +0 -1
- package/build/lib/graphql-document/types.d.ts +0 -117
- package/build/lib/graphql-document/types.d.ts.map +0 -1
- package/build/lib/graphql-document/types.js +0 -2
- package/build/lib/graphql-document/types.js.map +0 -1
- package/build/template/components/ChangelogLayout.d.ts.map +0 -1
- package/build/template/components/ChangelogLayout.js.map +0 -1
- package/build/template/components/CodeHikePre.d.ts +0 -16
- package/build/template/components/CodeHikePre.d.ts.map +0 -1
- package/build/template/components/CodeHikePre.js +0 -37
- package/build/template/components/CodeHikePre.js.map +0 -1
- package/src/lib/graphql-document/$$.ts +0 -4
- package/src/lib/graphql-document/$.test.ts +0 -132
- package/src/lib/graphql-document/$.ts +0 -1
- package/src/lib/graphql-document/README.md +0 -102
- package/src/lib/graphql-document/analysis.ts +0 -415
- package/src/lib/graphql-document/components/GraphQLDocument.tsx +0 -265
- package/src/lib/graphql-document/components/GraphQLDocument.unit.test.ts +0 -188
- package/src/lib/graphql-document/components/GraphQLDocumentWithSchema.tsx +0 -46
- package/src/lib/graphql-document/components/GraphQLIdentifierPopover.tsx +0 -199
- package/src/lib/graphql-document/components/IdentifierLink.tsx +0 -160
- package/src/lib/graphql-document/components/graphql-document-styles.ts +0 -144
- package/src/lib/graphql-document/components/index.ts +0 -4
- package/src/lib/graphql-document/demo.md +0 -155
- package/src/lib/graphql-document/example.ts +0 -163
- package/src/lib/graphql-document/graphql-document.ts +0 -37
- package/src/lib/graphql-document/hooks/use-tooltip-state.test.ts +0 -76
- package/src/lib/graphql-document/hooks/use-tooltip-state.ts +0 -191
- package/src/lib/graphql-document/positioning-simple.test.ts +0 -248
- package/src/lib/graphql-document/positioning-simple.ts +0 -260
- package/src/lib/graphql-document/schema-context.tsx +0 -20
- package/src/lib/graphql-document/schema-integration.test.ts +0 -365
- package/src/lib/graphql-document/schema-integration.ts +0 -488
- package/src/lib/graphql-document/types.ts +0 -129
- package/src/template/components/CodeHikePre.tsx +0 -51
- /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
|
-
})
|