@protobase/ui 0.40.0 → 0.40.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"file":"shared-protobase-ui-SkP04K7-.js","names":["useState","__toESM","require_react","require_jsx_runtime","useQuery","useQueryClient","keepPreviousData","useMeta","ChatThread","Section","diffStats","ActionCard","FieldList","RelationPicker","protobaseVersion","useRecord","useList","uiFromModule","usePlugin","Textarea","Markdown","definePlugin","SidePanel","defineUi","useAdminMeta","AppLink","DiffView","CompactTable","useApiToken","Field","pluginApi","ResendCodeButton","CodeForm","AuthLayout","useAssistant","MenuSelect","ResponsiveDialog","PartView","useOptionalListDisplay","Button","useFacets","Spinner","ApiProvider","useHistogram","Input","useAssistantClient","ActionInputError","Form","SignInPrompt","ChatMessage","Composer","Token","buttonClass","useLayoutRecord","LogoMark","isConflict","useResourceClient","OtpInput","useSeries","useFieldControl","mergeUi","useUpdateRecord","keys","useListDisplay","Dialog","App","useClient","fetchLabels","AssistantDock","parseDiff","StepList","useBackendData","useAppAddress","Segmented","cn","import_jsx_runtime","RecordLink","rest","display","around","name","resource","row","recordKey","Choices","label","options","option","value","onChange","usePickedLabels","client","queryClient","sorted","ids","target","view","import_react","RecordPicker","resources","props","views","known","setKnown","fetched","labelOf","key","remember","current","chosen"],"sources":["../../../src/app/displays/record-link.tsx","../../../src/primitives/choices.tsx","../../../src/app/use-picked-labels.ts","../../../src/app/record-picker.tsx"],"sourcesContent":["import type { AnchorHTMLAttributes } from 'react'\nimport type { KeyValue } from '@protobase/schema'\nimport { useLayoutRecord } from '../pages/record-scope'\nimport { AppLink } from '../use-app-address'\nimport { useOptionalListDisplay } from './display-context'\nimport type { ListDisplayRow } from './list-displays'\n\ntype Target = { row: ListDisplayRow; resource?: never; recordKey?: never } | { row?: never; resource?: string; recordKey: KeyValue | readonly KeyValue[] }\n\n/**\n * A link to a record's page, through the app's addresses: a list display's `row`, or a `recordKey` of `resource`. The\n * resource defaults to the list display's or the record's around it, so a custom component never writes a path.\n */\nexport const RecordLink = ({ row, resource, recordKey, ...rest }: AnchorHTMLAttributes<HTMLAnchorElement> & Target) => {\n const display = useOptionalListDisplay()\n const around = useLayoutRecord()\n const name = resource ?? display?.resource ?? around?.model.name\n if (name === undefined) throw new Error('RecordLink needs a resource outside a list display or a record')\n return <AppLink to={{ kind: 'record', resource: name, key: row ? row.key : recordKey }} {...rest} />\n}\n","import type { ReactNode } from 'react'\nimport { cn } from '../lib/cn'\n\nexport type ChoiceOption<T extends string> = { value: T; label: string; description?: ReactNode; disabled?: boolean }\n\n/**\n * `name` groups the radio buttons, so that the arrow keys move between them; `label` names the group for screen\n * readers. A disabled option shows and cannot be chosen.\n */\nexport type ChoicesProps<T extends string> = { name: string; label?: string; options: Array<ChoiceOption<T>>; value: T | undefined; onChange: (value: T) => void }\n\n/** One of a few options, each a card of its own row with a line that says what it means; the chosen one is outlined. */\nexport const Choices = <T extends string>({ name, label, options, value, onChange }: ChoicesProps<T>) => (\n <div role=\"radiogroup\" aria-label={label} className=\"flex flex-col gap-2\">\n {options.map((option) => (\n <label\n key={option.value}\n className={cn(\n 'block rounded-lg border p-3 transition-colors has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-primary',\n option.disabled ? 'cursor-default bg-background opacity-60' : option.value === value ? 'cursor-pointer border-primary bg-primary-soft' : 'cursor-pointer bg-background hover:bg-surface',\n )}\n >\n <input type=\"radio\" name={name} value={option.value} checked={option.value === value} disabled={option.disabled} onChange={() => onChange(option.value)} className=\"sr-only\" />\n <span className={cn('block font-medium', option.value === value && 'text-primary-text')}>{option.label}</span>\n {option.description && <span className=\"mt-0.5 block text-xs leading-snug text-muted-foreground\">{option.description}</span>}\n </label>\n ))}\n </div>\n)\n","import { keepPreviousData, useQuery, useQueryClient } from '@tanstack/react-query'\nimport type { ResourceModel, ViewModel } from '@protobase/schema'\nimport { useClient } from '../data/api-provider'\nimport { keys } from '../data/query-keys'\nimport { fetchLabels, type Labels } from '../live/relation-labels'\n\n/** The names of the chosen records, fetched in one list call; the previous names stay while the next ones load. */\nexport const usePickedLabels = (target: ResourceModel, view: ViewModel | undefined, ids: string[]): Labels => {\n const client = useClient()\n const queryClient = useQueryClient()\n const sorted = [...new Set(ids)].sort()\n const labels = useQuery({\n queryKey: keys.pickedLabels(target.name, sorted.join(',')),\n enabled: sorted.length > 0,\n placeholderData: keepPreviousData,\n queryFn: () => fetchLabels(queryClient, client, target, sorted, view),\n })\n return labels.data ?? new Map()\n}\n","import { useState } from 'react'\nimport { Token } from '../primitives/token'\nimport { useAdminMeta } from './meta-gate'\nimport { RelationPicker } from './relation-picker'\nimport { usePickedLabels } from './use-picked-labels'\n\ntype One = {\n multiple?: false\n /** The chosen record's key, as text; `undefined` for none. */\n value: string | undefined\n onChange: (key: string) => void\n}\n\ntype Several = {\n multiple: true\n /** The chosen records' keys, as text. */\n value: string[]\n onChange: (keys: string[]) => void\n}\n\nexport type RecordPickerProps = (One | Several) & {\n /** The name of the resource whose records it picks. */\n resource: string\n invalid?: boolean\n}\n\n/**\n * Picks records of a resource of the app with the create form's relation picker: type to narrow them by their search\n * fields or title, scroll for more, choose with the mouse or the keyboard. With `multiple`, each choice is added as a\n * token that can be taken off again, and choosing a chosen record takes it off.\n */\nexport const RecordPicker = (props: RecordPickerProps) => {\n const { resources, views } = useAdminMeta()\n const target = resources[props.resource]\n if (!target) throw new Error(`RecordPicker: the app has no resource named \"${props.resource}\"`)\n if (target.primaryKey.length !== 1) throw new Error(`RecordPicker: \"${props.resource}\" has a composite key, which a picker cannot name`)\n const view = views[props.resource]\n const keys = props.multiple ? props.value : props.value === undefined ? [] : [props.value]\n // The names of records chosen here, so a choice shows its name before the names are fetched.\n const [known, setKnown] = useState<Record<string, string>>({})\n const fetched = usePickedLabels(target, view, keys)\n const labelOf = (key: string) => known[key] ?? fetched.get(key) ?? key\n const remember = (key: string, label: string) => setKnown((current) => ({ ...current, [key]: label }))\n\n if (!props.multiple) {\n const { value, onChange } = props\n return (\n <RelationPicker\n target={target}\n view={view}\n value={value ?? ''}\n label={value === undefined ? undefined : labelOf(value)}\n invalid={props.invalid}\n onChange={(key, label) => {\n remember(key, label)\n onChange(key)\n }}\n />\n )\n }\n\n const { value, onChange } = props\n return (\n <div className=\"flex flex-col gap-2\">\n <RelationPicker\n target={target}\n view={view}\n value=\"\"\n chosen={value}\n several\n invalid={props.invalid}\n onChange={(key, label) => {\n remember(key, label)\n onChange(value.includes(key) ? value.filter((chosen) => chosen !== key) : [...value, key])\n }}\n />\n {value.length > 0 && (\n <div className=\"flex flex-wrap gap-1\">\n {value.map((key) => (\n <Token key={key} label={labelOf(key)} onRemove={() => onChange(value.filter((chosen) => chosen !== key))} />\n ))}\n </div>\n )}\n </div>\n )\n}\n"],"mappings":"+wBAaa4E,IAAc,CAAE,MAAK,WAAU,YAAW,GAAGC,KAA6D,CACrH,IAAMC,EAAUxC,EAAuB,EACjCyC,EAAS1B,EAAgB,EACzB2B,EAAOC,GAAYH,GAAS,UAAYC,GAAQ,MAAM,KAC5D,GAAIC,IAAS,IAAA,GAAW,MAAU,MAAM,gEAAgE,EACxG,OAAO,EAAAL,EAAA,IAAA,CAAClD,EAAD,CAAS,GAAI,CAAE,KAAM,SAAU,SAAUuD,EAAM,IAAKE,EAAMA,EAAI,IAAMC,CAAU,EAAG,GAAIN,CAAO,CAAA,CACrG,ECPaO,IAA6B,CAAE,OAAM,QAAO,UAAS,QAAO,eACvE,EAAAT,EAAA,IAAA,CAAC,MAAD,CAAK,KAAK,aAAa,aAAYU,EAAO,UAAU,sBACjD,SAAAC,EAAQ,IAAK,IACZ,EAAAX,EAAA,KAAA,CAAC,QAAD,CAEE,UAAWD,EACT,0JACAa,EAAO,SAAW,0CAA4CA,EAAO,QAAUC,EAAQ,gDAAkD,+CAC3I,EALF,SAAA,EAOE,EAAAb,EAAA,IAAA,CAAC,QAAD,CAAO,KAAK,QAAc,OAAM,MAA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