@openfin/core 26.70.3 → 27.70.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/OpenFin.d.ts CHANGED
@@ -874,7 +874,56 @@ declare namespace OpenFin {
874
874
  payload: import('./src/api/events/window').WindowOptionsChangedEvent<'window', 'options-changed'>
875
875
  ): Promise<OpenFin.HostContextChangedPayload | undefined>;
876
876
 
877
+ /**
878
+ * Closes a Window.
879
+ * By default it will fire any before unload handler set by a View in the Window.
880
+ * This can be disabled by setting skipBeforeUnload in the options object of the payload.
881
+ * This method is called by {@link Platform#closeWindow Platform.closeWindow}.
882
+ * @param {CloseWindowPayload} payload Object that contains the Window Identity and related options.
883
+ * @param {Identity} callerIdentity
884
+ * @returns {Promise<void>}
885
+ */
877
886
  closeWindow(payload: CloseWindowPayload, callerIdentity: Identity): Promise<void>;
887
+
888
+ /**
889
+ * Gets all the Views attached to a Window that should close along with it. This is meant to be overridable
890
+ * in the case where you want to return other Views that may not be attached to the Window that is closing.
891
+ * @param winId Identity of the Window that is closing
892
+ * @returns { Promise<View> }
893
+ */
894
+ getViewsForWindowClose(windowId: OpenFin.Identity): Promise<OpenFin.View[]>;
895
+
896
+ /**
897
+ * It takes in an array of Views and returns an object specifying which of them are trying to prevent an unload and which are not.
898
+ * @param {View[]} views Array of Views
899
+ * @returns { Promise<ViewStatuses> }
900
+ */
901
+ checkViewsForPreventUnload(views: OpenFin.View[]): Promise<OpenFin.ViewStatuses>;
902
+
903
+ /**
904
+ * Handle the decision of whether a Window or specific View should close when trying to prevent an unload. This is meant to be overridden.
905
+ * Called in {@link PlatformProvider#closeWindow PlatformProvider.closeWindow}.
906
+ * Normally you would use this method to show a dialog indicating that there are Views that are trying to prevent an unload.
907
+ * By default it will always return all Views passed into it as meaning to close.
908
+ * @param {ViewsPreventingUnloadPayload} payload
909
+ * @tutorial PlatformProvider.getUserDecisionForBeforeUnload
910
+ * @returns {Promise<BeforeUnloadUserDecision>}
911
+ */
912
+ getUserDecisionForBeforeUnload(
913
+ payload: OpenFin.ViewsPreventingUnloadPayload
914
+ ): Promise<OpenFin.BeforeUnloadUserDecision>;
915
+
916
+ /**
917
+ * Handles the closing of a Window and/or its Views. Called in {@link PlatformProvider#closeWindow PlatformProvider.closeWindow}.
918
+ * The return of {@link PlatformProvider#getUserDecisionForBeforeUnload PlatformProvider.getUserDecisionForBeforeUnload} is passed into this method.
919
+ * @param {Identity} winId Identity of the Window
920
+ * @param {BeforeUnloadUserDecision} userDecision Decision object
921
+ * @returns {Promise<void>}
922
+ */
923
+ handleViewsAndWindowClose(
924
+ windowId: OpenFin.Identity,
925
+ userDecision: OpenFin.BeforeUnloadUserDecision
926
+ ): Promise<void>;
878
927
  };
879
928
 
880
929
  export type InitPlatformOptions = {
@@ -1572,8 +1621,9 @@ declare namespace OpenFin {
1572
1621
 
1573
1622
  export type PopupBlurBehavior = 'modal' | PopupBaseBehavior;
1574
1623
 
1624
+ type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
1575
1625
  export interface PopupOptions {
1576
- initialOptions?: OpenFin.WindowCreationOptions;
1626
+ initialOptions?: Optional<OpenFin.WindowCreationOptions, 'name'>;
1577
1627
  additionalOptions?: OpenFin.UpdatableWindowOptions;
1578
1628
  name?: string;
1579
1629
  url?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfin/core",
3
- "version": "26.70.3",
3
+ "version": "27.70.3",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./src/mock.js",
6
6
  "types": "./src/mock.d.ts",
@@ -119,6 +119,15 @@ export declare class Platform extends EmitterBase<PlatformEvents> {
119
119
  * @experimental
120
120
  */
121
121
  getWindowContext(target?: OpenFin.Identity): Promise<any>;
122
+ /**
123
+ * Closes a window. If enableBeforeUnload is enabled in the Platform options, any beforeunload handler set on Views will fire
124
+ * This behavior can be disabled by setting skipBeforeUnload to false in the options parameter.
125
+ * @param {Identity} winId
126
+ * @param {closeWindowoptions} [options]
127
+ * @returns {Promise<void>}
128
+ * @tutorial Platform.closeWindow
129
+ * @experimental
130
+ */
122
131
  closeWindow(windowId: OpenFin.Identity, options?: {
123
132
  skipBeforeUnload: boolean;
124
133
  }): Promise<void>;
@@ -293,6 +293,15 @@ class Platform extends base_1.EmitterBase {
293
293
  entityType
294
294
  });
295
295
  }
296
+ /**
297
+ * Closes a window. If enableBeforeUnload is enabled in the Platform options, any beforeunload handler set on Views will fire
298
+ * This behavior can be disabled by setting skipBeforeUnload to false in the options parameter.
299
+ * @param {Identity} winId
300
+ * @param {closeWindowoptions} [options]
301
+ * @returns {Promise<void>}
302
+ * @tutorial Platform.closeWindow
303
+ * @experimental
304
+ */
296
305
  async closeWindow(windowId, options = { skipBeforeUnload: false }) {
297
306
  this.wire.sendAction('platform-close-window', this.identity).catch((e) => {
298
307
  // don't expose
@@ -303,6 +303,15 @@ export declare class View extends WebContents<ViewEvents> {
303
303
  * @return {Promise.<void>}
304
304
  * @tutorial View.inspectServiceWorker
305
305
  */
306
+ /**
307
+ * Shows a popup window. If the window this view is currently attached to has a popup open, closes it.
308
+ * @function showPopupWindow
309
+ * @memberOf View
310
+ * @instance
311
+ * @param {PopupOptions} options
312
+ * @return {Promise<PopupResult>}
313
+ * @tutorial View.showPopupWindow
314
+ */
306
315
  /**
307
316
  * Attaches the current view to a the given window identity.
308
317
  * Identity must be the identity of a window in the same application.
@@ -384,5 +393,12 @@ export declare class View extends WebContents<ViewEvents> {
384
393
  * @experimental
385
394
  */
386
395
  getCurrentWindow: () => Promise<OpenFin.Window>;
396
+ /**
397
+ * Triggers the before-unload handler for the View, if one is set. Returns `true` if the handler is trying to prevent the View from unloading, and `false` if it isn't.
398
+ * Only enabled when setting enableBeforeUnload: true in your View options. If this option is not enabled it will always return false.
399
+ * @returns {Promise<boolean>}
400
+ * @tutorial View.triggerBeforeUnload
401
+ * @experimental
402
+ */
387
403
  triggerBeforeUnload: () => Promise<boolean>;
388
404
  }
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.View = void 0;
4
4
  /* eslint-disable import/prefer-default-export */
5
+ /* eslint-disable consistent-return */
6
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
5
7
  const main_1 = require("../webcontents/main");
6
8
  const window_1 = require("../window");
7
9
  /**
@@ -273,6 +275,15 @@ class View extends main_1.WebContents {
273
275
  * @return {Promise.<void>}
274
276
  * @tutorial View.inspectServiceWorker
275
277
  */
278
+ /**
279
+ * Shows a popup window. If the window this view is currently attached to has a popup open, closes it.
280
+ * @function showPopupWindow
281
+ * @memberOf View
282
+ * @instance
283
+ * @param {PopupOptions} options
284
+ * @return {Promise<PopupResult>}
285
+ * @tutorial View.showPopupWindow
286
+ */
276
287
  /**
277
288
  * Attaches the current view to a the given window identity.
278
289
  * Identity must be the identity of a window in the same application.
@@ -349,7 +360,7 @@ class View extends main_1.WebContents {
349
360
  * @experimental
350
361
  */
351
362
  this.getParentLayout = async () => {
352
- this.wire.sendAction('view-get-parent-layout', { ...this.identity }).catch((e) => {
363
+ this.wire.sendAction('view-get-parent-layout', { ...this.identity }).catch(() => {
353
364
  // don't expose
354
365
  });
355
366
  const currentWindow = await this.getCurrentWindow();
@@ -383,6 +394,13 @@ class View extends main_1.WebContents {
383
394
  const { payload: { data } } = await this.wire.sendAction('get-view-window', { ...this.identity });
384
395
  return new window_1._Window(this.wire, data);
385
396
  };
397
+ /**
398
+ * Triggers the before-unload handler for the View, if one is set. Returns `true` if the handler is trying to prevent the View from unloading, and `false` if it isn't.
399
+ * Only enabled when setting enableBeforeUnload: true in your View options. If this option is not enabled it will always return false.
400
+ * @returns {Promise<boolean>}
401
+ * @tutorial View.triggerBeforeUnload
402
+ * @experimental
403
+ */
386
404
  this.triggerBeforeUnload = async () => {
387
405
  const message = await this.wire.sendAction('trigger-before-unload', { ...this.identity });
388
406
  return message.payload.data;
@@ -32,5 +32,6 @@ export declare class WebContents<T extends WebContentsEventMapping> extends Emit
32
32
  inspectSharedWorker(): Promise<void>;
33
33
  inspectSharedWorkerById(workerId: string): Promise<void>;
34
34
  inspectServiceWorker(): Promise<void>;
35
+ showPopupWindow(options: OpenFin.PopupOptions): Promise<OpenFin.PopupResult>;
35
36
  }
36
37
  export {};
@@ -78,5 +78,68 @@ class WebContents extends base_1.EmitterBase {
78
78
  async inspectServiceWorker() {
79
79
  await this.wire.sendAction('inspect-service-worker', { ...this.identity });
80
80
  }
81
+ async showPopupWindow(options) {
82
+ this.wire.sendAction(`${this.entityType}-show-popup-window`, this.identity).catch(() => {
83
+ // we do not want to expose this error, just continue if this analytics-only call fails
84
+ });
85
+ if (options === null || options === void 0 ? void 0 : options.onPopupReady) {
86
+ const readyListener = async ({ popupName }) => {
87
+ try {
88
+ const popupWindow = this.fin.Window.wrapSync({ uuid: this.fin.me.uuid, name: popupName });
89
+ await options.onPopupReady(popupWindow);
90
+ }
91
+ catch (error) {
92
+ throw new Error(`Something went wrong during onPopupReady execution: ${error}`);
93
+ }
94
+ };
95
+ await this.once('popup-ready', readyListener);
96
+ }
97
+ const { payload: tryCreatePayload } = await this.wire.sendAction('try-create-popup-window', {
98
+ options: {
99
+ ...options,
100
+ // Internal use only.
101
+ // @ts-expect-error
102
+ hasResultCallback: !!(options === null || options === void 0 ? void 0 : options.onPopupResult),
103
+ hasReadyCallback: !!(options === null || options === void 0 ? void 0 : options.onPopupReady)
104
+ },
105
+ ...this.identity
106
+ });
107
+ const { data: { willOpen, options: popupOptions } } = tryCreatePayload;
108
+ if (willOpen) {
109
+ await this.wire.environment.createChildContent({
110
+ options: popupOptions.initialOptions,
111
+ entityType: 'window'
112
+ });
113
+ }
114
+ const normalizePopupResult = (payload) => {
115
+ const { name, uuid, result, data } = payload;
116
+ const popupResult = {
117
+ identity: {
118
+ name,
119
+ uuid
120
+ },
121
+ result
122
+ };
123
+ if (data) {
124
+ popupResult.data = data;
125
+ }
126
+ return popupResult;
127
+ };
128
+ if (options === null || options === void 0 ? void 0 : options.onPopupResult) {
129
+ const dispatchResultListener = async (payload) => {
130
+ await options.onPopupResult(normalizePopupResult(payload));
131
+ };
132
+ const teardownListener = async () => {
133
+ await this.removeListener('popup-result', dispatchResultListener);
134
+ };
135
+ await this.on('popup-result', dispatchResultListener);
136
+ await this.once('popup-teardown', teardownListener);
137
+ }
138
+ const { payload } = await this.wire.sendAction('show-popup-window', {
139
+ options: popupOptions,
140
+ ...this.identity
141
+ });
142
+ return payload.data;
143
+ }
81
144
  }
82
145
  exports.WebContents = WebContents;
@@ -994,11 +994,13 @@ export declare class _Window extends WebContents<WindowEvents> {
994
994
  */
995
995
  /**
996
996
  * Shows a popup window. If this window currently has a popup open, closes it.
997
+ * @function showPopupWindow
998
+ * @memberOf Window
999
+ * @instance
997
1000
  * @param {PopupOptions} options
998
1001
  * @return {Promise<PopupResult>}
999
1002
  * @tutorial Window.showPopupWindow
1000
1003
  */
1001
- showPopupWindow(options: OpenFin.PopupOptions): Promise<OpenFin.PopupResult>;
1002
1004
  /**
1003
1005
  * Dispatch a result to the caller of `showPopupWindow`. If this window isn't currently being shown as a popup, this call will silently fail.
1004
1006
  * @param {*} data Serializable data to send to the caller window.
@@ -1233,70 +1233,13 @@ class _Window extends main_1.WebContents {
1233
1233
  */
1234
1234
  /**
1235
1235
  * Shows a popup window. If this window currently has a popup open, closes it.
1236
+ * @function showPopupWindow
1237
+ * @memberOf Window
1238
+ * @instance
1236
1239
  * @param {PopupOptions} options
1237
1240
  * @return {Promise<PopupResult>}
1238
1241
  * @tutorial Window.showPopupWindow
1239
1242
  */
1240
- async showPopupWindow(options) {
1241
- this.wire.sendAction('window-show-popup-window', this.identity).catch((e) => {
1242
- // we do not want to expose this error, just continue if this analytics-only call fails
1243
- });
1244
- if (options === null || options === void 0 ? void 0 : options.onPopupReady) {
1245
- const readyListener = async ({ popupName }) => {
1246
- try {
1247
- const popupWindow = this.fin.Window.wrapSync({ uuid: this.fin.me.uuid, name: popupName });
1248
- await options.onPopupReady(popupWindow);
1249
- }
1250
- catch (error) {
1251
- throw new Error(`Something went wrong during onPopupReady execution: ${error}`);
1252
- }
1253
- };
1254
- await this.once('popup-ready', readyListener);
1255
- }
1256
- const { payload: tryCreatePayload } = await this.wire.sendAction('try-create-popup-window', {
1257
- options: {
1258
- ...options,
1259
- // Internal use only.
1260
- // @ts-expect-error
1261
- hasResultCallback: !!(options === null || options === void 0 ? void 0 : options.onPopupResult),
1262
- hasReadyCallback: !!(options === null || options === void 0 ? void 0 : options.onPopupReady)
1263
- },
1264
- ...this.identity
1265
- });
1266
- const { data: { willOpen, options: popupOptions } } = tryCreatePayload;
1267
- if (willOpen) {
1268
- await this.wire.environment.createChildContent({
1269
- options: popupOptions.initialOptions,
1270
- entityType: 'window'
1271
- });
1272
- }
1273
- const normalizePopupResult = (payload) => {
1274
- const { name, uuid, result, data } = payload;
1275
- return {
1276
- identity: {
1277
- name,
1278
- uuid
1279
- },
1280
- result,
1281
- data
1282
- };
1283
- };
1284
- if (options === null || options === void 0 ? void 0 : options.onPopupResult) {
1285
- const dispatchResultListener = async (payload) => {
1286
- await options.onPopupResult(normalizePopupResult(payload));
1287
- };
1288
- const teardownListener = async () => {
1289
- await this.removeListener('popup-result', dispatchResultListener);
1290
- };
1291
- await this.on('popup-result', dispatchResultListener);
1292
- await this.once('popup-teardown', teardownListener);
1293
- }
1294
- const { payload } = await this.wire.sendAction('show-popup-window', {
1295
- options: popupOptions,
1296
- ...this.identity
1297
- });
1298
- return payload.data;
1299
- }
1300
1243
  /**
1301
1244
  * Dispatch a result to the caller of `showPopupWindow`. If this window isn't currently being shown as a popup, this call will silently fail.
1302
1245
  * @param {*} data Serializable data to send to the caller window.