sanity-plugin-internationalized-array 1.6.1 → 1.6.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.js CHANGED
@@ -9467,7 +9467,7 @@ var _=runInContext();// Some AMD build optimizers, like r.js, check for conditio
9467
9467
  if(freeModule){// Export for Node.js.
9468
9468
  (freeModule.exports=_)._=_;// Export for CommonJS support.
9469
9469
  freeExports._=_;}else{// Export to the global object.
9470
- root._=_;}}).call(commonjsGlobal);})(lodash,lodash.exports);var lodashExports=lodash.exports;const getSelectedValue=(select,document)=>{if(!select||!document){return{};}const selection=select||{};const selectedValue={};for(const[key,path]of Object.entries(selection)){let value=lodashExports.get(document,path);if(Array.isArray(value)){value=value.filter(item=>typeof item==="object"?(item==null?void 0:item._type)==="reference"&&"_ref"in item:true);}selectedValue[key]=value;}return selectedValue;};const schemaExample={languages:[{id:"en",title:"English"},{id:"no",title:"Norsk"}]};function Feedback(){return/* @__PURE__ */jsxRuntime.jsx(ui.Card,{tone:"caution",border:true,radius:2,padding:3,children:/* @__PURE__ */jsxRuntime.jsxs(ui.Stack,{space:4,children:[/* @__PURE__ */jsxRuntime.jsxs(ui.Text,{children:["An array of language objects must be passed into the ",/* @__PURE__ */jsxRuntime.jsx("code",{children:"internationalizedArray"})," ","helper function, each with an ",/* @__PURE__ */jsxRuntime.jsx("code",{children:"id"})," and ",/* @__PURE__ */jsxRuntime.jsx("code",{children:"title"})," field. Example:"]}),/* @__PURE__ */jsxRuntime.jsx(ui.Card,{padding:2,border:true,radius:2,children:/* @__PURE__ */jsxRuntime.jsx(ui.Code,{size:1,language:"javascript",children:JSON.stringify(schemaExample,null,2)})})]})});}const LanguageContext=React__default.default.createContext({languages:[]});const LanguageProvider=LanguageContext.Provider;function InternationalizedArray(props){const{members,value,schemaType,onChange}=props;const readOnly=typeof schemaType.readOnly==="boolean"?schemaType.readOnly:false;const{options}=schemaType;const toast=ui.useToast();const{value:document}=sanity.useFormBuilder();const deferredDocument=React.useDeferredValue(document);const selectedValue=React.useMemo(()=>getSelectedValue(options.select,deferredDocument),[options.select,deferredDocument]);const{apiVersion}=options;const client=sanity.useClient({apiVersion});const languages=Array.isArray(options.languages)?options.languages:suspend.suspend(// eslint-disable-next-line require-await
9470
+ root._=_;}}).call(commonjsGlobal);})(lodash,lodash.exports);var lodashExports=lodash.exports;const getSelectedValue=(select,document)=>{if(!select||!document){return{};}const selection=select||{};const selectedValue={};for(const[key,path]of Object.entries(selection)){let value=lodashExports.get(document,path);if(Array.isArray(value)){value=value.filter(item=>typeof item==="object"?(item==null?void 0:item._type)==="reference"&&"_ref"in item:true);}selectedValue[key]=value;}return selectedValue;};const schemaExample={languages:[{id:"en",title:"English"},{id:"no",title:"Norsk"}]};function Feedback(){return/* @__PURE__ */jsxRuntime.jsx(ui.Card,{tone:"caution",border:true,radius:2,padding:3,children:/* @__PURE__ */jsxRuntime.jsxs(ui.Stack,{space:4,children:[/* @__PURE__ */jsxRuntime.jsxs(ui.Text,{children:["An array of language objects must be passed into the"," ",/* @__PURE__ */jsxRuntime.jsx("code",{children:"internationalizedArray"})," helper function, each with an"," ",/* @__PURE__ */jsxRuntime.jsx("code",{children:"id"})," and ",/* @__PURE__ */jsxRuntime.jsx("code",{children:"title"})," field. Example:"]}),/* @__PURE__ */jsxRuntime.jsx(ui.Card,{padding:2,border:true,radius:2,children:/* @__PURE__ */jsxRuntime.jsx(ui.Code,{size:1,language:"javascript",children:JSON.stringify(schemaExample,null,2)})})]})});}const LanguageContext=React__default.default.createContext({languages:[]});const LanguageProvider=LanguageContext.Provider;function InternationalizedArray(props){const{members,value,schemaType,onChange}=props;const readOnly=typeof schemaType.readOnly==="boolean"?schemaType.readOnly:false;const{options}=schemaType;const toast=ui.useToast();const{value:document}=sanity.useFormBuilder();const deferredDocument=React.useDeferredValue(document);const selectedValue=React.useMemo(()=>getSelectedValue(options.select,deferredDocument),[options.select,deferredDocument]);const{apiVersion}=options;const client=sanity.useClient({apiVersion});const languages=Array.isArray(options.languages)?options.languages:suspend.suspend(// eslint-disable-next-line require-await
9471
9471
  async()=>{if(typeof options.languages==="function"){return options.languages(client,selectedValue);}return options.languages;},[version,namespace,selectedValue],{equal:equal__default.default});const handleAddLanguage=React.useCallback(languageId=>{if(!(languages==null?void 0:languages.length)){return;}const itemBase={_type:"".concat(schemaType.name,"Value")};const newItems=languageId?// Just one for this language
9472
9472
  [{...itemBase,_key:languageId}]:// Or one for every missing language
9473
9473
  languages.filter(language=>(value==null?void 0:value.length)?!value.find(v=>v._key===language.id):true).map(language=>({...itemBase,_key:language.id}));const languagesInUse2=(value==null?void 0:value.length)?value.map(v=>v):[];const insertions=newItems.map(item=>{const languageIndex=languages.findIndex(l=>item._key===l.id);const remainingLanguages=languages.slice(languageIndex+1);const nextLanguageIndex=languagesInUse2.findIndex(l=>// eslint-disable-next-line max-nested-callbacks