@sanity/document-internationalization 2.1.2 → 3.0.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/dist/index.d.mts +90 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.esm.js +768 -1166
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +753 -1176
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1048 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +34 -38
- package/src/actions/DeleteMetadataAction.tsx +5 -5
- package/src/actions/DeleteTranslationAction.tsx +6 -2
- package/src/badges/index.tsx +1 -1
- package/src/components/BulkPublish/DocumentCheck.tsx +1 -1
- package/src/components/BulkPublish/InfoIcon.tsx +4 -3
- package/src/components/BulkPublish/index.tsx +3 -2
- package/src/components/ConstrainedBox.tsx +1 -1
- package/src/components/DeleteTranslationDialog/index.tsx +1 -1
- package/src/components/DeleteTranslationDialog/separateReferences.ts +1 -1
- package/src/components/DocumentInternationalizationContext.tsx +2 -2
- package/src/components/DocumentInternationalizationMenu.tsx +3 -2
- package/src/components/LanguageManage.tsx +1 -0
- package/src/components/LanguageOption.tsx +28 -4
- package/src/components/LanguagePatch.tsx +2 -2
- package/src/components/OptimisticallyStrengthen/ReferencePatcher.tsx +2 -2
- package/src/components/OptimisticallyStrengthen/index.tsx +1 -1
- package/src/components/Warning.tsx +1 -1
- package/src/constants.ts +1 -1
- package/src/hooks/useLanguageMetadata.tsx +1 -1
- package/src/hooks/useOpenInNewPane.tsx +2 -2
- package/src/plugin.tsx +4 -4
- package/src/schema/translation/metadata.ts +2 -4
- package/src/utils/createReference.ts +1 -1
- package/src/utils/excludePaths.ts +4 -4
- package/dist/index.cjs.mjs +0 -7
package/src/constants.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {useListeningQuery} from 'sanity-plugin-utils'
|
|
2
2
|
|
|
3
3
|
import {METADATA_SCHEMA_NAME} from '../constants'
|
|
4
|
-
import {Metadata} from '../types'
|
|
4
|
+
import type {Metadata} from '../types'
|
|
5
5
|
|
|
6
6
|
// Using references() seemed less reliable for updating the listener
|
|
7
7
|
// results than querying raw values in the array
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {useCallback, useContext} from 'react'
|
|
2
|
-
import {usePaneRouter} from 'sanity/desk'
|
|
3
2
|
import {RouterContext} from 'sanity/router'
|
|
3
|
+
import {usePaneRouter} from 'sanity/structure'
|
|
4
4
|
|
|
5
5
|
export function useOpenInNewPane(id?: string, type?: string) {
|
|
6
6
|
const routerContext = useContext(RouterContext)
|
|
@@ -11,7 +11,7 @@ export function useOpenInNewPane(id?: string, type?: string) {
|
|
|
11
11
|
return
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// No panes open, function might be called outside
|
|
14
|
+
// No panes open, function might be called outside Structure
|
|
15
15
|
if (!routerPanesState.length) {
|
|
16
16
|
routerContext.navigateIntent('edit', {id, type})
|
|
17
17
|
return
|
package/src/plugin.tsx
CHANGED
|
@@ -10,7 +10,7 @@ import {DocumentInternationalizationMenu} from './components/DocumentInternation
|
|
|
10
10
|
import OptimisticallyStrengthen from './components/OptimisticallyStrengthen'
|
|
11
11
|
import {API_VERSION, DEFAULT_CONFIG, METADATA_SCHEMA_NAME} from './constants'
|
|
12
12
|
import metadata from './schema/translation/metadata'
|
|
13
|
-
import {PluginConfig, TranslationReference} from './types'
|
|
13
|
+
import type {PluginConfig, TranslationReference} from './types'
|
|
14
14
|
|
|
15
15
|
export const documentInternationalization = definePlugin<PluginConfig>(
|
|
16
16
|
(config) => {
|
|
@@ -54,7 +54,7 @@ export const documentInternationalization = definePlugin<PluginConfig>(
|
|
|
54
54
|
const translations =
|
|
55
55
|
(props?.value?.translations as TranslationReference[]) ?? []
|
|
56
56
|
const weakAndTypedTranslations = translations.filter(
|
|
57
|
-
({value}) => value
|
|
57
|
+
({value}) => value?._weak && value._strengthenOnPublish
|
|
58
58
|
)
|
|
59
59
|
|
|
60
60
|
return (
|
|
@@ -171,6 +171,7 @@ export const documentInternationalization = definePlugin<PluginConfig>(
|
|
|
171
171
|
weak: pluginConfig.weakReferences,
|
|
172
172
|
// Reference filters don't actually enforce validation!
|
|
173
173
|
validation: (Rule) =>
|
|
174
|
+
// @ts-expect-error - fix typings
|
|
174
175
|
Rule.custom(async (item: TranslationReference, context) => {
|
|
175
176
|
if (!item?.value?._ref || !item?._key) {
|
|
176
177
|
return true
|
|
@@ -192,8 +193,7 @@ export const documentInternationalization = definePlugin<PluginConfig>(
|
|
|
192
193
|
return `Referenced document does not have the correct language value`
|
|
193
194
|
}),
|
|
194
195
|
options: {
|
|
195
|
-
//
|
|
196
|
-
// @ts-expect-error
|
|
196
|
+
// @ts-expect-error - Update type once it knows the values of this filter
|
|
197
197
|
filter: ({parent, document}) => {
|
|
198
198
|
if (!parent) return null
|
|
199
199
|
|
|
@@ -2,8 +2,8 @@ import {TranslateIcon} from '@sanity/icons'
|
|
|
2
2
|
import {
|
|
3
3
|
defineField,
|
|
4
4
|
defineType,
|
|
5
|
-
DocumentDefinition,
|
|
6
|
-
FieldDefinition,
|
|
5
|
+
type DocumentDefinition,
|
|
6
|
+
type FieldDefinition,
|
|
7
7
|
} from 'sanity'
|
|
8
8
|
|
|
9
9
|
import {METADATA_SCHEMA_NAME, TRANSLATIONS_ARRAY_NAME} from '../../constants'
|
|
@@ -28,8 +28,6 @@ export default (
|
|
|
28
28
|
description:
|
|
29
29
|
'Optional: Used to filter the reference fields above so all translations share the same types.',
|
|
30
30
|
type: 'array',
|
|
31
|
-
// For some reason TS dislikes this line because of the DocumentDefinition return type
|
|
32
|
-
// @ts-expect-error
|
|
33
31
|
of: [{type: 'string'}],
|
|
34
32
|
options: {list: schemaTypes},
|
|
35
33
|
readOnly: ({value}) => Boolean(value),
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {extractWithPath, Mutation} from '@sanity/mutator'
|
|
2
2
|
import {
|
|
3
3
|
isDocumentSchemaType,
|
|
4
|
-
ObjectSchemaType,
|
|
5
|
-
Path,
|
|
4
|
+
type ObjectSchemaType,
|
|
5
|
+
type Path,
|
|
6
6
|
pathToString,
|
|
7
|
-
SanityDocument,
|
|
8
|
-
SchemaType,
|
|
7
|
+
type SanityDocument,
|
|
8
|
+
type SchemaType,
|
|
9
9
|
} from 'sanity'
|
|
10
10
|
|
|
11
11
|
export interface DocumentMember {
|
package/dist/index.cjs.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import cjs from './index.js';
|
|
2
|
-
|
|
3
|
-
export const DeleteTranslationAction = cjs.DeleteTranslationAction;
|
|
4
|
-
export const DocumentInternationalizationMenu = cjs.DocumentInternationalizationMenu;
|
|
5
|
-
export const documentInternationalization = cjs.documentInternationalization;
|
|
6
|
-
export const useDocumentInternationalizationContext = cjs.useDocumentInternationalizationContext;
|
|
7
|
-
|