@sitecore-jss/sitecore-jss-react 12.0.2 → 12.0.5

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.
@@ -52,9 +52,8 @@ var getImageAttrs = function (_a, imageParams) {
52
52
  // replace with HTML-formatted srcset, including updated image URLs
53
53
  newAttrs.srcSet = sitecore_jss_1.mediaApi.getSrcSet(resolvedSrc, srcSet, imageParams);
54
54
  }
55
- else {
56
- newAttrs.src = resolvedSrc;
57
- }
55
+ // always output original src as fallback for older browsers
56
+ newAttrs.src = resolvedSrc;
58
57
  return newAttrs;
59
58
  };
60
59
  exports.Image = function (_a) {
@@ -12,6 +12,17 @@ var __extends = (this && this.__extends) || (function () {
12
12
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
13
  };
14
14
  })();
15
+ var __assign = (this && this.__assign) || function () {
16
+ __assign = Object.assign || function(t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
+ t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
15
26
  var __importDefault = (this && this.__importDefault) || function (mod) {
16
27
  return (mod && mod.__esModule) ? mod : { "default": mod };
17
28
  };
@@ -20,27 +31,28 @@ var react_1 = __importDefault(require("react"));
20
31
  var prop_types_1 = __importDefault(require("prop-types"));
21
32
  var SitecoreContextFactory = /** @class */ (function () {
22
33
  function SitecoreContextFactory() {
34
+ var _this = this;
23
35
  this.subscribers = [];
36
+ this.getSitecoreContext = function () {
37
+ return _this.context;
38
+ };
39
+ this.subscribeToContext = function (func) {
40
+ _this.subscribers.push(func);
41
+ };
42
+ this.unsubscribeFromContext = function (func) {
43
+ var index = _this.subscribers.indexOf(func);
44
+ if (index >= 0) {
45
+ _this.subscribers.splice(index, 1);
46
+ }
47
+ };
48
+ this.setSitecoreContext = function (value) {
49
+ _this.context = value;
50
+ _this.subscribers.forEach(function (func) { return func(value); });
51
+ };
24
52
  this.context = {
25
53
  pageEditing: false,
26
54
  };
27
55
  }
28
- SitecoreContextFactory.prototype.getSitecoreContext = function () {
29
- return this.context;
30
- };
31
- SitecoreContextFactory.prototype.subscribeToContext = function (func) {
32
- this.subscribers.push(func);
33
- };
34
- SitecoreContextFactory.prototype.unsubscribeFromContext = function (func) {
35
- var index = this.subscribers.indexOf(func);
36
- if (index >= 0) {
37
- this.subscribers.splice(index, 1);
38
- }
39
- };
40
- SitecoreContextFactory.prototype.setSitecoreContext = function (value) {
41
- this.context = value;
42
- this.subscribers.forEach(function (func) { return func(value); });
43
- };
44
56
  return SitecoreContextFactory;
45
57
  }());
46
58
  exports.SitecoreContextFactory = SitecoreContextFactory;
@@ -51,6 +63,11 @@ var SitecoreContext = /** @class */ (function (_super) {
51
63
  function SitecoreContext(props, context) {
52
64
  var _this = _super.call(this, props, context) || this;
53
65
  _this.contextListener = function () { return _this.forceUpdate(); };
66
+ /**
67
+ * React Context Provider should accept Object instead of
68
+ * SitecoreContextFactory class instance
69
+ */
70
+ _this.getSitecoreContextValue = function () { return (__assign({}, _this.contextFactory)); };
54
71
  _this.componentFactory = props.componentFactory;
55
72
  if (props.contextFactory) {
56
73
  _this.contextFactory = props.contextFactory;
@@ -58,19 +75,17 @@ var SitecoreContext = /** @class */ (function (_super) {
58
75
  else {
59
76
  _this.contextFactory = new SitecoreContextFactory();
60
77
  }
61
- return _this;
62
- }
63
- SitecoreContext.prototype.componentDidMount = function () {
64
78
  // we force the children of the context to re-render when the context is updated
65
79
  // even if the local props are unchanged; we assume the contents depend on the Sitecore context
66
- this.contextFactory.subscribeToContext(this.contextListener);
67
- };
80
+ _this.contextFactory.subscribeToContext(_this.contextListener);
81
+ return _this;
82
+ }
68
83
  SitecoreContext.prototype.componentWillUnmount = function () {
69
84
  this.contextFactory.unsubscribeFromContext(this.contextListener);
70
85
  };
71
86
  SitecoreContext.prototype.render = function () {
72
87
  return (react_1.default.createElement(exports.ComponentFactoryReactContext.Provider, { value: this.componentFactory },
73
- react_1.default.createElement(exports.SitecoreContextReactContext.Provider, { value: this.contextFactory }, this.props.children)));
88
+ react_1.default.createElement(exports.SitecoreContextReactContext.Provider, { value: this.getSitecoreContextValue() }, this.props.children)));
74
89
  };
75
90
  SitecoreContext.propTypes = {
76
91
  children: prop_types_1.default.any.isRequired,
@@ -1,23 +1,26 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var react_1 = __importDefault(require("react"));
7
3
  var withSitecoreContext_1 = require("../enhancers/withSitecoreContext");
8
4
  var emittedVI = false;
9
5
  var VIComponent = function (_a) {
10
6
  var sitecoreContext = _a.sitecoreContext;
11
- if (!emittedVI &&
12
- typeof document !== 'undefined' &&
13
- sitecoreContext.visitorIdentificationTimestamp) {
14
- emittedVI = true;
15
- var script = document.createElement('script');
16
- script.src = "/layouts/system/VisitorIdentification.js";
17
- script.type = 'text/javascript';
18
- document.getElementsByTagName('head')[0].appendChild(script);
19
- return (react_1.default.createElement("meta", { name: "VIcurrentDateTime", content: sitecoreContext.visitorIdentificationTimestamp }));
7
+ if (emittedVI ||
8
+ typeof document === 'undefined' ||
9
+ !sitecoreContext.visitorIdentificationTimestamp) {
10
+ // Don't emit VI script and meta tag if we've already done so,
11
+ // aren't rendering client-side, or don't have a VI timestamp.
12
+ return null;
20
13
  }
14
+ emittedVI = true;
15
+ var script = document.createElement('script');
16
+ script.src = "/layouts/system/VisitorIdentification.js";
17
+ script.type = 'text/javascript';
18
+ var meta = document.createElement('meta');
19
+ meta.name = 'VIcurrentDateTime';
20
+ meta.content = sitecoreContext.visitorIdentificationTimestamp;
21
+ var head = document.querySelector('head');
22
+ head && head.appendChild(script);
23
+ head && head.appendChild(meta);
21
24
  return null;
22
25
  };
23
26
  VIComponent.displayName = 'VisitorIdentification';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-react",
3
- "version": "12.0.2",
3
+ "version": "12.0.5",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "npm run clean && tsc",
@@ -56,11 +56,11 @@
56
56
  "react-dom": "^16.9.0"
57
57
  },
58
58
  "dependencies": {
59
- "@sitecore-jss/sitecore-jss": "^12.0.2",
59
+ "@sitecore-jss/sitecore-jss": "^12.0.5",
60
60
  "prop-types": "^15.7.2",
61
61
  "style-attr": "^1.3.0"
62
62
  },
63
63
  "description": "",
64
64
  "types": "types/index.d.ts",
65
- "gitHead": "56567123da937fc546ec6c6d59b11cd3872f23f8"
65
+ "gitHead": "e7503e862d40c254af2054c3e3fc97f9c6c78871"
66
66
  }
@@ -11,10 +11,10 @@ export declare class SitecoreContextFactory {
11
11
  subscribers: any[];
12
12
  context: any;
13
13
  constructor();
14
- getSitecoreContext(): any;
15
- subscribeToContext(func: any): void;
16
- unsubscribeFromContext(func: any): void;
17
- setSitecoreContext(value: any): void;
14
+ getSitecoreContext: () => any;
15
+ subscribeToContext: (func: any) => void;
16
+ unsubscribeFromContext: (func: any) => void;
17
+ setSitecoreContext: (value: any) => void;
18
18
  }
19
19
  export declare const SitecoreContextReactContext: React.Context<SitecoreContextFactory>;
20
20
  export declare const ComponentFactoryReactContext: React.Context<ComponentFactory>;
@@ -28,8 +28,19 @@ export declare class SitecoreContext extends React.Component<SitecoreContextProp
28
28
  componentFactory: ComponentFactory;
29
29
  contextFactory: SitecoreContextFactory;
30
30
  constructor(props: SitecoreContextProps, context: any);
31
- componentDidMount(): void;
32
31
  contextListener: () => void;
33
32
  componentWillUnmount(): void;
33
+ /**
34
+ * React Context Provider should accept Object instead of
35
+ * SitecoreContextFactory class instance
36
+ */
37
+ getSitecoreContextValue: () => {
38
+ subscribers: any[];
39
+ context: any;
40
+ getSitecoreContext: () => any;
41
+ subscribeToContext: (func: any) => void;
42
+ unsubscribeFromContext: (func: any) => void;
43
+ setSitecoreContext: (value: any) => void;
44
+ };
34
45
  render(): JSX.Element;
35
46
  }