@panomc/theme-core 1.0.0-dev.59 → 1.0.0-dev.61
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/assets/css/pano-fallback-legacy.css +12381 -0
- package/assets/css/pano-fallback.css +3222 -0
- package/bin/__tests__/check/fixtures/plugin-contracts/market/controllers.json +4 -0
- package/bin/__tests__/check/fixtures/plugin-contracts/market/views.json +67 -0
- package/bin/__tests__/check/fixtures/routes.json +5 -0
- package/bin/__tests__/check/helpers.js +55 -0
- package/bin/__tests__/check/overrides.test.js +287 -0
- package/bin/__tests__/check/theme.test.js +332 -0
- package/bin/__tests__/cli/accept-and-list.test.js +159 -0
- package/bin/__tests__/cli/config-edit.test.js +213 -0
- package/bin/__tests__/cli/contracts-pull.test.js +187 -0
- package/bin/__tests__/cli/core-meta.test.js +305 -0
- package/bin/__tests__/cli/eject-view.test.js +356 -0
- package/bin/__tests__/cli/helpers.js +258 -0
- package/bin/__tests__/scaffold/scaffold.test.js +84 -0
- package/bin/bundle-internal-libs.js +14 -2
- package/bin/check.js +1150 -213
- package/bin/contracts.js +1643 -0
- package/bin/generate-contract.js +378 -0
- package/bin/generate-licenses.js +14 -2
- package/bin/generate-runtime-shims.js +27 -9
- package/bin/new.js +101 -2
- package/bin/package-zip.js +16 -2
- package/bin/sync.js +360 -7
- package/bin/theme-core.js +65 -107
- package/lang/en-US.json +1 -0
- package/lang/ru.json +1 -0
- package/lang/tr.json +1 -0
- package/package.json +7 -3
- package/skin-contract.json +864 -19
- package/src/kit/__tests__/hooks-server-fetch.test.js +56 -0
- package/src/kit/__tests__/route-map.test.js +154 -0
- package/src/kit/__tests__/theme-meta.test.js +249 -0
- package/src/kit/hooks-client.js +3 -0
- package/src/kit/hooks-server.js +91 -7
- package/src/kit/route-map.js +300 -0
- package/src/kit/specifiers.js +3 -0
- package/src/kit/svelte-config.js +3 -0
- package/src/kit/theme-meta.js +405 -0
- package/src/kit/vite-config.js +156 -12
- package/src/lib/NotificationManager.js +18 -0
- package/src/lib/PluginAPI.js +313 -9
- package/src/lib/Store.js +18 -5
- package/src/lib/__tests__/avatarVersion.test.js +25 -0
- package/src/lib/__tests__/check.test.js +201 -0
- package/src/lib/__tests__/controllerHost.test.js +363 -0
- package/src/lib/__tests__/cx03.test.js +245 -0
- package/src/lib/__tests__/engineBoot.test.js +151 -0
- package/src/lib/__tests__/engineParts.helper.js +284 -0
- package/src/lib/__tests__/engineParts.test.js +179 -0
- package/src/lib/__tests__/engineSidebars.helper.js +353 -0
- package/src/lib/__tests__/engineSidebars.test.js +273 -0
- package/src/lib/__tests__/engineStyles.test.js +227 -0
- package/src/lib/__tests__/engineWiring.test.js +1000 -0
- package/src/lib/__tests__/fallbackStyles.test.js +1254 -0
- package/src/lib/__tests__/fixtures/Probe.svelte +5 -0
- package/src/lib/__tests__/fixtures/engine-parts.ssr.json +29 -0
- package/src/lib/__tests__/fixtures/engine-sidebars.ssr.json +16 -0
- package/src/lib/__tests__/home.test.js +563 -0
- package/src/lib/__tests__/injectedScope.test.js +490 -0
- package/src/lib/__tests__/languageConcurrency.test.js +55 -0
- package/src/lib/__tests__/languageLayers.test.js +286 -0
- package/src/lib/__tests__/pageHead.test.js +167 -0
- package/src/lib/__tests__/pageMeta.util.test.js +216 -0
- package/src/lib/__tests__/pageTitle.util.test.js +96 -0
- package/src/lib/__tests__/pluginApiViews.test.js +529 -0
- package/src/lib/__tests__/plugins.test.js +53 -0
- package/src/lib/__tests__/profileNav.util.test.js +145 -0
- package/src/lib/__tests__/registryReady.test.js +26 -0
- package/src/lib/__tests__/returnTo.util.test.js +294 -0
- package/src/lib/__tests__/routeConfig.test.js +361 -0
- package/src/lib/__tests__/sidebarSpec.util.test.js +152 -0
- package/src/lib/__tests__/skinContract.test.js +558 -0
- package/src/lib/__tests__/svelteSsr.helper.js +68 -0
- package/src/lib/__tests__/tc03.test.js +427 -0
- package/src/lib/__tests__/tc11.test.js +184 -0
- package/src/lib/__tests__/translationLayers.test.js +161 -0
- package/src/lib/avatarVersion.js +39 -0
- package/src/lib/components/Breadcrumb.svelte +9 -40
- package/src/lib/components/Date.svelte +1 -1
- package/src/lib/components/DefaultToast.svelte +13 -3
- package/src/lib/components/FallbackLinks.svelte +28 -0
- package/src/lib/components/FallbackScope.svelte +24 -0
- package/src/lib/components/Footer.svelte +8 -8
- package/src/lib/components/Header.svelte +3 -3
- package/src/lib/components/Hook.svelte +12 -1
- package/src/lib/components/LoginFormBody.svelte +5 -5
- package/src/lib/components/Main.svelte +22 -47
- package/src/lib/components/Navbar.svelte +30 -29
- package/src/lib/components/NoContent.svelte +2 -2
- package/src/lib/components/NotificationContainer.svelte +31 -82
- package/src/lib/components/OnlineAdmins.svelte +3 -2
- package/src/lib/components/PageActions.svelte +1 -1
- package/src/lib/components/PageHead.svelte +50 -0
- package/src/lib/components/PageTitle.svelte +2 -2
- package/src/lib/components/Pagination.svelte +6 -6
- package/src/lib/components/PlayerHead.svelte +4 -4
- package/src/lib/components/PluginBlock.svelte +132 -0
- package/src/lib/components/PluginSlot.svelte +40 -0
- package/src/lib/components/Post.svelte +13 -230
- package/src/lib/components/Posts.svelte +7 -14
- package/src/lib/components/RegisterForm.svelte +12 -11
- package/src/lib/components/Sidebar.svelte +9 -7
- package/src/lib/components/TicketRow.svelte +8 -48
- package/src/lib/components/TicketStatus.svelte +10 -16
- package/src/lib/components/Tickets.svelte +8 -30
- package/src/lib/components/Toast.svelte +16 -14
- package/src/lib/components/ToastContainer.svelte +16 -9
- package/src/lib/components/ViewComponent.svelte +13 -1
- package/src/lib/components/modals/CloseTicketConfirmModal.svelte +15 -46
- package/src/lib/components/modals/ConfirmRemoveAllNotificationsModal.svelte +17 -39
- package/src/lib/components/modals/LogoutSessionConfirmModal.svelte +12 -30
- package/src/lib/components/sidebars/HomeSidebar.svelte +33 -284
- package/src/lib/components/sidebars/PlayerDetailSidebar.svelte +14 -63
- package/src/lib/components/sidebars/PluginSidebar.svelte +21 -0
- package/src/lib/components/sidebars/ProfileNavCard.svelte +24 -0
- package/src/lib/components/sidebars/ProfileSidebar.svelte +44 -84
- package/src/lib/components/sidebars/SupportSidebar.svelte +19 -22
- package/src/lib/components/sidebars/TicketCreateAndDetailSidebar.svelte +23 -35
- package/src/lib/components/sidebars/profileNav.util.js +105 -0
- package/src/lib/components/sidebars/sidebarSpec.util.js +92 -0
- package/src/lib/controllerHost.js +261 -0
- package/src/lib/fallbackStyles.js +317 -0
- package/src/lib/home.js +202 -0
- package/src/lib/language.util.js +70 -37
- package/src/lib/layouts/AppLayout.svelte +16 -8
- package/src/lib/layouts/AuthLayout.svelte +6 -4
- package/src/lib/layouts/MainLayout.svelte +17 -12
- package/src/lib/layouts/ProfileLayout.svelte +6 -4
- package/src/lib/layouts/ThemeSettingsLayout.svelte +6 -4
- package/src/lib/layouts/TicketsLayout.svelte +6 -5
- package/src/lib/pageMeta.util.js +212 -0
- package/src/lib/pageShape.js +33 -0
- package/src/lib/pageTitle.util.js +32 -0
- package/src/lib/pages/ActivateEmailPage.svelte +2 -7
- package/src/lib/pages/ConfirmNewEmailPage.svelte +2 -7
- package/src/lib/pages/ErrorPage.svelte +5 -2
- package/src/lib/pages/HomePage.svelte +31 -8
- package/src/lib/pages/LoginPage.svelte +38 -41
- package/src/lib/pages/NotificationsPage.svelte +2 -7
- package/src/lib/pages/PlayerDetailPage.svelte +2 -7
- package/src/lib/pages/PostDetailPage.svelte +2 -7
- package/src/lib/pages/PreviewPostPage.svelte +2 -7
- package/src/lib/pages/RegisterPage.svelte +10 -13
- package/src/lib/pages/RenewPasswordPage.svelte +2 -7
- package/src/lib/pages/ResetPasswordPage.svelte +2 -7
- package/src/lib/pages/RulesPage.svelte +3 -8
- package/src/lib/pages/SupportPage.svelte +2 -7
- package/src/lib/pages/ThemeSettingsPage.svelte +2 -7
- package/src/lib/pages/profile/ProfilePage.svelte +2 -7
- package/src/lib/pages/profile/SettingsPage.svelte +2 -7
- package/src/lib/pages/profile/TicketsPage.svelte +2 -7
- package/src/lib/pages/ticket/CreateTicketPage.svelte +2 -7
- package/src/lib/pages/ticket/TicketDetailPage.svelte +2 -7
- package/src/lib/plugins.js +61 -0
- package/src/lib/returnTo.util.js +116 -0
- package/src/lib/services/auth.js +11 -11
- package/src/lib/services/posts.js +21 -10
- package/src/lib/services/profile.js +5 -5
- package/src/lib/services/theme-setting.js +1 -1
- package/src/lib/services/tickets.js +36 -15
- package/src/lib/siteRealtime.js +55 -8
- package/src/lib/themePageLoad.js +38 -0
- package/src/lib/translationLayers.js +144 -0
- package/src/lib/ui-logics/layout-logics/AppLayoutLogics.js +160 -6
- package/src/lib/ui-logics/layout-logics/AuthLayoutLogics.js +3 -2
- package/src/lib/ui-logics/layout-logics/ProfileLayoutLogics.js +3 -2
- package/src/lib/ui-logics/layout-logics/TicketsLayoutLogics.js +3 -2
- package/src/lib/ui-logics/page-logics/ActiveEmailPageLogics.js +4 -4
- package/src/lib/ui-logics/page-logics/ConfirmNewEmailPageLogics.js +4 -4
- package/src/lib/ui-logics/page-logics/CreateTicketPageLogics.js +5 -5
- package/src/lib/ui-logics/page-logics/HomePageLogics.js +5 -3
- package/src/lib/ui-logics/page-logics/NotificationsPageLogics.js +40 -16
- package/src/lib/ui-logics/page-logics/PlayerDetailPageLogics.js +3 -3
- package/src/lib/ui-logics/page-logics/PostDetailPageLogics.js +3 -3
- package/src/lib/ui-logics/page-logics/PreviewPostPageLogics.js +1 -1
- package/src/lib/ui-logics/page-logics/RenewPasswordPageLogics.js +4 -4
- package/src/lib/ui-logics/page-logics/ResetPasswordPageLogics.js +6 -6
- package/src/lib/ui-logics/page-logics/SettingsPageLogics.js +8 -8
- package/src/lib/ui-logics/page-logics/TicketDetailPageLogics.js +3 -3
- package/src/lib/ui-logics/page-logics/TicketsPageLogics.js +5 -3
- package/src/lib/views/ActivateEmailView.samples.js +22 -0
- package/src/lib/views/ActivateEmailView.svelte +4 -4
- package/src/lib/views/AppLayoutView.samples.js +17 -0
- package/src/lib/views/AppLayoutView.svelte +1 -1
- package/src/lib/views/AuthLayoutView.samples.js +4 -0
- package/src/lib/views/AuthLayoutView.svelte +1 -1
- package/src/lib/views/Breadcrumb.samples.js +15 -0
- package/src/lib/views/CloseTicketConfirmModal.samples.js +12 -0
- package/src/lib/views/ConfirmNewEmailView.samples.js +22 -0
- package/src/lib/views/ConfirmNewEmailView.svelte +4 -4
- package/src/lib/views/ConfirmRemoveAllNotificationsModal.samples.js +9 -0
- package/src/lib/views/CreateTicketView.samples.js +21 -0
- package/src/lib/views/CreateTicketView.svelte +5 -5
- package/src/lib/views/Date.samples.js +9 -0
- package/src/lib/views/DefaultToast.samples.js +7 -0
- package/src/lib/views/ErrorView.samples.js +8 -0
- package/src/lib/views/ErrorView.svelte +4 -2
- package/src/lib/views/Footer.samples.js +8 -0
- package/src/lib/views/Header.samples.js +8 -0
- package/src/lib/views/HomeSidebar.samples.js +59 -0
- package/src/lib/views/HomeView.samples.js +34 -0
- package/src/lib/views/HomeView.svelte +14 -6
- package/src/lib/views/LoginFormBody.samples.js +8 -0
- package/src/lib/views/LoginView.samples.js +50 -0
- package/src/lib/views/LoginView.svelte +24 -22
- package/src/lib/views/LogoutSessionConfirmModal.samples.js +8 -0
- package/src/lib/views/Main.samples.js +23 -0
- package/src/lib/views/MainLayoutView.svelte +3 -4
- package/src/lib/views/Navbar.samples.js +8 -0
- package/src/lib/views/NoContent.samples.js +7 -0
- package/src/lib/views/NotificationContainer.samples.js +25 -0
- package/src/lib/views/NotificationsView.samples.js +36 -0
- package/src/lib/views/NotificationsView.svelte +21 -12
- package/src/lib/views/PageActions.samples.js +7 -0
- package/src/lib/views/PageTitle.samples.js +8 -0
- package/src/lib/views/Pagination.samples.js +7 -0
- package/src/lib/views/PlayerDetailSidebar.samples.js +35 -0
- package/src/lib/views/PlayerDetailView.samples.js +8 -0
- package/src/lib/views/PlayerDetailView.svelte +3 -3
- package/src/lib/views/PlayerHead.samples.js +8 -0
- package/src/lib/views/Post.samples.js +10 -0
- package/src/lib/views/PostDetailView.samples.js +28 -0
- package/src/lib/views/PostDetailView.svelte +24 -16
- package/src/lib/views/Posts.samples.js +9 -0
- package/src/lib/views/PreviewPostView.samples.js +20 -0
- package/src/lib/views/PreviewPostView.svelte +10 -10
- package/src/lib/views/ProfileLayoutView.samples.js +4 -0
- package/src/lib/views/ProfileSidebar.samples.js +33 -0
- package/src/lib/views/ProfileView.samples.js +29 -0
- package/src/lib/views/ProfileView.svelte +2 -2
- package/src/lib/views/RegisterForm.samples.js +7 -0
- package/src/lib/views/RegisterView.samples.js +28 -0
- package/src/lib/views/RegisterView.svelte +5 -3
- package/src/lib/views/RenewPasswordView.samples.js +24 -0
- package/src/lib/views/RenewPasswordView.svelte +6 -6
- package/src/lib/views/ResetPasswordView.samples.js +24 -0
- package/src/lib/views/ResetPasswordView.svelte +3 -3
- package/src/lib/views/RulesView.samples.js +14 -0
- package/src/lib/views/RulesView.svelte +3 -3
- package/src/lib/views/SettingsView.svelte +48 -17
- package/src/lib/views/Sidebar.samples.js +7 -0
- package/src/lib/views/SupportSidebar.samples.js +24 -0
- package/src/lib/views/SupportView.samples.js +16 -0
- package/src/lib/views/SupportView.svelte +8 -6
- package/src/lib/views/ThemeSettingsLayoutView.samples.js +9 -0
- package/src/lib/views/ThemeSettingsLayoutView.svelte +1 -1
- package/src/lib/views/ThemeSettingsView.svelte +89 -89
- package/src/lib/views/TicketCreateAndDetailSidebar.samples.js +33 -0
- package/src/lib/views/TicketDetailView.samples.js +34 -0
- package/src/lib/views/TicketDetailView.svelte +17 -15
- package/src/lib/views/TicketRow.samples.js +10 -0
- package/src/lib/views/TicketStatus.samples.js +8 -0
- package/src/lib/views/Tickets.samples.js +9 -0
- package/src/lib/views/TicketsLayoutView.samples.js +4 -0
- package/src/lib/views/TicketsView.samples.js +23 -0
- package/src/lib/views/TicketsView.svelte +11 -9
- package/src/lib/views/Toast.samples.js +9 -0
- package/src/lib/views/ToastContainer.samples.js +8 -0
- package/src/lib/views/parts/Breadcrumb.svelte +53 -0
- package/src/lib/views/parts/CloseTicketConfirmModal.svelte +63 -0
- package/src/lib/views/parts/ConfirmRemoveAllNotificationsModal.svelte +55 -0
- package/src/lib/views/parts/DefaultToast.svelte +22 -0
- package/src/lib/views/parts/HomeSidebar.svelte +334 -0
- package/src/lib/views/parts/LogoutSessionConfirmModal.svelte +46 -0
- package/src/lib/views/parts/Main.svelte +71 -0
- package/src/lib/views/parts/NotificationContainer.svelte +109 -0
- package/src/lib/views/parts/PlayerDetailSidebar.svelte +81 -0
- package/src/lib/views/parts/Post.svelte +255 -0
- package/src/lib/views/parts/Posts.svelte +25 -0
- package/src/lib/views/parts/ProfileSidebar.svelte +115 -0
- package/src/lib/views/parts/Sidebar.svelte +19 -0
- package/src/lib/views/parts/SupportSidebar.svelte +34 -0
- package/src/lib/views/parts/TicketCreateAndDetailSidebar.svelte +51 -0
- package/src/lib/views/parts/TicketRow.svelte +63 -0
- package/src/lib/views/parts/TicketStatus.svelte +24 -0
- package/src/lib/views/parts/Tickets.svelte +45 -0
- package/src/lib/views/parts/Toast.svelte +27 -0
- package/src/lib/views/parts/ToastContainer.svelte +17 -0
- package/src/lib/views/parts/engine-views.generated.js +63 -0
- package/src/lib/views/parts/publicHref.js +18 -0
- package/src/lib/views/parts/ticketStatuses.js +7 -0
- package/src/plugin-engine/__tests__/engine.test.js +161 -0
- package/src/plugin-engine/engine.js +80 -12
- package/src/registry/__tests__/registry.test.js +510 -0
- package/src/registry/__tests__/view.test.js +52 -0
- package/src/registry/index.js +700 -51
- package/src/registry/routes.js +62 -0
- package/src/registry/view.js +69 -0
- package/src/routes/RootLayout.svelte +24 -1
- package/src/routes/catalogue/List.svelte +163 -0
- package/src/routes/catalogue/Stage.svelte +355 -0
- package/src/routes/catalogue/__tests__/browserSafe.test.js +13 -0
- package/src/routes/catalogue/__tests__/catalogue.test.js +539 -0
- package/src/routes/catalogue/catalogue.js +129 -0
- package/src/routes/catalogue/deps.js +147 -0
- package/src/routes/catalogue/engineSamples.js +63 -0
- package/src/routes/catalogue/fixtures.js +77 -0
- package/src/routes/catalogue/list.js +37 -0
- package/src/routes/catalogue/model.js +286 -0
- package/src/routes/catalogue/stage.js +69 -0
- package/src/routes/catalogue/views-json.js +24 -0
- package/src/routes/plugin-ui/Layout.svelte +29 -4
- package/src/routes/plugin-ui/Page.svelte +86 -31
- package/src/routes/plugin-ui/load.js +173 -0
- package/src/routes/plugins-client-file.js +8 -3
- package/src/routes/plugins-ui-file.js +60 -0
- package/src/routes/root-layout-load.js +59 -2
package/src/lib/PluginAPI.js
CHANGED
|
@@ -1,35 +1,269 @@
|
|
|
1
|
-
import { baseAPI, pageAPI } from "@panomc/sdk/core/js/PluginAPI";
|
|
2
|
-
import { get, writable } from "svelte/store";
|
|
3
|
-
import
|
|
1
|
+
import { baseAPI, createFeatureSet, pageAPI } from "@panomc/sdk/core/js/PluginAPI";
|
|
2
|
+
import { derived, get, writable } from "svelte/store";
|
|
3
|
+
import * as pluginManager from "@panomc/sdk/core/js/PluginManager.js";
|
|
4
4
|
import { sortSiteNavLinks } from "./orderNavLinks.util.js";
|
|
5
|
+
import { addPluginListener, resetPluginListeners } from "@panomc/sdk/core/js/NotificationManager.js";
|
|
5
6
|
import { avatarVersion } from "./Store.js";
|
|
7
|
+
import { controllers } from "@panomc/sdk/core/js/ControllerRegistry.js";
|
|
6
8
|
import { browser } from "$app/environment";
|
|
9
|
+
import { redirect } from "@sveltejs/kit";
|
|
10
|
+
// Engine-internal imports are relative: they resolve to the same files as the `$pano/...` alias, and a
|
|
11
|
+
// module that holds state (the registry) must be one instance whichever spelling reaches it.
|
|
12
|
+
import { buildLoginUrl, returnToFromUrl } from "./returnTo.util.js";
|
|
13
|
+
import {
|
|
14
|
+
describeView,
|
|
15
|
+
getClaims,
|
|
16
|
+
hasView,
|
|
17
|
+
loadForInjection,
|
|
18
|
+
registerViews,
|
|
19
|
+
resetPluginViews,
|
|
20
|
+
route,
|
|
21
|
+
} from "../registry/index.js";
|
|
7
22
|
import {
|
|
8
23
|
createHookEngine,
|
|
9
24
|
createLifecycleRegistry,
|
|
10
25
|
createSlotRegistry,
|
|
11
|
-
} from "
|
|
26
|
+
} from "../plugin-engine/engine.js";
|
|
12
27
|
|
|
13
28
|
// All the ordering / SSR-safe-clone / hook-load machinery lives in the shared plugin engine.
|
|
14
29
|
// This file is the THEME profile: it composes the engine registries into the theme's `pano.ui.*`
|
|
15
30
|
// namespace tree and re-exports the host contract (init, panoApiClient, panoApiServer).
|
|
31
|
+
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Named views (doc 01 sections 3 and 5)
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
/** @type {Map<string, string>} view id -> pluginId that registered it (first writer wins, like the registry's namespace guard) */
|
|
37
|
+
const viewOwners = new Map();
|
|
38
|
+
/** @type {Map<string, string>} pluginId -> ns, for the `<pluginId>:<Name>` alias */
|
|
39
|
+
const pluginNamespaces = new Map();
|
|
40
|
+
|
|
41
|
+
/** Levenshtein distance, for the "closest registered name" hint. */
|
|
42
|
+
function distance(a, b) {
|
|
43
|
+
const row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
44
|
+
for (let i = 1; i <= a.length; i++) {
|
|
45
|
+
let previous = row[0];
|
|
46
|
+
row[0] = i;
|
|
47
|
+
for (let j = 1; j <= b.length; j++) {
|
|
48
|
+
const next = Math.min(row[j] + 1, row[j - 1] + 1, previous + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
49
|
+
previous = row[j];
|
|
50
|
+
row[j] = next;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return row[b.length];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The registered plugin view id nearest to `id`, or null when nothing was registered. */
|
|
57
|
+
function closestViewName(id) {
|
|
58
|
+
let best = null;
|
|
59
|
+
let bestDistance = Infinity;
|
|
60
|
+
for (const name of viewOwners.keys()) {
|
|
61
|
+
const d = distance(id.toLowerCase(), name.toLowerCase());
|
|
62
|
+
if (d < bestDistance) {
|
|
63
|
+
best = name;
|
|
64
|
+
bestDistance = d;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return best;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** `<pluginId>:<Name>` -> `<ns>:<Name>`; anything else unchanged. */
|
|
71
|
+
function canonicalViewId(id) {
|
|
72
|
+
if (typeof id !== "string") return id;
|
|
73
|
+
const at = id.indexOf(":");
|
|
74
|
+
if (at <= 0) return id;
|
|
75
|
+
const ns = pluginNamespaces.get(id.slice(0, at));
|
|
76
|
+
return ns ? ns + id.slice(at) : id;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Items the theme places itself with `<PluginBlock>` or `claims` are left out of slots and hooks
|
|
81
|
+
* (doc 01 section 5): `getClaims().has(item.view)`, with the alias spelling understood too.
|
|
82
|
+
* @param {{ view?: string }} item
|
|
83
|
+
*/
|
|
84
|
+
function isSuppressed(item) {
|
|
85
|
+
if (typeof item?.view !== "string") return false;
|
|
86
|
+
const claims = getClaims();
|
|
87
|
+
return claims.has(item.view) || claims.has(canonicalViewId(item.view));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function labelOf(item) {
|
|
91
|
+
return item.id ?? item.name ?? item.path ?? "?";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Run on every registered, edited or upserted item (slot items, hook entries, pages).
|
|
96
|
+
*
|
|
97
|
+
* - `view` set: `item.component = () => loadForInjection(view)`, only when `component` is unset or
|
|
98
|
+
* `item._view !== item.view`, so a module `executeComponentLoad` already stored in the item is not
|
|
99
|
+
* blanked by a later `edit`. An unknown view id drops the item and names the closest registered view.
|
|
100
|
+
* - a function / object `component` without `view` is dropped with an error naming the replacement (SDK 2.0).
|
|
101
|
+
* - nothing else is touched (engine items such as `component: "local:profile-nav"`).
|
|
102
|
+
*
|
|
103
|
+
* Mutates and returns `item`; null = drop. Idempotent.
|
|
104
|
+
* @param {any} item
|
|
105
|
+
*/
|
|
106
|
+
export function normalizeItem(item) {
|
|
107
|
+
if (!item || typeof item !== "object") return item;
|
|
108
|
+
|
|
109
|
+
if (typeof item.view === "string" && item.view) {
|
|
110
|
+
const id = item.view;
|
|
111
|
+
|
|
112
|
+
if (!hasView(id)) {
|
|
113
|
+
const owner = item.pluginId ? `${item.pluginId}: ` : "";
|
|
114
|
+
const nearest = closestViewName(canonicalViewId(id));
|
|
115
|
+
console.error(
|
|
116
|
+
`[pano] ${owner}'${labelOf(item)}' names view '${id}', which is not registered` +
|
|
117
|
+
(nearest ? ` (closest registered view: '${nearest}')` : "") +
|
|
118
|
+
"; the item is dropped",
|
|
119
|
+
);
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (item.component === undefined || item.component === null || item._view !== item.view) {
|
|
124
|
+
item.component = () => loadForInjection(id);
|
|
125
|
+
item._view = id;
|
|
126
|
+
}
|
|
127
|
+
return item;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (typeof item.component === "function" || (item.component && typeof item.component === "object")) {
|
|
131
|
+
// SDK 2.0: the un-named form is gone. Engine items (string components) are not plugin items.
|
|
132
|
+
console.error(
|
|
133
|
+
`[pano] ${item.pluginId ?? "a plugin"}: '${labelOf(item)}' is registered with 'component', which SDK 2.0 no longer accepts; the item is dropped. Use export const view = { hook: '...' } in a view file`,
|
|
134
|
+
);
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return item;
|
|
139
|
+
}
|
|
140
|
+
|
|
16
141
|
const lifecycle = createLifecycleRegistry();
|
|
17
|
-
const hooks = createHookEngine();
|
|
142
|
+
const hooks = createHookEngine({ normalizeItem, isSuppressed });
|
|
18
143
|
const slots = createSlotRegistry({
|
|
19
|
-
getPlugins: () => get(plugins),
|
|
144
|
+
getPlugins: () => get(pluginManager.plugins),
|
|
20
145
|
browser,
|
|
21
146
|
executeLifecycle: lifecycle.executeLifecycle,
|
|
22
147
|
lifecyclePrefix: "theme",
|
|
148
|
+
normalizeItem,
|
|
149
|
+
isSuppressed,
|
|
23
150
|
});
|
|
24
151
|
|
|
25
152
|
// Theme-specific: the ordered site navigation links (uses the theme's sort util, not a plain slot).
|
|
26
153
|
const siteNavLinks = writable([]);
|
|
154
|
+
// What `getNavLinks()` hands out: the same links with `href` mapped through the theme's route config.
|
|
155
|
+
// Mapped on read, so a link is never mapped twice and a route config set later still applies.
|
|
156
|
+
const publicNavLinks = derived(siteNavLinks, ($links) =>
|
|
157
|
+
$links.map((link) => (typeof link?.href === "string" ? { ...link, href: route(link.href) } : link)),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
/** A site-relative URL goes through `route()`; absolute, protocol-relative and other values pass unchanged. */
|
|
161
|
+
function toPublicUrl(url) {
|
|
162
|
+
return typeof url === "string" && url.startsWith("/") && !url.startsWith("//") ? route(url) : url;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** `goto` for plugins: a renamed route lands on its public path. */
|
|
166
|
+
export async function routedGoto(url, options) {
|
|
167
|
+
const { goto } = await import("$app/navigation");
|
|
168
|
+
|
|
169
|
+
return goto(toPublicUrl(url), options);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** `redirect` for plugins (throws like SvelteKit's): a renamed route lands on its public path. */
|
|
173
|
+
export function routedRedirect(status, location) {
|
|
174
|
+
return redirect(status, toPublicUrl(location));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* `pano.views.add`: called by the generated entry wrapper before the author's `onLoad`.
|
|
179
|
+
* Registers the defaults with the registry, then applies their page / inject / home metadata.
|
|
180
|
+
* @param {Array<object>} defs ViewDef[] (doc 01 section 3)
|
|
181
|
+
*/
|
|
182
|
+
function addViews(defs) {
|
|
183
|
+
const list = (Array.isArray(defs) ? defs : []).filter((def) => def && typeof def === "object");
|
|
184
|
+
const accepted = [];
|
|
185
|
+
|
|
186
|
+
for (const def of list) {
|
|
187
|
+
const name = def.name;
|
|
188
|
+
const owner = viewOwners.get(name);
|
|
189
|
+
|
|
190
|
+
// The registry rejects a def whose namespace belongs to another plugin; the side effects follow it.
|
|
191
|
+
if (owner !== undefined && def.pluginId !== undefined && owner !== def.pluginId) continue;
|
|
192
|
+
|
|
193
|
+
accepted.push(def);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
registerViews(accepted);
|
|
197
|
+
|
|
198
|
+
for (const def of accepted) {
|
|
199
|
+
if (!hasView(def.name)) continue;
|
|
200
|
+
|
|
201
|
+
viewOwners.set(def.name, def.pluginId ?? "");
|
|
202
|
+
const ns = def.name.slice(0, def.name.indexOf(":"));
|
|
203
|
+
if (def.pluginId) pluginNamespaces.set(def.pluginId, ns);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
for (const def of accepted) {
|
|
207
|
+
if (!viewOwners.has(def.name)) continue;
|
|
208
|
+
|
|
209
|
+
const pluginId = def.pluginId;
|
|
210
|
+
|
|
211
|
+
if (def.page && typeof def.page === "object" && def.page.path) {
|
|
212
|
+
panoApi.ui.page.register({
|
|
213
|
+
...def.page,
|
|
214
|
+
view: def.name,
|
|
215
|
+
pluginId,
|
|
216
|
+
...(def.home ? { home: def.home } : {}),
|
|
217
|
+
...(def.block ? { block: true } : {}),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
for (const inject of def.inject ?? []) {
|
|
222
|
+
if (!inject || typeof inject !== "object") continue;
|
|
223
|
+
|
|
224
|
+
const id = inject.id ?? def.name;
|
|
225
|
+
const priority = inject.priority;
|
|
226
|
+
const each = (value) => (Array.isArray(value) ? value : value ? [value] : []);
|
|
227
|
+
|
|
228
|
+
for (const viewId of each(inject.slot)) {
|
|
229
|
+
panoApi.ui.view.register({ viewId, id, view: def.name, pluginId, ...(priority !== undefined ? { priority } : {}) });
|
|
230
|
+
}
|
|
231
|
+
for (const sidebarId of each(inject.sidebar)) {
|
|
232
|
+
// a sidebar item gets the prop `sidebarId` (doc 01 section 2)
|
|
233
|
+
panoApi.ui.sidebar.register({
|
|
234
|
+
sidebarId,
|
|
235
|
+
id,
|
|
236
|
+
view: def.name,
|
|
237
|
+
pluginId,
|
|
238
|
+
props: { sidebarId },
|
|
239
|
+
...(priority !== undefined ? { priority } : {}),
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
for (const name of each(inject.hook)) {
|
|
243
|
+
panoApi.ui.hook.register({
|
|
244
|
+
name,
|
|
245
|
+
id,
|
|
246
|
+
view: def.name,
|
|
247
|
+
pluginId,
|
|
248
|
+
...(inject.skipLoad ? { skipLoad: true } : {}),
|
|
249
|
+
...(inject.permission ? { permission: inject.permission } : {}),
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
27
255
|
|
|
28
256
|
export async function init() {
|
|
257
|
+
// plugin views and controllers are forgotten with everything else a plugin registered
|
|
258
|
+
resetPluginViews();
|
|
259
|
+
controllers.reset();
|
|
260
|
+
viewOwners.clear();
|
|
261
|
+
pluginNamespaces.clear();
|
|
29
262
|
hooks.reset();
|
|
30
263
|
slots.reset();
|
|
31
264
|
siteNavLinks.set([]);
|
|
32
265
|
lifecycle.reset();
|
|
266
|
+
resetPluginListeners();
|
|
33
267
|
}
|
|
34
268
|
|
|
35
269
|
export const executeLifecycle = lifecycle.executeLifecycle;
|
|
@@ -37,10 +271,65 @@ export const executeSidebarLoad = slots.executeSidebarLoad;
|
|
|
37
271
|
export const executeViewLoad = slots.executeViewLoad;
|
|
38
272
|
export const executeHookLoad = hooks.executeHookLoad;
|
|
39
273
|
|
|
274
|
+
// Capability ids this theme announces through `pano.features` (see the feature table of the
|
|
275
|
+
// market plugin spec). Plugins test `pano.features?.has(id)`.
|
|
276
|
+
export const THEME_FEATURE_IDS = [
|
|
277
|
+
"login-return-url",
|
|
278
|
+
"page-meta",
|
|
279
|
+
"page-title-options",
|
|
280
|
+
"page-sidebar-id",
|
|
281
|
+
"profile-nav",
|
|
282
|
+
"context-components",
|
|
283
|
+
"toast-escaped-values",
|
|
284
|
+
"decoded-route-params",
|
|
285
|
+
"layout-route-params",
|
|
286
|
+
"plugin-notifications",
|
|
287
|
+
"named-views",
|
|
288
|
+
"plugin-slots",
|
|
289
|
+
"blocks",
|
|
290
|
+
"route-map",
|
|
291
|
+
];
|
|
292
|
+
|
|
40
293
|
export const panoApi = {
|
|
41
294
|
...baseAPI,
|
|
295
|
+
features: createFeatureSet(THEME_FEATURE_IDS),
|
|
296
|
+
// Named views (doc 01 section 3): `add` is the generated call, `has` / `describe` are read-only.
|
|
297
|
+
views: {
|
|
298
|
+
add: addViews,
|
|
299
|
+
has: (id) => hasView(id),
|
|
300
|
+
describe: (id) => describeView(id),
|
|
301
|
+
},
|
|
302
|
+
// Public controllers (doc 02 section 2): `use`, `load`, `has`, `list`, `register`, ...
|
|
303
|
+
controllers,
|
|
304
|
+
// Route config of the active theme: `pano.routes.resolve("/store")` is the path the theme publishes.
|
|
305
|
+
routes: {
|
|
306
|
+
resolve: route,
|
|
307
|
+
},
|
|
308
|
+
// Login return URL for plugin pages: `pano.auth.loginUrl("/store/checkout")`. `pano.ui.auth`
|
|
309
|
+
// (the login / register view slots) is a different namespace and is untouched.
|
|
310
|
+
auth: {
|
|
311
|
+
loginUrl: (returnTo) => route(buildLoginUrl(returnTo)),
|
|
312
|
+
returnTo: (url) => returnToFromUrl(url),
|
|
313
|
+
// Use in a plugin page `load(event)`: guests are sent to `/login?redirect=<this page>`.
|
|
314
|
+
async requireLogin(event) {
|
|
315
|
+
const { session } = await event.parent();
|
|
316
|
+
|
|
317
|
+
if (!session.user) {
|
|
318
|
+
throw routedRedirect(302, buildLoginUrl(event.url.pathname + event.url.search));
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
},
|
|
42
322
|
ui: {
|
|
43
323
|
...pageAPI,
|
|
324
|
+
// `view: "<ns>:<Name>"` instead of `component` (doc 01 section 3); the SDK's register stores the page.
|
|
325
|
+
page: {
|
|
326
|
+
...pageAPI.page,
|
|
327
|
+
register(page) {
|
|
328
|
+
const normalized = normalizeItem({ ...page });
|
|
329
|
+
|
|
330
|
+
if (normalized) pageAPI.page.register(normalized);
|
|
331
|
+
},
|
|
332
|
+
},
|
|
44
333
|
nav: {
|
|
45
334
|
site: {
|
|
46
335
|
editNavLinks(callback) {
|
|
@@ -50,7 +339,7 @@ export const panoApi = {
|
|
|
50
339
|
});
|
|
51
340
|
},
|
|
52
341
|
getNavLinks() {
|
|
53
|
-
return
|
|
342
|
+
return publicNavLinks;
|
|
54
343
|
},
|
|
55
344
|
},
|
|
56
345
|
profileDropdown: {
|
|
@@ -74,6 +363,15 @@ export const panoApi = {
|
|
|
74
363
|
},
|
|
75
364
|
},
|
|
76
365
|
profile: {
|
|
366
|
+
// Profile sidebar navigation: items `{ id, priority, hidden?, props: { href, text, icon?, startsWith?, badge? } }`.
|
|
367
|
+
nav: {
|
|
368
|
+
edit(callback) {
|
|
369
|
+
slots.edit("profile-nav", callback);
|
|
370
|
+
},
|
|
371
|
+
get() {
|
|
372
|
+
return panoApi.ui.view.get("profile-nav");
|
|
373
|
+
},
|
|
374
|
+
},
|
|
77
375
|
content: {
|
|
78
376
|
edit(callback) {
|
|
79
377
|
slots.edit("profile-content", callback);
|
|
@@ -164,7 +462,7 @@ export const panoApi = {
|
|
|
164
462
|
async get() {
|
|
165
463
|
// Registry-resolved: a theme overriding LoginFormBody restyles the
|
|
166
464
|
// form everywhere plugins mount it, too.
|
|
167
|
-
const { resolveView } = await import("
|
|
465
|
+
const { resolveView } = await import("../registry/index.js");
|
|
168
466
|
return resolveView(
|
|
169
467
|
"LoginFormBody",
|
|
170
468
|
() => import("$pano/lib/components/LoginFormBody.svelte"),
|
|
@@ -204,7 +502,7 @@ export const panoApi = {
|
|
|
204
502
|
// Theme-provided register form body. See login.form for rationale.
|
|
205
503
|
form: {
|
|
206
504
|
async get() {
|
|
207
|
-
const { resolveView } = await import("
|
|
505
|
+
const { resolveView } = await import("../registry/index.js");
|
|
208
506
|
return resolveView(
|
|
209
507
|
"RegisterForm",
|
|
210
508
|
() => import("$pano/lib/components/RegisterForm.svelte"),
|
|
@@ -316,6 +614,12 @@ export const panoApi = {
|
|
|
316
614
|
panoApi.ui.lifecycle.on(`theme:sidebar:${sidebarId}:load`, handler);
|
|
317
615
|
},
|
|
318
616
|
},
|
|
617
|
+
notification: {
|
|
618
|
+
// Click handler for a plugin-defined notification type; runs after the core listeners.
|
|
619
|
+
onClick(type, handler) {
|
|
620
|
+
addPluginListener(type, handler);
|
|
621
|
+
},
|
|
622
|
+
},
|
|
319
623
|
post: {
|
|
320
624
|
onLoad(handler) {
|
|
321
625
|
panoApi.ui.lifecycle.on("theme:post-detail:load", handler);
|
package/src/lib/Store.js
CHANGED
|
@@ -3,13 +3,14 @@ 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 { buildLoginUrl, returnToFromUrl } from "$pano/lib/returnTo.util.js";
|
|
6
7
|
import { showSuccess as showSuccessToast } from "$pano/lib/components/ToastContainer.svelte";
|
|
7
8
|
|
|
8
9
|
export const notificationsCount = writable(0);
|
|
9
10
|
export const quickNotifications = writable([]);
|
|
10
11
|
|
|
11
12
|
export const initialized = writable(false);
|
|
12
|
-
export
|
|
13
|
+
export { avatarVersion, markAvatarVersionHydrated } from "./avatarVersion.js";
|
|
13
14
|
|
|
14
15
|
export async function logout(session) {
|
|
15
16
|
sendLogout().then(async () => {
|
|
@@ -30,14 +31,26 @@ export async function logout(session) {
|
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Sends a guest to the login page. Pass the load event to come back to the page after login
|
|
36
|
+
* (`/login?redirect=<path + query>`); a string target keeps the old fixed-redirect behaviour.
|
|
37
|
+
*/
|
|
38
|
+
export function requireLogin(session, target = "/login") {
|
|
34
39
|
if (!session.user) {
|
|
35
|
-
|
|
40
|
+
if (target && typeof target === "object" && target.url) {
|
|
41
|
+
throw redirect(302, buildLoginUrl(target.url.pathname + target.url.search));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
throw redirect(302, target);
|
|
36
45
|
}
|
|
37
46
|
}
|
|
38
47
|
|
|
39
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Sends a logged-in visitor away from an auth page: back to `?redirect=` when it is a safe
|
|
50
|
+
* site-relative target, else `/`.
|
|
51
|
+
*/
|
|
52
|
+
export function requireNotLogin(session, event) {
|
|
40
53
|
if (session.user) {
|
|
41
|
-
throw redirect(302,
|
|
54
|
+
throw redirect(302, returnToFromUrl(event?.url));
|
|
42
55
|
}
|
|
43
56
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { get } from "svelte/store";
|
|
3
|
+
import { createAvatarVersionStore } from "../avatarVersion.js";
|
|
4
|
+
|
|
5
|
+
describe("avatarVersion", () => {
|
|
6
|
+
test("two simulated SSR requests never share a value", () => {
|
|
7
|
+
const server = createAvatarVersionStore(false);
|
|
8
|
+
server.set("v=1111"); // request A (processLoad)
|
|
9
|
+
expect(get(server)).toBe(""); // request B renders: nothing leaked
|
|
10
|
+
server.set("v=2222");
|
|
11
|
+
expect(get(server)).toBe("");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("server output equals the first client render; value applies after hydration", () => {
|
|
15
|
+
const server = createAvatarVersionStore(false);
|
|
16
|
+
const client = createAvatarVersionStore(true);
|
|
17
|
+
server.set("v=1");
|
|
18
|
+
client.set("v=1"); // load runs before hydration
|
|
19
|
+
expect(get(client)).toBe(get(server)); // first client render matches SSR
|
|
20
|
+
client.markHydrated(); // RootLayout onMount
|
|
21
|
+
expect(get(client)).toBe("v=1");
|
|
22
|
+
client.set("v=2"); // later PluginAPI.avatar.updateVersion
|
|
23
|
+
expect(get(client)).toBe("v=2");
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { afterAll, describe, expect, test } from "bun:test";
|
|
2
|
+
import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
|
|
6
|
+
const pkgDir = join(import.meta.dir, "..", "..", "..");
|
|
7
|
+
const checkJs = join(pkgDir, "bin", "check.js");
|
|
8
|
+
const corePkg = JSON.parse(readFileSync(join(pkgDir, "package.json"), "utf-8"));
|
|
9
|
+
const defaultView = join(pkgDir, "src", "lib", "views", "MainLayoutView.svelte");
|
|
10
|
+
|
|
11
|
+
const roots = [];
|
|
12
|
+
afterAll(() => {
|
|
13
|
+
for (const root of roots) rmSync(root, { recursive: true, force: true });
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
/** A minimal valid theme whose only override is MainLayoutView (a copy of the default, plus `extra`). */
|
|
17
|
+
function makeTheme({ extraHead = "", registerOverride = true } = {}) {
|
|
18
|
+
const dir = mkdtempSync(join(tmpdir(), "theme-core-check-"));
|
|
19
|
+
roots.push(dir);
|
|
20
|
+
|
|
21
|
+
writeFileSync(
|
|
22
|
+
join(dir, "package.json"),
|
|
23
|
+
JSON.stringify({ name: "pano-fixture-theme", dependencies: { svelte: corePkg.dependencies.svelte } }),
|
|
24
|
+
);
|
|
25
|
+
writeFileSync(
|
|
26
|
+
join(dir, "manifest.json"),
|
|
27
|
+
JSON.stringify({
|
|
28
|
+
id: "fixture-theme",
|
|
29
|
+
title: "Fixture",
|
|
30
|
+
version: "1.0.0",
|
|
31
|
+
author: "x",
|
|
32
|
+
panoVersion: "1.0.0",
|
|
33
|
+
screenshots: [],
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
writeFileSync(
|
|
37
|
+
join(dir, "theme.config.js"),
|
|
38
|
+
registerOverride
|
|
39
|
+
? `export default { views: { MainLayoutView: () => import("./src/views/MainLayoutView.svelte") } };\n`
|
|
40
|
+
: `export default { views: {} };\n`,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
mkdirSync(join(dir, "src", "views"), { recursive: true });
|
|
44
|
+
const view = join(dir, "src", "views", "MainLayoutView.svelte");
|
|
45
|
+
cpSync(defaultView, view);
|
|
46
|
+
if (extraHead) {
|
|
47
|
+
const source = readFileSync(view, "utf-8").replace("<svelte:head>", `<svelte:head>\n ${extraHead}`);
|
|
48
|
+
writeFileSync(view, source);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return dir;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function runCheck(cwd, args = []) {
|
|
55
|
+
const proc = Bun.spawnSync([process.execPath, checkJs, ...args], {
|
|
56
|
+
cwd,
|
|
57
|
+
stdout: "pipe",
|
|
58
|
+
stderr: "pipe",
|
|
59
|
+
env: { ...process.env, PANO_CHECK_ROUTES: join(pkgDir, "bin", "__tests__", "check", "fixtures", "routes.json") },
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
code: proc.exitCode,
|
|
64
|
+
out: proc.stdout.toString() + proc.stderr.toString(),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe("bin/check.js MainLayoutView description (TC-8)", () => {
|
|
69
|
+
test("the default MainLayoutView no longer emits a description tag", () => {
|
|
70
|
+
expect(readFileSync(defaultView, "utf-8")).not.toMatch(/name\s*=\s*["']description["']/);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("control: an override that is a copy of the default passes", () => {
|
|
74
|
+
const { code, out } = runCheck(makeTheme());
|
|
75
|
+
|
|
76
|
+
expect(out).toContain("OK");
|
|
77
|
+
expect(code).toBe(0);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("an override that still contains name=\"description\" fails", () => {
|
|
81
|
+
const { code, out } = runCheck(
|
|
82
|
+
makeTheme({ extraHead: '<meta content={$session.siteInfo.websiteDescription} name="description" />' }),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
expect(code).not.toBe(0);
|
|
86
|
+
expect(out).toContain("MainLayoutView");
|
|
87
|
+
expect(out).toContain("description");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("single-quoted attribute and attribute-first order also fail", () => {
|
|
91
|
+
for (const tag of [
|
|
92
|
+
"<meta name='description' content=\"x\" />",
|
|
93
|
+
'<meta name="description" content="x" />',
|
|
94
|
+
'<meta name = "description" content="x">',
|
|
95
|
+
]) {
|
|
96
|
+
expect(runCheck(makeTheme({ extraHead: tag })).code).not.toBe(0);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("a commented-out description tag and other meta names do not fail", () => {
|
|
101
|
+
expect(runCheck(makeTheme({ extraHead: '<!-- <meta name="description" content="x" /> -->' })).code).toBe(0);
|
|
102
|
+
expect(runCheck(makeTheme({ extraHead: '<meta name="author" content="x" />' })).code).toBe(0);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("an unregistered override file is not checked", () => {
|
|
106
|
+
const dir = makeTheme({
|
|
107
|
+
extraHead: '<meta name="description" content="x" />',
|
|
108
|
+
registerOverride: false,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
expect(runCheck(dir).code).toBe(0);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("bin/check.js arguments (TC-41)", () => {
|
|
116
|
+
/** A theme with one warning (a plugin view without a snapshot) and nothing else. */
|
|
117
|
+
function warningTheme() {
|
|
118
|
+
const dir = makeTheme({ registerOverride: false });
|
|
119
|
+
mkdirSync(join(dir, "src", "views"), { recursive: true });
|
|
120
|
+
writeFileSync(join(dir, "src", "views", "P.svelte"), "<div></div>");
|
|
121
|
+
writeFileSync(
|
|
122
|
+
join(dir, "theme.config.js"),
|
|
123
|
+
`export default { views: { "market:ProductCard": () => import("./src/views/P.svelte") } };\n`,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
return dir;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
test("a warning prints and exits 0; --strict turns it into a failure", () => {
|
|
130
|
+
const dir = warningTheme();
|
|
131
|
+
const lax = runCheck(dir);
|
|
132
|
+
|
|
133
|
+
expect(lax.code).toBe(0);
|
|
134
|
+
expect(lax.out).toContain("[C2]");
|
|
135
|
+
expect(lax.out).toContain("run: theme-core contracts pull");
|
|
136
|
+
expect(lax.out).toContain("OK");
|
|
137
|
+
|
|
138
|
+
const strict = runCheck(dir, ["--strict"]);
|
|
139
|
+
|
|
140
|
+
expect(strict.code).toBe(1);
|
|
141
|
+
expect(strict.out).toContain("[C2]");
|
|
142
|
+
expect(strict.out).toContain("1 problem must be fixed");
|
|
143
|
+
expect(strict.out).toContain("strict");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("an unknown argument exits 2 and names the usage", () => {
|
|
147
|
+
const { code, out } = runCheck(makeTheme(), ["--stric"]);
|
|
148
|
+
|
|
149
|
+
expect(code).toBe(2);
|
|
150
|
+
expect(out).toContain("--stric");
|
|
151
|
+
expect(out).toContain("theme-core check [--strict] [--fix]");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("--fix writes the controller pins; a second run is clean even under --strict", () => {
|
|
155
|
+
const dir = makeTheme({ registerOverride: false });
|
|
156
|
+
cpSync(
|
|
157
|
+
join(pkgDir, "bin", "__tests__", "check", "fixtures", "plugin-contracts"),
|
|
158
|
+
join(dir, "plugin-contracts"),
|
|
159
|
+
{ recursive: true },
|
|
160
|
+
);
|
|
161
|
+
mkdirSync(join(dir, "src", "pages"), { recursive: true });
|
|
162
|
+
writeFileSync(
|
|
163
|
+
join(dir, "src", "pages", "Cart.svelte"),
|
|
164
|
+
`<script>\n import { plugin } from "@panomc/sdk/controllers";\n const cart = plugin("market").use("cart");\n</script>\n`,
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
const before = runCheck(dir);
|
|
168
|
+
|
|
169
|
+
expect(before.code).toBe(0);
|
|
170
|
+
expect(before.out).toContain("[C12]");
|
|
171
|
+
expect(before.out).toContain("run: theme-core check --fix");
|
|
172
|
+
expect(runCheck(dir, ["--strict"]).code).toBe(1);
|
|
173
|
+
|
|
174
|
+
const fixed = runCheck(dir, ["--strict", "--fix"]);
|
|
175
|
+
|
|
176
|
+
expect(fixed.out).toContain("fixed: pinned controller 'market/cart' to version 2");
|
|
177
|
+
expect(fixed.code).toBe(0);
|
|
178
|
+
expect(readFileSync(join(dir, "theme.config.js"), "utf-8")).toContain('"market/cart": 2');
|
|
179
|
+
expect(runCheck(dir, ["--strict"]).code).toBe(0);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("info lines (claims) never fail a strict run", () => {
|
|
183
|
+
const dir = makeTheme({ registerOverride: false });
|
|
184
|
+
cpSync(
|
|
185
|
+
join(pkgDir, "bin", "__tests__", "check", "fixtures", "plugin-contracts"),
|
|
186
|
+
join(dir, "plugin-contracts"),
|
|
187
|
+
{ recursive: true },
|
|
188
|
+
);
|
|
189
|
+
mkdirSync(join(dir, "src", "views"), { recursive: true });
|
|
190
|
+
writeFileSync(join(dir, "src", "views", "Navbar.svelte"), '<PluginBlock id="market:NavCart" />');
|
|
191
|
+
writeFileSync(
|
|
192
|
+
join(dir, "theme.config.js"),
|
|
193
|
+
`export default { views: { Navbar: () => import("./src/views/Navbar.svelte") } };\n`,
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
const { code, out } = runCheck(dir, ["--strict"]);
|
|
197
|
+
|
|
198
|
+
expect(out).toContain("automatic copy in 'navbar-right' is suppressed");
|
|
199
|
+
expect(code).toBe(0);
|
|
200
|
+
});
|
|
201
|
+
});
|