insync-stage-handler 4.0.0-beta.2 → 4.0.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.
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) {
@@ -3562,10 +3576,10 @@ const scaleZoomSteps$1 = stage => {
3562
3576
  zoomSteps: rest.zoomStepsIsScaled ? zoomSteps : zoomSteps.map(step => step * Math.sqrt(measurementScale))
3563
3577
  }))))(stage);
3564
3578
  };
3565
- const updateVersion$3 = R.assoc("version", 3);
3579
+ const updateVersion$2 = R.assoc("version", 3);
3566
3580
  var v2ToV3$1 = R.pipe(R.tap(stage => {
3567
3581
  console.log("upgrading ", stage, " from 2 to 3");
3568
- }), consolidate, R.unless(R.prop("error"), R.pipe(R.prop("stage"), removeOutlets$1, scaleZoomSteps$1, dataStreamsToMeasurements$1, createTimingSlice, createTimelineSlice, createFilesTimings, createComments, createCommentsTimings, createTimelineGroups, createTimeline, fixTracks, updateVersion$3, fixPanels$1, upgradeResources)));
3582
+ }), consolidate, R.unless(R.prop("error"), R.pipe(R.prop("stage"), removeOutlets$1, scaleZoomSteps$1, dataStreamsToMeasurements$1, createTimingSlice, createTimelineSlice, createFilesTimings, createComments, createCommentsTimings, createTimelineGroups, createTimeline, fixTracks, updateVersion$2, fixPanels$1, upgradeResources)));
3569
3583
 
3570
3584
  /**
3571
3585
  * v3-to-v4 Stage Upgrader
@@ -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]));
@@ -3683,6 +3714,19 @@ const createDockviewGridNode = (section, sections) => {
3683
3714
  data: children
3684
3715
  };
3685
3716
  };
3717
+ const ensureBranchRoot = node => {
3718
+ if (!node || node.type !== "leaf") {
3719
+ return node;
3720
+ }
3721
+ return {
3722
+ type: "branch",
3723
+ size: 100,
3724
+ data: [{
3725
+ ...node,
3726
+ size: 100
3727
+ }]
3728
+ };
3729
+ };
3686
3730
  const filterLayoutSectionsByAssets = (sectionsById, assetsById) => {
3687
3731
  return R.pipe(R.map(section => {
3688
3732
  const assetId = R.path(["props", "assetId"], section);
@@ -3701,25 +3745,25 @@ const createPanelsById = sections => {
3701
3745
  }, {}))(sections);
3702
3746
  };
3703
3747
  const convertLegacyLayoutToDockview = stage => {
3704
- var _rootSection$content;
3705
3748
  const content = R.path(["layout", "content"], stage);
3706
3749
  const rawSections = R.pathOr({}, ["layout", "entities", "layoutSections", "byId"], stage);
3707
3750
  const assetsById = R.pathOr({}, ["assets", "entities", "assets", "byId"], stage);
3708
3751
  const sections = filterLayoutSectionsByAssets(rawSections, assetsById);
3709
3752
  const rootSection = getRootSection(content, sections);
3710
3753
  const rootNode = createDockviewGridNode(rootSection, sections);
3711
- if (!rootSection || !rootNode) {
3754
+ const dockviewRoot = ensureBranchRoot(rootNode);
3755
+ if (!rootSection || !dockviewRoot) {
3712
3756
  return null;
3713
3757
  }
3714
3758
  return {
3715
3759
  grid: {
3716
- root: rootNode,
3760
+ root: dockviewRoot,
3717
3761
  height: 100,
3718
3762
  width: 100,
3719
3763
  orientation: getOrientationForSection(rootSection)
3720
3764
  },
3721
3765
  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)
3766
+ activeGroup: findFirstLeafGroupId(rootNode)
3723
3767
  };
3724
3768
  };
3725
3769
  const upgradeToDockviewLayout = stage => {
@@ -3739,12 +3783,12 @@ const upgradeToDockviewLayout = stage => {
3739
3783
  // Preserve these layout state properties if they exist
3740
3784
  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
3785
  };
3742
- const updateVersion$2 = R.assoc("version", 4);
3743
- var v3ToV4$1 = R.pipe(R.tap(stage => {
3786
+ const updateVersion$1 = R.assoc("version", 4);
3787
+ var stageV3ToV4 = R.pipe(R.tap(stage => {
3744
3788
  console.log("upgrading ", stage, " from 3 to 4");
3745
- }), upgradeToDockviewLayout, updateVersion$2);
3789
+ }), upgradeToDockviewLayout, updateVersion$1);
3746
3790
 
3747
- var upgraders = () => [[2, v1ToV2], [3, v2ToV3$1], [4, v3ToV4$1]];
3791
+ var upgraders = () => [[2, v1ToV2], [3, v2ToV3$1], [4, stageV3ToV4]];
3748
3792
 
3749
3793
  const resolveFrom = stage => detectVersion(stage);
3750
3794
  const resolveTo = to => defaultTo(last(versions))(to);
@@ -3926,19 +3970,14 @@ const scaleZoomSteps = stage => settings => {
3926
3970
  }))))(settings);
3927
3971
  };
3928
3972
  const removeTimeline = R.dissoc("timeline");
3929
- const updateVersion$1 = R.assoc("version", 3);
3973
+ const updateVersion = R.assoc("version", 3);
3930
3974
  var v2ToV3 = R.curry((stage, settings) => {
3931
3975
  return R.pipe(R.tap(s => {
3932
3976
  console.log("upgrading settings", s, " from 2 to 3");
3933
- }), R.pipe(removeOutlets, dataStreamsToMeasurements, updateVersion$1, scaleZoomSteps(stage), fixPanels, removeTimeline))(settings);
3977
+ }), R.pipe(removeOutlets, dataStreamsToMeasurements, updateVersion, scaleZoomSteps(stage), fixPanels, removeTimeline))(settings);
3934
3978
  });
3935
3979
 
3936
- const updateVersion = R.assoc("version", 4);
3937
- var v3ToV4 = R.curry((stage, settings) => {
3938
- return R.pipe(R.tap(s => {
3939
- console.log("upgrading settings", s, " from 3 to 4", stage.version);
3940
- }), updateVersion)(settings);
3941
- });
3980
+ var v3ToV4 = (stage, settings) => stageV3ToV4(settings);
3942
3981
 
3943
3982
  var settingsUpgrader = R.curry((stage, settings) => {
3944
3983
  const targetVersion = R.propOr(3, "version", stage);
@@ -3957,7 +3996,7 @@ const settingsCleaner = R.pipe(R.dissocPath(["timer", "wantedTime"]));
3957
3996
  var settingsHandler = (stage, settings) => R.pipe(settingsUpgrader(stage), settingsCleaner)(settings);
3958
3997
 
3959
3998
  var name = "insync-stage-handler";
3960
- var version = "4.0.0-beta.2";
3999
+ var version = "4.0.0";
3961
4000
  var description = "Handles stages files. This consists of validating, upgrading and consolodating them.";
3962
4001
  var author = "David Ammeraal (Noterik B.V.)";
3963
4002
  var license = "MIT";