@openfin/core 30.74.7 → 30.74.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfin/core",
3
- "version": "30.74.7",
3
+ "version": "30.74.9",
4
4
  "license": "SEE LICENSE IN LICENSE.MD",
5
5
  "main": "./src/mock.js",
6
6
  "types": "./src/mock.d.ts",
package/src/OpenFin.d.ts CHANGED
@@ -2248,6 +2248,7 @@ export declare type FindInPageResult = {
2248
2248
  export declare type FrameInfo = {
2249
2249
  name: string;
2250
2250
  uuid: string;
2251
+ url: string;
2251
2252
  entityType: EntityType;
2252
2253
  parent: Identity;
2253
2254
  };
@@ -15,6 +15,7 @@ export interface ChannelMessage extends Message<any> {
15
15
  export declare class Channel extends EmitterBase<ChannelEvent> {
16
16
  #private;
17
17
  constructor(wire: Transport);
18
+ private channelExists;
18
19
  getAllChannels(): Promise<ProviderIdentity[]>;
19
20
  onChannelConnect(listener: (...args: any[]) => void): Promise<void>;
20
21
  onChannelDisconnect(listener: (...args: any[]) => void): Promise<void>;
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _Channel_connectionManager;
13
+ var _Channel_connectionManager, _Channel_internalEmitter, _Channel_readyToConnect;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Channel = void 0;
16
16
  /* eslint-disable no-console */
@@ -18,16 +18,29 @@ const client_1 = require("./client");
18
18
  const provider_1 = require("./provider");
19
19
  const base_1 = require("../../base");
20
20
  const connection_manager_1 = require("./connection-manager");
21
- // eslint-disable-next-line @typescript-eslint/no-empty-function
22
- const noop = () => { };
21
+ const events_1 = require("events");
22
+ const lazy_1 = require("../../../util/lazy");
23
23
  class Channel extends base_1.EmitterBase {
24
24
  constructor(wire) {
25
25
  super(wire, 'channel');
26
26
  _Channel_connectionManager.set(this, void 0);
27
+ _Channel_internalEmitter.set(this, new events_1.EventEmitter());
28
+ // OpenFin API has not been injected at construction time, *must* wait for API to be ready.
29
+ _Channel_readyToConnect.set(this, new lazy_1.AsyncRetryableLazy(async () => {
30
+ await Promise.all([
31
+ this.on('disconnected', (eventPayload) => {
32
+ client_1.default.handleProviderDisconnect(eventPayload);
33
+ }),
34
+ this.on('connected', (...args) => {
35
+ __classPrivateFieldGet(this, _Channel_internalEmitter, "f").emit('connected', ...args);
36
+ })
37
+ ]).catch(() => new Error('error setting up channel connection listeners'));
38
+ }));
27
39
  __classPrivateFieldSet(this, _Channel_connectionManager, new connection_manager_1.ConnectionManager(wire), "f");
28
- this.on('disconnected', (eventPayload) => {
29
- client_1.default.handleProviderDisconnect(eventPayload);
30
- }).catch((e) => console.error('Error setting up a disconnected listener:', e));
40
+ }
41
+ async channelExists(channelName) {
42
+ const channels = await this.getAllChannels();
43
+ return channels.some((providerIdentity) => providerIdentity.channelName === channelName);
31
44
  }
32
45
  async getAllChannels() {
33
46
  return this.wire.sendAction('get-all-channels').then(({ payload }) => payload.data);
@@ -38,47 +51,39 @@ class Channel extends base_1.EmitterBase {
38
51
  async onChannelDisconnect(listener) {
39
52
  await this.on('disconnected', listener);
40
53
  }
41
- async connect(channelName, options) {
54
+ async connect(channelName, options = {}) {
55
+ // Make sure we don't connect before listeners are set up
56
+ // This also errors if we're not in OpenFin, ensuring we don't run unnecessary code
57
+ await __classPrivateFieldGet(this, _Channel_readyToConnect, "f").getValue();
42
58
  if (!channelName || typeof channelName !== 'string') {
43
59
  throw new Error('Please provide a channelName string to connect to a channel.');
44
60
  }
45
- const opts = Object.assign(this.wire.environment.getDefaultChannelOptions().connect, options || {});
46
- let resolver = noop;
47
- let listener = noop;
48
- const waitResponse = new Promise((resolve) => {
49
- resolver = resolve;
50
- listener = (payload) => {
51
- if (channelName === payload.channelName) {
52
- this.removeListener('connected', listener);
53
- resolve(this.connect(channelName, opts));
54
- }
55
- };
56
- this.on('connected', listener);
57
- });
61
+ const opts = { wait: true, ...this.wire.environment.getDefaultChannelOptions().connect, ...options };
62
+ const shouldWait = opts.wait;
63
+ if (shouldWait) {
64
+ const channelExists = await this.channelExists(channelName);
65
+ if (!channelExists) {
66
+ console.warn(`Channel not found for channelName: ${channelName}, waiting for channel connection.`);
67
+ await new Promise((resolve) => {
68
+ const connectedListener = (payload) => {
69
+ if (channelName === payload.channelName) {
70
+ __classPrivateFieldGet(this, _Channel_internalEmitter, "f").removeListener('connected', connectedListener);
71
+ resolve();
72
+ }
73
+ };
74
+ __classPrivateFieldGet(this, _Channel_internalEmitter, "f").on('connected', connectedListener);
75
+ });
76
+ }
77
+ }
58
78
  try {
59
79
  const { offer, rtc: rtcPacket } = await __classPrivateFieldGet(this, _Channel_connectionManager, "f").createClientOffer(opts);
60
- let connectionUrl;
61
- const entityType = this.wire.environment.getCurrentEntityType();
62
- if (entityType === 'iframe') {
63
- // @ts-expect-error
64
- // TODO: type this correctly (frame types are broken)
65
- connectionUrl = (await this.fin.me.getInfo()).url;
66
- }
67
- else if (entityType === 'window' || entityType === 'view') {
68
- connectionUrl = (await this.fin.me.getInfo()).url;
69
- }
70
- const res = await this.wire.sendAction('connect-to-channel', {
80
+ const connectionUrl = (await this.fin.me.getInfo()).url;
81
+ const { payload: { data: routingInfo } } = await this.wire.sendAction('connect-to-channel', {
71
82
  channelName,
72
83
  ...opts,
73
84
  offer,
74
85
  connectionUrl
75
86
  });
76
- const { payload: { data: routingInfo } } = res;
77
- // If there isn't a matching channel, the above sendAction call will error out and go to catch, skipping the logic below.
78
- if (resolver) {
79
- resolver();
80
- }
81
- this.removeListener('connected', listener);
82
87
  const strategy = await __classPrivateFieldGet(this, _Channel_connectionManager, "f").createClientStrategy(rtcPacket, routingInfo);
83
88
  const channel = new client_1.default(routingInfo, this.wire, strategy);
84
89
  // It is the client's responsibility to handle endpoint disconnection to the provider.
@@ -97,18 +102,13 @@ class Channel extends base_1.EmitterBase {
97
102
  });
98
103
  return channel;
99
104
  }
100
- catch (e) {
101
- const shouldWait = { wait: true, ...opts }.wait;
105
+ catch (error) {
102
106
  const internalNackMessage = 'internal-nack';
103
- if (shouldWait && e.message && e.message.includes(internalNackMessage)) {
104
- console.warn(`Channel not found for channelName: ${channelName}, waiting for channel connection.`);
105
- return waitResponse;
106
- }
107
- if (e.message === internalNackMessage) {
108
- throw new Error(`No channel found for channelName: ${channelName}`);
107
+ if (error.message.includes(internalNackMessage)) {
108
+ throw new Error(`No channel found for channelName: ${channelName}.`);
109
109
  }
110
110
  else {
111
- throw new Error(e);
111
+ throw new Error(error);
112
112
  }
113
113
  }
114
114
  }
@@ -129,4 +129,4 @@ class Channel extends base_1.EmitterBase {
129
129
  }
130
130
  }
131
131
  exports.Channel = Channel;
132
- _Channel_connectionManager = new WeakMap();
132
+ _Channel_connectionManager = new WeakMap(), _Channel_internalEmitter = new WeakMap(), _Channel_readyToConnect = new WeakMap();
@@ -10,7 +10,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
11
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
12
  };
13
- var _LayoutModule_layoutManager;
13
+ var _LayoutModule_layoutManager, _LayoutModule_layoutInitializationAttempted;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.LayoutModule = void 0;
16
16
  /* eslint-disable no-undef, import/prefer-default-export */
@@ -91,6 +91,7 @@ class LayoutModule extends base_1.Base {
91
91
  constructor() {
92
92
  super(...arguments);
93
93
  _LayoutModule_layoutManager.set(this, void 0);
94
+ _LayoutModule_layoutInitializationAttempted.set(this, false);
94
95
  /**
95
96
  * Initialize the window's Layout. Must be called from a custom window that has a 'layout' option set upon creation of that window.
96
97
  * If a containerId is not provided, this method attempts to find an element with the id `layout-container`.
@@ -109,9 +110,10 @@ class LayoutModule extends base_1.Base {
109
110
  if (!this.fin.me.isWindow) {
110
111
  throw new Error('Layout.init can only be called from a Window context.');
111
112
  }
112
- else if (__classPrivateFieldGet(this, _LayoutModule_layoutManager, "f")) {
113
+ else if (__classPrivateFieldGet(this, _LayoutModule_layoutInitializationAttempted, "f")) {
113
114
  throw new Error('Layout for this window already initialized, please use Layout.replace call to replace the layout.');
114
115
  }
116
+ __classPrivateFieldSet(this, _LayoutModule_layoutInitializationAttempted, true, "f");
115
117
  // We need to go through environment to make sure it is only imported/bundled in OpenFin.
116
118
  const ManagerConstructor = await this.wire.environment.getManagerConstructor();
117
119
  const viewOverlay = new view_overlay_1.ViewOverlay(this.wire);
@@ -203,4 +205,4 @@ class LayoutModule extends base_1.Base {
203
205
  }
204
206
  }
205
207
  exports.LayoutModule = LayoutModule;
206
- _LayoutModule_layoutManager = new WeakMap();
208
+ _LayoutModule_layoutManager = new WeakMap(), _LayoutModule_layoutInitializationAttempted = new WeakMap();
@@ -102,10 +102,10 @@ export declare class LayoutEntitiesController {
102
102
  * Creates a new adjacent 'stack' and adds the views to it at the specified position
103
103
  * @param targetId Entity id of the content item to add a stack adjacent to it
104
104
  * @param views List of identities or view creation options of the views to include in the stack
105
- * @param options Creation options, defaults to position: 'right'
105
+ * @param options Creation options, defaults to { position: 'right' }
106
106
  * @returns the Entity Id of the new stack
107
107
  */
108
- createAdjacentStack: (targetId: string, views: ViewCreationOrReference[], options: {
108
+ createAdjacentStack: (targetId: string, views: ViewCreationOrReference[], { position }?: {
109
109
  position?: OpenFin.LayoutPosition;
110
110
  }) => Promise<string>;
111
111
  getAdjacentStacks: ({ targetId, edge }: {
@@ -148,14 +148,13 @@ class LayoutEntitiesController {
148
148
  * Creates a new adjacent 'stack' and adds the views to it at the specified position
149
149
  * @param targetId Entity id of the content item to add a stack adjacent to it
150
150
  * @param views List of identities or view creation options of the views to include in the stack
151
- * @param options Creation options, defaults to position: 'right'
151
+ * @param options Creation options, defaults to { position: 'right' }
152
152
  * @returns the Entity Id of the new stack
153
153
  */
154
- this.createAdjacentStack = async (targetId, views, options) => {
155
- if (views.length === 0) {
156
- throw new Error('Cannot create stack with empty view array.');
154
+ this.createAdjacentStack = async (targetId, views, { position = 'right' } = {}) => {
155
+ if (!Array.isArray(views) || views.length === 0) {
156
+ throw new Error('The parameter "views" must be an array with at least 1 element.');
157
157
  }
158
- const { position = 'right' } = options;
159
158
  if (!['top', 'bottom', 'left', 'right'].includes(position)) {
160
159
  throw new Error(`Invalid position '${position}' specified.`);
161
160
  }
@@ -1,25 +1,27 @@
1
1
  import type * as OpenFin from '../../../../OpenFin';
2
2
  import { LayoutEntitiesClient } from '../shapes';
3
3
  /**
4
+ * @ignore
4
5
  * @internal
5
6
  * Supplies an ApiClient for {@link LayoutEntitiesController} and helper methods
6
7
  * for the entities {@link TabStack} AND {@link ColumnOrRow} to use.
7
8
  */
8
9
  export declare abstract class LayoutNode {
9
10
  #private;
10
- /** @internal */
11
- protected constructor(client: LayoutEntitiesClient, entityId: string);
12
11
  /**
13
12
  * @internal
14
- * The type of this node, one of: 'row' | 'column' | 'stack';
13
+ * @ignore
15
14
  */
16
- readonly abstract type: OpenFin.LayoutEntityTypes;
15
+ protected constructor(client: LayoutEntitiesClient, entityId: string);
16
+ abstract readonly type: OpenFin.LayoutEntityTypes;
17
17
  /**
18
18
  * @internal
19
+ * @ignore
19
20
  * This instance's unique id used when calling the layout-entities-controller api client
20
21
  */
21
22
  protected readonly entityId: string;
22
23
  /**
24
+ * @ignore
23
25
  * @internal
24
26
  * Encapsulates Api consumption of {@link LayoutEntitiesController} with a relayed dispatch
25
27
  * @param client
@@ -29,51 +31,83 @@ export declare abstract class LayoutNode {
29
31
  */
30
32
  static newLayoutEntitiesClient: (client: OpenFin.ChannelClient, controllerId: string, identity: OpenFin.Identity) => Promise<LayoutEntitiesClient>;
31
33
  static getEntity: (definition: OpenFin.LayoutEntityDefinition, client: LayoutEntitiesClient) => ColumnOrRow | TabStack;
34
+ isRoot: () => Promise<boolean>;
35
+ exists: () => Promise<boolean>;
36
+ getParent: () => Promise<ColumnOrRow | TabStack | undefined>;
37
+ createAdjacentStack: (views: OpenFin.PlatformViewCreationOptions[], options: {
38
+ position?: OpenFin.LayoutPosition;
39
+ }) => Promise<TabStack>;
40
+ getAdjacentStacks: (edge: OpenFin.LayoutPosition) => Promise<TabStack[]>;
41
+ }
42
+ /**
43
+ * @typedef {string} LayoutPosition
44
+ * @summary Represents the position of an item in a layout relative to another. Possible values are 'top', 'bottom', 'left' and 'right'.
45
+ */
46
+ /**
47
+ * @typedef {object} StackCreationOptions
48
+ * @summary Stack creation options.
49
+ * @property {LayoutPosition} [position] - The position to create the new {@link TabStack} in, relative to the given adjacent {@link TabStack}. Defaults to 'right'.
50
+ */
51
+ /**
52
+ * @typedef {object} TabStack~AddViewOptions
53
+ * @summary Options to use when adding a view to a {@link TabStack}
54
+ * @property {number} [index] - Insertion index when adding the view. Defaults to 0.
55
+ */
56
+ /**
57
+ * A TabStack is used to manage the state of a stack of tabs within an OpenFin Layout.
58
+ */
59
+ export declare class TabStack extends LayoutNode {
60
+ #private;
32
61
  /**
33
- * Determines if this {@link ColumnOrRow} or {@link TabStack} is the top level content item in the current layout.
34
- * @returns Promise resolving true if this is the root, or false otherwise.
62
+ * Determines if this {@link TabStack} is the top level content item in the current layout.
63
+ * @function isRoot
64
+ * @memberof TabStack
65
+ * @instance
66
+ * @tutorial TabStack.isRoot
67
+ * @return {Promise<boolean>} Resolves true if this TabStack is the top level content item, or false if it is not.
35
68
  */
36
- isRoot: () => Promise<boolean>;
37
69
  /**
38
- * Determines if this {@link ColumnOrRow} or {@link TabStack} is the top level
39
- * content item in the current layout.
40
- * @returns Promise resolving true if this is the root, or false otherwise.
70
+ * Determines if this {@link TabStack} exists.
71
+ * @function exists
72
+ * @instance
73
+ * @memberof TabStack
74
+ * @tutorial TabStack.exists
75
+ * @return {Promise<boolean>} Resolves true if this is the TabStack exists, or false if it has been destroyed.
41
76
  */
42
- exists: () => Promise<boolean>;
43
77
  /**
44
- * Retrieves the parent {@link ColumnOrRow} or {@link TabStack} of this item, if one exists.
45
- * @returns Promise resolving with the {@link ColumnOrRow} or {@link TabStack} that contains this item, or undefined if this is the root content item.
78
+ * Retrieves the parent {@link ColumnOrRow} of this {@link TabStack}, if one exists.
79
+ * @function getParent
80
+ * @instance
81
+ * @memberof TabStack
82
+ * @tutorial TabStack.getParent
83
+ * @return {Promise<ColumnOrRow | TabStack | undefined>} Promise resolving with the {@link ColumnOrRow} that contains this item, or undefined if this {@link TabStack} is the root content item or does not exist.
84
+ */
85
+ /**
86
+ * Returns all the adjacent stacks that share an edge with the given {@link TabStack}.
87
+ * @function getAdjacentStacks
88
+ * @instance
89
+ * @memberof TabStack
90
+ * @param {LayoutPosition} edge - Edge to check for any adjacent stacks.
91
+ * @returns {Promise<TabStack[]>}
92
+ * @tutorial TabStack.getAdjacentStacks
46
93
  */
47
- getParent: () => Promise<ColumnOrRow | TabStack | undefined>;
48
94
  /**
49
- * Given a list of view creation options or references and a layout position, creates an adjacent {@link TabStack}
95
+ * Given a list of view creation options or references and a layout position, creates a {@link TabStack} adjacent to the current {@link TabStack}
50
96
  *
51
97
  * Known Issue: If the number of views to add overflows the tab-container, the added views will be set as active
52
98
  * during each render, and then placed at the front of the tab-stack, while the underlying order of tabs will remain unchanged.
53
99
  * This means the views you pass to createAdjacentStack() may not render in the order given by the array.
54
100
  * Until fixed, this problem can be avoided only if your window is wide enough to fit creating all the views in the tabstack.
55
101
  *
56
- * @param views List of identities or view creation options of the views to include in the stack
57
- * @param options Creation options, defaults to position: 'right'
58
- * @returns an instance of {@link TabStack} containing the given views
102
+ * @function createAdjacentStack
103
+ * @instance
104
+ * @memberof TabStack
105
+ * @param {View~options} views - List of identities or view creation options of the views to include in the stack
106
+ * @param {StackCreationOptions} options - Creation options.
107
+ * @returns {Promise<TabStack>} The created TabStack.
108
+ * @tutorial TabStack.createAdjacentStack
59
109
  * @experimental
60
110
  */
61
- createAdjacentStack: (views: OpenFin.PlatformViewCreationOptions[], options: {
62
- position?: OpenFin.LayoutPosition;
63
- }) => Promise<TabStack>;
64
- /**
65
- * Finds the immediate adjacent layout item given an edge Position
66
- * @param edge
67
- * @returns an array of {@link TabStack} found, if none found returns an empty array.
68
- */
69
- getAdjacentStacks: (edge: OpenFin.LayoutPosition) => Promise<TabStack[]>;
70
- }
71
- /**
72
- * A {@link TabStack} is used to manage the state of a TabStack within an OpenFin Layout and
73
- * traverse to its parent Content Item.
74
- */
75
- export declare class TabStack extends LayoutNode {
76
- #private;
77
111
  /** @internal */
78
112
  constructor(client: LayoutEntitiesClient, entityId: string);
79
113
  /**
@@ -88,8 +122,9 @@ export declare class TabStack extends LayoutNode {
88
122
  * If that happens and then getViews() is called, it will return the identities in a different order than
89
123
  * than the currently rendered tab order.
90
124
  *
91
- * @returns Resolves with a list containing the {@link OpenFin.Identity identities} of each view belonging to the {@link TabStack}.
125
+ * @returns {Promise<Identity[]>} Resolves with a list containing the {@link OpenFin.Identity identities} of each view belonging to the {@link TabStack}.
92
126
  * @throws If the {@link TabStack} has been destroyed.
127
+ * @tutorial TabStack.getViews
93
128
  * @experimental
94
129
  */
95
130
  getViews: () => Promise<OpenFin.Identity[]>;
@@ -99,25 +134,28 @@ export declare class TabStack extends LayoutNode {
99
134
  * Known Issue: If adding a view overflows the tab-container, the added view will be set as active
100
135
  * and rendered at the front of the tab-stack, while the underlying order of tabs will remain unchanged.
101
136
  *
102
- * @param view The identity of an existing view to add, or options to create a view.
103
- * @param options Optional view options: index number used to insert the view into the stack at that index. Defaults to 0 (front of the stack)
104
- * @returns Resolves with the {@link OpenFin.Identity identity} of the added view.
137
+ * @param {View~options} view The identity of an existing view to add, or options to create a view.
138
+ * @param {TabStack~AddViewOptions} options Optional view options: index number used to insert the view into the stack at that index. Defaults to 0 (front of the stack)
139
+ * @returns {Promise<identity>} Resolves with the {@link OpenFin.Identity identity} of the added view.
105
140
  * @throws If the view does not exist or fails to create.
106
141
  * @throws If the {@link TabStack} has been destroyed.
142
+ * @tutorial TabStack.addView
107
143
  * @experimental
108
144
  */
109
145
  addView: (view: OpenFin.Identity | OpenFin.PlatformViewCreationOptions, options?: OpenFin.AddViewToStackOptions) => Promise<OpenFin.Identity>;
110
146
  /**
111
147
  * Removes a view from this {@link TabStack}.
112
- * @param view {@link OpenFin.Identiy Identity} of the view to remove.
148
+ * @param {Identity} view - Identity of the view to remove.
113
149
  * @throws If the view does not exist or does not belong to the stack.
114
150
  * @throws If the {@link TabStack} has been destroyed.
151
+ * @return {Promise<void>}
152
+ * @tutorial TabStack.removeView
115
153
  */
116
154
  removeView: (view: OpenFin.Identity) => Promise<void>;
117
155
  /**
118
156
  * Sets the active view of the {@link TabStack} without focusing it.
119
- * @param view {@link OpenFin.Identity Identity} of the view to activate.
120
- * @returns Promise which resolves with void once the view has been activated.
157
+ * @param {Identity} view - Identity of the view to activate.
158
+ * @returns {Promise<void>} Promise which resolves with void once the view has been activated.
121
159
  * @throws If the {@link TabStack} has been destroyed.
122
160
  * @throws If the view does not exist.
123
161
  * @tutorial TabStack.setActiveView
@@ -126,11 +164,63 @@ export declare class TabStack extends LayoutNode {
126
164
  setActiveView: (view: OpenFin.Identity) => Promise<void>;
127
165
  }
128
166
  /**
129
- * A {@link ColumnOrRow} is used to manage the state of a ColumnOrRow within an OpenFin Layout.
167
+ * A ColumnOrRow is used to manage the state of Column and Rows within an OpenFin Layout.
130
168
  */
131
169
  export declare class ColumnOrRow extends LayoutNode {
132
170
  #private;
133
- /** @internal */
171
+ /**
172
+ * Determines if this {@link ColumnOrRow} is the top level content item in the current layout.
173
+ * @function isRoot
174
+ * @memberof ColumnOrRow
175
+ * @instance
176
+ * @tutorial ColumnOrRow.isRoot
177
+ * @return {Promise<boolean>} Resolves true if this TabStack is the top level content item, or false if it is not.
178
+ */
179
+ /**
180
+ * Determines if this {@link ColumnOrRow} exists.
181
+ * @function exists
182
+ * @instance
183
+ * @memberof ColumnOrRow
184
+ * @tutorial ColumnOrRow.exists
185
+ * @return {Promise<boolean>} Resolves true if the TabStack exists, or false if it has been destroyed.
186
+ */
187
+ /**
188
+ * Retrieves the parent {@link ColumnOrRow} of this {@link ColumnOrRow}, if one exists.
189
+ * @function getParent
190
+ * @instance
191
+ * @memberof ColumnOrRow
192
+ * @tutorial ColumnOrRow.getParent
193
+ * @return {Promise<ColumnOrRow | undefined>} Promise resolving with the {@link ColumnOrRow} that contains this item, or undefined if this {@link ColumnOrRow} does not exist or is the root content item.
194
+ */
195
+ /**
196
+ * Returns all the adjacent stacks that share an edge with the given {@link ColumnOrRow}.
197
+ * @function getAdjacentStacks
198
+ * @instance
199
+ * @memberof ColumnOrRow
200
+ * @param {LayoutPosition} edge - Edge to check for any adjacent stacks.
201
+ * @returns {Promise<TabStack[]>}
202
+ * @tutorial ColumnOrRow.getAdjacentStacks
203
+ */
204
+ /**
205
+ * Given a list of view creation options or references and a layout position, creates a {@link TabStack} adjacent to the given {@link ColumnOrRow}
206
+ *
207
+ * Known Issue: If the number of views to add overflows the tab-container, the added views will be set as active
208
+ * during each render, and then placed at the front of the tab-stack, while the underlying order of tabs will remain unchanged.
209
+ * This means the views you pass to createAdjacentStack() may not render in the order given by the array.
210
+ * Until fixed, this problem can be avoided only if your window is wide enough to fit creating all the views in the tabstack.
211
+ *
212
+ * @function createAdjacentStack
213
+ * @instance
214
+ * @memberof ColumnOrRow
215
+ * @param {View~options} views - List of identities or view creation options of the views to include in the stack
216
+ * @param {StackCreationOptions} options - Creation options.
217
+ * @returns {Promise<TabStack>} The created TabStack
218
+ * @tutorial ColumnOrRow.createAdjacentStack
219
+ * @experimental
220
+ */
221
+ /**
222
+ * @internal
223
+ */
134
224
  constructor(client: LayoutEntitiesClient, entityId: string, type: 'row' | 'column');
135
225
  /**
136
226
  * The type of this {@link ColumnOrRow}. Either 'row' or 'column'.
@@ -138,7 +228,8 @@ export declare class ColumnOrRow extends LayoutNode {
138
228
  readonly type: 'column' | 'row';
139
229
  /**
140
230
  * Retrieves a list of all content items belonging to this {@link ColumnOrRow} in order of appearance.
141
- * @returns Resolves with a list containing {@link ColumnOrRow} and {@link TabStack} items belonging to this {@link ColumnOrRow}.
231
+ * @returns {Promise<Array<ColumnOrRow | TabStack>>} Resolves with a list containing {@link ColumnOrRow} and {@link TabStack} items belonging to this {@link ColumnOrRow}.
232
+ * @tutorial ColumnOrRow.getContent
142
233
  */
143
234
  getContent: () => Promise<(ColumnOrRow | TabStack)[]>;
144
235
  }
@@ -21,33 +21,25 @@ const channel_api_relay_1 = require("../../../../util/channel-api-relay");
21
21
  refs, we define and export all the classes here.
22
22
  */
23
23
  /**
24
+ * @ignore
24
25
  * @internal
25
26
  * Supplies an ApiClient for {@link LayoutEntitiesController} and helper methods
26
27
  * for the entities {@link TabStack} AND {@link ColumnOrRow} to use.
27
28
  */
28
29
  class LayoutNode {
29
- /** @internal */
30
+ /**
31
+ * @internal
32
+ * @ignore
33
+ */
30
34
  constructor(client, entityId) {
31
35
  /**
36
+ * @ignore
32
37
  * @internal
33
38
  * ApiClient for {@link LayoutEntitiesController}
34
39
  */
35
40
  _LayoutNode_client.set(this, void 0);
36
- /**
37
- * Determines if this {@link ColumnOrRow} or {@link TabStack} is the top level content item in the current layout.
38
- * @returns Promise resolving true if this is the root, or false otherwise.
39
- */
40
41
  this.isRoot = () => __classPrivateFieldGet(this, _LayoutNode_client, "f").isRoot(this.entityId);
41
- /**
42
- * Determines if this {@link ColumnOrRow} or {@link TabStack} is the top level
43
- * content item in the current layout.
44
- * @returns Promise resolving true if this is the root, or false otherwise.
45
- */
46
42
  this.exists = () => __classPrivateFieldGet(this, _LayoutNode_client, "f").exists(this.entityId);
47
- /**
48
- * Retrieves the parent {@link ColumnOrRow} or {@link TabStack} of this item, if one exists.
49
- * @returns Promise resolving with the {@link ColumnOrRow} or {@link TabStack} that contains this item, or undefined if this is the root content item.
50
- */
51
43
  this.getParent = async () => {
52
44
  const parent = await __classPrivateFieldGet(this, _LayoutNode_client, "f").getParent(this.entityId);
53
45
  if (!parent) {
@@ -55,34 +47,16 @@ class LayoutNode {
55
47
  }
56
48
  return LayoutNode.getEntity(parent, __classPrivateFieldGet(this, _LayoutNode_client, "f"));
57
49
  };
58
- /**
59
- * Given a list of view creation options or references and a layout position, creates an adjacent {@link TabStack}
60
- *
61
- * Known Issue: If the number of views to add overflows the tab-container, the added views will be set as active
62
- * during each render, and then placed at the front of the tab-stack, while the underlying order of tabs will remain unchanged.
63
- * This means the views you pass to createAdjacentStack() may not render in the order given by the array.
64
- * Until fixed, this problem can be avoided only if your window is wide enough to fit creating all the views in the tabstack.
65
- *
66
- * @param views List of identities or view creation options of the views to include in the stack
67
- * @param options Creation options, defaults to position: 'right'
68
- * @returns an instance of {@link TabStack} containing the given views
69
- * @experimental
70
- */
71
50
  this.createAdjacentStack = async (views, options) => {
72
51
  const entityId = await __classPrivateFieldGet(this, _LayoutNode_client, "f").createAdjacentStack(this.entityId, views, options);
73
52
  return LayoutNode.getEntity({ entityId, type: 'stack' }, __classPrivateFieldGet(this, _LayoutNode_client, "f"));
74
53
  };
75
- /**
76
- * Finds the immediate adjacent layout item given an edge Position
77
- * @param edge
78
- * @returns an array of {@link TabStack} found, if none found returns an empty array.
79
- */
80
54
  this.getAdjacentStacks = async (edge) => {
81
55
  const adjacentStacks = await __classPrivateFieldGet(this, _LayoutNode_client, "f").getAdjacentStacks({
82
56
  targetId: this.entityId,
83
57
  edge
84
58
  });
85
- return adjacentStacks.map(stack => LayoutNode.getEntity({
59
+ return adjacentStacks.map((stack) => LayoutNode.getEntity({
86
60
  type: 'stack',
87
61
  entityId: stack.entityId
88
62
  }, __classPrivateFieldGet(this, _LayoutNode_client, "f")));
@@ -94,6 +68,7 @@ class LayoutNode {
94
68
  exports.LayoutNode = LayoutNode;
95
69
  _a = LayoutNode, _LayoutNode_client = new WeakMap();
96
70
  /**
71
+ * @ignore
97
72
  * @internal
98
73
  * Encapsulates Api consumption of {@link LayoutEntitiesController} with a relayed dispatch
99
74
  * @param client
@@ -119,10 +94,73 @@ LayoutNode.getEntity = (definition, client) => {
119
94
  }
120
95
  };
121
96
  /**
122
- * A {@link TabStack} is used to manage the state of a TabStack within an OpenFin Layout and
123
- * traverse to its parent Content Item.
97
+ * @typedef {string} LayoutPosition
98
+ * @summary Represents the position of an item in a layout relative to another. Possible values are 'top', 'bottom', 'left' and 'right'.
99
+ */
100
+ /**
101
+ * @typedef {object} StackCreationOptions
102
+ * @summary Stack creation options.
103
+ * @property {LayoutPosition} [position] - The position to create the new {@link TabStack} in, relative to the given adjacent {@link TabStack}. Defaults to 'right'.
104
+ */
105
+ /**
106
+ * @typedef {object} TabStack~AddViewOptions
107
+ * @summary Options to use when adding a view to a {@link TabStack}
108
+ * @property {number} [index] - Insertion index when adding the view. Defaults to 0.
109
+ */
110
+ /**
111
+ * A TabStack is used to manage the state of a stack of tabs within an OpenFin Layout.
124
112
  */
125
113
  class TabStack extends LayoutNode {
114
+ /**
115
+ * Determines if this {@link TabStack} is the top level content item in the current layout.
116
+ * @function isRoot
117
+ * @memberof TabStack
118
+ * @instance
119
+ * @tutorial TabStack.isRoot
120
+ * @return {Promise<boolean>} Resolves true if this TabStack is the top level content item, or false if it is not.
121
+ */
122
+ /**
123
+ * Determines if this {@link TabStack} exists.
124
+ * @function exists
125
+ * @instance
126
+ * @memberof TabStack
127
+ * @tutorial TabStack.exists
128
+ * @return {Promise<boolean>} Resolves true if this is the TabStack exists, or false if it has been destroyed.
129
+ */
130
+ /**
131
+ * Retrieves the parent {@link ColumnOrRow} of this {@link TabStack}, if one exists.
132
+ * @function getParent
133
+ * @instance
134
+ * @memberof TabStack
135
+ * @tutorial TabStack.getParent
136
+ * @return {Promise<ColumnOrRow | TabStack | undefined>} Promise resolving with the {@link ColumnOrRow} that contains this item, or undefined if this {@link TabStack} is the root content item or does not exist.
137
+ */
138
+ /**
139
+ * Returns all the adjacent stacks that share an edge with the given {@link TabStack}.
140
+ * @function getAdjacentStacks
141
+ * @instance
142
+ * @memberof TabStack
143
+ * @param {LayoutPosition} edge - Edge to check for any adjacent stacks.
144
+ * @returns {Promise<TabStack[]>}
145
+ * @tutorial TabStack.getAdjacentStacks
146
+ */
147
+ /**
148
+ * Given a list of view creation options or references and a layout position, creates a {@link TabStack} adjacent to the current {@link TabStack}
149
+ *
150
+ * Known Issue: If the number of views to add overflows the tab-container, the added views will be set as active
151
+ * during each render, and then placed at the front of the tab-stack, while the underlying order of tabs will remain unchanged.
152
+ * This means the views you pass to createAdjacentStack() may not render in the order given by the array.
153
+ * Until fixed, this problem can be avoided only if your window is wide enough to fit creating all the views in the tabstack.
154
+ *
155
+ * @function createAdjacentStack
156
+ * @instance
157
+ * @memberof TabStack
158
+ * @param {View~options} views - List of identities or view creation options of the views to include in the stack
159
+ * @param {StackCreationOptions} options - Creation options.
160
+ * @returns {Promise<TabStack>} The created TabStack.
161
+ * @tutorial TabStack.createAdjacentStack
162
+ * @experimental
163
+ */
126
164
  /** @internal */
127
165
  constructor(client, entityId) {
128
166
  super(client, entityId);
@@ -143,8 +181,9 @@ class TabStack extends LayoutNode {
143
181
  * If that happens and then getViews() is called, it will return the identities in a different order than
144
182
  * than the currently rendered tab order.
145
183
  *
146
- * @returns Resolves with a list containing the {@link OpenFin.Identity identities} of each view belonging to the {@link TabStack}.
184
+ * @returns {Promise<Identity[]>} Resolves with a list containing the {@link OpenFin.Identity identities} of each view belonging to the {@link TabStack}.
147
185
  * @throws If the {@link TabStack} has been destroyed.
186
+ * @tutorial TabStack.getViews
148
187
  * @experimental
149
188
  */
150
189
  this.getViews = () => __classPrivateFieldGet(this, _TabStack_client, "f").getStackViews(this.entityId);
@@ -154,27 +193,30 @@ class TabStack extends LayoutNode {
154
193
  * Known Issue: If adding a view overflows the tab-container, the added view will be set as active
155
194
  * and rendered at the front of the tab-stack, while the underlying order of tabs will remain unchanged.
156
195
  *
157
- * @param view The identity of an existing view to add, or options to create a view.
158
- * @param options Optional view options: index number used to insert the view into the stack at that index. Defaults to 0 (front of the stack)
159
- * @returns Resolves with the {@link OpenFin.Identity identity} of the added view.
196
+ * @param {View~options} view The identity of an existing view to add, or options to create a view.
197
+ * @param {TabStack~AddViewOptions} options Optional view options: index number used to insert the view into the stack at that index. Defaults to 0 (front of the stack)
198
+ * @returns {Promise<identity>} Resolves with the {@link OpenFin.Identity identity} of the added view.
160
199
  * @throws If the view does not exist or fails to create.
161
200
  * @throws If the {@link TabStack} has been destroyed.
201
+ * @tutorial TabStack.addView
162
202
  * @experimental
163
203
  */
164
204
  this.addView = async (view, options = { index: 0 }) => __classPrivateFieldGet(this, _TabStack_client, "f").addViewToStack(this.entityId, view, options);
165
205
  /**
166
206
  * Removes a view from this {@link TabStack}.
167
- * @param view {@link OpenFin.Identiy Identity} of the view to remove.
207
+ * @param {Identity} view - Identity of the view to remove.
168
208
  * @throws If the view does not exist or does not belong to the stack.
169
209
  * @throws If the {@link TabStack} has been destroyed.
210
+ * @return {Promise<void>}
211
+ * @tutorial TabStack.removeView
170
212
  */
171
213
  this.removeView = async (view) => {
172
214
  await __classPrivateFieldGet(this, _TabStack_client, "f").removeViewFromStack(this.entityId, view);
173
215
  };
174
216
  /**
175
217
  * Sets the active view of the {@link TabStack} without focusing it.
176
- * @param view {@link OpenFin.Identity Identity} of the view to activate.
177
- * @returns Promise which resolves with void once the view has been activated.
218
+ * @param {Identity} view - Identity of the view to activate.
219
+ * @returns {Promise<void>} Promise which resolves with void once the view has been activated.
178
220
  * @throws If the {@link TabStack} has been destroyed.
179
221
  * @throws If the view does not exist.
180
222
  * @tutorial TabStack.setActiveView
@@ -189,20 +231,74 @@ class TabStack extends LayoutNode {
189
231
  exports.TabStack = TabStack;
190
232
  _TabStack_client = new WeakMap();
191
233
  /**
192
- * A {@link ColumnOrRow} is used to manage the state of a ColumnOrRow within an OpenFin Layout.
234
+ * A ColumnOrRow is used to manage the state of Column and Rows within an OpenFin Layout.
193
235
  */
194
236
  class ColumnOrRow extends LayoutNode {
195
- /** @internal */
237
+ /**
238
+ * Determines if this {@link ColumnOrRow} is the top level content item in the current layout.
239
+ * @function isRoot
240
+ * @memberof ColumnOrRow
241
+ * @instance
242
+ * @tutorial ColumnOrRow.isRoot
243
+ * @return {Promise<boolean>} Resolves true if this TabStack is the top level content item, or false if it is not.
244
+ */
245
+ /**
246
+ * Determines if this {@link ColumnOrRow} exists.
247
+ * @function exists
248
+ * @instance
249
+ * @memberof ColumnOrRow
250
+ * @tutorial ColumnOrRow.exists
251
+ * @return {Promise<boolean>} Resolves true if the TabStack exists, or false if it has been destroyed.
252
+ */
253
+ /**
254
+ * Retrieves the parent {@link ColumnOrRow} of this {@link ColumnOrRow}, if one exists.
255
+ * @function getParent
256
+ * @instance
257
+ * @memberof ColumnOrRow
258
+ * @tutorial ColumnOrRow.getParent
259
+ * @return {Promise<ColumnOrRow | undefined>} Promise resolving with the {@link ColumnOrRow} that contains this item, or undefined if this {@link ColumnOrRow} does not exist or is the root content item.
260
+ */
261
+ /**
262
+ * Returns all the adjacent stacks that share an edge with the given {@link ColumnOrRow}.
263
+ * @function getAdjacentStacks
264
+ * @instance
265
+ * @memberof ColumnOrRow
266
+ * @param {LayoutPosition} edge - Edge to check for any adjacent stacks.
267
+ * @returns {Promise<TabStack[]>}
268
+ * @tutorial ColumnOrRow.getAdjacentStacks
269
+ */
270
+ /**
271
+ * Given a list of view creation options or references and a layout position, creates a {@link TabStack} adjacent to the given {@link ColumnOrRow}
272
+ *
273
+ * Known Issue: If the number of views to add overflows the tab-container, the added views will be set as active
274
+ * during each render, and then placed at the front of the tab-stack, while the underlying order of tabs will remain unchanged.
275
+ * This means the views you pass to createAdjacentStack() may not render in the order given by the array.
276
+ * Until fixed, this problem can be avoided only if your window is wide enough to fit creating all the views in the tabstack.
277
+ *
278
+ * @function createAdjacentStack
279
+ * @instance
280
+ * @memberof ColumnOrRow
281
+ * @param {View~options} views - List of identities or view creation options of the views to include in the stack
282
+ * @param {StackCreationOptions} options - Creation options.
283
+ * @returns {Promise<TabStack>} The created TabStack
284
+ * @tutorial ColumnOrRow.createAdjacentStack
285
+ * @experimental
286
+ */
287
+ /**
288
+ * @internal
289
+ */
196
290
  constructor(client, entityId, type) {
197
291
  super(client, entityId);
198
292
  /**
293
+ * @ignore
199
294
  * @internal
200
295
  * ApiClient for {@link LayoutEntitiesController}
201
296
  */
202
297
  _ColumnOrRow_client.set(this, void 0);
203
298
  /**
204
299
  * Retrieves a list of all content items belonging to this {@link ColumnOrRow} in order of appearance.
205
- * @returns Resolves with a list containing {@link ColumnOrRow} and {@link TabStack} items belonging to this {@link ColumnOrRow}.
300
+ * @returns {Promise<Array<ColumnOrRow | TabStack>>} Resolves with a list containing {@link ColumnOrRow} and {@link TabStack} items belonging to this {@link ColumnOrRow}.
301
+ * @tutorial ColumnOrRow.getContent
206
302
  */
207
303
  this.getContent = async () => {
208
304
  const contentItemEntities = await __classPrivateFieldGet(this, _ColumnOrRow_client, "f").getContent(this.entityId);
@@ -1,4 +1,4 @@
1
1
  import type * as OpenFin from '../../../../OpenFin';
2
2
  export declare const getAdjacentItem: (component: GoldenLayout.ContentItem, edge: OpenFin.LayoutPosition) => GoldenLayout.ContentItem | undefined;
3
- export declare const doShareEdge: (a: GoldenLayout.ContentItem, b: GoldenLayout.ContentItem, edge: OpenFin.LayoutPosition) => boolean;
3
+ export declare const doShareEdge: (from: GoldenLayout.ContentItem, to: GoldenLayout.ContentItem, edge: OpenFin.LayoutPosition) => boolean;
4
4
  export declare const getAdjacentStacks: (item: GoldenLayout.ContentItem, edge: OpenFin.LayoutPosition) => GoldenLayout.ContentItem[];
@@ -18,19 +18,19 @@ const getAdjacentItem = (component, edge) => {
18
18
  return (0, exports.getAdjacentItem)(parent, edge);
19
19
  };
20
20
  exports.getAdjacentItem = getAdjacentItem;
21
- const doShareEdge = (a, b, edge) => {
21
+ const doShareEdge = (from, to, edge) => {
22
22
  var _a, _b;
23
- const boundsA = (_a = a.element.get(0)) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
24
- const boundsB = (_b = b.element.get(0)) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect();
25
- if (!boundsA || !boundsB) {
23
+ const boundsFrom = (_a = from.element.get(0)) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
24
+ const boundsTo = (_b = to.element.get(0)) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect();
25
+ if (!boundsFrom || !boundsTo) {
26
26
  return false;
27
27
  }
28
28
  if (['top', 'bottom'].includes(edge)) {
29
- return ((boundsB.left >= boundsA.left && boundsB.left < boundsA.right) ||
30
- (boundsB.right > boundsA.left && boundsB.right <= boundsA.right));
29
+ const horizontallyOutOfBounds = boundsFrom.right < boundsTo.left || boundsFrom.left > boundsTo.right;
30
+ return !horizontallyOutOfBounds;
31
31
  }
32
- return ((boundsB.top >= boundsA.top && boundsB.top < boundsA.bottom) ||
33
- (boundsB.bottom > boundsA.top && boundsB.bottom <= boundsA.bottom));
32
+ const verticallyOutOfBounds = boundsFrom.bottom < boundsTo.top || boundsFrom.top > boundsTo.bottom;
33
+ return !verticallyOutOfBounds;
34
34
  };
35
35
  exports.doShareEdge = doShareEdge;
36
36
  const getAdjacentStacks = (item, edge) => {
@@ -0,0 +1,27 @@
1
+ import { Environment } from './environment';
2
+ import type * as OpenFin from '../OpenFin';
3
+ import { NewConnectConfig } from '../transport/wire';
4
+ import { EntityType } from '../OpenFin';
5
+ export declare class MockEnvironment implements Environment {
6
+ getDefaultChannelOptions(): {
7
+ create: OpenFin.ChannelCreateOptions;
8
+ connect: OpenFin.ChannelConnectOptions;
9
+ };
10
+ getRtcPeer(): RTCPeerConnection;
11
+ getManagerConstructor(): Promise<never>;
12
+ getProviderInitializer(): Promise<never>;
13
+ observeBounds(): never;
14
+ writeToken(path: string, token: string): Promise<string>;
15
+ retrievePort(config: NewConnectConfig): Promise<number>;
16
+ getNextMessageId(): string;
17
+ getRandomId(): string;
18
+ createChildContent(options: any): Promise<any>;
19
+ getWebWindow(identity: OpenFin.Identity): globalThis.Window;
20
+ getCurrentEntityIdentity(): OpenFin.EntityInfo;
21
+ getCurrentEntityType(): EntityType;
22
+ raiseEvent(eventName: string, eventArgs: any): void;
23
+ getUrl(): string;
24
+ whenReady(): Promise<void>;
25
+ childViews: boolean;
26
+ getWsConstructor(): any;
27
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockEnvironment = void 0;
4
+ const me_1 = require("../api/me");
5
+ class MockEnvironment {
6
+ constructor() {
7
+ this.childViews = true;
8
+ }
9
+ getDefaultChannelOptions() {
10
+ throw new Error(me_1.environmentUnsupportedMessage);
11
+ }
12
+ getRtcPeer() {
13
+ throw new Error(me_1.environmentUnsupportedMessage);
14
+ }
15
+ getManagerConstructor() {
16
+ throw new Error(me_1.environmentUnsupportedMessage);
17
+ }
18
+ getProviderInitializer() {
19
+ throw new Error(me_1.environmentUnsupportedMessage);
20
+ }
21
+ observeBounds() {
22
+ throw new Error(me_1.environmentUnsupportedMessage);
23
+ }
24
+ writeToken(path, token) {
25
+ throw new Error(me_1.environmentUnsupportedMessage);
26
+ }
27
+ retrievePort(config) {
28
+ throw new Error(me_1.environmentUnsupportedMessage);
29
+ }
30
+ getNextMessageId() {
31
+ throw new Error(me_1.environmentUnsupportedMessage);
32
+ }
33
+ getRandomId() {
34
+ throw new Error(me_1.environmentUnsupportedMessage);
35
+ }
36
+ createChildContent(options) {
37
+ throw new Error(me_1.environmentUnsupportedMessage);
38
+ }
39
+ getWebWindow(identity) {
40
+ throw new Error(me_1.environmentUnsupportedMessage);
41
+ }
42
+ getCurrentEntityIdentity() {
43
+ throw new Error(me_1.environmentUnsupportedMessage);
44
+ }
45
+ getCurrentEntityType() {
46
+ return 'unknown';
47
+ }
48
+ raiseEvent(eventName, eventArgs) {
49
+ throw new Error(me_1.environmentUnsupportedMessage);
50
+ }
51
+ getUrl() {
52
+ throw new Error(me_1.environmentUnsupportedMessage);
53
+ }
54
+ whenReady() {
55
+ throw new Error(me_1.environmentUnsupportedMessage);
56
+ }
57
+ getWsConstructor() {
58
+ throw new Error('Method not implemented.');
59
+ }
60
+ }
61
+ exports.MockEnvironment = MockEnvironment;
package/src/mock.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fin = void 0;
4
- const events_1 = require("events");
5
4
  /* eslint-disable import/prefer-default-export */
6
5
  /* eslint-disable spaced-comment */
7
6
  /* eslint-disable @typescript-eslint/triple-slash-reference */
@@ -10,82 +9,12 @@ const events_1 = require("events");
10
9
  /// <reference path="../OpenFin.d.ts"/>
11
10
  const fin_1 = require("./api/fin");
12
11
  const transport_1 = require("./transport/transport");
13
- const me_1 = require("./api/me");
14
- class MockWire extends events_1.EventEmitter {
15
- connect(address) {
16
- throw new Error('You are not running in OpenFin.');
17
- }
18
- connectSync() {
19
- throw new Error('You are not running in OpenFin.');
20
- }
21
- send(data) {
22
- throw new Error('You are not running in OpenFin.');
23
- }
24
- shutdown() {
25
- throw new Error('You are not running in OpenFin.');
26
- }
27
- // eslint-disable-next-line no-useless-constructor
28
- constructor() {
29
- super();
30
- }
31
- }
32
- class MockEnvironment {
33
- constructor() {
34
- this.childViews = true;
35
- }
36
- getDefaultChannelOptions() {
37
- throw new Error(me_1.environmentUnsupportedMessage);
38
- }
39
- getRtcPeer() {
40
- throw new Error(me_1.environmentUnsupportedMessage);
41
- }
42
- getManagerConstructor() {
43
- throw new Error(me_1.environmentUnsupportedMessage);
44
- }
45
- getProviderInitializer() {
46
- throw new Error(me_1.environmentUnsupportedMessage);
47
- }
48
- writeToken(path, token) {
49
- throw new Error(me_1.environmentUnsupportedMessage);
50
- }
51
- retrievePort(config) {
52
- throw new Error(me_1.environmentUnsupportedMessage);
53
- }
54
- getNextMessageId() {
55
- throw new Error(me_1.environmentUnsupportedMessage);
56
- }
57
- getRandomId() {
58
- throw new Error(me_1.environmentUnsupportedMessage);
59
- }
60
- createChildContent(options) {
61
- throw new Error(me_1.environmentUnsupportedMessage);
62
- }
63
- getWebWindow(identity) {
64
- throw new Error(me_1.environmentUnsupportedMessage);
65
- }
66
- getCurrentEntityIdentity() {
67
- throw new Error(me_1.environmentUnsupportedMessage);
68
- }
69
- getCurrentEntityType() {
70
- return 'unknown';
71
- }
72
- raiseEvent(eventName, eventArgs) {
73
- throw new Error(me_1.environmentUnsupportedMessage);
74
- }
75
- getUrl() {
76
- throw new Error(me_1.environmentUnsupportedMessage);
77
- }
78
- whenReady() {
79
- throw new Error(me_1.environmentUnsupportedMessage);
80
- }
81
- getWsConstructor() {
82
- throw new Error('Method not implemented.');
83
- }
84
- }
12
+ const mockEnvironment_1 = require("./environment/mockEnvironment");
13
+ const mockWire_1 = require("./transport/mockWire");
85
14
  exports.fin = ((typeof window !== 'undefined' && (window === null || window === void 0 ? void 0 : window.fin)) ||
86
15
  (() => {
87
- const environment = new MockEnvironment();
88
- const transport = new transport_1.Transport(MockWire, environment, {
16
+ const environment = new mockEnvironment_1.MockEnvironment();
17
+ const transport = new transport_1.Transport(mockWire_1.MockWire, environment, {
89
18
  uuid: '',
90
19
  name: ''
91
20
  });
@@ -66,10 +66,8 @@ export interface ProtocolMap extends ProtocolMapBase {
66
66
  };
67
67
  response: OpenFin.NativeWindowIntegrationProviderAuthorization;
68
68
  };
69
- 'get-permissions': {
70
- request: void;
71
- response: any;
72
- };
69
+ 'get-permissions': GetterCall<any>;
70
+ 'get-all-channels': GetterCall<OpenFin.ProviderIdentity[]>;
73
71
  'set-file-download-location': {
74
72
  request: OpenFin.ApplicationIdentity & {
75
73
  downloadLocation: string;
@@ -144,16 +142,14 @@ export interface ProtocolMap extends ProtocolMapBase {
144
142
  };
145
143
  response: void;
146
144
  };
147
- 'system-get-printers': {
148
- request: void;
149
- response: OpenFin.PrinterInfo[];
150
- };
145
+ 'system-get-printers': GetterCall<OpenFin.PrinterInfo[]>;
151
146
  }
152
147
  declare type ApiCall<Request, Response> = {
153
148
  request: Request;
154
149
  response: Response;
155
150
  };
156
151
  declare type VoidCall = ApiCall<void, void>;
152
+ declare type GetterCall<T> = ApiCall<void, T>;
157
153
  declare type IdentityCall<AdditionalPayload = {}, Response = void> = ApiCall<AdditionalPayload & OpenFin.Identity, Response>;
158
154
  interface ProtocolMapBase {
159
155
  [action: string]: {
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import { Wire } from './wire';
4
+ export declare class MockWire extends EventEmitter implements Wire {
5
+ connect(address: string): Promise<any>;
6
+ connectSync(): any;
7
+ send(data: any): Promise<any>;
8
+ shutdown(): Promise<void>;
9
+ getPort(): string;
10
+ constructor();
11
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockWire = void 0;
4
+ const events_1 = require("events");
5
+ class MockWire extends events_1.EventEmitter {
6
+ connect(address) {
7
+ throw new Error('You are not running in OpenFin.');
8
+ }
9
+ connectSync() {
10
+ throw new Error('You are not running in OpenFin.');
11
+ }
12
+ send(data) {
13
+ throw new Error('You are not running in OpenFin.');
14
+ }
15
+ shutdown() {
16
+ throw new Error('You are not running in OpenFin.');
17
+ }
18
+ getPort() {
19
+ throw new Error('This transport has no port');
20
+ }
21
+ // eslint-disable-next-line no-useless-constructor
22
+ constructor() {
23
+ super();
24
+ }
25
+ }
26
+ exports.MockWire = MockWire;
@@ -14,3 +14,21 @@ export declare class Lazy<T> {
14
14
  */
15
15
  getValue(): T;
16
16
  }
17
+ /**
18
+ * Handy class for managing asynchronous dependencies of classes.
19
+ *
20
+ * Will call asynchronous producer only after `getValue` is called. If the
21
+ * deferred code errors, we can try it again by re-calling `getValue` after
22
+ * the promise rejects.
23
+ */
24
+ export declare class AsyncRetryableLazy<T> {
25
+ private producerFn;
26
+ constructor(producerFn: () => Promise<T>);
27
+ private promise?;
28
+ /**
29
+ * Lazily get the value returned by the async producer.
30
+ *
31
+ * @returns The value returned from the producer function
32
+ */
33
+ getValue(): Promise<T>;
34
+ }
package/src/util/lazy.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Lazy = void 0;
3
+ exports.AsyncRetryableLazy = exports.Lazy = void 0;
4
4
  /**
5
5
  * Handy class for managing asynchronous dependencies of classes.
6
6
  *
@@ -24,3 +24,31 @@ class Lazy {
24
24
  }
25
25
  }
26
26
  exports.Lazy = Lazy;
27
+ /**
28
+ * Handy class for managing asynchronous dependencies of classes.
29
+ *
30
+ * Will call asynchronous producer only after `getValue` is called. If the
31
+ * deferred code errors, we can try it again by re-calling `getValue` after
32
+ * the promise rejects.
33
+ */
34
+ class AsyncRetryableLazy {
35
+ // eslint-disable-next-line
36
+ constructor(producerFn) {
37
+ this.producerFn = producerFn;
38
+ }
39
+ /**
40
+ * Lazily get the value returned by the async producer.
41
+ *
42
+ * @returns The value returned from the producer function
43
+ */
44
+ async getValue() {
45
+ if (!this.promise) {
46
+ this.promise = this.producerFn().catch((e) => {
47
+ delete this.promise;
48
+ throw e;
49
+ });
50
+ }
51
+ return this.promise;
52
+ }
53
+ }
54
+ exports.AsyncRetryableLazy = AsyncRetryableLazy;