@arcote.tech/platform 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts ADDED
@@ -0,0 +1,165 @@
1
+ import type { ComponentType, LazyExoticComponent, ReactNode } from "react";
2
+ import type { ArcContextElementAny } from "@arcote.tech/arc";
3
+
4
+ // ---------------------------------------------------------------------------
5
+ // Slot IDs
6
+ // ---------------------------------------------------------------------------
7
+
8
+ export type SlotId = string & { readonly __brand?: "SlotId" };
9
+
10
+ // ---------------------------------------------------------------------------
11
+ // Ordering
12
+ // ---------------------------------------------------------------------------
13
+
14
+ export interface FragmentOrdering {
15
+ /** Niższy = wcześniej. Domyślnie 0. */
16
+ order?: number;
17
+ /** Renderuj po fragmencie o podanym id. */
18
+ after?: string;
19
+ /** Renderuj przed fragmentem o podanym id. */
20
+ before?: string;
21
+ }
22
+
23
+ // ---------------------------------------------------------------------------
24
+ // Fragment base — unified interface for all fragments
25
+ // ---------------------------------------------------------------------------
26
+
27
+ export type ArcComponent = ComponentType<any> | LazyExoticComponent<ComponentType<any>>;
28
+
29
+ interface FragmentBase {
30
+ readonly id: string;
31
+ readonly types: readonly string[];
32
+ moduleId: string;
33
+ is(type: string): boolean;
34
+ }
35
+
36
+ // ---------------------------------------------------------------------------
37
+ // Concrete fragment types
38
+ // ---------------------------------------------------------------------------
39
+
40
+ export interface SlotFragment extends FragmentBase {
41
+ readonly types: readonly ["slot"];
42
+ readonly slotId: SlotId;
43
+ readonly component: ArcComponent;
44
+ readonly ordering: FragmentOrdering;
45
+ }
46
+
47
+ export type ArcLayoutComponent = ComponentType<{ children: ReactNode }>;
48
+
49
+ export interface PageFragment<
50
+ TPath extends string = string,
51
+ > extends FragmentBase {
52
+ readonly types: readonly ["page"];
53
+ readonly path: TPath;
54
+ readonly component: ArcComponent;
55
+ readonly layout?: ArcLayoutComponent;
56
+ readonly icon?: ComponentType<{ className?: string }>;
57
+ readonly label?: string | ReactNode;
58
+ readonly tooltip?: string | ReactNode;
59
+ readonly children?: readonly PageFragment[];
60
+ }
61
+
62
+ export type PageShellProps = {
63
+ children: ReactNode;
64
+ tabs: readonly PageFragment[];
65
+ };
66
+
67
+ export interface WrapperFragment extends FragmentBase {
68
+ readonly types: readonly ["wrapper"];
69
+ readonly component: ComponentType<{ children: ReactNode }>;
70
+ readonly ordering: FragmentOrdering;
71
+ }
72
+
73
+ export interface ContextElementFragment extends FragmentBase {
74
+ readonly types: readonly ["context-element"];
75
+ readonly element: ArcContextElementAny;
76
+ }
77
+
78
+ export type ArcFragment =
79
+ | SlotFragment
80
+ | PageFragment
81
+ | WrapperFragment
82
+ | ContextElementFragment;
83
+
84
+ export type PublicArcFragment = ArcFragment;
85
+
86
+ // ---------------------------------------------------------------------------
87
+ // Moduł
88
+ // ---------------------------------------------------------------------------
89
+
90
+ export interface ArcModule {
91
+ readonly id: string;
92
+ readonly fragments: readonly ArcFragment[];
93
+ readonly publicFragments: readonly ArcFragment[];
94
+ }
95
+
96
+ // ---------------------------------------------------------------------------
97
+ // Built Module — enriched return type from module().build()
98
+ // ---------------------------------------------------------------------------
99
+
100
+ export type ExtractPages<T> = {
101
+ readonly [K in keyof T]: T[K] extends PageFragment<infer P> ? P : never;
102
+ };
103
+
104
+ export type BuiltModule<
105
+ TPages = {},
106
+ TCtx = undefined,
107
+ TScope extends string | undefined = undefined,
108
+ > = ArcModule & {
109
+ readonly pages: Readonly<TPages>;
110
+ } & (TCtx extends undefined ? {} : { readonly context: TCtx })
111
+ & (TScope extends undefined ? {} : { readonly scope: TScope });
112
+
113
+ // ---------------------------------------------------------------------------
114
+ // Typed navigation
115
+ // ---------------------------------------------------------------------------
116
+
117
+ /** @deprecated Use module().build() pages field instead */
118
+ export type PublicPaths<T extends ArcModule> =
119
+ T["publicFragments"][number] extends infer F
120
+ ? F extends PageFragment<infer P>
121
+ ? P
122
+ : never
123
+ : never;
124
+
125
+ // ---------------------------------------------------------------------------
126
+ // Factory (deprecated — use module() instead)
127
+ // ---------------------------------------------------------------------------
128
+
129
+ export interface SlotOptions extends FragmentOrdering {
130
+ id?: string;
131
+ }
132
+
133
+ export interface PageOptions {
134
+ id?: string;
135
+ layout?: ArcLayoutComponent;
136
+ icon?: ComponentType<{ className?: string }>;
137
+ label?: string | ReactNode;
138
+ tooltip?: string | ReactNode;
139
+ children?: PageFragment[];
140
+ }
141
+
142
+ export interface WrapperOptions extends FragmentOrdering {
143
+ id?: string;
144
+ }
145
+
146
+ export interface ArcFactoryMethods {
147
+ slot: (
148
+ slotId: SlotId | string,
149
+ component: ArcComponent,
150
+ options?: SlotOptions,
151
+ ) => SlotFragment;
152
+ page: <TPath extends string>(
153
+ path: TPath,
154
+ component: ArcComponent,
155
+ options?: PageOptions,
156
+ ) => PageFragment<TPath>;
157
+ wrapper: (
158
+ component: ComponentType<{ children: ReactNode }>,
159
+ options?: WrapperOptions,
160
+ ) => WrapperFragment;
161
+ }
162
+
163
+ export type ArcFactory = (
164
+ methods: ArcFactoryMethods,
165
+ ) => PublicArcFragment[] | void;