@panomc/theme-core 1.0.0-dev.53 → 1.0.0-dev.55

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/bin/new.js CHANGED
@@ -288,11 +288,13 @@ export const { handle, handleError, handleFetch } = createThemeHooks({
288
288
  "src/hooks.client.js": `import {
289
289
  installRuntimeRegistry,
290
290
  createClientInit,
291
+ createClientHandleError,
291
292
  } from "$pano/kit/hooks-client.js";
292
293
 
293
294
  installRuntimeRegistry();
294
295
 
295
296
  export const init = createClientInit();
297
+ export const handleError = createClientHandleError();
296
298
  `,
297
299
 
298
300
  "src/styles/tokens.scss": `// Design tokens — imported FIRST by style.scss, so anything you set here
@@ -8,17 +8,17 @@
8
8
  // module map for the lifetime of the document (per HTML spec), so a single
9
9
  // transient 404/network error on any script chunk leaves the SSR'd page
10
10
  // permanently dead with no retry. Recover with ONE cache-busting reload;
11
- // hooks.client.js clears the flag once the app boots successfully.
11
+ // RootLayout calls markAppBooted() once the page really hydrated.
12
12
  (function () {
13
13
  var KEY = "pano:hydration-reload";
14
14
  var MODULE_ERROR =
15
15
  /(failed to fetch dynamically imported module|error loading dynamically imported module|importing a module script failed|failed to resolve module specifier|import map|pano-runtime|failed to load module script)/i;
16
16
  function recover(message) {
17
17
  // Only rescue pages whose boot never completed (dead SSR page with a
18
- // poisoned module map). After a successful boot (hooks.client init sets
19
- // the flag) a failing module import is a plugin's own runtime problem —
20
- // reloading would loop forever since init also re-arms the sessionStorage
21
- // guard on every successful boot.
18
+ // poisoned module map). After a successful boot (RootLayout's onMount sets
19
+ // the flag via markAppBooted) a failing module import is a plugin's own
20
+ // runtime problem — reloading would loop forever since markAppBooted also
21
+ // re-arms the sessionStorage guard on every successful boot.
22
22
  if (window.__PANO_APP_BOOTED__) return;
23
23
  if (!MODULE_ERROR.test(String(message || ""))) return;
24
24
  try {
package/lang/en-US.json CHANGED
@@ -443,8 +443,10 @@
443
443
  }
444
444
  },
445
445
  "page-errors": {
446
+ "title": "Error: {status}",
446
447
  "404": "The page is not found!",
447
448
  "404-description": "The page you're looking for doesn't exist or has been moved.",
449
+ "assets-failed": "Some of the page's files could not be loaded. Please refresh the page; if it keeps happening, contact support.",
448
450
  "need-help": "If you believe this is an error, please contact support."
449
451
  },
450
452
  "ticket-statuses": {
package/lang/ru.json CHANGED
@@ -443,8 +443,10 @@
443
443
  }
444
444
  },
445
445
  "page-errors": {
446
+ "title": "Ошибка: {status}",
446
447
  "404": "Страница не найдена!",
447
448
  "404-description": "Страница, которую вы ищете, не существует или была перенесена.",
449
+ "assets-failed": "Не удалось загрузить часть файлов страницы. Обновите страницу; если ошибка повторяется, обратитесь в поддержку.",
448
450
  "need-help": "Если вы считаете, что это ошибка, обратитесь в поддержку."
449
451
  },
450
452
  "ticket-statuses": {
package/lang/tr.json CHANGED
@@ -443,8 +443,10 @@
443
443
  }
444
444
  },
445
445
  "page-errors": {
446
+ "title": "Hata: {status}",
446
447
  "404": "Aradığınız sayfa bulunamadı!",
447
448
  "404-description": "Aradığınız sayfa mevcut değil veya taşınmış olabilir.",
449
+ "assets-failed": "Sayfanın bazı dosyaları yüklenemedi. Lütfen sayfayı yenileyin; devam ederse destek ile iletişime geçin.",
448
450
  "need-help": "Bunun bir hata olduğunu düşünüyorsanız, lütfen destek ile iletişime geçin."
449
451
  },
450
452
  "ticket-statuses": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panomc/theme-core",
3
- "version": "1.0.0-dev.53",
3
+ "version": "1.0.0-dev.55",
4
4
  "description": "The Pano theme engine: hooks factories, plugin engine, headless page controllers, default views and the theme CLI. Themes depend on this package instead of forking vanilla-theme.",
5
5
  "author": "PanoMC",
6
6
  "license": "MIT",
@@ -101,20 +101,72 @@ export function installRuntimeRegistry() {
101
101
  g.__PANO_RT_RESOLVE__?.(g.__PANO_RUNTIME__);
102
102
  }
103
103
 
104
+ const HYDRATION_RELOAD_KEY = "pano:hydration-reload";
105
+
106
+ /**
107
+ * Tells the hydration watchdog in app.html that this document booted. Until this runs, a
108
+ * failed module fetch (a chunk 502'd behind a proxy/CDN, a stale hash after an update) makes
109
+ * the watchdog reload the page once with a cache-busting query; afterwards a failing import is
110
+ * a plugin's own runtime problem and must not reload.
111
+ *
112
+ * Call it once the root layout has hydrated WITHOUT an error page — not from the SvelteKit
113
+ * `init` hook. `init` runs before hydration, before the route chunks are even requested, so a
114
+ * flag set there disarmed the watchdog exactly when it was needed and left visitors on a dead
115
+ * error page.
116
+ */
117
+ export function markAppBooted() {
118
+ if (!browser) return;
119
+
120
+ globalThis.__PANO_APP_BOOTED__ = true;
121
+
122
+ try {
123
+ // Re-arm the one-shot reload guard for the NEXT document.
124
+ sessionStorage.removeItem(HYDRATION_RELOAD_KEY);
125
+ } catch {
126
+ /* sessionStorage unavailable (e.g. blocked); the watchdog degrades gracefully */
127
+ }
128
+ }
129
+
130
+ /** Matches every browser's wording for a script chunk that could not be fetched/parsed. */
131
+ const MODULE_LOAD_ERROR =
132
+ /(failed to fetch dynamically imported module|error loading dynamically imported module|importing a module script failed|failed to load module script|failed to resolve module specifier)/i;
133
+
134
+ /**
135
+ * Client-side error hook. SvelteKit's default only prints the error; this one also names the
136
+ * page and the status, flags chunk-load failures (the classic "SSR fine, hydration dead"
137
+ * symptom: a proxy/CDN served HTML or a 5xx for a JS module) and hands the error page a code
138
+ * so it can tell the visitor to refresh instead of "report this".
139
+ *
140
+ * A theme's src/hooks.client.js exports it as:
141
+ *
142
+ * export const handleError = createClientHandleError();
143
+ */
144
+ export function createClientHandleError() {
145
+ /** @type {import('@sveltejs/kit').HandleClientError} */
146
+ return function handleError({ error, event, status, message }) {
147
+ const text = String(error?.message ?? error ?? "");
148
+ const moduleLoadFailed = MODULE_LOAD_ERROR.test(text);
149
+ const where = `${event?.url?.pathname ?? location.pathname} (status ${status})`;
150
+
151
+ console.error(
152
+ moduleLoadFailed
153
+ ? `[pano] a script chunk failed to load on ${where}; the page cannot hydrate:`
154
+ : `[pano] client error on ${where}:`,
155
+ error,
156
+ );
157
+
158
+ return {
159
+ message: moduleLoadFailed ? "Page files could not be loaded" : message,
160
+ code: moduleLoadFailed ? "MODULE_LOAD_FAILED" : error?.code,
161
+ };
162
+ };
163
+ }
164
+
104
165
  export function createClientInit() {
105
166
  /** @type {import('@sveltejs/kit').ClientInit} */
106
167
  return async function init() {
107
- // Hydration succeeded far enough to run app code: disarm the watchdog for this
108
- // document (post-boot module failures must not reload), re-arm the one-shot
109
- // reload guard for the NEXT document, and drop the cache-busting marker.
110
- globalThis.__PANO_APP_BOOTED__ = true;
111
-
112
- try {
113
- sessionStorage.removeItem("pano:hydration-reload");
114
- } catch {
115
- /* sessionStorage unavailable (e.g. blocked); the watchdog degrades gracefully */
116
- }
117
-
168
+ // Only cosmetic cleanup belongs here: `init` runs before hydration, so it must NOT mark the
169
+ // app as booted — see markAppBooted(), called from RootLayout after a successful mount.
118
170
  try {
119
171
  const url = new URL(location.href);
120
172
  if (url.searchParams.has("pano-rl")) {
package/src/lib/Store.js CHANGED
@@ -3,7 +3,7 @@ import { writable } from "svelte/store";
3
3
  import { sendLogout } from "$pano/lib/services/auth.js";
4
4
  import { goto } from "$app/navigation";
5
5
  import { redirect } from "@sveltejs/kit";
6
- import { show as showToast } from "$pano/lib/components/ToastContainer.svelte";
6
+ import { showSuccess as showSuccessToast } from "$pano/lib/components/ToastContainer.svelte";
7
7
 
8
8
  export const notificationsCount = writable(0);
9
9
  export const quickNotifications = writable([]);
@@ -25,7 +25,7 @@ export async function logout(session) {
25
25
  });
26
26
  }
27
27
 
28
- await showToast("toasts.session-logged-out-successful");
28
+ await showSuccessToast("toasts.session-logged-out-successful");
29
29
  await goto("/");
30
30
  });
31
31
  }
@@ -1,4 +1,4 @@
1
- <Toast {id}>{@html $_(text, { values })}</Toast>
1
+ <Toast {id} {variant}>{@html $_(text, { values })}</Toast>
2
2
 
3
3
  <script>
4
4
  import { _ } from 'svelte-i18n';
@@ -8,4 +8,5 @@
8
8
  export let id;
9
9
  export let text;
10
10
  export let values;
11
+ export let variant = null;
11
12
  </script>
@@ -61,7 +61,14 @@
61
61
  const resolved = await Promise.all(
62
62
  list.map(async (h) => {
63
63
  if (typeof h === "function" && !h.prototype) {
64
- return await h();
64
+ try {
65
+ return await h();
66
+ } catch (e) {
67
+ // Keep the unresolved thunk so the markup's `typeof module !== 'function'` guard
68
+ // skips this hook instead of the whole effect rejecting.
69
+ console.error(`[Hook:${name}] Failed to load plugin module`, e);
70
+ return h;
71
+ }
65
72
  }
66
73
  return h;
67
74
  }),
@@ -1,6 +1,6 @@
1
1
  <div
2
2
  id="appToast{id}"
3
- class="animate__animated animate__bounceInUp toast align-items-center shadow-lg text-bg-tertiary opacity-100"
3
+ class="animate__animated animate__bounceInUp toast align-items-center shadow-lg text-bg-tertiary opacity-100 {variantClass}"
4
4
  role="alert"
5
5
  aria-live="assertive"
6
6
  aria-atomic="true"
@@ -10,4 +10,16 @@
10
10
 
11
11
  <script>
12
12
  export let id;
13
+
14
+ // 'success' | 'danger' | null. Mapped instead of interpolated straight into the class
15
+ // list so a caller can't inject an arbitrary utility class, and so a neutral toast
16
+ // keeps text-bg-tertiary's own contrast colour.
17
+ export let variant = null;
18
+
19
+ const VARIANT_CLASSES = {
20
+ success: 'text-success',
21
+ danger: 'text-danger',
22
+ };
23
+
24
+ $: variantClass = VARIANT_CLASSES[variant] ?? '';
13
25
  </script>
@@ -29,13 +29,16 @@
29
29
  return new Promise((resolve) => setTimeout(resolve, time));
30
30
  }
31
31
 
32
- export async function show(text, params = {}, toastComponent = DefaultToast) {
32
+ // `options.variant` ('success' | 'danger') colours the toast text. Prefer the
33
+ // showSuccess/showError wrappers below at call sites — they read as the outcome they
34
+ // report. Plain `show` stays neutral for toasts that are neither.
35
+ export async function show(text, params = {}, toastComponent = DefaultToast, options = {}) {
33
36
  if (text) {
34
37
  params.text = text;
35
38
  }
36
39
 
37
40
  if (toastComponent === DefaultToast) {
38
- params = { text, values: params };
41
+ params = { text, values: params, variant: options.variant ?? null };
39
42
  }
40
43
 
41
44
  const toast = { component: toastComponent, params };
@@ -71,6 +74,17 @@
71
74
  }
72
75
  }
73
76
 
77
+ // No toastComponent parameter on purpose: `variant` is only threaded into
78
+ // DefaultToast's props, so a custom component would silently drop it. Reach for
79
+ // `show` directly when you need one.
80
+ export function showSuccess(text, params = {}) {
81
+ return show(text, params, DefaultToast, { variant: 'success' });
82
+ }
83
+
84
+ export function showError(text, params = {}) {
85
+ return show(text, params, DefaultToast, { variant: 'danger' });
86
+ }
87
+
74
88
  export function limitTitle(text) {
75
89
  const limit = 32;
76
90
 
@@ -68,7 +68,7 @@
68
68
  import { currentLanguage } from "$pano/lib/language.util";
69
69
 
70
70
  import { getCredentials, sendLogin, sendRegister, verifyLinkCode } from "$pano/lib/services/auth.js";
71
- import { show as showToast } from "$pano/lib/components/ToastContainer.svelte";
71
+ import { showSuccess as showSuccessToast } from "$pano/lib/components/ToastContainer.svelte";
72
72
 
73
73
  import { stripIdentifierWhitespace } from "$pano/lib/loginInput.util.js";
74
74
  import { panoApiClient } from "$pano/lib/PluginAPI.js";
@@ -232,7 +232,7 @@
232
232
  return data;
233
233
  });
234
234
 
235
- await showToast("successes.LOGIN_SUCCESSFUL");
235
+ await showSuccessToast("successes.LOGIN_SUCCESSFUL");
236
236
  await goto("/");
237
237
  return;
238
238
  }
@@ -247,7 +247,7 @@
247
247
  return;
248
248
  }
249
249
 
250
- await showToast("successes.REGISTER_SUCCESSFUL");
250
+ await showSuccessToast("successes.REGISTER_SUCCESSFUL");
251
251
 
252
252
  const loginBody = await sendLogin({ usernameOrEmail: $usernameOrEmail, password: $password });
253
253
  if (loginBody.result !== "ok") {
@@ -408,7 +408,7 @@
408
408
  return data;
409
409
  });
410
410
 
411
- await showToast("successes.LOGIN_SUCCESSFUL");
411
+ await showSuccessToast("successes.LOGIN_SUCCESSFUL");
412
412
 
413
413
  await goto("/");
414
414
 
@@ -56,7 +56,7 @@
56
56
  import { NETWORK_ERROR } from "$pano/lib/api.util";
57
57
 
58
58
  import PageTitle from "$pano/lib/components/PageTitle.svelte";
59
- import { show as showToast } from "$pano/lib/components/ToastContainer.svelte";
59
+ import { showSuccess as showSuccessToast } from "$pano/lib/components/ToastContainer.svelte";
60
60
 
61
61
  import { sendRegister, getCredentials } from "$pano/lib/services/auth.js";
62
62
  import { panoApiClient } from "$pano/lib/PluginAPI.js";
@@ -115,7 +115,7 @@
115
115
  return data;
116
116
  });
117
117
 
118
- await showToast("successes.LOGIN_SUCCESSFUL");
118
+ await showSuccessToast("successes.LOGIN_SUCCESSFUL");
119
119
  await goto("/");
120
120
  loading.set(false);
121
121
  return;
@@ -62,7 +62,8 @@
62
62
  <script>
63
63
  import { _ } from "svelte-i18n";
64
64
  import {
65
- showToast,
65
+ showSuccessToast,
66
+ showErrorToast,
66
67
  showConfirm
67
68
  } from "$pano/lib/ui-logics/layout-logics/ThemeSettingsLayoutLogics";
68
69
  import { getContext } from "svelte";
@@ -479,7 +480,7 @@
479
480
  $themeSettings = newSettings;
480
481
  originalThemeSettings.set(structuredClone($themeSettings));
481
482
 
482
- showToast(
483
+ showSuccessToast(
483
484
  $_("messages.settings-save-success") || "Ayarlar başarıyla kaydedildi!"
484
485
  );
485
486
  $saving = false;
@@ -516,7 +517,7 @@
516
517
  $themeSettings = newSettings;
517
518
  originalThemeSettings.set(structuredClone($themeSettings));
518
519
 
519
- showToast(
520
+ showSuccessToast(
520
521
  $_("messages.settings-reset-tab-success") ||
521
522
  "Sekme ayarları sıfırlandı!"
522
523
  );
@@ -539,10 +540,10 @@
539
540
  $themeSettings = newSettings;
540
541
  originalThemeSettings.set(structuredClone($themeSettings));
541
542
 
542
- showToast($_("messages.settings-reset-all-success"));
543
+ showSuccessToast($_("messages.settings-reset-all-success"));
543
544
  } catch (error) {
544
545
  console.error("Failed to reset all settings:", error);
545
- showToast($_("messages.settings-reset-all-error"));
546
+ showErrorToast($_("messages.settings-reset-all-error"));
546
547
  } finally {
547
548
  $resettingAll = false;
548
549
  }
@@ -21,8 +21,21 @@ function postReady() {
21
21
  window.parent.postMessage({ type: "theme-settings-ready" }, "*");
22
22
  }
23
23
 
24
- export function showToast(text, params = {}, toastComponent) {
25
- window.parent.postMessage({ type: "show-toast", text, params, toastComponent }, "*");
24
+ // The theme settings UI runs inside an iframe in the panel, so its toasts are posted to
25
+ // the parent instead of rendered here. `variant` ('success' | 'danger') rides along so the
26
+ // panel can colour the toast — without it the panel has no way to tell an outcome from a
27
+ // failure and has to fall back to a neutral toast. A panel build that predates the field
28
+ // simply ignores it.
29
+ export function showToast(text, params = {}, toastComponent, variant = null) {
30
+ window.parent.postMessage({ type: "show-toast", text, params, toastComponent, variant }, "*");
31
+ }
32
+
33
+ export function showSuccessToast(text, params = {}) {
34
+ showToast(text, params, undefined, "success");
35
+ }
36
+
37
+ export function showErrorToast(text, params = {}) {
38
+ showToast(text, params, undefined, "danger");
26
39
  }
27
40
 
28
41
  const confirmCallbacks = new Map();
@@ -183,11 +183,16 @@ export async function onLogoutSession(sessionId, loadingSessionId, showToast, in
183
183
  loadingSessionId.set(null);
184
184
 
185
185
  if (body.error) {
186
- await showToast('errors.' + body.error);
186
+ // The variant rides on `show`'s options argument rather than a separate
187
+ // showError parameter: onLogoutSession receives the toast function from the
188
+ // view, and widening that signature would be a breaking controller-props change.
189
+ await showToast('errors.' + body.error, {}, undefined, { variant: 'danger' });
187
190
  return;
188
191
  }
189
192
 
190
- await showToast('toasts.session-logged-out-successful');
193
+ await showToast('toasts.session-logged-out-successful', {}, undefined, {
194
+ variant: 'success',
195
+ });
191
196
  invalidateAll();
192
197
  },
193
198
  });
@@ -3,16 +3,18 @@
3
3
  Controller: $pano/lib/pages/ErrorPage.svelte
4
4
  Props:
5
5
  data object|undefined — undefined when rendered as +error.svelte (no load runs); kept for the shared controller contract
6
- page object — SvelteKit's reactive page state ($app/state); page.status picks the 404 vs. internal-error message
6
+ page object — SvelteKit's reactive page state ($app/state); page.status drives the title; page.status / page.error.code pick the 404, chunk-load or internal-error message
7
7
  Override from a theme:
8
8
  theme.config.js → views: { ErrorView: () => import("./src/views/ErrorView.svelte") }
9
9
  -->
10
10
  <div class="vstack gap-3">
11
11
  <PageTitle
12
- title="Hata: 404"
12
+ title={$_("page-errors.title", { values: { status: page.status }, default: `Error: ${page.status}` })}
13
13
  subtitle={page.status === 404
14
14
  ? $_("page-errors.404-description")
15
- : $_("errors.INTERNAL_SERVER_ERROR")} />
15
+ : page.error?.code === "MODULE_LOAD_FAILED"
16
+ ? $_("page-errors.assets-failed")
17
+ : $_("errors.INTERNAL_SERVER_ERROR")} />
16
18
 
17
19
  <div class="text-center mb-3">
18
20
  <img src="/assets/img/404.png" alt="Error" width="256" height="auto" />
@@ -205,7 +205,17 @@ export function createHookEngine() {
205
205
  const raw = entry.component || entry;
206
206
  let module = raw;
207
207
  if (typeof raw === "function" && !raw.prototype) {
208
- module = await raw();
208
+ try {
209
+ module = await raw();
210
+ } catch (e) {
211
+ // One plugin's chunk failing to load (a 502 behind a proxy/CDN, a stale hash after
212
+ // an update) must cost that plugin its slot, not the whole page: a throw here
213
+ // propagates out of the page's universal load and SvelteKit renders a 500. Leave
214
+ // the entry unresolved so Hook.svelte skips it, and keep the result aligned with
215
+ // the hook list (hookProps is indexed by position).
216
+ console.error(`[Hook:${name}] Failed to load plugin module`, e);
217
+ return {};
218
+ }
209
219
  // Cache the resolved module back into the hooks store
210
220
  hooks.update((h) => {
211
221
  if (h[name]) {
@@ -1,5 +1,7 @@
1
1
  <script>
2
+ import { onMount } from "svelte";
2
3
  import { page } from "$app/stores";
4
+ import { markAppBooted } from "$pano/kit/hooks-client.js";
3
5
  import AppLayout from "$pano/lib/layouts/AppLayout.svelte";
4
6
  import MainLayout from "$pano/lib/layouts/MainLayout.svelte";
5
7
 
@@ -8,6 +10,15 @@
8
10
  $: isThemeSettings = $page.route.id?.includes("(theme-settings)");
9
11
  $: isResetLayout = $page.data.resetLayout;
10
12
  $: showMainLayout = !isThemeSettings && !isResetLayout;
13
+
14
+ onMount(() => {
15
+ // Arms the hydration watchdog's "booted" state only after the page really rendered. An
16
+ // error render (a route chunk that failed to load) keeps it unarmed so the watchdog can
17
+ // still issue its one recovery reload.
18
+ if (!$page.error) {
19
+ markAppBooted();
20
+ }
21
+ });
11
22
  </script>
12
23
 
13
24
  <AppLayout {data}>