@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.
Files changed (95) hide show
  1. package/bin/ncf-kit.mjs +201 -0
  2. package/dist/index.d.ts +1643 -0
  3. package/dist/index.js +6632 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/web-server.d.ts +46 -0
  6. package/dist/web-server.js +51 -0
  7. package/dist/web-server.js.map +1 -0
  8. package/dist/web.d.ts +27 -0
  9. package/dist/web.js +117 -0
  10. package/dist/web.js.map +1 -0
  11. package/package.json +90 -0
  12. package/scripts/use-client.mjs +20 -0
  13. package/src/config/defaults.ts +74 -0
  14. package/src/config/resolve.ts +153 -0
  15. package/src/config/types.ts +290 -0
  16. package/src/config/validate.ts +193 -0
  17. package/src/context/BoardLayoutContext.tsx +24 -0
  18. package/src/context/KitContext.tsx +30 -0
  19. package/src/context/PreviewTargetContext.tsx +27 -0
  20. package/src/hooks/useAnnotations.ts +60 -0
  21. package/src/hooks/useBoardLayout.ts +398 -0
  22. package/src/hooks/useColumnOptions.ts +47 -0
  23. package/src/hooks/useDocumentColumns.ts +61 -0
  24. package/src/hooks/useHistory.ts +89 -0
  25. package/src/hooks/useInternalColumns.ts +19 -0
  26. package/src/hooks/useKitClient.ts +15 -0
  27. package/src/hooks/useOccurrences.ts +62 -0
  28. package/src/hooks/usePageContents.ts +65 -0
  29. package/src/hooks/usePages.ts +41 -0
  30. package/src/hooks/usePreviewTarget.ts +162 -0
  31. package/src/hooks/useQueryData.ts +103 -0
  32. package/src/hooks/useRegistration.ts +50 -0
  33. package/src/index.ts +280 -0
  34. package/src/lib/blocks.ts +38 -0
  35. package/src/lib/colors.ts +103 -0
  36. package/src/lib/columns.ts +137 -0
  37. package/src/lib/diff.ts +200 -0
  38. package/src/lib/elkLayout.ts +124 -0
  39. package/src/lib/graph.ts +238 -0
  40. package/src/lib/grouping.ts +116 -0
  41. package/src/lib/links.ts +70 -0
  42. package/src/lib/occurrences.ts +93 -0
  43. package/src/lib/pageThumbnail.ts +43 -0
  44. package/src/lib/pages.ts +199 -0
  45. package/src/lib/paths.ts +68 -0
  46. package/src/lib/query.ts +113 -0
  47. package/src/lib/schemaColumns.ts +162 -0
  48. package/src/lib/schemaTypes.ts +75 -0
  49. package/src/lib/sectionsMap.ts +83 -0
  50. package/src/lib/service.ts +88 -0
  51. package/src/lib/siteRoutes.ts +43 -0
  52. package/src/lib/status.ts +122 -0
  53. package/src/lib/studioLinks.ts +137 -0
  54. package/src/schema/boardLayout.ts +190 -0
  55. package/src/tools/components/BlockCard.tsx +79 -0
  56. package/src/tools/components/ComponentsTool.tsx +171 -0
  57. package/src/tools/components/map/SectionNode.tsx +109 -0
  58. package/src/tools/components/map/SectionsMap.tsx +339 -0
  59. package/src/tools/createToolComponent.tsx +67 -0
  60. package/src/tools/history/ChangeRow.tsx +87 -0
  61. package/src/tools/history/DiffPanel.tsx +227 -0
  62. package/src/tools/history/HistoryTool.tsx +230 -0
  63. package/src/tools/more/MoreTool.tsx +82 -0
  64. package/src/tools/pages/ColumnHeader.tsx +216 -0
  65. package/src/tools/pages/ColumnVisibility.tsx +173 -0
  66. package/src/tools/pages/FieldValue.tsx +327 -0
  67. package/src/tools/pages/PagesTable.tsx +394 -0
  68. package/src/tools/pages/PagesTool.tsx +333 -0
  69. package/src/tools/pages/PagesToolbar.tsx +53 -0
  70. package/src/tools/pages/PathCell.tsx +71 -0
  71. package/src/tools/pages/PreviewTarget.tsx +226 -0
  72. package/src/tools/pages/TagCell.tsx +124 -0
  73. package/src/tools/pages/ViewTabs.tsx +57 -0
  74. package/src/tools/pages/board/BoardView.tsx +661 -0
  75. package/src/tools/pages/board/PageNode.tsx +306 -0
  76. package/src/tools/pages/board/PagePanel.tsx +228 -0
  77. package/src/tools/presentation/PreviewHeader.tsx +75 -0
  78. package/src/tools/shared/AnnotationNode.tsx +126 -0
  79. package/src/ui/ActorName.tsx +20 -0
  80. package/src/ui/ConfigIssues.tsx +41 -0
  81. package/src/ui/InlineCode.tsx +22 -0
  82. package/src/ui/Popover.tsx +85 -0
  83. package/src/ui/ProjectStatusNotice.tsx +58 -0
  84. package/src/ui/QueryError.tsx +16 -0
  85. package/src/ui/QuietInput.tsx +64 -0
  86. package/src/ui/StatusBadge.tsx +11 -0
  87. package/src/ui/ToolPlaceholder.tsx +23 -0
  88. package/src/ui/formatDate.ts +14 -0
  89. package/src/ui/tokens.ts +54 -0
  90. package/src/version.ts +5 -0
  91. package/src/web/PreviewBanner.tsx +115 -0
  92. package/src/web/draftModeToggle.ts +56 -0
  93. package/src/web/environment.ts +21 -0
  94. package/src/web/index.ts +15 -0
  95. 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()
@@ -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'