@adula/ui 2.2.0 → 2.3.0
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.
- package/README.md +1 -1
- package/build/attachment-preview.json +1 -1
- package/build/breadcrumb.json +18 -0
- package/build/copy-button.json +21 -0
- package/build/data-table.json +3 -2
- package/build/dialog-param.json +17 -0
- package/build/dialog.json +1 -1
- package/build/file-input.json +21 -0
- package/build/list-filters.json +2 -2
- package/build/long-dialog.json +17 -0
- package/build/manifest.json +109 -69
- package/build/messages.json +2 -2
- package/build/record-assignments.json +3 -2
- package/build/record-collaboration.json +3 -2
- package/build/record-workflows.json +3 -2
- package/build/resource-actions.json +1 -1
- package/build/resource-bulk.json +1 -1
- package/build/resource-dashboard.json +1 -1
- package/build/resource-field.json +3 -2
- package/build/resource-form.json +2 -1
- package/build/resource-import.json +3 -2
- package/build/resource-page.json +2 -1
- package/build/resource-show.json +4 -2
- package/build/resource-surface.json +2 -1
- package/build/resource-value.json +4 -3
- package/build/slider.json +17 -0
- package/build/sortable-list.json +20 -0
- package/build/tabs.json +1 -1
- package/build/theme.css +48 -2
- package/build/user-avatar.json +17 -0
- package/package.json +1 -1
package/build/list-filters.json
CHANGED
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
{
|
|
21
21
|
"path": "registry/ui/list-filters.tsx",
|
|
22
22
|
"type": "registry:ui",
|
|
23
|
-
"content": "import { useEffect, useId, useRef, useState, type KeyboardEvent } from 'react'\nimport axios from 'axios'\nimport { ChevronDown, X } from 'lucide-react'\nimport type { CalendarPreference, ResourceField, ResourceList, SerializedRecord } from 'adula'\nimport { Badge } from '~/components/ui/badge'\nimport { Button } from '~/components/ui/button'\nimport { Checkbox } from '~/components/ui/checkbox'\nimport {\n Command,\n CommandEmpty,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n} from '~/components/ui/command'\nimport { Input } from '~/components/ui/input'\nimport { Popover, PopoverContent, PopoverTrigger } from '~/components/ui/popover'\nimport { FieldControl } from '~/components/ui/resource-field'\nimport { useMessages, type Translate } from '~/components/ui/messages'\nimport {\n CURRENCY_LABEL,\n PERCENT_LABEL,\n fieldOptions,\n formatDate,\n formatDatetime,\n inputValue,\n moneyDisplay,\n optionLabel,\n parseValue,\n relationLabel,\n type Option,\n} from '~/components/ui/resource-value'\nimport { decimalDisplay, decimalScale } from '~/components/ui/field_values'\nimport {\n FILTER_IN_LIMIT,\n choiceFilter,\n chosenValues,\n filterAllowed,\n filterMode,\n inclusiveDatetime,\n normalizeFilter,\n singleChoice,\n type FieldFilter,\n} from '~/components/ui/list_query'\n\n/** Labels of chosen related records, remembered so chips stay readable after a reload. */\nexport type FilterLabels = Record<string, Record<string, string>>\n\n/**\n * A bound or value as the user reads it: lookup or option label, record title, formatted\n * date, amount, decimal or percent.\n */\nexport function filterValueLabel(\n field: ResourceField,\n value: string,\n context: {\n options?: Option[]\n related?: SerializedRecord[]\n labels?: Record<string, string>\n calendar: CalendarPreference\n t: Translate\n /** The interface language of option labels and number formats; Arabic by default. */\n language?: string\n }\n) {\n const language = context.language ?? 'ar'\n switch (field.type) {\n case 'lookup':\n return context.options?.find((option) => option.value === value)?.label ?? value\n case 'enum':\n case 'multiSelect':\n return optionLabel(field, value, language)\n case 'boolean':\n return value === 'true' ? context.t('نعم') : context.t('لا')\n case 'belongsTo':\n case 'user':\n case 'manyToMany': {\n const row = context.related?.find((item) => String(item.id) === value)\n return context.labels?.[value] ?? (row ? relationLabel(row, value) : `#${value}`)\n }\n case 'money':\n return `${moneyDisplay(value)} ${context.t(CURRENCY_LABEL)}`\n case 'decimal':\n return decimalDisplay(value, decimalScale(field), language)\n case 'percent':\n return `${decimalDisplay(value, decimalScale(field), language)}${context.t(PERCENT_LABEL)}`\n case 'date':\n return formatDate(value, context.calendar)\n case 'datetime':\n return formatDatetime(value, context.calendar)\n default:\n return value\n }\n}\n\n/** The chip text of one active filter, without the field label. */\nexport function describeFilter(filter: FieldFilter, value: (raw: string) => string, t: Translate) {\n switch (filter.op) {\n case 'eq':\n return value(filter.value)\n case 'in':\n return filter.values.map(value).join(t('، '))\n case 'range':\n if (filter.gte && filter.lte)\n return t('من {from} إلى {to}', {\n from: value(filter.gte),\n to: value(filter.lte),\n })\n return filter.gte\n ? t('من {from}', { from: value(filter.gte) })\n : t('إلى {to}', { to: value(filter.lte ?? '') })\n case 'empty':\n return filter.empty ? t('فارغ') : t('غير فارغ')\n }\n}\n\n/**\n * One field's filter: «أيٌّ من» for lookups, options, text and related records, «يحتوي على»\n * one option or linked record for multiSelect and manyToMany, «من / إلى» for numbers,\n * amounts, decimals, percents and dates, نعم/لا for booleans and «فارغ / غير فارغ» for\n * every field. Changes stay a draft until «تطبيق».\n */\nexport function FilterControl({\n resource,\n field,\n filter,\n options,\n related,\n labels,\n onRemember,\n onApply,\n}: {\n resource: string\n field: ResourceField\n filter?: FieldFilter\n options?: Option[]\n related?: SerializedRecord[]\n labels?: Record<string, string>\n onRemember?: (choices: Option[]) => void\n onApply: (filter: FieldFilter | null) => void\n}) {\n const { t, label, locale } = useMessages()\n const [open, setOpen] = useState(false)\n const [draft, setDraft] = useState<FieldFilter | null>(filter ?? null)\n const [error, setError] = useState('')\n const mode = filterMode(field.type)\n const name = label(field.label)\n const id = `filter-${field.key}`\n const count = filter?.op === 'in' ? filter.values.length : filter ? 1 : 0\n const apply = (next: FieldFilter | null) => {\n setError('')\n if (next?.op === 'in' && next.values.length > FILTER_IN_LIMIT) {\n setError(t('يمكن اختيار {count} قيمة كحد أقصى.', { count: FILTER_IN_LIMIT }))\n return\n }\n if (next && !filterAllowed(field.type, next)) {\n setError(t('لا يدعم هذا الحقل هذا النوع من التصفية.'))\n return\n }\n setOpen(false)\n onApply(normalizeFilter(next))\n }\n const empty = draft?.op === 'empty' ? draft.empty : null\n return (\n <Popover\n open={open}\n onOpenChange={(next) => {\n setOpen(next)\n if (next) {\n setDraft(filter ?? null)\n setError('')\n }\n }}\n >\n <PopoverTrigger asChild>\n <Button\n id={id}\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n aria-label={t('تصفية {field}', { field: name })}\n className={`h-9 gap-2 text-xs font-normal ${filter ? 'border-primary/60' : ''}`}\n >\n {name}\n {count > 0 && (\n <Badge variant=\"secondary\" className=\"h-5 px-1.5 tabular-nums\">\n {count}\n </Badge>\n )}\n <ChevronDown className=\"opacity-50\" />\n </Button>\n </PopoverTrigger>\n <PopoverContent className=\"w-72 p-0\" align=\"start\">\n <div className=\"border-b px-3 py-2 text-xs font-medium\">\n {t('تصفية {field}', { field: name })}\n </div>\n <div className=\"p-3\">\n {mode === 'boolean' ? (\n <div role=\"group\" aria-label={name} className=\"flex gap-2\">\n {(['true', 'false'] as const).map((value) => {\n const on = draft?.op === 'eq' && draft.value === value\n return (\n <Button\n key={value}\n type=\"button\"\n size=\"sm\"\n variant={on ? 'default' : 'outline'}\n aria-pressed={on}\n className=\"flex-1\"\n onClick={() => setDraft(on ? null : { op: 'eq', value })}\n >\n {value === 'true' ? t('نعم') : t('لا')}\n </Button>\n )\n })}\n </div>\n ) : mode === 'range' ? (\n <RangeInputs\n field={field}\n filter={draft?.op === 'range' ? draft : undefined}\n onChange={(next) => setDraft(next)}\n onError={setError}\n />\n ) : mode === 'choice' && LISTED.has(field.type) ? (\n <ChoiceList\n resource={resource}\n field={field}\n values={chosenValues(draft ?? undefined)}\n options={\n field.type === 'enum' || field.type === 'multiSelect'\n ? fieldOptions(field, locale)\n : options\n }\n related={related}\n labels={labels}\n onRemember={onRemember}\n onChange={(values) => setDraft(choiceFilter(field.type, values))}\n />\n ) : mode === 'choice' ? (\n <TextValues\n name={name}\n values={chosenValues(draft ?? undefined)}\n onChange={(values) => setDraft({ op: 'in', values })}\n />\n ) : (\n <Input\n aria-label={t('قيمة {field}', { field: name })}\n className=\"h-9 text-xs\"\n value={draft?.op === 'eq' ? draft.value : ''}\n onChange={(event) => setDraft({ op: 'eq', value: event.target.value })}\n onKeyDown={(event) => {\n if (event.key === 'Enter') {\n event.preventDefault()\n apply(draft)\n }\n }}\n />\n )}\n <div\n role=\"group\"\n aria-label={t('القيم الفارغة')}\n className=\"mt-3 flex gap-2 border-t pt-3\"\n >\n {[true, false].map((value) => (\n <Button\n key={String(value)}\n type=\"button\"\n size=\"sm\"\n variant={empty === value ? 'secondary' : 'ghost'}\n aria-pressed={empty === value}\n className=\"h-7 flex-1 text-xs\"\n onClick={() => setDraft(empty === value ? null : { op: 'empty', empty: value })}\n >\n {value ? t('فارغ') : t('غير فارغ')}\n </Button>\n ))}\n </div>\n {error && (\n <p role=\"alert\" className=\"mt-2 text-xs text-destructive\">\n {error}\n </p>\n )}\n </div>\n <div className=\"flex justify-between gap-2 border-t px-3 py-2\">\n <Button type=\"button\" variant=\"ghost\" size=\"sm\" onClick={() => apply(null)}>\n {t('إزالة التصفية')}\n </Button>\n <Button type=\"button\" size=\"sm\" onClick={() => apply(draft)}>\n {t('تطبيق')}\n </Button>\n </div>\n </PopoverContent>\n </Popover>\n )\n}\n\n/** Choice fields whose values come from a list: lookups, options or related records. */\nconst LISTED = new Set(['lookup', 'enum', 'multiSelect', 'belongsTo', 'user', 'manyToMany'])\n/** Related records searched through the target resource's list route. */\nconst REMOTE = new Set(['belongsTo', 'user', 'manyToMany'])\n\n/**\n * Inclusive bounds; dates use the field's own control, so the calendar preference applies.\n * Numbers accept Arabic-Indic digits and the Arabic decimal separator (parseValue).\n */\nfunction RangeInputs({\n field,\n filter,\n onChange,\n onError,\n}: {\n field: ResourceField\n filter?: FieldFilter & { op: 'range' }\n onChange: (filter: FieldFilter | null) => void\n onError: (message: string) => void\n}) {\n const { t, label } = useMessages()\n const [text, setText] = useState({\n gte: filter?.gte ? inputValue(field, filter.gte) : '',\n lte: filter?.lte ? inputValue(field, filter.lte) : '',\n })\n const bound = (raw: string, side: 'gte' | 'lte') => {\n const parsed = parseValue(field, field.type === 'datetime' ? inclusiveDatetime(raw, side) : raw)\n return parsed === null || parsed === undefined ? undefined : String(parsed)\n }\n const change = (side: 'gte' | 'lte', raw: string) => {\n const next = { ...text, [side]: raw }\n setText(next)\n try {\n onError('')\n onChange({ op: 'range', gte: bound(next.gte, 'gte'), lte: bound(next.lte, 'lte') })\n } catch (error) {\n // Keep partial input; the previous valid bounds stay in the draft.\n onError(error instanceof Error ? t(error.message) : t('قيمة غير صالحة'))\n }\n }\n const name = label(field.label)\n const dated = field.type === 'date' || field.type === 'datetime'\n return (\n <div className=\"grid gap-3\">\n {(['gte', 'lte'] as const).map((side) => {\n const caption = side === 'gte' ? t('من') : t('إلى')\n const id = `filter-${field.key}-${side}`\n return (\n <label key={side} htmlFor={id} className=\"grid gap-1 text-xs text-muted-foreground\">\n {caption}\n {dated ? (\n <FieldControl\n field={field}\n id={id}\n value={text[side]}\n label={t('{bound} · {field}', { bound: caption, field: name })}\n onChange={(raw) => change(side, raw)}\n />\n ) : (\n <Input\n id={id}\n dir=\"ltr\"\n inputMode={field.type === 'integer' ? 'numeric' : 'decimal'}\n className=\"h-9 text-xs tabular-nums\"\n value={text[side]}\n onChange={(event) => change(side, event.target.value)}\n />\n )}\n </label>\n )\n })}\n </div>\n )\n}\n\n/**\n * «أيٌّ من»: lookup or field options, or related records searched through the server. A\n * multiSelect or manyToMany filter is «يحتوي على» one option or record.\n */\nfunction ChoiceList({\n resource,\n field,\n values,\n options,\n related = [],\n labels = {},\n onRemember,\n onChange,\n}: {\n resource: string\n field: ResourceField\n values: string[]\n options?: Option[]\n related?: SerializedRecord[]\n labels?: Record<string, string>\n onRemember?: (choices: Option[]) => void\n onChange: (values: string[]) => void\n}) {\n const { t, label } = useMessages()\n const remote = REMOTE.has(field.type)\n const single = singleChoice(field.type)\n const [term, setTerm] = useState('')\n const [found, setFound] = useState<Option[] | null>(null)\n const [busy, setBusy] = useState(false)\n const timer = useRef<ReturnType<typeof setTimeout>>(undefined)\n const listId = useId()\n const load = async (search: string) => {\n setBusy(true)\n try {\n let choices: Option[]\n if (field.type === 'user') {\n const users = await axios.get<{ data: Option[] }>(\n `/resources/${resource}/options/${field.key}`,\n {\n params: { purpose: 'filter', ...(search ? { search } : {}) },\n headers: { Accept: 'application/json' },\n }\n )\n choices = users.data.data\n } else {\n const target = (field as ResourceField & { resource?: string }).resource\n const response = await axios.get<ResourceList>(`/resources/${target}`, {\n params: {\n limit: 50,\n estimate: 'false',\n ...(search ? { search } : {}),\n },\n headers: { Accept: 'application/json' },\n })\n choices = response.data.data.map((row) => ({\n value: String(row.id),\n label: relationLabel(row, row.id),\n }))\n }\n setFound(choices)\n onRemember?.(choices)\n } catch {\n setFound([])\n } finally {\n setBusy(false)\n }\n }\n // The list mounts when the popover opens; related records load once per opening.\n const first = useRef(load)\n useEffect(() => {\n if (remote) void first.current('')\n }, [remote])\n const known = new Map<string, string>()\n for (const row of related) known.set(String(row.id), relationLabel(row, row.id))\n for (const [value, text] of Object.entries(labels)) known.set(value, text)\n const base = remote ? (found ?? []) : (options ?? [])\n // Chosen values stay listed even when the current search does not return them.\n const listed = [\n ...values\n .filter((value) => !base.some((option) => option.value === value))\n .map((value) => ({ value, label: known.get(value) ?? `#${value}` })),\n ...base.filter((option) => String(option.value) !== ''),\n ]\n const toggle = (value: string) =>\n onChange(\n values.includes(value) ? values.filter((entry) => entry !== value) : [...values, value]\n )\n return (\n <div className=\"grid gap-2\">\n <span className=\"text-xs text-muted-foreground\">\n {single ? t('يحتوي على') : t('أيٌّ من')}\n </span>\n <Command shouldFilter={!remote} className=\"rounded-md border\">\n <CommandInput\n placeholder={remote ? t('ابحث في السجلات المرتبطة') : t('ابحث في الخيارات')}\n aria-label={t('البحث في {field}', { field: label(field.label) })}\n value={term}\n onValueChange={(next) => {\n setTerm(next)\n if (!remote) return\n clearTimeout(timer.current)\n timer.current = setTimeout(() => void load(next), 300)\n }}\n />\n <CommandList id={listId} className=\"max-h-56\">\n <CommandEmpty>{busy ? t('جارٍ البحث...') : t('لا توجد خيارات مطابقة')}</CommandEmpty>\n <CommandGroup>\n {listed.map((option) => {\n const on = values.includes(option.value)\n return (\n <CommandItem\n key={option.value}\n value={remote ? option.value : `${option.label} ${option.value}`}\n aria-checked={on}\n onSelect={() => toggle(option.value)}\n >\n <Checkbox\n checked={on}\n tabIndex={-1}\n aria-hidden\n className=\"pointer-events-none\"\n />\n <span className=\"truncate\">{option.label}</span>\n </CommandItem>\n )\n })}\n </CommandGroup>\n </CommandList>\n </Command>\n </div>\n )\n}\n\n/** «أيٌّ من» for free text: Enter adds a value; each value is removable. */\nfunction TextValues({\n name,\n values,\n onChange,\n}: {\n name: string\n values: string[]\n onChange: (values: string[]) => void\n}) {\n const { t } = useMessages()\n const [text, setText] = useState('')\n const add = (event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key !== 'Enter') return\n event.preventDefault()\n const value = text.trim()\n if (value && !values.includes(value)) onChange([...values, value])\n setText('')\n }\n return (\n <div className=\"grid gap-2\">\n <span className=\"text-xs text-muted-foreground\">{t('أيٌّ من')}</span>\n <Input\n aria-label={t('قيمة {field}', { field: name })}\n className=\"h-9 text-xs\"\n value={text}\n placeholder={t('اكتب قيمة ثم اضغط Enter')}\n onChange={(event) => setText(event.target.value)}\n onKeyDown={add}\n />\n {values.length > 0 && (\n <ul className=\"flex flex-wrap gap-1\">\n {values.map((value) => (\n <li key={value}>\n <Badge variant=\"secondary\" className=\"gap-1 font-normal\">\n {value}\n <button\n type=\"button\"\n aria-label={t('إزالة {value}', { value })}\n className=\"text-muted-foreground hover:text-foreground\"\n onClick={() => onChange(values.filter((entry) => entry !== value))}\n >\n <X size={12} />\n </button>\n </Badge>\n </li>\n ))}\n </ul>\n )}\n </div>\n )\n}\n",
|
|
23
|
+
"content": "import { useEffect, useId, useRef, useState, type KeyboardEvent } from 'react'\nimport axios from 'axios'\nimport { ChevronDown, X } from 'lucide-react'\nimport type { CalendarPreference, ResourceField, ResourceList, SerializedRecord } from 'adula'\nimport { Badge } from '~/components/ui/badge'\nimport { Button } from '~/components/ui/button'\nimport { Checkbox } from '~/components/ui/checkbox'\nimport {\n Command,\n CommandEmpty,\n CommandGroup,\n CommandInput,\n CommandItem,\n CommandList,\n} from '~/components/ui/command'\nimport { Input } from '~/components/ui/input'\nimport { Popover, PopoverContent, PopoverTrigger } from '~/components/ui/popover'\nimport { FieldControl } from '~/components/ui/resource-field'\nimport { useMessages, type Translate } from '~/components/ui/messages'\nimport {\n CURRENCY_LABEL,\n PERCENT_LABEL,\n fieldOptions,\n formatDate,\n formatDatetime,\n inputValue,\n moneyDisplay,\n optionLabel,\n parseValue,\n relationLabel,\n type Option,\n} from '~/components/ui/resource-value'\nimport { decimalDisplay, decimalScale } from '~/components/ui/field_values'\nimport {\n FILTER_IN_LIMIT,\n choiceFilter,\n chosenValues,\n filterAllowed,\n filterMode,\n inclusiveDatetime,\n normalizeFilter,\n singleChoice,\n type FieldFilter,\n} from '~/components/ui/list_query'\n\n/** Labels of chosen related records, remembered so chips stay readable after a reload. */\nexport type FilterLabels = Record<string, Record<string, string>>\n\n/**\n * A bound or value as the user reads it: lookup or option label, record title, formatted\n * date, amount, decimal or percent.\n */\nexport function filterValueLabel(\n field: ResourceField,\n value: string,\n context: {\n options?: Option[]\n related?: SerializedRecord[]\n labels?: Record<string, string>\n calendar: CalendarPreference\n t: Translate\n /** The interface language of option labels and number formats; Arabic by default. */\n language?: string\n }\n) {\n const language = context.language ?? 'ar'\n switch (field.type) {\n case 'lookup':\n return context.options?.find((option) => option.value === value)?.label ?? value\n case 'enum':\n case 'multiSelect':\n return optionLabel(field, value, language)\n case 'boolean':\n return value === 'true' ? context.t('نعم') : context.t('لا')\n case 'belongsTo':\n case 'user':\n case 'manyToMany': {\n const row = context.related?.find((item) => String(item.id) === value)\n return context.labels?.[value] ?? (row ? relationLabel(row, value) : `#${value}`)\n }\n case 'money':\n return `${moneyDisplay(value)} ${context.t(CURRENCY_LABEL)}`\n case 'decimal':\n return decimalDisplay(value, decimalScale(field), language)\n case 'percent':\n return `${decimalDisplay(value, decimalScale(field), language)}${context.t(PERCENT_LABEL)}`\n case 'date':\n return formatDate(value, context.calendar)\n case 'datetime':\n return formatDatetime(value, context.calendar)\n default:\n return value\n }\n}\n\n/** The chip text of one active filter, without the field label. */\nexport function describeFilter(filter: FieldFilter, value: (raw: string) => string, t: Translate) {\n switch (filter.op) {\n case 'eq':\n return value(filter.value)\n case 'in':\n return filter.values.map(value).join(t('، '))\n case 'range':\n if (filter.gte && filter.lte)\n return t('من {from} إلى {to}', {\n from: value(filter.gte),\n to: value(filter.lte),\n })\n return filter.gte\n ? t('من {from}', { from: value(filter.gte) })\n : t('إلى {to}', { to: value(filter.lte ?? '') })\n case 'empty':\n return filter.empty ? t('فارغ') : t('غير فارغ')\n }\n}\n\n/**\n * One field's filter: «أيٌّ من» for lookups, options, text and related records, «يحتوي على»\n * one option or linked record for multiSelect and manyToMany, «من / إلى» for numbers,\n * amounts, decimals, percents and dates, نعم/لا for booleans and «فارغ / غير فارغ» for\n * every field. Changes stay a draft until «تطبيق».\n */\nexport function FilterControl({\n resource,\n field,\n filter,\n options,\n related,\n labels,\n onRemember,\n onApply,\n}: {\n resource: string\n field: ResourceField\n filter?: FieldFilter\n options?: Option[]\n related?: SerializedRecord[]\n labels?: Record<string, string>\n onRemember?: (choices: Option[]) => void\n onApply: (filter: FieldFilter | null) => void\n}) {\n const { t, label, locale } = useMessages()\n const [open, setOpen] = useState(false)\n const [draft, setDraft] = useState<FieldFilter | null>(filter ?? null)\n const [error, setError] = useState('')\n const mode = filterMode(field.type)\n const name = label(field.label)\n const id = `filter-${field.key}`\n const count = filter?.op === 'in' ? filter.values.length : filter ? 1 : 0\n const apply = (next: FieldFilter | null) => {\n setError('')\n if (next?.op === 'in' && next.values.length > FILTER_IN_LIMIT) {\n setError(t('يمكن اختيار {count} قيمة كحد أقصى.', { count: FILTER_IN_LIMIT }))\n return\n }\n if (next && !filterAllowed(field.type, next)) {\n setError(t('لا يدعم هذا الحقل هذا النوع من التصفية.'))\n return\n }\n setOpen(false)\n onApply(normalizeFilter(next))\n }\n const empty = draft?.op === 'empty' ? draft.empty : null\n return (\n <Popover\n open={open}\n onOpenChange={(next) => {\n setOpen(next)\n if (next) {\n setDraft(filter ?? null)\n setError('')\n }\n }}\n >\n <PopoverTrigger asChild>\n <Button\n id={id}\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n aria-label={t('تصفية {field}', { field: name })}\n className={`h-9 gap-2 text-xs font-normal ${filter ? 'border-primary/60' : ''}`}\n >\n {name}\n {count > 0 && (\n <Badge variant=\"secondary\" className=\"h-5 px-1.5 tabular-nums\">\n {count}\n </Badge>\n )}\n <ChevronDown className=\"opacity-50\" />\n </Button>\n </PopoverTrigger>\n <PopoverContent className=\"w-72 p-0\" align=\"start\">\n <div className=\"border-b px-3 py-2 text-xs font-medium\">\n {t('تصفية {field}', { field: name })}\n </div>\n <div className=\"p-3\">\n {mode === 'boolean' ? (\n <div role=\"group\" aria-label={name} className=\"flex gap-2\">\n {(['true', 'false'] as const).map((value) => {\n const on = draft?.op === 'eq' && draft.value === value\n return (\n <Button\n key={value}\n type=\"button\"\n size=\"sm\"\n variant={on ? 'default' : 'outline'}\n aria-pressed={on}\n className=\"flex-1\"\n onClick={() => setDraft(on ? null : { op: 'eq', value })}\n >\n {value === 'true' ? t('نعم') : t('لا')}\n </Button>\n )\n })}\n </div>\n ) : mode === 'range' ? (\n <RangeInputs\n field={field}\n filter={draft?.op === 'range' ? draft : undefined}\n onChange={(next) => setDraft(next)}\n onError={setError}\n />\n ) : mode === 'choice' && LISTED.has(field.type) ? (\n <ChoiceList\n resource={resource}\n field={field}\n values={chosenValues(draft ?? undefined)}\n options={\n field.type === 'enum' || field.type === 'multiSelect'\n ? fieldOptions(field, locale)\n : options\n }\n related={related}\n labels={labels}\n onRemember={onRemember}\n onChange={(values) => setDraft(choiceFilter(field.type, values))}\n />\n ) : mode === 'choice' ? (\n <TextValues\n name={name}\n values={chosenValues(draft ?? undefined)}\n onChange={(values) => setDraft({ op: 'in', values })}\n />\n ) : (\n <Input\n aria-label={t('قيمة {field}', { field: name })}\n className=\"h-9 text-xs\"\n value={draft?.op === 'eq' ? draft.value : ''}\n onChange={(event) => setDraft({ op: 'eq', value: event.target.value })}\n onKeyDown={(event) => {\n if (event.key === 'Enter') {\n event.preventDefault()\n apply(draft)\n }\n }}\n />\n )}\n <div\n role=\"group\"\n aria-label={t('القيم الفارغة')}\n className=\"mt-3 flex gap-2 border-t pt-3\"\n >\n {[true, false].map((value) => (\n <Button\n key={String(value)}\n type=\"button\"\n size=\"xs\"\n variant={empty === value ? 'secondary' : 'ghost'}\n aria-pressed={empty === value}\n className=\"flex-1\"\n onClick={() => setDraft(empty === value ? null : { op: 'empty', empty: value })}\n >\n {value ? t('فارغ') : t('غير فارغ')}\n </Button>\n ))}\n </div>\n {error && (\n <p role=\"alert\" className=\"mt-2 text-xs text-destructive\">\n {error}\n </p>\n )}\n </div>\n <div className=\"flex justify-between gap-2 border-t px-3 py-2\">\n <Button type=\"button\" variant=\"ghost\" size=\"sm\" onClick={() => apply(null)}>\n {t('إزالة التصفية')}\n </Button>\n <Button type=\"button\" size=\"sm\" onClick={() => apply(draft)}>\n {t('تطبيق')}\n </Button>\n </div>\n </PopoverContent>\n </Popover>\n )\n}\n\n/** Choice fields whose values come from a list: lookups, options or related records. */\nconst LISTED = new Set(['lookup', 'enum', 'multiSelect', 'belongsTo', 'user', 'manyToMany'])\n/** Related records searched through the target resource's list route. */\nconst REMOTE = new Set(['belongsTo', 'user', 'manyToMany'])\n\n/**\n * Inclusive bounds; dates use the field's own control, so the calendar preference applies.\n * Numbers accept Arabic-Indic digits and the Arabic decimal separator (parseValue).\n */\nfunction RangeInputs({\n field,\n filter,\n onChange,\n onError,\n}: {\n field: ResourceField\n filter?: FieldFilter & { op: 'range' }\n onChange: (filter: FieldFilter | null) => void\n onError: (message: string) => void\n}) {\n const { t, label } = useMessages()\n const [text, setText] = useState({\n gte: filter?.gte ? inputValue(field, filter.gte) : '',\n lte: filter?.lte ? inputValue(field, filter.lte) : '',\n })\n const bound = (raw: string, side: 'gte' | 'lte') => {\n const parsed = parseValue(field, field.type === 'datetime' ? inclusiveDatetime(raw, side) : raw)\n return parsed === null || parsed === undefined ? undefined : String(parsed)\n }\n const change = (side: 'gte' | 'lte', raw: string) => {\n const next = { ...text, [side]: raw }\n setText(next)\n try {\n onError('')\n onChange({ op: 'range', gte: bound(next.gte, 'gte'), lte: bound(next.lte, 'lte') })\n } catch (error) {\n // Keep partial input; the previous valid bounds stay in the draft.\n onError(error instanceof Error ? t(error.message) : t('قيمة غير صالحة'))\n }\n }\n const name = label(field.label)\n const dated = field.type === 'date' || field.type === 'datetime'\n return (\n <div className=\"grid gap-3\">\n {(['gte', 'lte'] as const).map((side) => {\n const caption = side === 'gte' ? t('من') : t('إلى')\n const id = `filter-${field.key}-${side}`\n return (\n <label key={side} htmlFor={id} className=\"grid gap-1 text-xs text-muted-foreground\">\n {caption}\n {dated ? (\n <FieldControl\n field={field}\n id={id}\n value={text[side]}\n label={t('{bound} · {field}', { bound: caption, field: name })}\n onChange={(raw) => change(side, raw)}\n />\n ) : (\n <Input\n id={id}\n dir=\"ltr\"\n inputMode={field.type === 'integer' ? 'numeric' : 'decimal'}\n className=\"h-9 text-xs tabular-nums\"\n value={text[side]}\n onChange={(event) => change(side, event.target.value)}\n />\n )}\n </label>\n )\n })}\n </div>\n )\n}\n\n/**\n * «أيٌّ من»: lookup or field options, or related records searched through the server. A\n * multiSelect or manyToMany filter is «يحتوي على» one option or record.\n */\nfunction ChoiceList({\n resource,\n field,\n values,\n options,\n related = [],\n labels = {},\n onRemember,\n onChange,\n}: {\n resource: string\n field: ResourceField\n values: string[]\n options?: Option[]\n related?: SerializedRecord[]\n labels?: Record<string, string>\n onRemember?: (choices: Option[]) => void\n onChange: (values: string[]) => void\n}) {\n const { t, label } = useMessages()\n const remote = REMOTE.has(field.type)\n const single = singleChoice(field.type)\n const [term, setTerm] = useState('')\n const [found, setFound] = useState<Option[] | null>(null)\n const [busy, setBusy] = useState(false)\n const timer = useRef<ReturnType<typeof setTimeout>>(undefined)\n const listId = useId()\n const load = async (search: string) => {\n setBusy(true)\n try {\n let choices: Option[]\n if (field.type === 'user') {\n const users = await axios.get<{ data: Option[] }>(\n `/resources/${resource}/options/${field.key}`,\n {\n params: { purpose: 'filter', ...(search ? { search } : {}) },\n headers: { Accept: 'application/json' },\n }\n )\n choices = users.data.data\n } else {\n const target = (field as ResourceField & { resource?: string }).resource\n const response = await axios.get<ResourceList>(`/resources/${target}`, {\n params: {\n limit: 50,\n estimate: 'false',\n ...(search ? { search } : {}),\n },\n headers: { Accept: 'application/json' },\n })\n choices = response.data.data.map((row) => ({\n value: String(row.id),\n label: relationLabel(row, row.id),\n }))\n }\n setFound(choices)\n onRemember?.(choices)\n } catch {\n setFound([])\n } finally {\n setBusy(false)\n }\n }\n // The list mounts when the popover opens; related records load once per opening.\n const first = useRef(load)\n useEffect(() => {\n if (remote) void first.current('')\n }, [remote])\n const known = new Map<string, string>()\n for (const row of related) known.set(String(row.id), relationLabel(row, row.id))\n for (const [value, text] of Object.entries(labels)) known.set(value, text)\n const base = remote ? (found ?? []) : (options ?? [])\n // Chosen values stay listed even when the current search does not return them.\n const listed = [\n ...values\n .filter((value) => !base.some((option) => option.value === value))\n .map((value) => ({ value, label: known.get(value) ?? `#${value}` })),\n ...base.filter((option) => String(option.value) !== ''),\n ]\n const toggle = (value: string) =>\n onChange(\n values.includes(value) ? values.filter((entry) => entry !== value) : [...values, value]\n )\n return (\n <div className=\"grid gap-2\">\n <span className=\"text-xs text-muted-foreground\">\n {single ? t('يحتوي على') : t('أيٌّ من')}\n </span>\n <Command shouldFilter={!remote} className=\"rounded-md border\">\n <CommandInput\n placeholder={remote ? t('ابحث في السجلات المرتبطة') : t('ابحث في الخيارات')}\n aria-label={t('البحث في {field}', { field: label(field.label) })}\n value={term}\n onValueChange={(next) => {\n setTerm(next)\n if (!remote) return\n clearTimeout(timer.current)\n timer.current = setTimeout(() => void load(next), 300)\n }}\n />\n <CommandList id={listId} className=\"max-h-56\">\n <CommandEmpty>{busy ? t('جارٍ البحث...') : t('لا توجد خيارات مطابقة')}</CommandEmpty>\n <CommandGroup>\n {listed.map((option) => {\n const on = values.includes(option.value)\n return (\n <CommandItem\n key={option.value}\n value={remote ? option.value : `${option.label} ${option.value}`}\n aria-checked={on}\n onSelect={() => toggle(option.value)}\n >\n <Checkbox\n checked={on}\n tabIndex={-1}\n aria-hidden\n className=\"pointer-events-none\"\n />\n <span className=\"truncate\">{option.label}</span>\n </CommandItem>\n )\n })}\n </CommandGroup>\n </CommandList>\n </Command>\n </div>\n )\n}\n\n/** «أيٌّ من» for free text: Enter adds a value; each value is removable. */\nfunction TextValues({\n name,\n values,\n onChange,\n}: {\n name: string\n values: string[]\n onChange: (values: string[]) => void\n}) {\n const { t } = useMessages()\n const [text, setText] = useState('')\n const add = (event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key !== 'Enter') return\n event.preventDefault()\n const value = text.trim()\n if (value && !values.includes(value)) onChange([...values, value])\n setText('')\n }\n return (\n <div className=\"grid gap-2\">\n <span className=\"text-xs text-muted-foreground\">{t('أيٌّ من')}</span>\n <Input\n aria-label={t('قيمة {field}', { field: name })}\n className=\"h-9 text-xs\"\n value={text}\n placeholder={t('اكتب قيمة ثم اضغط Enter')}\n onChange={(event) => setText(event.target.value)}\n onKeyDown={add}\n />\n {values.length > 0 && (\n <ul className=\"flex flex-wrap gap-1\">\n {values.map((value) => (\n <li key={value}>\n <Badge variant=\"secondary\" className=\"gap-1 font-normal\">\n {value}\n <button\n type=\"button\"\n aria-label={t('إزالة {value}', { value })}\n className=\"text-muted-foreground hover:text-foreground\"\n onClick={() => onChange(values.filter((entry) => entry !== value))}\n >\n <X size={12} />\n </button>\n </Badge>\n </li>\n ))}\n </ul>\n )}\n </div>\n )\n}\n",
|
|
24
24
|
"target": "inertia/components/ui/list-filters.tsx"
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
"path": "registry/ui/list_query.ts",
|
|
28
28
|
"type": "registry:ui",
|
|
29
|
-
"content": "export const FILTER_IN_LIMIT = 50\nexport const BULK_LIMIT = 100\n/*\n * List query helpers shared by the data table (ADR 046): operator filters in the URL,\n * saved-view round trips, the server export link and server error messages. Pure and\n * import-free so the registry tests run it directly.\n */\n\n/** One active filter of a field; `eq` is the scalar equality the list always accepted. */\nexport type FieldFilter =\n | { op: 'eq'; value: string }\n | { op: 'in'; values: string[] }\n | { op: 'range'; gte?: string; lte?: string }\n | { op: 'empty'; empty: boolean }\n\n/** The shape a saved view stores for one field: a scalar or one operator object. */\nexport type SavedFilterValue =\n | string\n | number\n | boolean\n | null\n | { in: (string | number)[] }\n | { gte?: string | number; lte?: string | number }\n | { empty: boolean }\n\n/** How the filter control of a field type behaves. */\nexport type FilterMode = 'choice' | 'range' | 'boolean' | 'text'\n\nconst CHOICE = new Set([\n 'lookup',\n 'enum',\n 'belongsTo',\n 'user',\n 'string',\n 'text',\n 'email',\n 'phone',\n 'url',\n 'multiSelect',\n 'manyToMany',\n])\nconst RANGE = new Set(['integer', 'money', 'decimal', 'percent', 'date', 'datetime'])\n/** Several values per record: the server matches one member (equality) or emptiness only. */\nconst MEMBER = new Set(['multiSelect', 'manyToMany'])\n\nexport function filterMode(type: string): FilterMode {\n if (type === 'boolean') return 'boolean'\n if (RANGE.has(type)) return 'range'\n if (CHOICE.has(type)) return 'choice'\n return 'text'\n}\n\n/** Whether a choice filter picks one member (multiSelect, manyToMany) instead of «أيٌّ من». */\nexport function singleChoice(type: string) {\n return MEMBER.has(type)\n}\n\n/**\n * The draft of a choice control: «أيٌّ من» is `in`; a member filter keeps only the latest\n * choice as equality, since the server accepts no `in` for several-valued fields.\n */\nexport function choiceFilter(type: string, values: string[]): FieldFilter | null {\n const chosen = values.filter(Boolean)\n if (!singleChoice(type)) return { op: 'in', values: chosen }\n const last = chosen.at(-1)\n return last ? { op: 'eq', value: last } : null\n}\n\n/**\n * Whether the filter controls emit this operator for the field type, each one the server\n * accepts (ADR 046): `in` for choices except member fields, ranges for numbers and dates,\n * equality and emptiness for every type.\n */\nexport function filterAllowed(type: string, filter: FieldFilter) {\n switch (filter.op) {\n case 'eq':\n case 'empty':\n return true\n case 'in':\n return filterMode(type) === 'choice' && !singleChoice(type)\n case 'range':\n return filterMode(type) === 'range'\n }\n}\n\nconst prefix = (key: string) => `filters[${key}]`\n\n/** Reads the filters of the given field keys from the list URL. */\nexport function readFilters(params: URLSearchParams, keys: string[]) {\n const filters: Record<string, FieldFilter> = {}\n for (const key of keys) {\n const base = prefix(key)\n const empty = params.get(`${base}[empty]`)\n const list = params.getAll(`${base}[in][]`)\n const joined = params.get(`${base}[in]`)\n const gte = params.get(`${base}[gte]`)\n const lte = params.get(`${base}[lte]`)\n const value = params.get(base)\n if (empty === 'true' || empty === 'false')\n filters[key] = { op: 'empty', empty: empty === 'true' }\n else if (list.length || joined) {\n const values = (list.length ? list : joined!.split(','))\n .map((entry) => entry.trim())\n .filter(Boolean)\n if (values.length) filters[key] = { op: 'in', values }\n } else if (gte || lte)\n filters[key] = {\n op: 'range',\n ...(gte ? { gte } : {}),\n ...(lte ? { lte } : {}),\n }\n else if (value) filters[key] = { op: 'eq', value }\n }\n return filters\n}\n\n/** Removes every parameter of one field's filter, whatever its operator. */\nexport function clearFilter(params: URLSearchParams, key: string) {\n const base = prefix(key)\n for (const name of [...params.keys()])\n if (name === base || name.startsWith(`${base}[`)) params.delete(name)\n}\n\n/**\n * Writes one field's filter. A single choice stays plain equality; several are\n * `[in]=a,b`, or repeated `[in][]` when a value itself contains a comma.\n */\nexport function writeFilter(params: URLSearchParams, key: string, filter: FieldFilter | null) {\n clearFilter(params, key)\n if (!filter) return\n const base = prefix(key)\n switch (filter.op) {\n case 'eq':\n if (filter.value) params.set(base, filter.value)\n return\n case 'in': {\n const values = [...new Set(filter.values.filter(Boolean))]\n if (values.length === 1) params.set(base, values[0])\n else if (values.some((value) => value.includes(',')))\n for (const value of values) params.append(`${base}[in][]`, value)\n else if (values.length) params.set(`${base}[in]`, values.join(','))\n return\n }\n case 'range':\n if (filter.gte) params.set(`${base}[gte]`, filter.gte)\n if (filter.lte) params.set(`${base}[lte]`, filter.lte)\n return\n case 'empty':\n params.set(`${base}[empty]`, String(filter.empty))\n }\n}\n\n/** A filter with nothing to apply (no values, no bounds) is no filter. */\nexport function normalizeFilter(filter: FieldFilter | null): FieldFilter | null {\n if (!filter) return null\n if (filter.op === 'eq') return filter.value ? filter : null\n if (filter.op === 'in') {\n const values = [...new Set(filter.values.filter(Boolean))]\n if (!values.length) return null\n return values.length === 1 ? { op: 'eq', value: values[0] } : { op: 'in', values }\n }\n if (filter.op === 'range') {\n if (!filter.gte && !filter.lte) return null\n return {\n op: 'range',\n ...(filter.gte ? { gte: filter.gte } : {}),\n ...(filter.lte ? { lte: filter.lte } : {}),\n }\n }\n return filter\n}\n\n/** The values a choice control shows as selected. */\nexport function chosenValues(filter: FieldFilter | undefined) {\n if (!filter) return []\n if (filter.op === 'eq') return [filter.value]\n if (filter.op === 'in') return filter.values\n return []\n}\n\nexport function toSavedFilter(filter: FieldFilter): SavedFilterValue {\n switch (filter.op) {\n case 'eq':\n return filter.value\n case 'in':\n return { in: filter.values }\n case 'range':\n return {\n ...(filter.gte ? { gte: filter.gte } : {}),\n ...(filter.lte ? { lte: filter.lte } : {}),\n }\n case 'empty':\n return { empty: filter.empty }\n }\n}\n\n/** Reads a stored saved-view value; anything unrecognised is dropped (null). */\nexport function fromSavedFilter(value: unknown): FieldFilter | null {\n if (value === null || value === undefined || value === '') return null\n if (['string', 'number', 'boolean'].includes(typeof value))\n return { op: 'eq', value: String(value) }\n if (typeof value !== 'object' || Array.isArray(value)) return null\n const entry = value as Record<string, unknown>\n if ('empty' in entry) {\n const empty = entry.empty\n if (empty === true || empty === 'true') return { op: 'empty', empty: true }\n if (empty === false || empty === 'false') return { op: 'empty', empty: false }\n return null\n }\n if ('in' in entry) {\n const list = Array.isArray(entry.in)\n ? entry.in\n : typeof entry.in === 'string'\n ? entry.in.split(',')\n : []\n return normalizeFilter({\n op: 'in',\n values: list.map((item) => String(item).trim()),\n })\n }\n if ('gte' in entry || 'lte' in entry) {\n const bound = (operand: unknown) =>\n operand === null || operand === undefined || operand === '' ? undefined : String(operand)\n return normalizeFilter({\n op: 'range',\n gte: bound(entry.gte),\n lte: bound(entry.lte),\n })\n }\n return null\n}\n\n/** `GET /resources/:name/export` with the list's query (search, filters, tag, sort) but no cursor. */\nexport function exportHref(resource: string, params: URLSearchParams) {\n const query = new URLSearchParams(params)\n query.delete('cursor')\n query.delete('limit')\n const suffix = query.toString()\n return `/resources/${resource}/export${suffix ? `?${suffix}` : ''}`\n}\n\n/** The `error.message` of an AdulaJS JSON error body (object, JSON text or nothing). */\nexport function serverMessage(data: unknown): string | null {\n let body = data\n if (typeof body === 'string') {\n try {\n body = JSON.parse(body)\n } catch {\n return null\n }\n }\n const message = (body as { error?: { message?: unknown } } | null)?.error?.message\n return typeof message === 'string' && message ? message : null\n}\n\n/** Selection helpers for bulk actions; ids are the string keys the table uses. */\nexport function toggleSelection(selected: Set<string>, id: string, on: boolean) {\n const next = new Set(selected)\n if (on) next.add(id)\n else next.delete(id)\n return next\n}\n\nexport function selectionState(selected: Set<string>, ids: string[]): boolean | 'indeterminate' {\n const count = ids.filter((id) => selected.has(id)).length\n if (!count) return false\n return count === ids.length ? true : 'indeterminate'\n}\n\n/** The bulk request body: numeric ids and the loaded rows' versions keyed by id. */\nexport function bulkPayload(\n action: string,\n ids: string[],\n rows: { id?: unknown; version?: unknown }[]\n) {\n const versions: Record<string, unknown> = {}\n const wanted = new Set(ids)\n for (const row of rows)\n if (wanted.has(String(row.id)) && row.version !== undefined && row.version !== null)\n versions[String(row.id)] = row.version\n return { action, ids: ids.map(Number), versions }\n}\n\n/**\n * A datetime range bound as typed (`YYYY-MM-DD` or `YYYY-MM-DDTHH:mm`, optionally `hijri:`)\n * made inclusive: «من» starts at the beginning of the chosen day or minute, «إلى» ends at\n * its last millisecond, so filtering «إلى ١ أكتوبر» keeps records of 1 October.\n */\nexport function inclusiveDatetime(raw: string, side: 'gte' | 'lte') {\n const value = raw.trim()\n if (!value) return value\n const [day, time] = value.split('T')\n if (!time) return `${day}T${side === 'gte' ? '00:00:00.000' : '23:59:59.999'}`\n if (/^\\d{2}:\\d{2}$/.test(time)) return `${day}T${time}${side === 'gte' ? ':00.000' : ':59.999'}`\n return value\n}\n",
|
|
29
|
+
"content": "export const FILTER_IN_LIMIT = 50\nexport const BULK_LIMIT = 100\n/*\n * List query helpers shared by the data table (ADR 046): operator filters in the URL,\n * saved-view round trips, the server export link and server error messages. Pure and\n * import-free so the registry tests run it directly.\n */\n\n/** One active filter of a field; `eq` is the scalar equality the list always accepted. */\nexport type FieldFilter =\n | { op: 'eq'; value: string }\n | { op: 'in'; values: string[] }\n | { op: 'range'; gte?: string; lte?: string }\n | { op: 'empty'; empty: boolean }\n\n/** The shape a saved view stores for one field: a scalar or one operator object. */\nexport type SavedFilterValue =\n | string\n | number\n | boolean\n | null\n | { in: (string | number)[] }\n | { gte?: string | number; lte?: string | number }\n | { empty: boolean }\n\n/** How the filter control of a field type behaves. */\nexport type FilterMode = 'choice' | 'range' | 'boolean' | 'text'\n\nconst CHOICE = new Set([\n 'lookup',\n 'enum',\n 'belongsTo',\n 'user',\n 'string',\n 'text',\n 'email',\n 'phone',\n 'url',\n 'multiSelect',\n 'manyToMany',\n])\nconst RANGE = new Set(['integer', 'money', 'decimal', 'percent', 'date', 'datetime'])\n/** Several values per record: the server matches one member (equality) or emptiness only. */\nconst MEMBER = new Set(['multiSelect', 'manyToMany'])\n\nexport function filterMode(type: string): FilterMode {\n if (type === 'boolean') return 'boolean'\n if (RANGE.has(type)) return 'range'\n if (CHOICE.has(type)) return 'choice'\n return 'text'\n}\n\n/** Whether a choice filter picks one member (multiSelect, manyToMany) instead of «أيٌّ من». */\nexport function singleChoice(type: string) {\n return MEMBER.has(type)\n}\n\n/**\n * The draft of a choice control: «أيٌّ من» is `in`; a member filter keeps only the latest\n * choice as equality, since the server accepts no `in` for several-valued fields.\n */\nexport function choiceFilter(type: string, values: string[]): FieldFilter | null {\n const chosen = values.filter(Boolean)\n if (!singleChoice(type)) return { op: 'in', values: chosen }\n const last = chosen.at(-1)\n return last ? { op: 'eq', value: last } : null\n}\n\n/**\n * Whether the filter controls emit this operator for the field type, each one the server\n * accepts (ADR 046): `in` for choices except member fields, ranges for numbers and dates,\n * equality and emptiness for every type.\n */\nexport function filterAllowed(type: string, filter: FieldFilter) {\n switch (filter.op) {\n case 'eq':\n case 'empty':\n return true\n case 'in':\n return filterMode(type) === 'choice' && !singleChoice(type)\n case 'range':\n return filterMode(type) === 'range'\n }\n}\n\nconst prefix = (key: string) => `filters[${key}]`\n\n/** Reads the filters of the given field keys from the list URL. */\nexport function readFilters(params: URLSearchParams, keys: string[]) {\n const filters: Record<string, FieldFilter> = {}\n for (const key of keys) {\n const base = prefix(key)\n const empty = params.get(`${base}[empty]`)\n const list = params.getAll(`${base}[in][]`)\n const joined = params.get(`${base}[in]`)\n const gte = params.get(`${base}[gte]`)\n const lte = params.get(`${base}[lte]`)\n const value = params.get(base)\n if (empty === 'true' || empty === 'false')\n filters[key] = { op: 'empty', empty: empty === 'true' }\n else if (list.length || joined) {\n const values = (list.length ? list : joined!.split(','))\n .map((entry) => entry.trim())\n .filter(Boolean)\n if (values.length) filters[key] = { op: 'in', values }\n } else if (gte || lte)\n filters[key] = {\n op: 'range',\n ...(gte ? { gte } : {}),\n ...(lte ? { lte } : {}),\n }\n else if (value) filters[key] = { op: 'eq', value }\n }\n return filters\n}\n\n/** Removes every parameter of one field's filter, whatever its operator. */\nexport function clearFilter(params: URLSearchParams, key: string) {\n const base = prefix(key)\n for (const name of [...params.keys()])\n if (name === base || name.startsWith(`${base}[`)) params.delete(name)\n}\n\n/**\n * Writes one field's filter. A single choice stays plain equality; several are\n * `[in]=a,b`, or repeated `[in][]` when a value itself contains a comma.\n */\nexport function writeFilter(params: URLSearchParams, key: string, filter: FieldFilter | null) {\n clearFilter(params, key)\n if (!filter) return\n const base = prefix(key)\n switch (filter.op) {\n case 'eq':\n if (filter.value) params.set(base, filter.value)\n return\n case 'in': {\n const values = [...new Set(filter.values.filter(Boolean))]\n if (values.length === 1) params.set(base, values[0])\n else if (values.some((value) => value.includes(',')))\n for (const value of values) params.append(`${base}[in][]`, value)\n else if (values.length) params.set(`${base}[in]`, values.join(','))\n return\n }\n case 'range':\n if (filter.gte) params.set(`${base}[gte]`, filter.gte)\n if (filter.lte) params.set(`${base}[lte]`, filter.lte)\n return\n case 'empty':\n params.set(`${base}[empty]`, String(filter.empty))\n }\n}\n\n/** A filter with nothing to apply (no values, no bounds) is no filter. */\nexport function normalizeFilter(filter: FieldFilter | null): FieldFilter | null {\n if (!filter) return null\n if (filter.op === 'eq') return filter.value ? filter : null\n if (filter.op === 'in') {\n const values = [...new Set(filter.values.filter(Boolean))]\n if (!values.length) return null\n return values.length === 1 ? { op: 'eq', value: values[0] } : { op: 'in', values }\n }\n if (filter.op === 'range') {\n if (!filter.gte && !filter.lte) return null\n return {\n op: 'range',\n ...(filter.gte ? { gte: filter.gte } : {}),\n ...(filter.lte ? { lte: filter.lte } : {}),\n }\n }\n return filter\n}\n\n/** The values a choice control shows as selected. */\nexport function chosenValues(filter: FieldFilter | undefined) {\n if (!filter) return []\n if (filter.op === 'eq') return [filter.value]\n if (filter.op === 'in') return filter.values\n return []\n}\n\nexport function toSavedFilter(filter: FieldFilter): SavedFilterValue {\n switch (filter.op) {\n case 'eq':\n return filter.value\n case 'in':\n return { in: filter.values }\n case 'range':\n return {\n ...(filter.gte ? { gte: filter.gte } : {}),\n ...(filter.lte ? { lte: filter.lte } : {}),\n }\n case 'empty':\n return { empty: filter.empty }\n }\n}\n\n/** Reads a stored saved-view value; anything unrecognised is dropped (null). */\nexport function fromSavedFilter(value: unknown): FieldFilter | null {\n if (value === null || value === undefined || value === '') return null\n if (['string', 'number', 'boolean'].includes(typeof value))\n return { op: 'eq', value: String(value) }\n if (typeof value !== 'object' || Array.isArray(value)) return null\n const entry = value as Record<string, unknown>\n if ('empty' in entry) {\n const empty = entry.empty\n if (empty === true || empty === 'true') return { op: 'empty', empty: true }\n if (empty === false || empty === 'false') return { op: 'empty', empty: false }\n return null\n }\n if ('in' in entry) {\n const list = Array.isArray(entry.in)\n ? entry.in\n : typeof entry.in === 'string'\n ? entry.in.split(',')\n : []\n return normalizeFilter({\n op: 'in',\n values: list.map((item) => String(item).trim()),\n })\n }\n if ('gte' in entry || 'lte' in entry) {\n const bound = (operand: unknown) =>\n operand === null || operand === undefined || operand === '' ? undefined : String(operand)\n return normalizeFilter({\n op: 'range',\n gte: bound(entry.gte),\n lte: bound(entry.lte),\n })\n }\n return null\n}\n\n/**\n * `GET /resources/:name/export` with the list's query (search, filters, tag, sort) but no\n * cursor; `format` 'xlsx' asks for an Excel workbook instead of CSV.\n */\nexport function exportHref(\n resource: string,\n params: URLSearchParams,\n format: 'csv' | 'xlsx' = 'csv'\n) {\n const query = new URLSearchParams(params)\n query.delete('cursor')\n query.delete('limit')\n query.delete('format')\n if (format === 'xlsx') query.set('format', 'xlsx')\n const suffix = query.toString()\n return `/resources/${resource}/export${suffix ? `?${suffix}` : ''}`\n}\n\n/** The `error.message` of an AdulaJS JSON error body (object, JSON text or nothing). */\nexport function serverMessage(data: unknown): string | null {\n let body = data\n if (typeof body === 'string') {\n try {\n body = JSON.parse(body)\n } catch {\n return null\n }\n }\n const message = (body as { error?: { message?: unknown } } | null)?.error?.message\n return typeof message === 'string' && message ? message : null\n}\n\n/** Selection helpers for bulk actions; ids are the string keys the table uses. */\nexport function toggleSelection(selected: Set<string>, id: string, on: boolean) {\n const next = new Set(selected)\n if (on) next.add(id)\n else next.delete(id)\n return next\n}\n\nexport function selectionState(selected: Set<string>, ids: string[]): boolean | 'indeterminate' {\n const count = ids.filter((id) => selected.has(id)).length\n if (!count) return false\n return count === ids.length ? true : 'indeterminate'\n}\n\n/** The bulk request body: numeric ids and the loaded rows' versions keyed by id. */\nexport function bulkPayload(\n action: string,\n ids: string[],\n rows: { id?: unknown; version?: unknown }[]\n) {\n const versions: Record<string, unknown> = {}\n const wanted = new Set(ids)\n for (const row of rows)\n if (wanted.has(String(row.id)) && row.version !== undefined && row.version !== null)\n versions[String(row.id)] = row.version\n return { action, ids: ids.map(Number), versions }\n}\n\n/**\n * A datetime range bound as typed (`YYYY-MM-DD` or `YYYY-MM-DDTHH:mm`, optionally `hijri:`)\n * made inclusive: «من» starts at the beginning of the chosen day or minute, «إلى» ends at\n * its last millisecond, so filtering «إلى ١ أكتوبر» keeps records of 1 October.\n */\nexport function inclusiveDatetime(raw: string, side: 'gte' | 'lte') {\n const value = raw.trim()\n if (!value) return value\n const [day, time] = value.split('T')\n if (!time) return `${day}T${side === 'gte' ? '00:00:00.000' : '23:59:59.999'}`\n if (/^\\d{2}:\\d{2}$/.test(time)) return `${day}T${time}${side === 'gte' ? ':00.000' : ':59.999'}`\n return value\n}\n\n/**\n * The URL of the list itself. While a record dialog is open over the list, the page URL is the\n * record's, so filters, sort and refresh read the list URL the dialog returns to instead (#104).\n */\nexport function listUrl(pageUrl: string, overlay?: { list?: unknown } | null) {\n return typeof overlay?.list === 'string' && overlay.list ? overlay.list : pageUrl\n}\n",
|
|
30
30
|
"target": "inertia/components/ui/list_query.ts"
|
|
31
31
|
}
|
|
32
32
|
],
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "long-dialog",
|
|
3
|
+
"type": "registry:ui",
|
|
4
|
+
"registryDependencies": [
|
|
5
|
+
"dialog"
|
|
6
|
+
],
|
|
7
|
+
"dependencies": [],
|
|
8
|
+
"files": [
|
|
9
|
+
{
|
|
10
|
+
"path": "registry/ui/long-dialog.tsx",
|
|
11
|
+
"type": "registry:ui",
|
|
12
|
+
"content": "import * as React from 'react'\nimport { cn } from 'cn'\nimport {\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from '~/components/ui/dialog'\n\n// Named after the Tailwind max-width each one applies from the small screen breakpoint up.\nconst widths = {\n lg: 'sm:max-w-lg',\n xl: 'sm:max-w-xl',\n '2xl': 'sm:max-w-2xl',\n '3xl': 'sm:max-w-3xl',\n '4xl': 'sm:max-w-4xl',\n '5xl': 'sm:max-w-5xl',\n} as const\n\ntype LongDialogContentProps = {\n title: React.ReactNode\n description?: React.ReactNode\n /**\n * Actions shown in the fixed footer: secondary actions first (pushed to the start side with\n * `sm:me-auto`), then «إلغاء» or «إغلاق» as outline inside `DialogClose`, then the primary.\n * Closing asks first only while something differs from how the dialog opened (Dialog).\n */\n footer?: React.ReactNode\n /** Dialog width from the small screen breakpoint up; phones always use the full width. */\n width?: keyof typeof widths\n /**\n * `content` (default) grows with the body up to the maximum height. `fill` takes the maximum\n * height from the first frame, for a body that loads after opening: the dialog's size never\n * changes when its data arrives, so the opening animation is never disturbed.\n */\n height?: 'content' | 'fill'\n children: React.ReactNode\n} & Omit<React.ComponentProps<typeof DialogContent>, 'title' | 'className' | 'children'>\n\n/**\n * The long dialog pattern (ADR 016): the header and footer stay fixed and only the body scrolls,\n * with a scrollbar that stays visible in both themes so the reader sees there is more below.\n * Place it inside a shadcn `Dialog`; the layout matches the record surface (resource-surface).\n */\nexport function LongDialogContent({\n title,\n description,\n footer,\n width = 'xl',\n height = 'content',\n children,\n ...props\n}: LongDialogContentProps) {\n return (\n <DialogContent\n // Anchored to the top, so content that loads after opening extends the dialog downward.\n // Clipped, not hidden: focus cannot scroll the header away; the body is the only scroller.\n className={cn(\n 'top-4 flex max-h-[calc(100dvh-2rem)] w-[calc(100vw-2rem)] translate-y-0 flex-col gap-0 overflow-clip p-0 sm:top-[5dvh] sm:max-h-[90dvh]',\n height === 'fill' && 'h-[calc(100dvh-2rem)] sm:h-[90dvh]',\n widths[width]\n )}\n data-long-dialog=\"\"\n {...props}\n >\n <DialogHeader className=\"shrink-0 border-b px-6 py-5 pe-12 text-start\">\n <DialogTitle>{title}</DialogTitle>\n {description && <DialogDescription>{description}</DialogDescription>}\n </DialogHeader>\n <div\n data-slot=\"long-dialog-body\"\n // overflow-y: scroll keeps the scrollbar on screen while idle; the gutter keeps the\n // content from shifting, and the thumb uses theme tokens to read in light and dark.\n className=\"min-h-0 flex-1 scroll-py-6 overflow-y-scroll overscroll-contain p-4 [scrollbar-color:var(--muted-foreground)_transparent] [scrollbar-gutter:stable] [scrollbar-width:thin] sm:p-6\"\n >\n {children}\n </div>\n {footer && (\n <DialogFooter className=\"shrink-0 border-t px-6 py-4\" data-slot=\"long-dialog-footer\">\n {footer}\n </DialogFooter>\n )}\n </DialogContent>\n )\n}\n",
|
|
13
|
+
"target": "inertia/components/ui/long-dialog.tsx"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
17
|
+
}
|
package/build/manifest.json
CHANGED
|
@@ -1,246 +1,286 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
3
|
-
"adulaCompatibility": "2.
|
|
2
|
+
"version": "2.3.0",
|
|
3
|
+
"adulaCompatibility": "2.3",
|
|
4
4
|
"items": [
|
|
5
5
|
{
|
|
6
6
|
"name": "button",
|
|
7
|
-
"version": "2.
|
|
7
|
+
"version": "2.3.0",
|
|
8
8
|
"hash": "cf1a045e41f5029fe9a8e3f3513a142dbe6550d6ffbe560b652a0aed1bb76f94"
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
"name": "input",
|
|
12
|
-
"version": "2.
|
|
12
|
+
"version": "2.3.0",
|
|
13
13
|
"hash": "5a398efe048aff90155d858e63290dee2b7ad31c060936ac5bfce5ecf691e022"
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
"name": "textarea",
|
|
17
|
-
"version": "2.
|
|
17
|
+
"version": "2.3.0",
|
|
18
18
|
"hash": "f0f615a9112e64ccb0d580d9325558c97750c24bcce933211acd2fa01c24b008"
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
21
|
"name": "select",
|
|
22
|
-
"version": "2.
|
|
22
|
+
"version": "2.3.0",
|
|
23
23
|
"hash": "18ee21eba11ffcff5ae395c7b3b6d98f46fb16c7ebfe9524702698ce3d28d2a8"
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
26
|
"name": "checkbox",
|
|
27
|
-
"version": "2.
|
|
27
|
+
"version": "2.3.0",
|
|
28
28
|
"hash": "cca8adce36cf2ec1ee0a931e94fde84b2cf99c5161aa0cdb64bfab9ddeeaccf2"
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
"name": "switch",
|
|
32
|
-
"version": "2.
|
|
32
|
+
"version": "2.3.0",
|
|
33
33
|
"hash": "e7c66890e466ce01de637cfbebd61e9419125d15455649026363402967424e58"
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
"name": "radio-group",
|
|
37
|
-
"version": "2.
|
|
37
|
+
"version": "2.3.0",
|
|
38
38
|
"hash": "812401f01905afba206becc0925a65ae74b55c94f355602051106f093d2d18e3"
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
41
|
"name": "table",
|
|
42
|
-
"version": "2.
|
|
42
|
+
"version": "2.3.0",
|
|
43
43
|
"hash": "b2510151b64e672f358deac23046e7f2a43ec6d8835006577ac93a05a4d30ac0"
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
46
|
"name": "form",
|
|
47
|
-
"version": "2.
|
|
47
|
+
"version": "2.3.0",
|
|
48
48
|
"hash": "dd62ca3716c521cba34e96bc85f9193165ca6ed7905b90d53b7be891515a304d"
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
51
|
"name": "label",
|
|
52
|
-
"version": "2.
|
|
52
|
+
"version": "2.3.0",
|
|
53
53
|
"hash": "011da9573b00b89c2209a30a17d400f9bc1bb77b25d1547f496a7a1bc9dd5093"
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
"name": "dialog",
|
|
57
|
-
"version": "2.
|
|
58
|
-
"hash": "
|
|
57
|
+
"version": "2.3.0",
|
|
58
|
+
"hash": "2f4d3ab3fe8fee5537265e46b72ad88f9e58b585a979b98afc56ab5d0b82e47c"
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
61
|
"name": "sheet",
|
|
62
|
-
"version": "2.
|
|
62
|
+
"version": "2.3.0",
|
|
63
63
|
"hash": "779c0787c8f32ea1c23046b31f75a631a1358c02e6737def284920469676bc68"
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
66
|
"name": "dropdown-menu",
|
|
67
|
-
"version": "2.
|
|
67
|
+
"version": "2.3.0",
|
|
68
68
|
"hash": "7b5ed94e71634435d99ea48e4dda3009f9d82f5ad7ecb14219156d729048660e"
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
71
|
"name": "popover",
|
|
72
|
-
"version": "2.
|
|
72
|
+
"version": "2.3.0",
|
|
73
73
|
"hash": "f6dc0a30f9054e5aab39b210f85f4a59e119ac6059290298e3e9ea4000266e05"
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
"name": "command",
|
|
77
|
-
"version": "2.
|
|
77
|
+
"version": "2.3.0",
|
|
78
78
|
"hash": "23a8649d95107efb19c88f4673c8465ee1260eb4ef2761129e20809ce36875ab"
|
|
79
79
|
},
|
|
80
80
|
{
|
|
81
81
|
"name": "calendar",
|
|
82
|
-
"version": "2.
|
|
82
|
+
"version": "2.3.0",
|
|
83
83
|
"hash": "146fe26176aaae0f6607d4a511bffa12ce530f4e70057821dbc54d463f04028e"
|
|
84
84
|
},
|
|
85
85
|
{
|
|
86
86
|
"name": "badge",
|
|
87
|
-
"version": "2.
|
|
87
|
+
"version": "2.3.0",
|
|
88
88
|
"hash": "08a668f461549c6edf7da629899d59373e7cae5686d1533fd5d451fbf7c2e33e"
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
91
|
"name": "card",
|
|
92
|
-
"version": "2.
|
|
92
|
+
"version": "2.3.0",
|
|
93
93
|
"hash": "0c7ac44916cc64285da5d8734fd34896a72cabecada2119b68f7f04ac6995b9a"
|
|
94
94
|
},
|
|
95
|
+
{
|
|
96
|
+
"name": "breadcrumb",
|
|
97
|
+
"version": "2.3.0",
|
|
98
|
+
"hash": "4fdb892b4873cea530050ff2b5382bce25c55bfc895cff9d3409e3ed4e4b613c"
|
|
99
|
+
},
|
|
95
100
|
{
|
|
96
101
|
"name": "tabs",
|
|
97
|
-
"version": "2.
|
|
98
|
-
"hash": "
|
|
102
|
+
"version": "2.3.0",
|
|
103
|
+
"hash": "d146730d0fd73ecb4d57b50a18d99fd81fd75a394bbba554ed090b168a601ede"
|
|
99
104
|
},
|
|
100
105
|
{
|
|
101
106
|
"name": "sonner",
|
|
102
|
-
"version": "2.
|
|
107
|
+
"version": "2.3.0",
|
|
103
108
|
"hash": "bab1201bf8abbc1316ab0bb6140443e4451e92026b0a2fbd27b90323fdb6ff14"
|
|
104
109
|
},
|
|
105
110
|
{
|
|
106
111
|
"name": "skeleton",
|
|
107
|
-
"version": "2.
|
|
112
|
+
"version": "2.3.0",
|
|
108
113
|
"hash": "8dd2b789d3a4b70fb62a99922ef48ee7a0d23a7cda09b00cc1df49c8c29fac90"
|
|
109
114
|
},
|
|
110
115
|
{
|
|
111
116
|
"name": "pagination",
|
|
112
|
-
"version": "2.
|
|
117
|
+
"version": "2.3.0",
|
|
113
118
|
"hash": "c04e4d0e0f037136ed30cc2602ce2122e3ae65a866eb04b4ae26f218b58303d4"
|
|
114
119
|
},
|
|
115
120
|
{
|
|
116
121
|
"name": "tooltip",
|
|
117
|
-
"version": "2.
|
|
122
|
+
"version": "2.3.0",
|
|
118
123
|
"hash": "ba7a2b3d666f1848b063585c25bb87f16d2b46891f23ee0727992a63ba310540"
|
|
119
124
|
},
|
|
120
125
|
{
|
|
121
126
|
"name": "separator",
|
|
122
|
-
"version": "2.
|
|
127
|
+
"version": "2.3.0",
|
|
123
128
|
"hash": "12f949bd09fa730831cc500e15f2b3556779e1c840da70a57febae9580fed5f6"
|
|
124
129
|
},
|
|
125
130
|
{
|
|
126
131
|
"name": "alert",
|
|
127
|
-
"version": "2.
|
|
132
|
+
"version": "2.3.0",
|
|
128
133
|
"hash": "17940923e71122bb30d830c569e36e3886109cbfdfb405fd3954774fed1f0ead"
|
|
129
134
|
},
|
|
130
135
|
{
|
|
131
136
|
"name": "can",
|
|
132
|
-
"version": "2.
|
|
137
|
+
"version": "2.3.0",
|
|
133
138
|
"hash": "325cc32dac417e6001146ff59ba45b0c2231b672c92cebf389eaff378b82120c"
|
|
134
139
|
},
|
|
135
140
|
{
|
|
136
141
|
"name": "attachment-preview",
|
|
137
|
-
"version": "2.
|
|
138
|
-
"hash": "
|
|
142
|
+
"version": "2.3.0",
|
|
143
|
+
"hash": "ebe2fd30ad80cbac797fba2368b807f7edd06d40b298bf3fbf1b7602f2481645"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"name": "slider",
|
|
147
|
+
"version": "2.3.0",
|
|
148
|
+
"hash": "a58f2f389bcd7535cc33e164895e9c07c2bfe98fbfa95325871817c84dd991ec"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"name": "user-avatar",
|
|
152
|
+
"version": "2.3.0",
|
|
153
|
+
"hash": "b71b6504fd7792ad98e2ba3d58f6a1cb7f835ccf9cf69f0d39bb6bcabba45a0c"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"name": "sortable-list",
|
|
157
|
+
"version": "2.3.0",
|
|
158
|
+
"hash": "d22c1bfecaf6ac38a5b122c31f48927dd329d34f31b518e2243946f1a0b16c2f"
|
|
139
159
|
},
|
|
140
160
|
{
|
|
141
161
|
"name": "resource-value",
|
|
142
|
-
"version": "2.
|
|
143
|
-
"hash": "
|
|
162
|
+
"version": "2.3.0",
|
|
163
|
+
"hash": "a835b27097555882bbaaefd183ec9e444a8d3aa6b04ddbde5f23e108658ab3af"
|
|
144
164
|
},
|
|
145
165
|
{
|
|
146
166
|
"name": "resource-field",
|
|
147
|
-
"version": "2.
|
|
148
|
-
"hash": "
|
|
167
|
+
"version": "2.3.0",
|
|
168
|
+
"hash": "06b892cf8ea0610facd2d67106c518789d7f1e103068a3072c988147de7fbfac"
|
|
149
169
|
},
|
|
150
170
|
{
|
|
151
171
|
"name": "data-table",
|
|
152
|
-
"version": "2.
|
|
153
|
-
"hash": "
|
|
172
|
+
"version": "2.3.0",
|
|
173
|
+
"hash": "e937d9c825c6d59f1e6f0a2e4702ce75e5c32b961e76922e1bc3fb9acf28692e"
|
|
154
174
|
},
|
|
155
175
|
{
|
|
156
176
|
"name": "resource-form",
|
|
157
|
-
"version": "2.
|
|
158
|
-
"hash": "
|
|
177
|
+
"version": "2.3.0",
|
|
178
|
+
"hash": "604c474a096e7e700db5add5c3720e2d49c9b40111f2612c84b7ee03186e16a5"
|
|
159
179
|
},
|
|
160
180
|
{
|
|
161
181
|
"name": "record-collaboration",
|
|
162
|
-
"version": "2.
|
|
163
|
-
"hash": "
|
|
182
|
+
"version": "2.3.0",
|
|
183
|
+
"hash": "48998f4879d95448ed3ca74a1c04f7d456701010319516404caf9934e6639ba0"
|
|
164
184
|
},
|
|
165
185
|
{
|
|
166
186
|
"name": "record-assignments",
|
|
167
|
-
"version": "2.
|
|
168
|
-
"hash": "
|
|
187
|
+
"version": "2.3.0",
|
|
188
|
+
"hash": "85f5e00077013fec639875644f8b378294e3033d9a140a379c4d6df8bea9348c"
|
|
169
189
|
},
|
|
170
190
|
{
|
|
171
191
|
"name": "record-workflows",
|
|
172
|
-
"version": "2.
|
|
173
|
-
"hash": "
|
|
192
|
+
"version": "2.3.0",
|
|
193
|
+
"hash": "b84a4431ec07364c46c7efab2c4346e19922aa3d5f1e7fdc91ae50bb01acc5bd"
|
|
174
194
|
},
|
|
175
195
|
{
|
|
176
196
|
"name": "record-print",
|
|
177
|
-
"version": "2.
|
|
197
|
+
"version": "2.3.0",
|
|
178
198
|
"hash": "20caed486c5330f371e08e796f2c2b8196bc3da416ef571cdcf9041c57589159"
|
|
179
199
|
},
|
|
180
200
|
{
|
|
181
201
|
"name": "resource-show",
|
|
182
|
-
"version": "2.
|
|
183
|
-
"hash": "
|
|
202
|
+
"version": "2.3.0",
|
|
203
|
+
"hash": "710c8855877156c1a910782569658016c5464ba672a53fdb2a787547961a51d4"
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"name": "file-input",
|
|
207
|
+
"version": "2.3.0",
|
|
208
|
+
"hash": "d9ae66af8bd073641b4390e3da8be531d3117ca3e2eb0106477e403cf580c1a3"
|
|
184
209
|
},
|
|
185
210
|
{
|
|
186
211
|
"name": "resource-import",
|
|
187
|
-
"version": "2.
|
|
188
|
-
"hash": "
|
|
212
|
+
"version": "2.3.0",
|
|
213
|
+
"hash": "0604fc858010f4df8de744939a04e1817ec94bb1e0a2785745219fdac847bfb5"
|
|
189
214
|
},
|
|
190
215
|
{
|
|
191
216
|
"name": "resource-page",
|
|
192
|
-
"version": "2.
|
|
193
|
-
"hash": "
|
|
217
|
+
"version": "2.3.0",
|
|
218
|
+
"hash": "6e589ce87799a0822c0e7e8021226bb8d793ac65608c5d5d2adc2c6f0a5c6eca"
|
|
194
219
|
},
|
|
195
220
|
{
|
|
196
221
|
"name": "resource-actions",
|
|
197
|
-
"version": "2.
|
|
198
|
-
"hash": "
|
|
222
|
+
"version": "2.3.0",
|
|
223
|
+
"hash": "ae8a5a8abe4e5872ae8fbc803f88a4306ca6da21d96a396f55d675de27a776fe"
|
|
199
224
|
},
|
|
200
225
|
{
|
|
201
226
|
"name": "resource-surface",
|
|
202
|
-
"version": "2.
|
|
203
|
-
"hash": "
|
|
227
|
+
"version": "2.3.0",
|
|
228
|
+
"hash": "01731d810c0710c0e6ddce875d9ea94b585a258abba273a9f299e5f06f37ca97"
|
|
204
229
|
},
|
|
205
230
|
{
|
|
206
231
|
"name": "ui-preferences",
|
|
207
|
-
"version": "2.
|
|
232
|
+
"version": "2.3.0",
|
|
208
233
|
"hash": "c5430a68726b1b01dd1259481fac4cd60ddfdd6cd986dc2c6fe63cc35e2d5cdb"
|
|
209
234
|
},
|
|
210
235
|
{
|
|
211
236
|
"name": "calendar-date",
|
|
212
|
-
"version": "2.
|
|
237
|
+
"version": "2.3.0",
|
|
213
238
|
"hash": "f166217803da3ae1beac2662f8c5528ea52c96b1fb4891dfc19b71090b345ff2"
|
|
214
239
|
},
|
|
215
240
|
{
|
|
216
241
|
"name": "messages",
|
|
217
|
-
"version": "2.
|
|
218
|
-
"hash": "
|
|
242
|
+
"version": "2.3.0",
|
|
243
|
+
"hash": "7a8db307f85ad397f8f54e63a5cc863c4a2acd7d7b3f9e6262f341cbb81ae3c1"
|
|
219
244
|
},
|
|
220
245
|
{
|
|
221
246
|
"name": "hijri-calendar",
|
|
222
|
-
"version": "2.
|
|
247
|
+
"version": "2.3.0",
|
|
223
248
|
"hash": "45821450e1dc1e2418326b4fca36d4e1980a2ac08a096e92775b6bfc017cd16f"
|
|
224
249
|
},
|
|
225
250
|
{
|
|
226
251
|
"name": "confirm-action",
|
|
227
|
-
"version": "2.
|
|
252
|
+
"version": "2.3.0",
|
|
228
253
|
"hash": "b707040fc28ffd69902eb9f19b80aeb415b73f66cdfeff50c98c27f8cdc64bf8"
|
|
229
254
|
},
|
|
230
255
|
{
|
|
231
256
|
"name": "list-filters",
|
|
232
|
-
"version": "2.
|
|
233
|
-
"hash": "
|
|
257
|
+
"version": "2.3.0",
|
|
258
|
+
"hash": "50f22bce337189e741b17104d6b602985d24d3aea25f3ddeef397de6cb8eb5c2"
|
|
234
259
|
},
|
|
235
260
|
{
|
|
236
261
|
"name": "resource-bulk",
|
|
237
|
-
"version": "2.
|
|
238
|
-
"hash": "
|
|
262
|
+
"version": "2.3.0",
|
|
263
|
+
"hash": "1a12724a82045012e11561199d13b68746e0960f8b6f79befd89311467f3efe6"
|
|
239
264
|
},
|
|
240
265
|
{
|
|
241
266
|
"name": "resource-dashboard",
|
|
242
|
-
"version": "2.
|
|
243
|
-
"hash": "
|
|
267
|
+
"version": "2.3.0",
|
|
268
|
+
"hash": "eb24b1da870d4f26e32e116e7391df257a09e3fb78b6969a8e28f50a599e18c5"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
"name": "copy-button",
|
|
272
|
+
"version": "2.3.0",
|
|
273
|
+
"hash": "230201018d328e7a35f923b3697db878ea8e665c273ca201fa2cd7470157a9d6"
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
"name": "long-dialog",
|
|
277
|
+
"version": "2.3.0",
|
|
278
|
+
"hash": "660cbb3ff7765b93516deb5a8904ff97748591c3f6a08111d41637a271af2a6b"
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
"name": "dialog-param",
|
|
282
|
+
"version": "2.3.0",
|
|
283
|
+
"hash": "1759e33dd41c737f7889af86b20fea7757cbbb11417d1d222b2d20b9567fbc6e"
|
|
244
284
|
}
|
|
245
285
|
],
|
|
246
286
|
"dependencies": {
|
package/build/messages.json
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
{
|
|
8
8
|
"path": "registry/ui/messages.ts",
|
|
9
9
|
"type": "registry:ui",
|
|
10
|
-
"content": "import { usePage } from '@inertiajs/react'\nimport { useMemo } from 'react'\nimport {\n createTranslator,\n localizedLabel,\n type InterfaceDirection,\n type InterfaceLanguage,\n type LocalizedLabel,\n} from '~/components/ui/message_format'\n\nexport {\n arabicText,\n createTranslator,\n interpolate,\n localizedLabel,\n type InterfaceDirection,\n type InterfaceLanguage,\n type LocalizedLabel,\n type MessageParams,\n type Translate,\n} from '~/components/ui/message_format'\n\ntype MessageProps = {\n locale?: string\n dir?: InterfaceDirection\n languages?: InterfaceLanguage[]\n messages?: Record<string, string>\n}\n\nconst none: Record<string, string> = {}\nconst arabicOnly: InterfaceLanguage[] = [{ code: 'ar', name: 'العربية', dir: 'rtl' }]\n\n/**\n * Interface text for the current user: `t('نص عربي', params)` and `label(field.label)`.\n * A consumer that does not share `locale`, `dir` and `messages` keeps rendering Arabic.\n */\nexport function useMessages() {\n const props = usePage<MessageProps>().props\n const locale = props.locale ?? 'ar'\n const dir = props.dir ?? 'rtl'\n const messages = props.messages ?? none\n return useMemo(\n () => ({\n locale,\n dir,\n t: createTranslator(messages),\n label: (value: LocalizedLabel) => localizedLabel(value, locale),\n }),\n [locale, dir, messages]\n )\n}\n\n/** The enabled interface languages, Arabic first; one entry when only Arabic is enabled. */\nexport function useLanguages(): InterfaceLanguage[] {\n return usePage<MessageProps>().props.languages ?? arabicOnly\n}\n",
|
|
10
|
+
"content": "import { usePage } from '@inertiajs/react'\nimport { useMemo } from 'react'\nimport {\n createTranslator,\n localizedLabel,\n type InterfaceDirection,\n type InterfaceLanguage,\n type LocalizedLabel,\n} from '~/components/ui/message_format'\n\nexport {\n arabicText,\n countForm,\n createTranslator,\n documentCount,\n recordCount,\n interpolate,\n localizedLabel,\n type InterfaceDirection,\n type InterfaceLanguage,\n type CountForm,\n type LocalizedLabel,\n type MessageParams,\n type Translate,\n} from '~/components/ui/message_format'\n\ntype MessageProps = {\n locale?: string\n dir?: InterfaceDirection\n languages?: InterfaceLanguage[]\n messages?: Record<string, string>\n}\n\nconst none: Record<string, string> = {}\nconst arabicOnly: InterfaceLanguage[] = [{ code: 'ar', name: 'العربية', dir: 'rtl' }]\n\n/**\n * Interface text for the current user: `t('نص عربي', params)` and `label(field.label)`.\n * A consumer that does not share `locale`, `dir` and `messages` keeps rendering Arabic.\n */\nexport function useMessages() {\n const props = usePage<MessageProps>().props\n const locale = props.locale ?? 'ar'\n const dir = props.dir ?? 'rtl'\n const messages = props.messages ?? none\n return useMemo(\n () => ({\n locale,\n dir,\n t: createTranslator(messages),\n label: (value: LocalizedLabel) => localizedLabel(value, locale),\n }),\n [locale, dir, messages]\n )\n}\n\n/** The enabled interface languages, Arabic first; one entry when only Arabic is enabled. */\nexport function useLanguages(): InterfaceLanguage[] {\n return usePage<MessageProps>().props.languages ?? arabicOnly\n}\n",
|
|
11
11
|
"target": "inertia/components/ui/messages.ts"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
14
|
"path": "registry/ui/message_format.ts",
|
|
15
15
|
"type": "registry:ui",
|
|
16
|
-
"content": "export type InterfaceDirection = 'rtl' | 'ltr'\nexport type InterfaceLanguage = { code: string; name: string; dir: InterfaceDirection }\n/** A resource or field label: Arabic is required, every other language is optional. */\nexport type LocalizedLabel = { ar: string; [language: string]: string | undefined }\nexport type MessageParams = Record<string, string | number>\nexport type Translate = (arabic: string, params?: MessageParams) => string\n\nconst none: Record<string, string> = {}\n\n/** Replaces `{name}` placeholders; an unknown placeholder is kept as written. */\nexport function interpolate(template: string, params?: MessageParams) {\n if (!params) return template\n return template.replace(/\\{(\\w+)\\}/g, (match, name: string) =>\n Object.hasOwn(params, name) ? String(params[name]) : match\n )\n}\n\n/**\n * Arabic is the base language: the interface text is the lookup key and is shown\n * unchanged when no translation exists (always the case for Arabic users).\n */\nexport function createTranslator(messages: Record<string, string> = none): Translate {\n return (arabic, params) =>\n interpolate(Object.hasOwn(messages, arabic) ? messages[arabic] : arabic, params)\n}\n\n/** The Arabic text with its placeholders filled, for helpers called outside components. */\nexport const arabicText: Translate = createTranslator()\n\n/** `label.<locale>` when present, otherwise the required Arabic label. */\nexport function localizedLabel(label: LocalizedLabel, locale: string) {\n return label[locale] || label.ar\n}\n",
|
|
16
|
+
"content": "export type InterfaceDirection = 'rtl' | 'ltr'\nexport type InterfaceLanguage = { code: string; name: string; dir: InterfaceDirection }\n/** A resource or field label: Arabic is required, every other language is optional. */\nexport type LocalizedLabel = { ar: string; [language: string]: string | undefined }\nexport type MessageParams = Record<string, string | number>\nexport type Translate = (arabic: string, params?: MessageParams) => string\n\nconst none: Record<string, string> = {}\n\n/** Replaces `{name}` placeholders; an unknown placeholder is kept as written. */\nexport function interpolate(template: string, params?: MessageParams) {\n if (!params) return template\n return template.replace(/\\{(\\w+)\\}/g, (match, name: string) =>\n Object.hasOwn(params, name) ? String(params[name]) : match\n )\n}\n\n/**\n * Arabic is the base language: the interface text is the lookup key and is shown\n * unchanged when no translation exists (always the case for Arabic users).\n */\nexport function createTranslator(messages: Record<string, string> = none): Translate {\n return (arabic, params) =>\n interpolate(Object.hasOwn(messages, arabic) ? messages[arabic] : arabic, params)\n}\n\n/** The Arabic text with its placeholders filled, for helpers called outside components. */\nexport const arabicText: Translate = createTranslator()\n\n/** `label.<locale>` when present, otherwise the required Arabic label. */\nexport function localizedLabel(label: LocalizedLabel, locale: string) {\n return label[locale] || label.ar\n}\n\n/** The CLDR plural category of a count under Arabic rules (n % 100 decides from 100 on). */\nexport type CountForm = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other'\nconst arabicPlurals = new Intl.PluralRules('ar')\nexport function countForm(count: number): CountForm {\n return arabicPlurals.select(count) as CountForm\n}\n\n/**\n * «سجل واحد»، «سجلان»، «3 سجلات»، «11 سجلًا»، «100 سجل» (#110). Each form is its own catalog\n * text, so translations choose their wording per form.\n */\nexport function recordCount(count: number, t: Translate = arabicText) {\n switch (countForm(count)) {\n case 'one':\n return t('سجل واحد')\n case 'two':\n return t('سجلان')\n case 'few':\n return t('{count} سجلات', { count })\n case 'many':\n return t('{count} سجلًا', { count })\n default:\n return t('{count} سجل', { count })\n }\n}\n\n/** «مستند واحد»، «مستندان»، «3 مستندات»، «11 مستندًا»، «100 مستند». */\nexport function documentCount(count: number, t: Translate = arabicText) {\n switch (countForm(count)) {\n case 'one':\n return t('مستند واحد')\n case 'two':\n return t('مستندان')\n case 'few':\n return t('{count} مستندات', { count })\n case 'many':\n return t('{count} مستندًا', { count })\n default:\n return t('{count} مستند', { count })\n }\n}\n",
|
|
17
17
|
"target": "inertia/components/ui/message_format.ts"
|
|
18
18
|
}
|
|
19
19
|
],
|