| export { c as component } from './api-c5c73b52.node.react-server.js'; |
| import { b as basicFormFieldWithSimpleReaderParse, S as SelectFieldInput, F as FieldDataError, B as BlocksFieldInput, C as CheckboxFieldInput, t as text, a as CloudImageFieldInput, D as DateFieldInput, c as assertRequired, d as DatetimeFieldInput, e as FileFieldInput, I as ImageFieldInput, M as MultiRelationshipInput, f as MultiselectFieldInput, N as NumberFieldInput, P as PathReferenceInput, R as RelationshipInput, s as slugify, g as SlugFieldInput, v as validateText, U as UrlFieldInput } from './index-10ea50e2.node.react-server.js'; |
| import { jsx } from 'react/jsx-runtime'; |
| import { o as object, g as getSrcPrefix, f as fixPath, d as document, m as mdx, a as markdoc } from './index-ca270311.node.react-server.js'; |
| import { isString } from 'emery'; |
| import { sanitizeUrl } from '@braintree/sanitize-url'; |
| import { i as integer } from './index-9722793d.node.react-server.js'; |
| import '@markdoc/markdoc/dist/index.mjs'; |
| import 'emery/assertions'; |
| import 'crypto'; |
|
|
| // Common |
|
|
| // Storage |
| // ---------------------------------------------------------------------------- |
|
|
| // ============================================================================ |
| // Functions |
| // ============================================================================ |
|
|
| function config(config) { |
| return config; |
| } |
| function collection(collection) { |
| return collection; |
| } |
| function singleton(collection) { |
| return collection; |
| } |
|
|
| function array(element, opts) { |
| var _opts$label; |
| return { |
| kind: 'array', |
| element, |
| label: (_opts$label = opts === null || opts === void 0 ? void 0 : opts.label) !== null && _opts$label !== void 0 ? _opts$label : 'Items', |
| description: opts === null || opts === void 0 ? void 0 : opts.description, |
| itemLabel: opts === null || opts === void 0 ? void 0 : opts.itemLabel, |
| asChildTag: opts === null || opts === void 0 ? void 0 : opts.asChildTag, |
| slugField: opts === null || opts === void 0 ? void 0 : opts.slugField, |
| validation: opts === null || opts === void 0 ? void 0 : opts.validation |
| }; |
| } |
|
|
| function select({ |
| label, |
| options, |
| defaultValue, |
| description |
| }) { |
| const optionValuesSet = new Set(options.map(x => x.value)); |
| if (!optionValuesSet.has(defaultValue)) { |
| throw new Error(`A defaultValue of ${defaultValue} was provided to a select field but it does not match the value of one of the options provided`); |
| } |
| const field = basicFormFieldWithSimpleReaderParse({ |
| label, |
| Input(props) { |
| return /*#__PURE__*/jsx(SelectFieldInput, { |
| label: label, |
| options: options, |
| description: description, |
| ...props |
| }); |
| }, |
| defaultValue() { |
| return defaultValue; |
| }, |
| parse(value) { |
| if (value === undefined) { |
| return defaultValue; |
| } |
| if (typeof value !== 'string') { |
| throw new FieldDataError('Must be a string'); |
| } |
| if (!optionValuesSet.has(value)) { |
| throw new FieldDataError('Must be a valid option'); |
| } |
| return value; |
| }, |
| validate(value) { |
| return value; |
| }, |
| serialize(value) { |
| return { |
| value |
| }; |
| } |
| }); |
| return { |
| ...field, |
| options |
| }; |
| } |
|
|
| function blocks(blocks, opts) { |
| const entries = Object.entries(blocks); |
| if (!entries.length) { |
| throw new Error('fields.blocks must have at least one entry'); |
| } |
| const select$1 = select({ |
| label: 'Kind', |
| defaultValue: entries[0][0], |
| options: Object.entries(blocks).map(([key, { |
| label |
| }]) => ({ |
| label, |
| value: key |
| })) |
| }); |
| const element = conditional(select$1, Object.fromEntries(entries.map(([key, { |
| schema |
| }]) => [key, schema]))); |
| return { |
| ...array(element, { |
| label: opts.label, |
| description: opts.description, |
| validation: opts.validation, |
| itemLabel(props) { |
| const kind = props.discriminant; |
| const block = blocks[kind]; |
| if (!block.itemLabel) return block.label; |
| return block.itemLabel(props.value); |
| } |
| }), |
| Input: BlocksFieldInput |
| }; |
| } |
|
|
| function checkbox({ |
| label, |
| defaultValue = false, |
| description |
| }) { |
| return basicFormFieldWithSimpleReaderParse({ |
| label, |
| Input(props) { |
| return /*#__PURE__*/jsx(CheckboxFieldInput, { |
| ...props, |
| label: label, |
| description: description |
| }); |
| }, |
| defaultValue() { |
| return defaultValue; |
| }, |
| parse(value) { |
| if (value === undefined) return defaultValue; |
| if (typeof value !== 'boolean') { |
| throw new FieldDataError('Must be a boolean'); |
| } |
| return value; |
| }, |
| validate(value) { |
| return value; |
| }, |
| serialize(value) { |
| return { |
| value |
| }; |
| } |
| }); |
| } |
|
|
| function child(options) { |
| return { |
| kind: 'child', |
| options: options.kind === 'block' ? { |
| ...options, |
| dividers: options.dividers, |
| formatting: options.formatting === 'inherit' ? { |
| blockTypes: 'inherit', |
| headingLevels: 'inherit', |
| inlineMarks: 'inherit', |
| listTypes: 'inherit', |
| alignment: 'inherit', |
| softBreaks: 'inherit' |
| } : options.formatting, |
| links: options.links, |
| images: options.images, |
| tables: options.tables, |
| componentBlocks: options.componentBlocks |
| } : { |
| kind: 'inline', |
| placeholder: options.placeholder, |
| formatting: options.formatting === 'inherit' ? { |
| inlineMarks: 'inherit', |
| softBreaks: 'inherit' |
| } : options.formatting, |
| links: options.links |
| } |
| }; |
| } |
|
|
| function cloudImage({ |
| label, |
| description, |
| validation |
| }) { |
| return { |
| ...object({ |
| src: text({ |
| label: 'URL', |
| validation: { |
| length: { |
| min: validation !== null && validation !== void 0 && validation.isRequired ? 1 : 0 |
| } |
| } |
| }), |
| alt: text({ |
| label: 'Alt text' |
| }), |
| height: integer({ |
| label: 'Height' |
| }), |
| width: integer({ |
| label: 'Width' |
| }) |
| }, { |
| label, |
| description |
| }), |
| Input(props) { |
| return /*#__PURE__*/jsx(CloudImageFieldInput, { |
| ...props, |
| isRequired: validation === null || validation === void 0 ? void 0 : validation.isRequired |
| }); |
| } |
| }; |
| } |
|
|
| function conditional(discriminant, values) { |
| return { |
| kind: 'conditional', |
| discriminant, |
| values: values |
| }; |
| } |
|
|
| function validateDate(validation, value, label) { |
| if (value !== null && !/^\d{4}-\d{2}-\d{2}$/.test(value)) { |
| return `${label} is not a valid date`; |
| } |
| if (validation !== null && validation !== void 0 && validation.isRequired && value === null) { |
| return `${label} is required`; |
| } |
| if ((validation !== null && validation !== void 0 && validation.min || validation !== null && validation !== void 0 && validation.max) && value !== null) { |
| const date = new Date(value); |
| if ((validation === null || validation === void 0 ? void 0 : validation.min) !== undefined) { |
| const min = new Date(validation.min); |
| if (date < min) { |
| return `${label} must be after ${min.toLocaleDateString()}`; |
| } |
| } |
| if ((validation === null || validation === void 0 ? void 0 : validation.max) !== undefined) { |
| const max = new Date(validation.max); |
| if (date > max) { |
| return `${label} must be no later than ${max.toLocaleDateString()}`; |
| } |
| } |
| } |
| } |
|
|
| function date({ |
| label, |
| defaultValue, |
| validation, |
| description |
| }) { |
| return basicFormFieldWithSimpleReaderParse({ |
| label, |
| Input(props) { |
| return /*#__PURE__*/jsx(DateFieldInput, { |
| validation: validation, |
| label: label, |
| description: description, |
| ...props |
| }); |
| }, |
| defaultValue() { |
| if (defaultValue === undefined) { |
| return null; |
| } |
| if (typeof defaultValue === 'string') { |
| return defaultValue; |
| } |
| const today = new Date(); |
| const year = today.getFullYear(); |
| const month = String(today.getMonth() + 1).padStart(2, '0'); |
| const day = String(today.getDate()).padStart(2, '0'); |
| return `${year}-${month}-${day}`; |
| }, |
| parse(value) { |
| if (value === undefined) { |
| return null; |
| } |
| if (value instanceof Date) { |
| const year = value.getUTCFullYear(); |
| const month = String(value.getUTCMonth() + 1).padStart(2, '0'); |
| const day = String(value.getUTCDate()).padStart(2, '0'); |
| return `${year}-${month}-${day}`; |
| } |
| if (typeof value !== 'string') { |
| throw new FieldDataError('Must be a string'); |
| } |
| return value; |
| }, |
| serialize(value) { |
| if (value === null) return { |
| value: undefined |
| }; |
| const date = new Date(value); |
| date.toISOString = () => value; |
| date.toString = () => value; |
| return { |
| value: date |
| }; |
| }, |
| validate(value) { |
| const message = validateDate(validation, value, label); |
| if (message !== undefined) { |
| throw new FieldDataError(message); |
| } |
| assertRequired(value, validation, label); |
| return value; |
| } |
| }); |
| } |
|
|
| function validateDatetime(validation, value, label) { |
| if (value !== null && !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/.test(value)) { |
| return `${label} is not a valid datetime`; |
| } |
| if (validation !== null && validation !== void 0 && validation.isRequired && value === null) { |
| return `${label} is required`; |
| } |
| if ((validation !== null && validation !== void 0 && validation.min || validation !== null && validation !== void 0 && validation.max) && value !== null) { |
| const datetime = new Date(value); |
| if ((validation === null || validation === void 0 ? void 0 : validation.min) !== undefined) { |
| const min = new Date(validation.min); |
| if (datetime < min) { |
| return `${label} must be after ${min.toISOString()}`; |
| } |
| } |
| if ((validation === null || validation === void 0 ? void 0 : validation.max) !== undefined) { |
| const max = new Date(validation.max); |
| if (datetime > max) { |
| return `${label} must be no later than ${max.toISOString()}`; |
| } |
| } |
| } |
| } |
|
|
| function datetime({ |
| label, |
| defaultValue, |
| validation, |
| description |
| }) { |
| return basicFormFieldWithSimpleReaderParse({ |
| label, |
| Input(props) { |
| return /*#__PURE__*/jsx(DatetimeFieldInput, { |
| validation: validation, |
| label: label, |
| description: description, |
| ...props |
| }); |
| }, |
| defaultValue() { |
| if (defaultValue === undefined) { |
| return null; |
| } |
| if (typeof defaultValue === 'string') { |
| return defaultValue; |
| } |
| if (defaultValue.kind === 'now') { |
| const now = new Date(); |
| return new Date(now.getTime() - now.getTimezoneOffset() * 60 * 1000).toISOString().slice(0, -8); |
| } |
| return null; |
| }, |
| parse(value) { |
| if (value === undefined) { |
| return null; |
| } |
| if (value instanceof Date) { |
| return value.toISOString().slice(0, -8); |
| } |
| if (typeof value !== 'string') { |
| throw new FieldDataError('Must be a string or date'); |
| } |
| return value; |
| }, |
| serialize(value) { |
| if (value === null) return { |
| value: undefined |
| }; |
| const date = new Date(value + 'Z'); |
| date.toJSON = () => date.toISOString().slice(0, -8); |
| date.toString = () => date.toISOString().slice(0, -8); |
| return { |
| value: date |
| }; |
| }, |
| validate(value) { |
| const message = validateDatetime(validation, value, label); |
| if (message !== undefined) { |
| throw new FieldDataError(message); |
| } |
| assertRequired(value, validation, label); |
| return value; |
| } |
| }); |
| } |
|
|
| function empty() { |
| return basicFormFieldWithSimpleReaderParse({ |
| Input() { |
| return null; |
| }, |
| defaultValue() { |
| return null; |
| }, |
| parse() { |
| return null; |
| }, |
| serialize() { |
| return { |
| value: undefined |
| }; |
| }, |
| validate(value) { |
| return value; |
| }, |
| label: 'Empty' |
| }); |
| } |
|
|
| /** |
| * @deprecated `emptyDocument` has been replaced with the `emptyContent` field |
| */ |
| function emptyDocument() { |
| return { |
| kind: 'form', |
| formKind: 'content', |
| Input() { |
| return null; |
| }, |
| defaultValue() { |
| return null; |
| }, |
| parse() { |
| return null; |
| }, |
| contentExtension: '.mdoc', |
| serialize() { |
| return { |
| value: undefined, |
| content: new Uint8Array(), |
| external: new Map(), |
| other: new Map() |
| }; |
| }, |
| validate(value) { |
| return value; |
| }, |
| reader: { |
| parse() { |
| return null; |
| } |
| } |
| }; |
| } |
|
|
| function emptyContent(opts) { |
| return { |
| kind: 'form', |
| formKind: 'content', |
| Input() { |
| return null; |
| }, |
| defaultValue() { |
| return null; |
| }, |
| parse() { |
| return null; |
| }, |
| contentExtension: `.${opts.extension}`, |
| serialize() { |
| return { |
| value: undefined, |
| content: new Uint8Array(), |
| external: new Map(), |
| other: new Map() |
| }; |
| }, |
| validate(value) { |
| return value; |
| }, |
| reader: { |
| parse() { |
| return null; |
| } |
| } |
| }; |
| } |
|
|
| function file({ |
| label, |
| directory, |
| validation, |
| description, |
| publicPath, |
| transformFilename |
| }) { |
| return { |
| kind: 'form', |
| formKind: 'asset', |
| label, |
| Input(props) { |
| return /*#__PURE__*/jsx(FileFieldInput, { |
| label: label, |
| description: description, |
| validation: validation, |
| transformFilename: transformFilename, |
| ...props |
| }); |
| }, |
| defaultValue() { |
| return null; |
| }, |
| filename(value, args) { |
| if (typeof value === 'string') { |
| return value.slice(getSrcPrefix(publicPath, args.slug).length); |
| } |
| return undefined; |
| }, |
| parse(value, args) { |
| var _value$match$, _value$match; |
| if (value === undefined) { |
| return null; |
| } |
| if (typeof value !== 'string') { |
| throw new FieldDataError('Must be a string'); |
| } |
| if (args.asset === undefined) { |
| return null; |
| } |
| return { |
| data: args.asset, |
| filename: value.slice(getSrcPrefix(publicPath, args.slug).length), |
| extension: (_value$match$ = (_value$match = value.match(/\.([^.]+$)/)) === null || _value$match === void 0 ? void 0 : _value$match[1]) !== null && _value$match$ !== void 0 ? _value$match$ : '' |
| }; |
| }, |
| validate(value) { |
| assertRequired(value, validation, label); |
| return value; |
| }, |
| serialize(value, args) { |
| if (value === null) { |
| return { |
| value: undefined, |
| asset: undefined |
| }; |
| } |
| const filename = args.suggestedFilenamePrefix ? args.suggestedFilenamePrefix + '.' + value.extension : value.filename; |
| return { |
| value: `${getSrcPrefix(publicPath, args.slug)}${filename}`, |
| asset: { |
| filename, |
| content: value.data |
| } |
| }; |
| }, |
| directory: directory ? fixPath(directory) : undefined, |
| reader: { |
| parse(value) { |
| if (typeof value !== 'string' && value !== undefined) { |
| throw new FieldDataError('Must be a string'); |
| } |
| const val = value === undefined ? null : value; |
| assertRequired(val, validation, label); |
| return val; |
| } |
| } |
| }; |
| } |
|
|
| function image({ |
| label, |
| directory, |
| validation, |
| description, |
| publicPath, |
| transformFilename |
| }) { |
| return { |
| kind: 'form', |
| formKind: 'asset', |
| label, |
| Input(props) { |
| return /*#__PURE__*/jsx(ImageFieldInput, { |
| label: label, |
| description: description, |
| validation: validation, |
| transformFilename: transformFilename, |
| ...props |
| }); |
| }, |
| defaultValue() { |
| return null; |
| }, |
| filename(value, args) { |
| if (typeof value === 'string') { |
| return value.slice(getSrcPrefix(publicPath, args.slug).length); |
| } |
| return undefined; |
| }, |
| parse(value, args) { |
| var _value$match$, _value$match; |
| if (value === undefined) { |
| return null; |
| } |
| if (typeof value !== 'string') { |
| throw new FieldDataError('Must be a string'); |
| } |
| if (args.asset === undefined) { |
| return null; |
| } |
| return { |
| data: args.asset, |
| filename: value.slice(getSrcPrefix(publicPath, args.slug).length), |
| extension: (_value$match$ = (_value$match = value.match(/\.([^.]+$)/)) === null || _value$match === void 0 ? void 0 : _value$match[1]) !== null && _value$match$ !== void 0 ? _value$match$ : '' |
| }; |
| }, |
| validate(value) { |
| assertRequired(value, validation, label); |
| return value; |
| }, |
| serialize(value, args) { |
| if (value === null) { |
| return { |
| value: undefined, |
| asset: undefined |
| }; |
| } |
| const filename = args.suggestedFilenamePrefix ? args.suggestedFilenamePrefix + '.' + value.extension : value.filename; |
| return { |
| value: `${getSrcPrefix(publicPath, args.slug)}${filename}`, |
| asset: { |
| filename, |
| content: value.data |
| } |
| }; |
| }, |
| directory: directory ? fixPath(directory) : undefined, |
| reader: { |
| parse(value) { |
| if (typeof value !== 'string' && value !== undefined) { |
| throw new FieldDataError('Must be a string'); |
| } |
| const val = value === undefined ? null : value; |
| assertRequired(val, validation, label); |
| return val; |
| } |
| } |
| }; |
| } |
|
|
| function pluralize(count, options) { |
| const { |
| singular, |
| plural = singular + 's', |
| inclusive = true |
| } = options; |
| const variant = count === 1 ? singular : plural; |
| return inclusive ? `${count} ${variant}` : variant; |
| } |
|
|
| function validateMultiRelationshipLength(validation, value) { |
| var _validation$length$mi, _validation$length, _validation$length$ma, _validation$length2; |
| const minLength = (_validation$length$mi = validation === null || validation === void 0 || (_validation$length = validation.length) === null || _validation$length === void 0 ? void 0 : _validation$length.min) !== null && _validation$length$mi !== void 0 ? _validation$length$mi : 0; |
| if (value.length < minLength) { |
| return `Must have at least ${pluralize(minLength, { |
| singular: 'item' |
| })}.`; |
| } |
| const maxLength = (_validation$length$ma = validation === null || validation === void 0 || (_validation$length2 = validation.length) === null || _validation$length2 === void 0 ? void 0 : _validation$length2.max) !== null && _validation$length$ma !== void 0 ? _validation$length$ma : Infinity; |
| if (value.length > maxLength) { |
| return `Must have at most ${pluralize(maxLength, { |
| singular: 'item' |
| })}.`; |
| } |
| } |
|
|
| function multiRelationship({ |
| label, |
| collection, |
| validation, |
| description |
| }) { |
| return basicFormFieldWithSimpleReaderParse({ |
| label, |
| Input(props) { |
| return /*#__PURE__*/jsx(MultiRelationshipInput, { |
| label: label, |
| collection: collection, |
| description: description, |
| validation: validation, |
| ...props |
| }); |
| }, |
| defaultValue() { |
| return []; |
| }, |
| parse(value) { |
| if (value === undefined) { |
| return []; |
| } |
| if (!Array.isArray(value) || !value.every(isString)) { |
| throw new FieldDataError('Must be an array of strings'); |
| } |
| return value; |
| }, |
| validate(value) { |
| const error = validateMultiRelationshipLength(validation, value); |
| if (error) { |
| throw new FieldDataError(error); |
| } |
| return value; |
| }, |
| serialize(value) { |
| return { |
| value |
| }; |
| } |
| }); |
| } |
|
|
| function multiselect({ |
| label, |
| options, |
| defaultValue = [], |
| description |
| }) { |
| const valuesToOption = new Map(options.map(x => [x.value, x])); |
| const field = basicFormFieldWithSimpleReaderParse({ |
| label, |
| Input(props) { |
| return /*#__PURE__*/jsx(MultiselectFieldInput, { |
| label: label, |
| description: description, |
| options: options, |
| ...props |
| }); |
| }, |
| defaultValue() { |
| return defaultValue; |
| }, |
| parse(value) { |
| if (value === undefined) { |
| return []; |
| } |
| if (!Array.isArray(value)) { |
| throw new FieldDataError('Must be an array of options'); |
| } |
| if (!value.every(x => typeof x === 'string' && valuesToOption.has(x))) { |
| throw new FieldDataError(`Must be an array with one of ${options.map(x => x.value).join(', ')}`); |
| } |
| return value; |
| }, |
| validate(value) { |
| return value; |
| }, |
| serialize(value) { |
| return { |
| value |
| }; |
| } |
| }); |
| return { |
| ...field, |
| options |
| }; |
| } |
|
|
| function validateNumber(validation, value, step, label) { |
| if (value !== null && typeof value !== 'number') { |
| return `${label} must be a number`; |
| } |
| if (validation !== null && validation !== void 0 && validation.isRequired && value === null) { |
| return `${label} is required`; |
| } |
| if (value !== null) { |
| if ((validation === null || validation === void 0 ? void 0 : validation.min) !== undefined && value < validation.min) { |
| return `${label} must be at least ${validation.min}`; |
| } |
| if ((validation === null || validation === void 0 ? void 0 : validation.max) !== undefined && value > validation.max) { |
| return `${label} must be at most ${validation.max}`; |
| } |
| if (step !== undefined && (validation === null || validation === void 0 ? void 0 : validation.validateStep) !== undefined && !isAtStep(value, step)) { |
| return `${label} must be a multiple of ${step}`; |
| } |
| } |
| } |
| function decimalPlaces(value) { |
| const stringified = value.toString(); |
| const indexOfDecimal = stringified.indexOf('.'); |
| if (indexOfDecimal === -1) { |
| const indexOfE = stringified.indexOf('e-'); |
| return indexOfE === -1 ? 0 : parseInt(stringified.slice(indexOfE + 2)); |
| } |
| return stringified.length - indexOfDecimal - 1; |
| } |
| function isAtStep(value, step) { |
| const dc = Math.max(decimalPlaces(step), decimalPlaces(value)); |
| const base = Math.pow(10, dc); |
| return value * base % (step * base) === 0; |
| } |
|
|
| function number({ |
| label, |
| defaultValue, |
| step, |
| validation, |
| description |
| }) { |
| return basicFormFieldWithSimpleReaderParse({ |
| label, |
| Input(props) { |
| return /*#__PURE__*/jsx(NumberFieldInput, { |
| label: label, |
| description: description, |
| validation: validation, |
| step: step, |
| ...props |
| }); |
| }, |
| defaultValue() { |
| return defaultValue !== null && defaultValue !== void 0 ? defaultValue : null; |
| }, |
| parse(value) { |
| if (value === undefined) { |
| return null; |
| } |
| if (typeof value === 'number') { |
| return value; |
| } |
| throw new FieldDataError('Must be a number'); |
| }, |
| validate(value) { |
| const message = validateNumber(validation, value, step, label); |
| if (message !== undefined) { |
| throw new FieldDataError(message); |
| } |
| assertRequired(value, validation, label); |
| return value; |
| }, |
| serialize(value) { |
| return { |
| value: value === null ? undefined : value |
| }; |
| } |
| }); |
| } |
|
|
| function pathReference({ |
| label, |
| pattern, |
| validation, |
| description |
| }) { |
| return basicFormFieldWithSimpleReaderParse({ |
| label, |
| Input(props) { |
| return /*#__PURE__*/jsx(PathReferenceInput, { |
| label: label, |
| pattern: pattern, |
| description: description, |
| validation: validation, |
| ...props |
| }); |
| }, |
| defaultValue() { |
| return null; |
| }, |
| parse(value) { |
| if (value === undefined) { |
| return null; |
| } |
| if (typeof value !== 'string') { |
| throw new FieldDataError('Must be a string'); |
| } |
| return value; |
| }, |
| validate(value) { |
| assertRequired(value, validation, label); |
| return value; |
| }, |
| serialize(value) { |
| return { |
| value: value === null ? undefined : value |
| }; |
| } |
| }); |
| } |
|
|
| function relationship({ |
| label, |
| collection, |
| validation, |
| description |
| }) { |
| return basicFormFieldWithSimpleReaderParse({ |
| label, |
| Input(props) { |
| return /*#__PURE__*/jsx(RelationshipInput, { |
| label: label, |
| collection: collection, |
| description: description, |
| validation: validation, |
| ...props |
| }); |
| }, |
| defaultValue() { |
| return null; |
| }, |
| parse(value) { |
| if (value === undefined) { |
| return null; |
| } |
| if (typeof value !== 'string') { |
| throw new FieldDataError('Must be a string'); |
| } |
| return value; |
| }, |
| validate(value) { |
| assertRequired(value, validation, label); |
| return value; |
| }, |
| serialize(value) { |
| return { |
| value: value === null ? undefined : value |
| }; |
| } |
| }); |
| } |
|
|
| function parseSlugFieldAsNormalField(value) { |
| if (value === undefined) { |
| return { |
| name: '', |
| slug: '' |
| }; |
| } |
| if (typeof value !== 'object') { |
| throw new FieldDataError('Must be an object'); |
| } |
| if (Object.keys(value).length !== 2) { |
| throw new FieldDataError('Unexpected keys'); |
| } |
| if (!('name' in value) || !('slug' in value)) { |
| throw new FieldDataError('Missing name or slug'); |
| } |
| if (typeof value.name !== 'string') { |
| throw new FieldDataError('name must be a string'); |
| } |
| if (typeof value.slug !== 'string') { |
| throw new FieldDataError('slug must be a string'); |
| } |
| return { |
| name: value.name, |
| slug: value.slug |
| }; |
| } |
| function parseAsSlugField(value, slug) { |
| if (value === undefined) { |
| return { |
| name: '', |
| slug |
| }; |
| } |
| if (typeof value !== 'string') { |
| throw new FieldDataError('Must be a string'); |
| } |
| return { |
| name: value, |
| slug |
| }; |
| } |
| function slug(_args) { |
| var _args$name$validation, _args$name$validation2, _args$name$validation3, _args$name$validation4, _args$name$validation5, _args$slug; |
| const args = { |
| ..._args, |
| name: { |
| ..._args.name, |
| validation: { |
| pattern: (_args$name$validation = _args.name.validation) === null || _args$name$validation === void 0 ? void 0 : _args$name$validation.pattern, |
| length: { |
| min: Math.max((_args$name$validation2 = _args.name.validation) !== null && _args$name$validation2 !== void 0 && _args$name$validation2.isRequired ? 1 : 0, (_args$name$validation3 = (_args$name$validation4 = _args.name.validation) === null || _args$name$validation4 === void 0 || (_args$name$validation4 = _args$name$validation4.length) === null || _args$name$validation4 === void 0 ? void 0 : _args$name$validation4.min) !== null && _args$name$validation3 !== void 0 ? _args$name$validation3 : 0), |
| max: (_args$name$validation5 = _args.name.validation) === null || _args$name$validation5 === void 0 || (_args$name$validation5 = _args$name$validation5.length) === null || _args$name$validation5 === void 0 ? void 0 : _args$name$validation5.max |
| } |
| } |
| } |
| }; |
| const naiveGenerateSlug = ((_args$slug = args.slug) === null || _args$slug === void 0 ? void 0 : _args$slug.generate) || slugify; |
| let _defaultValue; |
| function defaultValue() { |
| if (!_defaultValue) { |
| var _args$name$defaultVal, _args$name$defaultVal2; |
| _defaultValue = { |
| name: (_args$name$defaultVal = args.name.defaultValue) !== null && _args$name$defaultVal !== void 0 ? _args$name$defaultVal : '', |
| slug: naiveGenerateSlug((_args$name$defaultVal2 = args.name.defaultValue) !== null && _args$name$defaultVal2 !== void 0 ? _args$name$defaultVal2 : '') |
| }; |
| } |
| return _defaultValue; |
| } |
| function validate(value, { |
| slugField |
| } = { |
| slugField: undefined |
| }) { |
| var _args$name$validation6, _args$name$validation7, _args$name$validation8, _args$name$validation9, _args$name$validation10, _args$slug$validation, _args$slug2, _args$slug$validation2, _args$slug3, _args$slug$label, _args$slug4, _args$slug5; |
| const nameMessage = validateText(value.name, (_args$name$validation6 = (_args$name$validation7 = args.name.validation) === null || _args$name$validation7 === void 0 || (_args$name$validation7 = _args$name$validation7.length) === null || _args$name$validation7 === void 0 ? void 0 : _args$name$validation7.min) !== null && _args$name$validation6 !== void 0 ? _args$name$validation6 : 0, (_args$name$validation8 = (_args$name$validation9 = args.name.validation) === null || _args$name$validation9 === void 0 || (_args$name$validation9 = _args$name$validation9.length) === null || _args$name$validation9 === void 0 ? void 0 : _args$name$validation9.max) !== null && _args$name$validation8 !== void 0 ? _args$name$validation8 : Infinity, args.name.label, undefined, (_args$name$validation10 = args.name.validation) === null || _args$name$validation10 === void 0 ? void 0 : _args$name$validation10.pattern); |
| if (nameMessage !== undefined) { |
| throw new FieldDataError(nameMessage); |
| } |
| const slugMessage = validateText(value.slug, (_args$slug$validation = (_args$slug2 = args.slug) === null || _args$slug2 === void 0 || (_args$slug2 = _args$slug2.validation) === null || _args$slug2 === void 0 || (_args$slug2 = _args$slug2.length) === null || _args$slug2 === void 0 ? void 0 : _args$slug2.min) !== null && _args$slug$validation !== void 0 ? _args$slug$validation : 1, (_args$slug$validation2 = (_args$slug3 = args.slug) === null || _args$slug3 === void 0 || (_args$slug3 = _args$slug3.validation) === null || _args$slug3 === void 0 || (_args$slug3 = _args$slug3.length) === null || _args$slug3 === void 0 ? void 0 : _args$slug3.max) !== null && _args$slug$validation2 !== void 0 ? _args$slug$validation2 : Infinity, (_args$slug$label = (_args$slug4 = args.slug) === null || _args$slug4 === void 0 ? void 0 : _args$slug4.label) !== null && _args$slug$label !== void 0 ? _args$slug$label : 'Slug', slugField ? slugField : { |
| slugs: emptySet, |
| glob: '*' |
| }, (_args$slug5 = args.slug) === null || _args$slug5 === void 0 || (_args$slug5 = _args$slug5.validation) === null || _args$slug5 === void 0 ? void 0 : _args$slug5.pattern); |
| if (slugMessage !== undefined) { |
| throw new FieldDataError(slugMessage); |
| } |
| return value; |
| } |
| const emptySet = new Set(); |
| return { |
| kind: 'form', |
| formKind: 'slug', |
| label: args.name.label, |
| Input(props) { |
| return /*#__PURE__*/jsx(SlugFieldInput, { |
| args: args, |
| naiveGenerateSlug: naiveGenerateSlug, |
| defaultValue: defaultValue(), |
| ...props |
| }); |
| }, |
| defaultValue, |
| parse(value, args) { |
| if ((args === null || args === void 0 ? void 0 : args.slug) !== undefined) { |
| return parseAsSlugField(value, args.slug); |
| } |
| return parseSlugFieldAsNormalField(value); |
| }, |
| validate, |
| serialize(value) { |
| return { |
| value |
| }; |
| }, |
| serializeWithSlug(value) { |
| return { |
| value: value.name, |
| slug: value.slug |
| }; |
| }, |
| reader: { |
| parse(value) { |
| const parsed = parseSlugFieldAsNormalField(value); |
| return validate(parsed); |
| }, |
| parseWithSlug(value, args) { |
| return validate(parseAsSlugField(value, args.slug), { |
| slugField: { |
| glob: args.glob, |
| slugs: emptySet |
| } |
| }).name; |
| } |
| } |
| }; |
| } |
|
|
| function isValidURL(url) { |
| return url === sanitizeUrl(url); |
| } |
|
|
| function validateUrl(validation, value, label) { |
| if (value !== null && (typeof value !== 'string' || !isValidURL(value))) { |
| return `${label} is not a valid URL`; |
| } |
| if (validation !== null && validation !== void 0 && validation.isRequired && value === null) { |
| return `${label} is required`; |
| } |
| } |
|
|
| function url({ |
| label, |
| defaultValue, |
| validation, |
| description |
| }) { |
| return basicFormFieldWithSimpleReaderParse({ |
| label, |
| Input(props) { |
| return /*#__PURE__*/jsx(UrlFieldInput, { |
| label: label, |
| description: description, |
| validation: validation, |
| ...props |
| }); |
| }, |
| defaultValue() { |
| return defaultValue || null; |
| }, |
| parse(value) { |
| if (value === undefined) { |
| return null; |
| } |
| if (typeof value !== 'string') { |
| throw new FieldDataError('Must be a string'); |
| } |
| return value === '' ? null : value; |
| }, |
| validate(value) { |
| const message = validateUrl(validation, value, label); |
| if (message !== undefined) { |
| throw new FieldDataError(message); |
| } |
| assertRequired(value, validation, label); |
| return value; |
| }, |
| serialize(value) { |
| return { |
| value: value === null ? undefined : value |
| }; |
| } |
| }); |
| } |
|
|
| function ignored() { |
| return { |
| kind: 'form', |
| Input() { |
| return null; |
| }, |
| defaultValue() { |
| return { |
| value: undefined |
| }; |
| }, |
| parse(value) { |
| return { |
| value |
| }; |
| }, |
| serialize(value) { |
| return value; |
| }, |
| validate(value) { |
| return value; |
| }, |
| label: 'Ignored', |
| reader: { |
| parse(value) { |
| return value; |
| } |
| } |
| }; |
| } |
|
|
| var index = /*#__PURE__*/Object.freeze({ |
| __proto__: null, |
| array: array, |
| blocks: blocks, |
| checkbox: checkbox, |
| child: child, |
| cloudImage: cloudImage, |
| conditional: conditional, |
| date: date, |
| datetime: datetime, |
| document: document, |
| empty: empty, |
| emptyDocument: emptyDocument, |
| emptyContent: emptyContent, |
| file: file, |
| image: image, |
| integer: integer, |
| multiRelationship: multiRelationship, |
| multiselect: multiselect, |
| number: number, |
| object: object, |
| pathReference: pathReference, |
| relationship: relationship, |
| select: select, |
| slug: slug, |
| text: text, |
| url: url, |
| ignored: ignored, |
| mdx: mdx, |
| markdoc: markdoc |
| }); |
|
|
| function BlockWrapper() {} |
| function NotEditable() {} |
| function ToolbarSeparator() {} |
|
|
| export { BlockWrapper, NotEditable, ToolbarSeparator, collection, config, index as fields, singleton }; |