@panomc/sdk 1.0.0-dev.3 → 1.0.0-dev.4

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/package.json CHANGED
@@ -1,31 +1,61 @@
1
1
  {
2
2
  "name": "@panomc/sdk",
3
- "version": "1.0.0-dev.3",
3
+ "version": "1.0.0-dev.4",
4
4
  "author": "PanoMC",
5
5
  "repository": {
6
6
  "url": "https://github.com/PanoMC/sdk"
7
7
  },
8
- "publishConfig": {
9
- "access": "public"
8
+ "devDependencies": {
9
+ "svelte": "^5.46.1"
10
+ },
11
+ "peerDependencies": {
12
+ "svelte": "^5.46.1"
10
13
  },
11
- "type": "module",
12
- "files": [
13
- "src"
14
- ],
15
- "svelte": "./src/index.js",
16
14
  "exports": {
17
15
  ".": {
18
16
  "svelte": "./src/index.js",
19
17
  "default": "./src/index.js"
18
+ },
19
+ "./components": {
20
+ "svelte": "./src/components/index.js",
21
+ "default": "./src/components/index.js"
22
+ },
23
+ "./internal": {
24
+ "svelte": "./src/internal/index.js",
25
+ "default": "./src/internal/index.js"
26
+ },
27
+ "./toasts": {
28
+ "svelte": "./src/toasts/index.js",
29
+ "default": "./src/toasts/index.js"
30
+ },
31
+ "./utils/api": {
32
+ "svelte": "./src/utils/api.js",
33
+ "default": "./src/utils/api.js"
34
+ },
35
+ "./utils/tooltip": {
36
+ "svelte": "./src/utils/tooltip.js",
37
+ "default": "./src/utils/tooltip.js"
38
+ },
39
+ "./utils/language": {
40
+ "svelte": "./src/utils/language.js",
41
+ "default": "./src/utils/language.js"
42
+ },
43
+ "./utils/component": {
44
+ "svelte": "./src/utils/component.js",
45
+ "default": "./src/utils/component.js"
46
+ },
47
+ "./variables": {
48
+ "svelte": "./src/variables.js",
49
+ "default": "./src/variables.js"
20
50
  }
21
51
  },
22
- "scripts": {},
23
- "peerDependencies": {
24
- "svelte": "^5.46.1"
52
+ "files": [
53
+ "src"
54
+ ],
55
+ "publishConfig": {
56
+ "access": "public"
25
57
  },
26
- "devDependencies": {
27
- "@sveltejs/vite-plugin-svelte": "^6.2.1",
28
- "vite": "^7.3.0",
29
- "svelte": "^5.46.1"
30
- }
58
+ "scripts": {},
59
+ "svelte": "./src/index.js",
60
+ "type": "module"
31
61
  }
@@ -0,0 +1,55 @@
1
+ const GLOBAL_KEY = "__PANO_PLUGIN_CONTEXTS__";
2
+
3
+ function getStore() {
4
+ if (!globalThis[GLOBAL_KEY]) {
5
+ globalThis[GLOBAL_KEY] = Object.create(null);
6
+ }
7
+ return globalThis[GLOBAL_KEY];
8
+ }
9
+
10
+ export function createPluginContext(pluginId) {
11
+ if (!pluginId) {
12
+ throw new Error("[PanoSDK] pluginId is required");
13
+ }
14
+
15
+ const store = getStore();
16
+
17
+ if (!store[pluginId]) {
18
+ store[pluginId] = {
19
+ context: {},
20
+ listeners: [],
21
+ };
22
+ }
23
+
24
+ const pluginStore = store[pluginId];
25
+
26
+ return {
27
+ context: pluginStore.context,
28
+
29
+ set(partial) {
30
+ if (typeof partial !== "object" || partial === null) return;
31
+
32
+ Object.assign(pluginStore.context, partial);
33
+
34
+ pluginStore.listeners.forEach((fn) => {
35
+ try {
36
+ fn(pluginStore.context);
37
+ } catch (e) {
38
+ console.error(`[PanoSDK][${pluginId}] listener error`, e);
39
+ }
40
+ });
41
+ },
42
+
43
+ subscribe(fn) {
44
+ pluginStore.listeners.push(fn);
45
+
46
+ return () => {
47
+ pluginStore.listeners = pluginStore.listeners.filter((l) => l !== fn);
48
+ };
49
+ },
50
+
51
+ destroy() {
52
+ delete store[pluginId];
53
+ },
54
+ };
55
+ }
@@ -0,0 +1,32 @@
1
+ import { createPluginContext } from "./plugin-context.js";
2
+
3
+ export class PanoPlugin {
4
+ static isPanoPlugin = true;
5
+ constructor({ pluginId, scope } = {}) {
6
+ if (!pluginId) {
7
+ throw new Error("[PanoPlugin] pluginId is required");
8
+ }
9
+
10
+ // plugin-scoped context
11
+ this.contextApi = createPluginContext(pluginId, scope);
12
+ this.context = this.contextApi.context;
13
+
14
+ this._unsubscribers = [];
15
+ }
16
+
17
+ /** lifecycle hooks */
18
+ onLoad(pano) {}
19
+ onUnload() {}
20
+
21
+ /** plugin context helper */
22
+ setContext(partial) {
23
+ this.contextApi.set(partial);
24
+ }
25
+
26
+ /** internal cleanup */
27
+ __destroy() {
28
+ this._unsubscribers.forEach((fn) => fn());
29
+ this.contextApi.destroy?.();
30
+ this.onUnload();
31
+ }
32
+ }
@@ -0,0 +1,18 @@
1
+ import { getPanoContext } from "../internal/index.js";
2
+
3
+ const panoContext = getPanoContext()
4
+ const components = panoContext.context.components
5
+
6
+ export const PageActions = components.PageActions;
7
+ export const PageLoader = components.PageLoader;
8
+ export const PageNavItem = components.PageNavItem;
9
+ export const PageNav = components.PageNav;
10
+ export const Pagination = components.Pagination;
11
+ export const PageLoading = components.PageLoading;
12
+ export const Toast = components.Toast;
13
+ export const CardFilters = components.CardFilters;
14
+ export const CardFiltersItem = components.CardFiltersItem;
15
+ export const CardHeader = components.CardHeader;
16
+ export const CardMenu = components.CardMenu;
17
+ export const CardMenuItem = components.CardMenuItem;
18
+ export const Date = components.Date;
package/src/index.js CHANGED
@@ -1,13 +1,5 @@
1
- import { setContext, getContext } from 'svelte'
1
+ export { getPanoContext } from "./internal"
2
2
 
3
- export { default as PanoTestButton } from './components/Button.svelte';
3
+ export * from "./api/plugin.js"
4
4
 
5
- export const PANO_CTX = Symbol()
6
-
7
- export function setPanoContext(ctx) {
8
- setContext(PANO_CTX, ctx)
9
- }
10
-
11
- export function usePano() {
12
- return getContext(PANO_CTX)
13
- }
5
+ export * from "./utils/component.js"
@@ -0,0 +1 @@
1
+ export * from "./pano-context.js"
@@ -0,0 +1,47 @@
1
+ const GLOBAL_KEY = "__PANO_CONTEXT__";
2
+
3
+ function getStore() {
4
+ if (!globalThis[GLOBAL_KEY]) {
5
+ globalThis[GLOBAL_KEY] = {
6
+ context: {},
7
+ listeners: [],
8
+ };
9
+ }
10
+ return globalThis[GLOBAL_KEY];
11
+ }
12
+
13
+ export function setPanoContext(partial) {
14
+ const store = getStore();
15
+
16
+ if (typeof partial !== "object" || partial === null) {
17
+ console.warn("[PanoSDK] setPanoContext expects an object");
18
+ return;
19
+ }
20
+
21
+ Object.assign(store.context, partial);
22
+
23
+ store.listeners.forEach((fn) => {
24
+ try {
25
+ fn(store.context);
26
+ } catch (e) {
27
+ console.error("[PanoSDK] listener error", e);
28
+ }
29
+ });
30
+ }
31
+
32
+ export function getPanoContext() {
33
+ const store = getStore();
34
+
35
+ return {
36
+ context: store.context,
37
+
38
+ subscribe(fn) {
39
+ store.listeners.push(fn);
40
+
41
+ // unsubscribe
42
+ return () => {
43
+ store.listeners = store.listeners.filter((l) => l !== fn);
44
+ };
45
+ },
46
+ };
47
+ }
@@ -0,0 +1,9 @@
1
+ import { getPanoContext } from "../internal/index.js";
2
+
3
+ const panoContext = getPanoContext();
4
+ const toastStuff = panoContext.context.utils.toast;
5
+
6
+ const showToast = toastStuff.show;
7
+ const limitTitle = toastStuff.limitTitle;
8
+
9
+ export { showToast, limitTitle };
@@ -0,0 +1,14 @@
1
+ import { getPanoContext } from "../internal/index.js";
2
+
3
+ const panoContext = getPanoContext();
4
+ const apiStuff = panoContext.context.utils.api;
5
+
6
+ const ApiUtil = apiStuff.ApiUtil;
7
+
8
+ const NETWORK_ERROR = apiStuff.NETWORK_ERROR;
9
+ const networkErrorBody = apiStuff.networkErrorBody;
10
+ const buildQueryParams = apiStuff.buildQueryParams;
11
+
12
+ export { ApiUtil, NETWORK_ERROR, networkErrorBody, buildQueryParams };
13
+
14
+ export default ApiUtil
@@ -0,0 +1,20 @@
1
+ import { mount, unmount, hydrate } from "svelte";
2
+
3
+ /**
4
+ * Wraps a dynamic component import to include the correct Svelte runtime mount/unmount methods.
5
+ * This bridges the gap between Host and Plugin runtimes.
6
+ *
7
+ * @param {() => Promise<any>} importer - Dynamic import function
8
+ * @returns {() => Promise<any>} - Wrapped importer
9
+ */
10
+ export function viewComponent(importer) {
11
+ return async () => {
12
+ const module = await importer();
13
+ return {
14
+ ...module,
15
+ mount: (options) => mount(module.default, options),
16
+ unmount: (instance) => unmount(instance),
17
+ hydrate: (options) => hydrate(module.default, options)
18
+ };
19
+ };
20
+ }
@@ -0,0 +1,24 @@
1
+ import { getPanoContext } from "../internal/index.js";
2
+
3
+ const panoContext = getPanoContext();
4
+ const languageStuff = panoContext.context.utils.language;
5
+
6
+ const languageLoading = languageStuff.languageLoading;
7
+ const currentLanguage = languageStuff.currentLanguage;
8
+ const Languages = languageStuff.Languages;
9
+ const init = languageStuff.init;
10
+ const getAcceptedLanguage = languageStuff.getAcceptedLanguage;
11
+ const loadLanguage = languageStuff.loadLanguage;
12
+ const changeLanguage = languageStuff.changeLanguage;
13
+ const getLanguageByLocale = languageStuff.getLanguageByLocale;
14
+
15
+ export {
16
+ languageLoading,
17
+ currentLanguage,
18
+ Languages,
19
+ init,
20
+ getAcceptedLanguage,
21
+ loadLanguage,
22
+ changeLanguage,
23
+ getLanguageByLocale,
24
+ };
@@ -0,0 +1,10 @@
1
+ import { getPanoContext } from "../internal/index.js";
2
+
3
+ const panoContext = getPanoContext();
4
+ const tooltipStuff = panoContext.context.utils.tooltip;
5
+
6
+ const tooltip = tooltipStuff.tooltip;
7
+
8
+ export { tooltip };
9
+
10
+ export default tooltip;
@@ -0,0 +1,36 @@
1
+ import { getPanoContext } from "./internal/index.js";
2
+
3
+ const panoContext = getPanoContext();
4
+ const variableStuff = panoContext.context.variables;
5
+
6
+ const API_URL = variableStuff.API_URL;
7
+ const UI_URL = variableStuff.UI_URL;
8
+ const PANEL_URL = variableStuff.PANEL_URL;
9
+ const SETUP_URL = variableStuff.SETUP_URL;
10
+ const PANO_WEBSITE_URL = variableStuff.PANO_WEBSITE_URL;
11
+ const PANO_WEBSITE_API_URL = variableStuff.PANO_WEBSITE_API_URL;
12
+ const PRERELEASE = variableStuff.PRERELEASE;
13
+ const COOKIE_PREFIX = variableStuff.COOKIE_PREFIX;
14
+ const CSRF_TOKEN_COOKIE_NAME = variableStuff.CSRF_TOKEN_COOKIE_NAME;
15
+ const JWT_COOKIE_NAME = variableStuff.JWT_COOKIE_NAME;
16
+ const CSRF_HEADER = variableStuff.CSRF_HEADER;
17
+ const updateApiUrl = variableStuff.updateApiUrl;
18
+ const updatePanoWebsiteUrl = variableStuff.updatePanoWebsiteUrl;
19
+ const updatePanoWebsiteApiUrl = variableStuff.updatePanoWebsiteApiUrl;
20
+
21
+ export {
22
+ API_URL,
23
+ UI_URL,
24
+ PANEL_URL,
25
+ SETUP_URL,
26
+ PANO_WEBSITE_URL,
27
+ PANO_WEBSITE_API_URL,
28
+ PRERELEASE,
29
+ COOKIE_PREFIX,
30
+ CSRF_TOKEN_COOKIE_NAME,
31
+ JWT_COOKIE_NAME,
32
+ CSRF_HEADER,
33
+ updateApiUrl,
34
+ updatePanoWebsiteUrl,
35
+ updatePanoWebsiteApiUrl,
36
+ };
@@ -1,13 +0,0 @@
1
- <script>
2
- export let variant = 'primary';
3
- </script>
4
-
5
- <button class="btn {variant}">
6
- <slot />
7
- </button>
8
-
9
- <style>
10
- .btn {
11
- padding: 8px 12px;
12
- }
13
- </style>