sanity-plugin-internationalized-array 1.10.1 → 1.10.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/lib/index.esm.js +3 -3
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/flattenSchemaType.ts +7 -9
package/lib/index.js
CHANGED
|
@@ -9493,9 +9493,9 @@ fields:[typeof type==="string"?// Define a simple field if all we have is the na
|
|
|
9493
9493
|
sanity.defineField({name:"value",type,components:{// TODO: Address this typing issue with the inner object
|
|
9494
9494
|
// @ts-expect-error
|
|
9495
9495
|
field:InternationalizedField}}):// Pass in the configured options, but overwrite the name
|
|
9496
|
-
{...type,name:"value",components:{field:InternationalizedField}}],preview:{select:{title:"value",subtitle:"_key"}}});};function flattenSchemaType(schemaType){if(!sanity.isDocumentSchemaType(schemaType)){console.error("Schema type is not a document");return[];}return extractInnerFields(schemaType.fields,[],3);}function extractInnerFields(fields,path,maxDepth){if(path.length>=maxDepth){return[];}return fields.reduce((acc,field)=>{const thisFieldWithPath={path:[...path,field.name],...field};if(field.type.jsonType==="object"){const innerFields=extractInnerFields(field.type.fields,[...path,field.name],maxDepth);return[...acc,thisFieldWithPath,...innerFields];}else if(field.type.jsonType==="array"&&
|
|
9496
|
+
{...type,name:"value",components:{field:InternationalizedField}}],preview:{select:{title:"value",subtitle:"_key"}}});};function flattenSchemaType(schemaType){if(!sanity.isDocumentSchemaType(schemaType)){console.error("Schema type is not a document");return[];}return extractInnerFields(schemaType.fields,[],3);}function extractInnerFields(fields,path,maxDepth){if(path.length>=maxDepth){return[];}return fields.reduce((acc,field)=>{const thisFieldWithPath={path:[...path,field.name],...field};if(field.type.jsonType==="object"){const innerFields=extractInnerFields(field.type.fields,[...path,field.name],maxDepth);return[...acc,thisFieldWithPath,...innerFields];}else if(field.type.jsonType==="array"&&field.type.of.length&&field.type.of.some(item=>"fields"in item)){const innerFields=extractInnerFields(// TODO: Fix TS assertion for array fields
|
|
9497
9497
|
// @ts-expect-error
|
|
9498
|
-
field.type.of,[...path,field.name],maxDepth);return[...acc,thisFieldWithPath,...innerFields];}return[...acc,thisFieldWithPath];},[]);}const internationalizedArray=sanity.definePlugin(config=>{const pluginConfig={...CONFIG_DEFAULT,...config};const{apiVersion="2022-11-27",select,languages,fieldTypes,defaultLanguages,buttonLocations}=pluginConfig;return{name:"sanity-plugin-internationalized-array",// Preload languages for use throughout the Studio
|
|
9498
|
+
field.type.of[0].fields,[...path,field.name],maxDepth);return[...acc,thisFieldWithPath,...innerFields];}return[...acc,thisFieldWithPath];},[]);}const internationalizedArray=sanity.definePlugin(config=>{const pluginConfig={...CONFIG_DEFAULT,...config};const{apiVersion="2022-11-27",select,languages,fieldTypes,defaultLanguages,buttonLocations}=pluginConfig;return{name:"sanity-plugin-internationalized-array",// Preload languages for use throughout the Studio
|
|
9499
9499
|
studio:Array.isArray(languages)?void 0:{components:{layout:props=>/* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[/* @__PURE__ */jsxRuntime.jsx(Preload,{apiVersion,languages}),props.renderDefault(props)]})}},// Optional: render "add language" buttons as field actions
|
|
9500
9500
|
document:{unstable_fieldActions:buttonLocations.includes("unstable__fieldAction")?prev=>[...prev,internationalizedArrayFieldAction]:void 0},// Wrap document editor with a language provider
|
|
9501
9501
|
form:{components:{input:props=>{const isRootInput=props.id==="root"&&sanity.isObjectInputProps(props);if(!isRootInput){return props.renderDefault(props);}const flatFieldTypeNames=flattenSchemaType(props.schemaType).map(field=>field.type.name);const hasInternationalizedArray=flatFieldTypeNames.some(name=>name.startsWith("internationalizedArray"));if(!hasInternationalizedArray){return props.renderDefault(props);}return InternationalizedArrayProvider({...props,internationalizedArray:pluginConfig});}}},// Register custom schema types for the outer array and the inner object
|