@nocode-factory/sanity-kit 2.24.0 → 2.25.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 +1 -1
- package/dist/index.js +103 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/form/LanguageMismatch.tsx +85 -0
- package/src/index.ts +3 -1
- package/src/lib/previewLocale.ts +17 -0
- package/src/version.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1340,7 +1340,7 @@ export declare function ActorName(props: {
|
|
|
1340
1340
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1341
1341
|
* le vérifie.
|
|
1342
1342
|
*/
|
|
1343
|
-
export declare const KIT_VERSION = "2.
|
|
1343
|
+
export declare const KIT_VERSION = "2.25.0";
|
|
1344
1344
|
/**
|
|
1345
1345
|
* Données de la page proposées comme colonnes.
|
|
1346
1346
|
*
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ import { RestoreIcon } from "@sanity/icons/Restore";
|
|
|
37
37
|
import { UndoIcon } from "@sanity/icons/Undo";
|
|
38
38
|
import { Tooltip } from "@sanity/ui/tooltip";
|
|
39
39
|
import { EyeClosedIcon } from "@sanity/icons/EyeClosed";
|
|
40
|
+
import { usePresentationNavigate, usePresentationParams } from "sanity/presentation";
|
|
40
41
|
import { useToast } from "@sanity/ui/toast";
|
|
41
42
|
const DEFAULT_PAGE_BUILDER_FIELD = "sections", DEFAULT_SLUG_FIELD = "slug", DEFAULT_TITLE_FIELD = "title", DEFAULT_NOINDEX_FIELDS = ["seo.noindex", "noindex"], DEFAULT_I18N = {
|
|
42
43
|
field: "language",
|
|
@@ -1418,7 +1419,7 @@ function explainGrantError(error) {
|
|
|
1418
1419
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1419
1420
|
* le vérifie.
|
|
1420
1421
|
*/
|
|
1421
|
-
const KIT_VERSION = "2.
|
|
1422
|
+
const KIT_VERSION = "2.25.0";
|
|
1422
1423
|
/**
|
|
1423
1424
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1424
1425
|
*
|
|
@@ -1761,7 +1762,7 @@ function useKitUpdate() {
|
|
|
1761
1762
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1762
1763
|
}).catch(() => {}), () => controller.abort();
|
|
1763
1764
|
}, []);
|
|
1764
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1765
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.25.0") > 0);
|
|
1765
1766
|
return {
|
|
1766
1767
|
current: KIT_VERSION,
|
|
1767
1768
|
latest,
|
|
@@ -8161,6 +8162,105 @@ function withPublishedHint(Inner) {
|
|
|
8161
8162
|
}
|
|
8162
8163
|
return PublishedHint;
|
|
8163
8164
|
}
|
|
8165
|
+
/**
|
|
8166
|
+
* Langue de la page affichée dans l'aperçu, d'après son adresse : premier segment
|
|
8167
|
+
* s'il est une langue autre que la principale (/en/...), sinon la langue principale.
|
|
8168
|
+
*/
|
|
8169
|
+
function localeOfPreview(preview, i18n) {
|
|
8170
|
+
if (!i18n || !preview) return null;
|
|
8171
|
+
let pathname;
|
|
8172
|
+
try {
|
|
8173
|
+
pathname = new URL(preview, "http://preview.local").pathname;
|
|
8174
|
+
} catch {
|
|
8175
|
+
return null;
|
|
8176
|
+
}
|
|
8177
|
+
let first = pathname.split("/").filter(Boolean)[0];
|
|
8178
|
+
return first && first !== i18n.defaultLocale && i18n.locales.includes(first) ? first : i18n.defaultLocale;
|
|
8179
|
+
}
|
|
8180
|
+
/**
|
|
8181
|
+
* Presentation : le panneau d'édition DOIT montrer la langue de l'aperçu. Si le
|
|
8182
|
+
* document édité n'est pas dans la langue de la page affichée (ex. aperçu EN, panneau
|
|
8183
|
+
* FR), un bandeau le dit en haut du formulaire, avec un bouton qui ouvre la bonne
|
|
8184
|
+
* version. Évite de modifier le français en croyant modifier l'anglais.
|
|
8185
|
+
* Structure stable : le formulaire garde sa place, que le bandeau soit là ou non.
|
|
8186
|
+
*/
|
|
8187
|
+
function withLanguageMismatch(Inner, config) {
|
|
8188
|
+
let i18n = config.i18n;
|
|
8189
|
+
function LanguageMismatch(props) {
|
|
8190
|
+
let inner = createElement(Inner, props);
|
|
8191
|
+
return !i18n || props.path.length > 0 ? inner : /* @__PURE__ */ jsxs(Stack, {
|
|
8192
|
+
gap: 4,
|
|
8193
|
+
children: [/* @__PURE__ */ jsx(MismatchCheck, {}), inner]
|
|
8194
|
+
});
|
|
8195
|
+
}
|
|
8196
|
+
function MismatchCheck() {
|
|
8197
|
+
let params = usePresentationParams(!1), language = useFormValue([i18n?.field ?? "language"]), shown = localeOfPreview(params?.preview, i18n);
|
|
8198
|
+
return !params || !language || !shown || language === shown ? null : /* @__PURE__ */ jsx(MismatchBanner, {
|
|
8199
|
+
editing: language,
|
|
8200
|
+
shown
|
|
8201
|
+
});
|
|
8202
|
+
}
|
|
8203
|
+
function MismatchBanner(props) {
|
|
8204
|
+
let { editing, shown } = props, navigate = usePresentationNavigate(), client = useKitClient(), id = useFormValue(["_id"])?.replace(/^drafts\./, ""), type = useFormValue(["_type"]), [target, setTarget] = useState(void 0);
|
|
8205
|
+
return useEffect(() => {
|
|
8206
|
+
if (!id) return;
|
|
8207
|
+
let alive = !0;
|
|
8208
|
+
return client.fetch("*[_type == \"translation.metadata\" && references($id)][0].translations[_key == $lang || language == $lang][0].value._ref", {
|
|
8209
|
+
id,
|
|
8210
|
+
lang: shown
|
|
8211
|
+
}).then((ref) => alive && setTarget(ref ?? null)).catch(() => alive && setTarget(null)), () => {
|
|
8212
|
+
alive = !1;
|
|
8213
|
+
};
|
|
8214
|
+
}, [
|
|
8215
|
+
client,
|
|
8216
|
+
id,
|
|
8217
|
+
shown
|
|
8218
|
+
]), /* @__PURE__ */ jsx(Card, {
|
|
8219
|
+
tone: "caution",
|
|
8220
|
+
padding: 3,
|
|
8221
|
+
radius: 2,
|
|
8222
|
+
border: !0,
|
|
8223
|
+
children: /* @__PURE__ */ jsxs(Flex, {
|
|
8224
|
+
align: "center",
|
|
8225
|
+
gap: 3,
|
|
8226
|
+
wrap: "wrap",
|
|
8227
|
+
children: [/* @__PURE__ */ jsxs(Text, {
|
|
8228
|
+
size: 1,
|
|
8229
|
+
weight: "semibold",
|
|
8230
|
+
style: {
|
|
8231
|
+
flex: 1,
|
|
8232
|
+
minWidth: 200
|
|
8233
|
+
},
|
|
8234
|
+
children: [
|
|
8235
|
+
"You are editing the ",
|
|
8236
|
+
editing.toUpperCase(),
|
|
8237
|
+
" version. The preview shows ",
|
|
8238
|
+
shown.toUpperCase(),
|
|
8239
|
+
"."
|
|
8240
|
+
]
|
|
8241
|
+
}), target && type ? /* @__PURE__ */ jsx(Button, {
|
|
8242
|
+
tone: "caution",
|
|
8243
|
+
fontSize: 1,
|
|
8244
|
+
padding: 2,
|
|
8245
|
+
text: `Edit the ${shown.toUpperCase()} version`,
|
|
8246
|
+
onClick: () => navigate(void 0, {
|
|
8247
|
+
type,
|
|
8248
|
+
id: target
|
|
8249
|
+
})
|
|
8250
|
+
}) : target === null ? /* @__PURE__ */ jsxs(Text, {
|
|
8251
|
+
size: 1,
|
|
8252
|
+
muted: !0,
|
|
8253
|
+
children: [
|
|
8254
|
+
"No ",
|
|
8255
|
+
shown.toUpperCase(),
|
|
8256
|
+
" version of this document yet."
|
|
8257
|
+
]
|
|
8258
|
+
}) : null]
|
|
8259
|
+
})
|
|
8260
|
+
});
|
|
8261
|
+
}
|
|
8262
|
+
return LanguageMismatch;
|
|
8263
|
+
}
|
|
8164
8264
|
const VALUE_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
8165
8265
|
"image",
|
|
8166
8266
|
"file",
|
|
@@ -8686,7 +8786,7 @@ function createKitInput(config) {
|
|
|
8686
8786
|
function KitInput(props) {
|
|
8687
8787
|
return isSlugInput(props) ? createElement(SlugUrl, props) : createElement(Override, props);
|
|
8688
8788
|
}
|
|
8689
|
-
return withPublishedHint(config.i18n ? withTranslationTodo(KitInput, config) : KitInput);
|
|
8789
|
+
return withPublishedHint(config.i18n ? withLanguageMismatch(withTranslationTodo(KitInput, config), config) : KitInput);
|
|
8690
8790
|
}
|
|
8691
8791
|
const ncfKit = definePlugin((options) => {
|
|
8692
8792
|
let config = resolveConfig(options), issues = validateConfig(config);
|