@portabletext/sanity-bridge 1.2.12 → 1.2.14
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 +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -6
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Schema } from "@sanity/schema";
|
|
2
2
|
import { builtinTypes } from "@sanity/schema/_internal";
|
|
3
3
|
import { defineType, defineField, isObjectSchemaType, isArraySchemaType } from "@sanity/types";
|
|
4
|
-
import startCase from "lodash.startcase";
|
|
5
4
|
function createPortableTextMemberSchemaTypes(portableTextType) {
|
|
6
5
|
if (!portableTextType)
|
|
7
6
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
@@ -157,6 +156,9 @@ function randomKey(length) {
|
|
|
157
156
|
const table = getByteHexTable();
|
|
158
157
|
return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
|
|
159
158
|
}
|
|
159
|
+
function startCase(str) {
|
|
160
|
+
return str.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").trim().split(/\s+/).filter(Boolean).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
161
|
+
}
|
|
160
162
|
const temporaryImageBlockObjectName = `tmp-${keyGenerator()}-image`, temporaryUrlBlockObjectName = `tmp-${keyGenerator()}-url`, temporaryImageInlineObjectName = `tmp-${keyGenerator()}-image`, temporaryUrlInlineObjectName = `tmp-${keyGenerator()}-url`, temporaryBlockObjectNames = {
|
|
161
163
|
image: temporaryImageBlockObjectName,
|
|
162
164
|
url: temporaryUrlBlockObjectName
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/portable-text-member-schema-types.ts","../src/portable-text-member-schema-types-to-schema.ts","../src/sanity-schema-to-portable-text-schema.ts","../src/key-generator.ts","../src/schema-definition-to-portable-text-member-schema-types.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 type {PortableTextMemberSchemaTypes} from './portable-text-member-schema-types'\n\n/**\n * @public\n * Convert Sanity-specific schema types for Portable Text to a first-class\n * Portable Text schema.\n */\nexport function portableTextMemberSchemaTypesToSchema(\n schema: PortableTextMemberSchemaTypes,\n): Schema {\n return {\n annotations: schema.annotations.map((annotation) => ({\n name: annotation.name,\n fields: annotation.fields.map((field) => ({\n name: field.name,\n type: field.type.jsonType,\n title: field.type.title,\n })),\n title: annotation.title,\n })),\n block: {\n name: schema.block.name,\n },\n blockObjects: schema.blockObjects.map((blockObject) => ({\n name: blockObject.name,\n fields: blockObject.fields.map((field) => ({\n name: field.name,\n type: field.type.jsonType,\n title: field.type.title,\n })),\n title: blockObject.title,\n })),\n decorators: schema.decorators.map((decorator) => ({\n name: decorator.value,\n title: decorator.title,\n value: decorator.value,\n })),\n inlineObjects: schema.inlineObjects.map((inlineObject) => ({\n name: inlineObject.name,\n fields: inlineObject.fields.map((field) => ({\n name: field.name,\n type: field.type.jsonType,\n title: field.type.title,\n })),\n title: inlineObject.title,\n })),\n span: {\n name: schema.span.name,\n },\n styles: schema.styles.map((style) => ({\n name: style.value,\n title: style.title,\n value: style.value,\n })),\n lists: schema.lists.map((list) => ({\n name: list.value,\n title: list.title,\n value: list.value,\n })),\n }\n}\n","import type {Schema} from '@portabletext/schema'\nimport {Schema as SanitySchema} from '@sanity/schema'\nimport {builtinTypes} from '@sanity/schema/_internal'\nimport type {ArrayDefinition, ArraySchemaType} from '@sanity/types'\nimport {createPortableTextMemberSchemaTypes} from './portable-text-member-schema-types'\nimport {portableTextMemberSchemaTypesToSchema} from './portable-text-member-schema-types-to-schema'\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 portableTextMemberSchemaTypes = createPortableTextMemberSchemaTypes(\n sanitySchema.hasOwnProperty('jsonType')\n ? sanitySchema\n : compileType(sanitySchema),\n )\n\n return portableTextMemberSchemaTypesToSchema(portableTextMemberSchemaTypes)\n}\n\nfunction compileType(rawType: any) {\n return SanitySchema.compile({\n name: 'blockTypeSchema',\n types: [rawType, ...builtinTypes],\n }).get(rawType.name)\n}\n","export const keyGenerator = (): string => randomKey(12)\n\nconst getByteHexTable = (() => {\n let table: any[]\n return () => {\n if (table) {\n return table\n }\n\n table = []\n for (let i = 0; i < 256; ++i) {\n table[i] = (i + 0x100).toString(16).slice(1)\n }\n return table\n }\n})()\n\n// WHATWG crypto RNG - https://w3c.github.io/webcrypto/Overview.html\nfunction whatwgRNG(length = 16) {\n const rnds8 = new Uint8Array(length)\n crypto.getRandomValues(rnds8)\n return rnds8\n}\n\nfunction randomKey(length?: number): string {\n const table = getByteHexTable()\n return whatwgRNG(length)\n .reduce((str, n) => str + table[n], '')\n .slice(0, length)\n}\n","import type {SchemaDefinition} from '@portabletext/schema'\nimport {Schema as SanitySchema} from '@sanity/schema'\nimport {\n defineField,\n defineType,\n isArraySchemaType,\n isObjectSchemaType,\n type ObjectSchemaType,\n} from '@sanity/types'\nimport startCase from 'lodash.startcase'\nimport {keyGenerator} from './key-generator'\nimport {\n createPortableTextMemberSchemaTypes,\n type PortableTextMemberSchemaTypes,\n} from './portable-text-member-schema-types'\n\nconst temporaryImageBlockObjectName = `tmp-${keyGenerator()}-image`\nconst temporaryUrlBlockObjectName = `tmp-${keyGenerator()}-url`\nconst temporaryImageInlineObjectName = `tmp-${keyGenerator()}-image`\nconst temporaryUrlInlineObjectName = `tmp-${keyGenerator()}-url`\n\nconst temporaryBlockObjectNames: Record<string, string> = {\n image: temporaryImageBlockObjectName,\n url: temporaryUrlBlockObjectName,\n}\n\nconst temporaryInlineObjectNames: Record<string, string> = {\n image: temporaryImageInlineObjectName,\n url: temporaryUrlInlineObjectName,\n}\n\nconst blockObjectNames: Record<string, string> = {\n [temporaryImageBlockObjectName]: 'image',\n [temporaryUrlBlockObjectName]: 'url',\n}\n\nconst inlineObjectNames: Record<string, string> = {\n [temporaryImageInlineObjectName]: 'image',\n [temporaryUrlInlineObjectName]: 'url',\n}\n\nconst defaultObjectTitles: Record<string, string> = {\n image: 'Image',\n url: 'URL',\n}\n\n/**\n * @public\n * Compile a Portable Text schema definition to Sanity-specific schema types for\n * Portable Text.\n */\nexport function compileSchemaDefinitionToPortableTextMemberSchemaTypes(\n definition?: SchemaDefinition,\n): PortableTextMemberSchemaTypes {\n const blockObjects =\n definition?.blockObjects?.map((blockObject) =>\n defineType({\n type: 'object',\n // Very naive way to work around `SanitySchema.compile` adding default\n // fields to objects with certain names.\n name: temporaryBlockObjectNames[blockObject.name] ?? blockObject.name,\n title:\n blockObject.title === undefined\n ? // This avoids the default title which is a title case of the object name\n defaultObjectTitles[blockObject.name]\n : blockObject.title,\n fields:\n blockObject.fields?.map((field) => ({\n name: field.name,\n type: field.type,\n title: field.title ?? startCase(field.name),\n })) ?? [],\n }),\n ) ?? []\n\n const inlineObjects =\n definition?.inlineObjects?.map((inlineObject) =>\n defineType({\n type: 'object',\n // Very naive way to work around `SanitySchema.compile` adding default\n // fields to objects with certain names.\n name:\n temporaryInlineObjectNames[inlineObject.name] ?? inlineObject.name,\n\n title:\n inlineObject.title === undefined\n ? // This avoids the default title which is a title case of the object name\n defaultObjectTitles[inlineObject.name]\n : inlineObject.title,\n fields:\n inlineObject.fields?.map((field) => ({\n name: field.name,\n type: field.type,\n title: field.title ?? startCase(field.name),\n })) ?? [],\n }),\n ) ?? []\n\n const portableTextSchema = defineField({\n type: 'array',\n name: 'portable-text',\n of: [\n ...blockObjects.map((blockObject) => ({type: blockObject.name})),\n {\n type: 'block',\n name: 'block',\n of: inlineObjects.map((inlineObject) => ({type: inlineObject.name})),\n marks: {\n decorators:\n definition?.decorators?.map((decorator) => ({\n title: decorator.title ?? startCase(decorator.name),\n value: decorator.name,\n })) ?? [],\n annotations:\n definition?.annotations?.map((annotation) => ({\n name: annotation.name,\n type: 'object',\n title: annotation.title,\n fields:\n annotation.fields?.map((field) => ({\n name: field.name,\n title: field.title ?? startCase(field.name),\n type: field.type,\n })) ?? [],\n })) ?? [],\n },\n lists:\n definition?.lists?.map((list) => ({\n value: list.name,\n title: list.title ?? startCase(list.name),\n })) ?? [],\n styles:\n definition?.styles?.map((style) => ({\n value: style.name,\n title: style.title ?? startCase(style.name),\n })) ?? [],\n },\n ],\n })\n\n const schema = SanitySchema.compile({\n types: [portableTextSchema, ...blockObjects, ...inlineObjects],\n }).get('portable-text')\n\n const pteSchema = createPortableTextMemberSchemaTypes(schema)\n\n return {\n ...pteSchema,\n portableText: {\n ...pteSchema.portableText,\n of: pteSchema.portableText.of.map((schemaType) => {\n if (!isObjectSchemaType(schemaType)) {\n return schemaType\n }\n\n const nameMapping = blockObjectNames[schemaType.name]\n\n schemaType.name = nameMapping ?? schemaType.name\n\n for (const field of schemaType.fields) {\n if (field.name !== 'children' || !isArraySchemaType(field.type)) {\n continue\n }\n\n for (const ofSchemaType of field.type.of) {\n const nameMapping = inlineObjectNames[ofSchemaType.name]\n\n if (!nameMapping) {\n continue\n }\n\n ofSchemaType.name = nameMapping\n }\n }\n\n return schemaType\n }),\n },\n blockObjects: pteSchema.blockObjects.map((blockObject) =>\n blockObjectNames[blockObject.name] !== undefined\n ? ({\n ...blockObject,\n name: blockObjectNames[blockObject.name],\n type: {\n ...blockObject.type,\n name: blockObjectNames[blockObject.name],\n },\n } as ObjectSchemaType)\n : blockObject,\n ),\n inlineObjects: pteSchema.inlineObjects.map((inlineObject) =>\n inlineObjectNames[inlineObject.name] !== undefined\n ? ({\n ...inlineObject,\n name: inlineObjectNames[inlineObject.name],\n } as ObjectSchemaType)\n : inlineObject,\n ),\n } satisfies PortableTextMemberSchemaTypes\n}\n"],"names":["SanitySchema","nameMapping"],"mappings":";;;;AAiCO,SAAS,oCACd,kBAC+B;AAC/B,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,iDAAiD;AAEnE,QAAM,YAAY,iBAAiB,IAAI,KAAK,aAAa;AAGzD,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,qDAAqD;AAEvE,QAAM,gBAAgB,UAAU,QAAQ;AAAA,IACtC,CAAC,UAAU,MAAM,SAAS;AAAA,EAAA;AAE5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portable-text-member-schema-types-to-schema.ts","../src/sanity-schema-to-portable-text-schema.ts","../src/key-generator.ts","../src/start-case.ts","../src/schema-definition-to-portable-text-member-schema-types.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 type {PortableTextMemberSchemaTypes} from './portable-text-member-schema-types'\n\n/**\n * @public\n * Convert Sanity-specific schema types for Portable Text to a first-class\n * Portable Text schema.\n */\nexport function portableTextMemberSchemaTypesToSchema(\n schema: PortableTextMemberSchemaTypes,\n): Schema {\n return {\n annotations: schema.annotations.map((annotation) => ({\n name: annotation.name,\n fields: annotation.fields.map((field) => ({\n name: field.name,\n type: field.type.jsonType,\n title: field.type.title,\n })),\n title: annotation.title,\n })),\n block: {\n name: schema.block.name,\n },\n blockObjects: schema.blockObjects.map((blockObject) => ({\n name: blockObject.name,\n fields: blockObject.fields.map((field) => ({\n name: field.name,\n type: field.type.jsonType,\n title: field.type.title,\n })),\n title: blockObject.title,\n })),\n decorators: schema.decorators.map((decorator) => ({\n name: decorator.value,\n title: decorator.title,\n value: decorator.value,\n })),\n inlineObjects: schema.inlineObjects.map((inlineObject) => ({\n name: inlineObject.name,\n fields: inlineObject.fields.map((field) => ({\n name: field.name,\n type: field.type.jsonType,\n title: field.type.title,\n })),\n title: inlineObject.title,\n })),\n span: {\n name: schema.span.name,\n },\n styles: schema.styles.map((style) => ({\n name: style.value,\n title: style.title,\n value: style.value,\n })),\n lists: schema.lists.map((list) => ({\n name: list.value,\n title: list.title,\n value: list.value,\n })),\n }\n}\n","import type {Schema} from '@portabletext/schema'\nimport {Schema as SanitySchema} from '@sanity/schema'\nimport {builtinTypes} from '@sanity/schema/_internal'\nimport type {ArrayDefinition, ArraySchemaType} from '@sanity/types'\nimport {createPortableTextMemberSchemaTypes} from './portable-text-member-schema-types'\nimport {portableTextMemberSchemaTypesToSchema} from './portable-text-member-schema-types-to-schema'\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 portableTextMemberSchemaTypes = createPortableTextMemberSchemaTypes(\n sanitySchema.hasOwnProperty('jsonType')\n ? sanitySchema\n : compileType(sanitySchema),\n )\n\n return portableTextMemberSchemaTypesToSchema(portableTextMemberSchemaTypes)\n}\n\nfunction compileType(rawType: any) {\n return SanitySchema.compile({\n name: 'blockTypeSchema',\n types: [rawType, ...builtinTypes],\n }).get(rawType.name)\n}\n","export const keyGenerator = (): string => randomKey(12)\n\nconst getByteHexTable = (() => {\n let table: any[]\n return () => {\n if (table) {\n return table\n }\n\n table = []\n for (let i = 0; i < 256; ++i) {\n table[i] = (i + 0x100).toString(16).slice(1)\n }\n return table\n }\n})()\n\n// WHATWG crypto RNG - https://w3c.github.io/webcrypto/Overview.html\nfunction whatwgRNG(length = 16) {\n const rnds8 = new Uint8Array(length)\n crypto.getRandomValues(rnds8)\n return rnds8\n}\n\nfunction randomKey(length?: number): string {\n const table = getByteHexTable()\n return whatwgRNG(length)\n .reduce((str, n) => str + table[n], '')\n .slice(0, length)\n}\n","export function startCase(str: string): string {\n return (\n str\n // Insert space before uppercase letters in camelCase (e.g., 'fooBar' -> 'foo Bar')\n .replace(/([a-z])([A-Z])/g, '$1 $2')\n // Replace underscores and dashes with spaces\n .replace(/[_-]+/g, ' ')\n // Trim and split on whitespace\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n // Capitalize first letter of each word, preserve rest\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n .join(' ')\n )\n}\n","import type {SchemaDefinition} from '@portabletext/schema'\nimport {Schema as SanitySchema} from '@sanity/schema'\nimport {\n defineField,\n defineType,\n isArraySchemaType,\n isObjectSchemaType,\n type ObjectSchemaType,\n} from '@sanity/types'\nimport {keyGenerator} from './key-generator'\nimport {\n createPortableTextMemberSchemaTypes,\n type PortableTextMemberSchemaTypes,\n} from './portable-text-member-schema-types'\nimport {startCase} from './start-case'\n\nconst temporaryImageBlockObjectName = `tmp-${keyGenerator()}-image`\nconst temporaryUrlBlockObjectName = `tmp-${keyGenerator()}-url`\nconst temporaryImageInlineObjectName = `tmp-${keyGenerator()}-image`\nconst temporaryUrlInlineObjectName = `tmp-${keyGenerator()}-url`\n\nconst temporaryBlockObjectNames: Record<string, string> = {\n image: temporaryImageBlockObjectName,\n url: temporaryUrlBlockObjectName,\n}\n\nconst temporaryInlineObjectNames: Record<string, string> = {\n image: temporaryImageInlineObjectName,\n url: temporaryUrlInlineObjectName,\n}\n\nconst blockObjectNames: Record<string, string> = {\n [temporaryImageBlockObjectName]: 'image',\n [temporaryUrlBlockObjectName]: 'url',\n}\n\nconst inlineObjectNames: Record<string, string> = {\n [temporaryImageInlineObjectName]: 'image',\n [temporaryUrlInlineObjectName]: 'url',\n}\n\nconst defaultObjectTitles: Record<string, string> = {\n image: 'Image',\n url: 'URL',\n}\n\n/**\n * @public\n * Compile a Portable Text schema definition to Sanity-specific schema types for\n * Portable Text.\n */\nexport function compileSchemaDefinitionToPortableTextMemberSchemaTypes(\n definition?: SchemaDefinition,\n): PortableTextMemberSchemaTypes {\n const blockObjects =\n definition?.blockObjects?.map((blockObject) =>\n defineType({\n type: 'object',\n // Very naive way to work around `SanitySchema.compile` adding default\n // fields to objects with certain names.\n name: temporaryBlockObjectNames[blockObject.name] ?? blockObject.name,\n title:\n blockObject.title === undefined\n ? // This avoids the default title which is a title case of the object name\n defaultObjectTitles[blockObject.name]\n : blockObject.title,\n fields:\n blockObject.fields?.map((field) => ({\n name: field.name,\n type: field.type,\n title: field.title ?? startCase(field.name),\n })) ?? [],\n }),\n ) ?? []\n\n const inlineObjects =\n definition?.inlineObjects?.map((inlineObject) =>\n defineType({\n type: 'object',\n // Very naive way to work around `SanitySchema.compile` adding default\n // fields to objects with certain names.\n name:\n temporaryInlineObjectNames[inlineObject.name] ?? inlineObject.name,\n\n title:\n inlineObject.title === undefined\n ? // This avoids the default title which is a title case of the object name\n defaultObjectTitles[inlineObject.name]\n : inlineObject.title,\n fields:\n inlineObject.fields?.map((field) => ({\n name: field.name,\n type: field.type,\n title: field.title ?? startCase(field.name),\n })) ?? [],\n }),\n ) ?? []\n\n const portableTextSchema = defineField({\n type: 'array',\n name: 'portable-text',\n of: [\n ...blockObjects.map((blockObject) => ({type: blockObject.name})),\n {\n type: 'block',\n name: 'block',\n of: inlineObjects.map((inlineObject) => ({type: inlineObject.name})),\n marks: {\n decorators:\n definition?.decorators?.map((decorator) => ({\n title: decorator.title ?? startCase(decorator.name),\n value: decorator.name,\n })) ?? [],\n annotations:\n definition?.annotations?.map((annotation) => ({\n name: annotation.name,\n type: 'object',\n title: annotation.title,\n fields:\n annotation.fields?.map((field) => ({\n name: field.name,\n title: field.title ?? startCase(field.name),\n type: field.type,\n })) ?? [],\n })) ?? [],\n },\n lists:\n definition?.lists?.map((list) => ({\n value: list.name,\n title: list.title ?? startCase(list.name),\n })) ?? [],\n styles:\n definition?.styles?.map((style) => ({\n value: style.name,\n title: style.title ?? startCase(style.name),\n })) ?? [],\n },\n ],\n })\n\n const schema = SanitySchema.compile({\n types: [portableTextSchema, ...blockObjects, ...inlineObjects],\n }).get('portable-text')\n\n const pteSchema = createPortableTextMemberSchemaTypes(schema)\n\n return {\n ...pteSchema,\n portableText: {\n ...pteSchema.portableText,\n of: pteSchema.portableText.of.map((schemaType) => {\n if (!isObjectSchemaType(schemaType)) {\n return schemaType\n }\n\n const nameMapping = blockObjectNames[schemaType.name]\n\n schemaType.name = nameMapping ?? schemaType.name\n\n for (const field of schemaType.fields) {\n if (field.name !== 'children' || !isArraySchemaType(field.type)) {\n continue\n }\n\n for (const ofSchemaType of field.type.of) {\n const nameMapping = inlineObjectNames[ofSchemaType.name]\n\n if (!nameMapping) {\n continue\n }\n\n ofSchemaType.name = nameMapping\n }\n }\n\n return schemaType\n }),\n },\n blockObjects: pteSchema.blockObjects.map((blockObject) =>\n blockObjectNames[blockObject.name] !== undefined\n ? ({\n ...blockObject,\n name: blockObjectNames[blockObject.name],\n type: {\n ...blockObject.type,\n name: blockObjectNames[blockObject.name],\n },\n } as ObjectSchemaType)\n : blockObject,\n ),\n inlineObjects: pteSchema.inlineObjects.map((inlineObject) =>\n inlineObjectNames[inlineObject.name] !== undefined\n ? ({\n ...inlineObject,\n name: inlineObjectNames[inlineObject.name],\n } as ObjectSchemaType)\n : inlineObject,\n ),\n } satisfies PortableTextMemberSchemaTypes\n}\n"],"names":["SanitySchema","nameMapping"],"mappings":";;;AAiCO,SAAS,oCACd,kBAC+B;AAC/B,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,iDAAiD;AAEnE,QAAM,YAAY,iBAAiB,IAAI,KAAK,aAAa;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,QAAQ,qBAAqB,SAAS;AAAA,IACtC,YAAY,yBAAyB,QAAQ;AAAA,IAC7C,OAAO,wBAAwB,SAAS;AAAA,IACxC,OAAO;AAAA,IACP,MAAM;AAAA,IACN,cAAc;AAAA,IACd,eAAe;AAAA,IACf,cAAc;AAAA,IACd,aAAc,SAA4B;AAAA,EAAA;AAE9C;AAEA,SAAS,qBAAqB,WAA6B;AACzD,QAAM,aAAa,UAAU,QAAQ;AAAA,IACnC,CAAC,YAAY,QAAQ,SAAS;AAAA,EAAA;AAEhC,MAAI,CAAC;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAGJ,QAAM,aACJ,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AAc,kBAAkB,aAAa,IAAI;AAElDA,+BAIL,aAAa,OAAOA;AAAAA,YACtB;AAGF,eAAO;AAAA,MACT,CAAC;AAAA,IAAA;AAAA,IAEH,cAAc,UAAU,aAAa;AAAA,MAAI,CAAC,gBACxC,iBAAiB,YAAY,IAAI,MAAM,SAClC;AAAA,QACC,GAAG;AAAA,QACH,MAAM,iBAAiB,YAAY,IAAI;AAAA,QACvC,MAAM;AAAA,UACJ,GAAG,YAAY;AAAA,UACf,MAAM,iBAAiB,YAAY,IAAI;AAAA,QAAA;AAAA,MACzC,IAEF;AAAA,IAAA;AAAA,IAEN,eAAe,UAAU,cAAc;AAAA,MAAI,CAAC,iBAC1C,kBAAkB,aAAa,IAAI,MAAM,SACpC;AAAA,QACC,GAAG;AAAA,QACH,MAAM,kBAAkB,aAAa,IAAI;AAAA,MAAA,IAE3C;AAAA,IAAA;AAAA,EACN;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/sanity-bridge",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.14",
|
|
4
4
|
"description": "Convert a Sanity Schema to a Portable Text Schema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -34,13 +34,11 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@sanity/schema": "^4.20.3",
|
|
36
36
|
"@sanity/types": "^4.20.3",
|
|
37
|
-
"
|
|
38
|
-
"@portabletext/schema": "^2.0.1"
|
|
37
|
+
"@portabletext/schema": "^2.1.0"
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|
|
41
|
-
"@sanity/pkg-utils": "^10.1.
|
|
42
|
-
"@sanity/tsconfig": "^
|
|
43
|
-
"@types/lodash.startcase": "^4.4.9",
|
|
40
|
+
"@sanity/pkg-utils": "^10.1.2",
|
|
41
|
+
"@sanity/tsconfig": "^2.0.0",
|
|
44
42
|
"typescript": "5.9.3",
|
|
45
43
|
"vitest": "^4.0.14"
|
|
46
44
|
},
|