@beinformed/ui 1.54.0 → 1.54.2

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/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [1.54.2](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.54.1...v1.54.2) (2024-09-17)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **layouthint-config:** merge duplicate hint entries ([29b837c](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/29b837c83d991d6f5dada5f6cd0eb165abdbd2eb))
11
+
12
+ ## [1.54.1](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.54.0...v1.54.1) (2024-09-17)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **flowtype:** make expectedModels optional ([ebb6953](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/ebb6953be1e96ed9aebf31d3997ba5fe684f1c10))
18
+
5
19
  ## [1.54.0](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.53.0...v1.54.0) (2024-09-17)
6
20
 
7
21
 
@@ -1,5 +1,5 @@
1
1
  import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
2
- import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
2
+ import _Set from "@babel/runtime-corejs3/core-js-stable/set";
3
3
  import _JSON$stringify from "@babel/runtime-corejs3/core-js-stable/json/stringify";
4
4
  import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
5
5
  const path = require("path");
@@ -9,6 +9,7 @@ const {
9
9
  readFileSync,
10
10
  writeFileSync
11
11
  } = require("fs");
12
+ const mergeWith = require("lodash/mergeWith");
12
13
  const {
13
14
  LayoutHintConfiguration
14
15
  } = require("../constants/LayoutHintConfig");
@@ -42,7 +43,14 @@ exports.mergeLayoutHintConfigurations = async (srcFolder, outputFolder) => {
42
43
  const content = readFileSync(file, "utf-8");
43
44
  return JSON.parse(content);
44
45
  });
45
- const newConfig = _Object$assign(LayoutHintConfiguration, ...jsons);
46
+
47
+ // Function to merge arrays during merging
48
+ const customizer = (objValue, srcValue) => {
49
+ if (Array.isArray(objValue)) {
50
+ return [...new _Set([...objValue, ...srcValue])];
51
+ }
52
+ };
53
+ const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);
46
54
  writeFileSync(path.join(outputFolder, "LayoutHintConfig.json"), _JSON$stringify(newConfig));
47
55
  return _Promise.resolve();
48
56
  };
@@ -1 +1 @@
1
- {"version":3,"file":"mergeLayoutHintConfigurations.js","names":["path","require","readdirSync","statSync","readFileSync","writeFileSync","LayoutHintConfiguration","findFiles","dir","matchedFiles","files","file","absolute","join","isDirectory","foundFiles","push","filename","basename","exports","mergeLayoutHintConfigurations","srcFolder","outputFolder","escapedSrcFolder","replace","jsons","_mapInstanceProperty","call","content","JSON","parse","newConfig","_Object$assign","_JSON$stringify","_Promise","resolve"],"sources":["../../src/builder/mergeLayoutHintConfigurations.js"],"sourcesContent":["// @flow\nconst path = require(\"path\");\nconst { readdirSync, statSync, readFileSync, writeFileSync } = require(\"fs\");\n\nconst { LayoutHintConfiguration } = require(\"../constants/LayoutHintConfig\");\n\nconst findFiles = (dir: string): Array<string> => {\n const matchedFiles = [];\n\n const files = readdirSync(dir);\n\n for (const file of files) {\n const absolute = path.join(dir, file);\n if (statSync(absolute).isDirectory()) {\n const foundFiles = findFiles(absolute);\n matchedFiles.push(...foundFiles);\n } else {\n const filename = path.basename(file);\n if (filename === \"LayoutHintConfig.json\") {\n matchedFiles.push(absolute);\n }\n }\n }\n\n return matchedFiles;\n};\n\n/**\n * Merge all LayoutHintConfig.json files from this library and in the srcFolder\n * together into one config file, and copies it to the outputFolder.<br/>\n * This file is consumed by Be Informed studio to give layout hint information\n */\nexports.mergeLayoutHintConfigurations = async (\n srcFolder: string,\n outputFolder: string,\n): Promise<void> => {\n const escapedSrcFolder = srcFolder.replace(/\\\\/g, \"/\");\n\n const files = findFiles(escapedSrcFolder);\n\n const jsons = files.map((file) => {\n const content = readFileSync(file, \"utf-8\");\n return JSON.parse(content);\n });\n\n const newConfig = Object.assign(LayoutHintConfiguration, ...jsons);\n\n writeFileSync(\n path.join(outputFolder, \"LayoutHintConfig.json\"),\n JSON.stringify(newConfig),\n );\n\n return Promise.resolve();\n};\n"],"mappings":";;;;AACA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAM,CAAC;AAC5B,MAAM;EAAEC,WAAW;EAAEC,QAAQ;EAAEC,YAAY;EAAEC;AAAc,CAAC,GAAGJ,OAAO,CAAC,IAAI,CAAC;AAE5E,MAAM;EAAEK;AAAwB,CAAC,GAAGL,OAAO,CAAC,+BAA+B,CAAC;AAE5E,MAAMM,SAAS,GAAIC,GAAW,IAAoB;EAChD,MAAMC,YAAY,GAAG,EAAE;EAEvB,MAAMC,KAAK,GAAGR,WAAW,CAACM,GAAG,CAAC;EAE9B,KAAK,MAAMG,IAAI,IAAID,KAAK,EAAE;IACxB,MAAME,QAAQ,GAAGZ,IAAI,CAACa,IAAI,CAACL,GAAG,EAAEG,IAAI,CAAC;IACrC,IAAIR,QAAQ,CAACS,QAAQ,CAAC,CAACE,WAAW,CAAC,CAAC,EAAE;MACpC,MAAMC,UAAU,GAAGR,SAAS,CAACK,QAAQ,CAAC;MACtCH,YAAY,CAACO,IAAI,CAAC,GAAGD,UAAU,CAAC;IAClC,CAAC,MAAM;MACL,MAAME,QAAQ,GAAGjB,IAAI,CAACkB,QAAQ,CAACP,IAAI,CAAC;MACpC,IAAIM,QAAQ,KAAK,uBAAuB,EAAE;QACxCR,YAAY,CAACO,IAAI,CAACJ,QAAQ,CAAC;MAC7B;IACF;EACF;EAEA,OAAOH,YAAY;AACrB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACAU,OAAO,CAACC,6BAA6B,GAAG,OACtCC,SAAiB,EACjBC,YAAoB,KACF;EAClB,MAAMC,gBAAgB,GAAGF,SAAS,CAACG,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;EAEtD,MAAMd,KAAK,GAAGH,SAAS,CAACgB,gBAAgB,CAAC;EAEzC,MAAME,KAAK,GAAGC,oBAAA,CAAAhB,KAAK,EAAAiB,IAAA,CAALjB,KAAK,EAAMC,IAAI,IAAK;IAChC,MAAMiB,OAAO,GAAGxB,YAAY,CAACO,IAAI,EAAE,OAAO,CAAC;IAC3C,OAAOkB,IAAI,CAACC,KAAK,CAACF,OAAO,CAAC;EAC5B,CAAC,CAAC;EAEF,MAAMG,SAAS,GAAGC,cAAA,CAAc1B,uBAAuB,EAAE,GAAGmB,KAAK,CAAC;EAElEpB,aAAa,CACXL,IAAI,CAACa,IAAI,CAACS,YAAY,EAAE,uBAAuB,CAAC,EAChDW,eAAA,CAAeF,SAAS,CAC1B,CAAC;EAED,OAAOG,QAAA,CAAQC,OAAO,CAAC,CAAC;AAC1B,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"mergeLayoutHintConfigurations.js","names":["path","require","readdirSync","statSync","readFileSync","writeFileSync","mergeWith","LayoutHintConfiguration","findFiles","dir","matchedFiles","files","file","absolute","join","isDirectory","foundFiles","push","filename","basename","exports","mergeLayoutHintConfigurations","srcFolder","outputFolder","escapedSrcFolder","replace","jsons","_mapInstanceProperty","call","content","JSON","parse","customizer","objValue","srcValue","Array","isArray","_Set","newConfig","_JSON$stringify","_Promise","resolve"],"sources":["../../src/builder/mergeLayoutHintConfigurations.js"],"sourcesContent":["// @flow\nconst path = require(\"path\");\nconst { readdirSync, statSync, readFileSync, writeFileSync } = require(\"fs\");\n\nconst mergeWith = require(\"lodash/mergeWith\");\nconst { LayoutHintConfiguration } = require(\"../constants/LayoutHintConfig\");\n\nconst findFiles = (dir: string): Array<string> => {\n const matchedFiles = [];\n\n const files = readdirSync(dir);\n\n for (const file of files) {\n const absolute = path.join(dir, file);\n if (statSync(absolute).isDirectory()) {\n const foundFiles = findFiles(absolute);\n matchedFiles.push(...foundFiles);\n } else {\n const filename = path.basename(file);\n if (filename === \"LayoutHintConfig.json\") {\n matchedFiles.push(absolute);\n }\n }\n }\n\n return matchedFiles;\n};\n\n/**\n * Merge all LayoutHintConfig.json files from this library and in the srcFolder\n * together into one config file, and copies it to the outputFolder.<br/>\n * This file is consumed by Be Informed studio to give layout hint information\n */\nexports.mergeLayoutHintConfigurations = async (\n srcFolder: string,\n outputFolder: string,\n): Promise<void> => {\n const escapedSrcFolder = srcFolder.replace(/\\\\/g, \"/\");\n\n const files = findFiles(escapedSrcFolder);\n\n const jsons = files.map((file) => {\n const content = readFileSync(file, \"utf-8\");\n return JSON.parse(content);\n });\n\n // Function to merge arrays during merging\n const customizer = (objValue: Object, srcValue: Object): Object => {\n if (Array.isArray(objValue)) {\n return [...new Set([...objValue, ...srcValue])];\n }\n };\n\n const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);\n\n writeFileSync(\n path.join(outputFolder, \"LayoutHintConfig.json\"),\n JSON.stringify(newConfig),\n );\n\n return Promise.resolve();\n};\n"],"mappings":";;;;AACA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAM,CAAC;AAC5B,MAAM;EAAEC,WAAW;EAAEC,QAAQ;EAAEC,YAAY;EAAEC;AAAc,CAAC,GAAGJ,OAAO,CAAC,IAAI,CAAC;AAE5E,MAAMK,SAAS,GAAGL,OAAO,CAAC,kBAAkB,CAAC;AAC7C,MAAM;EAAEM;AAAwB,CAAC,GAAGN,OAAO,CAAC,+BAA+B,CAAC;AAE5E,MAAMO,SAAS,GAAIC,GAAW,IAAoB;EAChD,MAAMC,YAAY,GAAG,EAAE;EAEvB,MAAMC,KAAK,GAAGT,WAAW,CAACO,GAAG,CAAC;EAE9B,KAAK,MAAMG,IAAI,IAAID,KAAK,EAAE;IACxB,MAAME,QAAQ,GAAGb,IAAI,CAACc,IAAI,CAACL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CAACc,IAAI,CAACS,YAAY,EAAE,uBAAuB,CAAC,EAChDgB,eAAA,CAAeD,SAAS,CAC1B,CAAC;EAED,OAAOE,QAAA,CAAQC,OAAO,CAAC,CAAC;AAC1B,CAAC","ignoreList":[]}
@@ -37,12 +37,13 @@ export const useModularUIBasic = function (key, href) {
37
37
  const {
38
38
  model
39
39
  } = modularUI;
40
- if (options.expectedModels.length > 0) {
41
- const isCorrectModel = options.expectedModels.some(expectedModel => {
40
+ const expectedModels = options.expectedModels ?? [];
41
+ if (expectedModels.length > 0) {
42
+ const isCorrectModel = expectedModels.some(expectedModel => {
42
43
  return model.type === expectedModel;
43
44
  });
44
45
  if (!isCorrectModel) {
45
- console.error(modularUI, "is not of instance", options.expectedModels);
46
+ console.error(modularUI, "is not of instance", expectedModels);
46
47
  throw new IllegalStateException("Resolved model has incorrect type");
47
48
  }
48
49
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUIBasic.js","names":["useModularUI","useLocation","IllegalStateException","useModularUIBasic","key","href","_context","options","arguments","length","undefined","expectedModels","targetModel","forceTargetModel","location","useModularUIOptions","isReload","cache","state","reload","_startsWithInstanceProperty","pathname","call","toString","modularUI","model","isCorrectModel","some","expectedModel","type","console","error"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useModularUI } from \"./useModularUI\";\n\nimport { useLocation } from \"./useRouter\";\n\nimport { IllegalStateException } from \"../exceptions\";\n\nimport type { ModularUIModel, Href } from \"../models\";\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n cache?: boolean,\n};\n\n/**\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n key: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n },\n): T | null => {\n const location = useLocation();\n\n const useModularUIOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n cache: false,\n };\n if (options.targetModel) {\n useModularUIOptions.targetModel = options.targetModel;\n useModularUIOptions.forceTargetModel = options.forceTargetModel;\n }\n\n if (options.cache) {\n useModularUIOptions.cache = options.cache;\n }\n\n // reload when the modular service starts with the current location\n if (location.state?.reload && location.pathname.startsWith(href.toString())) {\n useModularUIOptions.isReload = true;\n }\n\n // $FlowFixMe[incompatible-call]\n const modularUI = useModularUI(key, href, useModularUIOptions);\n\n if (modularUI?.model) {\n const { model } = modularUI;\n if (options.expectedModels.length > 0) {\n const isCorrectModel = options.expectedModels.some((expectedModel) => {\n return model.type === expectedModel;\n });\n\n if (!isCorrectModel) {\n console.error(modularUI, \"is not of instance\", options.expectedModels);\n throw new IllegalStateException(\"Resolved model has incorrect type\");\n }\n }\n\n return model;\n }\n\n return null;\n};\n"],"mappings":";AACA,SAASA,YAAY,QAAQ,gBAAgB;AAE7C,SAASC,WAAW,QAAQ,aAAa;AAEzC,SAASC,qBAAqB,QAAQ,eAAe;AAWrD;AACA;AACA,OAAO,MAAMC,iBAAiB,GAAG,SAAAA,CAC/BC,GAAW,EACXC,IAAmB,EAMN;EAAA,IAAAC,QAAA;EAAA,IALbC,OAAoC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IACrCG,cAAc,EAAE,EAAE;IAClBC,WAAW,EAAEF,SAAS;IACtBG,gBAAgB,EAAE;EACpB,CAAC;EAED,MAAMC,QAAQ,GAAGb,WAAW,CAAC,CAAC;EAE9B,MAAMc,mBAAmB,GAAG;IAC1BH,WAAW,EAAEF,SAAS;IACtBG,gBAAgB,EAAEH,SAAS;IAC3BM,QAAQ,EAAE,KAAK;IACfC,KAAK,EAAE;EACT,CAAC;EACD,IAAIV,OAAO,CAACK,WAAW,EAAE;IACvBG,mBAAmB,CAACH,WAAW,GAAGL,OAAO,CAACK,WAAW;IACrDG,mBAAmB,CAACF,gBAAgB,GAAGN,OAAO,CAACM,gBAAgB;EACjE;EAEA,IAAIN,OAAO,CAACU,KAAK,EAAE;IACjBF,mBAAmB,CAACE,KAAK,GAAGV,OAAO,CAACU,KAAK;EAC3C;;EAEA;EACA,IAAIH,QAAQ,CAACI,KAAK,EAAEC,MAAM,IAAIC,2BAAA,CAAAd,QAAA,GAAAQ,QAAQ,CAACO,QAAQ,EAAAC,IAAA,CAAAhB,QAAA,EAAYD,IAAI,CAACkB,QAAQ,CAAC,CAAC,CAAC,EAAE;IAC3ER,mBAAmB,CAACC,QAAQ,GAAG,IAAI;EACrC;;EAEA;EACA,MAAMQ,SAAS,GAAGxB,YAAY,CAACI,GAAG,EAAEC,IAAI,EAAEU,mBAAmB,CAAC;EAE9D,IAAIS,SAAS,EAAEC,KAAK,EAAE;IACpB,MAAM;MAAEA;IAAM,CAAC,GAAGD,SAAS;IAC3B,IAAIjB,OAAO,CAACI,cAAc,CAACF,MAAM,GAAG,CAAC,EAAE;MACrC,MAAMiB,cAAc,GAAGnB,OAAO,CAACI,cAAc,CAACgB,IAAI,CAAEC,aAAa,IAAK;QACpE,OAAOH,KAAK,CAACI,IAAI,KAAKD,aAAa;MACrC,CAAC,CAAC;MAEF,IAAI,CAACF,cAAc,EAAE;QACnBI,OAAO,CAACC,KAAK,CAACP,SAAS,EAAE,oBAAoB,EAAEjB,OAAO,CAACI,cAAc,CAAC;QACtE,MAAM,IAAIT,qBAAqB,CAAC,mCAAmC,CAAC;MACtE;IACF;IAEA,OAAOuB,KAAK;EACd;EAEA,OAAO,IAAI;AACb,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"useModularUIBasic.js","names":["useModularUI","useLocation","IllegalStateException","useModularUIBasic","key","href","_context","options","arguments","length","undefined","expectedModels","targetModel","forceTargetModel","location","useModularUIOptions","isReload","cache","state","reload","_startsWithInstanceProperty","pathname","call","toString","modularUI","model","isCorrectModel","some","expectedModel","type","console","error"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useModularUI } from \"./useModularUI\";\n\nimport { useLocation } from \"./useRouter\";\n\nimport { IllegalStateException } from \"../exceptions\";\n\nimport type { ModularUIModel, Href } from \"../models\";\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n cache?: boolean,\n};\n\n/**\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n key: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n },\n): T | null => {\n const location = useLocation();\n\n const useModularUIOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n cache: false,\n };\n if (options.targetModel) {\n useModularUIOptions.targetModel = options.targetModel;\n useModularUIOptions.forceTargetModel = options.forceTargetModel;\n }\n\n if (options.cache) {\n useModularUIOptions.cache = options.cache;\n }\n\n // reload when the modular service starts with the current location\n if (location.state?.reload && location.pathname.startsWith(href.toString())) {\n useModularUIOptions.isReload = true;\n }\n\n // $FlowFixMe[incompatible-call]\n const modularUI = useModularUI(key, href, useModularUIOptions);\n\n if (modularUI?.model) {\n const { model } = modularUI;\n\n const expectedModels = options.expectedModels ?? [];\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.some((expectedModel) => {\n return model.type === expectedModel;\n });\n\n if (!isCorrectModel) {\n console.error(modularUI, \"is not of instance\", expectedModels);\n throw new IllegalStateException(\"Resolved model has incorrect type\");\n }\n }\n\n return model;\n }\n\n return null;\n};\n"],"mappings":";AACA,SAASA,YAAY,QAAQ,gBAAgB;AAE7C,SAASC,WAAW,QAAQ,aAAa;AAEzC,SAASC,qBAAqB,QAAQ,eAAe;AAWrD;AACA;AACA,OAAO,MAAMC,iBAAiB,GAAG,SAAAA,CAC/BC,GAAW,EACXC,IAAmB,EAMN;EAAA,IAAAC,QAAA;EAAA,IALbC,OAAoC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA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,CAACC,KAAK,CAACP,SAAS,EAAE,oBAAoB,EAAEb,cAAc,CAAC;QAC9D,MAAM,IAAIT,qBAAqB,CAAC,mCAAmC,CAAC;MACtE;IACF;IAEA,OAAOuB,KAAK;EACd;EAEA,OAAO,IAAI;AACb,CAAC","ignoreList":[]}
@@ -1,6 +1,7 @@
1
1
  import { mergeLayoutHintConfigurations } from "../mergeLayoutHintConfigurations";
2
2
  import { LayoutHintConfiguration } from "../../constants/LayoutHintConfig";
3
3
  const fs = require("fs");
4
+
4
5
  //
5
6
  const projectJson1 = {
6
7
  MOCK: {
@@ -26,6 +27,18 @@ const projectJson2 = {
26
27
  },
27
28
  };
28
29
 
30
+ const projectMerge = {
31
+ MERGE: {
32
+ hint: "merge",
33
+ description: {
34
+ NL: "merge with extra component",
35
+ EN: "merge with extra component",
36
+ },
37
+ link: "",
38
+ component: ["component1", "component2", "component3"],
39
+ },
40
+ };
41
+
29
42
  jest.mock("fs", () => ({
30
43
  ...jest.requireActual("fs"),
31
44
  writeFileSync: jest.fn(),
@@ -33,19 +46,26 @@ jest.mock("fs", () => ({
33
46
 
34
47
  describe("mergeLayoutHintConfigurations", () => {
35
48
  it("generates layouthint.json", async () => {
36
- expect.assertions(1);
49
+ expect.assertions(2);
37
50
 
38
51
  const expectedJson = {
39
52
  ...LayoutHintConfiguration,
40
53
  ...projectJson1,
41
54
  ...projectJson2,
55
+ ...projectMerge,
42
56
  };
43
57
 
44
58
  await mergeLayoutHintConfigurations("./src", "/output");
45
59
 
46
60
  expect(fs.writeFileSync).toHaveBeenCalledWith(
47
61
  expect.stringContaining("LayoutHintConfig.json"),
48
- JSON.stringify(expectedJson),
62
+ expect.any(String),
49
63
  );
64
+
65
+ // Check that the JSON written matches the expected JSON
66
+ const actualJson = JSON.parse(fs.writeFileSync.mock.calls[0][1]);
67
+
68
+ // Compare objects using deep comparison to ensure they are equal
69
+ expect(actualJson).toEqual(expectedJson);
50
70
  });
51
71
  });
@@ -2,7 +2,7 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
4
  var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
5
- var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
5
+ var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set"));
6
6
  var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
7
7
  var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
8
8
  const path = require("path");
@@ -12,6 +12,7 @@ const {
12
12
  readFileSync,
13
13
  writeFileSync
14
14
  } = require("fs");
15
+ const mergeWith = require("lodash/mergeWith");
15
16
  const {
16
17
  LayoutHintConfiguration
17
18
  } = require("../constants/LayoutHintConfig");
@@ -45,7 +46,14 @@ exports.mergeLayoutHintConfigurations = async (srcFolder, outputFolder) => {
45
46
  const content = readFileSync(file, "utf-8");
46
47
  return JSON.parse(content);
47
48
  });
48
- const newConfig = (0, _assign.default)(LayoutHintConfiguration, ...jsons);
49
+
50
+ // Function to merge arrays during merging
51
+ const customizer = (objValue, srcValue) => {
52
+ if (Array.isArray(objValue)) {
53
+ return [...new _set.default([...objValue, ...srcValue])];
54
+ }
55
+ };
56
+ const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);
49
57
  writeFileSync(path.join(outputFolder, "LayoutHintConfig.json"), (0, _stringify.default)(newConfig));
50
58
  return _promise.default.resolve();
51
59
  };
@@ -2,6 +2,7 @@
2
2
  const path = require("path");
3
3
  const { readdirSync, statSync, readFileSync, writeFileSync } = require("fs");
4
4
 
5
+ const mergeWith = require("lodash/mergeWith");
5
6
  const { LayoutHintConfiguration } = require("../constants/LayoutHintConfig");
6
7
 
7
8
  const findFiles = (dir: string): Array<string> => {
@@ -43,7 +44,14 @@ exports.mergeLayoutHintConfigurations = async (
43
44
  return JSON.parse(content);
44
45
  });
45
46
 
46
- const newConfig = Object.assign(LayoutHintConfiguration, ...jsons);
47
+ // Function to merge arrays during merging
48
+ const customizer = (objValue: Object, srcValue: Object): Object => {
49
+ if (Array.isArray(objValue)) {
50
+ return [...new Set([...objValue, ...srcValue])];
51
+ }
52
+ };
53
+
54
+ const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);
47
55
 
48
56
  writeFileSync(
49
57
  path.join(outputFolder, "LayoutHintConfig.json"),
@@ -1 +1 @@
1
- {"version":3,"file":"mergeLayoutHintConfigurations.js","names":["path","require","readdirSync","statSync","readFileSync","writeFileSync","LayoutHintConfiguration","findFiles","dir","matchedFiles","files","file","absolute","join","isDirectory","foundFiles","push","filename","basename","exports","mergeLayoutHintConfigurations","srcFolder","outputFolder","escapedSrcFolder","replace","jsons","_map","default","call","content","JSON","parse","newConfig","_assign","_stringify","_promise","resolve"],"sources":["../../src/builder/mergeLayoutHintConfigurations.js"],"sourcesContent":["// @flow\nconst path = require(\"path\");\nconst { readdirSync, statSync, readFileSync, writeFileSync } = require(\"fs\");\n\nconst { LayoutHintConfiguration } = require(\"../constants/LayoutHintConfig\");\n\nconst findFiles = (dir: string): Array<string> => {\n const matchedFiles = [];\n\n const files = readdirSync(dir);\n\n for (const file of files) {\n const absolute = path.join(dir, file);\n if (statSync(absolute).isDirectory()) {\n const foundFiles = findFiles(absolute);\n matchedFiles.push(...foundFiles);\n } else {\n const filename = path.basename(file);\n if (filename === \"LayoutHintConfig.json\") {\n matchedFiles.push(absolute);\n }\n }\n }\n\n return matchedFiles;\n};\n\n/**\n * Merge all LayoutHintConfig.json files from this library and in the srcFolder\n * together into one config file, and copies it to the outputFolder.<br/>\n * This file is consumed by Be Informed studio to give layout hint information\n */\nexports.mergeLayoutHintConfigurations = async (\n srcFolder: string,\n outputFolder: string,\n): Promise<void> => {\n const escapedSrcFolder = srcFolder.replace(/\\\\/g, \"/\");\n\n const files = findFiles(escapedSrcFolder);\n\n const jsons = files.map((file) => {\n const content = readFileSync(file, \"utf-8\");\n return JSON.parse(content);\n });\n\n const newConfig = Object.assign(LayoutHintConfiguration, ...jsons);\n\n writeFileSync(\n path.join(outputFolder, \"LayoutHintConfig.json\"),\n JSON.stringify(newConfig),\n );\n\n return Promise.resolve();\n};\n"],"mappings":";;;;;;;AACA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAM,CAAC;AAC5B,MAAM;EAAEC,WAAW;EAAEC,QAAQ;EAAEC,YAAY;EAAEC;AAAc,CAAC,GAAGJ,OAAO,CAAC,IAAI,CAAC;AAE5E,MAAM;EAAEK;AAAwB,CAAC,GAAGL,OAAO,CAAC,+BAA+B,CAAC;AAE5E,MAAMM,SAAS,GAAIC,GAAW,IAAoB;EAChD,MAAMC,YAAY,GAAG,EAAE;EAEvB,MAAMC,KAAK,GAAGR,WAAW,CAACM,GAAG,CAAC;EAE9B,KAAK,MAAMG,IAAI,IAAID,KAAK,EAAE;IACxB,MAAME,QAAQ,GAAGZ,IAAI,CAACa,IAAI,CAACL,GAAG,EAAEG,IAAI,CAAC;IACrC,IAAIR,QAAQ,CAACS,QAAQ,CAAC,CAACE,WAAW,CAAC,CAAC,EAAE;MACpC,MAAMC,UAAU,GAAGR,SAAS,CAACK,QAAQ,CAAC;MACtCH,YAAY,CAACO,IAAI,CAAC,GAAGD,UAAU,CAAC;IAClC,CAAC,MAAM;MACL,MAAME,QAAQ,GAAGjB,IAAI,CAACkB,QAAQ,CAACP,IAAI,CAAC;MACpC,IAAIM,QAAQ,KAAK,uBAAuB,EAAE;QACxCR,YAAY,CAACO,IAAI,CAACJ,QAAQ,CAAC;MAC7B;IACF;EACF;EAEA,OAAOH,YAAY;AACrB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACAU,OAAO,CAACC,6BAA6B,GAAG,OACtCC,SAAiB,EACjBC,YAAoB,KACF;EAClB,MAAMC,gBAAgB,GAAGF,SAAS,CAACG,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;EAEtD,MAAMd,KAAK,GAAGH,SAAS,CAACgB,gBAAgB,CAAC;EAEzC,MAAME,KAAK,GAAG,IAAAC,IAAA,CAAAC,OAAA,EAAAjB,KAAK,EAAAkB,IAAA,CAALlB,KAAK,EAAMC,IAAI,IAAK;IAChC,MAAMkB,OAAO,GAAGzB,YAAY,CAACO,IAAI,EAAE,OAAO,CAAC;IAC3C,OAAOmB,IAAI,CAACC,KAAK,CAACF,OAAO,CAAC;EAC5B,CAAC,CAAC;EAEF,MAAMG,SAAS,GAAG,IAAAC,OAAA,CAAAN,OAAA,EAAcrB,uBAAuB,EAAE,GAAGmB,KAAK,CAAC;EAElEpB,aAAa,CACXL,IAAI,CAACa,IAAI,CAACS,YAAY,EAAE,uBAAuB,CAAC,EAChD,IAAAY,UAAA,CAAAP,OAAA,EAAeK,SAAS,CAC1B,CAAC;EAED,OAAOG,QAAA,CAAAR,OAAA,CAAQS,OAAO,CAAC,CAAC;AAC1B,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"mergeLayoutHintConfigurations.js","names":["path","require","readdirSync","statSync","readFileSync","writeFileSync","mergeWith","LayoutHintConfiguration","findFiles","dir","matchedFiles","files","file","absolute","join","isDirectory","foundFiles","push","filename","basename","exports","mergeLayoutHintConfigurations","srcFolder","outputFolder","escapedSrcFolder","replace","jsons","_map","default","call","content","JSON","parse","customizer","objValue","srcValue","Array","isArray","_set","newConfig","_stringify","_promise","resolve"],"sources":["../../src/builder/mergeLayoutHintConfigurations.js"],"sourcesContent":["// @flow\nconst path = require(\"path\");\nconst { readdirSync, statSync, readFileSync, writeFileSync } = require(\"fs\");\n\nconst mergeWith = require(\"lodash/mergeWith\");\nconst { LayoutHintConfiguration } = require(\"../constants/LayoutHintConfig\");\n\nconst findFiles = (dir: string): Array<string> => {\n const matchedFiles = [];\n\n const files = readdirSync(dir);\n\n for (const file of files) {\n const absolute = path.join(dir, file);\n if (statSync(absolute).isDirectory()) {\n const foundFiles = findFiles(absolute);\n matchedFiles.push(...foundFiles);\n } else {\n const filename = path.basename(file);\n if (filename === \"LayoutHintConfig.json\") {\n matchedFiles.push(absolute);\n }\n }\n }\n\n return matchedFiles;\n};\n\n/**\n * Merge all LayoutHintConfig.json files from this library and in the srcFolder\n * together into one config file, and copies it to the outputFolder.<br/>\n * This file is consumed by Be Informed studio to give layout hint information\n */\nexports.mergeLayoutHintConfigurations = async (\n srcFolder: string,\n outputFolder: string,\n): Promise<void> => {\n const escapedSrcFolder = srcFolder.replace(/\\\\/g, \"/\");\n\n const files = findFiles(escapedSrcFolder);\n\n const jsons = files.map((file) => {\n const content = readFileSync(file, \"utf-8\");\n return JSON.parse(content);\n });\n\n // Function to merge arrays during merging\n const customizer = (objValue: Object, srcValue: Object): Object => {\n if (Array.isArray(objValue)) {\n return [...new Set([...objValue, ...srcValue])];\n }\n };\n\n const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);\n\n writeFileSync(\n path.join(outputFolder, \"LayoutHintConfig.json\"),\n JSON.stringify(newConfig),\n );\n\n return Promise.resolve();\n};\n"],"mappings":";;;;;;;AACA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAM,CAAC;AAC5B,MAAM;EAAEC,WAAW;EAAEC,QAAQ;EAAEC,YAAY;EAAEC;AAAc,CAAC,GAAGJ,OAAO,CAAC,IAAI,CAAC;AAE5E,MAAMK,SAAS,GAAGL,OAAO,CAAC,kBAAkB,CAAC;AAC7C,MAAM;EAAEM;AAAwB,CAAC,GAAGN,OAAO,CAAC,+BAA+B,CAAC;AAE5E,MAAMO,SAAS,GAAIC,GAAW,IAAoB;EAChD,MAAMC,YAAY,GAAG,EAAE;EAEvB,MAAMC,KAAK,GAAGT,WAAW,CAACO,GAAG,CAAC;EAE9B,KAAK,MAAMG,IAAI,IAAID,KAAK,EAAE;IACxB,MAAME,QAAQ,GAAGb,IAAI,CAACc,IAAI,CAACL,GAAG,EAAEG,IAAI,CAAC;IACrC,IAAIT,QAAQ,CAACU,QAAQ,CAAC,CAACE,WAAW,CAAC,CAAC,EAAE;MACpC,MAAMC,UAAU,GAAGR,SAA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1B,CAAC;EAED,OAAOE,QAAA,CAAAb,OAAA,CAAQc,OAAO,CAAC,CAAC;AAC1B,CAAC","ignoreList":[]}
@@ -44,12 +44,13 @@ const useModularUIBasic = function (key, href) {
44
44
  const {
45
45
  model
46
46
  } = modularUI;
47
- if (options.expectedModels.length > 0) {
48
- const isCorrectModel = options.expectedModels.some(expectedModel => {
47
+ const expectedModels = options.expectedModels ?? [];
48
+ if (expectedModels.length > 0) {
49
+ const isCorrectModel = expectedModels.some(expectedModel => {
49
50
  return model.type === expectedModel;
50
51
  });
51
52
  if (!isCorrectModel) {
52
- console.error(modularUI, "is not of instance", options.expectedModels);
53
+ console.error(modularUI, "is not of instance", expectedModels);
53
54
  throw new _exceptions.IllegalStateException("Resolved model has incorrect type");
54
55
  }
55
56
  }
@@ -8,7 +8,7 @@ import { IllegalStateException } from "../exceptions";
8
8
  import type { ModularUIModel, Href } from "../models";
9
9
 
10
10
  export type UseModularUIBasicOptions<T: ModularUIModel> = {
11
- expectedModels: Array<string>,
11
+ expectedModels?: Array<string>,
12
12
  targetModel?: Class<T> | Array<Class<T>>,
13
13
  forceTargetModel?: boolean,
14
14
  cache?: boolean,
@@ -52,13 +52,15 @@ export const useModularUIBasic = <T: ModularUIModel>(
52
52
 
53
53
  if (modularUI?.model) {
54
54
  const { model } = modularUI;
55
- if (options.expectedModels.length > 0) {
56
- const isCorrectModel = options.expectedModels.some((expectedModel) => {
55
+
56
+ const expectedModels = options.expectedModels ?? [];
57
+ if (expectedModels.length > 0) {
58
+ const isCorrectModel = expectedModels.some((expectedModel) => {
57
59
  return model.type === expectedModel;
58
60
  });
59
61
 
60
62
  if (!isCorrectModel) {
61
- console.error(modularUI, "is not of instance", options.expectedModels);
63
+ console.error(modularUI, "is not of instance", expectedModels);
62
64
  throw new IllegalStateException("Resolved model has incorrect type");
63
65
  }
64
66
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useModularUIBasic.js","names":["_useModularUI","require","_useRouter","_exceptions","useModularUIBasic","key","href","_context","options","arguments","length","undefined","expectedModels","targetModel","forceTargetModel","location","useLocation","useModularUIOptions","isReload","cache","state","reload","_startsWith","default","pathname","call","toString","modularUI","useModularUI","model","isCorrectModel","some","expectedModel","type","console","error","IllegalStateException","exports"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useModularUI } from \"./useModularUI\";\n\nimport { useLocation } from \"./useRouter\";\n\nimport { IllegalStateException } from \"../exceptions\";\n\nimport type { ModularUIModel, Href } from \"../models\";\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n cache?: boolean,\n};\n\n/**\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n key: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n },\n): T | null => {\n const location = useLocation();\n\n const useModularUIOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n cache: false,\n };\n if (options.targetModel) {\n useModularUIOptions.targetModel = options.targetModel;\n useModularUIOptions.forceTargetModel = options.forceTargetModel;\n }\n\n if (options.cache) {\n useModularUIOptions.cache = options.cache;\n }\n\n // reload when the modular service starts with the current location\n if (location.state?.reload && location.pathname.startsWith(href.toString())) {\n useModularUIOptions.isReload = true;\n }\n\n // $FlowFixMe[incompatible-call]\n const modularUI = useModularUI(key, href, useModularUIOptions);\n\n if (modularUI?.model) {\n const { model } = modularUI;\n if (options.expectedModels.length > 0) {\n const isCorrectModel = options.expectedModels.some((expectedModel) => {\n return model.type === expectedModel;\n });\n\n if (!isCorrectModel) {\n console.error(modularUI, \"is not of instance\", options.expectedModels);\n throw new IllegalStateException(\"Resolved model has incorrect type\");\n }\n }\n\n return model;\n }\n\n return null;\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,aAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IA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AC,EAAE;MACrC,MAAMoB,cAAc,GAAGtB,OAAO,CAACI,cAAc,CAACmB,IAAI,CAAEC,aAAa,IAAK;QACpE,OAAOH,KAAK,CAACI,IAAI,KAAKD,aAAa;MACrC,CAAC,CAAC;MAEF,IAAI,CAACF,cAAc,EAAE;QACnBI,OAAO,CAACC,KAAK,CAACR,SAAS,EAAE,oBAAoB,EAAEnB,OAAO,CAACI,cAAc,CAAC;QACtE,MAAM,IAAIwB,iCAAqB,CAAC,mCAAmC,CAAC;MACtE;IACF;IAEA,OAAOP,KAAK;EACd;EAEA,OAAO,IAAI;AACb,CAAC;AAACQ,OAAA,CAAAjC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
1
+ {"version":3,"file":"useModularUIBasic.js","names":["_useModularUI","require","_useRouter","_exceptions","useModularUIBasic","key","href","_context","options","arguments","length","undefined","expectedModels","targetModel","forceTargetModel","location","useLocation","useModularUIOptions","isReload","cache","state","reload","_startsWith","default","pathname","call","toString","modularUI","useModularUI","model","isCorrectModel","some","expectedModel","type","console","error","IllegalStateException","exports"],"sources":["../../src/hooks/useModularUIBasic.js"],"sourcesContent":["// @flow\nimport { useModularUI } from \"./useModularUI\";\n\nimport { useLocation } from \"./useRouter\";\n\nimport { IllegalStateException } from \"../exceptions\";\n\nimport type { ModularUIModel, Href } from \"../models\";\n\nexport type UseModularUIBasicOptions<T: ModularUIModel> = {\n expectedModels?: Array<string>,\n targetModel?: Class<T> | Array<Class<T>>,\n forceTargetModel?: boolean,\n cache?: boolean,\n};\n\n/**\n */\nexport const useModularUIBasic = <T: ModularUIModel>(\n key: string,\n href: string | Href,\n options: UseModularUIBasicOptions<T> = {\n expectedModels: [],\n targetModel: undefined,\n forceTargetModel: false,\n },\n): T | null => {\n const location = useLocation();\n\n const useModularUIOptions = {\n targetModel: undefined,\n forceTargetModel: undefined,\n isReload: false,\n cache: false,\n };\n if (options.targetModel) {\n useModularUIOptions.targetModel = options.targetModel;\n useModularUIOptions.forceTargetModel = options.forceTargetModel;\n }\n\n if (options.cache) {\n useModularUIOptions.cache = options.cache;\n }\n\n // reload when the modular service starts with the current location\n if (location.state?.reload && location.pathname.startsWith(href.toString())) {\n useModularUIOptions.isReload = true;\n }\n\n // $FlowFixMe[incompatible-call]\n const modularUI = useModularUI(key, href, useModularUIOptions);\n\n if (modularUI?.model) {\n const { model } = modularUI;\n\n const expectedModels = options.expectedModels ?? [];\n if (expectedModels.length > 0) {\n const isCorrectModel = expectedModels.some((expectedModel) => {\n return model.type === expectedModel;\n });\n\n if (!isCorrectModel) {\n console.error(modularUI, \"is not of instance\", expectedModels);\n throw new IllegalStateException(\"Resolved model has incorrect type\");\n }\n }\n\n return model;\n }\n\n return null;\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,aAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAF,OAAA;AAWA;AACA;AACO,MAAMG,iBAAiB,GAAG,SAAAA,CAC/BC,GAAW,EACXC,IAAmB,EAMN;EAAA,IAAAC,QAAA;EAAA,IALbC,OAAoC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IACrCG,cAAc,EAAE,EAAE;IAClBC,WAAW,EAAEF,SAAS;IACtBG,gBAAgB,EAAE;EACpB,CAAC;EAED,MAAMC,QAAQ,GAAG,IAAAC,sBAAW,EAAC,CAAC;EAE9B,MAAMC,mBAAmB,GAAG;IAC1BJ,WAAW,EAAEF,SAAS;IACtBG,gBAAgB,EAAEH,SAAS;IAC3BO,QAAQ,EAAE,KAAK;IACfC,KAAK,EAAE;EACT,CAAC;EACD,IAAIX,OAAO,CAACK,WAAW,EAAE;IACvBI,mBAAmB,CAACJ,WAAW,GAAGL,OAAO,CAACK,WAAW;IACrDI,mBAAmB,CAACH,gBAAgB,GAAGN,OAAO,CAACM,gBAAgB;EACjE;EAEA,IAAIN,OAAO,CAACW,KAAK,EAAE;IACjBF,mBAAmB,CAACE,KAAK,GAAGX,OAAO,CAACW,KAAK;EAC3C;;EAEA;EACA,IAAIJ,QAAQ,CAACK,KAAK,EAAEC,MAAM,IAAI,IAAAC,WAAA,CAAAC,OAAA,EAAAhB,QAAA,GAAAQ,QAAQ,CAACS,QAAQ,EAAAC,IAAA,CAAAlB,QAAA,EAAYD,IAAI,CAACoB,QAAQ,CAAC,CAAC,CAAC,EAAE;IAC3ET,mBAAmB,CAACC,QAAQ,GAAG,IAAI;EACrC;;EAEA;EACA,MAAMS,SAAS,GAAG,IAAAC,0BAAY,EAACvB,GAAG,EAAEC,IAAI,EAAEW,mBAAmB,CAAC;EAE9D,IAAIU,SAAS,EAAEE,KAAK,EAAE;IACpB,MAAM;MAAEA;IAAM,CAAC,GAAGF,SAAS;IAE3B,MAAMf,cAAc,GAAGJ,OAAO,CAACI,cAAc,IAAI,EAAE;IACnD,IAAIA,cAAc,CAACF,MAAM,GAAG,CAAC,EAAE;MAC7B,MAAMoB,cAAc,GAAGlB,cAAc,CAACmB,IAAI,CAAEC,aAAa,IAAK;QAC5D,OAAOH,KAAK,CAACI,IAAI,KAAKD,aAAa;MACrC,CAAC,CAAC;MAEF,IAAI,CAACF,cAAc,EAAE;QACnBI,OAAO,CAACC,KAAK,CAACR,SAAS,EAAE,oBAAoB,EAAEf,cAAc,CAAC;QAC9D,MAAM,IAAIwB,iCAAqB,CAAC,mCAAmC,CAAC;MACtE;IACF;IAEA,OAAOP,KAAK;EACd;EAEA,OAAO,IAAI;AACb,CAAC;AAACQ,OAAA,CAAAjC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beinformed/ui",
3
- "version": "1.54.0",
3
+ "version": "1.54.2",
4
4
  "description": "Toolbox for be informed javascript layouts",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "bugs": "http://support.beinformed.com",
@@ -7,5 +7,14 @@
7
7
  },
8
8
  "link": "",
9
9
  "component": ["attribute"]
10
+ },
11
+ "MERGE": {
12
+ "hint": "merge",
13
+ "description": {
14
+ "NL": "merge with extra component",
15
+ "EN": "merge with extra component"
16
+ },
17
+ "link": "",
18
+ "component": ["component1", "component2"]
10
19
  }
11
20
  }
@@ -1,6 +1,7 @@
1
1
  import { mergeLayoutHintConfigurations } from "../mergeLayoutHintConfigurations";
2
2
  import { LayoutHintConfiguration } from "../../constants/LayoutHintConfig";
3
3
  const fs = require("fs");
4
+
4
5
  //
5
6
  const projectJson1 = {
6
7
  MOCK: {
@@ -26,6 +27,18 @@ const projectJson2 = {
26
27
  },
27
28
  };
28
29
 
30
+ const projectMerge = {
31
+ MERGE: {
32
+ hint: "merge",
33
+ description: {
34
+ NL: "merge with extra component",
35
+ EN: "merge with extra component",
36
+ },
37
+ link: "",
38
+ component: ["component1", "component2", "component3"],
39
+ },
40
+ };
41
+
29
42
  jest.mock("fs", () => ({
30
43
  ...jest.requireActual("fs"),
31
44
  writeFileSync: jest.fn(),
@@ -33,19 +46,26 @@ jest.mock("fs", () => ({
33
46
 
34
47
  describe("mergeLayoutHintConfigurations", () => {
35
48
  it("generates layouthint.json", async () => {
36
- expect.assertions(1);
49
+ expect.assertions(2);
37
50
 
38
51
  const expectedJson = {
39
52
  ...LayoutHintConfiguration,
40
53
  ...projectJson1,
41
54
  ...projectJson2,
55
+ ...projectMerge,
42
56
  };
43
57
 
44
58
  await mergeLayoutHintConfigurations("./src", "/output");
45
59
 
46
60
  expect(fs.writeFileSync).toHaveBeenCalledWith(
47
61
  expect.stringContaining("LayoutHintConfig.json"),
48
- JSON.stringify(expectedJson),
62
+ expect.any(String),
49
63
  );
64
+
65
+ // Check that the JSON written matches the expected JSON
66
+ const actualJson = JSON.parse(fs.writeFileSync.mock.calls[0][1]);
67
+
68
+ // Compare objects using deep comparison to ensure they are equal
69
+ expect(actualJson).toEqual(expectedJson);
50
70
  });
51
71
  });
@@ -7,5 +7,14 @@
7
7
  },
8
8
  "link": "",
9
9
  "component": ["attribute"]
10
+ },
11
+ "MERGE": {
12
+ "hint": "merge",
13
+ "description": {
14
+ "NL": "merge with extra component",
15
+ "EN": "merge with extra component"
16
+ },
17
+ "link": "",
18
+ "component": ["component1", "component3"]
10
19
  }
11
20
  }
@@ -2,6 +2,7 @@
2
2
  const path = require("path");
3
3
  const { readdirSync, statSync, readFileSync, writeFileSync } = require("fs");
4
4
 
5
+ const mergeWith = require("lodash/mergeWith");
5
6
  const { LayoutHintConfiguration } = require("../constants/LayoutHintConfig");
6
7
 
7
8
  const findFiles = (dir: string): Array<string> => {
@@ -43,7 +44,14 @@ exports.mergeLayoutHintConfigurations = async (
43
44
  return JSON.parse(content);
44
45
  });
45
46
 
46
- const newConfig = Object.assign(LayoutHintConfiguration, ...jsons);
47
+ // Function to merge arrays during merging
48
+ const customizer = (objValue: Object, srcValue: Object): Object => {
49
+ if (Array.isArray(objValue)) {
50
+ return [...new Set([...objValue, ...srcValue])];
51
+ }
52
+ };
53
+
54
+ const newConfig = mergeWith(LayoutHintConfiguration, ...jsons, customizer);
47
55
 
48
56
  writeFileSync(
49
57
  path.join(outputFolder, "LayoutHintConfig.json"),
@@ -8,7 +8,7 @@ import { IllegalStateException } from "../exceptions";
8
8
  import type { ModularUIModel, Href } from "../models";
9
9
 
10
10
  export type UseModularUIBasicOptions<T: ModularUIModel> = {
11
- expectedModels: Array<string>,
11
+ expectedModels?: Array<string>,
12
12
  targetModel?: Class<T> | Array<Class<T>>,
13
13
  forceTargetModel?: boolean,
14
14
  cache?: boolean,
@@ -52,13 +52,15 @@ export const useModularUIBasic = <T: ModularUIModel>(
52
52
 
53
53
  if (modularUI?.model) {
54
54
  const { model } = modularUI;
55
- if (options.expectedModels.length > 0) {
56
- const isCorrectModel = options.expectedModels.some((expectedModel) => {
55
+
56
+ const expectedModels = options.expectedModels ?? [];
57
+ if (expectedModels.length > 0) {
58
+ const isCorrectModel = expectedModels.some((expectedModel) => {
57
59
  return model.type === expectedModel;
58
60
  });
59
61
 
60
62
  if (!isCorrectModel) {
61
- console.error(modularUI, "is not of instance", options.expectedModels);
63
+ console.error(modularUI, "is not of instance", expectedModels);
62
64
  throw new IllegalStateException("Resolved model has incorrect type");
63
65
  }
64
66
  }