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/src/core/theme | petrpan-code/sanity-io/sanity/packages/sanity/src/core/theme/_legacy/types.ts | import {ColorTintKey} from '@sanity/color'
/** @internal */
// eslint-disable-next-line no-unused-vars
export type LegacyThemeTints = {[key in ColorTintKey]: string}
/**
* Properties that can be used to override the default theme.
*
* @public
*/
export interface LegacyThemeProps {
'--font-family-monospace': str... | 4,000 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/user-color/context.ts | import {createContext} from 'react'
import {UserColorManager} from './types'
export const UserColorManagerContext = createContext<UserColorManager | null>(null)
| 4,001 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/user-color/hooks.ts | import {useContext} from 'react'
import {empty} from 'rxjs'
import {useMemoObservable} from 'react-rx'
import {UserColorManagerContext} from './context'
import {UserColor, UserColorManager} from './types'
/** @internal */
export function useUserColorManager(): UserColorManager {
const userColorManager = useContext(U... | 4,002 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/user-color/index.ts | export * from './hooks'
export * from './manager'
export * from './provider'
export * from './types'
| 4,003 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/user-color/manager.ts | import {Observable} from 'rxjs'
import {shareReplay} from 'rxjs/operators'
import {hues, ColorHueKey, COLOR_HUES, ColorTintKey} from '@sanity/color'
import {ThemeColorSchemeKey} from '@sanity/ui'
import {UserColorHue, UserColorManager, UserColor, UserId} from './types'
/** @internal */
export interface UserColorManage... | 4,004 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/user-color/provider.tsx | import React, {useMemo} from 'react'
import {useColorScheme} from '../studio'
import {UserColorManagerContext} from './context'
import {UserColorManager} from './types'
import {createUserColorManager} from './manager'
/** @internal */
export interface UserColorManagerProviderProps {
children: React.ReactNode
manag... | 4,005 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/user-color/types.ts | import {ColorHueKey, ColorTints} from '@sanity/color'
import {Observable} from 'rxjs'
/** @internal */
export type HexColor = string
/** @internal */
export type UserColorHue = string
/** @internal */
export type UserId = string
/** @internal */
export interface UserColor {
name: ColorHueKey
background: HexColo... | 4,006 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/user-color | petrpan-code/sanity-io/sanity/packages/sanity/src/core/user-color/__tests__/userColorManager.test.ts | /* eslint-disable max-nested-callbacks */
import {omit} from 'lodash'
import {Observable, BehaviorSubject} from 'rxjs'
import {createUserColorManager, UserColorManagerOptions} from '../manager'
import {UserColor} from '../types'
const colorPreferences: Record<string, string> = {
anders: 'orange',
devin: 'blue',
... | 4,007 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/PartialExcept.ts | /** @internal */
export type PartialExcept<T, K extends keyof T> = Pick<T, K> & Partial<Omit<T, K>>
| 4,008 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/createHookFromObservableFactory.ts | import {useMemoObservable} from 'react-rx'
import {concat, Observable, of} from 'rxjs'
import {catchError, distinctUntilChanged, map, scan, switchMap} from 'rxjs/operators'
import {useUnique} from './useUnique'
/** @internal */
export type LoadingTuple<T> = [T, boolean]
/** @internal */
export type ReactHook<TArgs, T... | 4,009 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/draftUtils.test.ts | import {SanityDocument} from '@sanity/types'
import {collate, documentIdEquals, removeDupes} from './draftUtils'
test('collate()', () => {
const foo = {_type: 'foo', _id: 'foo'}
const fooDraft = {_type: 'foo', _id: 'drafts.foo'}
const barDraft = {_type: 'foo', _id: 'drafts.bar'}
const baz = {_type: 'foo', _id:... | 4,010 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/draftUtils.ts | import {SanityDocument} from '@sanity/types'
import {isNonNullable} from './isNonNullable'
/** @internal */
// nominal/opaque type hack
export type Opaque<T, K> = T & {__opaqueId__: K}
/** @internal */
export type DraftId = Opaque<string, 'draftId'>
/** @internal */
export type PublishedId = Opaque<string, 'publishe... | 4,011 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/empty.ts | /** @internal */
export const EMPTY_OBJECT: Record<string, unknown> = Object.freeze({})
/** @internal */
export const EMPTY_ARRAY: never[] = Object.freeze([]) as never[]
| 4,012 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/getPrintableType.ts | /**
* Gets the human-friendly printable type name for the given value, for instance it will yield
* `array` instead of `object`, as the native `typeof` operator would do. Can be extended to
* account for other types, such as React components, fragments, elements etc, and should thus
* not be counted as "exhaustive"... | 4,013 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/globalScope.ts | import {GlobalErrorChannel} from '../components/globalErrorHandler'
/**
* Gets the global scope instance in a given environment.
*
* The strategy is to return the most modern, and if not, the most common:
* - The `globalThis` variable is the modern approach to accessing the global scope
* - The `window` variable ... | 4,014 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/index.ts | export * from './PartialExcept'
export * from './createHookFromObservableFactory'
export * from './draftUtils'
export * from './empty'
export * from './globalScope'
export * from './isNonNullable'
export * from './isArray'
export * from './isRecord'
export * from './isString'
export * from './isTruthy'
export * from '.... | 4,015 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/isArray.ts | /** @internal */
export function isArray(value: unknown): value is unknown[] {
return Array.isArray(value)
}
| 4,016 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/isNonNullable.ts | /**
* @internal
*/
export function isNonNullable<T>(value: T): value is NonNullable<T> {
return value !== null && value !== undefined
}
| 4,017 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/isRecord.ts | /**
* @internal
*/
export function isRecord(value: unknown): value is Record<string, unknown> {
return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
}
| 4,018 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/isString.ts | /** @internal */
export function isString(value: unknown): value is string {
return typeof value === 'string'
}
| 4,019 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/isTruthy.ts | /** @internal */
export function isTruthy<T>(value: T | false): value is T {
return Boolean(value)
}
| 4,020 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/resizeObserver.ts | import {ResizeObserver as Polyfill, ResizeObserverEntry} from '@juggle/resize-observer'
import createPubSub, {Subscriber} from 'nano-pubsub'
const ResizeObserver: typeof Polyfill =
typeof document === 'object' && typeof window === 'object' && window.ResizeObserver
? window.ResizeObserver
: Polyfill
/** @int... | 4,021 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/schemaUtils.ts | import {SchemaTypeDefinition} from '@sanity/types'
const BUNDLED_DOC_TYPES = ['sanity.imageAsset', 'sanity.fileAsset']
/**
* @internal
*/
export function _isSanityDocumentTypeDefinition(
def: SchemaTypeDefinition,
): def is SchemaTypeDefinition<'document'> {
return def.type === 'document' && BUNDLED_DOC_TYPES.i... | 4,022 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/searchUtils.test.ts | import {escapeField, fieldNeedsEscape, joinPath} from './searchUtils'
test('fieldNeedsEscape', () => {
expect(fieldNeedsEscape('0foo')).toBe(true)
expect(fieldNeedsEscape('foo bar')).toBe(true)
expect(fieldNeedsEscape('0')).toBe(true)
expect(fieldNeedsEscape('foobar')).toBe(false)
expect(fieldNeedsEscape('f... | 4,023 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/searchUtils.ts | type SearchPathSegment = string | number | []
const GROQ_KEYWORDS = ['match', 'in', 'asc', 'desc', 'true', 'false', 'null']
const VALID_FIELD = /^[a-zA-Z_][a-zA-Z0-9_]*$/
/** @internal */
export const fieldNeedsEscape = (fieldName: string): boolean =>
!VALID_FIELD.test(fieldName) || GROQ_KEYWORDS.includes(fieldName... | 4,024 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/supportsTouch.ts | /** @internal */
export const supportsTouch = isTouchDevice()
function isTouchDevice() {
if (typeof window === 'undefined') return false
return (
'ontouchstart' in window ||
navigator.maxTouchPoints > 0 ||
(navigator as any).msMaxTouchPoints > 0
)
}
| 4,025 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/uncaughtErrorHandler.ts | const FONT_SANS_SERIF = `-apple-system, BlinkMacSystemFont, \\'Segoe UI\\', Roboto, \\'Helvetica Neue\\', Helvetica, Arial, system-ui, sans-serif`
const FONT_MONOSPACE = `-apple-system-ui-monospace, \\'SF Mono\\', Menlo, Monaco, Consolas, monospace`
/** @internal */
export const uncaughtErrorHandler = (): string =>
... | 4,026 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/useLoadable.ts | import {useMemoObservable} from 'react-rx'
import {Observable, of, OperatorFunction} from 'rxjs'
import {catchError, map} from 'rxjs/operators'
/** @internal */
export type LoadableState<T> = LoadingState | LoadedState<T> | ErrorState
/** @internal */
export interface LoadingState {
value: undefined
error: null
... | 4,027 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/useThrottledCallback.ts | import {throttle} from 'lodash'
import type {ThrottleSettings} from 'lodash'
import {useMemo} from 'react'
/**
* @internal
*
* @example
* ```tsx
* // First create a callback using React’s `useCallback` hook
* const myCallback = useCallback(() => {
* // this is not throttled
* }, [])
*
* // Then make a thro... | 4,028 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/useUnique.ts | import {isEqual} from 'lodash'
import {useRef} from 'react'
/**
* This React hook should be considered an escape hatch – to make sure that a value is the same
* on every render. SHOULD NOT BE USED IN MOST CASES.
* @deprecated please use `useMemo` and `useCallback` strategies instead to make deps stable, this hook r... | 4,029 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/userHasRole.test.ts | import type {ConditionalPropertyCallbackContext, CurrentUser} from '@sanity/types'
import {userHasRole} from './userHasRole'
const roleLessUser: CurrentUser = {
id: 'pabc123',
email: 'some@user.com',
name: 'Some User',
role: '',
roles: [],
}
const conditionalContextUser: ConditionalPropertyCallbackContext['... | 4,030 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/userHasRole.ts | import type {CurrentUser} from '@sanity/types'
/**
* Checks whether or not the given user has the role with the given ID
*
* @param user - The user to check (currently only the current user is supported)
* If `null` is passed, this function always returns `false`.
* @param roleId - The ID of the role to check f... | 4,031 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util | petrpan-code/sanity-io/sanity/packages/sanity/src/core/util/__tests__/createHookFromObservableFactory.test.tsx | import React, {Profiler, memo, useDeferredValue} from 'react'
import {render, renderHook, waitFor} from '@testing-library/react'
import * as Rx from 'rxjs'
import {createHookFromObservableFactory} from '../createHookFromObservableFactory'
const tick = () => new Promise((resolve) => setTimeout(resolve, 0))
describe('c... | 4,032 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/Rule.ts | import type {
CustomValidator,
FieldRules,
Rule as IRule,
RuleClass,
RuleSpec,
RuleSpecConstraint,
RuleTypeConstraint,
SchemaType,
ValidationContext,
ValidationMarker,
Validator,
} from '@sanity/types'
import {cloneDeep, get} from 'lodash'
import {ValidationError as ValidationErrorClass} from './V... | 4,033 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/ValidationError.ts | import type {
Path,
ValidationMarker,
ValidationError as IValidationError,
ValidationErrorOptions,
ValidationErrorClass,
} from '@sanity/types'
// Follows the same pattern as Rule and RuleClass. @see Rule
export const ValidationError: ValidationErrorClass = class ValidationError
implements IValidationError... | 4,034 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/index.ts | export {Rule} from './Rule'
export {validateDocument} from './validateDocument'
export {inferFromSchema} from './inferFromSchema'
export {inferFromSchemaType} from './inferFromSchemaType'
export {validateDocumentObservable} from './validateDocument'
| 4,035 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/inferFromSchema.ts | import type {Schema} from '@sanity/types'
import {inferFromSchemaType} from './inferFromSchemaType'
// Note: Mutates schema. Refactor when @sanity/schema supports middlewares
export function inferFromSchema(schema: Schema): Schema {
const typeNames = schema.getTypeNames()
typeNames.forEach((typeName) => {
con... | 4,036 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/inferFromSchemaType.ts | import type {Schema, SchemaType} from '@sanity/types'
import {normalizeValidationRules} from './util/normalizeValidationRules'
// NOTE: this overload is for TS API compatibility with a previous implementation
export function inferFromSchemaType(
typeDef: SchemaType,
// these are intentionally unused
_schema: Sch... | 4,037 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/validateDocument.ts | import {
isKeyedObject,
isTypedObject,
type SanityDocument,
type Schema,
type SchemaType,
type ValidationContext,
type ValidationMarker,
} from '@sanity/types'
import {concat, defer, lastValueFrom, merge, Observable, of} from 'rxjs'
import {catchError, map, mergeAll, mergeMap, toArray} from 'rxjs/operator... | 4,038 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/util/convertToValidationMarker.ts | import type {ValidationMarker, ValidationError, ValidationContext} from '@sanity/types'
import {ValidationError as ValidationErrorClass} from '../ValidationError'
import {pathToString} from '../util/pathToString'
type ValidationErrorLike = Pick<ValidationError, 'message'> & Partial<ValidationError>
export function is... | 4,039 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/util/deepEquals.ts | /**
* Modified version of fast-deep-equal (https://github.com/epoberezkin/fast-deep-equal)
* MIT-licensed, copyright (c) 2017 Evgeny Poberezkin
**/
// NOTE: when converting to typescript, some of the checks were inlined (vs
// having them in a variable) because the type predicate type narrowing only
// works when t... | 4,040 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/util/escapeRegex.ts | /* eslint-disable no-useless-escape */
export function escapeRegex(string: string): string {
// Escape ^$.*+-?=!:|\/()[]{},
return string.replace(/[\^\$\.\*\+\-\?\=\!\:\|\\\/\(\)\[\]\{\}\,]/g, '\\$&')
}
| 4,041 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/util/normalizeValidationRules.ts | import type {SchemaType, Rule, RuleTypeConstraint} from '@sanity/types'
import {Rule as RuleClass} from '../Rule'
import {slugValidator} from '../validators/slugValidator'
const ruleConstraintTypes: {[P in Lowercase<RuleTypeConstraint>]: true} = {
array: true,
boolean: true,
date: true,
number: true,
object:... | 4,042 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/util/pathToString.ts | import {type Path, isKeyedObject} from '@sanity/types'
export function pathToString(path: Path | undefined = []): string {
return path.reduce<string>((target, segment, i) => {
const segmentType = typeof segment
if (segmentType === 'number') {
return `${target}[${segment}]`
}
if (segmentType ==... | 4,043 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/util/requestIdleCallback.ts | /**
* Simple requestIdleCallback polyfill
* Can be removed when all browsers support requestIdleCallback: https://caniuse.com/requestidlecallback
* @param callback -
* @param options -
*/
const requestIdleCallbackShim: typeof window.requestIdleCallback = function requestIdleCallbackShim(
callback,
options?,
):... | 4,044 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/util/typeString.ts | // this file was adapted from a previous dependency `type-of-is`
// https://github.com/stephenhandley/type-of-is/blob/7138a7e79f5af7c286bf8123f60843a91aaebf38/index.js
const _toString = {}.toString
const builtIns = [Object, Function, Array, String, Boolean, Number, Date, RegExp, Error]
function isBuiltIn(_constructor... | 4,045 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/validators/arrayValidator.ts | import type {Path, PathSegment, Validators} from '@sanity/types'
import {deepEquals} from '../util/deepEquals'
import {ValidationError as ValidationErrorClass} from '../ValidationError'
import {genericValidators} from './genericValidator'
export const arrayValidators: Validators = {
...genericValidators,
min: (mi... | 4,046 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/validators/booleanValidator.ts | import type {Validators} from '@sanity/types'
import {genericValidators} from './genericValidator'
export const booleanValidators: Validators = {
...genericValidators,
presence: (flag, value, message) => {
if (flag === 'required' && typeof value !== 'boolean') {
return message || 'Required'
}
r... | 4,047 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/validators/dateValidator.ts | import {Validators} from '@sanity/types'
import formatDate from 'date-fns/format'
import {genericValidators} from './genericValidator'
function isRecord(obj: unknown): obj is Record<string, unknown> {
return typeof obj === 'object' && obj !== null && !Array.isArray(obj)
}
const isoDate =
/^(?:[-+]\d{2})?(?:\d{4}(... | 4,048 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/validators/genericValidator.ts | import type {ValidationMarker, Validators} from '@sanity/types'
import {typeString} from '../util/typeString'
import {deepEquals} from '../util/deepEquals'
import {pathToString} from '../util/pathToString'
import {ValidationError as ValidationErrorClass} from '../ValidationError'
const SLOW_VALIDATOR_TIMEOUT = 5000
c... | 4,049 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/validators/numberValidator.ts | import {Validators} from '@sanity/types'
import {genericValidators} from './genericValidator'
const precisionRx = /(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/
export const numberValidators: Validators = {
...genericValidators,
integer: (_unused, value, message) => {
if (!Number.isInteger(value)) {
return message... | 4,050 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/validators/objectValidator.ts | import {type Validators, isReference} from '@sanity/types'
import {genericValidators} from './genericValidator'
const metaKeys = ['_key', '_type', '_weak']
export const objectValidators: Validators = {
...genericValidators,
presence: (expected, value, message) => {
if (expected !== 'required') {
return... | 4,051 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/validators/slugValidator.ts | import {memoize} from 'lodash'
import {
type CustomValidator,
isKeyedObject,
type Path,
type SlugIsUniqueValidator,
type SlugParent,
type SlugSchemaType,
type SlugValidationContext,
} from '@sanity/types'
const memoizedWarnOnArraySlug = memoize(warnOnArraySlug)
function getDocumentIds(id: string) {
co... | 4,052 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation | petrpan-code/sanity-io/sanity/packages/sanity/src/core/validation/validators/stringValidator.ts | import type {Validators} from '@sanity/types'
import {genericValidators} from './genericValidator'
const DUMMY_ORIGIN = 'http://sanity'
const isRelativeUrl = (url: string) => /^\.*\//.test(url)
const emailRegex =
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-... | 4,053 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/DeskToolContext.ts | import {createContext} from 'react'
import {DeskToolContextValue} from './types'
export const DeskToolContext = createContext<DeskToolContextValue | null>(null)
| 4,054 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/DeskToolProvider.tsx | import React, {useMemo, useState} from 'react'
import {DeskToolContext} from './DeskToolContext'
import {createStructureBuilder, DefaultDocumentNodeResolver} from './structureBuilder'
import {DeskToolContextValue, StructureResolver, UnresolvedPaneNode} from './types'
import {useConfigContextFromSource, useDocumentStore... | 4,055 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/constants.ts | /**
* @internal
*/
export const _DEBUG = false
export const EMPTY_PARAMS = {}
export const LOADING_PANE = Symbol('LOADING_PANE')
export const DOCUMENT_PANEL_PORTAL_ELEMENT = 'documentPanelPortalElement'
| 4,056 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/deskTool.ts | import {MasterDetailIcon} from '@sanity/icons'
import {lazy} from 'react'
import {
DeleteAction,
DiscardChangesAction,
DuplicateAction,
HistoryRestoreAction,
PublishAction,
UnpublishAction,
} from './documentActions'
import {LiveEditBadge} from './documentBadges'
import {getIntentState} from './getIntentSta... | 4,057 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/getIntentState.ts | import {uuid} from '@sanity/uuid'
import {PaneNode, RouterPanes} from './types'
import {EMPTY_PARAMS, LOADING_PANE} from './constants'
const state: {
activePanes: Array<PaneNode | typeof LOADING_PANE>
} = {activePanes: []}
export function setActivePanes(panes: Array<PaneNode | typeof LOADING_PANE>): void {
state.... | 4,058 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/index.ts | export * from './deskTool'
export {DocumentInspectorHeader} from './panes/document/documentInspector'
// Export `DocumentPaneProvider`
export {type DocumentPaneProviderProps} from './panes/document/types'
export * from './panes/document/useDocumentPane'
export * from './types'
export * from './DeskToolProvider'
e... | 4,059 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/menuNodes.ts | /* eslint-disable camelcase */
import {negate} from 'lodash'
import {_PaneMenuGroup, _PaneMenuItem, _PaneMenuNode} from './components/pane/types'
import {PaneMenuItem, PaneMenuItemGroup, DocumentFieldMenuActionNode} from './types'
export function isMenuNodeButton(node: _PaneMenuNode): node is _PaneMenuItem | _PaneMen... | 4,060 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/router.ts | import {omit} from 'lodash'
import {RouterPanes, RouterPaneGroup, RouterPaneSibling} from './types'
import {route, decodeJsonParams, encodeJsonParams} from 'sanity/router'
const EMPTY_PARAMS = {}
/**
* @internal
*/
export function legacyEditParamsToState(params: string): Record<string, unknown> {
try {
return... | 4,061 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/types.ts | import {SchemaType} from '@sanity/types'
import {Observable} from 'rxjs'
import {
DefaultDocumentNodeResolver,
MenuItem as DeskToolMenuItem,
Intent,
StructureBuilder,
StructureContext,
UserComponent,
View,
} from './structureBuilder'
import {
GeneralPreviewLayoutKey,
ConfigContext,
InitialValueTempl... | 4,062 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/useDeskTool.ts | import {useContext} from 'react'
import {DeskToolContext} from './DeskToolContext'
import {DeskToolContextValue} from './types'
/** @internal */
export function useDeskTool(): DeskToolContextValue {
const deskTool = useContext(DeskToolContext)
if (!deskTool) throw new Error(`DeskTool: missing context value`)
r... | 4,063 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/useDeskToolSetting.ts | import {useCallback, useEffect, useMemo, useState} from 'react'
import {useSettingsStore} from 'sanity'
/**
* @internal
*/
export function useDeskToolSetting<ValueType>(
namespace: string | null,
key: string,
defaultValue?: ValueType,
): [ValueType | undefined, (_value: ValueType) => void] {
const settingsSt... | 4,064 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/__tests__/router.test.ts | import {toState, toPath} from '../router'
describe('toPath', () => {
it('takes in multiple pane groups and serializes them to a panes path for the state router', () => {
const path = toPath([[{id: 'level1'}], [{id: 'level2'}]])
expect(path).toBe('level1;level2')
})
it('takes in multiple panes groups wit... | 4,065 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/__workshop__/DocumentStateStory.tsx | import {Box, Code, Stack, Button, Dialog} from '@sanity/ui'
import React, {useMemo, useState, useCallback, useEffect} from 'react'
import {DeskToolProvider} from '../DeskToolProvider'
import {DocumentPaneProvider} from '../panes'
import {DocumentPaneNode} from '../types'
import {
DocumentActionComponent,
DocumentAc... | 4,066 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/__workshop__/ResolvePanesStory.tsx | /* eslint-disable react/no-array-index-key */
import {Box, Card, Code, Flex, Radio, Stack, Text} from '@sanity/ui'
import React, {useCallback, useState} from 'react'
import {LOADING_PANE} from '../constants'
import {DeskToolProvider} from '../DeskToolProvider'
import {useResolvedPanes} from '../structureResolvers'
imp... | 4,067 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/__workshop__/index.ts | import {defineScope} from '@sanity/ui-workshop'
import {lazy} from 'react'
export default defineScope({
name: 'desk/core',
title: 'Core',
stories: [
{
name: 'resolve-panes',
title: 'Resolve panes',
component: lazy(() => import('./ResolvePanesStory')),
},
{
name: 'document-stat... | 4,068 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/index.ts | export * from './plugin'
export * from './src'
| 4,069 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin/index.ts | import {commentsInspector} from './inspector'
import {CommentField} from './field'
import {CommentsLayout} from './layout'
import {definePlugin} from 'sanity'
export const comments = definePlugin({
name: 'sanity/desk/comments',
document: {
inspectors: [commentsInspector],
},
form: {
components: {
... | 4,070 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin/field/CommentField.tsx | import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'
import {uuid} from '@sanity/uuid'
import * as PathUtils from '@sanity/util/paths'
import {PortableTextBlock} from '@sanity/types'
import {Stack, useBoundaryElement} from '@sanity/ui'
import styled, {css} from 'styled-components'
import scrol... | 4,071 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin/field/CommentFieldButton.tsx | import React, {useCallback, useMemo, useRef, useState} from 'react'
import {
Box,
Button,
Flex,
Popover,
Stack,
Text,
Tooltip,
TooltipProps,
useClickOutside,
} from '@sanity/ui'
import styled from 'styled-components'
import {
CommentMessage,
CommentInput,
CommentInputHandle,
hasCommentMessageV... | 4,072 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin/field/index.ts | export * from './CommentField'
| 4,073 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin/inspector/CommentsInspector.tsx | import {Flex, Layer, useClickOutside, useLayer, useToast} from '@sanity/ui'
import React, {Fragment, useCallback, useEffect, useMemo, useRef, useState} from 'react'
import * as PathUtils from '@sanity/util/paths'
import styled from 'styled-components'
import {usePaneRouter} from '../../../components'
import {EMPTY_PARA... | 4,074 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin/inspector/CommentsInspectorFeedbackFooter.tsx | import {LaunchIcon} from '@sanity/icons'
import {Card, Text} from '@sanity/ui'
import React from 'react'
import styled from 'styled-components'
const FEEDBACK_FORM_LINK = 'https://snty.link/comments-beta-feedback'
const Span = styled.span`
margin-right: 0.2em;
`
const Link = styled.a`
white-space: nowrap;
`
con... | 4,075 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin/inspector/CommentsInspectorHeader.tsx | import {CheckmarkIcon, ChevronDownIcon, DoubleChevronRightIcon} from '@sanity/icons'
import {Button, Card, Flex, Menu, MenuButton, MenuItem, Text} from '@sanity/ui'
import {startCase} from 'lodash'
import React, {forwardRef, useCallback} from 'react'
import styled from 'styled-components'
import {CommentStatus} from '.... | 4,076 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin/inspector/index.ts | import {CommentIcon} from '@sanity/icons'
import {COMMENTS_INSPECTOR_NAME} from '../../../panes/document/constants'
import {useCommentsEnabled} from '../../src'
import {CommentsInspector} from './CommentsInspector'
import {
DocumentInspectorMenuItem,
DocumentInspectorUseMenuItemProps,
defineDocumentInspector,
} f... | 4,077 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin/layout/CommentsLayout.tsx | import React from 'react'
import {CommentsOnboardingProvider, CommentsSetupProvider} from '../../src'
import {LayoutProps} from 'sanity'
export function CommentsLayout(props: LayoutProps) {
return (
<CommentsSetupProvider>
<CommentsOnboardingProvider>{props.renderDefault(props)}</CommentsOnboardingProvider... | 4,078 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/plugin/layout/index.ts | export * from './CommentsLayout'
| 4,079 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/helpers.ts | import {useMemo, useRef} from 'react'
import {isEqual} from 'lodash'
import {CommentMessage} from './types'
import {isPortableTextSpan, isPortableTextTextBlock} from 'sanity'
export function useCommentHasChanged(message: CommentMessage): boolean {
const prevMessage = useRef<CommentMessage>(message)
return useMemo... | 4,080 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/index.ts | export * from './components'
export * from './context'
export * from './helpers'
export * from './hooks'
export * from './store'
export * from './types'
export * from './utils'
| 4,081 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/types.ts | import {PortableTextBlock, User} from '@sanity/types'
/**
* @beta
* @hidden
*/
export interface Loadable<T> {
data: T | null
error: Error | null
loading: boolean
}
/**
* @beta
* @hidden
*/
export interface CommentOperations {
create: (comment: CommentCreatePayload) => Promise<void>
edit: (id: string, ... | 4,082 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/__tests__/buildCommentBreadcrumbs.test.ts | import {Schema} from '@sanity/schema'
import {CurrentUser, defineField} from '@sanity/types'
import {buildCommentBreadcrumbs} from '../utils'
const CURRENT_USER: CurrentUser = {
email: '',
id: '',
name: '',
role: '',
roles: [],
profileImage: '',
provider: '',
}
const stringWithTitleField = defineField({... | 4,083 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/__workshop__/CommentBreadcrumbsStory.tsx | import React from 'react'
import {Flex} from '@sanity/ui'
import {useNumber} from '@sanity/ui-workshop'
import {CommentBreadcrumbs} from '../components'
export default function CommentBreadcrumbsStory() {
const maxLength = useNumber('Max length', 3, 'Props') || 3
return (
<Flex align="center" height="fill" ju... | 4,084 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/__workshop__/CommentDeleteDialogStory.tsx | import React from 'react'
import {useAction, useBoolean} from '@sanity/ui-workshop'
import {CommentDeleteDialog} from '../components'
export default function CommentDeleteDialogStory() {
const isParent = useBoolean('Is parent', false, 'Props') || false
const error = useBoolean('Error', false, 'Props') || false
c... | 4,085 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/__workshop__/CommentInputStory.tsx | import React, {useState} from 'react'
import {Card, Container, Flex} from '@sanity/ui'
import {PortableTextBlock} from '@sanity/types'
import {useBoolean} from '@sanity/ui-workshop'
import {CommentInput} from '../components'
import {CommentMessageSerializer} from '../components/pte'
import {useCurrentUser} from 'sanity... | 4,086 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/__workshop__/CommentsListStory.tsx | import React, {useCallback, useMemo, useState} from 'react'
import {useBoolean, useSelect} from '@sanity/ui-workshop'
import {Schema} from '@sanity/schema'
import {uuid} from '@sanity/uuid'
import {Container, Flex} from '@sanity/ui'
import {CommentsList} from '../components'
import {CommentDocument, CommentCreatePayloa... | 4,087 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/__workshop__/CommentsProviderStory.tsx | /* eslint-disable react/jsx-handler-names */
import React from 'react'
import {useString} from '@sanity/ui-workshop'
import {CommentsList} from '../components'
import {CommentsProvider, CommentsSetupProvider} from '../context'
import {useComments} from '../hooks'
import {useCurrentUser} from 'sanity'
const noop = () =... | 4,088 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/__workshop__/MentionOptionsHookStory.tsx | import React from 'react'
import {Card, Code} from '@sanity/ui'
import {useMentionOptions} from '../hooks'
const DOCUMENT = {
_id: '1e1744ab-43d5-4fff-8a2a-28c58bf0434a',
_type: 'author',
_rev: '1',
_createdAt: '2021-05-04T14:54:37Z',
_updatedAt: '2021-05-04T14:54:37Z',
}
export default function MentionOpti... | 4,089 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/__workshop__/MentionsMenuStory.tsx | import {Container, Flex} from '@sanity/ui'
import React from 'react'
import {MentionsMenu} from '../components/mentions'
import {useMentionOptions} from '../hooks'
const DOC = {
documentValue: {
_id: 'xyz123',
_type: 'author',
_rev: '1',
_createdAt: '2021-05-04T14:54:37Z',
_updatedAt: '2021-05-04... | 4,090 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/__workshop__/index.ts | import {defineScope} from '@sanity/ui-workshop'
import {lazy} from 'react'
export default defineScope({
name: 'desk/comments',
title: 'comments',
stories: [
{
name: 'comments-provider',
title: 'CommentsProvider',
component: lazy(() => import('./CommentsProviderStory')),
},
{
n... | 4,091 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/components/CommentBreadcrumbs.tsx | import {ChevronRightIcon} from '@sanity/icons'
import {Box, Flex, Stack, Text, Tooltip, TooltipProps} from '@sanity/ui'
import React, {Fragment, useMemo} from 'react'
export interface CommentBreadcrumbsProps {
titlePath: string[]
maxLength: number
}
type Item = string | string[]
const TOOLTIP_DELAY: TooltipProps... | 4,092 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/components/CommentDeleteDialog.tsx | import {Dialog, Grid, Button, Stack, Text} from '@sanity/ui'
import React, {useCallback} from 'react'
import {TextWithTone} from 'sanity'
const DIALOG_COPY: Record<
'thread' | 'comment',
{title: string; body: string; confirmButtonText: string}
> = {
thread: {
title: 'Delete this comment thread?',
body: '... | 4,093 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/components/TextTooltip.tsx | import React from 'react'
import {Flex, Text, Tooltip, TooltipProps} from '@sanity/ui'
import styled from 'styled-components'
const TOOLTIP_DELAY: TooltipProps['delay'] = {open: 500}
const ContextText = styled(Text)`
min-width: max-content;
`
interface TextTooltipProps {
children: React.ReactNode
text?: string... | 4,094 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/components/constants.ts | import {FlexProps} from '@sanity/ui'
export const FLEX_GAP: FlexProps['gap'] = 3
| 4,095 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/components/index.ts | export * from './pte'
export * from './list'
export * from './CommentDeleteDialog'
export * from './TextTooltip'
export * from './CommentBreadcrumbs'
export * from './icons'
export * from './onboarding'
| 4,096 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/components | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/components/avatars/CommentsAvatar.tsx | import React, {useMemo} from 'react'
import styled from 'styled-components'
import {Avatar, AvatarProps} from '@sanity/ui'
import {User} from '@sanity/types'
const StyledAvatar = styled(Avatar)`
svg > ellipse {
stroke: transparent;
}
`
const SYMBOLS = /[^\p{Alpha}\p{White_Space}]/gu
const WHITESPACE = /\p{Whi... | 4,097 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/components | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/components/avatars/SpacerAvatar.tsx | import React from 'react'
export const AVATAR_HEIGHT = 25
const INLINE_STYLE: React.CSSProperties = {
minWidth: AVATAR_HEIGHT,
}
/**
* This component is used to as a spacer in situations where we want to align
* components without avatars with components that have avatars.
*/
export function SpacerAvatar() {
... | 4,098 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/components | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/comments/src/components/avatars/index.ts | export * from './CommentsAvatar'
export * from './SpacerAvatar'
| 4,099 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.