@telamonjs/ui 1.0.4 → 1.1.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/components/business/CalendarWithEvents.d.ts +7 -1
  3. package/dist/components/business/CalendarWithEvents.js +8 -9
  4. package/dist/components/cards/stat-card.js +22 -3
  5. package/dist/components/charts/BarChart.d.ts +12 -1
  6. package/dist/components/charts/BarChart.js +6 -1
  7. package/dist/components/crud/crud-field.js +1 -0
  8. package/dist/components/data/DataTableActions.js +45 -77
  9. package/dist/components/data/action-access.d.ts +22 -0
  10. package/dist/components/data/action-access.js +33 -0
  11. package/dist/components/data/report-table.d.ts +3 -1
  12. package/dist/components/data/report-table.js +2 -1
  13. package/dist/components/dialog/DialogHeaderContent.js +1 -1
  14. package/dist/components/dialog/confirm-action-dialog.d.ts +54 -0
  15. package/dist/components/dialog/confirm-action-dialog.js +182 -0
  16. package/dist/components/dialog/crud-view-dialog.d.ts +7 -3
  17. package/dist/components/dialog/crud-view-dialog.js +3 -2
  18. package/dist/components/dialog/view-dialog.d.ts +9 -1
  19. package/dist/components/dialog/view-dialog.js +8 -3
  20. package/dist/components/forms/BaseForm.js +4 -3
  21. package/dist/components/forms/WizardForm.js +3 -2
  22. package/dist/components/forms/ZustandForm.js +5 -4
  23. package/dist/components/forms/admin-form/field-group.js +5 -4
  24. package/dist/components/forms/grid-classes.d.ts +4 -0
  25. package/dist/components/forms/grid-classes.js +40 -0
  26. package/dist/components/forms/validators/config-validator.js +2 -1
  27. package/dist/components/toolbar/TabToolbar.d.ts +6 -1
  28. package/dist/components/toolbar/TabToolbar.js +5 -3
  29. package/dist/exports/data-crud.d.ts +1 -1
  30. package/dist/exports/pages-dialogs.d.ts +3 -1
  31. package/dist/exports/pages-dialogs.js +2 -0
  32. package/dist/exports/types-constants.d.ts +2 -2
  33. package/dist/exports/types-constants.js +1 -1
  34. package/dist/field-system/mask-presets.d.ts +5 -0
  35. package/dist/field-system/mask-presets.js +18 -0
  36. package/dist/field-system/renderers/advanced-renderers.js +2 -4
  37. package/dist/field-system/renderers/textarea-renderers.js +1 -1
  38. package/dist/hooks/useCrudMutations.js +28 -16
  39. package/dist/pages/ListPage.js +23 -14
  40. package/dist/pages/list-page/ListPageDialogs.d.ts +8 -3
  41. package/dist/pages/list-page/ListPageDialogs.js +36 -7
  42. package/dist/pages/list-page/ListPageToolbar.js +10 -14
  43. package/dist/pages/list-page/apply-crud-permissions.d.ts +21 -0
  44. package/dist/pages/list-page/apply-crud-permissions.js +34 -0
  45. package/dist/pages/list-page/types.d.ts +21 -2
  46. package/dist/pages/list-page/useListPageData.d.ts +3 -1
  47. package/dist/pages/list-page/useListPageData.js +2 -1
  48. package/dist/pages/list-page/useListPageDialogs.d.ts +1 -0
  49. package/dist/pages/list-page/useListPageDialogs.js +13 -4
  50. package/dist/pages/list-page/useListPageToolbar.d.ts +8 -5
  51. package/dist/pages/list-page/useListPageToolbar.js +14 -10
  52. package/dist/queue/components/FailureGroupsModal.js +4 -3
  53. package/dist/queue/components/JobConfigDialog.js +9 -1
  54. package/dist/queue/components/JobDetailModal.js +3 -2
  55. package/dist/queue/components/JobDetailPage.js +10 -2
  56. package/dist/queue/components/JobEventModal.js +3 -2
  57. package/dist/queue/components/QueueTabbedDashboard.d.ts +20 -2
  58. package/dist/queue/components/QueueTabbedDashboard.js +26 -3
  59. package/dist/queue/components/QueuesTable.d.ts +3 -2
  60. package/dist/queue/components/QueuesTable.js +31 -27
  61. package/dist/queue/components/job-shared.d.ts +2 -0
  62. package/dist/queue/components/job-shared.js +2 -0
  63. package/dist/queue/components/jobs-history-modal/fullscreen-modal.js +3 -2
  64. package/dist/queue/components/jobs-history-modal/job-detail-modal.js +3 -2
  65. package/dist/queue/components/jobs-list-modal/job-row.js +3 -2
  66. package/dist/queue/components/labels-context.d.ts +31 -0
  67. package/dist/queue/components/labels-context.js +34 -0
  68. package/dist/queue/components/module-icon.d.ts +9 -0
  69. package/dist/queue/components/module-icon.js +14 -0
  70. package/dist/queue/components/tabs/ConfiguracaoTab.d.ts +2 -1
  71. package/dist/queue/components/tabs/ConfiguracaoTab.js +13 -9
  72. package/dist/queue/components/tabs/HistoricoTab.js +4 -3
  73. package/dist/queue/components/tabs/TempoRealTab.d.ts +3 -2
  74. package/dist/queue/components/tabs/TempoRealTab.js +2 -2
  75. package/dist/types/actions.d.ts +43 -14
  76. package/dist/types/crud.d.ts +47 -6
  77. package/dist/types/dialog-header.d.ts +2 -2
  78. package/dist/types/forms/admin-form.d.ts +8 -1
  79. package/dist/utils/with-scope.js +5 -3
  80. package/package.json +1 -1
@@ -0,0 +1,34 @@
1
+ "use client";
2
+
3
+ // src/queue/components/labels-context.ts
4
+ import { createContext, useContext, useMemo } from "react";
5
+ import { useText } from "../../i18n/use-t.js";
6
+ import { formatQueueName } from "../lib/format.js";
7
+ var QueueLabelsContext = createContext({});
8
+ function useQueueLabels() {
9
+ const { moduleLabels, jobLabel, displayNames } = useContext(QueueLabelsContext);
10
+ const text = useText();
11
+ return useMemo(() => {
12
+ const moduleLabel = (module) => text(moduleLabels?.[module]);
13
+ const rank = new Map(Object.keys(moduleLabels ?? {}).map((m, i) => [m, i]));
14
+ const sortKey = (m) => moduleLabel(m) ?? m;
15
+ return {
16
+ jobLabel: (jobName, displayName) => {
17
+ const contract = displayName ?? displayNames?.[jobName];
18
+ return text(jobLabel?.(jobName)) ?? // The backend serves the raw name when the contract has none
19
+ (contract && contract !== jobName ? contract : formatQueueName(jobName));
20
+ },
21
+ moduleLabel,
22
+ orderModules: (modules) => [...modules].sort(
23
+ (a, b) => (
24
+ // Infinity - Infinity is NaN (falsy) → both unranked: compare labels
25
+ (rank.get(a) ?? Infinity) - (rank.get(b) ?? Infinity) || sortKey(a).localeCompare(sortKey(b))
26
+ )
27
+ )
28
+ };
29
+ }, [moduleLabels, jobLabel, displayNames, text]);
30
+ }
31
+ export {
32
+ QueueLabelsContext,
33
+ useQueueLabels
34
+ };
@@ -0,0 +1,9 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { IconComponent } from '../../types/menu';
3
+ /** A `moduleIcons` entry: an emoji/text, a rendered node, or an icon component (e.g. Lucide). */
4
+ export type QueueModuleIcon = ReactNode | IconComponent;
5
+ /** Renders a `moduleIcons` entry; components get the group-header icon size. */
6
+ export declare function ModuleIcon({ icon, className }: {
7
+ icon: QueueModuleIcon;
8
+ className?: string;
9
+ }): import("react").JSX.Element;
@@ -0,0 +1,14 @@
1
+ // src/queue/components/module-icon.tsx
2
+ import { isValidElement } from "react";
3
+ import { Fragment, jsx } from "react/jsx-runtime";
4
+ function ModuleIcon({ icon, className }) {
5
+ const isComponent = typeof icon === "function" || typeof icon === "object" && icon !== null && "$$typeof" in icon && !isValidElement(icon);
6
+ if (isComponent) {
7
+ const Icon = icon;
8
+ return /* @__PURE__ */ jsx(Icon, { className: className ?? "h-4 w-4", "aria-hidden": "true" });
9
+ }
10
+ return /* @__PURE__ */ jsx(Fragment, { children: icon });
11
+ }
12
+ export {
13
+ ModuleIcon
14
+ };
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
+ import { type QueueModuleIcon } from '../module-icon';
2
3
  interface ConfiguracaoTabProps {
3
- moduleIcons?: Record<string, string>;
4
+ moduleIcons?: Record<string, QueueModuleIcon>;
4
5
  }
5
6
  export default function ConfiguracaoTab({ moduleIcons: moduleIconsProp, }: ConfiguracaoTabProps): React.JSX.Element;
6
7
  export {};
@@ -24,9 +24,10 @@ import {
24
24
  useUpdateJobConfig
25
25
  } from "../../hooks/index.js";
26
26
  import JobConfigDialog from "../JobConfigDialog.js";
27
- import { formatQueueName } from "../../lib/format.js";
28
27
  import { useTelamonjsT } from "../../../i18n/use-t.js";
29
28
  import { useQueueReadOnly } from "../read-only-context.js";
29
+ import { useQueueLabels } from "../labels-context.js";
30
+ import { ModuleIcon } from "../module-icon.js";
30
31
  import { jsx, jsxs } from "react/jsx-runtime";
31
32
  var defaultModuleIcons = {
32
33
  alertas: "\u{1F6A8}",
@@ -56,6 +57,7 @@ function ConfiguracaoTab({
56
57
  const t = useTelamonjsT();
57
58
  const readOnly = useQueueReadOnly();
58
59
  const icons = moduleIconsProp ?? defaultModuleIcons;
60
+ const { jobLabel, moduleLabel, orderModules } = useQueueLabels();
59
61
  const { data: allJobs, isLoading } = useAllJobs();
60
62
  const [searchQuery, setSearchQuery] = useState("");
61
63
  const [expandedModules, setExpandedModules] = useState(/* @__PURE__ */ new Set());
@@ -92,8 +94,8 @@ function ConfiguracaoTab({
92
94
  return grouped;
93
95
  }, [filteredJobs]);
94
96
  const sortedModules = useMemo(
95
- () => Object.entries(jobsByModule).sort(([a], [b]) => a.localeCompare(b)),
96
- [jobsByModule]
97
+ () => orderModules(Object.keys(jobsByModule)).map((m) => [m, jobsByModule[m]]),
98
+ [jobsByModule, orderModules]
97
99
  );
98
100
  const toggleModule = (module) => {
99
101
  const newExpanded = new Set(expandedModules);
@@ -199,6 +201,7 @@ function ConfiguracaoTab({
199
201
  const isExpanded = expandedModules.has(module);
200
202
  const moduleStats = getModuleStats(moduleJobs);
201
203
  const moduleIcon = icons[module] || "\u{1F4E6}";
204
+ const label = moduleLabel(module);
202
205
  const isTogglingModule = togglingModules.has(module);
203
206
  const allEnabled = moduleJobs.every((j) => j.enabled);
204
207
  const allDisabled = moduleJobs.every((j) => !j.enabled);
@@ -212,8 +215,8 @@ function ConfiguracaoTab({
212
215
  className: "flex flex-1 items-center gap-2",
213
216
  children: [
214
217
  isExpanded ? /* @__PURE__ */ jsx(ChevronDown, { className: "text-muted-foreground h-4 w-4" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "text-muted-foreground h-4 w-4" }),
215
- /* @__PURE__ */ jsx("span", { className: "text-base", children: moduleIcon }),
216
- /* @__PURE__ */ jsx("span", { className: "text-sm font-medium capitalize", children: module }),
218
+ /* @__PURE__ */ jsx("span", { className: "text-base", children: /* @__PURE__ */ jsx(ModuleIcon, { icon: moduleIcon }) }),
219
+ /* @__PURE__ */ jsx("span", { className: cn("text-sm font-medium", !label && "capitalize"), children: label ?? module }),
217
220
  /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground text-xs", children: [
218
221
  "\xB7 ",
219
222
  moduleJobs.length
@@ -241,7 +244,7 @@ function ConfiguracaoTab({
241
244
  disabled: isTogglingModule,
242
245
  className: "hover:bg-muted rounded p-1 transition-colors",
243
246
  title: t("queue.config.activateAll"),
244
- "aria-label": t("queue.config.activateAllModule", { module }),
247
+ "aria-label": t("queue.config.activateAllModule", { module: label ?? module }),
245
248
  children: /* @__PURE__ */ jsx(
246
249
  Play,
247
250
  {
@@ -260,7 +263,7 @@ function ConfiguracaoTab({
260
263
  disabled: isTogglingModule,
261
264
  className: "hover:bg-muted rounded p-1 transition-colors",
262
265
  title: t("queue.config.deactivateAll"),
263
- "aria-label": t("queue.config.deactivateAllModule", { module }),
266
+ "aria-label": t("queue.config.deactivateAllModule", { module: label ?? module }),
264
267
  children: /* @__PURE__ */ jsx(
265
268
  Pause,
266
269
  {
@@ -277,6 +280,7 @@ function ConfiguracaoTab({
277
280
  ] }),
278
281
  isExpanded && /* @__PURE__ */ jsx("div", { className: "bg-muted/70 dark:bg-muted/60 border-t", children: moduleJobs.sort((a, b) => a.jobName.localeCompare(b.jobName)).map((job) => {
279
282
  const isToggling = togglingJobs.has(job.jobName);
283
+ const title = jobLabel(job.jobName);
280
284
  return /* @__PURE__ */ jsxs(
281
285
  "div",
282
286
  {
@@ -301,7 +305,7 @@ function ConfiguracaoTab({
301
305
  ),
302
306
  /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
303
307
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
304
- /* @__PURE__ */ jsx("span", { className: "truncate text-sm font-medium", children: formatQueueName(job.jobName) }),
308
+ /* @__PURE__ */ jsx("span", { className: "truncate text-sm font-medium", children: title }),
305
309
  job.orphan && /* @__PURE__ */ jsx(
306
310
  Badge,
307
311
  {
@@ -312,7 +316,7 @@ function ConfiguracaoTab({
312
316
  }
313
317
  )
314
318
  ] }),
315
- /* @__PURE__ */ jsx("p", { className: "text-muted-foreground truncate text-xs", children: job.description || job.jobName })
319
+ /* @__PURE__ */ jsx("p", { className: "text-muted-foreground truncate text-xs", children: job.description && job.description !== title ? job.description : job.jobName })
316
320
  ] })
317
321
  ] }),
318
322
  /* @__PURE__ */ jsxs("div", { className: "ml-4 flex shrink-0 items-center gap-3", children: [
@@ -27,7 +27,7 @@ import { subHours } from "date-fns";
27
27
  import { useQueueApi } from "../../api/provider.js";
28
28
  import { useQueueHistoryAll, useCopyToClipboard } from "../../hooks/index.js";
29
29
  import { TabToolbar } from "../../../components/toolbar/TabToolbar.js";
30
- import { formatQueueName } from "../../lib/format.js";
30
+ import { useQueueLabels } from "../labels-context.js";
31
31
  import { useLocale } from "next-intl";
32
32
  import { useTelamonjsT } from "../../../i18n/use-t.js";
33
33
  import { useQueueReadOnly } from "../read-only-context.js";
@@ -44,6 +44,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
44
44
  function HistoricoTab() {
45
45
  "use no memo";
46
46
  const t = useTelamonjsT();
47
+ const { jobLabel } = useQueueLabels();
47
48
  const readOnly = useQueueReadOnly();
48
49
  const format = useFormat();
49
50
  const locale = useLocale();
@@ -290,7 +291,7 @@ function HistoricoTab() {
290
291
  onClick: () => setSelectedJob(job),
291
292
  formatDate,
292
293
  formatDuration: formatJobDuration,
293
- formatQueueName,
294
+ formatQueueName: jobLabel,
294
295
  truncateId
295
296
  }
296
297
  )
@@ -354,7 +355,7 @@ function HistoricoTab() {
354
355
  onRemove: handleRemove,
355
356
  formatDate,
356
357
  formatDuration: formatJobDuration,
357
- formatQueueName,
358
+ formatQueueName: jobLabel,
358
359
  copyToClipboard,
359
360
  copied,
360
361
  renderValue
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
+ import type { QueueModuleIcon } from '../module-icon';
2
3
  interface TempoRealTabProps {
3
4
  /** Enable SSE real-time updates (default: true) */
4
5
  enableSSE?: boolean;
5
- /** Module icons for the queues table (module name → emoji) */
6
- moduleIcons?: Record<string, string>;
6
+ /** Module icons for the queues table (module name → emoji, node or icon component) */
7
+ moduleIcons?: Record<string, QueueModuleIcon>;
7
8
  /** This tab is the visible one — visited tabs stay mounted (default: true) */
8
9
  active?: boolean;
9
10
  /** Timeline poll interval in ms while SSE is down (default: 2000) */
@@ -38,7 +38,7 @@ import { Badge } from "../../../ui/badge.js";
38
38
  import JobStatsCards from "../JobStatsCards.js";
39
39
  import QueuesTable from "../QueuesTable.js";
40
40
  import { TabToolbar } from "../../../components/toolbar/TabToolbar.js";
41
- import { formatQueueName } from "../../lib/format.js";
41
+ import { useQueueLabels } from "../labels-context.js";
42
42
  import { useTelamonjsT } from "../../../i18n/use-t.js";
43
43
  import { useFormat, useTickingNow } from "../../../i18n/use-format.js";
44
44
  import { actionDoneMessage } from "../../lib/action-message.js";
@@ -217,7 +217,7 @@ var JobRow = React.memo(({ job, isSelected, onClick }) => {
217
217
  const duration = formatDuration(job.processedOn, job.finishedOn, locale);
218
218
  const relativeTs = job.finishedOn || job.processedOn || job.timestamp;
219
219
  const timeAgo = relativeTs ? format.relative(relativeTs, now) : "\u2014";
220
- const queueDisplay = formatQueueName(job.queueName);
220
+ const queueDisplay = useQueueLabels().jobLabel(job.queueName);
221
221
  const StatusIcon = job.status === "active" ? Clock : job.status === "completed" ? CheckCircle : AlertCircle;
222
222
  return /* @__PURE__ */ jsxs(
223
223
  "div",
@@ -28,15 +28,34 @@ export interface ConfirmDialogConfig<TData = any> {
28
28
  cancelText?: I18nText;
29
29
  /** Dialog variant */
30
30
  variant?: 'default' | 'destructive';
31
- /** Optional input fields in the dialog */
32
- inputs?: Array<{
33
- name: string;
34
- label: string;
35
- type: 'text' | 'textarea' | 'select';
36
- required?: boolean;
37
- options?: string[];
38
- defaultValue?: string;
39
- }>;
31
+ /**
32
+ * Fields asked before confirming (a reason, a note…). Their values reach the
33
+ * action as the second argument of `handler`/`onClick`: `(row, { inputs })`.
34
+ */
35
+ inputs?: ConfirmDialogInput[];
36
+ }
37
+ /**
38
+ * A field of a confirmation dialog (`ConfirmDialogConfig.inputs`,
39
+ * `ConfirmActionDialog`'s `inputs`)
40
+ */
41
+ export interface ConfirmDialogInput {
42
+ /** Key of the value in `inputs` */
43
+ name: string;
44
+ label: I18nText;
45
+ type: 'text' | 'textarea' | 'select';
46
+ /** Confirming is blocked while it is empty */
47
+ required?: boolean;
48
+ /** Choices of a `select` (value = label) */
49
+ options?: string[];
50
+ defaultValue?: string;
51
+ }
52
+ /**
53
+ * Second argument of an action's `handler`/`onClick`, passed when its
54
+ * `confirmDialog` declares `inputs`
55
+ */
56
+ export interface ActionContext {
57
+ /** Values of `confirmDialog.inputs`, by `name` */
58
+ inputs: Record<string, string>;
40
59
  }
41
60
  /**
42
61
  * Tooltip configuration for actions
@@ -69,17 +88,20 @@ export interface ActionConfig<TData = any> {
69
88
  tooltip?: I18nText | TooltipConfig | ((row: TData) => string);
70
89
  /** Navigation URL */
71
90
  href?: string | ((row: TData) => string);
72
- /** Direct click handler */
73
- onClick?: (row: TData) => void | Promise<void>;
74
- /** Async handler with result */
75
- handler?: (row: TData) => Promise<unknown>;
91
+ /** Direct click handler (`ctx` only when `confirmDialog.inputs` is set) */
92
+ onClick?: (row: TData, ctx?: ActionContext) => void | Promise<void>;
93
+ /** Async handler with result (`ctx` only when `confirmDialog.inputs` is set) */
94
+ handler?: (row: TData, ctx?: ActionContext) => Promise<unknown>;
76
95
  /** Confirmation dialog configuration */
77
96
  confirmDialog?: boolean | ConfirmDialogConfig<TData>;
78
97
  /** Called on successful action completion */
79
98
  onSuccess?: (row: TData, result?: unknown) => void;
80
99
  /** Called on action error */
81
100
  onError?: (error: Error, row: TData) => void;
82
- /** Required permission(s) to show this action */
101
+ /**
102
+ * Required permission(s) to show this action (any of them). Checked with
103
+ * `DataTableActionsConfig.can` when set, else against `userPermissions`.
104
+ */
83
105
  permission?: string | string[];
84
106
  /** Success message to display (I18nText) */
85
107
  successMessage?: I18nText | ((row: TData) => I18nText);
@@ -136,4 +158,11 @@ export interface DataTableActionsConfig<TData = any> {
136
158
  onAfterAction?: (actionId: string, row: TData, result?: unknown) => void | Promise<void>;
137
159
  /** Current user permissions for permission checking */
138
160
  userPermissions?: string[];
161
+ /**
162
+ * Permission checker. When set it decides every `permission` instead of the
163
+ * exact lookup in `userPermissions`, so bypass roles and wildcards work, e.g.
164
+ * `can: perm => checker.can(user, perm)` with `createPermissionChecker` from
165
+ * `@telamonjs/permissions`.
166
+ */
167
+ can?: (permission: string) => boolean;
139
168
  }
@@ -60,7 +60,7 @@ import type { ColumnDef, HeaderContext } from '@tanstack/react-table';
60
60
  import type { z } from 'zod';
61
61
  import type { UseQueryOptions, UseMutationOptions, QueryKey } from '@tanstack/react-query';
62
62
  import type { ReactNode } from 'react';
63
- import type { DataTableActionsConfig } from './actions';
63
+ import type { ActionConfig, DataTableActionsConfig } from './actions';
64
64
  import type { PaginationParams, PaginatedResponse } from './pagination';
65
65
  import type { FormSection } from './forms/admin-form';
66
66
  import type { DialogHeaderConfig } from './dialog-header';
@@ -135,8 +135,18 @@ export interface ToolbarFilterConfig {
135
135
  label: I18nText;
136
136
  /** Filter options */
137
137
  options: ToolbarFilterOption[];
138
- /** Initial value (default: first option) */
138
+ /**
139
+ * Initial value (default: first option). With `allValue` set it applies even
140
+ * when it is the first option.
141
+ */
139
142
  defaultValue?: string;
143
+ /**
144
+ * The option value that means "no filter" (dropped from the query, shown when
145
+ * nothing is selected). Set it and the first option is an ordinary option and
146
+ * `'todos'`/`'all'` are ordinary values. Without it, the first option is the
147
+ * "all" choice and `''`/`'todos'`/`'all'` mean "no filter".
148
+ */
149
+ allValue?: string;
140
150
  /** Custom className */
141
151
  className?: string;
142
152
  /** Display mode: 'buttons' (ButtonGroup) or 'select' (compact dropdown). Default: 'buttons' */
@@ -237,8 +247,8 @@ export interface ListConfig<T> {
237
247
  export interface FormConfig {
238
248
  /** Form sections with fields */
239
249
  sections: FormSection | FormSection[];
240
- /** Zod validation schema */
241
- validation: z.ZodSchema;
250
+ /** Zod validation schema (optional: without it the form submits unvalidated) */
251
+ validation?: z.ZodSchema;
242
252
  /** Use tabs for sections (default: false for create, true for edit) */
243
253
  useTabs?: boolean;
244
254
  /**
@@ -518,6 +528,27 @@ export interface PagesConfig<T> {
518
528
  renderContent: (item: T) => React.ReactNode;
519
529
  };
520
530
  }
531
+ /**
532
+ * Permission model of a CrudConfig. Each operation names the permission(s) it
533
+ * needs (any of them, like an action's `permission`); an operation without
534
+ * one stays allowed.
535
+ *
536
+ * Checked with `can` when set (bypass roles, wildcards: pass
537
+ * `perm => checker.can(user, perm)` from `@telamonjs/permissions`), else against
538
+ * `actionsConfig.userPermissions`; with neither, everything is allowed.
539
+ */
540
+ export interface CrudPermissions {
541
+ /** Permission checker; wins over `actionsConfig.userPermissions` */
542
+ can?: (permission: string) => boolean;
543
+ /** The "New" button and the create dialog */
544
+ create?: ActionConfig['permission'];
545
+ /** The row edit, the view dialog's Edit, the edit dialog and portal section saving */
546
+ edit?: ActionConfig['permission'];
547
+ /** The row delete and the view dialog's Delete */
548
+ delete?: ActionConfig['permission'];
549
+ /** The row view and the view dialog (row click included) */
550
+ view?: ActionConfig['permission'];
551
+ }
521
552
  /**
522
553
  * Complete CRUD configuration
523
554
  *
@@ -560,8 +591,12 @@ export interface CrudConfig<T = any, TFormData = T> {
560
591
  module: ModuleMetadata;
561
592
  /** List page configuration */
562
593
  list: ListConfig<T>;
563
- /** Form configuration (shared by create/edit/dialogs) */
564
- form: FormConfig;
594
+ /**
595
+ * Form configuration (shared by create/edit/dialogs). Optional: a read-only
596
+ * list omits it, and then no create or edit dialog is offered even when
597
+ * `dialogs.create` / `dialogs.edit` are set.
598
+ */
599
+ form?: FormConfig;
565
600
  /**
566
601
  * React Query configuration for data fetching
567
602
  * REQUIRED - Replaces Server Actions pattern
@@ -578,6 +613,12 @@ export interface CrudConfig<T = any, TFormData = T> {
578
613
  dialogs?: DialogsConfig<T>;
579
614
  /** Dedicated pages configuration (optional) */
580
615
  pages?: PagesConfig<T>;
616
+ /**
617
+ * Who may create, edit, delete and view. Gates the "New" button, the row
618
+ * actions, the view dialog footer, the create/edit dialogs and portal
619
+ * section saving. Omit it and nothing changes.
620
+ */
621
+ permissions?: CrudPermissions;
581
622
  }
582
623
  /**
583
624
  * CrudConfig with the form-data side erased (existential).
@@ -70,8 +70,8 @@ export interface HeaderBadgeConfig<T = any> {
70
70
  labels?: Record<string, I18nText>;
71
71
  /** Optional: Custom function to determine badge variant */
72
72
  getVariant?: (item: T) => BadgeVariant;
73
- /** Optional: Custom function to determine badge label */
74
- getLabel?: (item: T) => string;
73
+ /** Optional: Custom function to determine badge label (a `msg()` is resolved) */
74
+ getLabel?: (item: T) => I18nText;
75
75
  }
76
76
  /**
77
77
  * Stats grid configuration
@@ -121,7 +121,14 @@ export interface FormField<TValue = unknown> {
121
121
  id: string;
122
122
  }) => React.ReactElement;
123
123
  mask?: string;
124
- maskType?: string;
124
+ /**
125
+ * `masked` fields: a built-in mask that wins over `mask` — `'tel'`
126
+ * (landline/mobile by digit count), `'cpf'`, `'cnpj'`, `'cep'`. Any other
127
+ * value falls back to `mask`
128
+ */
129
+ maskType?: 'tel' | 'cpf' | 'cnpj' | 'cep' | (string & Record<never, never>);
130
+ /** `textarea` fields: visible text lines. Default: 4 */
131
+ rows?: number;
125
132
  dependsOn?: string;
126
133
  focus?: boolean;
127
134
  readOnly?: boolean;
@@ -52,9 +52,11 @@ function withScope(config, scope) {
52
52
  }),
53
53
  ...toolbar && { toolbar }
54
54
  },
55
- form: {
56
- ...config.form,
57
- sections: stripFields(config.form.sections, lockedKeys)
55
+ ...config.form && {
56
+ form: {
57
+ ...config.form,
58
+ sections: stripFields(config.form.sections, lockedKeys)
59
+ }
58
60
  },
59
61
  query: {
60
62
  ...config.query,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telamonjs/ui",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "description": "Admin framework for Next.js + React: declarative CRUD (CrudConfig + TanStack Query), 36-type field system, rich dialogs, app shell, dashboards and charts",
6
6
  "main": "dist/index.js",