@middag-io/react 0.47.0 → 0.49.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 (41) hide show
  1. package/dist-lib/base/shell/BasicShell.d.ts +1 -1
  2. package/dist-lib/base/utils/icon-registry.d.ts +3 -2
  3. package/dist-lib/base/utils/icon-registry.d.ts.map +1 -1
  4. package/dist-lib/contracts/generated/index.d.ts +4 -4
  5. package/dist-lib/contracts/generated/index.d.ts.map +1 -1
  6. package/dist-lib/contracts/generated/schemas.d.ts +131 -163
  7. package/dist-lib/contracts/generated/schemas.d.ts.map +1 -1
  8. package/dist-lib/contracts/generated/types.d.ts +69 -43
  9. package/dist-lib/contracts/generated/types.d.ts.map +1 -1
  10. package/dist-lib/contracts/navigation.d.ts +5 -38
  11. package/dist-lib/contracts/navigation.d.ts.map +1 -1
  12. package/dist-lib/contracts/page-contract-schema.d.ts +3 -3
  13. package/dist-lib/contracts/shared-props.d.ts +10 -71
  14. package/dist-lib/contracts/shared-props.d.ts.map +1 -1
  15. package/dist-lib/engine/providers/auth.d.ts +2 -2
  16. package/dist-lib/engine/providers/auth.d.ts.map +1 -1
  17. package/dist-lib/engine/providers/flash.d.ts.map +1 -1
  18. package/dist-lib/index.d.ts +2 -3
  19. package/dist-lib/index.d.ts.map +1 -1
  20. package/dist-lib/middag-react.js +6166 -6144
  21. package/docs/public/schemas/ai-contract-manifest.json +9 -16
  22. package/docs/public/schemas/fragment.json +155 -87
  23. package/docs/public/schemas/manifest.json +4 -12
  24. package/docs/public/schemas/page-contract.json +155 -87
  25. package/docs/public/schemas/shared-props.json +2457 -114
  26. package/package.json +1 -1
  27. package/src/base/shell/BasicShell.tsx +7 -7
  28. package/src/base/utils/icon-registry.ts +3 -3
  29. package/src/contracts/generated/index.ts +4 -4
  30. package/src/contracts/generated/schemas.ts +66 -35
  31. package/src/contracts/generated/types.ts +71 -51
  32. package/src/contracts/navigation.ts +5 -52
  33. package/src/contracts/page-contract-schema.ts +2 -2
  34. package/src/contracts/shared-props.ts +10 -75
  35. package/src/engine/providers/auth.tsx +1 -1
  36. package/src/engine/providers/flash.tsx +0 -5
  37. package/dist-lib/contracts/connectors.d.ts +0 -50
  38. package/dist-lib/contracts/connectors.d.ts.map +0 -1
  39. package/docs/public/schemas/connectors.json +0 -97
  40. package/docs/public/schemas/navigation.json +0 -72
  41. package/src/contracts/connectors.ts +0 -60
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middag-io/react",
3
- "version": "0.47.0",
3
+ "version": "0.49.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",
@@ -7,7 +7,7 @@
7
7
  * the ReUI sidebar primitives, so any Community consumer gets a usable
8
8
  * dashboard frame without @middag-io/react-pro.
9
9
  *
10
- * Reads navigation from shared props (NavigationTreePayload, rendered flat —
10
+ * Reads navigation from shared props (NavigationTree, rendered flat —
11
11
  * top-level groups with one level of children) and page meta from the contract.
12
12
  * For rich navigation (drilldown, search, chrome panels), use the Pro
13
13
  * ProductShell via @middag-io/react-pro's registerProDefaults().
@@ -20,9 +20,9 @@ import { Link, usePage } from "@inertiajs/react";
20
20
  import { useIsDark } from "@/base/hooks/useIsDark";
21
21
  import { PageActionButton } from "@/base/shell/partials/PageActionButton";
22
22
  import { setAppearance } from "@/base/theme/appearance";
23
- import type { NavigationNode, NavigationTreePayload } from "@/contracts/navigation";
23
+ import type { NavigationNode, NavigationTree } from "@/contracts/navigation";
24
24
  import type { PageMeta } from "@/contracts/page-contract";
25
- import type { SharedProps, SharedPropsAuth } from "@/contracts/shared-props";
25
+ import type { SharedAuth, SharedProps } from "@/contracts/shared-props";
26
26
  import type { ShellProps } from "@/engine/registries";
27
27
  import { renderLabel } from "@/i18n/render-label";
28
28
  import { useTranslation } from "@/i18n/useTranslation";
@@ -51,7 +51,7 @@ import {
51
51
  } from "@/primitives/reui/sidebar";
52
52
  import { Toaster } from "@/primitives/reui/sonner";
53
53
 
54
- const EMPTY_NAV: NavigationTreePayload = { tree: [], footer: [], activeKey: "" };
54
+ const EMPTY_NAV: NavigationTree = { tree: [], footer: [], activeKey: "" };
55
55
 
56
56
  /** A single navigation leaf — a link (or label-only node) inside the menu. */
57
57
  function NavLeaf({ node, activeKey }: { node: NavigationNode; activeKey: string }): ReactElement {
@@ -90,7 +90,7 @@ function HeaderUserMenu({
90
90
  logoutUrl,
91
91
  csrfToken,
92
92
  }: {
93
- auth: SharedPropsAuth;
93
+ auth: SharedAuth;
94
94
  logoutUrl?: string;
95
95
  csrfToken?: string;
96
96
  }): ReactElement {
@@ -149,14 +149,14 @@ export function BasicShell({ children }: ShellProps): ReactElement {
149
149
  const { props } = usePage<SharedProps>();
150
150
  const isDark = useIsDark();
151
151
 
152
- const nav: NavigationTreePayload = (props as SharedProps).navigation ?? EMPTY_NAV;
152
+ const nav: NavigationTree = (props as SharedProps).navigation ?? EMPTY_NAV;
153
153
  const page: PageMeta = (props as SharedProps & { contract?: { page?: PageMeta } }).contract
154
154
  ?.page ?? { key: "unknown", title: "", breadcrumbs: [], actions: [] };
155
155
 
156
156
  // Header-right chrome inputs. `actions` are the contract's page-level actions
157
157
  // (Edit, back, etc.) — previously destructured into `page` but never rendered.
158
158
  // `logoutUrl`/`csrf_token` are optional shared props the app supplies.
159
- const auth: SharedPropsAuth | null | undefined = (props as SharedProps).auth;
159
+ const auth: SharedAuth | null | undefined = (props as SharedProps).auth;
160
160
  const actions = page.actions ?? [];
161
161
  // Canonical source is `auth.logoutUrl`; a top-level `logoutUrl` shared prop
162
162
  // is accepted as a fallback for hosts that inject it outside the auth object.
@@ -9,8 +9,6 @@
9
9
 
10
10
  import type { IconSvgElement } from "@hugeicons/react";
11
11
 
12
- import type { NavigationEntityType } from "@/contracts/navigation";
13
-
14
12
  /**
15
13
  * The maps live on globalThis so the registry stays ONE registry even when this
16
14
  * module is instantiated more than once.
@@ -58,8 +56,10 @@ export function registerIcon(name: string, icon: IconSvgElement): void {
58
56
 
59
57
  /**
60
58
  * Register an icon for a given entity type (navigation entity resolution).
59
+ * The navigation contract keeps 'entityType' an open string, so each product
60
+ * registers the types it sends.
61
61
  */
62
- export function registerEntityIcon(entityType: NavigationEntityType, icon: IconSvgElement): void {
62
+ export function registerEntityIcon(entityType: string, icon: IconSvgElement): void {
63
63
  entityIconMap.set(entityType, icon);
64
64
  }
65
65
 
@@ -7,9 +7,9 @@
7
7
  * Regenerate: npm run gen:contracts
8
8
  * Drift gate: npm run gen:contracts:check
9
9
  *
10
- * @source middag-io/middag-php-ui@v1.11.0 schema/{page-contract.json,fragment.json}
11
- * @contract-version 1
12
- * @hash 63f5044005aa4225
10
+ * @source middag-io/middag-php-ui@v1.13.0 schema/{page-contract.json,fragment.json,shared-props.json}
11
+ * @contract-version 2
12
+ * @hash a11a97d1f5ad9c63
13
13
  */
14
14
  export * from "./types.js";
15
- export { pageContractSchemaCore, fragmentSchemaCore } from "./schemas.js";
15
+ export { pageContractSchemaCore, fragmentSchemaCore, sharedPropsSchemaCore } from "./schemas.js";
@@ -7,9 +7,9 @@
7
7
  * Regenerate: npm run gen:contracts
8
8
  * Drift gate: npm run gen:contracts:check
9
9
  *
10
- * @source middag-io/middag-php-ui@v1.11.0 schema/{page-contract.json,fragment.json}
11
- * @contract-version 1
12
- * @hash 63f5044005aa4225
10
+ * @source middag-io/middag-php-ui@v1.13.0 schema/{page-contract.json,fragment.json,shared-props.json}
11
+ * @contract-version 2
12
+ * @hash a11a97d1f5ad9c63
13
13
  */
14
14
  import { z } from "zod";
15
15
  import type { NavigationNode, FormSectionNode, FormGroupNode, FormSchemaNode } from "./types.js";
@@ -103,24 +103,6 @@ export const LayoutDescriptorSchema = z.object({
103
103
  "meta": z.record(z.string(), z.unknown()).optional(),
104
104
  });
105
105
 
106
- export const ThemeModeSchema = z.union([z.enum(["light", "dark", "system"]), z.string()]);
107
-
108
- export const UserPreferencesSchema = z.object({
109
- "theme": ThemeModeSchema,
110
- "locale": z.string(),
111
- "timezone": z.string().optional(),
112
- "dateFormat": z.string().optional(),
113
- "numberFormat": z.string().optional(),
114
- }).catchall(z.unknown());
115
-
116
- export const IdentitySchema = z.object({
117
- "id": z.string(),
118
- "name": z.string(),
119
- "email": z.string().optional(),
120
- "avatarUrl": z.string().optional(),
121
- "roles": z.array(z.string()).optional(),
122
- });
123
-
124
106
  export const BrandingSchema = z.object({
125
107
  "appName": z.string(),
126
108
  "logoUrl": z.string().optional(),
@@ -128,10 +110,7 @@ export const BrandingSchema = z.object({
128
110
  });
129
111
 
130
112
  export const PageResourcesSchema = z.object({
131
- "preferences": UserPreferencesSchema,
132
- "capabilities": z.union([z.record(z.string(), z.boolean()), z.array(z.unknown()).max(0)]),
133
- "featureFlags": z.union([z.record(z.string(), z.boolean()), z.array(z.unknown()).max(0)]),
134
- "user": IdentitySchema.optional(),
113
+ "featureFlags": z.record(z.string(), z.boolean()),
135
114
  "branding": BrandingSchema.optional(),
136
115
  });
137
116
 
@@ -147,7 +126,7 @@ export const NotificationSchema = z.object({
147
126
  });
148
127
 
149
128
  export const PageContractSchema = z.object({
150
- "version": z.literal("1"),
129
+ "version": z.literal("2"),
151
130
  "shell": z.string(),
152
131
  "page": PageMetaSchema,
153
132
  "layout": LayoutDescriptorSchema,
@@ -158,14 +137,12 @@ export const PageContractSchema = z.object({
158
137
 
159
138
  export const FragmentKindSchema = z.enum(["block", "region", "table", "form", "detail", "inspector", "notifications", "custom"]);
160
139
 
161
- export const ResourcePatchSchema = z.union([z.object({
162
- "preferences": UserPreferencesSchema.optional(),
163
- "capabilities": z.record(z.string(), z.boolean()).optional(),
140
+ export const ResourcePatchSchema = z.object({
164
141
  "featureFlags": z.record(z.string(), z.boolean()).optional(),
165
- }), z.array(z.unknown()).max(0)]);
142
+ });
166
143
 
167
144
  export const FragmentSchema = z.object({
168
- "version": z.literal("1"),
145
+ "version": z.literal("2"),
169
146
  "kind": FragmentKindSchema,
170
147
  "payload": z.record(z.string(), z.unknown()).optional(),
171
148
  "notifications": z.array(NotificationSchema).optional(),
@@ -186,12 +163,24 @@ export const EditablePanelDescriptorSchema = z.object({
186
163
  "width": z.number().int(),
187
164
  });
188
165
 
166
+ export const IdentitySchema = z.object({
167
+ "id": z.string(),
168
+ "name": z.string(),
169
+ "email": z.string().optional(),
170
+ "avatarUrl": z.string().optional(),
171
+ "roles": z.array(z.string()).optional(),
172
+ });
173
+
189
174
  export const NavigationNodeSchema: z.ZodType<NavigationNode> = z.object({
190
175
  "key": z.string(),
191
176
  "label": LabelSchema,
192
177
  "icon": z.string().optional(),
193
178
  "href": z.string().optional(),
194
179
  "badge": z.string().optional(),
180
+ "entityType": z.string().optional(),
181
+ "badgeVariant": z.string().optional(),
182
+ "statusColor": z.string().optional(),
183
+ "target": z.string().optional(),
195
184
  "active": z.literal(true).optional(),
196
185
  "drilldown": z.literal(true).optional(),
197
186
  "collapsible": z.literal(true).optional(),
@@ -199,6 +188,51 @@ export const NavigationNodeSchema: z.ZodType<NavigationNode> = z.object({
199
188
  "children": z.array(z.lazy(() => NavigationNodeSchema)).optional(),
200
189
  });
201
190
 
191
+ export const NavigationTreeSchema = z.object({
192
+ "tree": z.array(NavigationNodeSchema),
193
+ "activeKey": z.string(),
194
+ "footer": z.array(NavigationNodeSchema),
195
+ });
196
+
197
+ export const SharedAuthSchema = z.object({
198
+ "id": z.string(),
199
+ "name": z.string(),
200
+ "email": z.string().optional(),
201
+ "avatarUrl": z.string().optional(),
202
+ "roles": z.array(z.string()).optional(),
203
+ "capabilities": z.array(z.string()),
204
+ "logoutUrl": z.string().optional(),
205
+ });
206
+
207
+ export const ThemeModeSchema = z.union([z.enum(["light", "dark", "system"]), z.string()]);
208
+
209
+ export const SharedThemeSchema = z.object({
210
+ "appearance": ThemeModeSchema.optional(),
211
+ "strings": z.record(z.string(), z.string()).optional(),
212
+ });
213
+
214
+ export const FlashMessagesSchema = z.object({
215
+ "success": z.string().optional(),
216
+ "error": z.string().optional(),
217
+ "info": z.string().optional(),
218
+ "warning": z.string().optional(),
219
+ });
220
+
221
+ export const FieldErrorSchema = z.union([z.string(), z.array(z.string())]);
222
+
223
+ export const FormErrorsSchema = z.record(z.string(), FieldErrorSchema);
224
+
225
+ export const SharedPropsSchema = z.object({
226
+ "auth": SharedAuthSchema.optional(),
227
+ "theme": SharedThemeSchema.optional(),
228
+ "flash": FlashMessagesSchema.optional(),
229
+ "errors": FormErrorsSchema.optional(),
230
+ "csrf_token": z.string().optional(),
231
+ "locale": z.string().optional(),
232
+ "scope": z.record(z.string(), z.unknown()).optional(),
233
+ "navigation": NavigationTreeSchema.optional(),
234
+ }).catchall(z.unknown());
235
+
202
236
  export const ValueFormatSchema = z.union([z.enum(["text", "date", "datetime", "time", "number", "currency", "boolean", "badge"]), z.string()]);
203
237
 
204
238
  export const ColumnVariantSchema = z.union([z.enum(["text", "status", "badge", "boolean", "timestamp", "link", "rich_status", "html", "link_group", "annotated", "progress"]), z.string()]);
@@ -290,10 +324,6 @@ export const FileValueSchema = z.union([z.string(), z.object({
290
324
  "uploadToken": z.string().optional(),
291
325
  })]);
292
326
 
293
- export const FieldErrorSchema = z.union([z.string(), z.array(z.string())]);
294
-
295
- export const FormErrorsSchema = z.record(z.string(), FieldErrorSchema);
296
-
297
327
  export const FormFieldValidationSchema = z.object({
298
328
  "minLength": z.number().int().optional(),
299
329
  "maxLength": z.number().int().optional(),
@@ -563,3 +593,4 @@ export const RenderTargetSchema = z.enum(["html", "props"]);
563
593
 
564
594
  export const pageContractSchemaCore = PageContractSchema;
565
595
  export const fragmentSchemaCore = FragmentSchema;
596
+ export const sharedPropsSchemaCore = SharedPropsSchema;
@@ -7,9 +7,9 @@
7
7
  * Regenerate: npm run gen:contracts
8
8
  * Drift gate: npm run gen:contracts:check
9
9
  *
10
- * @source middag-io/middag-php-ui@v1.11.0 schema/{page-contract.json,fragment.json}
11
- * @contract-version 1
12
- * @hash 63f5044005aa4225
10
+ * @source middag-io/middag-php-ui@v1.13.0 schema/{page-contract.json,fragment.json,shared-props.json}
11
+ * @contract-version 2
12
+ * @hash a11a97d1f5ad9c63
13
13
  */
14
14
  export type Label = string | Translatable;
15
15
  export type ActionTarget =
@@ -44,7 +44,6 @@ export type ActionIntent =
44
44
  | "link"
45
45
  | "ghost"
46
46
  | (string & {});
47
- export type ThemeMode = "light" | "dark" | "system" | (string & {});
48
47
  export type NotificationLevel = "success" | "info" | "warning" | "error" | (string & {});
49
48
  export type FragmentKind =
50
49
  | "block"
@@ -55,17 +54,8 @@ export type FragmentKind =
55
54
  | "inspector"
56
55
  | "notifications"
57
56
  | "custom";
58
- export type ResourcePatch =
59
- | {
60
- preferences?: UserPreferences;
61
- capabilities?: {
62
- [k: string]: boolean;
63
- };
64
- featureFlags?: {
65
- [k: string]: boolean;
66
- };
67
- }
68
- | [];
57
+ export type ThemeMode = "light" | "dark" | "system" | (string & {});
58
+ export type FieldError = string | string[];
69
59
  export type ValueFormat =
70
60
  | "text"
71
61
  | "date"
@@ -118,7 +108,6 @@ export type FileValue =
118
108
  id?: string;
119
109
  uploadToken?: string;
120
110
  };
121
- export type FieldError = string | string[];
122
111
  export type FormSchemaNode = FormFieldNode | FormSectionNode | FormGroupNode | FormHeaderNode;
123
112
  export type FormFieldNode =
124
113
  | {
@@ -411,7 +400,7 @@ export type FormComponent =
411
400
  export type RenderTarget = "html" | "props";
412
401
 
413
402
  export interface PageContract {
414
- version: "1";
403
+ version: "2";
415
404
  shell: string;
416
405
  page: PageMeta;
417
406
  layout: LayoutDescriptor;
@@ -495,35 +484,11 @@ export interface PollConfig {
495
484
  stopAfterMs?: number;
496
485
  }
497
486
  export interface PageResources {
498
- preferences: UserPreferences;
499
- capabilities:
500
- | {
501
- [k: string]: boolean;
502
- }
503
- | [];
504
- featureFlags:
505
- | {
506
- [k: string]: boolean;
507
- }
508
- | [];
509
- user?: Identity;
487
+ featureFlags: {
488
+ [k: string]: boolean;
489
+ };
510
490
  branding?: Branding;
511
491
  }
512
- export interface UserPreferences {
513
- theme: ThemeMode;
514
- locale: string;
515
- timezone?: string;
516
- dateFormat?: string;
517
- numberFormat?: string;
518
- [k: string]: unknown;
519
- }
520
- export interface Identity {
521
- id: string;
522
- name: string;
523
- email?: string;
524
- avatarUrl?: string;
525
- roles?: string[];
526
- }
527
492
  export interface Branding {
528
493
  appName: string;
529
494
  logoUrl?: string;
@@ -538,7 +503,7 @@ export interface Notification {
538
503
  action?: Action;
539
504
  }
540
505
  export interface Fragment {
541
- version: "1";
506
+ version: "2";
542
507
  kind: FragmentKind;
543
508
  payload?: {
544
509
  [k: string]: unknown;
@@ -547,6 +512,11 @@ export interface Fragment {
547
512
  resources?: ResourcePatch;
548
513
  customType?: string;
549
514
  }
515
+ export interface ResourcePatch {
516
+ featureFlags?: {
517
+ [k: string]: boolean;
518
+ };
519
+ }
550
520
  export interface InspectorDescriptor {
551
521
  endpoint: string;
552
522
  width: number;
@@ -558,18 +528,74 @@ export interface EditablePanelDescriptor {
558
528
  submitMethod: "post" | "put" | "patch";
559
529
  width: number;
560
530
  }
531
+ export interface Identity {
532
+ id: string;
533
+ name: string;
534
+ email?: string;
535
+ avatarUrl?: string;
536
+ roles?: string[];
537
+ }
561
538
  export interface NavigationNode {
562
539
  key: string;
563
540
  label: Label;
564
541
  icon?: string;
565
542
  href?: string;
566
543
  badge?: string;
544
+ entityType?: string;
545
+ badgeVariant?: string;
546
+ statusColor?: string;
547
+ target?: string;
567
548
  active?: true;
568
549
  drilldown?: true;
569
550
  collapsible?: true;
570
551
  defaultOpen?: true;
571
552
  children?: NavigationNode[];
572
553
  }
554
+ export interface NavigationTree {
555
+ tree: NavigationNode[];
556
+ activeKey: string;
557
+ footer: NavigationNode[];
558
+ }
559
+ export interface SharedProps {
560
+ auth?: SharedAuth;
561
+ theme?: SharedTheme;
562
+ flash?: FlashMessages;
563
+ errors?: FormErrors;
564
+ csrf_token?: string;
565
+ locale?: string;
566
+ scope?: {
567
+ [k: string]: unknown;
568
+ };
569
+ navigation?: NavigationTree;
570
+ [k: string]: unknown;
571
+ }
572
+ export interface SharedAuth {
573
+ id: string;
574
+ name: string;
575
+ email?: string;
576
+ avatarUrl?: string;
577
+ roles?: string[];
578
+ capabilities: string[];
579
+ logoutUrl?: string;
580
+ }
581
+ export interface SharedTheme {
582
+ appearance?: ThemeMode;
583
+ strings?: {
584
+ [k: string]: string;
585
+ };
586
+ }
587
+ export interface FlashMessages {
588
+ success?: string;
589
+ error?: string;
590
+ info?: string;
591
+ warning?: string;
592
+ }
593
+ /**
594
+ * Validation errors keyed by field name. The reserved key "_" carries form-level errors; dotted keys target nested fields.
595
+ */
596
+ export interface FormErrors {
597
+ [k: string]: FieldError;
598
+ }
573
599
  export interface TableConfig {
574
600
  columns: Column[];
575
601
  filters?: FilterDefinition[];
@@ -632,12 +658,6 @@ export interface FormStep {
632
658
  fields: string[];
633
659
  help?: Label;
634
660
  }
635
- /**
636
- * Validation errors keyed by field name. The reserved key "_" carries form-level errors; dotted keys target nested fields.
637
- */
638
- export interface FormErrors {
639
- [k: string]: FieldError;
640
- }
641
661
  export interface FieldPropsBase {
642
662
  label: string;
643
663
  placeholder?: string;
@@ -1,56 +1,9 @@
1
1
  /**
2
- * Navigation contract — typed shape for the `navigation` Inertia shared prop.
2
+ * Navigation contract — the 'navigation' slot of the shared props.
3
3
  *
4
- * Unified tree model.
5
- * PHP serializes this from navigation_registry during boot().
6
- * Frontend reads it from usePage().props.navigation.
4
+ * Generated from the middag-php-ui 'NavigationTree' and 'NavigationNode' value
5
+ * objects. The host builds the tree in 'NavigationRegistryInterface::build()';
6
+ * the frontend reads it from usePage<SharedProps>().props.navigation.
7
7
  */
8
8
 
9
- /** Entity types for automatic icon resolution when no explicit icon is set. */
10
- export type NavigationEntityType =
11
- | "connector"
12
- | "workflow"
13
- | "segment"
14
- | "instancegroup"
15
- | "condition"
16
- | "compliance"
17
- | "offering"
18
- | "order"
19
- | "course"
20
- | "category"
21
- | "form"
22
- | "certificate";
23
-
24
- export interface NavigationNode {
25
- key: string;
26
- label: string;
27
- icon?: string;
28
- /** Entity type for automatic icon resolution (CC-based). Overrides depth fallback. */
29
- entityType?: NavigationEntityType;
30
- href?: string;
31
- badge?: string | number;
32
- /** Badge display variant: 'count' (muted text, default) or 'alert' (red pill like WooCommerce). */
33
- badgeVariant?: "count" | "alert";
34
- active?: boolean;
35
- /** When true, clicking replaces sidebar with this node's children + back. */
36
- drilldown?: boolean;
37
- /** When true, group renders with a toggle to expand/collapse its content. */
38
- collapsible?: boolean;
39
- /** Whether a collapsible group starts expanded (default: false). */
40
- defaultOpen?: boolean;
41
- /** CSS color for status dot shown next to drilldown title (e.g. 'var(--success)'). */
42
- statusColor?: string;
43
- /** Link target attribute (e.g. '_blank'). External URLs (http/https) auto-detect. */
44
- target?: string;
45
- children?: NavigationNode[];
46
- }
47
-
48
- /** Navigation payload using the unified tree model */
49
- export interface NavigationTreePayload {
50
- tree: NavigationNode[];
51
- activeKey: string;
52
- /** Stack of drilled-down node keys (for ← back navigation). */
53
- drilldownStack?: string[];
54
- /** Persistent footer items (Settings, Help). */
55
- footer: NavigationNode[];
56
- }
9
+ export type { NavigationNode, NavigationTree } from "@/contracts/generated";
@@ -8,8 +8,8 @@
8
8
  * DA-03: the host-extensible parts are validated loosely. The generated core is
9
9
  * already lenient on unknown keys (Pro overlay + forward-compat fields are
10
10
  * stripped, not rejected); on top of that, `resources` is relaxed to a
11
- * permissive record because hosts patch it (preferences/capabilities/branding)
12
- * and the React Pro overlay (auth/locale) rides alongside.
11
+ * permissive record because hosts patch it (feature flags/branding) and the
12
+ * React Pro overlay rides alongside.
13
13
  */
14
14
 
15
15
  import { z } from "zod";
@@ -1,90 +1,25 @@
1
1
  /**
2
- * SharedProps — typed Inertia shared props sent on every request.
2
+ * Shared props — the Inertia props every host sends on each request.
3
3
  *
4
- * PHP side: inertia_manager::share() in http_kernel boot.
5
- * Frontend: usePage<SharedProps>().props
4
+ * The wire shape is generated from the middag-php-ui 'SharedProps' value object
5
+ * (schema/shared-props.json). Read them with usePage<SharedProps>().props.
6
6
  */
7
7
 
8
- import type { NavigationTreePayload } from "@/contracts/navigation";
9
-
10
- export interface SharedPropsAuth {
11
- /** Moodle user ID */
12
- id: number;
13
- /** Full display name */
14
- name: string;
15
- /** Email address */
16
- email: string;
17
- /** URL to user avatar (Moodle profile picture) */
18
- avatarUrl?: string;
19
- /** Array of Moodle capability strings the user holds in current context */
20
- capabilities: string[];
21
- /** Logout URL (Moodle sesskey-signed). Present when the host injects it. */
22
- logoutUrl?: string;
23
- }
24
-
25
- export interface SharedPropsTheme {
26
- /** Pre-loaded i18n strings for the current page (key → translated string) */
27
- strings?: Record<string, string>;
28
- /**
29
- * Current appearance preference: 'system' | 'light' | 'dark'.
30
- * Sent from server to sync cross-device. Client reads localStorage first.
31
- */
32
- appearance?: "system" | "light" | "dark";
33
- /**
34
- * Moodle brand color (hex, e.g. "#1177d1").
35
- * Present when local_middag/inherit_theme_colors = ON.
36
- * PHP injects :root { --middag-brand: <value> } in page head.
37
- */
38
- brandColor?: string;
39
- /** Whether Moodle theme color inheritance is active */
40
- inherit?: boolean;
41
- }
42
-
43
- export interface SharedPropsFlash {
44
- /** Success message to show as toast */
45
- success?: string;
46
- /** Error message to show as toast */
47
- error?: string;
48
- /** Info message to show as toast */
49
- info?: string;
50
- /** Warning message to show as toast */
51
- warning?: string;
52
- toast?: {
53
- severity: "success" | "error" | "warning" | "info";
54
- message: string;
55
- duration?: number;
56
- };
57
- }
8
+ export type { FlashMessages, SharedAuth, SharedProps, SharedTheme } from "@/contracts/generated";
58
9
 
10
+ /** One tab of the host admin tab bar. */
59
11
  export interface AdminTabItem {
60
12
  key: string;
61
13
  label: string;
62
14
  href: string;
63
15
  }
64
16
 
17
+ /**
18
+ * The 'admin_tabs' prop some hosts add next to the shared props. It is wire with
19
+ * no php-ui value object: each host builds it, and the shared props carry it
20
+ * through their open index signature.
21
+ */
65
22
  export interface AdminTabsProps {
66
23
  active: string;
67
24
  items: AdminTabItem[];
68
25
  }
69
-
70
- export interface SharedProps {
71
- navigation: NavigationTreePayload;
72
- /**
73
- * Authenticated user. Optional/null on guest-facing pages (e.g. login) where
74
- * no user is established yet. AuthProvider tolerates its absence: `user` is
75
- * null, `isAuthenticated` false, and every capability check returns false.
76
- */
77
- auth?: SharedPropsAuth | null;
78
- theme: SharedPropsTheme;
79
- flash?: SharedPropsFlash;
80
- /** Effective locale string, e.g. "pt-BR", "en" */
81
- locale: string;
82
- /** MIDDAG version string, e.g. "5.0.0" */
83
- version: string;
84
- /** Global scope data from global_scope_manager (extensions add their keys) */
85
- scope?: Record<string, unknown>;
86
- /** CSRF/session token (Moodle sesskey) for state-changing requests. */
87
- csrf_token?: string;
88
- /** Index signature required by Inertia's PageProps constraint (usePage<SharedProps>()). */
89
- [key: string]: unknown;
90
- }
@@ -11,7 +11,7 @@ import type { SharedProps } from "@/contracts/shared-props";
11
11
 
12
12
  interface AuthContextValue {
13
13
  /** Authenticated user, or null on guest pages (no `auth` shared prop). */
14
- user: { id: number; name: string; email: string; avatarUrl?: string } | null;
14
+ user: { id: string; name: string; email?: string; avatarUrl?: string } | null;
15
15
  capabilities: string[];
16
16
  can: (capability: string) => boolean;
17
17
  /** True when an authenticated user is present. False for guests. */
@@ -31,11 +31,6 @@ export function FlashProvider({ children }: { children: ReactNode }) {
31
31
  if (flash.error) toast.error(flash.error);
32
32
  if (flash.info) toast.info(flash.info);
33
33
  if (flash.warning) toast.warning(flash.warning);
34
- if (flash.toast) {
35
- toast[flash.toast.severity](flash.toast.message, {
36
- duration: flash.toast.duration ?? 5000,
37
- });
38
- }
39
34
  }, [flash]);
40
35
 
41
36
  return <>{children}</>;