@panomc/theme-core 1.0.0-dev.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/bundle-internal-libs.js +104 -0
- package/bin/check.js +253 -0
- package/bin/generate-licenses.js +125 -0
- package/bin/generate-runtime-shims.js +180 -0
- package/bin/license/file-fingerprint.js +74 -0
- package/bin/license/finalize-fingerprint.js +72 -0
- package/bin/license/generate-license-constants.js +335 -0
- package/bin/new.js +281 -0
- package/bin/package-zip.js +57 -0
- package/bin/sync.js +326 -0
- package/bin/templates/app.html +59 -0
- package/bin/theme-core.js +103 -0
- package/package.json +77 -0
- package/src/index.js +15 -0
- package/src/kit/hooks-client.js +128 -0
- package/src/kit/hooks-server.js +319 -0
- package/src/kit/license-runtime.js +373 -0
- package/src/kit/resolve.js +71 -0
- package/src/kit/specifiers.js +62 -0
- package/src/kit/svelte-config.js +74 -0
- package/src/kit/vite-config.js +249 -0
- package/src/lib/NotificationManager.js +1 -0
- package/src/lib/PluginAPI.js +368 -0
- package/src/lib/PluginManager.js +1 -0
- package/src/lib/Store.js +43 -0
- package/src/lib/api.util.js +5 -0
- package/src/lib/auth.util.js +77 -0
- package/src/lib/components/App.svelte +10 -0
- package/src/lib/components/Breadcrumb.svelte +88 -0
- package/src/lib/components/CardHeader.svelte +42 -0
- package/src/lib/components/Date.svelte +34 -0
- package/src/lib/components/DefaultToast.svelte +11 -0
- package/src/lib/components/ErrorAlert.svelte +16 -0
- package/src/lib/components/Footer.svelte +223 -0
- package/src/lib/components/Header.svelte +122 -0
- package/src/lib/components/Hook.svelte +71 -0
- package/src/lib/components/LinkCodeInput.svelte +129 -0
- package/src/lib/components/LoginFormBody.svelte +90 -0
- package/src/lib/components/Main.svelte +76 -0
- package/src/lib/components/Navbar.svelte +462 -0
- package/src/lib/components/NoContent.svelte +14 -0
- package/src/lib/components/NotificationContainer.svelte +304 -0
- package/src/lib/components/OnlineAdmins.svelte +64 -0
- package/src/lib/components/PageActions.svelte +39 -0
- package/src/lib/components/PageTitle.svelte +36 -0
- package/src/lib/components/Pagination.svelte +65 -0
- package/src/lib/components/PlayerHead.svelte +58 -0
- package/src/lib/components/PlayerPermissionBadge.svelte +19 -0
- package/src/lib/components/PlayerStatusBadge.svelte +63 -0
- package/src/lib/components/Post.svelte +240 -0
- package/src/lib/components/Posts.svelte +19 -0
- package/src/lib/components/RegisterForm.svelte +125 -0
- package/src/lib/components/Sidebar.svelte +12 -0
- package/src/lib/components/SuccessAlert.svelte +14 -0
- package/src/lib/components/TicketRow.svelte +61 -0
- package/src/lib/components/TicketStatus.svelte +24 -0
- package/src/lib/components/Tickets.svelte +43 -0
- package/src/lib/components/Toast.svelte +13 -0
- package/src/lib/components/ToastContainer.svelte +83 -0
- package/src/lib/components/ViewComponent.svelte +8 -0
- package/src/lib/components/modals/CloseTicketConfirmModal.svelte +121 -0
- package/src/lib/components/modals/ConfirmRemoveAllNotificationsModal.svelte +93 -0
- package/src/lib/components/modals/LogoutSessionConfirmModal.svelte +61 -0
- package/src/lib/components/sidebars/HomeSidebar.svelte +333 -0
- package/src/lib/components/sidebars/PlayerDetailSidebar.svelte +124 -0
- package/src/lib/components/sidebars/ProfileSidebar.svelte +149 -0
- package/src/lib/components/sidebars/SupportSidebar.svelte +54 -0
- package/src/lib/components/sidebars/TicketCreateAndDetailSidebar.svelte +84 -0
- package/src/lib/csrf.js +5 -0
- package/src/lib/init.libs.js +2 -0
- package/src/lib/language.util.js +154 -0
- package/src/lib/layouts/AppLayout.svelte +59 -0
- package/src/lib/layouts/AuthLayout.svelte +29 -0
- package/src/lib/layouts/MainLayout.svelte +60 -0
- package/src/lib/layouts/ProfileLayout.svelte +29 -0
- package/src/lib/layouts/ThemeSettingsLayout.svelte +37 -0
- package/src/lib/layouts/TicketsLayout.svelte +31 -0
- package/src/lib/loginInput.util.js +4 -0
- package/src/lib/orderNavLinks.util.js +58 -0
- package/src/lib/pages/ActivateEmailPage.svelte +48 -0
- package/src/lib/pages/ConfirmNewEmailPage.svelte +48 -0
- package/src/lib/pages/ErrorPage.svelte +41 -0
- package/src/lib/pages/HomePage.svelte +35 -0
- package/src/lib/pages/LoginPage.svelte +448 -0
- package/src/lib/pages/NotificationsPage.svelte +70 -0
- package/src/lib/pages/PlayerDetailPage.svelte +29 -0
- package/src/lib/pages/PostDetailPage.svelte +36 -0
- package/src/lib/pages/PreviewPostPage.svelte +38 -0
- package/src/lib/pages/RegisterPage.svelte +144 -0
- package/src/lib/pages/RenewPasswordPage.svelte +49 -0
- package/src/lib/pages/ResetPasswordPage.svelte +55 -0
- package/src/lib/pages/RulesPage.svelte +52 -0
- package/src/lib/pages/SupportPage.svelte +36 -0
- package/src/lib/pages/ThemeSettingsPage.svelte +551 -0
- package/src/lib/pages/profile/ProfilePage.svelte +32 -0
- package/src/lib/pages/profile/SettingsPage.svelte +163 -0
- package/src/lib/pages/profile/TicketsPage.svelte +54 -0
- package/src/lib/pages/ticket/CreateTicketPage.svelte +48 -0
- package/src/lib/pages/ticket/TicketDetailPage.svelte +59 -0
- package/src/lib/services/auth.js +85 -0
- package/src/lib/services/posts.js +152 -0
- package/src/lib/services/profile.js +37 -0
- package/src/lib/services/theme-setting.js +22 -0
- package/src/lib/services/tickets.js +95 -0
- package/src/lib/siteRealtime.js +244 -0
- package/src/lib/string.util.js +27 -0
- package/src/lib/tooltip.util.js +5 -0
- package/src/lib/ui-logics/layout-logics/AppLayoutLogics.js +321 -0
- package/src/lib/ui-logics/layout-logics/AuthLayoutLogics.js +10 -0
- package/src/lib/ui-logics/layout-logics/MainLayoutLogics.js +19 -0
- package/src/lib/ui-logics/layout-logics/ProfileLayoutLogics.js +10 -0
- package/src/lib/ui-logics/layout-logics/ThemeSettingsLayoutLogics.js +215 -0
- package/src/lib/ui-logics/layout-logics/TicketsLayoutLogics.js +10 -0
- package/src/lib/ui-logics/page-logics/ActiveEmailPageLogics.js +45 -0
- package/src/lib/ui-logics/page-logics/ConfirmNewEmailPageLogics.js +42 -0
- package/src/lib/ui-logics/page-logics/CreateTicketPageLogics.js +83 -0
- package/src/lib/ui-logics/page-logics/HomePageLogics.js +65 -0
- package/src/lib/ui-logics/page-logics/NotificationsPageLogics.js +264 -0
- package/src/lib/ui-logics/page-logics/PlayerDetailPageLogics.js +40 -0
- package/src/lib/ui-logics/page-logics/PostDetailPageLogics.js +58 -0
- package/src/lib/ui-logics/page-logics/PreviewPostPageLogics.js +53 -0
- package/src/lib/ui-logics/page-logics/ProfilePageLogics.js +44 -0
- package/src/lib/ui-logics/page-logics/RenewPasswordPageLogics.js +44 -0
- package/src/lib/ui-logics/page-logics/ResetPasswordPageLogics.js +53 -0
- package/src/lib/ui-logics/page-logics/SettingsPageLogics.js +230 -0
- package/src/lib/ui-logics/page-logics/SupportPageLogics.js +60 -0
- package/src/lib/ui-logics/page-logics/TicketDetailPageLogics.js +160 -0
- package/src/lib/ui-logics/page-logics/TicketsPageLogics.js +132 -0
- package/src/lib/variables.js +1 -0
- package/src/lib/views/ActivateEmailView.svelte +71 -0
- package/src/lib/views/AppLayoutView.svelte +31 -0
- package/src/lib/views/AuthLayoutView.svelte +23 -0
- package/src/lib/views/ConfirmNewEmailView.svelte +71 -0
- package/src/lib/views/CreateTicketView.svelte +73 -0
- package/src/lib/views/ErrorView.svelte +38 -0
- package/src/lib/views/HomeView.svelte +72 -0
- package/src/lib/views/LoginView.svelte +372 -0
- package/src/lib/views/MainLayoutView.svelte +86 -0
- package/src/lib/views/NotificationsView.svelte +129 -0
- package/src/lib/views/PlayerDetailView.svelte +31 -0
- package/src/lib/views/PostDetailView.svelte +199 -0
- package/src/lib/views/PreviewPostView.svelte +151 -0
- package/src/lib/views/ProfileLayoutView.svelte +16 -0
- package/src/lib/views/ProfileView.svelte +68 -0
- package/src/lib/views/RegisterView.svelte +113 -0
- package/src/lib/views/RenewPasswordView.svelte +98 -0
- package/src/lib/views/ResetPasswordView.svelte +88 -0
- package/src/lib/views/RulesView.svelte +26 -0
- package/src/lib/views/SettingsView.svelte +471 -0
- package/src/lib/views/SupportView.svelte +79 -0
- package/src/lib/views/ThemeSettingsLayoutView.svelte +19 -0
- package/src/lib/views/ThemeSettingsView.svelte +1508 -0
- package/src/lib/views/TicketDetailView.svelte +185 -0
- package/src/lib/views/TicketsLayoutView.svelte +21 -0
- package/src/lib/views/TicketsView.svelte +87 -0
- package/src/plugin-engine/engine.js +484 -0
- package/src/registry/index.js +86 -0
- package/src/routes/RootLayout.svelte +21 -0
- package/src/routes/plugin-ui/Layout.svelte +291 -0
- package/src/routes/plugin-ui/Page.svelte +117 -0
- package/src/routes/plugin-ui/layout.js +8 -0
- package/src/routes/plugin-ui/page.js +8 -0
- package/src/routes/plugins-client-file.js +76 -0
- package/src/routes/root-layout-load.js +15 -0
- package/src/routes/theme-api-languages.js +52 -0
- package/src/routes/theme-api-licenses.js +28 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
<style>
|
|
2
|
+
.plugin-layout-container {
|
|
3
|
+
width: 100%;
|
|
4
|
+
height: 100%;
|
|
5
|
+
}
|
|
6
|
+
</style>
|
|
7
|
+
|
|
8
|
+
{#if data.systemLayout}
|
|
9
|
+
<svelte:component this={data.systemLayout} {data}>
|
|
10
|
+
<div
|
|
11
|
+
bind:this={layoutContainer}
|
|
12
|
+
class="plugin-layout-container"
|
|
13
|
+
style={data.layout ? '' : 'display: none;'}>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
<div
|
|
17
|
+
bind:this={slotContentContainer}
|
|
18
|
+
class="plugin-content-wrapper"
|
|
19
|
+
style={data.layout ? 'display: none;' : ''}>
|
|
20
|
+
{#key data}
|
|
21
|
+
<slot />
|
|
22
|
+
{/key}
|
|
23
|
+
</div>
|
|
24
|
+
</svelte:component>
|
|
25
|
+
{:else}
|
|
26
|
+
<div
|
|
27
|
+
bind:this={layoutContainer}
|
|
28
|
+
class="plugin-layout-container"
|
|
29
|
+
style={data.layout ? '' : 'display: none;'}>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<div
|
|
33
|
+
bind:this={slotContentContainer}
|
|
34
|
+
class="plugin-content-wrapper"
|
|
35
|
+
style={data.layout ? 'display: none;' : ''}>
|
|
36
|
+
{#key data}
|
|
37
|
+
<slot />
|
|
38
|
+
{/key}
|
|
39
|
+
</div>
|
|
40
|
+
{/if}
|
|
41
|
+
|
|
42
|
+
<script context="module">
|
|
43
|
+
import { error } from "@sveltejs/kit";
|
|
44
|
+
|
|
45
|
+
import { findMatch, registeredPages } from "$pano/lib/PluginManager.js";
|
|
46
|
+
import { base } from "$app/paths";
|
|
47
|
+
import { hasPermission } from "$pano/lib/auth.util.js";
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
const layouts = import.meta.glob('$pano/lib/layouts/*.svelte', { eager: true });
|
|
51
|
+
|
|
52
|
+
const layoutMap = Object.keys(layouts).reduce((acc, path) => {
|
|
53
|
+
const name = path.split('/').pop().replace('.svelte', '');
|
|
54
|
+
acc[name] = layouts[path];
|
|
55
|
+
return acc;
|
|
56
|
+
}, {});
|
|
57
|
+
|
|
58
|
+
function removePrefix(str, prefix) {
|
|
59
|
+
return str.startsWith(prefix) ? str.slice(prefix.length) : str;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @type {import("@sveltejs/kit").PageLoad}
|
|
64
|
+
*/
|
|
65
|
+
export async function load(event) {
|
|
66
|
+
const {
|
|
67
|
+
url: { pathname },
|
|
68
|
+
parent,
|
|
69
|
+
} = event;
|
|
70
|
+
const { session: { user } } = await parent();
|
|
71
|
+
|
|
72
|
+
const registeredPage = findMatch(registeredPages, removePrefix(pathname, base));
|
|
73
|
+
|
|
74
|
+
if (registeredPage === undefined || registeredPage === null) {
|
|
75
|
+
throw error(404);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (registeredPage.permission && !hasPermission(registeredPage.permission, user)) {
|
|
79
|
+
throw error(404);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const resetLayout = registeredPage.resetLayout || false;
|
|
83
|
+
|
|
84
|
+
let systemLayout = null;
|
|
85
|
+
let systemLayoutOutput = {};
|
|
86
|
+
if (registeredPage.systemLayout) {
|
|
87
|
+
const systemLayoutModule = layoutMap[registeredPage.systemLayout];
|
|
88
|
+
if (systemLayoutModule) {
|
|
89
|
+
systemLayout = systemLayoutModule.default;
|
|
90
|
+
if (typeof systemLayoutModule.load === 'function') {
|
|
91
|
+
systemLayoutOutput = await systemLayoutModule.load(event);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let layoutOutput = {};
|
|
97
|
+
let layout = null;
|
|
98
|
+
if (registeredPage.layout) {
|
|
99
|
+
// Check if layout is a function (async import) or object
|
|
100
|
+
const layoutModule =
|
|
101
|
+
typeof registeredPage.layout === 'function'
|
|
102
|
+
? await registeredPage.layout()
|
|
103
|
+
: registeredPage.layout;
|
|
104
|
+
layout = layoutModule;
|
|
105
|
+
|
|
106
|
+
if (layout.load !== undefined) {
|
|
107
|
+
layoutOutput = await layout.load(event);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const output = {
|
|
112
|
+
registeredPage,
|
|
113
|
+
layout,
|
|
114
|
+
systemLayout,
|
|
115
|
+
props: layoutOutput,
|
|
116
|
+
params: registeredPage.params,
|
|
117
|
+
...systemLayoutOutput,
|
|
118
|
+
resetLayout
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// Expose layout-consumed fields from the plugin layout's load output
|
|
122
|
+
// at the top level so they end up on page.data (e.g. pageTitle, sidebar).
|
|
123
|
+
if (layoutOutput && typeof layoutOutput === "object") {
|
|
124
|
+
for (const key of ["pageTitle", "breadcrumbs", "sidebar", "sidebarProps"]) {
|
|
125
|
+
if (layoutOutput[key] !== undefined) {
|
|
126
|
+
output[key] = layoutOutput[key];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return output;
|
|
132
|
+
}
|
|
133
|
+
</script>
|
|
134
|
+
|
|
135
|
+
<script>
|
|
136
|
+
import { mount, unmount, getAllContexts } from 'svelte';
|
|
137
|
+
import { browser } from '$app/environment';
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
let { data } = $props();
|
|
141
|
+
|
|
142
|
+
const contexts = getAllContexts();
|
|
143
|
+
|
|
144
|
+
let layoutContainer = $state();
|
|
145
|
+
let slotContentContainer = $state();
|
|
146
|
+
let layoutInstance = null;
|
|
147
|
+
let activeLayoutComp = null;
|
|
148
|
+
|
|
149
|
+
// The slot wrapper's NATURAL DOM position (where Svelte rendered it, inside the theme
|
|
150
|
+
// shell / systemLayout). Captured on first bind — BEFORE any bridging move — so pages
|
|
151
|
+
// without a plugin layout can always be restored to normal document flow.
|
|
152
|
+
let slotHome = null;
|
|
153
|
+
|
|
154
|
+
$effect(() => {
|
|
155
|
+
if (!browser || !slotContentContainer || slotHome) return;
|
|
156
|
+
slotHome = {
|
|
157
|
+
parent: slotContentContainer.parentNode,
|
|
158
|
+
anchor: slotContentContainer.nextSibling,
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// A stable parent the slot content survives layout TEARDOWN in: before destroying a
|
|
163
|
+
// mounted layout we park the slot content here so the live <slot> subtree is never
|
|
164
|
+
// torn out together with the layout.
|
|
165
|
+
function stableSlotParent() {
|
|
166
|
+
return browser ? document.body : null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Put the slot wrapper back where Svelte originally rendered it (its SSR position).
|
|
170
|
+
function restoreSlotHome() {
|
|
171
|
+
if (!browser || !slotContentContainer || !slotHome?.parent?.isConnected) return;
|
|
172
|
+
if (slotContentContainer.parentNode !== slotHome.parent) {
|
|
173
|
+
slotHome.parent.insertBefore(
|
|
174
|
+
slotContentContainer,
|
|
175
|
+
slotHome.anchor?.parentNode === slotHome.parent ? slotHome.anchor : null,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function cleanupLayout() {
|
|
181
|
+
// Park the slot content outside the layout BEFORE unmounting it, otherwise unmounting
|
|
182
|
+
// rips the live <slot> subtree out of the DOM -> blank/torn content and a detached-DOM
|
|
183
|
+
// leak. ONLY when a layout is actually mounted: running this unconditionally stranded
|
|
184
|
+
// every no-layout plugin page's content at the end of <body> on hydration — the page
|
|
185
|
+
// rendered fine in SSR, then "vanished" below the footer at CSR (title correct, body
|
|
186
|
+
// seemingly gone).
|
|
187
|
+
if (browser && slotContentContainer && layoutInstance) {
|
|
188
|
+
const parent = stableSlotParent();
|
|
189
|
+
if (parent && slotContentContainer.parentNode !== parent) {
|
|
190
|
+
slotContentContainer.style.display = 'none';
|
|
191
|
+
parent.appendChild(slotContentContainer);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (layoutInstance) {
|
|
196
|
+
try {
|
|
197
|
+
// Use the snapshot of what was mounted
|
|
198
|
+
if (typeof activeLayoutComp?.unmount === 'function')
|
|
199
|
+
activeLayoutComp.unmount(layoutInstance);
|
|
200
|
+
else unmount(layoutInstance);
|
|
201
|
+
} catch (e) {}
|
|
202
|
+
layoutInstance = null;
|
|
203
|
+
activeLayoutComp = null;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Layout lifecycle: mount / re-mount the dynamic plugin layout into the persistent
|
|
208
|
+
// layoutContainer. The container itself is NOT keyed, so navigation between plugin pages never
|
|
209
|
+
// destroys it and never tears out the bridged slot content.
|
|
210
|
+
$effect(() => {
|
|
211
|
+
if (!browser || !layoutContainer) return;
|
|
212
|
+
|
|
213
|
+
if (!data.layout) {
|
|
214
|
+
cleanupLayout();
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const layoutComp = data.layout.default || data.layout;
|
|
219
|
+
if (activeLayoutComp !== data.layout) {
|
|
220
|
+
cleanupLayout();
|
|
221
|
+
try {
|
|
222
|
+
if (data.layout.mount) {
|
|
223
|
+
layoutInstance = data.layout.mount({
|
|
224
|
+
target: layoutContainer,
|
|
225
|
+
props: { ...(data.props || {}), panoContexts: contexts },
|
|
226
|
+
context: contexts,
|
|
227
|
+
});
|
|
228
|
+
} else {
|
|
229
|
+
layoutInstance = mount(layoutComp, {
|
|
230
|
+
target: layoutContainer,
|
|
231
|
+
props: { ...(data.props || {}), panoContexts: contexts },
|
|
232
|
+
context: contexts,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
activeLayoutComp = data.layout;
|
|
236
|
+
} catch (e) {
|
|
237
|
+
console.error('[Layout] Mount failed', e);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
$effect(() => () => cleanupLayout());
|
|
243
|
+
|
|
244
|
+
// Slot bridge: move the slot content into the layout's content anchor. Only append when the
|
|
245
|
+
// slot is not already the anchor's last child, so we never detach a live, correctly-placed
|
|
246
|
+
// subtree (which would blank the content during re-renders).
|
|
247
|
+
$effect(() => {
|
|
248
|
+
const _pageData = data; // dependency
|
|
249
|
+
if (!browser) return;
|
|
250
|
+
|
|
251
|
+
let rafId;
|
|
252
|
+
const poll = () => {
|
|
253
|
+
if (!slotContentContainer) {
|
|
254
|
+
rafId = requestAnimationFrame(poll);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// No dynamic layout: make sure the wrapper sits in its natural (SSR) position —
|
|
259
|
+
// a previous layout page's teardown may have parked it on <body> — then reset
|
|
260
|
+
// style and stop polling.
|
|
261
|
+
if (!data.layout) {
|
|
262
|
+
restoreSlotHome();
|
|
263
|
+
slotContentContainer.style.display = '';
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const anchor = layoutContainer?.querySelector(
|
|
268
|
+
'[data-pano-content], main, .content, .page-content, article',
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
if (anchor) {
|
|
272
|
+
if (anchor.lastElementChild !== slotContentContainer) {
|
|
273
|
+
anchor.appendChild(slotContentContainer);
|
|
274
|
+
}
|
|
275
|
+
slotContentContainer.style.display = '';
|
|
276
|
+
} else if (layoutContainer?.firstElementChild) {
|
|
277
|
+
if (layoutContainer.firstElementChild.lastElementChild !== slotContentContainer) {
|
|
278
|
+
layoutContainer.firstElementChild.appendChild(slotContentContainer);
|
|
279
|
+
}
|
|
280
|
+
slotContentContainer.style.display = '';
|
|
281
|
+
} else {
|
|
282
|
+
rafId = requestAnimationFrame(poll);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
poll();
|
|
287
|
+
return () => {
|
|
288
|
+
if (rafId) cancelAnimationFrame(rafId);
|
|
289
|
+
};
|
|
290
|
+
});
|
|
291
|
+
</script>
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
{#if !browser}
|
|
2
|
+
<!-- Server Side: Native Rendering to preserve Context ($page store) -->
|
|
3
|
+
<svelte:component this={data.component.default} {...data.props || {}} />
|
|
4
|
+
{:else}
|
|
5
|
+
<!-- Client Side: Manual Mount to prevent Runtime Mismatch (effect_orphan) -->
|
|
6
|
+
{#key data}
|
|
7
|
+
<div use:mountPlugin class="plugin-view-container"></div>
|
|
8
|
+
{/key}
|
|
9
|
+
{/if}
|
|
10
|
+
|
|
11
|
+
<script context="module">
|
|
12
|
+
/**
|
|
13
|
+
* @type {import('@sveltejs/kit').PageLoad}
|
|
14
|
+
*/
|
|
15
|
+
export async function load(event) {
|
|
16
|
+
const { parent } = event;
|
|
17
|
+
const { registeredPage } = await parent();
|
|
18
|
+
|
|
19
|
+
let componentOutput = {};
|
|
20
|
+
|
|
21
|
+
const component = await registeredPage.component();
|
|
22
|
+
|
|
23
|
+
// Inject plugin-specific params into the event
|
|
24
|
+
if (registeredPage.params) {
|
|
25
|
+
event.params = { ...event.params, ...registeredPage.params };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (component.load !== undefined) {
|
|
29
|
+
componentOutput = await component.load(event);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const output = { registeredPage, component, props: componentOutput };
|
|
33
|
+
|
|
34
|
+
// Expose layout-consumed fields from the component's load output
|
|
35
|
+
// at the top level so they end up on page.data (e.g. pageTitle is
|
|
36
|
+
// read by AppLayout/MainLayout to set <title> and the PageTitle component).
|
|
37
|
+
if (componentOutput && typeof componentOutput === "object") {
|
|
38
|
+
for (const key of ["pageTitle", "breadcrumbs", "sidebar", "sidebarProps"]) {
|
|
39
|
+
if (componentOutput[key] !== undefined) {
|
|
40
|
+
output[key] = componentOutput[key];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return output;
|
|
46
|
+
}
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<script>
|
|
50
|
+
import { mount, unmount, hydrate, getAllContexts } from 'svelte';
|
|
51
|
+
import { browser } from '$app/environment';
|
|
52
|
+
|
|
53
|
+
export let data;
|
|
54
|
+
|
|
55
|
+
const contexts = getAllContexts();
|
|
56
|
+
|
|
57
|
+
function mountPlugin(viewContainer) {
|
|
58
|
+
if (!browser || !viewContainer || !data.component?.default) return;
|
|
59
|
+
|
|
60
|
+
let componentInstance;
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
if (data.component.hydrate) {
|
|
64
|
+
try {
|
|
65
|
+
componentInstance = data.component.hydrate({
|
|
66
|
+
target: viewContainer,
|
|
67
|
+
props: { ...(data.props || {}), panoContexts: contexts },
|
|
68
|
+
context: contexts
|
|
69
|
+
});
|
|
70
|
+
} catch (hErr) {
|
|
71
|
+
console.warn('Plugin Hydration Failed (Mismatch), falling back to Clean Mount:', hErr);
|
|
72
|
+
viewContainer.innerHTML = '';
|
|
73
|
+
componentInstance = data.component.mount({
|
|
74
|
+
target: viewContainer,
|
|
75
|
+
props: { ...(data.props || {}), panoContexts: contexts },
|
|
76
|
+
context: contexts
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Legacy/Fallback for non-bridged (Native)
|
|
81
|
+
else {
|
|
82
|
+
try {
|
|
83
|
+
componentInstance = hydrate(data.component.default, {
|
|
84
|
+
target: viewContainer,
|
|
85
|
+
props: { ...(data.props || {}), panoContexts: contexts },
|
|
86
|
+
context: contexts
|
|
87
|
+
});
|
|
88
|
+
} catch (hErr) {
|
|
89
|
+
viewContainer.innerHTML = '';
|
|
90
|
+
componentInstance = mount(data.component.default, {
|
|
91
|
+
target: viewContainer,
|
|
92
|
+
props: { ...(data.props || {}), panoContexts: contexts },
|
|
93
|
+
context: contexts
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} catch (err) {
|
|
98
|
+
console.warn('Mount failed completely:', err);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
destroy() {
|
|
103
|
+
if (componentInstance) {
|
|
104
|
+
try {
|
|
105
|
+
if (data.component?.unmount) {
|
|
106
|
+
data.component.unmount(componentInstance);
|
|
107
|
+
} else {
|
|
108
|
+
unmount(componentInstance);
|
|
109
|
+
}
|
|
110
|
+
} catch (e) {
|
|
111
|
+
if (componentInstance?.$destroy) componentInstance.$destroy();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
</script>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import crypto from "crypto";
|
|
4
|
+
import mime from "mime-types";
|
|
5
|
+
|
|
6
|
+
// Content-hashed chunk, e.g. "Component-a1b2c3d4.js" or "chunk-1a2b3c4d.mjs". These names change
|
|
7
|
+
// whenever their content changes, so they are safe to cache forever.
|
|
8
|
+
const HASHED_CHUNK_RE = /-[0-9a-zA-Z_]{8,}\.m?js$/;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Pick a Cache-Control (and optional ETag) for a plugin client asset.
|
|
12
|
+
* @param {string} fileName
|
|
13
|
+
* @param {Buffer} data
|
|
14
|
+
*/
|
|
15
|
+
function cacheHeadersFor(fileName, data) {
|
|
16
|
+
if (fileName === "client.mjs") {
|
|
17
|
+
// The entry point is not content-hashed, so it must always be revalidated. A trivial strong
|
|
18
|
+
// ETag (content hash) lets the browser get a cheap 304 when nothing changed.
|
|
19
|
+
const etag = `"${crypto.createHash("sha1").update(data).digest("hex")}"`;
|
|
20
|
+
return { "Cache-Control": "no-cache", ETag: etag };
|
|
21
|
+
}
|
|
22
|
+
if (HASHED_CHUNK_RE.test(fileName)) {
|
|
23
|
+
return { "Cache-Control": "public, max-age=31536000, immutable" };
|
|
24
|
+
}
|
|
25
|
+
return { "Cache-Control": "no-cache" };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @type {import("@sveltejs/kit").RequestHandler} */
|
|
29
|
+
export async function GET({ params, request }) {
|
|
30
|
+
const { pluginId, fileName } = params;
|
|
31
|
+
|
|
32
|
+
// Ensure pluginId and fileName are safe and sanitize inputs
|
|
33
|
+
if (!pluginId || !fileName || typeof pluginId !== "string" || typeof fileName !== "string") {
|
|
34
|
+
return new Response("Invalid parameters.", { status: 400 });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Sanitize pluginId and fileName to prevent directory traversal
|
|
38
|
+
const safePluginId = path.basename(pluginId); // Prevent directory traversal by using only the base name
|
|
39
|
+
const safeFileName = path.basename(fileName); // Same for fileName
|
|
40
|
+
|
|
41
|
+
// Resolve the plugin's client directory and append a trailing separator so the boundary check
|
|
42
|
+
// below cannot be bypassed by a sibling directory whose name shares this prefix
|
|
43
|
+
// (e.g. ".../client" must not match ".../client-evil/...").
|
|
44
|
+
const baseDir = path.resolve(`plugins/${safePluginId}/client`) + path.sep;
|
|
45
|
+
|
|
46
|
+
// Construct the absolute file path
|
|
47
|
+
const filePath = path.resolve(baseDir, safeFileName);
|
|
48
|
+
|
|
49
|
+
// Ensure that the resolved file stays inside the intended plugin's client directory.
|
|
50
|
+
if (!filePath.startsWith(baseDir)) {
|
|
51
|
+
return new Response("Access to this file is forbidden.", { status: 403 });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
const data = fs.readFileSync(filePath);
|
|
56
|
+
|
|
57
|
+
// Use mime-types to automatically determine the content type
|
|
58
|
+
const contentType = mime.lookup(fileName) || "application/octet-stream"; // Default to 'application/octet-stream' if mime type is unknown
|
|
59
|
+
|
|
60
|
+
const cacheHeaders = cacheHeadersFor(safeFileName, data);
|
|
61
|
+
|
|
62
|
+
// Honor conditional requests when we expose an ETag (client.mjs).
|
|
63
|
+
if (cacheHeaders.ETag && request.headers.get("if-none-match") === cacheHeaders.ETag) {
|
|
64
|
+
return new Response(null, {
|
|
65
|
+
status: 304,
|
|
66
|
+
headers: { ...cacheHeaders }
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return new Response(data, {
|
|
71
|
+
headers: { "Content-Type": contentType, ...cacheHeaders }
|
|
72
|
+
});
|
|
73
|
+
} catch {
|
|
74
|
+
return new Response("File not found or unable to read.", { status: 404 });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { load as loadApp } from "$pano/lib/layouts/AppLayout.svelte";
|
|
2
|
+
import { load as loadMain } from "$pano/lib/layouts/MainLayout.svelte";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @type {import("@sveltejs/kit").LayoutLoad}
|
|
6
|
+
*/
|
|
7
|
+
export async function load(event) {
|
|
8
|
+
const appData = await loadApp(event);
|
|
9
|
+
const mainData = await loadMain(event);
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
...appData,
|
|
13
|
+
...mainData
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
/** @type {import("@sveltejs/kit").RequestHandler} */
|
|
5
|
+
export async function GET({ params }) {
|
|
6
|
+
const { language } = params;
|
|
7
|
+
|
|
8
|
+
// Sanitize the language id: strip any path components so a value like "../../etc/passwd"
|
|
9
|
+
// collapses to a bare file name. This alone prevents traversal, and the startsWith check below
|
|
10
|
+
// is an additional defense-in-depth boundary against symlink / edge-case escapes.
|
|
11
|
+
const safe = path.basename(String(language ?? ""));
|
|
12
|
+
const fileName = `${safe}.json`;
|
|
13
|
+
|
|
14
|
+
// Build (dir, filePath) pairs for the primary and process.argv[1]-relative fallback locations.
|
|
15
|
+
const candidates = [
|
|
16
|
+
path.resolve("lang"),
|
|
17
|
+
path.resolve(path.dirname(process.argv[1]) + "/lang"),
|
|
18
|
+
].map((dir) => ({ dir, filePath: path.resolve(dir, fileName) }));
|
|
19
|
+
|
|
20
|
+
// Reject anything that escapes its lang directory.
|
|
21
|
+
for (const { dir, filePath } of candidates) {
|
|
22
|
+
if (!filePath.startsWith(dir + path.sep)) {
|
|
23
|
+
return new Response(JSON.stringify({ error: "Forbidden" }), {
|
|
24
|
+
status: 403,
|
|
25
|
+
headers: {
|
|
26
|
+
"Content-Type": "application/json"
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let filePath = candidates[0].filePath;
|
|
33
|
+
if (!fs.existsSync(filePath)) {
|
|
34
|
+
filePath = candidates[1].filePath;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (fs.existsSync(filePath)) {
|
|
38
|
+
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
39
|
+
return new Response(fileContent, {
|
|
40
|
+
headers: {
|
|
41
|
+
"Content-Type": "application/json"
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
return new Response(JSON.stringify({ error: "Language file not found" }), {
|
|
46
|
+
status: 404,
|
|
47
|
+
headers: {
|
|
48
|
+
"Content-Type": "application/json"
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
/** @type {import("@sveltejs/kit").RequestHandler} */
|
|
5
|
+
export async function GET() {
|
|
6
|
+
let filePath = path.resolve(`licenses.json`);
|
|
7
|
+
|
|
8
|
+
if (!fs.existsSync(filePath)) {
|
|
9
|
+
filePath = path.resolve(path.dirname(process.argv[1]) + `/licenses.json`);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (fs.existsSync(filePath)) {
|
|
13
|
+
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
14
|
+
return new Response(fileContent, {
|
|
15
|
+
headers: {
|
|
16
|
+
"Content-Type": "application/json"
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
// Return empty object if file not found
|
|
21
|
+
return new Response(JSON.stringify({}), {
|
|
22
|
+
headers: {
|
|
23
|
+
"Content-Type": "application/json"
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|