@madebywild/sanity-reference-collection-field 1.2.0 → 1.3.0

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 CHANGED
@@ -40,17 +40,9 @@ defineField({
40
40
  type: "wild.referenceCollection",
41
41
  options: {
42
42
  inline: true,
43
- referenceKinds: ["post", { title: "Featured Projects", value: "project" }],
44
43
  extensions: {
45
- // each supports `true` or { enabled: true/false }
46
- filtering: {
47
- enabled: true,
48
- filterByKinds: ["post", "project"],
49
- },
50
- pagination: {
51
- enabled: true,
52
- pageCount: 12,
53
- },
44
+ filtering: true,
45
+ pagination: true,
54
46
  },
55
47
  },
56
48
  });
@@ -61,10 +53,11 @@ defineField({
61
53
  {
62
54
  collectionRef: "post",
63
55
  options: {
56
+ pageCount: 12,
57
+ canLoadMore: true,
64
58
  withFilters: true,
65
59
  filterByKinds: ["post", "project"],
66
60
  withPagination: true,
67
- pageCount: 12,
68
61
  },
69
62
  }
70
63
  ```
package/dist/index.cjs CHANGED
@@ -166,6 +166,20 @@ const typeName = "wild.referenceCollection", wildSanityReferenceCollectionFieldP
166
166
  options: {
167
167
  layout: "switch"
168
168
  }
169
+ }), sanity.defineField({
170
+ name: "canLoadMore",
171
+ type: "boolean",
172
+ title: "Can Load More",
173
+ description: "Whether to allow loading more items.",
174
+ hidden: ({
175
+ parent
176
+ }) => !parent?.withPagination,
177
+ initialValue: ({
178
+ parent
179
+ }) => parent?.withPagination,
180
+ options: {
181
+ layout: "switch"
182
+ }
169
183
  }), sanity.defineField({
170
184
  name: "pageCount",
171
185
  type: "number",
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/input.tsx","../src/types.tsx","../src/index.tsx"],"sourcesContent":["import { CompactObjectInput } from \"@madebywild/sanity-utils/compact-object-input\";\nimport { Stack } from \"@sanity/ui\";\nimport * as React from \"react\";\nimport type { ObjectFieldProps } from \"sanity\";\nimport { MemberField, type ObjectInputProps, type ObjectMember, type StringInputProps } from \"sanity\";\nimport type { CollectionReference, FieldOptions, PluginConfig, ReferenceCollectionExtensions } from \"./types\";\n\nfunction isExtensionEnabled(extensions: ReferenceCollectionExtensions, key: keyof ReferenceCollectionExtensions) {\n return extensions[key] && (extensions[key] === true || extensions[key].enabled !== false);\n}\n\nconst FieldContext = React.createContext<{ options?: FieldOptions }>({});\nconst useFieldCtx = () => React.useContext(FieldContext);\n\nfunction normalizeCollection(preset: CollectionReference) {\n return typeof preset === \"string\" ? { title: preset, value: preset } : preset;\n}\n\nfunction CollectionFieldInput(props: ObjectInputProps) {\n return (\n <FieldContext.Provider value={{ options: props.schemaType.options as FieldOptions | undefined }}>\n <CompactObjectInput space={4} {...props} />\n </FieldContext.Provider>\n );\n}\n\nfunction CollectionOptionsField(props: ObjectFieldProps) {\n const { options } = useFieldCtx();\n // We can hide the field if no extensions are enabled.\n if (!options?.extensions || !Object.keys(options?.extensions).length) return null;\n return <>{props.children}</>;\n}\n\nfunction CollectionOptionsInput(props: ObjectInputProps) {\n const { options } = useFieldCtx();\n const extensions = options?.extensions;\n\n return (\n <Stack space={4}>\n {props.members.map((member: ObjectMember) => {\n if (member.kind !== \"field\") return null;\n\n // Custom filtering extension.\n const filteringEnabled = extensions && isExtensionEnabled(extensions, \"filtering\");\n if (!filteringEnabled && member.name === \"withFilters\") return null;\n\n // Custom pagination extension.\n const paginationEnabled = extensions && isExtensionEnabled(extensions, \"pagination\");\n if (!paginationEnabled && member.name === \"withPagination\") return null;\n\n return <MemberField key={member.key} member={member} {...props} />;\n })}\n </Stack>\n );\n}\n\nfunction CollectionRefInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig?: PluginConfig;\n}) {\n const patchedSchemaType = React.useMemo(() => {\n // Local options take precedence over plugin config.\n const options = props.schemaType.options as FieldOptions | undefined;\n const references = options?.referenceKinds ?? pluginConfig?.referenceKinds;\n\n // No need to touch anything if the list is unchanged.\n if (!references?.length) return props.schemaType;\n\n return {\n ...props.schemaType,\n options: {\n ...props.schemaType.options,\n list: references.map(normalizeCollection),\n },\n };\n }, [props.schemaType]);\n\n return props.renderDefault({\n ...props,\n schemaType: patchedSchemaType,\n });\n}\n\nexport { CollectionRefInput, CollectionFieldInput, CollectionOptionsField, CollectionOptionsInput };\n","import type { ObjectDefinition, ObjectOptions } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.referenceCollection\" as const;\n\n/** @public */\nexport type CollectionReference = string | { title: string; value: string };\n\n/** @public */\nexport type ReferenceCollectionExtensions = Partial<{\n /** Allows filtering the references. */\n filtering: boolean | { enabled?: boolean };\n /** Allows paginating the references. */\n pagination: boolean | { enabled?: boolean };\n}>;\n\n/** @public */\nexport type PluginConfig = {\n /**\n * A list of references the user can choose from.\n * Can be overridden per-field via `options.referenceKinds`.\n * @example\n * ```ts\n * referenceKinds: [\"blogPost\", \"some-type\"],\n * ```\n */\n referenceKinds: CollectionReference[];\n};\n\n/** @public */\nexport type FieldOptions = ObjectOptions & {\n /**\n * Whether the media field should be displayed inline.\n * This will render all children inline on the same level.\n */\n inline?: boolean;\n /**\n * A list of references the user can choose from.\n * Will take precedence over the plugin-level `referenceKinds`.\n * @example\n * ```ts\n * referenceKinds: [\"blogPost\", \"some-type\"],\n * ```\n */\n referenceKinds?: CollectionReference[];\n /**\n * List of extension that add additional behaviors to the link field.\n */\n extensions?: ReferenceCollectionExtensions;\n};\n\n// Add the custom field definition to Sanity's intrinsic definitions\n// so that type checking works correctly when using this field type.\ndeclare module \"sanity\" {\n export interface IntrinsicDefinitions {\n [typeName]: Omit<ObjectDefinition, \"type\" | \"fields\" | \"options\" | \"components\"> & {\n type: typeof typeName;\n options?: FieldOptions;\n };\n }\n}\n","import { defineArrayMember, defineField, definePlugin, defineType } from \"sanity\";\nimport { CollectionFieldInput, CollectionOptionsField, CollectionOptionsInput, CollectionRefInput } from \"./input\";\nimport {\n type CollectionReference,\n type FieldOptions,\n type PluginConfig,\n type ReferenceCollectionExtensions,\n typeName,\n} from \"./types\";\n\n/** @public */\nconst wildSanityReferenceCollectionFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-reference-collection-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"object\",\n title: \"Reference Collection\",\n description: \"Choose a content type and control how the collection is displayed.\",\n icon: () => <>🔃</>,\n validation: (R) => {\n return R.custom((value) => {\n return !value?.collectionRef ? { message: \"Select a reference.\", path: [\"collectionRef\"] } : true;\n });\n },\n components: {\n field: (props) => (props.schemaType.options.inline ? props.children : props.renderDefault(props)),\n input: (props) => <CollectionFieldInput {...props} />,\n },\n fields: [\n defineField({\n name: \"collectionRef\",\n type: \"string\",\n title: \"Collection Type\",\n description: \"Choose which type of content this collection should show.\",\n components: {\n input: (props) => <CollectionRefInput pluginConfig={config} {...props} />,\n },\n options: {\n layout: \"dropdown\",\n list: config.referenceKinds,\n },\n }),\n defineField({\n type: \"object\",\n name: \"options\",\n title: \"Display Settings\",\n description: \"Control filters and pagination for this collection.\",\n options: {\n collapsed: false,\n collapsible: false,\n },\n components: {\n field: (props) => <CollectionOptionsField {...props} />,\n input: (props) => <CollectionOptionsInput {...props} />,\n },\n fields: [\n defineField({\n name: \"withFilters\",\n type: \"boolean\",\n title: \"Enable Filters\",\n description: \"Show filter controls for this collection.\",\n initialValue: false,\n options: { layout: \"switch\" },\n }),\n defineField({\n name: \"filterByKinds\",\n type: \"array\",\n title: \"Available Filter Types\",\n description: \"Choose which content types appear as filter options.\",\n hidden: ({ parent }) => !parent?.withFilters,\n of: [\n defineArrayMember({\n type: \"string\",\n }),\n ],\n options: { layout: \"tags\" },\n validation: (R) => R.unique(),\n }),\n defineField({\n name: \"withPagination\",\n type: \"boolean\",\n title: \"Enable Pagination\",\n description: \"Split collection results across multiple pages.\",\n initialValue: false,\n options: { layout: \"switch\" },\n }),\n defineField({\n name: \"pageCount\",\n type: \"number\",\n title: \"Items Per Page\",\n description: \"Set how many items to show on each page.\",\n hidden: ({ parent }) => !parent?.withPagination,\n initialValue: 12,\n validation: (R) => R.integer().positive(),\n }),\n ],\n }),\n ],\n preview: {\n select: {\n collection: \"collectionRef\",\n },\n prepare({ collection }) {\n return {\n title: \"Reference Collection\",\n subtitle: collection ? `Reference to ${collection}` : undefined,\n };\n },\n },\n }),\n ],\n },\n };\n});\n\nexport {\n wildSanityReferenceCollectionFieldPlugin,\n typeName,\n type ReferenceCollectionExtensions,\n type PluginConfig,\n type FieldOptions,\n type CollectionReference,\n};\n"],"names":["isExtensionEnabled","extensions","key","enabled","FieldContext","React","createContext","useFieldCtx","useContext","normalizeCollection","preset","title","value","CollectionFieldInput","props","$","_c","t0","schemaType","options","t1","t2","jsx","CompactObjectInput","t3","CollectionOptionsField","Object","keys","length","children","CollectionOptionsInput","members","map","member","kind","name","MemberField","Stack","CollectionRefInput","pluginConfig","bb0","references","referenceKinds","t4","t5","list","t6","patchedSchemaType","renderDefault","typeName","wildSanityReferenceCollectionFieldPlugin","definePlugin","config","schema","types","defineType","type","description","icon","Fragment","validation","R","custom","collectionRef","message","path","components","field","inline","input","fields","defineField","layout","collapsed","collapsible","initialValue","hidden","parent","withFilters","of","defineArrayMember","unique","withPagination","integer","positive","preview","select","collection","prepare","subtitle","undefined"],"mappings":";;;;;;;;;;;;;;;;;;;AAOA,SAASA,mBAAmBC,YAA2CC,KAA0C;AAC/G,SAAOD,WAAWC,GAAG,MAAMD,WAAWC,GAAG,MAAM,MAAQD,WAAWC,GAAG,EAAEC,YAAY;AACrF;AAEA,MAAMC,eAAeC,iBAAMC,cAA0C,CAAA,CAAE,GACjEC,cAAcA,MAAMF,iBAAKG,WAAYJ,YAAY;AAEvD,SAASK,oBAAoBC,QAA6B;AACxD,SAAO,OAAOA,UAAW,WAAW;AAAA,IAAEC,OAAOD;AAAAA,IAAQE,OAAOF;AAAAA,EAAAA,IAAWA;AACzE;AAEA,SAAAG,qBAAAC,OAAA;AAAA,QAAAC,IAAAC,gBAAAA,EAAA,CAAA,GAE6CC,KAAAH,MAAKI,WA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AA,YAAEqD,QAAQ;AAAA,UAAA;AAAA,UACnBZ,YAAaC,CAAAA,MAAMA,EAAEoB,OAAAA;AAAAA,QAAO,CAC7B,GACDV,OAAAA,YAAY;AAAA,UACVpC,MAAM;AAAA,UACNqB,MAAM;AAAA,UACN7C,OAAO;AAAA,UACP8C,aAAa;AAAA,UACbkB,cAAc;AAAA,UACdxD,SAAS;AAAA,YAAEqD,QAAQ;AAAA,UAAA;AAAA,QAAS,CAC7B,GACDD,OAAAA,YAAY;AAAA,UACVpC,MAAM;AAAA,UACNqB,MAAM;AAAA,UACN7C,OAAO;AAAA,UACP8C,aAAa;AAAA,UACbmB,QAAQA,CAAC;AAAA,YAAEC;AAAAA,UAAAA,MAAa,CAACA,QAAQK;AAAAA,UACjCP,cAAc;AAAA,UACdf,YAAaC,CAAAA,MAAMA,EAAEsB,QAAAA,EAAUC,SAAAA;AAAAA,QAAS,CACzC,CAAC;AAAA,MAAA,CAEL,CAAC;AAAA,MAEJC,SAAS;AAAA,QACPC,QAAQ;AAAA,UACNC,YAAY;AAAA,QAAA;AAAA,QAEdC,QAAQ;AAAA,UAAED;AAAAA,QAAAA,GAAc;AACtB,iBAAO;AAAA,YACL5E,OAAO;AAAA,YACP8E,UAAUF,aAAa,gBAAgBA,UAAU,KAAKG;AAAAA,UAAAA;AAAAA,QAE1D;AAAA,MAAA;AAAA,IACF,CACD,CAAC;AAAA,EAAA;AAGR,EACD;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/input.tsx","../src/types.tsx","../src/index.tsx"],"sourcesContent":["import { CompactObjectInput } from \"@madebywild/sanity-utils/compact-object-input\";\nimport { Stack } from \"@sanity/ui\";\nimport * as React from \"react\";\nimport type { ObjectFieldProps } from \"sanity\";\nimport { MemberField, type ObjectInputProps, type ObjectMember, type StringInputProps } from \"sanity\";\nimport type { CollectionReference, FieldOptions, PluginConfig, ReferenceCollectionExtensions } from \"./types\";\n\nfunction isExtensionEnabled(extensions: ReferenceCollectionExtensions, key: keyof ReferenceCollectionExtensions) {\n return extensions[key] && (extensions[key] === true || extensions[key].enabled !== false);\n}\n\nconst FieldContext = React.createContext<{ options?: FieldOptions }>({});\nconst useFieldCtx = () => React.useContext(FieldContext);\n\nfunction normalizeCollection(preset: CollectionReference) {\n return typeof preset === \"string\" ? { title: preset, value: preset } : preset;\n}\n\nfunction CollectionFieldInput(props: ObjectInputProps) {\n return (\n <FieldContext.Provider value={{ options: props.schemaType.options as FieldOptions | undefined }}>\n <CompactObjectInput space={4} {...props} />\n </FieldContext.Provider>\n );\n}\n\nfunction CollectionOptionsField(props: ObjectFieldProps) {\n const { options } = useFieldCtx();\n // We can hide the field if no extensions are enabled.\n if (!options?.extensions || !Object.keys(options?.extensions).length) return null;\n return <>{props.children}</>;\n}\n\nfunction CollectionOptionsInput(props: ObjectInputProps) {\n const { options } = useFieldCtx();\n const extensions = options?.extensions;\n\n return (\n <Stack space={4}>\n {props.members.map((member: ObjectMember) => {\n if (member.kind !== \"field\") return null;\n\n // Custom filtering extension.\n const filteringEnabled = extensions && isExtensionEnabled(extensions, \"filtering\");\n if (!filteringEnabled && member.name === \"withFilters\") return null;\n\n // Custom pagination extension.\n const paginationEnabled = extensions && isExtensionEnabled(extensions, \"pagination\");\n if (!paginationEnabled && member.name === \"withPagination\") return null;\n\n return <MemberField key={member.key} member={member} {...props} />;\n })}\n </Stack>\n );\n}\n\nfunction CollectionRefInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig?: PluginConfig;\n}) {\n const patchedSchemaType = React.useMemo(() => {\n // Local options take precedence over plugin config.\n const options = props.schemaType.options as FieldOptions | undefined;\n const references = options?.referenceKinds ?? pluginConfig?.referenceKinds;\n\n // No need to touch anything if the list is unchanged.\n if (!references?.length) return props.schemaType;\n\n return {\n ...props.schemaType,\n options: {\n ...props.schemaType.options,\n list: references.map(normalizeCollection),\n },\n };\n }, [props.schemaType]);\n\n return props.renderDefault({\n ...props,\n schemaType: patchedSchemaType,\n });\n}\n\nexport { CollectionRefInput, CollectionFieldInput, CollectionOptionsField, CollectionOptionsInput };\n","import type { ObjectDefinition, ObjectOptions } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.referenceCollection\" as const;\n\n/** @public */\nexport type CollectionReference = string | { title: string; value: string };\n\n/** @public */\nexport type ReferenceCollectionExtensions = Partial<{\n /** Allows filtering the references. */\n filtering: boolean | { enabled?: boolean };\n /** Allows paginating the references. */\n pagination: boolean | { enabled?: boolean };\n}>;\n\n/** @public */\nexport type PluginConfig = {\n /**\n * A list of references the user can choose from.\n * Can be overridden per-field via `options.referenceKinds`.\n * @example\n * ```ts\n * referenceKinds: [\"blogPost\", \"some-type\"],\n * ```\n */\n referenceKinds: CollectionReference[];\n};\n\n/** @public */\nexport type FieldOptions = ObjectOptions & {\n /**\n * Whether the media field should be displayed inline.\n * This will render all children inline on the same level.\n */\n inline?: boolean;\n /**\n * A list of references the user can choose from.\n * Will take precedence over the plugin-level `referenceKinds`.\n * @example\n * ```ts\n * referenceKinds: [\"blogPost\", \"some-type\"],\n * ```\n */\n referenceKinds?: CollectionReference[];\n /**\n * List of extension that add additional behaviors to the link field.\n */\n extensions?: ReferenceCollectionExtensions;\n};\n\n// Add the custom field definition to Sanity's intrinsic definitions\n// so that type checking works correctly when using this field type.\ndeclare module \"sanity\" {\n export interface IntrinsicDefinitions {\n [typeName]: Omit<ObjectDefinition, \"type\" | \"fields\" | \"options\" | \"components\"> & {\n type: typeof typeName;\n options?: FieldOptions;\n };\n }\n}\n","import { defineArrayMember, defineField, definePlugin, defineType } from \"sanity\";\nimport { CollectionFieldInput, CollectionOptionsField, CollectionOptionsInput, CollectionRefInput } from \"./input\";\nimport {\n type CollectionReference,\n type FieldOptions,\n type PluginConfig,\n type ReferenceCollectionExtensions,\n typeName,\n} from \"./types\";\n\n/** @public */\nconst wildSanityReferenceCollectionFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-reference-collection-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"object\",\n title: \"Reference Collection\",\n description: \"Choose a content type and control how the collection is displayed.\",\n icon: () => <>🔃</>,\n validation: (R) => {\n return R.custom((value) => {\n return !value?.collectionRef ? { message: \"Select a reference.\", path: [\"collectionRef\"] } : true;\n });\n },\n components: {\n field: (props) => (props.schemaType.options.inline ? props.children : props.renderDefault(props)),\n input: (props) => <CollectionFieldInput {...props} />,\n },\n fields: [\n defineField({\n name: \"collectionRef\",\n type: \"string\",\n title: \"Collection Type\",\n description: \"Choose which type of content this collection should show.\",\n components: {\n input: (props) => <CollectionRefInput pluginConfig={config} {...props} />,\n },\n options: {\n layout: \"dropdown\",\n list: config.referenceKinds,\n },\n }),\n defineField({\n type: \"object\",\n name: \"options\",\n title: \"Display Settings\",\n description: \"Control filters and pagination for this collection.\",\n options: {\n collapsed: false,\n collapsible: false,\n },\n components: {\n field: (props) => <CollectionOptionsField {...props} />,\n input: (props) => <CollectionOptionsInput {...props} />,\n },\n fields: [\n defineField({\n name: \"withFilters\",\n type: \"boolean\",\n title: \"Enable Filters\",\n description: \"Show filter controls for this collection.\",\n initialValue: false,\n options: { layout: \"switch\" },\n }),\n defineField({\n name: \"filterByKinds\",\n type: \"array\",\n title: \"Available Filter Types\",\n description: \"Choose which content types appear as filter options.\",\n hidden: ({ parent }) => !parent?.withFilters,\n of: [\n defineArrayMember({\n type: \"string\",\n }),\n ],\n options: { layout: \"tags\" },\n validation: (R) => R.unique(),\n }),\n defineField({\n name: \"withPagination\",\n type: \"boolean\",\n title: \"Enable Pagination\",\n description: \"Split collection results across multiple pages.\",\n initialValue: false,\n options: { layout: \"switch\" },\n }),\n defineField({\n name: \"canLoadMore\",\n type: \"boolean\",\n title: \"Can Load More\",\n description: \"Whether to allow loading more items.\",\n hidden: ({ parent }) => !parent?.withPagination,\n initialValue: ({ parent }) => parent?.withPagination,\n options: { layout: \"switch\" },\n }),\n defineField({\n name: \"pageCount\",\n type: \"number\",\n title: \"Items Per Page\",\n description: \"Set how many items to show on each page.\",\n hidden: ({ parent }) => !parent?.withPagination,\n initialValue: 12,\n validation: (R) => R.integer().positive(),\n }),\n ],\n }),\n ],\n preview: {\n select: {\n collection: \"collectionRef\",\n },\n prepare({ collection }) {\n return {\n title: \"Reference Collection\",\n subtitle: collection ? `Reference to ${collection}` : undefined,\n };\n },\n },\n }),\n ],\n },\n };\n});\n\nexport {\n wildSanityReferenceCollectionFieldPlugin,\n typeName,\n type ReferenceCollectionExtensions,\n type PluginConfig,\n type FieldOptions,\n type CollectionReference,\n};\n"],"names":["isExtensionEnabled","extensions","key","enabled","FieldContext","React","createContext","useFieldCtx","useContext","normalizeCollection","preset","title","value","CollectionFieldInput","props","$","_c","t0","schemaType","options","t1","t2","jsx","CompactObjectInput","t3","CollectionOptionsField","Object","keys","length","children","CollectionOptionsInput","members","map","member","kind","name","MemberField","Stack","CollectionRefInput","pluginConfig","bb0","references","referenceKinds","t4","t5","list","t6","patchedSchemaType","renderDefault","typeName","wildSanityReferenceCollectionFieldPlugin","definePlugin","config","schema","types","defineType","type","description","icon","Fragment","validation","R","custom","collectionRef","message","path","components","field","inline","input","fields","defineField","layout","collapsed","collapsible","initialValue","hidden","parent","withFilters","of","defineArrayMember","unique","withPagination","integer","positive","preview","select","collection","prepare","subtitle","undefined"],"mappings":";;;;;;;;;;;;;;;;;;;AAOA,SAASA,mBAAmBC,YAA2CC,KAA0C;AAC/G,SAAOD,WAAWC,GAAG,MAAMD,WAAWC,GAAG,MAAM,MAAQD,WAAWC,GAAG,EAAEC,YAAY;AACrF;AAEA,MAAMC,eAAeC,iBAAMC,cAA0C,CAAA,CAAE,GACjEC,cAAcA,MAAMF,iBAAKG,WAAYJ,YAAY;AAEvD,SAASK,oBAAoBC,QAA6B;AACxD,SAAO,OAAOA,UAAW,WAAW;AAAA,IAAEC,OAAOD;AAAAA,IAAQE,OAAOF;AAAAA,EAAAA,IAAWA;AACzE;AAEA,SAAAG,qBAAAC,OAAA;AAAA,QAAAC,IAAAC,gBAAAA,EA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;;"}
package/dist/index.js CHANGED
@@ -153,6 +153,20 @@ const typeName = "wild.referenceCollection", wildSanityReferenceCollectionFieldP
153
153
  options: {
154
154
  layout: "switch"
155
155
  }
156
+ }), defineField({
157
+ name: "canLoadMore",
158
+ type: "boolean",
159
+ title: "Can Load More",
160
+ description: "Whether to allow loading more items.",
161
+ hidden: ({
162
+ parent
163
+ }) => !parent?.withPagination,
164
+ initialValue: ({
165
+ parent
166
+ }) => parent?.withPagination,
167
+ options: {
168
+ layout: "switch"
169
+ }
156
170
  }), defineField({
157
171
  name: "pageCount",
158
172
  type: "number",
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/input.tsx","../src/types.tsx","../src/index.tsx"],"sourcesContent":["import { CompactObjectInput } from \"@madebywild/sanity-utils/compact-object-input\";\nimport { Stack } from \"@sanity/ui\";\nimport * as React from \"react\";\nimport type { ObjectFieldProps } from \"sanity\";\nimport { MemberField, type ObjectInputProps, type ObjectMember, type StringInputProps } from \"sanity\";\nimport type { CollectionReference, FieldOptions, PluginConfig, ReferenceCollectionExtensions } from \"./types\";\n\nfunction isExtensionEnabled(extensions: ReferenceCollectionExtensions, key: keyof ReferenceCollectionExtensions) {\n return extensions[key] && (extensions[key] === true || extensions[key].enabled !== false);\n}\n\nconst FieldContext = React.createContext<{ options?: FieldOptions }>({});\nconst useFieldCtx = () => React.useContext(FieldContext);\n\nfunction normalizeCollection(preset: CollectionReference) {\n return typeof preset === \"string\" ? { title: preset, value: preset } : preset;\n}\n\nfunction CollectionFieldInput(props: ObjectInputProps) {\n return (\n <FieldContext.Provider value={{ options: props.schemaType.options as FieldOptions | undefined }}>\n <CompactObjectInput space={4} {...props} />\n </FieldContext.Provider>\n );\n}\n\nfunction CollectionOptionsField(props: ObjectFieldProps) {\n const { options } = useFieldCtx();\n // We can hide the field if no extensions are enabled.\n if (!options?.extensions || !Object.keys(options?.extensions).length) return null;\n return <>{props.children}</>;\n}\n\nfunction CollectionOptionsInput(props: ObjectInputProps) {\n const { options } = useFieldCtx();\n const extensions = options?.extensions;\n\n return (\n <Stack space={4}>\n {props.members.map((member: ObjectMember) => {\n if (member.kind !== \"field\") return null;\n\n // Custom filtering extension.\n const filteringEnabled = extensions && isExtensionEnabled(extensions, \"filtering\");\n if (!filteringEnabled && member.name === \"withFilters\") return null;\n\n // Custom pagination extension.\n const paginationEnabled = extensions && isExtensionEnabled(extensions, \"pagination\");\n if (!paginationEnabled && member.name === \"withPagination\") return null;\n\n return <MemberField key={member.key} member={member} {...props} />;\n })}\n </Stack>\n );\n}\n\nfunction CollectionRefInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig?: PluginConfig;\n}) {\n const patchedSchemaType = React.useMemo(() => {\n // Local options take precedence over plugin config.\n const options = props.schemaType.options as FieldOptions | undefined;\n const references = options?.referenceKinds ?? pluginConfig?.referenceKinds;\n\n // No need to touch anything if the list is unchanged.\n if (!references?.length) return props.schemaType;\n\n return {\n ...props.schemaType,\n options: {\n ...props.schemaType.options,\n list: references.map(normalizeCollection),\n },\n };\n }, [props.schemaType]);\n\n return props.renderDefault({\n ...props,\n schemaType: patchedSchemaType,\n });\n}\n\nexport { CollectionRefInput, CollectionFieldInput, CollectionOptionsField, CollectionOptionsInput };\n","import type { ObjectDefinition, ObjectOptions } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.referenceCollection\" as const;\n\n/** @public */\nexport type CollectionReference = string | { title: string; value: string };\n\n/** @public */\nexport type ReferenceCollectionExtensions = Partial<{\n /** Allows filtering the references. */\n filtering: boolean | { enabled?: boolean };\n /** Allows paginating the references. */\n pagination: boolean | { enabled?: boolean };\n}>;\n\n/** @public */\nexport type PluginConfig = {\n /**\n * A list of references the user can choose from.\n * Can be overridden per-field via `options.referenceKinds`.\n * @example\n * ```ts\n * referenceKinds: [\"blogPost\", \"some-type\"],\n * ```\n */\n referenceKinds: CollectionReference[];\n};\n\n/** @public */\nexport type FieldOptions = ObjectOptions & {\n /**\n * Whether the media field should be displayed inline.\n * This will render all children inline on the same level.\n */\n inline?: boolean;\n /**\n * A list of references the user can choose from.\n * Will take precedence over the plugin-level `referenceKinds`.\n * @example\n * ```ts\n * referenceKinds: [\"blogPost\", \"some-type\"],\n * ```\n */\n referenceKinds?: CollectionReference[];\n /**\n * List of extension that add additional behaviors to the link field.\n */\n extensions?: ReferenceCollectionExtensions;\n};\n\n// Add the custom field definition to Sanity's intrinsic definitions\n// so that type checking works correctly when using this field type.\ndeclare module \"sanity\" {\n export interface IntrinsicDefinitions {\n [typeName]: Omit<ObjectDefinition, \"type\" | \"fields\" | \"options\" | \"components\"> & {\n type: typeof typeName;\n options?: FieldOptions;\n };\n }\n}\n","import { defineArrayMember, defineField, definePlugin, defineType } from \"sanity\";\nimport { CollectionFieldInput, CollectionOptionsField, CollectionOptionsInput, CollectionRefInput } from \"./input\";\nimport {\n type CollectionReference,\n type FieldOptions,\n type PluginConfig,\n type ReferenceCollectionExtensions,\n typeName,\n} from \"./types\";\n\n/** @public */\nconst wildSanityReferenceCollectionFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-reference-collection-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"object\",\n title: \"Reference Collection\",\n description: \"Choose a content type and control how the collection is displayed.\",\n icon: () => <>🔃</>,\n validation: (R) => {\n return R.custom((value) => {\n return !value?.collectionRef ? { message: \"Select a reference.\", path: [\"collectionRef\"] } : true;\n });\n },\n components: {\n field: (props) => (props.schemaType.options.inline ? props.children : props.renderDefault(props)),\n input: (props) => <CollectionFieldInput {...props} />,\n },\n fields: [\n defineField({\n name: \"collectionRef\",\n type: \"string\",\n title: \"Collection Type\",\n description: \"Choose which type of content this collection should show.\",\n components: {\n input: (props) => <CollectionRefInput pluginConfig={config} {...props} />,\n },\n options: {\n layout: \"dropdown\",\n list: config.referenceKinds,\n },\n }),\n defineField({\n type: \"object\",\n name: \"options\",\n title: \"Display Settings\",\n description: \"Control filters and pagination for this collection.\",\n options: {\n collapsed: false,\n collapsible: false,\n },\n components: {\n field: (props) => <CollectionOptionsField {...props} />,\n input: (props) => <CollectionOptionsInput {...props} />,\n },\n fields: [\n defineField({\n name: \"withFilters\",\n type: \"boolean\",\n title: \"Enable Filters\",\n description: \"Show filter controls for this collection.\",\n initialValue: false,\n options: { layout: \"switch\" },\n }),\n defineField({\n name: \"filterByKinds\",\n type: \"array\",\n title: \"Available Filter Types\",\n description: \"Choose which content types appear as filter options.\",\n hidden: ({ parent }) => !parent?.withFilters,\n of: [\n defineArrayMember({\n type: \"string\",\n }),\n ],\n options: { layout: \"tags\" },\n validation: (R) => R.unique(),\n }),\n defineField({\n name: \"withPagination\",\n type: \"boolean\",\n title: \"Enable Pagination\",\n description: \"Split collection results across multiple pages.\",\n initialValue: false,\n options: { layout: \"switch\" },\n }),\n defineField({\n name: \"pageCount\",\n type: \"number\",\n title: \"Items Per Page\",\n description: \"Set how many items to show on each page.\",\n hidden: ({ parent }) => !parent?.withPagination,\n initialValue: 12,\n validation: (R) => R.integer().positive(),\n }),\n ],\n }),\n ],\n preview: {\n select: {\n collection: \"collectionRef\",\n },\n prepare({ collection }) {\n return {\n title: \"Reference Collection\",\n subtitle: collection ? `Reference to ${collection}` : undefined,\n };\n },\n },\n }),\n ],\n },\n };\n});\n\nexport {\n wildSanityReferenceCollectionFieldPlugin,\n typeName,\n type ReferenceCollectionExtensions,\n type PluginConfig,\n type FieldOptions,\n type CollectionReference,\n};\n"],"names":["isExtensionEnabled","extensions","key","enabled","FieldContext","React","createContext","useFieldCtx","useContext","normalizeCollection","preset","title","value","CollectionFieldInput","props","$","_c","t0","schemaType","options","t1","t2","t3","CollectionOptionsField","Object","keys","length","children","CollectionOptionsInput","members","map","member","kind","name","CollectionRefInput","pluginConfig","bb0","references","referenceKinds","t4","t5","list","t6","patchedSchemaType","renderDefault","typeName","wildSanityReferenceCollectionFieldPlugin","definePlugin","config","schema","types","defineType","type","description","icon","validation","R","custom","collectionRef","message","path","components","field","inline","input","fields","defineField","layout","collapsed","collapsible","initialValue","hidden","parent","withFilters","of","defineArrayMember","unique","withPagination","integer","positive","preview","select","collection","prepare","subtitle","undefined"],"mappings":";;;;;;AAOA,SAASA,mBAAmBC,YAA2CC,KAA0C;AAC/G,SAAOD,WAAWC,GAAG,MAAMD,WAAWC,GAAG,MAAM,MAAQD,WAAWC,GAAG,EAAEC,YAAY;AACrF;AAEA,MAAMC,eAAeC,MAAMC,cAA0C,CAAA,CAAE,GACjEC,cAAcA,MAAMF,MAAKG,WAAYJ,YAAY;AAEvD,SAASK,oBAAoBC,QAA6B;AACxD,SAAO,OAAOA,UAAW,WAAW;AAAA,IAAEC,OAAOD;AAAAA,IAAQE,OAAOF;AAAAA,EAAAA,IAAWA;AACzE;AAEA,SAAAG,qBAAAC,OAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GAE6CC,KAAAH,MAAKI,WAAWC;AAAoC,MAAAC;AAAAL,WAAAE,MAA/DG,KAAA;AAAA,IAAAD,SAAWF;AAAAA,EAAAA,GAAsDF,OAAAE,IAAAF,OAAAK,MAAAA,KAAAL,EAAA,CAAA;AAAA,MAAAM;AAAAN,WAAAD,SAC7FO,KAAA,oBAAC,oBAAA,EAA0B,OAAA,GAAC,GAAMP,MAAAA,CAAK,GAAIC,OAAAD,OAAAC,OAAAM,MAAAA,KAAAN,EAAA,CAAA;AAAA,MAAAO;AAAA,SAAAP,EAAA,CAAA,MAAAK,MAAAL,SAAAM,MAD7CC,KAAA,oBAAA,aAAA,UAAA,EAA8B,OAAAF,IAC5BC,UAAAA,GAAAA,CACF,GAAwBN,OAAAK,IAAAL,OAAAM,IAAAN,OAAAO,MAAAA,KAAAP,EAAA,CAAA,GAFxBO;AAEwB;AAI5B,SAAAC,uBAAAT,OAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GACE;AAAA,IAAAG;AAAAA,EAAAA,IAAoBZ,YAAAA;AAEpB,MAAI,CAACY,SAAOlB,cAAR,CAAyBuB,OAAM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;AAAA,IACF,CACD,CAAC;AAAA,EAAA;AAGR,EACD;"}
1
+ {"version":3,"file":"index.js","sources":["../src/input.tsx","../src/types.tsx","../src/index.tsx"],"sourcesContent":["import { CompactObjectInput } from \"@madebywild/sanity-utils/compact-object-input\";\nimport { Stack } from \"@sanity/ui\";\nimport * as React from \"react\";\nimport type { ObjectFieldProps } from \"sanity\";\nimport { MemberField, type ObjectInputProps, type ObjectMember, type StringInputProps } from \"sanity\";\nimport type { CollectionReference, FieldOptions, PluginConfig, ReferenceCollectionExtensions } from \"./types\";\n\nfunction isExtensionEnabled(extensions: ReferenceCollectionExtensions, key: keyof ReferenceCollectionExtensions) {\n return extensions[key] && (extensions[key] === true || extensions[key].enabled !== false);\n}\n\nconst FieldContext = React.createContext<{ options?: FieldOptions }>({});\nconst useFieldCtx = () => React.useContext(FieldContext);\n\nfunction normalizeCollection(preset: CollectionReference) {\n return typeof preset === \"string\" ? { title: preset, value: preset } : preset;\n}\n\nfunction CollectionFieldInput(props: ObjectInputProps) {\n return (\n <FieldContext.Provider value={{ options: props.schemaType.options as FieldOptions | undefined }}>\n <CompactObjectInput space={4} {...props} />\n </FieldContext.Provider>\n );\n}\n\nfunction CollectionOptionsField(props: ObjectFieldProps) {\n const { options } = useFieldCtx();\n // We can hide the field if no extensions are enabled.\n if (!options?.extensions || !Object.keys(options?.extensions).length) return null;\n return <>{props.children}</>;\n}\n\nfunction CollectionOptionsInput(props: ObjectInputProps) {\n const { options } = useFieldCtx();\n const extensions = options?.extensions;\n\n return (\n <Stack space={4}>\n {props.members.map((member: ObjectMember) => {\n if (member.kind !== \"field\") return null;\n\n // Custom filtering extension.\n const filteringEnabled = extensions && isExtensionEnabled(extensions, \"filtering\");\n if (!filteringEnabled && member.name === \"withFilters\") return null;\n\n // Custom pagination extension.\n const paginationEnabled = extensions && isExtensionEnabled(extensions, \"pagination\");\n if (!paginationEnabled && member.name === \"withPagination\") return null;\n\n return <MemberField key={member.key} member={member} {...props} />;\n })}\n </Stack>\n );\n}\n\nfunction CollectionRefInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig?: PluginConfig;\n}) {\n const patchedSchemaType = React.useMemo(() => {\n // Local options take precedence over plugin config.\n const options = props.schemaType.options as FieldOptions | undefined;\n const references = options?.referenceKinds ?? pluginConfig?.referenceKinds;\n\n // No need to touch anything if the list is unchanged.\n if (!references?.length) return props.schemaType;\n\n return {\n ...props.schemaType,\n options: {\n ...props.schemaType.options,\n list: references.map(normalizeCollection),\n },\n };\n }, [props.schemaType]);\n\n return props.renderDefault({\n ...props,\n schemaType: patchedSchemaType,\n });\n}\n\nexport { CollectionRefInput, CollectionFieldInput, CollectionOptionsField, CollectionOptionsInput };\n","import type { ObjectDefinition, ObjectOptions } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.referenceCollection\" as const;\n\n/** @public */\nexport type CollectionReference = string | { title: string; value: string };\n\n/** @public */\nexport type ReferenceCollectionExtensions = Partial<{\n /** Allows filtering the references. */\n filtering: boolean | { enabled?: boolean };\n /** Allows paginating the references. */\n pagination: boolean | { enabled?: boolean };\n}>;\n\n/** @public */\nexport type PluginConfig = {\n /**\n * A list of references the user can choose from.\n * Can be overridden per-field via `options.referenceKinds`.\n * @example\n * ```ts\n * referenceKinds: [\"blogPost\", \"some-type\"],\n * ```\n */\n referenceKinds: CollectionReference[];\n};\n\n/** @public */\nexport type FieldOptions = ObjectOptions & {\n /**\n * Whether the media field should be displayed inline.\n * This will render all children inline on the same level.\n */\n inline?: boolean;\n /**\n * A list of references the user can choose from.\n * Will take precedence over the plugin-level `referenceKinds`.\n * @example\n * ```ts\n * referenceKinds: [\"blogPost\", \"some-type\"],\n * ```\n */\n referenceKinds?: CollectionReference[];\n /**\n * List of extension that add additional behaviors to the link field.\n */\n extensions?: ReferenceCollectionExtensions;\n};\n\n// Add the custom field definition to Sanity's intrinsic definitions\n// so that type checking works correctly when using this field type.\ndeclare module \"sanity\" {\n export interface IntrinsicDefinitions {\n [typeName]: Omit<ObjectDefinition, \"type\" | \"fields\" | \"options\" | \"components\"> & {\n type: typeof typeName;\n options?: FieldOptions;\n };\n }\n}\n","import { defineArrayMember, defineField, definePlugin, defineType } from \"sanity\";\nimport { CollectionFieldInput, CollectionOptionsField, CollectionOptionsInput, CollectionRefInput } from \"./input\";\nimport {\n type CollectionReference,\n type FieldOptions,\n type PluginConfig,\n type ReferenceCollectionExtensions,\n typeName,\n} from \"./types\";\n\n/** @public */\nconst wildSanityReferenceCollectionFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-reference-collection-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"object\",\n title: \"Reference Collection\",\n description: \"Choose a content type and control how the collection is displayed.\",\n icon: () => <>🔃</>,\n validation: (R) => {\n return R.custom((value) => {\n return !value?.collectionRef ? { message: \"Select a reference.\", path: [\"collectionRef\"] } : true;\n });\n },\n components: {\n field: (props) => (props.schemaType.options.inline ? props.children : props.renderDefault(props)),\n input: (props) => <CollectionFieldInput {...props} />,\n },\n fields: [\n defineField({\n name: \"collectionRef\",\n type: \"string\",\n title: \"Collection Type\",\n description: \"Choose which type of content this collection should show.\",\n components: {\n input: (props) => <CollectionRefInput pluginConfig={config} {...props} />,\n },\n options: {\n layout: \"dropdown\",\n list: config.referenceKinds,\n },\n }),\n defineField({\n type: \"object\",\n name: \"options\",\n title: \"Display Settings\",\n description: \"Control filters and pagination for this collection.\",\n options: {\n collapsed: false,\n collapsible: false,\n },\n components: {\n field: (props) => <CollectionOptionsField {...props} />,\n input: (props) => <CollectionOptionsInput {...props} />,\n },\n fields: [\n defineField({\n name: \"withFilters\",\n type: \"boolean\",\n title: \"Enable Filters\",\n description: \"Show filter controls for this collection.\",\n initialValue: false,\n options: { layout: \"switch\" },\n }),\n defineField({\n name: \"filterByKinds\",\n type: \"array\",\n title: \"Available Filter Types\",\n description: \"Choose which content types appear as filter options.\",\n hidden: ({ parent }) => !parent?.withFilters,\n of: [\n defineArrayMember({\n type: \"string\",\n }),\n ],\n options: { layout: \"tags\" },\n validation: (R) => R.unique(),\n }),\n defineField({\n name: \"withPagination\",\n type: \"boolean\",\n title: \"Enable Pagination\",\n description: \"Split collection results across multiple pages.\",\n initialValue: false,\n options: { layout: \"switch\" },\n }),\n defineField({\n name: \"canLoadMore\",\n type: \"boolean\",\n title: \"Can Load More\",\n description: \"Whether to allow loading more items.\",\n hidden: ({ parent }) => !parent?.withPagination,\n initialValue: ({ parent }) => parent?.withPagination,\n options: { layout: \"switch\" },\n }),\n defineField({\n name: \"pageCount\",\n type: \"number\",\n title: \"Items Per Page\",\n description: \"Set how many items to show on each page.\",\n hidden: ({ parent }) => !parent?.withPagination,\n initialValue: 12,\n validation: (R) => R.integer().positive(),\n }),\n ],\n }),\n ],\n preview: {\n select: {\n collection: \"collectionRef\",\n },\n prepare({ collection }) {\n return {\n title: \"Reference Collection\",\n subtitle: collection ? `Reference to ${collection}` : undefined,\n };\n },\n },\n }),\n ],\n },\n };\n});\n\nexport {\n wildSanityReferenceCollectionFieldPlugin,\n typeName,\n type ReferenceCollectionExtensions,\n type PluginConfig,\n type FieldOptions,\n type CollectionReference,\n};\n"],"names":["isExtensionEnabled","extensions","key","enabled","FieldContext","React","createContext","useFieldCtx","useContext","normalizeCollection","preset","title","value","CollectionFieldInput","props","$","_c","t0","schemaType","options","t1","t2","t3","CollectionOptionsField","Object","keys","length","children","CollectionOptionsInput","members","map","member","kind","name","CollectionRefInput","pluginConfig","bb0","references","referenceKinds","t4","t5","list","t6","patchedSchemaType","renderDefault","typeName","wildSanityReferenceCollectionFieldPlugin","definePlugin","config","schema","types","defineType","type","description","icon","validation","R","custom","collectionRef","message","path","components","field","inline","input","fields","defineField","layout","collapsed","collapsible","initialValue","hidden","parent","withFilters","of","defineArrayMember","unique","withPagination","integer","positive","preview","select","collection","prepare","subtitle","undefined"],"mappings":";;;;;;AAOA,SAASA,mBAAmBC,YAA2CC,KAA0C;AAC/G,SAAOD,WAAWC,GAAG,MAAMD,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AAO;AAAA,YACLvE,OAAO;AAAA,YACPyE,UAAUF,aAAa,gBAAgBA,UAAU,KAAKG;AAAAA,UAAAA;AAAAA,QAE1D;AAAA,MAAA;AAAA,IACF,CACD,CAAC;AAAA,EAAA;AAGR,EACD;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madebywild/sanity-reference-collection-field",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "UNLICENSED",
package/src/index.tsx CHANGED
@@ -87,6 +87,15 @@ const wildSanityReferenceCollectionFieldPlugin = definePlugin<PluginConfig>((con
87
87
  initialValue: false,
88
88
  options: { layout: "switch" },
89
89
  }),
90
+ defineField({
91
+ name: "canLoadMore",
92
+ type: "boolean",
93
+ title: "Can Load More",
94
+ description: "Whether to allow loading more items.",
95
+ hidden: ({ parent }) => !parent?.withPagination,
96
+ initialValue: ({ parent }) => parent?.withPagination,
97
+ options: { layout: "switch" },
98
+ }),
90
99
  defineField({
91
100
  name: "pageCount",
92
101
  type: "number",