@memberjunction/ng-shared-generic 6.2.0-edge.5 → 6.2.0-edge.7
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/lib/_tokens.scss +28 -0
- package/dist/lib/brand-overlay-prepaint.d.ts +20 -0
- package/dist/lib/brand-overlay-prepaint.d.ts.map +1 -0
- package/dist/lib/brand-overlay-prepaint.js +35 -0
- package/dist/lib/brand-overlay-prepaint.js.map +1 -0
- package/dist/lib/recent-access.service.d.ts.map +1 -1
- package/dist/lib/recent-access.service.js +2 -1
- package/dist/lib/recent-access.service.js.map +1 -1
- package/dist/lib/theme.service.d.ts +86 -3
- package/dist/lib/theme.service.d.ts.map +1 -1
- package/dist/lib/theme.service.js +170 -15
- package/dist/lib/theme.service.js.map +1 -1
- package/dist/public-api.d.ts +1 -0
- package/dist/public-api.d.ts.map +1 -1
- package/dist/public-api.js +1 -0
- package/dist/public-api.js.map +1 -1
- package/package.json +7 -7
package/dist/lib/_tokens.scss
CHANGED
|
@@ -124,6 +124,7 @@
|
|
|
124
124
|
/* Indigo Colors (updated actions, indicators) */
|
|
125
125
|
--mj-color-indigo-50: #eef2ff;
|
|
126
126
|
--mj-color-indigo-100: #e0e7ff;
|
|
127
|
+
--mj-color-indigo-400: #818cf8;
|
|
127
128
|
--mj-color-indigo-500: #6366f1;
|
|
128
129
|
--mj-color-indigo-600: #4f46e5;
|
|
129
130
|
|
|
@@ -150,6 +151,8 @@
|
|
|
150
151
|
--mj-text-inverse: var(--mj-color-neutral-0);
|
|
151
152
|
--mj-text-link: var(--mj-color-brand-500);
|
|
152
153
|
--mj-text-link-hover: var(--mj-color-brand-600);
|
|
154
|
+
/* Violet text/accent (special features, role chips); dark mode lifts it to the 300 step. */
|
|
155
|
+
--mj-text-violet: var(--mj-color-violet-700);
|
|
153
156
|
|
|
154
157
|
/* Border Colors */
|
|
155
158
|
--mj-border-default: var(--mj-color-neutral-200);
|
|
@@ -182,6 +185,17 @@
|
|
|
182
185
|
--mj-brand-tertiary-subtle: var(--mj-color-tertiary-50);
|
|
183
186
|
--mj-brand-on-tertiary: var(--mj-color-neutral-0);
|
|
184
187
|
|
|
188
|
+
/* Agent Categorical Accents (semantic)
|
|
189
|
+
Six theme-aware accent hues for multi-agent conversation attribution
|
|
190
|
+
(handoff cards, "via" rails, owner chips). Dark mode shifts each hue to a
|
|
191
|
+
lighter primitive step for contrast on dark surfaces. */
|
|
192
|
+
--mj-agent-accent-brand: var(--mj-color-brand-500);
|
|
193
|
+
--mj-agent-accent-accent: var(--mj-color-accent-500);
|
|
194
|
+
--mj-agent-accent-indigo: var(--mj-color-indigo-500);
|
|
195
|
+
--mj-agent-accent-violet: var(--mj-color-violet-500);
|
|
196
|
+
--mj-agent-accent-tertiary: var(--mj-color-tertiary-500);
|
|
197
|
+
--mj-agent-accent-info: var(--mj-color-info-500);
|
|
198
|
+
|
|
185
199
|
/* Status Colors (semantic) */
|
|
186
200
|
--mj-status-success: var(--mj-color-success-500);
|
|
187
201
|
--mj-status-success-bg: var(--mj-color-success-50);
|
|
@@ -192,6 +206,9 @@
|
|
|
192
206
|
--mj-status-warning-bg: var(--mj-color-warning-50);
|
|
193
207
|
--mj-status-warning-text: var(--mj-color-warning-700);
|
|
194
208
|
--mj-status-warning-border: var(--mj-color-warning-500);
|
|
209
|
+
/* Text on a SOLID --mj-status-warning fill. The amber fill is too light for
|
|
210
|
+
white text, so this stays dark in both themes. */
|
|
211
|
+
--mj-status-on-warning: var(--mj-color-neutral-900);
|
|
195
212
|
|
|
196
213
|
--mj-status-error: var(--mj-color-error-500);
|
|
197
214
|
--mj-status-error-bg: var(--mj-color-error-50);
|
|
@@ -536,6 +553,7 @@
|
|
|
536
553
|
--mj-text-inverse: var(--mj-color-neutral-900);
|
|
537
554
|
--mj-text-link: var(--mj-color-brand-300);
|
|
538
555
|
--mj-text-link-hover: var(--mj-color-brand-200);
|
|
556
|
+
--mj-text-violet: var(--mj-color-violet-300);
|
|
539
557
|
|
|
540
558
|
/* Border Colors */
|
|
541
559
|
--mj-border-default: var(--mj-color-neutral-700);
|
|
@@ -562,6 +580,14 @@
|
|
|
562
580
|
--mj-brand-tertiary-active: var(--mj-color-tertiary-200);
|
|
563
581
|
--mj-brand-tertiary-subtle: color-mix(in srgb, var(--mj-color-tertiary-500) 15%, transparent);
|
|
564
582
|
|
|
583
|
+
/* Agent Categorical Accents (adjusted for dark surfaces) */
|
|
584
|
+
--mj-agent-accent-brand: var(--mj-color-brand-400);
|
|
585
|
+
--mj-agent-accent-accent: var(--mj-color-accent-300);
|
|
586
|
+
--mj-agent-accent-indigo: var(--mj-color-indigo-400);
|
|
587
|
+
--mj-agent-accent-violet: var(--mj-color-violet-400);
|
|
588
|
+
--mj-agent-accent-tertiary: var(--mj-color-tertiary-400);
|
|
589
|
+
--mj-agent-accent-info: var(--mj-color-info-400);
|
|
590
|
+
|
|
565
591
|
/* Highlight (adjusted for dark) */
|
|
566
592
|
--mj-highlight: var(--mj-color-accent-300);
|
|
567
593
|
--mj-highlight-hover: var(--mj-color-accent-200);
|
|
@@ -585,6 +611,8 @@
|
|
|
585
611
|
--mj-status-warning-bg: rgba(245, 158, 11, 0.15);
|
|
586
612
|
--mj-status-warning-text: var(--mj-color-warning-300);
|
|
587
613
|
--mj-status-warning-border: var(--mj-color-warning-600);
|
|
614
|
+
/* --mj-status-warning keeps its light-mode amber in dark mode, so the text on it stays dark. */
|
|
615
|
+
--mj-status-on-warning: var(--mj-color-neutral-900);
|
|
588
616
|
|
|
589
617
|
/* Slightly stronger search highlight on dark surfaces so it stays visible. */
|
|
590
618
|
--mj-search-highlight-bg: color-mix(in srgb, var(--mj-status-warning) 30%, transparent);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The inline pre-paint snippet for the org brand overlay — paste it, wrapped in a `<script>`,
|
|
3
|
+
* at the TOP of the host's `index.html` `<body>`, before the app's root element. Not `<head>`:
|
|
4
|
+
* the snippet appends its `<style>` to the end of `<head>`, and it has to land after the app
|
|
5
|
+
* stylesheet link to win the cascade (the overlay's `[data-theme-overlay]` selectors tie the
|
|
6
|
+
* compiled `:root` tokens on specificity, so source order decides); Angular injects that link
|
|
7
|
+
* just before `</head>`, so from `<head>` the snippet always runs first and loses. It
|
|
8
|
+
* re-injects the overlay CSS that
|
|
9
|
+
* {@link ThemeService.ApplyBrandOverlay} persisted, so the static frame BEFORE the Angular
|
|
10
|
+
* bundle boots already carries the brand. Everything Angular renders is covered by
|
|
11
|
+
* {@link ThemeService.RestorePersistedBrandOverlay} (explorer-app calls it in its constructor);
|
|
12
|
+
* this snippet covers the one frame that runs before any package code can.
|
|
13
|
+
*
|
|
14
|
+
* Exported as a string so hosts carry a versioned copy rather than a hand-written one, and so
|
|
15
|
+
* the reference host's copy can be pinned by a test. Dependency-free by necessity, fails open,
|
|
16
|
+
* and shares the storage keys and the marker attribute with the service, so the two are
|
|
17
|
+
* idempotent and bootstrap's real stylesheet replaces either.
|
|
18
|
+
*/
|
|
19
|
+
export declare const BRAND_OVERLAY_PREPAINT_SCRIPT = "(function () {\n try {\n var id = localStorage.getItem('mj-theme-overlay');\n var raw = id && localStorage.getItem('mj-theme-overlay-css');\n if (!id || !raw) return;\n var entry = JSON.parse(raw);\n if (!entry || entry.id !== id || typeof entry.css !== 'string') return;\n if (document.querySelector('style[data-mj-brand-overlay-preload]')) return;\n var style = document.createElement('style');\n style.setAttribute('data-mj-brand-overlay-preload', id);\n style.textContent = entry.css;\n document.head.appendChild(style);\n document.documentElement.setAttribute('data-theme-overlay', id);\n } catch (e) { /* fail open: the stock frame paints, bootstrap brands it later */ }\n})();";
|
|
20
|
+
//# sourceMappingURL=brand-overlay-prepaint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brand-overlay-prepaint.d.ts","sourceRoot":"","sources":["../../src/lib/brand-overlay-prepaint.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,6BAA6B,mtBAcpC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PRELOAD_OVERLAY_CSS_KEY, PRELOAD_OVERLAY_KEY, PRELOAD_STYLE_ATTR } from './theme.service';
|
|
2
|
+
/**
|
|
3
|
+
* The inline pre-paint snippet for the org brand overlay — paste it, wrapped in a `<script>`,
|
|
4
|
+
* at the TOP of the host's `index.html` `<body>`, before the app's root element. Not `<head>`:
|
|
5
|
+
* the snippet appends its `<style>` to the end of `<head>`, and it has to land after the app
|
|
6
|
+
* stylesheet link to win the cascade (the overlay's `[data-theme-overlay]` selectors tie the
|
|
7
|
+
* compiled `:root` tokens on specificity, so source order decides); Angular injects that link
|
|
8
|
+
* just before `</head>`, so from `<head>` the snippet always runs first and loses. It
|
|
9
|
+
* re-injects the overlay CSS that
|
|
10
|
+
* {@link ThemeService.ApplyBrandOverlay} persisted, so the static frame BEFORE the Angular
|
|
11
|
+
* bundle boots already carries the brand. Everything Angular renders is covered by
|
|
12
|
+
* {@link ThemeService.RestorePersistedBrandOverlay} (explorer-app calls it in its constructor);
|
|
13
|
+
* this snippet covers the one frame that runs before any package code can.
|
|
14
|
+
*
|
|
15
|
+
* Exported as a string so hosts carry a versioned copy rather than a hand-written one, and so
|
|
16
|
+
* the reference host's copy can be pinned by a test. Dependency-free by necessity, fails open,
|
|
17
|
+
* and shares the storage keys and the marker attribute with the service, so the two are
|
|
18
|
+
* idempotent and bootstrap's real stylesheet replaces either.
|
|
19
|
+
*/
|
|
20
|
+
export const BRAND_OVERLAY_PREPAINT_SCRIPT = `(function () {
|
|
21
|
+
try {
|
|
22
|
+
var id = localStorage.getItem('${PRELOAD_OVERLAY_KEY}');
|
|
23
|
+
var raw = id && localStorage.getItem('${PRELOAD_OVERLAY_CSS_KEY}');
|
|
24
|
+
if (!id || !raw) return;
|
|
25
|
+
var entry = JSON.parse(raw);
|
|
26
|
+
if (!entry || entry.id !== id || typeof entry.css !== 'string') return;
|
|
27
|
+
if (document.querySelector('style[${PRELOAD_STYLE_ATTR}]')) return;
|
|
28
|
+
var style = document.createElement('style');
|
|
29
|
+
style.setAttribute('${PRELOAD_STYLE_ATTR}', id);
|
|
30
|
+
style.textContent = entry.css;
|
|
31
|
+
document.head.appendChild(style);
|
|
32
|
+
document.documentElement.setAttribute('data-theme-overlay', id);
|
|
33
|
+
} catch (e) { /* fail open: the stock frame paints, bootstrap brands it later */ }
|
|
34
|
+
})();`;
|
|
35
|
+
//# sourceMappingURL=brand-overlay-prepaint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brand-overlay-prepaint.js","sourceRoot":"","sources":["../../src/lib/brand-overlay-prepaint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAEnG;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG;;qCAER,mBAAmB;4CACZ,uBAAuB;;;;wCAI3B,kBAAkB;;0BAEhC,kBAAkB;;;;;MAKtC,CAAC","sourcesContent":["import { PRELOAD_OVERLAY_CSS_KEY, PRELOAD_OVERLAY_KEY, PRELOAD_STYLE_ATTR } from './theme.service';\n\n/**\n * The inline pre-paint snippet for the org brand overlay — paste it, wrapped in a `<script>`,\n * at the TOP of the host's `index.html` `<body>`, before the app's root element. Not `<head>`:\n * the snippet appends its `<style>` to the end of `<head>`, and it has to land after the app\n * stylesheet link to win the cascade (the overlay's `[data-theme-overlay]` selectors tie the\n * compiled `:root` tokens on specificity, so source order decides); Angular injects that link\n * just before `</head>`, so from `<head>` the snippet always runs first and loses. It\n * re-injects the overlay CSS that\n * {@link ThemeService.ApplyBrandOverlay} persisted, so the static frame BEFORE the Angular\n * bundle boots already carries the brand. Everything Angular renders is covered by\n * {@link ThemeService.RestorePersistedBrandOverlay} (explorer-app calls it in its constructor);\n * this snippet covers the one frame that runs before any package code can.\n *\n * Exported as a string so hosts carry a versioned copy rather than a hand-written one, and so\n * the reference host's copy can be pinned by a test. Dependency-free by necessity, fails open,\n * and shares the storage keys and the marker attribute with the service, so the two are\n * idempotent and bootstrap's real stylesheet replaces either.\n */\nexport const BRAND_OVERLAY_PREPAINT_SCRIPT = `(function () {\n try {\n var id = localStorage.getItem('${PRELOAD_OVERLAY_KEY}');\n var raw = id && localStorage.getItem('${PRELOAD_OVERLAY_CSS_KEY}');\n if (!id || !raw) return;\n var entry = JSON.parse(raw);\n if (!entry || entry.id !== id || typeof entry.css !== 'string') return;\n if (document.querySelector('style[${PRELOAD_STYLE_ATTR}]')) return;\n var style = document.createElement('style');\n style.setAttribute('${PRELOAD_STYLE_ATTR}', id);\n style.textContent = entry.css;\n document.head.appendChild(style);\n document.documentElement.setAttribute('data-theme-overlay', id);\n } catch (e) { /* fail open: the stock frame paints, bootstrap brands it later */ }\n})();`;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recent-access.service.d.ts","sourceRoot":"","sources":["../../src/lib/recent-access.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAqB,YAAY,EAAmC,MAAM,sBAAsB,CAAC;AAG3H,OAAO,EAAmB,UAAU,EAAE,MAAM,MAAM,CAAC;;AAGnD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,IAAI,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,YAAY,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,QAAQ,CAAC;CACvE;AAED;;;GAGG;AACH;;;GAGG;AACH,qBAGa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,CAA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EAAE,CAAC;IAI/G;;OAEG;IACU,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhD,kDAAkD;IACrC,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhD;;;OAGG;YACW,kBAAkB;IA+BhC;;;;;OAKG;IACH,OAAO,CAAC,0BAA0B;IAsBlC;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAI7B;;OAEG;IACI,UAAU,IAAI,IAAI;IAKzB,0CAA0C;IACnC,UAAU,IAAI,IAAI;yCAvSd,mBAAmB;6CAAnB,mBAAmB;CA0S/B"}
|
|
@@ -88,7 +88,8 @@ export class RecentAccessService {
|
|
|
88
88
|
EntityName: 'MJ: User Record Logs',
|
|
89
89
|
ExtraFilter: `UserID='${md.CurrentUser.ID}' AND EntityID='${entityInfo.ID}' AND RecordID='${recordIdString}'`,
|
|
90
90
|
ResultType: 'entity_object',
|
|
91
|
-
MaxRows: 1
|
|
91
|
+
MaxRows: 1,
|
|
92
|
+
SkipTotalRowCount: true
|
|
92
93
|
});
|
|
93
94
|
if (!existingResult.Success) {
|
|
94
95
|
console.error('RecentAccessService: Failed to check existing log', existingResult.ErrorMessage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recent-access.service.js","sourceRoot":"","sources":["../../src/lib/recent-access.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAqB,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAyB,MAAM,sBAAsB,CAAC;AAC3H,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAyB,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACtF,OAAO,EAAE,eAAe,EAAc,MAAM,MAAM,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;;AAiB/D;;;GAGG;AACH;;;GAGG;AAIH,MAAM,OAAO,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mB;gEAAnB,mBAAmB,WAAnB,mBAAmB,mBAFlB,MAAM;;iFAEP,mBAAmB;cAH/B,UAAU;eAAC;gBACV,UAAU,EAAE,MAAM;aACnB","sourcesContent":["import { Injectable } from '@angular/core';\nimport { IMetadataProvider, Metadata, RunView, CompositeKey, LogError, EntityRecordNameInput } from '@memberjunction/core';\nimport { GetGlobalObjectStore } from '@memberjunction/global';\nimport { MJUserRecordLogEntity, UserInfoEngine } from '@memberjunction/core-entities';\nimport { BehaviorSubject, Observable } from 'rxjs';\nimport { ResourceTypeForEntity } from './recent-resource-type';\n\n/**\n * Represents a recently accessed resource\n */\nexport interface RecentAccessItem {\n id: string;\n entityId: string;\n entityName: string;\n recordId: string;\n recordName?: string;\n latestAt: Date;\n totalCount: number;\n /** Resource type for special handling (record, view, dashboard, artifact) */\n resourceType: 'record' | 'view' | 'dashboard' | 'artifact' | 'report';\n}\n\n/**\n * Service for tracking and retrieving recently accessed resources.\n * Uses the User Record Logs entity to persist access history.\n */\n/**\n * Multi-provider note: callers under a non-default provider should set\n * `service.Provider = component.ProviderToUse` before invoking any methods.\n */\n@Injectable({\n providedIn: 'root'\n})\nexport class RecentAccessService {\n private static readonly _globalStoreKey = '___SINGLETON__RecentAccessService';\n private _recentItems$ = new BehaviorSubject<RecentAccessItem[]>([]);\n private _isLoading$ = new BehaviorSubject<boolean>(false);\n private _isLoaded = false;\n\n private _provider: IMetadataProvider | null = null;\n public get Provider(): IMetadataProvider {\n return this._provider ?? Metadata.Provider;\n }\n public set Provider(value: IMetadataProvider | null) {\n this._provider = value;\n }\n\n constructor() {\n const g = GetGlobalObjectStore()!;\n if (g[RecentAccessService._globalStoreKey]) {\n return g[RecentAccessService._globalStoreKey] as RecentAccessService;\n }\n g[RecentAccessService._globalStoreKey] = this;\n }\n\n public static get Instance(): RecentAccessService {\n return GetGlobalObjectStore()![RecentAccessService._globalStoreKey] as RecentAccessService;\n }\n\n /**\n * Observable of recent access items, sorted by most recent first\n */\n public get RecentItems(): Observable<RecentAccessItem[]> {\n return this._recentItems$.asObservable();\n }\n\n /**\n * Current value of recent items\n */\n public get RecentItemsValue(): RecentAccessItem[] {\n return this._recentItems$.value;\n }\n\n /**\n * Observable loading state\n */\n public get IsLoading(): Observable<boolean> {\n return this._isLoading$.asObservable();\n }\n\n /**\n * Logs access to a record. Creates or updates the User Record Log entry.\n * This is a fire-and-forget operation - errors are logged but don't interrupt the user.\n *\n * @param entityName - The name of the entity being accessed\n * @param recordId - The record ID (single value or CompositeKey string)\n * @param resourceType - The type of resource being accessed\n */\n public async LogAccess(\n entityName: string,\n recordId: string | CompositeKey,\n resourceType: 'record' | 'view' | 'dashboard' | 'artifact' | 'report' = 'record'\n ): Promise<void> {\n try {\n const md = this.Provider;\n const entityInfo = md.Entities.find(e => e.Name === entityName);\n if (!entityInfo) {\n console.warn(`RecentAccessService: Entity \"${entityName}\" not found in metadata`);\n return;\n }\n\n // Skip logging when the current user's roles do not grant Create/Update on MJ: User Record Logs\n const logEntityInfo = md.Entities.find(e => e.Name === 'MJ: User Record Logs');\n const logPerms = logEntityInfo?.GetUserPermisions(md.CurrentUser);\n if (logPerms && !logPerms.CanCreate && !logPerms.CanUpdate) {\n return;\n }\n\n // Persist the key in the compact CompositeKey segment form — the bare value for a single-column\n // primary key (so existing rows and lookups are unchanged), \"F1|v1||F2|v2\" for a composite one.\n // That is the form CompositeKey.FromURLSegment reads back; the previous Values(',') dropped\n // the field names, so a composite key written here could never be re-opened.\n const recordIdString = recordId instanceof CompositeKey\n ? recordId.ToCompactURLSegment()\n : recordId;\n\n // Check if we already have a log entry for this user/entity/record combination\n const rv = RunView.FromMetadataProvider(this.Provider);\n const existingResult = await rv.RunView<MJUserRecordLogEntity>({\n EntityName: 'MJ: User Record Logs',\n ExtraFilter: `UserID='${md.CurrentUser.ID}' AND EntityID='${entityInfo.ID}' AND RecordID='${recordIdString}'`,\n ResultType: 'entity_object',\n MaxRows: 1\n });\n\n if (!existingResult.Success) {\n console.error('RecentAccessService: Failed to check existing log', existingResult.ErrorMessage);\n return;\n }\n\n if (existingResult.Results && existingResult.Results.length > 0) {\n if (logPerms && !logPerms.CanUpdate) {\n return;\n }\n // Update existing entry\n const existing = existingResult.Results[0];\n existing.LatestAt = new Date();\n existing.TotalCount = (existing.TotalCount || 0) + 1;\n\n const saveResult = await existing.Save();\n if (!saveResult) {\n console.error('RecentAccessService: Failed to update log entry', existing.LatestResult?.CompleteMessage || '');\n }\n } else {\n if (logPerms && !logPerms.CanCreate) {\n return;\n }\n // Create new entry\n const newLog = await md.GetEntityObject<MJUserRecordLogEntity>('MJ: User Record Logs', md.CurrentUser);\n newLog.UserID = md.CurrentUser.ID;\n newLog.EntityID = entityInfo.ID;\n newLog.RecordID = recordIdString;\n // EarliestAt and LatestAt have default values of getdate() in the DB\n // TotalCount defaults to 0, so we set it to 1\n newLog.TotalCount = 1;\n\n const saveResult = await newLog.Save();\n if (!saveResult) {\n console.error('RecentAccessService: Failed to create log entry', newLog.LatestResult?.CompleteMessage || '');\n }\n }\n\n // Refresh the recent items list in background\n this.RefreshRecentItems();\n } catch (error) {\n // Don't throw - this is non-critical functionality\n console.error('RecentAccessService: Error logging access', error);\n }\n }\n\n /** @deprecated Use {@link LogAccess}. */\n public async logAccess(\n entityName: string,\n recordId: string | CompositeKey,\n resourceType: 'record' | 'view' | 'dashboard' | 'artifact' | 'report' = 'record'\n ): Promise<void> {\n return this.LogAccess(entityName, recordId, resourceType);\n }\n\n /**\n * Loads recent access items for the current user from `MJ: User Record Logs`.\n * @param maxItems - Maximum number of items to return (default 15)\n * @param forceRefresh - Force refresh even if already loaded\n */\n public async LoadRecentItems(maxItems: number = 15, forceRefresh: boolean = false): Promise<RecentAccessItem[]> {\n if (this._isLoaded && !forceRefresh) {\n return this._recentItems$.value;\n }\n\n try {\n this._isLoading$.next(true);\n\n const md = this.Provider;\n\n const userRecordLogs = await UserInfoEngine.Instance.LoadRecentRecordLogs(maxItems, md.CurrentUser, md);\n\n const items: RecentAccessItem[] = [];\n\n for (const log of userRecordLogs) {\n const entityInfo = md.EntityByID(log.EntityID);\n if (!entityInfo) continue;\n\n // Determine resource type based on entity name\n const resourceType = this.determineResourceType(entityInfo.Name);\n\n items.push({\n id: log.ID,\n entityId: log.EntityID,\n entityName: entityInfo.Name,\n recordId: log.RecordID,\n latestAt: log.LatestAt,\n totalCount: log.TotalCount,\n resourceType\n });\n }\n\n // Batch-resolve record names for all items\n await this.resolveRecordNames(items, md);\n\n this._recentItems$.next(items);\n this._isLoaded = true;\n\n return items;\n } catch (error) {\n LogError('RecentAccessService: Error loading recent items', undefined, error);\n return [];\n } finally {\n this._isLoading$.next(false);\n }\n }\n\n /** @deprecated Use {@link LoadRecentItems}. */\n public async loadRecentItems(maxItems: number = 15, forceRefresh: boolean = false): Promise<RecentAccessItem[]> {\n return this.LoadRecentItems(maxItems, forceRefresh);\n }\n\n /**\n * Refresh recent items in background\n */\n public async RefreshRecentItems(): Promise<void> {\n await this.LoadRecentItems(15, true);\n }\n\n /** @deprecated Use {@link RefreshRecentItems}. */\n public async refreshRecentItems(): Promise<void> {\n return this.RefreshRecentItems();\n }\n\n /**\n * Batch-resolve record names for a list of recent access items using GetEntityRecordNames().\n * Mutates the items in-place to set recordName where resolved.\n */\n private async resolveRecordNames(items: RecentAccessItem[], md: IMetadataProvider): Promise<void> {\n const nameInputs: EntityRecordNameInput[] = [];\n const indexMap = new Map<string, number>();\n\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n const compositeKey = this.buildCompositeKeyForRecord(item.entityName, item.recordId, md);\n if (!compositeKey) continue;\n\n nameInputs.push({ EntityName: item.entityName, CompositeKey: compositeKey });\n indexMap.set(`${item.entityName}||${compositeKey.ToConcatenatedString()}`, i);\n }\n\n if (nameInputs.length === 0) return;\n\n try {\n const nameResults = await md.GetEntityRecordNames(nameInputs);\n for (const result of nameResults) {\n if (result.Success && result.RecordName) {\n const key = `${result.EntityName}||${result.CompositeKey.ToConcatenatedString()}`;\n const index = indexMap.get(key);\n if (index !== undefined) {\n items[index].recordName = result.RecordName;\n }\n }\n }\n } catch (error) {\n console.warn('RecentAccessService: Failed to resolve record names', error);\n }\n }\n\n /**\n * Build a CompositeKey for a record. RecordID may be stored as either:\n * - Concatenated format: \"FieldName|Value\" or \"Field1|Val1||Field2|Val2\"\n * - Plain value: just the raw value (e.g. a GUID)\n * Detects the format and constructs the key accordingly.\n */\n private buildCompositeKeyForRecord(entityName: string, recordId: string, md: IMetadataProvider): CompositeKey | null {\n if (!recordId) return null;\n\n // If recordId contains '|', it's in concatenated format\n if (recordId.includes('|')) {\n try {\n const compositeKey = new CompositeKey();\n compositeKey.LoadFromConcatenatedString(recordId);\n if (compositeKey.KeyValuePairs.length > 0) return compositeKey;\n } catch {\n // Fall through to entity-based lookup\n }\n }\n\n // Plain value — map it onto the entity's real primary key column (whatever it is called).\n // FromURLSegment also re-parses a delimited segment, covering the case where the try above failed.\n const entityInfo = md.Entities.find(e => e.Name === entityName);\n if (!entityInfo || entityInfo.PrimaryKeys.length === 0) return null;\n\n return CompositeKey.FromURLSegment(entityInfo, recordId);\n }\n\n /**\n * Determines the resource type based on entity name\n */\n private determineResourceType(entityName: string): 'record' | 'view' | 'dashboard' | 'artifact' | 'report' {\n return ResourceTypeForEntity(entityName);\n }\n\n /**\n * Clears the cached recent items (useful for logout)\n */\n public ClearCache(): void {\n this._recentItems$.next([]);\n this._isLoaded = false;\n }\n\n /** @deprecated Use {@link ClearCache}. */\n public clearCache(): void {\n return this.ClearCache();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"recent-access.service.js","sourceRoot":"","sources":["../../src/lib/recent-access.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAqB,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAyB,MAAM,sBAAsB,CAAC;AAC3H,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,E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ACI,UAAU;QACf,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,CAAC;IAED,0CAA0C;IACnC,UAAU;QACf,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC3B,CAAC;6GAzSU,mBAAmB;gEAAnB,mBAAmB,WAAnB,mBAAmB,mBAFlB,MAAM;;iFAEP,mBAAmB;cAH/B,UAAU;eAAC;gBACV,UAAU,EAAE,MAAM;aACnB","sourcesContent":["import { Injectable } from '@angular/core';\nimport { IMetadataProvider, Metadata, RunView, CompositeKey, LogError, EntityRecordNameInput } from '@memberjunction/core';\nimport { GetGlobalObjectStore } from '@memberjunction/global';\nimport { MJUserRecordLogEntity, UserInfoEngine } from '@memberjunction/core-entities';\nimport { BehaviorSubject, Observable } from 'rxjs';\nimport { ResourceTypeForEntity } from './recent-resource-type';\n\n/**\n * Represents a recently accessed resource\n */\nexport interface RecentAccessItem {\n id: string;\n entityId: string;\n entityName: string;\n recordId: string;\n recordName?: string;\n latestAt: Date;\n totalCount: number;\n /** Resource type for special handling (record, view, dashboard, artifact) */\n resourceType: 'record' | 'view' | 'dashboard' | 'artifact' | 'report';\n}\n\n/**\n * Service for tracking and retrieving recently accessed resources.\n * Uses the User Record Logs entity to persist access history.\n */\n/**\n * Multi-provider note: callers under a non-default provider should set\n * `service.Provider = component.ProviderToUse` before invoking any methods.\n */\n@Injectable({\n providedIn: 'root'\n})\nexport class RecentAccessService {\n private static readonly _globalStoreKey = '___SINGLETON__RecentAccessService';\n private _recentItems$ = new BehaviorSubject<RecentAccessItem[]>([]);\n private _isLoading$ = new BehaviorSubject<boolean>(false);\n private _isLoaded = false;\n\n private _provider: IMetadataProvider | null = null;\n public get Provider(): IMetadataProvider {\n return this._provider ?? Metadata.Provider;\n }\n public set Provider(value: IMetadataProvider | null) {\n this._provider = value;\n }\n\n constructor() {\n const g = GetGlobalObjectStore()!;\n if (g[RecentAccessService._globalStoreKey]) {\n return g[RecentAccessService._globalStoreKey] as RecentAccessService;\n }\n g[RecentAccessService._globalStoreKey] = this;\n }\n\n public static get Instance(): RecentAccessService {\n return GetGlobalObjectStore()![RecentAccessService._globalStoreKey] as RecentAccessService;\n }\n\n /**\n * Observable of recent access items, sorted by most recent first\n */\n public get RecentItems(): Observable<RecentAccessItem[]> {\n return this._recentItems$.asObservable();\n }\n\n /**\n * Current value of recent items\n */\n public get RecentItemsValue(): RecentAccessItem[] {\n return this._recentItems$.value;\n }\n\n /**\n * Observable loading state\n */\n public get IsLoading(): Observable<boolean> {\n return this._isLoading$.asObservable();\n }\n\n /**\n * Logs access to a record. Creates or updates the User Record Log entry.\n * This is a fire-and-forget operation - errors are logged but don't interrupt the user.\n *\n * @param entityName - The name of the entity being accessed\n * @param recordId - The record ID (single value or CompositeKey string)\n * @param resourceType - The type of resource being accessed\n */\n public async LogAccess(\n entityName: string,\n recordId: string | CompositeKey,\n resourceType: 'record' | 'view' | 'dashboard' | 'artifact' | 'report' = 'record'\n ): Promise<void> {\n try {\n const md = this.Provider;\n const entityInfo = md.Entities.find(e => e.Name === entityName);\n if (!entityInfo) {\n console.warn(`RecentAccessService: Entity \"${entityName}\" not found in metadata`);\n return;\n }\n\n // Skip logging when the current user's roles do not grant Create/Update on MJ: User Record Logs\n const logEntityInfo = md.Entities.find(e => e.Name === 'MJ: User Record Logs');\n const logPerms = logEntityInfo?.GetUserPermisions(md.CurrentUser);\n if (logPerms && !logPerms.CanCreate && !logPerms.CanUpdate) {\n return;\n }\n\n // Persist the key in the compact CompositeKey segment form — the bare value for a single-column\n // primary key (so existing rows and lookups are unchanged), \"F1|v1||F2|v2\" for a composite one.\n // That is the form CompositeKey.FromURLSegment reads back; the previous Values(',') dropped\n // the field names, so a composite key written here could never be re-opened.\n const recordIdString = recordId instanceof CompositeKey\n ? recordId.ToCompactURLSegment()\n : recordId;\n\n // Check if we already have a log entry for this user/entity/record combination\n const rv = RunView.FromMetadataProvider(this.Provider);\n const existingResult = await rv.RunView<MJUserRecordLogEntity>({\n EntityName: 'MJ: User Record Logs',\n ExtraFilter: `UserID='${md.CurrentUser.ID}' AND EntityID='${entityInfo.ID}' AND RecordID='${recordIdString}'`,\n ResultType: 'entity_object',\n MaxRows: 1,\n SkipTotalRowCount: true\n });\n\n if (!existingResult.Success) {\n console.error('RecentAccessService: Failed to check existing log', existingResult.ErrorMessage);\n return;\n }\n\n if (existingResult.Results && existingResult.Results.length > 0) {\n if (logPerms && !logPerms.CanUpdate) {\n return;\n }\n // Update existing entry\n const existing = existingResult.Results[0];\n existing.LatestAt = new Date();\n existing.TotalCount = (existing.TotalCount || 0) + 1;\n\n const saveResult = await existing.Save();\n if (!saveResult) {\n console.error('RecentAccessService: Failed to update log entry', existing.LatestResult?.CompleteMessage || '');\n }\n } else {\n if (logPerms && !logPerms.CanCreate) {\n return;\n }\n // Create new entry\n const newLog = await md.GetEntityObject<MJUserRecordLogEntity>('MJ: User Record Logs', md.CurrentUser);\n newLog.UserID = md.CurrentUser.ID;\n newLog.EntityID = entityInfo.ID;\n newLog.RecordID = recordIdString;\n // EarliestAt and LatestAt have default values of getdate() in the DB\n // TotalCount defaults to 0, so we set it to 1\n newLog.TotalCount = 1;\n\n const saveResult = await newLog.Save();\n if (!saveResult) {\n console.error('RecentAccessService: Failed to create log entry', newLog.LatestResult?.CompleteMessage || '');\n }\n }\n\n // Refresh the recent items list in background\n this.RefreshRecentItems();\n } catch (error) {\n // Don't throw - this is non-critical functionality\n console.error('RecentAccessService: Error logging access', error);\n }\n }\n\n /** @deprecated Use {@link LogAccess}. */\n public async logAccess(\n entityName: string,\n recordId: string | CompositeKey,\n resourceType: 'record' | 'view' | 'dashboard' | 'artifact' | 'report' = 'record'\n ): Promise<void> {\n return this.LogAccess(entityName, recordId, resourceType);\n }\n\n /**\n * Loads recent access items for the current user from `MJ: User Record Logs`.\n * @param maxItems - Maximum number of items to return (default 15)\n * @param forceRefresh - Force refresh even if already loaded\n */\n public async LoadRecentItems(maxItems: number = 15, forceRefresh: boolean = false): Promise<RecentAccessItem[]> {\n if (this._isLoaded && !forceRefresh) {\n return this._recentItems$.value;\n }\n\n try {\n this._isLoading$.next(true);\n\n const md = this.Provider;\n\n const userRecordLogs = await UserInfoEngine.Instance.LoadRecentRecordLogs(maxItems, md.CurrentUser, md);\n\n const items: RecentAccessItem[] = [];\n\n for (const log of userRecordLogs) {\n const entityInfo = md.EntityByID(log.EntityID);\n if (!entityInfo) continue;\n\n // Determine resource type based on entity name\n const resourceType = this.determineResourceType(entityInfo.Name);\n\n items.push({\n id: log.ID,\n entityId: log.EntityID,\n entityName: entityInfo.Name,\n recordId: log.RecordID,\n latestAt: log.LatestAt,\n totalCount: log.TotalCount,\n resourceType\n });\n }\n\n // Batch-resolve record names for all items\n await this.resolveRecordNames(items, md);\n\n this._recentItems$.next(items);\n this._isLoaded = true;\n\n return items;\n } catch (error) {\n LogError('RecentAccessService: Error loading recent items', undefined, error);\n return [];\n } finally {\n this._isLoading$.next(false);\n }\n }\n\n /** @deprecated Use {@link LoadRecentItems}. */\n public async loadRecentItems(maxItems: number = 15, forceRefresh: boolean = false): Promise<RecentAccessItem[]> {\n return this.LoadRecentItems(maxItems, forceRefresh);\n }\n\n /**\n * Refresh recent items in background\n */\n public async RefreshRecentItems(): Promise<void> {\n await this.LoadRecentItems(15, true);\n }\n\n /** @deprecated Use {@link RefreshRecentItems}. */\n public async refreshRecentItems(): Promise<void> {\n return this.RefreshRecentItems();\n }\n\n /**\n * Batch-resolve record names for a list of recent access items using GetEntityRecordNames().\n * Mutates the items in-place to set recordName where resolved.\n */\n private async resolveRecordNames(items: RecentAccessItem[], md: IMetadataProvider): Promise<void> {\n const nameInputs: EntityRecordNameInput[] = [];\n const indexMap = new Map<string, number>();\n\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n const compositeKey = this.buildCompositeKeyForRecord(item.entityName, item.recordId, md);\n if (!compositeKey) continue;\n\n nameInputs.push({ EntityName: item.entityName, CompositeKey: compositeKey });\n indexMap.set(`${item.entityName}||${compositeKey.ToConcatenatedString()}`, i);\n }\n\n if (nameInputs.length === 0) return;\n\n try {\n const nameResults = await md.GetEntityRecordNames(nameInputs);\n for (const result of nameResults) {\n if (result.Success && result.RecordName) {\n const key = `${result.EntityName}||${result.CompositeKey.ToConcatenatedString()}`;\n const index = indexMap.get(key);\n if (index !== undefined) {\n items[index].recordName = result.RecordName;\n }\n }\n }\n } catch (error) {\n console.warn('RecentAccessService: Failed to resolve record names', error);\n }\n }\n\n /**\n * Build a CompositeKey for a record. RecordID may be stored as either:\n * - Concatenated format: \"FieldName|Value\" or \"Field1|Val1||Field2|Val2\"\n * - Plain value: just the raw value (e.g. a GUID)\n * Detects the format and constructs the key accordingly.\n */\n private buildCompositeKeyForRecord(entityName: string, recordId: string, md: IMetadataProvider): CompositeKey | null {\n if (!recordId) return null;\n\n // If recordId contains '|', it's in concatenated format\n if (recordId.includes('|')) {\n try {\n const compositeKey = new CompositeKey();\n compositeKey.LoadFromConcatenatedString(recordId);\n if (compositeKey.KeyValuePairs.length > 0) return compositeKey;\n } catch {\n // Fall through to entity-based lookup\n }\n }\n\n // Plain value — map it onto the entity's real primary key column (whatever it is called).\n // FromURLSegment also re-parses a delimited segment, covering the case where the try above failed.\n const entityInfo = md.Entities.find(e => e.Name === entityName);\n if (!entityInfo || entityInfo.PrimaryKeys.length === 0) return null;\n\n return CompositeKey.FromURLSegment(entityInfo, recordId);\n }\n\n /**\n * Determines the resource type based on entity name\n */\n private determineResourceType(entityName: string): 'record' | 'view' | 'dashboard' | 'artifact' | 'report' {\n return ResourceTypeForEntity(entityName);\n }\n\n /**\n * Clears the cached recent items (useful for logout)\n */\n public ClearCache(): void {\n this._recentItems$.next([]);\n this._isLoaded = false;\n }\n\n /** @deprecated Use {@link ClearCache}. */\n public clearCache(): void {\n return this.ClearCache();\n }\n}\n"]}
|
|
@@ -27,7 +27,41 @@ export interface ThemeDefinition {
|
|
|
27
27
|
Description?: string;
|
|
28
28
|
/** Optional preview swatch colors for a future theme picker UI */
|
|
29
29
|
PreviewColors?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* The theme {@link ThemeService.Initialize} applies when the user has no saved preference
|
|
32
|
+
* (or the saved one is no longer registered). At most one registered theme should set it;
|
|
33
|
+
* the first registered wins. Without one the default stays `'system'`. A single-brand host
|
|
34
|
+
* registers its brand as the default instead of calling `SetTheme` on every login, which
|
|
35
|
+
* fought `Initialize()`'s own resolution and wrote a preference the user never chose.
|
|
36
|
+
*
|
|
37
|
+
* Not the same axis as Theme Studio's org default (`MJ: Themes`.IsDefault): that one picks
|
|
38
|
+
* the org BRAND OVERLAY, registered via {@link ThemeService.RegisterBrandTheme} into the
|
|
39
|
+
* brand registry and layered under whatever base theme is active. This flag picks the BASE
|
|
40
|
+
* (picker) theme and never looks at the brand registry, so the two compose: a picker-only
|
|
41
|
+
* built-in default keeps the org overlay; a `CssUrl` default replaces it while selected, as
|
|
42
|
+
* any explicitly selected custom theme does.
|
|
43
|
+
*/
|
|
44
|
+
IsDefault?: boolean;
|
|
30
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* localStorage key holding the active org **brand overlay** id, mirrored so the
|
|
48
|
+
* inline pre-paint script can restore `data-theme-overlay` on first paint (the org
|
|
49
|
+
* brand persists across the user's light/dark choice AND across logout). The overlay
|
|
50
|
+
* CSS itself is a session-scoped Blob re-emitted at login bootstrap; the CSS text is
|
|
51
|
+
* persisted beside it under {@link PRELOAD_OVERLAY_CSS_KEY} so
|
|
52
|
+
* {@link ThemeService.RestorePersistedBrandOverlay} can put it back before first paint.
|
|
53
|
+
*/
|
|
54
|
+
export declare const PRELOAD_OVERLAY_KEY = "mj-theme-overlay";
|
|
55
|
+
/**
|
|
56
|
+
* localStorage key: the active org brand overlay's emitted CSS, as JSON `{ id, css }`.
|
|
57
|
+
* The overlay stylesheet is a Blob URL that does not survive a reload, so without this
|
|
58
|
+
* the loading screen and the sign-in page painted MJ's default tokens until bootstrap
|
|
59
|
+
* re-emitted the overlay at the end of workspace init. Only honored when `id` matches
|
|
60
|
+
* {@link PRELOAD_OVERLAY_KEY}; bootstrap's real `<link>` replaces the preloaded `<style>`.
|
|
61
|
+
*/
|
|
62
|
+
export declare const PRELOAD_OVERLAY_CSS_KEY = "mj-theme-overlay-css";
|
|
63
|
+
/** Attribute on the `<style>` that carries a restored overlay until bootstrap loads the real one. */
|
|
64
|
+
export declare const PRELOAD_STYLE_ATTR = "data-mj-brand-overlay-preload";
|
|
31
65
|
/**
|
|
32
66
|
* Service to manage application themes with pluggable custom theme support.
|
|
33
67
|
*
|
|
@@ -68,11 +102,27 @@ export declare class ThemeService {
|
|
|
68
102
|
* themeRegistry so brand overlays do NOT appear in the user's light/dark theme
|
|
69
103
|
* picker — the org brand is applied independently of the user's mode (decision #1).
|
|
70
104
|
*/
|
|
105
|
+
/**
|
|
106
|
+
* Theme ids in the order they were FIRST registered with {@link ThemeDefinition.IsDefault}.
|
|
107
|
+
* Kept apart from the registry because a Map keeps an id's original slot on replace: the
|
|
108
|
+
* seeded 'light'/'dark' entries would otherwise outrank any custom theme flagged earlier.
|
|
109
|
+
*/
|
|
110
|
+
private defaultCandidates;
|
|
71
111
|
private brandRegistry;
|
|
72
112
|
/** Cache of loaded <link> elements by theme ID to avoid re-downloading */
|
|
73
113
|
private loadedCssLinks;
|
|
74
114
|
/** Session-scoped Blob object URLs for brand overlays, keyed by theme ID (for revocation on re-register). */
|
|
75
115
|
private brandBlobUrls;
|
|
116
|
+
/** The emitted overlay CSS per brand theme id — what gets persisted for first paint. */
|
|
117
|
+
private brandCss;
|
|
118
|
+
/**
|
|
119
|
+
* An overlay id restored from localStorage by {@link RestorePersistedBrandOverlay} that
|
|
120
|
+
* bootstrap has not yet confirmed ({@link ApplyBrandOverlay}) or cleared
|
|
121
|
+
* ({@link ClearBrandOverlay}). Tracked here rather than inferred from the presence of the
|
|
122
|
+
* preload `<style>`, so a third party touching that element cannot change the service's
|
|
123
|
+
* answer, and "bootstrap has not run yet" is a state of its own.
|
|
124
|
+
*/
|
|
125
|
+
private pendingOverlayId;
|
|
76
126
|
/**
|
|
77
127
|
* Observable for user's theme preference (theme ID or 'system')
|
|
78
128
|
*/
|
|
@@ -160,8 +210,34 @@ export declare class ThemeService {
|
|
|
160
210
|
ApplyBrandOverlay(id: string, options?: {
|
|
161
211
|
persist?: boolean;
|
|
162
212
|
}): Promise<void>;
|
|
213
|
+
/**
|
|
214
|
+
* Put the persisted org brand overlay back BEFORE first paint, from localStorage alone —
|
|
215
|
+
* no registry, no database. Call it from the earliest code that runs in the app (the
|
|
216
|
+
* explorer-app constructor), so the sign-in page and the shell's loading screen paint
|
|
217
|
+
* branded on a cold load instead of waiting for bootstrap to re-emit the overlay.
|
|
218
|
+
*
|
|
219
|
+
* Injects the persisted CSS as a `<style>` (bootstrap's real `<link>` replaces it), sets
|
|
220
|
+
* `data-theme-overlay`, and records the id so {@link Initialize} does not strip the
|
|
221
|
+
* attribute before bootstrap registers the brand. A CSS entry whose id no longer matches
|
|
222
|
+
* the persisted overlay id is stale and is dropped. Returns whether anything was restored.
|
|
223
|
+
*/
|
|
224
|
+
RestorePersistedBrandOverlay(): boolean;
|
|
225
|
+
/**
|
|
226
|
+
* The restored preload `<style>` for this overlay id, if one is in the document (ours or the
|
|
227
|
+
* host's inline snippet). An attribute walk rather than an interpolated selector: the id
|
|
228
|
+
* comes from localStorage, and a quote or bracket in it would make `querySelector` throw —
|
|
229
|
+
* from the explorer-app constructor.
|
|
230
|
+
*/
|
|
231
|
+
private findPreloadStyle;
|
|
232
|
+
/** Drop every restored preload `<style>` (a real stylesheet has taken over, or the brand was cleared). */
|
|
233
|
+
private removePreloadStyles;
|
|
163
234
|
/**
|
|
164
235
|
* Remove the active org brand overlay (revert to the base MJ tokens).
|
|
236
|
+
*
|
|
237
|
+
* Scoped to the brand: only the brand's own `<link>` is disabled and the `data-theme-overlay`
|
|
238
|
+
* attribute is dropped only when it still names that brand. Bootstrap calls this on every login
|
|
239
|
+
* where the org has no active brand, right after `Initialize()` applied the user's theme, so a
|
|
240
|
+
* blanket clear would switch off a user's custom theme on any install that never used Theme Studio.
|
|
165
241
|
*/
|
|
166
242
|
ClearBrandOverlay(): void;
|
|
167
243
|
/**
|
|
@@ -169,6 +245,13 @@ export declare class ThemeService {
|
|
|
169
245
|
* Call after login when UserInfoEngine is available.
|
|
170
246
|
*/
|
|
171
247
|
Initialize(): Promise<void>;
|
|
248
|
+
/**
|
|
249
|
+
* What {@link Initialize} applies when nothing is saved: the first theme REGISTERED with
|
|
250
|
+
* {@link ThemeDefinition.IsDefault} (registration order, not registry slot order — re-registering
|
|
251
|
+
* a built-in slot with the flag does not jump the queue), else `'system'`. Public so a picker
|
|
252
|
+
* can mark the default.
|
|
253
|
+
*/
|
|
254
|
+
get DefaultPreference(): string;
|
|
172
255
|
/**
|
|
173
256
|
* Set the theme preference and apply it.
|
|
174
257
|
* @param preference - A registered theme ID or 'system'
|
|
@@ -250,9 +333,9 @@ export declare class ThemeService {
|
|
|
250
333
|
/** Persist (or clear, with null) the user's chosen brand theme so login restores it. */
|
|
251
334
|
SetSelectedBrandTheme(id: string | null): Promise<void>;
|
|
252
335
|
/**
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
336
|
+
* The user's saved preference ('system' or a registered theme ID), or `null` when there is
|
|
337
|
+
* none to honor — nothing saved, a saved theme that is no longer registered, or a failed
|
|
338
|
+
* read. The caller decides what `null` means (see {@link DefaultPreference}).
|
|
256
339
|
*/
|
|
257
340
|
private loadSetting;
|
|
258
341
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.service.d.ts","sourceRoot":"","sources":["../../src/lib/theme.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,UAAU,EAAW,MAAM,MAAM,CAAC;AAE5D,OAAO,EAAU,YAAY,EAAsC,UAAU,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;;AAEhI;;;;GAIG;AACH,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GAAG,OAAO,CAAC,IAAI,CAAC;IAaxD;;OAEG;IACI,KAAK,IAAI,IAAI;IAoCpB;;;;OAIG;YACW,UAAU;IA4CxB;;;;;;;;OAQG;IACH,OAAO,CAAC,uBAAuB;IAe/B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAUzB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAkCpB;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAa3B;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAcpB;;OAEG;IACH,OAAO,CAAC,cAAc;IAOtB;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAUhC;;OAEG;YACW,mBAAmB;IAWjC,2DAA2D;IAC3D,IAAW,QAAQ,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC,CAE1C;IAED,uFAAuF;IACvF,IAAW,cAAc,IAAI,UAAU,CAAC,IAAI,CAAC,CAE5C;IAED,+FAA+F;IACxF,mBAAmB,IAAI,IAAI;IAIlC,wDAAwD;IACjD,kBAAkB,IAAI,MAAM,EAAE;IAIrC,iDAAiD;IAC1C,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIrC;;;OAGG;IACU,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAkBrD,OAAO,CAAC,cAAc;IAUtB,iFAAiF;IAC1E,uBAAuB,IAAI,MAAM,GAAG,IAAI;IAQ/C,wFAAwF;IAC3E,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAYpE;;;;OAIG;YACW,WAAW;IAsBzB;;OAEG;YACW,WAAW;yCArwBhB,YAAY;6CAAZ,YAAY;CA6wBxB"}
|
|
@@ -25,10 +25,21 @@ const PRELOAD_BASE_THEME_KEY = 'mj-theme';
|
|
|
25
25
|
* localStorage key holding the active org **brand overlay** id, mirrored so the
|
|
26
26
|
* inline pre-paint script can restore `data-theme-overlay` on first paint (the org
|
|
27
27
|
* brand persists across the user's light/dark choice AND across logout). The overlay
|
|
28
|
-
* CSS itself is a session-scoped Blob re-emitted at login bootstrap
|
|
29
|
-
*
|
|
28
|
+
* CSS itself is a session-scoped Blob re-emitted at login bootstrap; the CSS text is
|
|
29
|
+
* persisted beside it under {@link PRELOAD_OVERLAY_CSS_KEY} so
|
|
30
|
+
* {@link ThemeService.RestorePersistedBrandOverlay} can put it back before first paint.
|
|
30
31
|
*/
|
|
31
|
-
const PRELOAD_OVERLAY_KEY = 'mj-theme-overlay';
|
|
32
|
+
export const PRELOAD_OVERLAY_KEY = 'mj-theme-overlay';
|
|
33
|
+
/**
|
|
34
|
+
* localStorage key: the active org brand overlay's emitted CSS, as JSON `{ id, css }`.
|
|
35
|
+
* The overlay stylesheet is a Blob URL that does not survive a reload, so without this
|
|
36
|
+
* the loading screen and the sign-in page painted MJ's default tokens until bootstrap
|
|
37
|
+
* re-emitted the overlay at the end of workspace init. Only honored when `id` matches
|
|
38
|
+
* {@link PRELOAD_OVERLAY_KEY}; bootstrap's real `<link>` replaces the preloaded `<style>`.
|
|
39
|
+
*/
|
|
40
|
+
export const PRELOAD_OVERLAY_CSS_KEY = 'mj-theme-overlay-css';
|
|
41
|
+
/** Attribute on the `<style>` that carries a restored overlay until bootstrap loads the real one. */
|
|
42
|
+
export const PRELOAD_STYLE_ATTR = 'data-mj-brand-overlay-preload';
|
|
32
43
|
/** User-settings key: JSON array of the user's starred (favorited) brand theme ids. */
|
|
33
44
|
const STARRED_THEMES_KEY = 'Explorer.StarredThemes';
|
|
34
45
|
/** User-settings key: the brand theme id the user last applied (restored over org default). */
|
|
@@ -96,11 +107,27 @@ export class ThemeService {
|
|
|
96
107
|
* themeRegistry so brand overlays do NOT appear in the user's light/dark theme
|
|
97
108
|
* picker — the org brand is applied independently of the user's mode (decision #1).
|
|
98
109
|
*/
|
|
110
|
+
/**
|
|
111
|
+
* Theme ids in the order they were FIRST registered with {@link ThemeDefinition.IsDefault}.
|
|
112
|
+
* Kept apart from the registry because a Map keeps an id's original slot on replace: the
|
|
113
|
+
* seeded 'light'/'dark' entries would otherwise outrank any custom theme flagged earlier.
|
|
114
|
+
*/
|
|
115
|
+
defaultCandidates = [];
|
|
99
116
|
brandRegistry = new Map();
|
|
100
117
|
/** Cache of loaded <link> elements by theme ID to avoid re-downloading */
|
|
101
118
|
loadedCssLinks = new Map();
|
|
102
119
|
/** Session-scoped Blob object URLs for brand overlays, keyed by theme ID (for revocation on re-register). */
|
|
103
120
|
brandBlobUrls = new Map();
|
|
121
|
+
/** The emitted overlay CSS per brand theme id — what gets persisted for first paint. */
|
|
122
|
+
brandCss = new Map();
|
|
123
|
+
/**
|
|
124
|
+
* An overlay id restored from localStorage by {@link RestorePersistedBrandOverlay} that
|
|
125
|
+
* bootstrap has not yet confirmed ({@link ApplyBrandOverlay}) or cleared
|
|
126
|
+
* ({@link ClearBrandOverlay}). Tracked here rather than inferred from the presence of the
|
|
127
|
+
* preload `<style>`, so a third party touching that element cannot change the service's
|
|
128
|
+
* answer, and "bootstrap has not run yet" is a state of its own.
|
|
129
|
+
*/
|
|
130
|
+
pendingOverlayId = null;
|
|
104
131
|
/**
|
|
105
132
|
* Observable for user's theme preference (theme ID or 'system')
|
|
106
133
|
*/
|
|
@@ -153,6 +180,13 @@ export class ThemeService {
|
|
|
153
180
|
*/
|
|
154
181
|
RegisterTheme(theme) {
|
|
155
182
|
this.themeRegistry.set(theme.Id, theme);
|
|
183
|
+
const at = this.defaultCandidates.indexOf(theme.Id);
|
|
184
|
+
if (theme.IsDefault && at === -1) {
|
|
185
|
+
this.defaultCandidates.push(theme.Id);
|
|
186
|
+
}
|
|
187
|
+
else if (!theme.IsDefault && at !== -1) {
|
|
188
|
+
this.defaultCandidates.splice(at, 1);
|
|
189
|
+
}
|
|
156
190
|
}
|
|
157
191
|
/**
|
|
158
192
|
* Register multiple custom themes at once.
|
|
@@ -197,6 +231,7 @@ export class ThemeService {
|
|
|
197
231
|
}
|
|
198
232
|
const url = URL.createObjectURL(new Blob([css], { type: 'text/css' }));
|
|
199
233
|
this.brandBlobUrls.set(params.id, url);
|
|
234
|
+
this.brandCss.set(params.id, css);
|
|
200
235
|
// Register into the brand registry only — NOT themeRegistry — so the org brand
|
|
201
236
|
// does not surface as a user-selectable option in the theme picker.
|
|
202
237
|
this.brandRegistry.set(params.id, {
|
|
@@ -256,26 +291,122 @@ export class ThemeService {
|
|
|
256
291
|
}
|
|
257
292
|
this._brandOverlayId = id;
|
|
258
293
|
await this.loadThemeCss(def);
|
|
294
|
+
// The real stylesheet carries the brand now; a restored preload (this id or a stale one) goes.
|
|
295
|
+
this.removePreloadStyles();
|
|
296
|
+
this.pendingOverlayId = null;
|
|
259
297
|
document.documentElement.setAttribute('data-theme-overlay', id);
|
|
260
298
|
if (options?.persist === false) {
|
|
261
299
|
return;
|
|
262
300
|
}
|
|
263
301
|
try {
|
|
264
302
|
window.localStorage.setItem(PRELOAD_OVERLAY_KEY, id);
|
|
303
|
+
// The CSS is a few KB; skip the synchronous write when the stored entry already matches
|
|
304
|
+
// (a re-apply of the same brand), so repeated applies cost nothing.
|
|
305
|
+
const entry = JSON.stringify({ id, css: this.brandCss.get(id) ?? '' });
|
|
306
|
+
if (window.localStorage.getItem(PRELOAD_OVERLAY_CSS_KEY) !== entry) {
|
|
307
|
+
window.localStorage.setItem(PRELOAD_OVERLAY_CSS_KEY, entry);
|
|
308
|
+
}
|
|
265
309
|
}
|
|
266
310
|
catch (e) {
|
|
267
311
|
// non-fatal: a brief brand flash on next reload at worst
|
|
268
312
|
}
|
|
269
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Put the persisted org brand overlay back BEFORE first paint, from localStorage alone —
|
|
316
|
+
* no registry, no database. Call it from the earliest code that runs in the app (the
|
|
317
|
+
* explorer-app constructor), so the sign-in page and the shell's loading screen paint
|
|
318
|
+
* branded on a cold load instead of waiting for bootstrap to re-emit the overlay.
|
|
319
|
+
*
|
|
320
|
+
* Injects the persisted CSS as a `<style>` (bootstrap's real `<link>` replaces it), sets
|
|
321
|
+
* `data-theme-overlay`, and records the id so {@link Initialize} does not strip the
|
|
322
|
+
* attribute before bootstrap registers the brand. A CSS entry whose id no longer matches
|
|
323
|
+
* the persisted overlay id is stale and is dropped. Returns whether anything was restored.
|
|
324
|
+
*/
|
|
325
|
+
RestorePersistedBrandOverlay() {
|
|
326
|
+
let id = null;
|
|
327
|
+
let entry = null;
|
|
328
|
+
try {
|
|
329
|
+
id = window.localStorage.getItem(PRELOAD_OVERLAY_KEY);
|
|
330
|
+
const raw = window.localStorage.getItem(PRELOAD_OVERLAY_CSS_KEY);
|
|
331
|
+
entry = raw ? JSON.parse(raw) : null;
|
|
332
|
+
}
|
|
333
|
+
catch (e) {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
if (!id || !entry) {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
if (entry.id !== id || typeof entry.css !== 'string') {
|
|
340
|
+
try {
|
|
341
|
+
window.localStorage.removeItem(PRELOAD_OVERLAY_CSS_KEY);
|
|
342
|
+
}
|
|
343
|
+
catch (e) {
|
|
344
|
+
// non-fatal
|
|
345
|
+
}
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
const existing = this.findPreloadStyle(id);
|
|
349
|
+
if (existing) {
|
|
350
|
+
// A host's inline snippet already injected it. Re-append so it follows every
|
|
351
|
+
// stylesheet that arrived after it (the app's own, above all): the overlay's
|
|
352
|
+
// selectors tie the compiled :root tokens on specificity, so order decides.
|
|
353
|
+
document.head.appendChild(existing);
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
const style = document.createElement('style');
|
|
357
|
+
style.setAttribute(PRELOAD_STYLE_ATTR, id);
|
|
358
|
+
style.textContent = entry.css;
|
|
359
|
+
document.head.appendChild(style);
|
|
360
|
+
}
|
|
361
|
+
document.documentElement.setAttribute('data-theme-overlay', id);
|
|
362
|
+
this._brandOverlayId = id;
|
|
363
|
+
this.pendingOverlayId = id;
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* The restored preload `<style>` for this overlay id, if one is in the document (ours or the
|
|
368
|
+
* host's inline snippet). An attribute walk rather than an interpolated selector: the id
|
|
369
|
+
* comes from localStorage, and a quote or bracket in it would make `querySelector` throw —
|
|
370
|
+
* from the explorer-app constructor.
|
|
371
|
+
*/
|
|
372
|
+
findPreloadStyle(id) {
|
|
373
|
+
const styles = document.head.querySelectorAll(`style[${PRELOAD_STYLE_ATTR}]`);
|
|
374
|
+
for (const el of Array.from(styles)) {
|
|
375
|
+
if (el.getAttribute(PRELOAD_STYLE_ATTR) === id) {
|
|
376
|
+
return el;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
/** Drop every restored preload `<style>` (a real stylesheet has taken over, or the brand was cleared). */
|
|
382
|
+
removePreloadStyles() {
|
|
383
|
+
document.head.querySelectorAll(`style[${PRELOAD_STYLE_ATTR}]`).forEach((el) => el.remove());
|
|
384
|
+
}
|
|
270
385
|
/**
|
|
271
386
|
* Remove the active org brand overlay (revert to the base MJ tokens).
|
|
387
|
+
*
|
|
388
|
+
* Scoped to the brand: only the brand's own `<link>` is disabled and the `data-theme-overlay`
|
|
389
|
+
* attribute is dropped only when it still names that brand. Bootstrap calls this on every login
|
|
390
|
+
* where the org has no active brand, right after `Initialize()` applied the user's theme, so a
|
|
391
|
+
* blanket clear would switch off a user's custom theme on any install that never used Theme Studio.
|
|
272
392
|
*/
|
|
273
393
|
ClearBrandOverlay() {
|
|
394
|
+
const brandId = this._brandOverlayId;
|
|
274
395
|
this._brandOverlayId = null;
|
|
275
|
-
|
|
276
|
-
|
|
396
|
+
this.pendingOverlayId = null;
|
|
397
|
+
if (brandId !== null) {
|
|
398
|
+
if (document.documentElement.getAttribute('data-theme-overlay') === brandId) {
|
|
399
|
+
document.documentElement.removeAttribute('data-theme-overlay');
|
|
400
|
+
}
|
|
401
|
+
const brandLink = this.loadedCssLinks.get(brandId);
|
|
402
|
+
if (brandLink) {
|
|
403
|
+
brandLink.disabled = true;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
this.removePreloadStyles();
|
|
277
407
|
try {
|
|
278
408
|
window.localStorage.removeItem(PRELOAD_OVERLAY_KEY);
|
|
409
|
+
window.localStorage.removeItem(PRELOAD_OVERLAY_CSS_KEY);
|
|
279
410
|
}
|
|
280
411
|
catch (e) {
|
|
281
412
|
// non-fatal
|
|
@@ -294,12 +425,28 @@ export class ThemeService {
|
|
|
294
425
|
}
|
|
295
426
|
this.setupSystemThemeListener();
|
|
296
427
|
this._starred$.next(this.loadStarredIds());
|
|
428
|
+
// A saved preference wins; without one the host's default theme (IsDefault), else 'system'.
|
|
297
429
|
const savedPreference = await this.loadSetting();
|
|
298
|
-
this.
|
|
299
|
-
|
|
430
|
+
const preference = savedPreference ?? this.DefaultPreference;
|
|
431
|
+
this._preference$.next(preference);
|
|
432
|
+
const resolvedThemeId = this.resolveTheme(preference);
|
|
300
433
|
await this.applyTheme(resolvedThemeId);
|
|
301
434
|
this._initialized = true;
|
|
302
435
|
}
|
|
436
|
+
/**
|
|
437
|
+
* What {@link Initialize} applies when nothing is saved: the first theme REGISTERED with
|
|
438
|
+
* {@link ThemeDefinition.IsDefault} (registration order, not registry slot order — re-registering
|
|
439
|
+
* a built-in slot with the flag does not jump the queue), else `'system'`. Public so a picker
|
|
440
|
+
* can mark the default.
|
|
441
|
+
*/
|
|
442
|
+
get DefaultPreference() {
|
|
443
|
+
for (const id of this.defaultCandidates) {
|
|
444
|
+
if (this.themeRegistry.get(id)?.IsDefault) {
|
|
445
|
+
return id;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return 'system';
|
|
449
|
+
}
|
|
303
450
|
/**
|
|
304
451
|
* Set the theme preference and apply it.
|
|
305
452
|
* @param preference - A registered theme ID or 'system'
|
|
@@ -322,7 +469,9 @@ export class ThemeService {
|
|
|
322
469
|
}
|
|
323
470
|
this.systemMediaQuery = null;
|
|
324
471
|
this.boundSystemThemeHandler = null;
|
|
325
|
-
|
|
472
|
+
// "Nothing chosen" is the host's default, not literally 'system': a reader of Preference in
|
|
473
|
+
// the logged-out window (a sign-in page toggle) should see the same answer Initialize() will.
|
|
474
|
+
this._preference$.next(this.DefaultPreference);
|
|
326
475
|
this._appliedTheme$.next('light');
|
|
327
476
|
this._initialized = false;
|
|
328
477
|
// Remove the base-theme attribute only. We deliberately KEEP the org brand
|
|
@@ -369,6 +518,12 @@ export class ThemeService {
|
|
|
369
518
|
await this.loadThemeCss(brandDef);
|
|
370
519
|
document.documentElement.setAttribute('data-theme-overlay', this._brandOverlayId);
|
|
371
520
|
}
|
|
521
|
+
else if (this.pendingOverlayId === this._brandOverlayId) {
|
|
522
|
+
// Restored from localStorage and not yet confirmed or cleared by bootstrap: keep
|
|
523
|
+
// the attribute so the preloaded CSS stays matched until the real overlay lands.
|
|
524
|
+
document.documentElement.setAttribute('data-theme-overlay', this._brandOverlayId);
|
|
525
|
+
this.disableAllCustomCss();
|
|
526
|
+
}
|
|
372
527
|
else {
|
|
373
528
|
document.documentElement.removeAttribute('data-theme-overlay');
|
|
374
529
|
this.disableAllCustomCss();
|
|
@@ -595,27 +750,27 @@ export class ThemeService {
|
|
|
595
750
|
// PERSISTENCE
|
|
596
751
|
// ========================================
|
|
597
752
|
/**
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
753
|
+
* The user's saved preference ('system' or a registered theme ID), or `null` when there is
|
|
754
|
+
* none to honor — nothing saved, a saved theme that is no longer registered, or a failed
|
|
755
|
+
* read. The caller decides what `null` means (see {@link DefaultPreference}).
|
|
601
756
|
*/
|
|
602
757
|
async loadSetting() {
|
|
603
758
|
try {
|
|
604
759
|
const engine = UserInfoEngine.Instance;
|
|
605
760
|
const settingValue = engine.GetSetting(THEME_SETTING_KEY);
|
|
606
761
|
if (!settingValue) {
|
|
607
|
-
return
|
|
762
|
+
return null;
|
|
608
763
|
}
|
|
609
764
|
// Accept 'system' or any registered theme ID
|
|
610
765
|
if (settingValue === 'system' || this.themeRegistry.has(settingValue)) {
|
|
611
766
|
return settingValue;
|
|
612
767
|
}
|
|
613
|
-
// Saved theme no longer registered —
|
|
614
|
-
return
|
|
768
|
+
// Saved theme no longer registered — nothing to honor
|
|
769
|
+
return null;
|
|
615
770
|
}
|
|
616
771
|
catch (error) {
|
|
617
772
|
console.warn('Failed to load theme setting:', error);
|
|
618
|
-
return
|
|
773
|
+
return null;
|
|
619
774
|
}
|
|
620
775
|
}
|
|
621
776
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.service.js","sourceRoot":"","sources":["../../src/lib/theme.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAc,OAAO,EAAE,MAAM,MAAM,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAgB,kBAAkB,EAAE,cAAc,EAA0B,MAAM,8BAA8B,CAAC;;AA8BhI;;GAEG;AACH,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAM,sBAAsB,GAAG,UAAU,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAE/C,uFAAuF;AACvF,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;AAEpD,+FAA+F;AAC/F,MAAM,kBAAkB,GAAG,6BAA6B,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,GAAoB;IACjC,EAAE,EAAE,OAAO;IACX,IAAI,EAAE,OAAO;IACb,SAAS,EAAE,OAAO;IAClB,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,qBAAqB;CACrC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,GAAoB;IAChC,EAAE,EAAE,MAAM;IAC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AAK,CAAC,CAAC;YACrD,OAAO,QAAQ,CAAC;QACpB,CAAC;IACL,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,WAAW,CAAC,UAAkB;QACxC,IAAI,CAAC;YACD,MAAM,MAAM,GAAG,cAAc,CAAC,QAAQ,CAAC;YACvC,MAAM,MAAM,CAAC,UAAU,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;QAC3D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;QACzD,CAAC;IACL,CAAC;sGA1nBQ,YAAY;gEAAZ,YAAY,WAAZ,YAAY,mBADC,MAAM;;iFACnB,YAAY;cADxB,UAAU;eAAC,EAAE,UAAU,EAAE,MAAM,EAAE","sourcesContent":["import { Injectable } from '@angular/core';\nimport { BehaviorSubject, Observable, Subject } from 'rxjs';\nimport { UserInfoEngine } from '@memberjunction/core-entities';\nimport { derive, DerivedTheme, emitLogoOverlayCss, emitOverlayCss, ThemeLogos, ThemeSeeds } from '@memberjunction/theme-engine';\n\n/**\n * Defines a theme available in the application.\n * Built-in themes (light/dark) have no CssUrl.\n * Custom themes specify a BaseTheme to inherit from and a CssUrl with overrides.\n */\nexport interface ThemeDefinition {\n /** Unique identifier (e.g. 'light', 'dark', 'izzy-dark') */\n Id: string;\n /** Human-readable display name (e.g. 'Light', 'Dark', 'Izzy Dark') */\n Name: string;\n /** Which built-in theme this inherits from */\n BaseTheme: 'light' | 'dark';\n /** URL to the CSS file with token overrides (omit for built-in themes) */\n CssUrl?: string;\n /**\n * Derived --mj-* token overrides. Populated for brand themes emitted\n * from seeds; an alternative/companion to CssUrl for token-based application and\n * for feeding the Theme Builder preview without a round-trip through CSS.\n */\n Tokens?: Record<string, string>;\n /** Whether this is a built-in theme (light/dark) */\n IsBuiltIn: boolean;\n /** Optional description shown in theme picker */\n Description?: string;\n /** Optional preview swatch colors for a future theme picker UI */\n PreviewColors?: string[];\n}\n\n/**\n * Setting key for theme preference in MJ: User Settings entity\n */\nconst THEME_SETTING_KEY = 'Explorer.Theme';\n\n/**\n * localStorage key the inline theme-preload script reads on first paint\n * (before Angular boots) to apply the correct theme without flashing.\n *\n * The value is the **base theme** ('dark' or 'light'), NOT the full theme\n * preference (which can be 'system' or a custom theme ID like 'izzy-dark').\n * The preload script needs an unambiguous answer: should I set\n * data-theme=\"dark\" or not? Storing the base theme is the simplest\n * contract: the script does `if (value === 'dark') setAttribute(...)`.\n *\n * Mirrored by ThemeService whenever the applied base theme changes,\n * cleared on logout via Reset().\n */\nconst PRELOAD_BASE_THEME_KEY = 'mj-theme';\n\n/**\n * localStorage key holding the active org **brand overlay** id, mirrored so the\n * inline pre-paint script can restore `data-theme-overlay` on first paint (the org\n * brand persists across the user's light/dark choice AND across logout). The overlay\n * CSS itself is a session-scoped Blob re-emitted at login bootstrap, so this key only\n * restores the attribute — brand colors repaint once bootstrap re-injects the CSS.\n */\nconst PRELOAD_OVERLAY_KEY = 'mj-theme-overlay';\n\n/** User-settings key: JSON array of the user's starred (favorited) brand theme ids. */\nconst STARRED_THEMES_KEY = 'Explorer.StarredThemes';\n\n/** User-settings key: the brand theme id the user last applied (restored over org default). */\nconst SELECTED_BRAND_KEY = 'Explorer.SelectedBrandTheme';\n\n/**\n * Built-in light theme definition\n */\nconst LIGHT_THEME: ThemeDefinition = {\n Id: 'light',\n Name: 'Light',\n BaseTheme: 'light',\n IsBuiltIn: true,\n Description: 'Default light theme'\n};\n\n/**\n * Built-in dark theme definition\n */\nconst DARK_THEME: ThemeDefinition = {\n Id: 'dark',\n Name: 'Dark',\n BaseTheme: 'dark',\n IsBuiltIn: true,\n Description: 'Default dark theme'\n};\n\n/**\n * Service to manage application themes with pluggable custom theme support.\n *\n * Built-in themes (light/dark) work identically to before. Custom themes\n * inherit from a base theme and overlay additional CSS token overrides via\n * a dynamically loaded stylesheet.\n *\n * CSS resolution for custom themes (e.g. \"Izzy Dark\" extending dark):\n * 1. `:root` light defaults (from _tokens.scss in this package)\n * 2. `[data-theme=\"dark\"]` dark overrides (from _tokens.scss in this package)\n * 3. `[data-theme-overlay=\"izzy-dark\"]` custom overrides (loaded dynamically)\n *\n * Follows the DeveloperModeService pattern:\n * - Settings persisted via UserInfoEngine\n * - BehaviorSubject for reactive state\n * - Initialize after login, Reset on logout\n */\n@Injectable({ providedIn: 'root' })\nexport class ThemeService {\n private _preference$ = new BehaviorSubject<string>('system');\n private _appliedTheme$ = new BehaviorSubject<string>('light');\n /**\n * The active org brand overlay id, applied independently of the user's light/dark\n * choice and preserved across Reset()/logout.\n */\n private _brandOverlayId: string | null = null;\n /** The user's starred (favorited) brand theme ids, reactive for menus/badges. */\n private _starred$ = new BehaviorSubject<string[]>([]);\n /** Emits when the set of saved themes changes (create/rename/delete/duplicate/default)\n * so open dashboards (Theme Studio, Manage Themes) refresh without a page reload. */\n private _themesChanged$ = new Subject<void>();\n private _initialized = false;\n private systemMediaQuery: MediaQueryList | null = null;\n private boundSystemThemeHandler: (() => void) | null = null;\n\n /** Registry of USER-SELECTABLE themes (shown in the theme picker), seeded with light + dark. */\n private themeRegistry = new Map<string, ThemeDefinition>([\n ['light', LIGHT_THEME],\n ['dark', DARK_THEME]\n ]);\n\n /**\n * Registry of ORG BRAND overlays (from RegisterBrandTheme). Kept separate from\n * themeRegistry so brand overlays do NOT appear in the user's light/dark theme\n * picker — the org brand is applied independently of the user's mode (decision #1).\n */\n private brandRegistry = new Map<string, ThemeDefinition>();\n\n /** Cache of loaded <link> elements by theme ID to avoid re-downloading */\n private loadedCssLinks = new Map<string, HTMLLinkElement>();\n\n /** Session-scoped Blob object URLs for brand overlays, keyed by theme ID (for revocation on re-register). */\n private brandBlobUrls = new Map<string, string>();\n\n /**\n * Observable for user's theme preference (theme ID or 'system')\n */\n public get Preference$(): Observable<string> {\n return this._preference$.asObservable();\n }\n\n /**\n * Observable for the actually applied theme (resolved theme ID)\n */\n public get AppliedTheme$(): Observable<string> {\n return this._appliedTheme$.asObservable();\n }\n\n /**\n * Current theme preference (synchronous access)\n */\n public get Preference(): string {\n return this._preference$.value;\n }\n\n /**\n * Currently applied theme ID (synchronous access)\n */\n public get AppliedTheme(): string {\n return this._appliedTheme$.value;\n }\n\n /**\n * Whether the service has been initialized\n */\n public get IsInitialized(): boolean {\n return this._initialized;\n }\n\n /**\n * All registered themes, for UI consumption (e.g. theme picker menus)\n */\n public get AvailableThemes(): ThemeDefinition[] {\n return Array.from(this.themeRegistry.values());\n }\n\n /**\n * Look up a theme definition by ID.\n * Returns undefined if the theme ID is not registered.\n */\n public GetThemeDefinition(id: string): ThemeDefinition | undefined {\n return this.themeRegistry.get(id);\n }\n\n // ========================================\n // THEME REGISTRATION\n // ========================================\n\n /**\n * Register a custom theme. If a theme with the same ID already exists,\n * it is replaced (allowing override of built-in themes if desired).\n */\n public RegisterTheme(theme: ThemeDefinition): void {\n this.themeRegistry.set(theme.Id, theme);\n }\n\n /**\n * Register multiple custom themes at once.\n */\n public RegisterThemes(themes: ThemeDefinition[]): void {\n for (const theme of themes) {\n this.RegisterTheme(theme);\n }\n }\n\n /**\n * Register a brand theme from its seeds.\n *\n * Derives the full --mj-* token contract with @memberjunction/theme-engine, emits\n * the `[data-theme-overlay=\"<id>\"]` CSS, and publishes it as a session-scoped Blob\n * URL that plugs into the existing CssUrl overlay path — so brand themes apply\n * through the same machinery as file-based custom themes. Returns the derived\n * theme so callers can surface the a11y contrast report / previews.\n *\n * The emitted overlay overrides only the primitive ramps (plus viz/shadow/font/\n * radius); every semantic token and the `[data-theme=\"dark\"]` block reference those\n * primitives, so both light and dark re-point automatically off one block.\n *\n * @param params.seeds ThemeSeeds object or the entity's Seeds JSON string.\n */\n public RegisterBrandTheme(params: {\n id: string;\n name: string;\n seeds: ThemeSeeds | string;\n description?: string;\n baseTheme?: 'light' | 'dark';\n /** Optional logo variant URLs + geometry, emitted as --mj-logo-*. */\n logos?: ThemeLogos;\n /** Advanced: per-token overrides (JSON map or object) merged over the derived vars. */\n overrides?: Record<string, string> | string | null;\n /** Advanced: raw CSS appended to the overlay, auto-scoped to this theme. */\n customCss?: string | null;\n }): DerivedTheme {\n const seeds = typeof params.seeds === 'string' ? (JSON.parse(params.seeds) as ThemeSeeds) : params.seeds;\n const derived = derive(seeds);\n const overrides = this.parseOverrides(params.overrides);\n // One Blob carries the whole brand: color/shape/font overlay (+ advanced layer) + logo tokens.\n const css = emitOverlayCss(params.id, derived, { overrides, customCss: params.customCss })\n + (params.logos ? emitLogoOverlayCss(params.id, params.logos) : '');\n\n // Replace any prior Blob URL + cached <link> for this id so a re-registration\n // (e.g. live preview) loads the new CSS instead of re-enabling stale bytes.\n const priorUrl = this.brandBlobUrls.get(params.id);\n if (priorUrl) {\n URL.revokeObjectURL(priorUrl);\n }\n const cachedLink = this.loadedCssLinks.get(params.id);\n if (cachedLink) {\n cachedLink.remove();\n this.loadedCssLinks.delete(params.id);\n }\n\n const url = URL.createObjectURL(new Blob([css], { type: 'text/css' }));\n this.brandBlobUrls.set(params.id, url);\n\n // Register into the brand registry only — NOT themeRegistry — so the org brand\n // does not surface as a user-selectable option in the theme picker.\n this.brandRegistry.set(params.id, {\n Id: params.id,\n Name: params.name,\n BaseTheme: params.baseTheme ?? 'light',\n CssUrl: url,\n Tokens: derived.overlayVars,\n IsBuiltIn: false,\n Description: params.description,\n PreviewColors: [\n derived.tokens.light['--mj-brand-primary'],\n derived.tokens.light['--mj-brand-accent'],\n derived.tokens.light['--mj-brand-tertiary'],\n ],\n });\n\n return derived;\n }\n\n /** Normalize the advanced overrides input (JSON string, object, or null) to a token map. */\n private parseOverrides(input?: Record<string, string> | string | null): Record<string, string> | undefined {\n if (!input) return undefined;\n if (typeof input === 'string') {\n try {\n const parsed = JSON.parse(input);\n return parsed && typeof parsed === 'object' ? (parsed as Record<string, string>) : undefined;\n } catch {\n return undefined;\n }\n }\n return input;\n }\n\n /**\n * The active org brand overlay id, or null if none is applied.\n */\n public get BrandOverlayId(): string | null {\n return this._brandOverlayId;\n }\n\n /**\n * Apply an org brand overlay **independently of the user's light/dark mode.\n * The overlay layers under whatever base theme is\n * active and is re-asserted whenever the user toggles light/dark. Persists the id\n * to localStorage so the pre-paint script restores the attribute on next load.\n *\n * @param id id of a brand theme registered via {@link RegisterBrandTheme}.\n * @param options.persist pass `false` for session-only overlays backed by Blob URLs\n * (e.g. Theme Studio's draft workspace preview) — a Blob URL doesn't survive a\n * reload, so persisting its id would leave the pre-paint script pointing at a\n * dangling overlay and clobber the user's real persisted selection. Defaults true.\n */\n public async ApplyBrandOverlay(id: string, options?: { persist?: boolean }): Promise<void> {\n const def = this.brandRegistry.get(id);\n if (!def || !def.CssUrl) {\n console.warn(`ApplyBrandOverlay: no registered brand theme \"${id}\" with CSS.`);\n return;\n }\n this._brandOverlayId = id;\n await this.loadThemeCss(def);\n document.documentElement.setAttribute('data-theme-overlay', id);\n if (options?.persist === false) {\n return;\n }\n try {\n window.localStorage.setItem(PRELOAD_OVERLAY_KEY, id);\n } catch (e) {\n // non-fatal: a brief brand flash on next reload at worst\n }\n }\n\n /**\n * Remove the active org brand overlay (revert to the base MJ tokens).\n */\n public ClearBrandOverlay(): void {\n this._brandOverlayId = null;\n document.documentElement.removeAttribute('data-theme-overlay');\n this.disableAllCustomCss();\n try {\n window.localStorage.removeItem(PRELOAD_OVERLAY_KEY);\n } catch (e) {\n // non-fatal\n }\n }\n\n // ========================================\n // LIFECYCLE\n // ========================================\n\n /**\n * Initialize the theme service.\n * Call after login when UserInfoEngine is available.\n */\n public async Initialize(): Promise<void> {\n if (this._initialized) {\n return;\n }\n\n this.setupSystemThemeListener();\n\n this._starred$.next(this.loadStarredIds());\n\n const savedPreference = await this.loadSetting();\n this._preference$.next(savedPreference);\n\n const resolvedThemeId = this.resolveTheme(savedPreference);\n await this.applyTheme(resolvedThemeId);\n\n this._initialized = true;\n }\n\n /**\n * Set the theme preference and apply it.\n * @param preference - A registered theme ID or 'system'\n */\n public async SetTheme(preference: string): Promise<void> {\n if (preference === this._preference$.value) {\n return;\n }\n\n this._preference$.next(preference);\n\n const resolvedThemeId = this.resolveTheme(preference);\n await this.applyTheme(resolvedThemeId);\n\n await this.saveSetting(preference);\n }\n\n /**\n * Reset the service (call on logout)\n */\n public Reset(): void {\n if (this.systemMediaQuery && this.boundSystemThemeHandler) {\n this.systemMediaQuery.removeEventListener('change', this.boundSystemThemeHandler);\n }\n this.systemMediaQuery = null;\n this.boundSystemThemeHandler = null;\n\n this._preference$.next('system');\n this._appliedTheme$.next('light');\n this._initialized = false;\n\n // Remove the base-theme attribute only. We deliberately KEEP the org brand\n // overlay (data-theme-overlay + its CSS + _brandOverlayId) so the brand\n // survives logout and stays on the login screen.\n // The overlay is re-emitted at the next login bootstrap.\n document.documentElement.removeAttribute('data-theme');\n\n // NOTE: we deliberately do NOT clear PRELOAD_BASE_THEME_KEY here.\n // The unified theme key ('mj-theme') is the single source of truth\n // shared with the login-screen toggle and the inline pre-paint script.\n // Clearing it on logout would force the login screen back to OS\n // default and cause a theme flash for the post-logout/pre-login\n // window. The auth provider's clearClientCaches() preserves it for\n // exactly this reason (see preservedLocalStorageKeys).\n\n // Disable custom CSS links EXCEPT the active org brand overlay, which must\n // survive logout so the brand persists on the login screen.\n this.disableAllCustomCss(this._brandOverlayId);\n }\n\n // ========================================\n // THEME APPLICATION\n // ========================================\n\n /**\n * Apply a resolved theme ID to the DOM.\n * Sets `data-theme` based on BaseTheme and `data-theme-overlay` for custom themes.\n * Loads custom CSS if needed, disables previous custom CSS.\n */\n private async applyTheme(themeId: string): Promise<void> {\n const themeDef = this.themeRegistry.get(themeId);\n\n // Fall back to 'light' if the theme ID isn't recognized\n if (!themeDef) {\n this.applyBuiltInTheme('light');\n this._appliedTheme$.next('light');\n return;\n }\n\n // Set the base theme attribute (drives existing [data-theme=\"dark\"] selectors)\n this.applyBaseThemeAttribute(themeDef.BaseTheme);\n\n if (themeDef.IsBuiltIn) {\n // Built-in (light/dark): the user's mode changes, but the org brand overlay\n // stays layered under it. Re-assert the brand overlay if one is active;\n // otherwise clear any overlay.\n if (this._brandOverlayId) {\n const brandDef = this.brandRegistry.get(this._brandOverlayId);\n if (brandDef?.CssUrl) {\n await this.loadThemeCss(brandDef);\n document.documentElement.setAttribute('data-theme-overlay', this._brandOverlayId);\n } else {\n document.documentElement.removeAttribute('data-theme-overlay');\n this.disableAllCustomCss();\n }\n } else {\n document.documentElement.removeAttribute('data-theme-overlay');\n this.disableAllCustomCss();\n }\n } else if (themeDef.CssUrl) {\n // Explicit custom theme selected — its overlay overrides any brand overlay.\n await this.loadThemeCss(themeDef);\n document.documentElement.setAttribute('data-theme-overlay', themeDef.Id);\n }\n\n this._appliedTheme$.next(themeId);\n }\n\n /**\n * Apply the base theme attribute to <html>.\n * 'dark' sets data-theme=\"dark\"; 'light' removes it (matching existing convention).\n *\n * Also mirrors the base theme to localStorage under PRELOAD_BASE_THEME_KEY\n * so the inline pre-bootstrap theme-preload script in index.html can apply\n * the correct theme on first paint of the next page load — eliminating\n * the brief light-mode flash dark-mode users would otherwise see.\n */\n private applyBaseThemeAttribute(baseTheme: 'light' | 'dark'): void {\n if (baseTheme === 'dark') {\n document.documentElement.setAttribute('data-theme', 'dark');\n } else {\n document.documentElement.removeAttribute('data-theme');\n }\n try {\n window.localStorage.setItem(PRELOAD_BASE_THEME_KEY, baseTheme);\n } catch (e) {\n // localStorage exceptions (private mode, quota) are non-fatal here —\n // the app still works, the user just may see a brief theme flash on\n // their next reload.\n }\n }\n\n /**\n * Shorthand for built-in theme application (no custom CSS)\n */\n private applyBuiltInTheme(baseTheme: 'light' | 'dark'): void {\n this.applyBaseThemeAttribute(baseTheme);\n document.documentElement.removeAttribute('data-theme-overlay');\n this.disableAllCustomCss();\n }\n\n // ========================================\n // DYNAMIC CSS LOADING\n // ========================================\n\n /**\n * Load (or re-enable) a custom theme's CSS file.\n * Injects a <link> element into <head> with a data-mj-theme attribute.\n * Caches the link element to avoid re-downloading on theme switches.\n * Returns a Promise that resolves once the stylesheet is loaded.\n */\n private loadThemeCss(theme: ThemeDefinition): Promise<void> {\n if (!theme.CssUrl) {\n return Promise.resolve();\n }\n\n // Disable all other custom CSS first\n this.disableAllCustomCss();\n\n // Check cache — if already loaded, just re-enable\n const existingLink = this.loadedCssLinks.get(theme.Id);\n if (existingLink) {\n existingLink.disabled = false;\n return Promise.resolve();\n }\n\n // Create and inject new <link> element\n return new Promise<void>((resolve, reject) => {\n const link = document.createElement('link');\n link.rel = 'stylesheet';\n link.href = theme.CssUrl!;\n link.setAttribute('data-mj-theme', theme.Id);\n\n link.onload = () => resolve();\n link.onerror = () => {\n console.warn(`Failed to load theme CSS: ${theme.CssUrl}`);\n // Still resolve so the theme switch isn't blocked\n resolve();\n };\n\n document.head.appendChild(link);\n this.loadedCssLinks.set(theme.Id, link);\n });\n }\n\n /**\n * Disable (not remove) custom theme CSS <link> elements.\n * Disabling rather than removing avoids re-downloading when switching back.\n * @param keepId optional theme id to leave enabled (e.g. the active brand overlay).\n */\n private disableAllCustomCss(keepId?: string | null): void {\n for (const [id, link] of this.loadedCssLinks.entries()) {\n if (keepId && id === keepId) {\n continue;\n }\n link.disabled = true;\n }\n }\n\n // ========================================\n // THEME RESOLUTION\n // ========================================\n\n /**\n * Resolve a preference string to an actual theme ID.\n * 'system' resolves to 'light' or 'dark' based on OS preference.\n * Unrecognized IDs fall back to 'light'.\n */\n private resolveTheme(preference: string): string {\n if (preference === 'system') {\n return this.getSystemTheme();\n }\n\n // If the preference is a registered theme, use it directly\n if (this.themeRegistry.has(preference)) {\n return preference;\n }\n\n // Unrecognized theme ID — fall back to light\n return 'light';\n }\n\n /**\n * Get system theme preference from OS\n */\n private getSystemTheme(): 'light' | 'dark' {\n if (typeof window === 'undefined') {\n return 'light';\n }\n return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\n }\n\n /**\n * Setup listener for system theme changes\n */\n private setupSystemThemeListener(): void {\n if (typeof window === 'undefined') {\n return;\n }\n\n this.systemMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');\n this.boundSystemThemeHandler = () => this.onSystemThemeChange();\n this.systemMediaQuery.addEventListener('change', this.boundSystemThemeHandler);\n }\n\n /**\n * Handle system theme change (only applies if in 'system' mode)\n */\n private async onSystemThemeChange(): Promise<void> {\n if (this._preference$.value === 'system') {\n const newThemeId = this.getSystemTheme();\n await this.applyTheme(newThemeId);\n }\n }\n\n // ========================================\n // STARRED (FAVORITE) BRAND THEMES\n // ========================================\n\n /** Reactive list of the user's starred brand theme ids. */\n public get Starred$(): Observable<string[]> {\n return this._starred$.asObservable();\n }\n\n /** Emits after any saved-theme mutation so open dashboards can refresh their lists. */\n public get ThemesChanged$(): Observable<void> {\n return this._themesChanged$.asObservable();\n }\n\n /** Broadcast that the set of saved themes changed (create/rename/delete/duplicate/default). */\n public NotifyThemesChanged(): void {\n this._themesChanged$.next();\n }\n\n /** The user's starred brand theme ids (synchronous). */\n public GetStarredThemeIds(): string[] {\n return this._starred$.value;\n }\n\n /** Whether a theme id is starred by the user. */\n public IsStarred(id: string): boolean {\n return this._starred$.value.includes(id);\n }\n\n /**\n * Toggle a theme's starred state and persist to User Settings.\n * @returns the new starred state (true = now starred).\n */\n public async ToggleStar(id: string): Promise<boolean> {\n const set = new Set(this._starred$.value);\n const nowStarred = !set.has(id);\n if (nowStarred) {\n set.add(id);\n } else {\n set.delete(id);\n }\n const ids = Array.from(set);\n this._starred$.next(ids);\n try {\n await UserInfoEngine.Instance.SetSetting(STARRED_THEMES_KEY, JSON.stringify(ids));\n } catch (error) {\n console.warn('Failed to save starred themes:', error);\n }\n return nowStarred;\n }\n\n private loadStarredIds(): string[] {\n try {\n const raw = UserInfoEngine.Instance.GetSetting(STARRED_THEMES_KEY);\n const parsed = raw ? JSON.parse(raw) : [];\n return Array.isArray(parsed) ? parsed.filter((x) => typeof x === 'string') : [];\n } catch {\n return [];\n }\n }\n\n /** The brand theme the user last applied (or null to follow the org default). */\n public GetSelectedBrandThemeId(): string | null {\n try {\n return UserInfoEngine.Instance.GetSetting(SELECTED_BRAND_KEY) || null;\n } catch {\n return null;\n }\n }\n\n /** Persist (or clear, with null) the user's chosen brand theme so login restores it. */\n public async SetSelectedBrandTheme(id: string | null): Promise<void> {\n try {\n await UserInfoEngine.Instance.SetSetting(SELECTED_BRAND_KEY, id ?? '');\n } catch (error) {\n console.warn('Failed to save selected brand theme:', error);\n }\n }\n\n // ========================================\n // PERSISTENCE\n // ========================================\n\n /**\n * Load theme preference from User Settings.\n * Accepts any registered theme ID or 'system'.\n * Falls back to 'system' if saved value is not recognized.\n */\n private async loadSetting(): Promise<string> {\n try {\n const engine = UserInfoEngine.Instance;\n const settingValue = engine.GetSetting(THEME_SETTING_KEY);\n\n if (!settingValue) {\n return 'system';\n }\n\n // Accept 'system' or any registered theme ID\n if (settingValue === 'system' || this.themeRegistry.has(settingValue)) {\n return settingValue;\n }\n\n // Saved theme no longer registered — fall back\n return 'system';\n } catch (error) {\n console.warn('Failed to load theme setting:', error);\n return 'system';\n }\n }\n\n /**\n * Save theme preference to User Settings\n */\n private async saveSetting(preference: string): Promise<void> {\n try {\n const engine = UserInfoEngine.Instance;\n await engine.SetSetting(THEME_SETTING_KEY, preference);\n } catch (error) {\n console.warn('Failed to save theme setting:', error);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"theme.service.js","sourceRoot":"","sources":["../../src/lib/theme.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAc,OAAO,EAAE,MAAM,MAAM,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAgB,kBAAkB,EAAE,cAAc,EAA0B,MAAM,8BAA8B,CAAC;;AA6ChI;;GAEG;AACH,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAM,sBAAsB,GAAG,UAAU,CAAC;AAE1C;;;;;;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B,CAAC;IACL,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,WAAW,CAAC,UAAkB;QACxC,IAAI,CAAC;YACD,MAAM,MAAM,GAAG,cAAc,CAAC,QAAQ,CAAC;YACvC,MAAM,MAAM,CAAC,UAAU,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;QAC3D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;QACzD,CAAC;IACL,CAAC;sGA5wBQ,YAAY;gEAAZ,YAAY,WAAZ,YAAY,mBADC,MAAM;;iFACnB,YAAY;cADxB,UAAU;eAAC,EAAE,UAAU,EAAE,MAAM,EAAE","sourcesContent":["import { Injectable } from '@angular/core';\nimport { BehaviorSubject, Observable, Subject } from 'rxjs';\nimport { UserInfoEngine } from '@memberjunction/core-entities';\nimport { derive, DerivedTheme, emitLogoOverlayCss, emitOverlayCss, ThemeLogos, ThemeSeeds } from '@memberjunction/theme-engine';\n\n/**\n * Defines a theme available in the application.\n * Built-in themes (light/dark) have no CssUrl.\n * Custom themes specify a BaseTheme to inherit from and a CssUrl with overrides.\n */\nexport interface ThemeDefinition {\n /** Unique identifier (e.g. 'light', 'dark', 'izzy-dark') */\n Id: string;\n /** Human-readable display name (e.g. 'Light', 'Dark', 'Izzy Dark') */\n Name: string;\n /** Which built-in theme this inherits from */\n BaseTheme: 'light' | 'dark';\n /** URL to the CSS file with token overrides (omit for built-in themes) */\n CssUrl?: string;\n /**\n * Derived --mj-* token overrides. Populated for brand themes emitted\n * from seeds; an alternative/companion to CssUrl for token-based application and\n * for feeding the Theme Builder preview without a round-trip through CSS.\n */\n Tokens?: Record<string, string>;\n /** Whether this is a built-in theme (light/dark) */\n IsBuiltIn: boolean;\n /** Optional description shown in theme picker */\n Description?: string;\n /** Optional preview swatch colors for a future theme picker UI */\n PreviewColors?: string[];\n /**\n * The theme {@link ThemeService.Initialize} applies when the user has no saved preference\n * (or the saved one is no longer registered). At most one registered theme should set it;\n * the first registered wins. Without one the default stays `'system'`. A single-brand host\n * registers its brand as the default instead of calling `SetTheme` on every login, which\n * fought `Initialize()`'s own resolution and wrote a preference the user never chose.\n *\n * Not the same axis as Theme Studio's org default (`MJ: Themes`.IsDefault): that one picks\n * the org BRAND OVERLAY, registered via {@link ThemeService.RegisterBrandTheme} into the\n * brand registry and layered under whatever base theme is active. This flag picks the BASE\n * (picker) theme and never looks at the brand registry, so the two compose: a picker-only\n * built-in default keeps the org overlay; a `CssUrl` default replaces it while selected, as\n * any explicitly selected custom theme does.\n */\n IsDefault?: boolean;\n}\n\n/**\n * Setting key for theme preference in MJ: User Settings entity\n */\nconst THEME_SETTING_KEY = 'Explorer.Theme';\n\n/**\n * localStorage key the inline theme-preload script reads on first paint\n * (before Angular boots) to apply the correct theme without flashing.\n *\n * The value is the **base theme** ('dark' or 'light'), NOT the full theme\n * preference (which can be 'system' or a custom theme ID like 'izzy-dark').\n * The preload script needs an unambiguous answer: should I set\n * data-theme=\"dark\" or not? Storing the base theme is the simplest\n * contract: the script does `if (value === 'dark') setAttribute(...)`.\n *\n * Mirrored by ThemeService whenever the applied base theme changes,\n * cleared on logout via Reset().\n */\nconst PRELOAD_BASE_THEME_KEY = 'mj-theme';\n\n/**\n * localStorage key holding the active org **brand overlay** id, mirrored so the\n * inline pre-paint script can restore `data-theme-overlay` on first paint (the org\n * brand persists across the user's light/dark choice AND across logout). The overlay\n * CSS itself is a session-scoped Blob re-emitted at login bootstrap; the CSS text is\n * persisted beside it under {@link PRELOAD_OVERLAY_CSS_KEY} so\n * {@link ThemeService.RestorePersistedBrandOverlay} can put it back before first paint.\n */\nexport const PRELOAD_OVERLAY_KEY = 'mj-theme-overlay';\n\n/**\n * localStorage key: the active org brand overlay's emitted CSS, as JSON `{ id, css }`.\n * The overlay stylesheet is a Blob URL that does not survive a reload, so without this\n * the loading screen and the sign-in page painted MJ's default tokens until bootstrap\n * re-emitted the overlay at the end of workspace init. Only honored when `id` matches\n * {@link PRELOAD_OVERLAY_KEY}; bootstrap's real `<link>` replaces the preloaded `<style>`.\n */\nexport const PRELOAD_OVERLAY_CSS_KEY = 'mj-theme-overlay-css';\n\n/** Attribute on the `<style>` that carries a restored overlay until bootstrap loads the real one. */\nexport const PRELOAD_STYLE_ATTR = 'data-mj-brand-overlay-preload';\n\n/** User-settings key: JSON array of the user's starred (favorited) brand theme ids. */\nconst STARRED_THEMES_KEY = 'Explorer.StarredThemes';\n\n/** User-settings key: the brand theme id the user last applied (restored over org default). */\nconst SELECTED_BRAND_KEY = 'Explorer.SelectedBrandTheme';\n\n/**\n * Built-in light theme definition\n */\nconst LIGHT_THEME: ThemeDefinition = {\n Id: 'light',\n Name: 'Light',\n BaseTheme: 'light',\n IsBuiltIn: true,\n Description: 'Default light theme'\n};\n\n/**\n * Built-in dark theme definition\n */\nconst DARK_THEME: ThemeDefinition = {\n Id: 'dark',\n Name: 'Dark',\n BaseTheme: 'dark',\n IsBuiltIn: true,\n Description: 'Default dark theme'\n};\n\n/**\n * Service to manage application themes with pluggable custom theme support.\n *\n * Built-in themes (light/dark) work identically to before. Custom themes\n * inherit from a base theme and overlay additional CSS token overrides via\n * a dynamically loaded stylesheet.\n *\n * CSS resolution for custom themes (e.g. \"Izzy Dark\" extending dark):\n * 1. `:root` light defaults (from _tokens.scss in this package)\n * 2. `[data-theme=\"dark\"]` dark overrides (from _tokens.scss in this package)\n * 3. `[data-theme-overlay=\"izzy-dark\"]` custom overrides (loaded dynamically)\n *\n * Follows the DeveloperModeService pattern:\n * - Settings persisted via UserInfoEngine\n * - BehaviorSubject for reactive state\n * - Initialize after login, Reset on logout\n */\n@Injectable({ providedIn: 'root' })\nexport class ThemeService {\n private _preference$ = new BehaviorSubject<string>('system');\n private _appliedTheme$ = new BehaviorSubject<string>('light');\n /**\n * The active org brand overlay id, applied independently of the user's light/dark\n * choice and preserved across Reset()/logout.\n */\n private _brandOverlayId: string | null = null;\n /** The user's starred (favorited) brand theme ids, reactive for menus/badges. */\n private _starred$ = new BehaviorSubject<string[]>([]);\n /** Emits when the set of saved themes changes (create/rename/delete/duplicate/default)\n * so open dashboards (Theme Studio, Manage Themes) refresh without a page reload. */\n private _themesChanged$ = new Subject<void>();\n private _initialized = false;\n private systemMediaQuery: MediaQueryList | null = null;\n private boundSystemThemeHandler: (() => void) | null = null;\n\n /** Registry of USER-SELECTABLE themes (shown in the theme picker), seeded with light + dark. */\n private themeRegistry = new Map<string, ThemeDefinition>([\n ['light', LIGHT_THEME],\n ['dark', DARK_THEME]\n ]);\n\n /**\n * Registry of ORG BRAND overlays (from RegisterBrandTheme). Kept separate from\n * themeRegistry so brand overlays do NOT appear in the user's light/dark theme\n * picker — the org brand is applied independently of the user's mode (decision #1).\n */\n /**\n * Theme ids in the order they were FIRST registered with {@link ThemeDefinition.IsDefault}.\n * Kept apart from the registry because a Map keeps an id's original slot on replace: the\n * seeded 'light'/'dark' entries would otherwise outrank any custom theme flagged earlier.\n */\n private defaultCandidates: string[] = [];\n\n private brandRegistry = new Map<string, ThemeDefinition>();\n\n /** Cache of loaded <link> elements by theme ID to avoid re-downloading */\n private loadedCssLinks = new Map<string, HTMLLinkElement>();\n\n /** Session-scoped Blob object URLs for brand overlays, keyed by theme ID (for revocation on re-register). */\n private brandBlobUrls = new Map<string, string>();\n\n /** The emitted overlay CSS per brand theme id — what gets persisted for first paint. */\n private brandCss = new Map<string, string>();\n\n /**\n * An overlay id restored from localStorage by {@link RestorePersistedBrandOverlay} that\n * bootstrap has not yet confirmed ({@link ApplyBrandOverlay}) or cleared\n * ({@link ClearBrandOverlay}). Tracked here rather than inferred from the presence of the\n * preload `<style>`, so a third party touching that element cannot change the service's\n * answer, and \"bootstrap has not run yet\" is a state of its own.\n */\n private pendingOverlayId: string | null = null;\n\n /**\n * Observable for user's theme preference (theme ID or 'system')\n */\n public get Preference$(): Observable<string> {\n return this._preference$.asObservable();\n }\n\n /**\n * Observable for the actually applied theme (resolved theme ID)\n */\n public get AppliedTheme$(): Observable<string> {\n return this._appliedTheme$.asObservable();\n }\n\n /**\n * Current theme preference (synchronous access)\n */\n public get Preference(): string {\n return this._preference$.value;\n }\n\n /**\n * Currently applied theme ID (synchronous access)\n */\n public get AppliedTheme(): string {\n return this._appliedTheme$.value;\n }\n\n /**\n * Whether the service has been initialized\n */\n public get IsInitialized(): boolean {\n return this._initialized;\n }\n\n /**\n * All registered themes, for UI consumption (e.g. theme picker menus)\n */\n public get AvailableThemes(): ThemeDefinition[] {\n return Array.from(this.themeRegistry.values());\n }\n\n /**\n * Look up a theme definition by ID.\n * Returns undefined if the theme ID is not registered.\n */\n public GetThemeDefinition(id: string): ThemeDefinition | undefined {\n return this.themeRegistry.get(id);\n }\n\n // ========================================\n // THEME REGISTRATION\n // ========================================\n\n /**\n * Register a custom theme. If a theme with the same ID already exists,\n * it is replaced (allowing override of built-in themes if desired).\n */\n public RegisterTheme(theme: ThemeDefinition): void {\n this.themeRegistry.set(theme.Id, theme);\n const at = this.defaultCandidates.indexOf(theme.Id);\n if (theme.IsDefault && at === -1) {\n this.defaultCandidates.push(theme.Id);\n } else if (!theme.IsDefault && at !== -1) {\n this.defaultCandidates.splice(at, 1);\n }\n }\n\n /**\n * Register multiple custom themes at once.\n */\n public RegisterThemes(themes: ThemeDefinition[]): void {\n for (const theme of themes) {\n this.RegisterTheme(theme);\n }\n }\n\n /**\n * Register a brand theme from its seeds.\n *\n * Derives the full --mj-* token contract with @memberjunction/theme-engine, emits\n * the `[data-theme-overlay=\"<id>\"]` CSS, and publishes it as a session-scoped Blob\n * URL that plugs into the existing CssUrl overlay path — so brand themes apply\n * through the same machinery as file-based custom themes. Returns the derived\n * theme so callers can surface the a11y contrast report / previews.\n *\n * The emitted overlay overrides only the primitive ramps (plus viz/shadow/font/\n * radius); every semantic token and the `[data-theme=\"dark\"]` block reference those\n * primitives, so both light and dark re-point automatically off one block.\n *\n * @param params.seeds ThemeSeeds object or the entity's Seeds JSON string.\n */\n public RegisterBrandTheme(params: {\n id: string;\n name: string;\n seeds: ThemeSeeds | string;\n description?: string;\n baseTheme?: 'light' | 'dark';\n /** Optional logo variant URLs + geometry, emitted as --mj-logo-*. */\n logos?: ThemeLogos;\n /** Advanced: per-token overrides (JSON map or object) merged over the derived vars. */\n overrides?: Record<string, string> | string | null;\n /** Advanced: raw CSS appended to the overlay, auto-scoped to this theme. */\n customCss?: string | null;\n }): DerivedTheme {\n const seeds = typeof params.seeds === 'string' ? (JSON.parse(params.seeds) as ThemeSeeds) : params.seeds;\n const derived = derive(seeds);\n const overrides = this.parseOverrides(params.overrides);\n // One Blob carries the whole brand: color/shape/font overlay (+ advanced layer) + logo tokens.\n const css = emitOverlayCss(params.id, derived, { overrides, customCss: params.customCss })\n + (params.logos ? emitLogoOverlayCss(params.id, params.logos) : '');\n\n // Replace any prior Blob URL + cached <link> for this id so a re-registration\n // (e.g. live preview) loads the new CSS instead of re-enabling stale bytes.\n const priorUrl = this.brandBlobUrls.get(params.id);\n if (priorUrl) {\n URL.revokeObjectURL(priorUrl);\n }\n const cachedLink = this.loadedCssLinks.get(params.id);\n if (cachedLink) {\n cachedLink.remove();\n this.loadedCssLinks.delete(params.id);\n }\n\n const url = URL.createObjectURL(new Blob([css], { type: 'text/css' }));\n this.brandBlobUrls.set(params.id, url);\n this.brandCss.set(params.id, css);\n\n // Register into the brand registry only — NOT themeRegistry — so the org brand\n // does not surface as a user-selectable option in the theme picker.\n this.brandRegistry.set(params.id, {\n Id: params.id,\n Name: params.name,\n BaseTheme: params.baseTheme ?? 'light',\n CssUrl: url,\n Tokens: derived.overlayVars,\n IsBuiltIn: false,\n Description: params.description,\n PreviewColors: [\n derived.tokens.light['--mj-brand-primary'],\n derived.tokens.light['--mj-brand-accent'],\n derived.tokens.light['--mj-brand-tertiary'],\n ],\n });\n\n return derived;\n }\n\n /** Normalize the advanced overrides input (JSON string, object, or null) to a token map. */\n private parseOverrides(input?: Record<string, string> | string | null): Record<string, string> | undefined {\n if (!input) return undefined;\n if (typeof input === 'string') {\n try {\n const parsed = JSON.parse(input);\n return parsed && typeof parsed === 'object' ? (parsed as Record<string, string>) : undefined;\n } catch {\n return undefined;\n }\n }\n return input;\n }\n\n /**\n * The active org brand overlay id, or null if none is applied.\n */\n public get BrandOverlayId(): string | null {\n return this._brandOverlayId;\n }\n\n /**\n * Apply an org brand overlay **independently of the user's light/dark mode.\n * The overlay layers under whatever base theme is\n * active and is re-asserted whenever the user toggles light/dark. Persists the id\n * to localStorage so the pre-paint script restores the attribute on next load.\n *\n * @param id id of a brand theme registered via {@link RegisterBrandTheme}.\n * @param options.persist pass `false` for session-only overlays backed by Blob URLs\n * (e.g. Theme Studio's draft workspace preview) — a Blob URL doesn't survive a\n * reload, so persisting its id would leave the pre-paint script pointing at a\n * dangling overlay and clobber the user's real persisted selection. Defaults true.\n */\n public async ApplyBrandOverlay(id: string, options?: { persist?: boolean }): Promise<void> {\n const def = this.brandRegistry.get(id);\n if (!def || !def.CssUrl) {\n console.warn(`ApplyBrandOverlay: no registered brand theme \"${id}\" with CSS.`);\n return;\n }\n this._brandOverlayId = id;\n await this.loadThemeCss(def);\n // The real stylesheet carries the brand now; a restored preload (this id or a stale one) goes.\n this.removePreloadStyles();\n this.pendingOverlayId = null;\n document.documentElement.setAttribute('data-theme-overlay', id);\n if (options?.persist === false) {\n return;\n }\n try {\n window.localStorage.setItem(PRELOAD_OVERLAY_KEY, id);\n // The CSS is a few KB; skip the synchronous write when the stored entry already matches\n // (a re-apply of the same brand), so repeated applies cost nothing.\n const entry = JSON.stringify({ id, css: this.brandCss.get(id) ?? '' });\n if (window.localStorage.getItem(PRELOAD_OVERLAY_CSS_KEY) !== entry) {\n window.localStorage.setItem(PRELOAD_OVERLAY_CSS_KEY, entry);\n }\n } catch (e) {\n // non-fatal: a brief brand flash on next reload at worst\n }\n }\n\n /**\n * Put the persisted org brand overlay back BEFORE first paint, from localStorage alone —\n * no registry, no database. Call it from the earliest code that runs in the app (the\n * explorer-app constructor), so the sign-in page and the shell's loading screen paint\n * branded on a cold load instead of waiting for bootstrap to re-emit the overlay.\n *\n * Injects the persisted CSS as a `<style>` (bootstrap's real `<link>` replaces it), sets\n * `data-theme-overlay`, and records the id so {@link Initialize} does not strip the\n * attribute before bootstrap registers the brand. A CSS entry whose id no longer matches\n * the persisted overlay id is stale and is dropped. Returns whether anything was restored.\n */\n public RestorePersistedBrandOverlay(): boolean {\n let id: string | null = null;\n let entry: { id?: unknown; css?: unknown } | null = null;\n try {\n id = window.localStorage.getItem(PRELOAD_OVERLAY_KEY);\n const raw = window.localStorage.getItem(PRELOAD_OVERLAY_CSS_KEY);\n entry = raw ? (JSON.parse(raw) as { id?: unknown; css?: unknown }) : null;\n } catch (e) {\n return false;\n }\n if (!id || !entry) {\n return false;\n }\n if (entry.id !== id || typeof entry.css !== 'string') {\n try {\n window.localStorage.removeItem(PRELOAD_OVERLAY_CSS_KEY);\n } catch (e) {\n // non-fatal\n }\n return false;\n }\n const existing = this.findPreloadStyle(id);\n if (existing) {\n // A host's inline snippet already injected it. Re-append so it follows every\n // stylesheet that arrived after it (the app's own, above all): the overlay's\n // selectors tie the compiled :root tokens on specificity, so order decides.\n document.head.appendChild(existing);\n } else {\n const style = document.createElement('style');\n style.setAttribute(PRELOAD_STYLE_ATTR, id);\n style.textContent = entry.css;\n document.head.appendChild(style);\n }\n document.documentElement.setAttribute('data-theme-overlay', id);\n this._brandOverlayId = id;\n this.pendingOverlayId = id;\n return true;\n }\n\n /**\n * The restored preload `<style>` for this overlay id, if one is in the document (ours or the\n * host's inline snippet). An attribute walk rather than an interpolated selector: the id\n * comes from localStorage, and a quote or bracket in it would make `querySelector` throw —\n * from the explorer-app constructor.\n */\n private findPreloadStyle(id: string): HTMLStyleElement | null {\n const styles = document.head.querySelectorAll<HTMLStyleElement>(`style[${PRELOAD_STYLE_ATTR}]`);\n for (const el of Array.from(styles)) {\n if (el.getAttribute(PRELOAD_STYLE_ATTR) === id) {\n return el;\n }\n }\n return null;\n }\n\n /** Drop every restored preload `<style>` (a real stylesheet has taken over, or the brand was cleared). */\n private removePreloadStyles(): void {\n document.head.querySelectorAll(`style[${PRELOAD_STYLE_ATTR}]`).forEach((el) => el.remove());\n }\n\n /**\n * Remove the active org brand overlay (revert to the base MJ tokens).\n *\n * Scoped to the brand: only the brand's own `<link>` is disabled and the `data-theme-overlay`\n * attribute is dropped only when it still names that brand. Bootstrap calls this on every login\n * where the org has no active brand, right after `Initialize()` applied the user's theme, so a\n * blanket clear would switch off a user's custom theme on any install that never used Theme Studio.\n */\n public ClearBrandOverlay(): void {\n const brandId = this._brandOverlayId;\n this._brandOverlayId = null;\n this.pendingOverlayId = null;\n if (brandId !== null) {\n if (document.documentElement.getAttribute('data-theme-overlay') === brandId) {\n document.documentElement.removeAttribute('data-theme-overlay');\n }\n const brandLink = this.loadedCssLinks.get(brandId);\n if (brandLink) {\n brandLink.disabled = true;\n }\n }\n this.removePreloadStyles();\n try {\n window.localStorage.removeItem(PRELOAD_OVERLAY_KEY);\n window.localStorage.removeItem(PRELOAD_OVERLAY_CSS_KEY);\n } catch (e) {\n // non-fatal\n }\n }\n\n // ========================================\n // LIFECYCLE\n // ========================================\n\n /**\n * Initialize the theme service.\n * Call after login when UserInfoEngine is available.\n */\n public async Initialize(): Promise<void> {\n if (this._initialized) {\n return;\n }\n\n this.setupSystemThemeListener();\n\n this._starred$.next(this.loadStarredIds());\n\n // A saved preference wins; without one the host's default theme (IsDefault), else 'system'.\n const savedPreference = await this.loadSetting();\n const preference = savedPreference ?? this.DefaultPreference;\n this._preference$.next(preference);\n\n const resolvedThemeId = this.resolveTheme(preference);\n await this.applyTheme(resolvedThemeId);\n\n this._initialized = true;\n }\n\n /**\n * What {@link Initialize} applies when nothing is saved: the first theme REGISTERED with\n * {@link ThemeDefinition.IsDefault} (registration order, not registry slot order — re-registering\n * a built-in slot with the flag does not jump the queue), else `'system'`. Public so a picker\n * can mark the default.\n */\n public get DefaultPreference(): string {\n for (const id of this.defaultCandidates) {\n if (this.themeRegistry.get(id)?.IsDefault) {\n return id;\n }\n }\n return 'system';\n }\n\n /**\n * Set the theme preference and apply it.\n * @param preference - A registered theme ID or 'system'\n */\n public async SetTheme(preference: string): Promise<void> {\n if (preference === this._preference$.value) {\n return;\n }\n\n this._preference$.next(preference);\n\n const resolvedThemeId = this.resolveTheme(preference);\n await this.applyTheme(resolvedThemeId);\n\n await this.saveSetting(preference);\n }\n\n /**\n * Reset the service (call on logout)\n */\n public Reset(): void {\n if (this.systemMediaQuery && this.boundSystemThemeHandler) {\n this.systemMediaQuery.removeEventListener('change', this.boundSystemThemeHandler);\n }\n this.systemMediaQuery = null;\n this.boundSystemThemeHandler = null;\n\n // \"Nothing chosen\" is the host's default, not literally 'system': a reader of Preference in\n // the logged-out window (a sign-in page toggle) should see the same answer Initialize() will.\n this._preference$.next(this.DefaultPreference);\n this._appliedTheme$.next('light');\n this._initialized = false;\n\n // Remove the base-theme attribute only. We deliberately KEEP the org brand\n // overlay (data-theme-overlay + its CSS + _brandOverlayId) so the brand\n // survives logout and stays on the login screen.\n // The overlay is re-emitted at the next login bootstrap.\n document.documentElement.removeAttribute('data-theme');\n\n // NOTE: we deliberately do NOT clear PRELOAD_BASE_THEME_KEY here.\n // The unified theme key ('mj-theme') is the single source of truth\n // shared with the login-screen toggle and the inline pre-paint script.\n // Clearing it on logout would force the login screen back to OS\n // default and cause a theme flash for the post-logout/pre-login\n // window. The auth provider's clearClientCaches() preserves it for\n // exactly this reason (see preservedLocalStorageKeys).\n\n // Disable custom CSS links EXCEPT the active org brand overlay, which must\n // survive logout so the brand persists on the login screen.\n this.disableAllCustomCss(this._brandOverlayId);\n }\n\n // ========================================\n // THEME APPLICATION\n // ========================================\n\n /**\n * Apply a resolved theme ID to the DOM.\n * Sets `data-theme` based on BaseTheme and `data-theme-overlay` for custom themes.\n * Loads custom CSS if needed, disables previous custom CSS.\n */\n private async applyTheme(themeId: string): Promise<void> {\n const themeDef = this.themeRegistry.get(themeId);\n\n // Fall back to 'light' if the theme ID isn't recognized\n if (!themeDef) {\n this.applyBuiltInTheme('light');\n this._appliedTheme$.next('light');\n return;\n }\n\n // Set the base theme attribute (drives existing [data-theme=\"dark\"] selectors)\n this.applyBaseThemeAttribute(themeDef.BaseTheme);\n\n if (themeDef.IsBuiltIn) {\n // Built-in (light/dark): the user's mode changes, but the org brand overlay\n // stays layered under it. Re-assert the brand overlay if one is active;\n // otherwise clear any overlay.\n if (this._brandOverlayId) {\n const brandDef = this.brandRegistry.get(this._brandOverlayId);\n if (brandDef?.CssUrl) {\n await this.loadThemeCss(brandDef);\n document.documentElement.setAttribute('data-theme-overlay', this._brandOverlayId);\n } else if (this.pendingOverlayId === this._brandOverlayId) {\n // Restored from localStorage and not yet confirmed or cleared by bootstrap: keep\n // the attribute so the preloaded CSS stays matched until the real overlay lands.\n document.documentElement.setAttribute('data-theme-overlay', this._brandOverlayId);\n this.disableAllCustomCss();\n } else {\n document.documentElement.removeAttribute('data-theme-overlay');\n this.disableAllCustomCss();\n }\n } else {\n document.documentElement.removeAttribute('data-theme-overlay');\n this.disableAllCustomCss();\n }\n } else if (themeDef.CssUrl) {\n // Explicit custom theme selected — its overlay overrides any brand overlay.\n await this.loadThemeCss(themeDef);\n document.documentElement.setAttribute('data-theme-overlay', themeDef.Id);\n }\n\n this._appliedTheme$.next(themeId);\n }\n\n /**\n * Apply the base theme attribute to <html>.\n * 'dark' sets data-theme=\"dark\"; 'light' removes it (matching existing convention).\n *\n * Also mirrors the base theme to localStorage under PRELOAD_BASE_THEME_KEY\n * so the inline pre-bootstrap theme-preload script in index.html can apply\n * the correct theme on first paint of the next page load — eliminating\n * the brief light-mode flash dark-mode users would otherwise see.\n */\n private applyBaseThemeAttribute(baseTheme: 'light' | 'dark'): void {\n if (baseTheme === 'dark') {\n document.documentElement.setAttribute('data-theme', 'dark');\n } else {\n document.documentElement.removeAttribute('data-theme');\n }\n try {\n window.localStorage.setItem(PRELOAD_BASE_THEME_KEY, baseTheme);\n } catch (e) {\n // localStorage exceptions (private mode, quota) are non-fatal here —\n // the app still works, the user just may see a brief theme flash on\n // their next reload.\n }\n }\n\n /**\n * Shorthand for built-in theme application (no custom CSS)\n */\n private applyBuiltInTheme(baseTheme: 'light' | 'dark'): void {\n this.applyBaseThemeAttribute(baseTheme);\n document.documentElement.removeAttribute('data-theme-overlay');\n this.disableAllCustomCss();\n }\n\n // ========================================\n // DYNAMIC CSS LOADING\n // ========================================\n\n /**\n * Load (or re-enable) a custom theme's CSS file.\n * Injects a <link> element into <head> with a data-mj-theme attribute.\n * Caches the link element to avoid re-downloading on theme switches.\n * Returns a Promise that resolves once the stylesheet is loaded.\n */\n private loadThemeCss(theme: ThemeDefinition): Promise<void> {\n if (!theme.CssUrl) {\n return Promise.resolve();\n }\n\n // Disable all other custom CSS first\n this.disableAllCustomCss();\n\n // Check cache — if already loaded, just re-enable\n const existingLink = this.loadedCssLinks.get(theme.Id);\n if (existingLink) {\n existingLink.disabled = false;\n return Promise.resolve();\n }\n\n // Create and inject new <link> element\n return new Promise<void>((resolve, reject) => {\n const link = document.createElement('link');\n link.rel = 'stylesheet';\n link.href = theme.CssUrl!;\n link.setAttribute('data-mj-theme', theme.Id);\n\n link.onload = () => resolve();\n link.onerror = () => {\n console.warn(`Failed to load theme CSS: ${theme.CssUrl}`);\n // Still resolve so the theme switch isn't blocked\n resolve();\n };\n\n document.head.appendChild(link);\n this.loadedCssLinks.set(theme.Id, link);\n });\n }\n\n /**\n * Disable (not remove) custom theme CSS <link> elements.\n * Disabling rather than removing avoids re-downloading when switching back.\n * @param keepId optional theme id to leave enabled (e.g. the active brand overlay).\n */\n private disableAllCustomCss(keepId?: string | null): void {\n for (const [id, link] of this.loadedCssLinks.entries()) {\n if (keepId && id === keepId) {\n continue;\n }\n link.disabled = true;\n }\n }\n\n // ========================================\n // THEME RESOLUTION\n // ========================================\n\n /**\n * Resolve a preference string to an actual theme ID.\n * 'system' resolves to 'light' or 'dark' based on OS preference.\n * Unrecognized IDs fall back to 'light'.\n */\n private resolveTheme(preference: string): string {\n if (preference === 'system') {\n return this.getSystemTheme();\n }\n\n // If the preference is a registered theme, use it directly\n if (this.themeRegistry.has(preference)) {\n return preference;\n }\n\n // Unrecognized theme ID — fall back to light\n return 'light';\n }\n\n /**\n * Get system theme preference from OS\n */\n private getSystemTheme(): 'light' | 'dark' {\n if (typeof window === 'undefined') {\n return 'light';\n }\n return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\n }\n\n /**\n * Setup listener for system theme changes\n */\n private setupSystemThemeListener(): void {\n if (typeof window === 'undefined') {\n return;\n }\n\n this.systemMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');\n this.boundSystemThemeHandler = () => this.onSystemThemeChange();\n this.systemMediaQuery.addEventListener('change', this.boundSystemThemeHandler);\n }\n\n /**\n * Handle system theme change (only applies if in 'system' mode)\n */\n private async onSystemThemeChange(): Promise<void> {\n if (this._preference$.value === 'system') {\n const newThemeId = this.getSystemTheme();\n await this.applyTheme(newThemeId);\n }\n }\n\n // ========================================\n // STARRED (FAVORITE) BRAND THEMES\n // ========================================\n\n /** Reactive list of the user's starred brand theme ids. */\n public get Starred$(): Observable<string[]> {\n return this._starred$.asObservable();\n }\n\n /** Emits after any saved-theme mutation so open dashboards can refresh their lists. */\n public get ThemesChanged$(): Observable<void> {\n return this._themesChanged$.asObservable();\n }\n\n /** Broadcast that the set of saved themes changed (create/rename/delete/duplicate/default). */\n public NotifyThemesChanged(): void {\n this._themesChanged$.next();\n }\n\n /** The user's starred brand theme ids (synchronous). */\n public GetStarredThemeIds(): string[] {\n return this._starred$.value;\n }\n\n /** Whether a theme id is starred by the user. */\n public IsStarred(id: string): boolean {\n return this._starred$.value.includes(id);\n }\n\n /**\n * Toggle a theme's starred state and persist to User Settings.\n * @returns the new starred state (true = now starred).\n */\n public async ToggleStar(id: string): Promise<boolean> {\n const set = new Set(this._starred$.value);\n const nowStarred = !set.has(id);\n if (nowStarred) {\n set.add(id);\n } else {\n set.delete(id);\n }\n const ids = Array.from(set);\n this._starred$.next(ids);\n try {\n await UserInfoEngine.Instance.SetSetting(STARRED_THEMES_KEY, JSON.stringify(ids));\n } catch (error) {\n console.warn('Failed to save starred themes:', error);\n }\n return nowStarred;\n }\n\n private loadStarredIds(): string[] {\n try {\n const raw = UserInfoEngine.Instance.GetSetting(STARRED_THEMES_KEY);\n const parsed = raw ? JSON.parse(raw) : [];\n return Array.isArray(parsed) ? parsed.filter((x) => typeof x === 'string') : [];\n } catch {\n return [];\n }\n }\n\n /** The brand theme the user last applied (or null to follow the org default). */\n public GetSelectedBrandThemeId(): string | null {\n try {\n return UserInfoEngine.Instance.GetSetting(SELECTED_BRAND_KEY) || null;\n } catch {\n return null;\n }\n }\n\n /** Persist (or clear, with null) the user's chosen brand theme so login restores it. */\n public async SetSelectedBrandTheme(id: string | null): Promise<void> {\n try {\n await UserInfoEngine.Instance.SetSetting(SELECTED_BRAND_KEY, id ?? '');\n } catch (error) {\n console.warn('Failed to save selected brand theme:', error);\n }\n }\n\n // ========================================\n // PERSISTENCE\n // ========================================\n\n /**\n * The user's saved preference ('system' or a registered theme ID), or `null` when there is\n * none to honor — nothing saved, a saved theme that is no longer registered, or a failed\n * read. The caller decides what `null` means (see {@link DefaultPreference}).\n */\n private async loadSetting(): Promise<string | null> {\n try {\n const engine = UserInfoEngine.Instance;\n const settingValue = engine.GetSetting(THEME_SETTING_KEY);\n\n if (!settingValue) {\n return null;\n }\n\n // Accept 'system' or any registered theme ID\n if (settingValue === 'system' || this.themeRegistry.has(settingValue)) {\n return settingValue;\n }\n\n // Saved theme no longer registered — nothing to honor\n return null;\n } catch (error) {\n console.warn('Failed to load theme setting:', error);\n return null;\n }\n }\n\n /**\n * Save theme preference to User Settings\n */\n private async saveSetting(preference: string): Promise<void> {\n try {\n const engine = UserInfoEngine.Instance;\n await engine.SetSetting(THEME_SETTING_KEY, preference);\n } catch (error) {\n console.warn('Failed to save theme setting:', error);\n }\n }\n}\n"]}
|
package/dist/public-api.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './lib/module';
|
|
|
2
2
|
export * from './lib/recent-access.service';
|
|
3
3
|
export * from './lib/recent-resource-type';
|
|
4
4
|
export * from './lib/theme.service';
|
|
5
|
+
export * from './lib/brand-overlay-prepaint';
|
|
5
6
|
export * from './lib/dom-utils';
|
|
6
7
|
export * from './lib/ag-grid-theme-params';
|
|
7
8
|
export * from './lib/loading/loading.component';
|
package/dist/public-api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-api.d.ts","sourceRoot":"","sources":["../src/public-api.ts"],"names":[],"mappings":"AAKA,cAAc,cAAc,CAAC;AAG7B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"public-api.d.ts","sourceRoot":"","sources":["../src/public-api.ts"],"names":[],"mappings":"AAKA,cAAc,cAAc,CAAC;AAG7B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAG7C,cAAc,iBAAiB,CAAC;AAGhC,cAAc,4BAA4B,CAAC;AAG3C,cAAc,iCAAiC,CAAC;AAGhD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qCAAqC,CAAC"}
|
package/dist/public-api.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from './lib/module';
|
|
|
7
7
|
export * from './lib/recent-access.service';
|
|
8
8
|
export * from './lib/recent-resource-type';
|
|
9
9
|
export * from './lib/theme.service';
|
|
10
|
+
export * from './lib/brand-overlay-prepaint';
|
|
10
11
|
// DOM helpers
|
|
11
12
|
export * from './lib/dom-utils';
|
|
12
13
|
// Theming constants
|
package/dist/public-api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../src/public-api.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,SAAS;AACT,cAAc,cAAc,CAAC;AAE7B,WAAW;AACX,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../src/public-api.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,SAAS;AACT,cAAc,cAAc,CAAC;AAE7B,WAAW;AACX,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAE7C,cAAc;AACd,cAAc,iBAAiB,CAAC;AAEhC,oBAAoB;AACpB,cAAc,4BAA4B,CAAC;AAE3C,aAAa;AACb,cAAc,iCAAiC,CAAC;AAEhD,mDAAmD;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qCAAqC,CAAC","sourcesContent":["/*\n * Public API Surface for @memberjunction/ng-shared-generic\n */\n\n// Module\nexport * from './lib/module';\n\n// Services\nexport * from './lib/recent-access.service';\nexport * from './lib/recent-resource-type';\nexport * from './lib/theme.service';\nexport * from './lib/brand-overlay-prepaint';\n\n// DOM helpers\nexport * from './lib/dom-utils';\n\n// Theming constants\nexport * from './lib/ag-grid-theme-params';\n\n// Components\nexport * from './lib/loading/loading.component';\n\n// Rich-text rendering (safe HTML/SVG sanitization)\nexport * from './lib/rich-text/rich-text-sanitize';\nexport * from './lib/rich-text/safe-rich-html.pipe';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ng-shared-generic",
|
|
3
|
-
"version": "6.2.0-edge.
|
|
3
|
+
"version": "6.2.0-edge.7",
|
|
4
4
|
"description": "MemberJunction: Generic Angular Shared Package - utility services and reusable elements used in any Angular application.",
|
|
5
5
|
"main": "./dist/public-api.js",
|
|
6
6
|
"typings": "./dist/public-api.d.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@angular/compiler": "21.2.22",
|
|
18
18
|
"@angular/compiler-cli": "21.2.22",
|
|
19
|
-
"@memberjunction/ng-test-utils": "6.2.0-edge.
|
|
19
|
+
"@memberjunction/ng-test-utils": "6.2.0-edge.7",
|
|
20
20
|
"vitest": "^4.0.18"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"rxjs": "^7.8.2"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@memberjunction/core": "6.2.0-edge.
|
|
30
|
-
"@memberjunction/ng-base-types": "6.2.0-edge.
|
|
31
|
-
"@memberjunction/core-entities": "6.2.0-edge.
|
|
32
|
-
"@memberjunction/global": "6.2.0-edge.
|
|
33
|
-
"@memberjunction/theme-engine": "6.2.0-edge.
|
|
29
|
+
"@memberjunction/core": "6.2.0-edge.7",
|
|
30
|
+
"@memberjunction/ng-base-types": "6.2.0-edge.7",
|
|
31
|
+
"@memberjunction/core-entities": "6.2.0-edge.7",
|
|
32
|
+
"@memberjunction/global": "6.2.0-edge.7",
|
|
33
|
+
"@memberjunction/theme-engine": "6.2.0-edge.7",
|
|
34
34
|
"dompurify": "^3.3.0",
|
|
35
35
|
"tslib": "^2.8.1"
|
|
36
36
|
},
|