@nocode-factory/sanity-kit 2.17.2 → 2.18.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/README.md +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +90 -56
- package/dist/index.js.map +1 -1
- package/dist/web-server.js +2 -1
- package/dist/web-server.js.map +1 -1
- package/package.json +1 -1
- package/src/form/OverrideInput.tsx +1 -45
- package/src/form/SlugUrlInput.tsx +60 -0
- package/src/index.ts +16 -2
- package/src/lib/openComponent.ts +1 -2
- package/src/version.ts +1 -1
- package/src/web/previewGrant.ts +4 -1
- package/src/hooks/useInPresentation.ts +0 -26
package/README.md
CHANGED
|
@@ -83,8 +83,8 @@ Dans le Studio :
|
|
|
83
83
|
- **Onglet Composants** : un clic sur un composant (grille ou vue Map) ouvre
|
|
84
84
|
Presentation avec son rendu réel et ses valeurs par défaut côte à côte. Depuis
|
|
85
85
|
la Map, chaque page listée ouvre le formulaire sur l'instance.
|
|
86
|
-
- **
|
|
87
|
-
|
|
86
|
+
- **Champ Slug d'une page** : l'adresse complète de la page en ligne s'affiche
|
|
87
|
+
dessous (préfixe et langue compris), avec « Copier » et « Ouvrir ».
|
|
88
88
|
- **Formulaire d'une page** : une pastille bleue marque tout champ d'instance
|
|
89
89
|
différent de la valeur par défaut. Au survol, elle affiche la valeur par défaut ;
|
|
90
90
|
au clic, le champ revient en héritage. Un champ qui hérite affiche la valeur par
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as defineComponentDefaults, i as defaultsFieldName, n as componentDefaultsMainDocument, o as requiredUnlessDefault, r as componentDefaultsMainDocuments, s as requiredUnlessDefaultFor, t as DEFAULT_COMPONENT_DEFAULTS_TYPE } from "./componentDefaults-CNiuukLt.js";
|
|
2
|
-
import { SanityClient, Schema, Tool, ToolMenuProps } from "sanity";
|
|
3
2
|
import { ReactNode } from "react";
|
|
3
|
+
import { SanityClient, Schema, Tool, ToolMenuProps } from "sanity";
|
|
4
4
|
import { PreviewHeaderProps } from "sanity/presentation";
|
|
5
5
|
/**
|
|
6
6
|
* Configuration publique du plugin. Tout est optionnel sauf `pageTypes` :
|
|
@@ -1303,7 +1303,7 @@ export declare function ActorName(props: {
|
|
|
1303
1303
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1304
1304
|
* le vérifie.
|
|
1305
1305
|
*/
|
|
1306
|
-
export declare const KIT_VERSION = "2.
|
|
1306
|
+
export declare const KIT_VERSION = "2.18.0";
|
|
1307
1307
|
/**
|
|
1308
1308
|
* Données de la page proposées comme colonnes.
|
|
1309
1309
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { a as defineComponentDefaults, i as defaultsFieldName, n as componentDefaultsMainDocument, o as requiredUnlessDefault, r as componentDefaultsMainDocuments, s as requiredUnlessDefaultFor, t as DEFAULT_COMPONENT_DEFAULTS_TYPE } from "./componentDefaults-BY3hQ6aD.js";
|
|
2
|
+
import { createContext, createElement, forwardRef, memo, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
2
3
|
import { ToolLink, defineField, definePlugin, defineType, pathToString, set, unset, useClient, useCurrentUser, useFormValue, useSchema, useUser, useWorkspace } from "sanity";
|
|
3
4
|
import { ClockIcon } from "@sanity/icons/Clock";
|
|
4
5
|
import { ComponentIcon } from "@sanity/icons/Component";
|
|
5
6
|
import { DocumentsIcon } from "@sanity/icons/Documents";
|
|
6
7
|
import { ColorWheelIcon } from "@sanity/icons/ColorWheel";
|
|
7
8
|
import { Badge, Box, Button, Card, Container, Flex, Grid, Select, Spinner, Stack, Tab, TabList, TabPanel, Text, TextArea, TextInput } from "@sanity/ui";
|
|
8
|
-
import { createContext, forwardRef, memo, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
9
9
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
-
import { IntentLink, useRouter
|
|
10
|
+
import { IntentLink, useRouter } from "sanity/router";
|
|
11
11
|
import { EyeOpenIcon } from "@sanity/icons/EyeOpen";
|
|
12
12
|
import { LaunchIcon } from "@sanity/icons/Launch";
|
|
13
13
|
import { ArrowUpIcon } from "@sanity/icons/ArrowUp";
|
|
@@ -1380,7 +1380,7 @@ function explainGrantError(error) {
|
|
|
1380
1380
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1381
1381
|
* le vérifie.
|
|
1382
1382
|
*/
|
|
1383
|
-
const KIT_VERSION = "2.
|
|
1383
|
+
const KIT_VERSION = "2.18.0";
|
|
1384
1384
|
/**
|
|
1385
1385
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1386
1386
|
*
|
|
@@ -1707,7 +1707,7 @@ function useKitUpdate() {
|
|
|
1707
1707
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1708
1708
|
}).catch(() => {}), () => controller.abort();
|
|
1709
1709
|
}, []);
|
|
1710
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1710
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.18.0") > 0);
|
|
1711
1711
|
return {
|
|
1712
1712
|
current: KIT_VERSION,
|
|
1713
1713
|
latest,
|
|
@@ -5891,8 +5891,7 @@ function componentIntentParams(type, namespace, preview, documentId) {
|
|
|
5891
5891
|
* Ouvre un composant : Presentation avec son rendu réel et ses valeurs par
|
|
5892
5892
|
* défaut côte à côte (le document des valeurs par défaut, champ du composant).
|
|
5893
5893
|
* Sans document de valeurs par défaut dans le schéma : la démo du design system
|
|
5894
|
-
* dans un nouvel onglet.
|
|
5895
|
-
* bouton « Modifier l'instance principale » des formulaires.
|
|
5894
|
+
* dans un nouvel onglet. Utilisé par l'onglet Composants (grille, Map).
|
|
5896
5895
|
*/
|
|
5897
5896
|
async function openComponentDefaults(options) {
|
|
5898
5897
|
let { type, config, hasDefaults, client, navigateIntent } = options, preview = config.componentPreview;
|
|
@@ -7579,23 +7578,6 @@ function useComponentDefaults(client, type, languageField, language) {
|
|
|
7579
7578
|
entry.listeners.size === 0 && entry.stop && (entry.stop(), entry.stop = null);
|
|
7580
7579
|
}, [entry]), value;
|
|
7581
7580
|
}
|
|
7582
|
-
/** Noms des outils Presentation du workspace (le nom est configurable). */
|
|
7583
|
-
function presentationToolNames(tools) {
|
|
7584
|
-
return tools.filter((t) => t.__internalApplicationType === "sanity/presentation" || t.name === "presentation").map((t) => t.name);
|
|
7585
|
-
}
|
|
7586
|
-
/** Vrai si l'adresse du Studio est dans un de ces outils (premier segment après la base). */
|
|
7587
|
-
function isInTool(pathname, names) {
|
|
7588
|
-
return pathname.split("/").some((segment) => names.includes(segment));
|
|
7589
|
-
}
|
|
7590
|
-
/**
|
|
7591
|
-
* Le formulaire est-il affiché dans Presentation ? Le routeur sert à se mettre à jour
|
|
7592
|
-
* quand on change d'outil ; l'adresse dit lequel (le formulaire de Presentation est rendu
|
|
7593
|
-
* dans la portée de son outil, qui ne porte pas le nom de l'outil).
|
|
7594
|
-
*/
|
|
7595
|
-
function useInPresentation() {
|
|
7596
|
-
let { tools } = useWorkspace();
|
|
7597
|
-
return useRouterState(), typeof window > "u" ? !1 : isInTool(window.location.pathname, presentationToolNames(tools));
|
|
7598
|
-
}
|
|
7599
7581
|
const LINK_TARGET_FIELDS = [
|
|
7600
7582
|
"page",
|
|
7601
7583
|
"fixedPath",
|
|
@@ -7718,11 +7700,7 @@ function shortValue(value, max = 32) {
|
|
|
7718
7700
|
function createOverrideInput(config) {
|
|
7719
7701
|
let { defaultsType } = config.componentPreview, namespace = config.blockNamespace;
|
|
7720
7702
|
function OverrideInput(props) {
|
|
7721
|
-
let schema = useSchema(), path = props.path, keyed = firstKeyedIndex(path), anchor = keyed >= 0 ? keyed : 0, instance = useFormValue(path.slice(0, anchor + 1)), parent = useFormValue(path.length > 1 ? path.slice(0, -1) : path), resolved = resolveFieldPath(path, anchor, instance, namespace)
|
|
7722
|
-
if (props.schemaType.jsonType === "object" && typeof own?._type == "string" && own._type.startsWith(namespace) && props.path.length > 0 && schema.get(defaultsType)) return /* @__PURE__ */ jsx(WithMainInstance, {
|
|
7723
|
-
...props,
|
|
7724
|
-
type: own._type
|
|
7725
|
-
});
|
|
7703
|
+
let schema = useSchema(), path = props.path, keyed = firstKeyedIndex(path), anchor = keyed >= 0 ? keyed : 0, instance = useFormValue(path.slice(0, anchor + 1)), parent = useFormValue(path.length > 1 ? path.slice(0, -1) : path), resolved = resolveFieldPath(path, anchor, instance, namespace);
|
|
7726
7704
|
if (!resolved || !schema.get(defaultsType) || !carriesDot(props.schemaType)) return props.renderDefault(props);
|
|
7727
7705
|
let shortName = blockName(instance._type, namespace);
|
|
7728
7706
|
return /* @__PURE__ */ jsx(WithDot, {
|
|
@@ -7769,32 +7747,6 @@ function createOverrideInput(config) {
|
|
|
7769
7747
|
})]
|
|
7770
7748
|
});
|
|
7771
7749
|
}
|
|
7772
|
-
function WithMainInstance(props) {
|
|
7773
|
-
let { type, ...inputProps } = props, client = useKitClient(), router = useRouter();
|
|
7774
|
-
if (useInPresentation()) return inputProps.renderDefault(inputProps);
|
|
7775
|
-
let open = () => void openComponentDefaults({
|
|
7776
|
-
type,
|
|
7777
|
-
config,
|
|
7778
|
-
hasDefaults: !0,
|
|
7779
|
-
client,
|
|
7780
|
-
navigateIntent: (i, p) => router.navigateIntent(i, p)
|
|
7781
|
-
});
|
|
7782
|
-
return /* @__PURE__ */ jsxs(Stack, {
|
|
7783
|
-
gap: 3,
|
|
7784
|
-
children: [/* @__PURE__ */ jsx(Flex, {
|
|
7785
|
-
justify: "flex-end",
|
|
7786
|
-
children: /* @__PURE__ */ jsx(Button, {
|
|
7787
|
-
mode: "ghost",
|
|
7788
|
-
tone: "primary",
|
|
7789
|
-
fontSize: 1,
|
|
7790
|
-
padding: 2,
|
|
7791
|
-
text: "Modifier l'instance principale",
|
|
7792
|
-
title: "Valeurs par défaut du composant : elles s'appliquent à toutes ses instances dont le champ est vide",
|
|
7793
|
-
onClick: open
|
|
7794
|
-
})
|
|
7795
|
-
}), inputProps.renderDefault(inputProps)]
|
|
7796
|
-
});
|
|
7797
|
-
}
|
|
7798
7750
|
return OverrideInput;
|
|
7799
7751
|
}
|
|
7800
7752
|
function carriesDot(schemaType) {
|
|
@@ -7853,6 +7805,79 @@ function OverrideDot(props) {
|
|
|
7853
7805
|
});
|
|
7854
7806
|
}
|
|
7855
7807
|
/**
|
|
7808
|
+
* Sous le champ Slug d'une page (types de pages du kit) : l'adresse COMPLÈTE de la
|
|
7809
|
+
* page sur le site en ligne, avec « Copier » et « Ouvrir ». Le slug seul ne dit pas
|
|
7810
|
+
* où la page vivra (préfixe de collection, langue) ; l'adresse se met à jour à
|
|
7811
|
+
* chaque frappe. Même calcul que l'onglet Pages (toPath / toUrl).
|
|
7812
|
+
*/
|
|
7813
|
+
function createSlugUrlInput(config) {
|
|
7814
|
+
function SlugUrlInput(props) {
|
|
7815
|
+
let doc = useFormValue([]), [copied, setCopied] = useState(!1), type = typeof doc?._type == "string" ? doc._type : null, pageType = type ? pageTypeFor(type, config.pageTypes) : null, slug = props.value?.current ?? null, locale = config.i18n ? doc?.[config.i18n.field] ?? null : null, path = pageType ? toPath({
|
|
7816
|
+
slug,
|
|
7817
|
+
path: pageType.path,
|
|
7818
|
+
pathPrefix: pageType.pathPrefix,
|
|
7819
|
+
locale
|
|
7820
|
+
}, config.i18n) : null, url = toUrl(config.previewUrl, path);
|
|
7821
|
+
if (!url) return props.renderDefault(props);
|
|
7822
|
+
let copy = () => {
|
|
7823
|
+
navigator.clipboard.writeText(url).then(() => {
|
|
7824
|
+
setCopied(!0), window.setTimeout(() => setCopied(!1), 1500);
|
|
7825
|
+
});
|
|
7826
|
+
};
|
|
7827
|
+
return /* @__PURE__ */ jsxs(Stack, {
|
|
7828
|
+
gap: 2,
|
|
7829
|
+
children: [props.renderDefault(props), /* @__PURE__ */ jsx(Card, {
|
|
7830
|
+
tone: "primary",
|
|
7831
|
+
padding: 2,
|
|
7832
|
+
radius: 2,
|
|
7833
|
+
border: !0,
|
|
7834
|
+
children: /* @__PURE__ */ jsxs(Flex, {
|
|
7835
|
+
align: "center",
|
|
7836
|
+
gap: 2,
|
|
7837
|
+
children: [
|
|
7838
|
+
/* @__PURE__ */ jsx(Text, {
|
|
7839
|
+
size: 1,
|
|
7840
|
+
muted: !0,
|
|
7841
|
+
style: {
|
|
7842
|
+
flex: 1,
|
|
7843
|
+
minWidth: 0,
|
|
7844
|
+
wordBreak: "break-all"
|
|
7845
|
+
},
|
|
7846
|
+
children: url
|
|
7847
|
+
}),
|
|
7848
|
+
/* @__PURE__ */ jsx(Button, {
|
|
7849
|
+
mode: "ghost",
|
|
7850
|
+
fontSize: 1,
|
|
7851
|
+
padding: 2,
|
|
7852
|
+
text: copied ? "Copié" : "Copier",
|
|
7853
|
+
onClick: copy
|
|
7854
|
+
}),
|
|
7855
|
+
/* @__PURE__ */ jsx(Button, {
|
|
7856
|
+
as: "a",
|
|
7857
|
+
href: url,
|
|
7858
|
+
target: "_blank",
|
|
7859
|
+
rel: "noopener noreferrer",
|
|
7860
|
+
mode: "ghost",
|
|
7861
|
+
fontSize: 1,
|
|
7862
|
+
padding: 2,
|
|
7863
|
+
text: "Ouvrir"
|
|
7864
|
+
})
|
|
7865
|
+
]
|
|
7866
|
+
})
|
|
7867
|
+
})]
|
|
7868
|
+
});
|
|
7869
|
+
}
|
|
7870
|
+
return SlugUrlInput;
|
|
7871
|
+
}
|
|
7872
|
+
function isSlugInput(props) {
|
|
7873
|
+
let t = props.schemaType;
|
|
7874
|
+
for (; t;) {
|
|
7875
|
+
if (t.name === "slug") return !0;
|
|
7876
|
+
t = t.type;
|
|
7877
|
+
}
|
|
7878
|
+
return !1;
|
|
7879
|
+
}
|
|
7880
|
+
/**
|
|
7856
7881
|
* `pageTypes` déduits du registre du starter, pour ne pas redire au kit ce que
|
|
7857
7882
|
* le site sait déjà : l'accueil (chemin fixe `/`) et chaque collection avec
|
|
7858
7883
|
* son préfixe d'URL (`/blog`, `/produits`, ou la racine).
|
|
@@ -8031,7 +8056,16 @@ const NCF_PAGES_TOOL = "ncf-pages", NCF_COMPONENTS_TOOL = "ncf-components", NCF_
|
|
|
8031
8056
|
NCF_COMPONENTS_TOOL,
|
|
8032
8057
|
NCF_HISTORY_TOOL,
|
|
8033
8058
|
NCF_DESIGN_SYSTEM_TOOL
|
|
8034
|
-
]
|
|
8059
|
+
];
|
|
8060
|
+
/** Champs du formulaire : adresse sous le Slug d'une page, pastille sur les sections. */
|
|
8061
|
+
function createKitInput(config) {
|
|
8062
|
+
let Override = createOverrideInput(config), SlugUrl = createSlugUrlInput(config);
|
|
8063
|
+
function KitInput(props) {
|
|
8064
|
+
return isSlugInput(props) ? createElement(SlugUrl, props) : createElement(Override, props);
|
|
8065
|
+
}
|
|
8066
|
+
return KitInput;
|
|
8067
|
+
}
|
|
8068
|
+
const ncfKit = definePlugin((options) => {
|
|
8035
8069
|
let config = resolveConfig(options), issues = validateConfig(config);
|
|
8036
8070
|
return {
|
|
8037
8071
|
name: "@nocode-factory/sanity-kit",
|
|
@@ -8103,7 +8137,7 @@ const NCF_PAGES_TOOL = "ncf-pages", NCF_COMPONENTS_TOOL = "ncf-components", NCF_
|
|
|
8103
8137
|
},
|
|
8104
8138
|
document: { newDocumentOptions: (prev) => prev.filter((option) => option.templateId !== BOARD_LAYOUT_TYPE) },
|
|
8105
8139
|
studio: { components: { toolMenu: createPreviewLauncher(config, issues) } },
|
|
8106
|
-
form: { components: { input:
|
|
8140
|
+
form: { components: { input: createKitInput(config) } }
|
|
8107
8141
|
};
|
|
8108
8142
|
});
|
|
8109
8143
|
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_DEFAULTS_TYPE, 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_DESIGN_SYSTEM_TOOL, NCF_HIDDEN_TYPES, NCF_HISTORY_TOOL, NCF_MORE_TOOL, NCF_PAGES_TOOL, NCF_TOOL_NAMES, NODE_FIELD_TYPE, NODE_HEIGHT, NODE_WIDTH, NcfKitUpdate, NcfPreviewHeader, NcfPreviewLauncher, 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, compareVersions, componentDefaultsMainDocument, componentDefaultsMainDocuments, createPreviewLauncher, customEnvironment, defaultNodeSize, defaultsFieldName, defineComponentDefaults, depth, deriveDocumentColumns, diffDocuments, diffWords, editIntentPath, explainGrantError, fallbackLayout, fetchDetail, fetchTimeline, fillTemplate, filterRows, flatten, formatDocumentValue, groupPageRows, groupValue, hasBlockingIssue, humanizeBlockName, isDraftId, isKitType, isPrerelease, 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, requiredUnlessDefault, requiredUnlessDefaultFor, resolveColorBy, resolveConfig, segments, slugKey, sortRows, summarize, toKebabCase, toPath, toUrl, topLevelBlockCount, uniqueColumnId, upsertLayout, urlOn, useAnnotations, useBoardLayout, useDocumentColumns, useHistory, useInternalColumns, useKitClient, useKitConfig, useKitContext, useKitUpdate, useOccurrences, usePageContents, usePages, usePreviewTarget, useRegistration, validateConfig, withAlpha, withMoreTool };
|