@mohamedatia/fly-design-system 2.7.1 → 2.7.2

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.
@@ -395,6 +395,40 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImpor
395
395
  * routing.
396
396
  */
397
397
  const FLY_REMOTE_ROUTES = new InjectionToken('FLY_REMOTE_ROUTES');
398
+ /**
399
+ * Optional injection token a remote provides at its root to declare the shell
400
+ * mount path prefix (e.g. `'/desktop'`). When set, `FlyRemoteRouter.segments()`
401
+ * strips this prefix from `window.location.pathname` before matching routes.
402
+ *
403
+ * **Why this is needed:** In embedded mode the remote is loaded via
404
+ * `NgComponentOutlet` inside the shell SPA. The shell's own Angular route may
405
+ * leave `window.location.pathname` as `/desktop` (or any shell-level path).
406
+ * Without stripping that prefix, `segments()` returns `['desktop']` which
407
+ * matches none of the remote's Circles-internal routes (e.g. `''`, `'signals'`,
408
+ * `'signals/:id'`), so `<fly-remote-router-outlet>` renders nothing.
409
+ *
410
+ * **Default behaviour (token absent):** `FlyRemoteRouter` initialises `_url`
411
+ * to `'/'` in embedded mode, completely ignoring `window.location.pathname`.
412
+ * This is safe because the shell does not push the remote's logical URL into
413
+ * browser history — only `navigate()` / `navigateByUrl()` calls do.
414
+ *
415
+ * **Usage in a remote root component:**
416
+ * ```ts
417
+ * providers: [
418
+ * FlyRemoteRouter,
419
+ * { provide: FLY_REMOTE_ROUTES, useValue: MY_ROUTES },
420
+ * { provide: FLY_REMOTE_BASE_PATH, useValue: '/desktop' },
421
+ * ]
422
+ * ```
423
+ *
424
+ * With `basePath = '/desktop'` and `window.location.pathname = '/desktop'`,
425
+ * the stripped URL is `'/'` → `segments() = []` → matches the `''` default
426
+ * route. With pathname `'/desktop/signals/abc'`, segments become
427
+ * `['signals', 'abc']` → matches `'signals/:id'`.
428
+ *
429
+ * Available since design-system **2.7.2**.
430
+ */
431
+ const FLY_REMOTE_BASE_PATH = new InjectionToken('FLY_REMOTE_BASE_PATH');
398
432
  /**
399
433
  * Match a route's path pattern against URL segments. Returns the captured params
400
434
  * map on a successful match, or `null` if the pattern can't match. Empty path
@@ -489,6 +523,15 @@ class FlyRemoteRouter {
489
523
  * driving its own switch/template — `matchedRoute` stays `null`.
490
524
  */
491
525
  routes = inject(FLY_REMOTE_ROUTES, { optional: true }) ?? [];
526
+ /**
527
+ * Shell mount path prefix to strip from `window.location.pathname` when
528
+ * deriving the initial URL in embedded mode. See `FLY_REMOTE_BASE_PATH` docs.
529
+ *
530
+ * When absent (the common case), the embedded router initialises `_url` to
531
+ * `'/'` and ignores `window.location.pathname` entirely — correct because the
532
+ * shell SPA never encodes the remote's logical route into the browser URL.
533
+ */
534
+ basePath = inject(FLY_REMOTE_BASE_PATH, { optional: true }) ?? null;
492
535
  /**
493
536
  * True when this remote is rendered inside the FlyOS desktop shell.
494
537
  *
@@ -565,9 +608,16 @@ class FlyRemoteRouter {
565
608
  });
566
609
  }
567
610
  else if (this.isEmbedded) {
568
- // Embedded: seed from current browser location on initial load.
611
+ // Embedded: the shell SPA keeps its own route in window.location.pathname
612
+ // (e.g. '/desktop') which is meaningless for the remote's route table.
613
+ // Default: initialise to '/' so the remote's empty-path default route
614
+ // matches on first render. When FLY_REMOTE_BASE_PATH is provided, strip
615
+ // it from pathname first — useful if the shell does push a remote-aware
616
+ // URL (e.g. '/desktop/signals/abc' with basePath '/desktop').
569
617
  if (typeof window !== 'undefined') {
570
- this._url.set(window.location.pathname || '/');
618
+ const rawPath = window.location.pathname || '/';
619
+ const initialUrl = this._resolveEmbeddedInitialUrl(rawPath);
620
+ this._url.set(initialUrl);
571
621
  // Listen for browser back/forward so segments() stays in sync with
572
622
  // history entries pushed by navigate() / navigateByUrl().
573
623
  const onPopState = (event) => {
@@ -623,6 +673,34 @@ class FlyRemoteRouter {
623
673
  history.back();
624
674
  }
625
675
  }
676
+ /**
677
+ * Resolve the logical URL to seed `_url` from on embedded initial load.
678
+ *
679
+ * - No basePath: always return `'/'`. The shell's SPA path (e.g. `/desktop`)
680
+ * is irrelevant to the remote — `navigate()` is the only thing that should
681
+ * move the remote's URL.
682
+ * - basePath provided: strip it from `rawPath`. If rawPath starts with the
683
+ * basePath, the remainder becomes the seed URL (normalised to start with
684
+ * `'/'`). If it doesn't match (e.g. shell changed its own route), fall back
685
+ * to `'/'` rather than surfacing shell-specific segments to the remote's
686
+ * route table.
687
+ */
688
+ _resolveEmbeddedInitialUrl(rawPath) {
689
+ if (!this.basePath) {
690
+ // Default: ignore the shell's pathname, start at remote root.
691
+ return '/';
692
+ }
693
+ const base = this.basePath.endsWith('/') ? this.basePath.slice(0, -1) : this.basePath;
694
+ if (rawPath === base || rawPath === base + '/') {
695
+ return '/';
696
+ }
697
+ if (rawPath.startsWith(base + '/')) {
698
+ const remainder = rawPath.slice(base.length);
699
+ return remainder.startsWith('/') ? remainder : '/' + remainder;
700
+ }
701
+ // Shell path doesn't begin with our basePath — fall through to root.
702
+ return '/';
703
+ }
626
704
  /**
627
705
  * In embedded mode: push a real browser history entry (so back/forward work)
628
706
  * and update the internal signal synchronously.
@@ -4219,5 +4297,5 @@ const AUDIENCE_ERROR_CODES = {
4219
4297
  * Generated bundle index. Do not edit.
4220
4298
  */
4221
4299
 
4222
- export { AGENT_DRAG_MIME, AGENT_PAYLOAD_VERSION, AUDIENCE_ERROR_CODES, AUDIENCE_LIMITS, AUDIENCE_PRESETS, AUDIENCE_TERM_KINDS, AgentCommandRegistry, AgentDropRegistry, AgentPayloadOversizeError, AudienceBuilderComponent, AuthService, ContextMenuComponent, DEFAULT_AGENT_PAYLOAD_LIMITS, DEFAULT_FLY_THEME_MODE, DialogResult, FLY_LOCALE_CATALOG, FLY_REMOTE_ROUTES, FLY_THEME_MODE_IDS, FlyAgentDraggableDirective, FlyBlockUiComponent, FlyFileUploadComponent, FlyImageUploadComponent, FlyRemoteRouter, FlyRemoteRouterOutletComponent, FlyThemeService, I18nService, LAUNCH_CONTEXT, MessageBoxButtons, MessageBoxComponent, MessageBoxIcon, MessageBoxService, MockAuthService, RTL_LOCALE_SET, SHARE_ORG_CHART_SYSTEM_KEY_APPS, SHARE_ORG_CHART_SYSTEM_KEY_DEFAULT, SHARE_PANEL_DEFAULT_FILE_LEVELS, SharePanelComponent, StandaloneWindowManagerService, TranslatePipe, WINDOW_DATA, WindowManagerService, findLocaleByDialect, findLocaleByPrefix, isRtlLocale, isRtlLocaleEntry, loadRemoteStyles, matchFlyRoutePattern, normalizeFlyTheme, trimAgentPayload, trimAgentString, unloadRemoteStyles, utf8ByteLength, validateAgentPayload };
4300
+ export { AGENT_DRAG_MIME, AGENT_PAYLOAD_VERSION, AUDIENCE_ERROR_CODES, AUDIENCE_LIMITS, AUDIENCE_PRESETS, AUDIENCE_TERM_KINDS, AgentCommandRegistry, AgentDropRegistry, AgentPayloadOversizeError, AudienceBuilderComponent, AuthService, ContextMenuComponent, DEFAULT_AGENT_PAYLOAD_LIMITS, DEFAULT_FLY_THEME_MODE, DialogResult, FLY_LOCALE_CATALOG, FLY_REMOTE_BASE_PATH, FLY_REMOTE_ROUTES, FLY_THEME_MODE_IDS, FlyAgentDraggableDirective, FlyBlockUiComponent, FlyFileUploadComponent, FlyImageUploadComponent, FlyRemoteRouter, FlyRemoteRouterOutletComponent, FlyThemeService, I18nService, LAUNCH_CONTEXT, MessageBoxButtons, MessageBoxComponent, MessageBoxIcon, MessageBoxService, MockAuthService, RTL_LOCALE_SET, SHARE_ORG_CHART_SYSTEM_KEY_APPS, SHARE_ORG_CHART_SYSTEM_KEY_DEFAULT, SHARE_PANEL_DEFAULT_FILE_LEVELS, SharePanelComponent, StandaloneWindowManagerService, TranslatePipe, WINDOW_DATA, WindowManagerService, findLocaleByDialect, findLocaleByPrefix, isRtlLocale, isRtlLocaleEntry, loadRemoteStyles, matchFlyRoutePattern, normalizeFlyTheme, trimAgentPayload, trimAgentString, unloadRemoteStyles, utf8ByteLength, validateAgentPayload };
4223
4301
  //# sourceMappingURL=mohamedatia-fly-design-system.mjs.map