@atlaskit/react-ufo 3.12.5 → 3.13.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.
Files changed (24) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/vc/vc-observer/index.js +4 -0
  3. package/dist/cjs/vc/vc-observer/observers/index.js +3 -2
  4. package/dist/cjs/vc/vc-observer/observers/ssr-placeholders/index.js +38 -12
  5. package/dist/cjs/vc/vc-observer/observers/ssr-placeholders/ssr-scripts/collectSSRPlaceholderDimensions.js +9 -0
  6. package/dist/es2019/vc/vc-observer/index.js +6 -0
  7. package/dist/es2019/vc/vc-observer/observers/index.js +2 -1
  8. package/dist/es2019/vc/vc-observer/observers/ssr-placeholders/index.js +38 -13
  9. package/dist/es2019/vc/vc-observer/observers/ssr-placeholders/ssr-scripts/collectSSRPlaceholderDimensions.js +9 -1
  10. package/dist/esm/vc/vc-observer/index.js +4 -0
  11. package/dist/esm/vc/vc-observer/observers/index.js +3 -2
  12. package/dist/esm/vc/vc-observer/observers/ssr-placeholders/index.js +38 -12
  13. package/dist/esm/vc/vc-observer/observers/ssr-placeholders/ssr-scripts/collectSSRPlaceholderDimensions.js +9 -0
  14. package/dist/types/config/index.d.ts +1 -0
  15. package/dist/types/vc/types.d.ts +1 -0
  16. package/dist/types/vc/vc-observer/observers/index.d.ts +3 -0
  17. package/dist/types/vc/vc-observer/observers/ssr-placeholders/index.d.ts +4 -1
  18. package/dist/types/vc/vc-observer/observers/ssr-placeholders/ssr-scripts/collectSSRPlaceholderDimensions.d.ts +1 -1
  19. package/dist/types-ts4.5/config/index.d.ts +1 -0
  20. package/dist/types-ts4.5/vc/types.d.ts +1 -0
  21. package/dist/types-ts4.5/vc/vc-observer/observers/index.d.ts +3 -0
  22. package/dist/types-ts4.5/vc/vc-observer/observers/ssr-placeholders/index.d.ts +4 -1
  23. package/dist/types-ts4.5/vc/vc-observer/observers/ssr-placeholders/ssr-scripts/collectSSRPlaceholderDimensions.d.ts +1 -1
  24. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/ufo-interaction-ignore
2
2
 
3
+ ## 3.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#156673](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/156673)
8
+ [`27ecf5244d858`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/27ecf5244d858) -
9
+ Added API to account for page layout in VC calculation
10
+
3
11
  ## 3.12.5
4
12
 
5
13
  ### Patch Changes
@@ -523,6 +523,7 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
523
523
  this.arraySize = options.heatmapSize || 200;
524
524
  this.devToolsEnabled = options.devToolsEnabled || false;
525
525
  this.oldDomUpdatesEnabled = options.oldDomUpdates || false;
526
+ var ssrEnablePageLayoutPlaceholder = options.ssrEnablePageLayoutPlaceholder;
526
527
  this.observers = new _observers.Observers({
527
528
  selectorConfig: options.selectorConfig || {
528
529
  id: false,
@@ -530,6 +531,9 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
530
531
  role: false,
531
532
  className: true,
532
533
  dataVC: true
534
+ },
535
+ SSRConfig: {
536
+ enablePageLayoutPlaceholder: ssrEnablePageLayoutPlaceholder || false
533
537
  }
534
538
  });
535
539
  this.heatmap = !(0, _config.isVCRevisionEnabled)('fy25.01') ? [] : this.getCleanHeatmap();
@@ -31,7 +31,8 @@ function isElementVisible(target) {
31
31
  }
32
32
  var Observers = exports.Observers = /*#__PURE__*/function () {
33
33
  function Observers(opts) {
34
- var _this = this;
34
+ var _this = this,
35
+ _opts$SSRConfig;
35
36
  (0, _classCallCheck2.default)(this, Observers);
36
37
  (0, _defineProperty2.default)(this, "observedMutations", new WeakMap());
37
38
  (0, _defineProperty2.default)(this, "elementsInView", new Set());
@@ -71,7 +72,7 @@ var Observers = exports.Observers = /*#__PURE__*/function () {
71
72
  this.selectorConfig = _objectSpread(_objectSpread({}, this.selectorConfig), opts.selectorConfig);
72
73
  this.intersectionObserver = this.getIntersectionObserver();
73
74
  this.mutationObserver = this.getMutationObserver();
74
- this.ssrPlaceholderHandler = new _ssrPlaceholders.SSRPlaceholderHandlers();
75
+ this.ssrPlaceholderHandler = new _ssrPlaceholders.SSRPlaceholderHandlers((_opts$SSRConfig = opts.SSRConfig) === null || _opts$SSRConfig === void 0 ? void 0 : _opts$SSRConfig.enablePageLayoutPlaceholder);
75
76
  }
76
77
  return (0, _createClass2.default)(Observers, [{
77
78
  key: "isBrowserSupported",
@@ -9,15 +9,39 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
  var ANCESTOR_LOOKUP_LIMIT = 10;
12
+ var PAGE_LAYOUT_ID = 'page-layout.root';
12
13
  var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/function () {
13
14
  function SSRPlaceholderHandlers() {
14
15
  var _this = this;
16
+ var enablePageLayoutPlaceholder = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
15
17
  (0, _classCallCheck2.default)(this, SSRPlaceholderHandlers);
16
18
  (0, _defineProperty2.default)(this, "staticPlaceholders", new Map());
17
19
  (0, _defineProperty2.default)(this, "callbacks", new Map());
18
20
  (0, _defineProperty2.default)(this, "getSizeCallbacks", new Map());
19
21
  (0, _defineProperty2.default)(this, "reactValidateCallbacks", new Map());
20
22
  (0, _defineProperty2.default)(this, "EQUALITY_THRESHOLD", 1);
23
+ (0, _defineProperty2.default)(this, "getPlaceholderId", function (el) {
24
+ var _el$dataset;
25
+ var ssrPlaceholderId = el === null || el === void 0 || (_el$dataset = el.dataset) === null || _el$dataset === void 0 ? void 0 : _el$dataset.ssrPlaceholder;
26
+ if (!!ssrPlaceholderId) {
27
+ return ssrPlaceholderId;
28
+ }
29
+ if (_this.enablePageLayoutPlaceholder && (el === null || el === void 0 ? void 0 : el.dataset.testid) === PAGE_LAYOUT_ID) {
30
+ return PAGE_LAYOUT_ID;
31
+ }
32
+ return '';
33
+ });
34
+ (0, _defineProperty2.default)(this, "getPlaceholderReplacementId", function (el) {
35
+ var _el$dataset2;
36
+ var ssrPlaceholderReplaceId = el === null || el === void 0 || (_el$dataset2 = el.dataset) === null || _el$dataset2 === void 0 ? void 0 : _el$dataset2.ssrPlaceholderReplace;
37
+ if (!!ssrPlaceholderReplaceId) {
38
+ return ssrPlaceholderReplaceId;
39
+ }
40
+ if (_this.enablePageLayoutPlaceholder && (el === null || el === void 0 ? void 0 : el.dataset.testid) === PAGE_LAYOUT_ID) {
41
+ return PAGE_LAYOUT_ID;
42
+ }
43
+ return '';
44
+ });
21
45
  (0, _defineProperty2.default)(this, "intersectionObserverCallback", function (_ref) {
22
46
  var _this$intersectionObs;
23
47
  var target = _ref.target,
@@ -27,7 +51,7 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
27
51
  // impossible case - keep typescript healthy
28
52
  return;
29
53
  }
30
- var staticKey = target.dataset.ssrPlaceholder || '';
54
+ var staticKey = _this.getPlaceholderId(target);
31
55
  if (staticKey) {
32
56
  if (_this.staticPlaceholders.has(staticKey) && _this.callbacks.has(staticKey)) {
33
57
  // validation
@@ -49,7 +73,7 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
49
73
  _this.callbacks.delete(staticKey);
50
74
  }
51
75
  } else {
52
- var key = target.dataset.ssrPlaceholderReplace || '';
76
+ var key = _this.getPlaceholderReplacementId(target);
53
77
  var _resolve2 = _this.reactValidateCallbacks.get(key);
54
78
  if (!_resolve2) {
55
79
  return;
@@ -77,25 +101,27 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
77
101
  }).forEach(_this.intersectionObserverCallback);
78
102
  });
79
103
  }
104
+ this.enablePageLayoutPlaceholder = enablePageLayoutPlaceholder;
80
105
  if (window.document) {
81
106
  try {
82
- var existingElements = document.querySelectorAll('[data-ssr-placeholder]');
107
+ var selector = this.enablePageLayoutPlaceholder ? '[data-ssr-placeholder],[data-testid="page-layout.root"]' : '[data-ssr-placeholder]';
108
+ var existingElements = document.querySelectorAll(selector);
83
109
  existingElements.forEach(function (el) {
84
- var _el$dataset;
85
- if (el instanceof HTMLElement && el !== null && el !== void 0 && (_el$dataset = el.dataset) !== null && _el$dataset !== void 0 && _el$dataset.ssrPlaceholder) {
110
+ var placeholderId = el instanceof HTMLElement && _this.getPlaceholderId(el);
111
+ if (placeholderId) {
86
112
  var _window$__SSR_PLACEHO, _this$intersectionObs2;
87
113
  var width = -1;
88
114
  var height = -1;
89
115
  var x = -1;
90
116
  var y = -1;
91
- var boundingClientRect = (_window$__SSR_PLACEHO = window.__SSR_PLACEHOLDERS_DIMENSIONS__) === null || _window$__SSR_PLACEHO === void 0 ? void 0 : _window$__SSR_PLACEHO[el.dataset.ssrPlaceholder];
117
+ var boundingClientRect = (_window$__SSR_PLACEHO = window.__SSR_PLACEHOLDERS_DIMENSIONS__) === null || _window$__SSR_PLACEHO === void 0 ? void 0 : _window$__SSR_PLACEHO[placeholderId];
92
118
  if (boundingClientRect) {
93
119
  width = boundingClientRect.width;
94
120
  height = boundingClientRect.height;
95
121
  x = boundingClientRect.x;
96
122
  y = boundingClientRect.y;
97
123
  }
98
- _this.staticPlaceholders.set(el.dataset.ssrPlaceholder, {
124
+ _this.staticPlaceholders.set(placeholderId, {
99
125
  width: width,
100
126
  height: height,
101
127
  x: x,
@@ -120,12 +146,12 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
120
146
  }, {
121
147
  key: "isPlaceholder",
122
148
  value: function isPlaceholder(element) {
123
- return Boolean(element.dataset.ssrPlaceholder);
149
+ return Boolean(this.getPlaceholderId(element));
124
150
  }
125
151
  }, {
126
152
  key: "isPlaceholderReplacement",
127
153
  value: function isPlaceholderReplacement(element) {
128
- return Boolean(element.dataset.ssrPlaceholderReplace);
154
+ return Boolean(this.getPlaceholderReplacementId(element));
129
155
  }
130
156
  }, {
131
157
  key: "isPlaceholderIgnored",
@@ -155,7 +181,7 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
155
181
  value: function checkIfExistedAndSizeMatching(el) {
156
182
  var _this2 = this;
157
183
  el = this.findNearestPlaceholderContainerIfIgnored(el);
158
- var id = el.dataset.ssrPlaceholder || '';
184
+ var id = this.getPlaceholderId(el);
159
185
  return new Promise(function (resolve) {
160
186
  if (!_this2.staticPlaceholders.has(id)) {
161
187
  resolve(false);
@@ -173,7 +199,7 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
173
199
  var _this3 = this;
174
200
  return new Promise(function (resolve) {
175
201
  var _this3$intersectionOb;
176
- _this3.getSizeCallbacks.set(el.dataset.ssrPlaceholder || '', resolve);
202
+ _this3.getSizeCallbacks.set(_this3.getPlaceholderId(el), resolve);
177
203
  (_this3$intersectionOb = _this3.intersectionObserver) === null || _this3$intersectionOb === void 0 || _this3$intersectionOb.observe(el);
178
204
  });
179
205
  }
@@ -182,7 +208,7 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
182
208
  value: function validateReactComponentMatchToPlaceholder(el) {
183
209
  var _this4 = this;
184
210
  el = this.findNearestPlaceholderContainerIfIgnored(el);
185
- var id = el.dataset.ssrPlaceholderReplace || '';
211
+ var id = this.getPlaceholderReplacementId(el);
186
212
  return new Promise(function (resolve) {
187
213
  if (!_this4.staticPlaceholders.has(id)) {
188
214
  resolve(false);
@@ -8,6 +8,7 @@ exports.collectSSRPlaceholderDimensions = collectSSRPlaceholderDimensions;
8
8
  // and save their size/positions in a map __SSR_PLACEHOLDERS_DIMENSIONS__ on the Window object. Each placeholderId is
9
9
  // unique and maps to its corresponding elements bounding client rectangle dimensions.
10
10
  function collectSSRPlaceholderDimensions(document, window) {
11
+ var enablePageLayoutPlaceholder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
11
12
  var ssrPlaceholders = document === null || document === void 0 ? void 0 : document.querySelectorAll('[data-ssr-placeholder]');
12
13
  ssrPlaceholders.forEach(function (elem) {
13
14
  var placeholderId = elem.getAttribute('data-ssr-placeholder');
@@ -17,4 +18,12 @@ function collectSSRPlaceholderDimensions(document, window) {
17
18
  window.__SSR_PLACEHOLDERS_DIMENSIONS__[placeholderId] = boundingClient;
18
19
  }
19
20
  });
21
+ if (enablePageLayoutPlaceholder) {
22
+ var pageLayoutRoot = document === null || document === void 0 ? void 0 : document.getElementById('unsafe-design-system-page-layout-root');
23
+ if (pageLayoutRoot) {
24
+ var boundingClient = pageLayoutRoot.getBoundingClientRect();
25
+ window.__SSR_PLACEHOLDERS_DIMENSIONS__ = window.__SSR_PLACEHOLDERS_DIMENSIONS__ || {};
26
+ window.__SSR_PLACEHOLDERS_DIMENSIONS__['page-layout.root'] = boundingClient;
27
+ }
28
+ }
20
29
  }
@@ -554,6 +554,9 @@ export class VCObserver {
554
554
  this.arraySize = options.heatmapSize || 200;
555
555
  this.devToolsEnabled = options.devToolsEnabled || false;
556
556
  this.oldDomUpdatesEnabled = options.oldDomUpdates || false;
557
+ const {
558
+ ssrEnablePageLayoutPlaceholder
559
+ } = options;
557
560
  this.observers = new Observers({
558
561
  selectorConfig: options.selectorConfig || {
559
562
  id: false,
@@ -561,6 +564,9 @@ export class VCObserver {
561
564
  role: false,
562
565
  className: true,
563
566
  dataVC: true
567
+ },
568
+ SSRConfig: {
569
+ enablePageLayoutPlaceholder: ssrEnablePageLayoutPlaceholder || false
564
570
  }
565
571
  });
566
572
  this.heatmap = !isVCRevisionEnabled('fy25.01') ? [] : this.getCleanHeatmap();
@@ -20,6 +20,7 @@ function isElementVisible(target) {
20
20
  }
21
21
  export class Observers {
22
22
  constructor(opts) {
23
+ var _opts$SSRConfig;
23
24
  _defineProperty(this, "observedMutations", new WeakMap());
24
25
  _defineProperty(this, "elementsInView", new Set());
25
26
  _defineProperty(this, "callbacks", new Set());
@@ -59,7 +60,7 @@ export class Observers {
59
60
  };
60
61
  this.intersectionObserver = this.getIntersectionObserver();
61
62
  this.mutationObserver = this.getMutationObserver();
62
- this.ssrPlaceholderHandler = new SSRPlaceholderHandlers();
63
+ this.ssrPlaceholderHandler = new SSRPlaceholderHandlers((_opts$SSRConfig = opts.SSRConfig) === null || _opts$SSRConfig === void 0 ? void 0 : _opts$SSRConfig.enablePageLayoutPlaceholder);
63
64
  }
64
65
  isBrowserSupported() {
65
66
  return typeof window.IntersectionObserver === 'function' && typeof window.MutationObserver === 'function';
@@ -1,12 +1,35 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  const ANCESTOR_LOOKUP_LIMIT = 10;
3
+ const PAGE_LAYOUT_ID = 'page-layout.root';
3
4
  export class SSRPlaceholderHandlers {
4
- constructor() {
5
+ constructor(enablePageLayoutPlaceholder = false) {
5
6
  _defineProperty(this, "staticPlaceholders", new Map());
6
7
  _defineProperty(this, "callbacks", new Map());
7
8
  _defineProperty(this, "getSizeCallbacks", new Map());
8
9
  _defineProperty(this, "reactValidateCallbacks", new Map());
9
10
  _defineProperty(this, "EQUALITY_THRESHOLD", 1);
11
+ _defineProperty(this, "getPlaceholderId", el => {
12
+ var _el$dataset;
13
+ const ssrPlaceholderId = el === null || el === void 0 ? void 0 : (_el$dataset = el.dataset) === null || _el$dataset === void 0 ? void 0 : _el$dataset.ssrPlaceholder;
14
+ if (!!ssrPlaceholderId) {
15
+ return ssrPlaceholderId;
16
+ }
17
+ if (this.enablePageLayoutPlaceholder && (el === null || el === void 0 ? void 0 : el.dataset.testid) === PAGE_LAYOUT_ID) {
18
+ return PAGE_LAYOUT_ID;
19
+ }
20
+ return '';
21
+ });
22
+ _defineProperty(this, "getPlaceholderReplacementId", el => {
23
+ var _el$dataset2;
24
+ const ssrPlaceholderReplaceId = el === null || el === void 0 ? void 0 : (_el$dataset2 = el.dataset) === null || _el$dataset2 === void 0 ? void 0 : _el$dataset2.ssrPlaceholderReplace;
25
+ if (!!ssrPlaceholderReplaceId) {
26
+ return ssrPlaceholderReplaceId;
27
+ }
28
+ if (this.enablePageLayoutPlaceholder && (el === null || el === void 0 ? void 0 : el.dataset.testid) === PAGE_LAYOUT_ID) {
29
+ return PAGE_LAYOUT_ID;
30
+ }
31
+ return '';
32
+ });
10
33
  _defineProperty(this, "intersectionObserverCallback", ({
11
34
  target,
12
35
  boundingClientRect
@@ -17,7 +40,7 @@ export class SSRPlaceholderHandlers {
17
40
  // impossible case - keep typescript healthy
18
41
  return;
19
42
  }
20
- const staticKey = target.dataset.ssrPlaceholder || '';
43
+ const staticKey = this.getPlaceholderId(target);
21
44
  if (staticKey) {
22
45
  if (this.staticPlaceholders.has(staticKey) && this.callbacks.has(staticKey)) {
23
46
  // validation
@@ -39,7 +62,7 @@ export class SSRPlaceholderHandlers {
39
62
  this.callbacks.delete(staticKey);
40
63
  }
41
64
  } else {
42
- const key = target.dataset.ssrPlaceholderReplace || '';
65
+ const key = this.getPlaceholderReplacementId(target);
43
66
  const resolve = this.reactValidateCallbacks.get(key);
44
67
  if (!resolve) {
45
68
  return;
@@ -63,25 +86,27 @@ export class SSRPlaceholderHandlers {
63
86
  // Only instantiate the IntersectionObserver if it's supported
64
87
  this.intersectionObserver = new IntersectionObserver(entries => entries.filter(entry => entry.intersectionRatio > 0).forEach(this.intersectionObserverCallback));
65
88
  }
89
+ this.enablePageLayoutPlaceholder = enablePageLayoutPlaceholder;
66
90
  if (window.document) {
67
91
  try {
68
- const existingElements = document.querySelectorAll('[data-ssr-placeholder]');
92
+ const selector = this.enablePageLayoutPlaceholder ? '[data-ssr-placeholder],[data-testid="page-layout.root"]' : '[data-ssr-placeholder]';
93
+ const existingElements = document.querySelectorAll(selector);
69
94
  existingElements.forEach(el => {
70
- var _el$dataset;
71
- if (el instanceof HTMLElement && el !== null && el !== void 0 && (_el$dataset = el.dataset) !== null && _el$dataset !== void 0 && _el$dataset.ssrPlaceholder) {
95
+ const placeholderId = el instanceof HTMLElement && this.getPlaceholderId(el);
96
+ if (placeholderId) {
72
97
  var _window$__SSR_PLACEHO, _this$intersectionObs2;
73
98
  let width = -1;
74
99
  let height = -1;
75
100
  let x = -1;
76
101
  let y = -1;
77
- const boundingClientRect = (_window$__SSR_PLACEHO = window.__SSR_PLACEHOLDERS_DIMENSIONS__) === null || _window$__SSR_PLACEHO === void 0 ? void 0 : _window$__SSR_PLACEHO[el.dataset.ssrPlaceholder];
102
+ const boundingClientRect = (_window$__SSR_PLACEHO = window.__SSR_PLACEHOLDERS_DIMENSIONS__) === null || _window$__SSR_PLACEHO === void 0 ? void 0 : _window$__SSR_PLACEHO[placeholderId];
78
103
  if (boundingClientRect) {
79
104
  width = boundingClientRect.width;
80
105
  height = boundingClientRect.height;
81
106
  x = boundingClientRect.x;
82
107
  y = boundingClientRect.y;
83
108
  }
84
- this.staticPlaceholders.set(el.dataset.ssrPlaceholder, {
109
+ this.staticPlaceholders.set(placeholderId, {
85
110
  width,
86
111
  height,
87
112
  x,
@@ -102,10 +127,10 @@ export class SSRPlaceholderHandlers {
102
127
  this.reactValidateCallbacks = new Map();
103
128
  }
104
129
  isPlaceholder(element) {
105
- return Boolean(element.dataset.ssrPlaceholder);
130
+ return Boolean(this.getPlaceholderId(element));
106
131
  }
107
132
  isPlaceholderReplacement(element) {
108
- return Boolean(element.dataset.ssrPlaceholderReplace);
133
+ return Boolean(this.getPlaceholderReplacementId(element));
109
134
  }
110
135
  isPlaceholderIgnored(element) {
111
136
  // data-ssr-placeholder-ignored doesn't have a value.
@@ -128,7 +153,7 @@ export class SSRPlaceholderHandlers {
128
153
  }
129
154
  checkIfExistedAndSizeMatching(el) {
130
155
  el = this.findNearestPlaceholderContainerIfIgnored(el);
131
- const id = el.dataset.ssrPlaceholder || '';
156
+ const id = this.getPlaceholderId(el);
132
157
  return new Promise(resolve => {
133
158
  if (!this.staticPlaceholders.has(id)) {
134
159
  resolve(false);
@@ -143,13 +168,13 @@ export class SSRPlaceholderHandlers {
143
168
  getSize(el) {
144
169
  return new Promise(resolve => {
145
170
  var _this$intersectionObs4;
146
- this.getSizeCallbacks.set(el.dataset.ssrPlaceholder || '', resolve);
171
+ this.getSizeCallbacks.set(this.getPlaceholderId(el), resolve);
147
172
  (_this$intersectionObs4 = this.intersectionObserver) === null || _this$intersectionObs4 === void 0 ? void 0 : _this$intersectionObs4.observe(el);
148
173
  });
149
174
  }
150
175
  validateReactComponentMatchToPlaceholder(el) {
151
176
  el = this.findNearestPlaceholderContainerIfIgnored(el);
152
- const id = el.dataset.ssrPlaceholderReplace || '';
177
+ const id = this.getPlaceholderReplacementId(el);
153
178
  return new Promise(resolve => {
154
179
  if (!this.staticPlaceholders.has(id)) {
155
180
  resolve(false);
@@ -1,7 +1,7 @@
1
1
  // lightweight script to scan the SSR response and collect all elements with data-ssr-placeholder attribute
2
2
  // and save their size/positions in a map __SSR_PLACEHOLDERS_DIMENSIONS__ on the Window object. Each placeholderId is
3
3
  // unique and maps to its corresponding elements bounding client rectangle dimensions.
4
- export function collectSSRPlaceholderDimensions(document, window) {
4
+ export function collectSSRPlaceholderDimensions(document, window, enablePageLayoutPlaceholder = false) {
5
5
  const ssrPlaceholders = document === null || document === void 0 ? void 0 : document.querySelectorAll('[data-ssr-placeholder]');
6
6
  ssrPlaceholders.forEach(elem => {
7
7
  const placeholderId = elem.getAttribute('data-ssr-placeholder');
@@ -11,4 +11,12 @@ export function collectSSRPlaceholderDimensions(document, window) {
11
11
  window.__SSR_PLACEHOLDERS_DIMENSIONS__[placeholderId] = boundingClient;
12
12
  }
13
13
  });
14
+ if (enablePageLayoutPlaceholder) {
15
+ const pageLayoutRoot = document === null || document === void 0 ? void 0 : document.getElementById('unsafe-design-system-page-layout-root');
16
+ if (pageLayoutRoot) {
17
+ const boundingClient = pageLayoutRoot.getBoundingClientRect();
18
+ window.__SSR_PLACEHOLDERS_DIMENSIONS__ = window.__SSR_PLACEHOLDERS_DIMENSIONS__ || {};
19
+ window.__SSR_PLACEHOLDERS_DIMENSIONS__['page-layout.root'] = boundingClient;
20
+ }
21
+ }
14
22
  }
@@ -516,6 +516,7 @@ export var VCObserver = /*#__PURE__*/function () {
516
516
  this.arraySize = options.heatmapSize || 200;
517
517
  this.devToolsEnabled = options.devToolsEnabled || false;
518
518
  this.oldDomUpdatesEnabled = options.oldDomUpdates || false;
519
+ var ssrEnablePageLayoutPlaceholder = options.ssrEnablePageLayoutPlaceholder;
519
520
  this.observers = new Observers({
520
521
  selectorConfig: options.selectorConfig || {
521
522
  id: false,
@@ -523,6 +524,9 @@ export var VCObserver = /*#__PURE__*/function () {
523
524
  role: false,
524
525
  className: true,
525
526
  dataVC: true
527
+ },
528
+ SSRConfig: {
529
+ enablePageLayoutPlaceholder: ssrEnablePageLayoutPlaceholder || false
526
530
  }
527
531
  });
528
532
  this.heatmap = !isVCRevisionEnabled('fy25.01') ? [] : this.getCleanHeatmap();
@@ -24,7 +24,8 @@ function isElementVisible(target) {
24
24
  }
25
25
  export var Observers = /*#__PURE__*/function () {
26
26
  function Observers(opts) {
27
- var _this = this;
27
+ var _this = this,
28
+ _opts$SSRConfig;
28
29
  _classCallCheck(this, Observers);
29
30
  _defineProperty(this, "observedMutations", new WeakMap());
30
31
  _defineProperty(this, "elementsInView", new Set());
@@ -64,7 +65,7 @@ export var Observers = /*#__PURE__*/function () {
64
65
  this.selectorConfig = _objectSpread(_objectSpread({}, this.selectorConfig), opts.selectorConfig);
65
66
  this.intersectionObserver = this.getIntersectionObserver();
66
67
  this.mutationObserver = this.getMutationObserver();
67
- this.ssrPlaceholderHandler = new SSRPlaceholderHandlers();
68
+ this.ssrPlaceholderHandler = new SSRPlaceholderHandlers((_opts$SSRConfig = opts.SSRConfig) === null || _opts$SSRConfig === void 0 ? void 0 : _opts$SSRConfig.enablePageLayoutPlaceholder);
68
69
  }
69
70
  return _createClass(Observers, [{
70
71
  key: "isBrowserSupported",
@@ -2,15 +2,39 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  var ANCESTOR_LOOKUP_LIMIT = 10;
5
+ var PAGE_LAYOUT_ID = 'page-layout.root';
5
6
  export var SSRPlaceholderHandlers = /*#__PURE__*/function () {
6
7
  function SSRPlaceholderHandlers() {
7
8
  var _this = this;
9
+ var enablePageLayoutPlaceholder = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
8
10
  _classCallCheck(this, SSRPlaceholderHandlers);
9
11
  _defineProperty(this, "staticPlaceholders", new Map());
10
12
  _defineProperty(this, "callbacks", new Map());
11
13
  _defineProperty(this, "getSizeCallbacks", new Map());
12
14
  _defineProperty(this, "reactValidateCallbacks", new Map());
13
15
  _defineProperty(this, "EQUALITY_THRESHOLD", 1);
16
+ _defineProperty(this, "getPlaceholderId", function (el) {
17
+ var _el$dataset;
18
+ var ssrPlaceholderId = el === null || el === void 0 || (_el$dataset = el.dataset) === null || _el$dataset === void 0 ? void 0 : _el$dataset.ssrPlaceholder;
19
+ if (!!ssrPlaceholderId) {
20
+ return ssrPlaceholderId;
21
+ }
22
+ if (_this.enablePageLayoutPlaceholder && (el === null || el === void 0 ? void 0 : el.dataset.testid) === PAGE_LAYOUT_ID) {
23
+ return PAGE_LAYOUT_ID;
24
+ }
25
+ return '';
26
+ });
27
+ _defineProperty(this, "getPlaceholderReplacementId", function (el) {
28
+ var _el$dataset2;
29
+ var ssrPlaceholderReplaceId = el === null || el === void 0 || (_el$dataset2 = el.dataset) === null || _el$dataset2 === void 0 ? void 0 : _el$dataset2.ssrPlaceholderReplace;
30
+ if (!!ssrPlaceholderReplaceId) {
31
+ return ssrPlaceholderReplaceId;
32
+ }
33
+ if (_this.enablePageLayoutPlaceholder && (el === null || el === void 0 ? void 0 : el.dataset.testid) === PAGE_LAYOUT_ID) {
34
+ return PAGE_LAYOUT_ID;
35
+ }
36
+ return '';
37
+ });
14
38
  _defineProperty(this, "intersectionObserverCallback", function (_ref) {
15
39
  var _this$intersectionObs;
16
40
  var target = _ref.target,
@@ -20,7 +44,7 @@ export var SSRPlaceholderHandlers = /*#__PURE__*/function () {
20
44
  // impossible case - keep typescript healthy
21
45
  return;
22
46
  }
23
- var staticKey = target.dataset.ssrPlaceholder || '';
47
+ var staticKey = _this.getPlaceholderId(target);
24
48
  if (staticKey) {
25
49
  if (_this.staticPlaceholders.has(staticKey) && _this.callbacks.has(staticKey)) {
26
50
  // validation
@@ -42,7 +66,7 @@ export var SSRPlaceholderHandlers = /*#__PURE__*/function () {
42
66
  _this.callbacks.delete(staticKey);
43
67
  }
44
68
  } else {
45
- var key = target.dataset.ssrPlaceholderReplace || '';
69
+ var key = _this.getPlaceholderReplacementId(target);
46
70
  var _resolve2 = _this.reactValidateCallbacks.get(key);
47
71
  if (!_resolve2) {
48
72
  return;
@@ -70,25 +94,27 @@ export var SSRPlaceholderHandlers = /*#__PURE__*/function () {
70
94
  }).forEach(_this.intersectionObserverCallback);
71
95
  });
72
96
  }
97
+ this.enablePageLayoutPlaceholder = enablePageLayoutPlaceholder;
73
98
  if (window.document) {
74
99
  try {
75
- var existingElements = document.querySelectorAll('[data-ssr-placeholder]');
100
+ var selector = this.enablePageLayoutPlaceholder ? '[data-ssr-placeholder],[data-testid="page-layout.root"]' : '[data-ssr-placeholder]';
101
+ var existingElements = document.querySelectorAll(selector);
76
102
  existingElements.forEach(function (el) {
77
- var _el$dataset;
78
- if (el instanceof HTMLElement && el !== null && el !== void 0 && (_el$dataset = el.dataset) !== null && _el$dataset !== void 0 && _el$dataset.ssrPlaceholder) {
103
+ var placeholderId = el instanceof HTMLElement && _this.getPlaceholderId(el);
104
+ if (placeholderId) {
79
105
  var _window$__SSR_PLACEHO, _this$intersectionObs2;
80
106
  var width = -1;
81
107
  var height = -1;
82
108
  var x = -1;
83
109
  var y = -1;
84
- var boundingClientRect = (_window$__SSR_PLACEHO = window.__SSR_PLACEHOLDERS_DIMENSIONS__) === null || _window$__SSR_PLACEHO === void 0 ? void 0 : _window$__SSR_PLACEHO[el.dataset.ssrPlaceholder];
110
+ var boundingClientRect = (_window$__SSR_PLACEHO = window.__SSR_PLACEHOLDERS_DIMENSIONS__) === null || _window$__SSR_PLACEHO === void 0 ? void 0 : _window$__SSR_PLACEHO[placeholderId];
85
111
  if (boundingClientRect) {
86
112
  width = boundingClientRect.width;
87
113
  height = boundingClientRect.height;
88
114
  x = boundingClientRect.x;
89
115
  y = boundingClientRect.y;
90
116
  }
91
- _this.staticPlaceholders.set(el.dataset.ssrPlaceholder, {
117
+ _this.staticPlaceholders.set(placeholderId, {
92
118
  width: width,
93
119
  height: height,
94
120
  x: x,
@@ -113,12 +139,12 @@ export var SSRPlaceholderHandlers = /*#__PURE__*/function () {
113
139
  }, {
114
140
  key: "isPlaceholder",
115
141
  value: function isPlaceholder(element) {
116
- return Boolean(element.dataset.ssrPlaceholder);
142
+ return Boolean(this.getPlaceholderId(element));
117
143
  }
118
144
  }, {
119
145
  key: "isPlaceholderReplacement",
120
146
  value: function isPlaceholderReplacement(element) {
121
- return Boolean(element.dataset.ssrPlaceholderReplace);
147
+ return Boolean(this.getPlaceholderReplacementId(element));
122
148
  }
123
149
  }, {
124
150
  key: "isPlaceholderIgnored",
@@ -148,7 +174,7 @@ export var SSRPlaceholderHandlers = /*#__PURE__*/function () {
148
174
  value: function checkIfExistedAndSizeMatching(el) {
149
175
  var _this2 = this;
150
176
  el = this.findNearestPlaceholderContainerIfIgnored(el);
151
- var id = el.dataset.ssrPlaceholder || '';
177
+ var id = this.getPlaceholderId(el);
152
178
  return new Promise(function (resolve) {
153
179
  if (!_this2.staticPlaceholders.has(id)) {
154
180
  resolve(false);
@@ -166,7 +192,7 @@ export var SSRPlaceholderHandlers = /*#__PURE__*/function () {
166
192
  var _this3 = this;
167
193
  return new Promise(function (resolve) {
168
194
  var _this3$intersectionOb;
169
- _this3.getSizeCallbacks.set(el.dataset.ssrPlaceholder || '', resolve);
195
+ _this3.getSizeCallbacks.set(_this3.getPlaceholderId(el), resolve);
170
196
  (_this3$intersectionOb = _this3.intersectionObserver) === null || _this3$intersectionOb === void 0 || _this3$intersectionOb.observe(el);
171
197
  });
172
198
  }
@@ -175,7 +201,7 @@ export var SSRPlaceholderHandlers = /*#__PURE__*/function () {
175
201
  value: function validateReactComponentMatchToPlaceholder(el) {
176
202
  var _this4 = this;
177
203
  el = this.findNearestPlaceholderContainerIfIgnored(el);
178
- var id = el.dataset.ssrPlaceholderReplace || '';
204
+ var id = this.getPlaceholderReplacementId(el);
179
205
  return new Promise(function (resolve) {
180
206
  if (!_this4.staticPlaceholders.has(id)) {
181
207
  resolve(false);
@@ -2,6 +2,7 @@
2
2
  // and save their size/positions in a map __SSR_PLACEHOLDERS_DIMENSIONS__ on the Window object. Each placeholderId is
3
3
  // unique and maps to its corresponding elements bounding client rectangle dimensions.
4
4
  export function collectSSRPlaceholderDimensions(document, window) {
5
+ var enablePageLayoutPlaceholder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
5
6
  var ssrPlaceholders = document === null || document === void 0 ? void 0 : document.querySelectorAll('[data-ssr-placeholder]');
6
7
  ssrPlaceholders.forEach(function (elem) {
7
8
  var placeholderId = elem.getAttribute('data-ssr-placeholder');
@@ -11,4 +12,12 @@ export function collectSSRPlaceholderDimensions(document, window) {
11
12
  window.__SSR_PLACEHOLDERS_DIMENSIONS__[placeholderId] = boundingClient;
12
13
  }
13
14
  });
15
+ if (enablePageLayoutPlaceholder) {
16
+ var pageLayoutRoot = document === null || document === void 0 ? void 0 : document.getElementById('unsafe-design-system-page-layout-root');
17
+ if (pageLayoutRoot) {
18
+ var boundingClient = pageLayoutRoot.getBoundingClientRect();
19
+ window.__SSR_PLACEHOLDERS_DIMENSIONS__ = window.__SSR_PLACEHOLDERS_DIMENSIONS__ || {};
20
+ window.__SSR_PLACEHOLDERS_DIMENSIONS__['page-layout.root'] = boundingClient;
21
+ }
22
+ }
14
23
  }
@@ -73,6 +73,7 @@ export type Config = {
73
73
  readonly selectorConfig?: SelectorConfig;
74
74
  readonly ssr?: boolean;
75
75
  readonly ssrWhitelist?: string[];
76
+ readonly ssrEnablePageLayoutPlaceholder?: boolean;
76
77
  readonly stopVCAtInteractionFinish?: boolean;
77
78
  /**
78
79
  * The revisions of TTVC that will be calculated
@@ -23,6 +23,7 @@ export type VCObserverOptions = {
23
23
  devToolsEnabled?: boolean | undefined;
24
24
  selectorConfig?: SelectorConfig | undefined;
25
25
  isPostInteraction?: boolean;
26
+ ssrEnablePageLayoutPlaceholder?: boolean;
26
27
  };
27
28
  export interface VCObserverInterface {
28
29
  start(startArg: {
@@ -9,6 +9,9 @@ export type SelectorConfig = {
9
9
  };
10
10
  type ConstructorOptions = {
11
11
  selectorConfig: SelectorConfig;
12
+ SSRConfig?: {
13
+ enablePageLayoutPlaceholder: boolean;
14
+ };
12
15
  };
13
16
  export declare class Observers implements BrowserObservers {
14
17
  private intersectionObserver;
@@ -11,7 +11,10 @@ export declare class SSRPlaceholderHandlers {
11
11
  private reactValidateCallbacks;
12
12
  private intersectionObserver;
13
13
  private EQUALITY_THRESHOLD;
14
- constructor();
14
+ private enablePageLayoutPlaceholder;
15
+ constructor(enablePageLayoutPlaceholder?: boolean);
16
+ private getPlaceholderId;
17
+ private getPlaceholderReplacementId;
15
18
  clear(): void;
16
19
  isPlaceholder(element: HTMLElement): boolean;
17
20
  isPlaceholderReplacement(element: HTMLElement): boolean;
@@ -1 +1 @@
1
- export declare function collectSSRPlaceholderDimensions(document: Document, window: Window): void;
1
+ export declare function collectSSRPlaceholderDimensions(document: Document, window: Window, enablePageLayoutPlaceholder?: boolean): void;
@@ -73,6 +73,7 @@ export type Config = {
73
73
  readonly selectorConfig?: SelectorConfig;
74
74
  readonly ssr?: boolean;
75
75
  readonly ssrWhitelist?: string[];
76
+ readonly ssrEnablePageLayoutPlaceholder?: boolean;
76
77
  readonly stopVCAtInteractionFinish?: boolean;
77
78
  /**
78
79
  * The revisions of TTVC that will be calculated
@@ -23,6 +23,7 @@ export type VCObserverOptions = {
23
23
  devToolsEnabled?: boolean | undefined;
24
24
  selectorConfig?: SelectorConfig | undefined;
25
25
  isPostInteraction?: boolean;
26
+ ssrEnablePageLayoutPlaceholder?: boolean;
26
27
  };
27
28
  export interface VCObserverInterface {
28
29
  start(startArg: {
@@ -9,6 +9,9 @@ export type SelectorConfig = {
9
9
  };
10
10
  type ConstructorOptions = {
11
11
  selectorConfig: SelectorConfig;
12
+ SSRConfig?: {
13
+ enablePageLayoutPlaceholder: boolean;
14
+ };
12
15
  };
13
16
  export declare class Observers implements BrowserObservers {
14
17
  private intersectionObserver;
@@ -11,7 +11,10 @@ export declare class SSRPlaceholderHandlers {
11
11
  private reactValidateCallbacks;
12
12
  private intersectionObserver;
13
13
  private EQUALITY_THRESHOLD;
14
- constructor();
14
+ private enablePageLayoutPlaceholder;
15
+ constructor(enablePageLayoutPlaceholder?: boolean);
16
+ private getPlaceholderId;
17
+ private getPlaceholderReplacementId;
15
18
  clear(): void;
16
19
  isPlaceholder(element: HTMLElement): boolean;
17
20
  isPlaceholderReplacement(element: HTMLElement): boolean;
@@ -1 +1 @@
1
- export declare function collectSSRPlaceholderDimensions(document: Document, window: Window): void;
1
+ export declare function collectSSRPlaceholderDimensions(document: Document, window: Window, enablePageLayoutPlaceholder?: boolean): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/react-ufo",
3
- "version": "3.12.5",
3
+ "version": "3.13.0",
4
4
  "description": "Parts of React UFO that are publicly available",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",