@atlaskit/smart-card 46.8.1 → 46.8.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @atlaskit/smart-card
2
2
 
3
+ ## 46.8.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`baff2e6826566`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/baff2e6826566) -
8
+ Behind `platform_sl_embed_modal_escape_isolation`: the Smart Link embed preview modal now only
9
+ handles Escape while it is the active layer, i.e. it is in front of the modal dialog stack and
10
+ focus is inside it (or fell back to the body after last being inside it). A dialog opened on top
11
+ of the preview, such as a Share dialog, now closes on Escape instead of the preview.
12
+
3
13
  ## 46.8.1
4
14
 
5
15
  ### Patch Changes
@@ -25,7 +25,7 @@ var ANALYTICS_CHANNEL = exports.ANALYTICS_CHANNEL = 'media';
25
25
  var context = exports.context = {
26
26
  componentName: 'smart-cards',
27
27
  packageName: "@atlaskit/smart-card" || '',
28
- packageVersion: "46.8.0" || ''
28
+ packageVersion: "46.8.1" || ''
29
29
  };
30
30
  var TrackQuickActionType = exports.TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
31
31
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -158,34 +158,74 @@ var EmbedModal = function EmbedModal(_ref) {
158
158
  // `window` keydown listeners, so without this they would all close on a single Escape press.
159
159
  // Handle Escape during the capture phase on `window`, close only this modal, and stop the event
160
160
  // before it reaches the layers underneath.
161
+ // Only claim Escape while this modal is the active layer, so a dialog opened on top of it (e.g. a
162
+ // Share dialog from the page underneath) keeps its Escape:
163
+ // - it is in front of the modal dialog stack, which is shared across React roots (the same rule
164
+ // `ModalDialog` uses to decide whether it closes on Escape), and
165
+ // - focus is inside it, or focus fell back to `<body>` after last being inside it (as the
166
+ // top-layer `Dialog` decides), which covers layers on top that are not modal dialogs.
167
+ var dialogRef = (0, _react.useRef)(null);
168
+ // A newly opened modal dialog starts in front of the stack; `onStackChange` reports later moves.
169
+ var stackIndexRef = (0, _react.useRef)(0);
170
+ var handleOnStackChange = (0, _react.useCallback)(function (stackIndex) {
171
+ stackIndexRef.current = stackIndex;
172
+ }, []);
161
173
  (0, _react.useEffect)(function () {
174
+ var _dialogRef$current$ow, _dialogRef$current2;
162
175
  if (!isOpen || !(0, _fg.fg)('platform_sl_embed_modal_escape_isolation')) {
163
176
  return;
164
177
  }
178
+ var isInsideDialog = function isInsideDialog(node) {
179
+ var _dialogRef$current;
180
+ return node instanceof Node && Boolean((_dialogRef$current = dialogRef.current) === null || _dialogRef$current === void 0 ? void 0 : _dialogRef$current.contains(node));
181
+ };
182
+ var wasLastFocused = isInsideDialog((_dialogRef$current$ow = (_dialogRef$current2 = dialogRef.current) === null || _dialogRef$current2 === void 0 ? void 0 : _dialogRef$current2.ownerDocument.activeElement) !== null && _dialogRef$current$ow !== void 0 ? _dialogRef$current$ow : null);
183
+ var handleFocusIn = function handleFocusIn(event) {
184
+ wasLastFocused = isInsideDialog(event.target);
185
+ };
186
+ var isOwnEscape = function isOwnEscape(event) {
187
+ var dialog = dialogRef.current;
188
+ if (!dialog) {
189
+ return false;
190
+ }
191
+ if (event.target instanceof HTMLBodyElement || event.target instanceof HTMLHtmlElement) {
192
+ return wasLastFocused;
193
+ }
194
+ return event.composedPath().includes(dialog);
195
+ };
165
196
  var handleEscapeKeyDown = function handleEscapeKeyDown(event) {
166
- if (event.key !== 'Escape' || event.defaultPrevented || event.isComposing) {
197
+ if (event.key !== 'Escape' || event.defaultPrevented || event.isComposing || stackIndexRef.current !== 0 || !isOwnEscape(event)) {
167
198
  return;
168
199
  }
169
200
  event.stopPropagation();
170
201
  handleOnClose();
171
202
  };
203
+ window.addEventListener('focusin', handleFocusIn, {
204
+ capture: true
205
+ });
172
206
  window.addEventListener('keydown', handleEscapeKeyDown, {
173
207
  capture: true
174
208
  });
175
209
  return function () {
210
+ window.removeEventListener('focusin', handleFocusIn, {
211
+ capture: true
212
+ });
176
213
  window.removeEventListener('keydown', handleEscapeKeyDown, {
177
214
  capture: true
178
215
  });
216
+ stackIndexRef.current = 0;
179
217
  };
180
218
  }, [isOpen, handleOnClose]);
181
219
  return /*#__PURE__*/_react.default.createElement(_modalTransition.default, null, isOpen &&
182
220
  /*#__PURE__*/
183
221
  // eslint-disable-next-line @atlaskit/design-system/no-modal-label
184
222
  _react.default.createElement(_modalDialog.default, {
223
+ ref: dialogRef,
185
224
  height: "100%",
186
225
  onClose: handleOnClose,
187
226
  onCloseComplete: handleOnCloseComplete,
188
227
  onOpenComplete: handleOnOpenComplete,
228
+ onStackChange: handleOnStackChange,
189
229
  testId: testId,
190
230
  width: width,
191
231
  label: title,
@@ -19,7 +19,7 @@ var _excluded = ["href", "children", "checkSafety", "onClick", "testId", "isLink
19
19
  _excluded2 = ["isLinkSafe", "showSafetyWarningModal"];
20
20
  var PACKAGE_DATA = {
21
21
  packageName: "@atlaskit/smart-card",
22
- packageVersion: "46.8.0",
22
+ packageVersion: "46.8.1",
23
23
  componentName: 'linkUrl'
24
24
  };
25
25
  var LinkUrl = function LinkUrl(_ref) {
@@ -4,7 +4,7 @@ export const ANALYTICS_CHANNEL = 'media';
4
4
  export const context = {
5
5
  componentName: 'smart-cards',
6
6
  packageName: "@atlaskit/smart-card" || '',
7
- packageVersion: "46.8.0" || ''
7
+ packageVersion: "46.8.1" || ''
8
8
  };
9
9
  export let TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
10
10
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -134,34 +134,74 @@ const EmbedModal = ({
134
134
  // `window` keydown listeners, so without this they would all close on a single Escape press.
135
135
  // Handle Escape during the capture phase on `window`, close only this modal, and stop the event
136
136
  // before it reaches the layers underneath.
137
+ // Only claim Escape while this modal is the active layer, so a dialog opened on top of it (e.g. a
138
+ // Share dialog from the page underneath) keeps its Escape:
139
+ // - it is in front of the modal dialog stack, which is shared across React roots (the same rule
140
+ // `ModalDialog` uses to decide whether it closes on Escape), and
141
+ // - focus is inside it, or focus fell back to `<body>` after last being inside it (as the
142
+ // top-layer `Dialog` decides), which covers layers on top that are not modal dialogs.
143
+ const dialogRef = useRef(null);
144
+ // A newly opened modal dialog starts in front of the stack; `onStackChange` reports later moves.
145
+ const stackIndexRef = useRef(0);
146
+ const handleOnStackChange = useCallback(stackIndex => {
147
+ stackIndexRef.current = stackIndex;
148
+ }, []);
137
149
  useEffect(() => {
150
+ var _dialogRef$current$ow, _dialogRef$current2;
138
151
  if (!isOpen || !fg('platform_sl_embed_modal_escape_isolation')) {
139
152
  return;
140
153
  }
154
+ const isInsideDialog = node => {
155
+ var _dialogRef$current;
156
+ return node instanceof Node && Boolean((_dialogRef$current = dialogRef.current) === null || _dialogRef$current === void 0 ? void 0 : _dialogRef$current.contains(node));
157
+ };
158
+ let wasLastFocused = isInsideDialog((_dialogRef$current$ow = (_dialogRef$current2 = dialogRef.current) === null || _dialogRef$current2 === void 0 ? void 0 : _dialogRef$current2.ownerDocument.activeElement) !== null && _dialogRef$current$ow !== void 0 ? _dialogRef$current$ow : null);
159
+ const handleFocusIn = event => {
160
+ wasLastFocused = isInsideDialog(event.target);
161
+ };
162
+ const isOwnEscape = event => {
163
+ const dialog = dialogRef.current;
164
+ if (!dialog) {
165
+ return false;
166
+ }
167
+ if (event.target instanceof HTMLBodyElement || event.target instanceof HTMLHtmlElement) {
168
+ return wasLastFocused;
169
+ }
170
+ return event.composedPath().includes(dialog);
171
+ };
141
172
  const handleEscapeKeyDown = event => {
142
- if (event.key !== 'Escape' || event.defaultPrevented || event.isComposing) {
173
+ if (event.key !== 'Escape' || event.defaultPrevented || event.isComposing || stackIndexRef.current !== 0 || !isOwnEscape(event)) {
143
174
  return;
144
175
  }
145
176
  event.stopPropagation();
146
177
  handleOnClose();
147
178
  };
179
+ window.addEventListener('focusin', handleFocusIn, {
180
+ capture: true
181
+ });
148
182
  window.addEventListener('keydown', handleEscapeKeyDown, {
149
183
  capture: true
150
184
  });
151
185
  return () => {
186
+ window.removeEventListener('focusin', handleFocusIn, {
187
+ capture: true
188
+ });
152
189
  window.removeEventListener('keydown', handleEscapeKeyDown, {
153
190
  capture: true
154
191
  });
192
+ stackIndexRef.current = 0;
155
193
  };
156
194
  }, [isOpen, handleOnClose]);
157
195
  return /*#__PURE__*/React.createElement(ModalTransition, null, isOpen &&
158
196
  /*#__PURE__*/
159
197
  // eslint-disable-next-line @atlaskit/design-system/no-modal-label
160
198
  React.createElement(ModalDialog, {
199
+ ref: dialogRef,
161
200
  height: "100%",
162
201
  onClose: handleOnClose,
163
202
  onCloseComplete: handleOnCloseComplete,
164
203
  onOpenComplete: handleOnOpenComplete,
204
+ onStackChange: handleOnStackChange,
165
205
  testId: testId,
166
206
  width: width,
167
207
  label: title,
@@ -9,7 +9,7 @@ import LinkWarningModal from './LinkWarningModal';
9
9
  import { useLinkWarningModal } from './LinkWarningModal/hooks/use-link-warning-modal';
10
10
  const PACKAGE_DATA = {
11
11
  packageName: "@atlaskit/smart-card",
12
- packageVersion: "46.8.0",
12
+ packageVersion: "46.8.1",
13
13
  componentName: 'linkUrl'
14
14
  };
15
15
  const LinkUrl = ({
@@ -4,7 +4,7 @@ export var ANALYTICS_CHANNEL = 'media';
4
4
  export var context = {
5
5
  componentName: 'smart-cards',
6
6
  packageName: "@atlaskit/smart-card" || '',
7
- packageVersion: "46.8.0" || ''
7
+ packageVersion: "46.8.1" || ''
8
8
  };
9
9
  export var TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
10
10
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -149,34 +149,74 @@ var EmbedModal = function EmbedModal(_ref) {
149
149
  // `window` keydown listeners, so without this they would all close on a single Escape press.
150
150
  // Handle Escape during the capture phase on `window`, close only this modal, and stop the event
151
151
  // before it reaches the layers underneath.
152
+ // Only claim Escape while this modal is the active layer, so a dialog opened on top of it (e.g. a
153
+ // Share dialog from the page underneath) keeps its Escape:
154
+ // - it is in front of the modal dialog stack, which is shared across React roots (the same rule
155
+ // `ModalDialog` uses to decide whether it closes on Escape), and
156
+ // - focus is inside it, or focus fell back to `<body>` after last being inside it (as the
157
+ // top-layer `Dialog` decides), which covers layers on top that are not modal dialogs.
158
+ var dialogRef = useRef(null);
159
+ // A newly opened modal dialog starts in front of the stack; `onStackChange` reports later moves.
160
+ var stackIndexRef = useRef(0);
161
+ var handleOnStackChange = useCallback(function (stackIndex) {
162
+ stackIndexRef.current = stackIndex;
163
+ }, []);
152
164
  useEffect(function () {
165
+ var _dialogRef$current$ow, _dialogRef$current2;
153
166
  if (!isOpen || !fg('platform_sl_embed_modal_escape_isolation')) {
154
167
  return;
155
168
  }
169
+ var isInsideDialog = function isInsideDialog(node) {
170
+ var _dialogRef$current;
171
+ return node instanceof Node && Boolean((_dialogRef$current = dialogRef.current) === null || _dialogRef$current === void 0 ? void 0 : _dialogRef$current.contains(node));
172
+ };
173
+ var wasLastFocused = isInsideDialog((_dialogRef$current$ow = (_dialogRef$current2 = dialogRef.current) === null || _dialogRef$current2 === void 0 ? void 0 : _dialogRef$current2.ownerDocument.activeElement) !== null && _dialogRef$current$ow !== void 0 ? _dialogRef$current$ow : null);
174
+ var handleFocusIn = function handleFocusIn(event) {
175
+ wasLastFocused = isInsideDialog(event.target);
176
+ };
177
+ var isOwnEscape = function isOwnEscape(event) {
178
+ var dialog = dialogRef.current;
179
+ if (!dialog) {
180
+ return false;
181
+ }
182
+ if (event.target instanceof HTMLBodyElement || event.target instanceof HTMLHtmlElement) {
183
+ return wasLastFocused;
184
+ }
185
+ return event.composedPath().includes(dialog);
186
+ };
156
187
  var handleEscapeKeyDown = function handleEscapeKeyDown(event) {
157
- if (event.key !== 'Escape' || event.defaultPrevented || event.isComposing) {
188
+ if (event.key !== 'Escape' || event.defaultPrevented || event.isComposing || stackIndexRef.current !== 0 || !isOwnEscape(event)) {
158
189
  return;
159
190
  }
160
191
  event.stopPropagation();
161
192
  handleOnClose();
162
193
  };
194
+ window.addEventListener('focusin', handleFocusIn, {
195
+ capture: true
196
+ });
163
197
  window.addEventListener('keydown', handleEscapeKeyDown, {
164
198
  capture: true
165
199
  });
166
200
  return function () {
201
+ window.removeEventListener('focusin', handleFocusIn, {
202
+ capture: true
203
+ });
167
204
  window.removeEventListener('keydown', handleEscapeKeyDown, {
168
205
  capture: true
169
206
  });
207
+ stackIndexRef.current = 0;
170
208
  };
171
209
  }, [isOpen, handleOnClose]);
172
210
  return /*#__PURE__*/React.createElement(ModalTransition, null, isOpen &&
173
211
  /*#__PURE__*/
174
212
  // eslint-disable-next-line @atlaskit/design-system/no-modal-label
175
213
  React.createElement(ModalDialog, {
214
+ ref: dialogRef,
176
215
  height: "100%",
177
216
  onClose: handleOnClose,
178
217
  onCloseComplete: handleOnCloseComplete,
179
218
  onOpenComplete: handleOnOpenComplete,
219
+ onStackChange: handleOnStackChange,
180
220
  testId: testId,
181
221
  width: width,
182
222
  label: title,
@@ -12,7 +12,7 @@ import LinkWarningModal from './LinkWarningModal';
12
12
  import { useLinkWarningModal } from './LinkWarningModal/hooks/use-link-warning-modal';
13
13
  var PACKAGE_DATA = {
14
14
  packageName: "@atlaskit/smart-card",
15
- packageVersion: "46.8.0",
15
+ packageVersion: "46.8.1",
16
16
  componentName: 'linkUrl'
17
17
  };
18
18
  var LinkUrl = function LinkUrl(_ref) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "46.8.1",
3
+ "version": "46.8.2",
4
4
  "description": "Smart card component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -94,7 +94,7 @@
94
94
  "@atlaskit/textfield": "^10.2.0",
95
95
  "@atlaskit/theme": "^28.2.0",
96
96
  "@atlaskit/tile": "^5.0.0",
97
- "@atlaskit/tmp-editor-statsig": "^246.0.0",
97
+ "@atlaskit/tmp-editor-statsig": "^246.1.0",
98
98
  "@atlaskit/tokens": "^20.7.0",
99
99
  "@atlaskit/tooltip": "^24.4.0",
100
100
  "@atlaskit/top-layer": "^6.7.0",