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/README.md +4 -4
- package/lib/index.esm.js +1 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/Feedback.tsx +4 -4
- package/src/components/InternationalizedInput.tsx +35 -10
- package/src/components/Preload.tsx +6 -3
- package/src/plugin.tsx +33 -24
- package/src/components/Table.tsx +0 -88
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
> This is the **Sanity Studio v3 version** of sanity-plugin-internationalized-array.
|
|
2
2
|
>
|
|
3
|
-
> For the v2 version, please refer to the [v2-branch](https://github.com/
|
|
3
|
+
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/sanity-plugin-internationalized-array/tree/studio-v2).
|
|
4
4
|
|
|
5
5
|
# sanity-plugin-internationalized-array
|
|
6
6
|
|
|
7
7
|
A helper function that renders a custom input component for writing localized fields of content into an array.
|
|
8
8
|
|
|
9
|
-

|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
@@ -161,7 +161,7 @@ Using GROQ filters you can query for a specific language key like so:
|
|
|
161
161
|
|
|
162
162
|
## Migrate from objects to arrays
|
|
163
163
|
|
|
164
|
-
[See the migration script](https://github.com/
|
|
164
|
+
[See the migration script](https://github.com/sanity-io/sanity-plugin-internationalized-array/blob/main/migrations/transformObjectToArray.js) inside `./migrations/transformObjectToArray.js` of this Repo.
|
|
165
165
|
|
|
166
166
|
Follow the instructions inside the script and set the `_type` and field name you wish to target.
|
|
167
167
|
|
|
@@ -222,7 +222,7 @@ on how to run this plugin with hotreload in the studio.
|
|
|
222
222
|
|
|
223
223
|
### Release new version
|
|
224
224
|
|
|
225
|
-
Run ["CI & Release" workflow](https://github.com/
|
|
225
|
+
Run ["CI & Release" workflow](https://github.com/sanity-io/sanity-plugin-internationalized-array/actions/workflows/main.yml).
|
|
226
226
|
Make sure to select the main branch and check "Release new version".
|
|
227
227
|
|
|
228
228
|
Semantic release will only release on configured branches, so it is safe to run release on any branch.
|
package/lib/index.esm.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__ */jsx(Card,{tone:"caution",border:true,radius:2,padding:3,children:/* @__PURE__ */jsxs(Stack,{space:4,children:[/* @__PURE__ */jsxs(Text,{children:["An array of language objects must be passed into the ",/* @__PURE__ */jsx("code",{children:"internationalizedArray"}),"
|
|
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__ */jsx(Card,{tone:"caution",border:true,radius:2,padding:3,children:/* @__PURE__ */jsxs(Stack,{space:4,children:[/* @__PURE__ */jsxs(Text,{children:["An array of language objects must be passed into the"," ",/* @__PURE__ */jsx("code",{children:"internationalizedArray"})," helper function, each with an"," ",/* @__PURE__ */jsx("code",{children:"id"})," and ",/* @__PURE__ */jsx("code",{children:"title"})," field. Example:"]}),/* @__PURE__ */jsx(Card,{padding:2,border:true,radius:2,children:/* @__PURE__ */jsx(Code,{size:1,language:"javascript",children:JSON.stringify(schemaExample,null,2)})})]})});}const LanguageContext=React.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=useToast();const{value:document}=useFormBuilder();const deferredDocument=useDeferredValue(document);const selectedValue=useMemo(()=>getSelectedValue(options.select,deferredDocument),[options.select,deferredDocument]);const{apiVersion}=options;const client=useClient({apiVersion});const languages=Array.isArray(options.languages)?options.languages:suspend$1(// 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});const handleAddLanguage=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
|