@pc-nexus/bridge 0.0.1-next.1 → 0.0.1-next.2
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;
|
|
@@ -45,9 +45,7 @@ class NexusBridge {
|
|
|
45
45
|
|
|
46
46
|
class NexusDialog {
|
|
47
47
|
async open(options) {
|
|
48
|
-
return
|
|
49
|
-
console.error("nexus open dialog failed", error);
|
|
50
|
-
}));
|
|
48
|
+
return await NexusBridge.call("openDialog", options);
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
51
|
const dialog = new NexusDialog();
|
|
@@ -91,6 +89,12 @@ class NexusView {
|
|
|
91
89
|
async close() {
|
|
92
90
|
await NexusBridge.call("viewClose");
|
|
93
91
|
}
|
|
92
|
+
async onClose(payload) {
|
|
93
|
+
await NexusBridge.call("viewOnClose", { payload });
|
|
94
|
+
}
|
|
95
|
+
async isDialog() {
|
|
96
|
+
return await NexusBridge.call("viewIsDialog");
|
|
97
|
+
}
|
|
94
98
|
async createHistory() {
|
|
95
99
|
const history = await NexusBridge.call("createHistory");
|
|
96
100
|
history.listen((location, action) => {
|
|
@@ -99,22 +103,25 @@ class NexusView {
|
|
|
99
103
|
});
|
|
100
104
|
return history;
|
|
101
105
|
}
|
|
106
|
+
async submit(payload) {
|
|
107
|
+
await NexusBridge.call("viewSubmit", payload);
|
|
108
|
+
}
|
|
102
109
|
}
|
|
103
110
|
const view = new NexusView();
|
|
104
111
|
|
|
105
112
|
const isPlainObject = (value) => {
|
|
106
|
-
if (typeof value !==
|
|
113
|
+
if (typeof value !== "object" || value === null) {
|
|
107
114
|
return false;
|
|
108
115
|
}
|
|
109
|
-
if (Object.prototype.toString.call(value) !==
|
|
116
|
+
if (Object.prototype.toString.call(value) !== "[object Object]") {
|
|
110
117
|
return false;
|
|
111
118
|
}
|
|
112
119
|
const proto = Object.getPrototypeOf(value);
|
|
113
120
|
if (proto === null) {
|
|
114
121
|
return true;
|
|
115
122
|
}
|
|
116
|
-
const constructor = Object.prototype.hasOwnProperty.call(proto,
|
|
117
|
-
return (typeof constructor ===
|
|
123
|
+
const constructor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
124
|
+
return (typeof constructor === "function" &&
|
|
118
125
|
constructor instanceof constructor &&
|
|
119
126
|
Function.prototype.call(constructor) === Function.prototype.call(value));
|
|
120
127
|
};
|
|
@@ -122,7 +129,7 @@ const base64ToBlob = (b64string, mimeType) => {
|
|
|
122
129
|
if (!b64string) {
|
|
123
130
|
return null;
|
|
124
131
|
}
|
|
125
|
-
const base64String = b64string.includes(
|
|
132
|
+
const base64String = b64string.includes(",") ? b64string.split(",")[1] : b64string;
|
|
126
133
|
const byteCharacters = atob(base64String);
|
|
127
134
|
const byteNumbers = new Array(byteCharacters.length);
|
|
128
135
|
for (let i = 0; i < byteCharacters.length; i++) {
|
|
@@ -147,7 +154,7 @@ const serialiseBlobsInPayload = async (payload) => {
|
|
|
147
154
|
return {
|
|
148
155
|
data: base64Data,
|
|
149
156
|
type: payload.type,
|
|
150
|
-
__isBlobData: true
|
|
157
|
+
__isBlobData: true,
|
|
151
158
|
};
|
|
152
159
|
}
|
|
153
160
|
if (Array.isArray(payload)) {
|
|
@@ -160,7 +167,7 @@ const serialiseBlobsInPayload = async (payload) => {
|
|
|
160
167
|
return payload;
|
|
161
168
|
};
|
|
162
169
|
const deserialiseBlobsInPayload = (payload) => {
|
|
163
|
-
if (payload && isPlainObject(payload) &&
|
|
170
|
+
if (payload && isPlainObject(payload) && "__isBlobData" in payload) {
|
|
164
171
|
const typedData = payload;
|
|
165
172
|
return base64ToBlob(typedData.data, typedData.type);
|
|
166
173
|
}
|
|
@@ -181,7 +188,7 @@ const containsBlobs = (payload) => {
|
|
|
181
188
|
return true;
|
|
182
189
|
}
|
|
183
190
|
if (Array.isArray(payload)) {
|
|
184
|
-
return payload.some(item => containsBlobs(item));
|
|
191
|
+
return payload.some((item) => containsBlobs(item));
|
|
185
192
|
}
|
|
186
193
|
if (payload && isPlainObject(payload)) {
|
|
187
194
|
return Object.values(payload).some((value) => containsBlobs(value));
|
|
@@ -189,7 +196,7 @@ const containsBlobs = (payload) => {
|
|
|
189
196
|
return false;
|
|
190
197
|
};
|
|
191
198
|
const containsSerialisedBlobs = (payload) => {
|
|
192
|
-
if (payload && isPlainObject(payload) &&
|
|
199
|
+
if (payload && isPlainObject(payload) && "__isBlobData" in payload) {
|
|
193
200
|
return true;
|
|
194
201
|
}
|
|
195
202
|
if (Array.isArray(payload)) {
|
|
@@ -209,18 +216,18 @@ async function on(eventName, callback) {
|
|
|
209
216
|
}
|
|
210
217
|
return callback(newPayload);
|
|
211
218
|
};
|
|
212
|
-
return NexusBridge.call(
|
|
219
|
+
return NexusBridge.call("on", { eventName, callback: wrappedCallback });
|
|
213
220
|
}
|
|
214
221
|
async function emit(eventName, payload) {
|
|
215
222
|
let newPayload = payload;
|
|
216
223
|
if (containsBlobs(payload)) {
|
|
217
224
|
newPayload = await serialiseBlobsInPayload(payload);
|
|
218
225
|
}
|
|
219
|
-
return NexusBridge.call(
|
|
226
|
+
return NexusBridge.call("emit", { eventName, payload: newPayload });
|
|
220
227
|
}
|
|
221
228
|
const events = {
|
|
222
229
|
on,
|
|
223
|
-
emit
|
|
230
|
+
emit,
|
|
224
231
|
};
|
|
225
232
|
|
|
226
233
|
class NexusI18n {
|
|
@@ -231,7 +238,7 @@ class NexusI18n {
|
|
|
231
238
|
locale = (await view.getContext()).locale;
|
|
232
239
|
}
|
|
233
240
|
const translations = await this.loadTranslations(locale);
|
|
234
|
-
return { locale, translations };
|
|
241
|
+
return { locale: locale, translations };
|
|
235
242
|
}
|
|
236
243
|
async createTranslator(locale) {
|
|
237
244
|
if (!locale) {
|
|
@@ -256,13 +263,44 @@ class NexusI18n {
|
|
|
256
263
|
}
|
|
257
264
|
const i18n = new NexusI18n();
|
|
258
265
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
266
|
+
async function buildPayloadByRequestInit(init) {
|
|
267
|
+
const requestBody = init === null || init === void 0 ? void 0 : init.body;
|
|
268
|
+
const requestMethod = init === null || init === void 0 ? void 0 : init.method;
|
|
269
|
+
const requestHeaders = init === null || init === void 0 ? void 0 : init.headers;
|
|
270
|
+
const req = new Request("", {
|
|
271
|
+
body: requestBody,
|
|
272
|
+
method: requestMethod,
|
|
273
|
+
headers: requestHeaders,
|
|
274
|
+
});
|
|
275
|
+
const headers = Object.fromEntries(req.headers.entries());
|
|
276
|
+
const body = req.method !== "GET" ? await req.text() : undefined;
|
|
277
|
+
return {
|
|
278
|
+
...init,
|
|
279
|
+
body: body,
|
|
280
|
+
headers,
|
|
281
|
+
method: requestMethod ?? "GET",
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
async function parseToResponseData(res) {
|
|
285
|
+
const response = new Response(res.body == null ? undefined : typeof res.body === "object" ? JSON.stringify(res.body) : res.body, {
|
|
286
|
+
status: res.status,
|
|
287
|
+
headers: new Headers(res.headers),
|
|
288
|
+
});
|
|
289
|
+
return response;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async function callRequestBridge(handlerName, payload) {
|
|
293
|
+
const postPayload = await buildPayloadByRequestInit(payload);
|
|
294
|
+
const { status, headers, body } = await NexusBridge.call(handlerName, postPayload);
|
|
295
|
+
return parseToResponseData({ status, headers, body });
|
|
296
|
+
}
|
|
297
|
+
async function requestApi(path, options) {
|
|
298
|
+
return callRequestBridge("requestApi", { path, ...options });
|
|
299
|
+
}
|
|
262
300
|
|
|
263
301
|
/**
|
|
264
302
|
* Generated bundle index. Do not edit.
|
|
265
303
|
*/
|
|
266
304
|
|
|
267
|
-
export {
|
|
305
|
+
export { dialog, events, i18n, invoke, requestApi, router, view, NexusBridge as ɵNexusBridge };
|
|
268
306
|
//# 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,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,OAA4B,EAAA;AAC3D,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;;ACnDD,MAAM,WAAW,CAAA;IACb,MAAM,IAAI,CAAI,OAAsB,EAAA;AAChC,QAAA,QAA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AAI,CAAC,UAAU,EAAE,EAAE,MAAM;QAC7C;QACA,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;AACxD,QAAA,OAAO,MAAM,WAAW,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IAC/E;AAEQ,IAAA,gBAAgB,CAAC,MAAgC,EAAA;QACrD,MAAM,GAAG,GAAG,CAAA,GAAA,EAAM,IAAI,CAAC,cAAc,CAAA,CAAA,EAAI,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/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","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 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, 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 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 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\";\nimport { NexusBridge } from \"./bridge\";\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 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","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,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;;ACnDD,MAAM,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AC/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.2",
|
|
4
4
|
"peerDependencies": {},
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@pc-nexus/models": "
|
|
6
|
+
"@pc-nexus/models": "0.0.1-next.2",
|
|
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 消息名称
|
|
@@ -36,32 +36,15 @@ declare class NexusRouter {
|
|
|
36
36
|
}
|
|
37
37
|
declare const router: NexusRouter;
|
|
38
38
|
|
|
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
39
|
declare class NexusView {
|
|
60
40
|
getContext<T = ExtensionData>(): Promise<NexusFullContext<T>>;
|
|
61
41
|
setWindowTitle(title: string): Promise<void>;
|
|
62
42
|
reload(): Promise<void>;
|
|
63
43
|
close(): Promise<void>;
|
|
44
|
+
onClose(payload: () => Promise<void>): Promise<void>;
|
|
45
|
+
isDialog(): Promise<boolean>;
|
|
64
46
|
createHistory(): Promise<NexusHistory>;
|
|
47
|
+
submit<T = any>(payload?: T): Promise<void>;
|
|
65
48
|
}
|
|
66
49
|
declare const view: NexusView;
|
|
67
50
|
|
|
@@ -81,5 +64,6 @@ declare class NexusI18n {
|
|
|
81
64
|
}
|
|
82
65
|
declare const i18n: NexusI18n;
|
|
83
66
|
|
|
84
|
-
|
|
85
|
-
|
|
67
|
+
declare function requestApi(path: string, options?: RequestInit): Promise<Response>;
|
|
68
|
+
|
|
69
|
+
export { dialog, events, i18n, invoke, requestApi, router, view, NexusBridge as ɵNexusBridge };
|