@akinon/app-client
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -1,3 +0,13 @@ | ||
import { AppClientConfig, ApplicationData } from '@akinon/app-shared'; | ||
import { ApplicationData, FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType } from '@akinon/app-shared'; | ||
import React from 'react'; | ||
/** | ||
* Defines the context state for the AppClient, including application data, | ||
* loading status, and methods for invoking actions and navigating. | ||
* @typedef {Object} AppClientContextState | ||
* @property {ApplicationData} [data] - Optional application data shared across micro frontends. | ||
* @property {boolean} isLoading - Indicates whether the application data is currently loading. | ||
* @property {Function} invokeAction - Method to invoke an action defined in the AppShell. | ||
* @property {Function} navigate - Method to navigate to a specified path within the application. | ||
* Additional helper methods for invoking default actions like showing dialogs or toasts. | ||
*/ | ||
interface AppClientContextState { | ||
@@ -13,10 +23,25 @@ data?: ApplicationData; | ||
} | ||
/** | ||
* Props for the AppClientProvider component. | ||
* @typedef {Object} AppClientProviderProps | ||
* @property {React.ReactNode} children - Children components to be rendered within the provider. | ||
* @property {ApplicationConfig} config - Configuration for the application, including settings like `isDev` and `forceRedirect`. | ||
*/ | ||
interface AppClientProviderProps { | ||
children: React.ReactNode; | ||
config: AppClientConfig; | ||
config: FullpageApplicationConfig | PluginApplicationConfig; | ||
} | ||
/** | ||
* Custom hook to access the AppClient context. | ||
* @returns {AppClientContextState} The current context state. | ||
*/ | ||
declare const useAppClient: () => AppClientContextState; | ||
/** | ||
* Component providing the context for AppClient. It initializes communication | ||
* with the AppShell and provides methods for action invocation and navigation. | ||
* @param {AppClientProviderProps} props - The props for the AppClientProvider component. | ||
*/ | ||
declare const AppClientProvider: ({ children, config }: AppClientProviderProps) => React.JSX.Element; | ||
export { AppClientProvider, useAppClient }; | ||
export type { AppClientConfig }; | ||
export type { FullpageApplicationConfig, PluginApplicationConfig, RegisteredApp, RegisteredAppType }; | ||
//# sourceMappingURL=app-client-provider.d.ts.map |
@@ -1,12 +0,12 @@ | ||
import { jsx as G } from "react/jsx-runtime"; | ||
import { createContext as J, useContext as z, useState as E, useEffect as H } from "react"; | ||
import { jsx as z } from "react/jsx-runtime"; | ||
import { createContext as H, useContext as Q, useState as C, useEffect as X } from "react"; | ||
var v = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; | ||
function Q(r) { | ||
function Y(r) { | ||
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r; | ||
} | ||
var x = {}, h = {}, C; | ||
function X() { | ||
if (C) | ||
var I = {}, h = {}, j; | ||
function Z() { | ||
if (j) | ||
return h; | ||
C = 1, Object.defineProperty(h, "__esModule", { value: !0 }), h.detach = h.attach = void 0; | ||
j = 1, Object.defineProperty(h, "__esModule", { value: !0 }), h.detach = h.attach = void 0; | ||
var r = d(), o = !1; | ||
@@ -22,7 +22,7 @@ function n() { | ||
} | ||
var b = {}, j; | ||
function Y() { | ||
if (j) | ||
return b; | ||
j = 1, Object.defineProperty(b, "__esModule", { value: !0 }), b.broadcastToChildWindows = void 0; | ||
var g = {}, S; | ||
function ee() { | ||
if (S) | ||
return g; | ||
S = 1, Object.defineProperty(g, "__esModule", { value: !0 }), g.broadcastToChildWindows = void 0; | ||
var r = d(); | ||
@@ -38,9 +38,9 @@ function o(n, t, e) { | ||
} | ||
return b.broadcastToChildWindows = o, b; | ||
return g.broadcastToChildWindows = o, g; | ||
} | ||
var g = {}, q; | ||
function Z() { | ||
var y = {}, q; | ||
function re() { | ||
if (q) | ||
return g; | ||
q = 1, Object.defineProperty(g, "__esModule", { value: !0 }), g.broadcast = void 0; | ||
return y; | ||
q = 1, Object.defineProperty(y, "__esModule", { value: !0 }), y.broadcast = void 0; | ||
var r = d(); | ||
@@ -61,3 +61,3 @@ function o(n, t) { | ||
} | ||
return g.broadcast = o, g; | ||
return y.broadcast = o, y; | ||
} | ||
@@ -70,7 +70,7 @@ var l = {}; | ||
l.subscribers = {}; | ||
var y = {}, R; | ||
function ee() { | ||
var m = {}, R; | ||
function te() { | ||
if (R) | ||
return y; | ||
R = 1, Object.defineProperty(y, "__esModule", { value: !0 }), y.dispatch = void 0; | ||
return m; | ||
R = 1, Object.defineProperty(m, "__esModule", { value: !0 }), m.dispatch = void 0; | ||
var r = d(); | ||
@@ -85,23 +85,23 @@ function o(n, t, e, i, s) { | ||
} | ||
return y.dispatch = o, y; | ||
return m.dispatch = o, m; | ||
} | ||
var M = {}; | ||
Object.defineProperty(M, "__esModule", { value: !0 }); | ||
M.hasOpener = void 0; | ||
function re(r) { | ||
var T = {}; | ||
Object.defineProperty(T, "__esModule", { value: !0 }); | ||
T.hasOpener = void 0; | ||
function ie(r) { | ||
return !(r.top !== r || r.opener == null || r.opener === r || r.opener.closed === !0); | ||
} | ||
M.hasOpener = re; | ||
var T = {}; | ||
Object.defineProperty(T, "__esModule", { value: !0 }); | ||
T.isntString = void 0; | ||
function te(r) { | ||
T.hasOpener = ie; | ||
var D = {}; | ||
Object.defineProperty(D, "__esModule", { value: !0 }); | ||
D.isntString = void 0; | ||
function ne(r) { | ||
return typeof r != "string"; | ||
} | ||
T.isntString = te; | ||
var m = {}, S; | ||
function ie() { | ||
if (S) | ||
return m; | ||
S = 1, Object.defineProperty(m, "__esModule", { value: !0 }), m.onMessage = void 0; | ||
D.isntString = ne; | ||
var _ = {}, k; | ||
function ae() { | ||
if (k) | ||
return _; | ||
k = 1, Object.defineProperty(_, "__esModule", { value: !0 }), _.onMessage = void 0; | ||
var r = d(); | ||
@@ -117,9 +117,9 @@ function o(n) { | ||
} | ||
return m.onMessage = o, m; | ||
return _.onMessage = o, _; | ||
} | ||
var _ = {}, I; | ||
function ne() { | ||
if (I) | ||
return _; | ||
I = 1, Object.defineProperty(_, "__esModule", { value: !0 }), _.packagePayload = void 0; | ||
var w = {}, L; | ||
function se() { | ||
if (L) | ||
return w; | ||
L = 1, Object.defineProperty(w, "__esModule", { value: !0 }), w.packagePayload = void 0; | ||
var r = d(); | ||
@@ -139,8 +139,8 @@ function o(n, t, e, i) { | ||
} | ||
return _.packagePayload = o, _; | ||
return w.packagePayload = o, w; | ||
} | ||
var D = {}; | ||
Object.defineProperty(D, "__esModule", { value: !0 }); | ||
D.sendMessage = void 0; | ||
function ae(r, o, n) { | ||
var F = {}; | ||
Object.defineProperty(F, "__esModule", { value: !0 }); | ||
F.sendMessage = void 0; | ||
function oe(r, o, n) { | ||
try { | ||
@@ -151,8 +151,8 @@ r.postMessage(o, n); | ||
} | ||
D.sendMessage = ae; | ||
var w = {}, P = {}, k; | ||
function K() { | ||
if (k) | ||
return P; | ||
k = 1, Object.defineProperty(P, "__esModule", { value: !0 }), P.Framebus = void 0; | ||
F.sendMessage = oe; | ||
var P = {}, A = {}, B; | ||
function U() { | ||
if (B) | ||
return A; | ||
B = 1, Object.defineProperty(A, "__esModule", { value: !0 }), A.Framebus = void 0; | ||
var r = d(), o = typeof window < "u" && window.Promise, n = ( | ||
@@ -182,4 +182,4 @@ /** @class */ | ||
var u = (0, r.packagePayload)(e, a, i, s); | ||
return u ? (this.limitBroadcastToFramesArray ? this.targetFramesAsWindows().forEach(function(c) { | ||
(0, r.sendMessage)(c, u, a); | ||
return u ? (this.limitBroadcastToFramesArray ? this.targetFramesAsWindows().forEach(function(f) { | ||
(0, r.sendMessage)(f, u, a); | ||
}) : (0, r.broadcast)(u, { | ||
@@ -192,6 +192,6 @@ origin: a, | ||
return new t.Promise(function(a, u) { | ||
var c = s.emit(e, i, function(f) { | ||
a(f); | ||
var f = s.emit(e, i, function(c) { | ||
a(c); | ||
}); | ||
c || u(new Error('Listener not added for "'.concat(e, '"'))); | ||
f || u(new Error('Listener not added for "'.concat(e, '"'))); | ||
}); | ||
@@ -203,5 +203,5 @@ }, t.prototype.on = function(e, i) { | ||
return e = this.namespaceEvent(e), (0, r.subscriptionArgsInvalid)(e, u, a) ? !1 : (this.hasAdditionalChecksForOnListeners && (u = function() { | ||
for (var c = [], f = 0; f < arguments.length; f++) | ||
c[f] = arguments[f]; | ||
s.passesVerifyDomainCheck(this && this.origin) && s.hasMatchingTargetFrame(this && this.source) && i.apply(void 0, c); | ||
for (var f = [], c = 0; c < arguments.length; c++) | ||
f[c] = arguments[c]; | ||
s.passesVerifyDomainCheck(this && this.origin) && s.hasMatchingTargetFrame(this && this.source) && i.apply(void 0, f); | ||
}), this.listeners.push({ | ||
@@ -222,11 +222,11 @@ eventName: e, | ||
e = this.namespaceEvent(e); | ||
var c = this.origin; | ||
if ((0, r.subscriptionArgsInvalid)(e, s, c)) | ||
var f = this.origin; | ||
if ((0, r.subscriptionArgsInvalid)(e, s, f)) | ||
return !1; | ||
var f = r.subscribers[c] && r.subscribers[c][e]; | ||
if (!f) | ||
var c = r.subscribers[f] && r.subscribers[f][e]; | ||
if (!c) | ||
return !1; | ||
for (var a = 0; a < f.length; a++) | ||
if (f[a] === s) | ||
return f.splice(a, 1), !0; | ||
for (var a = 0; a < c.length; a++) | ||
if (c[a] === s) | ||
return c.splice(a, 1), !0; | ||
return !1; | ||
@@ -267,5 +267,5 @@ }, t.prototype.teardown = function() { | ||
); | ||
return P.Framebus = n, P; | ||
return A.Framebus = n, A; | ||
} | ||
function se() { | ||
function ue() { | ||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(r) { | ||
@@ -276,16 +276,16 @@ var o = Math.random() * 16 | 0, n = r === "x" ? o : o & 3 | 8; | ||
} | ||
var oe = se, L; | ||
function ue() { | ||
if (L) | ||
return w; | ||
L = 1; | ||
var ce = ue, W; | ||
function fe() { | ||
if (W) | ||
return P; | ||
W = 1; | ||
var r = v && v.__importDefault || function(e) { | ||
return e && e.__esModule ? e : { default: e }; | ||
}; | ||
Object.defineProperty(w, "__esModule", { value: !0 }), w.subscribeReplier = void 0; | ||
var o = K(), n = r(oe); | ||
Object.defineProperty(P, "__esModule", { value: !0 }), P.subscribeReplier = void 0; | ||
var o = U(), n = r(ce); | ||
function t(e, i) { | ||
var s = (0, n.default)(); | ||
function a(u, c) { | ||
e(u, c), o.Framebus.target({ | ||
function a(u, f) { | ||
e(u, f), o.Framebus.target({ | ||
origin: i | ||
@@ -298,9 +298,9 @@ }).off(s, a); | ||
} | ||
return w.subscribeReplier = t, w; | ||
return P.subscribeReplier = t, P; | ||
} | ||
var A = {}, B; | ||
function ce() { | ||
if (B) | ||
return A; | ||
B = 1, Object.defineProperty(A, "__esModule", { value: !0 }), A.subscriptionArgsInvalid = void 0; | ||
var O = {}, $; | ||
function de() { | ||
if ($) | ||
return O; | ||
$ = 1, Object.defineProperty(O, "__esModule", { value: !0 }), O.subscriptionArgsInvalid = void 0; | ||
var r = d(); | ||
@@ -310,11 +310,11 @@ function o(n, t, e) { | ||
} | ||
return A.subscriptionArgsInvalid = o, A; | ||
return O.subscriptionArgsInvalid = o, O; | ||
} | ||
var V = {}; | ||
Object.defineProperty(V, "__esModule", { value: !0 }); | ||
var O = {}, W; | ||
function fe() { | ||
if (W) | ||
return O; | ||
W = 1, Object.defineProperty(O, "__esModule", { value: !0 }), O.unpackPayload = void 0; | ||
var N = {}; | ||
Object.defineProperty(N, "__esModule", { value: !0 }); | ||
var M = {}, K; | ||
function le() { | ||
if (K) | ||
return M; | ||
K = 1, Object.defineProperty(M, "__esModule", { value: !0 }), M.unpackPayload = void 0; | ||
var r = d(); | ||
@@ -334,4 +334,4 @@ function o(n) { | ||
if (i) { | ||
var c = (0, r.packagePayload)(s, e, u); | ||
c && i.postMessage(c, e); | ||
var f = (0, r.packagePayload)(s, e, u); | ||
f && i.postMessage(f, e); | ||
} | ||
@@ -342,7 +342,7 @@ }; | ||
} | ||
return O.unpackPayload = o, O; | ||
return M.unpackPayload = o, M; | ||
} | ||
var $; | ||
var V; | ||
function d() { | ||
return $ || ($ = 1, function(r) { | ||
return V || (V = 1, function(r) { | ||
var o = v && v.__createBinding || (Object.create ? function(t, e, i, s) { | ||
@@ -360,9 +360,9 @@ s === void 0 && (s = i); | ||
}; | ||
Object.defineProperty(r, "__esModule", { value: !0 }), n(X(), r), n(Y(), r), n(Z(), r), n(l, r), n(ee(), r), n(M, r), n(T, r), n(ie(), r), n(ne(), r), n(D, r), n(ue(), r), n(ce(), r), n(V, r), n(fe(), r); | ||
}(x)), x; | ||
Object.defineProperty(r, "__esModule", { value: !0 }), n(Z(), r), n(ee(), r), n(re(), r), n(l, r), n(te(), r), n(T, r), n(D, r), n(ae(), r), n(se(), r), n(F, r), n(fe(), r), n(de(), r), n(N, r), n(le(), r); | ||
}(I)), I; | ||
} | ||
var de = d(), le = K(); | ||
(0, de.attach)(); | ||
var he = le.Framebus; | ||
const p = /* @__PURE__ */ Q(he), pe = { | ||
var he = d(), pe = U(); | ||
(0, he.attach)(); | ||
var ve = pe.Framebus; | ||
const p = /* @__PURE__ */ Y(ve), be = { | ||
isLoading: !0, | ||
@@ -372,5 +372,5 @@ invokeAction: async () => Promise.reject("Action functionality not initialized."), | ||
} | ||
}, ve = (r) => { | ||
}, G = H(be), Me = () => Q(G), ge = (r) => { | ||
new p().emit("NAVIGATE", { path: r }); | ||
}, be = (r, o) => { | ||
}, ye = (r, o) => { | ||
new p().emit("INVOKE_DEFAULT_ACTION", { | ||
@@ -380,6 +380,6 @@ actionKey: "showModalDialog", | ||
}); | ||
}, ge = (r, o) => new p().emit("INVOKE_DEFAULT_ACTION", { | ||
}, me = (r, o) => new p().emit("INVOKE_DEFAULT_ACTION", { | ||
actionKey: "showConfirmationDialog", | ||
args: [r, o] | ||
}), ye = (r, o) => { | ||
}), _e = (r, o) => { | ||
new p().emit("INVOKE_DEFAULT_ACTION", { | ||
@@ -389,3 +389,3 @@ actionKey: "showToast", | ||
}); | ||
}, me = (r, o) => { | ||
}, we = (r, o) => { | ||
new p().emit("INVOKE_DEFAULT_ACTION", { | ||
@@ -395,9 +395,9 @@ actionKey: "showErrorMessage", | ||
}); | ||
}, U = J(pe), Ae = () => z(U), Oe = ({ children: r, config: o }) => { | ||
const [n, t] = E(void 0), [e, i] = E(!0), s = (u, ...c) => new Promise((f, N) => { | ||
new p().emit("INVOKE_ACTION", { actionKey: u, args: c }, (F) => { | ||
F.success ? f(F.result) : N(new Error(F.error)); | ||
}, Te = ({ children: r, config: o }) => { | ||
const [n, t] = C(void 0), [e, i] = C(void 0), [s, a] = C(!0), u = (c, ...b) => new Promise((x, J) => { | ||
new p().emit("INVOKE_ACTION", { actionKey: c, args: b }, (E) => { | ||
E.success ? x(E.result) : J(new Error(E.error)); | ||
}); | ||
}); | ||
H(() => { | ||
X(() => { | ||
if (o.forceRedirect && !o.isDev && window.self === window.top) { | ||
@@ -409,24 +409,27 @@ console.error( | ||
} | ||
const u = new p(); | ||
return u.on("DATA_RESPONSE", (c) => { | ||
t(c), i(!1); | ||
}), u.emit("REQUEST_DATA"), () => { | ||
u.teardown(); | ||
const c = new p(); | ||
return c.emit("REQUEST_DATA", { config: o }), c.on("DATA_RESPONSE", (b) => { | ||
i(b), a(!1); | ||
}), c.on("SET_APP_ID", (b) => { | ||
const { appId: x } = b; | ||
t(x); | ||
}), () => { | ||
c.teardown(); | ||
}; | ||
}, [o]); | ||
const a = { | ||
data: n, | ||
isLoading: e, | ||
invokeAction: s, | ||
navigate: ve, | ||
showModalDialog: be, | ||
showConfirmationDialog: ge, | ||
showToast: ye, | ||
showErrorMessage: me | ||
const f = { | ||
data: e, | ||
isLoading: s, | ||
invokeAction: u, | ||
navigate: ge, | ||
showModalDialog: ye, | ||
showConfirmationDialog: me, | ||
showToast: _e, | ||
showErrorMessage: we | ||
}; | ||
return /* @__PURE__ */ G(U.Provider, { value: a, children: r }); | ||
return /* @__PURE__ */ z(G.Provider, { value: f, children: r }); | ||
}; | ||
export { | ||
Oe as AppClientProvider, | ||
Ae as useAppClient | ||
Te as AppClientProvider, | ||
Me as useAppClient | ||
}; |
{ | ||
"name": "@akinon/app-client", | ||
"description": "Akinon UI App Client. This library is used to create a new plugin or an application which will reside in Akinon's applications.", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"private": false, | ||
@@ -16,3 +16,3 @@ "type": "module", | ||
"use-immer": "^0.9.0", | ||
"@akinon/app-shared": "^0.2.1" | ||
"@akinon/app-shared": "^0.2.2" | ||
}, | ||
@@ -22,4 +22,4 @@ "devDependencies": { | ||
"clean-package": "2.2.0", | ||
"eslint-config-custom": "0.1.0", | ||
"@akinon/vite-config": "^0.1.1", | ||
"eslint-config-custom": "0.1.0", | ||
"tsconfig": "0.0.0" | ||
@@ -26,0 +26,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
30497
497
69
Updated@akinon/app-shared@^0.2.2