react-visualizer 2.1.1 → 3.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.
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ const React = require("react");
3
+ const makeVisualizerPage = require("./makeVisualizerPage");
4
+ const ReactVisualizer = require("./ReactVisualizer");
5
+ const urls = /* @__PURE__ */ new Map();
6
+ function relativeUrl(from, to) {
7
+ return new URL(to, from).href;
8
+ }
9
+ class OldReactVisualizer extends React.PureComponent {
10
+ render() {
11
+ const currentHref = window.location.href;
12
+ let cdn = this.props.cdn ? this.props.cdn.replace(/\/$/, "") : "https://www.lactame.com/visualizer";
13
+ cdn = relativeUrl(currentHref, cdn);
14
+ let scripts = this.props.scripts || [];
15
+ scripts = scripts.map((script) => {
16
+ if (script.url || typeof script === "string") {
17
+ return {
18
+ url: relativeUrl(currentHref, script.url || script)
19
+ };
20
+ } else {
21
+ return script;
22
+ }
23
+ });
24
+ const page = makeVisualizerPage({
25
+ cdn,
26
+ fallbackVersion: this.props.fallbackVersion,
27
+ scripts
28
+ });
29
+ if (!urls.has(page)) {
30
+ urls.set(page, URL.createObjectURL(new Blob([page], { type: "text/html" })));
31
+ }
32
+ const url = urls.get(page);
33
+ return /* @__PURE__ */ React.createElement(
34
+ ReactVisualizer,
35
+ {
36
+ url,
37
+ viewURL: this.props.viewURL,
38
+ dataURL: this.props.dataURL,
39
+ config: this.props.config,
40
+ version: this.props.version,
41
+ style: this.props.style
42
+ }
43
+ );
44
+ }
45
+ }
46
+ module.exports = OldReactVisualizer;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ const React = require("react");
3
+ const configs = /* @__PURE__ */ new Map();
4
+ function relativeUrl(from, to) {
5
+ return new URL(to, from).href;
6
+ }
7
+ function ReactVisualizer(props) {
8
+ const currentHref = window.location.href;
9
+ let viewURL = props.viewURL || "";
10
+ if (viewURL) viewURL = relativeUrl(currentHref, viewURL);
11
+ let dataURL = props.dataURL || "";
12
+ if (dataURL) dataURL = relativeUrl(currentHref, dataURL);
13
+ let config = props.config || "";
14
+ const version = props.version || "latest";
15
+ if (typeof config === "object" && config !== null) {
16
+ if (config.header && config.header.elements) {
17
+ config = JSON.parse(JSON.stringify(config));
18
+ const els = config.header.elements;
19
+ for (let i = 0; i < els.length; i++) {
20
+ if (els[i].url) els[i].url = relativeUrl(currentHref, els[i].url);
21
+ }
22
+ }
23
+ const configJson = JSON.stringify(config);
24
+ if (!configs.has(configJson))
25
+ configs.set(
26
+ configJson,
27
+ URL.createObjectURL(
28
+ new Blob([configJson], { type: "application/json" })
29
+ )
30
+ );
31
+ config = configs.get(configJson);
32
+ }
33
+ const style = props.style || {
34
+ width: "100%",
35
+ height: "100%",
36
+ position: "absolute",
37
+ border: "none"
38
+ };
39
+ let query = ["viewURL", viewURL, "dataURL", dataURL, "config", config];
40
+ query = query.map(function(v, i) {
41
+ if (i % 2 === 1)
42
+ return query[i - 1] + "=" + encodeURIComponent(query[i]);
43
+ }).filter(function(v) {
44
+ return v !== void 0;
45
+ });
46
+ query = query.join("&");
47
+ if (version !== "auto" || !viewURL) {
48
+ const v = version === "auto" ? "latest" : version;
49
+ query += "&v=" + v;
50
+ } else {
51
+ query += "&loadversion=true";
52
+ }
53
+ return /* @__PURE__ */ React.createElement("iframe", { allowFullScreen: true, src: props.url + "#?" + query, style });
54
+ }
55
+ module.exports = ReactVisualizer;
package/dist/index.js CHANGED
@@ -1,110 +1,6 @@
1
- 'use strict';
2
-
3
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
4
-
5
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
6
-
7
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
-
9
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
10
-
11
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
12
-
13
- var React = require('react');
14
-
15
- var page = require('./visualizer.js');
16
- var urls = new Map();
17
- var configs = new Map();
18
-
19
- function relativeUrl(from, to) {
20
- return new URL(to, from).href;
21
- }
22
-
23
- var ReactVisualizer = function (_React$PureComponent) {
24
- _inherits(ReactVisualizer, _React$PureComponent);
25
-
26
- function ReactVisualizer() {
27
- _classCallCheck(this, ReactVisualizer);
28
-
29
- return _possibleConstructorReturn(this, (ReactVisualizer.__proto__ || Object.getPrototypeOf(ReactVisualizer)).apply(this, arguments));
30
- }
31
-
32
- _createClass(ReactVisualizer, [{
33
- key: 'render',
34
- value: function render() {
35
- var currentHref = window.location.href;
36
- var cdn = this.props.cdn ? this.props.cdn.replace(/\/$/, '') : 'https://www.lactame.com/visualizer';
37
- cdn = relativeUrl(currentHref, cdn);
38
- var fallbackVersion = this.props.fallbackVersion || 'latest';
39
- var h = page.replace(/\{\{ cdn }}/g, cdn);
40
- h = h.replace(/\{\{ fallbackVersion }}/g, fallbackVersion);
41
- var scripts = this.props.scripts || [];
42
- var scriptsStr = scripts.reduce(function (value, script) {
43
- if (script.url || typeof script === 'string') {
44
- var url = script.url;
45
- if (url) {
46
- url = relativeUrl(currentHref, url);
47
- }
48
- return value + ('<script src="' + (url || script) + '"></script>\n');
49
- } else if (script.content) {
50
- return value + ('<script>' + script.content + '</script>\n');
51
- } else {
52
- throw new Error('script must have url or content');
53
- }
54
- }, '');
55
- h = h.replace('{{scripts}}', scriptsStr);
56
-
57
- if (!urls.has(h)) {
58
- urls.set(h, URL.createObjectURL(new Blob([h], { type: 'text/html' })));
59
- }
60
- var url = urls.get(h);
61
- var viewURL = this.props.viewURL || '';
62
- if (viewURL) viewURL = relativeUrl(currentHref, viewURL);
63
- var dataURL = this.props.dataURL || '';
64
- if (dataURL) dataURL = relativeUrl(currentHref, dataURL);
65
- var config = this.props.config || '';
66
- var version = this.props.version || 'latest';
67
-
68
- if ((typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' && config !== null) {
69
- if (config.header && config.header.elements) {
70
- config = JSON.parse(JSON.stringify(config));
71
- var els = config.header.elements;
72
- for (var i = 0; i < els.length; i++) {
73
- if (els[i].url) els[i].url = relativeUrl(currentHref, els[i].url);
74
- }
75
- }
76
- var configJson = JSON.stringify(config);
77
- if (!configs.has(configJson)) configs.set(configJson, URL.createObjectURL(new Blob([configJson], { type: 'application/json' })));
78
- config = configs.get(configJson);
79
- }
80
-
81
- var style = this.props.style || {
82
- width: '100%',
83
- height: '100%',
84
- position: 'absolute',
85
- border: 'none'
86
- };
87
-
88
- var query = ['viewURL', viewURL, 'dataURL', dataURL, 'config', config];
89
- query = query.map(function (v, i) {
90
- if (i % 2 === 1) return query[i - 1] + '=' + encodeURIComponent(query[i]);
91
- }).filter(function (v) {
92
- return v !== undefined;
93
- });
94
- query = query.join('&');
95
-
96
- if (version !== 'auto' || !viewURL) {
97
- // Force version to be loaded
98
- var v = version === 'auto' ? 'latest' : version;
99
- query += '&v=' + v;
100
- } else {
101
- query += '&loadversion=true';
102
- }
103
- return React.createElement('iframe', { allowFullScreen: true, src: url + '#?' + query, style: style });
104
- }
105
- }]);
106
-
107
- return ReactVisualizer;
108
- }(React.PureComponent);
109
-
110
- module.exports = ReactVisualizer;
1
+ "use strict";
2
+ module.exports = {
3
+ ReactVisualizer: require("./ReactVisualizer"),
4
+ makeVisualizerPage: require("./makeVisualizerPage"),
5
+ OldReactVisualizer: require("./OldReactVisualizer")
6
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ const template = require("./visualizer");
3
+ function makeVisualizerPage(options = {}) {
4
+ const {
5
+ cdn = "https://www.lactame.com/visualizer",
6
+ fallbackVersion = "latest",
7
+ scripts = []
8
+ } = options;
9
+ const scriptsStr = scripts.reduce(function(value, script) {
10
+ if (script.url) {
11
+ return value + `<script src="${script.url}"><\/script>
12
+ `;
13
+ } else if (script.content) {
14
+ return value + `<script>${script.content}<\/script>
15
+ `;
16
+ } else {
17
+ throw new Error("script must have url or content");
18
+ }
19
+ }, "");
20
+ return template.replaceAll("{{ cdn }}", cdn).replaceAll("{{ fallbackVersion }}", fallbackVersion).replace("{{ scripts }}", scriptsStr);
21
+ }
22
+ module.exports = makeVisualizerPage;