@atlaskit/editor-core 186.0.0 → 187.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.
- package/CHANGELOG.md +19 -0
- package/dist/cjs/labs-next.js +0 -65
- package/dist/cjs/plugins/expand/commands.js +2 -0
- package/dist/cjs/plugins/expand/index.js +1 -1
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/labs-next.js +0 -4
- package/dist/es2019/plugins/expand/commands.js +2 -0
- package/dist/es2019/plugins/expand/index.js +1 -1
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/labs-next.js +0 -4
- package/dist/esm/plugins/expand/commands.js +2 -0
- package/dist/esm/plugins/expand/index.js +1 -1
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/labs/next/presets/default.d.ts +2 -3
- package/dist/types/labs-next.d.ts +0 -7
- package/dist/types/plugins/expand/commands.d.ts +3 -3
- package/dist/types/plugins/expand/index.d.ts +2 -2
- package/dist/types-ts4.5/labs/next/presets/default.d.ts +2 -3
- package/dist/types-ts4.5/labs-next.d.ts +0 -7
- package/dist/types-ts4.5/plugins/expand/commands.d.ts +3 -3
- package/dist/types-ts4.5/plugins/expand/index.d.ts +2 -2
- package/package.json +5 -5
- package/report.api.md +2 -26
- package/dist/cjs/labs/next/ContentComponents.js +0 -43
- package/dist/cjs/labs/next/Editor.js +0 -76
- package/dist/cjs/labs/next/Toolbar.js +0 -39
- package/dist/cjs/labs/next/full-page.js +0 -127
- package/dist/cjs/labs/next/internal/components/EditorContent.js +0 -25
- package/dist/cjs/labs/next/internal/components/EditorInternal.js +0 -81
- package/dist/cjs/labs/next/internal/context/preset-context.js +0 -15
- package/dist/cjs/labs/next/internal/context/shared-config.js +0 -77
- package/dist/cjs/labs/next/internal/editor-props-type.js +0 -5
- package/dist/cjs/labs/next/internal/hooks/use-analytics/index.js +0 -41
- package/dist/cjs/labs/next/internal/hooks/use-editor/create-dispatch-transaction.js +0 -62
- package/dist/cjs/labs/next/internal/hooks/use-editor/create-editor.js +0 -94
- package/dist/cjs/labs/next/internal/hooks/use-editor/index.js +0 -193
- package/dist/cjs/labs/next/mobile.js +0 -37
- package/dist/cjs/labs/next/presets/cxhtml.js +0 -117
- package/dist/cjs/labs/next/presets/mobile.js +0 -130
- package/dist/cjs/labs/next/presets/utils.js +0 -30
- package/dist/es2019/labs/next/ContentComponents.js +0 -38
- package/dist/es2019/labs/next/Editor.js +0 -46
- package/dist/es2019/labs/next/Toolbar.js +0 -34
- package/dist/es2019/labs/next/full-page.js +0 -192
- package/dist/es2019/labs/next/internal/components/EditorContent.js +0 -17
- package/dist/es2019/labs/next/internal/components/EditorInternal.js +0 -66
- package/dist/es2019/labs/next/internal/context/preset-context.js +0 -5
- package/dist/es2019/labs/next/internal/context/shared-config.js +0 -34
- package/dist/es2019/labs/next/internal/editor-props-type.js +0 -1
- package/dist/es2019/labs/next/internal/hooks/use-analytics/index.js +0 -32
- package/dist/es2019/labs/next/internal/hooks/use-editor/create-dispatch-transaction.js +0 -51
- package/dist/es2019/labs/next/internal/hooks/use-editor/create-editor.js +0 -85
- package/dist/es2019/labs/next/internal/hooks/use-editor/index.js +0 -179
- package/dist/es2019/labs/next/mobile.js +0 -27
- package/dist/es2019/labs/next/presets/cxhtml.js +0 -106
- package/dist/es2019/labs/next/presets/mobile.js +0 -118
- package/dist/es2019/labs/next/presets/utils.js +0 -22
- package/dist/esm/labs/next/ContentComponents.js +0 -36
- package/dist/esm/labs/next/Editor.js +0 -48
- package/dist/esm/labs/next/Toolbar.js +0 -32
- package/dist/esm/labs/next/full-page.js +0 -121
- package/dist/esm/labs/next/internal/components/EditorContent.js +0 -17
- package/dist/esm/labs/next/internal/components/EditorInternal.js +0 -73
- package/dist/esm/labs/next/internal/context/preset-context.js +0 -7
- package/dist/esm/labs/next/internal/context/shared-config.js +0 -68
- package/dist/esm/labs/next/internal/editor-props-type.js +0 -1
- package/dist/esm/labs/next/internal/hooks/use-analytics/index.js +0 -34
- package/dist/esm/labs/next/internal/hooks/use-editor/create-dispatch-transaction.js +0 -55
- package/dist/esm/labs/next/internal/hooks/use-editor/create-editor.js +0 -88
- package/dist/esm/labs/next/internal/hooks/use-editor/index.js +0 -185
- package/dist/esm/labs/next/mobile.js +0 -25
- package/dist/esm/labs/next/presets/cxhtml.js +0 -108
- package/dist/esm/labs/next/presets/mobile.js +0 -120
- package/dist/esm/labs/next/presets/utils.js +0 -23
- package/dist/types/labs/next/ContentComponents.d.ts +0 -8
- package/dist/types/labs/next/Editor.d.ts +0 -27
- package/dist/types/labs/next/Toolbar.d.ts +0 -6
- package/dist/types/labs/next/full-page.d.ts +0 -9
- package/dist/types/labs/next/internal/components/EditorContent.d.ts +0 -7
- package/dist/types/labs/next/internal/components/EditorInternal.d.ts +0 -9
- package/dist/types/labs/next/internal/context/preset-context.d.ts +0 -5
- package/dist/types/labs/next/internal/context/shared-config.d.ts +0 -50
- package/dist/types/labs/next/internal/editor-props-type.d.ts +0 -29
- package/dist/types/labs/next/internal/hooks/use-analytics/index.d.ts +0 -8
- package/dist/types/labs/next/internal/hooks/use-editor/create-dispatch-transaction.d.ts +0 -6
- package/dist/types/labs/next/internal/hooks/use-editor/create-editor.d.ts +0 -19
- package/dist/types/labs/next/internal/hooks/use-editor/index.d.ts +0 -11
- package/dist/types/labs/next/mobile.d.ts +0 -12
- package/dist/types/labs/next/presets/cxhtml.d.ts +0 -338
- package/dist/types/labs/next/presets/mobile.d.ts +0 -343
- package/dist/types/labs/next/presets/utils.d.ts +0 -3
- package/dist/types-ts4.5/labs/next/ContentComponents.d.ts +0 -8
- package/dist/types-ts4.5/labs/next/Editor.d.ts +0 -27
- package/dist/types-ts4.5/labs/next/Toolbar.d.ts +0 -6
- package/dist/types-ts4.5/labs/next/full-page.d.ts +0 -9
- package/dist/types-ts4.5/labs/next/internal/components/EditorContent.d.ts +0 -7
- package/dist/types-ts4.5/labs/next/internal/components/EditorInternal.d.ts +0 -9
- package/dist/types-ts4.5/labs/next/internal/context/preset-context.d.ts +0 -5
- package/dist/types-ts4.5/labs/next/internal/context/shared-config.d.ts +0 -50
- package/dist/types-ts4.5/labs/next/internal/editor-props-type.d.ts +0 -29
- package/dist/types-ts4.5/labs/next/internal/hooks/use-analytics/index.d.ts +0 -8
- package/dist/types-ts4.5/labs/next/internal/hooks/use-editor/create-dispatch-transaction.d.ts +0 -6
- package/dist/types-ts4.5/labs/next/internal/hooks/use-editor/create-editor.d.ts +0 -19
- package/dist/types-ts4.5/labs/next/internal/hooks/use-editor/index.d.ts +0 -14
- package/dist/types-ts4.5/labs/next/mobile.d.ts +0 -12
- package/dist/types-ts4.5/labs/next/presets/cxhtml.d.ts +0 -414
- package/dist/types-ts4.5/labs/next/presets/mobile.d.ts +0 -419
- package/dist/types-ts4.5/labs/next/presets/utils.d.ts +0 -3
- package/tmp/api-report-tmp.d.ts +0 -2278
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
/** @jsx jsx */
|
|
3
|
-
import rafSchedule from 'raf-schd';
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import { css, jsx } from '@emotion/react';
|
|
6
|
-
import { N30 } from '@atlaskit/theme/colors';
|
|
7
|
-
import { withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
8
|
-
import { BaseTheme } from '@atlaskit/editor-common/ui';
|
|
9
|
-
import { akEditorMenuZIndex, akEditorToolbarKeylineHeight } from '@atlaskit/editor-shared-styles';
|
|
10
|
-
import ContentStyles from '../../ui/ContentStyles';
|
|
11
|
-
import { ClickAreaBlock } from '../../ui/Addon';
|
|
12
|
-
import { scrollbarStyles } from '../../ui/styles';
|
|
13
|
-
import { tableFullPageEditorStyles } from '@atlaskit/editor-plugin-table/ui/common-styles';
|
|
14
|
-
import AvatarsWithPluginState from '../../plugins/collab-edit/ui';
|
|
15
|
-
import { Editor, EditorContent, useEditorSharedConfig } from './Editor';
|
|
16
|
-
import { Toolbar } from './Toolbar';
|
|
17
|
-
import { ContentComponents } from './ContentComponents';
|
|
18
|
-
import { useCreateAnalyticsHandler } from './internal/hooks/use-analytics';
|
|
19
|
-
import { ContextPanelWidthProvider } from '@atlaskit/editor-common/ui';
|
|
20
|
-
const fullPageEditorWrapper = css`
|
|
21
|
-
min-width: 340px;
|
|
22
|
-
height: 100%;
|
|
23
|
-
display: flex;
|
|
24
|
-
flex-direction: column;
|
|
25
|
-
box-sizing: border-box;
|
|
26
|
-
`;
|
|
27
|
-
const scrollContainer = css`
|
|
28
|
-
flex-grow: 1;
|
|
29
|
-
overflow-y: scroll;
|
|
30
|
-
position: relative;
|
|
31
|
-
display: flex;
|
|
32
|
-
flex-direction: column;
|
|
33
|
-
scroll-behavior: smooth;
|
|
34
|
-
${scrollbarStyles};
|
|
35
|
-
`;
|
|
36
|
-
const GUTTER_PADDING = 32;
|
|
37
|
-
const GUTTER_STYLE = {
|
|
38
|
-
padding: `0 ${GUTTER_PADDING}px`
|
|
39
|
-
};
|
|
40
|
-
const contentArea = css`
|
|
41
|
-
display: flex;
|
|
42
|
-
flex-direction: row;
|
|
43
|
-
height: 100%;
|
|
44
|
-
box-sizing: border-box;
|
|
45
|
-
`;
|
|
46
|
-
const editorContentArea = theme => css`
|
|
47
|
-
line-height: 24px;
|
|
48
|
-
height: 100%;
|
|
49
|
-
width: 100%;
|
|
50
|
-
max-width: ${theme.layoutMaxWidth + GUTTER_PADDING * 2}px;
|
|
51
|
-
padding-top: 50px;
|
|
52
|
-
margin: 0 auto;
|
|
53
|
-
display: flex;
|
|
54
|
-
flex-direction: column;
|
|
55
|
-
flex-grow: 1;
|
|
56
|
-
padding-bottom: 55px;
|
|
57
|
-
|
|
58
|
-
& .ProseMirror {
|
|
59
|
-
flex-grow: 1;
|
|
60
|
-
box-sizing: border-box;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
&& .ProseMirror {
|
|
64
|
-
& > * {
|
|
65
|
-
clear: both;
|
|
66
|
-
}
|
|
67
|
-
> p,
|
|
68
|
-
> ul,
|
|
69
|
-
> ol,
|
|
70
|
-
> h1,
|
|
71
|
-
> h2,
|
|
72
|
-
> h3,
|
|
73
|
-
> h4,
|
|
74
|
-
> h5,
|
|
75
|
-
> h6 {
|
|
76
|
-
clear: none;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
${tableFullPageEditorStyles};
|
|
80
|
-
`;
|
|
81
|
-
const mainToolbar = css`
|
|
82
|
-
position: relative;
|
|
83
|
-
align-items: center;
|
|
84
|
-
box-shadow: 'none';
|
|
85
|
-
|
|
86
|
-
transition: box-shadow 200ms;
|
|
87
|
-
z-index: ${akEditorMenuZIndex};
|
|
88
|
-
display: flex;
|
|
89
|
-
height: 80px;
|
|
90
|
-
flex-shrink: 0;
|
|
91
|
-
background-color: ${"var(--ds-surface, white)"};
|
|
92
|
-
|
|
93
|
-
& object {
|
|
94
|
-
height: 0 !important;
|
|
95
|
-
}
|
|
96
|
-
`;
|
|
97
|
-
const mainToolbarWithKeyline = css`
|
|
98
|
-
${mainToolbar}
|
|
99
|
-
box-shadow: 0 ${akEditorToolbarKeylineHeight}px 0 0 ${`var(--ds-border, ${N30})`}
|
|
100
|
-
`;
|
|
101
|
-
const mainToolbarCustomComponentsSlot = css`
|
|
102
|
-
display: flex;
|
|
103
|
-
justify-content: flex-end;
|
|
104
|
-
flex-grow: 1;
|
|
105
|
-
`;
|
|
106
|
-
const sidebarArea = css`
|
|
107
|
-
height: 100%;
|
|
108
|
-
box-sizing: border-box;
|
|
109
|
-
`;
|
|
110
|
-
function useKeyline() {
|
|
111
|
-
const [showKeyline, setShowKeyline] = React.useState(false);
|
|
112
|
-
const scrollContainerRef = React.useRef(null);
|
|
113
|
-
React.useEffect(() => {
|
|
114
|
-
let current = scrollContainerRef.current;
|
|
115
|
-
const handleScroll = rafSchedule(() => {
|
|
116
|
-
if (!current) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const {
|
|
120
|
-
scrollTop
|
|
121
|
-
} = current;
|
|
122
|
-
setShowKeyline(scrollTop > akEditorToolbarKeylineHeight);
|
|
123
|
-
});
|
|
124
|
-
if (!current) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
window.addEventListener('resize', handleScroll);
|
|
128
|
-
current.addEventListener('scroll', handleScroll);
|
|
129
|
-
handleScroll();
|
|
130
|
-
return () => {
|
|
131
|
-
if (current) {
|
|
132
|
-
current.removeEventListener('scroll', handleScroll);
|
|
133
|
-
}
|
|
134
|
-
window.removeEventListener('resize', handleScroll);
|
|
135
|
-
};
|
|
136
|
-
}, []);
|
|
137
|
-
return [showKeyline, scrollContainerRef];
|
|
138
|
-
}
|
|
139
|
-
function FullPage(props) {
|
|
140
|
-
const {
|
|
141
|
-
primaryToolbarComponents,
|
|
142
|
-
contentComponents,
|
|
143
|
-
collabEdit,
|
|
144
|
-
createAnalyticsEvent,
|
|
145
|
-
contextPanel
|
|
146
|
-
} = props;
|
|
147
|
-
const handleAnalyticsEvent = useCreateAnalyticsHandler(createAnalyticsEvent);
|
|
148
|
-
const [showKeyline, scrollContainerRef] = useKeyline();
|
|
149
|
-
const config = useEditorSharedConfig();
|
|
150
|
-
const wrapperElementRef = /*#__PURE__*/React.createRef();
|
|
151
|
-
return jsx(ContextPanelWidthProvider, null, jsx(Editor, _extends({}, props, {
|
|
152
|
-
onAnalyticsEvent: handleAnalyticsEvent
|
|
153
|
-
}), jsx(BaseTheme, null, jsx("div", {
|
|
154
|
-
css: fullPageEditorWrapper,
|
|
155
|
-
className: "akEditor",
|
|
156
|
-
ref: wrapperElementRef
|
|
157
|
-
}, jsx("div", {
|
|
158
|
-
"data-testid": "ak-editor-main-toolbar",
|
|
159
|
-
css: showKeyline ? mainToolbarWithKeyline : mainToolbar
|
|
160
|
-
}, jsx(Toolbar, {
|
|
161
|
-
containerElement: scrollContainerRef.current
|
|
162
|
-
}), jsx("div", {
|
|
163
|
-
css: mainToolbarCustomComponentsSlot
|
|
164
|
-
}, !config ? null : jsx(AvatarsWithPluginState, {
|
|
165
|
-
editorView: config.editorView,
|
|
166
|
-
eventDispatcher: config.eventDispatcher,
|
|
167
|
-
inviteToEditHandler: collabEdit === null || collabEdit === void 0 ? void 0 : collabEdit.inviteToEditHandler,
|
|
168
|
-
isInviteToEditButtonSelected: collabEdit === null || collabEdit === void 0 ? void 0 : collabEdit.isInviteToEditButtonSelected,
|
|
169
|
-
featureFlags: {}
|
|
170
|
-
}), primaryToolbarComponents)), jsx("div", {
|
|
171
|
-
css: contentArea
|
|
172
|
-
}, jsx(ContentStyles, {
|
|
173
|
-
ref: scrollContainerRef,
|
|
174
|
-
className: "fabric-editor-popup-scroll-parent",
|
|
175
|
-
css: scrollContainer
|
|
176
|
-
}, jsx(ClickAreaBlock, {
|
|
177
|
-
editorView: config === null || config === void 0 ? void 0 : config.editorView
|
|
178
|
-
}, jsx("div", {
|
|
179
|
-
css: editorContentArea
|
|
180
|
-
}, jsx("div", {
|
|
181
|
-
style: GUTTER_STYLE,
|
|
182
|
-
className: "ak-editor-content-area"
|
|
183
|
-
}, contentComponents, jsx(EditorContent, null), jsx(ContentComponents, {
|
|
184
|
-
wrapperElement: wrapperElementRef.current,
|
|
185
|
-
containerElement: scrollContainerRef.current
|
|
186
|
-
}))))), contextPanel && jsx("div", {
|
|
187
|
-
css: sidebarArea
|
|
188
|
-
}, contextPanel))))));
|
|
189
|
-
}
|
|
190
|
-
FullPage.displayName = 'FullPageEditor';
|
|
191
|
-
const FullPageWithAnalytics = withAnalyticsEvents()(FullPage);
|
|
192
|
-
export { FullPageWithAnalytics as FullPage };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
const EditorContentContext = /*#__PURE__*/React.createContext(() => {});
|
|
3
|
-
const EditorContentProvider = EditorContentContext.Provider;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* ProseMirror View mount point.
|
|
7
|
-
*/
|
|
8
|
-
const EditorContent = /*#__PURE__*/React.memo(() => {
|
|
9
|
-
const handleRef = React.useContext(EditorContentContext);
|
|
10
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
11
|
-
style: {
|
|
12
|
-
height: '100%'
|
|
13
|
-
},
|
|
14
|
-
ref: handleRef
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
export { EditorContentProvider, EditorContent };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { WidthProvider } from '@atlaskit/editor-common/ui';
|
|
4
|
-
import { injectIntl } from 'react-intl-next';
|
|
5
|
-
import { useProviderFactory } from '@atlaskit/editor-common/provider-factory';
|
|
6
|
-
import EditorContext from '../../../../ui/EditorContext';
|
|
7
|
-
import EditorActions from '../../../../actions';
|
|
8
|
-
import { EditorSharedConfigProvider } from '../context/shared-config';
|
|
9
|
-
import { useEditor } from '../hooks/use-editor';
|
|
10
|
-
import { EditorContentProvider } from './EditorContent';
|
|
11
|
-
function BaseEditorInternal({
|
|
12
|
-
onAnalyticsEvent,
|
|
13
|
-
disabled,
|
|
14
|
-
transformer,
|
|
15
|
-
defaultValue,
|
|
16
|
-
plugins,
|
|
17
|
-
portalProviderAPI,
|
|
18
|
-
popupsMountPoint,
|
|
19
|
-
popupsBoundariesElement,
|
|
20
|
-
popupsScrollableElement,
|
|
21
|
-
onChange,
|
|
22
|
-
onDestroy,
|
|
23
|
-
onMount,
|
|
24
|
-
children,
|
|
25
|
-
intl
|
|
26
|
-
}, context) {
|
|
27
|
-
// Need to memoize editor actions otherwise in case when editor is not
|
|
28
|
-
// wrapped with EditorContext every prop change triggers all hooks
|
|
29
|
-
// that depend on editorActions
|
|
30
|
-
const maybeEditorActions = (context || {}).editorActions;
|
|
31
|
-
const editorActions = React.useMemo(() => maybeEditorActions || new EditorActions(), [maybeEditorActions]);
|
|
32
|
-
|
|
33
|
-
// Get the provider factory from context
|
|
34
|
-
const providerFactory = useProviderFactory();
|
|
35
|
-
const getIntl = () => intl;
|
|
36
|
-
const [editorSharedConfig, mountEditor] = useEditor({
|
|
37
|
-
context,
|
|
38
|
-
editorActions,
|
|
39
|
-
onAnalyticsEvent,
|
|
40
|
-
disabled,
|
|
41
|
-
transformer,
|
|
42
|
-
defaultValue,
|
|
43
|
-
plugins,
|
|
44
|
-
portalProviderAPI,
|
|
45
|
-
popupsMountPoint,
|
|
46
|
-
popupsBoundariesElement,
|
|
47
|
-
popupsScrollableElement,
|
|
48
|
-
onChange,
|
|
49
|
-
onDestroy,
|
|
50
|
-
onMount,
|
|
51
|
-
providerFactory,
|
|
52
|
-
featureFlags: {},
|
|
53
|
-
getIntl
|
|
54
|
-
});
|
|
55
|
-
return /*#__PURE__*/React.createElement(WidthProvider, null, /*#__PURE__*/React.createElement(EditorContext, {
|
|
56
|
-
editorActions: editorActions
|
|
57
|
-
}, /*#__PURE__*/React.createElement(EditorSharedConfigProvider, {
|
|
58
|
-
value: editorSharedConfig
|
|
59
|
-
}, /*#__PURE__*/React.createElement(EditorContentProvider, {
|
|
60
|
-
value: mountEditor
|
|
61
|
-
}, children))));
|
|
62
|
-
}
|
|
63
|
-
BaseEditorInternal.contextTypes = {
|
|
64
|
-
editorActions: PropTypes.object
|
|
65
|
-
};
|
|
66
|
-
export const EditorInternal = injectIntl(BaseEditorInternal);
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Provides access to most commonly used configurations and instances of classes,
|
|
7
|
-
* that most editor components rely on.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const EditorSharedConfigContext = /*#__PURE__*/React.createContext(null);
|
|
11
|
-
export class EditorSharedConfigProvider extends React.Component {
|
|
12
|
-
getChildContext() {
|
|
13
|
-
return {
|
|
14
|
-
editorSharedConfig: this.props.value
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
render() {
|
|
18
|
-
return /*#__PURE__*/React.createElement(EditorSharedConfigContext.Provider, {
|
|
19
|
-
value: this.props.value
|
|
20
|
-
}, this.props.children);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
_defineProperty(EditorSharedConfigProvider, "childContextTypes", {
|
|
24
|
-
editorSharedConfig: PropTypes.object
|
|
25
|
-
});
|
|
26
|
-
export class EditorSharedConfigConsumer extends React.Component {
|
|
27
|
-
render() {
|
|
28
|
-
return /*#__PURE__*/React.createElement(EditorSharedConfigContext.Consumer, null, value => this.props.children(this.context.editorSharedConfig || value));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
_defineProperty(EditorSharedConfigConsumer, "contextTypes", {
|
|
32
|
-
editorSharedConfig: PropTypes.object
|
|
33
|
-
});
|
|
34
|
-
export const useEditorSharedConfig = () => React.useContext(EditorSharedConfigContext);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { fireAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
3
|
-
import { analyticsEventKey } from '@atlaskit/editor-common/utils';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Subscribes to analytics events fired from editor components
|
|
7
|
-
* and passes them through to `fireAnalyticsEvent`.
|
|
8
|
-
*/
|
|
9
|
-
export function useAnalyticsHandler(editorSharedConfig) {
|
|
10
|
-
// handleAnalyticsEvent – must always be the same so we can unsubscribe from events properly.
|
|
11
|
-
const handleAnalyticsEvent = React.useCallback(payload => {
|
|
12
|
-
const handleAnalyticsEvent = editorSharedConfig && editorSharedConfig.dispatchAnalyticsEvent;
|
|
13
|
-
if (!handleAnalyticsEvent) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
handleAnalyticsEvent(payload);
|
|
17
|
-
}, [editorSharedConfig]);
|
|
18
|
-
if (editorSharedConfig) {
|
|
19
|
-
editorSharedConfig.eventDispatcher.on(analyticsEventKey, handleAnalyticsEvent);
|
|
20
|
-
}
|
|
21
|
-
React.useEffect(() => () => {
|
|
22
|
-
if (!editorSharedConfig || !editorSharedConfig.eventDispatcher) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
editorSharedConfig.eventDispatcher.off(analyticsEventKey, handleAnalyticsEvent);
|
|
26
|
-
}, [editorSharedConfig, handleAnalyticsEvent]);
|
|
27
|
-
}
|
|
28
|
-
export function useCreateAnalyticsHandler(createAnalyticsEvent) {
|
|
29
|
-
// AFP-2511 TODO: Fix automatic suppressions below
|
|
30
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
|
-
return React.useCallback(fireAnalyticsEvent(createAnalyticsEvent), [createAnalyticsEvent]);
|
|
32
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Node } from 'prosemirror-model';
|
|
2
|
-
import { analyticsEventKey } from '@atlaskit/editor-common/utils';
|
|
3
|
-
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, getAnalyticsEventsFromTransaction } from '@atlaskit/editor-common/analytics';
|
|
4
|
-
import { findChangedNodesFromTransaction, validateNodes, validNode } from '../../../../../utils/nodes';
|
|
5
|
-
import { compose, toJSON } from '../../../../../utils';
|
|
6
|
-
import { getDocStructure } from '../../../../../utils/document-logger';
|
|
7
|
-
// Helper to assure correct payload when dispatch analytics
|
|
8
|
-
function dispatchAnalytics(dispatch, payload) {
|
|
9
|
-
dispatch(analyticsEventKey, payload);
|
|
10
|
-
}
|
|
11
|
-
export function createDispatchTransaction(editorSharedConfig) {
|
|
12
|
-
return function dispatchTransaction(transaction) {
|
|
13
|
-
const {
|
|
14
|
-
editorView,
|
|
15
|
-
onChange,
|
|
16
|
-
transformer,
|
|
17
|
-
dispatch
|
|
18
|
-
} = editorSharedConfig;
|
|
19
|
-
if (!editorView) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const nodes = findChangedNodesFromTransaction(transaction);
|
|
23
|
-
if (validateNodes(nodes)) {
|
|
24
|
-
// go ahead and update the state now we know the transaction is good
|
|
25
|
-
const editorState = editorView.state.apply(transaction);
|
|
26
|
-
editorView.updateState(editorState);
|
|
27
|
-
if (onChange && transaction.docChanged) {
|
|
28
|
-
onChange(getEditorValue(editorView, transformer), {
|
|
29
|
-
source: 'local'
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
33
|
-
// If invalid document, send analytics event with the structure of the nodes
|
|
34
|
-
if (dispatch) {
|
|
35
|
-
const invalidNodes = nodes.filter(node => !validNode(node)).map(node => getDocStructure(node));
|
|
36
|
-
dispatchAnalytics(dispatch, {
|
|
37
|
-
action: ACTION.DISPATCHED_INVALID_TRANSACTION,
|
|
38
|
-
actionSubject: ACTION_SUBJECT.EDITOR,
|
|
39
|
-
eventType: EVENT_TYPE.OPERATIONAL,
|
|
40
|
-
attributes: {
|
|
41
|
-
analyticsEventPayloads: getAnalyticsEventsFromTransaction(transaction),
|
|
42
|
-
invalidNodes
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export function getEditorValue(editorView, transformer) {
|
|
50
|
-
return compose(doc => transformer && transformer.encode ? transformer.encode(Node.fromJSON(editorView.state.schema, doc)) : doc, toJSON)(editorView.state.doc);
|
|
51
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { EditorView } from 'prosemirror-view';
|
|
2
|
-
import { EditorState } from 'prosemirror-state';
|
|
3
|
-
import { EventDispatcher, createDispatch } from '../../../../../event-dispatcher';
|
|
4
|
-
import { processPluginsList, createPMPlugins } from '../../../../../create-editor/create-editor';
|
|
5
|
-
import { processRawValue } from '@atlaskit/editor-common/utils';
|
|
6
|
-
import { createSchema } from '../../../../../create-editor/create-schema';
|
|
7
|
-
export function createEditor({
|
|
8
|
-
context,
|
|
9
|
-
onAnalyticsEvent,
|
|
10
|
-
transformer,
|
|
11
|
-
providerFactory,
|
|
12
|
-
plugins,
|
|
13
|
-
portalProviderAPI,
|
|
14
|
-
defaultValue,
|
|
15
|
-
ref,
|
|
16
|
-
popupsMountPoint,
|
|
17
|
-
popupsBoundariesElement,
|
|
18
|
-
popupsScrollableElement,
|
|
19
|
-
editorActions,
|
|
20
|
-
disabled,
|
|
21
|
-
onChange,
|
|
22
|
-
onDestroy,
|
|
23
|
-
onMount,
|
|
24
|
-
featureFlags,
|
|
25
|
-
getIntl
|
|
26
|
-
}) {
|
|
27
|
-
if (!ref) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
const eventDispatcher = new EventDispatcher();
|
|
31
|
-
const dispatch = createDispatch(eventDispatcher);
|
|
32
|
-
const editorConfig = processPluginsList(plugins || []);
|
|
33
|
-
const schema = createSchema(editorConfig);
|
|
34
|
-
const transformerInstance = transformer && transformer(schema);
|
|
35
|
-
const pmPlugins = createPMPlugins({
|
|
36
|
-
editorConfig,
|
|
37
|
-
schema,
|
|
38
|
-
dispatch,
|
|
39
|
-
eventDispatcher,
|
|
40
|
-
portalProviderAPI: portalProviderAPI,
|
|
41
|
-
providerFactory,
|
|
42
|
-
// Required to workaround issues with multiple react trees.
|
|
43
|
-
// Though it's kinda leaking react to outside world.
|
|
44
|
-
reactContext: () => context,
|
|
45
|
-
// TODO: ED-8133 Need to make types more generic otherwise it's not extensible.
|
|
46
|
-
dispatchAnalyticsEvent: onAnalyticsEvent,
|
|
47
|
-
performanceTracking: {},
|
|
48
|
-
featureFlags,
|
|
49
|
-
getIntl
|
|
50
|
-
});
|
|
51
|
-
const state = EditorState.create({
|
|
52
|
-
schema,
|
|
53
|
-
plugins: pmPlugins,
|
|
54
|
-
doc: transformerInstance ? transformerInstance.parse(defaultValue) : processRawValue(schema, defaultValue)
|
|
55
|
-
});
|
|
56
|
-
const editorView = new EditorView({
|
|
57
|
-
mount: ref
|
|
58
|
-
}, {
|
|
59
|
-
state,
|
|
60
|
-
attributes: {
|
|
61
|
-
'data-gramm': 'false'
|
|
62
|
-
},
|
|
63
|
-
// Ignore all transactions by default
|
|
64
|
-
dispatchTransaction: () => {},
|
|
65
|
-
// Disables the contentEditable attribute of the editor if the editor is disabled
|
|
66
|
-
editable: _state => !!disabled
|
|
67
|
-
});
|
|
68
|
-
return {
|
|
69
|
-
editorView,
|
|
70
|
-
transformer: transformerInstance,
|
|
71
|
-
dispatchAnalyticsEvent: onAnalyticsEvent,
|
|
72
|
-
eventDispatcher,
|
|
73
|
-
dispatch,
|
|
74
|
-
primaryToolbarComponents: editorConfig.primaryToolbarComponents,
|
|
75
|
-
contentComponents: editorConfig.contentComponents,
|
|
76
|
-
popupsMountPoint,
|
|
77
|
-
popupsBoundariesElement,
|
|
78
|
-
popupsScrollableElement,
|
|
79
|
-
providerFactory,
|
|
80
|
-
editorActions,
|
|
81
|
-
onChange,
|
|
82
|
-
onDestroy,
|
|
83
|
-
onMount
|
|
84
|
-
};
|
|
85
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { measureRender, getResponseEndTime, startMeasure, stopMeasure } from '@atlaskit/editor-common/utils';
|
|
3
|
-
import measurements from '../../../../../utils/performance/measure-enum';
|
|
4
|
-
import { getNodesCount } from '../../../../../utils';
|
|
5
|
-
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, PLATFORMS } from '../../../../../plugins/analytics';
|
|
6
|
-
import { getEnabledFeatureFlagKeys } from '@atlaskit/editor-common/normalize-feature-flags';
|
|
7
|
-
import { useAnalyticsHandler } from '../use-analytics';
|
|
8
|
-
import { createDispatchTransaction } from './create-dispatch-transaction';
|
|
9
|
-
import { createEditor } from './create-editor';
|
|
10
|
-
import { analyticsEventKey } from '../../../../../plugins/analytics/consts';
|
|
11
|
-
export function useEditor(config) {
|
|
12
|
-
startMeasure(measurements.EDITOR_MOUNTED);
|
|
13
|
-
const [editorSharedConfig, mountEditor] = useCreateEditor(config);
|
|
14
|
-
useApplyEditorViewProps(editorSharedConfig, config.disabled);
|
|
15
|
-
useHandleEditorLifecycle(editorSharedConfig, config.featureFlags);
|
|
16
|
-
useAnalyticsHandler(editorSharedConfig);
|
|
17
|
-
return [editorSharedConfig, mountEditor];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
* Sub hooks ¯\_(ツ)_/¯
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Main hook that creates an instance of EditorView, EditorSharedConfig, etc...
|
|
28
|
-
*/
|
|
29
|
-
function useCreateEditor(config) {
|
|
30
|
-
const [editorSharedConfig, setEditorSharedConfig] = React.useState(null);
|
|
31
|
-
return [editorSharedConfig,
|
|
32
|
-
// This callback is being used as `ref={callback}` on EditorContentProvider,
|
|
33
|
-
// When called with `ref` mounts editor and creates editorSharedConfig.
|
|
34
|
-
React.useCallback(ref => {
|
|
35
|
-
// If editorSharedConfig already exists it means that editorView is mounted
|
|
36
|
-
// and we just need to ignore this function altogether.
|
|
37
|
-
if (!ref) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
setEditorSharedConfig(editorSharedConfig => {
|
|
41
|
-
if (!editorSharedConfig) {
|
|
42
|
-
measureRender(measurements.PROSEMIRROR_RENDERED, ({
|
|
43
|
-
duration,
|
|
44
|
-
startTime,
|
|
45
|
-
distortedDuration
|
|
46
|
-
}) => {
|
|
47
|
-
if (sharedConfig && sharedConfig.dispatch) {
|
|
48
|
-
sharedConfig.dispatch(analyticsEventKey, {
|
|
49
|
-
payload: {
|
|
50
|
-
action: ACTION.PROSEMIRROR_RENDERED,
|
|
51
|
-
actionSubject: ACTION_SUBJECT.EDITOR,
|
|
52
|
-
attributes: {
|
|
53
|
-
duration,
|
|
54
|
-
distortedDuration,
|
|
55
|
-
startTime,
|
|
56
|
-
nodes: getNodesCount(sharedConfig.editorView.state.doc),
|
|
57
|
-
ttfb: getResponseEndTime()
|
|
58
|
-
},
|
|
59
|
-
eventType: EVENT_TYPE.OPERATIONAL
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
const sharedConfig = editorSharedConfig || createEditor({
|
|
66
|
-
...config,
|
|
67
|
-
ref
|
|
68
|
-
});
|
|
69
|
-
stopMeasure(measurements.EDITOR_MOUNTED, (duration, startTime) => {
|
|
70
|
-
if (!sharedConfig) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Fire editor mounted event
|
|
75
|
-
sharedConfig.dispatch(analyticsEventKey, {
|
|
76
|
-
payload: {
|
|
77
|
-
action: ACTION.EDITOR_MOUNTED,
|
|
78
|
-
actionSubject: ACTION_SUBJECT.EDITOR,
|
|
79
|
-
attributes: {
|
|
80
|
-
duration,
|
|
81
|
-
startTime
|
|
82
|
-
},
|
|
83
|
-
eventType: EVENT_TYPE.OPERATIONAL
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
return sharedConfig;
|
|
88
|
-
});
|
|
89
|
-
}, [config])];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Applies updated EditorView properties e.g. set dispatchTransaction or 'disabled' state changes
|
|
94
|
-
*/
|
|
95
|
-
function useApplyEditorViewProps(editorSharedConfig, disabled) {
|
|
96
|
-
React.useEffect(() => {
|
|
97
|
-
if (editorSharedConfig) {
|
|
98
|
-
editorSharedConfig.editorView.setProps({
|
|
99
|
-
dispatchTransaction: createDispatchTransaction(editorSharedConfig)
|
|
100
|
-
});
|
|
101
|
-
editorSharedConfig.editorView.setProps({
|
|
102
|
-
editable: _state => !disabled
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}, [editorSharedConfig, disabled]);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Handles editor component unmount
|
|
110
|
-
*/
|
|
111
|
-
export function useHandleEditorLifecycle(editorSharedConfig, featureFlags) {
|
|
112
|
-
React.useEffect(() => {
|
|
113
|
-
//#region Did mount
|
|
114
|
-
if (editorSharedConfig) {
|
|
115
|
-
const {
|
|
116
|
-
onMount,
|
|
117
|
-
editorActions,
|
|
118
|
-
editorView,
|
|
119
|
-
eventDispatcher,
|
|
120
|
-
dispatch
|
|
121
|
-
} = editorSharedConfig;
|
|
122
|
-
editorActions._privateRegisterEditor(editorView, eventDispatcher);
|
|
123
|
-
if (onMount) {
|
|
124
|
-
onMount(editorActions);
|
|
125
|
-
}
|
|
126
|
-
const featureFlagsEnabled = featureFlags ? getEnabledFeatureFlagKeys(featureFlags) : [];
|
|
127
|
-
|
|
128
|
-
// Fire editor started event
|
|
129
|
-
dispatch(analyticsEventKey, {
|
|
130
|
-
payload: {
|
|
131
|
-
action: ACTION.STARTED,
|
|
132
|
-
actionSubject: ACTION_SUBJECT.EDITOR,
|
|
133
|
-
attributes: {
|
|
134
|
-
platform: PLATFORMS.WEB,
|
|
135
|
-
featureFlags: featureFlagsEnabled
|
|
136
|
-
},
|
|
137
|
-
eventType: EVENT_TYPE.UI
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
//#endregion
|
|
142
|
-
|
|
143
|
-
return () => {
|
|
144
|
-
if (!editorSharedConfig) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
const {
|
|
148
|
-
eventDispatcher,
|
|
149
|
-
editorView,
|
|
150
|
-
onDestroy,
|
|
151
|
-
editorActions
|
|
152
|
-
} = editorSharedConfig;
|
|
153
|
-
if (eventDispatcher) {
|
|
154
|
-
eventDispatcher.destroy();
|
|
155
|
-
}
|
|
156
|
-
if (onDestroy) {
|
|
157
|
-
onDestroy();
|
|
158
|
-
}
|
|
159
|
-
editorActions._privateUnregisterEditor();
|
|
160
|
-
if (editorView) {
|
|
161
|
-
// Prevent any transactions from coming through when unmounting
|
|
162
|
-
editorView.setProps({
|
|
163
|
-
dispatchTransaction: _tr => {}
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
// Destroy plugin states and editor state
|
|
167
|
-
// when the editor is being unmounted
|
|
168
|
-
const editorState = editorView.state;
|
|
169
|
-
editorState.plugins.forEach(plugin => {
|
|
170
|
-
const state = plugin.getState(editorState);
|
|
171
|
-
if (state && state.destroy) {
|
|
172
|
-
state.destroy();
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
editorView.destroy();
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
}, [editorSharedConfig, featureFlags]);
|
|
179
|
-
}
|