sanity-plugin-internationalized-array

5.3.75.3.8
dist/index.js
~dist/index.jsModified
+57−21
Index: package/dist/index.js
===================================================================
--- package/dist/index.js
+++ package/dist/index.js
@@ -1084,8 +1084,41 @@
 		})
 	});
 };
 /**
+* Option keys this plugin stores on the internationalized array type.
+* They configure languages and validation, and are not options of the
+* underlying value field (string, file, image, and so on).
+*/
+const PLUGIN_OPTION_KEYS = /* @__PURE__ */ new Set([
+	"apiVersion",
+	"languages",
+	"select"
+]);
+function isOptionRecord(options) {
+	return typeof options == "object" && !!options && !Array.isArray(options);
+}
+/**
+* Options from an `internationalizedArray*` field that should be applied to
+* each language row's `value` field.
+*
+* Sanity compiles field `options` onto the array field only. The shared value
+* type never sees them, so `accept`, `collapsed`, `hotspot`, `list`, and
+* similar settings have to be copied when the row renders. Plugin keys stay
+* on the array. Field-usage options override options already set on the value
+* field via `fieldTypes`.
+*/
+function optionsForValueField(arrayFieldOptions, valueFieldOptions) {
+	let valueOptions = isOptionRecord(valueFieldOptions) ? valueFieldOptions : void 0;
+	if (!isOptionRecord(arrayFieldOptions)) return valueOptions;
+	let forwarded;
+	for (let [key, value] of Object.entries(arrayFieldOptions)) PLUGIN_OPTION_KEYS.has(key) || (forwarded ??= {}, forwarded[key] = value);
+	return forwarded ? {
+		...valueOptions,
+		...forwarded
+	} : valueOptions;
+}
+/**
 * Maps an array of Sanity form validation entries to a `@sanity/ui` `CardTone`
 * for visual feedback on internationalized array items.
 *
 * - Returns `'critical'` if any validation has `level: 'error'`
@@ -1192,9 +1225,9 @@
 * - Shows a `Spinner` when languages have not been loaded yet.
 * - Applies a `CardTone` based on validation state via `getToneFromValidation`.
 */
 function InternationalizedInput(props) {
-	let $ = c(51), originalOnChange = props.inputProps.onChange, t0;
+	let $ = c(53), originalOnChange = props.inputProps.onChange, t0;
 	$[0] !== originalOnChange || $[1] !== props.value?.value ? (t0 = (patches) => {
 		if (!Array.isArray(patches)) return originalOnChange(patches);
 		let valueField = props.value?.value;
 		if ((valueField == null || Array.isArray(valueField) && valueField.length === 0) && patches.some(_temp2)) {
@@ -1214,11 +1247,11 @@
 		let language = languages?.find((l_0) => l_0.id === props.value[LANGUAGE_FIELD_NAME]);
 		t2 = keyIsValid && language ? getLanguageDisplay(languageDisplay, language.title, language.id) : "", $[6] = keyIsValid, $[7] = languageDisplay, $[8] = languages, $[9] = props.value, $[10] = t2;
 	} else t2 = $[10];
 	let languageTitle = t2, t3 = props.inputProps, t4;
-	if ($[11] !== keyIsValid || $[12] !== languageTitle || $[13] !== originalOnChange || $[14] !== props.inputProps.members || $[15] !== props.path || $[16] !== props.value) {
+	if ($[11] !== keyIsValid || $[12] !== languageTitle || $[13] !== originalOnChange || $[14] !== props.inputProps.members || $[15] !== props.parentSchemaType?.options || $[16] !== props.path || $[17] !== props.value) {
 		let t5;
-		$[18] !== keyIsValid || $[19] !== languageTitle || $[20] !== originalOnChange || $[21] !== props.path || $[22] !== props.value ? (t5 = (member) => {
+		$[19] !== keyIsValid || $[20] !== languageTitle || $[21] !== originalOnChange || $[22] !== props.parentSchemaType?.options || $[23] !== props.path || $[24] !== props.value ? (t5 = (member) => {
 			if (member.kind !== "field") return member;
 			let field = member.field, schemaType = field?.schemaType, title = props.value.language ? keyIsValid ? /* @__PURE__ */ jsx(Label, {
 				muted: !0,
 				size: 1,
@@ -1226,53 +1259,56 @@
 			}) : /* @__PURE__ */ jsx(ChangeLanguageButton, {
 				value: props.value,
 				path: props.path,
 				onChange: originalOnChange
-			}) : null;
-			return Object.assign({}, member, { field: Object.assign({}, field, { schemaType: Object.assign({}, schemaType, { title }) }) });
-		}, $[18] = keyIsValid, $[19] = languageTitle, $[20] = originalOnChange, $[21] = props.path, $[22] = props.value, $[23] = t5) : t5 = $[23], t4 = props.inputProps.members.filter(_temp4).map(t5), $[11] = keyIsValid, $[12] = languageTitle, $[13] = originalOnChange, $[14] = props.inputProps.members, $[15] = props.path, $[16] = props.value, $[17] = t4;
-	} else t4 = $[17];
+			}) : null, options = optionsForValueField(props.parentSchemaType?.options, schemaType?.options);
+			return Object.assign({}, member, { field: Object.assign({}, field, { schemaType: Object.assign({}, schemaType, {
+				title,
+				...options ? { options } : {}
+			}) }) });
+		}, $[19] = keyIsValid, $[20] = languageTitle, $[21] = originalOnChange, $[22] = props.parentSchemaType?.options, $[23] = props.path, $[24] = props.value, $[25] = t5) : t5 = $[25], t4 = props.inputProps.members.filter(_temp4).map(t5), $[11] = keyIsValid, $[12] = languageTitle, $[13] = originalOnChange, $[14] = props.inputProps.members, $[15] = props.parentSchemaType?.options, $[16] = props.path, $[17] = props.value, $[18] = t4;
+	} else t4 = $[18];
 	let t5;
-	$[24] !== props.inputProps || $[25] !== props.value || $[26] !== t4 || $[27] !== wrappedOnChange ? (t5 = {
+	$[26] !== props.inputProps || $[27] !== props.value || $[28] !== t4 || $[29] !== wrappedOnChange ? (t5 = {
 		...t3,
 		members: t4,
 		value: props.value,
 		onChange: wrappedOnChange
-	}, $[24] = props.inputProps, $[25] = props.value, $[26] = t4, $[27] = wrappedOnChange, $[28] = t5) : t5 = $[28];
+	}, $[26] = props.inputProps, $[27] = props.value, $[28] = t4, $[29] = wrappedOnChange, $[30] = t5) : t5 = $[30];
 	let inlineProps = t5, { validation, value, readOnly } = inlineProps;
 	if (!languages) {
 		let t6;
-		return $[29] === Symbol.for("react.memo_cache_sentinel") ? (t6 = /* @__PURE__ */ jsx(Spinner, {}), $[29] = t6) : t6 = $[29], t6;
+		return $[31] === Symbol.for("react.memo_cache_sentinel") ? (t6 = /* @__PURE__ */ jsx(Spinner, {}), $[31] = t6) : t6 = $[31], t6;
 	}
 	let t6;
-	$[30] !== allowRemovingDefaultLanguages || $[31] !== defaultLanguages || $[32] !== value ? (t6 = !allowRemovingDefaultLanguages && defaultLanguages.includes(value.language), $[30] = allowRemovingDefaultLanguages, $[31] = defaultLanguages, $[32] = value, $[33] = t6) : t6 = $[33];
+	$[32] !== allowRemovingDefaultLanguages || $[33] !== defaultLanguages || $[34] !== value ? (t6 = !allowRemovingDefaultLanguages && defaultLanguages.includes(value.language), $[32] = allowRemovingDefaultLanguages, $[33] = defaultLanguages, $[34] = value, $[35] = t6) : t6 = $[35];
 	let isDefault = t6, t7;
-	$[34] === validation ? t7 = $[35] : (t7 = getToneFromValidation(validation), $[34] = validation, $[35] = t7);
+	$[36] === validation ? t7 = $[37] : (t7 = getToneFromValidation(validation), $[36] = validation, $[37] = t7);
 	let t8;
-	$[36] !== inlineProps || $[37] !== props.inputProps ? (t8 = props.inputProps.renderInput(inlineProps), $[36] = inlineProps, $[37] = props.inputProps, $[38] = t8) : t8 = $[38];
+	$[38] !== inlineProps || $[39] !== props.inputProps ? (t8 = props.inputProps.renderInput(inlineProps), $[38] = inlineProps, $[39] = props.inputProps, $[40] = t8) : t8 = $[40];
 	let t9;
-	$[39] === t8 ? t9 = $[40] : (t9 = /* @__PURE__ */ jsx(Box, {
+	$[41] === t8 ? t9 = $[42] : (t9 = /* @__PURE__ */ jsx(Box, {
 		flex: 1,
 		children: t8
-	}), $[39] = t8, $[40] = t9);
+	}), $[41] = t8, $[42] = t9);
 	let t10 = !!readOnly, t11;
-	$[41] !== isDefault || $[42] !== originalOnChange || $[43] !== t10 ? (t11 = /* @__PURE__ */ jsx(RemoveButton, {
+	$[43] !== isDefault || $[44] !== originalOnChange || $[45] !== t10 ? (t11 = /* @__PURE__ */ jsx(RemoveButton, {
 		isDefault,
 		readOnly: t10,
 		onChange: originalOnChange
-	}), $[41] = isDefault, $[42] = originalOnChange, $[43] = t10, $[44] = t11) : t11 = $[44];
+	}), $[43] = isDefault, $[44] = originalOnChange, $[45] = t10, $[46] = t11) : t11 = $[46];
 	let t12;
-	$[45] !== t11 || $[46] !== t9 ? (t12 = /* @__PURE__ */ jsxs(Flex, {
+	$[47] !== t11 || $[48] !== t9 ? (t12 = /* @__PURE__ */ jsxs(Flex, {
 		align: "flex-end",
 		gap: 2,
 		children: [t9, t11]
-	}), $[45] = t11, $[46] = t9, $[47] = t12) : t12 = $[47];
+	}), $[47] = t11, $[48] = t9, $[49] = t12) : t12 = $[49];
 	let t13;
-	return $[48] !== t12 || $[49] !== t7 ? (t13 = /* @__PURE__ */ jsx(Card, {
+	return $[50] !== t12 || $[51] !== t7 ? (t13 = /* @__PURE__ */ jsx(Card, {
 		paddingTop: 2,
 		tone: t7,
 		children: t12
-	}), $[48] = t12, $[49] = t7, $[50] = t13) : t13 = $[50], t13;
+	}), $[50] = t12, $[51] = t7, $[52] = t13) : t13 = $[52], t13;
 }
 function _temp4(m) {
 	return m.kind === "field" && m.name === "value";
 }