@panomc/theme-core 1.0.0-dev.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/bin/bundle-internal-libs.js +104 -0
  2. package/bin/check.js +253 -0
  3. package/bin/generate-licenses.js +125 -0
  4. package/bin/generate-runtime-shims.js +180 -0
  5. package/bin/license/file-fingerprint.js +74 -0
  6. package/bin/license/finalize-fingerprint.js +72 -0
  7. package/bin/license/generate-license-constants.js +335 -0
  8. package/bin/new.js +281 -0
  9. package/bin/package-zip.js +57 -0
  10. package/bin/sync.js +326 -0
  11. package/bin/templates/app.html +59 -0
  12. package/bin/theme-core.js +103 -0
  13. package/package.json +77 -0
  14. package/src/index.js +15 -0
  15. package/src/kit/hooks-client.js +128 -0
  16. package/src/kit/hooks-server.js +319 -0
  17. package/src/kit/license-runtime.js +373 -0
  18. package/src/kit/resolve.js +71 -0
  19. package/src/kit/specifiers.js +62 -0
  20. package/src/kit/svelte-config.js +74 -0
  21. package/src/kit/vite-config.js +249 -0
  22. package/src/lib/NotificationManager.js +1 -0
  23. package/src/lib/PluginAPI.js +368 -0
  24. package/src/lib/PluginManager.js +1 -0
  25. package/src/lib/Store.js +43 -0
  26. package/src/lib/api.util.js +5 -0
  27. package/src/lib/auth.util.js +77 -0
  28. package/src/lib/components/App.svelte +10 -0
  29. package/src/lib/components/Breadcrumb.svelte +88 -0
  30. package/src/lib/components/CardHeader.svelte +42 -0
  31. package/src/lib/components/Date.svelte +34 -0
  32. package/src/lib/components/DefaultToast.svelte +11 -0
  33. package/src/lib/components/ErrorAlert.svelte +16 -0
  34. package/src/lib/components/Footer.svelte +223 -0
  35. package/src/lib/components/Header.svelte +122 -0
  36. package/src/lib/components/Hook.svelte +71 -0
  37. package/src/lib/components/LinkCodeInput.svelte +129 -0
  38. package/src/lib/components/LoginFormBody.svelte +90 -0
  39. package/src/lib/components/Main.svelte +76 -0
  40. package/src/lib/components/Navbar.svelte +462 -0
  41. package/src/lib/components/NoContent.svelte +14 -0
  42. package/src/lib/components/NotificationContainer.svelte +304 -0
  43. package/src/lib/components/OnlineAdmins.svelte +64 -0
  44. package/src/lib/components/PageActions.svelte +39 -0
  45. package/src/lib/components/PageTitle.svelte +36 -0
  46. package/src/lib/components/Pagination.svelte +65 -0
  47. package/src/lib/components/PlayerHead.svelte +58 -0
  48. package/src/lib/components/PlayerPermissionBadge.svelte +19 -0
  49. package/src/lib/components/PlayerStatusBadge.svelte +63 -0
  50. package/src/lib/components/Post.svelte +240 -0
  51. package/src/lib/components/Posts.svelte +19 -0
  52. package/src/lib/components/RegisterForm.svelte +125 -0
  53. package/src/lib/components/Sidebar.svelte +12 -0
  54. package/src/lib/components/SuccessAlert.svelte +14 -0
  55. package/src/lib/components/TicketRow.svelte +61 -0
  56. package/src/lib/components/TicketStatus.svelte +24 -0
  57. package/src/lib/components/Tickets.svelte +43 -0
  58. package/src/lib/components/Toast.svelte +13 -0
  59. package/src/lib/components/ToastContainer.svelte +83 -0
  60. package/src/lib/components/ViewComponent.svelte +8 -0
  61. package/src/lib/components/modals/CloseTicketConfirmModal.svelte +121 -0
  62. package/src/lib/components/modals/ConfirmRemoveAllNotificationsModal.svelte +93 -0
  63. package/src/lib/components/modals/LogoutSessionConfirmModal.svelte +61 -0
  64. package/src/lib/components/sidebars/HomeSidebar.svelte +333 -0
  65. package/src/lib/components/sidebars/PlayerDetailSidebar.svelte +124 -0
  66. package/src/lib/components/sidebars/ProfileSidebar.svelte +149 -0
  67. package/src/lib/components/sidebars/SupportSidebar.svelte +54 -0
  68. package/src/lib/components/sidebars/TicketCreateAndDetailSidebar.svelte +84 -0
  69. package/src/lib/csrf.js +5 -0
  70. package/src/lib/init.libs.js +2 -0
  71. package/src/lib/language.util.js +154 -0
  72. package/src/lib/layouts/AppLayout.svelte +59 -0
  73. package/src/lib/layouts/AuthLayout.svelte +29 -0
  74. package/src/lib/layouts/MainLayout.svelte +60 -0
  75. package/src/lib/layouts/ProfileLayout.svelte +29 -0
  76. package/src/lib/layouts/ThemeSettingsLayout.svelte +37 -0
  77. package/src/lib/layouts/TicketsLayout.svelte +31 -0
  78. package/src/lib/loginInput.util.js +4 -0
  79. package/src/lib/orderNavLinks.util.js +58 -0
  80. package/src/lib/pages/ActivateEmailPage.svelte +48 -0
  81. package/src/lib/pages/ConfirmNewEmailPage.svelte +48 -0
  82. package/src/lib/pages/ErrorPage.svelte +41 -0
  83. package/src/lib/pages/HomePage.svelte +35 -0
  84. package/src/lib/pages/LoginPage.svelte +448 -0
  85. package/src/lib/pages/NotificationsPage.svelte +70 -0
  86. package/src/lib/pages/PlayerDetailPage.svelte +29 -0
  87. package/src/lib/pages/PostDetailPage.svelte +36 -0
  88. package/src/lib/pages/PreviewPostPage.svelte +38 -0
  89. package/src/lib/pages/RegisterPage.svelte +144 -0
  90. package/src/lib/pages/RenewPasswordPage.svelte +49 -0
  91. package/src/lib/pages/ResetPasswordPage.svelte +55 -0
  92. package/src/lib/pages/RulesPage.svelte +52 -0
  93. package/src/lib/pages/SupportPage.svelte +36 -0
  94. package/src/lib/pages/ThemeSettingsPage.svelte +551 -0
  95. package/src/lib/pages/profile/ProfilePage.svelte +32 -0
  96. package/src/lib/pages/profile/SettingsPage.svelte +163 -0
  97. package/src/lib/pages/profile/TicketsPage.svelte +54 -0
  98. package/src/lib/pages/ticket/CreateTicketPage.svelte +48 -0
  99. package/src/lib/pages/ticket/TicketDetailPage.svelte +59 -0
  100. package/src/lib/services/auth.js +85 -0
  101. package/src/lib/services/posts.js +152 -0
  102. package/src/lib/services/profile.js +37 -0
  103. package/src/lib/services/theme-setting.js +22 -0
  104. package/src/lib/services/tickets.js +95 -0
  105. package/src/lib/siteRealtime.js +244 -0
  106. package/src/lib/string.util.js +27 -0
  107. package/src/lib/tooltip.util.js +5 -0
  108. package/src/lib/ui-logics/layout-logics/AppLayoutLogics.js +321 -0
  109. package/src/lib/ui-logics/layout-logics/AuthLayoutLogics.js +10 -0
  110. package/src/lib/ui-logics/layout-logics/MainLayoutLogics.js +19 -0
  111. package/src/lib/ui-logics/layout-logics/ProfileLayoutLogics.js +10 -0
  112. package/src/lib/ui-logics/layout-logics/ThemeSettingsLayoutLogics.js +215 -0
  113. package/src/lib/ui-logics/layout-logics/TicketsLayoutLogics.js +10 -0
  114. package/src/lib/ui-logics/page-logics/ActiveEmailPageLogics.js +45 -0
  115. package/src/lib/ui-logics/page-logics/ConfirmNewEmailPageLogics.js +42 -0
  116. package/src/lib/ui-logics/page-logics/CreateTicketPageLogics.js +83 -0
  117. package/src/lib/ui-logics/page-logics/HomePageLogics.js +65 -0
  118. package/src/lib/ui-logics/page-logics/NotificationsPageLogics.js +264 -0
  119. package/src/lib/ui-logics/page-logics/PlayerDetailPageLogics.js +40 -0
  120. package/src/lib/ui-logics/page-logics/PostDetailPageLogics.js +58 -0
  121. package/src/lib/ui-logics/page-logics/PreviewPostPageLogics.js +53 -0
  122. package/src/lib/ui-logics/page-logics/ProfilePageLogics.js +44 -0
  123. package/src/lib/ui-logics/page-logics/RenewPasswordPageLogics.js +44 -0
  124. package/src/lib/ui-logics/page-logics/ResetPasswordPageLogics.js +53 -0
  125. package/src/lib/ui-logics/page-logics/SettingsPageLogics.js +230 -0
  126. package/src/lib/ui-logics/page-logics/SupportPageLogics.js +60 -0
  127. package/src/lib/ui-logics/page-logics/TicketDetailPageLogics.js +160 -0
  128. package/src/lib/ui-logics/page-logics/TicketsPageLogics.js +132 -0
  129. package/src/lib/variables.js +1 -0
  130. package/src/lib/views/ActivateEmailView.svelte +71 -0
  131. package/src/lib/views/AppLayoutView.svelte +31 -0
  132. package/src/lib/views/AuthLayoutView.svelte +23 -0
  133. package/src/lib/views/ConfirmNewEmailView.svelte +71 -0
  134. package/src/lib/views/CreateTicketView.svelte +73 -0
  135. package/src/lib/views/ErrorView.svelte +38 -0
  136. package/src/lib/views/HomeView.svelte +72 -0
  137. package/src/lib/views/LoginView.svelte +372 -0
  138. package/src/lib/views/MainLayoutView.svelte +86 -0
  139. package/src/lib/views/NotificationsView.svelte +129 -0
  140. package/src/lib/views/PlayerDetailView.svelte +31 -0
  141. package/src/lib/views/PostDetailView.svelte +199 -0
  142. package/src/lib/views/PreviewPostView.svelte +151 -0
  143. package/src/lib/views/ProfileLayoutView.svelte +16 -0
  144. package/src/lib/views/ProfileView.svelte +68 -0
  145. package/src/lib/views/RegisterView.svelte +113 -0
  146. package/src/lib/views/RenewPasswordView.svelte +98 -0
  147. package/src/lib/views/ResetPasswordView.svelte +88 -0
  148. package/src/lib/views/RulesView.svelte +26 -0
  149. package/src/lib/views/SettingsView.svelte +471 -0
  150. package/src/lib/views/SupportView.svelte +79 -0
  151. package/src/lib/views/ThemeSettingsLayoutView.svelte +19 -0
  152. package/src/lib/views/ThemeSettingsView.svelte +1508 -0
  153. package/src/lib/views/TicketDetailView.svelte +185 -0
  154. package/src/lib/views/TicketsLayoutView.svelte +21 -0
  155. package/src/lib/views/TicketsView.svelte +87 -0
  156. package/src/plugin-engine/engine.js +484 -0
  157. package/src/registry/index.js +86 -0
  158. package/src/routes/RootLayout.svelte +21 -0
  159. package/src/routes/plugin-ui/Layout.svelte +291 -0
  160. package/src/routes/plugin-ui/Page.svelte +117 -0
  161. package/src/routes/plugin-ui/layout.js +8 -0
  162. package/src/routes/plugin-ui/page.js +8 -0
  163. package/src/routes/plugins-client-file.js +76 -0
  164. package/src/routes/root-layout-load.js +15 -0
  165. package/src/routes/theme-api-languages.js +52 -0
  166. package/src/routes/theme-api-licenses.js +28 -0
@@ -0,0 +1,484 @@
1
+ /**
2
+ * Pano plugin engine — the profile-agnostic machinery shared by every PluginAPI profile
3
+ * (the theme profile in `$lib/PluginAPI.js` and the panel profile in panel-ui).
4
+ *
5
+ * A "profile" is the thin file plugins actually import (`$lib/PluginAPI.js`). It composes the
6
+ * factories exported here — {@link createLifecycleRegistry}, {@link createHookEngine},
7
+ * {@link createSlotRegistry} — into its own `pano.*` namespace tree and re-exports the host
8
+ * contract (`init`, `panoApiClient`, `panoApiServer`). All the ordering/caching/SSR-safety
9
+ * fixes live here once, so both profiles get them.
10
+ *
11
+ * Nothing in this module reads SvelteKit app aliases ($app/environment, the PluginManager) or a
12
+ * theme's utils directly — the profile injects `plugins` and `browser` so this file stays a pure,
13
+ * portable engine that both the theme and panel bundles can consume.
14
+ */
15
+
16
+ import { derived, get, writable } from "svelte/store";
17
+
18
+ // ---------------------------------------------------------------------------
19
+ // Pure utilities
20
+ // ---------------------------------------------------------------------------
21
+
22
+ /**
23
+ * Deduplicate items by id, keeping the last occurrence. Items without an id are all kept
24
+ * (each gets a fresh Symbol key). Mutates `arr` in place.
25
+ */
26
+ export function deduplicateById(arr) {
27
+ const seen = new Map();
28
+ for (const item of arr) {
29
+ if (item.id) seen.set(item.id, item);
30
+ else seen.set(Symbol(), item);
31
+ }
32
+ arr.length = 0;
33
+ arr.push(...seen.values());
34
+ }
35
+
36
+ /**
37
+ * Deep-clone a slot item's serializable parts without touching its `component`
38
+ * (a function / component module that is not structured-cloneable). Used on the server so
39
+ * resolved load() props are merged into a per-request copy instead of the shared global entry.
40
+ */
41
+ export function structuredCloneSafe(item) {
42
+ const { component, ...rest } = item;
43
+ let cloned;
44
+ try {
45
+ cloned = structuredClone(rest);
46
+ } catch {
47
+ // Fallback for values structuredClone can't handle: JSON round-trip the plain data.
48
+ try {
49
+ cloned = JSON.parse(JSON.stringify(rest));
50
+ } catch {
51
+ cloned = { ...rest, props: rest.props ? { ...rest.props } : undefined };
52
+ }
53
+ }
54
+ cloned.component = component;
55
+ return cloned;
56
+ }
57
+
58
+ /**
59
+ * Sort hooks by their stable registration index. Sorting by the hook's importer `.toString()`
60
+ * is unsafe — that source contains build-specific chunk hashes that differ between the server
61
+ * and client bundles, so the two sides produce different orders -> hydration mismatch. The
62
+ * monotonic `_seq` captured at register time is identical across bundles, so it is the only
63
+ * deterministic key.
64
+ */
65
+ export function sortHooks(rawHooks) {
66
+ return [...rawHooks].sort((a, b) => {
67
+ const seqA = a._seq ?? 0;
68
+ const seqB = b._seq ?? 0;
69
+ if (seqA !== seqB) return seqA - seqB;
70
+ // Deterministic tiebreak on a stable id so the total order never depends on bundle internals.
71
+ return String(a.id ?? a.name ?? "").localeCompare(String(b.id ?? b.name ?? ""));
72
+ });
73
+ }
74
+
75
+ /**
76
+ * Comparator for view-slot items: higher priority first, then stable registration sequence
77
+ * (so equal-priority items keep a stable order across SSR and client instead of depending on
78
+ * array insertion order), then id as the final deterministic tiebreak.
79
+ */
80
+ export function compareViewItems(a, b) {
81
+ if (b.priority !== a.priority) return b.priority - a.priority;
82
+ const seqA = a._seq ?? 0;
83
+ const seqB = b._seq ?? 0;
84
+ if (seqA !== seqB) return seqA - seqB;
85
+ return String(a.id ?? "").localeCompare(String(b.id ?? ""));
86
+ }
87
+
88
+ /** A private monotonic counter. Each registry gets its own so hook/view sequences never collide. */
89
+ export function createSeq() {
90
+ let n = 0;
91
+ return () => n++;
92
+ }
93
+
94
+ // ---------------------------------------------------------------------------
95
+ // Lifecycle registry
96
+ // ---------------------------------------------------------------------------
97
+
98
+ /**
99
+ * Named lifecycle hooks (theme:profile:load, panel:posts:load, …). Handlers run with
100
+ * Promise.allSettled so one throwing handler never blocks the others.
101
+ */
102
+ export function createLifecycleRegistry() {
103
+ const lifecycleHandlers = writable({});
104
+
105
+ function on(name, handler) {
106
+ lifecycleHandlers.update((h) => {
107
+ if (!h[name]) h[name] = [];
108
+ h[name].push(handler);
109
+ return h;
110
+ });
111
+ }
112
+
113
+ async function executeLifecycle(name, data, event) {
114
+ const handlers = get(lifecycleHandlers)[name] || [];
115
+ await Promise.allSettled(
116
+ handlers.map(async (handler) => {
117
+ try {
118
+ await handler(data, event);
119
+ } catch (e) {
120
+ console.error(`[Lifecycle:${name}] failed`, e);
121
+ }
122
+ }),
123
+ );
124
+ }
125
+
126
+ function reset() {
127
+ lifecycleHandlers.set({});
128
+ }
129
+
130
+ return { lifecycleHandlers, on, executeLifecycle, reset };
131
+ }
132
+
133
+ // ---------------------------------------------------------------------------
134
+ // Hook engine
135
+ // ---------------------------------------------------------------------------
136
+
137
+ /**
138
+ * Registry of render "hooks" — components mounted into named extension points that can also
139
+ * contribute load() props. Deterministic ordering (via {@link sortHooks}) is crucial for
140
+ * server/client prop synchronization; without it SSR and CSR insertion order drift and hydrate
141
+ * out of sync.
142
+ */
143
+ export function createHookEngine() {
144
+ const hooks = writable({});
145
+ const nextSeq = createSeq();
146
+
147
+ const hookExecutionCache = new WeakMap();
148
+ const componentLoadCache = new WeakMap();
149
+
150
+ function register(options) {
151
+ const { name } = options;
152
+ // Stamp a stable registration index so server and client sort hooks identically.
153
+ const entry = options._seq === undefined ? { ...options, _seq: nextSeq() } : options;
154
+ hooks.update((h) => {
155
+ if (!h[name]) h[name] = [];
156
+ h[name].push(entry);
157
+ return h;
158
+ });
159
+ }
160
+
161
+ function getHook(name) {
162
+ return derived(hooks, ($h) => {
163
+ // Sort by stable registration order. Deterministic order is crucial for server-client
164
+ // prop synchronization (see sortHooks).
165
+ return sortHooks($h[name] || []);
166
+ });
167
+ }
168
+
169
+ function setVisible(name, component, visible) {
170
+ hooks.update((h) => {
171
+ if (!h[name]) return h;
172
+ const idx = h[name].findIndex(
173
+ (item) => item.component === component || item.component?._original === component,
174
+ );
175
+ if (idx !== -1) {
176
+ h[name][idx].invisible = !visible;
177
+ }
178
+ return h;
179
+ });
180
+ }
181
+
182
+ async function executeHookLoad(name, originalEvent) {
183
+ // Prevent double execution of the SAME hook name during the same load cycle
184
+ const event = originalEvent ? { ...originalEvent, hookName: name } : { hookName: name };
185
+ // Use originalEvent as a stable cache key if possible, otherwise fall back to the local event object
186
+ const cacheKey = originalEvent && typeof originalEvent === "object" ? originalEvent : event;
187
+
188
+ if (cacheKey) {
189
+ if (!hookExecutionCache.has(cacheKey)) {
190
+ hookExecutionCache.set(cacheKey, {});
191
+ }
192
+ const cache = hookExecutionCache.get(cacheKey);
193
+ if (cache[name]) {
194
+ return cache[name];
195
+ }
196
+ }
197
+
198
+ const $h = get(hooks);
199
+ // MUST match the sort order used in the 'get' accessor (see sortHooks).
200
+ let list = sortHooks($h[name] || []);
201
+
202
+ // Resolve all modules and execute load functions in parallel
203
+ const results = await Promise.all(
204
+ list.map(async (entry) => {
205
+ const raw = entry.component || entry;
206
+ let module = raw;
207
+ if (typeof raw === "function" && !raw.prototype) {
208
+ module = await raw();
209
+ // Cache the resolved module back into the hooks store
210
+ hooks.update((h) => {
211
+ if (h[name]) {
212
+ // Find the actual index in the original unsorted array
213
+ const actualIdx = h[name].findIndex((item) => (item.component || item) === raw);
214
+ if (actualIdx !== -1) {
215
+ const resolved = { ...module, _original: raw };
216
+ if (module.default) resolved.default = module.default;
217
+
218
+ if (h[name][actualIdx].component) {
219
+ h[name][actualIdx].component = resolved;
220
+ } else {
221
+ // Preserve the stable registration index so re-sorting stays deterministic.
222
+ h[name][actualIdx] = { ...resolved, _seq: h[name][actualIdx]._seq };
223
+ }
224
+ }
225
+ }
226
+ return h;
227
+ });
228
+ } else if (typeof raw !== "object" || !raw.default) {
229
+ module = { default: raw };
230
+ }
231
+
232
+ let props = {};
233
+ const Component = module.default || module;
234
+ const loadFn = module.load || (Component && Component.load);
235
+
236
+ if (loadFn && !entry.skipLoad) {
237
+ // PER-EVENT COMPONENT CACHE: reuse results if this component already loaded for another hook in this event
238
+ let eventCache = null;
239
+ if (cacheKey) {
240
+ if (!componentLoadCache.has(cacheKey)) componentLoadCache.set(cacheKey, new Map());
241
+ eventCache = componentLoadCache.get(cacheKey);
242
+ }
243
+
244
+ if (eventCache && eventCache.has(module)) {
245
+ props = eventCache.get(module);
246
+ } else {
247
+ try {
248
+ props = await loadFn(event);
249
+ if (eventCache) eventCache.set(module, props);
250
+ } catch (e) {
251
+ console.warn(`[Hook:${name}] Load failed`, e);
252
+ }
253
+ }
254
+ }
255
+ return props && typeof props === "object" ? { ...props } : {};
256
+ }),
257
+ );
258
+
259
+ // Cache the final results for this specific hook name
260
+ if (cacheKey && results.length > 0) {
261
+ const cache = hookExecutionCache.get(cacheKey);
262
+ cache[name] = results;
263
+ }
264
+
265
+ return results;
266
+ }
267
+
268
+ function reset() {
269
+ hooks.set({});
270
+ }
271
+
272
+ return { hooks, register, get: getHook, setVisible, executeHookLoad, reset };
273
+ }
274
+
275
+ // ---------------------------------------------------------------------------
276
+ // Slot registry (view slots / sidebars / component containers)
277
+ // ---------------------------------------------------------------------------
278
+
279
+ /**
280
+ * Registry of view-slot items — the components plugins inject into named containers
281
+ * (profile-content, navbar-right, login-content, …), plus the SSR-safe load() pipeline that
282
+ * resolves their code-split modules and merges their load() props.
283
+ *
284
+ * @param {object} deps
285
+ * @param {() => Record<string, any>} deps.getPlugins returns the current plugin map (already
286
+ * `get()`-resolved from the PluginManager `plugins` store). A thunk, not the store itself, so
287
+ * this factory never reads the store at construction — the PluginManager<->PluginAPI import
288
+ * cycle would otherwise put that binding in the temporal dead zone at module-eval time.
289
+ * @param {boolean} deps.browser `$app/environment`'s browser flag — decides whether to clone
290
+ * items per-request on the server.
291
+ * @param {(name: string, data: any, event: any) => Promise<void>} [deps.executeLifecycle]
292
+ * the lifecycle registry's executor, used by executeViewLoad/executeSidebarLoad.
293
+ * @param {string} [deps.lifecyclePrefix] lifecycle-event namespace (default "theme").
294
+ */
295
+ export function createSlotRegistry({ getPlugins, browser, executeLifecycle, lifecyclePrefix = "theme" }) {
296
+ const uiItems = writable({});
297
+ const nextSeq = createSeq();
298
+
299
+ // Version-based UI caching using plugin IDs and versions
300
+ const uiLoadedCacheKeys = new Map(); // Map<containerId, pluginCacheKey>
301
+
302
+ function generatePluginCacheKey() {
303
+ const loadedPlugins = getPlugins();
304
+ if (!loadedPlugins || typeof loadedPlugins !== "object") {
305
+ return "";
306
+ }
307
+ return Object.keys(loadedPlugins)
308
+ .sort()
309
+ .map((pluginId) => {
310
+ const plugin = loadedPlugins[pluginId];
311
+ const version = plugin.version?.version || plugin.version || "dev";
312
+ return `${pluginId}:${version}`;
313
+ })
314
+ .join(",");
315
+ }
316
+
317
+ /** The register+dedupe pattern shared by every `.content.edit` / `.cardRows.edit` helper. */
318
+ function edit(slotId, callback) {
319
+ uiItems.update((items) => {
320
+ if (!items[slotId]) items[slotId] = [];
321
+ callback(items[slotId]);
322
+ deduplicateById(items[slotId]);
323
+ return items;
324
+ });
325
+ }
326
+
327
+ /** Upsert a raw item by id (no dedup/priority/seq stamping) — used by alternativeMethods.add. */
328
+ function upsert(slotId, item) {
329
+ uiItems.update((items) => {
330
+ if (!items[slotId]) items[slotId] = [];
331
+ const existing = items[slotId].findIndex((i) => i.id === item.id);
332
+ if (existing !== -1) {
333
+ items[slotId][existing] = item;
334
+ } else {
335
+ items[slotId].push(item);
336
+ }
337
+ return items;
338
+ });
339
+ }
340
+
341
+ function register(options) {
342
+ const { viewId, id, component, priority = 10 } = options;
343
+ uiItems.update((items) => {
344
+ if (!items[viewId]) items[viewId] = [];
345
+ const existingIdx = items[viewId].findIndex((i) => i.id === id);
346
+ if (existingIdx !== -1) {
347
+ items[viewId][existingIdx] = {
348
+ ...items[viewId][existingIdx],
349
+ component,
350
+ priority,
351
+ // Keep the original registration sequence on re-registration so order stays stable.
352
+ _seq: items[viewId][existingIdx]._seq ?? nextSeq(),
353
+ };
354
+ } else {
355
+ items[viewId].push({ id, component, priority, hidden: false, _seq: nextSeq() });
356
+ }
357
+ return items;
358
+ });
359
+ }
360
+
361
+ function hide(viewId, id) {
362
+ uiItems.update((items) => {
363
+ if (!items[viewId]) return items;
364
+ const item = items[viewId].find((i) => i.id === id);
365
+ if (item) item.hidden = true;
366
+ return items;
367
+ });
368
+ }
369
+
370
+ function show(viewId, id) {
371
+ uiItems.update((items) => {
372
+ if (!items[viewId]) return items;
373
+ const item = items[viewId].find((i) => i.id === id);
374
+ if (item) item.hidden = false;
375
+ return items;
376
+ });
377
+ }
378
+
379
+ function move(viewId, id, priority) {
380
+ uiItems.update((items) => {
381
+ if (!items[viewId]) return items;
382
+ const item = items[viewId].find((i) => i.id === id);
383
+ if (item) item.priority = priority;
384
+ return items;
385
+ });
386
+ }
387
+
388
+ function getView(viewId) {
389
+ return derived(uiItems, ($items) => {
390
+ return ($items[viewId] || []).filter((item) => !item.hidden).sort(compareViewItems);
391
+ });
392
+ }
393
+
394
+ async function executeComponentLoad(containerId, type, event) {
395
+ const freshPluginCacheKey = generatePluginCacheKey();
396
+
397
+ // Cache check removed because UI items are dynamic and rebuilt on navigation
398
+
399
+ const items = get(uiItems)[containerId] || [];
400
+
401
+ const resolvedItems = await Promise.all(
402
+ items.map(async (item) => {
403
+ let module = item.component;
404
+ if (typeof item.component === "function" && !item.component.prototype) {
405
+ try {
406
+ module = await item.component();
407
+ } catch (e) {
408
+ console.error(`[${type}:${containerId}] Failed to load component ${item.id}`, e);
409
+ return item;
410
+ }
411
+ }
412
+
413
+ if (!module) return item;
414
+
415
+ const Component = module.default || module;
416
+ const loadFn = module.load || (Component && Component.load);
417
+
418
+ let props = null;
419
+ if (loadFn) {
420
+ try {
421
+ props = await loadFn(event);
422
+ } catch (e) {
423
+ console.warn(`[${type}:${containerId}:${item.id}] Load failed`, e);
424
+ }
425
+ }
426
+
427
+ // The uiItems store is a process-global singleton, so on the server it is shared across all
428
+ // concurrent requests. A shallow spread of `item` keeps `item.props` (and `item.props.data`)
429
+ // aliased to the global registration entry, so merging resolved load() props would mutate that
430
+ // shared entry -> cross-request data leak and SSR/client divergence. Deep-clone the item's
431
+ // serializable parts on the server so we only ever mutate a per-request copy.
432
+ const baseItem = browser ? item : structuredCloneSafe(item);
433
+ const updatedItem = { ...baseItem, component: module };
434
+ if (props && typeof props === "object" && Object.keys(props).length > 0) {
435
+ if (!updatedItem.props) updatedItem.props = {};
436
+ updatedItem.props.data = { ...updatedItem.props.data, ...props };
437
+ }
438
+
439
+ return updatedItem;
440
+ }),
441
+ );
442
+
443
+ uiItems.update((current) => ({ ...current, [containerId]: resolvedItems }));
444
+ uiLoadedCacheKeys.set(containerId, freshPluginCacheKey);
445
+
446
+ return resolvedItems;
447
+ }
448
+
449
+ async function executeViewLoad(viewId, event) {
450
+ if (executeLifecycle) {
451
+ await executeLifecycle(`${lifecyclePrefix}:view:${viewId}:load`, {}, event);
452
+ }
453
+ return await executeComponentLoad(viewId, "View", event);
454
+ }
455
+
456
+ async function executeSidebarLoad(sidebarId, event) {
457
+ if (executeLifecycle) {
458
+ await executeLifecycle(`${lifecyclePrefix}:sidebar:${sidebarId}:load`, {}, event);
459
+ }
460
+ return await executeComponentLoad(sidebarId, "Sidebar", event);
461
+ }
462
+
463
+ function reset() {
464
+ uiItems.set({});
465
+ uiLoadedCacheKeys.clear();
466
+ }
467
+
468
+ return {
469
+ uiItems,
470
+ uiLoadedCacheKeys,
471
+ generatePluginCacheKey,
472
+ edit,
473
+ upsert,
474
+ register,
475
+ hide,
476
+ show,
477
+ move,
478
+ get: getView,
479
+ executeComponentLoad,
480
+ executeViewLoad,
481
+ executeSidebarLoad,
482
+ reset,
483
+ };
484
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Theme config + view registry.
3
+ *
4
+ * A theme declares overrides in its theme.config.js; the generated root layout
5
+ * shim calls setThemeConfig() as a module side effect, so the registry is
6
+ * populated on both server and client before any load function runs.
7
+ *
8
+ * Core code never imports a theme's view directly — it resolves through
9
+ * resolveView(name, defaultThunk):
10
+ * - theme override registered → the theme's component wins
11
+ * - otherwise → core's default view (code-split via the thunk)
12
+ *
13
+ * If a theme override fails to load at runtime, the default view is used and
14
+ * the failure is logged instead of crashing the page (graceful degradation —
15
+ * the site keeps working while the theme author catches up with a core major).
16
+ */
17
+
18
+ let themeConfig = {};
19
+
20
+ export function setThemeConfig(config) {
21
+ themeConfig = config ?? {};
22
+ }
23
+
24
+ export function getThemeConfig() {
25
+ return themeConfig;
26
+ }
27
+
28
+ /** Theme-declared extensions to the theme-settings schema (P2). */
29
+ export function getSettingsSchemaExtension() {
30
+ return themeConfig.settingsSchema ?? null;
31
+ }
32
+
33
+ import { dev } from "$app/environment";
34
+
35
+ const overrideCache = new Map();
36
+
37
+ /**
38
+ * @param {string} name stable view id, e.g. "LoginView" — part of the theme contract
39
+ * @param {() => Promise<any>} defaultThunk core's default view module thunk
40
+ * @returns {Promise<any>} the Svelte component to render
41
+ */
42
+ export async function resolveView(name, defaultThunk) {
43
+ const override = themeConfig.views?.[name];
44
+
45
+ if (override) {
46
+ // Never cache in dev: the cache would pin the module instance from the
47
+ // first request, so view-file edits (and core fixes) would silently not
48
+ // apply until a full dev-server restart. Vite already dedupes and
49
+ // HMR-invalidates the underlying import() calls.
50
+ if (dev) {
51
+ return Promise.resolve(
52
+ typeof override === "function" ? override() : override,
53
+ ).then(
54
+ (mod) => mod?.default ?? mod,
55
+ (e) => {
56
+ console.error(
57
+ `[theme-core] view override '${name}' failed to load; falling back to the default view`,
58
+ e,
59
+ );
60
+ return defaultThunk().then((m) => m?.default ?? m);
61
+ },
62
+ );
63
+ }
64
+
65
+ let cached = overrideCache.get(name);
66
+ if (!cached) {
67
+ cached = Promise.resolve(
68
+ typeof override === "function" ? override() : override,
69
+ ).then(
70
+ (mod) => mod?.default ?? mod,
71
+ (e) => {
72
+ console.error(
73
+ `[theme-core] view override '${name}' failed to load; falling back to the default view`,
74
+ e,
75
+ );
76
+ overrideCache.delete(name);
77
+ return defaultThunk().then((m) => m?.default ?? m);
78
+ },
79
+ );
80
+ overrideCache.set(name, cached);
81
+ }
82
+ return cached;
83
+ }
84
+
85
+ return defaultThunk().then((m) => m?.default ?? m);
86
+ }
@@ -0,0 +1,21 @@
1
+ <script>
2
+ import { page } from "$app/stores";
3
+ import AppLayout from "$pano/lib/layouts/AppLayout.svelte";
4
+ import MainLayout from "$pano/lib/layouts/MainLayout.svelte";
5
+
6
+ export let data;
7
+
8
+ $: isThemeSettings = $page.route.id?.includes("(theme-settings)");
9
+ $: isResetLayout = $page.data.resetLayout;
10
+ $: showMainLayout = !isThemeSettings && !isResetLayout;
11
+ </script>
12
+
13
+ <AppLayout {data}>
14
+ {#if showMainLayout}
15
+ <MainLayout>
16
+ <slot />
17
+ </MainLayout>
18
+ {:else}
19
+ <slot />
20
+ {/if}
21
+ </AppLayout>