@relax.js/core 1.0.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 (194) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +188 -0
  3. package/dist/DataLoader.d.ts +51 -0
  4. package/dist/DependencyInjection.d.ts +271 -0
  5. package/dist/DependencyInjectionOld.d.ts +35 -0
  6. package/dist/Metadata.d.ts +8 -0
  7. package/dist/SequentialId.d.ts +47 -0
  8. package/dist/_alt/src/MustardEngine.d.ts +30 -0
  9. package/dist/_alt/src/MustardParser.d.ts +63 -0
  10. package/dist/_alt/src/MustardParser2.d.ts +35 -0
  11. package/dist/_alt/src/pipes.d.ts +93 -0
  12. package/dist/_alt/src/template.d.ts +166 -0
  13. package/dist/_alt/src/tools.d.ts +4 -0
  14. package/dist/_alt/tests/pipes.tests.d.ts +1 -0
  15. package/dist/_alt/tests/template.tests.d.ts +1 -0
  16. package/dist/_alt/vitest.config.d.ts +2 -0
  17. package/dist/collections/Index.d.ts +1 -0
  18. package/dist/collections/LinkedList.d.ts +75 -0
  19. package/dist/collections/Pager.d.ts +15 -0
  20. package/dist/collections/index.js +2 -0
  21. package/dist/collections/index.js.map +7 -0
  22. package/dist/collections/index.mjs +2 -0
  23. package/dist/collections/index.mjs.map +7 -0
  24. package/dist/components/Table.d.ts +13 -0
  25. package/dist/components/index.d.ts +4 -0
  26. package/dist/components/index.js +128 -0
  27. package/dist/components/index.js.map +7 -0
  28. package/dist/components/index.mjs +128 -0
  29. package/dist/components/index.mjs.map +7 -0
  30. package/dist/components/lists/Table.d.ts +59 -0
  31. package/dist/components/lists/TreeView.d.ts +67 -0
  32. package/dist/components/lists/index.d.ts +2 -0
  33. package/dist/components/loader.d.ts +60 -0
  34. package/dist/components/menus/MenuItem.d.ts +30 -0
  35. package/dist/components/menus/TopMenu.d.ts +16 -0
  36. package/dist/components/menus/index.d.ts +2 -0
  37. package/dist/components/panels/tabs.d.ts +15 -0
  38. package/dist/di/index.d.ts +1 -0
  39. package/dist/di/index.js +2 -0
  40. package/dist/di/index.js.map +7 -0
  41. package/dist/di/index.mjs +2 -0
  42. package/dist/di/index.mjs.map +7 -0
  43. package/dist/elements/CopyAttributes.d.ts +2 -0
  44. package/dist/elements/dom.d.ts +18 -0
  45. package/dist/elements/index.d.ts +2 -0
  46. package/dist/elements/index.js +2 -0
  47. package/dist/elements/index.js.map +7 -0
  48. package/dist/elements/index.mjs +2 -0
  49. package/dist/elements/index.mjs.map +7 -0
  50. package/dist/errors.d.ts +71 -0
  51. package/dist/forms/FormReader.d.ts +182 -0
  52. package/dist/forms/FormValidator.d.ts +114 -0
  53. package/dist/forms/ValidationRules.d.ts +103 -0
  54. package/dist/forms/index.d.ts +4 -0
  55. package/dist/forms/index.js +2 -0
  56. package/dist/forms/index.js.map +7 -0
  57. package/dist/forms/index.mjs +2 -0
  58. package/dist/forms/index.mjs.map +7 -0
  59. package/dist/forms/setFormData.d.ts +49 -0
  60. package/dist/getParentComponent.d.ts +43 -0
  61. package/dist/html/TableRenderer.d.ts +44 -0
  62. package/dist/html/TreeBinder.d.ts +9 -0
  63. package/dist/html/html.d.ts +55 -0
  64. package/dist/html/index.d.ts +5 -0
  65. package/dist/html/index.js +2 -0
  66. package/dist/html/index.js.map +7 -0
  67. package/dist/html/index.mjs +2 -0
  68. package/dist/html/index.mjs.map +7 -0
  69. package/dist/html/template.d.ts +167 -0
  70. package/dist/http/ServerSentEvents.d.ts +116 -0
  71. package/dist/http/SimpleWebSocket.d.ts +153 -0
  72. package/dist/http/http.d.ts +177 -0
  73. package/dist/http/index.d.ts +3 -0
  74. package/dist/http/index.js +2 -0
  75. package/dist/http/index.js.map +7 -0
  76. package/dist/http/index.mjs +2 -0
  77. package/dist/http/index.mjs.map +7 -0
  78. package/dist/i18n/i18n.d.ts +105 -0
  79. package/dist/i18n/icu.d.ts +64 -0
  80. package/dist/i18n/index.d.ts +2 -0
  81. package/dist/i18n/index.js +2 -0
  82. package/dist/i18n/index.js.map +7 -0
  83. package/dist/i18n/index.mjs +2 -0
  84. package/dist/i18n/index.mjs.map +7 -0
  85. package/dist/index.d.ts +16 -0
  86. package/dist/index.js +5 -0
  87. package/dist/index.js.map +7 -0
  88. package/dist/index.mjs +5 -0
  89. package/dist/index.mjs.map +7 -0
  90. package/dist/lib/DataLoader.d.ts +51 -0
  91. package/dist/lib/DependencyInjection.d.ts +271 -0
  92. package/dist/lib/InvokeParent.d.ts +10 -0
  93. package/dist/lib/Pipes.d.ts +236 -0
  94. package/dist/lib/SequentialId.d.ts +47 -0
  95. package/dist/lib/collections/Index.d.ts +1 -0
  96. package/dist/lib/collections/LinkedList.d.ts +75 -0
  97. package/dist/lib/collections/Pager.d.ts +15 -0
  98. package/dist/lib/collections/TableRenderer.d.ts +44 -0
  99. package/dist/lib/di/index.d.ts +1 -0
  100. package/dist/lib/elements/CopyAttributes.d.ts +2 -0
  101. package/dist/lib/elements/dom.d.ts +18 -0
  102. package/dist/lib/elements/index.d.ts +2 -0
  103. package/dist/lib/errors.d.ts +71 -0
  104. package/dist/lib/forms/FormReader.d.ts +182 -0
  105. package/dist/lib/forms/FormValidator.d.ts +114 -0
  106. package/dist/lib/forms/ValidationRules.d.ts +103 -0
  107. package/dist/lib/forms/index.d.ts +4 -0
  108. package/dist/lib/forms/setFormData.d.ts +49 -0
  109. package/dist/lib/getParentComponent.d.ts +43 -0
  110. package/dist/lib/html/TableRenderer.d.ts +44 -0
  111. package/dist/lib/html/TreeBinder.d.ts +9 -0
  112. package/dist/lib/html/html.d.ts +55 -0
  113. package/dist/lib/html/html2.d.ts +55 -0
  114. package/dist/lib/html/index.d.ts +5 -0
  115. package/dist/lib/html/m.d.ts +167 -0
  116. package/dist/lib/html/m2.d.ts +8 -0
  117. package/dist/lib/html/m3.d.ts +0 -0
  118. package/dist/lib/html/template.d.ts +167 -0
  119. package/dist/lib/http/HttpClient.d.ts +153 -0
  120. package/dist/lib/http/ServerSentEvents.d.ts +116 -0
  121. package/dist/lib/http/SimpleWebSocket.d.ts +153 -0
  122. package/dist/lib/http/http.d.ts +177 -0
  123. package/dist/lib/http/index.d.ts +3 -0
  124. package/dist/lib/i18n/i18n.d.ts +105 -0
  125. package/dist/lib/i18n/icu.d.ts +64 -0
  126. package/dist/lib/i18n/index.d.ts +2 -0
  127. package/dist/lib/index.d.ts +16 -0
  128. package/dist/lib/routing/NavigateRouteEvent.d.ts +52 -0
  129. package/dist/lib/routing/RouteLink.d.ts +7 -0
  130. package/dist/lib/routing/Routing.d.ts +270 -0
  131. package/dist/lib/routing/RoutingTarget.d.ts +22 -0
  132. package/dist/lib/routing/index.d.ts +7 -0
  133. package/dist/lib/routing/navigation.d.ts +70 -0
  134. package/dist/lib/routing/routeMatching.d.ts +21 -0
  135. package/dist/lib/routing/routeTargetRegistry.d.ts +23 -0
  136. package/dist/lib/routing/types.d.ts +130 -0
  137. package/dist/lib/templates/NodeTemplate.d.ts +38 -0
  138. package/dist/lib/templates/accessorParser.d.ts +87 -0
  139. package/dist/lib/templates/parseTemplate.d.ts +6 -0
  140. package/dist/lib/templates/tokenizer.d.ts +76 -0
  141. package/dist/lib/tools.d.ts +30 -0
  142. package/dist/lib/utils/index.d.ts +4 -0
  143. package/dist/pipes.d.ts +236 -0
  144. package/dist/routing/NavigateRouteEvent.d.ts +52 -0
  145. package/dist/routing/RouteLink.d.ts +7 -0
  146. package/dist/routing/RoutingTarget.d.ts +22 -0
  147. package/dist/routing/index.d.ts +7 -0
  148. package/dist/routing/index.js +5 -0
  149. package/dist/routing/index.js.map +7 -0
  150. package/dist/routing/index.mjs +5 -0
  151. package/dist/routing/index.mjs.map +7 -0
  152. package/dist/routing/navigation.d.ts +70 -0
  153. package/dist/routing/routeMatching.d.ts +21 -0
  154. package/dist/routing/routeTargetRegistry.d.ts +23 -0
  155. package/dist/routing/types.d.ts +130 -0
  156. package/dist/templates/NodeTemplate.d.ts +38 -0
  157. package/dist/templates/accessorParser.d.ts +87 -0
  158. package/dist/templates/parseTemplate.d.ts +6 -0
  159. package/dist/templates/tokenizer.d.ts +76 -0
  160. package/dist/tools.d.ts +30 -0
  161. package/dist/utils/index.d.ts +4 -0
  162. package/dist/utils/index.js +2 -0
  163. package/dist/utils/index.js.map +7 -0
  164. package/dist/utils/index.mjs +2 -0
  165. package/dist/utils/index.mjs.map +7 -0
  166. package/docs/Architecture.md +333 -0
  167. package/docs/DependencyInjection.md +237 -0
  168. package/docs/Errors.md +87 -0
  169. package/docs/GettingStarted.md +231 -0
  170. package/docs/Pipes.md +211 -0
  171. package/docs/Translations.md +312 -0
  172. package/docs/WhyRelaxjs.md +336 -0
  173. package/docs/elements/dom.md +102 -0
  174. package/docs/forms/creating-form-components.md +924 -0
  175. package/docs/forms/form-api.md +94 -0
  176. package/docs/forms/forms.md +99 -0
  177. package/docs/forms/patterns.md +311 -0
  178. package/docs/forms/reading-writing.md +365 -0
  179. package/docs/forms/validation.md +351 -0
  180. package/docs/html/TableRenderer.md +292 -0
  181. package/docs/html/html.md +175 -0
  182. package/docs/html/index.md +54 -0
  183. package/docs/html/template.md +422 -0
  184. package/docs/http/HttpClient.md +459 -0
  185. package/docs/http/ServerSentEvents.md +184 -0
  186. package/docs/http/index.md +109 -0
  187. package/docs/i18n/i18n.md +309 -0
  188. package/docs/i18n/intl-standard.md +178 -0
  189. package/docs/routing/RouteLink.md +98 -0
  190. package/docs/routing/Routing.md +332 -0
  191. package/docs/routing/RoutingTarget.md +136 -0
  192. package/docs/routing/layouts.md +207 -0
  193. package/docs/utilities.md +143 -0
  194. package/package.json +93 -0
@@ -0,0 +1,116 @@
1
+ /**
2
+ * @module ServerSentEvents
3
+ * SSE client that dispatches received events as DOM events.
4
+ * Uses the browser's built-in EventSource reconnection.
5
+ *
6
+ * @example
7
+ * const sse = new SSEClient('/api/events', {
8
+ * eventTypes: ['user-updated', 'order-created']
9
+ * });
10
+ * sse.connect();
11
+ *
12
+ * document.addEventListener('user-updated', (e: SSEDataEvent) => {
13
+ * console.log('User updated:', e.data);
14
+ * });
15
+ */
16
+ /**
17
+ * Event dispatched when an SSE message is received.
18
+ * The event name matches the SSE event type.
19
+ */
20
+ export declare class SSEDataEvent extends Event {
21
+ data: unknown;
22
+ constructor(eventName: string, data: unknown, eventInit?: EventInit);
23
+ }
24
+ /**
25
+ * Factory function for creating custom event instances.
26
+ *
27
+ * @example
28
+ * const factory: SSEEventFactory = (eventName, data) => {
29
+ * switch (eventName) {
30
+ * case 'user-updated':
31
+ * return new UserUpdatedEvent(data as User);
32
+ * default:
33
+ * return new SSEDataEvent(eventName, data);
34
+ * }
35
+ * };
36
+ */
37
+ export type SSEEventFactory = (eventName: string, data: unknown) => Event;
38
+ /**
39
+ * Configuration options for SSEClient.
40
+ */
41
+ export interface SSEOptions {
42
+ /**
43
+ * Target element or CSS selector for event dispatching.
44
+ * Defaults to document.
45
+ */
46
+ target?: string | Element;
47
+ /**
48
+ * Whether to send credentials with the request (default: false).
49
+ */
50
+ withCredentials?: boolean;
51
+ /**
52
+ * Specific SSE event types to listen for.
53
+ * If not specified, listens to the default 'message' event.
54
+ *
55
+ * @example
56
+ * eventTypes: ['user-updated', 'order-created']
57
+ */
58
+ eventTypes?: string[];
59
+ /**
60
+ * Factory function for creating custom event instances.
61
+ * If not provided, SSEDataEvent is used.
62
+ *
63
+ * @example
64
+ * eventFactory: (name, data) => new MyCustomEvent(name, data)
65
+ */
66
+ eventFactory?: SSEEventFactory;
67
+ /**
68
+ * Callback when connection is established.
69
+ */
70
+ onConnect?: (client: SSEClient) => void;
71
+ /**
72
+ * Callback when an error occurs.
73
+ * Note: EventSource automatically reconnects on errors.
74
+ */
75
+ onError?: (client: SSEClient, error: Event) => void;
76
+ }
77
+ /**
78
+ * Server-Sent Events client that dispatches received events as DOM events.
79
+ * Uses the browser's built-in EventSource with automatic reconnection.
80
+ *
81
+ * @example
82
+ * const sse = new SSEClient('/api/events', {
83
+ * target: '#notifications',
84
+ * eventTypes: ['notification', 'alert']
85
+ * });
86
+ *
87
+ * sse.connect();
88
+ *
89
+ * document.querySelector('#notifications')
90
+ * .addEventListener('notification', (e: SSEDataEvent) => {
91
+ * showNotification(e.data);
92
+ * });
93
+ *
94
+ * sse.disconnect();
95
+ */
96
+ export declare class SSEClient {
97
+ private url;
98
+ private options?;
99
+ private eventSource?;
100
+ private target;
101
+ /**
102
+ * Whether the client is currently connected.
103
+ */
104
+ get connected(): boolean;
105
+ constructor(url: string, options?: SSEOptions);
106
+ /**
107
+ * Establish connection to the SSE endpoint.
108
+ */
109
+ connect(): void;
110
+ /**
111
+ * Close the connection.
112
+ */
113
+ disconnect(): void;
114
+ private resolveTarget;
115
+ private dispatchEvent;
116
+ }
@@ -0,0 +1,153 @@
1
+ /**
2
+ * @module SimpleWebSocket
3
+ * WebSocket client with automatic reconnection and message queuing.
4
+ * Provides a reliable messaging layer over WebSocket connections.
5
+ *
6
+ * @example
7
+ * // Create and connect
8
+ * const ws = new WebSocketClient<ChatMessage>('wss://chat.example.com');
9
+ * ws.connect();
10
+ *
11
+ * // Send and receive
12
+ * await ws.send({ text: 'Hello' });
13
+ * const msg = await ws.receive();
14
+ */
15
+ /**
16
+ * Simplified message event for WebSocket data.
17
+ */
18
+ export interface SimpleDataEvent {
19
+ data: string | ArrayBufferLike | Blob | ArrayBufferView;
20
+ }
21
+ /**
22
+ * Abstraction interface for WebSocket to enable unit testing.
23
+ * Implement this for custom WebSocket instances or mocks.
24
+ */
25
+ export interface WebSocketAbstraction {
26
+ onopen: ((event: Event) => void) | null;
27
+ onerror: ((event: ErrorEvent) => void) | null;
28
+ onclose: ((event: CloseEvent) => void) | null;
29
+ onmessage: ((event: SimpleDataEvent) => void) | null;
30
+ send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
31
+ close(): void;
32
+ }
33
+ /**
34
+ * Factory function type for creating WebSocket instances.
35
+ */
36
+ export type WebSocketFactory = () => WebSocketAbstraction;
37
+ /**
38
+ * Managed WebSocket client with automatic reconnection and message queuing.
39
+ *
40
+ * Features:
41
+ * - Automatic reconnection on disconnect
42
+ * - Message queuing when disconnected
43
+ * - Type-safe message handling with optional codecs
44
+ * - Promise-based receive API
45
+ *
46
+ * @template TMessage - The type of messages sent and received
47
+ *
48
+ * @example
49
+ * // Basic usage
50
+ * interface ChatMessage { user: string; text: string; }
51
+ *
52
+ * const client = new WebSocketClient<ChatMessage>('wss://chat.example.com');
53
+ * client.connect();
54
+ *
55
+ * // Send messages
56
+ * await client.send({ user: 'John', text: 'Hello!' });
57
+ *
58
+ * // Receive messages
59
+ * while (true) {
60
+ * const message = await client.receive();
61
+ * console.log(`${message.user}: ${message.text}`);
62
+ * }
63
+ *
64
+ * @example
65
+ * // With options
66
+ * const client = new WebSocketClient<Message>('wss://api.example.com', {
67
+ * autoReconnect: true,
68
+ * onConnect: (socket) => console.log('Connected'),
69
+ * onClose: () => console.log('Disconnected')
70
+ * });
71
+ */
72
+ export declare class WebSocketClient<TMessage> {
73
+ private options?;
74
+ private ws?;
75
+ private receiveQueue;
76
+ private receivePromiseWrapper?;
77
+ private sendQueue;
78
+ private _isConnected;
79
+ private isSendingQueue;
80
+ private url?;
81
+ private wsFactory?;
82
+ private reconnectAttempts;
83
+ private shouldReconnect;
84
+ get connected(): boolean;
85
+ constructor(urlOrWebSocketFactory: string | WebSocketFactory, options?: WebSocketOptions<TMessage>);
86
+ connect(): void;
87
+ disconnect(): void;
88
+ send(data: TMessage): void;
89
+ /**
90
+ * Receive a new message.
91
+ *
92
+ * @throws Error if called while another receive() is pending.
93
+ * @throws Error if connection closes while waiting.
94
+ */
95
+ receive(): Promise<TMessage>;
96
+ private onMessage;
97
+ private reConnect;
98
+ private sendInternal;
99
+ private sendQueueItems;
100
+ }
101
+ /**
102
+ * CODEC used for messages.
103
+ */
104
+ export interface WebSocketCodec<TMessage> {
105
+ /**
106
+ *
107
+ * @param data
108
+ */
109
+ encode(data: TMessage): string | ArrayBufferLike | Blob | ArrayBufferView;
110
+ /**
111
+ *
112
+ * @param data
113
+ */
114
+ decode(data: string | ArrayBufferLike | Blob | ArrayBufferView): TMessage;
115
+ }
116
+ /**
117
+ * Configuration options for @see WebSocketClient.
118
+ */
119
+ export interface WebSocketOptions<TMessage> {
120
+ /**
121
+ * CODEC to use for inbound and outbound messages (if something else that JSON should be used).
122
+ */
123
+ codec?: WebSocketCodec<TMessage>;
124
+ /**
125
+ * Automatically reconnect when getting disconnected (default: true).
126
+ */
127
+ autoReconnect?: boolean;
128
+ /**
129
+ * Initial delay in milliseconds before reconnecting (default: 1000).
130
+ * Uses exponential backoff on subsequent attempts.
131
+ */
132
+ reconnectDelay?: number;
133
+ /**
134
+ * Maximum delay in milliseconds between reconnect attempts (default: 30000).
135
+ */
136
+ maxReconnectDelay?: number;
137
+ /**
138
+ * Callback when the WS is connected.
139
+ *
140
+ * Can be used for authentication messages etc.
141
+ *
142
+ * @param socket Socket
143
+ */
144
+ onConnect?: (socket: WebSocketClient<TMessage>) => void;
145
+ /**
146
+ * Invoked when the connection is closed.
147
+ *
148
+ * The connection will be automatically reconnected if configured (on by default).
149
+ *
150
+ * @param socket Socket.
151
+ */
152
+ onClose?: (socket: WebSocketClient<TMessage>) => void;
153
+ }
@@ -0,0 +1,177 @@
1
+ /**
2
+ * @module http
3
+ * Type-safe HTTP module built on fetch() with automatic JWT handling.
4
+ *
5
+ * @example
6
+ * import { configure, get, post } from './http';
7
+ *
8
+ * configure({ baseUrl: '/api' });
9
+ * const response = await get('/users');
10
+ * const users = response.as<User[]>();
11
+ */
12
+ /**
13
+ * Configuration options for the http module.
14
+ */
15
+ export interface HttpOptions {
16
+ /**
17
+ * Root URL to remote endpoint. Used so that each method only has to specify path in requests.
18
+ */
19
+ baseUrl?: string;
20
+ /**
21
+ * Default content type to use if none is specified in the request method.
22
+ */
23
+ contentType?: string;
24
+ /**
25
+ * Checks for a JWT token in localStorage to automatically include it in requests.
26
+ *
27
+ * Undefined = use "jwt", null = disable.
28
+ */
29
+ bearerTokenName?: string | null;
30
+ /**
31
+ * Default request timeout in milliseconds.
32
+ * Uses `AbortSignal.timeout()` to automatically abort requests that take too long.
33
+ * Can be overridden per-request by passing a `signal` in `RequestInit`.
34
+ *
35
+ * @example
36
+ * configure({ baseUrl: '/api', timeout: 10000 }); // 10 second timeout
37
+ */
38
+ timeout?: number;
39
+ }
40
+ /**
41
+ * Response for request methods.
42
+ */
43
+ export interface HttpResponse {
44
+ /**
45
+ * Http status code.
46
+ */
47
+ statusCode: number;
48
+ /**
49
+ * Reason to why the status code was used.
50
+ */
51
+ statusReason: string;
52
+ /**
53
+ * True if this is a 2xx response.
54
+ */
55
+ success: boolean;
56
+ /**
57
+ * Content type of response body.
58
+ */
59
+ contentType: string | null;
60
+ /**
61
+ * Body returned.
62
+ *
63
+ * Body has been read and deserialized from json (if the request content type was 'application/json' which is the default).
64
+ */
65
+ body: unknown;
66
+ /**
67
+ * Charset used in body.
68
+ */
69
+ charset: string | null;
70
+ /**
71
+ * Cast body to a type.
72
+ */
73
+ as<T>(): T;
74
+ }
75
+ /**
76
+ * Error thrown when a request fails.
77
+ */
78
+ export declare class HttpError extends Error {
79
+ message: string;
80
+ response: HttpResponse;
81
+ constructor(response: HttpResponse);
82
+ }
83
+ /**
84
+ * HTTP request options.
85
+ */
86
+ export interface RequestOptions {
87
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
88
+ mode?: 'cors' | 'no-cors' | '*cors' | 'same-origin';
89
+ cache: 'default' | 'no-store' | 'reload' | 'no-cache' | 'force-cache' | 'only-if-cached';
90
+ credentials: 'omit' | 'same-origin' | 'include';
91
+ headers: Map<string, string>;
92
+ redirect: 'follow' | 'manual' | '*follow' | 'error';
93
+ referrerPolicy: 'no-referrer' | '*no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url';
94
+ /**
95
+ * Will be serialized if the content type is json (and the body is an object).
96
+ */
97
+ body: unknown;
98
+ }
99
+ declare type FetchFn = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
100
+ /**
101
+ * Replace the fetch implementation for testing purposes.
102
+ *
103
+ * @param fn - Custom fetch function, or undefined to restore the default.
104
+ *
105
+ * @example
106
+ * setFetch(async (url, options) => {
107
+ * return new Response(JSON.stringify({ id: 1 }), { status: 200 });
108
+ * });
109
+ */
110
+ export declare function setFetch(fn?: FetchFn): void;
111
+ /**
112
+ * Configure the http module.
113
+ *
114
+ * @example
115
+ * configure({ baseUrl: '/api/v1', bearerTokenName: 'auth_token' });
116
+ */
117
+ export declare function configure(options: HttpOptions): void;
118
+ /**
119
+ * Make an HTTP request.
120
+ *
121
+ * @param url - URL to make the request against.
122
+ * @param options - Request options.
123
+ * @returns Response from server.
124
+ *
125
+ * @example
126
+ * const response = await request('/users', { method: 'GET' });
127
+ */
128
+ export declare function request(url: string, options?: RequestInit): Promise<HttpResponse>;
129
+ /**
130
+ * GET a resource.
131
+ *
132
+ * @param url - URL to get resource from.
133
+ * @param queryString - Optional query string parameters.
134
+ * @param options - Request options.
135
+ * @returns HTTP response.
136
+ *
137
+ * @example
138
+ * const response = await get('/users', { page: '1', limit: '10' });
139
+ * const users = response.as<User[]>();
140
+ */
141
+ export declare function get(url: string, queryString?: Record<string, string>, options?: RequestInit): Promise<HttpResponse>;
142
+ /**
143
+ * POST a resource.
144
+ *
145
+ * @param url - URL to post to.
146
+ * @param data - Data to post.
147
+ * @param options - Request options.
148
+ * @returns HTTP response.
149
+ *
150
+ * @example
151
+ * const response = await post('/users', JSON.stringify({ name: 'John' }));
152
+ */
153
+ export declare function post(url: string, data: BodyInit, options?: RequestInit): Promise<HttpResponse>;
154
+ /**
155
+ * PUT a resource.
156
+ *
157
+ * @param url - URL to resource.
158
+ * @param data - Data to put.
159
+ * @param options - Request options.
160
+ * @returns HTTP response.
161
+ *
162
+ * @example
163
+ * const response = await put('/users/1', JSON.stringify({ name: 'Jane' }));
164
+ */
165
+ export declare function put(url: string, data: BodyInit, options?: RequestInit): Promise<HttpResponse>;
166
+ /**
167
+ * DELETE a resource.
168
+ *
169
+ * @param url - URL to resource.
170
+ * @param options - Request options.
171
+ * @returns HTTP response.
172
+ *
173
+ * @example
174
+ * const response = await del('/users/1');
175
+ */
176
+ export declare function del(url: string, options?: RequestInit): Promise<HttpResponse>;
177
+ export {};
@@ -0,0 +1,3 @@
1
+ export { HttpOptions, HttpResponse, HttpError, RequestOptions, configure, setFetch, request, get, post, put, del } from './http';
2
+ export { SSEDataEvent, SSEOptions, SSEEventFactory, SSEClient } from './ServerSentEvents';
3
+ export { SimpleDataEvent, WebSocketAbstraction, WebSocketFactory, WebSocketClient, WebSocketCodec, WebSocketOptions } from './SimpleWebSocket';
@@ -0,0 +1,105 @@
1
+ /**
2
+ * @module i18n
3
+ * Internationalization support with namespace-based translations.
4
+ * Uses ICU message format for pluralization, select, and formatting.
5
+ *
6
+ * @example
7
+ * // Initialize locale
8
+ * await setLocale('sv');
9
+ *
10
+ * // Use translations
11
+ * const greeting = t('r-common:greeting', { name: 'John' });
12
+ * const items = t('shop:items', { count: 5 });
13
+ */
14
+ type Namespace = string;
15
+ export type MissingTranslationHandler = (key: string, namespace: string, locale: string) => void;
16
+ /**
17
+ * Dispatched on `document` after `setLocale()` completes.
18
+ * The `locale` property contains the new normalized locale code.
19
+ *
20
+ * @example
21
+ * document.addEventListener('localechange', (e) => {
22
+ * console.log(`Locale changed to ${e.locale}`);
23
+ * this.render();
24
+ * });
25
+ */
26
+ export declare class LocaleChangeEvent extends Event {
27
+ readonly locale: string;
28
+ constructor(locale: string);
29
+ }
30
+ declare global {
31
+ interface DocumentEventMap {
32
+ localechange: LocaleChangeEvent;
33
+ }
34
+ }
35
+ /**
36
+ * Sets the current locale and loads the common namespace.
37
+ * Clears previously loaded translations and dispatches a `localechange` event.
38
+ *
39
+ * @param locale - The locale code (e.g., 'en', 'sv', 'en-US')
40
+ *
41
+ * @example
42
+ * await setLocale('sv');
43
+ */
44
+ export declare function setLocale(locale: string): Promise<void>;
45
+ /**
46
+ * Loads a translation namespace on demand.
47
+ * Falls back to the default locale if translations are not found.
48
+ *
49
+ * @param namespace - The namespace to load (e.g., 'shop', 'errors')
50
+ *
51
+ * @example
52
+ * await loadNamespace('shop');
53
+ * const price = t('shop:priceLabel');
54
+ */
55
+ export declare function loadNamespace(namespace: Namespace): Promise<void>;
56
+ /**
57
+ * Loads multiple translation namespaces in parallel.
58
+ *
59
+ * @param namespaces - Array of namespace names to load
60
+ *
61
+ * @example
62
+ * await loadNamespaces(['r-pipes', 'r-validation']);
63
+ */
64
+ export declare function loadNamespaces(namespaces: Namespace[]): Promise<void>;
65
+ /**
66
+ * Translates a key with optional value interpolation.
67
+ * Supports ICU message format for pluralization and select.
68
+ *
69
+ * @param fullKey - Translation key in format 'namespace:key' or just 'key' (uses 'r-common')
70
+ * @param values - Values to interpolate into the message
71
+ * @returns The translated string, or the key if not found
72
+ *
73
+ * @example
74
+ * // Simple translation
75
+ * t('greeting'); // Uses r-common:greeting
76
+ *
77
+ * // With namespace
78
+ * t('errors:notFound');
79
+ *
80
+ * // With interpolation
81
+ * t('welcome', { name: 'John' }); // "Welcome, John!"
82
+ *
83
+ * // With pluralization (ICU format)
84
+ * t('items', { count: 5 }); // "5 items" or "5 föremål"
85
+ */
86
+ export declare function t(fullKey: string, values?: Record<string, any>): string;
87
+ /**
88
+ * Returns the current locale code.
89
+ *
90
+ * @returns The normalized locale code (e.g., 'en', 'sv')
91
+ */
92
+ export declare function getCurrentLocale(): string;
93
+ /**
94
+ * Registers a handler called when `t()` encounters a missing translation key.
95
+ * Pass `null` to remove the handler.
96
+ *
97
+ * @param handler - Callback receiving the key, namespace, and locale
98
+ *
99
+ * @example
100
+ * onMissingTranslation((key, ns, locale) => {
101
+ * console.warn(`Missing: ${ns}:${key} [${locale}]`);
102
+ * });
103
+ */
104
+ export declare function onMissingTranslation(handler: MissingTranslationHandler | null): void;
105
+ export {};
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @module icu
3
+ * ICU message format support for internationalization.
4
+ * Provides pluralization, select, and value interpolation.
5
+ *
6
+ * @example
7
+ * // Simple interpolation
8
+ * formatICU('Hello, {name}!', { name: 'World' });
9
+ * // Returns: 'Hello, World!'
10
+ *
11
+ * @example
12
+ * // Pluralization
13
+ * formatICU('{count, plural, one {# item} other {# items}}', { count: 5 });
14
+ * // Returns: '5 items'
15
+ *
16
+ * @example
17
+ * // Select
18
+ * formatICU('{gender, select, male {He} female {She} other {They}}', { gender: 'female' });
19
+ * // Returns: 'She'
20
+ */
21
+ /**
22
+ * Function type for message formatters.
23
+ * Implement this to provide custom message formatting.
24
+ */
25
+ export type MessageFormatter = (message: string, values?: Record<string, any>, locale?: string) => string;
26
+ /**
27
+ * Default ICU message formatter implementation.
28
+ * Supports simple interpolation, pluralization with exact matches, and select.
29
+ *
30
+ * @param message - ICU format message string
31
+ * @param values - Values to interpolate
32
+ * @param locale - Locale for plural rules (default: 'en')
33
+ * @returns Formatted message string
34
+ *
35
+ * @example
36
+ * defaultFormatICU('{n, plural, =0 {none} one {# item} other {# items}}', { n: 0 }, 'en');
37
+ * // Returns: 'none'
38
+ *
39
+ * @example
40
+ * defaultFormatICU('{role, select, admin {Full access} other {Limited access}}', { role: 'admin' });
41
+ * // Returns: 'Full access'
42
+ */
43
+ export declare function defaultFormatICU(message: string, values: Record<string, any>, locale?: string): string;
44
+ /**
45
+ * The active message formatter. Defaults to `defaultFormatICU`.
46
+ * Can be replaced with `setMessageFormatter` for custom formatting.
47
+ */
48
+ export declare let formatICU: MessageFormatter;
49
+ /**
50
+ * Replaces the default message formatter with a custom implementation.
51
+ * Use this to integrate with external i18n libraries like FormatJS.
52
+ *
53
+ * @param formatter - The custom formatter function
54
+ *
55
+ * @example
56
+ * // Use FormatJS IntlMessageFormat
57
+ * import { IntlMessageFormat } from 'intl-messageformat';
58
+ *
59
+ * setMessageFormatter((message, values, locale) => {
60
+ * const fmt = new IntlMessageFormat(message, locale);
61
+ * return fmt.format(values);
62
+ * });
63
+ */
64
+ export declare function setMessageFormatter(formatter: MessageFormatter): void;
@@ -0,0 +1,2 @@
1
+ export { t, setLocale, loadNamespace, loadNamespaces, getCurrentLocale, onMissingTranslation, LocaleChangeEvent, MissingTranslationHandler, } from './i18n';
2
+ export { MessageFormatter, formatICU, setMessageFormatter, } from './icu';
@@ -0,0 +1,16 @@
1
+ export * from './errors';
2
+ export * from './collections/Index';
3
+ export * from './forms/FormValidator';
4
+ export * from './forms/FormReader';
5
+ export * from './forms/ValidationRules';
6
+ export * from './forms/setFormData';
7
+ export * from './html/index';
8
+ export * from './routing';
9
+ export * from "./DependencyInjection";
10
+ export * from "./getParentComponent";
11
+ export * from "./templates/NodeTemplate";
12
+ export { generateSequentialId } from './SequentialId';
13
+ export * from "./http/http";
14
+ export * from "./http/ServerSentEvents";
15
+ export * from './pipes';
16
+ export * from './tools';
@@ -0,0 +1,52 @@
1
+ import type { Route, RouteData } from './types';
2
+ /**
3
+ * Event sent to routing targets when a new route should be displayed.
4
+ */
5
+ export declare class NavigateRouteEvent extends Event {
6
+ /**
7
+ * Matched route.
8
+ */
9
+ route: Route;
10
+ /**
11
+ * The generated url sements which can be used to push the url into the browser history.
12
+ */
13
+ urlSegments: string[];
14
+ /**
15
+ * Data supplied to the route.
16
+ */
17
+ routeData?: RouteData;
18
+ /**
19
+ * The target can differ from the default target that is defined in the route.
20
+ *
21
+ * undefined means that the default (unnamed) target should be used.
22
+ */
23
+ routeTarget?: string;
24
+ static NAME: string;
25
+ constructor(
26
+ /**
27
+ * Matched route.
28
+ */
29
+ route: Route,
30
+ /**
31
+ * The generated url sements which can be used to push the url into the browser history.
32
+ */
33
+ urlSegments: string[],
34
+ /**
35
+ * Data supplied to the route.
36
+ */
37
+ routeData?: RouteData,
38
+ /**
39
+ * The target can differ from the default target that is defined in the route.
40
+ *
41
+ * undefined means that the default (unnamed) target should be used.
42
+ */
43
+ routeTarget?: string, eventInit?: EventInit);
44
+ }
45
+ declare global {
46
+ interface HTMLElementEventMap {
47
+ 'rlx.navigateRoute': NavigateRouteEvent;
48
+ }
49
+ interface DocumentEventMap {
50
+ 'rlx.navigateRoute': NavigateRouteEvent;
51
+ }
52
+ }