insync-stage-handler 4.0.0-beta.1 → 4.0.0-beta.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/dist/module.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as R from 'ramda';
2
- import { flip, prop, path, curry, map as map$1, compose, indexBy, pipe, converge, pathOr, defaultTo, of, prepend, append, flatten, join, applyTo, assoc, dissocPath, filter, propSatisfies, startsWith, pair, replace, reduce, assocPath, tap, propOr, always, last, gte, nth, apply, nAry, unless } from 'ramda';
2
+ import { flip, prop, path, curry, map as map$1, compose, indexBy, pipe, converge, pathOr, defaultTo, hasPath, of, prepend, append, flatten, join, applyTo, assoc, dissocPath, filter, propSatisfies, startsWith, pair, replace, reduce, assocPath, tap, propOr, always, last, gte, nth, apply, nAry, unless } from 'ramda';
3
3
  import Ajv from 'ajv';
4
4
  import { formatWithOptions, parseISO } from 'date-fns/fp';
5
5
 
@@ -12,9 +12,23 @@ const listEntities = curry((entitiesContainerPath, from) => pipe(converge(lookup
12
12
 
13
13
  /**
14
14
  * Return the version of a stage object.
15
+ *
16
+ * Compatibility rule:
17
+ * Some legacy stages are marked as version 4 while still carrying
18
+ * Golden Layout data under layout.entities.layoutSections and no
19
+ * layout.dockviewLayout. Those need to pass through v3-to-v4.
20
+ *
15
21
  * @param {Object} stage The stage for which to return the version.
16
22
  */
17
- var detectVersion = pipe(prop("version"), defaultTo(1));
23
+ var detectVersion = (stage = {}) => {
24
+ const version = defaultTo(1)(prop("version", stage));
25
+ const hasLegacyLayoutSections = hasPath(["layout", "entities", "layoutSections", "byId"], stage);
26
+ const hasDockviewLayout = hasPath(["layout", "dockviewLayout"], stage);
27
+ if (version >= 4 && hasLegacyLayoutSections && !hasDockviewLayout) {
28
+ return 3;
29
+ }
30
+ return version;
31
+ };
18
32
 
19
33
  class ValidationError extends Error {
20
34
  setErrors(errors) {
@@ -3601,7 +3615,11 @@ const isComponentSection = section => {
3601
3615
  };
3602
3616
  const getRootSection = (content, sections) => {
3603
3617
  const rootId = getSectionId(content && content[0]);
3604
- return rootId ? sections[rootId] : undefined;
3618
+ if (rootId) {
3619
+ return sections[rootId];
3620
+ }
3621
+ const firstId = Object.keys(sections)[0];
3622
+ return firstId ? sections[firstId] : undefined;
3605
3623
  };
3606
3624
  const getOrientationForSection = section => {
3607
3625
  return (section === null || section === void 0 ? void 0 : section.type) === "row" ? DOCKVIEW_HORIZONTAL : DOCKVIEW_VERTICAL;
@@ -3640,6 +3658,19 @@ const createDockviewGroupId = section => {
3640
3658
  }
3641
3659
  return `${section.id}__group`;
3642
3660
  };
3661
+ const findFirstLeafGroupId = node => {
3662
+ if (!node) {
3663
+ return undefined;
3664
+ }
3665
+ if (node.type === "leaf") {
3666
+ var _node$data;
3667
+ return (_node$data = node.data) === null || _node$data === void 0 ? void 0 : _node$data.id;
3668
+ }
3669
+ if (!Array.isArray(node.data) || node.data.length === 0) {
3670
+ return undefined;
3671
+ }
3672
+ return findFirstLeafGroupId(node.data[0]);
3673
+ };
3643
3674
  const createDockviewLeaf = (section, sections) => {
3644
3675
  const childValues = section.type === "stack" ? section.content || [] : [section.id];
3645
3676
  const panelIds = childValues.map(getSectionId).filter(panelId => Boolean(sections[panelId]));
@@ -3701,7 +3732,6 @@ const createPanelsById = sections => {
3701
3732
  }, {}))(sections);
3702
3733
  };
3703
3734
  const convertLegacyLayoutToDockview = stage => {
3704
- var _rootSection$content;
3705
3735
  const content = R.path(["layout", "content"], stage);
3706
3736
  const rawSections = R.pathOr({}, ["layout", "entities", "layoutSections", "byId"], stage);
3707
3737
  const assetsById = R.pathOr({}, ["assets", "entities", "assets", "byId"], stage);
@@ -3719,7 +3749,7 @@ const convertLegacyLayoutToDockview = stage => {
3719
3749
  orientation: getOrientationForSection(rootSection)
3720
3750
  },
3721
3751
  panels: createPanelsById(sections),
3722
- activeGroup: createDockviewGroupId(rootSection.type === "stack" ? rootSection : getSection(sections, (_rootSection$content = rootSection.content) === null || _rootSection$content === void 0 ? void 0 : _rootSection$content[0]) || rootSection)
3752
+ activeGroup: findFirstLeafGroupId(rootNode)
3723
3753
  };
3724
3754
  };
3725
3755
  const upgradeToDockviewLayout = stage => {
@@ -3740,11 +3770,11 @@ const upgradeToDockviewLayout = stage => {
3740
3770
  R.when(R.hasPath(["layout", "focus"]), R.identity), R.when(R.hasPath(["layout", "dragging"]), R.identity), R.when(R.hasPath(["layout", "resizingPanels"]), R.identity))(stage);
3741
3771
  };
3742
3772
  const updateVersion$1 = R.assoc("version", 4);
3743
- var v3ToV4 = R.pipe(R.tap(stage => {
3773
+ var stageV3ToV4 = R.pipe(R.tap(stage => {
3744
3774
  console.log("upgrading ", stage, " from 3 to 4");
3745
3775
  }), upgradeToDockviewLayout, updateVersion$1);
3746
3776
 
3747
- var upgraders = () => [[2, v1ToV2], [3, v2ToV3$1], [4, v3ToV4]];
3777
+ var upgraders = () => [[2, v1ToV2], [3, v2ToV3$1], [4, stageV3ToV4]];
3748
3778
 
3749
3779
  const resolveFrom = stage => detectVersion(stage);
3750
3780
  const resolveTo = to => defaultTo(last(versions))(to);
@@ -3933,15 +3963,26 @@ var v2ToV3 = R.curry((stage, settings) => {
3933
3963
  }), R.pipe(removeOutlets, dataStreamsToMeasurements, updateVersion, scaleZoomSteps(stage), fixPanels, removeTimeline))(settings);
3934
3964
  });
3935
3965
 
3966
+ var v3ToV4 = (stage, settings) => stageV3ToV4(settings);
3967
+
3936
3968
  var settingsUpgrader = R.curry((stage, settings) => {
3937
- return R.pipe(R.unless(R.propEq(3, "version"), v2ToV3(stage)))(settings);
3969
+ const targetVersion = R.propOr(3, "version", stage);
3970
+ const getVersion = R.propOr(2, "version");
3971
+ let upgraded = settings;
3972
+ if (getVersion(upgraded) < 3 && targetVersion >= 3) {
3973
+ upgraded = v2ToV3(stage, upgraded);
3974
+ }
3975
+ if (getVersion(upgraded) < 4 && targetVersion >= 4) {
3976
+ upgraded = v3ToV4(stage, upgraded);
3977
+ }
3978
+ return upgraded;
3938
3979
  });
3939
3980
 
3940
3981
  const settingsCleaner = R.pipe(R.dissocPath(["timer", "wantedTime"]));
3941
3982
  var settingsHandler = (stage, settings) => R.pipe(settingsUpgrader(stage), settingsCleaner)(settings);
3942
3983
 
3943
3984
  var name = "insync-stage-handler";
3944
- var version = "4.0.0-beta.1";
3985
+ var version = "4.0.0-beta.2";
3945
3986
  var description = "Handles stages files. This consists of validating, upgrading and consolodating them.";
3946
3987
  var author = "David Ammeraal (Noterik B.V.)";
3947
3988
  var license = "MIT";