@sanity/language-filter 2.31.2-performance-opts.7 → 3.0.0-v3-studio.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2016 - 2022 Sanity.io
3
+ Copyright (c) 2022 Sanity.io
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
+ # @sanity/language-filter
2
+
3
+ > **NOTE**
4
+ >
5
+ > This is the **Sanity Studio v3 version** of @sanity/language-filter.
6
+ >
7
+ > For the v2 version, please refer to the [v2 version](https://github.com/sanity-io/sanity/tree/next/packages/%40sanity/language-filter).
8
+
1
9
  # Field-level translation filter Plugin for Sanity.io
2
10
 
3
11
  A Sanity plugin that supports filtering localized fields by language
@@ -26,50 +34,108 @@ This plugin adds features to the Studio to improve handling **field-level transl
26
34
 
27
35
  For **document-level translations** you should use the [@sanity/document-internationalization plugin](https://www.npmjs.com/package/@sanity/document-internationalization).
28
36
 
37
+
29
38
  ## Installation
30
39
 
31
40
  ```
32
- sanity install @sanity/language-filter
41
+ npm install --save @sanity/language-filter@studio-v3
33
42
  ```
34
43
 
35
- Installing with `sanity install` updates your `sanity.json` to include this plugin. If installing with npm or yarn, ensure your `plugins` array includes `@sanity/language-filter`.
36
-
37
- ### Add config file
44
+ or
38
45
 
39
- In order to know what languages are supported, this plugin needs to be set up with a config file that exports a few options.
46
+ ```
47
+ yarn add @sanity/language-filter@studio-v3
48
+ ```
40
49
 
41
- This config file needs to implement the part `part:@sanity/language-filter/config`, by adding the following lines to the `parts`-section of your `sanity.json`
50
+ ## Usage
51
+ Add it as a plugin in sanity.config.ts (or .js), and configure it:
42
52
 
43
- ```json
44
- {
45
- "name": "part:@sanity/language-filter/config",
46
- "path": "./parts/languageFilterConfig.js"
47
- }
48
53
  ```
54
+ import {createConfig} from 'sanity'
55
+ import {languageFilter} from '@sanity/language-filter'
56
+
57
+ export const createConfig({
58
+ //...
59
+ plugins: [
60
+ languageFilter({
61
+ supportedLanguages: [
62
+ {id: 'nb', title: 'Norwegian (Bokmål)'},
63
+ {id: 'nn', title: 'Norwegian (Nynorsk)'},
64
+ {id: 'en', title: 'English'},
65
+ {id: 'es', title: 'Spanish'},
66
+ {id: 'arb', title: 'Arabic'},
67
+ {id: 'pt', title: 'Portuguese'},
68
+ //...
69
+ ],
70
+ // Select Norwegian (Bokmål) by default
71
+ defaultLanguages: ['nb'],
72
+ // Only show language filter for document type `page` (schemaType.name)
73
+ documentTypes: ['page'],
74
+ filterField: (enclosingType, field, selectedLanguageIds) =>
75
+ !enclosingType.name.startsWith('locale') || selectedLanguageIds.includes(field.name),
76
+ })
77
+ ]
78
+ })
79
+ ```
80
+
81
+ Config properties:
82
+ - `supportedLanguages` is an array of languages with `id` and `title`. If your localized fields are defined using our recommended way described here (https://www.sanity.io/docs/localization), you probably want to share this list of supported languages between this config and your schema.
83
+ - `defaultLanguages` (optional) is an array of strings where each entry must match an `id` from the `supportedLanguages` array. These languages will be listed by default and will not be possible to unselect. If no `defaultLanguages` is configured, all localized fields will be selected by default.
84
+ - `documentTypes` (optional) is an array of strings where each entry must match a `name` from your document schemas. If defined, this property will be used to conditionally show the language filter on specific document schema types. If undefined, the language filter will show on all document schema types.
85
+ - `filterField` (optional) is a function that must return true if the field should be displayed. It is passed the enclosing type (e.g the object type containing the localized fields, the field, and an array of the currently selected language ids.
86
+ This function is called for all fields and fieldsets in objects for documents that have language filter enabled.
87
+ _Default:_ `!enclosingType.name.startsWith('locale') || selectedLanguageIds.includes(field.name)`
88
+
89
+ ## Changes in V3
90
+
91
+ ### filterField
92
+ `filerField` will also be passed any fieldsets in the enclosing object, when present.
49
93
 
50
- Here's an example `languageFilterConfig.js` file:
94
+ ### documentTypes
95
+ Language filter can now be enabled/disabled directly from a schema, using `options.languageFilter: boolean`.
96
+ When `documentTypes` is omitted from plugin config, use `options.languageFilter: false` in a document-definition to hide the filter button.
97
+ When `documentTypes` is provided in plugin config, use `options.languageFilter: true` in a document-definition to show the filter button.
98
+
99
+ Example:
51
100
 
52
101
  ```js
53
- export default {
54
- supportedLanguages: [
55
- {id: 'nb', title: 'Norwegian (Bokmål)'},
56
- {id: 'nn', title: 'Norwegian (Nynorsk)'},
57
- {id: 'en', title: 'English'},
58
- {id: 'es', title: 'Spanish'},
59
- {id: 'arb', title: 'Arabic'},
60
- {id: 'pt', title: 'Portuguese'},
61
- //...
62
- ],
63
- // Select Norwegian (Bokmål) by default
64
- defaultLanguages: ['nb'],
65
- // Only show language filter for document type `page` (schemaType.name)
66
- documentTypes: ['page'],
67
- filterField: (enclosingType, field, selectedLanguageIds) =>
68
- !enclosingType.name.startsWith('locale') || selectedLanguageIds.includes(field.name),
102
+ export const myDocumentSchema = {
103
+ type: 'document',
104
+ name: 'my-enabled-language-filter-document',
105
+ /** ... */
106
+ options: {
107
+ // show language filter for this document type, regardless of how documentTypes for the plugin is configured
108
+ languageFilter: true
109
+ }
69
110
  }
70
111
  ```
71
112
 
72
- - `supportedLanguages` is an array of languages with `id` and `title`. If your localized fields are defined using our recommended way described here (https://www.sanity.io/docs/localization), you probably want to share this list of supported languages between this config and your schema.
73
- - `defaultLanguages` (optional) is an array of strings where each entry must match an `id` from the `supportedLanguages` array. These languages will be listed by default and will not be possible to unselect. If no `defaultLanguages` is configured, all localized fields will be selected by default.
74
- - `documentTypes` (optional) is an array of strings where each entry must match a `name` from your document schemas. If defined, this property will be used to conditionally show the language filter on specific document schema types. If undefined, the language filter will show on all document schema types.
75
- - `filterField` is a function that must return true if the field should be displayed. It is passed the enclosing type (e.g the object type containing the localized fields, the field, and an array of the currently selected language ids.
113
+ ### State management
114
+ Selected languages are now stored as `langs` url-param state; this allows users to copy paste
115
+ a url in the studio with the currently selected languages preselected.
116
+
117
+ Previously this state was stored in localstorage.
118
+
119
+ ## License
120
+
121
+ MIT © Sanity.io
122
+ See LICENSE
123
+
124
+ ## Develop
125
+
126
+ This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
127
+ with default configuration for build & watch scripts.
128
+
129
+ See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
130
+ on how to run this plugin with hotreload in the studio.
131
+
132
+ ### Release new version
133
+
134
+ Run ["CI & Release" workflow](https://github.com/sanity-io/language-filter/actions/workflows/main.yml).
135
+ Make sure to select the main branch and check "Release new version".
136
+
137
+ Semantic release will only release on configured branches, so it is safe to run release on any branch.
138
+
139
+ Note: main branch is configured to release a studio-v3 tagged version of the plugin.
140
+ To make semantic-release happy, the branch "semver-main-placeholder" is regarded as the non-prerelease branch,
141
+ but it is unused. The v2 version lives in the sanity mono-repo.
@@ -0,0 +1,425 @@
1
+ var $k7rGe$reactjsxruntime = require("react/jsx-runtime");
2
+ var $k7rGe$react = require("react");
3
+ var $k7rGe$sanity = require("sanity");
4
+ var $k7rGe$sanityui = require("@sanity/ui");
5
+
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+
10
+ $parcel$export(module.exports, "languageFilter", () => $45e3093e7de8dca2$export$bae498c4212cce68);
11
+ $parcel$export(module.exports, "defaultFilterField", () => $f29012bc04d39674$export$373781be62a9896e);
12
+ $parcel$export(module.exports, "isLanguageFilterEnabled", () => $f29012bc04d39674$export$fe9baa09973dbf22);
13
+
14
+
15
+
16
+
17
+
18
+ const $f29012bc04d39674$export$373781be62a9896e = (enclosingType, field, selectedLanguageIds)=>!enclosingType.name.startsWith("locale") || selectedLanguageIds.includes(field.name);
19
+ function $f29012bc04d39674$export$fe9baa09973dbf22(schemaType, options) {
20
+ const schemaFilter = $f29012bc04d39674$var$isDocument(schemaType) && schemaType?.options?.languageFilter;
21
+ const defaultEnabled = !options.documentTypes;
22
+ return !!(defaultEnabled && schemaFilter !== false || !defaultEnabled && schemaFilter || schemaType && options.documentTypes?.includes(schemaType.name));
23
+ }
24
+ function $f29012bc04d39674$var$isDocument(schemaType) {
25
+ return schemaType?.jsonType === "object" && $f29012bc04d39674$var$getRootType(schemaType).name === "document";
26
+ }
27
+ function $f29012bc04d39674$var$getRootType(schema) {
28
+ if (schema.type) return $f29012bc04d39674$var$getRootType(schema.type);
29
+ return schema;
30
+ }
31
+
32
+
33
+
34
+
35
+ const $bb26db9356030deb$var$LanguageFilterContext = /*#__PURE__*/ (0, $k7rGe$react.createContext)(undefined);
36
+ function $bb26db9356030deb$export$f00537e9911d9516({ options: options , enabled: enabled , children: children }) {
37
+ const value = (0, $k7rGe$react.useMemo)(()=>({
38
+ options: options,
39
+ enabled: enabled
40
+ }), [
41
+ options,
42
+ enabled
43
+ ]);
44
+ return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)($bb26db9356030deb$var$LanguageFilterContext.Provider, {
45
+ value: value,
46
+ children: children
47
+ });
48
+ }
49
+ function $bb26db9356030deb$export$d5c74ca916607f46() {
50
+ const value = (0, $k7rGe$react.useContext)($bb26db9356030deb$var$LanguageFilterContext);
51
+ if (!value) throw new Error("LanguageFilterContext is missing");
52
+ return value;
53
+ }
54
+
55
+
56
+
57
+ const $fe597f02a0bccb26$var$storageKey = "@sanity/plugin/language-filter/selected-languages";
58
+ function $fe597f02a0bccb26$export$f21c039050fb95eb(options) {
59
+ const selectableLangs = $fe597f02a0bccb26$export$76676750ed98bafe(options).map((l)=>l.id);
60
+ let selected = selectableLangs;
61
+ try {
62
+ const persistedValue = window.localStorage.getItem($fe597f02a0bccb26$var$storageKey);
63
+ if (persistedValue) selected = JSON.parse(persistedValue);
64
+ } catch (err) {} // eslint-disable-line no-empty
65
+ // constrain persisted/selected languages to the ones currently supported
66
+ selected = $fe597f02a0bccb26$var$intersection(selected, selectableLangs);
67
+ return selected;
68
+ }
69
+ function $fe597f02a0bccb26$export$833b55f5102c4e70(languageIds) {
70
+ window.localStorage.setItem($fe597f02a0bccb26$var$storageKey, JSON.stringify(languageIds));
71
+ }
72
+ function $fe597f02a0bccb26$var$intersection(array1, array2) {
73
+ return array1.filter((value)=>array2.includes(value));
74
+ }
75
+ function $fe597f02a0bccb26$export$76676750ed98bafe({ supportedLanguages: supportedLanguages , defaultLanguages: defaultLanguages }) {
76
+ return supportedLanguages.filter((lang)=>!defaultLanguages?.includes(lang.id));
77
+ }
78
+ function $fe597f02a0bccb26$export$b484a630b97f9ca3(options) {
79
+ return (0, $k7rGe$react.useState)(()=>$fe597f02a0bccb26$export$f21c039050fb95eb(options));
80
+ }
81
+
82
+
83
+ function $a0f4109b367c6ff0$export$7f9ce1f19dc34df5(props) {
84
+ const { options: options , enabled: enabled } = (0, $bb26db9356030deb$export$d5c74ca916607f46)();
85
+ const { next: next , subscribeSelectedIds: subscribeSelectedIds , ...restProps } = props;
86
+ if (!enabled || !options) return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$reactjsxruntime.Fragment), {
87
+ children: next(restProps)
88
+ });
89
+ return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)($a0f4109b367c6ff0$var$FilteredObjectInput, {
90
+ ...restProps,
91
+ next: next,
92
+ options: options,
93
+ subscribeSelectedIds: subscribeSelectedIds
94
+ });
95
+ }
96
+ function $a0f4109b367c6ff0$var$FilteredObjectInput(props) {
97
+ const { members: membersProp , options: options , schemaType: schemaType , next: next , subscribeSelectedIds: subscribeSelectedIds , ...restProps } = props;
98
+ const [selectedIds, setSelectedIds] = (0, $fe597f02a0bccb26$export$b484a630b97f9ca3)(options);
99
+ (0, $k7rGe$react.useEffect)(()=>{
100
+ const unsubscribe = subscribeSelectedIds(setSelectedIds);
101
+ return ()=>unsubscribe();
102
+ }, [
103
+ subscribeSelectedIds,
104
+ setSelectedIds
105
+ ]);
106
+ const activeLanguages = (0, $k7rGe$react.useMemo)(()=>[
107
+ ...options.defaultLanguages ?? [],
108
+ ...selectedIds
109
+ ], [
110
+ options.defaultLanguages,
111
+ selectedIds
112
+ ]);
113
+ const filterField = options.filterField ?? (0, $f29012bc04d39674$export$373781be62a9896e);
114
+ const members = (0, $k7rGe$react.useMemo)(()=>{
115
+ return membersProp.filter((member)=>member.kind === "field" && filterField(schemaType, member, activeLanguages) || member.kind === "fieldSet" && filterField(schemaType, member.fieldSet, activeLanguages));
116
+ }, [
117
+ schemaType,
118
+ membersProp,
119
+ filterField,
120
+ activeLanguages
121
+ ]);
122
+ return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$reactjsxruntime.Fragment), {
123
+ children: next({
124
+ ...restProps,
125
+ members: members,
126
+ schemaType: schemaType
127
+ })
128
+ });
129
+ }
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+ function $b7317e67f107ab55$export$cd56401a2a088ead(props) {
138
+ const { options: options , onSelectedIdsChange: onSelectedIdsChange } = props;
139
+ const { defaultLanguages: defaultLanguages } = options;
140
+ const [selectedIds, setSelectedIds] = (0, $fe597f02a0bccb26$export$b484a630b97f9ca3)(options);
141
+ const selectableLanguages = (0, $k7rGe$react.useMemo)(()=>(0, $fe597f02a0bccb26$export$76676750ed98bafe)(options), [
142
+ options
143
+ ]);
144
+ const updateSelectedIds = (0, $k7rGe$react.useCallback)((ids)=>{
145
+ setSelectedIds(ids);
146
+ (0, $fe597f02a0bccb26$export$833b55f5102c4e70)(ids);
147
+ onSelectedIdsChange(ids);
148
+ }, [
149
+ onSelectedIdsChange,
150
+ setSelectedIds
151
+ ]);
152
+ const selectAll = (0, $k7rGe$react.useCallback)(()=>updateSelectedIds(selectableLanguages.map((l)=>l.id)), [
153
+ updateSelectedIds,
154
+ selectableLanguages
155
+ ]);
156
+ const selectNone = (0, $k7rGe$react.useCallback)(()=>{
157
+ updateSelectedIds([]);
158
+ }, [
159
+ updateSelectedIds
160
+ ]);
161
+ const toggleLanguage = (0, $k7rGe$react.useCallback)((languageId)=>{
162
+ let lang = selectedIds;
163
+ if (lang.includes(languageId)) lang = lang.filter((l)=>l !== languageId);
164
+ else lang = [
165
+ ...lang,
166
+ languageId
167
+ ];
168
+ updateSelectedIds(lang);
169
+ }, [
170
+ updateSelectedIds,
171
+ selectedIds
172
+ ]);
173
+ const activeLanguages = (0, $k7rGe$react.useMemo)(()=>[
174
+ ...defaultLanguages ?? [],
175
+ ...selectedIds
176
+ ], [
177
+ defaultLanguages,
178
+ selectedIds
179
+ ]);
180
+ return {
181
+ activeLanguages: activeLanguages,
182
+ allSelected: selectedIds.length === selectableLanguages.length,
183
+ selectAll: selectAll,
184
+ selectNone: selectNone,
185
+ toggleLanguage: toggleLanguage
186
+ };
187
+ }
188
+
189
+
190
+ function $4de932c0c6553dd2$export$85fc605f11895007(props) {
191
+ const { options: options , onSelectedIdsChange: onSelectedIdsChange } = props;
192
+ const defaultLanguages = options.supportedLanguages.filter((l)=>options.defaultLanguages?.includes(l.id));
193
+ const languageOptions = options.supportedLanguages.filter((l)=>!options.defaultLanguages?.includes(l.id));
194
+ const [open, setOpen] = (0, $k7rGe$react.useState)(false);
195
+ const { activeLanguages: activeLanguages , allSelected: allSelected , selectAll: selectAll , selectNone: selectNone , toggleLanguage: toggleLanguage } = (0, $b7317e67f107ab55$export$cd56401a2a088ead)({
196
+ options: options,
197
+ onSelectedIdsChange: onSelectedIdsChange
198
+ });
199
+ const [button, setButton] = (0, $k7rGe$react.useState)(null);
200
+ const [popover, setPopover] = (0, $k7rGe$react.useState)(null);
201
+ const handleToggleAll = (0, $k7rGe$react.useCallback)((event)=>{
202
+ const checked = event.currentTarget.checked;
203
+ if (checked) selectAll();
204
+ else selectNone();
205
+ }, [
206
+ selectAll,
207
+ selectNone
208
+ ]);
209
+ const handleClick = (0, $k7rGe$react.useCallback)(()=>setOpen((o)=>!o), []);
210
+ const handleClickOutside = (0, $k7rGe$react.useCallback)(()=>setOpen(false), []);
211
+ (0, $k7rGe$sanityui.useClickOutside)(handleClickOutside, [
212
+ button,
213
+ popover
214
+ ]);
215
+ const content = /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Box), {
216
+ overflow: "auto",
217
+ padding: 1,
218
+ children: [
219
+ defaultLanguages.length > 0 && /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Card), {
220
+ radius: 2,
221
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Stack), {
222
+ padding: 2,
223
+ space: 3,
224
+ children: [
225
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
226
+ paddingBottom: 2,
227
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Text), {
228
+ size: 1,
229
+ weight: "semibold",
230
+ children: [
231
+ "Default language",
232
+ defaultLanguages.length > 1 && /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$reactjsxruntime.Fragment), {
233
+ children: "s"
234
+ })
235
+ ]
236
+ })
237
+ }),
238
+ defaultLanguages.map((l)=>/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Text), {
239
+ children: l.title
240
+ }, l.id))
241
+ ]
242
+ })
243
+ }),
244
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Stack), {
245
+ marginTop: 3,
246
+ padding: 2,
247
+ space: 2,
248
+ children: [
249
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
250
+ paddingBottom: 2,
251
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Text), {
252
+ size: 1,
253
+ weight: "semibold",
254
+ children: "Show translations"
255
+ })
256
+ }),
257
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Card), {
258
+ as: "label",
259
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Flex), {
260
+ align: "center",
261
+ gap: 2,
262
+ children: [
263
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Checkbox), {
264
+ checked: allSelected,
265
+ name: "_allSelected",
266
+ onChange: handleToggleAll
267
+ }),
268
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
269
+ flex: 1,
270
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Text), {
271
+ muted: !allSelected,
272
+ weight: "semibold",
273
+ children: "All translations"
274
+ })
275
+ })
276
+ ]
277
+ })
278
+ }),
279
+ languageOptions.map((lang)=>/*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)($4de932c0c6553dd2$var$LanguageFilterOption, {
280
+ id: lang.id,
281
+ onToggle: toggleLanguage,
282
+ selected: activeLanguages.includes(lang.id),
283
+ title: lang.title
284
+ }, lang.id))
285
+ ]
286
+ })
287
+ ]
288
+ });
289
+ const langCount = options.supportedLanguages.length;
290
+ return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Popover), {
291
+ content: content,
292
+ open: open,
293
+ portal: true,
294
+ ref: setPopover,
295
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Button), {
296
+ text: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Flex), {
297
+ gap: 1,
298
+ children: [
299
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
300
+ children: "Filter languages:"
301
+ }),
302
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Flex), {
303
+ gap: 1,
304
+ justify: "space-around",
305
+ children: [
306
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Flex), {
307
+ style: {
308
+ width: `${Math.floor(Math.log10(langCount) + 1)}ch`
309
+ },
310
+ justify: "flex-end",
311
+ children: activeLanguages.length
312
+ }),
313
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
314
+ children: "/"
315
+ }),
316
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
317
+ children: langCount
318
+ })
319
+ ]
320
+ })
321
+ ]
322
+ }),
323
+ mode: "bleed",
324
+ onClick: handleClick,
325
+ ref: setButton,
326
+ selected: open
327
+ })
328
+ });
329
+ }
330
+ function $4de932c0c6553dd2$var$LanguageFilterOption(props) {
331
+ const { id: id , onToggle: onToggle , selected: selected , title: title } = props;
332
+ const handleChange = (0, $k7rGe$react.useCallback)(()=>{
333
+ onToggle(id);
334
+ }, [
335
+ id,
336
+ onToggle
337
+ ]);
338
+ return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Card), {
339
+ as: "label",
340
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsxs)((0, $k7rGe$sanityui.Flex), {
341
+ align: "center",
342
+ gap: 2,
343
+ children: [
344
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Checkbox), {
345
+ checked: selected,
346
+ name: `language-${id}`,
347
+ onChange: handleChange
348
+ }),
349
+ /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Box), {
350
+ flex: 1,
351
+ children: /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $k7rGe$sanityui.Text), {
352
+ muted: !selected,
353
+ children: title
354
+ })
355
+ })
356
+ ]
357
+ })
358
+ });
359
+ }
360
+
361
+
362
+
363
+
364
+ function $a3222324b33f4bdf$export$de189c01fb1f896d() {
365
+ const subs = [];
366
+ const onSelectedIdsChange = (ids)=>{
367
+ subs.forEach((s)=>s(ids));
368
+ };
369
+ const subscribeSelectedIds = (subscription)=>{
370
+ subs.push(subscription);
371
+ return ()=>{
372
+ subs.splice(subs.indexOf(subscription), 1);
373
+ };
374
+ };
375
+ return {
376
+ onSelectedIdsChange: onSelectedIdsChange,
377
+ subscribeSelectedIds: subscribeSelectedIds
378
+ };
379
+ }
380
+
381
+
382
+ const $45e3093e7de8dca2$export$bae498c4212cce68 = (0, $k7rGe$sanity.createPlugin)((options)=>{
383
+ const { onSelectedIdsChange: onSelectedIdsChange , subscribeSelectedIds: subscribeSelectedIds } = (0, $a3222324b33f4bdf$export$de189c01fb1f896d)();
384
+ const RenderLanguageFilter = ()=>{
385
+ return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $4de932c0c6553dd2$export$85fc605f11895007), {
386
+ options: options,
387
+ onSelectedIdsChange: onSelectedIdsChange
388
+ });
389
+ };
390
+ return {
391
+ name: "@sanity/language-filter",
392
+ document: {
393
+ unstable_languageFilter: (prev, { schemaType: schemaType , schema: schema })=>{
394
+ if ((0, $f29012bc04d39674$export$fe9baa09973dbf22)(schema.get(schemaType), options)) return [
395
+ ...prev,
396
+ RenderLanguageFilter
397
+ ];
398
+ return prev;
399
+ }
400
+ },
401
+ form: {
402
+ renderInput (props, next) {
403
+ const enabled = (0, $f29012bc04d39674$export$fe9baa09973dbf22)(props.schemaType, options);
404
+ // will only be considered enabled for document, so this is only done once
405
+ if (enabled) return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $bb26db9356030deb$export$f00537e9911d9516), {
406
+ enabled: enabled,
407
+ options: options,
408
+ children: next(props)
409
+ });
410
+ if (props.schemaType.jsonType === "object") return /*#__PURE__*/ (0, $k7rGe$reactjsxruntime.jsx)((0, $a0f4109b367c6ff0$export$7f9ce1f19dc34df5), {
411
+ ...props,
412
+ next: next,
413
+ subscribeSelectedIds: subscribeSelected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BAExC,OAAO,IAAI,CAAA;aACZ;SACF;QAED,IAAI,EAAE;YACJ,WAAW,EAAC,KAAK,EAAE,IAAI,EAAE;gBACvB,MAAM,OAAO,GAAG,CAAA,GAAA,yCAAuB,CAAA,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC;gBAClE,0EAA0E;gBAC1E,IAAI,OAAO,EACT,qBACE,gCAAC,CAAA,GAAA,yCAAsB,CAAA;oBAAC,OAAO,EAAE,OAAO;oBAAE,OAAO,EAAE,OAAO;8BACvD,IAAI,CAAC,KAAK,CAAC;kBACW,CAC1B;gBAEH,IAAI,KAAK,CAAC,UAAU,CAAC,QAAQ,KAAK,QAAQ,EACxC,qBACE,gCAAC,CAAA,GAAA,yCAAyB,CAAA;oBACvB,GAAI,KAAK;oBACV,IAAI,EAAE,IAAI;oBACV,oBAAoB,EAAE,oBAAoB;kBAC1C,CACH;gBAGH,OAAO,SAAS,CAAA;aACjB;SACF;KACF,CAAA;CACF,CAAC;;ADlFF","sources":["src/index.ts","src/plugin.tsx","src/LanguageFilterObjectInput.tsx","src/filterField.ts","src/LanguageFilterContext.tsx","src/useSelectedLanguageIds.ts","src/LanguageFilterMenuButton.tsx","src/usePaneLanguages.ts","src/languageSubscription.ts"],"sourcesContent":["/**\n * Plugin function\n */\nexport {languageFilter} from './plugin'\n\nexport {defaultFilterField, isLanguageFilterEnabled} from './filterField'\n\nexport type {\n LanguageFilterConfig,\n LanguageFilterSchema,\n LanguageFilterOptions,\n FilterFieldFunction,\n Language,\n} from './types'\n","import React from 'react'\nimport {_DocumentLanguageFilterComponent, createPlugin, ObjectInputProps} from 'sanity'\nimport {LanguageFilterObjectInput} from './LanguageFilterObjectInput'\nimport {LanguageFilterMenuButton} from './LanguageFilterMenuButton'\nimport {LanguageFilterConfig} from './types'\nimport {isLanguageFilterEnabled} from './filterField'\nimport {LanguageFilterProvider} from './LanguageFilterContext'\nimport {createSelectedLanguageIdsBus} from './languageSubscription'\n\n/**\n * ## Usage in sanity.config.ts (or .js)\n *\n * ```\n * import {createConfig} from 'sanity'\n * import {languageFilter} from '@sanity/language-filter'\n *\n * export const createConfig({\n * /...\n * plugins: [\n * languageFilter({\n * supportedLanguages: [\n * {id: 'nb', title: 'Norwegian (Bokmål)'},\n * {id: 'nn', title: 'Norwegian (Nynorsk)'},\n * {id: 'en', title: 'English'},\n * {id: 'es', title: 'Spanish'},\n * {id: 'arb', title: 'Arabic'},\n * {id: 'pt', title: 'Portuguese'},\n * //...\n * ],\n * // Select Norwegian (Bokmål) by default\n * defaultLanguages: ['nb'],\n * // Only show language filter for document type `page` (schemaType.name)\n * // Can also enable via document-options: options.languageFilter: true\n * documentTypes: ['page'],\n * // default filter function shown\n * filterField: (enclosingType, field, selectedLanguageIds) =>\n * !enclosingType.name.startsWith('locale') || selectedLanguageIds.includes(field.name),\n * })\n * ]\n * })\n * ```\n */\nexport const languageFilter = createPlugin<LanguageFilterConfig>((options) => {\n const {onSelectedIdsChange, subscribeSelectedIds} = createSelectedLanguageIdsBus()\n\n const RenderLanguageFilter: _DocumentLanguageFilterComponent = () => {\n return <LanguageFilterMenuButton options={options} onSelectedIdsChange={onSelectedIdsChange} />\n }\n\n return {\n name: '@sanity/language-filter',\n document: {\n unstable_languageFilter: (prev, {schemaType, schema}) => {\n if (isLanguageFilterEnabled(schema.get(schemaType), options)) {\n return [...prev, RenderLanguageFilter]\n }\n return prev\n },\n },\n\n form: {\n renderInput(props, next) {\n const enabled = isLanguageFilterEnabled(props.schemaType, options)\n // will only be considered enabled for document, so this is only done once\n if (enabled) {\n return (\n <LanguageFilterProvider enabled={enabled} options={options}>\n {next(props)}\n </LanguageFilterProvider>\n )\n }\n if (props.schemaType.jsonType === 'object') {\n return (\n <LanguageFilterObjectInput\n {...(props as ObjectInputProps)}\n next={next}\n subscribeSelectedIds={subscribeSelectedIds}\n />\n )\n }\n\n return undefined\n },\n },\n }\n})\n","import React, {useEffect, useMemo} from 'react'\nimport {ObjectInputProps, ObjectMember, RenderInputCallback} from 'sanity'\nimport {LanguageFilterConfig} from './types'\nimport {defaultFilterField} from './filterField'\nimport {useLanguageFilterContext} from './LanguageFilterContext'\nimport {useSelectedLanguageIds} from './useSelectedLanguageIds'\n\nexport type LanguageFilterObjectInputProps = {\n options: LanguageFilterConfig\n next: RenderInputCallback\n /**\n * We need a way to communicate state changes between the pane menu and input components.\n * LanguageFilter button lives outside the input-render tree, so Context is out.\n * This is a workaround for that.\n */\n subscribeSelectedIds: (callback: (ids: string[]) => void) => () => void\n} & ObjectInputProps\n\nexport function LanguageFilterObjectInput(\n props: ObjectInputProps & {\n next: RenderInputCallback\n subscribeSelectedIds: (callback: (ids: string[]) => void) => () => void\n }\n) {\n const {options, enabled} = useLanguageFilterContext()\n const {next, subscribeSelectedIds, ...restProps} = props\n if (!enabled || !options) {\n return <>{next(restProps)}</>\n }\n return (\n <FilteredObjectInput\n {...restProps}\n next={next}\n options={options}\n subscribeSelectedIds={subscribeSelectedIds}\n />\n )\n}\n\nfunction FilteredObjectInput(props: LanguageFilterObjectInputProps) {\n const {\n members: membersProp,\n options,\n schemaType,\n next,\n subscribeSelectedIds,\n ...restProps\n } = props\n const [selectedIds, setSelectedIds] = useSelectedLanguageIds(options)\n\n useEffect(() => {\n const unsubscribe = subscribeSelectedIds(setSelectedIds)\n return () => unsubscribe()\n }, [subscribeSelectedIds, setSelectedIds])\n\n const activeLanguages = useMemo(\n () => [...(options.defaultLanguages ?? []), ...selectedIds],\n [options.defaultLanguages, selectedIds]\n )\n\n const filterField = options.filterField ?? defaultFilterField\n\n const members: ObjectMember[] = useMemo(() => {\n return membersProp.filter(\n (member) =>\n (member.kind === 'field' && filterField(schemaType, member, activeLanguages)) ||\n (member.kind === 'fieldSet' && filterField(schemaType, member.fieldSet, activeLanguages))\n )\n }, [schemaType, membersProp, filterField, activeLanguages])\n\n return <>{next({...restProps, members, schemaType})}</>\n}\n","import type {SchemaType} from 'sanity'\nimport {FilterFieldFunction, LanguageFilterConfig, LanguageFilterSchema} from './types'\n\nexport const defaultFilterField: FilterFieldFunction = (\n enclosingType,\n field,\n selectedLanguageIds\n) => !enclosingType.name.startsWith('locale') || selectedLanguageIds.includes(field.name)\n\nexport function isLanguageFilterEnabled(\n schemaType: SchemaType | undefined,\n options: LanguageFilterConfig\n): boolean {\n const schemaFilter =\n isDocument(schemaType) && (schemaType as LanguageFilterSchema)?.options?.languageFilter\n const defaultEnabled = !options.documentTypes\n\n return !!(\n (defaultEnabled && schemaFilter !== false) ||\n (!defaultEnabled && schemaFilter) ||\n (schemaType && options.documentTypes?.includes(schemaType.name))\n )\n}\n\nfunction isDocument(schemaType?: SchemaType) {\n return schemaType?.jsonType === 'object' && getRootType(schemaType).name === 'document'\n}\n\nfunction getRootType(schema: SchemaType): SchemaType {\n if (schema.type) {\n return getRootType(schema.type)\n }\n return schema\n}\n","import React, {createContext, PropsWithChildren, useContext, useMemo} from 'react'\nimport {LanguageFilterConfig} from './types'\n\nexport interface LanguageFilterContextValue {\n // eslint-disable-next-line react/require-default-props\n options: LanguageFilterConfig\n // eslint-disable-next-line react/require-default-props\n enabled: boolean\n}\n\nconst LanguageFilterContext = createContext<LanguageFilterContextValue | undefined>(undefined)\n\nexport function LanguageFilterProvider({\n options,\n enabled,\n children,\n}: PropsWithChildren<\n Omit<LanguageFilterContextValue, 'selectedLanguageIds' | 'setSelectedLanguageIds'>\n>) {\n const value = useMemo(() => ({options, enabled}), [options, enabled])\n return <LanguageFilterContext.Provider value={value}>{children}</LanguageFilterContext.Provider>\n}\n\nexport function useLanguageFilterContext() {\n const value = useContext(LanguageFilterContext)\n if (!value) {\n throw new Error('LanguageFilterContext is missing')\n }\n return value\n}\n","import {Language, LanguageFilterConfig} from './types'\nimport {useState} from 'react'\nconst storageKey = '@sanity/plugin/language-filter/selected-languages'\n\nexport function getPersistedLanguageIds(options: LanguageFilterConfig): string[] {\n const selectableLangs = getSelectableLanguages(options).map((l) => l.id)\n\n let selected: string[] = selectableLangs\n try {\n const persistedValue = window.localStorage.getItem(storageKey)\n if (persistedValue) {\n selected = JSON.parse(persistedValue)\n }\n } catch (err) {} // eslint-disable-line no-empty\n\n // constrain persisted/selected languages to the ones currently supported\n selected = intersection(selected, selectableLangs)\n return selected\n}\n\nexport function persistLanguageIds(languageIds: string[]): void {\n window.localStorage.setItem(storageKey, JSON.stringify(languageIds))\n}\n\nfunction intersection(array1: string[], array2: string[]) {\n return array1.filter((value) => array2.includes(value))\n}\n\nexport function getSelectableLanguages({\n supportedLanguages,\n defaultLanguages,\n}: LanguageFilterConfig): Language[] {\n return supportedLanguages.filter((lang) => !defaultLanguages?.includes(lang.id))\n}\n\nexport function useSelectedLanguageIds(\n options: LanguageFilterConfig\n): [string[], (ids: string[]) => void] {\n return useState(() => getPersistedLanguageIds(options))\n}\n","import {Box, Button, Card, Checkbox, Flex, Popover, Stack, Text, useClickOutside} from '@sanity/ui'\nimport React, {FormEvent, useCallback, useState} from 'react'\nimport {usePaneLanguages} from './usePaneLanguages'\nimport {LanguageFilterConfig} from './types'\n\nexport interface LanguageFilterMenuButtonProps {\n options: LanguageFilterConfig\n onSelectedIdsChange: (ids: string[]) => void\n}\n\nexport function LanguageFilterMenuButton(props: LanguageFilterMenuButtonProps) {\n const {options, onSelectedIdsChange} = props\n\n const defaultLanguages = options.supportedLanguages.filter((l) =>\n options.defaultLanguages?.includes(l.id)\n )\n\n const languageOptions = options.supportedLanguages.filter(\n (l) => !options.defaultLanguages?.includes(l.id)\n )\n const [open, setOpen] = useState(false)\n const {activeLanguages, allSelected, selectAll, selectNone, toggleLanguage} = usePaneLanguages({\n options,\n onSelectedIdsChange,\n })\n const [button, setButton] = useState<HTMLElement | null>(null)\n const [popover, setPopover] = useState<HTMLElement | null>(null)\n\n const handleToggleAll = useCallback(\n (event: FormEvent<HTMLInputElement>) => {\n const checked = event.currentTarget.checked\n\n if (checked) {\n selectAll()\n } else {\n selectNone()\n }\n },\n [selectAll, selectNone]\n )\n\n const handleClick = useCallback(() => setOpen((o) => !o), [])\n\n const handleClickOutside = useCallback(() => setOpen(false), [])\n\n useClickOutside(handleClickOutside, [button, popover])\n\n const content = (\n <Box overflow=\"auto\" padding={1}>\n {defaultLanguages.length > 0 && (\n <Card radius={2}>\n <Stack padding={2} space={3}>\n <Box paddingBottom={2}>\n <Text size={1} weight=\"semibold\">\n Default language{defaultLanguages.length > 1 && <>s</>}\n </Text>\n </Box>\n\n {defaultLanguages.map((l) => (\n <Text key={l.id}>{l.title}</Text>\n ))}\n </Stack>\n </Card>\n )}\n\n <Stack marginTop={3} padding={2} space={2}>\n <Box paddingBottom={2}>\n <Text size={1} weight=\"semibold\">\n Show translations\n </Text>\n </Box>\n\n <Card as=\"label\">\n <Flex align=\"center\" gap={2}>\n <Checkbox checked={allSelected} name=\"_allSelected\" onChange={handleToggleAll} />\n <Box flex={1}>\n <Text muted={!allSelected} weight=\"semibold\">\n All translations\n </Text>\n </Box>\n </Flex>\n </Card>\n\n {languageOptions.map((lang) => (\n <LanguageFilterOption\n id={lang.id}\n key={lang.id}\n onToggle={toggleLanguage}\n selected={activeLanguages.includes(lang.id)}\n title={lang.title}\n />\n ))}\n </Stack>\n </Box>\n )\n\n const langCount = options.supportedLanguages.length\n return (\n <Popover content={content} open={open} portal ref={setPopover}>\n <Button\n text={\n <Flex gap={1}>\n <Box>Filter languages:</Box>\n <Flex gap={1} justify=\"space-around\">\n <Flex\n style={{width: `${Math.floor(Math.log10(langCount) + 1)}ch`}}\n justify=\"flex-end\"\n >\n {activeLanguages.length}\n </Flex>\n <Box>/</Box>\n <Box>{langCount}</Box>\n </Flex>\n </Flex>\n }\n mode=\"bleed\"\n onClick={handleClick}\n ref={setButton}\n selected={open}\n />\n </Popover>\n )\n}\n\nfunction LanguageFilterOption(props: {\n id: string\n onToggle: (id: string) => void\n selected: boolean\n title: string\n}) {\n const {id, onToggle, selected, title} = props\n\n const handleChange = useCallback(() => {\n onToggle(id)\n }, [id, onToggle])\n\n return (\n <Card as=\"label\">\n <Flex align=\"center\" gap={2}>\n <Checkbox checked={selected} name={`language-${id}`} onChange={handleChange} />\n <Box flex={1}>\n <Text muted={!selected}>{title}</Text>\n </Box>\n </Flex>\n </Card>\n )\n}\n","import {useCallback, useMemo} from 'react'\nimport {LanguageFilterConfig} from './types'\nimport {\n getSelectableLanguages,\n persistLanguageIds,\n useSelectedLanguageIds,\n} from './useSelectedLanguageIds'\n\nexport interface UsePaneLanguagesParams {\n options: LanguageFilterConfig\n /**\n * We need a way to communicate state changes between the pane menu and input components.\n * LanguageFilter button lives outside the input-render tree, so Context is out.\n * This is a workaround for that.\n */\n onSelectedIdsChange: (ids: string[]) => void\n}\n\nexport function usePaneLanguages(props: UsePaneLanguagesParams): {\n activeLanguages: string[]\n allSelected: boolean\n selectAll: () => void\n selectNone: () => void\n toggleLanguage: (languageId: string) => void\n} {\n const {options, onSelectedIdsChange} = props\n const {defaultLanguages} = options\n\n const [selectedIds, setSelectedIds] = useSelectedLanguageIds(options)\n\n const selectableLanguages = useMemo(() => getSelectableLanguages(options), [options])\n\n const updateSelectedIds = useCallback(\n (ids: string[]) => {\n setSelectedIds(ids)\n persistLanguageIds(ids)\n onSelectedIdsChange(ids)\n },\n [onSelectedIdsChange, setSelectedIds]\n )\n\n const selectAll = useCallback(\n () => updateSelectedIds(selectableLanguages.map((l) => l.id)),\n [updateSelectedIds, selectableLanguages]\n )\n\n const selectNone = useCallback(() => {\n updateSelectedIds([])\n }, [updateSelectedIds])\n\n const toggleLanguage = useCallback(\n (languageId: string) => {\n let lang = selectedIds\n\n if (lang.includes(languageId)) {\n lang = lang.filter((l) => l !== languageId)\n } else {\n lang = [...lang, languageId]\n }\n\n updateSelectedIds(lang)\n },\n [updateSelectedIds, selectedIds]\n )\n\n const activeLanguages = useMemo(\n () => [...(defaultLanguages ?? []), ...selectedIds],\n [defaultLanguages, selectedIds]\n )\n\n return {\n activeLanguages,\n allSelected: selectedIds.length === selectableLanguages.length,\n selectAll,\n selectNone,\n toggleLanguage,\n }\n}\n","export type LanguageSubscription = (ids: string[]) => void\nexport type Unsubscribe = () => void\nexport type LanguageSubscribe = (subscription: LanguageSubscription) => Unsubscribe\n\nexport interface SelectedLanguageIdsBus {\n onSelectedIdsChange: (ids: string[]) => void\n subscribeSelectedIds: LanguageSubscribe\n}\n\n/**\n * We need a way to communicate state changes between the pane menu and input components.\n * LanguageFilter button lives outside the input-render tree, so Context is out.\n * This is a workaround for that.\n */\nexport function createSelectedLanguageIdsBus(): SelectedLanguageIdsBus {\n const subs: LanguageSubscription[] = []\n\n const onSelectedIdsChange = (ids: string[]) => {\n subs.forEach((s) => s(ids))\n }\n const subscribeSelectedIds = (subscription: LanguageSubscription) => {\n subs.push(subscription)\n return () => {\n subs.splice(subs.indexOf(subscription), 1)\n }\n }\n\n return {\n onSelectedIdsChange,\n subscribeSelectedIds,\n }\n}\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../../"}