@atlaskit/editor-common 84.5.0 → 85.0.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 (66) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/afm-jira/tsconfig.json +3 -0
  3. package/dist/cjs/analytics/types/enums.js +2 -0
  4. package/dist/cjs/element-browser/components/ElementList/ElementList.js +27 -91
  5. package/dist/cjs/extensibility/extensionNodeView.js +1 -2
  6. package/dist/cjs/keymaps/keymap.js +25 -43
  7. package/dist/cjs/link/ConfigureLinkOverlay/Dropdown.js +34 -9
  8. package/dist/cjs/link/ConfigureLinkOverlay/index.js +15 -5
  9. package/dist/cjs/link/ConfigureLinkOverlay/useLinkOverlayAnalyticsEvents.js +46 -0
  10. package/dist/cjs/messages/table.js +30 -0
  11. package/dist/cjs/monitoring/error.js +1 -1
  12. package/dist/cjs/react-node-view/getInlineNodeViewProducer.js +2 -4
  13. package/dist/cjs/react-node-view/index.js +4 -10
  14. package/dist/cjs/selection-based-node-view/SelectionBasedNodeView.js +2 -5
  15. package/dist/cjs/ui/DropList/index.js +1 -1
  16. package/dist/es2019/analytics/types/enums.js +2 -0
  17. package/dist/es2019/element-browser/components/ElementList/ElementList.js +7 -70
  18. package/dist/es2019/extensibility/extensionNodeView.js +1 -2
  19. package/dist/es2019/keymaps/keymap.js +25 -43
  20. package/dist/es2019/link/ConfigureLinkOverlay/Dropdown.js +33 -7
  21. package/dist/es2019/link/ConfigureLinkOverlay/index.js +16 -5
  22. package/dist/es2019/link/ConfigureLinkOverlay/useLinkOverlayAnalyticsEvents.js +39 -0
  23. package/dist/es2019/messages/table.js +30 -0
  24. package/dist/es2019/monitoring/error.js +1 -1
  25. package/dist/es2019/react-node-view/getInlineNodeViewProducer.js +2 -4
  26. package/dist/es2019/react-node-view/index.js +5 -7
  27. package/dist/es2019/selection-based-node-view/SelectionBasedNodeView.js +3 -2
  28. package/dist/es2019/ui/DropList/index.js +1 -1
  29. package/dist/esm/analytics/types/enums.js +2 -0
  30. package/dist/esm/element-browser/components/ElementList/ElementList.js +27 -91
  31. package/dist/esm/extensibility/extensionNodeView.js +1 -2
  32. package/dist/esm/keymaps/keymap.js +25 -43
  33. package/dist/esm/link/ConfigureLinkOverlay/Dropdown.js +34 -9
  34. package/dist/esm/link/ConfigureLinkOverlay/index.js +15 -5
  35. package/dist/esm/link/ConfigureLinkOverlay/useLinkOverlayAnalyticsEvents.js +40 -0
  36. package/dist/esm/messages/table.js +30 -0
  37. package/dist/esm/monitoring/error.js +1 -1
  38. package/dist/esm/react-node-view/getInlineNodeViewProducer.js +2 -4
  39. package/dist/esm/react-node-view/index.js +4 -10
  40. package/dist/esm/selection-based-node-view/SelectionBasedNodeView.js +3 -5
  41. package/dist/esm/ui/DropList/index.js +1 -1
  42. package/dist/types/analytics/types/enums.d.ts +3 -1
  43. package/dist/types/extensibility/extensionNodeView.d.ts +1 -2
  44. package/dist/types/link/ConfigureLinkOverlay/Dropdown.d.ts +5 -4
  45. package/dist/types/link/ConfigureLinkOverlay/index.d.ts +2 -2
  46. package/dist/types/link/ConfigureLinkOverlay/useLinkOverlayAnalyticsEvents.d.ts +5 -0
  47. package/dist/types/messages/table.d.ts +30 -0
  48. package/dist/types/react-node-view/index.d.ts +2 -5
  49. package/dist/types/selection-based-node-view/SelectionBasedNodeView.d.ts +1 -2
  50. package/dist/types/types/plugin-factory.d.ts +1 -2
  51. package/dist/types-ts4.5/analytics/types/enums.d.ts +3 -1
  52. package/dist/types-ts4.5/extensibility/extensionNodeView.d.ts +1 -2
  53. package/dist/types-ts4.5/link/ConfigureLinkOverlay/Dropdown.d.ts +5 -4
  54. package/dist/types-ts4.5/link/ConfigureLinkOverlay/index.d.ts +2 -2
  55. package/dist/types-ts4.5/link/ConfigureLinkOverlay/useLinkOverlayAnalyticsEvents.d.ts +5 -0
  56. package/dist/types-ts4.5/messages/table.d.ts +30 -0
  57. package/dist/types-ts4.5/react-node-view/index.d.ts +2 -5
  58. package/dist/types-ts4.5/selection-based-node-view/SelectionBasedNodeView.d.ts +1 -2
  59. package/dist/types-ts4.5/types/plugin-factory.d.ts +1 -2
  60. package/package.json +6 -14
  61. package/dist/cjs/ui/PortalProvider/index.js +0 -235
  62. package/dist/es2019/ui/PortalProvider/index.js +0 -171
  63. package/dist/esm/ui/PortalProvider/index.js +0 -229
  64. package/dist/types/ui/PortalProvider/index.d.ts +0 -48
  65. package/dist/types-ts4.5/ui/PortalProvider/index.d.ts +0 -48
  66. package/portal-provider/package.json +0 -15
@@ -1,235 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.PortalRenderer = exports.PortalProviderWithThemeProviders = exports.PortalProvider = exports.LegacyPortalProviderAPI = void 0;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
12
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
13
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
14
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
15
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
- var _react = _interopRequireDefault(require("react"));
17
- var _propTypes = _interopRequireDefault(require("prop-types"));
18
- var _reactDom = require("react-dom");
19
- var _reactIntlNext = require("react-intl-next");
20
- var _analyticsNextStableReactContext = _interopRequireDefault(require("@atlaskit/analytics-next-stable-react-context"));
21
- var _analytics = require("../../analytics");
22
- var _eventDispatcher = require("../../event-dispatcher");
23
- var _IntlProviderIfMissingWrapper = _interopRequireDefault(require("../IntlProviderIfMissingWrapper"));
24
- var _class4;
25
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
26
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
27
- var LegacyPortalProviderAPI = exports.LegacyPortalProviderAPI = /*#__PURE__*/function (_EventDispatcher) {
28
- (0, _inherits2.default)(LegacyPortalProviderAPI, _EventDispatcher);
29
- var _super = _createSuper(LegacyPortalProviderAPI);
30
- function LegacyPortalProviderAPI(intl, onAnalyticsEvent, analyticsContext) {
31
- var _this;
32
- (0, _classCallCheck2.default)(this, LegacyPortalProviderAPI);
33
- _this = _super.call(this);
34
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "portals", new Map());
35
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "setContext", function (context) {
36
- _this.context = context;
37
- });
38
- _this.intl = intl;
39
- _this.onAnalyticsEvent = onAnalyticsEvent;
40
- _this.useAnalyticsContext = analyticsContext;
41
- return _this;
42
- }
43
- (0, _createClass2.default)(LegacyPortalProviderAPI, [{
44
- key: "render",
45
- value: function render(children, container, key) {
46
- var hasAnalyticsContext = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
47
- var hasIntlContext = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
48
- this.portals.set(container, {
49
- key: key,
50
- children: children,
51
- hasAnalyticsContext: hasAnalyticsContext,
52
- hasIntlContext: hasIntlContext
53
- });
54
- var wrappedChildren = this.useAnalyticsContext ? /*#__PURE__*/_react.default.createElement(AnalyticsContextWrapper, null, children()) : children();
55
- if (hasIntlContext) {
56
- wrappedChildren = /*#__PURE__*/_react.default.createElement(_reactIntlNext.RawIntlProvider, {
57
- value: this.intl
58
- }, wrappedChildren);
59
- }
60
- (0, _reactDom.unstable_renderSubtreeIntoContainer)(this.context, wrappedChildren, container);
61
- }
62
-
63
- // TODO: until https://product-fabric.atlassian.net/browse/ED-5013
64
- // we (unfortunately) need to re-render to pass down any updated context.
65
- // selectively do this for nodeviews that opt-in via `hasAnalyticsContext`
66
- }, {
67
- key: "forceUpdate",
68
- value: function forceUpdate(_ref) {
69
- var _this2 = this;
70
- var intl = _ref.intl;
71
- this.intl = intl;
72
- this.portals.forEach(function (portal, container) {
73
- if (!portal.hasAnalyticsContext && !_this2.useAnalyticsContext && !portal.hasIntlContext) {
74
- return;
75
- }
76
- var wrappedChildren = portal.children();
77
- if (portal.hasAnalyticsContext && _this2.useAnalyticsContext) {
78
- wrappedChildren = /*#__PURE__*/_react.default.createElement(AnalyticsContextWrapper, null, wrappedChildren);
79
- }
80
- if (portal.hasIntlContext) {
81
- wrappedChildren = /*#__PURE__*/_react.default.createElement(_reactIntlNext.RawIntlProvider, {
82
- value: _this2.intl
83
- }, wrappedChildren);
84
- }
85
- (0, _reactDom.unstable_renderSubtreeIntoContainer)(_this2.context, wrappedChildren, container);
86
- });
87
- }
88
- }, {
89
- key: "remove",
90
- value: function remove(key, container) {
91
- this.portals.delete(container);
92
-
93
- // There is a race condition that can happen caused by Prosemirror vs React,
94
- // where Prosemirror removes the container from the DOM before React gets
95
- // around to removing the child from the container
96
- // This will throw a NotFoundError: The node to be removed is not a child of this node
97
- // Both Prosemirror and React remove the elements asynchronously, and in edge
98
- // cases Prosemirror beats React
99
- try {
100
- (0, _reactDom.unmountComponentAtNode)(container);
101
- } catch (error) {
102
- if (this.onAnalyticsEvent) {
103
- this.onAnalyticsEvent({
104
- payload: {
105
- action: _analytics.ACTION.FAILED_TO_UNMOUNT,
106
- actionSubject: _analytics.ACTION_SUBJECT.EDITOR,
107
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.REACT_NODE_VIEW,
108
- attributes: {
109
- error: error,
110
- domNodes: {
111
- container: container ? container.className : undefined,
112
- child: container.firstElementChild ? container.firstElementChild.className : undefined
113
- }
114
- },
115
- eventType: _analytics.EVENT_TYPE.OPERATIONAL
116
- }
117
- });
118
- }
119
- }
120
- }
121
- }]);
122
- return LegacyPortalProviderAPI;
123
- }(_eventDispatcher.EventDispatcher);
124
- var BasePortalProvider = /*#__PURE__*/function (_React$Component) {
125
- (0, _inherits2.default)(BasePortalProvider, _React$Component);
126
- var _super2 = _createSuper(BasePortalProvider);
127
- function BasePortalProvider(props) {
128
- var _this3;
129
- (0, _classCallCheck2.default)(this, BasePortalProvider);
130
- _this3 = _super2.call(this, props);
131
- _this3.portalProviderAPI = new LegacyPortalProviderAPI(props.intl, props.onAnalyticsEvent, props.useAnalyticsContext);
132
- return _this3;
133
- }
134
- (0, _createClass2.default)(BasePortalProvider, [{
135
- key: "render",
136
- value: function render() {
137
- return this.props.render(this.portalProviderAPI);
138
- }
139
- }, {
140
- key: "componentDidUpdate",
141
- value: function componentDidUpdate() {
142
- this.portalProviderAPI.forceUpdate({
143
- intl: this.props.intl
144
- });
145
- }
146
- }]);
147
- return BasePortalProvider;
148
- }(_react.default.Component);
149
- (0, _defineProperty2.default)(BasePortalProvider, "displayName", 'PortalProvider');
150
- var PortalProvider = exports.PortalProvider = (0, _reactIntlNext.injectIntl)(BasePortalProvider);
151
- var PortalProviderWithThemeProviders = exports.PortalProviderWithThemeProviders = function PortalProviderWithThemeProviders(_ref2) {
152
- var onAnalyticsEvent = _ref2.onAnalyticsEvent,
153
- useAnalyticsContext = _ref2.useAnalyticsContext,
154
- render = _ref2.render;
155
- return /*#__PURE__*/_react.default.createElement(_IntlProviderIfMissingWrapper.default, null, /*#__PURE__*/_react.default.createElement(PortalProviderWithThemeAndIntlProviders, {
156
- onAnalyticsEvent: onAnalyticsEvent,
157
- useAnalyticsContext: useAnalyticsContext,
158
- render: render
159
- }));
160
- };
161
- var PortalProviderWithThemeAndIntlProviders = function PortalProviderWithThemeAndIntlProviders(_ref3) {
162
- var onAnalyticsEvent = _ref3.onAnalyticsEvent,
163
- useAnalyticsContext = _ref3.useAnalyticsContext,
164
- render = _ref3.render;
165
- var intl = (0, _reactIntlNext.useIntl)();
166
- return /*#__PURE__*/_react.default.createElement(BasePortalProvider, {
167
- intl: intl,
168
- onAnalyticsEvent: onAnalyticsEvent,
169
- useAnalyticsContext: useAnalyticsContext,
170
- render: render
171
- });
172
- };
173
- var PortalRenderer = exports.PortalRenderer = /*#__PURE__*/function (_React$Component2) {
174
- (0, _inherits2.default)(PortalRenderer, _React$Component2);
175
- var _super3 = _createSuper(PortalRenderer);
176
- function PortalRenderer(props) {
177
- var _this4;
178
- (0, _classCallCheck2.default)(this, PortalRenderer);
179
- _this4 = _super3.call(this, props);
180
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this4), "handleUpdate", function (portals) {
181
- return _this4.setState({
182
- portals: portals
183
- });
184
- });
185
- props.portalProviderAPI.setContext((0, _assertThisInitialized2.default)(_this4));
186
- props.portalProviderAPI.on('update', _this4.handleUpdate);
187
- _this4.state = {
188
- portals: new Map()
189
- };
190
- return _this4;
191
- }
192
- (0, _createClass2.default)(PortalRenderer, [{
193
- key: "render",
194
- value: function render() {
195
- var portals = this.state.portals;
196
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, Array.from(portals.entries()).map(function (_ref4) {
197
- var _ref5 = (0, _slicedToArray2.default)(_ref4, 2),
198
- container = _ref5[0],
199
- children = _ref5[1];
200
- return /*#__PURE__*/(0, _reactDom.createPortal)(children, container);
201
- }));
202
- }
203
- }]);
204
- return PortalRenderer;
205
- }(_react.default.Component);
206
- /**
207
- * Wrapper to re-provide modern analytics context to ReactNodeViews.
208
- */
209
- var dummyAnalyticsContext = {
210
- getAtlaskitAnalyticsContext: function getAtlaskitAnalyticsContext() {},
211
- getAtlaskitAnalyticsEventHandlers: function getAtlaskitAnalyticsEventHandlers() {}
212
- };
213
- var AnalyticsContextWrapper = (_class4 = /*#__PURE__*/function (_React$Component3) {
214
- (0, _inherits2.default)(AnalyticsContextWrapper, _React$Component3);
215
- var _super4 = _createSuper(AnalyticsContextWrapper);
216
- function AnalyticsContextWrapper() {
217
- (0, _classCallCheck2.default)(this, AnalyticsContextWrapper);
218
- return _super4.apply(this, arguments);
219
- }
220
- (0, _createClass2.default)(AnalyticsContextWrapper, [{
221
- key: "render",
222
- value: function render() {
223
- var _ref6 = this.context.contextAdapter.analytics || {
224
- value: dummyAnalyticsContext
225
- },
226
- value = _ref6.value;
227
- return /*#__PURE__*/_react.default.createElement(_analyticsNextStableReactContext.default.Provider, {
228
- value: value
229
- }, this.props.children);
230
- }
231
- }]);
232
- return AnalyticsContextWrapper;
233
- }(_react.default.Component), (0, _defineProperty2.default)(_class4, "contextTypes", {
234
- contextAdapter: _propTypes.default.object
235
- }), _class4);
@@ -1,171 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- var _class4;
3
- import React from 'react';
4
- import PropTypes from 'prop-types';
5
- import { createPortal, unmountComponentAtNode, unstable_renderSubtreeIntoContainer } from 'react-dom';
6
- import { injectIntl, RawIntlProvider, useIntl } from 'react-intl-next';
7
- import { default as AnalyticsReactContext } from '@atlaskit/analytics-next-stable-react-context';
8
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '../../analytics';
9
- import { EventDispatcher } from '../../event-dispatcher';
10
- import IntlProviderIfMissingWrapper from '../IntlProviderIfMissingWrapper';
11
- export class LegacyPortalProviderAPI extends EventDispatcher {
12
- constructor(intl, onAnalyticsEvent, analyticsContext) {
13
- super();
14
- _defineProperty(this, "portals", new Map());
15
- _defineProperty(this, "setContext", context => {
16
- this.context = context;
17
- });
18
- this.intl = intl;
19
- this.onAnalyticsEvent = onAnalyticsEvent;
20
- this.useAnalyticsContext = analyticsContext;
21
- }
22
- render(children, container, key, hasAnalyticsContext = false, hasIntlContext = false) {
23
- this.portals.set(container, {
24
- key,
25
- children,
26
- hasAnalyticsContext,
27
- hasIntlContext
28
- });
29
- let wrappedChildren = this.useAnalyticsContext ? /*#__PURE__*/React.createElement(AnalyticsContextWrapper, null, children()) : children();
30
- if (hasIntlContext) {
31
- wrappedChildren = /*#__PURE__*/React.createElement(RawIntlProvider, {
32
- value: this.intl
33
- }, wrappedChildren);
34
- }
35
- unstable_renderSubtreeIntoContainer(this.context, wrappedChildren, container);
36
- }
37
-
38
- // TODO: until https://product-fabric.atlassian.net/browse/ED-5013
39
- // we (unfortunately) need to re-render to pass down any updated context.
40
- // selectively do this for nodeviews that opt-in via `hasAnalyticsContext`
41
- forceUpdate({
42
- intl
43
- }) {
44
- this.intl = intl;
45
- this.portals.forEach((portal, container) => {
46
- if (!portal.hasAnalyticsContext && !this.useAnalyticsContext && !portal.hasIntlContext) {
47
- return;
48
- }
49
- let wrappedChildren = portal.children();
50
- if (portal.hasAnalyticsContext && this.useAnalyticsContext) {
51
- wrappedChildren = /*#__PURE__*/React.createElement(AnalyticsContextWrapper, null, wrappedChildren);
52
- }
53
- if (portal.hasIntlContext) {
54
- wrappedChildren = /*#__PURE__*/React.createElement(RawIntlProvider, {
55
- value: this.intl
56
- }, wrappedChildren);
57
- }
58
- unstable_renderSubtreeIntoContainer(this.context, wrappedChildren, container);
59
- });
60
- }
61
- remove(key, container) {
62
- this.portals.delete(container);
63
-
64
- // There is a race condition that can happen caused by Prosemirror vs React,
65
- // where Prosemirror removes the container from the DOM before React gets
66
- // around to removing the child from the container
67
- // This will throw a NotFoundError: The node to be removed is not a child of this node
68
- // Both Prosemirror and React remove the elements asynchronously, and in edge
69
- // cases Prosemirror beats React
70
- try {
71
- unmountComponentAtNode(container);
72
- } catch (error) {
73
- if (this.onAnalyticsEvent) {
74
- this.onAnalyticsEvent({
75
- payload: {
76
- action: ACTION.FAILED_TO_UNMOUNT,
77
- actionSubject: ACTION_SUBJECT.EDITOR,
78
- actionSubjectId: ACTION_SUBJECT_ID.REACT_NODE_VIEW,
79
- attributes: {
80
- error: error,
81
- domNodes: {
82
- container: container ? container.className : undefined,
83
- child: container.firstElementChild ? container.firstElementChild.className : undefined
84
- }
85
- },
86
- eventType: EVENT_TYPE.OPERATIONAL
87
- }
88
- });
89
- }
90
- }
91
- }
92
- }
93
- class BasePortalProvider extends React.Component {
94
- constructor(props) {
95
- super(props);
96
- this.portalProviderAPI = new LegacyPortalProviderAPI(props.intl, props.onAnalyticsEvent, props.useAnalyticsContext);
97
- }
98
- render() {
99
- return this.props.render(this.portalProviderAPI);
100
- }
101
- componentDidUpdate() {
102
- this.portalProviderAPI.forceUpdate({
103
- intl: this.props.intl
104
- });
105
- }
106
- }
107
- _defineProperty(BasePortalProvider, "displayName", 'PortalProvider');
108
- export const PortalProvider = injectIntl(BasePortalProvider);
109
- export const PortalProviderWithThemeProviders = ({
110
- onAnalyticsEvent,
111
- useAnalyticsContext,
112
- render
113
- }) => /*#__PURE__*/React.createElement(IntlProviderIfMissingWrapper, null, /*#__PURE__*/React.createElement(PortalProviderWithThemeAndIntlProviders, {
114
- onAnalyticsEvent: onAnalyticsEvent,
115
- useAnalyticsContext: useAnalyticsContext,
116
- render: render
117
- }));
118
- const PortalProviderWithThemeAndIntlProviders = ({
119
- onAnalyticsEvent,
120
- useAnalyticsContext,
121
- render
122
- }) => {
123
- const intl = useIntl();
124
- return /*#__PURE__*/React.createElement(BasePortalProvider, {
125
- intl: intl,
126
- onAnalyticsEvent: onAnalyticsEvent,
127
- useAnalyticsContext: useAnalyticsContext,
128
- render: render
129
- });
130
- };
131
- export class PortalRenderer extends React.Component {
132
- constructor(props) {
133
- super(props);
134
- _defineProperty(this, "handleUpdate", portals => this.setState({
135
- portals
136
- }));
137
- props.portalProviderAPI.setContext(this);
138
- props.portalProviderAPI.on('update', this.handleUpdate);
139
- this.state = {
140
- portals: new Map()
141
- };
142
- }
143
- render() {
144
- const {
145
- portals
146
- } = this.state;
147
- return /*#__PURE__*/React.createElement(React.Fragment, null, Array.from(portals.entries()).map(([container, children]) => /*#__PURE__*/createPortal(children, container)));
148
- }
149
- }
150
-
151
- /**
152
- * Wrapper to re-provide modern analytics context to ReactNodeViews.
153
- */
154
- const dummyAnalyticsContext = {
155
- getAtlaskitAnalyticsContext() {},
156
- getAtlaskitAnalyticsEventHandlers() {}
157
- };
158
- const AnalyticsContextWrapper = (_class4 = class AnalyticsContextWrapper extends React.Component {
159
- render() {
160
- const {
161
- value
162
- } = this.context.contextAdapter.analytics || {
163
- value: dummyAnalyticsContext
164
- };
165
- return /*#__PURE__*/React.createElement(AnalyticsReactContext.Provider, {
166
- value: value
167
- }, this.props.children);
168
- }
169
- }, _defineProperty(_class4, "contextTypes", {
170
- contextAdapter: PropTypes.object
171
- }), _class4);
@@ -1,229 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
- var _class4;
10
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
12
- import React from 'react';
13
- import PropTypes from 'prop-types';
14
- import { createPortal, unmountComponentAtNode, unstable_renderSubtreeIntoContainer } from 'react-dom';
15
- import { injectIntl, RawIntlProvider, useIntl } from 'react-intl-next';
16
- import { default as AnalyticsReactContext } from '@atlaskit/analytics-next-stable-react-context';
17
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '../../analytics';
18
- import { EventDispatcher } from '../../event-dispatcher';
19
- import IntlProviderIfMissingWrapper from '../IntlProviderIfMissingWrapper';
20
- export var LegacyPortalProviderAPI = /*#__PURE__*/function (_EventDispatcher) {
21
- _inherits(LegacyPortalProviderAPI, _EventDispatcher);
22
- var _super = _createSuper(LegacyPortalProviderAPI);
23
- function LegacyPortalProviderAPI(intl, onAnalyticsEvent, analyticsContext) {
24
- var _this;
25
- _classCallCheck(this, LegacyPortalProviderAPI);
26
- _this = _super.call(this);
27
- _defineProperty(_assertThisInitialized(_this), "portals", new Map());
28
- _defineProperty(_assertThisInitialized(_this), "setContext", function (context) {
29
- _this.context = context;
30
- });
31
- _this.intl = intl;
32
- _this.onAnalyticsEvent = onAnalyticsEvent;
33
- _this.useAnalyticsContext = analyticsContext;
34
- return _this;
35
- }
36
- _createClass(LegacyPortalProviderAPI, [{
37
- key: "render",
38
- value: function render(children, container, key) {
39
- var hasAnalyticsContext = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
40
- var hasIntlContext = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
41
- this.portals.set(container, {
42
- key: key,
43
- children: children,
44
- hasAnalyticsContext: hasAnalyticsContext,
45
- hasIntlContext: hasIntlContext
46
- });
47
- var wrappedChildren = this.useAnalyticsContext ? /*#__PURE__*/React.createElement(AnalyticsContextWrapper, null, children()) : children();
48
- if (hasIntlContext) {
49
- wrappedChildren = /*#__PURE__*/React.createElement(RawIntlProvider, {
50
- value: this.intl
51
- }, wrappedChildren);
52
- }
53
- unstable_renderSubtreeIntoContainer(this.context, wrappedChildren, container);
54
- }
55
-
56
- // TODO: until https://product-fabric.atlassian.net/browse/ED-5013
57
- // we (unfortunately) need to re-render to pass down any updated context.
58
- // selectively do this for nodeviews that opt-in via `hasAnalyticsContext`
59
- }, {
60
- key: "forceUpdate",
61
- value: function forceUpdate(_ref) {
62
- var _this2 = this;
63
- var intl = _ref.intl;
64
- this.intl = intl;
65
- this.portals.forEach(function (portal, container) {
66
- if (!portal.hasAnalyticsContext && !_this2.useAnalyticsContext && !portal.hasIntlContext) {
67
- return;
68
- }
69
- var wrappedChildren = portal.children();
70
- if (portal.hasAnalyticsContext && _this2.useAnalyticsContext) {
71
- wrappedChildren = /*#__PURE__*/React.createElement(AnalyticsContextWrapper, null, wrappedChildren);
72
- }
73
- if (portal.hasIntlContext) {
74
- wrappedChildren = /*#__PURE__*/React.createElement(RawIntlProvider, {
75
- value: _this2.intl
76
- }, wrappedChildren);
77
- }
78
- unstable_renderSubtreeIntoContainer(_this2.context, wrappedChildren, container);
79
- });
80
- }
81
- }, {
82
- key: "remove",
83
- value: function remove(key, container) {
84
- this.portals.delete(container);
85
-
86
- // There is a race condition that can happen caused by Prosemirror vs React,
87
- // where Prosemirror removes the container from the DOM before React gets
88
- // around to removing the child from the container
89
- // This will throw a NotFoundError: The node to be removed is not a child of this node
90
- // Both Prosemirror and React remove the elements asynchronously, and in edge
91
- // cases Prosemirror beats React
92
- try {
93
- unmountComponentAtNode(container);
94
- } catch (error) {
95
- if (this.onAnalyticsEvent) {
96
- this.onAnalyticsEvent({
97
- payload: {
98
- action: ACTION.FAILED_TO_UNMOUNT,
99
- actionSubject: ACTION_SUBJECT.EDITOR,
100
- actionSubjectId: ACTION_SUBJECT_ID.REACT_NODE_VIEW,
101
- attributes: {
102
- error: error,
103
- domNodes: {
104
- container: container ? container.className : undefined,
105
- child: container.firstElementChild ? container.firstElementChild.className : undefined
106
- }
107
- },
108
- eventType: EVENT_TYPE.OPERATIONAL
109
- }
110
- });
111
- }
112
- }
113
- }
114
- }]);
115
- return LegacyPortalProviderAPI;
116
- }(EventDispatcher);
117
- var BasePortalProvider = /*#__PURE__*/function (_React$Component) {
118
- _inherits(BasePortalProvider, _React$Component);
119
- var _super2 = _createSuper(BasePortalProvider);
120
- function BasePortalProvider(props) {
121
- var _this3;
122
- _classCallCheck(this, BasePortalProvider);
123
- _this3 = _super2.call(this, props);
124
- _this3.portalProviderAPI = new LegacyPortalProviderAPI(props.intl, props.onAnalyticsEvent, props.useAnalyticsContext);
125
- return _this3;
126
- }
127
- _createClass(BasePortalProvider, [{
128
- key: "render",
129
- value: function render() {
130
- return this.props.render(this.portalProviderAPI);
131
- }
132
- }, {
133
- key: "componentDidUpdate",
134
- value: function componentDidUpdate() {
135
- this.portalProviderAPI.forceUpdate({
136
- intl: this.props.intl
137
- });
138
- }
139
- }]);
140
- return BasePortalProvider;
141
- }(React.Component);
142
- _defineProperty(BasePortalProvider, "displayName", 'PortalProvider');
143
- export var PortalProvider = injectIntl(BasePortalProvider);
144
- export var PortalProviderWithThemeProviders = function PortalProviderWithThemeProviders(_ref2) {
145
- var onAnalyticsEvent = _ref2.onAnalyticsEvent,
146
- useAnalyticsContext = _ref2.useAnalyticsContext,
147
- render = _ref2.render;
148
- return /*#__PURE__*/React.createElement(IntlProviderIfMissingWrapper, null, /*#__PURE__*/React.createElement(PortalProviderWithThemeAndIntlProviders, {
149
- onAnalyticsEvent: onAnalyticsEvent,
150
- useAnalyticsContext: useAnalyticsContext,
151
- render: render
152
- }));
153
- };
154
- var PortalProviderWithThemeAndIntlProviders = function PortalProviderWithThemeAndIntlProviders(_ref3) {
155
- var onAnalyticsEvent = _ref3.onAnalyticsEvent,
156
- useAnalyticsContext = _ref3.useAnalyticsContext,
157
- render = _ref3.render;
158
- var intl = useIntl();
159
- return /*#__PURE__*/React.createElement(BasePortalProvider, {
160
- intl: intl,
161
- onAnalyticsEvent: onAnalyticsEvent,
162
- useAnalyticsContext: useAnalyticsContext,
163
- render: render
164
- });
165
- };
166
- export var PortalRenderer = /*#__PURE__*/function (_React$Component2) {
167
- _inherits(PortalRenderer, _React$Component2);
168
- var _super3 = _createSuper(PortalRenderer);
169
- function PortalRenderer(props) {
170
- var _this4;
171
- _classCallCheck(this, PortalRenderer);
172
- _this4 = _super3.call(this, props);
173
- _defineProperty(_assertThisInitialized(_this4), "handleUpdate", function (portals) {
174
- return _this4.setState({
175
- portals: portals
176
- });
177
- });
178
- props.portalProviderAPI.setContext(_assertThisInitialized(_this4));
179
- props.portalProviderAPI.on('update', _this4.handleUpdate);
180
- _this4.state = {
181
- portals: new Map()
182
- };
183
- return _this4;
184
- }
185
- _createClass(PortalRenderer, [{
186
- key: "render",
187
- value: function render() {
188
- var portals = this.state.portals;
189
- return /*#__PURE__*/React.createElement(React.Fragment, null, Array.from(portals.entries()).map(function (_ref4) {
190
- var _ref5 = _slicedToArray(_ref4, 2),
191
- container = _ref5[0],
192
- children = _ref5[1];
193
- return /*#__PURE__*/createPortal(children, container);
194
- }));
195
- }
196
- }]);
197
- return PortalRenderer;
198
- }(React.Component);
199
-
200
- /**
201
- * Wrapper to re-provide modern analytics context to ReactNodeViews.
202
- */
203
- var dummyAnalyticsContext = {
204
- getAtlaskitAnalyticsContext: function getAtlaskitAnalyticsContext() {},
205
- getAtlaskitAnalyticsEventHandlers: function getAtlaskitAnalyticsEventHandlers() {}
206
- };
207
- var AnalyticsContextWrapper = (_class4 = /*#__PURE__*/function (_React$Component3) {
208
- _inherits(AnalyticsContextWrapper, _React$Component3);
209
- var _super4 = _createSuper(AnalyticsContextWrapper);
210
- function AnalyticsContextWrapper() {
211
- _classCallCheck(this, AnalyticsContextWrapper);
212
- return _super4.apply(this, arguments);
213
- }
214
- _createClass(AnalyticsContextWrapper, [{
215
- key: "render",
216
- value: function render() {
217
- var _ref6 = this.context.contextAdapter.analytics || {
218
- value: dummyAnalyticsContext
219
- },
220
- value = _ref6.value;
221
- return /*#__PURE__*/React.createElement(AnalyticsReactContext.Provider, {
222
- value: value
223
- }, this.props.children);
224
- }
225
- }]);
226
- return AnalyticsContextWrapper;
227
- }(React.Component), _defineProperty(_class4, "contextTypes", {
228
- contextAdapter: PropTypes.object
229
- }), _class4);
@@ -1,48 +0,0 @@
1
- import React from 'react';
2
- import type { IntlShape, WrappedComponentProps } from 'react-intl-next';
3
- import type { FireAnalyticsCallback } from '../../analytics';
4
- import { EventDispatcher } from '../../event-dispatcher';
5
- export type BasePortalProviderProps = {
6
- render: (portalProviderAPI: LegacyPortalProviderAPI) => React.ReactChild | JSX.Element | null;
7
- onAnalyticsEvent?: FireAnalyticsCallback;
8
- useAnalyticsContext?: boolean;
9
- } & WrappedComponentProps;
10
- export type Portals = Map<HTMLElement, React.ReactChild>;
11
- export type PortalRendererState = {
12
- portals: Portals;
13
- };
14
- type MountedPortal = {
15
- key: string;
16
- children: () => React.ReactChild | null;
17
- hasAnalyticsContext: boolean;
18
- hasIntlContext: boolean;
19
- };
20
- export declare class LegacyPortalProviderAPI extends EventDispatcher {
21
- portals: Map<HTMLElement, MountedPortal>;
22
- context: any;
23
- intl: IntlShape;
24
- onAnalyticsEvent?: FireAnalyticsCallback;
25
- useAnalyticsContext?: boolean;
26
- constructor(intl: IntlShape, onAnalyticsEvent?: FireAnalyticsCallback, analyticsContext?: boolean);
27
- setContext: (context: any) => void;
28
- render(children: () => React.ReactChild | JSX.Element | null, container: HTMLElement, key: string, hasAnalyticsContext?: boolean, hasIntlContext?: boolean): void;
29
- forceUpdate({ intl }: {
30
- intl: IntlShape;
31
- }): void;
32
- remove(key: string, container: HTMLElement): void;
33
- }
34
- export declare const PortalProvider: React.FC<import("react-intl-next").WithIntlProps<BasePortalProviderProps>> & {
35
- WrappedComponent: React.ComponentType<BasePortalProviderProps>;
36
- };
37
- type PortalProviderWithThemeProvidersProps = Omit<BasePortalProviderProps, 'intl' | 'themeMode'>;
38
- export declare const PortalProviderWithThemeProviders: ({ onAnalyticsEvent, useAnalyticsContext, render, }: PortalProviderWithThemeProvidersProps) => JSX.Element;
39
- export declare class PortalRenderer extends React.Component<{
40
- portalProviderAPI: LegacyPortalProviderAPI;
41
- }, PortalRendererState> {
42
- constructor(props: {
43
- portalProviderAPI: LegacyPortalProviderAPI;
44
- });
45
- handleUpdate: (portals: Portals) => void;
46
- render(): JSX.Element;
47
- }
48
- export {};