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/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder/types.ts | import type {SanityDocument, SchemaType, SortOrdering} from '@sanity/types'
import type {ComponentBuilder, ComponentInput} from './Component'
import type {DocumentBuilder, PartialDocumentNode} from './Document'
import type {DocumentListInput, DocumentListBuilder} from './DocumentList'
import type {DocumentListItemInput... | 4,400 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder/util/getExtendedProjection.ts | import {SchemaType, SortOrderingItem} from '@sanity/types'
const IMPLICIT_FIELDS = ['_id', '_type', '_createdAt', '_updatedAt', '_rev']
// Takes a path array and a schema type and builds a GROQ join every time it enters a reference field
function joinReferences(schemaType: SchemaType, path: string[]): string {
cons... | 4,401 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder/util/getStructureNodeId.ts | import {camelCase} from 'lodash'
import getSlug from 'speakingurl'
import {disallowedPattern} from './validateId'
export function getStructureNodeId(title: string, id?: string): string {
if (id) {
return id
}
const camelCased = camelCase(title)
return disallowedPattern.test(camelCased) ? camelCase(getSlu... | 4,402 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder/util/resolveTypeForDocument.ts | import type {SanityClient} from '@sanity/client'
import {
DEFAULT_STUDIO_CLIENT_OPTIONS,
getDraftId,
getPublishedId,
type SourceClientOptions,
} from 'sanity'
export async function resolveTypeForDocument(
getClient: (options: SourceClientOptions) => SanityClient,
id: string,
): Promise<string | undefined> ... | 4,403 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder/util/validateId.ts | import {SerializeError} from '../SerializeError'
import {SerializePath} from '../StructureNodes'
export const disallowedPattern = /([^A-Za-z0-9-_.])/
export function validateId(
id: string,
parentPath: SerializePath,
pathSegment: string | number | undefined,
): string {
if (typeof id !== 'string') {
throw... | 4,404 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder/util | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder/util/__tests__/getStructureNodeId.test.ts | import {getStructureNodeId} from '../getStructureNodeId'
describe('getStructureNodeId', () => {
it('should return the id if provided', () => {
expect(getStructureNodeId('foo', 'bar')).toBe('bar')
})
it('should return a camelCased id if the title contains space', () => {
expect(getStructureNodeId('foo ba... | 4,405 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder/views/ComponentView.ts | import {SerializeOptions} from '../StructureNodes'
import {SerializeError, HELP_URL} from '../SerializeError'
import type {UserViewComponent} from '../types'
import {BaseView, GenericViewBuilder} from './View'
import {isRecord} from 'sanity'
/**
* Interface for component views.
*
* @public */
export interface Compo... | 4,406 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder/views/FormView.ts | import {SerializeOptions} from '../StructureNodes'
import {BaseView, GenericViewBuilder} from './View'
/**
* Interface for form views.
*
* @public */
export interface FormView extends BaseView {
type: 'form'
}
/**
* Class for building a form view.
*
* @public */
export class FormViewBuilder extends GenericVie... | 4,407 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder/views/View.ts | import {kebabCase} from 'lodash'
import {Serializable, SerializeOptions, SerializePath} from '../StructureNodes'
import {HELP_URL, SerializeError} from '../SerializeError'
import {validateId} from '../util/validateId'
import {View} from '../types'
import {ComponentViewBuilder} from './ComponentView'
import {FormViewBui... | 4,408 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureBuilder/views/index.ts | import type {UserViewComponent} from '../types'
import {ComponentView, ComponentViewBuilder} from './ComponentView'
import {FormView, FormViewBuilder} from './FormView'
export * from './FormView'
export * from './ComponentView'
export * from './View'
/** @internal */
export const form = (spec?: Partial<FormView>): Fo... | 4,409 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers/PaneResolutionError.ts | import {RouterPaneSiblingContext} from '../types'
export interface PaneResolutionErrorOptions {
message: string
context?: RouterPaneSiblingContext
helpId?: string
cause?: Error
}
/**
* An error thrown during pane resolving. This error is meant to be bubbled up
* through react and handled in an error boundar... | 4,410 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers/assignId.ts | import {nanoid} from 'nanoid'
// `WeakMap`s require the first type param to extend `object`
// eslint-disable-next-line @typescript-eslint/ban-types
const randomIdCache = new WeakMap<object, string>()
/**
* given an object, this function randomly generates an ID and returns it. this
* result is then saved in a Weak... | 4,411 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers/createPaneResolver.ts | import {from, isObservable, Observable, of as observableOf, Subscribable} from 'rxjs'
import {publishReplay, refCount, switchMap} from 'rxjs/operators'
import {PaneNode, RouterPaneSiblingContext, UnresolvedPaneNode} from '../types'
import {PaneResolutionError} from './PaneResolutionError'
import {isRecord} from 'sani... | 4,412 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers/createResolvedPaneNodeStream.ts | import {generateHelpUrl} from '@sanity/generate-help-url'
import {isEqual} from 'lodash'
import {Observable, NEVER, of as observableOf, concat} from 'rxjs'
import {switchMap, map, scan, distinctUntilChanged, pairwise, startWith} from 'rxjs/operators'
import {
DocumentPaneNode,
PaneNode,
RouterPaneSiblingContext,
... | 4,413 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers/index.ts | export * from './PaneResolutionError'
export * from './resolveIntent'
export * from './useResolvedPanes'
| 4,414 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers/leven.ts | /* eslint-disable no-nested-ternary */
/* eslint-disable no-bitwise */
const array: number[] = []
const characterCodeCache: number[] = []
export function leven(a: string, b: string): number {
let first = a
let second = b
if (first === second) {
return 0
}
const swap = first
// Swapping the strings i... | 4,415 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers/memoBind.ts | /* eslint-disable @typescript-eslint/ban-types */
// `WeakMap`s require the first type param to extend `object`
const bindCache = new WeakMap<object, Map<string, Function>>()
/**
* An alternative to `obj.method.bind(obj)` that utilizes a weakmap to return
* the same memory reference for sequent binds.
*/
export fu... | 4,416 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers/resolveIntent.ts | import {omit} from 'lodash'
import {firstValueFrom, Observable} from 'rxjs'
import {PaneNode, RouterPanes, RouterPaneSiblingContext, UnresolvedPaneNode} from '../types'
import {StructureContext} from '../structureBuilder'
import {assignId} from './assignId'
import {memoBind} from './memoBind'
import {createPaneResolver... | 4,417 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers/useResolvedPanes.ts | import {useEffect, useMemo, useState} from 'react'
import {ReplaySubject} from 'rxjs'
import {map} from 'rxjs/operators'
import {LOADING_PANE} from '../constants'
import {RouterPanes, PaneNode, RouterPaneGroup} from '../types'
import {useDeskTool} from '../useDeskTool'
import {createResolvedPaneNodeStream} from './crea... | 4,418 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers/validateStructure.ts | import {SerializeError} from '../structureBuilder'
import {UnresolvedPaneNode} from '../types'
import {leven} from './leven'
import {isRecord} from 'sanity'
// TODO: this is not wired up
export function validateStructure(structure: any): UnresolvedPaneNode {
if (!structure) {
let val = 'null'
if (structure ... | 4,419 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers/__tests__/assignId.test.ts | import {assignId} from '../assignId'
describe('assignId', () => {
it('takes in an object and assigns it an ID, on subsequent requests, the same ID will be returned', () => {
const foo = {}
const bar = {}
const baz = {}
const fooAlias = foo
expect(assignId(foo)).toBe(assignId(foo))
expect(as... | 4,420 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers/__tests__/memoBind.test.ts | import {memoBind} from '../memoBind'
describe('memoBind', () => {
it('takes in an object and a method key and binds the object to the `this` value of the method', () => {
class ExampleClass {
data = 'example'
aPrototype() {
return this.data
}
}
const instance = new ExampleClas... | 4,421 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers | petrpan-code/sanity-io/sanity/packages/sanity/src/desk/structureResolvers/__tests__/resolveIntent.test.ts | import {PaneNode, UnresolvedPaneNode} from '../../types'
import {createStructureBuilder, SerializeError} from '../../structureBuilder'
import {resolveIntent} from '../resolveIntent'
import {PaneResolutionError} from '../PaneResolutionError'
import {getMockSource} from '../../../../test/testUtils/getMockWorkspaceFromCon... | 4,422 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/IntentLink.tsx | import React, {ForwardedRef, forwardRef} from 'react'
import {IntentParameters} from './types'
import {useIntentLink} from './useIntentLink'
/**
* Props for the {@link IntentLink} component.
*
* @public
*/
export interface IntentLinkProps {
/**
* The name of the intent.
*/
intent: string
/**
* The ... | 4,423 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/Link.tsx | import React, {forwardRef} from 'react'
import {useLink} from './useLink'
/**
* Props for the {@link Link} component.
*
* @public
*/
export interface LinkProps {
/**
* Whether to replace the current URL in the browser history instead of adding a new entry.
*/
replace?: boolean
}
/**
* A component that ... | 4,424 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/README.md | # `sanity/router`
## Features
Based on a routing schema:
- A state object can be derived from the current pathname
- A state object can be used to generate a path name
## API Usage
Define the routes for your application and how they should map to application state
```js
import {route} from 'sanity/router'
const ... | 4,425 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/RouteScope.tsx | /* eslint-disable camelcase */
import React, {useCallback, useMemo, useRef} from 'react'
import {RouterContext} from './RouterContext'
import {RouterContextValue, RouterState} from './types'
import {useRouter} from './useRouter'
function addScope(
routerState: Record<string, any>,
scope: string,
scopedState: Re... | 4,426 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/RouterContext.ts | import React from 'react'
import {RouterContextValue} from './types'
/**
* @internal
*/
export const RouterContext = React.createContext<RouterContextValue | null>(null)
| 4,427 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/RouterProvider.tsx | import React, {useCallback, useMemo} from 'react'
import {RouterContext} from './RouterContext'
import {IntentParameters, RouterContextValue, NavigateOptions, Router, RouterState} from './types'
/**
* The props for the {@link RouterProvider} component.
*
* @public
*/
export interface RouterProviderProps {
/**
... | 4,428 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/StateLink.tsx | import React, {forwardRef} from 'react'
import {useStateLink} from './useStateLink'
/**
* Props for the {@link StateLink} component.
*
* @public
*/
export interface StateLinkProps {
/**
* Whether to replace the current history entry instead of adding a new one.
*/
replace?: boolean
/**
* The state t... | 4,429 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/_findMatchingRoutes.ts | import {difference, intersection, isPlainObject, pick} from 'lodash'
import {
InternalSearchParam,
MatchError,
MatchOk,
MatchResult,
RouterNode,
RouterState,
} from './types'
import {arrayify} from './utils/arrayify'
function isRecord(value: unknown): value is Record<string, unknown> {
return isPlainObje... | 4,430 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/_parseRoute.ts | import {Route, RouteSegment} from './types'
const VALID_PARAM_SEGMENT = /^[a-zA-Z0-9_-]+$/
function createSegment(segment: string): RouteSegment | null {
if (!segment) {
return null
}
if (segment.startsWith(':')) {
const paramName = segment.substring(1)
if (!VALID_PARAM_SEGMENT.test(paramName)) {
... | 4,431 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/_resolvePathFromState.ts | import {_findMatchingRoutes} from './_findMatchingRoutes'
import {InternalSearchParam, MatchOk, RouterNode, RouterState} from './types'
import {debug} from './utils/debug'
import {encodeURIComponentExcept} from './encodeURIComponentExcept'
/** @internal */
export function _resolvePathFromState(node: RouterNode, _state... | 4,432 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/_resolveStateFromPath.ts | import {partition} from 'lodash'
import {InternalSearchParam, RouterNode, RouterState, SearchParam} from './types'
import {debug} from './utils/debug'
import {arrayify} from './utils/arrayify'
import {parseScopedParams} from './utils/parseScopedParams'
function matchPath(
node: RouterNode,
path: string,
searchPa... | 4,433 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/encodeURIComponentExcept.ts | /**
* Like encodeURIComponent, but supports a custom set of unescaped characters.
* @param uriComponent - A value representing an unencoded URI component.
* @param unescaped - a string containing characters to not escape
*/
export function encodeURIComponentExcept(
uriComponent: string | number | boolean,
unesc... | 4,434 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/index.ts | export * from './IntentLink'
export * from './Link'
export * from './RouteScope'
export * from './RouterContext'
export * from './RouterProvider'
export * from './StateLink'
export * from './route'
export * from './types'
export * from './useIntentLink'
export * from './useLink'
export * from './useRouter'
export * fro... | 4,435 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/route.ts | import {_parseRoute} from './_parseRoute'
import {_resolveStateFromPath} from './_resolveStateFromPath'
import {_resolvePathFromState} from './_resolvePathFromState'
import {RouteTransform, Router, RouteChildren} from './types'
import {decodeJsonParams, encodeJsonParams} from './utils/jsonParamsEncoding'
import {decode... | 4,436 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/types.ts | /**
* @public
*/
export interface RouteSegment {
/**
* The name of the segment.
*/
name: string
/**
* The type of the segment.
* Can be either "dir" or "param".
*/
type: 'dir' | 'param'
}
/**
* @public
*/
export interface RouteTransform<T> {
/**
* Converts a path string to a state objec... | 4,437 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/useIntentLink.ts | import {useMemo} from 'react'
import {IntentParameters} from './types'
import {useLink} from './useLink'
import {useRouter} from './useRouter'
/**
* @public
*/
export interface UseIntentLinkOptions {
/**
* The name of the intent to trigger.
*/
intent: string
/**
* An optional click event handler.
... | 4,438 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/useLink.ts | import {useCallback} from 'react'
import {useRouter} from './useRouter'
function isLeftClickEvent(event: React.MouseEvent) {
return event.button === 0
}
function isModifiedEvent(event: React.MouseEvent) {
return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey)
}
/**
* @public
*/
export inte... | 4,439 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/useRouter.ts | import {useContext} from 'react'
import {RouterContext} from './RouterContext'
import {RouterContextValue} from './types'
/**
* Returns the router context value.
* @public
*
* @returns The router context value.
* {@link RouterContextValue}
* @throws An error if the router context value is missing.
*
* @exampl... | 4,440 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/useRouterState.ts | import {identity} from 'lodash'
import {useMemo} from 'react'
import {RouterState} from './types'
import {useRouter} from './useRouter'
/**
* @public
*
* @param selector - A selector function that receives the router state and returns a value. See {@link RouterState}
*
* @returns The value returned by the selecto... | 4,441 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/useStateLink.ts | import React, {useMemo} from 'react'
import {useRouter} from './useRouter'
import {useLink} from './useLink'
const EMPTY_STATE = {}
/**
* @public
*/
export interface UseStateLinkOptions {
/**
* The click event handler for the link.
*/
onClick?: React.MouseEventHandler<HTMLElement>
/**
* Whether to re... | 4,442 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src | petrpan-code/sanity-io/sanity/packages/sanity/src/router/withRouter.tsx | import React, {ComponentType, FunctionComponent} from 'react'
import {RouterContextValue} from './types'
import {useRouter} from './useRouter'
/**
* A higher-order component that injects the `router` object from the `useRouter` hook
* into the props of the wrapped component.
*
* @internal
* @deprecated - Use the ... | 4,443 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/__test__/api.test.ts | import {route} from '../route'
test('route.create(options)', () => {
const router = route.create({
path: '/root/:param',
transform: {
param: {
toState: (param) => param.toUpperCase(),
toPath: (param) => param.toLowerCase(),
},
},
children: [route.create({path: '/sub/:subpa... | 4,444 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/__test__/base64url.test.ts | import {decodeBase64Url, encodeBase64Url} from '../utils/base64url'
test('base64url: "safe" strings', () => {
expect(decodeBase64Url(encodeBase64Url('foo'))).toBe('foo')
expect(decodeBase64Url(encodeBase64Url('this one has spaces and stuff!'))).toBe(
'this one has spaces and stuff!',
)
})
test('base64url: e... | 4,445 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/__test__/basepath.test.ts | import {route} from '../route'
test('route(options)', () => {
const router = route.create('/some/basepath', [route.create('/:param')])
expect(router.decode('/some/basepath')).toEqual({})
expect(router.encode({})).toEqual('/some/basepath')
expect(router.encode({param: 'foo'})).toEqual('/some/basepath/foo')
})
| 4,446 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/__test__/errors.test.ts | import {route} from '../route'
function mock<T, K extends keyof T>(obj: T, methodName: K, mockFn: T[K]) {
const original = obj[methodName]
obj[methodName] = mockFn
return function restore() {
obj[methodName] = original
}
}
test('warn on invalid characters', () => {
const restore = mock(console, 'error',... | 4,447 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/__test__/examples.ts | /* eslint-disable quote-props */
import {route} from '../route'
export const router = route.create('/:dataset', [
route.create('/settings/:setting'),
route.create('/tools/:tool', (params: any): any => {
if (params.tool === 'desk') {
return [route.scope('desk', '/collections/:collection')]
}
if (... | 4,448 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/__test__/factory.test.ts | import {route} from '../route'
test('only route', () => {
const router = route.create('/foo/:bar')
expect(router.decode('/foo/bar')).toEqual({bar: 'bar'})
})
test('null options', () => {
const router = route.create('/foo/:bar', null)
expect(router.decode('/foo/bar')).toEqual({bar: 'bar'})
})
test('empty chil... | 4,449 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/__test__/findMatchingNodes.test.ts | import {MatchResult, RouterNode} from '../types'
import {_findMatchingRoutes} from '../_findMatchingRoutes'
const node: RouterNode = {
route: {
raw: '/foo/:bar',
segments: [
{type: 'dir', name: 'foo'},
{type: 'param', name: 'bar'},
],
},
children: [
{
route: {
raw: '/nix... | 4,450 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/__test__/resolvePathFromState.test.ts | import {route} from '../route'
import {Router} from '../types'
import {_resolvePathFromState} from '../_resolvePathFromState'
test('resolves empty state to fixed base path', () => {
const rootRoute: Router = route.create('/root', [
route.create('/:page', [route.create('/:productId')]),
])
expect(_resolvePath... | 4,451 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/__test__/resolveStateFromPath.test.ts | import {RouterNode} from '../types'
import {_resolveStateFromPath} from '../_resolveStateFromPath'
const node: RouterNode = {
route: {
raw: '/foo/:bar',
segments: [
{type: 'dir', name: 'foo'},
{type: 'param', name: 'bar'},
],
},
children: [
{
route: {
raw: '/dynamic/:foo... | 4,452 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/__test__/scope.test.ts | import {route} from '../route'
test('toplevel', () => {
const router = route.scope('omg', '/foo/:bar')
expect(router.decode('/foo/bar')).toEqual({omg: {bar: 'bar'}})
expect(router.encode({omg: {bar: 'bar'}})).toBe('/foo/bar')
})
test('toplevel, with params', () => {
const router = route.scope('omg', '/foo/:ba... | 4,453 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/__test__/transform.test.ts | import {route} from '../route'
import {decodeParams, encodeParams} from '../utils/paramsEncoding'
test('transform config on regular routes', () => {
const router = route.create(
'/some/:section/:settings',
{
transform: {
settings: {
toState: decodeParams,
toPath: encodeParam... | 4,454 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/__test__/urlSearchParams.test.ts | import {route} from '../route'
describe('decode w/UrlSearchParams', () => {
const router = route.create('/tools/:tool', route.create('/edit/:documentId'))
test('UrlSearchParams params with a simple route', () => {
expect(router.decode('/tools/desk?a=b')).toEqual({
tool: 'desk',
_searchParams: [['a'... | 4,455 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/__test__/usage.test.ts | import {route} from '../route'
const router = route.create('/', [
route.create('/animals/:animal'),
route.create('/countries', [
route.create('/:country', [route.create('/:county', [route.create('/:municipality')])]),
route.create('/:country/:county'),
route.create('/:country/:county/:municipality/neig... | 4,456 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/utils/arrayify.ts | export function arrayify<T>(val: Array<T> | T): Array<T> {
if (Array.isArray(val)) {
return val
}
return val ? [val] : []
}
| 4,457 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/utils/base64url.ts | /**
* `atob()` and `btoa()` do not support Unicode characters outside of the Latin1 range,
* but we obviously want to support the full range of Unicode characters in our router.
*
* Additionally, we would prefer not to use characters like `+` and `=` in URLs, as they
* have specific meanings there and may be misin... | 4,458 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/utils/debug.ts | import Debug from 'debug'
export const debug = Debug('state-router')
| 4,459 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/utils/hasOwn.ts | const _hasOWn = Object.prototype.hasOwnProperty
export const hasOwn = _hasOWn.call.bind(_hasOWn)
| 4,460 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/utils/isEmpty.ts | import {hasOwn} from './hasOwn'
export function isEmpty(object: Record<string, unknown>): boolean {
for (const key in object) {
if (hasOwn(object, key)) {
return false
}
}
return true
}
| 4,461 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/utils/jsonParamsEncoding.ts | import {decodeBase64Url, encodeBase64Url} from './base64url'
/**
* Decode a path segment containing JSON parameters
*
* @param pathSegment - The path segment to decode
* @returns The decoded parameters
* @internal
* @hidden
*/
export function decodeJsonParams(pathSegment = ''): Record<string, unknown> {
const... | 4,462 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/utils/paramsEncoding.ts | export function decodeParams(pathSegment: string): Record<string, string> {
return pathSegment.split(';').reduce<Record<string, string>>((params, pair) => {
const [key, value] = pair.split('=')
params[decodeURIComponent(key)] = decodeURIComponent(value)
return params
}, {})
}
export function encodePa... | 4,463 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/src/router | petrpan-code/sanity-io/sanity/packages/sanity/src/router/utils/parseScopedParams.ts | import {InternalSearchParam} from '../types'
export function parseScopedParams(params: [key: string, value: string][]): InternalSearchParam[] {
return params.map(([key, value]) => [parse(key), value])
}
const OPEN = 1
const CLOSED = 0
function parse(str: string) {
const result = []
let i = 0
let state = CLOS... | 4,464 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/static | petrpan-code/sanity-io/sanity/packages/sanity/static/favicons/favicon.svg | <?xml version="1.0" encoding="utf-8"?>
<svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="512" height="512" fill="#F03E2F" rx="30" />
<path d="M161.527 136.723C161.527 179.76 187.738 205.443 240.388 219.095L296 232.283C345.687 243.852 376 272.775 376 319.5... | 4,465 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/cli/.eslintrc | {
"rules": {
"tsdoc/syntax": "off"
}
}
| 4,466 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test/cli | petrpan-code/sanity-io/sanity/packages/sanity/test/cli/graphql/extract.test.ts | import {orderBy} from 'lodash'
import {extractFromSanitySchema} from '../../../src/_internal/cli/actions/graphql/extractFromSanitySchema'
import type {ApiSpecification} from '../../../src/_internal/cli/actions/graphql/types'
import testStudioSchema from './fixtures/test-studio'
describe('GraphQL - Schema extraction', ... | 4,467 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test/cli | petrpan-code/sanity-io/sanity/packages/sanity/test/cli/graphql/gen2.test.ts | import {orderBy} from 'lodash'
import {extractFromSanitySchema} from '../../../src/_internal/cli/actions/graphql/extractFromSanitySchema'
import generateSchema from '../../../src/_internal/cli/actions/graphql/gen2'
import testStudioSchema from './fixtures/test-studio'
describe('GraphQL - Generation 2', () => {
bef... | 4,468 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test/cli | petrpan-code/sanity-io/sanity/packages/sanity/test/cli/graphql/gen3.test.ts | import {orderBy} from 'lodash'
import {extractFromSanitySchema} from '../../../src/_internal/cli/actions/graphql/extractFromSanitySchema'
import generateSchema from '../../../src/_internal/cli/actions/graphql/gen3'
import testStudioSchema from './fixtures/test-studio'
describe('GraphQL - Generation 3', () => {
bef... | 4,469 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test/cli/graphql | petrpan-code/sanity-io/sanity/packages/sanity/test/cli/graphql/__snapshots__/extract.test.ts.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`GraphQL - Schema extraction Should be able to extract schema 1`] = `
Object {
"interfaces": Array [
Object {
"description": "A Sanity document",
"fields": Array [
Object {
"description": "Date the document was created",
"... | 4,470 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test/cli/graphql | petrpan-code/sanity-io/sanity/packages/sanity/test/cli/graphql/__snapshots__/gen2.test.ts.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`GraphQL - Generation 2 Should be able to generate graphql schema 1`] = `
Object {
"generation": "gen2",
"interfaces": Array [
Object {
"description": "A Sanity document",
"fields": Array [
Object {
"description": "Date the docume... | 4,471 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test/cli/graphql | petrpan-code/sanity-io/sanity/packages/sanity/test/cli/graphql/__snapshots__/gen3.test.ts.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`GraphQL - Generation 3 Should be able to generate graphql schema 1`] = `
Object {
"generation": "gen3",
"interfaces": Array [
Object {
"description": "A Sanity document",
"fields": Array [
Object {
"description": "Date the docume... | 4,472 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test/cli/graphql | petrpan-code/sanity-io/sanity/packages/sanity/test/cli/graphql/fixtures/test-studio.ts | import {Schema} from '@sanity/schema'
export default Schema.compile({
types: [
{
name: 'sanity.assetSourceData',
title: 'Asset Source Data',
type: 'object',
fields: [
{
name: 'name',
title: 'Source name',
description: 'A canonical name for the source ... | 4,473 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/form/index.ts | export * from './renderArrayOfObjectsInput'
export * from './renderBooleanInput'
export * from './renderCrossDatasetReferenceInput'
export * from './renderFileInput'
export * from './renderImageInput'
export * from './renderNumberInput'
export * from './renderObjectInput'
export * from './renderStringInput'
| 4,474 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/form/renderArrayOfObjectsInput.tsx | import {ArraySchemaType, FieldDefinition} from '@sanity/types'
import React from 'react'
import {
ArrayOfObjectsFormNode,
ArrayOfObjectsInputProps,
ComplexElementProps,
FieldMember,
defaultRenderAnnotation,
defaultRenderBlock,
defaultRenderField,
defaultRenderInlineBlock,
defaultRenderInput,
default... | 4,475 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/form/renderBooleanInput.tsx | import React from 'react'
import {BooleanSchemaType, FieldDefinition} from '@sanity/types'
import {BooleanInputProps, PrimitiveInputElementProps} from '../../src/core'
import {renderInput, TestRenderInputProps} from './renderInput'
import {TestRenderProps} from './types'
const noopRenderDefault = () => <></>
export t... | 4,476 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/form/renderCrossDatasetReferenceInput.tsx | import {CrossDatasetReferenceSchemaType, FieldDefinition, SchemaTypeDefinition} from '@sanity/types'
import React from 'react'
import {of} from 'rxjs'
import {ObjectInputProps} from '../../src/core'
import {CrossDatasetReferenceInputProps} from '../../src/core/form/inputs/CrossDatasetReferenceInput'
import {TestRenderI... | 4,477 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/form/renderFileInput.tsx | import {SchemaTypeDefinition, FileSchemaType, AssetSource, FieldDefinition} from '@sanity/types'
import React from 'react'
import {EMPTY} from 'rxjs'
import {ObjectInputProps} from '../../src/core'
import {BaseFileInputProps} from '../../src/core/form/inputs/files/FileInput'
import {renderObjectInput} from './renderObj... | 4,478 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/form/renderImageInput.tsx | import {ImageSchemaType, AssetSource, FieldDefinition, SchemaTypeDefinition} from '@sanity/types'
import React from 'react'
import {EMPTY} from 'rxjs'
import {ObjectInputProps, ImageUrlBuilder} from '../../src/core'
import {BaseImageInputProps} from '../../src/core/form/inputs/files/ImageInput'
import {renderObjectInpu... | 4,479 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/form/renderInput.tsx | import {SanityClient} from '@sanity/client'
import {
defineType,
FieldDefinition,
FormNodeValidation,
ObjectSchemaType,
Path,
SchemaType,
} from '@sanity/types'
import {render} from '@testing-library/react'
import React, {FocusEvent} from 'react'
import {
EMPTY_ARRAY,
FieldMember,
FormNodePresence,
... | 4,480 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/form/renderNumberInput.tsx | import React, {ReactElement} from 'react'
import {NumberSchemaType, FieldDefinition} from '@sanity/types'
import {NumberInputProps, PrimitiveInputElementProps} from '../../src/core'
import {renderInput, TestRenderInputContext, TestRenderInputProps} from './renderInput'
import {TestRenderProps} from './types'
const noo... | 4,481 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/form/renderObjectInput.tsx | import {FieldDefinition, ObjectSchemaType} from '@sanity/types'
import React from 'react'
import {
ComplexElementProps,
FieldMember,
ObjectFormNode,
ObjectInputProps,
defaultRenderAnnotation,
defaultRenderBlock,
defaultRenderField,
defaultRenderInlineBlock,
defaultRenderInput,
defaultRenderItem,
d... | 4,482 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/form/renderStringInput.tsx | import React from 'react'
import {FieldDefinition, StringSchemaType} from '@sanity/types'
import {PrimitiveInputElementProps, StringInputProps} from '../../src/core'
import {renderInput, TestRenderInputContext, TestRenderInputProps} from './renderInput'
import {TestRenderProps} from './types'
const noopRenderDefault =... | 4,483 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/form/types.ts | import {Path, ValidationMarker} from '@sanity/types'
import {FormNodePresence} from '../../src/core'
export interface TestRenderProps {
documentValue?: Record<string, unknown>
focusPath?: Path
openPath?: Path
presence?: FormNodePresence[]
validation?: ValidationMarker[]
}
| 4,484 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/mocks/mockBifur.ts | import {BifurClient} from '@sanity/bifur-client'
import {of} from 'rxjs'
export function createMockBifurClient(): BifurClient {
const data: {requests: Record<string, any>} = {
requests: {
presence: [],
},
}
return {
request: (id: string) => {
return of(data.requests[id] || null)
},
... | 4,485 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/mocks/mockSanityClient.ts | import {Observable, of} from 'rxjs'
export interface MockClientTransactionLog {
id: number
commit: any[][]
create: any[][]
createIfNotExists: any[][]
createOrReplace: any[][]
delete: any[][]
patch: any[][]
}
export interface MockClientLog {
listen: {query: string; params?: any}[]
observable: {
f... | 4,486 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/setup/afterEnv.ts | // eslint-disable-next-line import/no-unassigned-import
import '@testing-library/jest-dom'
| 4,487 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/setup/environment.ts | export {}
;(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true
// get rid of context warning
const warn = console.warn
const error = console.error
window.console = {
...window.console,
warn: (...args: any[]) => {
if (!/No context provided/.test(args[0])) {
warn(...args)
}
},
error: (...args: any[... | 4,488 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/setup/global.ts | /* eslint-disable no-process-env */
import os from 'os'
import {execSync} from 'child_process'
const wantedUnixTZ = 'America/Los_Angeles'
const wantedWindowsTZ = 'Pacific Standard Time'
export default function globalSetup(): void {
if (os.platform() !== 'win32') {
process.env.TZ = wantedUnixTZ
return
}
... | 4,489 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/testUtils/TestProvider.tsx | import React from 'react'
import {SanityClient} from '@sanity/client'
import {LayerProvider, studioTheme, ThemeProvider, ToastProvider} from '@sanity/ui'
import {
ResourceCacheProvider,
SingleWorkspace,
SourceProvider,
WorkspaceProvider,
} from '../../src/core'
import {getMockWorkspace} from './getMockWorkspace... | 4,490 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/testUtils/getMockWorkspaceFromConfig.ts | import type {SanityClient} from '@sanity/client'
import type {CurrentUser} from '@sanity/types'
import {
createWorkspaceFromConfig,
SchemaPluginOptions,
SingleWorkspace,
Source,
Workspace,
} from '../../src/core/config'
import {createMockSanityClient} from '../mocks/mockSanityClient'
const defaultMockUser: C... | 4,491 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/validation/.eslintrc | {
"env": {
"node": true,
"jest": true
},
"rules": {
"no-sync": 0,
"max-nested-callbacks": ["error", 4]
}
}
| 4,492 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/validation/array.test.ts | import {Rule} from '../../src/core/validation'
const context: any = {client: {}}
describe('array', () => {
test('required constraint', async () => {
const rule = Rule.array().required()
await expect(rule.validate(null, context)).resolves.toMatchSnapshot('required: null')
await expect(rule.validate(undef... | 4,493 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/validation/children.test.ts | import {Rule} from '../../src/core/validation'
const context: any = {client: {}}
describe('child rules', () => {
// --- ALL ---
test('all() rules - single failure', async () => {
const rule = Rule.string().all([
Rule.string()
.regex(/^[A-Z]/)
.error('Must start with an uppercase characte... | 4,494 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/validation/generics.test.ts | import {Rule} from '../../src/core/validation'
const context: any = {client: {}}
describe('generics', () => {
test('should be able to construct an empty rule', () => {
expect(() => new Rule()).not.toThrow(Error)
expect(new Rule()).toBeInstanceOf(Rule)
})
test('should be able to construct a new typed ru... | 4,495 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/validation/infer.test.ts | import type {SanityClient} from '@sanity/client'
import type {ObjectSchemaType, Rule, SanityDocument} from '@sanity/types'
import {Schema as SchemaBuilder} from '@sanity/schema'
import {inferFromSchema} from '../../src/core/validation/inferFromSchema'
import {validateDocument} from '../../src/core/validation/validateDo... | 4,496 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/validation/numbers.test.ts | import {Rule} from '../../src/core/validation'
const context: any = {client: {}}
describe('number', () => {
test('required constraint', async () => {
const rule = Rule.number().required()
await expect(rule.validate(undefined, context)).resolves.toMatchSnapshot('required: undefined')
await expect(rule.va... | 4,497 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/validation/strings.test.ts | import {Rule} from '../../src/core/validation'
const context: any = {client: {}}
describe('string', () => {
test('required constraint', async () => {
const rule = Rule.string().required()
await expect(rule.validate('', context)).resolves.toMatchSnapshot('required: empty string')
await expect(rule.valida... | 4,498 |
0 | petrpan-code/sanity-io/sanity/packages/sanity/test | petrpan-code/sanity-io/sanity/packages/sanity/test/validation/validateDocument.test.ts | import type {
ArraySchemaType,
PortableTextTextBlock,
Rule,
SanityDocument,
Schema,
SchemaType,
ValidationContext,
} from '@sanity/types'
import {
validateDocument,
resolveTypeForArrayItem,
validateItem,
} from '../../src/core/validation/validateDocument'
import {convertToValidationMarker} from '../... | 4,499 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.