@madebywild/sanity-quote-field 0.0.17 → 1.0.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/LICENSE +21 -0
- package/README.md +39 -0
- package/dist/index.cjs +3 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/index.tsx +3 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Made by Wild
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1 +1,40 @@
|
|
|
1
|
+
> [!IMPORTANT]
|
|
2
|
+
> This package is primarily intended for internal use.
|
|
3
|
+
|
|
1
4
|
# @madebywild/sanity-quote-field
|
|
5
|
+
|
|
6
|
+
Sanity object field for quotes with optional referenced authors.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @madebywild/sanity-quote-field
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Configure Plugin
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { wildSanityQuoteFieldPlugin } from "@madebywild/sanity-quote-field";
|
|
19
|
+
|
|
20
|
+
export default defineConfig({
|
|
21
|
+
plugins: [
|
|
22
|
+
wildSanityQuoteFieldPlugin({
|
|
23
|
+
authorRef: { to: [{ type: "person" }] },
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Use in Schema
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { requireQuote } from "@madebywild/sanity-quote-field";
|
|
33
|
+
|
|
34
|
+
defineField({
|
|
35
|
+
name: "testimonial",
|
|
36
|
+
type: "wild.quote",
|
|
37
|
+
validation: (R) => requireQuote(R),
|
|
38
|
+
options: { inline: true },
|
|
39
|
+
});
|
|
40
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var jsxRuntime = require("react/jsx-runtime"), sanityUtils = require("@madebywild/sanity-utils"), sanity = require("sanity");
|
|
3
|
+
var jsxRuntime = require("react/jsx-runtime"), sanityUtils = require("@madebywild/sanity-utils"), compactObjectInput = require("@madebywild/sanity-utils/compact-object-input"), sanity = require("sanity");
|
|
4
4
|
const typeName = "wild.quote", wildSanityQuoteFieldPlugin = sanity.definePlugin((config) => ({
|
|
5
5
|
name: "@madebywild/sanity-quote-field",
|
|
6
6
|
schema: {
|
|
@@ -15,7 +15,8 @@ const typeName = "wild.quote", wildSanityQuoteFieldPlugin = sanity.definePlugin(
|
|
|
15
15
|
collapsible: !0
|
|
16
16
|
},
|
|
17
17
|
components: {
|
|
18
|
-
field: (props) => props.schemaType.options.inline ? props.children : props.renderDefault(props)
|
|
18
|
+
field: (props) => props.schemaType.options.inline ? props.children : props.renderDefault(props),
|
|
19
|
+
input: (props) => /* @__PURE__ */ jsxRuntime.jsx(compactObjectInput.CompactObjectInput, { ...props, space: 4 })
|
|
19
20
|
},
|
|
20
21
|
fields: [
|
|
21
22
|
sanity.defineField({
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/types.tsx","../src/index.tsx"],"sourcesContent":["import type { FieldOptions as RichtextOptions } from \"@madebywild/sanity-richtext-field\";\nimport type { ObjectDefinition, ObjectOptions, ReferenceDefinition } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.quote\" as const;\n\n/** @public */\nexport type PluginConfig = {\n /**\n * A reference definition for the author of the quote.\n * If provided, this reference will be used to fetch author details.\n * If not provided, the quote will use simple text fields for author name and title.\n */\n authorRef?: Omit<ReferenceDefinition, \"type\" | \"name\">;\n /**\n * Options to configure the richtext field used for the quote content.\n * Options will be passed to the underlying `@madebywild/sanity-richtext-field` field.\n */\n richtextOptions?: RichtextOptions;\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\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 { createExcerptFromPortableText } from \"@madebywild/sanity-utils\";\nimport { defineField, definePlugin, defineType, type ObjectRule } from \"sanity\";\nimport { type PluginConfig, typeName } from \"./types\";\n\n/** @public */\n// biome-ignore lint/suspicious/noConfusingVoidType: it can be void.\nconst wildSanityQuoteFieldPlugin = definePlugin<PluginConfig | void>((config) => {\n return {\n name: \"@madebywild/sanity-quote-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"object\",\n title: \"Quote\",\n description: \"A stylized quote with optional author.\",\n icon: () => <>❝❞</>,\n options: {\n collapsed: false,\n collapsible: true,\n },\n components: {\n field: (props) => (props.schemaType.options.inline ? props.children : props.renderDefault(props)),\n },\n fields: [\n defineField({\n name: \"quote\",\n type: \"wild.richtext\",\n title: \"Quote\",\n description: \"The quote text.\",\n options: {\n // Disable all parts by default.\n allowedParts: [],\n ...config?.richtextOptions,\n },\n }),\n // Display a reference field if the user provided a author typeName.\n // Otherwise, display a string field for the author name & description.\n ...(config?.authorRef\n ? [\n defineField({\n name: \"authorRef\",\n title: \"Author\",\n description: \"The author of the quote.\",\n type: \"reference\",\n weak: true,\n ...config.authorRef,\n }),\n ]\n : [\n defineField({\n type: \"string\",\n name: \"authorName\",\n title: \"Author Name\",\n description: \"The author name of the quote.\",\n }),\n defineField({\n type: \"text\",\n rows: 2,\n name: \"authorDescription\",\n title: \"Author Description\",\n description: \"The author description of the quote.\",\n }),\n ]),\n ],\n preview: {\n select: {\n quote: \"quote\",\n // Try a few common properties to try and guess the referenced value.\n // TODO: To do this properly, we need the user to pass in a preview.\n authorName: config?.authorRef?.to ? \"author.name\" : \"authorName\",\n authorTitle: config?.authorRef?.to ? \"author.title\" : \"authorName\",\n },\n prepare({ quote, authorName, authorTitle }) {\n const resolvedName = authorName || authorTitle;\n return {\n title: quote ? createExcerptFromPortableText(quote, 25) : \"No quote\",\n subtitle: resolvedName ? `— ${resolvedName}` : undefined,\n };\n },\n },\n }),\n ],\n },\n };\n});\n\n/** @public */\nfunction requireQuote(R: ObjectRule) {\n return R.custom((ctx) => (!ctx?.quote ? { message: \"Enter a quote.\", path: [\"quote\"] } : true));\n}\n\nexport {
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/types.tsx","../src/index.tsx"],"sourcesContent":["import type { FieldOptions as RichtextOptions } from \"@madebywild/sanity-richtext-field\";\nimport type { ObjectDefinition, ObjectOptions, ReferenceDefinition } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.quote\" as const;\n\n/** @public */\nexport type PluginConfig = {\n /**\n * A reference definition for the author of the quote.\n * If provided, this reference will be used to fetch author details.\n * If not provided, the quote will use simple text fields for author name and title.\n */\n authorRef?: Omit<ReferenceDefinition, \"type\" | \"name\">;\n /**\n * Options to configure the richtext field used for the quote content.\n * Options will be passed to the underlying `@madebywild/sanity-richtext-field` field.\n */\n richtextOptions?: RichtextOptions;\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\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 { createExcerptFromPortableText } from \"@madebywild/sanity-utils\";\nimport { CompactObjectInput } from \"@madebywild/sanity-utils/compact-object-input\";\nimport { defineField, definePlugin, defineType, type ObjectRule } from \"sanity\";\nimport { type PluginConfig, typeName } from \"./types\";\n\n/** @public */\n// biome-ignore lint/suspicious/noConfusingVoidType: it can be void.\nconst wildSanityQuoteFieldPlugin = definePlugin<PluginConfig | void>((config) => {\n return {\n name: \"@madebywild/sanity-quote-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"object\",\n title: \"Quote\",\n description: \"A stylized quote with optional author.\",\n icon: () => <>❝❞</>,\n options: {\n collapsed: false,\n collapsible: true,\n },\n components: {\n field: (props) => (props.schemaType.options.inline ? props.children : props.renderDefault(props)),\n input: (props) => <CompactObjectInput {...props} space={4} />,\n },\n fields: [\n defineField({\n name: \"quote\",\n type: \"wild.richtext\",\n title: \"Quote\",\n description: \"The quote text.\",\n options: {\n // Disable all parts by default.\n allowedParts: [],\n ...config?.richtextOptions,\n },\n }),\n // Display a reference field if the user provided a author typeName.\n // Otherwise, display a string field for the author name & description.\n ...(config?.authorRef\n ? [\n defineField({\n name: \"authorRef\",\n title: \"Author\",\n description: \"The author of the quote.\",\n type: \"reference\",\n weak: true,\n ...config.authorRef,\n }),\n ]\n : [\n defineField({\n type: \"string\",\n name: \"authorName\",\n title: \"Author Name\",\n description: \"The author name of the quote.\",\n }),\n defineField({\n type: \"text\",\n rows: 2,\n name: \"authorDescription\",\n title: \"Author Description\",\n description: \"The author description of the quote.\",\n }),\n ]),\n ],\n preview: {\n select: {\n quote: \"quote\",\n // Try a few common properties to try and guess the referenced value.\n // TODO: To do this properly, we need the user to pass in a preview.\n authorName: config?.authorRef?.to ? \"author.name\" : \"authorName\",\n authorTitle: config?.authorRef?.to ? \"author.title\" : \"authorName\",\n },\n prepare({ quote, authorName, authorTitle }) {\n const resolvedName = authorName || authorTitle;\n return {\n title: quote ? createExcerptFromPortableText(quote, 25) : \"No quote\",\n subtitle: resolvedName ? `— ${resolvedName}` : undefined,\n };\n },\n },\n }),\n ],\n },\n };\n});\n\n/** @public */\nfunction requireQuote(R: ObjectRule) {\n return R.custom((ctx) => (!ctx?.quote ? { message: \"Enter a quote.\", path: [\"quote\"] } : true));\n}\n\nexport { requireQuote, typeName, wildSanityQuoteFieldPlugin, type PluginConfig };\n"],"names":["typeName","wildSanityQuoteFieldPlugin","definePlugin","config","name","schema","types","defineType","type","title","description","icon","jsx","Fragment","options","collapsed","collapsible","components","field","props","schemaType","inline","children","renderDefault","input","CompactObjectInput","fields","defineField","allowedParts","richtextOptions","authorRef","weak","rows","preview","select","quote","authorName","to","authorTitle","prepare","resolvedName","createExcerptFromPortableText","subtitle","undefined","requireQuote","R","custom","ctx","message","path"],"mappings":";;;AAIO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AAa;AAAA,QAAA,CACd,CAAC;AAAA,MAAA;AAAA,MAGVuB,SAAS;AAAA,QACPC,QAAQ;AAAA,UACNC,OAAO;AAAA;AAAA;AAAA,UAGPC,YAAYjC,QAAQ2B,WAAWO,KAAK,gBAAgB;AAAA,UACpDC,aAAanC,QAAQ2B,WAAWO,KAAK,iBAAiB;AAAA,QAAA;AAAA,QAExDE,QAAQ;AAAA,UAAEJ;AAAAA,UAAOC;AAAAA,UAAYE;AAAAA,QAAAA,GAAe;AAC1C,gBAAME,eAAeJ,cAAcE;AACnC,iBAAO;AAAA,YACL7B,OAAO0B,QAAQM,YAAAA,8BAA8BN,OAAO,EAAE,IAAI;AAAA,YAC1DO,UAAUF,eAAe,UAAKA,YAAY,KAAKG;AAAAA,UAAAA;AAAAA,QAEnD;AAAA,MAAA;AAAA,IACF,CACD,CAAC;AAAA,EAAA;AAGR,EACD;AAGD,SAASC,aAAaC,GAAe;AACnC,SAAOA,EAAEC,OAAQC,CAAAA,QAAUA,KAAKZ,QAAyD,KAAjD;AAAA,IAAEa,SAAS;AAAA,IAAkBC,MAAM,CAAC,OAAO;AAAA,EAAA,CAAW;AAChG;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { createExcerptFromPortableText } from "@madebywild/sanity-utils";
|
|
3
|
+
import { CompactObjectInput } from "@madebywild/sanity-utils/compact-object-input";
|
|
3
4
|
import { definePlugin, defineType, defineField } from "sanity";
|
|
4
5
|
const typeName = "wild.quote", wildSanityQuoteFieldPlugin = definePlugin((config) => ({
|
|
5
6
|
name: "@madebywild/sanity-quote-field",
|
|
@@ -15,7 +16,8 @@ const typeName = "wild.quote", wildSanityQuoteFieldPlugin = definePlugin((config
|
|
|
15
16
|
collapsible: !0
|
|
16
17
|
},
|
|
17
18
|
components: {
|
|
18
|
-
field: (props) => props.schemaType.options.inline ? props.children : props.renderDefault(props)
|
|
19
|
+
field: (props) => props.schemaType.options.inline ? props.children : props.renderDefault(props),
|
|
20
|
+
input: (props) => /* @__PURE__ */ jsx(CompactObjectInput, { ...props, space: 4 })
|
|
19
21
|
},
|
|
20
22
|
fields: [
|
|
21
23
|
defineField({
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/types.tsx","../src/index.tsx"],"sourcesContent":["import type { FieldOptions as RichtextOptions } from \"@madebywild/sanity-richtext-field\";\nimport type { ObjectDefinition, ObjectOptions, ReferenceDefinition } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.quote\" as const;\n\n/** @public */\nexport type PluginConfig = {\n /**\n * A reference definition for the author of the quote.\n * If provided, this reference will be used to fetch author details.\n * If not provided, the quote will use simple text fields for author name and title.\n */\n authorRef?: Omit<ReferenceDefinition, \"type\" | \"name\">;\n /**\n * Options to configure the richtext field used for the quote content.\n * Options will be passed to the underlying `@madebywild/sanity-richtext-field` field.\n */\n richtextOptions?: RichtextOptions;\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\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 { createExcerptFromPortableText } from \"@madebywild/sanity-utils\";\nimport { defineField, definePlugin, defineType, type ObjectRule } from \"sanity\";\nimport { type PluginConfig, typeName } from \"./types\";\n\n/** @public */\n// biome-ignore lint/suspicious/noConfusingVoidType: it can be void.\nconst wildSanityQuoteFieldPlugin = definePlugin<PluginConfig | void>((config) => {\n return {\n name: \"@madebywild/sanity-quote-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"object\",\n title: \"Quote\",\n description: \"A stylized quote with optional author.\",\n icon: () => <>❝❞</>,\n options: {\n collapsed: false,\n collapsible: true,\n },\n components: {\n field: (props) => (props.schemaType.options.inline ? props.children : props.renderDefault(props)),\n },\n fields: [\n defineField({\n name: \"quote\",\n type: \"wild.richtext\",\n title: \"Quote\",\n description: \"The quote text.\",\n options: {\n // Disable all parts by default.\n allowedParts: [],\n ...config?.richtextOptions,\n },\n }),\n // Display a reference field if the user provided a author typeName.\n // Otherwise, display a string field for the author name & description.\n ...(config?.authorRef\n ? [\n defineField({\n name: \"authorRef\",\n title: \"Author\",\n description: \"The author of the quote.\",\n type: \"reference\",\n weak: true,\n ...config.authorRef,\n }),\n ]\n : [\n defineField({\n type: \"string\",\n name: \"authorName\",\n title: \"Author Name\",\n description: \"The author name of the quote.\",\n }),\n defineField({\n type: \"text\",\n rows: 2,\n name: \"authorDescription\",\n title: \"Author Description\",\n description: \"The author description of the quote.\",\n }),\n ]),\n ],\n preview: {\n select: {\n quote: \"quote\",\n // Try a few common properties to try and guess the referenced value.\n // TODO: To do this properly, we need the user to pass in a preview.\n authorName: config?.authorRef?.to ? \"author.name\" : \"authorName\",\n authorTitle: config?.authorRef?.to ? \"author.title\" : \"authorName\",\n },\n prepare({ quote, authorName, authorTitle }) {\n const resolvedName = authorName || authorTitle;\n return {\n title: quote ? createExcerptFromPortableText(quote, 25) : \"No quote\",\n subtitle: resolvedName ? `— ${resolvedName}` : undefined,\n };\n },\n },\n }),\n ],\n },\n };\n});\n\n/** @public */\nfunction requireQuote(R: ObjectRule) {\n return R.custom((ctx) => (!ctx?.quote ? { message: \"Enter a quote.\", path: [\"quote\"] } : true));\n}\n\nexport {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/types.tsx","../src/index.tsx"],"sourcesContent":["import type { FieldOptions as RichtextOptions } from \"@madebywild/sanity-richtext-field\";\nimport type { ObjectDefinition, ObjectOptions, ReferenceDefinition } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.quote\" as const;\n\n/** @public */\nexport type PluginConfig = {\n /**\n * A reference definition for the author of the quote.\n * If provided, this reference will be used to fetch author details.\n * If not provided, the quote will use simple text fields for author name and title.\n */\n authorRef?: Omit<ReferenceDefinition, \"type\" | \"name\">;\n /**\n * Options to configure the richtext field used for the quote content.\n * Options will be passed to the underlying `@madebywild/sanity-richtext-field` field.\n */\n richtextOptions?: RichtextOptions;\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\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 { createExcerptFromPortableText } from \"@madebywild/sanity-utils\";\nimport { CompactObjectInput } from \"@madebywild/sanity-utils/compact-object-input\";\nimport { defineField, definePlugin, defineType, type ObjectRule } from \"sanity\";\nimport { type PluginConfig, typeName } from \"./types\";\n\n/** @public */\n// biome-ignore lint/suspicious/noConfusingVoidType: it can be void.\nconst wildSanityQuoteFieldPlugin = definePlugin<PluginConfig | void>((config) => {\n return {\n name: \"@madebywild/sanity-quote-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"object\",\n title: \"Quote\",\n description: \"A stylized quote with optional author.\",\n icon: () => <>❝❞</>,\n options: {\n collapsed: false,\n collapsible: true,\n },\n components: {\n field: (props) => (props.schemaType.options.inline ? props.children : props.renderDefault(props)),\n input: (props) => <CompactObjectInput {...props} space={4} />,\n },\n fields: [\n defineField({\n name: \"quote\",\n type: \"wild.richtext\",\n title: \"Quote\",\n description: \"The quote text.\",\n options: {\n // Disable all parts by default.\n allowedParts: [],\n ...config?.richtextOptions,\n },\n }),\n // Display a reference field if the user provided a author typeName.\n // Otherwise, display a string field for the author name & description.\n ...(config?.authorRef\n ? [\n defineField({\n name: \"authorRef\",\n title: \"Author\",\n description: \"The author of the quote.\",\n type: \"reference\",\n weak: true,\n ...config.authorRef,\n }),\n ]\n : [\n defineField({\n type: \"string\",\n name: \"authorName\",\n title: \"Author Name\",\n description: \"The author name of the quote.\",\n }),\n defineField({\n type: \"text\",\n rows: 2,\n name: \"authorDescription\",\n title: \"Author Description\",\n description: \"The author description of the quote.\",\n }),\n ]),\n ],\n preview: {\n select: {\n quote: \"quote\",\n // Try a few common properties to try and guess the referenced value.\n // TODO: To do this properly, we need the user to pass in a preview.\n authorName: config?.authorRef?.to ? \"author.name\" : \"authorName\",\n authorTitle: config?.authorRef?.to ? \"author.title\" : \"authorName\",\n },\n prepare({ quote, authorName, authorTitle }) {\n const resolvedName = authorName || authorTitle;\n return {\n title: quote ? createExcerptFromPortableText(quote, 25) : \"No quote\",\n subtitle: resolvedName ? `— ${resolvedName}` : undefined,\n };\n },\n },\n }),\n ],\n },\n };\n});\n\n/** @public */\nfunction requireQuote(R: ObjectRule) {\n return R.custom((ctx) => (!ctx?.quote ? { message: \"Enter a quote.\", path: [\"quote\"] } : true));\n}\n\nexport { requireQuote, typeName, wildSanityQuoteFieldPlugin, type PluginConfig };\n"],"names":["typeName","wildSanityQuoteFieldPlugin","definePlugin","config","name","schema","types","defineType","type","title","description","icon","options","collapsed","collapsible","components","field","props","schemaType","inline","children","renderDefault","input","fields","defineField","allowedParts","richtextOptions","authorRef","weak","rows","preview","select","quote","authorName","to","authorTitle","prepare","resolvedName","createExcerptFromPortableText","subtitle","undefined","requireQuote","R","custom","ctx","message","path"],"mappings":";;;;AAIO,MAAMA,WAAW,cCGlBC,6BAA6BC,aAAmCC,CAAAA,YAC7D;AAAA,EACLC,MAAM;AAAA,EACNC,QAAQ;AAAA,IACNC,OAAO,CACLC,WAAW;AAAA,MACTH,MAAMJ;AAAAA,MACNQ,MAAM;AAAA,MACNC,OAAO;AAAA,MACPC,aAAa;AAAA,MACbC,MAAMA,MAAM,oBAAA,UAAA,EAAE,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A,GAAe;AAC1C,gBAAME,eAAeJ,cAAcE;AACnC,iBAAO;AAAA,YACL1B,OAAOuB,QAAQM,8BAA8BN,OAAO,EAAE,IAAI;AAAA,YAC1DO,UAAUF,eAAe,UAAKA,YAAY,KAAKG;AAAAA,UAAAA;AAAAA,QAEnD;AAAA,MAAA;AAAA,IACF,CACD,CAAC;AAAA,EAAA;AAGR,EACD;AAGD,SAASC,aAAaC,GAAe;AACnC,SAAOA,EAAEC,OAAQC,CAAAA,QAAUA,KAAKZ,QAAyD,KAAjD;AAAA,IAAEa,SAAS;AAAA,IAAkBC,MAAM,CAAC,OAAO;AAAA,EAAA,CAAW;AAChG;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@madebywild/sanity-quote-field",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -21,22 +21,22 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@madebywild/sanity-richtext-field": "0.
|
|
25
|
-
"@madebywild/sanity-utils": "0.
|
|
24
|
+
"@madebywild/sanity-richtext-field": "1.0.0",
|
|
25
|
+
"@madebywild/sanity-utils": "1.0.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@sanity/ui": "^3.1",
|
|
29
|
-
"react": "^19",
|
|
30
|
-
"react-dom": "^19",
|
|
29
|
+
"react": "^19.2.2",
|
|
30
|
+
"react-dom": "^19.2.2",
|
|
31
31
|
"sanity": "^4.17 || ^5.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@sanity/pkg-utils": "^9.2",
|
|
35
|
-
"@types/react": "^19",
|
|
36
|
-
"@types/react-dom": "^19",
|
|
35
|
+
"@types/react": "^19.2.2",
|
|
36
|
+
"@types/react-dom": "^19.2.2",
|
|
37
37
|
"babel-plugin-react-compiler": "1.0.0",
|
|
38
|
-
"react": "^19",
|
|
39
|
-
"react-dom": "^19",
|
|
38
|
+
"react": "^19.2.2",
|
|
39
|
+
"react-dom": "^19.2.2",
|
|
40
40
|
"sanity": "^4.17 || ^5.0.0",
|
|
41
41
|
"typescript": "^5"
|
|
42
42
|
},
|
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createExcerptFromPortableText } from "@madebywild/sanity-utils";
|
|
2
|
+
import { CompactObjectInput } from "@madebywild/sanity-utils/compact-object-input";
|
|
2
3
|
import { defineField, definePlugin, defineType, type ObjectRule } from "sanity";
|
|
3
4
|
import { type PluginConfig, typeName } from "./types";
|
|
4
5
|
|
|
@@ -21,6 +22,7 @@ const wildSanityQuoteFieldPlugin = definePlugin<PluginConfig | void>((config) =>
|
|
|
21
22
|
},
|
|
22
23
|
components: {
|
|
23
24
|
field: (props) => (props.schemaType.options.inline ? props.children : props.renderDefault(props)),
|
|
25
|
+
input: (props) => <CompactObjectInput {...props} space={4} />,
|
|
24
26
|
},
|
|
25
27
|
fields: [
|
|
26
28
|
defineField({
|
|
@@ -90,4 +92,4 @@ function requireQuote(R: ObjectRule) {
|
|
|
90
92
|
return R.custom((ctx) => (!ctx?.quote ? { message: "Enter a quote.", path: ["quote"] } : true));
|
|
91
93
|
}
|
|
92
94
|
|
|
93
|
-
export {
|
|
95
|
+
export { requireQuote, typeName, wildSanityQuoteFieldPlugin, type PluginConfig };
|