@nocode-factory/sanity-kit 2.63.0-rc.1 → 2.64.0-rc.2
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/CHANGELOG.md +70 -3
- package/bin/check-lcp.mjs +10 -0
- package/bin/ncf-kit.mjs +31 -2
- package/dist/index.d.ts +47 -2
- package/dist/index.js +383 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/form/choices/ChoiceInputs.tsx +268 -0
- package/src/form/choices/inheritedValue.ts +55 -0
- package/src/form/choices/options.ts +59 -0
- package/src/form/choices/withNcfChoiceInputs.ts +54 -0
- package/src/index.ts +2 -0
- package/src/tools/components/BlockCard.tsx +9 -5
- package/src/tools/components/ComponentsTool.tsx +29 -5
- package/src/version.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { ComponentIcon } from "@sanity/icons/Component";
|
|
|
10
10
|
import { DocumentsIcon } from "@sanity/icons/Documents";
|
|
11
11
|
import { ColorWheelIcon } from "@sanity/icons/ColorWheel";
|
|
12
12
|
import { ImagesIcon } from "@sanity/icons/Images";
|
|
13
|
-
import { Badge, Box, Button, Card, Checkbox, Container, Dialog, Flex, Grid, Label, Select, Spinner, Stack, Tab, TabList, TabPanel, Text, TextArea, TextInput } from "@sanity/ui";
|
|
13
|
+
import { Badge, Box, Button, Card, Checkbox, Container, Dialog, Flex, Grid, Label, Radio, Select, Spinner, Stack, Tab, TabList, TabPanel, Text, TextArea, TextInput } from "@sanity/ui";
|
|
14
14
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
15
15
|
import { IntentLink, useRouter } from "sanity/router";
|
|
16
16
|
import { EyeOpenIcon } from "@sanity/icons/EyeOpen";
|
|
@@ -1423,7 +1423,7 @@ function explainGrantError(error) {
|
|
|
1423
1423
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1424
1424
|
* le vérifie.
|
|
1425
1425
|
*/
|
|
1426
|
-
const KIT_VERSION = "2.
|
|
1426
|
+
const KIT_VERSION = "2.64.0-rc.2";
|
|
1427
1427
|
/**
|
|
1428
1428
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1429
1429
|
*
|
|
@@ -1823,7 +1823,7 @@ function InlinePopover(props) {
|
|
|
1823
1823
|
})] });
|
|
1824
1824
|
}
|
|
1825
1825
|
/** Libellé des laissez-passer délivrés pour soi, distinct des liens partagés. */
|
|
1826
|
-
const cache = /* @__PURE__ */ new Map();
|
|
1826
|
+
const cache$1 = /* @__PURE__ */ new Map();
|
|
1827
1827
|
/**
|
|
1828
1828
|
* Ouvre le vrai site, en ligne, dans un nouvel onglet.
|
|
1829
1829
|
*
|
|
@@ -1854,14 +1854,14 @@ function useOpenOnline() {
|
|
|
1854
1854
|
try {
|
|
1855
1855
|
let { projectId, dataset, token } = client.config();
|
|
1856
1856
|
if (!projectId || !dataset) throw Error("unknown_project");
|
|
1857
|
-
let key = `${config.serviceEndpoint}|${projectId}|${dataset}`, grant = cache.get(key);
|
|
1857
|
+
let key = `${config.serviceEndpoint}|${projectId}|${dataset}`, grant = cache$1.get(key);
|
|
1858
1858
|
(!grant || new Date(grant.expiresAt).getTime() - Date.now() < 864e5) && (grant = await requestPreviewGrant(config.serviceEndpoint, {
|
|
1859
1859
|
projectId,
|
|
1860
1860
|
dataset,
|
|
1861
1861
|
sanityToken: token ?? "",
|
|
1862
1862
|
label: "Ouverture depuis le Studio",
|
|
1863
1863
|
days: 30
|
|
1864
|
-
}), cache.set(key, grant));
|
|
1864
|
+
}), cache$1.set(key, grant));
|
|
1865
1865
|
let signed = onlineUrl(environment, perspective, {
|
|
1866
1866
|
path: options.path,
|
|
1867
1867
|
grant: grant.token,
|
|
@@ -1931,7 +1931,7 @@ function useKitUpdate() {
|
|
|
1931
1931
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1932
1932
|
}).catch(() => {}), () => controller.abort();
|
|
1933
1933
|
}, []);
|
|
1934
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1934
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.64.0-rc.2") > 0);
|
|
1935
1935
|
return {
|
|
1936
1936
|
current: KIT_VERSION,
|
|
1937
1937
|
latest,
|
|
@@ -3270,10 +3270,10 @@ function sortRows$1(rows, key, direction, options = {}) {
|
|
|
3270
3270
|
let sorted = [...rows].sort((a, b) => compare(a, b, key, options));
|
|
3271
3271
|
return direction === "asc" ? sorted : sorted.reverse();
|
|
3272
3272
|
}
|
|
3273
|
-
const normalize$
|
|
3273
|
+
const normalize$2 = (value) => value.toLocaleLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "");
|
|
3274
3274
|
function filterRows$1(rows, filters) {
|
|
3275
|
-
let search = filters.search?.trim() ? normalize$
|
|
3276
|
-
return rows.filter((row) => !(filters.types?.length && !filters.types.includes(row.type) || filters.statuses?.length && !filters.statuses.includes(row.status) || filters.locales?.length && row.locale && !filters.locales.includes(row.locale) || search && !`${normalize$
|
|
3275
|
+
let search = filters.search?.trim() ? normalize$2(filters.search.trim()) : null;
|
|
3276
|
+
return rows.filter((row) => !(filters.types?.length && !filters.types.includes(row.type) || filters.statuses?.length && !filters.statuses.includes(row.status) || filters.locales?.length && row.locale && !filters.locales.includes(row.locale) || search && !`${normalize$2(row.title)} ${normalize$2(row.path ?? "")}`.includes(search)));
|
|
3277
3277
|
}
|
|
3278
3278
|
/** Langues réellement présentes, pour ne proposer que des filtres utiles. */
|
|
3279
3279
|
function localesInRows(rows) {
|
|
@@ -7771,7 +7771,7 @@ function useComponentMeta() {
|
|
|
7771
7771
|
* à le lire.
|
|
7772
7772
|
*/
|
|
7773
7773
|
function BlockCard(props) {
|
|
7774
|
-
let { block, occurrence, namespace,
|
|
7774
|
+
let { block, occurrence, namespace, thumbnailUrls, onOpen, onEdit } = props, [attempt, setAttempt] = useState(0), thumbnailUrl = thumbnailUrls[attempt] ?? null, failed = thumbnailUrls.length > 0 && attempt >= thumbnailUrls.length, unused = occurrence.count === 0;
|
|
7775
7775
|
return /* @__PURE__ */ jsxs(Card, {
|
|
7776
7776
|
radius: 3,
|
|
7777
7777
|
shadow: 1,
|
|
@@ -7822,18 +7822,18 @@ function BlockCard(props) {
|
|
|
7822
7822
|
overflow: "hidden",
|
|
7823
7823
|
background: "var(--card-muted-bg-color, rgba(127,127,127,0.08))"
|
|
7824
7824
|
},
|
|
7825
|
-
children: thumbnailUrl
|
|
7825
|
+
children: thumbnailUrl ? /* @__PURE__ */ jsx("img", {
|
|
7826
7826
|
src: thumbnailUrl,
|
|
7827
7827
|
alt: "",
|
|
7828
7828
|
loading: "lazy",
|
|
7829
|
-
onError: () =>
|
|
7829
|
+
onError: () => setAttempt((n) => n + 1),
|
|
7830
7830
|
style: {
|
|
7831
7831
|
width: "100%",
|
|
7832
7832
|
height: "100%",
|
|
7833
7833
|
objectFit: "contain",
|
|
7834
7834
|
display: "block"
|
|
7835
7835
|
}
|
|
7836
|
-
}) : /* @__PURE__ */ jsx(Flex, {
|
|
7836
|
+
}, thumbnailUrl) : /* @__PURE__ */ jsx(Flex, {
|
|
7837
7837
|
align: "center",
|
|
7838
7838
|
justify: "center",
|
|
7839
7839
|
style: { height: "100%" },
|
|
@@ -8428,6 +8428,28 @@ const ORDERS = [
|
|
|
8428
8428
|
}
|
|
8429
8429
|
];
|
|
8430
8430
|
/** Outil Composants, sous son provider d'organisation (groupes + noms). */
|
|
8431
|
+
/**
|
|
8432
|
+
* Vignette d'un composant : d'abord la MOSAÏQUE de toutes ses dispositions
|
|
8433
|
+
* (`<capture>--dispositions.png`, produite par le script des captures du starter), pour
|
|
8434
|
+
* voir d'un coup toutes les variantes disponibles ; à défaut, la capture simple.
|
|
8435
|
+
*/
|
|
8436
|
+
function thumbnailCandidates(url) {
|
|
8437
|
+
if (url.includes("--dispositions")) return [url];
|
|
8438
|
+
let mosaic = url.replace(/(\.[a-z0-9]+)(\?.*)?$/i, "--dispositions$1$2");
|
|
8439
|
+
return mosaic === url ? [url] : [mosaic, url];
|
|
8440
|
+
}
|
|
8441
|
+
/**
|
|
8442
|
+
* Vue par groupes : chaque groupe dans un cadre, un sur deux sur un fond teinté, pour
|
|
8443
|
+
* distinguer les groupes d'un coup d'œil. Teinte tirée des couleurs du thème du Studio
|
|
8444
|
+
* (clair et sombre).
|
|
8445
|
+
*/
|
|
8446
|
+
function groupStyle(index) {
|
|
8447
|
+
return {
|
|
8448
|
+
padding: "1rem 1.25rem 1.25rem",
|
|
8449
|
+
borderRadius: "0.75rem",
|
|
8450
|
+
background: index % 2 ? "color-mix(in srgb, var(--card-fg-color) 5%, var(--card-bg-color))" : void 0
|
|
8451
|
+
};
|
|
8452
|
+
}
|
|
8431
8453
|
function ComponentsTool() {
|
|
8432
8454
|
return /* @__PURE__ */ jsx(ComponentMetaProvider, { children: /* @__PURE__ */ jsx(ComponentsToolInner, {}) });
|
|
8433
8455
|
}
|
|
@@ -8446,7 +8468,7 @@ function ComponentsToolInner() {
|
|
|
8446
8468
|
block: card.block,
|
|
8447
8469
|
occurrence: card.occurrence,
|
|
8448
8470
|
namespace: config.blockNamespace,
|
|
8449
|
-
|
|
8471
|
+
thumbnailUrls: canPreview ? thumbnailCandidates(`${config.previewUrl}${fillTemplate(preview.thumbnail, card.block.name, config.blockNamespace)}`) : [],
|
|
8450
8472
|
onOpen: openComponent ? () => openComponent(card.block.name) : void 0,
|
|
8451
8473
|
onEdit: () => setEditing(card.block.name)
|
|
8452
8474
|
}, card.block.name);
|
|
@@ -8595,8 +8617,10 @@ function ComponentsToolInner() {
|
|
|
8595
8617
|
order: order === "schema" ? "type" : order
|
|
8596
8618
|
}) : grouping ? /* @__PURE__ */ jsxs(Stack, {
|
|
8597
8619
|
gap: 5,
|
|
8598
|
-
children: [grouping.grouped.map(({ group, blocks }) => /* @__PURE__ */ jsxs(Stack, {
|
|
8620
|
+
children: [grouping.grouped.map(({ group, blocks }, index) => /* @__PURE__ */ jsxs(Stack, {
|
|
8599
8621
|
gap: 3,
|
|
8622
|
+
"data-ncf-component-group": group.id,
|
|
8623
|
+
style: groupStyle(index),
|
|
8600
8624
|
children: [/* @__PURE__ */ jsxs(Flex, {
|
|
8601
8625
|
align: "center",
|
|
8602
8626
|
gap: 2,
|
|
@@ -8652,6 +8676,8 @@ function ComponentsToolInner() {
|
|
|
8652
8676
|
})]
|
|
8653
8677
|
}, group.id)), /* @__PURE__ */ jsxs(Stack, {
|
|
8654
8678
|
gap: 3,
|
|
8679
|
+
"data-ncf-component-group": "",
|
|
8680
|
+
style: groupStyle(grouping.grouped.length),
|
|
8655
8681
|
children: [/* @__PURE__ */ jsx(Text, {
|
|
8656
8682
|
size: 2,
|
|
8657
8683
|
weight: "semibold",
|
|
@@ -10960,10 +10986,10 @@ const LINK_TARGET_FIELDS = [
|
|
|
10960
10986
|
function isEmptyValue(value) {
|
|
10961
10987
|
return value == null || value === "" || Array.isArray(value) && value.length === 0;
|
|
10962
10988
|
}
|
|
10963
|
-
const isKeyed = (s) => typeof s == "object" && !!s && !Array.isArray(s) && typeof s._key == "string";
|
|
10989
|
+
const isKeyed$1 = (s) => typeof s == "object" && !!s && !Array.isArray(s) && typeof s._key == "string";
|
|
10964
10990
|
/** Index du premier élément de liste du chemin (l'instance de composant dans le page builder), ou -1. */
|
|
10965
10991
|
function firstKeyedIndex(path) {
|
|
10966
|
-
return path.findIndex(isKeyed);
|
|
10992
|
+
return path.findIndex(isKeyed$1);
|
|
10967
10993
|
}
|
|
10968
10994
|
/**
|
|
10969
10995
|
* Chemin du champ à l'intérieur de l'instance, listes comprises : un élément de
|
|
@@ -10980,7 +11006,7 @@ function resolveFieldPath(path, index, instance, namespace) {
|
|
|
10980
11006
|
if (rest.length === 0) return null;
|
|
10981
11007
|
let out = [], inList = !1, node = instance;
|
|
10982
11008
|
for (let seg of rest) if (typeof seg == "string") out.push(seg), node = node && typeof node == "object" ? node[seg] : void 0;
|
|
10983
|
-
else if (isKeyed(seg) || typeof seg == "number") {
|
|
11009
|
+
else if (isKeyed$1(seg) || typeof seg == "number") {
|
|
10984
11010
|
if (!Array.isArray(node)) return null;
|
|
10985
11011
|
let i = typeof seg == "number" ? seg : node.findIndex((item) => item?._key === seg._key);
|
|
10986
11012
|
if (i < 0 || node[i]?._type === "block") return null;
|
|
@@ -12955,6 +12981,344 @@ function ncfPresentationComponents(options) {
|
|
|
12955
12981
|
unstable_header: { component: NcfPresentationHeader }
|
|
12956
12982
|
};
|
|
12957
12983
|
}
|
|
12984
|
+
const cache = /* @__PURE__ */ new Map();
|
|
12985
|
+
function loadDefaults(client, type, language) {
|
|
12986
|
+
let key = `${type}:${language ?? ""}`, hit = cache.get(key);
|
|
12987
|
+
if (hit && Date.now() - hit.at < 1e4) return hit.value;
|
|
12988
|
+
let value = client.fetch("*[_type == $type && !(_id in path(\"drafts.**\")) && select(defined($language) => language == $language, true)][0]", {
|
|
12989
|
+
type,
|
|
12990
|
+
language
|
|
12991
|
+
}).catch(() => null);
|
|
12992
|
+
return cache.set(key, {
|
|
12993
|
+
at: Date.now(),
|
|
12994
|
+
value
|
|
12995
|
+
}), value;
|
|
12996
|
+
}
|
|
12997
|
+
const isKeyed = (segment) => typeof segment == "object" && !!segment && "_key" in segment;
|
|
12998
|
+
/**
|
|
12999
|
+
* Valeur héritée par le champ `path` (undefined : rien à hériter ici, par exemple dans le
|
|
13000
|
+
* document des valeurs par défaut lui-même ou dans un élément de liste).
|
|
13001
|
+
*/
|
|
13002
|
+
function useInheritedValue(path, defaultsType, namespace) {
|
|
13003
|
+
let client = useClient({ apiVersion: "2024-10-01" }), docType = useFormValue(["_type"]), language = useFormValue(["language"]) ?? null, keyed = path.findIndex(isKeyed), instance = useFormValue(keyed >= 0 ? path.slice(0, keyed + 1) : []), active = docType !== defaultsType && keyed >= 0, [defaults, setDefaults] = useState(null);
|
|
13004
|
+
useEffect(() => {
|
|
13005
|
+
if (!active) return;
|
|
13006
|
+
let live = !0;
|
|
13007
|
+
return loadDefaults(client, defaultsType, language).then((d) => live && setDefaults(d)), () => {
|
|
13008
|
+
live = !1;
|
|
13009
|
+
};
|
|
13010
|
+
}, [
|
|
13011
|
+
client,
|
|
13012
|
+
defaultsType,
|
|
13013
|
+
language,
|
|
13014
|
+
active
|
|
13015
|
+
]);
|
|
13016
|
+
let rel = path.slice(keyed + 1);
|
|
13017
|
+
if (!active || !defaults || !instance?._type || rel.some(isKeyed)) return;
|
|
13018
|
+
let node = defaults[instance._type.startsWith(namespace) ? instance._type.slice(namespace.length) : instance._type];
|
|
13019
|
+
for (let segment of rel) node = node && typeof node == "object" ? node[segment] : void 0;
|
|
13020
|
+
return node;
|
|
13021
|
+
}
|
|
13022
|
+
const normalize$1 = (list = []) => list.map((item) => typeof item == "string" ? {
|
|
13023
|
+
title: item,
|
|
13024
|
+
value: item
|
|
13025
|
+
} : {
|
|
13026
|
+
title: item.title ?? item.value ?? "",
|
|
13027
|
+
value: item.value ?? ""
|
|
13028
|
+
});
|
|
13029
|
+
function Label$1({ text, isDefault, suffix }) {
|
|
13030
|
+
return /* @__PURE__ */ jsxs(Text, {
|
|
13031
|
+
size: 1,
|
|
13032
|
+
weight: isDefault ? "semibold" : "regular",
|
|
13033
|
+
children: [text, isDefault ? ` ${suffix}` : ""]
|
|
13034
|
+
});
|
|
13035
|
+
}
|
|
13036
|
+
function createChoiceInputs(o) {
|
|
13037
|
+
let { labels } = o;
|
|
13038
|
+
function DefaultChoiceInput(props) {
|
|
13039
|
+
let options = props.schemaType.options ?? {}, list = normalize$1(options.list), raw = useInheritedValue(props.path, o.defaultsType, o.namespace), inherited = typeof raw == "string" && raw ? raw : null, parent = props.path[props.path.length - 2], field = props.path[props.path.length - 1], conventional = typeof parent == "string" && typeof field == "string" ? o.fallbacks[`${parent}.${field}`] : void 0, fallback = inherited ?? conventional ?? options.ncfFallback ?? list[0]?.value, current = props.value || fallback, pick = (value) => props.onChange(value === fallback ? unset() : set(value));
|
|
13040
|
+
return options.ncfThumbs ? /* @__PURE__ */ jsx("div", {
|
|
13041
|
+
role: "radiogroup",
|
|
13042
|
+
style: {
|
|
13043
|
+
display: "grid",
|
|
13044
|
+
gridTemplateColumns: "repeat(auto-fill, minmax(132px, 1fr))",
|
|
13045
|
+
gap: 10
|
|
13046
|
+
},
|
|
13047
|
+
children: list.map(({ title, value }) => {
|
|
13048
|
+
let checked = current === value;
|
|
13049
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
13050
|
+
type: "button",
|
|
13051
|
+
role: "radio",
|
|
13052
|
+
"aria-checked": checked,
|
|
13053
|
+
disabled: props.readOnly,
|
|
13054
|
+
onClick: () => pick(value),
|
|
13055
|
+
style: {
|
|
13056
|
+
display: "flex",
|
|
13057
|
+
flexDirection: "column",
|
|
13058
|
+
gap: 6,
|
|
13059
|
+
padding: 8,
|
|
13060
|
+
textAlign: "left",
|
|
13061
|
+
borderRadius: 6,
|
|
13062
|
+
cursor: props.readOnly ? "default" : "pointer",
|
|
13063
|
+
color: "var(--card-fg-color)",
|
|
13064
|
+
background: checked ? "var(--card-bg2-color, transparent)" : "transparent",
|
|
13065
|
+
border: checked ? "2px solid var(--card-focus-ring-color, #2276fc)" : "1px solid var(--card-border-color, #ccc)",
|
|
13066
|
+
margin: +!checked
|
|
13067
|
+
},
|
|
13068
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
13069
|
+
"aria-hidden": "true",
|
|
13070
|
+
style: {
|
|
13071
|
+
display: "block",
|
|
13072
|
+
width: "100%"
|
|
13073
|
+
},
|
|
13074
|
+
dangerouslySetInnerHTML: { __html: options.ncfThumbs?.[value] ?? "" }
|
|
13075
|
+
}), /* @__PURE__ */ jsx(Label$1, {
|
|
13076
|
+
text: title,
|
|
13077
|
+
isDefault: value === fallback,
|
|
13078
|
+
suffix: labels.default
|
|
13079
|
+
})]
|
|
13080
|
+
}, value);
|
|
13081
|
+
})
|
|
13082
|
+
}) : /* @__PURE__ */ jsx(Flex, {
|
|
13083
|
+
wrap: "wrap",
|
|
13084
|
+
style: { gap: "10px 20px" },
|
|
13085
|
+
children: list.map(({ title, value }) => {
|
|
13086
|
+
let swatch = options.ncfSwatches?.[value], color = swatch ? o.colors[swatch]?.value : void 0;
|
|
13087
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
13088
|
+
style: {
|
|
13089
|
+
display: "flex",
|
|
13090
|
+
alignItems: "center",
|
|
13091
|
+
gap: 8,
|
|
13092
|
+
cursor: props.readOnly ? "default" : "pointer"
|
|
13093
|
+
},
|
|
13094
|
+
children: [
|
|
13095
|
+
/* @__PURE__ */ jsx(Radio, {
|
|
13096
|
+
name: props.id,
|
|
13097
|
+
value,
|
|
13098
|
+
checked: current === value,
|
|
13099
|
+
disabled: props.readOnly,
|
|
13100
|
+
onChange: () => pick(value)
|
|
13101
|
+
}),
|
|
13102
|
+
color && /* @__PURE__ */ jsx("span", {
|
|
13103
|
+
"aria-hidden": "true",
|
|
13104
|
+
style: {
|
|
13105
|
+
width: 16,
|
|
13106
|
+
height: 16,
|
|
13107
|
+
borderRadius: 3,
|
|
13108
|
+
background: color,
|
|
13109
|
+
boxShadow: "inset 0 0 0 1px rgba(0, 0, 0, 0.18)",
|
|
13110
|
+
flex: "none"
|
|
13111
|
+
}
|
|
13112
|
+
}),
|
|
13113
|
+
/* @__PURE__ */ jsx(Label$1, {
|
|
13114
|
+
text: title,
|
|
13115
|
+
isDefault: value === fallback,
|
|
13116
|
+
suffix: labels.default
|
|
13117
|
+
})
|
|
13118
|
+
]
|
|
13119
|
+
}, value);
|
|
13120
|
+
})
|
|
13121
|
+
});
|
|
13122
|
+
}
|
|
13123
|
+
let LEVELS = [
|
|
13124
|
+
"h1",
|
|
13125
|
+
"h2",
|
|
13126
|
+
"h3",
|
|
13127
|
+
"h4",
|
|
13128
|
+
"h5",
|
|
13129
|
+
"h6",
|
|
13130
|
+
"p"
|
|
13131
|
+
], sectionDefault = (type) => o.headingLevels.sections[type] ?? o.headingLevels.default, below = (level) => `h${Math.min(Number(level.slice(1)) + 1, 6)}`;
|
|
13132
|
+
function HeadingLevelInput(props) {
|
|
13133
|
+
let options = (props.schemaType.options ?? {}).ncfHeadingLevel ?? {}, parent = useFormValue(props.path.slice(0, -1)), type = options.section ?? parent?._type ?? "", fallback = sectionDefault(type);
|
|
13134
|
+
if (options.item) {
|
|
13135
|
+
let section = parent?.headingLevel || sectionDefault(type);
|
|
13136
|
+
fallback = below(section === "p" ? sectionDefault(type) : section);
|
|
13137
|
+
}
|
|
13138
|
+
let current = props.value || fallback;
|
|
13139
|
+
return /* @__PURE__ */ jsx(Flex, {
|
|
13140
|
+
wrap: "wrap",
|
|
13141
|
+
style: { gap: 16 },
|
|
13142
|
+
children: LEVELS.map((level) => /* @__PURE__ */ jsxs("label", {
|
|
13143
|
+
style: {
|
|
13144
|
+
display: "flex",
|
|
13145
|
+
alignItems: "center",
|
|
13146
|
+
gap: 8,
|
|
13147
|
+
cursor: props.readOnly ? "default" : "pointer"
|
|
13148
|
+
},
|
|
13149
|
+
children: [/* @__PURE__ */ jsx(Radio, {
|
|
13150
|
+
name: props.id,
|
|
13151
|
+
value: level,
|
|
13152
|
+
checked: current === level,
|
|
13153
|
+
disabled: props.readOnly,
|
|
13154
|
+
onChange: () => props.onChange(level === fallback ? unset() : set(level))
|
|
13155
|
+
}), /* @__PURE__ */ jsx(Label$1, {
|
|
13156
|
+
text: level.toUpperCase(),
|
|
13157
|
+
isDefault: level === fallback,
|
|
13158
|
+
suffix: labels.default
|
|
13159
|
+
})]
|
|
13160
|
+
}, level))
|
|
13161
|
+
});
|
|
13162
|
+
}
|
|
13163
|
+
function ItemTextInput(props) {
|
|
13164
|
+
return props.renderDefault({
|
|
13165
|
+
...props,
|
|
13166
|
+
elementProps: {
|
|
13167
|
+
...props.elementProps,
|
|
13168
|
+
placeholder: labels.emptyItem
|
|
13169
|
+
}
|
|
13170
|
+
});
|
|
13171
|
+
}
|
|
13172
|
+
function InheritedListInput(props) {
|
|
13173
|
+
let inherited = useInheritedValue(props.path, o.defaultsType, o.namespace);
|
|
13174
|
+
if (!(!props.value?.length && Array.isArray(inherited) && inherited.length > 0)) return props.renderDefault(props);
|
|
13175
|
+
let defaults = () => structuredClone(inherited);
|
|
13176
|
+
return props.renderDefault({
|
|
13177
|
+
...props,
|
|
13178
|
+
onItemAppend: (item) => {
|
|
13179
|
+
props.onChange(set(defaults())), props.onItemAppend(item);
|
|
13180
|
+
},
|
|
13181
|
+
onItemPrepend: (item) => {
|
|
13182
|
+
props.onChange(set(defaults())), props.onItemPrepend(item);
|
|
13183
|
+
}
|
|
13184
|
+
});
|
|
13185
|
+
}
|
|
13186
|
+
function RangeInput(props) {
|
|
13187
|
+
let { onChange, readOnly, value, schemaType } = props, range = schemaType.options?.range ?? {
|
|
13188
|
+
min: 0,
|
|
13189
|
+
max: 100
|
|
13190
|
+
}, mid = (range.min + range.max) / 2, [draft, setDraft] = useState(typeof value == "number" ? value : mid);
|
|
13191
|
+
useEffect(() => {
|
|
13192
|
+
setDraft(typeof value == "number" ? value : mid);
|
|
13193
|
+
}, [value, mid]);
|
|
13194
|
+
let commit = useCallback(() => {
|
|
13195
|
+
draft !== value && onChange(set(draft));
|
|
13196
|
+
}, [
|
|
13197
|
+
draft,
|
|
13198
|
+
value,
|
|
13199
|
+
onChange
|
|
13200
|
+
]);
|
|
13201
|
+
return /* @__PURE__ */ jsxs(Stack, {
|
|
13202
|
+
gap: 3,
|
|
13203
|
+
children: [
|
|
13204
|
+
/* @__PURE__ */ jsx("style", { children: RANGE_CSS }),
|
|
13205
|
+
/* @__PURE__ */ jsxs(Flex, {
|
|
13206
|
+
align: "center",
|
|
13207
|
+
gap: 3,
|
|
13208
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
13209
|
+
className: "ncf-range-wrap",
|
|
13210
|
+
children: /* @__PURE__ */ jsx("input", {
|
|
13211
|
+
className: "ncf-range",
|
|
13212
|
+
type: "range",
|
|
13213
|
+
min: range.min,
|
|
13214
|
+
max: range.max,
|
|
13215
|
+
step: range.step ?? 1,
|
|
13216
|
+
value: draft,
|
|
13217
|
+
disabled: readOnly,
|
|
13218
|
+
"aria-label": schemaType.title,
|
|
13219
|
+
onChange: (e) => setDraft(Number(e.currentTarget.value)),
|
|
13220
|
+
onPointerUp: commit,
|
|
13221
|
+
onKeyUp: commit,
|
|
13222
|
+
onBlur: commit
|
|
13223
|
+
})
|
|
13224
|
+
}), /* @__PURE__ */ jsxs(Text, {
|
|
13225
|
+
size: 1,
|
|
13226
|
+
weight: "medium",
|
|
13227
|
+
style: {
|
|
13228
|
+
minWidth: "3.5em",
|
|
13229
|
+
textAlign: "right",
|
|
13230
|
+
whiteSpace: "nowrap"
|
|
13231
|
+
},
|
|
13232
|
+
children: [draft > 0 ? `+${draft}` : draft, range.unit ?? ""]
|
|
13233
|
+
})]
|
|
13234
|
+
}),
|
|
13235
|
+
range.labels && /* @__PURE__ */ jsx(Flex, {
|
|
13236
|
+
justify: "space-between",
|
|
13237
|
+
children: range.labels.map((l) => /* @__PURE__ */ jsx(Text, {
|
|
13238
|
+
size: 0,
|
|
13239
|
+
muted: !0,
|
|
13240
|
+
children: l
|
|
13241
|
+
}, l))
|
|
13242
|
+
}),
|
|
13243
|
+
typeof value == "number" && !readOnly && /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(Button, {
|
|
13244
|
+
mode: "bleed",
|
|
13245
|
+
fontSize: 1,
|
|
13246
|
+
padding: 2,
|
|
13247
|
+
text: labels.reset,
|
|
13248
|
+
onClick: () => onChange(unset())
|
|
13249
|
+
}) })
|
|
13250
|
+
]
|
|
13251
|
+
});
|
|
13252
|
+
}
|
|
13253
|
+
return {
|
|
13254
|
+
DefaultChoiceInput,
|
|
13255
|
+
HeadingLevelInput,
|
|
13256
|
+
ItemTextInput,
|
|
13257
|
+
InheritedListInput,
|
|
13258
|
+
RangeInput
|
|
13259
|
+
};
|
|
13260
|
+
}
|
|
13261
|
+
const RANGE_CSS = "\n.ncf-range{-webkit-appearance:none;appearance:none;flex:1;height:24px;margin:0;background:transparent;cursor:pointer}\n.ncf-range:disabled{cursor:default;opacity:.5}\n.ncf-range::-webkit-slider-runnable-track{height:2px;border-radius:2px;background:var(--card-muted-fg-color,#8a8a8a)}\n.ncf-range::-moz-range-track{height:2px;border-radius:2px;background:var(--card-muted-fg-color,#8a8a8a)}\n.ncf-range::-webkit-slider-thumb{-webkit-appearance:none;width:18px;height:18px;margin-top:-8px;border-radius:50%;background:var(--card-focus-ring-color,#2276fc);border:2px solid var(--card-bg-color,#fff);box-shadow:0 0 0 1px var(--card-focus-ring-color,#2276fc)}\n.ncf-range::-moz-range-thumb{width:14px;height:14px;border-radius:50%;background:var(--card-focus-ring-color,#2276fc);border:2px solid var(--card-bg-color,#fff);box-shadow:0 0 0 1px var(--card-focus-ring-color,#2276fc)}\n.ncf-range:focus-visible{outline:2px solid var(--card-focus-ring-color,#2276fc);outline-offset:4px;border-radius:4px}\n.ncf-range-wrap{position:relative;flex:1;display:flex;align-items:center}\n.ncf-range-wrap::before{content:\"\";position:absolute;left:50%;top:50%;width:2px;height:12px;margin:-6px 0 0 -1px;border-radius:1px;background:var(--card-muted-fg-color,#8a8a8a);pointer-events:none}\n", DEFAULT_FALLBACKS = { "secondary.style": "secondary" };
|
|
13262
|
+
function resolveChoiceInputsOptions(input = {}) {
|
|
13263
|
+
return {
|
|
13264
|
+
colors: input.colors ?? {},
|
|
13265
|
+
headingLevels: {
|
|
13266
|
+
default: input.headingLevels?.default ?? "h2",
|
|
13267
|
+
sections: input.headingLevels?.sections ?? {}
|
|
13268
|
+
},
|
|
13269
|
+
defaultsType: input.defaultsType ?? "componentDefaults",
|
|
13270
|
+
namespace: input.namespace ?? "section.",
|
|
13271
|
+
linkType: input.linkType ?? "link",
|
|
13272
|
+
fallbacks: {
|
|
13273
|
+
...DEFAULT_FALLBACKS,
|
|
13274
|
+
...input.fallbacks
|
|
13275
|
+
},
|
|
13276
|
+
labels: {
|
|
13277
|
+
default: input.labels?.default ?? "(default)",
|
|
13278
|
+
reset: input.labels?.reset ?? "Reset",
|
|
13279
|
+
emptyItem: input.labels?.emptyItem ?? "Empty: nothing is shown"
|
|
13280
|
+
}
|
|
13281
|
+
};
|
|
13282
|
+
}
|
|
13283
|
+
/**
|
|
13284
|
+
* Saisies de choix du kit sur les types du projet (sanity.config.ts, `schema.types`) :
|
|
13285
|
+
* sections (et leur document de valeurs par défaut), champs style et size des liens.
|
|
13286
|
+
* Un champ qui a déjà sa propre saisie (components.input) n'est jamais remplacé.
|
|
13287
|
+
* Appliqué dans sanity.config.ts seulement : les scripts qui lisent les schémas
|
|
13288
|
+
* (npm run options, defaults:fill) n'importent aucun composant React.
|
|
13289
|
+
*/
|
|
13290
|
+
function withNcfChoiceInputs(types, options = {}) {
|
|
13291
|
+
let o = resolveChoiceInputsOptions(options), inputs = createChoiceInputs(o), choiceFor = (f) => f.options?.ncfHeadingLevel ? inputs.HeadingLevelInput : inputs.DefaultChoiceInput;
|
|
13292
|
+
function walk(f, inItem = !1) {
|
|
13293
|
+
let out = { ...f };
|
|
13294
|
+
return f.type === "number" && f.options?.range && !f.components?.input ? out.components = {
|
|
13295
|
+
...f.components,
|
|
13296
|
+
input: inputs.RangeInput
|
|
13297
|
+
} : f.type === "string" && f.options?.list?.length && !f.components?.input ? out.components = {
|
|
13298
|
+
...f.components,
|
|
13299
|
+
input: choiceFor(f)
|
|
13300
|
+
} : inItem && f.name && f.name !== "anchor" && f.name !== "alt" && (f.type === "string" || f.type === "text") && !f.components?.input && (out.components = {
|
|
13301
|
+
...f.components,
|
|
13302
|
+
input: inputs.ItemTextInput
|
|
13303
|
+
}), f.type === "array" && f.of?.some((m) => m.type === "object" || m.fields) && !f.components?.input && (out.components = {
|
|
13304
|
+
...f.components,
|
|
13305
|
+
input: inputs.InheritedListInput
|
|
13306
|
+
}), f.fields && (out.fields = f.fields.map((c) => walk(c, inItem))), f.of && (out.of = f.of.map((m) => walk(m, f.type === "array" && !!m.fields))), out;
|
|
13307
|
+
}
|
|
13308
|
+
return types.map((t) => {
|
|
13309
|
+
let type = t;
|
|
13310
|
+
return type.name?.startsWith(o.namespace) || type.name === o.defaultsType ? walk(type) : type.name === o.linkType ? {
|
|
13311
|
+
...type,
|
|
13312
|
+
fields: type.fields?.map((f) => (f.name === "style" || f.name === "size") && f.options?.list?.length && !f.components?.input ? {
|
|
13313
|
+
...f,
|
|
13314
|
+
components: {
|
|
13315
|
+
...f.components,
|
|
13316
|
+
input: inputs.DefaultChoiceInput
|
|
13317
|
+
}
|
|
13318
|
+
} : f)
|
|
13319
|
+
} : t;
|
|
13320
|
+
});
|
|
13321
|
+
}
|
|
12958
13322
|
/** Champs d'un titre affichable d'un document référencé, par ordre de préférence. */
|
|
12959
13323
|
const REFERENCE_TITLE_FIELDS = [
|
|
12960
13324
|
"title",
|
|
@@ -14068,6 +14432,6 @@ function hasLanguageField(schemaType, field) {
|
|
|
14068
14432
|
let fields = schemaType?.fields;
|
|
14069
14433
|
return Array.isArray(fields) && fields.some((f) => f?.name === field);
|
|
14070
14434
|
}
|
|
14071
|
-
export { ANNOTATION_TYPE, ActorName, AssetSourceBrowser, AssetsTool, 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, CodeEditorInput, CodeEmbedInput, CollectionTable, 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, HelpTextStyle, KIT_API_VERSION, KIT_VERSION, NCF_ASSETS_TOOL, 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, NcfKitNavbar, NcfKitUpdate, NcfPreviewHeader, NcfPreviewLauncher, PERSPECTIVES, PROJECTION, SECTION_NODE_TYPE, STATUS_COLORS, STATUS_LABELS, SharePreview, UNSET_LABEL, UPGRADE_COMMAND, addColumn, addColumnOption, announce, applySavedPositions, assetName, assetsInFolder, assignmentMap, baseId, blockName, blockTypesFromSchema, buildCollectionQuery, buildCollectionRows, buildContentsQuery, buildLinkGraph, buildPageRows, buildPagesQuery, codeEditorInput, collectLinks, collectOccurrences, colorForRow, colorFromString, columnId, compareVersions, componentDefaultsMainDocument, componentDefaultsMainDocuments, countByFolder, createPreviewLauncher, customEnvironment, defaultNodeSize, defaultsFieldName, defineCodeEmbedType, defineComponentDefaults, depth, deriveCollectionColumns, deriveDocumentColumns, detectPageBuilderField, diffDocuments, diffWords, discoverCollectionTypes, downloadText, editIntentPath, explainGrantError, fallbackLayout, fetchDetail, fetchTimeline, fillTemplate, filterAssets, filterRows as filterCollectionRows, filterRows$1 as filterRows, fixCrossLanguageReferences, flatten, formatBytes, formatDocumentValue, groupComponents, groupMap, groupPageRows, groupValue, hasBlockingIssue, humanizeBlockName, isDraftId, isImageAsset, isKitType, isPrerelease, isSafeColumnKey, isSafeFieldPath, isTextChange, isVersionId, issuesForTool, keyForPath, kitSchemaTypes, layoutGraph, layoutSectionsMap, localesInRows, mergeVersions, missingPageTypes, moveColumn, nameMap, ncfAllowedOrigins, ncfCollectionTable, ncfCollections, ncfKit, ncfMainDocuments, ncfPresentationComponents, ncfPreviewComponents, normalizeInternalPath, normalizePath, occurrencesForTypes, pageThumbnailUrl, pageTypeFor, pageTypesFromSiteRoutes, pageTypesWithoutBuilder, parentPath, presentationPath, pruneSavedPositions, releaseId, removeColumn, renameColumn, requestPreviewGrant, requiredUnlessDefault, requiredUnlessDefaultFor, resolveColorBy, resolveConfig, resolvePageBuilderField, sectionNamesFromDefaults, segments, slugKey, sortAssets, sortRows as sortCollectionRows, sortRows$1 as sortRows, summarize, thumbnailUrl, titleColumn, toCsv, toKebabCase, toPath, toUrl, topLevelBlockCount, uniqueColumnId, upgradePrompt, upsertLayout, urlOn, useAnnotations, useAssetMeta, useAssetUpload, useAssets, useBoardLayout, useCollection, useComponentNames, useDocumentColumns, useHistory, useInternalColumns, useKitClient, useKitConfig, useKitContext, useKitUpdate, useOccurrences, useOptionalKitConfig, useOptionalKitContext, usePageBuilder, usePageContents, usePages, usePreviewTarget, useRegistration, validateConfig, withAlpha, withCustomNames, withMoreTool, withSameLanguageReferences };
|
|
14435
|
+
export { ANNOTATION_TYPE, ActorName, AssetSourceBrowser, AssetsTool, 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, CodeEditorInput, CodeEmbedInput, CollectionTable, 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, HelpTextStyle, KIT_API_VERSION, KIT_VERSION, NCF_ASSETS_TOOL, 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, NcfKitNavbar, NcfKitUpdate, NcfPreviewHeader, NcfPreviewLauncher, PERSPECTIVES, PROJECTION, SECTION_NODE_TYPE, STATUS_COLORS, STATUS_LABELS, SharePreview, UNSET_LABEL, UPGRADE_COMMAND, addColumn, addColumnOption, announce, applySavedPositions, assetName, assetsInFolder, assignmentMap, baseId, blockName, blockTypesFromSchema, buildCollectionQuery, buildCollectionRows, buildContentsQuery, buildLinkGraph, buildPageRows, buildPagesQuery, codeEditorInput, collectLinks, collectOccurrences, colorForRow, colorFromString, columnId, compareVersions, componentDefaultsMainDocument, componentDefaultsMainDocuments, countByFolder, createPreviewLauncher, customEnvironment, defaultNodeSize, defaultsFieldName, defineCodeEmbedType, defineComponentDefaults, depth, deriveCollectionColumns, deriveDocumentColumns, detectPageBuilderField, diffDocuments, diffWords, discoverCollectionTypes, downloadText, editIntentPath, explainGrantError, fallbackLayout, fetchDetail, fetchTimeline, fillTemplate, filterAssets, filterRows as filterCollectionRows, filterRows$1 as filterRows, fixCrossLanguageReferences, flatten, formatBytes, formatDocumentValue, groupComponents, groupMap, groupPageRows, groupValue, hasBlockingIssue, humanizeBlockName, isDraftId, isImageAsset, isKitType, isPrerelease, isSafeColumnKey, isSafeFieldPath, isTextChange, isVersionId, issuesForTool, keyForPath, kitSchemaTypes, layoutGraph, layoutSectionsMap, localesInRows, mergeVersions, missingPageTypes, moveColumn, nameMap, ncfAllowedOrigins, ncfCollectionTable, ncfCollections, ncfKit, ncfMainDocuments, ncfPresentationComponents, ncfPreviewComponents, normalizeInternalPath, normalizePath, occurrencesForTypes, pageThumbnailUrl, pageTypeFor, pageTypesFromSiteRoutes, pageTypesWithoutBuilder, parentPath, presentationPath, pruneSavedPositions, releaseId, removeColumn, renameColumn, requestPreviewGrant, requiredUnlessDefault, requiredUnlessDefaultFor, resolveColorBy, resolveConfig, resolvePageBuilderField, sectionNamesFromDefaults, segments, slugKey, sortAssets, sortRows as sortCollectionRows, sortRows$1 as sortRows, summarize, thumbnailUrl, titleColumn, toCsv, toKebabCase, toPath, toUrl, topLevelBlockCount, uniqueColumnId, upgradePrompt, upsertLayout, urlOn, useAnnotations, useAssetMeta, useAssetUpload, useAssets, useBoardLayout, useCollection, useComponentNames, useDocumentColumns, useHistory, useInternalColumns, useKitClient, useKitConfig, useKitContext, useKitUpdate, useOccurrences, useOptionalKitConfig, useOptionalKitContext, usePageBuilder, usePageContents, usePages, usePreviewTarget, useRegistration, validateConfig, withAlpha, withCustomNames, withMoreTool, withNcfChoiceInputs, withSameLanguageReferences };
|
|
14072
14436
|
|
|
14073
14437
|
//# sourceMappingURL=index.js.map
|