@atlaskit/editor-core 185.2.24 → 185.2.26
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 +14 -0
- package/dist/cjs/editor-next/editor-internal.js +3 -3
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/labs/next/Editor.js +3 -3
- package/dist/cjs/labs/next/presets/universal.js +6 -5
- package/dist/cjs/nodeviews/index.js +1 -16
- package/dist/cjs/plugins/annotation/index.js +31 -21
- package/dist/cjs/plugins/annotation/nodeviews/index.js +2 -2
- package/dist/cjs/plugins/base/index.js +0 -6
- package/dist/cjs/plugins/caption/index.js +1 -2
- package/dist/cjs/plugins/caption/nodeviews/index.js +3 -3
- package/dist/cjs/plugins/caption/pm-plugins/main.js +4 -2
- package/dist/cjs/plugins/card/nodeviews/embedCard.js +4 -4
- package/dist/cjs/plugins/extension/actions.js +6 -4
- package/dist/cjs/plugins/extension/commands.js +19 -16
- package/dist/cjs/plugins/extension/context-panel.js +4 -4
- package/dist/cjs/plugins/extension/extension-api.js +1 -1
- package/dist/cjs/plugins/extension/index.js +11 -4
- package/dist/cjs/plugins/extension/nodeviews/extension.js +2 -2
- package/dist/cjs/plugins/extension/pm-plugins/keymap.js +2 -2
- package/dist/cjs/plugins/extension/pm-plugins/main.js +10 -5
- package/dist/cjs/plugins/extension/toolbar.js +8 -6
- package/dist/cjs/plugins/floating-toolbar/ui/ExtensionsPlaceholder.js +11 -6
- package/dist/cjs/plugins/floating-toolbar/ui/Toolbar.js +5 -2
- package/dist/cjs/plugins/index.js +0 -7
- package/dist/cjs/plugins/jira-issue/index.js +2 -2
- package/dist/cjs/plugins/media/index.js +2 -2
- package/dist/cjs/plugins/media/nodeviews/mediaGroup.js +25 -19
- package/dist/cjs/plugins/media/nodeviews/mediaInline.js +3 -3
- package/dist/cjs/plugins/media/nodeviews/mediaNodeView/index.js +16 -10
- package/dist/cjs/plugins/media/nodeviews/mediaSingle.js +2 -2
- package/dist/cjs/plugins/media/pm-plugins/main.js +25 -8
- package/dist/cjs/plugins/tasks-and-decisions/nodeviews/decisionItem.js +2 -2
- package/dist/cjs/plugins/tasks-and-decisions/nodeviews/taskItem.js +2 -2
- package/dist/cjs/plugins/unsupported-content/index.js +6 -4
- package/dist/cjs/test-utils.js +0 -7
- package/dist/cjs/ui/ContextPanel/index.js +9 -2
- package/dist/cjs/utils/action.js +1 -1
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/editor-next/editor-internal.js +1 -1
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/labs/next/Editor.js +1 -1
- package/dist/es2019/labs/next/presets/universal.js +7 -6
- package/dist/es2019/nodeviews/index.js +1 -2
- package/dist/es2019/plugins/annotation/index.js +34 -23
- package/dist/es2019/plugins/annotation/nodeviews/index.js +1 -1
- package/dist/es2019/plugins/base/index.js +0 -4
- package/dist/es2019/plugins/caption/index.js +1 -4
- package/dist/es2019/plugins/caption/nodeviews/index.js +2 -2
- package/dist/es2019/plugins/caption/pm-plugins/main.js +4 -2
- package/dist/es2019/plugins/card/nodeviews/embedCard.js +2 -2
- package/dist/es2019/plugins/extension/actions.js +6 -4
- package/dist/es2019/plugins/extension/commands.js +6 -7
- package/dist/es2019/plugins/extension/context-panel.js +4 -4
- package/dist/es2019/plugins/extension/extension-api.js +1 -1
- package/dist/es2019/plugins/extension/index.js +11 -4
- package/dist/es2019/plugins/extension/nodeviews/extension.js +1 -1
- package/dist/es2019/plugins/extension/pm-plugins/keymap.js +2 -2
- package/dist/es2019/plugins/extension/pm-plugins/main.js +10 -5
- package/dist/es2019/plugins/extension/toolbar.js +8 -4
- package/dist/es2019/plugins/floating-toolbar/ui/ExtensionsPlaceholder.js +11 -6
- package/dist/es2019/plugins/floating-toolbar/ui/Toolbar.js +5 -2
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/plugins/jira-issue/index.js +1 -1
- package/dist/es2019/plugins/media/index.js +2 -2
- package/dist/es2019/plugins/media/nodeviews/mediaGroup.js +21 -14
- package/dist/es2019/plugins/media/nodeviews/mediaInline.js +2 -2
- package/dist/es2019/plugins/media/nodeviews/mediaNodeView/index.js +13 -9
- package/dist/es2019/plugins/media/nodeviews/mediaSingle.js +1 -1
- package/dist/es2019/plugins/media/pm-plugins/main.js +28 -11
- package/dist/es2019/plugins/tasks-and-decisions/nodeviews/decisionItem.js +1 -1
- package/dist/es2019/plugins/tasks-and-decisions/nodeviews/taskItem.js +1 -1
- package/dist/es2019/plugins/unsupported-content/index.js +1 -1
- package/dist/es2019/test-utils.js +0 -1
- package/dist/es2019/ui/ContextPanel/index.js +8 -1
- package/dist/es2019/utils/action.js +1 -1
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/editor-next/editor-internal.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/labs/next/Editor.js +1 -1
- package/dist/esm/labs/next/presets/universal.js +7 -6
- package/dist/esm/nodeviews/index.js +1 -2
- package/dist/esm/plugins/annotation/index.js +32 -22
- package/dist/esm/plugins/annotation/nodeviews/index.js +1 -1
- package/dist/esm/plugins/base/index.js +0 -6
- package/dist/esm/plugins/caption/index.js +1 -2
- package/dist/esm/plugins/caption/nodeviews/index.js +2 -2
- package/dist/esm/plugins/caption/pm-plugins/main.js +4 -2
- package/dist/esm/plugins/card/nodeviews/embedCard.js +4 -4
- package/dist/esm/plugins/extension/actions.js +6 -4
- package/dist/esm/plugins/extension/commands.js +18 -15
- package/dist/esm/plugins/extension/context-panel.js +4 -4
- package/dist/esm/plugins/extension/extension-api.js +1 -1
- package/dist/esm/plugins/extension/index.js +11 -4
- package/dist/esm/plugins/extension/nodeviews/extension.js +1 -1
- package/dist/esm/plugins/extension/pm-plugins/keymap.js +2 -2
- package/dist/esm/plugins/extension/pm-plugins/main.js +10 -5
- package/dist/esm/plugins/extension/toolbar.js +8 -6
- package/dist/esm/plugins/floating-toolbar/ui/ExtensionsPlaceholder.js +11 -6
- package/dist/esm/plugins/floating-toolbar/ui/Toolbar.js +5 -2
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/plugins/jira-issue/index.js +1 -1
- package/dist/esm/plugins/media/index.js +2 -2
- package/dist/esm/plugins/media/nodeviews/mediaGroup.js +24 -18
- package/dist/esm/plugins/media/nodeviews/mediaInline.js +2 -2
- package/dist/esm/plugins/media/nodeviews/mediaNodeView/index.js +15 -9
- package/dist/esm/plugins/media/nodeviews/mediaSingle.js +1 -1
- package/dist/esm/plugins/media/pm-plugins/main.js +26 -9
- package/dist/esm/plugins/tasks-and-decisions/nodeviews/decisionItem.js +1 -1
- package/dist/esm/plugins/tasks-and-decisions/nodeviews/taskItem.js +1 -1
- package/dist/esm/plugins/unsupported-content/index.js +1 -1
- package/dist/esm/test-utils.js +0 -1
- package/dist/esm/ui/ContextPanel/index.js +8 -1
- package/dist/esm/utils/action.js +1 -1
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/create-editor/ReactEditorViewInternal.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/labs/next/internal/components/EditorInternal.d.ts +2 -2
- package/dist/types/labs/next/internal/editor-props-type.d.ts +1 -1
- package/dist/types/labs/next/internal/hooks/use-editor/create-editor.d.ts +1 -1
- package/dist/types/labs/next/presets/cxhtml.d.ts +18 -2
- package/dist/types/labs/next/presets/default.d.ts +36 -4
- package/dist/types/labs/next/presets/mobile.d.ts +18 -2
- package/dist/types/nodeviews/index.d.ts +0 -2
- package/dist/types/plugins/annotation/index.d.ts +3 -1
- package/dist/types/plugins/annotation/nodeviews/index.d.ts +2 -1
- package/dist/types/plugins/annotation/pm-plugins/types.d.ts +2 -2
- package/dist/types/plugins/caption/index.d.ts +1 -1
- package/dist/types/plugins/caption/nodeviews/index.d.ts +7 -4
- package/dist/types/plugins/caption/pm-plugins/main.d.ts +5 -4
- package/dist/types/plugins/card/nodeviews/embedCard.d.ts +2 -2
- package/dist/types/plugins/extension/actions.d.ts +2 -1
- package/dist/types/plugins/extension/commands.d.ts +4 -3
- package/dist/types/plugins/extension/context-panel.d.ts +2 -1
- package/dist/types/plugins/extension/extension-api.d.ts +2 -0
- package/dist/types/plugins/extension/index.d.ts +4 -2
- package/dist/types/plugins/extension/nodeviews/extension.d.ts +3 -2
- package/dist/types/plugins/extension/pm-plugins/keymap.d.ts +2 -1
- package/dist/types/plugins/extension/pm-plugins/main.d.ts +5 -3
- package/dist/types/plugins/extension/toolbar.d.ts +8 -1
- package/dist/types/plugins/extension/types.d.ts +2 -0
- package/dist/types/plugins/floating-toolbar/ui/ExtensionsPlaceholder.d.ts +2 -0
- package/dist/types/plugins/floating-toolbar/ui/Toolbar.d.ts +7 -3
- package/dist/types/plugins/index.d.ts +0 -1
- package/dist/types/plugins/media/index.d.ts +3 -1
- package/dist/types/plugins/media/nodeviews/mediaGroup.d.ts +5 -3
- package/dist/types/plugins/media/nodeviews/mediaInline.d.ts +6 -3
- package/dist/types/plugins/media/nodeviews/mediaNodeView/index.d.ts +6 -4
- package/dist/types/plugins/media/nodeviews/mediaSingle.d.ts +2 -2
- package/dist/types/plugins/media/types.d.ts +4 -0
- package/dist/types/plugins/tasks-and-decisions/nodeviews/decisionItem.d.ts +1 -1
- package/dist/types/plugins/tasks-and-decisions/nodeviews/taskItem.d.ts +1 -1
- package/dist/types/plugins/tasks-and-decisions/pm-plugins/main.d.ts +1 -1
- package/dist/types/test-utils.d.ts +0 -1
- package/dist/types-ts4.5/create-editor/ReactEditorViewInternal.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/labs/next/internal/components/EditorInternal.d.ts +2 -2
- package/dist/types-ts4.5/labs/next/internal/editor-props-type.d.ts +1 -1
- package/dist/types-ts4.5/labs/next/internal/hooks/use-editor/create-editor.d.ts +1 -1
- package/dist/types-ts4.5/labs/next/presets/cxhtml.d.ts +20 -2
- package/dist/types-ts4.5/labs/next/presets/default.d.ts +40 -4
- package/dist/types-ts4.5/labs/next/presets/mobile.d.ts +20 -2
- package/dist/types-ts4.5/nodeviews/index.d.ts +0 -2
- package/dist/types-ts4.5/plugins/annotation/index.d.ts +3 -1
- package/dist/types-ts4.5/plugins/annotation/nodeviews/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/annotation/pm-plugins/types.d.ts +2 -2
- package/dist/types-ts4.5/plugins/caption/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/caption/nodeviews/index.d.ts +7 -4
- package/dist/types-ts4.5/plugins/caption/pm-plugins/main.d.ts +5 -4
- package/dist/types-ts4.5/plugins/card/nodeviews/embedCard.d.ts +2 -2
- package/dist/types-ts4.5/plugins/extension/actions.d.ts +2 -1
- package/dist/types-ts4.5/plugins/extension/commands.d.ts +4 -3
- package/dist/types-ts4.5/plugins/extension/context-panel.d.ts +2 -1
- package/dist/types-ts4.5/plugins/extension/extension-api.d.ts +2 -0
- package/dist/types-ts4.5/plugins/extension/index.d.ts +4 -2
- package/dist/types-ts4.5/plugins/extension/nodeviews/extension.d.ts +3 -2
- package/dist/types-ts4.5/plugins/extension/pm-plugins/keymap.d.ts +2 -1
- package/dist/types-ts4.5/plugins/extension/pm-plugins/main.d.ts +5 -3
- package/dist/types-ts4.5/plugins/extension/toolbar.d.ts +8 -1
- package/dist/types-ts4.5/plugins/extension/types.d.ts +2 -0
- package/dist/types-ts4.5/plugins/floating-toolbar/ui/ExtensionsPlaceholder.d.ts +2 -0
- package/dist/types-ts4.5/plugins/floating-toolbar/ui/Toolbar.d.ts +7 -3
- package/dist/types-ts4.5/plugins/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/media/index.d.ts +3 -1
- package/dist/types-ts4.5/plugins/media/nodeviews/mediaGroup.d.ts +5 -3
- package/dist/types-ts4.5/plugins/media/nodeviews/mediaInline.d.ts +6 -3
- package/dist/types-ts4.5/plugins/media/nodeviews/mediaNodeView/index.d.ts +6 -4
- package/dist/types-ts4.5/plugins/media/nodeviews/mediaSingle.d.ts +2 -2
- package/dist/types-ts4.5/plugins/media/types.d.ts +4 -0
- package/dist/types-ts4.5/plugins/tasks-and-decisions/nodeviews/decisionItem.d.ts +1 -1
- package/dist/types-ts4.5/plugins/tasks-and-decisions/nodeviews/taskItem.d.ts +1 -1
- package/dist/types-ts4.5/plugins/tasks-and-decisions/pm-plugins/main.d.ts +1 -1
- package/dist/types-ts4.5/test-utils.d.ts +0 -1
- package/package.json +3 -2
- package/report.api.md +20 -85
- package/tmp/api-report-tmp.d.ts +18 -68
- package/dist/cjs/nodeviews/ReactNodeView.js +0 -224
- package/dist/cjs/nodeviews/SelectionBasedNodeView.js +0 -169
- package/dist/cjs/plugins/base/pm-plugins/react-nodeview.js +0 -72
- package/dist/cjs/plugins/context-panel/index.js +0 -66
- package/dist/cjs/plugins/context-panel/transforms.js +0 -13
- package/dist/cjs/plugins/context-panel/types.js +0 -5
- package/dist/cjs/ui/PortalProvider/PortalProviderThemesProvider.js +0 -43
- package/dist/cjs/ui/PortalProvider/index.js +0 -252
- package/dist/es2019/nodeviews/ReactNodeView.js +0 -170
- package/dist/es2019/nodeviews/SelectionBasedNodeView.js +0 -158
- package/dist/es2019/plugins/base/pm-plugins/react-nodeview.js +0 -48
- package/dist/es2019/plugins/context-panel/index.js +0 -45
- package/dist/es2019/plugins/context-panel/transforms.js +0 -4
- package/dist/es2019/plugins/context-panel/types.js +0 -1
- package/dist/es2019/ui/PortalProvider/PortalProviderThemesProvider.js +0 -37
- package/dist/es2019/ui/PortalProvider/index.js +0 -184
- package/dist/esm/nodeviews/ReactNodeView.js +0 -217
- package/dist/esm/nodeviews/SelectionBasedNodeView.js +0 -163
- package/dist/esm/plugins/base/pm-plugins/react-nodeview.js +0 -62
- package/dist/esm/plugins/context-panel/index.js +0 -57
- package/dist/esm/plugins/context-panel/transforms.js +0 -6
- package/dist/esm/plugins/context-panel/types.js +0 -1
- package/dist/esm/ui/PortalProvider/PortalProviderThemesProvider.js +0 -36
- package/dist/esm/ui/PortalProvider/index.js +0 -242
- package/dist/types/nodeviews/ReactNodeView.d.ts +0 -52
- package/dist/types/nodeviews/SelectionBasedNodeView.d.ts +0 -53
- package/dist/types/plugins/base/pm-plugins/react-nodeview.d.ts +0 -13
- package/dist/types/plugins/context-panel/index.d.ts +0 -11
- package/dist/types/plugins/context-panel/transforms.d.ts +0 -2
- package/dist/types/plugins/context-panel/types.d.ts +0 -1
- package/dist/types/ui/PortalProvider/PortalProviderThemesProvider.d.ts +0 -6
- package/dist/types/ui/PortalProvider/index.d.ts +0 -51
- package/dist/types-ts4.5/nodeviews/ReactNodeView.d.ts +0 -52
- package/dist/types-ts4.5/nodeviews/SelectionBasedNodeView.d.ts +0 -53
- package/dist/types-ts4.5/plugins/base/pm-plugins/react-nodeview.d.ts +0 -13
- package/dist/types-ts4.5/plugins/context-panel/index.d.ts +0 -11
- package/dist/types-ts4.5/plugins/context-panel/transforms.d.ts +0 -2
- package/dist/types-ts4.5/plugins/context-panel/types.d.ts +0 -1
- package/dist/types-ts4.5/ui/PortalProvider/PortalProviderThemesProvider.d.ts +0 -6
- package/dist/types-ts4.5/ui/PortalProvider/index.d.ts +0 -51
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import AtlaskitTheme from '@atlaskit/theme/components';
|
|
3
|
-
import { CHANNEL } from '@atlaskit/theme/constants';
|
|
4
|
-
import { ThemeProvider } from '@emotion/react';
|
|
5
|
-
export function PortalProviderThemeProviders(props) {
|
|
6
|
-
const {
|
|
7
|
-
children,
|
|
8
|
-
mode
|
|
9
|
-
} = props;
|
|
10
|
-
const styledComponentsAndEmotionTheme = React.useMemo(
|
|
11
|
-
// This return value should only be one of the following
|
|
12
|
-
// - { [CHANNEL]: { mode },
|
|
13
|
-
// - { theme: { [CHANNEL]: { mode } }
|
|
14
|
-
// However, it appears that consumers have inconsistent expectations
|
|
15
|
-
// regarding the shape.
|
|
16
|
-
// This can be revisited in future work, and for the purposes of
|
|
17
|
-
// fixing https://product-fabric.atlassian.net/browse/ED-14956
|
|
18
|
-
// we are merging the two shapes consumers expect.
|
|
19
|
-
() => ({
|
|
20
|
-
[CHANNEL]: {
|
|
21
|
-
mode
|
|
22
|
-
},
|
|
23
|
-
theme: {
|
|
24
|
-
[CHANNEL]: {
|
|
25
|
-
mode
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}), [mode]);
|
|
29
|
-
const atlaskitTheme = React.useCallback(() => ({
|
|
30
|
-
mode
|
|
31
|
-
}), [mode]);
|
|
32
|
-
return /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
33
|
-
theme: styledComponentsAndEmotionTheme
|
|
34
|
-
}, /*#__PURE__*/React.createElement(AtlaskitTheme.Provider, {
|
|
35
|
-
value: atlaskitTheme
|
|
36
|
-
}, children));
|
|
37
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
var _class;
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { createPortal, unstable_renderSubtreeIntoContainer, unmountComponentAtNode } from 'react-dom';
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import { default as AnalyticsReactContext } from '@atlaskit/analytics-next-stable-react-context';
|
|
7
|
-
import { EventDispatcher } from '../../event-dispatcher';
|
|
8
|
-
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
9
|
-
import { useIntl, RawIntlProvider, injectIntl } from 'react-intl-next';
|
|
10
|
-
import { useGlobalTheme } from '@atlaskit/theme/components';
|
|
11
|
-
import { PortalProviderThemeProviders } from './PortalProviderThemesProvider';
|
|
12
|
-
import { IntlProviderIfMissingWrapper } from '@atlaskit/editor-common/ui';
|
|
13
|
-
export class PortalProviderAPI extends EventDispatcher {
|
|
14
|
-
constructor(intl, onAnalyticsEvent, analyticsContext, themeMode) {
|
|
15
|
-
super();
|
|
16
|
-
_defineProperty(this, "portals", new Map());
|
|
17
|
-
_defineProperty(this, "setContext", context => {
|
|
18
|
-
this.context = context;
|
|
19
|
-
});
|
|
20
|
-
this.intl = intl;
|
|
21
|
-
this.onAnalyticsEvent = onAnalyticsEvent;
|
|
22
|
-
this.useAnalyticsContext = analyticsContext;
|
|
23
|
-
this.themeMode = themeMode;
|
|
24
|
-
}
|
|
25
|
-
render(children, container, hasAnalyticsContext = false, hasIntlContext = false) {
|
|
26
|
-
this.portals.set(container, {
|
|
27
|
-
children: children,
|
|
28
|
-
hasAnalyticsContext,
|
|
29
|
-
hasIntlContext
|
|
30
|
-
});
|
|
31
|
-
const childrenWithThemeProviders = /*#__PURE__*/React.createElement(PortalProviderThemeProviders, {
|
|
32
|
-
mode: this.themeMode
|
|
33
|
-
}, children());
|
|
34
|
-
let wrappedChildren = this.useAnalyticsContext ? /*#__PURE__*/React.createElement(AnalyticsContextWrapper, null, childrenWithThemeProviders) : childrenWithThemeProviders;
|
|
35
|
-
if (hasIntlContext) {
|
|
36
|
-
wrappedChildren = /*#__PURE__*/React.createElement(RawIntlProvider, {
|
|
37
|
-
value: this.intl
|
|
38
|
-
}, wrappedChildren);
|
|
39
|
-
}
|
|
40
|
-
unstable_renderSubtreeIntoContainer(this.context, wrappedChildren, container);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// TODO: until https://product-fabric.atlassian.net/browse/ED-5013
|
|
44
|
-
// we (unfortunately) need to re-render to pass down any updated context.
|
|
45
|
-
// selectively do this for nodeviews that opt-in via `hasAnalyticsContext`
|
|
46
|
-
forceUpdate({
|
|
47
|
-
intl,
|
|
48
|
-
themeMode
|
|
49
|
-
}) {
|
|
50
|
-
this.intl = intl;
|
|
51
|
-
this.themeMode = themeMode;
|
|
52
|
-
this.portals.forEach((portal, container) => {
|
|
53
|
-
if (!portal.hasAnalyticsContext && !this.useAnalyticsContext && !portal.hasIntlContext) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
let wrappedChildren = portal.children();
|
|
57
|
-
const childrenWithThemeProviders = /*#__PURE__*/React.createElement(PortalProviderThemeProviders, {
|
|
58
|
-
mode: themeMode
|
|
59
|
-
}, wrappedChildren);
|
|
60
|
-
if (portal.hasAnalyticsContext && this.useAnalyticsContext) {
|
|
61
|
-
wrappedChildren = /*#__PURE__*/React.createElement(AnalyticsContextWrapper, null, childrenWithThemeProviders);
|
|
62
|
-
}
|
|
63
|
-
if (portal.hasIntlContext) {
|
|
64
|
-
wrappedChildren = /*#__PURE__*/React.createElement(RawIntlProvider, {
|
|
65
|
-
value: this.intl
|
|
66
|
-
}, childrenWithThemeProviders);
|
|
67
|
-
}
|
|
68
|
-
unstable_renderSubtreeIntoContainer(this.context, wrappedChildren, container);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
remove(container) {
|
|
72
|
-
this.portals.delete(container);
|
|
73
|
-
|
|
74
|
-
// There is a race condition that can happen caused by Prosemirror vs React,
|
|
75
|
-
// where Prosemirror removes the container from the DOM before React gets
|
|
76
|
-
// around to removing the child from the container
|
|
77
|
-
// This will throw a NotFoundError: The node to be removed is not a child of this node
|
|
78
|
-
// Both Prosemirror and React remove the elements asynchronously, and in edge
|
|
79
|
-
// cases Prosemirror beats React
|
|
80
|
-
try {
|
|
81
|
-
unmountComponentAtNode(container);
|
|
82
|
-
} catch (error) {
|
|
83
|
-
if (this.onAnalyticsEvent) {
|
|
84
|
-
this.onAnalyticsEvent({
|
|
85
|
-
payload: {
|
|
86
|
-
action: ACTION.FAILED_TO_UNMOUNT,
|
|
87
|
-
actionSubject: ACTION_SUBJECT.EDITOR,
|
|
88
|
-
actionSubjectId: ACTION_SUBJECT_ID.REACT_NODE_VIEW,
|
|
89
|
-
attributes: {
|
|
90
|
-
error: error,
|
|
91
|
-
domNodes: {
|
|
92
|
-
container: container ? container.className : undefined,
|
|
93
|
-
child: container.firstElementChild ? container.firstElementChild.className : undefined
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
eventType: EVENT_TYPE.OPERATIONAL
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
class BasePortalProvider extends React.Component {
|
|
104
|
-
constructor(props) {
|
|
105
|
-
super(props);
|
|
106
|
-
this.portalProviderAPI = new PortalProviderAPI(props.intl, props.onAnalyticsEvent, props.useAnalyticsContext, props.themeMode);
|
|
107
|
-
}
|
|
108
|
-
render() {
|
|
109
|
-
return this.props.render(this.portalProviderAPI);
|
|
110
|
-
}
|
|
111
|
-
componentDidUpdate() {
|
|
112
|
-
this.portalProviderAPI.forceUpdate({
|
|
113
|
-
intl: this.props.intl,
|
|
114
|
-
themeMode: this.props.themeMode
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
_defineProperty(BasePortalProvider, "displayName", 'PortalProvider');
|
|
119
|
-
export const PortalProvider = injectIntl(BasePortalProvider);
|
|
120
|
-
export const PortalProviderWithThemeProviders = ({
|
|
121
|
-
onAnalyticsEvent,
|
|
122
|
-
useAnalyticsContext,
|
|
123
|
-
render
|
|
124
|
-
}) => /*#__PURE__*/React.createElement(IntlProviderIfMissingWrapper, null, /*#__PURE__*/React.createElement(PortalProviderWithThemeAndIntlProviders, {
|
|
125
|
-
onAnalyticsEvent: onAnalyticsEvent,
|
|
126
|
-
useAnalyticsContext: useAnalyticsContext,
|
|
127
|
-
render: render
|
|
128
|
-
}));
|
|
129
|
-
const PortalProviderWithThemeAndIntlProviders = ({
|
|
130
|
-
onAnalyticsEvent,
|
|
131
|
-
useAnalyticsContext,
|
|
132
|
-
render
|
|
133
|
-
}) => {
|
|
134
|
-
const intl = useIntl();
|
|
135
|
-
const globalTheme = useGlobalTheme();
|
|
136
|
-
return /*#__PURE__*/React.createElement(BasePortalProvider, {
|
|
137
|
-
intl: intl,
|
|
138
|
-
themeMode: globalTheme.mode,
|
|
139
|
-
onAnalyticsEvent: onAnalyticsEvent,
|
|
140
|
-
useAnalyticsContext: useAnalyticsContext,
|
|
141
|
-
render: render
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
export class PortalRenderer extends React.Component {
|
|
145
|
-
constructor(props) {
|
|
146
|
-
super(props);
|
|
147
|
-
_defineProperty(this, "handleUpdate", portals => this.setState({
|
|
148
|
-
portals
|
|
149
|
-
}));
|
|
150
|
-
props.portalProviderAPI.setContext(this);
|
|
151
|
-
props.portalProviderAPI.on('update', this.handleUpdate);
|
|
152
|
-
this.state = {
|
|
153
|
-
portals: new Map()
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
render() {
|
|
157
|
-
const {
|
|
158
|
-
portals
|
|
159
|
-
} = this.state;
|
|
160
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, Array.from(portals.entries()).map(([container, children]) => /*#__PURE__*/createPortal(children, container)));
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Wrapper to re-provide modern analytics context to ReactNodeViews.
|
|
166
|
-
*/
|
|
167
|
-
const dummyAnalyticsContext = {
|
|
168
|
-
getAtlaskitAnalyticsContext() {},
|
|
169
|
-
getAtlaskitAnalyticsEventHandlers() {}
|
|
170
|
-
};
|
|
171
|
-
const AnalyticsContextWrapper = (_class = class AnalyticsContextWrapper extends React.Component {
|
|
172
|
-
render() {
|
|
173
|
-
const {
|
|
174
|
-
value
|
|
175
|
-
} = this.context.contextAdapter.analytics || {
|
|
176
|
-
value: dummyAnalyticsContext
|
|
177
|
-
};
|
|
178
|
-
return /*#__PURE__*/React.createElement(AnalyticsReactContext.Provider, {
|
|
179
|
-
value: value
|
|
180
|
-
}, this.props.children);
|
|
181
|
-
}
|
|
182
|
-
}, _defineProperty(_class, "contextTypes", {
|
|
183
|
-
contextAdapter: PropTypes.object
|
|
184
|
-
}), _class);
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { createDispatch } from '../event-dispatcher';
|
|
7
|
-
import { ACTION_SUBJECT, ACTION_SUBJECT_ID } from '../plugins/analytics';
|
|
8
|
-
import { analyticsEventKey } from '../plugins/analytics/consts';
|
|
9
|
-
import { ErrorBoundary } from '../ui/ErrorBoundary';
|
|
10
|
-
import { getPerformanceOptions, startMeasureReactNodeViewRendered, stopMeasureReactNodeViewRendered } from './getPerformanceOptions';
|
|
11
|
-
var ReactNodeView = /*#__PURE__*/function () {
|
|
12
|
-
function ReactNodeView(_node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, reactComponent) {
|
|
13
|
-
var _this = this;
|
|
14
|
-
var hasAnalyticsContext = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
|
|
15
|
-
var viewShouldUpdate = arguments.length > 8 ? arguments[8] : undefined;
|
|
16
|
-
var hasIntlContext = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : false;
|
|
17
|
-
_classCallCheck(this, ReactNodeView);
|
|
18
|
-
_defineProperty(this, "handleRef", function (node) {
|
|
19
|
-
return _this._handleRef(node);
|
|
20
|
-
});
|
|
21
|
-
_defineProperty(this, "dispatchAnalyticsEvent", function (payload) {
|
|
22
|
-
if (_this.eventDispatcher) {
|
|
23
|
-
var dispatch = createDispatch(_this.eventDispatcher);
|
|
24
|
-
dispatch(analyticsEventKey, {
|
|
25
|
-
payload: payload
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
this.node = _node;
|
|
30
|
-
this.view = view;
|
|
31
|
-
this.getPos = getPos;
|
|
32
|
-
this.portalProviderAPI = portalProviderAPI;
|
|
33
|
-
this.reactComponentProps = reactComponentProps || {};
|
|
34
|
-
this.reactComponent = reactComponent;
|
|
35
|
-
this.hasAnalyticsContext = hasAnalyticsContext;
|
|
36
|
-
this._viewShouldUpdate = viewShouldUpdate;
|
|
37
|
-
this.eventDispatcher = eventDispatcher;
|
|
38
|
-
this.hasIntlContext = hasIntlContext;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* This method exists to move initialization logic out of the constructor,
|
|
43
|
-
* so object can be initialized properly before calling render first time.
|
|
44
|
-
*
|
|
45
|
-
* Example:
|
|
46
|
-
* Instance properties get added to an object only after super call in
|
|
47
|
-
* constructor, which leads to some methods being undefined during the
|
|
48
|
-
* first render.
|
|
49
|
-
*/
|
|
50
|
-
_createClass(ReactNodeView, [{
|
|
51
|
-
key: "init",
|
|
52
|
-
value: function init() {
|
|
53
|
-
var _this2 = this;
|
|
54
|
-
this.domRef = this.createDomRef();
|
|
55
|
-
this.setDomAttrs(this.node, this.domRef);
|
|
56
|
-
var _ref = this.getContentDOM() || {
|
|
57
|
-
dom: undefined,
|
|
58
|
-
contentDOM: undefined
|
|
59
|
-
},
|
|
60
|
-
contentDOMWrapper = _ref.dom,
|
|
61
|
-
contentDOM = _ref.contentDOM;
|
|
62
|
-
if (this.domRef && contentDOMWrapper) {
|
|
63
|
-
this.domRef.appendChild(contentDOMWrapper);
|
|
64
|
-
this.contentDOM = contentDOM ? contentDOM : contentDOMWrapper;
|
|
65
|
-
this.contentDOMWrapper = contentDOMWrapper || contentDOM;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// @see ED-3790
|
|
69
|
-
// something gets messed up during mutation processing inside of a
|
|
70
|
-
// nodeView if DOM structure has nested plain "div"s, it doesn't see the
|
|
71
|
-
// difference between them and it kills the nodeView
|
|
72
|
-
this.domRef.classList.add("".concat(this.node.type.name, "View-content-wrap"));
|
|
73
|
-
var _getPerformanceOption = getPerformanceOptions(this.view),
|
|
74
|
-
samplingRate = _getPerformanceOption.samplingRate,
|
|
75
|
-
slowThreshold = _getPerformanceOption.slowThreshold,
|
|
76
|
-
trackingEnabled = _getPerformanceOption.trackingEnabled;
|
|
77
|
-
trackingEnabled && startMeasureReactNodeViewRendered({
|
|
78
|
-
nodeTypeName: this.node.type.name
|
|
79
|
-
});
|
|
80
|
-
this.renderReactComponent(function () {
|
|
81
|
-
return _this2.render(_this2.reactComponentProps, _this2.handleRef);
|
|
82
|
-
});
|
|
83
|
-
trackingEnabled && stopMeasureReactNodeViewRendered({
|
|
84
|
-
nodeTypeName: this.node.type.name,
|
|
85
|
-
dispatchAnalyticsEvent: this.dispatchAnalyticsEvent,
|
|
86
|
-
editorState: this.view.state,
|
|
87
|
-
samplingRate: samplingRate,
|
|
88
|
-
slowThreshold: slowThreshold
|
|
89
|
-
});
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
}, {
|
|
93
|
-
key: "renderReactComponent",
|
|
94
|
-
value: function renderReactComponent(component) {
|
|
95
|
-
var _this3 = this;
|
|
96
|
-
if (!this.domRef || !component) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
var componentWithErrorBoundary = function componentWithErrorBoundary() {
|
|
100
|
-
var _this3$node$type$name, _this3$node, _this3$node$type;
|
|
101
|
-
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
102
|
-
component: ACTION_SUBJECT.REACT_NODE_VIEW,
|
|
103
|
-
componentId: (_this3$node$type$name = _this3 === null || _this3 === void 0 ? void 0 : (_this3$node = _this3.node) === null || _this3$node === void 0 ? void 0 : (_this3$node$type = _this3$node.type) === null || _this3$node$type === void 0 ? void 0 : _this3$node$type.name) !== null && _this3$node$type$name !== void 0 ? _this3$node$type$name : ACTION_SUBJECT_ID.UNKNOWN_NODE,
|
|
104
|
-
dispatchAnalyticsEvent: _this3.dispatchAnalyticsEvent
|
|
105
|
-
}, component());
|
|
106
|
-
};
|
|
107
|
-
this.portalProviderAPI.render(componentWithErrorBoundary, this.domRef, this.hasAnalyticsContext, this.hasIntlContext);
|
|
108
|
-
}
|
|
109
|
-
}, {
|
|
110
|
-
key: "createDomRef",
|
|
111
|
-
value: function createDomRef() {
|
|
112
|
-
if (!this.node.isInline) {
|
|
113
|
-
return document.createElement('div');
|
|
114
|
-
}
|
|
115
|
-
var htmlElement = document.createElement('span');
|
|
116
|
-
return htmlElement;
|
|
117
|
-
}
|
|
118
|
-
}, {
|
|
119
|
-
key: "getContentDOM",
|
|
120
|
-
value: function getContentDOM() {
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
}, {
|
|
124
|
-
key: "_handleRef",
|
|
125
|
-
value: function _handleRef(node) {
|
|
126
|
-
var contentDOM = this.contentDOMWrapper || this.contentDOM;
|
|
127
|
-
|
|
128
|
-
// move the contentDOM node inside the inner reference after rendering
|
|
129
|
-
if (node && contentDOM && !node.contains(contentDOM)) {
|
|
130
|
-
node.appendChild(contentDOM);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}, {
|
|
134
|
-
key: "render",
|
|
135
|
-
value: function render(props, forwardRef) {
|
|
136
|
-
return this.reactComponent ? /*#__PURE__*/React.createElement(this.reactComponent, _extends({
|
|
137
|
-
view: this.view,
|
|
138
|
-
getPos: this.getPos,
|
|
139
|
-
node: this.node,
|
|
140
|
-
forwardRef: forwardRef
|
|
141
|
-
}, props)) : null;
|
|
142
|
-
}
|
|
143
|
-
}, {
|
|
144
|
-
key: "update",
|
|
145
|
-
value: function update(node, _decorations, _innerDecorations) {
|
|
146
|
-
var _this4 = this;
|
|
147
|
-
var validUpdate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {
|
|
148
|
-
return true;
|
|
149
|
-
};
|
|
150
|
-
// @see https://github.com/ProseMirror/prosemirror/issues/648
|
|
151
|
-
var isValidUpdate = this.node.type === node.type && validUpdate(this.node, node);
|
|
152
|
-
if (!isValidUpdate) {
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
if (this.domRef && !this.node.sameMarkup(node)) {
|
|
156
|
-
this.setDomAttrs(node, this.domRef);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// View should not process a re-render if this is false.
|
|
160
|
-
// We dont want to destroy the view, so we return true.
|
|
161
|
-
if (!this.viewShouldUpdate(node)) {
|
|
162
|
-
this.node = node;
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
|
-
this.node = node;
|
|
166
|
-
this.renderReactComponent(function () {
|
|
167
|
-
return _this4.render(_this4.reactComponentProps, _this4.handleRef);
|
|
168
|
-
});
|
|
169
|
-
return true;
|
|
170
|
-
}
|
|
171
|
-
}, {
|
|
172
|
-
key: "viewShouldUpdate",
|
|
173
|
-
value: function viewShouldUpdate(nextNode) {
|
|
174
|
-
if (this._viewShouldUpdate) {
|
|
175
|
-
return this._viewShouldUpdate(nextNode);
|
|
176
|
-
}
|
|
177
|
-
return true;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Copies the attributes from a ProseMirror Node to a DOM node.
|
|
182
|
-
* @param node The Prosemirror Node from which to source the attributes
|
|
183
|
-
*/
|
|
184
|
-
}, {
|
|
185
|
-
key: "setDomAttrs",
|
|
186
|
-
value: function setDomAttrs(node, element) {
|
|
187
|
-
Object.keys(node.attrs || {}).forEach(function (attr) {
|
|
188
|
-
element.setAttribute(attr, node.attrs[attr]);
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}, {
|
|
192
|
-
key: "dom",
|
|
193
|
-
get: function get() {
|
|
194
|
-
return this.domRef;
|
|
195
|
-
}
|
|
196
|
-
}, {
|
|
197
|
-
key: "destroy",
|
|
198
|
-
value: function destroy() {
|
|
199
|
-
if (!this.domRef) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
this.portalProviderAPI.remove(this.domRef);
|
|
203
|
-
this.domRef = undefined;
|
|
204
|
-
this.contentDOM = undefined;
|
|
205
|
-
}
|
|
206
|
-
}], [{
|
|
207
|
-
key: "fromComponent",
|
|
208
|
-
value: function fromComponent(component, portalProviderAPI, eventDispatcher, props, viewShouldUpdate) {
|
|
209
|
-
var hasIntlContext = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
210
|
-
return function (node, view, getPos) {
|
|
211
|
-
return new ReactNodeView(node, view, getPos, portalProviderAPI, eventDispatcher, props, component, false, viewShouldUpdate, hasIntlContext).init();
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
}]);
|
|
215
|
-
return ReactNodeView;
|
|
216
|
-
}();
|
|
217
|
-
export { ReactNodeView as default };
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
-
import _get from "@babel/runtime/helpers/get";
|
|
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
|
-
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); }; }
|
|
10
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
11
|
-
import { NodeSelection } from 'prosemirror-state';
|
|
12
|
-
import { stateKey as SelectionChangePluginKey } from '../plugins/base/pm-plugins/react-nodeview';
|
|
13
|
-
import ReactNodeView from './ReactNodeView';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A ReactNodeView that handles React components sensitive
|
|
17
|
-
* to selection changes.
|
|
18
|
-
*
|
|
19
|
-
* If the selection changes, it will attempt to re-render the
|
|
20
|
-
* React component. Otherwise it does nothing.
|
|
21
|
-
*
|
|
22
|
-
* You can subclass `viewShouldUpdate` to include other
|
|
23
|
-
* props that your component might want to consider before
|
|
24
|
-
* entering the React lifecycle. These are usually props you
|
|
25
|
-
* compare in `shouldComponentUpdate`.
|
|
26
|
-
*
|
|
27
|
-
* An example:
|
|
28
|
-
*
|
|
29
|
-
* ```
|
|
30
|
-
* viewShouldUpdate(nextNode) {
|
|
31
|
-
* if (nextNode.attrs !== this.node.attrs) {
|
|
32
|
-
* return true;
|
|
33
|
-
* }
|
|
34
|
-
*
|
|
35
|
-
* return super.viewShouldUpdate(nextNode);
|
|
36
|
-
* }```
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
export var SelectionBasedNodeView = /*#__PURE__*/function (_ReactNodeView) {
|
|
40
|
-
_inherits(SelectionBasedNodeView, _ReactNodeView);
|
|
41
|
-
var _super = _createSuper(SelectionBasedNodeView);
|
|
42
|
-
function SelectionBasedNodeView(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, reactComponent) {
|
|
43
|
-
var _this;
|
|
44
|
-
var hasContext = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
|
|
45
|
-
var viewShouldUpdate = arguments.length > 8 ? arguments[8] : undefined;
|
|
46
|
-
var hasIntlContext = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : false;
|
|
47
|
-
_classCallCheck(this, SelectionBasedNodeView);
|
|
48
|
-
_this = _super.call(this, node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, reactComponent, hasContext, viewShouldUpdate, hasIntlContext);
|
|
49
|
-
_defineProperty(_assertThisInitialized(_this), "isNodeInsideSelection", function (from, to, pos, posEnd) {
|
|
50
|
-
var _this$getPositionsWit = _this.getPositionsWithDefault(pos, posEnd);
|
|
51
|
-
pos = _this$getPositionsWit.pos;
|
|
52
|
-
posEnd = _this$getPositionsWit.posEnd;
|
|
53
|
-
if (typeof pos !== 'number' || typeof posEnd !== 'number') {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
return from <= pos && to >= posEnd;
|
|
57
|
-
});
|
|
58
|
-
_defineProperty(_assertThisInitialized(_this), "isSelectionInsideNode", function (from, to, pos, posEnd) {
|
|
59
|
-
var _this$getPositionsWit2 = _this.getPositionsWithDefault(pos, posEnd);
|
|
60
|
-
pos = _this$getPositionsWit2.pos;
|
|
61
|
-
posEnd = _this$getPositionsWit2.posEnd;
|
|
62
|
-
if (typeof pos !== 'number' || typeof posEnd !== 'number') {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
return pos < from && to < posEnd;
|
|
66
|
-
});
|
|
67
|
-
_defineProperty(_assertThisInitialized(_this), "isSelectedNode", function (selection) {
|
|
68
|
-
if (selection instanceof NodeSelection) {
|
|
69
|
-
var _this$view$state$sele = _this.view.state.selection,
|
|
70
|
-
from = _this$view$state$sele.from,
|
|
71
|
-
to = _this$view$state$sele.to;
|
|
72
|
-
return selection.node === _this.node ||
|
|
73
|
-
// If nodes are not the same object, we check if they are referring to the same document node
|
|
74
|
-
_this.pos === from && _this.posEnd === to && selection.node.eq(_this.node);
|
|
75
|
-
}
|
|
76
|
-
return false;
|
|
77
|
-
});
|
|
78
|
-
_defineProperty(_assertThisInitialized(_this), "insideSelection", function () {
|
|
79
|
-
var _this$view$state$sele2 = _this.view.state.selection,
|
|
80
|
-
from = _this$view$state$sele2.from,
|
|
81
|
-
to = _this$view$state$sele2.to;
|
|
82
|
-
return _this.isSelectedNode(_this.view.state.selection) || _this.isSelectionInsideNode(from, to);
|
|
83
|
-
});
|
|
84
|
-
_defineProperty(_assertThisInitialized(_this), "nodeInsideSelection", function () {
|
|
85
|
-
var selection = _this.view.state.selection;
|
|
86
|
-
var from = selection.from,
|
|
87
|
-
to = selection.to;
|
|
88
|
-
return _this.isSelectedNode(selection) || _this.isNodeInsideSelection(from, to);
|
|
89
|
-
});
|
|
90
|
-
_defineProperty(_assertThisInitialized(_this), "onSelectionChange", function () {
|
|
91
|
-
_this.update(_this.node, []);
|
|
92
|
-
});
|
|
93
|
-
_this.updatePos();
|
|
94
|
-
_this.oldSelection = view.state.selection;
|
|
95
|
-
_this.selectionChangeState = SelectionChangePluginKey.getState(_this.view.state);
|
|
96
|
-
_this.selectionChangeState.subscribe(_this.onSelectionChange);
|
|
97
|
-
return _this;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Update current node's start and end positions.
|
|
102
|
-
*
|
|
103
|
-
* Prefer `this.pos` rather than getPos(), because calling getPos is
|
|
104
|
-
* expensive, unless you know you're definitely going to render.
|
|
105
|
-
*/
|
|
106
|
-
_createClass(SelectionBasedNodeView, [{
|
|
107
|
-
key: "updatePos",
|
|
108
|
-
value: function updatePos() {
|
|
109
|
-
if (typeof this.getPos === 'boolean') {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
this.pos = this.getPos();
|
|
113
|
-
this.posEnd = this.pos + this.node.nodeSize;
|
|
114
|
-
}
|
|
115
|
-
}, {
|
|
116
|
-
key: "getPositionsWithDefault",
|
|
117
|
-
value: function getPositionsWithDefault(pos, posEnd) {
|
|
118
|
-
return {
|
|
119
|
-
pos: typeof pos !== 'number' ? this.pos : pos,
|
|
120
|
-
posEnd: typeof posEnd !== 'number' ? this.posEnd : posEnd
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
}, {
|
|
124
|
-
key: "viewShouldUpdate",
|
|
125
|
-
value: function viewShouldUpdate(_nextNode) {
|
|
126
|
-
var selection = this.view.state.selection;
|
|
127
|
-
|
|
128
|
-
// update selection
|
|
129
|
-
var oldSelection = this.oldSelection;
|
|
130
|
-
this.oldSelection = selection;
|
|
131
|
-
|
|
132
|
-
// update cached positions
|
|
133
|
-
var oldPos = this.pos,
|
|
134
|
-
oldPosEnd = this.posEnd;
|
|
135
|
-
this.updatePos();
|
|
136
|
-
var from = selection.from,
|
|
137
|
-
to = selection.to;
|
|
138
|
-
var oldFrom = oldSelection.from,
|
|
139
|
-
oldTo = oldSelection.to;
|
|
140
|
-
if (this.node.type.spec.selectable) {
|
|
141
|
-
var newNodeSelection = selection instanceof NodeSelection && selection.from === this.pos;
|
|
142
|
-
var oldNodeSelection = oldSelection instanceof NodeSelection && oldSelection.from === this.pos;
|
|
143
|
-
if (newNodeSelection && !oldNodeSelection || oldNodeSelection && !newNodeSelection) {
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
var movedInToSelection = this.isNodeInsideSelection(from, to) && !this.isNodeInsideSelection(oldFrom, oldTo);
|
|
148
|
-
var movedOutOfSelection = !this.isNodeInsideSelection(from, to) && this.isNodeInsideSelection(oldFrom, oldTo);
|
|
149
|
-
var moveOutFromOldSelection = this.isNodeInsideSelection(from, to, oldPos, oldPosEnd) && !this.isNodeInsideSelection(from, to);
|
|
150
|
-
if (movedInToSelection || movedOutOfSelection || moveOutFromOldSelection) {
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
}, {
|
|
156
|
-
key: "destroy",
|
|
157
|
-
value: function destroy() {
|
|
158
|
-
this.selectionChangeState.unsubscribe(this.onSelectionChange);
|
|
159
|
-
_get(_getPrototypeOf(SelectionBasedNodeView.prototype), "destroy", this).call(this);
|
|
160
|
-
}
|
|
161
|
-
}]);
|
|
162
|
-
return SelectionBasedNodeView;
|
|
163
|
-
}(ReactNodeView);
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
-
import { PluginKey } from 'prosemirror-state';
|
|
6
|
-
export var ReactNodeViewState = /*#__PURE__*/function () {
|
|
7
|
-
function ReactNodeViewState() {
|
|
8
|
-
_classCallCheck(this, ReactNodeViewState);
|
|
9
|
-
_defineProperty(this, "changeHandlers", []);
|
|
10
|
-
this.changeHandlers = [];
|
|
11
|
-
}
|
|
12
|
-
_createClass(ReactNodeViewState, [{
|
|
13
|
-
key: "subscribe",
|
|
14
|
-
value: function subscribe(cb) {
|
|
15
|
-
this.changeHandlers.push(cb);
|
|
16
|
-
}
|
|
17
|
-
}, {
|
|
18
|
-
key: "unsubscribe",
|
|
19
|
-
value: function unsubscribe(cb) {
|
|
20
|
-
this.changeHandlers = this.changeHandlers.filter(function (ch) {
|
|
21
|
-
return ch !== cb;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}, {
|
|
25
|
-
key: "notifyNewSelection",
|
|
26
|
-
value: function notifyNewSelection(fromPos, toPos) {
|
|
27
|
-
this.changeHandlers.forEach(function (cb) {
|
|
28
|
-
return cb(fromPos, toPos);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}]);
|
|
32
|
-
return ReactNodeViewState;
|
|
33
|
-
}();
|
|
34
|
-
export var stateKey = new PluginKey('reactNodeView');
|
|
35
|
-
export var plugin = new SafePlugin({
|
|
36
|
-
state: {
|
|
37
|
-
init: function init() {
|
|
38
|
-
return new ReactNodeViewState();
|
|
39
|
-
},
|
|
40
|
-
apply: function apply(_tr, pluginState) {
|
|
41
|
-
return pluginState;
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
key: stateKey,
|
|
45
|
-
view: function view(_view) {
|
|
46
|
-
var pluginState = stateKey.getState(_view.state);
|
|
47
|
-
var prevFrom = -1;
|
|
48
|
-
var prevTo = -1;
|
|
49
|
-
return {
|
|
50
|
-
update: function update(view) {
|
|
51
|
-
var _view$state$selection = view.state.selection,
|
|
52
|
-
from = _view$state$selection.from,
|
|
53
|
-
to = _view$state$selection.to;
|
|
54
|
-
if (from !== prevFrom || to !== prevTo) {
|
|
55
|
-
pluginState.notifyNewSelection(from, to);
|
|
56
|
-
prevFrom = from;
|
|
57
|
-
prevTo = to;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
});
|