@middag-io/react 0.46.0 → 0.47.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 (50) hide show
  1. package/dist-lib/{FormField-Csx8hGAW.js → FormField-BGqAQLtX.js} +1863 -1806
  2. package/dist-lib/{FormPanelBlock-Bmd0DpiX.js → FormPanelBlock-CGgA83Mu.js} +50 -49
  3. package/dist-lib/base/blocks/CardGridBlock.d.ts.map +1 -1
  4. package/dist-lib/base/blocks/DenseTableBlock.d.ts.map +1 -1
  5. package/dist-lib/base/blocks/DetailPanelBlock.d.ts.map +1 -1
  6. package/dist-lib/base/blocks/FormPanelBlock.d.ts.map +1 -1
  7. package/dist-lib/base/partials/ActionBar/index.d.ts.map +1 -1
  8. package/dist-lib/base/partials/FilterBar/index.d.ts.map +1 -1
  9. package/dist-lib/base/shell/BasicShell.js +1 -1
  10. package/dist-lib/base/shell/partials/InlineEditablePanel.d.ts.map +1 -1
  11. package/dist-lib/base/shell/partials/InlineEditablePanel.js +131 -127
  12. package/dist-lib/base/shell/partials/PageActionButton.d.ts.map +1 -1
  13. package/dist-lib/base/shell/partials/PageActionButton.js +1 -1
  14. package/dist-lib/base/theme/appearance.d.ts.map +1 -1
  15. package/dist-lib/base/theme/appearance.js +1 -1
  16. package/dist-lib/base/utils/action-intent.d.ts +3 -0
  17. package/dist-lib/base/utils/action-intent.d.ts.map +1 -0
  18. package/dist-lib/base/utils/action-intent.js +16 -0
  19. package/dist-lib/chunks/subpath-Bs35txZS.js +166 -0
  20. package/dist-lib/contracts/generated/index.d.ts +7 -7
  21. package/dist-lib/contracts/generated/index.d.ts.map +1 -1
  22. package/dist-lib/contracts/generated/schemas.d.ts +3992 -0
  23. package/dist-lib/contracts/generated/schemas.d.ts.map +1 -0
  24. package/dist-lib/contracts/generated/{contract-types.d.ts → types.d.ts} +26 -16
  25. package/dist-lib/contracts/generated/types.d.ts.map +1 -0
  26. package/dist-lib/contracts/page-contract-schema.d.ts +217 -27
  27. package/dist-lib/contracts/page-contract-schema.d.ts.map +1 -1
  28. package/dist-lib/middag-react.js +10111 -10782
  29. package/dist-lib/primitives/reui/button.d.ts +1 -1
  30. package/docs/public/schemas/fragment.json +66 -2
  31. package/docs/public/schemas/page-contract.json +66 -2
  32. package/package.json +1 -1
  33. package/src/base/blocks/CardGridBlock.tsx +2 -1
  34. package/src/base/blocks/DenseTableBlock.tsx +2 -1
  35. package/src/base/blocks/DetailPanelBlock.tsx +2 -1
  36. package/src/base/blocks/FormPanelBlock.tsx +2 -1
  37. package/src/base/partials/ActionBar/index.tsx +3 -2
  38. package/src/base/partials/FilterBar/index.tsx +12 -1
  39. package/src/base/shell/partials/InlineEditablePanel.tsx +14 -7
  40. package/src/base/shell/partials/PageActionButton.tsx +3 -1
  41. package/src/base/theme/appearance.ts +2 -1
  42. package/src/base/utils/action-intent.ts +22 -0
  43. package/src/contracts/generated/index.ts +7 -7
  44. package/src/contracts/generated/schemas.ts +565 -0
  45. package/src/contracts/generated/{contract-types.ts → types.ts} +42 -15
  46. package/dist-lib/chunks/subpath-Bh1MAmBT.js +0 -165
  47. package/dist-lib/contracts/generated/contract-schema.d.ts +0 -183
  48. package/dist-lib/contracts/generated/contract-schema.d.ts.map +0 -1
  49. package/dist-lib/contracts/generated/contract-types.d.ts.map +0 -1
  50. package/src/contracts/generated/contract-schema.ts +0 -1237
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { type VariantProps } from "class-variance-authority";
3
3
  declare const buttonVariants: (props?: ({
4
- variant?: "default" | "secondary" | "link" | "ghost" | "destructive" | "outline" | null | undefined;
4
+ variant?: "default" | "link" | "secondary" | "ghost" | "destructive" | "outline" | null | undefined;
5
5
  size?: "default" | "icon" | "xs" | "sm" | "lg" | "icon-xs" | "icon-sm" | "icon-lg" | null | undefined;
6
6
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
7
7
  declare function Button({ className, variant, size, asChild, ...props }: React.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
@@ -1794,6 +1794,57 @@
1794
1794
  }
1795
1795
  },
1796
1796
  "additionalProperties": false
1797
+ },
1798
+ {
1799
+ "type": "object",
1800
+ "required": [
1801
+ "kind",
1802
+ "key",
1803
+ "component",
1804
+ "props"
1805
+ ],
1806
+ "properties": {
1807
+ "kind": {
1808
+ "const": "field"
1809
+ },
1810
+ "key": {
1811
+ "type": "string"
1812
+ },
1813
+ "component": {
1814
+ "enum": [
1815
+ "richtext",
1816
+ "time"
1817
+ ]
1818
+ },
1819
+ "props": {
1820
+ "$ref": "#/$defs/FieldPropsBase"
1821
+ }
1822
+ },
1823
+ "additionalProperties": false
1824
+ },
1825
+ {
1826
+ "type": "object",
1827
+ "required": [
1828
+ "kind",
1829
+ "key",
1830
+ "component",
1831
+ "props"
1832
+ ],
1833
+ "properties": {
1834
+ "kind": {
1835
+ "const": "field"
1836
+ },
1837
+ "key": {
1838
+ "type": "string"
1839
+ },
1840
+ "component": {
1841
+ "const": "autocomplete"
1842
+ },
1843
+ "props": {
1844
+ "$ref": "#/$defs/OptionFieldProps"
1845
+ }
1846
+ },
1847
+ "additionalProperties": false
1797
1848
  }
1798
1849
  ]
1799
1850
  },
@@ -1813,7 +1864,17 @@
1813
1864
  "type": "string"
1814
1865
  },
1815
1866
  "label": {
1816
- "type": "string"
1867
+ "oneOf": [
1868
+ {
1869
+ "type": "string"
1870
+ },
1871
+ {
1872
+ "$ref": "#/$defs/Translatable"
1873
+ },
1874
+ {
1875
+ "type": "null"
1876
+ }
1877
+ ]
1817
1878
  },
1818
1879
  "defaultCollapsed": {
1819
1880
  "type": "boolean"
@@ -2252,7 +2313,10 @@
2252
2313
  "date_range",
2253
2314
  "hidden",
2254
2315
  "static",
2255
- "header"
2316
+ "header",
2317
+ "richtext",
2318
+ "time",
2319
+ "autocomplete"
2256
2320
  ]
2257
2321
  },
2258
2322
  "FragmentKind": {
@@ -1794,6 +1794,57 @@
1794
1794
  }
1795
1795
  },
1796
1796
  "additionalProperties": false
1797
+ },
1798
+ {
1799
+ "type": "object",
1800
+ "required": [
1801
+ "kind",
1802
+ "key",
1803
+ "component",
1804
+ "props"
1805
+ ],
1806
+ "properties": {
1807
+ "kind": {
1808
+ "const": "field"
1809
+ },
1810
+ "key": {
1811
+ "type": "string"
1812
+ },
1813
+ "component": {
1814
+ "enum": [
1815
+ "richtext",
1816
+ "time"
1817
+ ]
1818
+ },
1819
+ "props": {
1820
+ "$ref": "#/$defs/FieldPropsBase"
1821
+ }
1822
+ },
1823
+ "additionalProperties": false
1824
+ },
1825
+ {
1826
+ "type": "object",
1827
+ "required": [
1828
+ "kind",
1829
+ "key",
1830
+ "component",
1831
+ "props"
1832
+ ],
1833
+ "properties": {
1834
+ "kind": {
1835
+ "const": "field"
1836
+ },
1837
+ "key": {
1838
+ "type": "string"
1839
+ },
1840
+ "component": {
1841
+ "const": "autocomplete"
1842
+ },
1843
+ "props": {
1844
+ "$ref": "#/$defs/OptionFieldProps"
1845
+ }
1846
+ },
1847
+ "additionalProperties": false
1797
1848
  }
1798
1849
  ]
1799
1850
  },
@@ -1813,7 +1864,17 @@
1813
1864
  "type": "string"
1814
1865
  },
1815
1866
  "label": {
1816
- "type": "string"
1867
+ "oneOf": [
1868
+ {
1869
+ "type": "string"
1870
+ },
1871
+ {
1872
+ "$ref": "#/$defs/Translatable"
1873
+ },
1874
+ {
1875
+ "type": "null"
1876
+ }
1877
+ ]
1817
1878
  },
1818
1879
  "defaultCollapsed": {
1819
1880
  "type": "boolean"
@@ -2252,7 +2313,10 @@
2252
2313
  "date_range",
2253
2314
  "hidden",
2254
2315
  "static",
2255
- "header"
2316
+ "header",
2317
+ "richtext",
2318
+ "time",
2319
+ "autocomplete"
2256
2320
  ]
2257
2321
  },
2258
2322
  "FragmentKind": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middag-io/react",
3
- "version": "0.46.0",
3
+ "version": "0.47.0",
4
4
  "type": "module",
5
5
  "description": "MIDDAG shared React UI library for Moodle, WordPress and other Inertia hosts",
6
6
  "license": "Apache-2.0",
@@ -19,6 +19,7 @@ import { Link } from "@inertiajs/react";
19
19
 
20
20
  import { ConfirmationDialog } from "@/base/partials/ConfirmationDialog";
21
21
  import { useInspector } from "@/base/shell/partials/InspectorContext";
22
+ import { isDangerIntent } from "@/base/utils/action-intent";
22
23
  import { getIcon } from "@/base/utils/icons";
23
24
  import { interpolate } from "@/base/utils/interpolate";
24
25
  import type {
@@ -180,7 +181,7 @@ export function CardGridBlock({ block }: BlockProps<CardGridBlockData>): ReactEl
180
181
  variant="ghost"
181
182
  size="icon-xs"
182
183
  className={cn(
183
- action.intent === "danger" && "text-destructive hover:text-destructive",
184
+ isDangerIntent(action.intent) && "text-destructive hover:text-destructive",
184
185
  )}
185
186
  title={renderLabel(action.label, t)}
186
187
  onClick={() => runRowAction(action, row)}
@@ -14,6 +14,7 @@ import { DataTable } from "@/base/partials/DataTable";
14
14
  import type { DataTableParamChange } from "@/base/partials/DataTable/types";
15
15
  import { useEditablePanel } from "@/base/shell/partials/EditablePanelContext";
16
16
  import { useInspector } from "@/base/shell/partials/InspectorContext";
17
+ import { isDangerIntent } from "@/base/utils/action-intent";
17
18
  import { evaluateCondition } from "@/base/utils/conditions";
18
19
  import { interpolate } from "@/base/utils/interpolate";
19
20
  import type { ActionConfirmation, DenseTableBlockData } from "@/contracts/block-data";
@@ -234,7 +235,7 @@ export function DenseTableBlock({ block }: BlockProps<DenseTableBlockData>): Rea
234
235
  id: action.id,
235
236
  label: renderLabel(action.label, t),
236
237
  icon: action.icon,
237
- intent: action.intent === "danger" ? ("danger" as const) : ("default" as const),
238
+ intent: isDangerIntent(action.intent) ? ("danger" as const) : ("default" as const),
238
239
  variant: action.variant,
239
240
  onAction: (row: Record<string, unknown>) => {
240
241
  const resolvedHref = interpolate(target.url, row);
@@ -12,6 +12,7 @@ import { router } from "@inertiajs/core";
12
12
  import type { TFunction } from "i18next";
13
13
 
14
14
  import { ConfirmationDialog } from "@/base/partials/ConfirmationDialog";
15
+ import { isDangerIntent } from "@/base/utils/action-intent";
15
16
  import { getIcon } from "@/base/utils/icons";
16
17
  import type {
17
18
  DetailPanelBlockData,
@@ -112,7 +113,7 @@ function SectionActionButton({ action }: { action: ExecutableAction }): ReactEle
112
113
  return (
113
114
  <>
114
115
  <Button
115
- variant={action.intent === "danger" ? "destructive" : "outline"}
116
+ variant={isDangerIntent(action.intent) ? "destructive" : "outline"}
116
117
  size="sm"
117
118
  onClick={handleClick}
118
119
  disabled={action.disabled}
@@ -94,6 +94,7 @@ function SchemaRenderer({
94
94
  onChange: (key: string, value: unknown) => void;
95
95
  sourceValues: Record<string, unknown>;
96
96
  }): ReactElement {
97
+ const { t } = useTranslation();
97
98
  return (
98
99
  <>
99
100
  {nodes.map((node, index) => {
@@ -116,7 +117,7 @@ function SchemaRenderer({
116
117
  <FormSection
117
118
  key={node.id}
118
119
  id={node.id}
119
- title={node.label}
120
+ title={renderLabel(node.label, t) || undefined}
120
121
  defaultCollapsed={node.defaultCollapsed}
121
122
  hasErrors={node.children.some((c) => c.kind === "field" && !!errors[c.key])}
122
123
  errorCount={
@@ -8,6 +8,7 @@
8
8
  import { useState, type ReactElement } from "react";
9
9
 
10
10
  import { ConfirmationDialog } from "@/base/partials/ConfirmationDialog";
11
+ import { isDangerIntent } from "@/base/utils/action-intent";
11
12
  import type { ExecutableAction } from "@/contracts/block-data";
12
13
  import { renderLabel } from "@/i18n/render-label";
13
14
  import { useTranslation } from "@/i18n/useTranslation";
@@ -72,7 +73,7 @@ export function ActionBar({
72
73
  <Button
73
74
  key={action.id}
74
75
  data-testid={actionTestId(action.id)}
75
- variant={action.intent === "danger" ? "destructive" : "outline"}
76
+ variant={isDangerIntent(action.intent) ? "destructive" : "outline"}
76
77
  size="sm"
77
78
  onClick={() => handleAction(action)}
78
79
  disabled={isLoading}
@@ -94,7 +95,7 @@ export function ActionBar({
94
95
  message={bulkMessage}
95
96
  intent={
96
97
  confirmAction.confirmation?.intent ??
97
- (confirmAction.intent === "danger" ? "danger" : undefined)
98
+ (isDangerIntent(confirmAction.intent) ? "danger" : undefined)
98
99
  }
99
100
  confirmLabel={
100
101
  confirmAction.confirmation?.confirmLabel
@@ -22,6 +22,17 @@ import {
22
22
  } from "@/primitives/reui/select";
23
23
  import { Separator } from "@/primitives/reui/separator";
24
24
 
25
+ const RENDERABLE_FILTER_TYPES: ReadonlySet<string> = new Set([
26
+ "select",
27
+ "multiselect",
28
+ "date_range",
29
+ ]);
30
+
31
+ /** FilterType is an open enum: a type this renderer cannot draw is skipped, not shown as a bare label. */
32
+ function isRenderableFilter(filter: { type: string }): boolean {
33
+ return RENDERABLE_FILTER_TYPES.has(filter.type);
34
+ }
35
+
25
36
  export interface FilterDef {
26
37
  key: string;
27
38
  label: string;
@@ -104,7 +115,7 @@ export function FilterBar({
104
115
  align="start"
105
116
  >
106
117
  <p className="text-sm font-semibold">{t("middag.ui.filter.title")}</p>
107
- {filters.map((filter) => (
118
+ {filters.filter(isRenderableFilter).map((filter) => (
108
119
  <div key={filter.key} className="space-y-1.5">
109
120
  <label className="text-muted-foreground text-xs font-medium">{filter.label}</label>
110
121
  {filter.type === "select" && filter.options && (
@@ -1,11 +1,13 @@
1
1
  "use client";
2
2
 
3
3
  import { useMemo, useState, type ReactElement, type ReactNode } from "react";
4
+ import type { TFunction } from "i18next";
4
5
 
5
6
  import { buildFormSchema } from "@/base/form/form-schema-builder";
6
7
  import { isFieldVisible } from "@/base/form/form-utils";
7
8
  import { FormField } from "@/base/form/FormField";
8
9
  import type { FormFieldNode, FormSchemaNode } from "@/contracts/block-data";
10
+ import { renderLabel } from "@/i18n/render-label";
9
11
  import { useTranslation } from "@/i18n/useTranslation";
10
12
  import { cn } from "@/lib/utils";
11
13
  import { Button } from "@/primitives/reui/button";
@@ -44,6 +46,7 @@ function renderNodes(
44
46
  values: Values,
45
47
  errors: Record<string, string>,
46
48
  setValue: (key: string, value: unknown) => void,
49
+ t: TFunction,
47
50
  ): ReactNode {
48
51
  return nodes.map((node, index) => {
49
52
  switch (node.kind) {
@@ -66,22 +69,26 @@ function renderNodes(
66
69
  {node.label}
67
70
  </h4>
68
71
  );
69
- case "section":
72
+ case "section": {
73
+ const sectionLabel = renderLabel(node.label, t);
70
74
  return (
71
75
  <section key={node.id} className="space-y-3">
72
- <div className="text-muted-foreground text-[11px] font-medium tracking-[0.04em] uppercase">
73
- {node.label}
74
- </div>
75
- {renderNodes(node.children, values, errors, setValue)}
76
+ {sectionLabel && (
77
+ <div className="text-muted-foreground text-[11px] font-medium tracking-[0.04em] uppercase">
78
+ {sectionLabel}
79
+ </div>
80
+ )}
81
+ {renderNodes(node.children, values, errors, setValue, t)}
76
82
  </section>
77
83
  );
84
+ }
78
85
  case "group":
79
86
  return (
80
87
  <div
81
88
  key={node.id}
82
89
  className={cn(node.columns === 2 ? "grid grid-cols-2 gap-3" : "space-y-3")}
83
90
  >
84
- {renderNodes(node.children, values, errors, setValue)}
91
+ {renderNodes(node.children, values, errors, setValue, t)}
85
92
  </div>
86
93
  );
87
94
  default:
@@ -217,7 +224,7 @@ export function InlineEditablePanel(): ReactElement | null {
217
224
  </div>
218
225
  ) : (
219
226
  <div className="space-y-3.5">
220
- {renderNodes(descriptor.schema, values, errors, setValue)}
227
+ {renderNodes(descriptor.schema, values, errors, setValue, t)}
221
228
  </div>
222
229
  )}
223
230
  </div>
@@ -20,6 +20,7 @@ import { router } from "@inertiajs/core";
20
20
  import { Link } from "@inertiajs/react";
21
21
 
22
22
  import { ConfirmationDialog } from "@/base/partials/ConfirmationDialog";
23
+ import { isDangerIntent } from "@/base/utils/action-intent";
23
24
  import { getIcon, hasIcon } from "@/base/utils/icons";
24
25
  import type { PageAction } from "@/contracts/page-contract";
25
26
  import { renderLabel } from "@/i18n/render-label";
@@ -44,7 +45,8 @@ export function PageActionButton({ action }: { action: PageAction }): ReactEleme
44
45
  const [isWaiting, setIsWaiting] = useState(false);
45
46
 
46
47
  const target = resolveActionTarget(action);
47
- const variant: ButtonVariant = VARIANT_MAP[action.intent] ?? "outline";
48
+ const variant: ButtonVariant =
49
+ VARIANT_MAP[action.intent] ?? (isDangerIntent(action.intent) ? "destructive" : "outline");
48
50
  const isNavigation = target.kind === "link";
49
51
  // External loading (server-driven via action.loading) merges with local in-flight state
50
52
  const effectiveLoading = isLoading || action.loading === true;
@@ -29,7 +29,8 @@ export type EffectiveTheme = "light" | "dark";
29
29
  * 'system' consults host page first, then OS.
30
30
  */
31
31
  export function getEffectiveTheme(preference: Appearance): EffectiveTheme {
32
- if (preference !== "system") return preference;
32
+ // An unknown preference (ThemeMode is an open enum) resolves like "system".
33
+ if (preference === "light" || preference === "dark") return preference;
33
34
 
34
35
  const hostTheme: DetectedTheme = detectHostTheme();
35
36
  if (hostTheme === "dark") return "dark";
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Action intent is an open enum: a newer producer may send a value this
3
+ * renderer does not know. An unknown intent is treated as destructive (the
4
+ * safest reading), never as the neutral default, so a dangerous action is not
5
+ * rendered as an ordinary one.
6
+ */
7
+ const KNOWN_ACTION_INTENTS: ReadonlySet<string> = new Set([
8
+ "primary",
9
+ "secondary",
10
+ "danger",
11
+ "success",
12
+ "warning",
13
+ "info",
14
+ "link",
15
+ "ghost",
16
+ ]);
17
+
18
+ /** True for `danger` and for any non-empty intent this renderer does not know. */
19
+ export function isDangerIntent(intent: string | undefined | null): boolean {
20
+ if (!intent) return false;
21
+ return intent === "danger" || !KNOWN_ACTION_INTENTS.has(intent);
22
+ }
@@ -1,15 +1,15 @@
1
1
  /**
2
- * @generated by scripts/gen-contracts.mjs — DO NOT EDIT BY HAND.
2
+ * @generated by @middag-io/ui-contracts-codegen — DO NOT EDIT BY HAND.
3
3
  *
4
- * Barrel for the generated contract layer.
4
+ * Barrel of the generated contract layer.
5
5
  *
6
- * Source of truth: middag-php-ui value objects -> JSON Schema (draft 2020-12).
6
+ * Source of truth: middag-io/ui value objects -> JSON Schema (draft 2020-12).
7
7
  * Regenerate: npm run gen:contracts
8
8
  * Drift gate: npm run gen:contracts:check
9
9
  *
10
- * @source middag-php-ui/schema/{page-contract,fragment}.json
10
+ * @source middag-io/middag-php-ui@v1.11.0 schema/{page-contract.json,fragment.json}
11
11
  * @contract-version 1
12
- * @hash 61137d173165ca8e
12
+ * @hash 63f5044005aa4225
13
13
  */
14
- export * from "./contract-types";
15
- export { pageContractSchemaCore, fragmentSchemaCore } from "./contract-schema";
14
+ export * from "./types.js";
15
+ export { pageContractSchemaCore, fragmentSchemaCore } from "./schemas.js";