react-visualizer 4.0.0 → 4.1.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.
|
@@ -13,6 +13,9 @@ const { values: args } = parseArgs({
|
|
|
13
13
|
fallbackVersion: {
|
|
14
14
|
type: 'string',
|
|
15
15
|
},
|
|
16
|
+
loadversion: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
},
|
|
16
19
|
cdn: {
|
|
17
20
|
type: 'string',
|
|
18
21
|
},
|
|
@@ -44,6 +47,13 @@ Options:
|
|
|
44
47
|
--fallbackVersion <string>
|
|
45
48
|
Visualizer version to use if it is not specified in the search url and not loaded from the view
|
|
46
49
|
|
|
50
|
+
--loadversion <'none' | 'exact' | 'major-latest'>
|
|
51
|
+
What version to load based on the version referenced by the view.
|
|
52
|
+
'exact': load exactly the version of the view.
|
|
53
|
+
'latest-major': use the major version of the view, but its latest version.
|
|
54
|
+
'none': do not use the view to decide which version to load.
|
|
55
|
+
Default: 'none'
|
|
56
|
+
|
|
47
57
|
--cdn <string>
|
|
48
58
|
CDN base URL for visualizer assets
|
|
49
59
|
|
|
@@ -51,8 +61,10 @@ Options:
|
|
|
51
61
|
Output file path to which to write the html file
|
|
52
62
|
Default: visualizer.html
|
|
53
63
|
|
|
54
|
-
--queryType <
|
|
55
|
-
Where the search parameters should be read from
|
|
64
|
+
--queryType <'fragment' | 'query'>
|
|
65
|
+
Where the search parameters should be read from.
|
|
66
|
+
'query': Uses the regular query string of the URL
|
|
67
|
+
'fragment': Uses the fragment identifier (aka hash) of the URL as query string
|
|
56
68
|
Default: query
|
|
57
69
|
`);
|
|
58
70
|
}
|
|
@@ -5,8 +5,11 @@ function makeVisualizerPage(options = {}) {
|
|
|
5
5
|
cdn = "https://www.lactame.com/visualizer",
|
|
6
6
|
fallbackVersion = "latest",
|
|
7
7
|
queryType = "fragment",
|
|
8
|
+
loadversion = "none",
|
|
8
9
|
scripts = []
|
|
9
10
|
} = options;
|
|
11
|
+
validateQueryType(queryType);
|
|
12
|
+
validateLoadVersion(loadversion);
|
|
10
13
|
const scriptsStr = scripts.reduce(function(value, script) {
|
|
11
14
|
if (script.url) {
|
|
12
15
|
return value + `<script src="${script.url}"><\/script>
|
|
@@ -18,6 +21,22 @@ function makeVisualizerPage(options = {}) {
|
|
|
18
21
|
throw new Error("script must have url or content");
|
|
19
22
|
}
|
|
20
23
|
}, "");
|
|
21
|
-
return template.replaceAll("{{ cdn }}", cdn).replaceAll("{{ fallbackVersion }}", fallbackVersion).replace("{{ scripts }}", scriptsStr).replace("{{ queryType }}", queryType);
|
|
24
|
+
return template.replaceAll("{{ cdn }}", cdn).replaceAll("{{ fallbackVersion }}", fallbackVersion).replace("{{ scripts }}", scriptsStr).replace("{{ queryType }}", queryType).replace("{{ loadversion }}", loadversion);
|
|
22
25
|
}
|
|
23
26
|
module.exports = makeVisualizerPage;
|
|
27
|
+
const validLoadversion = ["none", "exact", "latest-major"];
|
|
28
|
+
function validateLoadVersion(loadversion) {
|
|
29
|
+
if (!validLoadversion.includes(loadversion)) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Invalid "loadversion" parameter: ${loadversion}. Allowed values: ${validLoadversion.join(", ")}`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const validQueryType = ["fragment", "query"];
|
|
36
|
+
function validateQueryType(queryType) {
|
|
37
|
+
if (!validQueryType.includes(queryType)) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Invalid "queryType" parameter: ${queryType}, allowed values: ${validQueryType.join(", ")}`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -36,13 +36,13 @@ window.onload = function () {
|
|
|
36
36
|
const search = new URLSearchParams(query.startsWith("#") ? query.slice(1) : query);
|
|
37
37
|
const url = search.get('viewURL');
|
|
38
38
|
const v = search.get('v');
|
|
39
|
-
const loadversion = search.get('loadversion');
|
|
39
|
+
const loadversion = search.get('loadversion') || '{{ loadversion }}';
|
|
40
40
|
if (v) {
|
|
41
41
|
addVisualizer(checkVersion(v));
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
if (
|
|
45
|
+
if (loadversion === 'none' || !url) {
|
|
46
46
|
addVisualizer('{{ fallbackVersion }}');
|
|
47
47
|
} else {
|
|
48
48
|
const viewReg = new RegExp('/view.json$');
|