@nocode-factory/sanity-kit 2.34.0 → 2.35.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 +46 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/actions/PropagatePublish.tsx +4 -1
- package/src/index.ts +14 -1
- package/src/lib/localizeReferences.ts +48 -0
- package/src/lib/translateDocument.ts +3 -0
- package/src/version.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1389,7 +1389,7 @@ export declare function ActorName(props: {
|
|
|
1389
1389
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1390
1390
|
* le vérifie.
|
|
1391
1391
|
*/
|
|
1392
|
-
export declare const KIT_VERSION = "2.
|
|
1392
|
+
export declare const KIT_VERSION = "2.35.0";
|
|
1393
1393
|
/**
|
|
1394
1394
|
* Données de la page proposées comme colonnes.
|
|
1395
1395
|
*
|
package/dist/index.js
CHANGED
|
@@ -1384,7 +1384,7 @@ function explainGrantError(error) {
|
|
|
1384
1384
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1385
1385
|
* le vérifie.
|
|
1386
1386
|
*/
|
|
1387
|
-
const KIT_VERSION = "2.
|
|
1387
|
+
const KIT_VERSION = "2.35.0";
|
|
1388
1388
|
/**
|
|
1389
1389
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1390
1390
|
*
|
|
@@ -1727,7 +1727,7 @@ function useKitUpdate() {
|
|
|
1727
1727
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1728
1728
|
}).catch(() => {}), () => controller.abort();
|
|
1729
1729
|
}, []);
|
|
1730
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1730
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.35.0") > 0);
|
|
1731
1731
|
return {
|
|
1732
1732
|
current: KIT_VERSION,
|
|
1733
1733
|
latest,
|
|
@@ -2924,6 +2924,42 @@ function SharePreview() {
|
|
|
2924
2924
|
})
|
|
2925
2925
|
}) : null;
|
|
2926
2926
|
}
|
|
2927
|
+
/** Références de contenu d'une valeur (hors fichiers et images : leurs assets n'ont pas de langue). */
|
|
2928
|
+
function contentRefs(value, out = /* @__PURE__ */ new Set()) {
|
|
2929
|
+
if (Array.isArray(value)) for (let item of value) contentRefs(item, out);
|
|
2930
|
+
else if (value && typeof value == "object") {
|
|
2931
|
+
let ref = value._ref;
|
|
2932
|
+
typeof ref == "string" && !/^(image|file)-/.test(ref) && out.add(ref.replace(/^drafts\./, ""));
|
|
2933
|
+
for (let [k, v] of Object.entries(value)) k !== "_ref" && contentRefs(v, out);
|
|
2934
|
+
}
|
|
2935
|
+
return out;
|
|
2936
|
+
}
|
|
2937
|
+
/** Remplace chaque référence par celle de `map` (sans toucher au reste). Rend une copie. */
|
|
2938
|
+
function replaceRefs(value, map) {
|
|
2939
|
+
if (Array.isArray(value)) return value.map((item) => replaceRefs(item, map));
|
|
2940
|
+
if (value && typeof value == "object") {
|
|
2941
|
+
let out = {};
|
|
2942
|
+
for (let [k, v] of Object.entries(value)) out[k] = k === "_ref" && typeof v == "string" && map.has(v.replace(/^drafts\./, "")) ? map.get(v.replace(/^drafts\./, "")) : replaceRefs(v, map);
|
|
2943
|
+
return out;
|
|
2944
|
+
}
|
|
2945
|
+
return value;
|
|
2946
|
+
}
|
|
2947
|
+
/**
|
|
2948
|
+
* Version d'une autre langue : chaque référence vers un document traduit pointe la
|
|
2949
|
+
* traduction de CETTE langue (type de publication, catégorie, pages liées...). Une
|
|
2950
|
+
* référence sans traduction dans la langue reste telle quelle (document commun à
|
|
2951
|
+
* toutes les langues, ou traduction pas encore créée).
|
|
2952
|
+
*/
|
|
2953
|
+
async function localizeReferences(client, value, language) {
|
|
2954
|
+
let refs = [...contentRefs(value)];
|
|
2955
|
+
if (!refs.length) return value;
|
|
2956
|
+
let rows = await client.fetch("*[_type == \"translation.metadata\" && count(translations[value._ref in $refs]) > 0]{\n \"pairs\": translations[value._ref in $refs]{\"from\": value._ref, \"to\": ^.translations[_key == $language || language == $language][0].value._ref}\n }.pairs[]", {
|
|
2957
|
+
refs,
|
|
2958
|
+
language
|
|
2959
|
+
}), map = /* @__PURE__ */ new Map();
|
|
2960
|
+
for (let row of rows ?? []) row?.from && row.to && row.to !== row.from && map.set(row.from, row.to);
|
|
2961
|
+
return map.size ? replaceRefs(value, map) : value;
|
|
2962
|
+
}
|
|
2927
2963
|
const isObj$1 = (v) => typeof v == "object" && !!v && !Array.isArray(v);
|
|
2928
2964
|
/** Textes d'une valeur, dans l'ordre. */
|
|
2929
2965
|
function collectTexts$1(value) {
|
|
@@ -3233,7 +3269,7 @@ async function createTranslatedVersion(opts) {
|
|
|
3233
3269
|
} catch (cause) {
|
|
3234
3270
|
aiError = cause instanceof Error ? cause.message : String(cause);
|
|
3235
3271
|
}
|
|
3236
|
-
doc[field] = language;
|
|
3272
|
+
doc[field] = language, Object.assign(doc, await localizeReferences(client, doc, language));
|
|
3237
3273
|
let pageType = config.pageTypes.find((t) => t.type === type), slugField = pageType?.slugField ?? (source.slug?.current ? "slug" : null);
|
|
3238
3274
|
if (slugField && source[slugField]?.current) {
|
|
3239
3275
|
let titleField = pageType?.titleField ?? "title", base = slugify(typeof doc[titleField] == "string" ? doc[titleField] : "") || String(source[slugField].current), slug = base;
|
|
@@ -9130,7 +9166,7 @@ function PropagateDialog(props) {
|
|
|
9130
9166
|
created.aiError && (aiError = created.aiError), (created.published ? published : drafted).push(t.language.toUpperCase());
|
|
9131
9167
|
continue;
|
|
9132
9168
|
}
|
|
9133
|
-
let { _id, _rev, _createdAt, _updatedAt, ...
|
|
9169
|
+
let { _id, _rev, _createdAt, _updatedAt, ...raw } = structuredClone(t.result.document), doc = await localizeReferences(client, raw, t.language), targetId = t.id, kept = overwrite ? [] : t.edited, remaining = t.result.toTranslate, failed = !1, written = [];
|
|
9134
9170
|
if (ai && config.history && remaining.length) {
|
|
9135
9171
|
let toDo = remaining.filter((p) => !kept.includes(p));
|
|
9136
9172
|
try {
|
|
@@ -9930,12 +9966,17 @@ const ncfKit = definePlugin((options) => {
|
|
|
9930
9966
|
},
|
|
9931
9967
|
document: {
|
|
9932
9968
|
newDocumentOptions: (prev) => prev.filter((option) => option.templateId !== BOARD_LAYOUT_TYPE),
|
|
9933
|
-
actions: (prev, context) => config.pageTypeNames.includes(context.schemaType) ? prev.map((action) => action.action === "unpublish" ? RemoveFromSiteAction : action.action === "publish" && config.i18n ? withPropagation(action, config, void 0, { allowCreate: !0 }) : action) : context.schemaType === config.componentPreview.defaultsType && config.i18n ? prev.map((action) => action.action === "publish" ? withPropagation(action, config, config.i18n?.defaultsSourceLocale) : action) : prev
|
|
9969
|
+
actions: (prev, context) => config.pageTypeNames.includes(context.schemaType) ? prev.map((action) => action.action === "unpublish" ? RemoveFromSiteAction : action.action === "publish" && config.i18n ? withPropagation(action, config, void 0, { allowCreate: !0 }) : action) : context.schemaType === config.componentPreview.defaultsType && config.i18n ? prev.map((action) => action.action === "publish" ? withPropagation(action, config, config.i18n?.defaultsSourceLocale) : action) : config.i18n && !isKitType(context.schemaType) && hasLanguageField(context.schema.get(context.schemaType), config.i18n.field) ? prev.map((action) => action.action === "publish" ? withPropagation(action, config, void 0, { allowCreate: !0 }) : action) : prev
|
|
9934
9970
|
},
|
|
9935
9971
|
studio: { components: { toolMenu: createPreviewLauncher(config, issues) } },
|
|
9936
9972
|
form: { components: { input: createKitInput(config) } }
|
|
9937
9973
|
};
|
|
9938
9974
|
});
|
|
9975
|
+
/** Le type de document porte-t-il le champ de langue (traduit document par document) ? */
|
|
9976
|
+
function hasLanguageField(schemaType, field) {
|
|
9977
|
+
let fields = schemaType?.fields;
|
|
9978
|
+
return Array.isArray(fields) && fields.some((f) => f?.name === field);
|
|
9979
|
+
}
|
|
9939
9980
|
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, ncfMainDocuments, ncfPresentationComponents, 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 };
|
|
9940
9981
|
|
|
9941
9982
|
//# sourceMappingURL=index.js.map
|