index
int64
0
0
repo_id
stringlengths
16
181
file_path
stringlengths
28
270
content
stringlengths
1
11.6M
__index_level_0__
int64
0
10k
0
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils/selection.ts
import {isEqual} from 'lodash' import {Path, PortableTextBlock} from '@sanity/types' import {EditorSelection, EditorSelectionPoint} from '../types/editor' export function normalizePoint( point: EditorSelectionPoint, value: PortableTextBlock[], ): EditorSelectionPoint | null { if (!point || !value) { return n...
2,200
0
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils/ucs2Indices.ts
import type {Patch} from '@sanity/diff-match-patch' /** * Takes a `patches` array as produced by diff-match-patch and adjusts the * `start1` and `start2` properties so that they refer to UCS-2 index instead * of a UTF-8 index. * * @param patches - The patches to adjust * @param base - The base string to use for ...
2,201
0
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils/validateValue.ts
import {PortableTextBlock, PortableTextSpan, PortableTextTextBlock} from '@sanity/types' import {flatten, isObject, uniq} from 'lodash' import {set, unset, insert} from '../patch/PatchEvent' import {InvalidValueResolution, PortableTextMemberSchemaTypes} from '../types/editor' export interface Validation { valid: boo...
2,202
0
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils/values.ts
import {isEqual} from 'lodash' import {Node, Element, Text, Descendant} from 'slate' import { PathSegment, PortableTextBlock, PortableTextChild, PortableTextObject, PortableTextTextBlock, } from '@sanity/types' import {PortableTextMemberSchemaTypes} from '../types/editor' import {defaultKeyGenerator as keyGen...
2,203
0
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils/weakMaps.ts
import {Editor, Element, Range} from 'slate' import {EditorSelection} from '..' // Is the editor currently receiving remote changes that are being applied to the content? export const IS_PROCESSING_REMOTE_CHANGES: WeakMap<Editor, boolean> = new WeakMap() // Is the editor currently producing local changes that are not ...
2,204
0
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils/withChanges.ts
import {Editor} from 'slate' import {IS_PROCESSING_LOCAL_CHANGES, IS_PROCESSING_REMOTE_CHANGES} from './weakMaps' export function withRemoteChanges(editor: Editor, fn: () => void): void { const prev = isChangingRemotely(editor) || false IS_PROCESSING_REMOTE_CHANGES.set(editor, true) fn() IS_PROCESSING_REMOTE_C...
2,205
0
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils/withPreserveKeys.ts
import {Editor} from 'slate' export const PRESERVE_KEYS: WeakMap<Editor, boolean | undefined> = new WeakMap() export function withPreserveKeys(editor: Editor, fn: () => void): void { const prev = isPreservingKeys(editor) PRESERVE_KEYS.set(editor, true) fn() PRESERVE_KEYS.set(editor, prev) } export function i...
2,206
0
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils/withoutPatching.ts
import {Editor} from 'slate' export const PATCHING: WeakMap<Editor, boolean | undefined> = new WeakMap() export function withoutPatching(editor: Editor, fn: () => void): void { const prev = isPatching(editor) PATCHING.set(editor, false) fn() PATCHING.set(editor, prev) } export function isPatching(editor: Edi...
2,207
0
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils/__tests__/dmpToOperations.test.ts
import {Descendant, Operation} from 'slate' import { Path, PortableTextBlock, PortableTextSpan, PortableTextTextBlock, isPortableTextSpan, isPortableTextTextBlock, } from '@sanity/types' import {makeDiff, makePatches, stringifyPatches} from '@sanity/diff-match-patch' import {diffMatchPatch} from '../applyPa...
2,208
0
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils/__tests__/operationToPatches.test.ts
import {createEditor, Descendant} from 'slate' import {PortableTextTextBlock} from '@sanity/types' import {getPortableTextMemberSchemaTypes} from '../getPortableTextMemberSchemaTypes' import {schemaType} from '../../editor/__tests__/PortableTextEditorTester' import {createOperationToPatches} from '../operationToPatches...
2,209
0
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils/__tests__/patchToOperations.test.ts
import {createEditor, Descendant} from 'slate' import {noop} from 'lodash' import {schemaType} from '../../editor/__tests__/PortableTextEditorTester' import {createApplyPatch} from '../applyPatch' import {withPlugins} from '../../editor/plugins' import {keyGenerator, Patch, PortableTextEditor} from '../..' import {getP...
2,210
0
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils/__tests__/valueNormalization.test.tsx
import {render, waitFor} from '@testing-library/react' import React from 'react' import {PortableTextEditor} from '../../editor/PortableTextEditor' import {PortableTextEditorTester, schemaType} from '../../editor/__tests__/PortableTextEditorTester' describe('values: normalization', () => { it("accepts incoming valu...
2,211
0
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils
petrpan-code/sanity-io/sanity/packages/@sanity/portable-text-editor/src/utils/__tests__/values.test.ts
import {VOID_CHILD_KEY, fromSlateValue, toSlateValue} from '../values' import {schemaType} from '../../editor/__tests__/PortableTextEditorTester' import {getPortableTextMemberSchemaTypes} from '../getPortableTextMemberSchemaTypes' const schemaTypes = getPortableTextMemberSchemaTypes(schemaType) describe('toSlateValue...
2,212
0
petrpan-code/sanity-io/sanity/packages/@sanity
petrpan-code/sanity-io/sanity/packages/@sanity/schema/.depcheckignore.json
{ "ignore": ["@optimize-lodash/rollup-plugin", "@sanity/pkg-utils"] }
2,213
0
petrpan-code/sanity-io/sanity/packages/@sanity
petrpan-code/sanity-io/sanity/packages/@sanity/schema/.eslintignore
# package specific _internal.js
2,214
0
petrpan-code/sanity-io/sanity/packages/@sanity
petrpan-code/sanity-io/sanity/packages/@sanity/schema/.eslintrc.cjs
'use strict' const path = require('path') const ROOT_PATH = path.resolve(__dirname, '../../..') module.exports = { rules: { 'import/no-extraneous-dependencies': ['error', {packageDir: [ROOT_PATH, __dirname]}], }, }
2,215
0
petrpan-code/sanity-io/sanity/packages/@sanity
petrpan-code/sanity-io/sanity/packages/@sanity/schema/LICENSE
MIT License Copyright (c) 2016 - 2023 Sanity.io Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, ...
2,216
0
petrpan-code/sanity-io/sanity/packages/@sanity
petrpan-code/sanity-io/sanity/packages/@sanity/schema/README.md
# Sanity schema ## Terminology - **`Schema`** A collection of types - **`Type`** A specification of a data structure. Available through schema lookup. - **`Member type`** A member type is a type contained by a schema type. For example, an array may specify the allowed item types by defining members types from schema ...
2,217
0
petrpan-code/sanity-io/sanity/packages/@sanity
petrpan-code/sanity-io/sanity/packages/@sanity/schema/jest.config.cjs
'use strict' const {createJestConfig} = require('../../../test/config.cjs') module.exports = createJestConfig({ displayName: require('./package.json').name, testEnvironment: 'node', })
2,218
0
petrpan-code/sanity-io/sanity/packages/@sanity
petrpan-code/sanity-io/sanity/packages/@sanity/schema/member-types.md
## Member types A member type is a type that is not a part of the schema, but rather exists as a member of another type. For example, each fields of an object has fields which are just specialization of schema types.
2,219
0
petrpan-code/sanity-io/sanity/packages/@sanity
petrpan-code/sanity-io/sanity/packages/@sanity/schema/package.config.ts
import {defineConfig} from '@sanity/pkg-utils' import baseConfig from '../../../package.config' export default defineConfig({...baseConfig})
2,220
0
petrpan-code/sanity-io/sanity/packages/@sanity
petrpan-code/sanity-io/sanity/packages/@sanity/schema/package.json
{ "name": "@sanity/schema", "version": "3.20.1", "description": "", "keywords": [ "sanity", "cms", "headless", "realtime", "content", "schema" ], "homepage": "https://www.sanity.io/", "bugs": { "url": "https://github.com/sanity-io/sanity/issues" }, "repository": { "type...
2,221
0
petrpan-code/sanity-io/sanity/packages/@sanity
petrpan-code/sanity-io/sanity/packages/@sanity/schema/tsconfig.json
{ "extends": "../../../tsconfig.settings", "include": ["./example", "./src"], "compilerOptions": { "composite": true, "rootDir": ".", "outDir": "./lib/dts", "noUnusedLocals": false, "strict": false }, "references": [{"path": "../types/tsconfig.lib.json"}] }
2,222
0
petrpan-code/sanity-io/sanity/packages/@sanity
petrpan-code/sanity-io/sanity/packages/@sanity/schema/tsconfig.lib.json
{ "extends": "../../../tsconfig.settings", "include": ["./example", "./src"], "compilerOptions": { "composite": true, "rootDir": ".", "outDir": "./lib/dts", "noUnusedLocals": false, "strict": false }, "references": [{"path": "../types/tsconfig.lib.json"}] }
2,223
0
petrpan-code/sanity-io/sanity/packages/@sanity
petrpan-code/sanity-io/sanity/packages/@sanity/schema/turbo.json
{ "$schema": "https://turbo.build/schema.json", "extends": ["//"], "pipeline": { "build": { "outputs": ["lib/**", "index.js", "_internal.js"] } } }
2,224
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema
petrpan-code/sanity-io/sanity/packages/@sanity/schema/example/test.js
import assert from 'assert' import {Schema} from '../src/legacy/Schema' import schemaDef from './schema-def' const schema = new Schema(schemaDef) const person = schema.get('person') assert.equal(person.type, schema.get('object')) assert.equal(person.title, 'Person') const FIRSTNAME = 0 const ADDRESS = 1 const CUSTOM...
2,225
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/example
petrpan-code/sanity-io/sanity/packages/@sanity/schema/example/schema-def/index.js
const CUSTOMER = { name: 'customer', type: 'object', fields: [ { name: 'customerId', title: 'Customer ID', type: 'string', }, ], } const PERSON = { name: 'person', type: 'object', title: 'Person', options: { preview: { fields: ['foo'], prepare(v) { retu...
2,226
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/_exports/_internal.ts
export { type TypeWithProblems, type ProblemPathPropertySegment, type ProblemPathTypeSegment, type ProblemPathSegment, type ProblemPath, type SchemaValidationResult as Problem, type SchemaValidationResult as ValidationResult, type _FIXME_ as FIXME, } from '../sanity/typedefs' export {groupProblems} fro...
2,227
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/_exports/index.ts
import {Schema as NamedSchema, DeprecatedDefaultSchema} from '../legacy/Schema' export default DeprecatedDefaultSchema export const Schema = NamedSchema export {type SchemaValidationResult} from '../sanity/typedefs'
2,228
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/core/traverseSchema.ts
import {flatten, uniq} from 'lodash' import {getDupes} from '../sanity/validation/utils/getDupes' type SchemaType = Record<string, any> type SchemaTypeDef = Record<string, any> type VisitContext = { isRoot: boolean isReserved: (typeName: string) => boolean visit: Visitor index: number isDuplicate: (typeName...
2,229
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/Schema.ts
import * as types from './types' function compileRegistry(schemaDef) { const registry = Object.assign(Object.create(null), types) const defsByName = schemaDef.types.reduce((acc, def) => { if (acc[def.name]) { throw new Error(`Duplicate type name added to schema: ${def.name}`) } acc[def.name] = d...
2,230
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/actionUtils.ts
import {generateHelpUrl} from '@sanity/generate-help-url' import {SchemaType} from '@sanity/types' import {difference} from 'lodash' const ACTIONS_FLAG = '__experimental_actions' const DEFAULT_ACTIONS = ['create', 'update', 'delete', 'publish'] const VALID_ACTIONS = DEFAULT_ACTIONS // todo: enable this when official...
2,231
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/ordering/guessOrderingConfig.ts
import {capitalize, startCase} from 'lodash' const CANDIDATES = ['title', 'name', 'label', 'heading', 'header', 'caption', 'description'] const PRIMITIVES = ['string', 'boolean', 'number'] const isPrimitive = (field) => PRIMITIVES.includes(field.type) export default function guessOrderingConfig(objectTypeDef) { l...
2,232
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/preview/JSONStringifyHuman.ts
import {pick} from 'lodash' function isEmpty(object) { for (const key in object) { if (object.hasOwnProperty(key)) { return false } } return true } function _stringify(value, options, depth) { if (depth > options.maxDepth) { return '...' } if (Array.isArray(value)) { if (value.length...
2,233
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/preview/createPreviewGetter.ts
import {pick} from 'lodash' import guessPreviewConfig from './guessPreviewConfig' import {warnIfPreviewOnOptions, warnIfPreviewHasFields} from './deprecationUtils' function parseSelection(selection) { return selection.reduce((acc, field) => { acc[field] = field return acc }, {}) } function parsePreview(pr...
2,234
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/preview/deprecationUtils.ts
export function warnIfPreviewOnOptions(type) { if (type.options && type.options.preview) { // eslint-disable-next-line no-console console.warn(`Heads up! The preview config is no longer defined on "options", but instead on the type/field itself. Please move {options: {preview: ...}} to {..., preview: ...} on ...
2,235
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/preview/fallbackPrepare.ts
import {pick} from 'lodash' import stringify from './JSONStringifyHuman' const OPTIONS = { maxEntries: 2, maxDepth: 2, maxBreadth: 2, ignoreKeys: ['_id', '_type', '_key', '_ref'], } export function createFallbackPrepare(fieldNames) { return (value) => ({ title: stringify(pick(value, fieldNames), OPTIONS...
2,236
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/preview/guessPreviewConfig.ts
import {omitBy, isUndefined} from 'lodash' import arrify from 'arrify' import {createFallbackPrepare} from './fallbackPrepare' import {isBlockField} from './portableText' const TITLE_CANDIDATES = ['title', 'name', 'label', 'heading', 'header', 'caption'] const DESCRIPTION_CANDIDATES = ['description', ...TITLE_CANDIDAT...
2,237
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/preview/portableText.ts
type FieldDef = { type: string name: string of?: {type: string}[] } export function isBlockField(field: FieldDef): boolean { return field.type === 'array' && field.of && field.of.some((member) => member.type === 'block') }
2,238
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/preview/primitivePreview.ts
export default { prepare: (val) => ({title: String(val)}), }
2,239
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/searchConfig/normalize.ts
import {isPlainObject, toPath} from 'lodash' export function normalizeSearchConfigs(configs) { if (!Array.isArray(configs)) { throw new Error( 'The search config of a document type must be an array of search config objects', ) } return configs.map((conf) => { if (conf === 'defaults') { re...
2,240
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/searchConfig/resolve.ts
import {uniqBy} from 'lodash' const stringFieldsSymbol = Symbol('__cachedStringFields') const isReference = (type) => type.type && type.type.name === 'reference' const portableTextFields = ['style', 'list'] const isPortableTextBlock = (type) => type.name === 'block' || (type.type && isPortableTextBlock(type.type))...
2,241
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/any.ts
import {pick, omit} from 'lodash' import {DEFAULT_OVERRIDEABLE_FIELDS} from './constants' const OVERRIDABLE_FIELDS = [...DEFAULT_OVERRIDEABLE_FIELDS] const ANY_CORE = { name: 'any', type: null, jsonType: 'any', } export const AnyType = { get() { return ANY_CORE }, extend(subTypeDef, extendMember) { ...
2,242
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/array.ts
import {pick} from 'lodash' import {lazyGetter} from './utils' import {DEFAULT_OVERRIDEABLE_FIELDS} from './constants' const OVERRIDABLE_FIELDS = [...DEFAULT_OVERRIDEABLE_FIELDS] const ARRAY_CORE = { name: 'array', type: null, jsonType: 'array', of: [], } export const ArrayType = { get() { return ARRAY...
2,243
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/boolean.ts
import {pick} from 'lodash' import primitivePreview from '../preview/primitivePreview' import {DEFAULT_OVERRIDEABLE_FIELDS} from './constants' const OVERRIDABLE_FIELDS = [...DEFAULT_OVERRIDEABLE_FIELDS] const BOOLEAN_CORE = { name: 'boolean', title: 'Boolean', type: null, jsonType: 'boolean', } export const ...
2,244
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/constants.ts
export const DEFAULT_OVERRIDEABLE_FIELDS = [ 'jsonType', 'type', 'name', 'title', 'description', 'options', 'fieldsets', 'validation', 'readOnly', 'hidden', 'components', 'diffComponent', 'initialValue', ]
2,245
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/crossDatasetReference.ts
import arrify from 'arrify' import {capitalize, pick} from 'lodash' import {resolveSearchConfigForBaseFieldPaths} from '../searchConfig/resolve' import {lazyGetter} from './utils' import {DEFAULT_OVERRIDEABLE_FIELDS} from './constants' export const REF_FIELD = { name: '_ref', title: 'Referenced document ID', typ...
2,246
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/date.ts
import {pick} from 'lodash' import primitivePreview from '../preview/primitivePreview' import {DEFAULT_OVERRIDEABLE_FIELDS} from './constants' const OVERRIDABLE_FIELDS = [...DEFAULT_OVERRIDEABLE_FIELDS] const DATE_CORE = { name: 'date', title: 'Datetime', type: null, jsonType: 'string', } export const DateTy...
2,247
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/datetime.ts
import {pick} from 'lodash' import primitivePreview from '../preview/primitivePreview' import {DEFAULT_OVERRIDEABLE_FIELDS} from './constants' const OVERRIDABLE_FIELDS = [...DEFAULT_OVERRIDEABLE_FIELDS] const DATETIME_CORE = { name: 'datetime', title: 'Datetime', type: null, jsonType: 'string', } export cons...
2,248
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/document.ts
import {ObjectType} from './object' const DOCUMENT_CORE = { name: 'document', title: 'Document', type: null, jsonType: 'object', } export const DocumentType = { get() { return DOCUMENT_CORE }, extend: ObjectType.extend, }
2,249
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/email.ts
import {pick} from 'lodash' import primitivePreview from '../preview/primitivePreview' import {DEFAULT_OVERRIDEABLE_FIELDS} from './constants' const OVERRIDABLE_FIELDS = [...DEFAULT_OVERRIDEABLE_FIELDS] const EMAIL_CORE = { name: 'email', title: 'Email', type: null, jsonType: 'string', } export const EmailTy...
2,250
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/file.ts
import {pick, startCase} from 'lodash' import createPreviewGetter from '../preview/createPreviewGetter' import {lazyGetter} from './utils' import {DEFAULT_OVERRIDEABLE_FIELDS} from './constants' import {createFieldsets} from './object' export const ASSET_FIELD = { name: 'asset', type: 'reference', to: {type: 'sa...
2,251
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/image.ts
import {pick, startCase} from 'lodash' import createPreviewGetter from '../preview/createPreviewGetter' import {lazyGetter} from './utils' import {ASSET_FIELD, HOTSPOT_FIELD, CROP_FIELD} from './image/fieldDefs' import {DEFAULT_OVERRIDEABLE_FIELDS} from './constants' import {createFieldsets} from './object' const OVER...
2,252
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/index.ts
export {AnyType as any} from './any' export {StringType as string} from './string' export {TextType as text} from './text' export {DateTimeType as datetime} from './datetime' export {DateType as date} from './date' export {BooleanType as boolean} from './boolean' export {UrlType as url} from './url' export {EmailType a...
2,253
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/number.ts
import {pick} from 'lodash' import primitivePreview from '../preview/primitivePreview' import {DEFAULT_OVERRIDEABLE_FIELDS} from './constants' const OVERRIDABLE_FIELDS = [...DEFAULT_OVERRIDEABLE_FIELDS] const NUMBER_CORE = { name: 'number', title: 'Number', type: null, jsonType: 'number', } export const Numb...
2,254
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/object.ts
import {castArray, flatMap, pick, startCase} from 'lodash' import type { FieldGroup, FieldGroupDefinition, Fieldset, FieldsetDefinition, ObjectDefinition, ObjectField, } from '@sanity/types' import createPreviewGetter from '../preview/createPreviewGetter' import guessOrderingConfig from '../ordering/guessOr...
2,255
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/reference.ts
import arrify from 'arrify' import {pick} from 'lodash' import {lazyGetter} from './utils' import {DEFAULT_OVERRIDEABLE_FIELDS} from './constants' import {createFieldsets} from './object' export const REF_FIELD = { name: '_ref', title: 'Referenced document ID', type: 'string', } export const WEAK_FIELD = { na...
2,256
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/string.ts
import {pick} from 'lodash' import primitivePreview from '../preview/primitivePreview' import {DEFAULT_OVERRIDEABLE_FIELDS} from './constants' const OVERRIDABLE_FIELDS = [...DEFAULT_OVERRIDEABLE_FIELDS] const STRING_CORE = { name: 'string', title: 'String', type: null, jsonType: 'string', } export const Stri...
2,257
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/text.ts
import {pick} from 'lodash' import primitivePreview from '../preview/primitivePreview' import {DEFAULT_OVERRIDEABLE_FIELDS} from './constants' const OVERRIDABLE_FIELDS = [...DEFAULT_OVERRIDEABLE_FIELDS, 'rows'] const TEXT_CORE = { name: 'text', title: 'Text', type: null, jsonType: 'string', } export const Te...
2,258
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/url.ts
import {pick} from 'lodash' import primitivePreview from '../preview/primitivePreview' import {DEFAULT_OVERRIDEABLE_FIELDS} from './constants' const OVERRIDABLE_FIELDS = [...DEFAULT_OVERRIDEABLE_FIELDS] const URL_CORE = { name: 'url', title: 'Url', type: null, jsonType: 'string', } export const UrlType = { ...
2,259
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/utils.ts
interface Config { enumerable?: boolean writable?: boolean } export function lazyGetter(target, key, getter, config: Config = {}) { Object.defineProperty(target, key, { configurable: true, enumerable: config.enumerable !== false, get() { const val = getter() Object.defineProperty(target, k...
2,260
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/blocks/block.ts
import {pick} from 'lodash' import {lazyGetter} from '../utils' import createPreviewGetter from '../../preview/createPreviewGetter' import { BLOCK_STYLES, DEFAULT_BLOCK_STYLES, DEFAULT_LINK_ANNOTATION, DEFAULT_LIST_TYPES, DEFAULT_MARKS_FIELD, DEFAULT_TEXT_FIELD, DEFAULT_DECORATORS, } from './defaults' c...
2,261
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/blocks/defaults.ts
export const DEFAULT_LINK_ANNOTATION = { type: 'object', name: 'link', options: { modal: {type: 'popover'}, }, fields: [ { name: 'href', type: 'url', title: 'Link', description: 'A valid web, email, phone, or relative link.', validation: (Rule) => Rule.uri({ ...
2,262
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/blocks/span.ts
import {pick} from 'lodash' import {lazyGetter} from '../utils' import createPreviewGetter from '../../preview/createPreviewGetter' const INHERITED_FIELDS = [ 'type', 'name', 'title', 'jsonType', 'description', 'options', 'fieldsets', 'icon', ] const SPAN_CORE = { name: 'span', title: 'Span', ty...
2,263
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/legacy/types/image/fieldDefs.ts
export const ASSET_FIELD = { name: 'asset', type: 'reference', to: [{type: 'sanity.imageAsset'}], } export const HOTSPOT_FIELD = { name: 'hotspot', type: 'sanity.imageHotspot', } export const CROP_FIELD = { name: 'crop', type: 'sanity.imageCrop', }
2,264
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/coreTypes.ts
const coreTypes = [ {name: 'array', jsonType: 'array', type: 'type'}, {name: 'block', jsonType: 'object', type: 'type'}, {name: 'boolean', jsonType: 'boolean', type: 'type'}, {name: 'datetime', jsonType: 'string', type: 'type'}, {name: 'date', jsonType: 'string', type: 'type'}, {name: 'document', jsonType: ...
2,265
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/groupProblems.ts
import type {SchemaType, SchemaTypeDefinition} from '@sanity/types' import {flatten, get} from 'lodash' import {error} from './validation/createValidationResult' import type {ProblemPath, ProblemPathPropertySegment, TypeWithProblems} from './typedefs' /** * @internal */ export function groupProblems(types: SchemaTyp...
2,266
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/helpfulError.ts
import {generateHelpUrl} from '@sanity/generate-help-url' export function createHelpfulError(message: string, slug: string): Error { return new Error(`${message}. For more info see ${generateHelpUrl(slug)}`) }
2,267
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/inspect.ts
import inspect from 'object-inspect' export default inspect
2,268
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/traverseSchema.ts
import {traverseSchema, type Visitor} from '../core/traverseSchema' import type {_FIXME_} from './typedefs' import coreTypes from './coreTypes' export function traverseSanitySchema(schemaTypes: _FIXME_[], visitor: Visitor) { return traverseSchema(schemaTypes, coreTypes as _FIXME_, visitor) }
2,269
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/typedefs.ts
import type {SchemaType} from '@sanity/types' /** * @internal */ export type _FIXME_ = any export interface TypeDef { name: string type: string title?: string description?: string options?: Record<string, any> } export interface SchemaDef { name: string types: TypeDef[] } /** * @internal */ export...
2,270
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validateSchema.ts
import {traverseSanitySchema} from './traverseSchema' import object from './validation/types/object' import documentVisitor from './validation/types/document' import reference from './validation/types/reference' import array from './validation/types/array' import slug from './validation/types/slug' import file from './...
2,271
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/createValidationResult.ts
import type {SchemaValidationResult} from '../typedefs' // Temporary solution to ensure we have a central registry over used helpIds export const HELP_IDS = { TYPE_INVALID: 'schema-type-invalid', TYPE_IS_ESM_MODULE: 'schema-type-is-esm-module', TYPE_NAME_RESERVED: 'schema-type-name-reserved', TYPE_MISSING_NAME...
2,272
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/types/array.ts
import {flatten, partition} from 'lodash' import humanizeList from 'humanize-list' import {error, HELP_IDS, warning} from '../createValidationResult' import {getDupes} from '../utils/getDupes' import {coreTypeNames} from '../../coreTypes' function isPrimitiveTypeName(typeName) { return typeName === 'string' || typeN...
2,273
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/types/block.ts
import {omit, isPlainObject} from 'lodash' import humanizeList from 'humanize-list' import {error, HELP_IDS, warning} from '../createValidationResult' import {isJSONTypeOf} from '../utils/isJSONTypeOf' import {coreTypeNames} from '../../coreTypes' const getTypeOf = (thing) => (Array.isArray(thing) ? 'array' : typeof t...
2,274
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/types/common.ts
import {validateNonObjectFieldsProp} from '../utils/validateNonObjectFieldsProp' import {validateTypeName} from '../utils/validateTypeName' import {validateDeprecatedProperties} from './deprecated' export default (typeDef, visitorContext) => { return { ...typeDef, _problems: [ ...validateTypeName(typeD...
2,275
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/types/crossDatasetReference.ts
import {flatten, isPlainObject} from 'lodash' import {error, HELP_IDS} from '../createValidationResult' import {getDupes} from '../utils/getDupes' import {SchemaValidationResult} from '../../typedefs' function normalizeToProp(typeDef) { if (Array.isArray(typeDef.to)) { return typeDef.to } return typeDef.to ?...
2,276
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/types/deprecated.ts
import {SchemaValidationResult} from '../../typedefs' import {warning} from '../createValidationResult' export function validateDeprecatedProperties(type): SchemaValidationResult[] { const warnings = [] if (type?.inputComponent) { warnings.push( warning(`The "inputComponent" property is deprecated. Use ...
2,277
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/types/document.ts
import {isPlainObject} from 'lodash' import {error} from '../createValidationResult' import object from './object' export default (typeDefinition, visitorContext) => { const typeDef = object(typeDefinition, visitorContext) const {initialValue, initialValues} = typeDef const hasInitialValue = typeof initialValue...
2,278
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/types/file.ts
import {error, HELP_IDS} from '../createValidationResult' import {validateFields, validateField} from './object' export default (typeDef, visitorContext) => { const problems = [] const fields = typeDef.fields if (fields) { problems.push(...validateFields(fields, {allowEmpty: true})) } const invalidFiel...
2,279
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/types/image.ts
import {error, warning, HELP_IDS} from '../createValidationResult' import {validateFields, validateField} from './object' const autoMeta = ['dimensions', 'hasAlpha', 'isOpaque'] export default (typeDef, visitorContext) => { const problems = [] const fields = typeDef.fields if (fields) { problems.push(...va...
2,280
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/types/object.ts
import {isPlainObject} from 'lodash' import {error, HELP_IDS, warning} from '../createValidationResult' import inspect from '../../inspect' import {validateComponent} from '../utils/validateComponent' const VALID_FIELD_RE = /^[A-Za-z]+[0-9A-Za-z_]*$/ const CONVENTIONAL_FIELD_RE = /^[A-Za-z_]+[0-9A-Za-z_]*$/ interface ...
2,281
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/types/reference.ts
import {error, HELP_IDS} from '../createValidationResult' import {flatten, isPlainObject} from 'lodash' import {getDupes} from '../utils/getDupes' import {SchemaValidationResult} from '../../typedefs' function normalizeToProp(typeDef) { if (Array.isArray(typeDef.to)) { return typeDef.to } return typeDef.to ?...
2,282
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/types/rootType.ts
import {error, HELP_IDS, warning} from '../createValidationResult' import {validateComponent} from '../utils/validateComponent' export default (typeDef, visitorContext) => { const hasName = Boolean(typeDef.name) if (!hasName && Object.keys(typeDef).length === 1) { // Short-circuit on obviously invalid types (o...
2,283
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/types/slug.ts
import {warning, HELP_IDS} from '../createValidationResult' export default (typeDef, visitorContext) => { const problems = [] if (typeDef.options && typeDef.options.slugifyFn) { problems.push( warning( 'Heads up! The "slugifyFn" option has been renamed to "slugify".', HELP_IDS.SLUG_SLUGI...
2,284
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/utils/getDupes.ts
export function getDupes(array, selector = (v) => v) { const dupes = array.reduce((acc, item) => { const key = selector(item) if (!acc[key]) { acc[key] = [] } acc[key].push(item) return acc }, {}) return Object.keys(dupes) .map((key) => (dupes[key].length > 1 ? dupes[key] : null)) ...
2,285
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/utils/isComponent.ts
const REACT_SYM_RE = /^Symbol\(react\..+\)$/ export function isComponentLike(value: any) { const type = typeof value // Note: we're not using `isValidElementType` from react-is here since it accepts too much, e.g. any strings. return ( type === 'function' || (typeof value?.$$typeof === 'symbol' && REACT_...
2,286
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/utils/isJSONTypeOf.ts
export function isJSONTypeOf(type, jsonType, visitorContext) { if ('jsonType' in type) { return type.jsonType === jsonType } const parentType = visitorContext.getType(type.type) if (!parentType) { throw new Error(`Could not resolve jsonType of ${type.name}. No parent type found`) } return isJSONType...
2,287
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/utils/validateComponent.ts
import {warning} from '../createValidationResult' import inspect from '../../inspect' import type {SchemaValidationResult} from '../../typedefs' import {isComponentLike} from './isComponent' export function validateComponent(typeDef: any): SchemaValidationResult[] { const components = 'components' in typeDef ? typeD...
2,288
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/utils/validateNonObjectFieldsProp.ts
import type {SchemaType} from '@sanity/types' import type {SchemaValidationResult} from '../../typedefs' import {error} from '../createValidationResult' export function validateNonObjectFieldsProp( typeDef: SchemaType, visitorContext, ): SchemaValidationResult[] { if (!('fields' in typeDef)) { return [] } ...
2,289
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation
petrpan-code/sanity-io/sanity/packages/@sanity/schema/src/sanity/validation/utils/validateTypeName.ts
import leven from 'leven' import humanize from 'humanize-list' import {error, HELP_IDS} from '../createValidationResult' const quote = (str) => `"${str}"` export function validateTypeName(typeName: string, visitorContext) { const possibleTypeNames = visitorContext.getTypeNames() if (!typeName) { return [ ...
2,290
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/schemas.test.ts
import {Schema} from '../../src/legacy/Schema' import rawSchemas from './fixtures/schemas' function parseSchema(schemaDef) { const schema = new Schema(schemaDef) schema.getTypeNames().forEach((typeName) => { schema.get(typeName) }) } Object.keys(rawSchemas).forEach((name) => { test(`Legacy schema ${name}...
2,291
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures/schemas/arrays.ts
export default { name: 'arrays', types: [ { name: 'tags', type: 'array', of: [ { type: 'string', }, ], }, { name: 'car', type: 'object', title: 'Car', options: {}, fields: [ { name: 'brand', title...
2,292
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures/schemas/assets.ts
export default { name: 'assets', types: [ { name: 'user', type: 'object', fields: [ {name: 'name', type: 'string', title: 'Name'}, {name: 'photo', type: 'image', title: 'Portrait'}, ], }, { name: 'archive', type: 'object', fields: [ { ...
2,293
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures/schemas/blocks.ts
export default { name: 'blocks', types: [ { name: 'blogpost', type: 'object', fields: [ { name: 'title', title: 'Title', type: 'string', required: true, }, { name: 'slug', title: 'Slug', type: 'slug',...
2,294
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures/schemas/example-blog.ts
export default { name: 'exampleBlog', types: [ { name: 'blogpost', type: 'object', options: { preview: { fields: ['title', 'image', 'imageUrl'], prepare(document) { return { title: document.title || '', } }, },...
2,295
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures/schemas/fieldsets.ts
export default { name: 'fieldsets', types: [ { name: 'blogpost', type: 'object', displayField: 'author', fieldsets: [ { name: 'headings', title: 'Headings', description: 'FIELDSET HEADINGS DESCRIPTION', options: { columns: 2, ...
2,296
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures/schemas/index.ts
import arrays from './arrays' import assets from './assets' import messyDevSchema from './messy-dev' import blocks from './blocks' import vega from './vega' import fieldsets from './fieldsets' import oma from './oma' import exampleBlog from './example-blog' import reference from './reference' import selects from './sel...
2,297
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures/schemas/messy-dev.ts
//import {atLeast, atMost, required} from './sanity/validates' //import {image, imageVersion, richText} from './sanity/types/bundled' // export default { name: 'messyDevSchema', types: [ { name: 'simple', title: 'Simple', type: 'object', fields: [ { name: 'someString'...
2,298
0
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures
petrpan-code/sanity-io/sanity/packages/@sanity/schema/test/legacy/fixtures/schemas/oma.ts
/*eslint-disable quotes,quote-props,max-len*/ export default { name: 'oma', types: [ { name: 'client', type: 'object', fields: [ { name: 'name', type: 'string', title: 'Name', required: true, }, { name: 'logo', ...
2,299