@portabletext/sanity-bridge 3.0.0 → 3.1.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/dist/index.js +54 -15
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -125,32 +125,71 @@ function sanitySchemaTypeToSchema(portableTextType) {
|
|
|
125
125
|
annotations: annotations.map((annotation) => ({
|
|
126
126
|
name: annotation.name,
|
|
127
127
|
title: annotation.title,
|
|
128
|
-
fields: annotation.fields.map(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
title: field.type.title
|
|
132
|
-
}))
|
|
128
|
+
fields: annotation.fields.map(
|
|
129
|
+
(field) => sanityFieldToSchemaField(field, /* @__PURE__ */ new Set())
|
|
130
|
+
)
|
|
133
131
|
})),
|
|
134
132
|
blockObjects: blockObjectTypes.map((blockObject) => ({
|
|
135
133
|
name: blockObject.name,
|
|
136
134
|
title: blockObject.title,
|
|
137
|
-
fields: blockObject.fields.map(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
title: field.type.title
|
|
141
|
-
}))
|
|
135
|
+
fields: blockObject.fields.map(
|
|
136
|
+
(field) => sanityFieldToSchemaField(field, /* @__PURE__ */ new Set([blockObject.name]))
|
|
137
|
+
)
|
|
142
138
|
})),
|
|
143
139
|
inlineObjects: inlineObjectTypes.map((inlineObject) => ({
|
|
144
140
|
name: inlineObject.name,
|
|
145
141
|
title: inlineObject.title,
|
|
146
|
-
fields: inlineObject.fields.map(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
title: field.type.title
|
|
150
|
-
}))
|
|
142
|
+
fields: inlineObject.fields.map(
|
|
143
|
+
(field) => sanityFieldToSchemaField(field, /* @__PURE__ */ new Set([inlineObject.name]))
|
|
144
|
+
)
|
|
151
145
|
}))
|
|
152
146
|
};
|
|
153
147
|
}
|
|
148
|
+
function safeGetOf(schemaType) {
|
|
149
|
+
try {
|
|
150
|
+
if (schemaType.jsonType === "array") {
|
|
151
|
+
const arrayOf = schemaType.of;
|
|
152
|
+
return Array.isArray(arrayOf) ? arrayOf : void 0;
|
|
153
|
+
}
|
|
154
|
+
} catch {
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function sanityFieldToSchemaField(field, ancestorNames) {
|
|
158
|
+
if (field.type.jsonType === "array") {
|
|
159
|
+
const ofMembers = safeGetOf(field.type);
|
|
160
|
+
return {
|
|
161
|
+
name: field.name,
|
|
162
|
+
type: "array",
|
|
163
|
+
...field.type.title ? { title: field.type.title } : {},
|
|
164
|
+
of: ofMembers ? ofMembers.map(
|
|
165
|
+
(member) => sanityOfMemberToOfDefinition(member, ancestorNames)
|
|
166
|
+
) : []
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
name: field.name,
|
|
171
|
+
type: field.type.jsonType,
|
|
172
|
+
...field.type.title ? { title: field.type.title } : {}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function sanityOfMemberToOfDefinition(memberType, ancestorNames) {
|
|
176
|
+
if (findBlockType(memberType))
|
|
177
|
+
return { type: "block" };
|
|
178
|
+
if (!(memberType.jsonType === "object" && "fields" in memberType && Array.isArray(memberType.fields)) || ancestorNames.has(memberType.name))
|
|
179
|
+
return {
|
|
180
|
+
type: memberType.name,
|
|
181
|
+
...memberType.title ? { title: memberType.title } : {}
|
|
182
|
+
};
|
|
183
|
+
const nextAncestors = new Set(ancestorNames);
|
|
184
|
+
return nextAncestors.add(memberType.name), {
|
|
185
|
+
type: "object",
|
|
186
|
+
name: memberType.name,
|
|
187
|
+
...memberType.title ? { title: memberType.title } : {},
|
|
188
|
+
fields: memberType.fields.map(
|
|
189
|
+
(field) => sanityFieldToSchemaField(field, nextAncestors)
|
|
190
|
+
)
|
|
191
|
+
};
|
|
192
|
+
}
|
|
154
193
|
function resolveEnabledStyles(blockType) {
|
|
155
194
|
const styleField = blockType.fields?.find(
|
|
156
195
|
(btField) => btField.name === "style"
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/portable-text-member-schema-types.ts","../src/sanity-schema-to-portable-text-schema.ts"],"sourcesContent":["import type {\n ArraySchemaType,\n BlockDecoratorDefinition,\n BlockListDefinition,\n BlockSchemaType,\n BlockStyleDefinition,\n ObjectSchemaType,\n PortableTextBlock,\n SchemaType,\n SpanSchemaType,\n} from '@sanity/types'\n\n/**\n * @public\n * Sanity-specific schema types for Portable Text.\n */\nexport type PortableTextMemberSchemaTypes = {\n annotations: (ObjectSchemaType & {i18nTitleKey?: string})[]\n block: ObjectSchemaType\n blockObjects: ObjectSchemaType[]\n decorators: BlockDecoratorDefinition[]\n inlineObjects: ObjectSchemaType[]\n portableText: ArraySchemaType<PortableTextBlock>\n span: ObjectSchemaType\n styles: BlockStyleDefinition[]\n lists: BlockListDefinition[]\n}\n\n/**\n * @public\n * Create Sanity-specific schema types for Portable Text from a Sanity array\n * schema type.\n */\nexport function createPortableTextMemberSchemaTypes(\n portableTextType: ArraySchemaType<PortableTextBlock>,\n): PortableTextMemberSchemaTypes {\n if (!portableTextType) {\n throw new Error(\"Parameter 'portabletextType' missing (required)\")\n }\n const blockType = portableTextType.of?.find(findBlockType) as\n | BlockSchemaType\n | undefined\n if (!blockType) {\n throw new Error('Block type is not defined in this schema (required)')\n }\n const childrenField = blockType.fields?.find(\n (field) => field.name === 'children',\n ) as {type: ArraySchemaType} | undefined\n if (!childrenField) {\n throw new Error('Children field for block type found in schema (required)')\n }\n const ofType = childrenField.type.of\n if (!ofType) {\n throw new Error(\n 'Valid types for block children not found in schema (required)',\n )\n }\n const spanType = ofType.find((memberType) => memberType.name === 'span') as\n | ObjectSchemaType\n | undefined\n if (!spanType) {\n throw new Error('Span type not found in schema (required)')\n }\n const inlineObjectTypes = (ofType.filter(\n (memberType) => memberType.name !== 'span',\n ) || []) as ObjectSchemaType[]\n const blockObjectTypes = (portableTextType.of?.filter(\n (field) => field.name !== blockType.name,\n ) || []) as ObjectSchemaType[]\n return {\n styles: resolveEnabledStyles(blockType),\n decorators: resolveEnabledDecorators(spanType),\n lists: resolveEnabledListItems(blockType),\n block: blockType,\n span: spanType,\n portableText: portableTextType,\n inlineObjects: inlineObjectTypes,\n blockObjects: blockObjectTypes,\n annotations: (spanType as SpanSchemaType).annotations,\n }\n}\n\nfunction resolveEnabledStyles(blockType: ObjectSchemaType) {\n const styleField = blockType.fields?.find(\n (btField) => btField.name === 'style',\n )\n if (!styleField) {\n throw new Error(\n \"A field with name 'style' is not defined in the block type (required).\",\n )\n }\n const textStyles =\n styleField.type.options?.list &&\n styleField.type.options.list?.filter(\n (style: {value: string}) => style.value,\n )\n if (!textStyles || textStyles.length === 0) {\n throw new Error(\n 'The style fields need at least one style ' +\n \"defined. I.e: {title: 'Normal', value: 'normal'}.\",\n )\n }\n return textStyles\n}\n\nfunction resolveEnabledDecorators(spanType: ObjectSchemaType) {\n return (spanType as any).decorators\n}\n\nfunction resolveEnabledListItems(blockType: ObjectSchemaType) {\n const listField = blockType.fields?.find(\n (btField) => btField.name === 'listItem',\n )\n if (!listField) {\n throw new Error(\n \"A field with name 'listItem' is not defined in the block type (required).\",\n )\n }\n const listItems =\n listField.type.options?.list &&\n listField.type.options.list.filter((list: {value: string}) => list.value)\n if (!listItems) {\n throw new Error('The list field need at least to be an empty array')\n }\n return listItems\n}\n\nfunction findBlockType(type: SchemaType): BlockSchemaType | null {\n if (type.type) {\n return findBlockType(type.type)\n }\n\n if (type.name === 'block') {\n return type as BlockSchemaType\n }\n\n return null\n}\n","import type {Schema} from '@portabletext/schema'\nimport {Schema as SanitySchema} from '@sanity/schema'\nimport {builtinTypes} from '@sanity/schema/_internal'\nimport type {\n ArrayDefinition,\n ArraySchemaType,\n BlockDecoratorDefinition,\n BlockListDefinition,\n BlockSchemaType,\n BlockStyleDefinition,\n ObjectSchemaType,\n PortableTextBlock,\n SchemaType,\n SpanSchemaType,\n} from '@sanity/types'\n\n/**\n * @public\n * Compile a Sanity schema to a Portable Text `Schema`.\n *\n * A Portable Text `Schema` is compatible with a Portable Text\n * `SchemaDefinition` and can be used as configuration for the Portable Text\n * Editor.\n *\n * @example\n * ```tsx\n * const schema = sanitySchemaToPortableTextSchema(sanitySchema)\n *\n * return (\n * <EditorProvider\n * initialConfig={{\n * // ...\n * schemaDefinition: schema,\n * }}\n * >\n * // ...\n * </EditorProvider>\n * ```\n */\nexport function sanitySchemaToPortableTextSchema(\n sanitySchema: ArraySchemaType<unknown> | ArrayDefinition,\n): Schema {\n const compiled = sanitySchema.hasOwnProperty('jsonType')\n ? (sanitySchema as ArraySchemaType<PortableTextBlock>)\n : compileType(sanitySchema)\n\n return sanitySchemaTypeToSchema(compiled)\n}\n\nfunction sanitySchemaTypeToSchema(\n portableTextType: ArraySchemaType<PortableTextBlock>,\n): Schema {\n if (!portableTextType) {\n throw new Error(\"Parameter 'portableTextType' missing (required)\")\n }\n\n const blockType = portableTextType.of?.find(findBlockType) as\n | BlockSchemaType\n | undefined\n if (!blockType) {\n throw new Error('Block type is not defined in this schema (required)')\n }\n\n const childrenField = blockType.fields?.find(\n (field) => field.name === 'children',\n ) as {type: ArraySchemaType} | undefined\n if (!childrenField) {\n throw new Error('Children field for block type found in schema (required)')\n }\n\n const ofType = childrenField.type.of\n if (!ofType) {\n throw new Error(\n 'Valid types for block children not found in schema (required)',\n )\n }\n\n const spanType = ofType.find((memberType) => memberType.name === 'span') as\n | ObjectSchemaType\n | undefined\n if (!spanType) {\n throw new Error('Span type not found in schema (required)')\n }\n\n const inlineObjectTypes = (ofType.filter(\n (memberType) => memberType.name !== 'span',\n ) || []) as ObjectSchemaType[]\n\n const blockObjectTypes = (portableTextType.of?.filter(\n (field) => field.name !== blockType.name,\n ) || []) as ObjectSchemaType[]\n\n const styles = resolveEnabledStyles(blockType)\n const decorators = resolveEnabledDecorators(spanType)\n const lists = resolveEnabledListItems(blockType)\n const annotations = (spanType as SpanSchemaType).annotations\n\n return {\n block: {\n name: blockType.name,\n },\n span: {\n name: spanType.name,\n },\n styles: styles.map((style: BlockStyleDefinition) => ({\n name: style.value,\n title: style.title,\n value: style.value,\n })),\n lists: lists.map((list: BlockListDefinition) => ({\n name: list.value,\n title: list.title,\n value: list.value,\n })),\n decorators: decorators.map((decorator: BlockDecoratorDefinition) => ({\n name: decorator.value,\n title: decorator.title,\n value: decorator.value,\n })),\n annotations: annotations.map((annotation) => ({\n name: annotation.name,\n title: annotation.title,\n fields: annotation.fields.map((field) => ({\n name: field.name,\n type: field.type.jsonType,\n title: field.type.title,\n })),\n })),\n blockObjects: blockObjectTypes.map((blockObject) => ({\n name: blockObject.name,\n title: blockObject.title,\n fields: blockObject.fields.map((field) => ({\n name: field.name,\n type: field.type.jsonType,\n title: field.type.title,\n })),\n })),\n inlineObjects: inlineObjectTypes.map((inlineObject) => ({\n name: inlineObject.name,\n title: inlineObject.title,\n fields: inlineObject.fields.map((field) => ({\n name: field.name,\n type: field.type.jsonType,\n title: field.type.title,\n })),\n })),\n }\n}\n\nfunction resolveEnabledStyles(blockType: ObjectSchemaType) {\n const styleField = blockType.fields?.find(\n (btField) => btField.name === 'style',\n )\n if (!styleField) {\n throw new Error(\n \"A field with name 'style' is not defined in the block type (required).\",\n )\n }\n const textStyles =\n styleField.type.options?.list &&\n styleField.type.options.list?.filter(\n (style: {value: string}) => style.value,\n )\n if (!textStyles || textStyles.length === 0) {\n throw new Error(\n 'The style fields need at least one style ' +\n \"defined. I.e: {title: 'Normal', value: 'normal'}.\",\n )\n }\n return textStyles\n}\n\nfunction resolveEnabledDecorators(spanType: ObjectSchemaType) {\n return (spanType as any).decorators\n}\n\nfunction resolveEnabledListItems(blockType: ObjectSchemaType) {\n const listField = blockType.fields?.find(\n (btField) => btField.name === 'listItem',\n )\n if (!listField) {\n throw new Error(\n \"A field with name 'listItem' is not defined in the block type (required).\",\n )\n }\n const listItems =\n listField.type.options?.list &&\n listField.type.options.list.filter((list: {value: string}) => list.value)\n if (!listItems) {\n throw new Error('The list field need at least to be an empty array')\n }\n return listItems\n}\n\nfunction findBlockType(type: SchemaType): BlockSchemaType | null {\n if (type.type) {\n return findBlockType(type.type)\n }\n\n if (type.name === 'block') {\n return type as BlockSchemaType\n }\n\n return null\n}\n\nfunction compileType(rawType: any) {\n return SanitySchema.compile({\n name: 'blockTypeSchema',\n types: [rawType, ...builtinTypes],\n }).get(rawType.name)\n}\n"],"names":["findBlockType","resolveEnabledStyles","resolveEnabledDecorators","resolveEnabledListItems","SanitySchema"],"mappings":";;AAiCO,SAAS,oCACd,kBAC+B;AAC/B,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,iDAAiD;AAEnE,QAAM,YAAY,iBAAiB,IAAI,KAAKA,eAAa;AAGzD,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,qDAAqD;AAEvE,QAAM,gBAAgB,UAAU,QAAQ;AAAA,IACtC,CAAC,UAAU,MAAM,SAAS;AAAA,EAAA;AAE5B,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,0DAA0D;AAE5E,QAAM,SAAS,cAAc,KAAK;AAClC,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAGJ,QAAM,WAAW,OAAO,KAAK,CAAC,eAAe,WAAW,SAAS,MAAM;AAGvE,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,0CAA0C;AAE5D,QAAM,oBAAqB,OAAO;AAAA,IAChC,CAAC,eAAe,WAAW,SAAS;AAAA,EAAA,KACjC,IACC,mBAAoB,iBAAiB,IAAI;AAAA,IAC7C,CAAC,UAAU,MAAM,SAAS,UAAU;AAAA,EAAA,KACjC,CAAA;AACL,SAAO;AAAA,IACL,QAAQC,uBAAqB,SAAS;AAAA,IACtC,YAAYC,2BAAyB,QAAQ;AAAA,IAC7C,OAAOC,0BAAwB,SAAS;AAAA,IACxC,OAAO;AAAA,IACP,MAAM;AAAA,IACN,cAAc;AAAA,IACd,eAAe;AAAA,IACf,cAAc;AAAA,IACd,aAAc,SA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IAAI;AAAA,MACR;AAAA,IAAA;AAGJ,QAAM,YACJ,UAAU,KAAK,SAAS,QACxB,UAAU,KAAK,QAAQ,KAAK,OAAO,CAAC,SAA0B,KAAK,KAAK;AAC1E,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,mDAAmD;AAErE,SAAO;AACT;AAEA,SAAS,cAAc,MAA0C;AAC/D,SAAI,KAAK,OACA,cAAc,KAAK,IAAI,IAG5B,KAAK,SAAS,UACT,OAGF;AACT;AAEA,SAAS,YAAY,SAAc;AACjC,SAAOI,OAAa,QAAQ;AAAA,IAC1B,MAAM;AAAA,IACN,OAAO,CAAC,SAAS,GAAG,YAAY;AAAA,EAAA,CACjC,EAAE,IAAI,QAAQ,IAAI;AACrB;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/portable-text-member-schema-types.ts","../src/sanity-schema-to-portable-text-schema.ts"],"sourcesContent":["import type {\n ArraySchemaType,\n BlockDecoratorDefinition,\n BlockListDefinition,\n BlockSchemaType,\n BlockStyleDefinition,\n ObjectSchemaType,\n PortableTextBlock,\n SchemaType,\n SpanSchemaType,\n} from '@sanity/types'\n\n/**\n * @public\n * Sanity-specific schema types for Portable Text.\n */\nexport type PortableTextMemberSchemaTypes = {\n annotations: (ObjectSchemaType & {i18nTitleKey?: string})[]\n block: ObjectSchemaType\n blockObjects: ObjectSchemaType[]\n decorators: BlockDecoratorDefinition[]\n inlineObjects: ObjectSchemaType[]\n portableText: ArraySchemaType<PortableTextBlock>\n span: ObjectSchemaType\n styles: BlockStyleDefinition[]\n lists: BlockListDefinition[]\n}\n\n/**\n * @public\n * Create Sanity-specific schema types for Portable Text from a Sanity array\n * schema type.\n */\nexport function createPortableTextMemberSchemaTypes(\n portableTextType: ArraySchemaType<PortableTextBlock>,\n): PortableTextMemberSchemaTypes {\n if (!portableTextType) {\n throw new Error(\"Parameter 'portabletextType' missing (required)\")\n }\n const blockType = portableTextType.of?.find(findBlockType) as\n | BlockSchemaType\n | undefined\n if (!blockType) {\n throw new Error('Block type is not defined in this schema (required)')\n }\n const childrenField = blockType.fields?.find(\n (field) => field.name === 'children',\n ) as {type: ArraySchemaType} | undefined\n if (!childrenField) {\n throw new Error('Children field for block type found in schema (required)')\n }\n const ofType = childrenField.type.of\n if (!ofType) {\n throw new Error(\n 'Valid types for block children not found in schema (required)',\n )\n }\n const spanType = ofType.find((memberType) => memberType.name === 'span') as\n | ObjectSchemaType\n | undefined\n if (!spanType) {\n throw new Error('Span type not found in schema (required)')\n }\n const inlineObjectTypes = (ofType.filter(\n (memberType) => memberType.name !== 'span',\n ) || []) as ObjectSchemaType[]\n const blockObjectTypes = (portableTextType.of?.filter(\n (field) => field.name !== blockType.name,\n ) || []) as ObjectSchemaType[]\n\n return {\n styles: resolveEnabledStyles(blockType),\n decorators: resolveEnabledDecorators(spanType),\n lists: resolveEnabledListItems(blockType),\n block: blockType,\n span: spanType,\n portableText: portableTextType,\n inlineObjects: inlineObjectTypes,\n blockObjects: blockObjectTypes,\n annotations: (spanType as SpanSchemaType).annotations,\n }\n}\n\nfunction resolveEnabledStyles(blockType: ObjectSchemaType) {\n const styleField = blockType.fields?.find(\n (btField) => btField.name === 'style',\n )\n if (!styleField) {\n throw new Error(\n \"A field with name 'style' is not defined in the block type (required).\",\n )\n }\n const textStyles =\n styleField.type.options?.list &&\n styleField.type.options.list?.filter(\n (style: {value: string}) => style.value,\n )\n if (!textStyles || textStyles.length === 0) {\n throw new Error(\n 'The style fields need at least one style ' +\n \"defined. I.e: {title: 'Normal', value: 'normal'}.\",\n )\n }\n return textStyles\n}\n\nfunction resolveEnabledDecorators(spanType: ObjectSchemaType) {\n return (spanType as any).decorators\n}\n\nfunction resolveEnabledListItems(blockType: ObjectSchemaType) {\n const listField = blockType.fields?.find(\n (btField) => btField.name === 'listItem',\n )\n if (!listField) {\n throw new Error(\n \"A field with name 'listItem' is not defined in the block type (required).\",\n )\n }\n const listItems =\n listField.type.options?.list &&\n listField.type.options.list.filter((list: {value: string}) => list.value)\n if (!listItems) {\n throw new Error('The list field need at least to be an empty array')\n }\n return listItems\n}\n\nfunction findBlockType(type: SchemaType): BlockSchemaType | null {\n if (type.type) {\n return findBlockType(type.type)\n }\n\n if (type.name === 'block') {\n return type as BlockSchemaType\n }\n\n return null\n}\n","import type {FieldDefinition, OfDefinition, Schema} from '@portabletext/schema'\nimport {Schema as SanitySchema} from '@sanity/schema'\nimport {builtinTypes} from '@sanity/schema/_internal'\nimport type {\n ArrayDefinition,\n ArraySchemaType,\n BlockDecoratorDefinition,\n BlockListDefinition,\n BlockSchemaType,\n BlockStyleDefinition,\n ObjectSchemaType,\n PortableTextBlock,\n SchemaType,\n SpanSchemaType,\n} from '@sanity/types'\n\n/**\n * @public\n * Compile a Sanity schema to a Portable Text `Schema`.\n *\n * A Portable Text `Schema` is compatible with a Portable Text\n * `SchemaDefinition` and can be used as configuration for the Portable Text\n * Editor.\n *\n * @example\n * ```tsx\n * const schema = sanitySchemaToPortableTextSchema(sanitySchema)\n *\n * return (\n * <EditorProvider\n * initialConfig={{\n * // ...\n * schemaDefinition: schema,\n * }}\n * >\n * // ...\n * </EditorProvider>\n * ```\n */\nexport function sanitySchemaToPortableTextSchema(\n sanitySchema: ArraySchemaType<unknown> | ArrayDefinition,\n): Schema {\n const compiled = sanitySchema.hasOwnProperty('jsonType')\n ? (sanitySchema as ArraySchemaType<PortableTextBlock>)\n : compileType(sanitySchema)\n\n return sanitySchemaTypeToSchema(compiled)\n}\n\nfunction sanitySchemaTypeToSchema(\n portableTextType: ArraySchemaType<PortableTextBlock>,\n): Schema {\n if (!portableTextType) {\n throw new Error(\"Parameter 'portableTextType' missing (required)\")\n }\n\n const blockType = portableTextType.of?.find(findBlockType) as\n | BlockSchemaType\n | undefined\n if (!blockType) {\n throw new Error('Block type is not defined in this schema (required)')\n }\n\n const childrenField = blockType.fields?.find(\n (field) => field.name === 'children',\n ) as {type: ArraySchemaType} | undefined\n if (!childrenField) {\n throw new Error('Children field for block type found in schema (required)')\n }\n\n const ofType = childrenField.type.of\n if (!ofType) {\n throw new Error(\n 'Valid types for block children not found in schema (required)',\n )\n }\n\n const spanType = ofType.find((memberType) => memberType.name === 'span') as\n | ObjectSchemaType\n | undefined\n if (!spanType) {\n throw new Error('Span type not found in schema (required)')\n }\n\n const inlineObjectTypes = (ofType.filter(\n (memberType) => memberType.name !== 'span',\n ) || []) as ObjectSchemaType[]\n\n const blockObjectTypes = (portableTextType.of?.filter(\n (field) => field.name !== blockType.name,\n ) || []) as ObjectSchemaType[]\n\n const styles = resolveEnabledStyles(blockType)\n const decorators = resolveEnabledDecorators(spanType)\n const lists = resolveEnabledListItems(blockType)\n const annotations = (spanType as SpanSchemaType).annotations\n\n return {\n block: {\n name: blockType.name,\n },\n span: {\n name: spanType.name,\n },\n styles: styles.map((style: BlockStyleDefinition) => ({\n name: style.value,\n title: style.title,\n value: style.value,\n })),\n lists: lists.map((list: BlockListDefinition) => ({\n name: list.value,\n title: list.title,\n value: list.value,\n })),\n decorators: decorators.map((decorator: BlockDecoratorDefinition) => ({\n name: decorator.value,\n title: decorator.title,\n value: decorator.value,\n })),\n annotations: annotations.map((annotation) => ({\n name: annotation.name,\n title: annotation.title,\n fields: annotation.fields.map((field) =>\n sanityFieldToSchemaField(field, new Set()),\n ),\n })),\n blockObjects: blockObjectTypes.map((blockObject) => ({\n name: blockObject.name,\n title: blockObject.title,\n fields: blockObject.fields.map((field) =>\n sanityFieldToSchemaField(field, new Set([blockObject.name])),\n ),\n })),\n inlineObjects: inlineObjectTypes.map((inlineObject) => ({\n name: inlineObject.name,\n title: inlineObject.title,\n fields: inlineObject.fields.map((field) =>\n sanityFieldToSchemaField(field, new Set([inlineObject.name])),\n ),\n })),\n }\n}\n\nfunction safeGetOf(schemaType: SchemaType): readonly SchemaType[] | undefined {\n try {\n if (schemaType.jsonType === 'array') {\n const arrayOf = (schemaType as ArraySchemaType).of\n return Array.isArray(arrayOf) ? arrayOf : undefined\n }\n } catch {\n // Sanity schema getters can throw -- ignore\n }\n return undefined\n}\n\nfunction sanityFieldToSchemaField(\n field: {\n name: string\n type: SchemaType\n },\n ancestorNames: ReadonlySet<string>,\n): FieldDefinition {\n if (field.type.jsonType === 'array') {\n const ofMembers = safeGetOf(field.type)\n return {\n name: field.name,\n type: 'array',\n ...(field.type.title ? {title: field.type.title} : {}),\n of: ofMembers\n ? ofMembers.map((member) =>\n sanityOfMemberToOfDefinition(member, ancestorNames),\n )\n : [],\n }\n }\n\n return {\n name: field.name,\n type: field.type.jsonType,\n ...(field.type.title ? {title: field.type.title} : {}),\n }\n}\n\nfunction sanityOfMemberToOfDefinition(\n memberType: SchemaType,\n ancestorNames: ReadonlySet<string>,\n): OfDefinition {\n if (findBlockType(memberType)) {\n return {type: 'block'}\n }\n\n // If this member has fields and isn't already in the ancestor chain,\n // emit an INLINE declaration (`type: 'object'` + name + fields). If the\n // type is in the ancestor chain (cycle) or has no fields, emit a bare\n // REFERENCE (just `type: <name>`).\n const hasFields =\n memberType.jsonType === 'object' &&\n 'fields' in memberType &&\n Array.isArray((memberType as ObjectSchemaType).fields)\n\n if (!hasFields || ancestorNames.has(memberType.name)) {\n // Bare reference. The editor's resolver looks up `memberType.name`\n // in `blockObjects` / `inlineObjects`.\n return {\n type: memberType.name,\n ...(memberType.title ? {title: memberType.title} : {}),\n }\n }\n\n const nextAncestors = new Set(ancestorNames)\n nextAncestors.add(memberType.name)\n return {\n type: 'object',\n name: memberType.name,\n ...(memberType.title ? {title: memberType.title} : {}),\n fields: (memberType as ObjectSchemaType).fields.map((field) =>\n sanityFieldToSchemaField(field, nextAncestors),\n ),\n }\n}\n\nfunction resolveEnabledStyles(blockType: ObjectSchemaType) {\n const styleField = blockType.fields?.find(\n (btField) => btField.name === 'style',\n )\n if (!styleField) {\n throw new Error(\n \"A field with name 'style' is not defined in the block type (required).\",\n )\n }\n const textStyles =\n styleField.type.options?.list &&\n styleField.type.options.list?.filter(\n (style: {value: string}) => style.value,\n )\n if (!textStyles || textStyles.length === 0) {\n throw new Error(\n 'The style fields need at least one style ' +\n \"defined. I.e: {title: 'Normal', value: 'normal'}.\",\n )\n }\n return textStyles\n}\n\nfunction resolveEnabledDecorators(spanType: ObjectSchemaType) {\n return (spanType as any).decorators\n}\n\nfunction resolveEnabledListItems(blockType: ObjectSchemaType) {\n const listField = blockType.fields?.find(\n (btField) => btField.name === 'listItem',\n )\n if (!listField) {\n throw new Error(\n \"A field with name 'listItem' is not defined in the block type (required).\",\n )\n }\n const listItems =\n listField.type.options?.list &&\n listField.type.options.list.filter((list: {value: string}) => list.value)\n if (!listItems) {\n throw new Error('The list field need at least to be an empty array')\n }\n return listItems\n}\n\nfunction findBlockType(type: SchemaType): BlockSchemaType | null {\n if (type.type) {\n return findBlockType(type.type)\n }\n\n if (type.name === 'block') {\n return type as BlockSchemaType\n }\n\n return null\n}\n\nfunction compileType(rawType: any) {\n return SanitySchema.compile({\n name: 'blockTypeSchema',\n types: [rawType, ...builtinTypes],\n }).get(rawType.name)\n}\n"],"names":["findBlockType","resolveEnabledStyles","resolveEnabledDecorators","resolveEnabledListItems","SanitySchema"],"mappings":";;AAiCO,SAAS,oCACd,kBAC+B;AAC/B,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,iDAAiD;AAEnE,QAAM,YAAY,iBAAiB,IAAI,KAAKA,eAAa;AAGzD,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,qDAAqD;AAEvE,QAAM,gBAAgB,UAAU,QAAQ;AAAA,IACtC,CAAC,UAAU,MAAM,SAAS;AAAA,EAAA;AAE5B,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,0DAA0D;AAE5E,QAAM,SAAS,cAAc,KAAK;AAClC,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAGJ,QAAM,WAAW,OAAO,KAAK,CAAC,eAAe,WAAW,SAAS,MAAM;AAGvE,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,0CAA0C;AAE5D,QAAM,oBAAqB,OAAO;AAAA,IAChC,CAAC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2B,MAAM;AAAA,EAAA;AAEtC,MAAI,CAAC,cAAc,WAAW,WAAW;AACvC,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAIJ,SAAO;AACT;AAEA,SAAS,yBAAyB,UAA4B;AAC5D,SAAQ,SAAiB;AAC3B;AAEA,SAAS,wBAAwB,WAA6B;AAC5D,QAAM,YAAY,UAAU,QAAQ;AAAA,IAClC,CAAC,YAAY,QAAQ,SAAS;AAAA,EAAA;AAEhC,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAGJ,QAAM,YACJ,UAAU,KAAK,SAAS,QACxB,UAAU,KAAK,QAAQ,KAAK,OAAO,CAAC,SAA0B,KAAK,KAAK;AAC1E,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,mDAAmD;AAErE,SAAO;AACT;AAEA,SAAS,cAAc,MAA0C;AAC/D,SAAI,KAAK,OACA,cAAc,KAAK,IAAI,IAG5B,KAAK,SAAS,UACT,OAGF;AACT;AAEA,SAAS,YAAY,SAAc;AACjC,SAAOI,OAAa,QAAQ;AAAA,IAC1B,MAAM;AAAA,IACN,OAAO,CAAC,SAAS,GAAG,YAAY;AAAA,EAAA,CACjC,EAAE,IAAI,QAAQ,IAAI;AACrB;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/sanity-bridge",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Convert a Sanity Schema to a Portable Text Schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@sanity/schema": "^5.
|
|
33
|
-
"@sanity/types": "^5.
|
|
34
|
-
"@portabletext/schema": "^2.
|
|
32
|
+
"@sanity/schema": "^5.13.0",
|
|
33
|
+
"@sanity/types": "^5.13.0",
|
|
34
|
+
"@portabletext/schema": "^2.2.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@sanity/pkg-utils": "^10.2.1",
|
|
38
38
|
"@sanity/tsconfig": "^2.1.0",
|
|
39
39
|
"typescript": "5.9.3",
|
|
40
|
-
"vitest": "^4.
|
|
40
|
+
"vitest": "^4.1.4"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=20.19 <22 || >=22.12"
|