@nocode-factory/sanity-kit 2.0.0
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/bin/ncf-kit.mjs +201 -0
- package/dist/index.d.ts +1643 -0
- package/dist/index.js +6632 -0
- package/dist/index.js.map +1 -0
- package/dist/web-server.d.ts +46 -0
- package/dist/web-server.js +51 -0
- package/dist/web-server.js.map +1 -0
- package/dist/web.d.ts +27 -0
- package/dist/web.js +117 -0
- package/dist/web.js.map +1 -0
- package/package.json +90 -0
- package/scripts/use-client.mjs +20 -0
- package/src/config/defaults.ts +74 -0
- package/src/config/resolve.ts +153 -0
- package/src/config/types.ts +290 -0
- package/src/config/validate.ts +193 -0
- package/src/context/BoardLayoutContext.tsx +24 -0
- package/src/context/KitContext.tsx +30 -0
- package/src/context/PreviewTargetContext.tsx +27 -0
- package/src/hooks/useAnnotations.ts +60 -0
- package/src/hooks/useBoardLayout.ts +398 -0
- package/src/hooks/useColumnOptions.ts +47 -0
- package/src/hooks/useDocumentColumns.ts +61 -0
- package/src/hooks/useHistory.ts +89 -0
- package/src/hooks/useInternalColumns.ts +19 -0
- package/src/hooks/useKitClient.ts +15 -0
- package/src/hooks/useOccurrences.ts +62 -0
- package/src/hooks/usePageContents.ts +65 -0
- package/src/hooks/usePages.ts +41 -0
- package/src/hooks/usePreviewTarget.ts +162 -0
- package/src/hooks/useQueryData.ts +103 -0
- package/src/hooks/useRegistration.ts +50 -0
- package/src/index.ts +280 -0
- package/src/lib/blocks.ts +38 -0
- package/src/lib/colors.ts +103 -0
- package/src/lib/columns.ts +137 -0
- package/src/lib/diff.ts +200 -0
- package/src/lib/elkLayout.ts +124 -0
- package/src/lib/graph.ts +238 -0
- package/src/lib/grouping.ts +116 -0
- package/src/lib/links.ts +70 -0
- package/src/lib/occurrences.ts +93 -0
- package/src/lib/pageThumbnail.ts +43 -0
- package/src/lib/pages.ts +199 -0
- package/src/lib/paths.ts +68 -0
- package/src/lib/query.ts +113 -0
- package/src/lib/schemaColumns.ts +162 -0
- package/src/lib/schemaTypes.ts +75 -0
- package/src/lib/sectionsMap.ts +83 -0
- package/src/lib/service.ts +88 -0
- package/src/lib/siteRoutes.ts +43 -0
- package/src/lib/status.ts +122 -0
- package/src/lib/studioLinks.ts +137 -0
- package/src/schema/boardLayout.ts +190 -0
- package/src/tools/components/BlockCard.tsx +79 -0
- package/src/tools/components/ComponentsTool.tsx +171 -0
- package/src/tools/components/map/SectionNode.tsx +109 -0
- package/src/tools/components/map/SectionsMap.tsx +339 -0
- package/src/tools/createToolComponent.tsx +67 -0
- package/src/tools/history/ChangeRow.tsx +87 -0
- package/src/tools/history/DiffPanel.tsx +227 -0
- package/src/tools/history/HistoryTool.tsx +230 -0
- package/src/tools/more/MoreTool.tsx +82 -0
- package/src/tools/pages/ColumnHeader.tsx +216 -0
- package/src/tools/pages/ColumnVisibility.tsx +173 -0
- package/src/tools/pages/FieldValue.tsx +327 -0
- package/src/tools/pages/PagesTable.tsx +394 -0
- package/src/tools/pages/PagesTool.tsx +333 -0
- package/src/tools/pages/PagesToolbar.tsx +53 -0
- package/src/tools/pages/PathCell.tsx +71 -0
- package/src/tools/pages/PreviewTarget.tsx +226 -0
- package/src/tools/pages/TagCell.tsx +124 -0
- package/src/tools/pages/ViewTabs.tsx +57 -0
- package/src/tools/pages/board/BoardView.tsx +661 -0
- package/src/tools/pages/board/PageNode.tsx +306 -0
- package/src/tools/pages/board/PagePanel.tsx +228 -0
- package/src/tools/presentation/PreviewHeader.tsx +75 -0
- package/src/tools/shared/AnnotationNode.tsx +126 -0
- package/src/ui/ActorName.tsx +20 -0
- package/src/ui/ConfigIssues.tsx +41 -0
- package/src/ui/InlineCode.tsx +22 -0
- package/src/ui/Popover.tsx +85 -0
- package/src/ui/ProjectStatusNotice.tsx +58 -0
- package/src/ui/QueryError.tsx +16 -0
- package/src/ui/QuietInput.tsx +64 -0
- package/src/ui/StatusBadge.tsx +11 -0
- package/src/ui/ToolPlaceholder.tsx +23 -0
- package/src/ui/formatDate.ts +14 -0
- package/src/ui/tokens.ts +54 -0
- package/src/version.ts +5 -0
- package/src/web/PreviewBanner.tsx +115 -0
- package/src/web/draftModeToggle.ts +56 -0
- package/src/web/environment.ts +21 -0
- package/src/web/index.ts +15 -0
- package/src/web/server.ts +11 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {draftMode} from 'next/headers'
|
|
2
|
+
import {NextResponse} from 'next/server'
|
|
3
|
+
import {isProductionSite} from './environment'
|
|
4
|
+
|
|
5
|
+
export interface DraftModeToggleOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Chemin de repli après la bascule, quand la page d'origine est inconnue.
|
|
8
|
+
* Défaut : la racine.
|
|
9
|
+
*/
|
|
10
|
+
fallbackPath?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Route qui bascule le mode brouillon depuis le site.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* // app/api/draft-mode/toggle/route.ts
|
|
18
|
+
* export const {GET} = ncfDraftModeToggle()
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* **Refusée en production.** Activer le mode brouillon rend le contenu non
|
|
22
|
+
* publié visible à qui atteint l'URL : acceptable sur une préversion, jamais
|
|
23
|
+
* sur le site public. Ce refus est le seul garde-fou du dispositif — il ne
|
|
24
|
+
* dépend d'aucune configuration, et se trompe du bon côté.
|
|
25
|
+
*
|
|
26
|
+
* La route de Sanity, `defineEnableDraftMode`, reste préférable quand on entre
|
|
27
|
+
* par Presentation : elle vérifie un secret lié à la session de l'éditeur.
|
|
28
|
+
* Celle-ci sert le cas où l'on est déjà sur le site, sans Studio.
|
|
29
|
+
*/
|
|
30
|
+
export function ncfDraftModeToggle(options: DraftModeToggleOptions = {}) {
|
|
31
|
+
const fallback = options.fallbackPath ?? '/'
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
async GET(request: Request): Promise<Response> {
|
|
35
|
+
if (isProductionSite()) {
|
|
36
|
+
return NextResponse.json(
|
|
37
|
+
{error: 'Le mode brouillon est désactivé en production.'},
|
|
38
|
+
{status: 403},
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const url = new URL(request.url)
|
|
43
|
+
const draft = await draftMode()
|
|
44
|
+
|
|
45
|
+
if (url.searchParams.get('enable') === 'false') draft.disable()
|
|
46
|
+
else draft.enable()
|
|
47
|
+
|
|
48
|
+
// On revient d'où l'on vient : basculer les données ne doit pas faire
|
|
49
|
+
// perdre sa place au relecteur. Un chemin relatif seulement — une URL
|
|
50
|
+
// absolue ferait de cette route une redirection ouverte.
|
|
51
|
+
const back = url.searchParams.get('redirect')
|
|
52
|
+
const target = back && back.startsWith('/') && !back.startsWith('//') ? back : fallback
|
|
53
|
+
return NextResponse.redirect(new URL(target, request.url))
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outils destinés au **front** d'un site, pas au Studio.
|
|
3
|
+
*
|
|
4
|
+
* Ce point d'entrée n'importe ni `sanity` ni `@sanity/ui` : un site qui
|
|
5
|
+
* l'utilise n'embarque pas le Studio dans son bundle.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Vrai sur le déploiement public du site.
|
|
10
|
+
*
|
|
11
|
+
* `VERCEL_ENV` plutôt qu'une comparaison d'URL : un alias, un domaine ajouté
|
|
12
|
+
* plus tard ou une préversion nommée comme la production feraient mentir la
|
|
13
|
+
* seconde. Hors Vercel, on considère qu'on n'est pas en production — un
|
|
14
|
+
* environnement inconnu mérite le bandeau plutôt que le silence.
|
|
15
|
+
*/
|
|
16
|
+
export function isProductionSite(): boolean {
|
|
17
|
+
return process.env.VERCEL_ENV === 'production'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** L'inverse, pour se lire à l'endroit dans un layout. */
|
|
21
|
+
export const isPreviewSite = (): boolean => !isProductionSite()
|
package/src/web/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Point d'entrée **client** du front.
|
|
3
|
+
*
|
|
4
|
+
* ```tsx
|
|
5
|
+
* import {NcfPreviewBanner} from '@nocode-factory/sanity-kit/web'
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* Séparé de `/web/server` à dessein : un même module ne peut pas importer
|
|
9
|
+
* `next/navigation` et `next/headers`, et Next refuserait le mélange.
|
|
10
|
+
*
|
|
11
|
+
* Rien ici n'importe `sanity` ni `@sanity/ui` : le bundle d'un site reste
|
|
12
|
+
* celui d'un site.
|
|
13
|
+
*/
|
|
14
|
+
export {NcfPreviewBanner} from './PreviewBanner'
|
|
15
|
+
export type {PreviewBannerProps} from './PreviewBanner'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Point d'entrée **serveur** du front : route de bascule et détection
|
|
3
|
+
* d'environnement.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import {ncfDraftModeToggle, isPreviewSite} from '@nocode-factory/sanity-kit/web/server'
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export {ncfDraftModeToggle} from './draftModeToggle'
|
|
10
|
+
export type {DraftModeToggleOptions} from './draftModeToggle'
|
|
11
|
+
export {isProductionSite, isPreviewSite} from './environment'
|