@interopio/workspaces-api 4.5.0 → 5.0.0-next.0

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.
@@ -930,6 +930,19 @@
930
930
  const subParentDecoder = oneOf(constant("row"), constant("column"), constant("group"));
931
931
  const frameStateDecoder = oneOf(constant("maximized"), constant("minimized"), constant("normal"));
932
932
  const loadingAnimationTypeDecoder = oneOf(constant("workspace"));
933
+ const appRestrictionRuleDecoder = object({
934
+ allowInApplicationPopup: optional(boolean()),
935
+ allowDrop: optional(boolean())
936
+ });
937
+ const appRestrictionEntryDecoder = object({
938
+ appName: nonEmptyStringDecoder,
939
+ allowInApplicationPopup: optional(boolean()),
940
+ allowDrop: optional(boolean())
941
+ });
942
+ const appRestrictionsDecoder = object({
943
+ apps: optional(array(appRestrictionEntryDecoder)),
944
+ default: optional(appRestrictionRuleDecoder)
945
+ });
933
946
  const checkThrowCallback = (callback, allowUndefined) => {
934
947
  const argumentType = typeof callback;
935
948
  if (allowUndefined && argumentType !== "function" && argumentType !== "undefined") {
@@ -945,6 +958,9 @@
945
958
  const deleteLayoutConfigDecoder = object({
946
959
  name: nonEmptyStringDecoder
947
960
  });
961
+ const deleteLayoutByIdConfigDecoder = object({
962
+ layoutId: nonEmptyStringDecoder
963
+ });
948
964
  const windowDefinitionConfigDecoder = object({
949
965
  minWidth: optional(number()),
950
966
  maxWidth: optional(number()),
@@ -1051,7 +1067,13 @@
1051
1067
  isPinned: optional(boolean()),
1052
1068
  isSelected: optional(boolean()),
1053
1069
  positionIndex: optional(nonNegativeNumberDecoder),
1054
- allowSystemHibernation: optional(boolean())
1070
+ allowSystemHibernation: optional(boolean()),
1071
+ }));
1072
+ const restoreWorkspaceByIdConfigDecoder = intersection(restoreWorkspaceConfigDecoder, object({
1073
+ layoutId: nonEmptyStringDecoder,
1074
+ }));
1075
+ const openWorkspaceByIdConfigDecoder = intersection(restoreWorkspaceConfigDecoder, object({
1076
+ layoutId: nonEmptyStringDecoder,
1055
1077
  }));
1056
1078
  const openWorkspaceConfigDecoder = object({
1057
1079
  name: nonEmptyStringDecoder,
@@ -1087,7 +1109,8 @@
1087
1109
  isPinned: optional(boolean()),
1088
1110
  isSelected: optional(boolean()),
1089
1111
  positionIndex: optional(nonNegativeNumberDecoder),
1090
- windowDragMode: optional(windowDragModeDecoder)
1112
+ windowDragMode: optional(windowDragModeDecoder),
1113
+ appRestrictions: optional(appRestrictionsDecoder)
1091
1114
  })),
1092
1115
  frame: optional(object({
1093
1116
  activate: optional(boolean()),
@@ -1103,6 +1126,10 @@
1103
1126
  name: nonEmptyStringDecoder,
1104
1127
  restoreOptions: optional(restoreWorkspaceConfigDecoder)
1105
1128
  });
1129
+ const restoreWorkspaceByIdDefinitionDecoder = object({
1130
+ id: nonEmptyStringDecoder,
1131
+ restoreOptions: optional(restoreWorkspaceConfigDecoder)
1132
+ });
1106
1133
  const emptyFrameDefinitionDecoder = optional(object({
1107
1134
  applicationName: optional(string()),
1108
1135
  frameConfig: optional(newFrameConfigDecoder),
@@ -1110,11 +1137,11 @@
1110
1137
  layoutComponentId: optional(nonEmptyStringDecoder)
1111
1138
  }));
1112
1139
  const frameInitConfigDecoder = object({
1113
- workspaces: array(oneOf(optional(workspaceDefinitionDecoder), optional(restoreWorkspaceDefinitionDecoder)))
1140
+ workspaces: array(oneOf(optional(workspaceDefinitionDecoder), optional(restoreWorkspaceDefinitionDecoder), optional(restoreWorkspaceByIdDefinitionDecoder)))
1114
1141
  });
1115
1142
  const frameInitProtocolConfigDecoder = object({
1116
1143
  frameId: nonEmptyStringDecoder,
1117
- workspaces: array(oneOf(workspaceDefinitionDecoder, restoreWorkspaceDefinitionDecoder))
1144
+ workspaces: array(oneOf(workspaceDefinitionDecoder, restoreWorkspaceDefinitionDecoder, restoreWorkspaceByIdDefinitionDecoder))
1118
1145
  });
1119
1146
  const builderConfigDecoder = object({
1120
1147
  type: allParentDecoder,
@@ -1155,6 +1182,7 @@
1155
1182
  title: nonEmptyStringDecoder,
1156
1183
  positionIndex: nonNegativeNumberDecoder,
1157
1184
  name: nonEmptyStringDecoder,
1185
+ layoutId: optional(nonEmptyStringDecoder),
1158
1186
  layoutName: optional(nonEmptyStringDecoder),
1159
1187
  isHibernated: optional(boolean()),
1160
1188
  isSelected: optional(boolean()),
@@ -1182,7 +1210,8 @@
1182
1210
  heightInPx: optional(number()),
1183
1211
  isPinned: optional(boolean()),
1184
1212
  windowDragMode: optional(windowDragModeDecoder),
1185
- loadingStrategy: optional(loadingStrategyDecoder)
1213
+ loadingStrategy: optional(loadingStrategyDecoder),
1214
+ appRestrictions: optional(appRestrictionsDecoder)
1186
1215
  });
1187
1216
  const baseChildSnapshotConfigDecoder = object({
1188
1217
  frameId: nonEmptyStringDecoder,
@@ -1267,6 +1296,7 @@
1267
1296
  children: array(oneOf(columnLayoutItemDecoder, groupLayoutItemDecoder, windowLayoutItemDecoder, lazy(() => rowLayoutItemDecoder)))
1268
1297
  });
1269
1298
  const workspaceLayoutDecoder = object({
1299
+ id: optional(nonEmptyStringDecoder),
1270
1300
  name: nonEmptyStringDecoder,
1271
1301
  type: constant("Workspace"),
1272
1302
  metadata: optional(anyJson()),
@@ -1313,6 +1343,7 @@
1313
1343
  workspaces: array(workspaceSnapshotResultDecoder)
1314
1344
  });
1315
1345
  const layoutSummaryDecoder = object({
1346
+ id: optional(nonEmptyStringDecoder),
1316
1347
  name: nonEmptyStringDecoder,
1317
1348
  applicationName: optional(string())
1318
1349
  });
@@ -1441,6 +1472,16 @@
1441
1472
  })
1442
1473
  });
1443
1474
  const workspaceLayoutSaveConfigDecoder = object({
1475
+ id: optional(nonEmptyStringDecoder),
1476
+ name: nonEmptyStringDecoder,
1477
+ workspaceId: nonEmptyStringDecoder,
1478
+ saveContext: optional(boolean()),
1479
+ allowMultiple: optional(boolean()),
1480
+ metadata: optional(object()),
1481
+ saveWindowContexts: optional(boolean())
1482
+ });
1483
+ const workspaceLayoutSaveByIdConfigDecoder = object({
1484
+ id: optional(nonEmptyStringDecoder),
1444
1485
  name: nonEmptyStringDecoder,
1445
1486
  workspaceId: nonEmptyStringDecoder,
1446
1487
  saveContext: optional(boolean()),
@@ -1677,9 +1718,12 @@
1677
1718
  getAllWorkspacesSummaries: { name: "getAllWorkspacesSummaries", resultDecoder: workspaceSummariesResultDecoder },
1678
1719
  getWorkspaceSnapshot: { name: "getWorkspaceSnapshot", resultDecoder: workspaceSnapshotResultDecoder, argsDecoder: simpleItemConfigDecoder },
1679
1720
  getAllLayoutsSummaries: { name: "getAllLayoutsSummaries", resultDecoder: layoutSummariesDecoder },
1721
+ openWorkspaceById: { name: "openWorkspaceById", argsDecoder: openWorkspaceByIdConfigDecoder, resultDecoder: workspaceSnapshotResultDecoder },
1680
1722
  openWorkspace: { name: "openWorkspace", argsDecoder: openWorkspaceConfigDecoder, resultDecoder: workspaceSnapshotResultDecoder },
1681
1723
  deleteLayout: { name: "deleteLayout", resultDecoder: voidResultDecoder, argsDecoder: deleteLayoutConfigDecoder },
1724
+ deleteLayoutById: { name: "deleteLayoutById", resultDecoder: voidResultDecoder, argsDecoder: deleteLayoutByIdConfigDecoder },
1682
1725
  saveLayout: { name: "saveLayout", resultDecoder: workspaceLayoutDecoder, argsDecoder: workspaceLayoutSaveConfigDecoder },
1726
+ saveLayoutById: { name: "saveLayoutById", resultDecoder: workspaceLayoutDecoder, argsDecoder: workspaceLayoutSaveByIdConfigDecoder },
1683
1727
  importLayout: { name: "importLayout", resultDecoder: voidResultDecoder, argsDecoder: workspacesImportLayoutDecoder },
1684
1728
  importLayouts: { name: "importLayouts", resultDecoder: voidResultDecoder, argsDecoder: workspacesImportLayoutsDecoder },
1685
1729
  exportAllLayouts: { name: "exportAllLayouts", resultDecoder: exportedLayoutsResultDecoder },
@@ -2747,6 +2791,9 @@
2747
2791
  get title() {
2748
2792
  return getData$3(this).config.title;
2749
2793
  }
2794
+ get layoutId() {
2795
+ return getData$3(this).config.layoutId;
2796
+ }
2750
2797
  get layoutName() {
2751
2798
  return getData$3(this).config.layoutName;
2752
2799
  }
@@ -2789,6 +2836,9 @@
2789
2836
  get allowWindowReorder() {
2790
2837
  return getData$3(this).config.allowWindowReorder;
2791
2838
  }
2839
+ get appRestrictions() {
2840
+ return getData$3(this).config.appRestrictions;
2841
+ }
2792
2842
  get showCloseButton() {
2793
2843
  return getData$3(this).config.showCloseButton;
2794
2844
  }
@@ -4303,11 +4353,13 @@
4303
4353
  windows;
4304
4354
  contexts;
4305
4355
  layouts;
4306
- constructor(ioc, windows, contexts, layouts) {
4356
+ layoutsV2;
4357
+ constructor(ioc, windows, contexts, layouts, layoutsV2) {
4307
4358
  this.ioc = ioc;
4308
4359
  this.windows = windows;
4309
4360
  this.contexts = contexts;
4310
4361
  this.layouts = layouts;
4362
+ this.layoutsV2 = layoutsV2;
4311
4363
  }
4312
4364
  get bridge() {
4313
4365
  return this.ioc.bridge;
@@ -4337,6 +4389,16 @@
4337
4389
  async initFrame(frameId, config) {
4338
4390
  await this.bridge.send(OPERATIONS.initFrame.name, { frameId, ...config });
4339
4391
  }
4392
+ async restoreWorkspaceById(options) {
4393
+ const snapshot = await this.bridge.send(OPERATIONS.openWorkspaceById.name, { ...options });
4394
+ const frameSummary = await this.bridge.send(OPERATIONS.getFrameSummary.name, { itemId: snapshot.config.frameId });
4395
+ const frameConfig = {
4396
+ summary: frameSummary
4397
+ };
4398
+ const frame = this.ioc.getModel("frame", frameConfig);
4399
+ const workspaceConfig = { frame, snapshot };
4400
+ return this.ioc.getModel("workspace", workspaceConfig);
4401
+ }
4340
4402
  async restoreWorkspace(name, options) {
4341
4403
  const snapshot = await this.bridge.send(OPERATIONS.openWorkspace.name, { name, restoreOptions: options });
4342
4404
  const frameSummary = await this.bridge.send(OPERATIONS.getFrameSummary.name, { itemId: snapshot.config.frameId });
@@ -4389,13 +4451,20 @@
4389
4451
  return Object.assign({}, { id: summary.id, width: summary.config.widthInPx, height: summary.config.heightInPx }, summary.config);
4390
4452
  });
4391
4453
  }
4392
- handleOnSaved(callback) {
4454
+ async handleOnSaved(callback) {
4393
4455
  const wrappedCallback = (layout) => {
4394
4456
  if (layout.type !== "Workspace") {
4395
4457
  return;
4396
4458
  }
4397
4459
  callback(layout);
4398
4460
  };
4461
+ if (this.layoutsV2) {
4462
+ const [addedUnSub, changedUnSub] = await Promise.all([this.layoutsV2.onAdded(wrappedCallback), this.layoutsV2.onChanged(wrappedCallback)]);
4463
+ return () => {
4464
+ addedUnSub();
4465
+ changedUnSub();
4466
+ };
4467
+ }
4399
4468
  const addedUnSub = this.layouts.onAdded(wrappedCallback);
4400
4469
  const changedUnSub = this.layouts.onChanged(wrappedCallback);
4401
4470
  return () => {
@@ -4403,13 +4472,16 @@
4403
4472
  changedUnSub();
4404
4473
  };
4405
4474
  }
4406
- handleOnRemoved(callback) {
4475
+ async handleOnRemoved(callback) {
4407
4476
  const wrappedCallback = (layout) => {
4408
4477
  if (layout.type !== "Workspace") {
4409
4478
  return;
4410
4479
  }
4411
4480
  callback(layout);
4412
4481
  };
4482
+ if (this.layoutsV2) {
4483
+ return this.layoutsV2.onRemoved(wrappedCallback);
4484
+ }
4413
4485
  return this.layouts.onRemoved(wrappedCallback);
4414
4486
  }
4415
4487
  async importLayouts(layouts, mode) {
@@ -4733,6 +4805,21 @@
4733
4805
  async initFrame(frameId, config) {
4734
4806
  return this.base.initFrame(frameId, config);
4735
4807
  }
4808
+ async restoreWorkspaceById(options) {
4809
+ const allLayouts = await this.getLayoutSummaries();
4810
+ const layoutExists = allLayouts.some((summary) => summary.id === options.layoutId);
4811
+ if (!layoutExists) {
4812
+ throw new Error(`This layout: ${options.layoutId} cannot be restored, because it doesn't exist.`);
4813
+ }
4814
+ if (options?.frameId) {
4815
+ const allFrameSummaries = await this.bridge.send(OPERATIONS.getAllFramesSummaries.name);
4816
+ const foundMatchingFrame = allFrameSummaries.summaries.some((summary) => summary.id === options.frameId);
4817
+ if (!foundMatchingFrame) {
4818
+ throw new Error(`Cannot reuse the frame with id: ${options.frameId}, because there is no frame with that ID found`);
4819
+ }
4820
+ }
4821
+ return await this.base.restoreWorkspaceById(options);
4822
+ }
4736
4823
  async restoreWorkspace(name, options) {
4737
4824
  const allLayouts = await this.getLayoutSummaries();
4738
4825
  const layoutExists = allLayouts.some((summary) => summary.name === name);
@@ -4851,6 +4938,9 @@
4851
4938
  async deleteLayout(name) {
4852
4939
  await this.bridge.send(OPERATIONS.deleteLayout.name, { name });
4853
4940
  }
4941
+ async deleteLayoutById(layoutId) {
4942
+ await this.bridge.send(OPERATIONS.deleteLayoutById.name, { layoutId });
4943
+ }
4854
4944
  async exportLayout(predicate) {
4855
4945
  const allLayoutsResult = await this.bridge.send(OPERATIONS.exportAllLayouts.name);
4856
4946
  return allLayoutsResult.layouts.reduce((matchingLayouts, layout) => {
@@ -4863,6 +4953,9 @@
4863
4953
  async saveLayout(config) {
4864
4954
  return await this.bridge.send(OPERATIONS.saveLayout.name, config);
4865
4955
  }
4956
+ async saveLayoutById(config) {
4957
+ return await this.bridge.send(OPERATIONS.saveLayoutById.name, config);
4958
+ }
4866
4959
  async importLayouts(layouts, mode) {
4867
4960
  if (isDesktop()) {
4868
4961
  try {
@@ -4875,10 +4968,10 @@
4875
4968
  }
4876
4969
  await this.base.importLayouts(layouts, mode);
4877
4970
  }
4878
- handleOnSaved(callback) {
4971
+ async handleOnSaved(callback) {
4879
4972
  return this.base.handleOnSaved(callback);
4880
4973
  }
4881
- handleOnRemoved(callback) {
4974
+ async handleOnRemoved(callback) {
4882
4975
  return this.base.handleOnRemoved(callback);
4883
4976
  }
4884
4977
  async bundleWorkspaceTo(type, workspaceId) {
@@ -5199,6 +5292,7 @@
5199
5292
  windows;
5200
5293
  layouts;
5201
5294
  contexts;
5295
+ layoutsV2;
5202
5296
  _controllerInstance;
5203
5297
  _bridgeInstance;
5204
5298
  _transportInstance;
@@ -5207,15 +5301,16 @@
5207
5301
  _baseController;
5208
5302
  _shortcutsController;
5209
5303
  _closingController;
5210
- constructor(agm, windows, layouts, contexts) {
5304
+ constructor(agm, windows, layouts, contexts, layoutsV2) {
5211
5305
  this.agm = agm;
5212
5306
  this.windows = windows;
5213
5307
  this.layouts = layouts;
5214
5308
  this.contexts = contexts;
5309
+ this.layoutsV2 = layoutsV2;
5215
5310
  }
5216
5311
  get baseController() {
5217
5312
  if (!this._baseController) {
5218
- this._baseController = new BaseController(this, this.windows, this.contexts, this.layouts);
5313
+ this._baseController = new BaseController(this, this.windows, this.contexts, this.layouts, this.layoutsV2);
5219
5314
  }
5220
5315
  return this._baseController;
5221
5316
  }
@@ -5370,7 +5465,7 @@
5370
5465
  }
5371
5466
  }
5372
5467
 
5373
- var version = "4.5.0";
5468
+ var version = "5.0.0-next.0";
5374
5469
 
5375
5470
  const composeAPI = (glue, ioc) => {
5376
5471
  const controller = ioc.controller;
@@ -5438,6 +5533,10 @@
5438
5533
  checkThrowCallback(predicate);
5439
5534
  return controller.getParent(predicate);
5440
5535
  };
5536
+ const restoreWorkspaceById = async (options) => {
5537
+ const validatedOptions = restoreWorkspaceByIdConfigDecoder.runWithException(options);
5538
+ return controller.restoreWorkspaceById(validatedOptions);
5539
+ };
5441
5540
  const restoreWorkspace = async (name, options) => {
5442
5541
  nonEmptyStringDecoder.runWithException(name);
5443
5542
  const validatedOptions = restoreWorkspaceConfigDecoder.runWithException(options);
@@ -5460,6 +5559,10 @@
5460
5559
  nonEmptyStringDecoder.runWithException(name);
5461
5560
  return controller.deleteLayout(name);
5462
5561
  },
5562
+ deleteById: async (layoutId) => {
5563
+ nonEmptyStringDecoder.runWithException(layoutId);
5564
+ return controller.deleteLayoutById(layoutId);
5565
+ },
5463
5566
  export: async (predicate) => {
5464
5567
  checkThrowCallback(predicate, true);
5465
5568
  return controller.exportLayout(predicate);
@@ -5475,6 +5578,10 @@
5475
5578
  const verifiedConfig = workspaceLayoutSaveConfigDecoder.runWithException(config);
5476
5579
  return controller.saveLayout(verifiedConfig);
5477
5580
  },
5581
+ saveById: async (config) => {
5582
+ const verifiedConfig = workspaceLayoutSaveByIdConfigDecoder.runWithException(config);
5583
+ return controller.saveLayoutById(verifiedConfig);
5584
+ },
5478
5585
  onSaved: async (callback) => {
5479
5586
  checkThrowCallback(callback);
5480
5587
  return controller.handleOnSaved(callback);
@@ -5694,6 +5801,7 @@
5694
5801
  getWindow,
5695
5802
  getBox: getParent,
5696
5803
  restoreWorkspace,
5804
+ restoreWorkspaceById,
5697
5805
  createWorkspace,
5698
5806
  createEmptyFrame,
5699
5807
  waitForFrame,
@@ -5717,7 +5825,7 @@
5717
5825
  };
5718
5826
 
5719
5827
  const factoryFunction = async (io) => {
5720
- const ioc = new IoC(io.agm, io.windows, io.layouts, io.contexts);
5828
+ const ioc = new IoC(io.agm, io.windows, io.layouts, io.contexts, io.layouts.v2);
5721
5829
  const actualWindowId = io.interop.instance.windowId;
5722
5830
  await ioc.initiate(actualWindowId);
5723
5831
  io.workspaces = composeAPI(io, ioc);