sanity-plugin-internationalized-array 1.6.0 → 1.6.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanity-plugin-internationalized-array",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "Store localized fields in an array to save on attributes",
5
5
  "keywords": [
6
6
  "sanity",
@@ -15,13 +15,13 @@
15
15
  "url": "git@github.com:SimeonGriggs/sanity-plugin-internationalized-array.git"
16
16
  },
17
17
  "license": "MIT",
18
- "author": "Simeon Griggs <simeon@sanity.io>",
18
+ "author": "Sanity.io <hello@sanity.io>",
19
19
  "exports": {
20
20
  ".": {
21
- "types": "./lib/src/index.d.ts",
21
+ "types": "./lib/index.d.ts",
22
22
  "source": "./src/index.ts",
23
- "import": "./lib/index.esm.js",
24
23
  "require": "./lib/index.js",
24
+ "import": "./lib/index.esm.js",
25
25
  "default": "./lib/index.esm.js"
26
26
  },
27
27
  "./package.json": "./package.json"
@@ -29,63 +29,75 @@
29
29
  "main": "./lib/index.js",
30
30
  "module": "./lib/index.esm.js",
31
31
  "source": "./src/index.ts",
32
- "types": "./lib/src/index.d.ts",
32
+ "types": "./lib/index.d.ts",
33
33
  "files": [
34
- "src",
35
34
  "lib",
36
- "v2-incompatible.js",
37
- "sanity.json"
35
+ "sanity.json",
36
+ "src",
37
+ "v2-incompatible.js"
38
38
  ],
39
39
  "scripts": {
40
40
  "prebuild": "npm run clean && plugin-kit verify-package --silent && pkg-utils",
41
- "build": "pkg-utils build",
41
+ "build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
42
42
  "clean": "rimraf lib",
43
+ "format": "prettier --write --cache --ignore-unknown .",
43
44
  "link-watch": "plugin-kit link-watch",
44
45
  "lint": "eslint .",
46
+ "lint:fix": "eslint . --fix",
45
47
  "prepare": "husky install",
46
- "prepublishOnly": "npm run build",
47
- "watch": "pkg-utils watch"
48
+ "prepublishOnly": "run-s build",
49
+ "watch": "pkg-utils watch --strict"
48
50
  },
49
51
  "dependencies": {
50
- "@sanity/icons": "^2.0.0",
52
+ "@sanity/icons": "^2.2.2",
51
53
  "@sanity/incompatible-plugin": "^1.0.4",
52
- "@sanity/ui": "^1.0.0",
54
+ "@sanity/ui": "^1.2.2",
53
55
  "fast-deep-equal": "^3.1.3",
54
56
  "lodash.get": "^4.4.2",
55
57
  "suspend-react": "^0.0.8"
56
58
  },
57
59
  "devDependencies": {
58
- "@commitlint/cli": "^17.3.0",
59
- "@commitlint/config-conventional": "^17.3.0",
60
- "@sanity/pkg-utils": "^1.18.0",
61
- "@sanity/plugin-kit": "^2.1.17",
62
- "@sanity/semantic-release-preset": "^2.0.2",
63
- "@types/lodash.get": "^4.4.7",
60
+ "@commitlint/cli": "^17.4.4",
61
+ "@commitlint/config-conventional": "^17.4.4",
62
+ "@sanity/pkg-utils": "^2.2.4",
63
+ "@sanity/plugin-kit": "^3.1.4",
64
+ "@sanity/semantic-release-preset": "^4.0.1",
65
+ "@types/react": "^18.0.27",
64
66
  "@types/styled-components": "^5.1.26",
65
- "@typescript-eslint/eslint-plugin": "^5.44.0",
66
- "@typescript-eslint/parser": "^5.44.0",
67
- "eslint": "^8.28.0",
68
- "eslint-config-prettier": "^8.5.0",
67
+ "@typescript-eslint/eslint-plugin": "^5.51.0",
68
+ "@typescript-eslint/parser": "^5.51.0",
69
+ "eslint": "^8.33.0",
70
+ "eslint-config-prettier": "^8.6.0",
69
71
  "eslint-config-sanity": "^6.0.0",
70
72
  "eslint-plugin-prettier": "^4.2.1",
71
- "eslint-plugin-react": "^7.31.11",
73
+ "eslint-plugin-react": "^7.32.2",
72
74
  "eslint-plugin-react-hooks": "^4.6.0",
73
- "husky": "^8.0.2",
74
- "lint-staged": "^13.0.4",
75
- "prettier": "^2.8.0",
76
- "prettier-plugin-packagejson": "^2.3.0",
75
+ "eslint-plugin-simple-import-sort": "^10.0.0",
76
+ "husky": "^8.0.3",
77
+ "lint-staged": "^13.2.0",
78
+ "npm-run-all": "^4.1.5",
79
+ "prettier": "^2.8.4",
80
+ "prettier-plugin-packagejson": "^2.4.2",
77
81
  "react": "^18",
78
- "rimraf": "^3.0.2",
79
- "sanity": "3.0.0-rc.3",
80
- "styled-components": "^5.3.6",
81
- "typescript": "^4.9.3"
82
+ "react-dom": "^18",
83
+ "react-is": "^18",
84
+ "rimraf": "^4.1.2",
85
+ "sanity": "^3.3.1",
86
+ "semantic-release": "^20.1.0",
87
+ "typescript": "^4.9.5"
82
88
  },
83
89
  "peerDependencies": {
90
+ "@sanity/ui": "^1.2.2",
84
91
  "react": "^18",
85
- "sanity": "dev-preview || 3.0.0-rc.3 || ^3.0.0",
86
- "styled-components": "^5.2"
92
+ "sanity": "^3.0.0",
93
+ "styled-components": "^5.3.6"
87
94
  },
88
95
  "engines": {
89
96
  "node": ">=14"
97
+ },
98
+ "sanityPlugin": {
99
+ "verifyPackage": {
100
+ "eslintImports": false
101
+ }
90
102
  }
91
103
  }
package/src/cache.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2
2
 
3
3
  import * as suspend from 'suspend-react'
4
+
4
5
  import type {Language} from './types'
5
6
 
6
7
  export const namespace = 'sanity-plugin-internationalized-array'
@@ -1,34 +1,37 @@
1
- import React, {useCallback, useDeferredValue, useEffect, useMemo} from 'react'
1
+ import {AddIcon} from '@sanity/icons'
2
+ import {Button, Grid, Stack, useToast} from '@sanity/ui'
3
+ import equal from 'fast-deep-equal'
4
+ import {useCallback, useDeferredValue, useEffect, useMemo} from 'react'
2
5
  import {
6
+ ArrayOfObjectsInputProps,
7
+ ArrayOfObjectsItem,
8
+ ArrayOfObjectsItemMember,
3
9
  insert,
4
10
  set,
5
11
  setIfMissing,
6
- ArrayOfObjectsItemMember,
7
- ArrayOfObjectsItem,
8
- ArrayOfObjectsInputProps,
9
12
  useClient,
10
13
  useFormBuilder,
11
14
  } from 'sanity'
12
- import {Button, Grid, Stack, useToast} from '@sanity/ui'
13
- import {AddIcon} from '@sanity/icons'
14
15
  import {suspend} from 'suspend-react'
15
- import equal from 'fast-deep-equal'
16
16
 
17
- import type {Value, ArraySchemaWithLanguageOptions} from '../types'
17
+ import {namespace, version} from '../cache'
18
+ import type {ArraySchemaWithLanguageOptions, Value} from '../types'
18
19
  import Feedback from './Feedback'
20
+ import {getSelectedValue} from './getSelectedValue'
19
21
  // TODO: Move this provider to the root component
20
22
  import {LanguageProvider} from './languageContext'
21
- import {namespace, version} from '../cache'
22
- import {getSelectedValue} from './getSelectedValue'
23
23
 
24
24
  export type InternationalizedArrayProps = ArrayOfObjectsInputProps<
25
25
  Value,
26
26
  ArraySchemaWithLanguageOptions
27
27
  >
28
28
 
29
- export default function InternationalizedArray(props: InternationalizedArrayProps) {
29
+ export default function InternationalizedArray(
30
+ props: InternationalizedArrayProps
31
+ ) {
30
32
  const {members, value, schemaType, onChange} = props
31
- const readOnly = typeof schemaType.readOnly === 'boolean' ? schemaType.readOnly : false
33
+ const readOnly =
34
+ typeof schemaType.readOnly === 'boolean' ? schemaType.readOnly : false
32
35
  const {options} = schemaType
33
36
  const toast = useToast()
34
37
  const {value: document} = useFormBuilder()
@@ -161,13 +164,16 @@ export default function InternationalizedArray(props: InternationalizedArrayProp
161
164
  }
162
165
 
163
166
  return value
164
- .map((v, vIndex) => (vIndex === languagesInUse.findIndex((l) => l.id === v._key) ? null : v))
167
+ .map((v, vIndex) =>
168
+ vIndex === languagesInUse.findIndex((l) => l.id === v._key) ? null : v
169
+ )
165
170
  .filter(Boolean)
166
171
  }, [value, languagesInUse])
167
172
 
168
173
  const languagesAreValid = useMemo(
169
174
  () =>
170
- !languages?.length || (languages?.length && languages.every((item) => item.id && item.title)),
175
+ !languages?.length ||
176
+ (languages?.length && languages.every((item) => item.id && item.title)),
171
177
  [languages]
172
178
  )
173
179
 
@@ -231,7 +237,10 @@ export default function InternationalizedArray(props: InternationalizedArrayProp
231
237
  tone="primary"
232
238
  mode="ghost"
233
239
  fontSize={1}
234
- disabled={readOnly || Boolean(value?.find((item) => item._key === language.id))}
240
+ disabled={
241
+ readOnly ||
242
+ Boolean(value?.find((item) => item._key === language.id))
243
+ }
235
244
  text={language.id.toUpperCase()}
236
245
  icon={AddIcon}
237
246
  onClick={() => handleAddLanguage(language.id)}
@@ -242,13 +251,17 @@ export default function InternationalizedArray(props: InternationalizedArrayProp
242
251
  <Button
243
252
  tone="primary"
244
253
  mode="ghost"
245
- disabled={readOnly || (value && value?.length >= languages?.length)}
254
+ disabled={
255
+ readOnly || (value && value?.length >= languages?.length)
256
+ }
246
257
  icon={AddIcon}
247
258
  text={
248
259
  // eslint-disable-next-line no-nested-ternary
249
260
  value?.length
250
261
  ? `Add missing ${
251
- languages.length - value.length === 1 ? `language` : `languages`
262
+ languages.length - value.length === 1
263
+ ? `language`
264
+ : `languages`
252
265
  }`
253
266
  : languages.length === 1
254
267
  ? `Add ${languages[0].title} Field`
@@ -1,6 +1,6 @@
1
+ import {Box, BoxProps, Card, CardProps} from '@sanity/ui'
1
2
  import React from 'react'
2
3
  import styled, {css} from 'styled-components'
3
- import {Box, BoxProps, Card, CardProps} from '@sanity/ui'
4
4
 
5
5
  // Wrappers required because of bug with passing down "as" prop
6
6
  // https://github.com/styled-components/styled-components/issues/2449
@@ -19,7 +19,9 @@ export const getSelectedValue = (
19
19
  if (Array.isArray(value)) {
20
20
  // If there are references in the array, ensure they have `_ref` set, otherwise they are considered empty and can safely be ignored
21
21
  value = value.filter((item) =>
22
- typeof item === 'object' ? item?._type === 'reference' && '_ref' in item : true
22
+ typeof item === 'object'
23
+ ? item?._type === 'reference' && '_ref' in item
24
+ : true
23
25
  )
24
26
  }
25
27
  selectedValue[key] = value
@@ -1,7 +1,9 @@
1
1
  import {CardTone} from '@sanity/ui'
2
2
  import {FormNodeValidation} from 'sanity'
3
3
 
4
- export function getToneFromValidation(validations: FormNodeValidation[]): CardTone | undefined {
4
+ export function getToneFromValidation(
5
+ validations: FormNodeValidation[]
6
+ ): CardTone | undefined {
5
7
  if (!validations?.length) {
6
8
  return undefined
7
9
  }
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-nested-ternary */
2
2
  import {defineField, type FieldDefinition, type Rule} from 'sanity'
3
- import {peek} from '../cache'
4
3
 
4
+ import {peek} from '../cache'
5
5
  import {createFieldName} from '../components/createFieldName'
6
6
  import {getSelectedValue} from '../components/getSelectedValue'
7
7
  import InternationalizedArray from '../components/InternationalizedArray'
@@ -24,14 +24,12 @@ export default (config: ArrayFactoryConfig): FieldDefinition<'array'> => {
24
24
  name: arrayName,
25
25
  title: 'Internationalized array',
26
26
  type: 'array',
27
- // TODO: Resolve this typing issue with the outer component
28
- // @ts-ignore
29
27
  components: {
30
28
  input: InternationalizedArray,
31
29
  },
32
30
  options: {apiVersion, select, languages},
33
31
  // TODO: Resolve this typing issue with the inner object
34
- // @ts-ignore
32
+ // @ts-expect-error
35
33
  of: [
36
34
  defineField({
37
35
  ...(typeof type === 'string' ? {} : type),
@@ -47,7 +45,9 @@ export default (config: ArrayFactoryConfig): FieldDefinition<'array'> => {
47
45
 
48
46
  const selectedValue = getSelectedValue(select, context.document)
49
47
  const client = context.getClient({apiVersion})
50
- const contextLanguages: Language[] = Array.isArray(context?.type?.options?.languages)
48
+ const contextLanguages: Language[] = Array.isArray(
49
+ context?.type?.options?.languages
50
+ )
51
51
  ? context!.type!.options.languages
52
52
  : Array.isArray(peek(selectedValue))
53
53
  ? peek(selectedValue)
@@ -55,12 +55,17 @@ export default (config: ArrayFactoryConfig): FieldDefinition<'array'> => {
55
55
 
56
56
  if (value && value.length > contextLanguages.length) {
57
57
  return `Cannot be more than ${
58
- contextLanguages.length === 1 ? `1 item` : `${contextLanguages.length} items`
58
+ contextLanguages.length === 1
59
+ ? `1 item`
60
+ : `${contextLanguages.length} items`
59
61
  }`
60
62
  }
61
63
 
62
64
  const nonLanguageKeys = value?.length
63
- ? value.filter((item) => !contextLanguages.find((language) => item._key === language.id))
65
+ ? value.filter(
66
+ (item) =>
67
+ !contextLanguages.find((language) => item._key === language.id)
68
+ )
64
69
  : []
65
70
  if (nonLanguageKeys.length) {
66
71
  return {
@@ -17,26 +17,20 @@ export default (config: ObjectFactoryConfig): FieldDefinition<'object'> => {
17
17
  name: objectName,
18
18
  title: `Internationalized array ${type}`,
19
19
  type: 'object',
20
- // TODO: Resolve this typing issue with the return type
21
- // @ts-ignore
22
20
  components: {
23
- // TODO: Resolve this typing issue with the outer component
24
- // @ts-ignore
25
21
  item: InternationalizedInput,
26
22
  },
27
23
  // TODO: Address this typing issue with the inner object
28
- // @ts-ignore
24
+ // @ts-expect-error
29
25
  fields: [
30
26
  typeof type === `string`
31
27
  ? // Define a simple field if all we have is the name as a string
32
28
  defineField({
33
29
  name: 'value',
34
30
  type,
35
- // TODO: Address this typing issue with components on a dynamic `type`
36
- // @ts-ignore
37
31
  components: {
38
32
  // TODO: Address this typing issue with the inner object
39
- // @ts-ignore
33
+ // @ts-expect-error
40
34
  field: InternationalizedField,
41
35
  },
42
36
  })
package/src/types.ts CHANGED
@@ -1,4 +1,10 @@
1
- import type {Rule, ArraySchemaType, RuleTypeConstraint, SanityClient, FieldDefinition} from 'sanity'
1
+ import type {
2
+ ArraySchemaType,
3
+ FieldDefinition,
4
+ Rule,
5
+ RuleTypeConstraint,
6
+ SanityClient,
7
+ } from 'sanity'
2
8
 
3
9
  export type Language = {
4
10
  id: Intl.UnicodeBCP47LocaleIdentifier