@almadar/ui 1.0.0 → 1.0.10
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/dist/chunk-4FRUCUO5.js +14 -0
- package/dist/chunk-7NEWMNNU.js +147 -0
- package/dist/chunk-AQREMI4N.js +426 -0
- package/dist/chunk-BCERHHKU.js +2834 -0
- package/dist/chunk-I5RSZIOE.js +190 -0
- package/dist/chunk-KKCVDUK7.js +104 -0
- package/dist/chunk-N7MVUW4R.js +194 -0
- package/dist/chunk-S7EYY36U.js +13 -0
- package/dist/chunk-TTXKOHDO.js +270 -0
- package/dist/chunk-XSEDIUM6.js +93 -0
- package/dist/cn-mqkxz8Sd.d.ts +9 -0
- package/dist/components/index.d.ts +175 -4
- package/dist/components/index.js +701 -7595
- package/dist/context/index.js +6 -342
- package/dist/hooks/index.d.ts +70 -1
- package/dist/hooks/index.js +6 -2262
- package/dist/lib/index.d.ts +180 -8
- package/dist/lib/index.js +685 -171
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +8 -905
- package/dist/renderer/index.d.ts +144 -1
- package/dist/renderer/index.js +209 -402
- package/dist/stores/index.js +2 -196
- package/package.json +11 -13
- package/themes/almadar.css +8 -0
- package/themes/index.css +1 -0
- package/themes/minimalist.css +8 -0
- package/themes/trait-wars.css +176 -0
- package/themes/wireframe.css +8 -0
- package/dist/components/index.js.map +0 -1
- package/dist/context/index.js.map +0 -1
- package/dist/hooks/index.js.map +0 -1
- package/dist/lib/index.js.map +0 -1
- package/dist/providers/index.js.map +0 -1
- package/dist/renderer/index.js.map +0 -1
- package/dist/stores/index.js.map +0 -1
package/dist/renderer/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { executeClientEffects } from '../chunk-AQREMI4N.js';
|
|
2
|
+
export { OfflineExecutor, createOfflineExecutor, executeClientEffects, filterEffectsByType, getEmitEffects, getNavigateEffects, getNotifyEffects, getRenderUIEffects, parseClientEffect, parseClientEffects, useOfflineExecutor } from '../chunk-AQREMI4N.js';
|
|
3
|
+
import '../chunk-S7EYY36U.js';
|
|
4
|
+
import { createContext, useRef, useCallback, useEffect, useContext, useMemo, useState } from 'react';
|
|
5
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
6
|
import componentMappingJson from '@almadar/patterns/component-mapping.json';
|
|
3
7
|
import registryJson from '@almadar/patterns/registry.json';
|
|
4
8
|
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
-
|
|
9
9
|
// renderer/pattern-resolver.ts
|
|
10
10
|
var componentMapping = {};
|
|
11
11
|
var patternRegistry = {};
|
|
@@ -74,111 +74,6 @@ function getPatternMapping(type) {
|
|
|
74
74
|
function getPatternDefinition(type) {
|
|
75
75
|
return patternRegistry[type];
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
// renderer/client-effect-executor.ts
|
|
79
|
-
function executeClientEffects(effects, config) {
|
|
80
|
-
if (!effects || effects.length === 0) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
for (const effect of effects) {
|
|
84
|
-
try {
|
|
85
|
-
executeEffect(effect, config);
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error(
|
|
88
|
-
`[ClientEffectExecutor] Error executing effect:`,
|
|
89
|
-
effect,
|
|
90
|
-
error
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
config.onComplete?.();
|
|
95
|
-
}
|
|
96
|
-
function executeEffect(effect, config) {
|
|
97
|
-
const [effectType, ...args] = effect;
|
|
98
|
-
switch (effectType) {
|
|
99
|
-
case "render-ui": {
|
|
100
|
-
const [slot, patternConfig] = args;
|
|
101
|
-
executeRenderUI(slot, patternConfig, config);
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
case "navigate": {
|
|
105
|
-
const [path, params] = args;
|
|
106
|
-
executeNavigate(path, params, config);
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
case "notify": {
|
|
110
|
-
const [message, options] = args;
|
|
111
|
-
executeNotify(message, options, config);
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
case "emit": {
|
|
115
|
-
const [event, payload] = args;
|
|
116
|
-
executeEmit(event, payload, config);
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
default:
|
|
120
|
-
console.warn(`[ClientEffectExecutor] Unknown effect type: ${effectType}`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
function executeRenderUI(slot, patternConfig, config) {
|
|
124
|
-
config.renderToSlot(slot, patternConfig);
|
|
125
|
-
}
|
|
126
|
-
function executeNavigate(path, params, config) {
|
|
127
|
-
config.navigate(path, params);
|
|
128
|
-
}
|
|
129
|
-
function executeNotify(message, options, config) {
|
|
130
|
-
config.notify(message, options);
|
|
131
|
-
}
|
|
132
|
-
function executeEmit(event, payload, config) {
|
|
133
|
-
config.eventBus.emit(event, payload);
|
|
134
|
-
}
|
|
135
|
-
function parseClientEffect(raw) {
|
|
136
|
-
if (!Array.isArray(raw) || raw.length < 1) {
|
|
137
|
-
console.warn("[ClientEffectExecutor] Invalid effect format:", raw);
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
const [type, ...args] = raw;
|
|
141
|
-
if (typeof type !== "string") {
|
|
142
|
-
console.warn("[ClientEffectExecutor] Effect type must be string:", raw);
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
switch (type) {
|
|
146
|
-
case "render-ui":
|
|
147
|
-
return ["render-ui", args[0], args[1]];
|
|
148
|
-
case "navigate":
|
|
149
|
-
return ["navigate", args[0], args[1]];
|
|
150
|
-
case "notify":
|
|
151
|
-
return ["notify", args[0], args[1]];
|
|
152
|
-
case "emit":
|
|
153
|
-
return ["emit", args[0], args[1]];
|
|
154
|
-
default:
|
|
155
|
-
console.warn(`[ClientEffectExecutor] Unknown effect type: ${type}`);
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
function parseClientEffects(raw) {
|
|
160
|
-
if (!raw || !Array.isArray(raw)) {
|
|
161
|
-
return [];
|
|
162
|
-
}
|
|
163
|
-
return raw.map((effect) => parseClientEffect(effect)).filter((effect) => effect !== null);
|
|
164
|
-
}
|
|
165
|
-
function filterEffectsByType(effects, type) {
|
|
166
|
-
return effects.filter(
|
|
167
|
-
(effect) => effect[0] === type
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
function getRenderUIEffects(effects) {
|
|
171
|
-
return filterEffectsByType(effects, "render-ui");
|
|
172
|
-
}
|
|
173
|
-
function getNavigateEffects(effects) {
|
|
174
|
-
return filterEffectsByType(effects, "navigate");
|
|
175
|
-
}
|
|
176
|
-
function getNotifyEffects(effects) {
|
|
177
|
-
return filterEffectsByType(effects, "notify");
|
|
178
|
-
}
|
|
179
|
-
function getEmitEffects(effects) {
|
|
180
|
-
return filterEffectsByType(effects, "emit");
|
|
181
|
-
}
|
|
182
77
|
function useClientEffects(effects, options) {
|
|
183
78
|
const {
|
|
184
79
|
enabled = true,
|
|
@@ -466,322 +361,236 @@ function getPortalSlots() {
|
|
|
466
361
|
return getSlotsByType("portal");
|
|
467
362
|
}
|
|
468
363
|
var ALL_SLOTS = Object.keys(SLOT_DEFINITIONS);
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
__publicField(this, "config");
|
|
476
|
-
__publicField(this, "state");
|
|
477
|
-
__publicField(this, "storage");
|
|
478
|
-
/**
|
|
479
|
-
* Handle going online
|
|
480
|
-
*/
|
|
481
|
-
__publicField(this, "handleOnline", () => {
|
|
482
|
-
this.state.isOffline = false;
|
|
483
|
-
});
|
|
484
|
-
/**
|
|
485
|
-
* Handle going offline
|
|
486
|
-
*/
|
|
487
|
-
__publicField(this, "handleOffline", () => {
|
|
488
|
-
this.state.isOffline = true;
|
|
489
|
-
});
|
|
490
|
-
this.config = {
|
|
491
|
-
enableSyncQueue: true,
|
|
492
|
-
maxQueueSize: 100,
|
|
493
|
-
...config
|
|
494
|
-
};
|
|
495
|
-
this.state = {
|
|
496
|
-
isOffline: !this.checkOnline(),
|
|
497
|
-
syncQueue: [],
|
|
498
|
-
localEffectsProcessed: 0,
|
|
499
|
-
effectsSynced: 0
|
|
500
|
-
};
|
|
501
|
-
this.storage = typeof localStorage !== "undefined" ? localStorage : null;
|
|
502
|
-
this.loadSyncQueue();
|
|
503
|
-
if (typeof window !== "undefined") {
|
|
504
|
-
window.addEventListener("online", this.handleOnline);
|
|
505
|
-
window.addEventListener("offline", this.handleOffline);
|
|
364
|
+
function matchPath(pattern, path) {
|
|
365
|
+
const normalizeSegment = (p) => {
|
|
366
|
+
let normalized = p.trim();
|
|
367
|
+
if (!normalized.startsWith("/")) normalized = "/" + normalized;
|
|
368
|
+
if (normalized.length > 1 && normalized.endsWith("/")) {
|
|
369
|
+
normalized = normalized.slice(0, -1);
|
|
506
370
|
}
|
|
371
|
+
return normalized;
|
|
372
|
+
};
|
|
373
|
+
const normalizedPattern = normalizeSegment(pattern);
|
|
374
|
+
const normalizedPath = normalizeSegment(path);
|
|
375
|
+
const patternParts = normalizedPattern.split("/").filter(Boolean);
|
|
376
|
+
const pathParts = normalizedPath.split("/").filter(Boolean);
|
|
377
|
+
if (patternParts.length !== pathParts.length) {
|
|
378
|
+
return null;
|
|
507
379
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
380
|
+
const params = {};
|
|
381
|
+
for (let i = 0; i < patternParts.length; i++) {
|
|
382
|
+
const patternPart = patternParts[i];
|
|
383
|
+
const pathPart = pathParts[i];
|
|
384
|
+
if (patternPart.startsWith(":")) {
|
|
385
|
+
const paramName = patternPart.slice(1);
|
|
386
|
+
params[paramName] = decodeURIComponent(pathPart);
|
|
387
|
+
} else if (patternPart !== pathPart) {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
513
390
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
391
|
+
return params;
|
|
392
|
+
}
|
|
393
|
+
function extractRouteParams(pattern, path) {
|
|
394
|
+
return matchPath(pattern, path) || {};
|
|
395
|
+
}
|
|
396
|
+
function pathMatches(pattern, path) {
|
|
397
|
+
return matchPath(pattern, path) !== null;
|
|
398
|
+
}
|
|
399
|
+
function isInlineOrbital(orbital) {
|
|
400
|
+
return "name" in orbital && typeof orbital.name === "string";
|
|
401
|
+
}
|
|
402
|
+
function isInlinePage(page) {
|
|
403
|
+
return typeof page === "object" && page !== null && "name" in page && typeof page.name === "string";
|
|
404
|
+
}
|
|
405
|
+
function findPageByPath(schema, path) {
|
|
406
|
+
if (!schema.orbitals) return null;
|
|
407
|
+
for (const orbital of schema.orbitals) {
|
|
408
|
+
if (!isInlineOrbital(orbital)) continue;
|
|
409
|
+
if (!orbital.pages) continue;
|
|
410
|
+
for (const pageRef of orbital.pages) {
|
|
411
|
+
if (!isInlinePage(pageRef)) continue;
|
|
412
|
+
const page = pageRef;
|
|
413
|
+
const pagePath = page.path;
|
|
414
|
+
if (!pagePath) continue;
|
|
415
|
+
const params = matchPath(pagePath, path);
|
|
416
|
+
if (params !== null) {
|
|
417
|
+
return { page, params, orbitalName: orbital.name };
|
|
523
418
|
}
|
|
524
|
-
} catch (error) {
|
|
525
|
-
console.warn("[OfflineExecutor] Failed to load sync queue:", error);
|
|
526
419
|
}
|
|
527
420
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
function findPageByName(schema, pageName) {
|
|
424
|
+
if (!schema.orbitals) return null;
|
|
425
|
+
for (const orbital of schema.orbitals) {
|
|
426
|
+
if (!isInlineOrbital(orbital)) continue;
|
|
427
|
+
if (!orbital.pages) continue;
|
|
428
|
+
for (const pageRef of orbital.pages) {
|
|
429
|
+
if (!isInlinePage(pageRef)) continue;
|
|
430
|
+
const page = pageRef;
|
|
431
|
+
if (page.name === pageName) {
|
|
432
|
+
return { page, orbitalName: orbital.name };
|
|
433
|
+
}
|
|
537
434
|
}
|
|
538
435
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
maxRetries: 3
|
|
551
|
-
};
|
|
552
|
-
this.state.syncQueue.push(effect);
|
|
553
|
-
if (this.state.syncQueue.length > (this.config.maxQueueSize ?? 100)) {
|
|
554
|
-
this.state.syncQueue.shift();
|
|
436
|
+
return null;
|
|
437
|
+
}
|
|
438
|
+
function getDefaultPage(schema) {
|
|
439
|
+
if (!schema.orbitals) return null;
|
|
440
|
+
for (const orbital of schema.orbitals) {
|
|
441
|
+
if (!isInlineOrbital(orbital)) continue;
|
|
442
|
+
if (!orbital.pages) continue;
|
|
443
|
+
for (const pageRef of orbital.pages) {
|
|
444
|
+
if (isInlinePage(pageRef)) {
|
|
445
|
+
return { page: pageRef, orbitalName: orbital.name };
|
|
446
|
+
}
|
|
555
447
|
}
|
|
556
|
-
this.saveSyncQueue();
|
|
557
|
-
this.config.onEffectQueued?.(effect);
|
|
558
|
-
this.config.onQueueChange?.(this.state.syncQueue);
|
|
559
448
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
function getAllPages(schema) {
|
|
452
|
+
const pages = [];
|
|
453
|
+
if (!schema.orbitals) return pages;
|
|
454
|
+
for (const orbital of schema.orbitals) {
|
|
455
|
+
if (!isInlineOrbital(orbital)) continue;
|
|
456
|
+
if (!orbital.pages) continue;
|
|
457
|
+
for (const pageRef of orbital.pages) {
|
|
458
|
+
if (isInlinePage(pageRef)) {
|
|
459
|
+
pages.push({ page: pageRef, orbitalName: orbital.name });
|
|
460
|
+
}
|
|
461
|
+
}
|
|
567
462
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
case "notify":
|
|
587
|
-
case "emit":
|
|
588
|
-
clientEffects.push(effect);
|
|
589
|
-
break;
|
|
590
|
-
// Fetch effect - use mock data
|
|
591
|
-
case "fetch": {
|
|
592
|
-
const [entityName, _query] = args;
|
|
593
|
-
if (typeof entityName === "string" && this.config.mockDataProvider) {
|
|
594
|
-
fetchedData[entityName] = this.config.mockDataProvider(entityName);
|
|
595
|
-
}
|
|
596
|
-
break;
|
|
597
|
-
}
|
|
598
|
-
// Server effects - queue for sync
|
|
599
|
-
case "persist":
|
|
600
|
-
case "call-service":
|
|
601
|
-
case "spawn":
|
|
602
|
-
case "despawn":
|
|
603
|
-
this.queueForSync(type, { args, event, payload });
|
|
604
|
-
break;
|
|
605
|
-
default:
|
|
606
|
-
console.warn(`[OfflineExecutor] Unknown effect type: ${type}`);
|
|
607
|
-
}
|
|
463
|
+
return pages;
|
|
464
|
+
}
|
|
465
|
+
var NavigationContext = createContext(null);
|
|
466
|
+
function NavigationProvider({
|
|
467
|
+
schema,
|
|
468
|
+
initialPage,
|
|
469
|
+
updateUrl = true,
|
|
470
|
+
onNavigate,
|
|
471
|
+
children
|
|
472
|
+
}) {
|
|
473
|
+
const initialState = useMemo(() => {
|
|
474
|
+
let page = null;
|
|
475
|
+
let path = "/";
|
|
476
|
+
if (initialPage) {
|
|
477
|
+
const found = findPageByName(schema, initialPage);
|
|
478
|
+
if (found) {
|
|
479
|
+
page = found.page;
|
|
480
|
+
path = page.path || "/";
|
|
608
481
|
}
|
|
609
482
|
}
|
|
610
|
-
if (
|
|
611
|
-
|
|
483
|
+
if (!page) {
|
|
484
|
+
const defaultPage = getDefaultPage(schema);
|
|
485
|
+
if (defaultPage) {
|
|
486
|
+
page = defaultPage.page;
|
|
487
|
+
path = page.path || "/";
|
|
488
|
+
}
|
|
612
489
|
}
|
|
613
490
|
return {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
}
|
|
619
|
-
/**
|
|
620
|
-
* Sync pending effects to server.
|
|
621
|
-
*
|
|
622
|
-
* @param serverUrl - Base URL for the orbital server
|
|
623
|
-
* @param authToken - Optional auth token for requests
|
|
624
|
-
* @returns Number of successfully synced effects
|
|
625
|
-
*/
|
|
626
|
-
async syncPendingEffects(serverUrl, authToken) {
|
|
627
|
-
if (this.state.syncQueue.length === 0) {
|
|
628
|
-
return 0;
|
|
629
|
-
}
|
|
630
|
-
this.state.lastSyncAttempt = Date.now();
|
|
631
|
-
let syncedCount = 0;
|
|
632
|
-
const failedEffects = [];
|
|
633
|
-
const headers = {
|
|
634
|
-
"Content-Type": "application/json"
|
|
491
|
+
activePage: page?.name || "",
|
|
492
|
+
currentPath: path,
|
|
493
|
+
initPayload: {},
|
|
494
|
+
navigationId: 0
|
|
635
495
|
};
|
|
636
|
-
|
|
637
|
-
|
|
496
|
+
}, [schema, initialPage]);
|
|
497
|
+
const [state, setState] = useState(initialState);
|
|
498
|
+
const navigateTo = useCallback((path, payload) => {
|
|
499
|
+
const result = findPageByPath(schema, path);
|
|
500
|
+
if (!result) {
|
|
501
|
+
console.error(`[Navigation] No page found for path: ${path}`);
|
|
502
|
+
return;
|
|
638
503
|
}
|
|
639
|
-
|
|
504
|
+
const { page, params } = result;
|
|
505
|
+
const finalPayload = { ...params, ...payload };
|
|
506
|
+
console.log("[Navigation] Navigating to:", {
|
|
507
|
+
path,
|
|
508
|
+
page: page.name,
|
|
509
|
+
params,
|
|
510
|
+
payload,
|
|
511
|
+
finalPayload
|
|
512
|
+
});
|
|
513
|
+
setState((prev) => ({
|
|
514
|
+
activePage: page.name,
|
|
515
|
+
currentPath: path,
|
|
516
|
+
initPayload: finalPayload,
|
|
517
|
+
navigationId: prev.navigationId + 1
|
|
518
|
+
}));
|
|
519
|
+
if (updateUrl && typeof window !== "undefined") {
|
|
640
520
|
try {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
body: JSON.stringify({
|
|
645
|
-
type: effect.type,
|
|
646
|
-
payload: effect.payload,
|
|
647
|
-
offlineId: effect.id,
|
|
648
|
-
offlineTimestamp: effect.timestamp
|
|
649
|
-
})
|
|
650
|
-
});
|
|
651
|
-
if (response.ok) {
|
|
652
|
-
syncedCount++;
|
|
653
|
-
} else {
|
|
654
|
-
effect.retries++;
|
|
655
|
-
if (effect.retries < effect.maxRetries) {
|
|
656
|
-
failedEffects.push(effect);
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
} catch (error) {
|
|
660
|
-
effect.retries++;
|
|
661
|
-
if (effect.retries < effect.maxRetries) {
|
|
662
|
-
failedEffects.push(effect);
|
|
663
|
-
}
|
|
521
|
+
window.history.pushState(finalPayload, "", path);
|
|
522
|
+
} catch (e) {
|
|
523
|
+
console.warn("[Navigation] Could not update URL:", e);
|
|
664
524
|
}
|
|
665
525
|
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
if (syncedCount > 0) {
|
|
669
|
-
this.state.lastSuccessfulSync = Date.now();
|
|
526
|
+
if (onNavigate) {
|
|
527
|
+
onNavigate(page.name, path, finalPayload);
|
|
670
528
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
*/
|
|
678
|
-
getState() {
|
|
679
|
-
return { ...this.state };
|
|
680
|
-
}
|
|
681
|
-
/**
|
|
682
|
-
* Get number of pending effects
|
|
683
|
-
*/
|
|
684
|
-
getPendingCount() {
|
|
685
|
-
return this.state.syncQueue.length;
|
|
686
|
-
}
|
|
687
|
-
/**
|
|
688
|
-
* Clear the sync queue
|
|
689
|
-
*/
|
|
690
|
-
clearQueue() {
|
|
691
|
-
this.state.syncQueue = [];
|
|
692
|
-
this.saveSyncQueue();
|
|
693
|
-
this.config.onQueueChange?.(this.state.syncQueue);
|
|
694
|
-
}
|
|
695
|
-
/**
|
|
696
|
-
* Dispose the executor and clean up listeners
|
|
697
|
-
*/
|
|
698
|
-
dispose() {
|
|
699
|
-
if (typeof window !== "undefined") {
|
|
700
|
-
window.removeEventListener("online", this.handleOnline);
|
|
701
|
-
window.removeEventListener("offline", this.handleOffline);
|
|
529
|
+
}, [schema, updateUrl, onNavigate]);
|
|
530
|
+
const navigateToPage = useCallback((pageName, payload) => {
|
|
531
|
+
const result = findPageByName(schema, pageName);
|
|
532
|
+
if (!result) {
|
|
533
|
+
console.error(`[Navigation] No page found with name: ${pageName}`);
|
|
534
|
+
return;
|
|
702
535
|
}
|
|
703
|
-
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
const executorRef = useRef(null);
|
|
710
|
-
const [state, setState] = useState({
|
|
711
|
-
isOffline: false,
|
|
712
|
-
syncQueue: [],
|
|
713
|
-
localEffectsProcessed: 0,
|
|
714
|
-
effectsSynced: 0
|
|
715
|
-
});
|
|
716
|
-
useEffect(() => {
|
|
717
|
-
const executor = new OfflineExecutor({
|
|
718
|
-
...options,
|
|
719
|
-
onQueueChange: (queue) => {
|
|
720
|
-
setState(executor.getState());
|
|
721
|
-
options.onQueueChange?.(queue);
|
|
722
|
-
}
|
|
536
|
+
const { page } = result;
|
|
537
|
+
const path = page.path || `/${pageName.toLowerCase()}`;
|
|
538
|
+
console.log("[Navigation] Navigating to page:", {
|
|
539
|
+
pageName,
|
|
540
|
+
path,
|
|
541
|
+
payload
|
|
723
542
|
});
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
};
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
await executorRef.current.syncPendingEffects(
|
|
736
|
-
options.serverUrl,
|
|
737
|
-
options.authToken
|
|
738
|
-
);
|
|
739
|
-
setState(executorRef.current.getState());
|
|
543
|
+
setState((prev) => ({
|
|
544
|
+
activePage: page.name,
|
|
545
|
+
currentPath: path,
|
|
546
|
+
initPayload: payload || {},
|
|
547
|
+
navigationId: prev.navigationId + 1
|
|
548
|
+
}));
|
|
549
|
+
if (updateUrl && typeof window !== "undefined") {
|
|
550
|
+
try {
|
|
551
|
+
window.history.pushState(payload || {}, "", path);
|
|
552
|
+
} catch (e) {
|
|
553
|
+
console.warn("[Navigation] Could not update URL:", e);
|
|
740
554
|
}
|
|
741
|
-
};
|
|
742
|
-
window.addEventListener("online", handleOnline);
|
|
743
|
-
return () => window.removeEventListener("online", handleOnline);
|
|
744
|
-
}, [options.autoSync, options.serverUrl, options.authToken]);
|
|
745
|
-
const executeEffects = useCallback((effects) => {
|
|
746
|
-
executorRef.current?.executeClientEffects(effects);
|
|
747
|
-
if (executorRef.current) {
|
|
748
|
-
setState(executorRef.current.getState());
|
|
749
555
|
}
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
(event, payload, effects) => {
|
|
753
|
-
const result = executorRef.current?.processEventOffline(event, payload, effects);
|
|
754
|
-
if (executorRef.current) {
|
|
755
|
-
setState(executorRef.current.getState());
|
|
756
|
-
}
|
|
757
|
-
return result ?? { success: false, error: "Executor not initialized" };
|
|
758
|
-
},
|
|
759
|
-
[]
|
|
760
|
-
);
|
|
761
|
-
const sync = useCallback(async () => {
|
|
762
|
-
if (!executorRef.current || !options.serverUrl) return 0;
|
|
763
|
-
const count = await executorRef.current.syncPendingEffects(
|
|
764
|
-
options.serverUrl,
|
|
765
|
-
options.authToken
|
|
766
|
-
);
|
|
767
|
-
setState(executorRef.current.getState());
|
|
768
|
-
return count;
|
|
769
|
-
}, [options.serverUrl, options.authToken]);
|
|
770
|
-
const clearQueue = useCallback(() => {
|
|
771
|
-
executorRef.current?.clearQueue();
|
|
772
|
-
if (executorRef.current) {
|
|
773
|
-
setState(executorRef.current.getState());
|
|
556
|
+
if (onNavigate) {
|
|
557
|
+
onNavigate(page.name, path, payload || {});
|
|
774
558
|
}
|
|
775
|
-
}, []);
|
|
776
|
-
|
|
559
|
+
}, [schema, updateUrl, onNavigate]);
|
|
560
|
+
const contextValue = useMemo(() => ({
|
|
777
561
|
state,
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
562
|
+
navigateTo,
|
|
563
|
+
navigateToPage,
|
|
564
|
+
schema,
|
|
565
|
+
isReady: !!state.activePage
|
|
566
|
+
}), [state, navigateTo, navigateToPage, schema]);
|
|
567
|
+
return /* @__PURE__ */ jsx(NavigationContext.Provider, { value: contextValue, children });
|
|
568
|
+
}
|
|
569
|
+
function useNavigation() {
|
|
570
|
+
return useContext(NavigationContext);
|
|
571
|
+
}
|
|
572
|
+
function useNavigateTo() {
|
|
573
|
+
const context = useContext(NavigationContext);
|
|
574
|
+
const noOp = useCallback((path, _payload) => {
|
|
575
|
+
console.warn(`[Navigation] navigateTo called outside NavigationProvider. Path: ${path}`);
|
|
576
|
+
}, []);
|
|
577
|
+
return context?.navigateTo || noOp;
|
|
578
|
+
}
|
|
579
|
+
function useNavigationState() {
|
|
580
|
+
const context = useContext(NavigationContext);
|
|
581
|
+
return context?.state || null;
|
|
582
|
+
}
|
|
583
|
+
function useInitPayload() {
|
|
584
|
+
const context = useContext(NavigationContext);
|
|
585
|
+
return context?.state.initPayload || {};
|
|
586
|
+
}
|
|
587
|
+
function useActivePage() {
|
|
588
|
+
const context = useContext(NavigationContext);
|
|
589
|
+
return context?.state.activePage || null;
|
|
590
|
+
}
|
|
591
|
+
function useNavigationId() {
|
|
592
|
+
const context = useContext(NavigationContext);
|
|
593
|
+
return context?.state.navigationId || 0;
|
|
785
594
|
}
|
|
786
595
|
function initializePatterns() {
|
|
787
596
|
console.log("[PatternResolver] initializePatterns called");
|
|
@@ -803,6 +612,4 @@ function initializePatterns() {
|
|
|
803
612
|
return Object.keys(componentMapping2).length;
|
|
804
613
|
}
|
|
805
614
|
|
|
806
|
-
export { ALL_SLOTS, ClientEffectConfigContext, ClientEffectConfigProvider,
|
|
807
|
-
//# sourceMappingURL=index.js.map
|
|
808
|
-
//# sourceMappingURL=index.js.map
|
|
615
|
+
export { ALL_SLOTS, ClientEffectConfigContext, ClientEffectConfigProvider, NavigationProvider, SLOT_DEFINITIONS, createFetchedDataContext, extractRouteParams, findPageByName, findPageByPath, getAllPages, getDefaultPage, getInlineSlots, getKnownPatterns, getPatternDefinition, getPatternMapping, getPatternsByCategory, getPortalSlots, getSlotDefinition, getSlotsByType, hasEntities, initializePatternResolver, initializePatterns, isInlineSlot, isKnownPattern, isPortalSlot, matchPath, mergeDataContexts, pathMatches, resolveEntityById, resolveEntityCount, resolveEntityData, resolveEntityDataWithQuery, resolvePattern, setComponentMapping, setPatternRegistry, useActivePage, useClientEffectConfig, useClientEffectConfigOptional, useClientEffects, useInitPayload, useNavigateTo, useNavigation, useNavigationId, useNavigationState };
|