UNPKG

@j2inn/app

Version:

J2 Innovations core application framework

153 lines (152 loc) 6.07 kB
/* * Copyright (c) 2025, J2 Innovations. All Rights Reserved */ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _RemoteAppView_app, _RemoteAppView_ui; import { HNamespace } from 'haystack-core'; import { getAppViewId } from '../util'; import { getPodName, getRemoteEntry, loadDefault, loadDynamicResources, } from './util'; /** * Return the remote URLs to load for the application. * * @param app The application def. * @param ui The UI def. * @returns The remote URLs to load. */ export function getRemoteUrls(app, ui) { const urls = []; // Load any extra resources first. const finUiResources = ui.get('finUiResources'); if (finUiResources) { urls.push(...finUiResources.map((uri) => uri.value)); } urls.push(getRemoteEntry(app, ui)); return urls; } /** * Return the app view ids associated with this app view. * * @param ui The def dict for the ui. * @param namespace The defs namespace. * @returns The app view ids. */ function getAssociatedAppViewIds(ui, namespace) { return namespace .associations(ui.defName, 'finUiOn') .filter((def) => namespace.fits(def.defName, 'finUi')) .map((def) => { // Find the finApp for the finUi. const app = namespace .associations(def.defName, 'finUiOn') .filter((uiOnDef) => namespace.fits(uiOnDef.defName, 'finApp'))[0]; return app ? getAppViewId(HNamespace.getFeatureName(app.defName), HNamespace.getFeatureName(def.defName)) : ''; }) .filter((id) => !!id.length); } /** * The remote application view that's backed by defs. */ export class RemoteAppView { /** * Constructs a new remote app view. * * @param app The def dict for the app. * @param ui The def dict for the ui. * @param namespace The defs namespace. */ constructor(app, ui, namespace) { /** * The app def dict associated with the remote view. */ _RemoteAppView_app.set(this, void 0); /** * The ui def dict associated with the remote view. */ _RemoteAppView_ui.set(this, void 0); /** * The associated app view ids for this app view. * * This is used by a sidebar that should only show when another main app view is showing. */ this.associatedAppViewIds = []; /** * Load all resources required by the view. */ this.loadResources = async () => { await loadDynamicResources(this.podName, this.resourcesUrls); if (this.webComponentPath) { if (this.webComponentLoaderPath) { await loadDefault(this.podName, this.webComponentLoaderPath)(); } } }; __classPrivateFieldSet(this, _RemoteAppView_app, app, "f"); __classPrivateFieldSet(this, _RemoteAppView_ui, ui, "f"); this.associatedAppViewIds = getAssociatedAppViewIds(ui, namespace); } get type() { return __classPrivateFieldGet(this, _RemoteAppView_ui, "f") .get('finUiType') ?.value?.toLowerCase(); } get category() { return __classPrivateFieldGet(this, _RemoteAppView_ui, "f").get('finUiCategory')?.toString() ?? ''; } get hidden() { return __classPrivateFieldGet(this, _RemoteAppView_ui, "f").has('finUiHidden'); } get podName() { return getPodName(__classPrivateFieldGet(this, _RemoteAppView_ui, "f")); } get resourcesUrls() { return getRemoteUrls(__classPrivateFieldGet(this, _RemoteAppView_app, "f"), __classPrivateFieldGet(this, _RemoteAppView_ui, "f")); } get iconPath() { return __classPrivateFieldGet(this, _RemoteAppView_ui, "f").get('icon')?.value; } get reactComponentPath() { const path = __classPrivateFieldGet(this, _RemoteAppView_ui, "f").get('finUiReactComponent')?.value ?? __classPrivateFieldGet(this, _RemoteAppView_ui, "f").get('finUiRender')?.value; if (path && this.isReactComponent(path)) { return path; } else { return undefined; } } get webComponentPath() { const path = __classPrivateFieldGet(this, _RemoteAppView_ui, "f").get('finUiWebComponent')?.value ?? __classPrivateFieldGet(this, _RemoteAppView_ui, "f").get('finUiRender')?.value; if (path && !this.isReactComponent(path)) { return path; } else { return undefined; } } get webComponentLoaderPath() { return __classPrivateFieldGet(this, _RemoteAppView_ui, "f").get('finUiWebComponentLoader')?.value; } /** * Returns true if the path is for a react component. * * @param path The path to test. * @returns True if this points to a react component. */ isReactComponent(path) { return path.startsWith('./'); } } _RemoteAppView_app = new WeakMap(), _RemoteAppView_ui = new WeakMap();