@nocode-factory/sanity-kit 2.0.0 → 2.1.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/dist/index.d.ts CHANGED
@@ -1056,6 +1056,17 @@ export declare function ncfPreviewComponents(): {
1056
1056
  component: typeof NcfPreviewHeader;
1057
1057
  };
1058
1058
  };
1059
+ /**
1060
+ * Délivre un lien de préversion à partager.
1061
+ *
1062
+ * Le lien **est** l'autorisation : celui qui le reçoit voit le site de
1063
+ * préproduction et peut y basculer entre brouillons et contenu en ligne, sans
1064
+ * compte ni connexion. C'est tout l'intérêt pour faire relire un client.
1065
+ *
1066
+ * Il n'est délivré qu'à qui a déjà accès au projet Sanity — le service le
1067
+ * vérifie auprès de Sanity, il ne croit pas le Studio sur parole.
1068
+ */
1069
+ export declare function SharePreview(): import("react").JSX.Element | null;
1059
1070
  /**
1060
1071
  * Appels au service du kit.
1061
1072
  *
@@ -1114,6 +1125,27 @@ export declare function fetchTimeline(endpoint: string, key: string, options?: {
1114
1125
  retentionDays: number;
1115
1126
  }>;
1116
1127
  export declare function fetchDetail(endpoint: string, key: string, eventId: number, signal?: AbortSignal): Promise<HistoryDetail>;
1128
+ interface PreviewGrant {
1129
+ token: string;
1130
+ expiresAt: string;
1131
+ issuedBy: string;
1132
+ }
1133
+ /**
1134
+ * Demande un laissez-passer au service.
1135
+ *
1136
+ * Le jeton Sanity de l'éditeur accompagne la demande : c'est lui, et rien
1137
+ * d'autre, qui prouve au service qu'on a accès au projet. Sans lui la demande
1138
+ * est refusée — le kit étant public, un identifiant de projet ne prouve rien.
1139
+ */
1140
+ export declare function requestPreviewGrant(endpoint: string, payload: {
1141
+ projectId: string;
1142
+ dataset: string;
1143
+ sanityToken: string;
1144
+ label?: string;
1145
+ days?: number;
1146
+ }, signal?: AbortSignal): Promise<PreviewGrant>;
1147
+ /** Messages du service, rendus lisibles pour un éditeur. */
1148
+ export declare function explainGrantError(error: unknown): string;
1117
1149
  interface HistoryState {
1118
1150
  events: HistoryEvent[];
1119
1151
  loading: boolean;
@@ -1159,7 +1191,7 @@ export declare function ActorName(props: {
1159
1191
  * Version du kit, rapportée au service pour savoir quels projets tournent sur
1160
1192
  * quelle version. Tenue à jour avec `package.json`.
1161
1193
  */
1162
- export declare const KIT_VERSION = "2.0.0";
1194
+ export declare const KIT_VERSION = "2.1.0";
1163
1195
  /**
1164
1196
  * Données de la page proposées comme colonnes.
1165
1197
  *
@@ -1639,5 +1671,5 @@ export declare const NCF_TOOL_NAMES: readonly ["ncf-pages", "ncf-components", "n
1639
1671
  * pas le Studio de démarrer : l'onglet concerné affiche le détail à corriger.
1640
1672
  */
1641
1673
  export declare const ncfKit: import("sanity").Plugin<NcfKitConfig>;
1642
- export { type AddColumnInput, type Annotation, type AnnotationsState, type BlockOccurrence, type BlockTypeInfo, type BoardEdge, type BoardGraph, type BoardLayoutState, type BoardNode, CONTENT_SCAN_LIMIT as OCCURRENCE_SCAN_LIMIT, type Change, type ChangeKind, type CollectedLinks, type ColorBy, type ColorOptions, type ConfigIssue, type DeriveOptions, type GroupBy, type GroupOptions, type HistoryDetail, type HistoryEvent, type IssueLevel, type KitContextValue, type LayoutMode, type MergedDoc, type NcfBoardTag, type NcfComponentPreviewConfig, type NcfDocumentColumn, type NcfEnvironment, type NcfHistoryConfig, type NcfI18nConfig, type NcfInternalField, type NcfInternalFieldOption, type NcfKitConfig, type NcfPageTypeConfig, type NcfPageTypeInput, type NcfToolName, type NcfToolsConfig, type NodeLayout, type NodePosition, type OccurrenceInput, type OccurrencePage, type OccurrencesState, type PageContent, type PageContentsState, type PageDoc, type PageFilters, type PageRow, type PageStatus, type PagesState, type PathInput, type Positioned, type PresentationOptions, type PreviewPerspective, type PreviewTargetState, type ProjectStatus, type Registration, type ResolvedComponentPreview, type ResolvedDocumentColumn, type ResolvedHistory, type ResolvedI18n, type ResolvedKitConfig, type ResolvedPageType, type RowColor, type RowGroup, type SchemaFieldLike, type SchemaTypeLike, type SectionLayout, type SectionMapNode, type SectionOrder, type SectionsMapOptions, type Segment, type SiteRoutesRegistry, type SortDirection, type SortKey, type ThumbnailInput, type VersionedDoc };
1674
+ export { type AddColumnInput, type Annotation, type AnnotationsState, type BlockOccurrence, type BlockTypeInfo, type BoardEdge, type BoardGraph, type BoardLayoutState, type BoardNode, CONTENT_SCAN_LIMIT as OCCURRENCE_SCAN_LIMIT, type Change, type ChangeKind, type CollectedLinks, type ColorBy, type ColorOptions, type ConfigIssue, type DeriveOptions, type GroupBy, type GroupOptions, type HistoryDetail, type HistoryEvent, type IssueLevel, type KitContextValue, type LayoutMode, type MergedDoc, type NcfBoardTag, type NcfComponentPreviewConfig, type NcfDocumentColumn, type NcfEnvironment, type NcfHistoryConfig, type NcfI18nConfig, type NcfInternalField, type NcfInternalFieldOption, type NcfKitConfig, type NcfPageTypeConfig, type NcfPageTypeInput, type NcfToolName, type NcfToolsConfig, type NodeLayout, type NodePosition, type OccurrenceInput, type OccurrencePage, type OccurrencesState, type PageContent, type PageContentsState, type PageDoc, type PageFilters, type PageRow, type PageStatus, type PagesState, type PathInput, type Positioned, type PresentationOptions, type PreviewGrant, type PreviewPerspective, type PreviewTargetState, type ProjectStatus, type Registration, type ResolvedComponentPreview, type ResolvedDocumentColumn, type ResolvedHistory, type ResolvedI18n, type ResolvedKitConfig, type ResolvedPageType, type RowColor, type RowGroup, type SchemaFieldLike, type SchemaTypeLike, type SectionLayout, type SectionMapNode, type SectionOrder, type SectionsMapOptions, type Segment, type SiteRoutesRegistry, type SortDirection, type SortKey, type ThumbnailInput, type VersionedDoc };
1643
1675
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ import { CloseIcon } from "@sanity/icons/Close";
11
11
  import { EarthGlobeIcon } from "@sanity/icons/EarthGlobe";
12
12
  import { ProjectsIcon } from "@sanity/icons/Projects";
13
13
  import { CircleIcon } from "@sanity/icons/Circle";
14
+ import { ShareIcon } from "@sanity/icons/Share";
14
15
  import { ChevronDownIcon } from "@sanity/icons/ChevronDown";
15
16
  import { ChevronRightIcon } from "@sanity/icons/ChevronRight";
16
17
  import { ChevronUpIcon } from "@sanity/icons/ChevronUp";
@@ -1220,10 +1221,25 @@ async function fetchDetail(endpoint, key, eventId, signal) {
1220
1221
  }, signal);
1221
1222
  }
1222
1223
  /**
1224
+ * Demande un laissez-passer au service.
1225
+ *
1226
+ * Le jeton Sanity de l'éditeur accompagne la demande : c'est lui, et rien
1227
+ * d'autre, qui prouve au service qu'on a accès au projet. Sans lui la demande
1228
+ * est refusée — le kit étant public, un identifiant de projet ne prouve rien.
1229
+ */
1230
+ async function requestPreviewGrant(endpoint, payload, signal) {
1231
+ return post(`${endpoint}/preview-link`, payload, signal);
1232
+ }
1233
+ /** Messages du service, rendus lisibles pour un éditeur. */
1234
+ function explainGrantError(error) {
1235
+ let code = error instanceof Error ? error.message : String(error);
1236
+ return code === "missing_sanity_token" ? "Votre session Sanity n'expose pas de jeton : impossible de prouver votre accès au projet." : code === "no_project_access" ? "Votre compte n'a pas accès à ce projet Sanity." : code === "project_inactive" ? "Ce projet n'est pas actif chez NoCode Factory." : code === "unknown_project" ? "Ce projet n'est pas enregistré chez NoCode Factory." : "Le lien n'a pas pu être créé.";
1237
+ }
1238
+ /**
1223
1239
  * Version du kit, rapportée au service pour savoir quels projets tournent sur
1224
1240
  * quelle version. Tenue à jour avec `package.json`.
1225
1241
  */
1226
- const KIT_VERSION = "2.0.0";
1242
+ const KIT_VERSION = "2.1.0";
1227
1243
  /**
1228
1244
  * Signale ce Studio au service du kit, une fois par montage.
1229
1245
  *
@@ -2064,7 +2080,179 @@ const hostOf = (url) => {
2064
2080
  } catch {
2065
2081
  return url;
2066
2082
  }
2067
- }, UNSET_LABEL = "Non renseigné", fieldIdOf = (groupBy) => groupBy.startsWith("field:") ? groupBy.slice(6) : null;
2083
+ }, DURATIONS = [
2084
+ {
2085
+ days: 1,
2086
+ label: "1 jour"
2087
+ },
2088
+ {
2089
+ days: 7,
2090
+ label: "7 jours"
2091
+ },
2092
+ {
2093
+ days: 30,
2094
+ label: "30 jours"
2095
+ }
2096
+ ];
2097
+ /**
2098
+ * Délivre un lien de préversion à partager.
2099
+ *
2100
+ * Le lien **est** l'autorisation : celui qui le reçoit voit le site de
2101
+ * préproduction et peut y basculer entre brouillons et contenu en ligne, sans
2102
+ * compte ni connexion. C'est tout l'intérêt pour faire relire un client.
2103
+ *
2104
+ * Il n'est délivré qu'à qui a déjà accès au projet Sanity — le service le
2105
+ * vérifie auprès de Sanity, il ne croit pas le Studio sur parole.
2106
+ */
2107
+ function SharePreview() {
2108
+ let config = useKitConfig(), client = useKitClient(), { environment } = usePreviewTarget(), [link, setLink] = useState(null), [expiresAt, setExpiresAt] = useState(null), [busy, setBusy] = useState(!1), [error, setError] = useState(null), [copied, setCopied] = useState(!1), [label, setLabel] = useState(""), endpoint = config.serviceEndpoint, { projectId, dataset, token } = client.config(), issue = useCallback(async (days) => {
2109
+ if (endpoint && projectId && dataset && environment) {
2110
+ setBusy(!0), setError(null), setCopied(!1);
2111
+ try {
2112
+ let grant = await requestPreviewGrant(endpoint, {
2113
+ projectId,
2114
+ dataset,
2115
+ sanityToken: token ?? "",
2116
+ label: label.trim() || void 0,
2117
+ days
2118
+ }), url = new URL(environment.url);
2119
+ url.searchParams.set("ncf_preview", grant.token), setLink(url.toString()), setExpiresAt(grant.expiresAt);
2120
+ } catch (cause) {
2121
+ setError(explainGrantError(cause));
2122
+ } finally {
2123
+ setBusy(!1);
2124
+ }
2125
+ }
2126
+ }, [
2127
+ endpoint,
2128
+ projectId,
2129
+ dataset,
2130
+ environment,
2131
+ token,
2132
+ label
2133
+ ]), copy = async () => {
2134
+ if (link) try {
2135
+ await navigator.clipboard.writeText(link), setCopied(!0);
2136
+ } catch {
2137
+ setCopied(!1);
2138
+ }
2139
+ };
2140
+ return endpoint ? /* @__PURE__ */ jsx(InlinePopover, {
2141
+ width: 320,
2142
+ trigger: ({ toggle }) => /* @__PURE__ */ jsx(Button, {
2143
+ mode: "bleed",
2144
+ fontSize: 1,
2145
+ padding: 2,
2146
+ icon: ShareIcon,
2147
+ text: "Partager la préversion",
2148
+ title: "Créer un lien que n'importe qui peut ouvrir, sans compte",
2149
+ onClick: toggle
2150
+ }),
2151
+ children: () => /* @__PURE__ */ jsxs(Stack, {
2152
+ gap: 3,
2153
+ padding: 2,
2154
+ children: [
2155
+ /* @__PURE__ */ jsxs(Text, {
2156
+ size: 0,
2157
+ muted: !0,
2158
+ children: [
2159
+ "Un lien qui ouvre ",
2160
+ /* @__PURE__ */ jsx("b", { children: environment?.label ?? "le site" }),
2161
+ " et permet d'y basculer entre brouillons et contenu en ligne. Celui qui l'a n'a besoin d'aucun compte."
2162
+ ]
2163
+ }),
2164
+ !link && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(TextInput, {
2165
+ fontSize: 1,
2166
+ padding: 2,
2167
+ radius: 2,
2168
+ placeholder: "À quoi sert ce lien ? (facultatif)",
2169
+ value: label,
2170
+ onChange: (event) => setLabel(event.currentTarget.value)
2171
+ }), /* @__PURE__ */ jsx(Flex, {
2172
+ gap: 1,
2173
+ children: DURATIONS.map((duration) => /* @__PURE__ */ jsx(Button, {
2174
+ mode: "ghost",
2175
+ fontSize: 1,
2176
+ padding: 2,
2177
+ text: duration.label,
2178
+ disabled: busy,
2179
+ onClick: () => issue(duration.days)
2180
+ }, duration.days))
2181
+ })] }),
2182
+ busy && /* @__PURE__ */ jsxs(Flex, {
2183
+ align: "center",
2184
+ gap: 2,
2185
+ children: [/* @__PURE__ */ jsx(Spinner, { muted: !0 }), /* @__PURE__ */ jsx(Text, {
2186
+ size: 1,
2187
+ muted: !0,
2188
+ children: "Création…"
2189
+ })]
2190
+ }),
2191
+ error && /* @__PURE__ */ jsx(Card, {
2192
+ padding: 3,
2193
+ radius: 2,
2194
+ tone: "critical",
2195
+ children: /* @__PURE__ */ jsx(Text, {
2196
+ size: 1,
2197
+ children: error
2198
+ })
2199
+ }),
2200
+ link && /* @__PURE__ */ jsxs(Stack, {
2201
+ gap: 2,
2202
+ children: [
2203
+ /* @__PURE__ */ jsx(Box, {
2204
+ padding: 2,
2205
+ style: {
2206
+ border: "1px solid var(--card-border-color, rgba(127,127,127,0.22))",
2207
+ borderRadius: 3,
2208
+ maxHeight: 72,
2209
+ overflow: "auto"
2210
+ },
2211
+ children: /* @__PURE__ */ jsx(Text, {
2212
+ size: 0,
2213
+ style: {
2214
+ ...MONO,
2215
+ wordBreak: "break-all"
2216
+ },
2217
+ children: link
2218
+ })
2219
+ }),
2220
+ /* @__PURE__ */ jsxs(Flex, {
2221
+ gap: 2,
2222
+ children: [/* @__PURE__ */ jsx(Button, {
2223
+ mode: "default",
2224
+ tone: "primary",
2225
+ fontSize: 1,
2226
+ padding: 2,
2227
+ icon: copied ? CheckmarkIcon : ShareIcon,
2228
+ text: copied ? "Copié" : "Copier le lien",
2229
+ onClick: copy
2230
+ }), /* @__PURE__ */ jsx(Button, {
2231
+ mode: "bleed",
2232
+ fontSize: 1,
2233
+ padding: 2,
2234
+ text: "Un autre",
2235
+ onClick: () => {
2236
+ setLink(null), setCopied(!1);
2237
+ }
2238
+ })]
2239
+ }),
2240
+ expiresAt && /* @__PURE__ */ jsxs(Text, {
2241
+ size: 0,
2242
+ muted: !0,
2243
+ children: [
2244
+ "Valable jusqu'au ",
2245
+ new Date(expiresAt).toLocaleDateString("fr-FR"),
2246
+ ". Révocable à tout moment par NoCode Factory."
2247
+ ]
2248
+ })
2249
+ ]
2250
+ })
2251
+ ]
2252
+ })
2253
+ }) : null;
2254
+ }
2255
+ const UNSET_LABEL = "Non renseigné", fieldIdOf = (groupBy) => groupBy.startsWith("field:") ? groupBy.slice(6) : null;
2068
2256
  /** Valeur du critère pour une ligne. Chaîne vide = non renseigné. */
2069
2257
  function groupValue(row, groupBy, options) {
2070
2258
  if (groupBy === "type") return row.type;
@@ -4657,6 +4845,13 @@ function PagesTool() {
4657
4845
  onCustomUrl: preview.setCustomUrl,
4658
4846
  customUrl: preview.customUrl
4659
4847
  }),
4848
+ /* @__PURE__ */ jsx(Box, {
4849
+ style: {
4850
+ flex: "none",
4851
+ paddingBottom: 2
4852
+ },
4853
+ children: /* @__PURE__ */ jsx(SharePreview, {})
4854
+ }),
4660
4855
  view === "list" && /* @__PURE__ */ jsx(Box, {
4661
4856
  style: {
4662
4857
  flex: "none",
@@ -6627,6 +6822,6 @@ const NCF_PAGES_TOOL = "ncf-pages", NCF_COMPONENTS_TOOL = "ncf-components", NCF_
6627
6822
  document: { newDocumentOptions: (prev) => prev.filter((option) => option.templateId !== BOARD_LAYOUT_TYPE) }
6628
6823
  };
6629
6824
  });
6630
- export { ANNOTATION_TYPE, ActorName, BOARD_LAYOUT_ID, BOARD_LAYOUT_TYPE, BRAIN_NODE_SIZE, BoardLayoutProvider, COLUMN_TYPE, CONTENT_SCAN_LIMIT, CONTENT_SCAN_LIMIT as OCCURRENCE_SCAN_LIMIT, CUSTOM_ENVIRONMENT_ID, DATA_PREFIX, DEFAULT_BOARD_TAGS, DEFAULT_COMPONENT_PREVIEW, DEFAULT_I18N, DEFAULT_INTERNAL_FIELDS, DEFAULT_MORE_TOOLS, DEFAULT_PAGE_BUILDER_FIELD, DEFAULT_SLUG_FIELD, DEFAULT_TITLE_FIELD, KIT_API_VERSION, KIT_VERSION, NCF_COMPONENTS_TOOL, NCF_HIDDEN_TYPES, NCF_HISTORY_TOOL, NCF_MORE_TOOL, NCF_PAGES_TOOL, NCF_TOOL_NAMES, NODE_FIELD_TYPE, NODE_HEIGHT, NODE_WIDTH, NcfPreviewHeader, PERSPECTIVES, PROJECTION, SECTION_NODE_TYPE, STATUS_COLORS, STATUS_LABELS, UNSET_LABEL, addColumn, addColumnOption, announce, applySavedPositions, baseId, blockName, blockTypesFromSchema, buildContentsQuery, buildLinkGraph, buildPageRows, buildPagesQuery, collectLinks, collectOccurrences, colorForRow, colorFromString, columnId, customEnvironment, defaultNodeSize, depth, deriveDocumentColumns, diffDocuments, diffWords, editIntentPath, fallbackLayout, fetchDetail, fetchTimeline, fillTemplate, filterRows, flatten, formatDocumentValue, groupPageRows, groupValue, hasBlockingIssue, humanizeBlockName, isDraftId, isKitType, isSafeColumnKey, isSafeFieldPath, isTextChange, isVersionId, issuesForTool, keyForPath, kitSchemaTypes, layoutGraph, layoutSectionsMap, localesInRows, mergeVersions, missingPageTypes, moveColumn, ncfAllowedOrigins, ncfKit, ncfPreviewComponents, normalizeInternalPath, normalizePath, occurrencesForTypes, pageThumbnailUrl, pageTypeFor, pageTypesFromSiteRoutes, pageTypesWithoutBuilder, parentPath, presentationPath, pruneSavedPositions, releaseId, removeColumn, renameColumn, resolveColorBy, resolveConfig, segments, slugKey, sortRows, summarize, toKebabCase, toPath, toUrl, topLevelBlockCount, uniqueColumnId, upsertLayout, urlOn, useAnnotations, useBoardLayout, useDocumentColumns, useHistory, useInternalColumns, useKitClient, useKitConfig, useKitContext, useOccurrences, usePageContents, usePages, usePreviewTarget, useRegistration, validateConfig, withAlpha, withMoreTool };
6825
+ export { ANNOTATION_TYPE, ActorName, BOARD_LAYOUT_ID, BOARD_LAYOUT_TYPE, BRAIN_NODE_SIZE, BoardLayoutProvider, COLUMN_TYPE, CONTENT_SCAN_LIMIT, CONTENT_SCAN_LIMIT as OCCURRENCE_SCAN_LIMIT, CUSTOM_ENVIRONMENT_ID, DATA_PREFIX, DEFAULT_BOARD_TAGS, DEFAULT_COMPONENT_PREVIEW, DEFAULT_I18N, DEFAULT_INTERNAL_FIELDS, DEFAULT_MORE_TOOLS, DEFAULT_PAGE_BUILDER_FIELD, DEFAULT_SLUG_FIELD, DEFAULT_TITLE_FIELD, KIT_API_VERSION, KIT_VERSION, NCF_COMPONENTS_TOOL, NCF_HIDDEN_TYPES, NCF_HISTORY_TOOL, NCF_MORE_TOOL, NCF_PAGES_TOOL, NCF_TOOL_NAMES, NODE_FIELD_TYPE, NODE_HEIGHT, NODE_WIDTH, NcfPreviewHeader, PERSPECTIVES, PROJECTION, SECTION_NODE_TYPE, STATUS_COLORS, STATUS_LABELS, SharePreview, UNSET_LABEL, addColumn, addColumnOption, announce, applySavedPositions, baseId, blockName, blockTypesFromSchema, buildContentsQuery, buildLinkGraph, buildPageRows, buildPagesQuery, collectLinks, collectOccurrences, colorForRow, colorFromString, columnId, customEnvironment, defaultNodeSize, depth, deriveDocumentColumns, diffDocuments, diffWords, editIntentPath, explainGrantError, fallbackLayout, fetchDetail, fetchTimeline, fillTemplate, filterRows, flatten, formatDocumentValue, groupPageRows, groupValue, hasBlockingIssue, humanizeBlockName, isDraftId, isKitType, isSafeColumnKey, isSafeFieldPath, isTextChange, isVersionId, issuesForTool, keyForPath, kitSchemaTypes, layoutGraph, layoutSectionsMap, localesInRows, mergeVersions, missingPageTypes, moveColumn, ncfAllowedOrigins, ncfKit, ncfPreviewComponents, normalizeInternalPath, normalizePath, occurrencesForTypes, pageThumbnailUrl, pageTypeFor, pageTypesFromSiteRoutes, pageTypesWithoutBuilder, parentPath, presentationPath, pruneSavedPositions, releaseId, removeColumn, renameColumn, requestPreviewGrant, resolveColorBy, resolveConfig, segments, slugKey, sortRows, summarize, toKebabCase, toPath, toUrl, topLevelBlockCount, uniqueColumnId, upsertLayout, urlOn, useAnnotations, useBoardLayout, useDocumentColumns, useHistory, useInternalColumns, useKitClient, useKitConfig, useKitContext, useOccurrences, usePageContents, usePages, usePreviewTarget, useRegistration, validateConfig, withAlpha, withMoreTool };
6631
6826
 
6632
6827
  //# sourceMappingURL=index.js.map