mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 23:49:51 +00:00
Zeta: Rewrite typeVersions
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
---
|
||||
'create-next-docs-app': patch
|
||||
'next-docs-zeta': patch
|
||||
'next-docs-mdx': patch
|
||||
'next-docs-ui': patch
|
||||
---
|
||||
|
||||
Update tsup & dependencies
|
||||
@@ -8,23 +8,25 @@ export * as Primitive from './ui/tabs'
|
||||
|
||||
type ListenerObject = () => void
|
||||
const valueMap = new Map<string, string>()
|
||||
const listeners: Map<string, ListenerObject[]> = new Map()
|
||||
const listeners: Map<string, Set<ListenerObject>> = new Map()
|
||||
|
||||
function add(id: string, listener: ListenerObject) {
|
||||
if (listeners.has(id)) {
|
||||
listeners.get(id)!.push(listener)
|
||||
listeners.get(id)!.add(listener)
|
||||
} else {
|
||||
listeners.set(id, [listener])
|
||||
listeners.set(id, new Set([listener]))
|
||||
}
|
||||
}
|
||||
|
||||
function remove(id: string, listener: ListenerObject) {
|
||||
listeners.set(id, listeners.get(id)?.filter(ltem => listener !== ltem) ?? [])
|
||||
listeners.get(id)?.delete(listener)
|
||||
}
|
||||
|
||||
function update(id: string, v: string) {
|
||||
function update(id: string, v: string, persist: boolean) {
|
||||
valueMap.set(id, v)
|
||||
listeners.get(id)?.forEach(item => item())
|
||||
|
||||
if (persist) localStorage.setItem(id, v)
|
||||
}
|
||||
|
||||
export function Tabs({
|
||||
@@ -59,7 +61,7 @@ export function Tabs({
|
||||
if (persist) {
|
||||
const previous = localStorage.getItem(id)
|
||||
|
||||
if (previous) update(id, previous)
|
||||
if (previous) update(id, previous, persist)
|
||||
}
|
||||
|
||||
const onUpdate = () => {
|
||||
@@ -77,9 +79,7 @@ export function Tabs({
|
||||
setValue(value)
|
||||
|
||||
if (id) {
|
||||
update(id, value)
|
||||
|
||||
if (persist) localStorage.setItem(id, value)
|
||||
update(id, value, persist)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,9 +65,29 @@
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"*": [
|
||||
"./dist/*.d.ts",
|
||||
"./dist/*.d.mts"
|
||||
"sidebar": [
|
||||
"./dist/sidebar.d.mts"
|
||||
],
|
||||
"breadcrumb": [
|
||||
"./dist/breadcrumb.d.mts"
|
||||
],
|
||||
"toc": [
|
||||
"./dist/toc.d.mts"
|
||||
],
|
||||
"search/client": [
|
||||
"./dist/search/client.d.mts"
|
||||
],
|
||||
"search/shared": [
|
||||
"./dist/search/shared.d.ts"
|
||||
],
|
||||
"search/server": [
|
||||
"./dist/search/server.d.ts"
|
||||
],
|
||||
"server": [
|
||||
"./dist/server.d.mts"
|
||||
],
|
||||
"link": [
|
||||
"./dist/link.d.mts"
|
||||
],
|
||||
"contentlayer": [
|
||||
"./dist/contentlayer/index.d.mts"
|
||||
@@ -75,13 +95,17 @@
|
||||
"contentlayer/configuration": [
|
||||
"./dist/contentlayer/configuration.d.mts"
|
||||
],
|
||||
"search/*": [
|
||||
"./dist/search/*.d.ts",
|
||||
"./dist/search/*.d.mts"
|
||||
"middleware": [
|
||||
"./dist/middleware.d.ts"
|
||||
],
|
||||
"search-algolia/*": [
|
||||
"./dist/search-algolia/*.d.ts",
|
||||
"./dist/search-algolia/*.d.mts"
|
||||
"mdx-plugins": [
|
||||
"./dist/mdx-plugins.d.mts"
|
||||
],
|
||||
"search-algolia/client": [
|
||||
"./dist/search-algolia/client.d.mts"
|
||||
],
|
||||
"search-algolia/server": [
|
||||
"./dist/search-algolia/server.d.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -109,7 +133,7 @@
|
||||
"unist-util-visit": "^4.1.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": ">= 13",
|
||||
"next": ">= 13.4",
|
||||
"react": ">= 18",
|
||||
"react-dom": ">= 18"
|
||||
},
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Hit, SearchOptions } from '@algolia/client-search'
|
||||
import type { SearchIndex } from 'algoliasearch/lite'
|
||||
import { useState } from 'react'
|
||||
import useSWR, { type SWRResponse } from 'swr'
|
||||
import type { BaseIndex } from './shared'
|
||||
import type { BaseIndex } from './server'
|
||||
|
||||
export function groupResults(hits: Hit<BaseIndex>[]): SortedResult[] {
|
||||
const grouped: SortedResult[] = []
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
import type { StructuredData } from '@/mdx-plugins/remark-structure'
|
||||
import type { SearchClient, SearchIndex } from 'algoliasearch'
|
||||
import type { BaseIndex } from './shared'
|
||||
|
||||
type DocumentRecord = {
|
||||
/**
|
||||
@@ -101,3 +100,23 @@ export async function updateDocuments(
|
||||
|
||||
await index.replaceAllObjects(objects)
|
||||
}
|
||||
|
||||
export type BaseIndex = {
|
||||
objectID: string
|
||||
title: string
|
||||
url: string
|
||||
|
||||
section?: string
|
||||
|
||||
/**
|
||||
* The anchor id
|
||||
*/
|
||||
section_id?: string
|
||||
|
||||
/**
|
||||
* The id of page, used for distinct
|
||||
*/
|
||||
page_id: string
|
||||
|
||||
content: string
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
export type BaseIndex = {
|
||||
objectID: string
|
||||
title: string
|
||||
url: string
|
||||
|
||||
section?: string
|
||||
|
||||
/**
|
||||
* The anchor id
|
||||
*/
|
||||
section_id?: string
|
||||
|
||||
/**
|
||||
* The id of page, used for distinct
|
||||
*/
|
||||
page_id: string
|
||||
|
||||
content: string
|
||||
}
|
||||
@@ -35,12 +35,11 @@ export default defineConfig([
|
||||
{
|
||||
...shared,
|
||||
name: 'next-docs-cjs',
|
||||
entry: ['src/{search,search-algolia}/server.ts', 'src/middleware.ts'],
|
||||
entry: [
|
||||
'src/{search,search-algolia}/server.ts',
|
||||
'src/search/shared.ts',
|
||||
'src/middleware.ts'
|
||||
],
|
||||
format: 'cjs'
|
||||
},
|
||||
{
|
||||
name: 'next-docs-types',
|
||||
entry: ['src/{search,search-algolia}/shared.ts'],
|
||||
dts: { only: true }
|
||||
}
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user