@panomc/theme-core 1.0.0-dev.60 → 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 +79 -21
- 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
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
// View catalogue, pure part (doc 02 section 7): ids, urls, rows, filters and sample states.
|
|
2
|
+
//
|
|
3
|
+
// Nothing here imports SvelteKit, the registry or a component, so the list, the stage, `views.json` and
|
|
4
|
+
// the tests all build on the same functions. The catalogue exists in theme dev mode only: the generated
|
|
5
|
+
// route files import `list.js` / `stage.js` / `views-json.js` dynamically behind `dev` (see bin/sync.js).
|
|
6
|
+
|
|
7
|
+
/** Namespace of the engine's own views in catalogue urls (engine ids stay bare: `LoginView`). */
|
|
8
|
+
export const ENGINE_NS = "pano";
|
|
9
|
+
|
|
10
|
+
/** Where the catalogue lives. */
|
|
11
|
+
export const CATALOGUE_PATH = "/__pano/views";
|
|
12
|
+
|
|
13
|
+
/** The four state names the catalogue knows; other keys of a samples file are allowed and listed. */
|
|
14
|
+
export const STANDARD_STATES = Object.freeze(["empty", "filled", "error", "loading"]);
|
|
15
|
+
|
|
16
|
+
/** The six `themeColor` values (doc 03): the stage puts one on `data-bs-theme`. */
|
|
17
|
+
export const PALETTES = Object.freeze(["dark", "light", "copper", "emerald", "midnight", "crimson"]);
|
|
18
|
+
|
|
19
|
+
export const STATUSES = Object.freeze(["default", "overridden", "override outdated"]);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* One sample state (doc 02 section 7): the props the view gets, a patch per controller, the session the
|
|
23
|
+
* stage simulates and a title. The engine's samples may build stores; plugin samples are pure data.
|
|
24
|
+
*
|
|
25
|
+
* @typedef {object} SampleState
|
|
26
|
+
* @property {Record<string, any>} [props]
|
|
27
|
+
* @property {Record<string, Record<string, any>>} [controllers]
|
|
28
|
+
* @property {"guest" | "user"} [session]
|
|
29
|
+
* @property {string} [label]
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The default export of a `*.samples.js`: state name -> state (or a function returning one).
|
|
34
|
+
* Standard names: `empty`, `filled`, `error`, `loading`; other names are allowed and listed.
|
|
35
|
+
*
|
|
36
|
+
* @typedef {{ [state: string]: SampleState | (() => SampleState | Promise<SampleState>) | undefined }} Samples
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* `LoginView` -> `{ ns: "pano", name: "LoginView", pluginId: null }`; `market:ProductCard` -> `{ ns: "market", ... }`.
|
|
41
|
+
* @param {string} id
|
|
42
|
+
*/
|
|
43
|
+
export function splitViewId(id) {
|
|
44
|
+
const at = String(id).indexOf(":");
|
|
45
|
+
|
|
46
|
+
if (at <= 0) return { ns: ENGINE_NS, name: String(id), engine: true };
|
|
47
|
+
|
|
48
|
+
return { ns: id.slice(0, at), name: id.slice(at + 1), engine: false };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Inverse of the stage route: `/__pano/views/<ns>/<view>` -> the view id. */
|
|
52
|
+
export function viewIdFromParams(ns, view) {
|
|
53
|
+
return ns === ENGINE_NS ? view : `${ns}:${view}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {string} id
|
|
58
|
+
* @param {{ state?: string, palette?: string, source?: string, bare?: boolean }} [query]
|
|
59
|
+
*/
|
|
60
|
+
export function stageUrl(id, query = {}) {
|
|
61
|
+
const { ns, name } = splitViewId(id);
|
|
62
|
+
const params = new URLSearchParams();
|
|
63
|
+
|
|
64
|
+
if (query.state) params.set("state", query.state);
|
|
65
|
+
if (query.palette) params.set("palette", query.palette);
|
|
66
|
+
if (query.source && query.source !== "theme") params.set("source", query.source);
|
|
67
|
+
if (query.bare) params.set("bare", "1");
|
|
68
|
+
|
|
69
|
+
const qs = params.toString();
|
|
70
|
+
|
|
71
|
+
return `${CATALOGUE_PATH}/${encodeURIComponent(ns)}/${encodeURIComponent(name)}${qs ? `?${qs}` : ""}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The command that copies a view into the theme (doc 01 section 4, `eject-view`). */
|
|
75
|
+
export function ejectCommand(id) {
|
|
76
|
+
return `bunx theme-core eject-view ${id}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The stage's query string, validated. Unknown values fall back to the defaults.
|
|
81
|
+
* @param {URLSearchParams} searchParams
|
|
82
|
+
* @param {string[]} states the state names of the view
|
|
83
|
+
*/
|
|
84
|
+
export function parseStageQuery(searchParams, states = []) {
|
|
85
|
+
const wanted = searchParams.get("state");
|
|
86
|
+
const state = wanted && states.includes(wanted) ? wanted : states.includes("filled") ? "filled" : (states[0] ?? null);
|
|
87
|
+
const palette = PALETTES.includes(searchParams.get("palette") ?? "") ? searchParams.get("palette") : null;
|
|
88
|
+
const source = searchParams.get("source") === "default" ? "default" : "theme";
|
|
89
|
+
const bare = searchParams.get("bare") === "1";
|
|
90
|
+
|
|
91
|
+
return { state, requestedState: wanted, palette, source, bare };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Kind of an engine view: the skin contract only types the parts (`component`).
|
|
96
|
+
* @param {string} name
|
|
97
|
+
* @param {{ kind?: string }} def
|
|
98
|
+
*/
|
|
99
|
+
export function engineKind(name, def) {
|
|
100
|
+
if (def?.kind) return def.kind;
|
|
101
|
+
|
|
102
|
+
return /LayoutView$/.test(name) ? "layout" : "page";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* State names of a samples module (`export default { ... }`), standard ones first.
|
|
107
|
+
* @param {Record<string, unknown> | null | undefined} samples
|
|
108
|
+
*/
|
|
109
|
+
export function stateNames(samples) {
|
|
110
|
+
const keys = Object.keys(samples ?? {}).filter((key) => samples?.[key] !== undefined);
|
|
111
|
+
const standard = STANDARD_STATES.filter((key) => keys.includes(key));
|
|
112
|
+
|
|
113
|
+
return [...standard, ...keys.filter((key) => !STANDARD_STATES.includes(key))];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Controller names the object-form states of a samples module patch (function states are not run here).
|
|
118
|
+
* @param {Record<string, any> | null | undefined} samples
|
|
119
|
+
*/
|
|
120
|
+
export function controllersOfSamples(samples) {
|
|
121
|
+
const names = new Set();
|
|
122
|
+
|
|
123
|
+
for (const entry of Object.values(samples ?? {})) {
|
|
124
|
+
if (entry && typeof entry === "object") for (const name of Object.keys(entry.controllers ?? {})) names.add(name);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return [...names].sort();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* One state of a samples module as plain data: a function is called, a missing field gets its default.
|
|
132
|
+
* @param {Record<string, any> | null | undefined} samples
|
|
133
|
+
* @param {string | null} state
|
|
134
|
+
* @returns {Promise<{ props: Record<string, any>, controllers: Record<string, any>, session: "guest" | "user" | null, label: string | null } | null>}
|
|
135
|
+
*/
|
|
136
|
+
export async function resolveSample(samples, state) {
|
|
137
|
+
if (!state || !samples || samples[state] === undefined) return null;
|
|
138
|
+
|
|
139
|
+
const entry = typeof samples[state] === "function" ? await samples[state]() : samples[state];
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
props: entry?.props ?? {},
|
|
143
|
+
controllers: entry?.controllers ?? {},
|
|
144
|
+
session: entry?.session === "guest" || entry?.session === "user" ? entry.session : null,
|
|
145
|
+
label: typeof entry?.label === "string" ? entry.label : null,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Status of a view in the theme: `default`, `overridden` (an override renders) or `override outdated`
|
|
151
|
+
* (the theme has an override the registry refused, so the default renders).
|
|
152
|
+
* @param {{ overridden: boolean } | null} described `describeView(id)`
|
|
153
|
+
* @param {"override" | "default" | null} source `resolveViewModule(id).source`
|
|
154
|
+
*/
|
|
155
|
+
export function statusOf(described, source) {
|
|
156
|
+
if (!described?.overridden) return "default";
|
|
157
|
+
|
|
158
|
+
return source === "override" ? "overridden" : "override outdated";
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @typedef {object} Row
|
|
163
|
+
* @property {string} id
|
|
164
|
+
* @property {string} ns
|
|
165
|
+
* @property {string} name
|
|
166
|
+
* @property {string | null} pluginId
|
|
167
|
+
* @property {string} kind
|
|
168
|
+
* @property {number} contract
|
|
169
|
+
* @property {string} status
|
|
170
|
+
* @property {string[]} states
|
|
171
|
+
* @property {string[]} badges
|
|
172
|
+
* @property {string} url
|
|
173
|
+
* @property {string} source path of the readable source (engine: relative to the engine package; plugin: relative to `contract/`)
|
|
174
|
+
* @property {Record<string, any>} props the props contract
|
|
175
|
+
* @property {string[]} uses
|
|
176
|
+
* @property {Array<{ type: string, [k: string]: any }>} issues
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The engine's rows, from `skin-contract.json`.
|
|
181
|
+
* @param {{ views?: Record<string, any> }} skinContract
|
|
182
|
+
* @returns {Array<Omit<Row, "status" | "states" | "badges" | "issues">>}
|
|
183
|
+
*/
|
|
184
|
+
export function engineRows(skinContract) {
|
|
185
|
+
return Object.entries(skinContract?.views ?? {}).map(([name, def]) => ({
|
|
186
|
+
id: name,
|
|
187
|
+
ns: ENGINE_NS,
|
|
188
|
+
name,
|
|
189
|
+
pluginId: null,
|
|
190
|
+
kind: engineKind(name, def),
|
|
191
|
+
contract: def.contract ?? 1,
|
|
192
|
+
url: stageUrl(name),
|
|
193
|
+
source: def.source ?? `src/lib/views/${name}.svelte`,
|
|
194
|
+
props: def.props ?? {},
|
|
195
|
+
uses: def.uses ?? [],
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* The rows of one plugin, from its `contract/views.json`.
|
|
201
|
+
* @param {{ pluginId?: string, namespace?: string, views?: Record<string, any> }} viewsJson
|
|
202
|
+
* @param {string} [fallbackPluginId]
|
|
203
|
+
*/
|
|
204
|
+
export function pluginRows(viewsJson, fallbackPluginId) {
|
|
205
|
+
const pluginId = viewsJson?.pluginId ?? fallbackPluginId ?? null;
|
|
206
|
+
|
|
207
|
+
return Object.entries(viewsJson?.views ?? {}).map(([id, def]) => {
|
|
208
|
+
const { ns, name } = splitViewId(id);
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
id,
|
|
212
|
+
ns: viewsJson?.namespace ?? ns,
|
|
213
|
+
name,
|
|
214
|
+
pluginId,
|
|
215
|
+
kind: def.kind ?? "component",
|
|
216
|
+
contract: def.contract ?? 1,
|
|
217
|
+
url: stageUrl(id),
|
|
218
|
+
source: def.source ?? "",
|
|
219
|
+
props: def.props ?? {},
|
|
220
|
+
uses: def.uses ?? [],
|
|
221
|
+
block: def.block === true,
|
|
222
|
+
page: def.page ?? null,
|
|
223
|
+
inject: def.inject ?? null,
|
|
224
|
+
widget: def.widget ?? null,
|
|
225
|
+
};
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Badges of a row (doc 02: contracts, controllers, blocks, samples, widgets are opt-in and shown as badges).
|
|
231
|
+
* @param {Partial<Row> & { block?: boolean, page?: any, inject?: any, widget?: any }} row
|
|
232
|
+
* @param {string[]} states
|
|
233
|
+
* @param {string[]} controllersUsed
|
|
234
|
+
*/
|
|
235
|
+
export function badgesOf(row, states, controllersUsed = []) {
|
|
236
|
+
const badges = [];
|
|
237
|
+
|
|
238
|
+
if ((row.contract ?? 1) > 1) badges.push(`contract ${row.contract}`);
|
|
239
|
+
if (controllersUsed.length) badges.push("controllers");
|
|
240
|
+
if (row.block) badges.push("block");
|
|
241
|
+
if (row.page) badges.push("page");
|
|
242
|
+
if (row.inject) badges.push("injection");
|
|
243
|
+
if (row.widget) badges.push("widget");
|
|
244
|
+
if (states.includes("filled")) badges.push("samples");
|
|
245
|
+
|
|
246
|
+
return badges;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Filters of the list: plugin (`pano` = the engine), kind, status; each empty value matches everything.
|
|
251
|
+
* @template {{ ns: string, kind: string, status: string }} T
|
|
252
|
+
* @param {T[]} rows
|
|
253
|
+
* @param {{ plugin?: string, kind?: string, status?: string }} [filters]
|
|
254
|
+
* @returns {T[]}
|
|
255
|
+
*/
|
|
256
|
+
export function filterRows(rows, filters = {}) {
|
|
257
|
+
return rows.filter(
|
|
258
|
+
(row) =>
|
|
259
|
+
(!filters.plugin || row.ns === filters.plugin) &&
|
|
260
|
+
(!filters.kind || row.kind === filters.kind) &&
|
|
261
|
+
(!filters.status || row.status === filters.status),
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Values the three filter selects offer, from the rows. */
|
|
266
|
+
export function filterOptions(rows) {
|
|
267
|
+
const uniq = (key) => [...new Set(rows.map((row) => row[key]))].sort();
|
|
268
|
+
|
|
269
|
+
return { plugin: uniq("ns"), kind: uniq("kind"), status: uniq("status") };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The shape of `/__pano/views.json`: input of the visual comparison and the "same as before" shots.
|
|
274
|
+
* @param {Row[]} rows
|
|
275
|
+
* @param {string} [origin] prefix of every url (the page origin), "" for site-relative urls
|
|
276
|
+
*/
|
|
277
|
+
export function viewsJsonOf(rows, origin = "") {
|
|
278
|
+
return rows.map((row) => ({
|
|
279
|
+
id: row.id,
|
|
280
|
+
kind: row.kind,
|
|
281
|
+
contract: row.contract,
|
|
282
|
+
status: row.status,
|
|
283
|
+
states: row.states,
|
|
284
|
+
url: origin + row.url,
|
|
285
|
+
}));
|
|
286
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// `/__pano/views/<ns>/<view>?state=&palette=&source=theme|default&bare=1` (doc 02 section 7): one view with
|
|
2
|
+
// one sample state. Loaded by the generated `+page.js` behind `dev`.
|
|
3
|
+
//
|
|
4
|
+
// The load resolves everything the stage needs (the component of the chosen source, the sample, the readable
|
|
5
|
+
// source); `Stage.svelte` turns sample mode on while it is mounted and off when it leaves.
|
|
6
|
+
|
|
7
|
+
import { error } from "@sveltejs/kit";
|
|
8
|
+
|
|
9
|
+
import { loadCatalogue, samplesOf } from "./catalogue.js";
|
|
10
|
+
import { createDeps } from "./deps.js";
|
|
11
|
+
import { ejectCommand, parseStageQuery, resolveSample, viewIdFromParams } from "./model.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Props the contract marks as required that the sample does not give. The engine's contract describes props
|
|
15
|
+
* in prose, so only a plugin's `{ type, required }` records are checked.
|
|
16
|
+
* @param {Record<string, any>} contract
|
|
17
|
+
* @param {Record<string, any>} props
|
|
18
|
+
*/
|
|
19
|
+
export function missingProps(contract, props) {
|
|
20
|
+
return Object.entries(contract ?? {})
|
|
21
|
+
.filter(([name, spec]) => spec && typeof spec === "object" && spec.required === true && !(name in (props ?? {})))
|
|
22
|
+
.map(([name]) => name);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {{ url: URL, params: { ns: string, view: string }, fetch?: typeof fetch }} event
|
|
27
|
+
* @param {import("./catalogue.js").CatalogueDeps & {
|
|
28
|
+
* components?: { Stage: () => Promise<any> },
|
|
29
|
+
* readEngineSource?: (path: string) => Promise<string | null>,
|
|
30
|
+
* readText?: (pluginId: string, path: string) => Promise<string | null>,
|
|
31
|
+
* } | null} [deps] tests only
|
|
32
|
+
*/
|
|
33
|
+
export async function load(event, deps = null) {
|
|
34
|
+
const d = deps ?? (await createDeps(event));
|
|
35
|
+
const id = viewIdFromParams(event.params.ns, event.params.view);
|
|
36
|
+
const [row] = await loadCatalogue(d, { only: id });
|
|
37
|
+
|
|
38
|
+
if (!row) throw error(404, `No view named '${id}' in this theme`);
|
|
39
|
+
|
|
40
|
+
const query = parseStageQuery(event.url.searchParams, row.states);
|
|
41
|
+
const { samples } = await samplesOf(d, row);
|
|
42
|
+
const sample = await resolveSample(samples, query.state);
|
|
43
|
+
|
|
44
|
+
// The theme's component (the override while it is valid) or the default one, whichever the page asks for.
|
|
45
|
+
const resolved = await d.registry.resolveViewModule(id).catch(() => null);
|
|
46
|
+
const View = !resolved ? null : query.source === "default" ? (d.registry.getDefault?.(id) ?? resolved.module.default) : resolved.module.default;
|
|
47
|
+
const components = d.components ?? { Stage: () => import("./Stage.svelte") };
|
|
48
|
+
|
|
49
|
+
const readSource = row.pluginId
|
|
50
|
+
? d.readText?.(row.pluginId, row.source)
|
|
51
|
+
: d.readEngineSource?.(row.source);
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
component: (await components.Stage()).default,
|
|
55
|
+
id,
|
|
56
|
+
row,
|
|
57
|
+
...query,
|
|
58
|
+
sample,
|
|
59
|
+
View,
|
|
60
|
+
overridden: row.status === "overridden",
|
|
61
|
+
missing: missingProps(row.props, sample?.props),
|
|
62
|
+
eject: ejectCommand(id),
|
|
63
|
+
sourceText: Promise.resolve(readSource ?? null).catch(() => null),
|
|
64
|
+
// a bare stage drops the engine's chrome too (RootLayout skips MainLayout for `resetLayout`)
|
|
65
|
+
resetLayout: query.bare,
|
|
66
|
+
// the sample mode is rebuilt whenever one of these changes
|
|
67
|
+
stageKey: `${id}|${query.state}|${query.source}`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// `/__pano/views.json` (doc 02 section 7): `[{ id, kind, contract, status, states, url }]`, the input of the
|
|
2
|
+
// visual comparison and of the "same as before" shots. Loaded by the generated `+server.js` behind `dev`.
|
|
3
|
+
|
|
4
|
+
import { loadCatalogue } from "./catalogue.js";
|
|
5
|
+
import { createDeps } from "./deps.js";
|
|
6
|
+
import { filterRows, viewsJsonOf } from "./model.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {{ url: URL, fetch?: typeof fetch }} event the SvelteKit request event
|
|
10
|
+
* @param {import("./catalogue.js").CatalogueDeps | null} [deps] tests only
|
|
11
|
+
*/
|
|
12
|
+
export async function GET(event, deps = null) {
|
|
13
|
+
const d = deps ?? (await createDeps(event));
|
|
14
|
+
const params = event.url.searchParams;
|
|
15
|
+
const rows = filterRows(await loadCatalogue(d), {
|
|
16
|
+
plugin: params.get("plugin") ?? "",
|
|
17
|
+
kind: params.get("kind") ?? "",
|
|
18
|
+
status: params.get("status") ?? "",
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return new Response(JSON.stringify(viewsJsonOf(rows, event.url.origin), null, 2), {
|
|
22
|
+
headers: { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store" },
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -40,11 +40,13 @@
|
|
|
40
40
|
{/if}
|
|
41
41
|
|
|
42
42
|
<script context="module">
|
|
43
|
-
import { error } from "@sveltejs/kit";
|
|
43
|
+
import { error, redirect } from "@sveltejs/kit";
|
|
44
44
|
|
|
45
45
|
import { findMatch, registeredPages } from "$pano/lib/PluginManager.js";
|
|
46
46
|
import { base } from "$app/paths";
|
|
47
47
|
import { hasPermission } from "$pano/lib/auth.util.js";
|
|
48
|
+
import { loginRedirectFor } from "$pano/lib/returnTo.util.js";
|
|
49
|
+
import { resolveCanonical } from "$pano/registry/routes.js";
|
|
48
50
|
|
|
49
51
|
|
|
50
52
|
// Static imports instead of import.meta.glob: the glob's transform emits
|
|
@@ -77,23 +79,46 @@
|
|
|
77
79
|
*/
|
|
78
80
|
export async function load(event) {
|
|
79
81
|
const {
|
|
80
|
-
url: { pathname },
|
|
82
|
+
url: { pathname, search },
|
|
81
83
|
parent,
|
|
82
84
|
} = event;
|
|
83
85
|
const { session: { user } } = await parent();
|
|
84
86
|
|
|
85
|
-
|
|
87
|
+
// The URL carries the theme's public path (`/shop`); plugins register canonical paths
|
|
88
|
+
// (`/store`). A disabled route is `null`, and `/__pano*` can never be registered by a plugin
|
|
89
|
+
// (it is where `reroute` sends a disabled route), so both answer 404.
|
|
90
|
+
const sitePath = removePrefix(pathname, base);
|
|
91
|
+
const canonicalPath = resolveCanonical(sitePath);
|
|
92
|
+
|
|
93
|
+
if (canonicalPath === null || canonicalPath.startsWith("/__pano")) {
|
|
94
|
+
throw error(404);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const registeredPage = findMatch(registeredPages, canonicalPath);
|
|
86
98
|
|
|
87
99
|
if (registeredPage === undefined || registeredPage === null) {
|
|
88
100
|
throw error(404);
|
|
89
101
|
}
|
|
90
102
|
|
|
103
|
+
// A guest on a `loginRequired` page goes to login (and comes back) — this runs BEFORE the
|
|
104
|
+
// permission check, which would otherwise answer a guest with a 404.
|
|
105
|
+
const loginTarget = loginRedirectFor(registeredPage, user, { pathname, search });
|
|
106
|
+
if (loginTarget) {
|
|
107
|
+
throw redirect(302, loginTarget);
|
|
108
|
+
}
|
|
109
|
+
|
|
91
110
|
if (registeredPage.permission && !hasPermission(registeredPage.permission, user)) {
|
|
92
111
|
throw error(404);
|
|
93
112
|
}
|
|
94
113
|
|
|
95
114
|
const resetLayout = registeredPage.resetLayout || false;
|
|
96
115
|
|
|
116
|
+
// Route params of the matched plugin page (e.g. `[slug]`) reach the system layout's and the
|
|
117
|
+
// plugin layout's load, exactly as they reach the page load.
|
|
118
|
+
if (registeredPage.params) {
|
|
119
|
+
event.params = { ...event.params, ...registeredPage.params };
|
|
120
|
+
}
|
|
121
|
+
|
|
97
122
|
let systemLayout = null;
|
|
98
123
|
let systemLayoutOutput = {};
|
|
99
124
|
if (registeredPage.systemLayout) {
|
|
@@ -134,7 +159,7 @@
|
|
|
134
159
|
// Expose layout-consumed fields from the plugin layout's load output
|
|
135
160
|
// at the top level so they end up on page.data (e.g. pageTitle, sidebar).
|
|
136
161
|
if (layoutOutput && typeof layoutOutput === "object") {
|
|
137
|
-
for (const key of ["pageTitle", "breadcrumbs", "sidebar", "sidebarProps"]) {
|
|
162
|
+
for (const key of ["pageTitle", "breadcrumbs", "sidebar", "sidebarProps", "meta"]) {
|
|
138
163
|
if (layoutOutput[key] !== undefined) {
|
|
139
164
|
output[key] = layoutOutput[key];
|
|
140
165
|
}
|
|
@@ -1,64 +1,119 @@
|
|
|
1
|
-
{#if !browser}
|
|
2
|
-
<!-- Server Side: Native Rendering to preserve Context ($page store)
|
|
3
|
-
|
|
1
|
+
{#if !browser || data.viewSource === "override"}
|
|
2
|
+
<!-- Server Side: Native Rendering to preserve Context ($page store).
|
|
3
|
+
A view the theme overrides (doc 01 section 4) renders natively on the client too: it is the theme's own
|
|
4
|
+
component, same Svelte, same contexts, so there is nothing to bridge. -->
|
|
5
|
+
<!-- In a theme without Bootstrap a default view sits in the fallback scope of its plugin and an override nested
|
|
6
|
+
in such a scope in a stop scope (`views.wrap`, doc 03 section 4.4); `Rendered` is the component itself otherwise. -->
|
|
7
|
+
<svelte:component this={Rendered} {...data.props || {}} />
|
|
4
8
|
{:else}
|
|
5
9
|
<!-- Client Side: Manual Mount to prevent Runtime Mismatch (effect_orphan) -->
|
|
6
10
|
{#key data}
|
|
7
|
-
<div
|
|
11
|
+
<div
|
|
12
|
+
use:mountPlugin
|
|
13
|
+
class="plugin-view-container{scope.mode === 'fallback' ? ' pano-fb' : ''}"
|
|
14
|
+
data-pano-fb={scope.mode === 'fallback' ? scope.ns : undefined}
|
|
15
|
+
></div>
|
|
8
16
|
{/key}
|
|
9
17
|
{/if}
|
|
10
18
|
|
|
11
19
|
<script context="module">
|
|
20
|
+
import { get } from "svelte/store";
|
|
21
|
+
|
|
22
|
+
import { executeSidebarLoad, panoApi } from "$pano/lib/PluginAPI";
|
|
23
|
+
import * as HomeSidebar from "$pano/lib/components/sidebars/HomeSidebar.svelte";
|
|
24
|
+
import * as ProfileSidebar from "$pano/lib/components/sidebars/ProfileSidebar.svelte";
|
|
25
|
+
import PluginSidebar from "$pano/lib/components/sidebars/PluginSidebar.svelte";
|
|
26
|
+
|
|
27
|
+
import { loadPluginPage } from "./load.js";
|
|
28
|
+
|
|
29
|
+
// The sidebars a plugin page may name with a string (`sidebar: "home"`); `HomePage.svelte` uses the
|
|
30
|
+
// same set when a plugin page is the home page.
|
|
31
|
+
export const sidebarDeps = {
|
|
32
|
+
hosts: { home: HomeSidebar, profile: ProfileSidebar },
|
|
33
|
+
PluginSidebar,
|
|
34
|
+
executeSidebarLoad,
|
|
35
|
+
countVisible: (sidebarId) => get(panoApi.ui.sidebar.get(sidebarId)).length,
|
|
36
|
+
};
|
|
37
|
+
|
|
12
38
|
/**
|
|
13
39
|
* @type {import('@sveltejs/kit').PageLoad}
|
|
14
40
|
*/
|
|
15
41
|
export async function load(event) {
|
|
16
|
-
const {
|
|
17
|
-
const { registeredPage } = await parent();
|
|
42
|
+
const { registeredPage } = await event.parent();
|
|
18
43
|
|
|
19
|
-
|
|
44
|
+
return loadPluginPage(event, registeredPage, sidebarDeps);
|
|
45
|
+
}
|
|
46
|
+
</script>
|
|
20
47
|
|
|
21
|
-
|
|
48
|
+
<script>
|
|
49
|
+
import { mount, unmount, hydrate, getAllContexts } from 'svelte';
|
|
50
|
+
import { getPanoContext } from '@panomc/sdk/internal';
|
|
51
|
+
import { browser } from '$app/environment';
|
|
52
|
+
import { SCOPE_CONTEXT } from '$pano/lib/fallbackStyles.js';
|
|
22
53
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
54
|
+
export let data;
|
|
55
|
+
|
|
56
|
+
const pageContexts = getAllContexts();
|
|
57
|
+
|
|
58
|
+
/** The name the page was registered with (`<ns>:<Name>`); a legacy page (`component` only) has none. */
|
|
59
|
+
$: viewName = data.registeredPage?.view;
|
|
60
|
+
$: source = data.viewSource === 'override' ? 'override' : 'default';
|
|
61
|
+
$: views = getPanoContext().context?.views;
|
|
62
|
+
|
|
63
|
+
// Server and native branch: the component, wrapped when the theme has no Bootstrap. A named view goes through
|
|
64
|
+
// `wrap`; a legacy page (`component` only, no view name) through `wrapInjected`, which gives it the `legacy` scope.
|
|
65
|
+
$: Rendered = renderedComponent(viewName, source, views, data.component);
|
|
66
|
+
|
|
67
|
+
// Client branch (manual mount, default views and legacy pages only): the scope goes on the container div and into
|
|
68
|
+
// the context of the mounted component. Asking `wrap` / `wrapInjected` also registers the stylesheets the view
|
|
69
|
+
// needs; a wrapped component carries its scope as `.scope`.
|
|
70
|
+
$: scope = clientScope(viewName, source, views, data.component) ?? { mode: null, ns: '' };
|
|
27
71
|
|
|
28
|
-
|
|
29
|
-
|
|
72
|
+
function renderedComponent(name, current, hooks, module) {
|
|
73
|
+
if (name) {
|
|
74
|
+
return (!browser || current === 'override') && typeof hooks?.wrap === 'function'
|
|
75
|
+
? (hooks.wrap(name, module.default, current) ?? module.default)
|
|
76
|
+
: module.default;
|
|
30
77
|
}
|
|
31
78
|
|
|
32
|
-
|
|
79
|
+
return !browser && typeof hooks?.wrapInjected === 'function'
|
|
80
|
+
? (hooks.wrapInjected(module) ?? module.default)
|
|
81
|
+
: module.default;
|
|
82
|
+
}
|
|
33
83
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}
|
|
84
|
+
function clientScope(name, current, hooks, module) {
|
|
85
|
+
if (!browser) return null;
|
|
86
|
+
|
|
87
|
+
if (name) {
|
|
88
|
+
return current === 'default' && typeof hooks?.wrap === 'function'
|
|
89
|
+
? hooks.wrap(name, module.default, current)?.scope
|
|
90
|
+
: null;
|
|
43
91
|
}
|
|
44
92
|
|
|
45
|
-
return
|
|
93
|
+
return typeof hooks?.wrapInjected === 'function' ? hooks.wrapInjected(module)?.scope : null;
|
|
46
94
|
}
|
|
47
|
-
</script>
|
|
48
95
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
96
|
+
/**
|
|
97
|
+
* The page's contexts, plus the fallback scope the container opens (views below it must not wrap again).
|
|
98
|
+
* A copy: the map belongs to the parent component, and its other children read it.
|
|
99
|
+
*/
|
|
100
|
+
function scopedContexts(current) {
|
|
101
|
+
if (current.mode !== 'fallback') return pageContexts;
|
|
52
102
|
|
|
53
|
-
|
|
103
|
+
const copy = new Map(pageContexts);
|
|
54
104
|
|
|
55
|
-
|
|
105
|
+
copy.set(SCOPE_CONTEXT, current.ns);
|
|
106
|
+
|
|
107
|
+
return copy;
|
|
108
|
+
}
|
|
56
109
|
|
|
57
110
|
function mountPlugin(viewContainer) {
|
|
58
111
|
if (!browser || !viewContainer || !data.component?.default) return;
|
|
59
112
|
|
|
60
113
|
let componentInstance;
|
|
61
114
|
|
|
115
|
+
const contexts = scopedContexts(scope);
|
|
116
|
+
|
|
62
117
|
try {
|
|
63
118
|
if (data.component.hydrate) {
|
|
64
119
|
try {
|