@atlaskit/spotlight 0.4.0 → 0.5.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.
- package/CHANGELOG.md +15 -0
- package/dist/cjs/controllers/context.js +38 -0
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/ui/UNSAFE_update-on-change/index.js +59 -0
- package/dist/cjs/ui/popover-content/index.js +19 -4
- package/dist/es2019/controllers/context.js +9 -0
- package/dist/es2019/index.js +2 -1
- package/dist/es2019/ui/UNSAFE_update-on-change/index.js +53 -0
- package/dist/es2019/ui/popover-content/index.js +14 -5
- package/dist/esm/controllers/context.js +38 -0
- package/dist/esm/index.js +2 -1
- package/dist/esm/ui/UNSAFE_update-on-change/index.js +53 -0
- package/dist/esm/ui/popover-content/index.js +20 -5
- package/dist/types/controllers/context.d.ts +5 -2
- package/dist/types/index.d.ts +2 -1
- package/dist/types/ui/UNSAFE_update-on-change/index.d.ts +6 -0
- package/dist/types/ui/popover-content/index.d.ts +1 -2
- package/dist/types-ts4.5/controllers/context.d.ts +5 -2
- package/dist/types-ts4.5/index.d.ts +2 -1
- package/dist/types-ts4.5/ui/UNSAFE_update-on-change/index.d.ts +6 -0
- package/dist/types-ts4.5/ui/popover-content/index.d.ts +1 -2
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/spotlight
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`72526321aecd0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/72526321aecd0) -
|
|
8
|
+
Create UNSAFE_UpdateOnChange component to test strategies for recalculating PopoverContent
|
|
9
|
+
position when the DOM changes.
|
|
10
|
+
|
|
11
|
+
## 0.4.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`499c871b73060`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/499c871b73060) -
|
|
16
|
+
Exports the PopoverContentProps
|
|
17
|
+
|
|
3
18
|
## 0.4.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
|
@@ -10,6 +10,8 @@ exports.SpotlightContextProvider = exports.SpotlightContext = void 0;
|
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
var React = _react;
|
|
12
12
|
var _runtime = require("@compiled/react/runtime");
|
|
13
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
14
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
15
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
14
16
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
15
17
|
// eslint-disable-next-line @repo/internal/react/consistent-types-definitions
|
|
@@ -25,6 +27,22 @@ var SpotlightContext = exports.SpotlightContext = /*#__PURE__*/(0, _react.create
|
|
|
25
27
|
setId: function setId() {
|
|
26
28
|
return undefined;
|
|
27
29
|
}
|
|
30
|
+
},
|
|
31
|
+
popoverContent: {
|
|
32
|
+
update: function update() {
|
|
33
|
+
return function () {
|
|
34
|
+
return new Promise(function () {
|
|
35
|
+
return null;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
setUpdate: function setUpdate() {
|
|
40
|
+
return function () {
|
|
41
|
+
return new Promise(function () {
|
|
42
|
+
return null;
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
28
46
|
}
|
|
29
47
|
});
|
|
30
48
|
|
|
@@ -40,6 +58,22 @@ var SpotlightContextProvider = exports.SpotlightContextProvider = function Spotl
|
|
|
40
58
|
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
41
59
|
headingId = _useState4[0],
|
|
42
60
|
setHeadingId = _useState4[1];
|
|
61
|
+
var _useState5 = (0, _react.useState)(function () {
|
|
62
|
+
return /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
63
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
64
|
+
while (1) switch (_context.prev = _context.next) {
|
|
65
|
+
case 0:
|
|
66
|
+
return _context.abrupt("return", undefined);
|
|
67
|
+
case 1:
|
|
68
|
+
case "end":
|
|
69
|
+
return _context.stop();
|
|
70
|
+
}
|
|
71
|
+
}, _callee);
|
|
72
|
+
}));
|
|
73
|
+
}),
|
|
74
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
75
|
+
update = _useState6[0],
|
|
76
|
+
setUpdate = _useState6[1];
|
|
43
77
|
return /*#__PURE__*/React.createElement(SpotlightContext.Provider, {
|
|
44
78
|
value: {
|
|
45
79
|
placement: placement,
|
|
@@ -47,6 +81,10 @@ var SpotlightContextProvider = exports.SpotlightContextProvider = function Spotl
|
|
|
47
81
|
heading: {
|
|
48
82
|
id: headingId,
|
|
49
83
|
setId: setHeadingId
|
|
84
|
+
},
|
|
85
|
+
popoverContent: {
|
|
86
|
+
update: update,
|
|
87
|
+
setUpdate: setUpdate
|
|
50
88
|
}
|
|
51
89
|
}
|
|
52
90
|
}, children);
|
package/dist/cjs/index.js
CHANGED
|
@@ -99,6 +99,12 @@ Object.defineProperty(exports, "SpotlightStepCount", {
|
|
|
99
99
|
return _stepCount.SpotlightStepCount;
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
|
+
Object.defineProperty(exports, "UNSAFE_UpdateOnChange", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
get: function get() {
|
|
105
|
+
return _UNSAFE_updateOnChange.UNSAFE_UpdateOnChange;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
102
108
|
var _card = require("./ui/card");
|
|
103
109
|
var _body = require("./ui/body");
|
|
104
110
|
var _header = require("./ui/header");
|
|
@@ -114,4 +120,5 @@ var _showMoreControl = require("./ui/show-more-control");
|
|
|
114
120
|
var _media = require("./ui/media");
|
|
115
121
|
var _popoverProvider = require("./ui/popover-provider");
|
|
116
122
|
var _popoverContent = require("./ui/popover-content");
|
|
117
|
-
var _popoverTarget = require("./ui/popover-target");
|
|
123
|
+
var _popoverTarget = require("./ui/popover-target");
|
|
124
|
+
var _UNSAFE_updateOnChange = require("./ui/UNSAFE_update-on-change");
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UNSAFE_UpdateOnChange = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _browserApis = require("@atlaskit/browser-apis");
|
|
9
|
+
var _context = require("../../controllers/context");
|
|
10
|
+
var defaultOptions = {
|
|
11
|
+
childList: true,
|
|
12
|
+
subtree: true
|
|
13
|
+
};
|
|
14
|
+
var UNSAFE_UpdateOnChange = exports.UNSAFE_UpdateOnChange = function UNSAFE_UpdateOnChange(_ref) {
|
|
15
|
+
var _ref$selectors = _ref.selectors,
|
|
16
|
+
selectors = _ref$selectors === void 0 ? ['body'] : _ref$selectors,
|
|
17
|
+
_ref$options = _ref.options,
|
|
18
|
+
options = _ref$options === void 0 ? defaultOptions : _ref$options;
|
|
19
|
+
var _useContext = (0, _react.useContext)(_context.SpotlightContext),
|
|
20
|
+
popoverContent = _useContext.popoverContent;
|
|
21
|
+
var update = popoverContent.update;
|
|
22
|
+
(0, _react.useEffect)(function () {
|
|
23
|
+
if (!update || selectors.length === 0) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
var doc = (0, _browserApis.getDocument)();
|
|
27
|
+
if (!doc) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
var elements = new Set();
|
|
31
|
+
selectors.forEach(function (selector) {
|
|
32
|
+
var element = doc.querySelector(selector);
|
|
33
|
+
if (!element) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
elements.add(element);
|
|
37
|
+
});
|
|
38
|
+
if (elements.size === 0) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
var observers = [];
|
|
42
|
+
elements.forEach(function (element) {
|
|
43
|
+
var observer = new MutationObserver(function (mutations) {
|
|
44
|
+
if (mutations.length === 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
update();
|
|
48
|
+
});
|
|
49
|
+
observer.observe(element, options);
|
|
50
|
+
observers.push(observer);
|
|
51
|
+
});
|
|
52
|
+
return function () {
|
|
53
|
+
observers.forEach(function (observer) {
|
|
54
|
+
return observer.disconnect();
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
}, [selectors, options, update]);
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
@@ -22,7 +22,7 @@ var styles = {
|
|
|
22
22
|
* the caret extending beyond the bounding box (by roughly 2px). So, apply an offset to ensure
|
|
23
23
|
* the caret points to the very edge of the target element.
|
|
24
24
|
*
|
|
25
|
-
* Note: `@atlaskit/popper` maps the offset to
|
|
25
|
+
* Note: `@atlaskit/popper` maps the offset to the placement, so we only need to define `[0, 2]` and
|
|
26
26
|
* the offset will get correctly rotated depending on the placement.
|
|
27
27
|
*/
|
|
28
28
|
var offset = [0, 2];
|
|
@@ -56,21 +56,36 @@ var PopoverContent = exports.PopoverContent = function PopoverContent(_ref) {
|
|
|
56
56
|
_ref$isVisible = _ref.isVisible,
|
|
57
57
|
isVisible = _ref$isVisible === void 0 ? true : _ref$isVisible,
|
|
58
58
|
testId = _ref.testId;
|
|
59
|
+
var updateRef = (0, _react.useRef)(function () {
|
|
60
|
+
return new Promise(function () {
|
|
61
|
+
return undefined;
|
|
62
|
+
});
|
|
63
|
+
});
|
|
59
64
|
var _useContext = (0, _react.useContext)(_context.SpotlightContext),
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
heading = _useContext.heading,
|
|
66
|
+
popoverContent = _useContext.popoverContent,
|
|
67
|
+
setPlacement = _useContext.setPlacement;
|
|
62
68
|
(0, _react.useEffect)(function () {
|
|
63
69
|
setPlacement(placement);
|
|
64
70
|
}, [placement, setPlacement]);
|
|
71
|
+
(0, _react.useEffect)(function () {
|
|
72
|
+
if (updateRef.current) {
|
|
73
|
+
popoverContent.setUpdate(function () {
|
|
74
|
+
return updateRef.current;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}, [popoverContent]);
|
|
65
78
|
return /*#__PURE__*/React.createElement(_popper.Popper, {
|
|
66
79
|
offset: offset,
|
|
67
80
|
placement: popperPlacementMap[placement]
|
|
68
81
|
}, function (_ref2) {
|
|
69
82
|
var ref = _ref2.ref,
|
|
70
|
-
style = _ref2.style
|
|
83
|
+
style = _ref2.style,
|
|
84
|
+
update = _ref2.update;
|
|
71
85
|
if (!isVisible) {
|
|
72
86
|
return;
|
|
73
87
|
}
|
|
88
|
+
updateRef.current = update;
|
|
74
89
|
return /*#__PURE__*/React.createElement("div", {
|
|
75
90
|
role: "dialog",
|
|
76
91
|
"data-testid": testId,
|
|
@@ -12,6 +12,10 @@ export const SpotlightContext = /*#__PURE__*/createContext({
|
|
|
12
12
|
heading: {
|
|
13
13
|
id: '',
|
|
14
14
|
setId: () => undefined
|
|
15
|
+
},
|
|
16
|
+
popoverContent: {
|
|
17
|
+
update: () => () => new Promise(() => null),
|
|
18
|
+
setUpdate: () => () => new Promise(() => null)
|
|
15
19
|
}
|
|
16
20
|
});
|
|
17
21
|
|
|
@@ -22,6 +26,7 @@ export const SpotlightContextProvider = ({
|
|
|
22
26
|
const id = useId();
|
|
23
27
|
const [placement, setPlacement] = useState('bottom-end');
|
|
24
28
|
const [headingId, setHeadingId] = useState(`${id}-heading`);
|
|
29
|
+
const [update, setUpdate] = useState(() => async () => undefined);
|
|
25
30
|
return /*#__PURE__*/React.createElement(SpotlightContext.Provider, {
|
|
26
31
|
value: {
|
|
27
32
|
placement,
|
|
@@ -29,6 +34,10 @@ export const SpotlightContextProvider = ({
|
|
|
29
34
|
heading: {
|
|
30
35
|
id: headingId,
|
|
31
36
|
setId: setHeadingId
|
|
37
|
+
},
|
|
38
|
+
popoverContent: {
|
|
39
|
+
update,
|
|
40
|
+
setUpdate
|
|
32
41
|
}
|
|
33
42
|
}
|
|
34
43
|
}, children);
|
package/dist/es2019/index.js
CHANGED
|
@@ -13,4 +13,5 @@ export { SpotlightShowMoreControl } from './ui/show-more-control';
|
|
|
13
13
|
export { SpotlightMedia } from './ui/media';
|
|
14
14
|
export { PopoverProvider } from './ui/popover-provider';
|
|
15
15
|
export { PopoverContent } from './ui/popover-content';
|
|
16
|
-
export { PopoverTarget } from './ui/popover-target';
|
|
16
|
+
export { PopoverTarget } from './ui/popover-target';
|
|
17
|
+
export { UNSAFE_UpdateOnChange } from './ui/UNSAFE_update-on-change';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useContext, useEffect } from "react";
|
|
2
|
+
import { getDocument } from "@atlaskit/browser-apis";
|
|
3
|
+
import { SpotlightContext } from "../../controllers/context";
|
|
4
|
+
const defaultOptions = {
|
|
5
|
+
childList: true,
|
|
6
|
+
subtree: true
|
|
7
|
+
};
|
|
8
|
+
export const UNSAFE_UpdateOnChange = ({
|
|
9
|
+
selectors = ['body'],
|
|
10
|
+
options = defaultOptions
|
|
11
|
+
}) => {
|
|
12
|
+
const {
|
|
13
|
+
popoverContent
|
|
14
|
+
} = useContext(SpotlightContext);
|
|
15
|
+
const {
|
|
16
|
+
update
|
|
17
|
+
} = popoverContent;
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!update || selectors.length === 0) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const doc = getDocument();
|
|
23
|
+
if (!doc) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const elements = new Set();
|
|
27
|
+
selectors.forEach(selector => {
|
|
28
|
+
const element = doc.querySelector(selector);
|
|
29
|
+
if (!element) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
elements.add(element);
|
|
33
|
+
});
|
|
34
|
+
if (elements.size === 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const observers = [];
|
|
38
|
+
elements.forEach(element => {
|
|
39
|
+
const observer = new MutationObserver(mutations => {
|
|
40
|
+
if (mutations.length === 0) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
update();
|
|
44
|
+
});
|
|
45
|
+
observer.observe(element, options);
|
|
46
|
+
observers.push(observer);
|
|
47
|
+
});
|
|
48
|
+
return () => {
|
|
49
|
+
observers.forEach(observer => observer.disconnect());
|
|
50
|
+
};
|
|
51
|
+
}, [selectors, options, update]);
|
|
52
|
+
return null;
|
|
53
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import "./index.compiled.css";
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { ax, ix } from "@compiled/react/runtime";
|
|
5
|
-
import { useContext, useEffect } from 'react';
|
|
5
|
+
import { useContext, useEffect, useRef } from 'react';
|
|
6
6
|
import { Popper } from '@atlaskit/popper';
|
|
7
7
|
import { SpotlightContext } from '../../controllers/context';
|
|
8
8
|
const styles = {
|
|
@@ -14,7 +14,7 @@ const styles = {
|
|
|
14
14
|
* the caret extending beyond the bounding box (by roughly 2px). So, apply an offset to ensure
|
|
15
15
|
* the caret points to the very edge of the target element.
|
|
16
16
|
*
|
|
17
|
-
* Note: `@atlaskit/popper` maps the offset to
|
|
17
|
+
* Note: `@atlaskit/popper` maps the offset to the placement, so we only need to define `[0, 2]` and
|
|
18
18
|
* the offset will get correctly rotated depending on the placement.
|
|
19
19
|
*/
|
|
20
20
|
const offset = [0, 2];
|
|
@@ -48,23 +48,32 @@ export const PopoverContent = ({
|
|
|
48
48
|
isVisible = true,
|
|
49
49
|
testId
|
|
50
50
|
}) => {
|
|
51
|
+
const updateRef = useRef(() => new Promise(() => undefined));
|
|
51
52
|
const {
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
heading,
|
|
54
|
+
popoverContent,
|
|
55
|
+
setPlacement
|
|
54
56
|
} = useContext(SpotlightContext);
|
|
55
57
|
useEffect(() => {
|
|
56
58
|
setPlacement(placement);
|
|
57
59
|
}, [placement, setPlacement]);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (updateRef.current) {
|
|
62
|
+
popoverContent.setUpdate(() => updateRef.current);
|
|
63
|
+
}
|
|
64
|
+
}, [popoverContent]);
|
|
58
65
|
return /*#__PURE__*/React.createElement(Popper, {
|
|
59
66
|
offset: offset,
|
|
60
67
|
placement: popperPlacementMap[placement]
|
|
61
68
|
}, ({
|
|
62
69
|
ref,
|
|
63
|
-
style
|
|
70
|
+
style,
|
|
71
|
+
update
|
|
64
72
|
}) => {
|
|
65
73
|
if (!isVisible) {
|
|
66
74
|
return;
|
|
67
75
|
}
|
|
76
|
+
updateRef.current = update;
|
|
68
77
|
return /*#__PURE__*/React.createElement("div", {
|
|
69
78
|
role: "dialog",
|
|
70
79
|
"data-testid": testId,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/* context.tsx generated by @compiled/babel-plugin v0.38.1 */
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
4
|
import * as React from 'react';
|
|
4
5
|
import { ax, ix } from "@compiled/react/runtime";
|
|
6
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
7
|
import { createContext, useId, useState } from 'react';
|
|
6
8
|
|
|
7
9
|
// eslint-disable-next-line @repo/internal/react/consistent-types-definitions
|
|
@@ -17,6 +19,22 @@ export var SpotlightContext = /*#__PURE__*/createContext({
|
|
|
17
19
|
setId: function setId() {
|
|
18
20
|
return undefined;
|
|
19
21
|
}
|
|
22
|
+
},
|
|
23
|
+
popoverContent: {
|
|
24
|
+
update: function update() {
|
|
25
|
+
return function () {
|
|
26
|
+
return new Promise(function () {
|
|
27
|
+
return null;
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
setUpdate: function setUpdate() {
|
|
32
|
+
return function () {
|
|
33
|
+
return new Promise(function () {
|
|
34
|
+
return null;
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
20
38
|
}
|
|
21
39
|
});
|
|
22
40
|
|
|
@@ -32,6 +50,22 @@ export var SpotlightContextProvider = function SpotlightContextProvider(_ref) {
|
|
|
32
50
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
33
51
|
headingId = _useState4[0],
|
|
34
52
|
setHeadingId = _useState4[1];
|
|
53
|
+
var _useState5 = useState(function () {
|
|
54
|
+
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
55
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
56
|
+
while (1) switch (_context.prev = _context.next) {
|
|
57
|
+
case 0:
|
|
58
|
+
return _context.abrupt("return", undefined);
|
|
59
|
+
case 1:
|
|
60
|
+
case "end":
|
|
61
|
+
return _context.stop();
|
|
62
|
+
}
|
|
63
|
+
}, _callee);
|
|
64
|
+
}));
|
|
65
|
+
}),
|
|
66
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
67
|
+
update = _useState6[0],
|
|
68
|
+
setUpdate = _useState6[1];
|
|
35
69
|
return /*#__PURE__*/React.createElement(SpotlightContext.Provider, {
|
|
36
70
|
value: {
|
|
37
71
|
placement: placement,
|
|
@@ -39,6 +73,10 @@ export var SpotlightContextProvider = function SpotlightContextProvider(_ref) {
|
|
|
39
73
|
heading: {
|
|
40
74
|
id: headingId,
|
|
41
75
|
setId: setHeadingId
|
|
76
|
+
},
|
|
77
|
+
popoverContent: {
|
|
78
|
+
update: update,
|
|
79
|
+
setUpdate: setUpdate
|
|
42
80
|
}
|
|
43
81
|
}
|
|
44
82
|
}, children);
|
package/dist/esm/index.js
CHANGED
|
@@ -13,4 +13,5 @@ export { SpotlightShowMoreControl } from './ui/show-more-control';
|
|
|
13
13
|
export { SpotlightMedia } from './ui/media';
|
|
14
14
|
export { PopoverProvider } from './ui/popover-provider';
|
|
15
15
|
export { PopoverContent } from './ui/popover-content';
|
|
16
|
-
export { PopoverTarget } from './ui/popover-target';
|
|
16
|
+
export { PopoverTarget } from './ui/popover-target';
|
|
17
|
+
export { UNSAFE_UpdateOnChange } from './ui/UNSAFE_update-on-change';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useContext, useEffect } from "react";
|
|
2
|
+
import { getDocument } from "@atlaskit/browser-apis";
|
|
3
|
+
import { SpotlightContext } from "../../controllers/context";
|
|
4
|
+
var defaultOptions = {
|
|
5
|
+
childList: true,
|
|
6
|
+
subtree: true
|
|
7
|
+
};
|
|
8
|
+
export var UNSAFE_UpdateOnChange = function UNSAFE_UpdateOnChange(_ref) {
|
|
9
|
+
var _ref$selectors = _ref.selectors,
|
|
10
|
+
selectors = _ref$selectors === void 0 ? ['body'] : _ref$selectors,
|
|
11
|
+
_ref$options = _ref.options,
|
|
12
|
+
options = _ref$options === void 0 ? defaultOptions : _ref$options;
|
|
13
|
+
var _useContext = useContext(SpotlightContext),
|
|
14
|
+
popoverContent = _useContext.popoverContent;
|
|
15
|
+
var update = popoverContent.update;
|
|
16
|
+
useEffect(function () {
|
|
17
|
+
if (!update || selectors.length === 0) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
var doc = getDocument();
|
|
21
|
+
if (!doc) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
var elements = new Set();
|
|
25
|
+
selectors.forEach(function (selector) {
|
|
26
|
+
var element = doc.querySelector(selector);
|
|
27
|
+
if (!element) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
elements.add(element);
|
|
31
|
+
});
|
|
32
|
+
if (elements.size === 0) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
var observers = [];
|
|
36
|
+
elements.forEach(function (element) {
|
|
37
|
+
var observer = new MutationObserver(function (mutations) {
|
|
38
|
+
if (mutations.length === 0) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
update();
|
|
42
|
+
});
|
|
43
|
+
observer.observe(element, options);
|
|
44
|
+
observers.push(observer);
|
|
45
|
+
});
|
|
46
|
+
return function () {
|
|
47
|
+
observers.forEach(function (observer) {
|
|
48
|
+
return observer.disconnect();
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
}, [selectors, options, update]);
|
|
52
|
+
return null;
|
|
53
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import "./index.compiled.css";
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { ax, ix } from "@compiled/react/runtime";
|
|
5
|
-
import { useContext, useEffect } from 'react';
|
|
5
|
+
import { useContext, useEffect, useRef } from 'react';
|
|
6
6
|
import { Popper } from '@atlaskit/popper';
|
|
7
7
|
import { SpotlightContext } from '../../controllers/context';
|
|
8
8
|
var styles = {
|
|
@@ -14,7 +14,7 @@ var styles = {
|
|
|
14
14
|
* the caret extending beyond the bounding box (by roughly 2px). So, apply an offset to ensure
|
|
15
15
|
* the caret points to the very edge of the target element.
|
|
16
16
|
*
|
|
17
|
-
* Note: `@atlaskit/popper` maps the offset to
|
|
17
|
+
* Note: `@atlaskit/popper` maps the offset to the placement, so we only need to define `[0, 2]` and
|
|
18
18
|
* the offset will get correctly rotated depending on the placement.
|
|
19
19
|
*/
|
|
20
20
|
var offset = [0, 2];
|
|
@@ -48,21 +48,36 @@ export var PopoverContent = function PopoverContent(_ref) {
|
|
|
48
48
|
_ref$isVisible = _ref.isVisible,
|
|
49
49
|
isVisible = _ref$isVisible === void 0 ? true : _ref$isVisible,
|
|
50
50
|
testId = _ref.testId;
|
|
51
|
+
var updateRef = useRef(function () {
|
|
52
|
+
return new Promise(function () {
|
|
53
|
+
return undefined;
|
|
54
|
+
});
|
|
55
|
+
});
|
|
51
56
|
var _useContext = useContext(SpotlightContext),
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
heading = _useContext.heading,
|
|
58
|
+
popoverContent = _useContext.popoverContent,
|
|
59
|
+
setPlacement = _useContext.setPlacement;
|
|
54
60
|
useEffect(function () {
|
|
55
61
|
setPlacement(placement);
|
|
56
62
|
}, [placement, setPlacement]);
|
|
63
|
+
useEffect(function () {
|
|
64
|
+
if (updateRef.current) {
|
|
65
|
+
popoverContent.setUpdate(function () {
|
|
66
|
+
return updateRef.current;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}, [popoverContent]);
|
|
57
70
|
return /*#__PURE__*/React.createElement(Popper, {
|
|
58
71
|
offset: offset,
|
|
59
72
|
placement: popperPlacementMap[placement]
|
|
60
73
|
}, function (_ref2) {
|
|
61
74
|
var ref = _ref2.ref,
|
|
62
|
-
style = _ref2.style
|
|
75
|
+
style = _ref2.style,
|
|
76
|
+
update = _ref2.update;
|
|
63
77
|
if (!isVisible) {
|
|
64
78
|
return;
|
|
65
79
|
}
|
|
80
|
+
updateRef.current = update;
|
|
66
81
|
return /*#__PURE__*/React.createElement("div", {
|
|
67
82
|
role: "dialog",
|
|
68
83
|
"data-testid": testId,
|
|
@@ -4,16 +4,19 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { type Dispatch, type ReactNode, type SetStateAction } from 'react';
|
|
6
6
|
import type { Placement } from '../types';
|
|
7
|
-
interface SpotlightContextType {
|
|
7
|
+
export interface SpotlightContextType {
|
|
8
8
|
placement: Placement;
|
|
9
9
|
setPlacement: Dispatch<SetStateAction<Placement>>;
|
|
10
10
|
heading: {
|
|
11
11
|
id: string;
|
|
12
12
|
setId: Dispatch<SetStateAction<string>>;
|
|
13
13
|
};
|
|
14
|
+
popoverContent: {
|
|
15
|
+
update: () => () => Promise<any>;
|
|
16
|
+
setUpdate: Dispatch<SetStateAction<() => () => Promise<any>>>;
|
|
17
|
+
};
|
|
14
18
|
}
|
|
15
19
|
export declare const SpotlightContext: import("react").Context<SpotlightContextType>;
|
|
16
20
|
export declare const SpotlightContextProvider: ({ children }: {
|
|
17
21
|
children: ReactNode;
|
|
18
22
|
}) => JSX.Element;
|
|
19
|
-
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { SpotlightDismissControl, type SpotlightDismissControlProps } from './ui
|
|
|
12
12
|
export { SpotlightShowMoreControl, type SpotlightShowMoreControlProps, } from './ui/show-more-control';
|
|
13
13
|
export { SpotlightMedia, type SpotlightMediaProps } from './ui/media';
|
|
14
14
|
export { PopoverProvider } from './ui/popover-provider';
|
|
15
|
-
export { PopoverContent } from './ui/popover-content';
|
|
15
|
+
export { PopoverContent, type PopoverContentProps } from './ui/popover-content';
|
|
16
16
|
export { PopoverTarget } from './ui/popover-target';
|
|
17
17
|
export { type Placement } from './types';
|
|
18
|
+
export { UNSAFE_UpdateOnChange } from './ui/UNSAFE_update-on-change';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { type ReactNode } from 'react';
|
|
6
6
|
import type { Placement } from '../../types';
|
|
7
|
-
interface PopoverContentProps {
|
|
7
|
+
export interface PopoverContentProps {
|
|
8
8
|
/**
|
|
9
9
|
* A `testId` prop is provided for specified elements, which is a unique
|
|
10
10
|
* string that appears as a data attribute `data-testid` in the rendered code,
|
|
@@ -21,4 +21,3 @@ interface PopoverContentProps {
|
|
|
21
21
|
* A `PopoverContent` is the element that is shown as a popover.
|
|
22
22
|
*/
|
|
23
23
|
export declare const PopoverContent: ({ children, placement, isVisible, testId, }: PopoverContentProps) => JSX.Element;
|
|
24
|
-
export {};
|
|
@@ -4,16 +4,19 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { type Dispatch, type ReactNode, type SetStateAction } from 'react';
|
|
6
6
|
import type { Placement } from '../types';
|
|
7
|
-
interface SpotlightContextType {
|
|
7
|
+
export interface SpotlightContextType {
|
|
8
8
|
placement: Placement;
|
|
9
9
|
setPlacement: Dispatch<SetStateAction<Placement>>;
|
|
10
10
|
heading: {
|
|
11
11
|
id: string;
|
|
12
12
|
setId: Dispatch<SetStateAction<string>>;
|
|
13
13
|
};
|
|
14
|
+
popoverContent: {
|
|
15
|
+
update: () => () => Promise<any>;
|
|
16
|
+
setUpdate: Dispatch<SetStateAction<() => () => Promise<any>>>;
|
|
17
|
+
};
|
|
14
18
|
}
|
|
15
19
|
export declare const SpotlightContext: import("react").Context<SpotlightContextType>;
|
|
16
20
|
export declare const SpotlightContextProvider: ({ children }: {
|
|
17
21
|
children: ReactNode;
|
|
18
22
|
}) => JSX.Element;
|
|
19
|
-
export {};
|
|
@@ -12,6 +12,7 @@ export { SpotlightDismissControl, type SpotlightDismissControlProps } from './ui
|
|
|
12
12
|
export { SpotlightShowMoreControl, type SpotlightShowMoreControlProps, } from './ui/show-more-control';
|
|
13
13
|
export { SpotlightMedia, type SpotlightMediaProps } from './ui/media';
|
|
14
14
|
export { PopoverProvider } from './ui/popover-provider';
|
|
15
|
-
export { PopoverContent } from './ui/popover-content';
|
|
15
|
+
export { PopoverContent, type PopoverContentProps } from './ui/popover-content';
|
|
16
16
|
export { PopoverTarget } from './ui/popover-target';
|
|
17
17
|
export { type Placement } from './types';
|
|
18
|
+
export { UNSAFE_UpdateOnChange } from './ui/UNSAFE_update-on-change';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { type ReactNode } from 'react';
|
|
6
6
|
import type { Placement } from '../../types';
|
|
7
|
-
interface PopoverContentProps {
|
|
7
|
+
export interface PopoverContentProps {
|
|
8
8
|
/**
|
|
9
9
|
* A `testId` prop is provided for specified elements, which is a unique
|
|
10
10
|
* string that appears as a data attribute `data-testid` in the rendered code,
|
|
@@ -21,4 +21,3 @@ interface PopoverContentProps {
|
|
|
21
21
|
* A `PopoverContent` is the element that is shown as a popover.
|
|
22
22
|
*/
|
|
23
23
|
export declare const PopoverContent: ({ children, placement, isVisible, testId, }: PopoverContentProps) => JSX.Element;
|
|
24
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/spotlight",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A spotlight introduces users to various points of interest across Atlassian through focused messages or multi-step tours.",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
],
|
|
27
27
|
"atlaskit:src": "src/index.tsx",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@atlaskit/
|
|
29
|
+
"@atlaskit/browser-apis": "^0.0.1",
|
|
30
|
+
"@atlaskit/button": "^23.5.0",
|
|
30
31
|
"@atlaskit/css": "^0.14.0",
|
|
31
32
|
"@atlaskit/heading": "^5.2.0",
|
|
32
33
|
"@atlaskit/icon": "^28.3.0",
|