@brillout/docpress 0.12.1 → 0.12.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.
@@ -1,16 +1,18 @@
1
1
  export { Hit }
2
2
 
3
3
  import React from 'react'
4
- import { DocSearch } from '@docsearch/react'
5
- import type { InternalDocSearchHit } from './types'
4
+ import type { DocSearchHit, InternalDocSearchHit, StoredDocSearchHit } from '@docsearch/react'
6
5
  import { Snippet } from './Snippet'
7
6
  import { SourceIcon } from './SourceIcon'
8
7
  import { SelectIcon } from './SelectIcon'
9
8
 
10
- type HitProps = Parameters<typeof DocSearch>[0]['hitComponent']
11
- type ContentType = 'lvl0' | 'lvl1' | 'lvl2' | 'lvl3' | 'lvl4' | 'lvl5' | 'lvl6'
9
+ type HitProps = {
10
+ hit: InternalDocSearchHit | StoredDocSearchHit
11
+ children: React.ReactNode
12
+ }
13
+ type HierarchyType = Exclude<DocSearchHit['type'], 'content'>
12
14
 
13
- const Hit: HitProps = ({ hit }) => {
15
+ function Hit({ hit }: HitProps) {
14
16
  return (
15
17
  <a href={hit.type === 'lvl1' ? hit.url.split('#')[0] : hit.url}>
16
18
  <div className="DocSearch-Hit-Container">
@@ -29,14 +31,14 @@ const Hit: HitProps = ({ hit }) => {
29
31
  <div className="DocSearch-Hit-icon">
30
32
  <SourceIcon type={hit.type} />
31
33
  </div>
32
- {hit.hierarchy[hit.type as ContentType] && hit.type === 'lvl1' && (
34
+ {hit.hierarchy[hit.type as HierarchyType] && hit.type === 'lvl1' && (
33
35
  <div className="DocSearch-Hit-content-wrapper">
34
36
  <Snippet className="DocSearch-Hit-title" hit={hit} attribute="hierarchy.lvl1" />
35
37
  {hit.content && <Snippet className="DocSearch-Hit-path" hit={hit} attribute="content" />}
36
38
  </div>
37
39
  )}
38
40
 
39
- {hit.hierarchy[hit.type as ContentType] &&
41
+ {hit.hierarchy[hit.type as HierarchyType] &&
40
42
  (hit.type === 'lvl2' ||
41
43
  hit.type === 'lvl3' ||
42
44
  hit.type === 'lvl4' ||
@@ -1,5 +1,5 @@
1
1
  import { createElement } from 'react'
2
- import { StoredDocSearchHit } from './types'
2
+ import { InternalDocSearchHit, StoredDocSearchHit } from '@docsearch/react'
3
3
 
4
4
  function getPropertyByPath(object: Record<string, any>, path: string): any {
5
5
  const parts = path.split('.')
@@ -17,7 +17,7 @@ interface SnippetProps<TItem> {
17
17
  [prop: string]: unknown
18
18
  }
19
19
 
20
- export function Snippet<TItem extends StoredDocSearchHit>({
20
+ export function Snippet<TItem extends InternalDocSearchHit | StoredDocSearchHit>({
21
21
  hit,
22
22
  attribute,
23
23
  tagName = 'span',
@@ -26,7 +26,7 @@ export function Snippet<TItem extends StoredDocSearchHit>({
26
26
  let title = ''
27
27
  let lvl2 = ''
28
28
 
29
- if (!hit.__docsearch_parent && hit.type !== 'lvl1' && attribute !== 'content') {
29
+ if (!(hit as InternalDocSearchHit).__docsearch_parent && hit.type !== 'lvl1' && attribute !== 'content') {
30
30
  if (hit.type === 'content') {
31
31
  lvl2 = getPropertyByPath(hit, `_snippetResult.hierarchy.lvl2.value`) || getPropertyByPath(hit, 'hierarchy.lvl2')
32
32
  lvl2 = lvl2 ? ` > ${lvl2}` : ''
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@brillout/docpress",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@brillout/picocolors": "^1.0.10",
7
- "@docsearch/css": "3.6.1",
8
- "@docsearch/react": "3.6.1",
7
+ "@docsearch/css": "3.9.0",
8
+ "@docsearch/react": "3.9.0",
9
9
  "@mdx-js/mdx": "3.0.1",
10
10
  "@mdx-js/react": "3.0.1",
11
11
  "@mdx-js/rollup": "3.0.1",
@@ -1,86 +0,0 @@
1
- export type InternalDocSearchHit = DocSearchHit & {
2
- __docsearch_parent?: InternalDocSearchHit | null
3
- }
4
-
5
- export type StoredDocSearchHit = Omit<InternalDocSearchHit, '_highlightResult' | '_snippetResult'>
6
-
7
- type ContentType = 'content' | 'lvl0' | 'lvl1' | 'lvl2' | 'lvl3' | 'lvl4' | 'lvl5' | 'lvl6'
8
-
9
- interface DocSearchHitAttributeHighlightResult {
10
- value: string
11
- matchLevel: 'full' | 'none' | 'partial'
12
- matchedWords: string[]
13
- fullyHighlighted?: boolean
14
- }
15
-
16
- interface DocSearchHitHighlightResultHierarchy {
17
- lvl0: DocSearchHitAttributeHighlightResult
18
- lvl1: DocSearchHitAttributeHighlightResult
19
- lvl2: DocSearchHitAttributeHighlightResult
20
- lvl3: DocSearchHitAttributeHighlightResult
21
- lvl4: DocSearchHitAttributeHighlightResult
22
- lvl5: DocSearchHitAttributeHighlightResult
23
- lvl6: DocSearchHitAttributeHighlightResult
24
- }
25
-
26
- interface DocSearchHitHighlightResult {
27
- content: DocSearchHitAttributeHighlightResult
28
- hierarchy: DocSearchHitHighlightResultHierarchy
29
- hierarchy_camel: DocSearchHitHighlightResultHierarchy[]
30
- }
31
-
32
- interface DocSearchHitAttributeSnippetResult {
33
- value: string
34
- matchLevel: 'full' | 'none' | 'partial'
35
- }
36
-
37
- interface DocSearchHitSnippetResult {
38
- content: DocSearchHitAttributeSnippetResult
39
- hierarchy: DocSearchHitHighlightResultHierarchy
40
- hierarchy_camel: DocSearchHitHighlightResultHierarchy[]
41
- }
42
-
43
- export declare type DocSearchHit = {
44
- objectID: string
45
- content: string | null
46
- url: string
47
- url_without_anchor: string
48
- type: ContentType
49
- anchor: string | null
50
- hierarchy: {
51
- lvl0: string
52
- lvl1: string
53
- lvl2: string | null
54
- lvl3: string | null
55
- lvl4: string | null
56
- lvl5: string | null
57
- lvl6: string | null
58
- }
59
- _highlightResult: DocSearchHitHighlightResult
60
- _snippetResult: DocSearchHitSnippetResult
61
- _rankingInfo?: {
62
- promoted: boolean
63
- nbTypos: number
64
- firstMatchedWord: number
65
- proximityDistance?: number
66
- geoDistance: number
67
- geoPrecision?: number
68
- nbExactWords: number
69
- words: number
70
- filters: number
71
- userScore: number
72
- matchedGeoLocation?: {
73
- lat: number
74
- lng: number
75
- distance: number
76
- }
77
- }
78
- _distinctSeqID?: number
79
- __autocomplete_indexName?: string
80
- __autocomplete_queryID?: string
81
- __autocomplete_algoliaCredentials?: {
82
- appId: string
83
- apiKey: string
84
- }
85
- __autocomplete_id?: number
86
- }