@pc-nexus/bridge 0.0.1-next.1 → 0.0.1-next.3
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { HistoryAction, NavigationTarget, ViewportSize } from '@pc-nexus/models';
|
|
2
2
|
|
|
3
3
|
function attachObjectToWindow(key, value) {
|
|
4
4
|
window[key] = value;
|
|
@@ -43,11 +43,29 @@ class NexusBridge {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
class BridgeAPIError extends Error {
|
|
47
|
+
constructor(message) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.name = "BridgeAPIError";
|
|
50
|
+
Object.setPrototypeOf(this, BridgeAPIError.prototype);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// 自动注册:所有未 catch 的 Promise rejection 均以 "Uncaught (in promise)" 格式输出,无需用户配置
|
|
54
|
+
if (typeof window !== "undefined") {
|
|
55
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
56
|
+
const reason = event.reason;
|
|
57
|
+
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
58
|
+
const firstLine = `Uncaught (in promise) ${error.name}: ${error.message}`;
|
|
59
|
+
const stack = error.stack?.replace(/^[^\n]*\n?/, "").trim() || "";
|
|
60
|
+
console.error(stack ? `${firstLine}\n${stack}` : firstLine);
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
event.stopImmediatePropagation();
|
|
63
|
+
}, true);
|
|
64
|
+
}
|
|
65
|
+
|
|
46
66
|
class NexusDialog {
|
|
47
67
|
async open(options) {
|
|
48
|
-
return
|
|
49
|
-
console.error("nexus open dialog failed", error);
|
|
50
|
-
}));
|
|
68
|
+
return await NexusBridge.call("openDialog", options);
|
|
51
69
|
}
|
|
52
70
|
}
|
|
53
71
|
const dialog = new NexusDialog();
|
|
@@ -69,8 +87,8 @@ class NexusRouter {
|
|
|
69
87
|
async open(urlOrLocation) {
|
|
70
88
|
await NexusBridge.call("routerOpen", { urlOrLocation });
|
|
71
89
|
}
|
|
72
|
-
async
|
|
73
|
-
return await NexusBridge.call("
|
|
90
|
+
async generateUrl(location) {
|
|
91
|
+
return await NexusBridge.call("routerGenerateUrl", { location });
|
|
74
92
|
}
|
|
75
93
|
async reload() {
|
|
76
94
|
await NexusBridge.call("routerReload", {});
|
|
@@ -89,7 +107,17 @@ class NexusView {
|
|
|
89
107
|
await NexusBridge.call("viewReload");
|
|
90
108
|
}
|
|
91
109
|
async close() {
|
|
92
|
-
await NexusBridge.call("viewClose");
|
|
110
|
+
const isSuccess = await NexusBridge.call("viewClose");
|
|
111
|
+
if (!isSuccess) {
|
|
112
|
+
const errorMessage = "this resource's view is not closable.";
|
|
113
|
+
throw new BridgeAPIError(errorMessage);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async onClose(payload) {
|
|
117
|
+
await NexusBridge.call("viewOnClose", { payload });
|
|
118
|
+
}
|
|
119
|
+
async isDialog() {
|
|
120
|
+
return await NexusBridge.call("viewIsDialog");
|
|
93
121
|
}
|
|
94
122
|
async createHistory() {
|
|
95
123
|
const history = await NexusBridge.call("createHistory");
|
|
@@ -99,22 +127,25 @@ class NexusView {
|
|
|
99
127
|
});
|
|
100
128
|
return history;
|
|
101
129
|
}
|
|
130
|
+
async submit(payload) {
|
|
131
|
+
await NexusBridge.call("viewSubmit", payload);
|
|
132
|
+
}
|
|
102
133
|
}
|
|
103
134
|
const view = new NexusView();
|
|
104
135
|
|
|
105
136
|
const isPlainObject = (value) => {
|
|
106
|
-
if (typeof value !==
|
|
137
|
+
if (typeof value !== "object" || value === null) {
|
|
107
138
|
return false;
|
|
108
139
|
}
|
|
109
|
-
if (Object.prototype.toString.call(value) !==
|
|
140
|
+
if (Object.prototype.toString.call(value) !== "[object Object]") {
|
|
110
141
|
return false;
|
|
111
142
|
}
|
|
112
143
|
const proto = Object.getPrototypeOf(value);
|
|
113
144
|
if (proto === null) {
|
|
114
145
|
return true;
|
|
115
146
|
}
|
|
116
|
-
const constructor = Object.prototype.hasOwnProperty.call(proto,
|
|
117
|
-
return (typeof constructor ===
|
|
147
|
+
const constructor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
148
|
+
return (typeof constructor === "function" &&
|
|
118
149
|
constructor instanceof constructor &&
|
|
119
150
|
Function.prototype.call(constructor) === Function.prototype.call(value));
|
|
120
151
|
};
|
|
@@ -122,7 +153,7 @@ const base64ToBlob = (b64string, mimeType) => {
|
|
|
122
153
|
if (!b64string) {
|
|
123
154
|
return null;
|
|
124
155
|
}
|
|
125
|
-
const base64String = b64string.includes(
|
|
156
|
+
const base64String = b64string.includes(",") ? b64string.split(",")[1] : b64string;
|
|
126
157
|
const byteCharacters = atob(base64String);
|
|
127
158
|
const byteNumbers = new Array(byteCharacters.length);
|
|
128
159
|
for (let i = 0; i < byteCharacters.length; i++) {
|
|
@@ -147,7 +178,7 @@ const serialiseBlobsInPayload = async (payload) => {
|
|
|
147
178
|
return {
|
|
148
179
|
data: base64Data,
|
|
149
180
|
type: payload.type,
|
|
150
|
-
__isBlobData: true
|
|
181
|
+
__isBlobData: true,
|
|
151
182
|
};
|
|
152
183
|
}
|
|
153
184
|
if (Array.isArray(payload)) {
|
|
@@ -160,7 +191,7 @@ const serialiseBlobsInPayload = async (payload) => {
|
|
|
160
191
|
return payload;
|
|
161
192
|
};
|
|
162
193
|
const deserialiseBlobsInPayload = (payload) => {
|
|
163
|
-
if (payload && isPlainObject(payload) &&
|
|
194
|
+
if (payload && isPlainObject(payload) && "__isBlobData" in payload) {
|
|
164
195
|
const typedData = payload;
|
|
165
196
|
return base64ToBlob(typedData.data, typedData.type);
|
|
166
197
|
}
|
|
@@ -181,7 +212,7 @@ const containsBlobs = (payload) => {
|
|
|
181
212
|
return true;
|
|
182
213
|
}
|
|
183
214
|
if (Array.isArray(payload)) {
|
|
184
|
-
return payload.some(item => containsBlobs(item));
|
|
215
|
+
return payload.some((item) => containsBlobs(item));
|
|
185
216
|
}
|
|
186
217
|
if (payload && isPlainObject(payload)) {
|
|
187
218
|
return Object.values(payload).some((value) => containsBlobs(value));
|
|
@@ -189,7 +220,7 @@ const containsBlobs = (payload) => {
|
|
|
189
220
|
return false;
|
|
190
221
|
};
|
|
191
222
|
const containsSerialisedBlobs = (payload) => {
|
|
192
|
-
if (payload && isPlainObject(payload) &&
|
|
223
|
+
if (payload && isPlainObject(payload) && "__isBlobData" in payload) {
|
|
193
224
|
return true;
|
|
194
225
|
}
|
|
195
226
|
if (Array.isArray(payload)) {
|
|
@@ -209,18 +240,18 @@ async function on(eventName, callback) {
|
|
|
209
240
|
}
|
|
210
241
|
return callback(newPayload);
|
|
211
242
|
};
|
|
212
|
-
return NexusBridge.call(
|
|
243
|
+
return NexusBridge.call("on", { eventName, callback: wrappedCallback });
|
|
213
244
|
}
|
|
214
245
|
async function emit(eventName, payload) {
|
|
215
246
|
let newPayload = payload;
|
|
216
247
|
if (containsBlobs(payload)) {
|
|
217
248
|
newPayload = await serialiseBlobsInPayload(payload);
|
|
218
249
|
}
|
|
219
|
-
return NexusBridge.call(
|
|
250
|
+
return NexusBridge.call("emit", { eventName, payload: newPayload });
|
|
220
251
|
}
|
|
221
252
|
const events = {
|
|
222
253
|
on,
|
|
223
|
-
emit
|
|
254
|
+
emit,
|
|
224
255
|
};
|
|
225
256
|
|
|
226
257
|
class NexusI18n {
|
|
@@ -231,14 +262,16 @@ class NexusI18n {
|
|
|
231
262
|
locale = (await view.getContext()).locale;
|
|
232
263
|
}
|
|
233
264
|
const translations = await this.loadTranslations(locale);
|
|
234
|
-
return { locale, translations };
|
|
265
|
+
return { locale: locale, translations };
|
|
235
266
|
}
|
|
236
267
|
async createTranslator(locale) {
|
|
237
268
|
if (!locale) {
|
|
238
269
|
locale = (await view.getContext()).locale;
|
|
239
270
|
}
|
|
240
271
|
const translations = await this.loadTranslations(locale);
|
|
241
|
-
return
|
|
272
|
+
return {
|
|
273
|
+
translate: (key, params = {}) => this.translate(key, translations, params),
|
|
274
|
+
};
|
|
242
275
|
}
|
|
243
276
|
loadTranslations(locale) {
|
|
244
277
|
const url = `../${this.i18nFolderName}/${locale}.json`;
|
|
@@ -253,16 +286,71 @@ class NexusI18n {
|
|
|
253
286
|
}
|
|
254
287
|
return this.translationsCache[locale];
|
|
255
288
|
}
|
|
289
|
+
getValue(obj, path) {
|
|
290
|
+
return path.split(".").reduce((o, k) => (o != null && typeof o === "object" ? o[k] : undefined), obj);
|
|
291
|
+
}
|
|
292
|
+
translate(key, translations, params) {
|
|
293
|
+
// 获取值(扁平或嵌套)
|
|
294
|
+
let value = translations[key] ?? this.getValue(translations, key);
|
|
295
|
+
// key 不存在 → 返回 key
|
|
296
|
+
if (value == null)
|
|
297
|
+
return key;
|
|
298
|
+
// 如果 value 是对象 → 直接返回
|
|
299
|
+
if (typeof value === "object")
|
|
300
|
+
return value;
|
|
301
|
+
// 确保 value 是字符串
|
|
302
|
+
if (typeof value !== "string")
|
|
303
|
+
value = String(value);
|
|
304
|
+
// 无参数 → 直接返回
|
|
305
|
+
if (!params)
|
|
306
|
+
return value;
|
|
307
|
+
// 参数替换
|
|
308
|
+
return value.replace(/\{\{\s*(.*?)\s*\}\}/g, (_, k) => {
|
|
309
|
+
const paramValue = this.getValue(params, k.trim());
|
|
310
|
+
return paramValue != null ? String(paramValue) : `{{${k}}}`;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
256
313
|
}
|
|
257
314
|
const i18n = new NexusI18n();
|
|
258
315
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
316
|
+
async function buildPayloadByRequestInit(init) {
|
|
317
|
+
const requestBody = init === null || init === void 0 ? void 0 : init.body;
|
|
318
|
+
const requestMethod = init === null || init === void 0 ? void 0 : init.method;
|
|
319
|
+
const requestHeaders = init === null || init === void 0 ? void 0 : init.headers;
|
|
320
|
+
const req = new Request("", {
|
|
321
|
+
body: requestBody,
|
|
322
|
+
method: requestMethod,
|
|
323
|
+
headers: requestHeaders,
|
|
324
|
+
});
|
|
325
|
+
const headers = Object.fromEntries(req.headers.entries());
|
|
326
|
+
const body = req.method !== "GET" ? await req.text() : undefined;
|
|
327
|
+
return {
|
|
328
|
+
...init,
|
|
329
|
+
body: body,
|
|
330
|
+
headers,
|
|
331
|
+
method: requestMethod ?? "GET",
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
async function parseToResponseData(res) {
|
|
335
|
+
const response = new Response(res.body == null ? undefined : typeof res.body === "object" ? JSON.stringify(res.body) : res.body, {
|
|
336
|
+
status: res.status,
|
|
337
|
+
headers: new Headers(res.headers),
|
|
338
|
+
});
|
|
339
|
+
return response;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
async function callRequestBridge(handlerName, payload) {
|
|
343
|
+
const postPayload = await buildPayloadByRequestInit(payload);
|
|
344
|
+
const { status, headers, body } = await NexusBridge.call(handlerName, postPayload);
|
|
345
|
+
return parseToResponseData({ status, headers, body });
|
|
346
|
+
}
|
|
347
|
+
async function requestApi(path, options) {
|
|
348
|
+
return callRequestBridge("requestApi", { path, ...options });
|
|
349
|
+
}
|
|
262
350
|
|
|
263
351
|
/**
|
|
264
352
|
* Generated bundle index. Do not edit.
|
|
265
353
|
*/
|
|
266
354
|
|
|
267
|
-
export {
|
|
355
|
+
export { dialog, events, i18n, invoke, requestApi, router, view, BridgeAPIError as ɵBridgeAPIError, NexusBridge as ɵNexusBridge };
|
|
268
356
|
//# sourceMappingURL=pc-nexus-bridge.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pc-nexus-bridge.mjs","sources":["../../../../web/bridge/src/window.ts","../../../../web/bridge/src/bridge.ts","../../../../web/bridge/src/dialog.ts","../../../../web/bridge/src/invoke.ts","../../../../web/bridge/src/router.ts","../../../../web/bridge/src/view.ts","../../../../web/bridge/src/utils/blob-parser.ts","../../../../web/bridge/src/events.ts","../../../../web/bridge/src/i18n.ts","../../../../web/bridge/src/public-api.ts","../../../../web/bridge/src/pc-nexus-bridge.ts"],"sourcesContent":["export type SafeAny = any;\n\nexport function attachObjectToWindow<T>(key: string, value: T) {\n (window as SafeAny)[key] = value;\n}\n\nexport function getObjectFromWindow<T>(key: string) {\n return (window as SafeAny)[key];\n}\n","import { getObjectFromWindow } from \"./window\";\n\nexport interface HostMessageEvent<T = unknown> {\n source: Window | null;\n origin: string;\n data: T;\n}\n\nexport interface Cancelable {\n cancel: () => void;\n}\n\ninterface GlobalBridge {\n call<T>(name: string, payload?: object | undefined): Promise<T>;\n on<T>(name: string, handler: (event: HostMessageEvent<T>) => void): Cancelable;\n}\n\nfunction getBridge() {\n const bridge = getObjectFromWindow<GlobalBridge>(\"__pc_nexus_bridge__\");\n return bridge;\n}\n\nexport class NexusBridge {\n static getBridgeCall<T>(): (name: string, payload?: object) => Promise<T> {\n if (!getBridge()) {\n throw new Error(`\n Unable to establish a connection with the PingCode nexus bridge.\n If you are trying to run your app locally, Nexus apps only work in the context of PingCode products. Refer to https://developer.pingcode.com for how to tunnel when using a local development server.\n `);\n }\n return getBridge().call;\n }\n\n static async call<T>(name: string, payload?: object | undefined): Promise<T> {\n const result = await NexusBridge.getBridgeCall<T>()(name, payload);\n return result as T;\n }\n\n /**\n * 订阅宿主 host 发来的消息。\n * @param name 消息名称\n * @param handler 收到消息时的回调,event 包含 source、origin、data\n * @returns 返回带 cancel() 的对象,调用可取消订阅\n */\n static on<T>(name: string, handler: (event: HostMessageEvent<T>) => void): Cancelable {\n const bridge = getBridge();\n if (!bridge) {\n throw new Error(`\n Unable to establish a connection with the PingCode nexus bridge.\n If you are trying to run your app locally, Nexus apps only work in the context of PingCode products. Refer to https://developer.pingcode.com for how to tunnel when using a local development server.\n `);\n }\n return bridge.on(name, handler);\n }\n}\n","import { DialogOptions, DialogRef } from \"@pc-nexus/models\";\nimport { NexusBridge } from \"./bridge\";\n\nclass NexusDialog {\n async open<T>(options: DialogOptions): Promise<DialogRef<T>> {\n return (await NexusBridge.call<DialogRef<T>>(\"openDialog\", options).catch((error) => {\n console.error(\"nexus open dialog failed\", error);\n })) as DialogRef<T>;\n }\n}\n\nexport const dialog = new NexusDialog();\n","import { NexusBridge } from \"./bridge\";\nimport { InvokeFunctionParams } from \"./models\";\nimport { getObjectFromWindow } from \"./window\";\n\nexport async function invoke<TPayload = any, TResult = any>(functionKey: string, payload?: TPayload): Promise<TResult> {\n const params: InvokeFunctionParams = {\n function: functionKey,\n payload: payload,\n tunnel_token: getObjectFromWindow(\"__TUNNEL_TOKEN__\"),\n } as InvokeFunctionParams;\n const result = await NexusBridge.call(\"invokeFunction\", params);\n return result as TResult;\n}\n","import { NexusBridge } from \"./bridge\";\nimport { NavigationLocation } from \"./models\";\n\nexport class NexusRouter {\n async navigate(urlOrLocation: string | NavigationLocation): Promise<void> {\n await NexusBridge.call<void>(\"routerNavigate\", { urlOrLocation });\n }\n\n async open(urlOrLocation: string | NavigationLocation): Promise<void> {\n await NexusBridge.call<void>(\"routerOpen\", { urlOrLocation });\n }\n\n async getUrl(location: NavigationLocation): Promise<string> {\n return await NexusBridge.call<string>(\"routerGetUrl\", { location });\n }\n\n async reload(): Promise<void> {\n await NexusBridge.call<void>(\"routerReload\", {});\n }\n}\n\nexport const router = new NexusRouter();\n","import { NexusBridge } from \"./bridge\";\nimport { ExtensionData, NexusFullContext } from \"./models\";\n\nexport interface LocationDescriptor {\n pathname: string;\n search?: string;\n hash?: string;\n state?: unknown;\n}\n\nexport type HistoryAction = \"POP\" | \"PUSH\" | \"REPLACE\";\n\nexport type UnlistenCallback = () => void;\n\nexport interface NexusHistory {\n action: HistoryAction;\n location: LocationDescriptor;\n push(path: string, state?: unknown): void;\n push(location: LocationDescriptor): void;\n replace(path: string, state?: unknown): void;\n replace(location: LocationDescriptor): void;\n go(n: number): void;\n goBack(): void;\n goForward(): void;\n listen(listener: (location: LocationDescriptor, action: HistoryAction) => void): Promise<UnlistenCallback>;\n}\n\nexport class NexusView {\n async getContext<T = ExtensionData>(): Promise<NexusFullContext<T>> {\n return await NexusBridge.call(\"getContext\");\n }\n\n async setWindowTitle(title: string): Promise<void> {\n await NexusBridge.call<void>(\"setWindowTitle\", { title });\n }\n\n async reload(): Promise<void> {\n await NexusBridge.call<void>(\"viewReload\");\n }\n\n async close(): Promise<void> {\n await NexusBridge.call<void>(\"viewClose\");\n }\n\n async createHistory(): Promise<NexusHistory> {\n const history = await NexusBridge.call<NexusHistory>(\"createHistory\");\n history.listen((location, action) => {\n history.action = action;\n history.location = location;\n });\n return history;\n }\n}\n\nexport const view = new NexusView();\n","export const isPlainObject = (value: any) => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n if (Object.prototype.toString.call(value) !== '[object Object]') {\n return false;\n }\n const proto = Object.getPrototypeOf(value);\n if (proto === null) {\n return true;\n }\n const constructor = Object.prototype.hasOwnProperty.call(proto, 'constructor') && proto.constructor;\n return (typeof constructor === 'function' &&\n constructor instanceof constructor &&\n Function.prototype.call(constructor) === Function.prototype.call(value));\n};\n\nexport const base64ToBlob = (b64string: string, mimeType: string) => {\n if (!b64string) {\n return null;\n }\n const base64String = b64string.includes(',') ? b64string.split(',')[1] : b64string;\n const byteCharacters = atob(base64String);\n const byteNumbers = new Array(byteCharacters.length);\n for (let i = 0; i < byteCharacters.length; i++) {\n byteNumbers[i] = byteCharacters.charCodeAt(i);\n }\n\n const byteArray = new Uint8Array(byteNumbers);\n return new Blob([byteArray], { type: mimeType });\n};\n\nexport const blobToBase64 = (blob: Blob) => {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onloadend = () => {\n resolve(reader.result);\n };\n reader.onerror = reject;\n reader.readAsDataURL(blob);\n });\n};\n\nexport const serialiseBlobsInPayload = async (payload: any): Promise<any> => {\n if (payload instanceof Blob) {\n const base64Data = await blobToBase64(payload);\n return {\n data: base64Data,\n type: payload.type,\n __isBlobData: true\n };\n }\n if (Array.isArray(payload)) {\n return Promise.all(payload.map((item) => serialiseBlobsInPayload(item)));\n }\n if (payload && isPlainObject(payload)) {\n const entries = await Promise.all(Object.entries(payload).map(async ([key, value]) => [key, await serialiseBlobsInPayload(value)]));\n return Object.fromEntries(entries);\n }\n return payload;\n};\n\nexport const deserialiseBlobsInPayload = (payload: any): any => {\n if (payload && isPlainObject(payload) && '__isBlobData' in payload) {\n const typedData = payload;\n return base64ToBlob(typedData.data, typedData.type);\n }\n if (Array.isArray(payload)) {\n return payload.map((item) => deserialiseBlobsInPayload(item));\n }\n if (payload && isPlainObject(payload)) {\n const result = {};\n for (const [key, value] of Object.entries(payload)) {\n (result as any)[key] = deserialiseBlobsInPayload(value);\n }\n return result;\n }\n return payload;\n};\n\nexport const containsBlobs = (payload: any): boolean => {\n if (payload instanceof Blob) {\n return true;\n }\n if (Array.isArray(payload)) {\n return payload.some(item => containsBlobs(item));\n }\n if (payload && isPlainObject(payload)) {\n return Object.values(payload).some((value) => containsBlobs(value));\n }\n return false;\n};\nexport const containsSerialisedBlobs = (payload: any): boolean => {\n if (payload && isPlainObject(payload) && '__isBlobData' in payload) {\n return true;\n }\n if (Array.isArray(payload)) {\n return payload.some((item) => containsSerialisedBlobs(item));\n }\n if (payload && isPlainObject(payload)) {\n return Object.values(payload).some((value) => containsSerialisedBlobs(value));\n }\n return false;\n};\n","import { NexusBridge } from \"./bridge\";\nimport { Subscription } from \"./models\";\nimport { containsBlobs, serialiseBlobsInPayload, containsSerialisedBlobs, deserialiseBlobsInPayload } from \"./utils\";\n\nasync function on<T = any>(eventName: string, callback: (payload?: T) => any): Promise<Subscription> {\n const wrappedCallback = (payload: T) => {\n let newPayload = payload;\n if (containsSerialisedBlobs(payload)) {\n newPayload = deserialiseBlobsInPayload(payload);\n }\n return callback(newPayload);\n };\n return NexusBridge.call('on', { eventName, callback: wrappedCallback });\n}\n\nasync function emit<T = any>(eventName: string, payload: T): Promise<void> {\n let newPayload = payload;\n if (containsBlobs(payload)) {\n newPayload = await serialiseBlobsInPayload(payload);\n }\n return NexusBridge.call('emit', { eventName, payload: newPayload });\n}\n\nexport const events = {\n on,\n emit\n}\n","import { Translator, GetTranslationsResult, NexusSupportedLocaleCode, TranslationResourceContent } from \"@pc-nexus/models\";\nimport { view } from \"./view\";\nimport { NexusBridge } from \"./bridge\";\n\nexport class NexusI18n {\n private translationsCache: Partial<Record<NexusSupportedLocaleCode, Promise<TranslationResourceContent>>> = {};\n\n private i18nFolderName = \"__LOCALES__\";\n\n async getTranslations(locale?: NexusSupportedLocaleCode): Promise<GetTranslationsResult> {\n if (!locale) {\n locale = (await view.getContext()).locale;\n }\n const translations = await this.loadTranslations(locale);\n return { locale, translations };\n }\n\n async createTranslator(locale?: NexusSupportedLocaleCode): Promise<Translator> {\n if (!locale) {\n locale = (await view.getContext()).locale;\n }\n const translations = await this.loadTranslations(locale);\n return await NexusBridge.call(\"createTranslator\", { locale, translations });\n }\n\n private loadTranslations(locale: NexusSupportedLocaleCode): Promise<TranslationResourceContent> {\n const url = `../${this.i18nFolderName}/${locale}.json`;\n if (!this.translationsCache[locale]) {\n this.translationsCache[locale] = fetch(url)\n .then((res) => res.json())\n .catch((err) => {\n // 请求失败要清理缓存\n delete this.translationsCache[locale];\n throw err;\n });\n }\n\n return this.translationsCache[locale]!;\n }\n}\n\nexport const i18n = new NexusI18n();\n","/*\n * Public API Surface of bridge\n */\nexport {\n NexusBridge,\n type HostMessageEvent,\n type Cancelable,\n} from \"./bridge\";\nexport * from \"./dialog\";\nexport * from \"./invoke\";\nexport * from \"./models\";\nexport { router } from \"./router\";\nexport { view, type LocationDescriptor, type HistoryAction, type UnlistenCallback, type NexusHistory } from \"./view\";\nexport { events } from \"./events\";\nexport { i18n } from \"./i18n\";\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;AAEM,SAAU,oBAAoB,CAAI,GAAW,EAAE,KAAQ,EAAA;AACxD,IAAA,MAAkB,CAAC,GAAG,CAAC,GAAG,KAAK;AACpC;AAEM,SAAU,mBAAmB,CAAI,GAAW,EA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,MAAM,CAAA,KAAA,CAAO;QACtD,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE;YACjC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG;iBACrC,IAAI,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI,EAAE;AACxB,iBAAA,KAAK,CAAC,CAAC,GAAG,KAAI;;AAEX,gBAAA,OAAO,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC;AACrC,gBAAA,MAAM,GAAG;AACb,YAAA,CAAC,CAAC;QACV;AAEA,QAAA,OAAO,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAE;IAC1C;AACH;AAEM,MAAM,IAAI,GAAG,IAAI,SAAS;;ACzCjC;;AAEG;;ACFH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"pc-nexus-bridge.mjs","sources":["../../../../web/bridge/src/window.ts","../../../../web/bridge/src/bridge.ts","../../../../web/bridge/src/error.ts","../../../../web/bridge/src/dialog.ts","../../../../web/bridge/src/invoke.ts","../../../../web/bridge/src/router.ts","../../../../web/bridge/src/view.ts","../../../../web/bridge/src/utils/blob-parser.ts","../../../../web/bridge/src/events.ts","../../../../web/bridge/src/i18n.ts","../../../../web/bridge/src/utils/request.ts","../../../../web/bridge/src/request-api.ts","../../../../web/bridge/src/pc-nexus-bridge.ts"],"sourcesContent":["export type SafeAny = any;\n\nexport function attachObjectToWindow<T>(key: string, value: T) {\n (window as SafeAny)[key] = value;\n}\n\nexport function getObjectFromWindow<T>(key: string) {\n return (window as SafeAny)[key];\n}\n","import { getObjectFromWindow } from \"./window\";\n\ninterface HostMessageEvent<T = unknown> {\n source: Window | null;\n origin: string;\n data: T;\n}\n\ninterface Cancelable {\n cancel: () => void;\n}\n\ninterface GlobalBridge {\n call<T>(name: string, payload?: object | undefined): Promise<T>;\n on<T>(name: string, handler: (event: HostMessageEvent<T>) => void): Cancelable;\n}\n\nfunction getBridge() {\n const bridge = getObjectFromWindow<GlobalBridge>(\"__pc_nexus_bridge__\");\n return bridge;\n}\n\nexport class NexusBridge {\n static getBridgeCall<T>(): (name: string, payload?: object) => Promise<T> {\n if (!getBridge()) {\n throw new Error(`\n Unable to establish a connection with the PingCode nexus bridge.\n If you are trying to run your app locally, Nexus apps only work in the context of PingCode products. Refer to https://developer.pingcode.com for how to tunnel when using a local development server.\n `);\n }\n return getBridge().call;\n }\n\n static async call<T>(name: string, payload?: any): Promise<T> {\n const result = await NexusBridge.getBridgeCall<T>()(name, payload);\n return result as T;\n }\n\n /**\n * 订阅宿主 host 发来的消息。\n * @param name 消息名称\n * @param handler 收到消息时的回调,event 包含 source、origin、data\n * @returns 返回带 cancel() 的对象,调用可取消订阅\n */\n static on<T>(name: string, handler: (event: HostMessageEvent<T>) => void): Cancelable {\n const bridge = getBridge();\n if (!bridge) {\n throw new Error(`\n Unable to establish a connection with the PingCode nexus bridge.\n If you are trying to run your app locally, Nexus apps only work in the context of PingCode products. Refer to https://developer.pingcode.com for how to tunnel when using a local development server.\n `);\n }\n return bridge.on(name, handler);\n }\n}\n","export class BridgeAPIError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"BridgeAPIError\";\n Object.setPrototypeOf(this, BridgeAPIError.prototype);\n }\n}\n\n// 自动注册:所有未 catch 的 Promise rejection 均以 \"Uncaught (in promise)\" 格式输出,无需用户配置\nif (typeof window !== \"undefined\") {\n window.addEventListener(\n \"unhandledrejection\",\n (event: PromiseRejectionEvent) => {\n const reason = event.reason;\n const error = reason instanceof Error ? reason : new Error(String(reason));\n const firstLine = `Uncaught (in promise) ${error.name}: ${error.message}`;\n const stack = error.stack?.replace(/^[^\\n]*\\n?/, \"\").trim() || \"\";\n console.error(stack ? `${firstLine}\\n${stack}` : firstLine);\n event.preventDefault();\n event.stopImmediatePropagation();\n },\n true,\n );\n}\n","import { DialogOptions, DialogRef } from \"./models\";\nimport { NexusBridge } from \"./bridge\";\n\nclass NexusDialog {\n async open<T>(options: DialogOptions): Promise<DialogRef<T>> {\n return await NexusBridge.call<DialogRef<T>>(\"openDialog\", options);\n }\n}\n\nexport const dialog = new NexusDialog();\n","import { NexusBridge } from \"./bridge\";\nimport { InvokeFunctionParams } from \"./models\";\nimport { getObjectFromWindow } from \"./window\";\n\nexport async function invoke<TPayload = any, TResult = any>(functionKey: string, payload?: TPayload): Promise<TResult> {\n const params: InvokeFunctionParams = {\n function: functionKey,\n payload: payload,\n tunnel_token: getObjectFromWindow(\"__TUNNEL_TOKEN__\"),\n } as InvokeFunctionParams;\n const result = await NexusBridge.call(\"invokeFunction\", params);\n return result as TResult;\n}\n","import { NexusBridge } from \"./bridge\";\nimport { NavigationLocation } from \"./models\";\n\nclass NexusRouter {\n async navigate(urlOrLocation: string | NavigationLocation): Promise<void> {\n await NexusBridge.call<void>(\"routerNavigate\", { urlOrLocation });\n }\n\n async open(urlOrLocation: string | NavigationLocation): Promise<void> {\n await NexusBridge.call<void>(\"routerOpen\", { urlOrLocation });\n }\n\n async generateUrl(location: NavigationLocation): Promise<string> {\n return await NexusBridge.call<string>(\"routerGenerateUrl\", { location });\n }\n\n async reload(): Promise<void> {\n await NexusBridge.call<void>(\"routerReload\", {});\n }\n}\n\nexport const router = new NexusRouter();\n","import { NexusBridge } from \"./bridge\";\nimport { ExtensionData, NexusFullContext, NexusHistory } from \"./models\";\nimport { BridgeAPIError } from \"./error\";\n\nclass NexusView {\n async getContext<T = ExtensionData>(): Promise<NexusFullContext<T>> {\n return await NexusBridge.call(\"getContext\");\n }\n\n async setWindowTitle(title: string): Promise<void> {\n await NexusBridge.call<void>(\"setWindowTitle\", { title });\n }\n\n async reload(): Promise<void> {\n await NexusBridge.call<void>(\"viewReload\");\n }\n\n async close(): Promise<void> {\n const isSuccess = await NexusBridge.call<boolean>(\"viewClose\");\n if (!isSuccess) {\n const errorMessage = \"this resource's view is not closable.\";\n throw new BridgeAPIError(errorMessage);\n }\n }\n\n async onClose(payload: () => Promise<void>): Promise<void> {\n await NexusBridge.call<void>(\"viewOnClose\", { payload });\n }\n\n async isDialog(): Promise<boolean> {\n return await NexusBridge.call<boolean>(\"viewIsDialog\");\n }\n\n async createHistory(): Promise<NexusHistory> {\n const history = await NexusBridge.call<NexusHistory>(\"createHistory\");\n history.listen((location, action) => {\n history.action = action;\n history.location = location;\n });\n return history;\n }\n\n async submit<T = any>(payload?: T): Promise<void> {\n await NexusBridge.call<void>(\"viewSubmit\", payload);\n }\n}\n\nexport const view = new NexusView();\n","const isPlainObject = (value: any) => {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n if (Object.prototype.toString.call(value) !== \"[object Object]\") {\n return false;\n }\n const proto = Object.getPrototypeOf(value);\n if (proto === null) {\n return true;\n }\n const constructor = Object.prototype.hasOwnProperty.call(proto, \"constructor\") && proto.constructor;\n return (\n typeof constructor === \"function\" &&\n constructor instanceof constructor &&\n Function.prototype.call(constructor) === Function.prototype.call(value)\n );\n};\n\nconst base64ToBlob = (b64string: string, mimeType: string) => {\n if (!b64string) {\n return null;\n }\n const base64String = b64string.includes(\",\") ? b64string.split(\",\")[1] : b64string;\n const byteCharacters = atob(base64String);\n const byteNumbers = new Array(byteCharacters.length);\n for (let i = 0; i < byteCharacters.length; i++) {\n byteNumbers[i] = byteCharacters.charCodeAt(i);\n }\n\n const byteArray = new Uint8Array(byteNumbers);\n return new Blob([byteArray], { type: mimeType });\n};\n\nconst blobToBase64 = (blob: Blob) => {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onloadend = () => {\n resolve(reader.result);\n };\n reader.onerror = reject;\n reader.readAsDataURL(blob);\n });\n};\n\nexport const serialiseBlobsInPayload = async (payload: any): Promise<any> => {\n if (payload instanceof Blob) {\n const base64Data = await blobToBase64(payload);\n return {\n data: base64Data,\n type: payload.type,\n __isBlobData: true,\n };\n }\n if (Array.isArray(payload)) {\n return Promise.all(payload.map((item) => serialiseBlobsInPayload(item)));\n }\n if (payload && isPlainObject(payload)) {\n const entries = await Promise.all(Object.entries(payload).map(async ([key, value]) => [key, await serialiseBlobsInPayload(value)]));\n return Object.fromEntries(entries);\n }\n return payload;\n};\n\nexport const deserialiseBlobsInPayload = (payload: any): any => {\n if (payload && isPlainObject(payload) && \"__isBlobData\" in payload) {\n const typedData = payload;\n return base64ToBlob(typedData.data, typedData.type);\n }\n if (Array.isArray(payload)) {\n return payload.map((item) => deserialiseBlobsInPayload(item));\n }\n if (payload && isPlainObject(payload)) {\n const result = {};\n for (const [key, value] of Object.entries(payload)) {\n (result as any)[key] = deserialiseBlobsInPayload(value);\n }\n return result;\n }\n return payload;\n};\n\nexport const containsBlobs = (payload: any): boolean => {\n if (payload instanceof Blob) {\n return true;\n }\n if (Array.isArray(payload)) {\n return payload.some((item) => containsBlobs(item));\n }\n if (payload && isPlainObject(payload)) {\n return Object.values(payload).some((value) => containsBlobs(value));\n }\n return false;\n};\n\nexport const containsSerialisedBlobs = (payload: any): boolean => {\n if (payload && isPlainObject(payload) && \"__isBlobData\" in payload) {\n return true;\n }\n if (Array.isArray(payload)) {\n return payload.some((item) => containsSerialisedBlobs(item));\n }\n if (payload && isPlainObject(payload)) {\n return Object.values(payload).some((value) => containsSerialisedBlobs(value));\n }\n return false;\n};\n","import { NexusBridge } from \"./bridge\";\nimport { Subscription } from \"./models\";\nimport { containsBlobs, serialiseBlobsInPayload, containsSerialisedBlobs, deserialiseBlobsInPayload } from \"./utils\";\n\nasync function on<T = any>(eventName: string, callback: (payload?: T) => any): Promise<Subscription> {\n const wrappedCallback = (payload: T) => {\n let newPayload = payload;\n if (containsSerialisedBlobs(payload)) {\n newPayload = deserialiseBlobsInPayload(payload);\n }\n return callback(newPayload);\n };\n return NexusBridge.call(\"on\", { eventName, callback: wrappedCallback });\n}\n\nasync function emit<T = any>(eventName: string, payload: T): Promise<void> {\n let newPayload = payload;\n if (containsBlobs(payload)) {\n newPayload = await serialiseBlobsInPayload(payload);\n }\n return NexusBridge.call(\"emit\", { eventName, payload: newPayload });\n}\n\nexport const events = {\n on,\n emit,\n};\n","import { Translator, GetTranslationsResult, NexusSupportedLocaleCode, TranslationResourceContent } from \"./models\";\nimport { view } from \"./view\";\n\nclass NexusI18n {\n private translationsCache: Partial<Record<NexusSupportedLocaleCode, Promise<TranslationResourceContent>>> = {};\n\n private i18nFolderName = \"__LOCALES__\";\n\n async getTranslations(locale?: NexusSupportedLocaleCode): Promise<GetTranslationsResult> {\n if (!locale) {\n locale = (await view.getContext()).locale;\n }\n const translations = await this.loadTranslations(locale!);\n return { locale: locale!, translations };\n }\n\n async createTranslator(locale?: NexusSupportedLocaleCode): Promise<Translator> {\n if (!locale) {\n locale = (await view.getContext()).locale;\n }\n const translations = await this.loadTranslations(locale!);\n return {\n translate: (key: string, params: Record<string, any> = {}) => this.translate(key, translations, params),\n };\n }\n\n private loadTranslations(locale: NexusSupportedLocaleCode): Promise<TranslationResourceContent> {\n const url = `../${this.i18nFolderName}/${locale}.json`;\n if (!this.translationsCache[locale]) {\n this.translationsCache[locale] = fetch(url)\n .then((res) => res.json())\n .catch((err) => {\n // 请求失败要清理缓存\n delete this.translationsCache[locale];\n throw err;\n });\n }\n\n return this.translationsCache[locale]!;\n }\n\n private getValue(obj: any, path: string): any {\n return path.split(\".\").reduce((o, k) => (o != null && typeof o === \"object\" ? o[k] : undefined), obj);\n }\n\n private translate(\n key: string,\n translations: TranslationResourceContent,\n params?: Record<string, any>,\n ): TranslationResourceContent | string {\n // 获取值(扁平或嵌套)\n let value: any = translations[key] ?? this.getValue(translations, key);\n\n // key 不存在 → 返回 key\n if (value == null) return key;\n\n // 如果 value 是对象 → 直接返回\n if (typeof value === \"object\") return value;\n\n // 确保 value 是字符串\n if (typeof value !== \"string\") value = String(value);\n\n // 无参数 → 直接返回\n if (!params) return value;\n\n // 参数替换\n return value.replace(/\\{\\{\\s*(.*?)\\s*\\}\\}/g, (_: string, k: string) => {\n const paramValue = this.getValue(params, k.trim());\n return paramValue != null ? String(paramValue) : `{{${k}}}`;\n });\n }\n}\n\nexport const i18n = new NexusI18n();\n","import { RequestApiResponseData } from \"../models\";\n\nexport async function buildPayloadByRequestInit<TPayload extends RequestInit = RequestInit>(init?: TPayload) {\n const requestBody = init === null || init === void 0 ? void 0 : init.body;\n const requestMethod = init === null || init === void 0 ? void 0 : init.method;\n const requestHeaders = init === null || init === void 0 ? void 0 : init.headers;\n const req = new Request(\"\", {\n body: requestBody,\n method: requestMethod,\n headers: requestHeaders,\n });\n const headers = Object.fromEntries(req.headers.entries());\n const body = req.method !== \"GET\" ? await req.text() : undefined;\n return {\n ...init,\n body: body,\n headers,\n method: requestMethod ?? \"GET\",\n };\n}\n\nexport async function parseToResponseData(res: RequestApiResponseData): Promise<Response> {\n const response = new Response(\n res.body == null ? undefined : typeof res.body === \"object\" ? JSON.stringify(res.body) : (res.body as BodyInit),\n {\n status: res.status,\n headers: new Headers(res.headers),\n },\n );\n\n return response;\n}\n","import { NexusBridge } from \"./bridge\";\nimport { RequestApiResponseData } from \"./models\";\nimport { buildPayloadByRequestInit, parseToResponseData } from \"./utils/request\";\n\ninterface RequestApiParams extends RequestInit {\n path: string;\n}\n\nasync function callRequestBridge<TPayload extends RequestInit = RequestInit>(handlerName: string, payload: TPayload): Promise<Response> {\n const postPayload = await buildPayloadByRequestInit<TPayload>(payload);\n const { status, headers, body } = await NexusBridge.call<RequestApiResponseData>(handlerName, postPayload);\n return parseToResponseData({ status, headers, body });\n}\n\nexport async function requestApi(path: string, options?: RequestInit): Promise<Response> {\n return callRequestBridge<RequestApiParams>(\"requestApi\", { path, ...options });\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;AAEM,SAAU,oBAAoB,CAAI,GAAW,EAAE,KAAQ,EAAA;AACxD,IAAA,MAAkB,CAAC,GAAG,CAAC,GAAG,KAAK;AACpC;AAEM,SAAU,mBAAmB,CAAI,GAAW,EAAA;AAC9C,IAAA,OAAQ,MAAkB,CAAC,GAAG,CAAC;AACnC;;ACSA,SAAS,SAAS,GAAA;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A2B,EAAA;AACjE,IAAA,MAAM,QAAQ,GAAG,IAAI,QAAQ,CACzB,GAAG,CAAC,IAAI,IAAI,IAAI,GAAG,SAAS,GAAG,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,GAAI,GAAG,CAAC,IAAiB,EAC/G;QACI,MAAM,EAAE,GAAG,CAAC,MAAM;AAClB,QAAA,OAAO,EAAE,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;AACpC,KAAA,CACJ;AAED,IAAA,OAAO,QAAQ;AACnB;;ACvBA,eAAe,iBAAiB,CAA6C,WAAmB,EAAE,OAAiB,EAAA;AAC/G,IAAA,MAAM,WAAW,GAAG,MAAM,yBAAyB,CAAW,OAAO,CAAC;AACtE,IAAA,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,WAAW,CAAC,IAAI,CAAyB,WAAW,EAAE,WAAW,CAAC;IAC1G,OAAO,mBAAmB,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACzD;AAEO,eAAe,UAAU,CAAC,IAAY,EAAE,OAAqB,EAAA;IAChE,OAAO,iBAAiB,CAAmB,YAAY,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC;AAClF;;AChBA;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pc-nexus/bridge",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.3",
|
|
4
4
|
"peerDependencies": {},
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@pc-nexus/models": "
|
|
6
|
+
"@pc-nexus/models": "0.0.1-next.3",
|
|
7
7
|
"tslib": "^2.3.0"
|
|
8
8
|
},
|
|
9
9
|
"sideEffects": false,
|
|
@@ -18,4 +18,4 @@
|
|
|
18
18
|
"default": "./fesm2022/pc-nexus-bridge.mjs"
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
}
|
|
21
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DialogOptions, DialogRef, NavigationLocation, ExtensionData, NexusFullContext, Subscription, NexusSupportedLocaleCode, GetTranslationsResult, Translator } from '@pc-nexus/models';
|
|
2
|
-
export
|
|
1
|
+
import { DialogOptions, DialogRef, NavigationLocation, ExtensionData, NexusFullContext, NexusHistory, Subscription, NexusSupportedLocaleCode, GetTranslationsResult, Translator } from '@pc-nexus/models';
|
|
2
|
+
export { DialogOptions, DialogRef, ExtensionData, GetTranslationsResult, HistoryAction, LocationDescriptor, NavigationLocation, NavigationTarget, NexusFullContext, NexusHistory, NexusSupportedLocaleCode, Subscription, TranslationResourceContent, Translator, UnlistenCallback, ViewportSize } from '@pc-nexus/models';
|
|
3
3
|
|
|
4
4
|
interface HostMessageEvent<T = unknown> {
|
|
5
5
|
source: Window | null;
|
|
@@ -11,7 +11,7 @@ interface Cancelable {
|
|
|
11
11
|
}
|
|
12
12
|
declare class NexusBridge {
|
|
13
13
|
static getBridgeCall<T>(): (name: string, payload?: object) => Promise<T>;
|
|
14
|
-
static call<T>(name: string, payload?:
|
|
14
|
+
static call<T>(name: string, payload?: any): Promise<T>;
|
|
15
15
|
/**
|
|
16
16
|
* 订阅宿主 host 发来的消息。
|
|
17
17
|
* @param name 消息名称
|
|
@@ -21,6 +21,10 @@ declare class NexusBridge {
|
|
|
21
21
|
static on<T>(name: string, handler: (event: HostMessageEvent<T>) => void): Cancelable;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
declare class BridgeAPIError extends Error {
|
|
25
|
+
constructor(message: string);
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
declare class NexusDialog {
|
|
25
29
|
open<T>(options: DialogOptions): Promise<DialogRef<T>>;
|
|
26
30
|
}
|
|
@@ -31,37 +35,20 @@ declare function invoke<TPayload = any, TResult = any>(functionKey: string, payl
|
|
|
31
35
|
declare class NexusRouter {
|
|
32
36
|
navigate(urlOrLocation: string | NavigationLocation): Promise<void>;
|
|
33
37
|
open(urlOrLocation: string | NavigationLocation): Promise<void>;
|
|
34
|
-
|
|
38
|
+
generateUrl(location: NavigationLocation): Promise<string>;
|
|
35
39
|
reload(): Promise<void>;
|
|
36
40
|
}
|
|
37
41
|
declare const router: NexusRouter;
|
|
38
42
|
|
|
39
|
-
interface LocationDescriptor {
|
|
40
|
-
pathname: string;
|
|
41
|
-
search?: string;
|
|
42
|
-
hash?: string;
|
|
43
|
-
state?: unknown;
|
|
44
|
-
}
|
|
45
|
-
type HistoryAction = "POP" | "PUSH" | "REPLACE";
|
|
46
|
-
type UnlistenCallback = () => void;
|
|
47
|
-
interface NexusHistory {
|
|
48
|
-
action: HistoryAction;
|
|
49
|
-
location: LocationDescriptor;
|
|
50
|
-
push(path: string, state?: unknown): void;
|
|
51
|
-
push(location: LocationDescriptor): void;
|
|
52
|
-
replace(path: string, state?: unknown): void;
|
|
53
|
-
replace(location: LocationDescriptor): void;
|
|
54
|
-
go(n: number): void;
|
|
55
|
-
goBack(): void;
|
|
56
|
-
goForward(): void;
|
|
57
|
-
listen(listener: (location: LocationDescriptor, action: HistoryAction) => void): Promise<UnlistenCallback>;
|
|
58
|
-
}
|
|
59
43
|
declare class NexusView {
|
|
60
44
|
getContext<T = ExtensionData>(): Promise<NexusFullContext<T>>;
|
|
61
45
|
setWindowTitle(title: string): Promise<void>;
|
|
62
46
|
reload(): Promise<void>;
|
|
63
47
|
close(): Promise<void>;
|
|
48
|
+
onClose(payload: () => Promise<void>): Promise<void>;
|
|
49
|
+
isDialog(): Promise<boolean>;
|
|
64
50
|
createHistory(): Promise<NexusHistory>;
|
|
51
|
+
submit<T = any>(payload?: T): Promise<void>;
|
|
65
52
|
}
|
|
66
53
|
declare const view: NexusView;
|
|
67
54
|
|
|
@@ -78,8 +65,11 @@ declare class NexusI18n {
|
|
|
78
65
|
getTranslations(locale?: NexusSupportedLocaleCode): Promise<GetTranslationsResult>;
|
|
79
66
|
createTranslator(locale?: NexusSupportedLocaleCode): Promise<Translator>;
|
|
80
67
|
private loadTranslations;
|
|
68
|
+
private getValue;
|
|
69
|
+
private translate;
|
|
81
70
|
}
|
|
82
71
|
declare const i18n: NexusI18n;
|
|
83
72
|
|
|
84
|
-
|
|
85
|
-
|
|
73
|
+
declare function requestApi(path: string, options?: RequestInit): Promise<Response>;
|
|
74
|
+
|
|
75
|
+
export { dialog, events, i18n, invoke, requestApi, router, view, BridgeAPIError as ɵBridgeAPIError, NexusBridge as ɵNexusBridge };
|