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
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence/context.tsx
import React from 'react' import {FormNodePresence} from './types' /** @internal */ export const FormFieldPresenceContext = React.createContext<FormNodePresence[]>([])
3,500
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence/index.ts
export * from './DocumentPreviewPresence' export * from './FieldPresence' export * from './PresenceScope' export * from './context' export * from './overlay/PresenceOverlay' export * from './types'
3,501
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence/types.ts
import {Path, User} from '@sanity/types' import {Session, Status} from '../store/_legacy' /** @internal */ export type Position = 'top' | 'bottom' | 'inside' | null /** @internal */ export type Size = 'xsmall' | 'small' | 'medium' /** @internal */ export type ReportedRegionWithRect<T> = T & {id: string; rect: Rect} ...
3,502
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence/utils.ts
import {AVATAR_DISTANCE, AVATAR_SIZE} from './constants' export const splitRight = <T>(array: T[], max: number): [T[], T[]] => { const indexFromMax = array.length > max ? max - 1 : max const idx = Math.max(0, array.length - indexFromMax) return [array.slice(0, idx), array.slice(idx)] } // export const splitRigh...
3,503
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence/overlay/AbsoluteOverlay.tsx
import React from 'react' import {sortBy} from 'lodash' const OVERLAY_STYLE: React.CSSProperties = { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, pointerEvents: 'none', } const ITEM_STYLE = { display: 'inline-block', transitionProperty: 'all', transitionDuration: '2000ms', transitio...
3,504
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence/overlay/PresenceOverlay.tsx
import React from 'react' import {DISABLE_OVERLAY} from '../constants' import {Tracker} from './tracker' import {StickyOverlay} from './StickyOverlay' /** @internal */ export interface PresenceOverlayProps { children: React.ReactNode margins?: [number, number, number, number] } const DEFAULT_MARGINS: [number, num...
3,505
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence/overlay/RegionsWithIntersections.styled.tsx
import styled, {css} from 'styled-components' import {WithIntersection} from './WithIntersection' interface StyleProps { $debug: boolean margins?: [number, number, number, number] } export const RootWrapper = styled.div` position: relative; ` export const OverlayWrapper = styled.div` position: absolute; to...
3,506
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence/overlay/RegionsWithIntersections.tsx
import React, {forwardRef, useCallback, useMemo, useRef, useState} from 'react' import { SNAP_TO_DOCK_DISTANCE_BOTTOM, SNAP_TO_DOCK_DISTANCE_TOP, DEBUG, INTERSECTION_ELEMENT_PADDING, INTERSECTION_THRESHOLDS, } from '../constants' import {ReportedRegionWithRect, RegionWithIntersectionDetails, FieldPresenceData...
3,507
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence/overlay/StickyOverlay.tsx
/* eslint-disable @typescript-eslint/no-use-before-define */ import React, {memo, useMemo} from 'react' import {flatten, groupBy, orderBy, sortBy} from 'lodash' import { AVATAR_ARROW_HEIGHT, AVATAR_DISTANCE, AVATAR_SIZE, DEBUG, MAX_AVATARS_DOCK, SLIDE_RIGHT_THRESHOLD_BOTTOM, SLIDE_RIGHT_THRESHOLD_TOP, } ...
3,508
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence/overlay/WithIntersection.tsx
import React from 'react' import {tap} from 'rxjs/operators' import type {ObservableIntersectionObserver} from './intersectionObserver' export interface WithIntersectionProps { onIntersection: (id: string, entry: IntersectionObserverEntry) => void io: ObservableIntersectionObserver id: string } export const Wit...
3,509
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence/overlay/intersectionObserver.ts
import {Subject, Observable} from 'rxjs' import {filter} from 'rxjs/operators' export interface ObservableIntersectionObserver { observe: (element: Element) => Observable<IntersectionObserverEntry> } export const createIntersectionObserver = ( options?: IntersectionObserverInit, ): ObservableIntersectionObserver ...
3,510
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence
petrpan-code/sanity-io/sanity/packages/sanity/src/core/presence/overlay/tracker.ts
import {createTrackerScope, Reported} from '../../components/react-track-elements' import {FieldPresenceData} from '../types' export type ReportedPresenceData = Reported<FieldPresenceData> const {Tracker, useReporter, useReportedValues} = createTrackerScope<FieldPresenceData>() export {Tracker, useReporter, useRepor...
3,511
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/.eslintrc
{ "rules": { "camelcase": "off" } }
3,512
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/availability.ts
/* eslint-disable max-nested-callbacks */ import type {SanityClient} from '@sanity/client' import {combineLatest, defer, from, Observable, of} from 'rxjs' import {distinctUntilChanged, map, mergeMap, reduce, switchMap} from 'rxjs/operators' import shallowEquals from 'shallow-equals' import {flatten, keyBy} from 'lodas...
3,513
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/constants.tsx
import {WarningOutlineIcon} from '@sanity/icons' import {PreviewValue} from '@sanity/types' import React from 'react' export const INCLUDE_FIELDS_QUERY = ['_id', '_rev', '_type'] export const INCLUDE_FIELDS = [...INCLUDE_FIELDS_QUERY, '_key'] export const AVAILABILITY_READABLE = { available: true, reason: 'READAB...
3,514
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/createPathObserver.ts
import {uniq} from 'lodash' import {Observable, of as observableOf} from 'rxjs' import {switchMap} from 'rxjs/operators' import {isCrossDatasetReference, isReference} from '@sanity/types' import {isRecord} from '../util' import {ApiConfig, FieldName, PreviewPath, Previewable} from './types' import {props} from './utils...
3,515
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/createPreviewObserver.ts
import {Observable, of as observableOf} from 'rxjs' import {map, switchMap} from 'rxjs/operators' import { isCrossDatasetReference, isCrossDatasetReferenceSchemaType, isReferenceSchemaType, PrepareViewOptions, } from '@sanity/types' import {isPlainObject} from 'lodash' import {invokePrepare, prepareForPreview} ...
3,516
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/documentPair.ts
import {SanityClient} from '@sanity/client' import {combineLatest, Observable, of} from 'rxjs' import {map, switchMap} from 'rxjs/operators' import {SanityDocument} from '@sanity/types' import {getIdPair, isRecord} from '../util' import {DraftsModelDocument, ObservePathsFn, PreviewPath, Previewable} from './types' impo...
3,517
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/documentPreviewStore.ts
import {Observable} from 'rxjs' import {distinctUntilChanged, map} from 'rxjs/operators' import {SanityClient} from '@sanity/client' import {PrepareViewOptions, SanityDocument} from '@sanity/types' import {isRecord} from '../util' import {create_preview_availability} from './availability' import {createPathObserver} fr...
3,518
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/index.ts
export * from './components/SanityDefaultPreview' export * from './components/PreviewLoader' export * from './components/Preview' export {getPreviewPaths} from './utils/getPreviewPaths' export {getPreviewStateObservable} from './utils/getPreviewStateObservable' export {getPreviewValueWithFallback} from './utils/getPre...
3,519
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/observeFields.ts
import { combineLatest, concat, defer, EMPTY, from, fromEvent, merge, Observable, of as observableOf, timer, } from 'rxjs' import { distinctUntilChanged, filter, map, mergeMap, publishReplay, refCount, share, shareReplay, startWith, switchMap, tap, } from 'rxjs/operators' impor...
3,520
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/types.ts
import {PreviewConfig, PreviewValue, Reference, SanityDocumentLike, SchemaType} from '@sanity/types' import {Observable} from 'rxjs' /** @internal */ export type Id = string /** * @hidden * @beta */ export type Previewable = ( | {_id: string} | {_type: string} | {_ref: string; _dataset?: string; _projectId?: ...
3,521
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/useValuePreview.ts
import {PreviewValue, SchemaType, SortOrdering} from '@sanity/types' import {catchError, map} from 'rxjs/operators' import {of} from 'rxjs' import {useMemoObservable} from 'react-rx' import {useDocumentPreviewStore} from '../store' import {Previewable} from './types' export {useDocumentPreview as unstable_useValuePre...
3,522
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/useVisibility.ts
import {useEffect, useState} from 'react' import {concat, of} from 'rxjs' import {delay, distinctUntilChanged, map, switchMap} from 'rxjs/operators' import {intersectionObservableFor} from './streams/intersectionObservableFor' import {visibilityChange$} from './streams/visibilityChange' export function useVisibility(p...
3,523
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/__workshop__/SanityPreviewStory.tsx
import {Box, Card, Container} from '@sanity/ui' import {useSelect} from '@sanity/ui-workshop' import React, {useMemo} from 'react' import {Image, ObjectSchemaType} from '@sanity/types' import {PreviewLoader} from '../components/PreviewLoader' import {Previewable} from '../types' import {PreviewLayoutKey} from '../../co...
3,524
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/__workshop__/constants.ts
import {PreviewLayoutKey} from '../../components' export const WORKSHOP_PREVIEW_LAYOUT: Record<string, PreviewLayoutKey> = { Block: 'block', BlockImage: 'blockImage', Default: 'default', Detail: 'detail', Inline: 'inline', Media: 'media', }
3,525
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/__workshop__/index.ts
import {defineScope} from '@sanity/ui-workshop' import {lazy} from 'react' export default defineScope({ name: 'core/preview', title: 'preview', stories: [ { name: 'sanity-preview', title: 'SanityPreview', component: lazy(() => import('./SanityPreviewStory')), }, ], })
3,526
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/components/Preview.tsx
import React from 'react' import {RenderPreviewCallbackProps} from '../../form/types' import {usePreviewComponent} from '../../form/form-components-hooks' import {PreviewLoader} from '../index' /** * @internal */ export function Preview(props: RenderPreviewCallbackProps) { const PreviewComponent = usePreviewCompon...
3,527
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/components/PreviewLoader.tsx
import React, { ComponentType, createElement, CSSProperties, ReactElement, useMemo, useState, } from 'react' import {RenderPreviewCallbackProps} from '../../form' import {useVisibility} from '../useVisibility' import {unstable_useValuePreview as useValuePreview} from '../useValuePreview' import type {Previ...
3,528
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/components/SanityDefaultPreview.tsx
import {DocumentIcon} from '@sanity/icons' import imageUrlBuilder from '@sanity/image-url' import {ImageUrlFitMode} from '@sanity/types' import React, { ComponentType, createElement, ElementType, isValidElement, ReactElement, useCallback, useMemo, } from 'react' import {isValidElementType} from 'react-is'...
3,529
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/components/_constants.ts
export const _HIDE_DELAY = 1000 * 2 // 2 seconds
3,530
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/components/_extractUploadState.ts
import {UploadState} from '@sanity/types' import {isRecord, isString} from '../../util' export function _extractUploadState(value: any): UploadState | undefined { return _resolveUploadValue(value?._upload) } function getStringOrUndefined(value: unknown): string | undefined { return isString(value) ? value : undef...
3,531
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/components/_helpers.ts
import {Observable, of} from 'rxjs' import {distinctUntilChanged, filter, switchMap, tap} from 'rxjs/operators' import {isNonNullable} from '../../util' /** * Will track a memo of the value as long as the isActive$ stream emits true, * and emit the memoized value after it switches to to false. * * (disclaimer: the...
3,532
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/components/_previewComponents.ts
import {ComponentType} from 'react' import { BlockImagePreview, BlockPreview, DefaultPreview, DetailPreview, InlinePreview, MediaPreview, } from '../../components' export const _previewComponents = { default: DefaultPreview, media: MediaPreview, detail: DetailPreview, inline: InlinePreview, block...
3,533
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/streams/intersectionObservableFor.ts
import {Subject, Observable, merge, of as observableOf} from 'rxjs' import {map, mergeMap, filter} from 'rxjs/operators' import {resize$} from './resize' import {scroll$} from './scroll' import {orientationChange$} from './orientationChange' const ROOT_MARGIN_PX = 150 /* Adapted from the polyfill at https://github....
3,534
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/streams/orientationChange.ts
import {EMPTY, fromEvent} from 'rxjs' import {shareReplay} from 'rxjs/operators' export const orientationChange$ = typeof window === 'undefined' ? EMPTY : fromEvent(window, 'orientationchange').pipe(shareReplay(1))
3,535
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/streams/resize.ts
import {EMPTY, fromEvent} from 'rxjs' import {shareReplay} from 'rxjs/operators' export const resize$ = typeof window === 'undefined' ? EMPTY : fromEvent(window, 'resize').pipe(shareReplay(1))
3,536
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/streams/scroll.ts
import {EMPTY, fromEvent} from 'rxjs' import {shareReplay} from 'rxjs/operators' export const scroll$ = typeof window === 'undefined' ? EMPTY : fromEvent(window, 'scroll', {passive: true, capture: true}).pipe(shareReplay(1))
3,537
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/streams/visibilityChange.ts
import {EMPTY, fromEvent, Observable} from 'rxjs' import {shareReplay} from 'rxjs/operators' export const visibilityChange$: Observable<Event> = typeof window === 'undefined' ? EMPTY : fromEvent(document, 'visibilitychange').pipe(shareReplay(1))
3,538
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/utils/debounceCollect.ts
import {Observable, Subscriber} from 'rxjs' import {isNonNullable} from '../../util' interface QueueItem { args: any[] observer: Subscriber<any> completed: boolean } // Takes an observable returning function and returns a debounced function that, when called // collects its passed arguments until wait time has ...
3,539
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/utils/getPreviewPaths.ts
import {SchemaType} from '@sanity/types' import {PreviewPath} from '../types' /** @internal */ export function getPreviewPaths(preview: SchemaType['preview']): PreviewPath[] | undefined { const selection = preview?.select if (!selection) return undefined return Object.values(selection).map((value) => String(va...
3,540
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/utils/getPreviewStateObservable.ts
import {PreviewValue, SanityDocument, SchemaType} from '@sanity/types' import React from 'react' import {combineLatest, Observable, of} from 'rxjs' import {map, startWith} from 'rxjs/operators' import {getDraftId, getPublishedId} from '../../util/draftUtils' import {DocumentPreviewStore} from '../documentPreviewStore' ...
3,541
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/utils/getPreviewValueWithFallback.tsx
import {WarningOutlineIcon} from '@sanity/icons' import type {PreviewValue, SanityDocument} from '@sanity/types' import {assignWith} from 'lodash' import React from 'react' const getMissingDocumentFallback = (item: SanityDocument) => ({ title: <em>{item.title ? String(item.title) : 'Missing document'}</em>, subtit...
3,542
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/utils/hasEqualFields.ts
export function hasEqualFields(fields: string[]) { return (object: Record<string, any> | null, otherObject: Record<string, any> | null) => { if (object === otherObject) { return true } if (!object || !otherObject) { return false } if (typeof object !== 'object' || typeof otherObject !=...
3,543
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/utils/isUniqueBy.ts
const id = <T>(value: T): T => value type ItemSelector<T> = (element: T) => any // Takes an array and checks if each item is unique, // optionally by specifying an itemSelector function that will be called with // each item, returning the value to compare for uniqueness export function isUniqueBy<T>(array: Array<T>, ...
3,544
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/utils/keysOf.ts
export function keysOf<T extends object>(value: T) { return Object.keys(value) as (keyof T)[] }
3,545
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/utils/optimizeQuery.ts
import {identity, sortBy, values} from 'lodash' import {FieldName, Id, Selection} from '../types' import {INCLUDE_FIELDS_QUERY} from '../constants' import {escapeField, fieldNeedsEscape} from '../../util' type CombinedSelection = { ids: Id[] fields: FieldName[] map: number[] } type Doc = { _id: string } type...
3,546
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/utils/portableText.ts
import {isPortableTextTextBlock, isPortableTextSpan, PortableTextBlock} from '@sanity/types' export function isPortableTextPreviewValue(value: unknown): value is PortableTextBlock[] { return Array.isArray(value) && (value.length === 0 || value.some(isPortableTextTextBlock)) } export function extractTextFromBlocks(b...
3,547
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/utils/prepareForPreview.ts
import { isTitledListValue, PrepareViewOptions, PreviewValue, SchemaType, TitledListValue, } from '@sanity/types' import {debounce, flatten, get, isPlainObject, pick, uniqBy} from 'lodash' import {INVALID_PREVIEW_FALLBACK} from '../constants' import {PreviewableType} from '../types' import {isRecord} from '.....
3,548
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview
petrpan-code/sanity-io/sanity/packages/sanity/src/core/preview/utils/props.ts
import { combineLatest, from as observableFrom, isObservable, Observable, of as observableOf, } from 'rxjs' import {map, mergeAll, scan, switchMap} from 'rxjs/operators' import {keysOf} from './keysOf' function setKey(source: Record<string, unknown>, key: any, value: unknown) { return { ...source, ...
3,549
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/createSchema.ts
import {Schema as SchemaBuilder, type SchemaValidationResult} from '@sanity/schema' import {validateSchema, groupProblems} from '@sanity/schema/_internal' import {Schema} from '@sanity/types' import {inferFromSchema as inferValidation} from '../validation' import slug from './types/slug' import geopoint from './types/g...
3,550
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/helpers.ts
import type {SchemaType} from '@sanity/types' /** * Get the most specific defined title of a schema type * If not set directly on the given type, it will traverse up the tree until it * finds one, falling back to the _name_ of the type. * * @param type - The schema type to get the title of * @returns A title, al...
3,551
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/index.ts
export * from './createSchema' export * from './helpers'
3,552
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/__workshop__/ReferenceSchemaStory.tsx
import {SchemaType} from '@sanity/types' import {Box, Card, Code, Flex, Label} from '@sanity/ui' import React, {useMemo} from 'react' import {createSchema} from '../createSchema' export default function ReferenceSchemaStory() { const authorTypeDef = useMemo( () => ({ type: 'document', name: 'author',...
3,553
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/__workshop__/index.ts
import {defineScope} from '@sanity/ui-workshop' import ReferenceSchemaStory from './ReferenceSchemaStory' export default defineScope({ name: 'core/schema', title: 'schema', stories: [ { name: 'reference-schema', title: 'ReferenceSchema', component: ReferenceSchemaStory, }, ], })
3,554
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/types/assetSourceData.ts
export default { name: 'sanity.assetSourceData', title: 'Asset Source Data', type: 'object', fields: [ { name: 'name', title: 'Source name', description: 'A canonical name for the source this asset is originating from', type: 'string', }, { name: 'id', title: 'Ass...
3,555
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/types/fileAsset.ts
import {SanityDocument} from '@sanity/client' export default { name: 'sanity.fileAsset', title: 'File', type: 'document', fieldsets: [ { name: 'system', title: 'System fields', description: 'These fields are managed by the system and not editable', }, ], fields: [ { name...
3,556
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/types/geopoint.ts
export default { title: 'Geographical Point', name: 'geopoint', type: 'object', fields: [ { name: 'lat', type: 'number', title: 'Latitude', }, { name: 'lng', type: 'number', title: 'Longitude', }, { name: 'alt', type: 'number', title: 'Al...
3,557
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/types/imageAsset.ts
import {SanityDocument} from '@sanity/types' export default { name: 'sanity.imageAsset', title: 'Image', type: 'document', fieldsets: [ { name: 'system', title: 'System fields', description: 'These fields are managed by the system and not editable', }, ], fields: [ { nam...
3,558
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/types/imageCrop.ts
export default { name: 'sanity.imageCrop', title: 'Image crop', type: 'object', fields: [ { name: 'top', type: 'number', }, { name: 'bottom', type: 'number', }, { name: 'left', type: 'number', }, { name: 'right', type: 'number', }, ...
3,559
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/types/imageDimensions.ts
export default { name: 'sanity.imageDimensions', type: 'object', title: 'Image dimensions', fields: [ {name: 'height', type: 'number', title: 'Height', readOnly: true}, {name: 'width', type: 'number', title: 'Width', readOnly: true}, {name: 'aspectRatio', type: 'number', title: 'Aspect ratio', readO...
3,560
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/types/imageHotspot.ts
export default { name: 'sanity.imageHotspot', title: 'Image hotspot', type: 'object', fields: [ { name: 'x', type: 'number', }, { name: 'y', type: 'number', }, { name: 'height', type: 'number', }, { name: 'width', type: 'number', },...
3,561
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/types/imageMetadata.ts
export default { name: 'sanity.imageMetadata', title: 'Image metadata', type: 'object', fieldsets: [ { name: 'extra', title: 'Extra metadata…', options: { collapsable: true, }, }, ], fields: [ { name: 'location', type: 'geopoint', }, { na...
3,562
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/types/imagePalette.ts
export default { name: 'sanity.imagePalette', title: 'Image palette', type: 'object', fields: [ {name: 'darkMuted', type: 'sanity.imagePaletteSwatch', title: 'Dark Muted'}, {name: 'lightVibrant', type: 'sanity.imagePaletteSwatch', title: 'Light Vibrant'}, {name: 'darkVibrant', type: 'sanity.imagePal...
3,563
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/types/imagePaletteSwatch.ts
export default { name: 'sanity.imagePaletteSwatch', title: 'Image palette swatch', type: 'object', fields: [ {name: 'background', type: 'string', title: 'Background', readOnly: true}, {name: 'foreground', type: 'string', title: 'Foreground', readOnly: true}, {name: 'population', type: 'number', titl...
3,564
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema
petrpan-code/sanity-io/sanity/packages/sanity/src/core/schema/types/slug.ts
export default { title: 'Slug', name: 'slug', type: 'object', fields: [ { name: 'current', title: 'Current slug', type: 'string', }, { // The source field is deprecated/unused, but leaving it included and hidden // to prevent rendering "Unknown field" warnings on legacy...
3,565
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/constants.ts
// Findability version, prepended to every search query for future measurement export const FINDABILITY_MVI = 4
3,566
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/index.ts
export * from './search' export * from './weighted' export * from './useDocumentSearchResults'
3,567
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/search.ts
import {SanityClient} from '@sanity/client' import {Schema} from '@sanity/types' import {Observable} from 'rxjs' import {getSearchableTypes} from './common/utils' import {createWeightedSearch} from './weighted/createWeightedSearch' import {SearchOptions, WeightedHit} from './weighted/types' /** @internal */ export fun...
3,568
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/useDocumentSearchResults.ts
import {useEffect, useMemo, useState} from 'react' import {concat, EMPTY, Observable, of, Subject, timer} from 'rxjs' import { catchError, distinctUntilChanged, filter, map, mergeMapTo, share, switchMap, } from 'rxjs/operators' import {useClient, useSchema} from '../hooks' import {DEFAULT_STUDIO_CLIENT_OP...
3,569
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/common/tokenize.test.ts
import {tokenize} from './tokenize' const tests = [ {input: '', expected: []}, {input: 'foo', expected: ['foo']}, {input: '0foo', expected: ['0foo']}, {input: 'a16z', expected: ['a16z']}, {input: 'foo,,, , ,foo,bar', expected: ['foo', 'foo', 'bar']}, {input: 'pho-bar, foo-bar', expected: ['pho', 'bar', ...
3,570
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/common/tokenize.ts
const SPECIAL_CHARS = /([^!@#$%^&*(),\\/?";:{}|[\]+<>\s-])+/g const STRIP_EDGE_CHARS = /(^[.]+)|([.]+$)/ export function tokenize(string: string): string[] { return (string.match(SPECIAL_CHARS) || []).map((token) => token.replace(STRIP_EDGE_CHARS, '')) }
3,571
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/common/utils.ts
import {ObjectSchemaType, Schema, SchemaType} from '@sanity/types' import {isNonNullable} from '../../util/isNonNullable' const isDocumentType = (type: SchemaType): type is ObjectSchemaType => Boolean(type.type && type.type.name === 'document') const isSanityType = (type: SchemaType): boolean => type.name.startsWit...
3,572
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/weighted/applyWeights.test.ts
import { calculatePhraseScore, calculateWordScore, partitionAndSanitizeSearchTerms, } from './applyWeights' describe('calculatePhraseScore', () => { it('should handle exact matches', () => { expect(calculatePhraseScore(['the fox'], 'the fox')).toEqual([1, '[Phrase] Exact match']) }) it('should handle p...
3,573
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/weighted/applyWeights.ts
import {compact, intersection, keyBy, partition, toLower, union, uniq, words} from 'lodash' import {SearchHit, WeightedHit, SearchSpec} from './types' type SearchScore = [number, string] /** * Takes a set of terms and a value and returns a [score, story] pair where score is a value between 0, 1 and story is the expl...
3,574
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/weighted/createSearchQuery.test.ts
/* eslint-disable camelcase */ import {FINDABILITY_MVI} from '../constants' import {createSearchQuery, DEFAULT_LIMIT, extractTermsFromQuery} from './createSearchQuery' import type {SearchableType} from './types' const testType: SearchableType = { name: 'basic-schema-test', __experimental_search: [ { path...
3,575
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/weighted/createSearchQuery.ts
import {compact, flatten, flow, toLower, trim, union, uniq, words} from 'lodash' import {joinPath} from '../../../core/util/searchUtils' import {tokenize} from '../common/tokenize' import {FINDABILITY_MVI} from '../constants' import type { SearchableType, SearchOptions, SearchPath, SearchSort, SearchSpec, S...
3,576
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/weighted/createWeightedSearch.test.ts
import {Schema} from '@sanity/schema' import {renderHook} from '@testing-library/react' import {defer, lastValueFrom, of} from 'rxjs' import type {SearchTerms} from '..' import {useClient} from '../../hooks' import {getSearchableTypes} from '../common/utils' import {createWeightedSearch} from './createWeightedSearch' ...
3,577
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/weighted/createWeightedSearch.ts
import type {SanityClient} from '@sanity/client' import {sortBy} from 'lodash' import type {Observable} from 'rxjs' import {map, tap} from 'rxjs/operators' import {removeDupes} from '../../util/draftUtils' import {applyWeights} from './applyWeights' import {createSearchQuery} from './createSearchQuery' import type { ...
3,578
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/weighted/index.ts
export {createWeightedSearch} from './createWeightedSearch' export {createSearchQuery} from './createSearchQuery' export * from './types'
3,579
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search
petrpan-code/sanity-io/sanity/packages/sanity/src/core/search/weighted/types.ts
import type {ObjectSchemaType} from '@sanity/types' /** * @internal */ export interface SearchTerms { filter?: string query: string types: SearchableType[] } /** * @internal */ export interface SearchableType { name: string title?: string __experimental_search: ObjectSchemaType['__experimental_search'...
3,580
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/index.ts
export * from './_legacy' export * from './user'
3,581
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/ResourceCacheProvider.tsx
import React, {createContext, useContext, useMemo} from 'react' import {createMultiKeyWeakMap, MultiKeyWeakMap} from './createMultiKeyWeakMap' /** @internal */ export interface ResourceCache { get<T = unknown>(options: {namespace: string; dependencies: (object | null)[]}): T | undefined set(options: {namespace: st...
3,582
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/createMultiKeyWeakMap.ts
interface MultiKeyWeakMapNode { type: 'multi-key-weak-map-node' value: unknown next: WeakMap<object, MultiKeyWeakMapNode> } export interface MultiKeyWeakMap { get<T>(keys: object[]): T | undefined get(keys: object[]): unknown set(keys: object[], value: unknown): void } export function createMultiKeyWeakM...
3,583
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/datastores.ts
/* eslint-disable camelcase */ import {useMemo} from 'react' import {useClient, useSchema, useTemplates} from '../../hooks' import {createDocumentPreviewStore, DocumentPreviewStore} from '../../preview' import {useSource, useWorkspace} from '../../studio' import {DEFAULT_STUDIO_CLIENT_OPTIONS} from '../../studioClient...
3,584
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/index.ts
export * from './ResourceCacheProvider' export * from './authStore' export * from './connection-status' export * from './cors' export * from './datastores' export * from './document' export * from './grants' export * from './history' export * from './presence' export * from './project' export * from './settings' export...
3,585
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/types.ts
import {Config, Source as SanitySource} from '../../config' import {DocumentPreviewStore} from '../../preview' import {DocumentStore} from './document' import {GrantsStore} from './grants/types' import {HistoryStore} from './history' import {PresenceStore} from './presence' import {ProjectStore} from './project' import...
3,586
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/__tests__/createMultiKeyWeakMap.test.ts
import {createMultiKeyWeakMap} from '../createMultiKeyWeakMap' describe('createMultiKeyWeakMap', () => { it('returns a multi-key weakmap', () => { const multiKeyWeakMap = createMultiKeyWeakMap() const a = {_: 'a'} const b = {_: 'b'} const c = {_: 'c'} const ab = {_: 'ab'} const abc = {_: 'a...
3,587
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/__workshop__/CurrentUserStory.tsx
import React from 'react' import {Box, Button, Code, Text} from '@sanity/ui' import {useSource} from '../../../studio' export default function CurrentUserStory() { const {currentUser} = useSource() return ( <Box padding={4}> <Text size={1} weight="semibold"> <code>{`userStore.me`}</code> <...
3,588
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/__workshop__/DocumentPairStory.tsx
import {Box, Button, Code, Text} from '@sanity/ui' import React, {useEffect, useState} from 'react' import {useDocumentStore} from '../datastores' import {RemoteSnapshotVersionEvent} from '../document/document-pair/checkoutPair' export default function DocumentPairStory() { const documentStore = useDocumentStore() ...
3,589
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/__workshop__/DocumentPermissionStory.tsx
import {Box, Code, Text} from '@sanity/ui' import React, {useEffect, useState} from 'react' import {useGrantsStore} from '../datastores' import {PermissionCheckResult} from '../grants/types' export default function DocumentPermissionStory() { const grantsStore = useGrantsStore() const [permission, setPermission] =...
3,590
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/__workshop__/HistoryStory.tsx
import {SanityDocument} from '@sanity/types' import {Box, Code, Text} from '@sanity/ui' import React, {useEffect, useState} from 'react' import {useHistoryStore} from '../datastores' const SECOND = 1000 const MINUTE = SECOND * 60 const HOUR = MINUTE * 60 const DAY = HOUR * 24 export default function HistoryStory() { ...
3,591
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/__workshop__/HistoryTimelineStory.tsx
import {RestoreIcon} from '@sanity/icons' import {SanityDocument} from '@sanity/types' import {Box, Button, Card, Code, Flex, Inline, Stack, Text} from '@sanity/ui' import {format} from 'date-fns' import {omit} from 'lodash' import React, {useCallback, useMemo, useState} from 'react' import {ChangeFieldWrapper} from '....
3,592
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/__workshop__/PresenceStory.tsx
import {Box, Code, Text} from '@sanity/ui' import React, {useEffect, useState} from 'react' import {usePresenceStore} from '../datastores' import {GlobalPresence} from '../presence' export default function PresenceStory() { const presenceStore = usePresenceStore() const [globalPresence, setGlobalPresence] = useSta...
3,593
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/__workshop__/index.ts
import {defineScope} from '@sanity/ui-workshop' import {lazy} from 'react' export default defineScope({ name: 'core/store/datastores', title: 'Datastores (legacy)', stories: [ { name: 'current-user', title: 'Current user', component: lazy(() => import('./CurrentUserStory')), }, { ...
3,594
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/authStore/createAuthStore.ts
import { createClient as createSanityClient, ClientConfig as SanityClientConfig, type SanityClient, } from '@sanity/client' import {defer} from 'rxjs' import {distinctUntilChanged, map, shareReplay, startWith, switchMap} from 'rxjs/operators' import {isEqual, memoize} from 'lodash' import type {AuthConfig} from '...
3,595
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/authStore/createBroadcastChannel.ts
import {fromEvent, merge, Observable, of, Subject} from 'rxjs' import {filter, map, shareReplay} from 'rxjs/operators' import {isNonNullable} from '../../../util' import * as storage from './storage' export interface BroadcastChannel<T> { messages: Observable<T> broadcast: (message: T) => void } export function c...
3,596
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/authStore/createLoginComponent.tsx
import type {AuthProvider, AuthProviderResponse, SanityClient} from '@sanity/client' import {Button, Flex, Heading, Spinner, Stack, Text} from '@sanity/ui' import React, {useEffect, useState} from 'react' import type {Observable} from 'rxjs' import type {AuthConfig} from '../../../config' import {createHookFromObservab...
3,597
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/authStore/createMockAuthStore.ts
import {of} from 'rxjs' import {SanityClient} from '@sanity/client' import {CurrentUser} from '@sanity/types' import {AuthStore} from './types' /** @internal */ export interface MockAuthStoreOptions { currentUser: CurrentUser | null client: SanityClient } /** * Creates a mock `AuthStore` (for testing) that emits...
3,598
0
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy
petrpan-code/sanity-io/sanity/packages/sanity/src/core/store/_legacy/authStore/index.ts
export * from './types' export * from './createAuthStore' export * from './createMockAuthStore' export * from './providerTitle'
3,599