@pc-nexus/bridge 0.1.0 → 0.5.0-next.1
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,3 +1,4 @@
|
|
|
1
|
+
import { SUPPORTED_LOCALE_CODES } from '@pc-nexus/models';
|
|
1
2
|
export { HistoryAction, NavigationTarget, ViewportSize } from '@pc-nexus/models';
|
|
2
3
|
|
|
3
4
|
function attachObjectToWindow(key, value) {
|
|
@@ -63,14 +64,50 @@ if (typeof window !== "undefined") {
|
|
|
63
64
|
}, true);
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
function validateOpenOptions(options) {
|
|
68
|
+
if (typeof options !== "object" || options === null) {
|
|
69
|
+
throw new BridgeAPIError('"options" must be an object in dialog open.');
|
|
70
|
+
}
|
|
71
|
+
if (!options.resource) {
|
|
72
|
+
throw new BridgeAPIError('"resource" is required in dialog open options.');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function validateConfirmOptions(options) {
|
|
76
|
+
if (typeof options !== "object" || options === null) {
|
|
77
|
+
throw new BridgeAPIError('"options" must be an object in dialog confirm.');
|
|
78
|
+
}
|
|
79
|
+
if (!options.content) {
|
|
80
|
+
throw new BridgeAPIError('"content" is required in dialog confirm options.');
|
|
81
|
+
}
|
|
82
|
+
if (typeof options.onConfirm !== "function") {
|
|
83
|
+
throw new BridgeAPIError('"onConfirm" must be a function in dialog confirm options.');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
66
86
|
class NexusDialog {
|
|
67
87
|
async open(options) {
|
|
88
|
+
validateOpenOptions(options);
|
|
68
89
|
return await NexusBridge.call("openDialog", options);
|
|
69
90
|
}
|
|
91
|
+
async confirm(options) {
|
|
92
|
+
validateConfirmOptions(options);
|
|
93
|
+
return await NexusBridge.call("confirm", options);
|
|
94
|
+
}
|
|
70
95
|
}
|
|
71
96
|
const dialog = new NexusDialog();
|
|
72
97
|
|
|
98
|
+
function validatePayload(payload) {
|
|
99
|
+
if (!payload) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (Object.values(payload).some((value) => typeof value === "function")) {
|
|
103
|
+
throw new BridgeAPIError("Passing functions as part of the payload in invoke is not supported.");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
73
106
|
async function invoke(functionKey, payload) {
|
|
107
|
+
if (typeof functionKey !== "string") {
|
|
108
|
+
throw new BridgeAPIError('"functionKey" must be a string in invoke.');
|
|
109
|
+
}
|
|
110
|
+
validatePayload(payload);
|
|
74
111
|
const params = {
|
|
75
112
|
function: functionKey,
|
|
76
113
|
payload: payload,
|
|
@@ -82,12 +119,34 @@ async function invoke(functionKey, payload) {
|
|
|
82
119
|
|
|
83
120
|
class NexusRouter {
|
|
84
121
|
async navigate(urlOrLocation) {
|
|
85
|
-
|
|
122
|
+
if (typeof urlOrLocation === "string") {
|
|
123
|
+
await NexusBridge.call("routerNavigate", { urlOrLocation });
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
if (!urlOrLocation.target) {
|
|
127
|
+
const errorMessage = '"target" is required in router navigate.';
|
|
128
|
+
throw new BridgeAPIError(errorMessage);
|
|
129
|
+
}
|
|
130
|
+
await NexusBridge.call("routerNavigate", { urlOrLocation });
|
|
131
|
+
}
|
|
86
132
|
}
|
|
87
133
|
async open(urlOrLocation) {
|
|
88
|
-
|
|
134
|
+
if (typeof urlOrLocation === "string") {
|
|
135
|
+
await NexusBridge.call("routerOpen", { urlOrLocation });
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
if (!urlOrLocation.target) {
|
|
139
|
+
const errorMessage = '"target" is required in router open.';
|
|
140
|
+
throw new BridgeAPIError(errorMessage);
|
|
141
|
+
}
|
|
142
|
+
await NexusBridge.call("routerOpen", { urlOrLocation });
|
|
143
|
+
}
|
|
89
144
|
}
|
|
90
145
|
async generateUrl(location) {
|
|
146
|
+
if (!(location === null || location === void 0 ? void 0 : location.target)) {
|
|
147
|
+
const errorMessage = '"target" is required in router generateUrl.';
|
|
148
|
+
throw new BridgeAPIError(errorMessage);
|
|
149
|
+
}
|
|
91
150
|
return await NexusBridge.call("routerGenerateUrl", { location });
|
|
92
151
|
}
|
|
93
152
|
async reload() {
|
|
@@ -101,34 +160,57 @@ class NexusView {
|
|
|
101
160
|
return await NexusBridge.call("getContext");
|
|
102
161
|
}
|
|
103
162
|
async setWindowTitle(title) {
|
|
163
|
+
if (!title) {
|
|
164
|
+
throw new BridgeAPIError('"title" is required in view setWindowTitle.');
|
|
165
|
+
}
|
|
166
|
+
if (typeof title !== "string") {
|
|
167
|
+
throw new BridgeAPIError('"title" must be a string in view setWindowTitle.');
|
|
168
|
+
}
|
|
104
169
|
await NexusBridge.call("setWindowTitle", { title });
|
|
105
170
|
}
|
|
106
171
|
async reload() {
|
|
107
|
-
await NexusBridge.call("viewReload");
|
|
172
|
+
const success = await NexusBridge.call("viewReload");
|
|
173
|
+
if (success === false) {
|
|
174
|
+
throw new BridgeAPIError("this resource's view is not reloadable.");
|
|
175
|
+
}
|
|
108
176
|
}
|
|
109
|
-
async close() {
|
|
110
|
-
const
|
|
111
|
-
if (!
|
|
177
|
+
async close(payload) {
|
|
178
|
+
const success = await NexusBridge.call("viewClose", payload);
|
|
179
|
+
if (!success) {
|
|
112
180
|
const errorMessage = "this resource's view is not closable.";
|
|
113
181
|
throw new BridgeAPIError(errorMessage);
|
|
114
182
|
}
|
|
115
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* 非弹窗场景调用无效。
|
|
186
|
+
*/
|
|
116
187
|
async onClose(payload) {
|
|
117
|
-
|
|
188
|
+
if (typeof payload !== "function") {
|
|
189
|
+
const errorMessage = '"payload" must be a function in view onClose.';
|
|
190
|
+
throw new BridgeAPIError(errorMessage);
|
|
191
|
+
}
|
|
192
|
+
const success = await NexusBridge.call("viewOnClose", { payload });
|
|
193
|
+
if (!success) {
|
|
194
|
+
throw new BridgeAPIError("`onClose` failed because this resource's view is not closable.");
|
|
195
|
+
}
|
|
118
196
|
}
|
|
119
197
|
async isDialog() {
|
|
120
198
|
return await NexusBridge.call("viewIsDialog");
|
|
121
199
|
}
|
|
122
200
|
async createHistory() {
|
|
123
201
|
const history = await NexusBridge.call("createHistory");
|
|
124
|
-
history.listen((location, action) => {
|
|
202
|
+
await history.listen((location, action) => {
|
|
125
203
|
history.action = action;
|
|
126
204
|
history.location = location;
|
|
127
205
|
});
|
|
128
206
|
return history;
|
|
129
207
|
}
|
|
130
208
|
async submit(payload) {
|
|
131
|
-
await NexusBridge.call("viewSubmit", payload);
|
|
209
|
+
const result = await NexusBridge.call("viewSubmit", payload);
|
|
210
|
+
if (!result) {
|
|
211
|
+
throw new BridgeAPIError("this resource's view is not submittable.");
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
132
214
|
}
|
|
133
215
|
}
|
|
134
216
|
const view = new NexusView();
|
|
@@ -232,7 +314,30 @@ const containsSerialisedBlobs = (payload) => {
|
|
|
232
314
|
return false;
|
|
233
315
|
};
|
|
234
316
|
|
|
317
|
+
function validateOnPayload(eventName, callback) {
|
|
318
|
+
if (!eventName) {
|
|
319
|
+
throw new BridgeAPIError('"eventName" is required in events on.');
|
|
320
|
+
}
|
|
321
|
+
if (typeof eventName !== "string") {
|
|
322
|
+
throw new BridgeAPIError('"eventName" must be a string in events on.');
|
|
323
|
+
}
|
|
324
|
+
if (!callback) {
|
|
325
|
+
throw new BridgeAPIError('"callback" is required in events on.');
|
|
326
|
+
}
|
|
327
|
+
if (typeof callback !== "function") {
|
|
328
|
+
throw new BridgeAPIError('"callback" must be a function in events on.');
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function validateEmitPayload(eventName) {
|
|
332
|
+
if (!eventName) {
|
|
333
|
+
throw new BridgeAPIError('"eventName" is required in events emit.');
|
|
334
|
+
}
|
|
335
|
+
if (typeof eventName !== "string") {
|
|
336
|
+
throw new BridgeAPIError('"eventName" must be a string in events emit.');
|
|
337
|
+
}
|
|
338
|
+
}
|
|
235
339
|
async function on(eventName, callback) {
|
|
340
|
+
validateOnPayload(eventName, callback);
|
|
236
341
|
const wrappedCallback = (payload) => {
|
|
237
342
|
let newPayload = payload;
|
|
238
343
|
if (containsSerialisedBlobs(payload)) {
|
|
@@ -243,6 +348,7 @@ async function on(eventName, callback) {
|
|
|
243
348
|
return NexusBridge.call("on", { eventName, callback: wrappedCallback });
|
|
244
349
|
}
|
|
245
350
|
async function emit(eventName, payload) {
|
|
351
|
+
validateEmitPayload(eventName);
|
|
246
352
|
let newPayload = payload;
|
|
247
353
|
if (containsBlobs(payload)) {
|
|
248
354
|
newPayload = await serialiseBlobsInPayload(payload);
|
|
@@ -259,14 +365,24 @@ class NexusI18n {
|
|
|
259
365
|
i18nFolderName = "__LOCALES__";
|
|
260
366
|
async getTranslations(locale) {
|
|
261
367
|
if (!locale) {
|
|
262
|
-
locale = (await view.getContext()).locale;
|
|
368
|
+
locale = (await view.getContext()).user.locale;
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
if (!SUPPORTED_LOCALE_CODES.includes(locale)) {
|
|
372
|
+
throw new BridgeAPIError(`"locale" must be a valid locale code, supported codes: ${SUPPORTED_LOCALE_CODES.join(", ")}.`);
|
|
373
|
+
}
|
|
263
374
|
}
|
|
264
375
|
const translations = await this.loadTranslations(locale);
|
|
265
376
|
return { locale: locale, translations };
|
|
266
377
|
}
|
|
267
378
|
async createTranslator(locale) {
|
|
268
379
|
if (!locale) {
|
|
269
|
-
locale = (await view.getContext()).locale;
|
|
380
|
+
locale = (await view.getContext()).user.locale;
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
if (!SUPPORTED_LOCALE_CODES.includes(locale)) {
|
|
384
|
+
throw new BridgeAPIError(`"locale" must be a valid locale code, supported codes: ${SUPPORTED_LOCALE_CODES.join(", ")}.`);
|
|
385
|
+
}
|
|
270
386
|
}
|
|
271
387
|
const translations = await this.loadTranslations(locale);
|
|
272
388
|
return {
|
|
@@ -277,11 +393,11 @@ class NexusI18n {
|
|
|
277
393
|
const url = `../${this.i18nFolderName}/${locale}.json`;
|
|
278
394
|
if (!this.translationsCache[locale]) {
|
|
279
395
|
this.translationsCache[locale] = fetch(url)
|
|
280
|
-
.then((
|
|
281
|
-
.catch((
|
|
396
|
+
.then((response) => response.json())
|
|
397
|
+
.catch((error) => {
|
|
282
398
|
// 请求失败要清理缓存
|
|
283
399
|
delete this.translationsCache[locale];
|
|
284
|
-
throw
|
|
400
|
+
throw new BridgeAPIError(`Failed to load translations for locale ${locale}, cause: ${error}`);
|
|
285
401
|
});
|
|
286
402
|
}
|
|
287
403
|
return this.translationsCache[locale];
|
|
@@ -290,6 +406,9 @@ class NexusI18n {
|
|
|
290
406
|
return path.split(".").reduce((o, k) => (o != null && typeof o === "object" ? o[k] : undefined), obj);
|
|
291
407
|
}
|
|
292
408
|
translate(key, translations, params) {
|
|
409
|
+
if (!key) {
|
|
410
|
+
throw new BridgeAPIError('"key" is required in i18n translate.');
|
|
411
|
+
}
|
|
293
412
|
// 获取值(扁平或嵌套)
|
|
294
413
|
let value = translations[key] ?? this.getValue(translations, key);
|
|
295
414
|
// key 不存在 → 返回 key
|
|
@@ -339,13 +458,28 @@ async function parseToResponseData(res) {
|
|
|
339
458
|
return response;
|
|
340
459
|
}
|
|
341
460
|
|
|
461
|
+
const validateFetchOptions = (init) => {
|
|
462
|
+
if (!init) {
|
|
463
|
+
return init;
|
|
464
|
+
}
|
|
465
|
+
if ("signal" in init) {
|
|
466
|
+
const { signal: _signal, ...rest } = init;
|
|
467
|
+
console.error("Signal is not supported in @pc-nexus/bridge and was removed from fetch options.");
|
|
468
|
+
return rest;
|
|
469
|
+
}
|
|
470
|
+
return init;
|
|
471
|
+
};
|
|
342
472
|
async function callRequestBridge(handlerName, payload) {
|
|
343
473
|
const postPayload = await buildPayloadByRequestInit(payload);
|
|
344
474
|
const { status, headers, body } = await NexusBridge.call(handlerName, postPayload);
|
|
345
475
|
return parseToResponseData({ status, headers, body });
|
|
346
476
|
}
|
|
347
477
|
async function requestApi(path, options) {
|
|
348
|
-
|
|
478
|
+
if (typeof path !== "string") {
|
|
479
|
+
throw new BridgeAPIError('"path" must be a string in requestApi.');
|
|
480
|
+
}
|
|
481
|
+
const validatedOptions = validateFetchOptions(options);
|
|
482
|
+
return callRequestBridge("requestApi", { path, ...validatedOptions });
|
|
349
483
|
}
|
|
350
484
|
|
|
351
485
|
/**
|
|
@@ -1 +1 @@
|
|
|
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;AACd,IAAA,MAAM,MAAM,GAAG,mBAAmB,CAAe,qBAAqB,CAAC;AACvE,IAAA,OAAO,MAAM;AACjB;MAEa,WAAW,CAAA;AACpB,IAAA,OAAO,aAAa,GAAA;AAChB,QAAA,IAAI,CAAC,SAAS,EAAE,EAAE;YACd,MAAM,IAAI,KAAK,CAAC;;;AAGnB,QAAA,CAAA,CAAC;QACF;AACA,QAAA,O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AAG,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;;;;"}
|
|
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 { NexusBridge } from \"./bridge\";\nimport { BridgeAPIError } from \"./error\";\nimport { DialogConfirmOptions, DialogOptions, DialogRef } from \"./models\";\n\nfunction validateOpenOptions(options: DialogOptions) {\n if (typeof options !== \"object\" || options === null) {\n throw new BridgeAPIError('\"options\" must be an object in dialog open.');\n }\n if (!options.resource) {\n throw new BridgeAPIError('\"resource\" is required in dialog open options.');\n }\n}\n\nfunction validateConfirmOptions(options: DialogConfirmOptions) {\n if (typeof options !== \"object\" || options === null) {\n throw new BridgeAPIError('\"options\" must be an object in dialog confirm.');\n }\n if (!options.content) {\n throw new BridgeAPIError('\"content\" is required in dialog confirm options.');\n }\n if (typeof options.onConfirm !== \"function\") {\n throw new BridgeAPIError('\"onConfirm\" must be a function in dialog confirm options.');\n }\n}\n\nclass NexusDialog {\n async open<T>(options: DialogOptions): Promise<DialogRef<T>> {\n validateOpenOptions(options);\n return await NexusBridge.call<DialogRef<T>>(\"openDialog\", options);\n }\n\n async confirm<T>(options: DialogConfirmOptions): Promise<void> {\n validateConfirmOptions(options);\n return await NexusBridge.call<void>(\"confirm\", options);\n }\n}\n\nexport const dialog = new NexusDialog();\n","import { NexusBridge } from \"./bridge\";\nimport { BridgeAPIError } from \"./error\";\nimport { InvokeFunctionParams } from \"./models\";\nimport { getObjectFromWindow } from \"./window\";\n\nfunction validatePayload<TPayload>(payload?: TPayload) {\n if (!payload) {\n return;\n }\n if (Object.values(payload).some((value) => typeof value === \"function\")) {\n throw new BridgeAPIError(\"Passing functions as part of the payload in invoke is not supported.\");\n }\n}\n\nexport async function invoke<TPayload = any, TResult = any>(functionKey: string, payload?: TPayload): Promise<TResult> {\n if (typeof functionKey !== \"string\") {\n throw new BridgeAPIError('\"functionKey\" must be a string in invoke.');\n }\n validatePayload(payload);\n\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 { BridgeAPIError } from \"./error\";\nimport { NavigationLocation } from \"./models\";\n\nclass NexusRouter {\n async navigate(urlOrLocation: string | NavigationLocation): Promise<void> {\n if (typeof urlOrLocation === \"string\") {\n await NexusBridge.call<void>(\"routerNavigate\", { urlOrLocation });\n } else {\n if (!urlOrLocation.target) {\n const errorMessage = '\"target\" is required in router navigate.';\n throw new BridgeAPIError(errorMessage);\n }\n await NexusBridge.call<void>(\"routerNavigate\", { urlOrLocation });\n }\n }\n\n async open(urlOrLocation: string | NavigationLocation): Promise<void> {\n if (typeof urlOrLocation === \"string\") {\n await NexusBridge.call<void>(\"routerOpen\", { urlOrLocation });\n } else {\n if (!urlOrLocation.target) {\n const errorMessage = '\"target\" is required in router open.';\n throw new BridgeAPIError(errorMessage);\n }\n await NexusBridge.call<void>(\"routerOpen\", { urlOrLocation });\n }\n }\n\n async generateUrl(location: NavigationLocation): Promise<URL> {\n if (!(location === null || location === void 0 ? void 0 : location.target)) {\n const errorMessage = '\"target\" is required in router generateUrl.';\n throw new BridgeAPIError(errorMessage);\n }\n return await NexusBridge.call<URL>(\"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 { BridgeAPIError } from \"./error\";\nimport { ExtensionData, NexusFullContext, NexusHistory } from \"./models\";\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 if (!title) {\n throw new BridgeAPIError('\"title\" is required in view setWindowTitle.');\n }\n if (typeof title !== \"string\") {\n throw new BridgeAPIError('\"title\" must be a string in view setWindowTitle.');\n }\n\n await NexusBridge.call<void>(\"setWindowTitle\", { title });\n }\n\n async reload(): Promise<void> {\n const success = await NexusBridge.call<boolean>(\"viewReload\");\n if (success === false) {\n throw new BridgeAPIError(\"this resource's view is not reloadable.\");\n }\n }\n\n async close(payload?: unknown): Promise<void> {\n const success = await NexusBridge.call<boolean>(\"viewClose\", payload);\n if (!success) {\n const errorMessage = \"this resource's view is not closable.\";\n throw new BridgeAPIError(errorMessage);\n }\n }\n\n /**\n * 非弹窗场景调用无效。\n */\n async onClose(payload: () => Promise<void>): Promise<void> {\n if (typeof payload !== \"function\") {\n const errorMessage = '\"payload\" must be a function in view onClose.';\n throw new BridgeAPIError(errorMessage);\n }\n const success = await NexusBridge.call<boolean>(\"viewOnClose\", { payload });\n if (!success) {\n throw new BridgeAPIError(\"`onClose` failed because this resource's view is not closable.\");\n }\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 await 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<boolean> {\n const result = await NexusBridge.call<boolean>(\"viewSubmit\", payload);\n if (!result) {\n throw new BridgeAPIError(\"this resource's view is not submittable.\");\n }\n return result;\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 { BridgeAPIError } from \"./error\";\nimport { Subscription } from \"./models\";\nimport { containsBlobs, serialiseBlobsInPayload, containsSerialisedBlobs, deserialiseBlobsInPayload } from \"./utils\";\n\nfunction validateOnPayload<T>(eventName: string, callback: (payload?: T) => any) {\n if (!eventName) {\n throw new BridgeAPIError('\"eventName\" is required in events on.');\n }\n if (typeof eventName !== \"string\") {\n throw new BridgeAPIError('\"eventName\" must be a string in events on.');\n }\n if (!callback) {\n throw new BridgeAPIError('\"callback\" is required in events on.');\n }\n if (typeof callback !== \"function\") {\n throw new BridgeAPIError('\"callback\" must be a function in events on.');\n }\n}\n\nfunction validateEmitPayload<T>(eventName: string) {\n if (!eventName) {\n throw new BridgeAPIError('\"eventName\" is required in events emit.');\n }\n if (typeof eventName !== \"string\") {\n throw new BridgeAPIError('\"eventName\" must be a string in events emit.');\n }\n}\n\nasync function on<T = any>(eventName: string, callback: (payload?: T) => any): Promise<Subscription> {\n validateOnPayload<T>(eventName, callback);\n\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 validateEmitPayload<T>(eventName);\n\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, SUPPORTED_LOCALE_CODES } from \"./models\";\nimport { view } from \"./view\";\nimport { BridgeAPIError } from \"./error\";\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()).user.locale;\n } else {\n if (!SUPPORTED_LOCALE_CODES.includes(locale)) {\n throw new BridgeAPIError(`\"locale\" must be a valid locale code, supported codes: ${SUPPORTED_LOCALE_CODES.join(\", \")}.`);\n }\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()).user.locale;\n } else {\n if (!SUPPORTED_LOCALE_CODES.includes(locale)) {\n throw new BridgeAPIError(`\"locale\" must be a valid locale code, supported codes: ${SUPPORTED_LOCALE_CODES.join(\", \")}.`);\n }\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((response) => response.json())\n .catch((error) => {\n // 请求失败要清理缓存\n delete this.translationsCache[locale];\n throw new BridgeAPIError(`Failed to load translations for locale ${locale}, cause: ${error}`);\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 if (!key) {\n throw new BridgeAPIError('\"key\" is required in i18n translate.');\n }\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 { BridgeAPIError } from \"./error\";\nimport { NexusRequestInit, RequestApiResponseData } from \"./models\";\nimport { buildPayloadByRequestInit, parseToResponseData } from \"./utils/request\";\n\ninterface RequestApiParams extends NexusRequestInit {\n path: string;\n}\n\nconst validateFetchOptions = (init?: NexusRequestInit) => {\n if (!init) {\n return init;\n }\n if (\"signal\" in init) {\n const { signal: _signal, ...rest } = init;\n console.error(\"Signal is not supported in @pc-nexus/bridge and was removed from fetch options.\");\n return rest;\n }\n return init;\n};\n\nasync function callRequestBridge<TPayload extends NexusRequestInit = NexusRequestInit>(\n handlerName: string,\n payload: TPayload,\n): 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?: NexusRequestInit): Promise<Response> {\n if (typeof path !== \"string\") {\n throw new BridgeAPIError('\"path\" must be a string in requestApi.');\n }\n\n const validatedOptions = validateFetchOptions(options);\n return callRequestBridge<RequestApiParams>(\"requestApi\", { path, ...validatedOptions });\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;AACd,IAAA,MAAM,MAAM,GAAG,mBAAmB,CAAe,qBAAqB,CAAC;AACvE,IAAA,OAAO,MAAM;AACjB;MAEa,WAAW,CAAA;AACpB,IAAA,OAAO,aAAa,GAAA;AAChB,QAAA,IAAI,CAAC,SAAS,EAAE,EAAE;YACd,MAAM,IAAI,KAAK,CAAC;;;AAGnB,QAAA,CAAA,CAAC;QACF;AACA,QAAA,OAAO,SAAS,EAAE,CAAC,IAAI;IAC3B;AAEA,IAAA,aAAa,IAAI,CAAI,IAAY,EAAE,OAAa,EAAA;AAC5C,QAAA,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,aAAa,EAAK,CAAC,IAAI,EAAE,OAAO,CAAC;AAClE,QAAA,OAAO,MAAW;IACtB;AAEA;;;;;AAKG;AACH,IAAA,OAAO,EAAE,CAAI,IAAY,EAAE,OAA6C,EAAA;AACpE,QAAA,MAAM,MAAM,GAAG,SAAS,EAAE;QAC1B,IAAI,CAAC,MAAM,EAAE;YACT,MAAM,IAAI,KAAK,CAAC;;;AAGnB,QAAA,CAAA,CAAC;QACF;QACA,OAAO,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC;IACnC;AACH;;ACtDK,MAAO,cAAe,SAAQ,KAAK,CAAA;AACrC,IAAA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|
-
},
|
|
9
5
|
"sideEffects": false,
|
|
10
6
|
"module": "fesm2022/pc-nexus-bridge.mjs",
|
|
11
7
|
"typings": "types/pc-nexus-bridge.d.ts",
|
|
@@ -17,5 +13,9 @@
|
|
|
17
13
|
"types": "./types/pc-nexus-bridge.d.ts",
|
|
18
14
|
"default": "./fesm2022/pc-nexus-bridge.mjs"
|
|
19
15
|
}
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"tslib": "^2.3.0"
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
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';
|
|
1
|
+
import { DialogOptions, DialogRef, DialogConfirmOptions, NavigationLocation, ExtensionData, NexusFullContext, NexusHistory, Subscription, NexusSupportedLocaleCode, GetTranslationsResult, Translator, NexusRequestInit } from '@pc-nexus/models';
|
|
2
|
+
export { DialogConfirmOptions, DialogOptions, DialogRef, ExtensionData, GetTranslationsResult, HistoryAction, LocationDescriptor, NavigationLocation, NavigationTarget, NexusFullContext, NexusHistory, NexusRequestInit, NexusSupportedLocaleCode, Subscription, TranslationResourceContent, Translator, UnlistenCallback, ViewportSize } from '@pc-nexus/models';
|
|
3
3
|
|
|
4
4
|
interface HostMessageEvent<T = unknown> {
|
|
5
5
|
source: Window | null;
|
|
@@ -27,6 +27,7 @@ declare class BridgeAPIError extends Error {
|
|
|
27
27
|
|
|
28
28
|
declare class NexusDialog {
|
|
29
29
|
open<T>(options: DialogOptions): Promise<DialogRef<T>>;
|
|
30
|
+
confirm<T>(options: DialogConfirmOptions): Promise<void>;
|
|
30
31
|
}
|
|
31
32
|
declare const dialog: NexusDialog;
|
|
32
33
|
|
|
@@ -35,7 +36,7 @@ declare function invoke<TPayload = any, TResult = any>(functionKey: string, payl
|
|
|
35
36
|
declare class NexusRouter {
|
|
36
37
|
navigate(urlOrLocation: string | NavigationLocation): Promise<void>;
|
|
37
38
|
open(urlOrLocation: string | NavigationLocation): Promise<void>;
|
|
38
|
-
generateUrl(location: NavigationLocation): Promise<
|
|
39
|
+
generateUrl(location: NavigationLocation): Promise<URL>;
|
|
39
40
|
reload(): Promise<void>;
|
|
40
41
|
}
|
|
41
42
|
declare const router: NexusRouter;
|
|
@@ -44,16 +45,19 @@ declare class NexusView {
|
|
|
44
45
|
getContext<T = ExtensionData>(): Promise<NexusFullContext<T>>;
|
|
45
46
|
setWindowTitle(title: string): Promise<void>;
|
|
46
47
|
reload(): Promise<void>;
|
|
47
|
-
close(): Promise<void>;
|
|
48
|
+
close(payload?: unknown): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* 非弹窗场景调用无效。
|
|
51
|
+
*/
|
|
48
52
|
onClose(payload: () => Promise<void>): Promise<void>;
|
|
49
53
|
isDialog(): Promise<boolean>;
|
|
50
54
|
createHistory(): Promise<NexusHistory>;
|
|
51
|
-
submit<T = any>(payload?: T): Promise<
|
|
55
|
+
submit<T = any>(payload?: T): Promise<boolean>;
|
|
52
56
|
}
|
|
53
57
|
declare const view: NexusView;
|
|
54
58
|
|
|
55
59
|
declare function on<T = any>(eventName: string, callback: (payload?: T) => any): Promise<Subscription>;
|
|
56
|
-
declare function emit<T = any>(eventName: string, payload
|
|
60
|
+
declare function emit<T = any>(eventName: string, payload?: T): Promise<void>;
|
|
57
61
|
declare const events: {
|
|
58
62
|
on: typeof on;
|
|
59
63
|
emit: typeof emit;
|
|
@@ -70,6 +74,6 @@ declare class NexusI18n {
|
|
|
70
74
|
}
|
|
71
75
|
declare const i18n: NexusI18n;
|
|
72
76
|
|
|
73
|
-
declare function requestApi(path: string, options?:
|
|
77
|
+
declare function requestApi(path: string, options?: NexusRequestInit): Promise<Response>;
|
|
74
78
|
|
|
75
79
|
export { dialog, events, i18n, invoke, requestApi, router, view, BridgeAPIError as ɵBridgeAPIError, NexusBridge as ɵNexusBridge };
|