@sprinklrjs/spaceweb 14.14.4 → 14.14.6

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.
@@ -7,6 +7,7 @@ var react_1 = require("react");
7
7
  var styletron_engine_atomic_1 = require("styletron-engine-atomic");
8
8
  var styletron_react_1 = require("styletron-react");
9
9
  var DocumentProvider_1 = require("../spacewebProvider/DocumentProvider");
10
+ var createSingletonInstance_1 = require("@sprinklrjs/spaceweb/singleton/createSingletonInstance");
10
11
  exports.SPACEWEB_STYLE_PREFIX = 'sw--';
11
12
  exports.SPACEWEB_STYLE_CONTAINER_ID = 'spaceweb-style-cache';
12
13
  exports.isServer = typeof window === 'undefined';
@@ -16,9 +17,13 @@ var NoopDebugEngine = /** @class */ (function () {
16
17
  }
17
18
  return NoopDebugEngine;
18
19
  }());
19
- // NOTE: Define styletron as module variable (singleton)
20
- var styletron;
21
- var hasStyletron = function () { return typeof styletron !== 'undefined'; };
20
+ var getStyletron = function () {
21
+ return (0, createSingletonInstance_1.getSingletonInstance)(createSingletonInstance_1.SingletonInstanceIdentifier.STYLETRON_ENGINE);
22
+ };
23
+ var setStyletron = function (engine) {
24
+ return (0, createSingletonInstance_1.setSingletonInstance)(createSingletonInstance_1.SingletonInstanceIdentifier.STYLETRON_ENGINE, engine);
25
+ };
26
+ var hasStyletron = function () { return typeof getStyletron() !== 'undefined'; };
22
27
  // Throws and error if not called from the server.
23
28
  var ensureServer = function () {
24
29
  if (!exports.isServer) {
@@ -42,26 +47,22 @@ var hydrate = function (ownerDocument) {
42
47
  exports.hydrate = hydrate;
43
48
  // Gets isomorphic Styletron engine.
44
49
  var getStyleEngine = function (ownerDocument, nonce) {
50
+ var styletron = getStyletron();
45
51
  if (exports.isServer) {
46
- if (typeof styletron !== 'undefined')
47
- return styletron;
48
- styletron = new styletron_engine_atomic_1.Server({ prefix: exports.SPACEWEB_STYLE_PREFIX });
52
+ return styletron !== null && styletron !== void 0 ? styletron : setStyletron(new styletron_engine_atomic_1.Server({ prefix: exports.SPACEWEB_STYLE_PREFIX }));
49
53
  }
50
- else {
51
- var doc = ownerDocument || document;
52
- var el = doc.getElementById(exports.SPACEWEB_STYLE_CONTAINER_ID);
53
- if (el && styletron) {
54
- return styletron;
55
- }
56
- // adds a style tag in document.head to make sure only one instance of styletron is created in an app.
57
- (0, exports.appendCacheContainer)(ownerDocument, nonce);
58
- styletron = new styletron_engine_atomic_1.Client({
59
- hydrate: (0, exports.hydrate)(ownerDocument),
60
- prefix: exports.SPACEWEB_STYLE_PREFIX,
61
- container: ownerDocument === null || ownerDocument === void 0 ? void 0 : ownerDocument.head,
62
- });
54
+ var doc = ownerDocument || document;
55
+ var el = doc.getElementById(exports.SPACEWEB_STYLE_CONTAINER_ID);
56
+ if (el && styletron) {
57
+ return styletron;
63
58
  }
64
- return styletron;
59
+ // adds a style tag in document.head to make sure only one instance of styletron is created in an app.
60
+ (0, exports.appendCacheContainer)(ownerDocument, nonce);
61
+ return setStyletron(new styletron_engine_atomic_1.Client({
62
+ hydrate: (0, exports.hydrate)(ownerDocument),
63
+ prefix: exports.SPACEWEB_STYLE_PREFIX,
64
+ container: ownerDocument === null || ownerDocument === void 0 ? void 0 : ownerDocument.head,
65
+ }));
65
66
  };
66
67
  exports.getStyleEngine = getStyleEngine;
67
68
  // @ts-ignore
@@ -78,19 +79,19 @@ exports.StyleProvider.displayName = 'StyleProvider';
78
79
  var getStylesheets = function () {
79
80
  ensureServer();
80
81
  ensureEngine();
81
- return styletron.getStylesheets();
82
+ return getStyletron().getStylesheets();
82
83
  };
83
84
  exports.getStylesheets = getStylesheets;
84
85
  // Gets hydration stylesheets HTML code as string.
85
86
  var getStylesheetsHtml = function () {
86
87
  ensureServer();
87
88
  ensureEngine();
88
- return styletron.getStylesheetsHtml();
89
+ return getStyletron().getStylesheetsHtml();
89
90
  };
90
91
  exports.getStylesheetsHtml = getStylesheetsHtml;
91
92
  var deprecatedRenderKeyframes = function (keyframes) {
92
93
  ensureEngine();
93
- return styletron.renderKeyframes(keyframes);
94
+ return getStyletron().renderKeyframes(keyframes);
94
95
  };
95
96
  exports.deprecatedRenderKeyframes = deprecatedRenderKeyframes;
96
97
  // Appends cache styles to the DOM and returns element's instance.