@beinformed/ui 1.54.0 → 1.54.1
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 +7 -0
- package/esm/hooks/useModularUIBasic.js +4 -3
- package/esm/hooks/useModularUIBasic.js.map +1 -1
- package/lib/hooks/useModularUIBasic.js +4 -3
- package/lib/hooks/useModularUIBasic.js.flow +6 -4
- package/lib/hooks/useModularUIBasic.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useModularUIBasic.js +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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.1](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.54.0...v1.54.1) (2024-09-17)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **flowtype:** make expectedModels optional ([ebb6953](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/ebb6953be1e96ed9aebf31d3997ba5fe684f1c10))
|
|
11
|
+
|
|
5
12
|
## [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
13
|
|
|
7
14
|
|
|
@@ -37,12 +37,13 @@ export const useModularUIBasic = function (key, href) {
|
|
|
37
37
|
const {
|
|
38
38
|
model
|
|
39
39
|
} = modularUI;
|
|
40
|
-
|
|
41
|
-
|
|
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",
|
|
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
|
|
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,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;IAE3B,MAAMb,cAAc,GAAGJ,OAAO,CAACI,cAAc,IAAI,EAAE;IACnD,IAAIA,cAAc,CAACF,MAAM,GAAG,CAAC,EAAE;MAC7B,MAAMiB,cAAc,GAAGf,cAAc,CAACgB,IAAI,CAAEC,aAAa,IAAK;QAC5D,OAAOH,KAAK,CAACI,IAAI,KAAKD,aAAa;MACrC,CAAC,CAAC;MAEF,IAAI,CAACF,cAAc,EAAE;QACnBI,OAAO,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":[]}
|
|
@@ -44,12 +44,13 @@ const useModularUIBasic = function (key, href) {
|
|
|
44
44
|
const {
|
|
45
45
|
model
|
|
46
46
|
} = modularUI;
|
|
47
|
-
|
|
48
|
-
|
|
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",
|
|
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
|
|
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
|
-
|
|
56
|
-
|
|
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",
|
|
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
|
|
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
|
@@ -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
|
|
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
|
-
|
|
56
|
-
|
|
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",
|
|
63
|
+
console.error(modularUI, "is not of instance", expectedModels);
|
|
62
64
|
throw new IllegalStateException("Resolved model has incorrect type");
|
|
63
65
|
}
|
|
64
66
|
}
|