@atlaskit/editor-core 188.8.0 → 188.9.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 +13 -0
- package/dist/cjs/composable-editor/editor-internal.js +2 -2
- package/dist/cjs/create-editor/ReactEditorView.js +796 -8
- package/dist/cjs/labs/next/presets/universal.js +7 -4
- package/dist/cjs/plugins/index.js +0 -21
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/composable-editor/editor-internal.js +1 -1
- package/dist/es2019/create-editor/ReactEditorView.js +753 -2
- package/dist/es2019/labs/next/presets/universal.js +4 -1
- package/dist/es2019/plugins/index.js +0 -3
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/composable-editor/editor-internal.js +1 -1
- package/dist/esm/create-editor/ReactEditorView.js +797 -8
- package/dist/esm/labs/next/presets/universal.js +4 -1
- package/dist/esm/plugins/index.js +0 -3
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/create-editor/ReactEditorView.d.ts +119 -5
- package/dist/types/plugins/index.d.ts +0 -3
- package/dist/types/plugins/insert-block/types.d.ts +1 -1
- package/dist/types/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.d.ts +1 -1
- package/dist/types-ts4.5/create-editor/ReactEditorView.d.ts +119 -5
- package/dist/types-ts4.5/plugins/index.d.ts +0 -3
- package/dist/types-ts4.5/plugins/insert-block/types.d.ts +1 -1
- package/dist/types-ts4.5/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.d.ts +1 -1
- package/package.json +5 -3
- package/dist/cjs/create-editor/ReactEditorViewInternal.js +0 -812
- package/dist/cjs/create-editor/ReactEditorViewNext.js +0 -15
- package/dist/cjs/plugins/save-on-enter/index.js +0 -70
- package/dist/cjs/plugins/scroll-into-view/index.js +0 -55
- package/dist/cjs/plugins/status/actions.js +0 -158
- package/dist/cjs/plugins/status/analytics.js +0 -31
- package/dist/cjs/plugins/status/index.js +0 -143
- package/dist/cjs/plugins/status/keymap.js +0 -22
- package/dist/cjs/plugins/status/nodeviews/status.js +0 -58
- package/dist/cjs/plugins/status/plugin-key.js +0 -9
- package/dist/cjs/plugins/status/plugin.js +0 -133
- package/dist/cjs/plugins/status/types.js +0 -5
- package/dist/cjs/plugins/status/ui/statusPicker.js +0 -314
- package/dist/cjs/plugins/status/utils.js +0 -22
- package/dist/es2019/create-editor/ReactEditorViewInternal.js +0 -753
- package/dist/es2019/create-editor/ReactEditorViewNext.js +0 -7
- package/dist/es2019/plugins/save-on-enter/index.js +0 -63
- package/dist/es2019/plugins/scroll-into-view/index.js +0 -44
- package/dist/es2019/plugins/status/actions.js +0 -144
- package/dist/es2019/plugins/status/analytics.js +0 -18
- package/dist/es2019/plugins/status/index.js +0 -135
- package/dist/es2019/plugins/status/keymap.js +0 -13
- package/dist/es2019/plugins/status/nodeviews/status.js +0 -60
- package/dist/es2019/plugins/status/plugin-key.js +0 -3
- package/dist/es2019/plugins/status/plugin.js +0 -113
- package/dist/es2019/plugins/status/types.js +0 -1
- package/dist/es2019/plugins/status/ui/statusPicker.js +0 -293
- package/dist/es2019/plugins/status/utils.js +0 -12
- package/dist/esm/create-editor/ReactEditorViewInternal.js +0 -806
- package/dist/esm/create-editor/ReactEditorViewNext.js +0 -7
- package/dist/esm/plugins/save-on-enter/index.js +0 -63
- package/dist/esm/plugins/scroll-into-view/index.js +0 -50
- package/dist/esm/plugins/status/actions.js +0 -151
- package/dist/esm/plugins/status/analytics.js +0 -24
- package/dist/esm/plugins/status/index.js +0 -136
- package/dist/esm/plugins/status/keymap.js +0 -15
- package/dist/esm/plugins/status/nodeviews/status.js +0 -51
- package/dist/esm/plugins/status/plugin-key.js +0 -3
- package/dist/esm/plugins/status/plugin.js +0 -115
- package/dist/esm/plugins/status/types.js +0 -1
- package/dist/esm/plugins/status/ui/statusPicker.js +0 -308
- package/dist/esm/plugins/status/utils.js +0 -16
- package/dist/types/create-editor/ReactEditorViewInternal.d.ts +0 -119
- package/dist/types/create-editor/ReactEditorViewNext.d.ts +0 -8
- package/dist/types/plugins/save-on-enter/index.d.ts +0 -10
- package/dist/types/plugins/scroll-into-view/index.d.ts +0 -14
- package/dist/types/plugins/status/actions.d.ts +0 -16
- package/dist/types/plugins/status/analytics.d.ts +0 -4
- package/dist/types/plugins/status/index.d.ts +0 -15
- package/dist/types/plugins/status/keymap.d.ts +0 -3
- package/dist/types/plugins/status/nodeviews/status.d.ts +0 -25
- package/dist/types/plugins/status/plugin-key.d.ts +0 -4
- package/dist/types/plugins/status/plugin.d.ts +0 -7
- package/dist/types/plugins/status/types.d.ts +0 -18
- package/dist/types/plugins/status/ui/statusPicker.d.ts +0 -63
- package/dist/types/plugins/status/utils.d.ts +0 -5
- package/dist/types-ts4.5/create-editor/ReactEditorViewInternal.d.ts +0 -119
- package/dist/types-ts4.5/create-editor/ReactEditorViewNext.d.ts +0 -8
- package/dist/types-ts4.5/plugins/save-on-enter/index.d.ts +0 -10
- package/dist/types-ts4.5/plugins/scroll-into-view/index.d.ts +0 -14
- package/dist/types-ts4.5/plugins/status/actions.d.ts +0 -16
- package/dist/types-ts4.5/plugins/status/analytics.d.ts +0 -4
- package/dist/types-ts4.5/plugins/status/index.d.ts +0 -17
- package/dist/types-ts4.5/plugins/status/keymap.d.ts +0 -3
- package/dist/types-ts4.5/plugins/status/nodeviews/status.d.ts +0 -25
- package/dist/types-ts4.5/plugins/status/plugin-key.d.ts +0 -4
- package/dist/types-ts4.5/plugins/status/plugin.d.ts +0 -7
- package/dist/types-ts4.5/plugins/status/types.d.ts +0 -18
- package/dist/types-ts4.5/plugins/status/ui/statusPicker.d.ts +0 -63
- package/dist/types-ts4.5/plugins/status/utils.d.ts +0 -5
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ReactEditorView } from './ReactEditorViewInternal';
|
|
3
|
-
import { injectIntl } from 'react-intl-next';
|
|
4
|
-
export function ReactEditorViewEditor(props) {
|
|
5
|
-
return /*#__PURE__*/React.createElement(ReactEditorView, props);
|
|
6
|
-
}
|
|
7
|
-
export default injectIntl(ReactEditorViewEditor);
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
2
|
-
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '../../plugins/analytics';
|
|
3
|
-
import { analyticsEventKey } from '../analytics/consts';
|
|
4
|
-
export function createPlugin(eventDispatch, onSave) {
|
|
5
|
-
if (!onSave) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
return keymap({
|
|
9
|
-
Enter(state, _dispatch, editorView) {
|
|
10
|
-
if (editorView && canSaveOnEnter(editorView)) {
|
|
11
|
-
eventDispatch(analyticsEventKey, analyticsPayload(state));
|
|
12
|
-
onSave(editorView);
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
function canSaveOnEnter(editorView) {
|
|
20
|
-
const {
|
|
21
|
-
$cursor
|
|
22
|
-
} = editorView.state.selection;
|
|
23
|
-
const {
|
|
24
|
-
decisionItem,
|
|
25
|
-
paragraph,
|
|
26
|
-
taskItem
|
|
27
|
-
} = editorView.state.schema.nodes;
|
|
28
|
-
return !$cursor || $cursor.parent.type === paragraph && $cursor.depth === 1 || $cursor.parent.type === decisionItem && !isEmptyAtCursor($cursor) || $cursor.parent.type === taskItem && !isEmptyAtCursor($cursor);
|
|
29
|
-
}
|
|
30
|
-
function isEmptyAtCursor($cursor) {
|
|
31
|
-
const {
|
|
32
|
-
content
|
|
33
|
-
} = $cursor.parent;
|
|
34
|
-
return !(content && content.size);
|
|
35
|
-
}
|
|
36
|
-
const analyticsPayload = state => ({
|
|
37
|
-
payload: {
|
|
38
|
-
action: ACTION.STOPPED,
|
|
39
|
-
actionSubject: ACTION_SUBJECT.EDITOR,
|
|
40
|
-
actionSubjectId: ACTION_SUBJECT_ID.SAVE,
|
|
41
|
-
attributes: {
|
|
42
|
-
inputMethod: INPUT_METHOD.SHORTCUT,
|
|
43
|
-
documentSize: state.doc.nodeSize
|
|
44
|
-
// TODO add individual node counts - tables, headings, lists, mediaSingles, mediaGroups, mediaCards, panels, extensions, decisions, action, codeBlocks
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
eventType: EVENT_TYPE.UI
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
const saveOnEnterPlugin = ({
|
|
51
|
-
config: onSave
|
|
52
|
-
}) => ({
|
|
53
|
-
name: 'saveOnEnter',
|
|
54
|
-
pmPlugins() {
|
|
55
|
-
return [{
|
|
56
|
-
name: 'saveOnEnter',
|
|
57
|
-
plugin: ({
|
|
58
|
-
dispatch
|
|
59
|
-
}) => createPlugin(dispatch, onSave)
|
|
60
|
-
}];
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
export default saveOnEnterPlugin;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { TEXT_INPUT_RULE_TRANSACTION_KEY } from '@atlaskit/prosemirror-input-rules';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Plugin to scroll the user's selection into view whenever the user updates
|
|
7
|
-
* the document eg. inserting, deleting, formatting
|
|
8
|
-
*
|
|
9
|
-
* Behaviour is on by default, can be explicitly opted out of for a transaction by
|
|
10
|
-
* setting scrollIntoView=false meta
|
|
11
|
-
* We ignore collab transactions, appended transactions, transactions without steps,
|
|
12
|
-
* transactions with addToHistory=false meta and typeahead trigger transactions
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export const scrollIntoViewPluginKey = new PluginKey('scrollIntoViewPlugin');
|
|
16
|
-
const createPlugin = () => new SafePlugin({
|
|
17
|
-
key: scrollIntoViewPluginKey,
|
|
18
|
-
appendTransaction: (transactions, oldState, newState) => {
|
|
19
|
-
if (!transactions.length) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const tr = transactions[0];
|
|
23
|
-
if ((tr.docChanged || tr.storedMarksSet) && !tr.scrolledIntoView && tr.getMeta('scrollIntoView') !== false &&
|
|
24
|
-
// ignore anything we would not want to undo
|
|
25
|
-
// this covers things like autofixing layouts, hovering table rows/cols
|
|
26
|
-
tr.getMeta('addToHistory') !== false &&
|
|
27
|
-
// ignore collab changes from another user
|
|
28
|
-
!tr.getMeta('isRemote') &&
|
|
29
|
-
// ignore any transaction coming from the input text rule plugin
|
|
30
|
-
!tr.getMeta(TEXT_INPUT_RULE_TRANSACTION_KEY)) {
|
|
31
|
-
return newState.tr.scrollIntoView();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
const scrollIntoViewPlugin = () => ({
|
|
36
|
-
name: 'scrollIntoView',
|
|
37
|
-
pmPlugins() {
|
|
38
|
-
return [{
|
|
39
|
-
name: 'scrollIntoView',
|
|
40
|
-
plugin: () => createPlugin()
|
|
41
|
-
}];
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
export default scrollIntoViewPlugin;
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { uuid } from '@atlaskit/adf-schema';
|
|
4
|
-
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
5
|
-
import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
|
|
6
|
-
import { pluginKey } from './plugin-key';
|
|
7
|
-
import { canInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
8
|
-
export const DEFAULT_STATUS = {
|
|
9
|
-
text: '',
|
|
10
|
-
color: 'neutral'
|
|
11
|
-
};
|
|
12
|
-
export const createStatus = (showStatusPickerAtOffset = 0) => (insert, state) => {
|
|
13
|
-
const statusNode = state.schema.nodes.status.createChecked({
|
|
14
|
-
...DEFAULT_STATUS,
|
|
15
|
-
localId: uuid.generate()
|
|
16
|
-
});
|
|
17
|
-
const space = state.schema.text(' ');
|
|
18
|
-
const tr = insert(Fragment.from([statusNode, space]), {
|
|
19
|
-
selectInlineNode: true
|
|
20
|
-
});
|
|
21
|
-
const showStatusPickerAt = tr.selection.from + showStatusPickerAtOffset;
|
|
22
|
-
return tr.setSelection(NodeSelection.create(tr.doc, showStatusPickerAt)).setMeta(pluginKey, {
|
|
23
|
-
showStatusPickerAt,
|
|
24
|
-
isNew: true
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
export const updateStatus = status => (state, dispatch) => {
|
|
28
|
-
const {
|
|
29
|
-
schema
|
|
30
|
-
} = state;
|
|
31
|
-
const selectedStatus = status ? Object.assign(status, {
|
|
32
|
-
text: status.text.trim(),
|
|
33
|
-
localId: status.localId || uuid.generate()
|
|
34
|
-
}) : status;
|
|
35
|
-
const statusProps = {
|
|
36
|
-
...DEFAULT_STATUS,
|
|
37
|
-
...selectedStatus
|
|
38
|
-
};
|
|
39
|
-
let tr = state.tr;
|
|
40
|
-
const {
|
|
41
|
-
showStatusPickerAt
|
|
42
|
-
} = pluginKey.getState(state) || {};
|
|
43
|
-
if (!showStatusPickerAt) {
|
|
44
|
-
// Same behaviour as quick insert (used in createStatus)
|
|
45
|
-
const statusNode = schema.nodes.status.createChecked(statusProps);
|
|
46
|
-
const fragment = Fragment.fromArray([statusNode, state.schema.text(' ')]);
|
|
47
|
-
const insertable = canInsert(tr.selection.$from, fragment);
|
|
48
|
-
if (!insertable) {
|
|
49
|
-
const parentSelection = NodeSelection.create(tr.doc, tr.selection.from - tr.selection.$anchor.parentOffset - 1);
|
|
50
|
-
tr.insert(parentSelection.to, fragment).setSelection(NodeSelection.create(tr.doc, parentSelection.to + 1));
|
|
51
|
-
} else {
|
|
52
|
-
tr.insert(tr.selection.from, fragment).setSelection(NodeSelection.create(tr.doc, tr.selection.from - fragment.size));
|
|
53
|
-
}
|
|
54
|
-
tr.setMeta(pluginKey, {
|
|
55
|
-
showStatusPickerAt: tr.selection.from,
|
|
56
|
-
isNew: true
|
|
57
|
-
}).scrollIntoView();
|
|
58
|
-
if (dispatch) {
|
|
59
|
-
dispatch(tr);
|
|
60
|
-
}
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
if (state.doc.nodeAt(showStatusPickerAt)) {
|
|
64
|
-
tr.setNodeMarkup(showStatusPickerAt, schema.nodes.status, statusProps).setSelection(NodeSelection.create(tr.doc, showStatusPickerAt)).setMeta(pluginKey, {
|
|
65
|
-
showStatusPickerAt
|
|
66
|
-
}).scrollIntoView();
|
|
67
|
-
if (dispatch) {
|
|
68
|
-
dispatch(tr);
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
return false;
|
|
73
|
-
};
|
|
74
|
-
export const updateStatusWithAnalytics = editorAnalyticsAPI => (inputMethod, status) => withAnalytics(editorAnalyticsAPI, {
|
|
75
|
-
action: ACTION.INSERTED,
|
|
76
|
-
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
77
|
-
actionSubjectId: ACTION_SUBJECT_ID.STATUS,
|
|
78
|
-
attributes: {
|
|
79
|
-
inputMethod
|
|
80
|
-
},
|
|
81
|
-
eventType: EVENT_TYPE.TRACK
|
|
82
|
-
})(updateStatus(status));
|
|
83
|
-
export const setStatusPickerAt = showStatusPickerAt => (state, dispatch) => {
|
|
84
|
-
dispatch(state.tr.setMeta(pluginKey, {
|
|
85
|
-
showStatusPickerAt,
|
|
86
|
-
isNew: false
|
|
87
|
-
}));
|
|
88
|
-
return true;
|
|
89
|
-
};
|
|
90
|
-
export const removeStatus = showStatusPickerAt => (state, dispatch) => {
|
|
91
|
-
const tr = state.tr;
|
|
92
|
-
tr.replace(showStatusPickerAt, showStatusPickerAt + 1);
|
|
93
|
-
if (dispatch) {
|
|
94
|
-
dispatch(tr);
|
|
95
|
-
}
|
|
96
|
-
return true;
|
|
97
|
-
};
|
|
98
|
-
const handleClosingByArrows = (closingMethod, state, showStatusPickerAt, tr) => {
|
|
99
|
-
if (closingMethod === 'arrowLeft') {
|
|
100
|
-
// put cursor right before status Lozenge
|
|
101
|
-
tr = tr.setSelection(Selection.near(state.tr.doc.resolve(showStatusPickerAt), -1));
|
|
102
|
-
} else if (closingMethod === 'arrowRight') {
|
|
103
|
-
// put cursor right after status Lozenge
|
|
104
|
-
tr = tr.setSelection(Selection.near(state.tr.doc.resolve(showStatusPickerAt + 1)));
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
export const commitStatusPicker = closingPayload => editorView => {
|
|
108
|
-
const {
|
|
109
|
-
state,
|
|
110
|
-
dispatch
|
|
111
|
-
} = editorView;
|
|
112
|
-
const {
|
|
113
|
-
showStatusPickerAt
|
|
114
|
-
} = pluginKey.getState(state) || {};
|
|
115
|
-
const {
|
|
116
|
-
closingMethod
|
|
117
|
-
} = closingPayload || {};
|
|
118
|
-
if (!showStatusPickerAt) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
const statusNode = state.tr.doc.nodeAt(showStatusPickerAt);
|
|
122
|
-
if (!statusNode) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
let tr = state.tr;
|
|
126
|
-
tr = tr.setMeta(pluginKey, {
|
|
127
|
-
showStatusPickerAt: null,
|
|
128
|
-
isNew: false
|
|
129
|
-
});
|
|
130
|
-
if (closingMethod) {
|
|
131
|
-
handleClosingByArrows(closingMethod, state, showStatusPickerAt, tr);
|
|
132
|
-
} else if (statusNode.attrs.text) {
|
|
133
|
-
// still has content - keep content
|
|
134
|
-
// move selection after status if selection did not change
|
|
135
|
-
if (tr.selection.from === showStatusPickerAt) {
|
|
136
|
-
tr = tr.setSelection(Selection.near(state.tr.doc.resolve(showStatusPickerAt + 2)));
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
// no content - remove node
|
|
140
|
-
tr = tr.delete(showStatusPickerAt, showStatusPickerAt + 1);
|
|
141
|
-
}
|
|
142
|
-
dispatch(tr);
|
|
143
|
-
editorView.focus();
|
|
144
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { name as packageName, version as packageVersion } from '../../version-wrapper';
|
|
2
|
-
export const FABRIC_CHANNEL = 'fabric-elements';
|
|
3
|
-
export const createStatusAnalyticsAndFire = createAnalyticsEvent => payload => {
|
|
4
|
-
if (createAnalyticsEvent && payload) {
|
|
5
|
-
const statusPayload = {
|
|
6
|
-
...payload,
|
|
7
|
-
eventType: 'ui'
|
|
8
|
-
};
|
|
9
|
-
if (!statusPayload.attributes) {
|
|
10
|
-
statusPayload.attributes = {};
|
|
11
|
-
}
|
|
12
|
-
statusPayload.attributes.packageName = packageName;
|
|
13
|
-
statusPayload.attributes.packageVersion = packageVersion;
|
|
14
|
-
statusPayload.attributes.componentName = 'status';
|
|
15
|
-
createAnalyticsEvent(statusPayload).fire(FABRIC_CHANNEL);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
export const analyticsState = isNew => isNew ? 'new' : 'update';
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
3
|
-
import { status } from '@atlaskit/adf-schema';
|
|
4
|
-
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
5
|
-
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
6
|
-
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
7
|
-
import { IconStatus } from '@atlaskit/editor-common/quick-insert';
|
|
8
|
-
import { updateStatusWithAnalytics, commitStatusPicker, createStatus, updateStatus } from './actions';
|
|
9
|
-
import { keymapPlugin } from './keymap';
|
|
10
|
-
import createStatusPlugin from './plugin';
|
|
11
|
-
import { pluginKey } from './plugin-key';
|
|
12
|
-
import StatusPicker from './ui/statusPicker';
|
|
13
|
-
const baseStatusPlugin = ({
|
|
14
|
-
config: options,
|
|
15
|
-
api
|
|
16
|
-
}) => {
|
|
17
|
-
var _api$analytics;
|
|
18
|
-
return {
|
|
19
|
-
name: 'status',
|
|
20
|
-
nodes() {
|
|
21
|
-
return [{
|
|
22
|
-
name: 'status',
|
|
23
|
-
node: status
|
|
24
|
-
}];
|
|
25
|
-
},
|
|
26
|
-
pmPlugins() {
|
|
27
|
-
return [{
|
|
28
|
-
name: 'status',
|
|
29
|
-
plugin: pmPluginFactoryParams => createStatusPlugin(pmPluginFactoryParams, options)
|
|
30
|
-
}, {
|
|
31
|
-
name: 'statusKeymap',
|
|
32
|
-
plugin: keymapPlugin
|
|
33
|
-
}];
|
|
34
|
-
},
|
|
35
|
-
actions: {
|
|
36
|
-
commitStatusPicker,
|
|
37
|
-
updateStatus: updateStatusWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
|
|
38
|
-
},
|
|
39
|
-
contentComponent({
|
|
40
|
-
editorView,
|
|
41
|
-
popupsMountPoint,
|
|
42
|
-
popupsBoundariesElement,
|
|
43
|
-
popupsScrollableElement
|
|
44
|
-
}) {
|
|
45
|
-
const domAtPos = editorView.domAtPos.bind(editorView);
|
|
46
|
-
return /*#__PURE__*/React.createElement(WithPluginState, {
|
|
47
|
-
plugins: {
|
|
48
|
-
statusState: pluginKey
|
|
49
|
-
},
|
|
50
|
-
render: ({
|
|
51
|
-
statusState = {}
|
|
52
|
-
}) => {
|
|
53
|
-
const {
|
|
54
|
-
showStatusPickerAt
|
|
55
|
-
} = statusState;
|
|
56
|
-
if (typeof showStatusPickerAt !== 'number') {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
const target = findDomRefAtPos(showStatusPickerAt, domAtPos);
|
|
60
|
-
const statusNode = editorView.state.doc.nodeAt(showStatusPickerAt);
|
|
61
|
-
if (!statusNode || statusNode.type.name !== 'status') {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
const {
|
|
65
|
-
text,
|
|
66
|
-
color,
|
|
67
|
-
localId
|
|
68
|
-
} = statusNode.attrs;
|
|
69
|
-
return /*#__PURE__*/React.createElement(StatusPicker, {
|
|
70
|
-
isNew: statusState.isNew,
|
|
71
|
-
target: target,
|
|
72
|
-
defaultText: text,
|
|
73
|
-
defaultColor: color,
|
|
74
|
-
defaultLocalId: localId,
|
|
75
|
-
mountTo: popupsMountPoint,
|
|
76
|
-
boundariesElement: popupsBoundariesElement,
|
|
77
|
-
scrollableElement: popupsScrollableElement,
|
|
78
|
-
onSelect: status => {
|
|
79
|
-
updateStatus(status)(editorView.state, editorView.dispatch);
|
|
80
|
-
},
|
|
81
|
-
onTextChanged: status => {
|
|
82
|
-
updateStatus(status)(editorView.state, editorView.dispatch);
|
|
83
|
-
},
|
|
84
|
-
closeStatusPicker: closingPayload => {
|
|
85
|
-
commitStatusPicker(closingPayload)(editorView);
|
|
86
|
-
},
|
|
87
|
-
onEnter: () => {
|
|
88
|
-
commitStatusPicker()(editorView);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
const decorateWithPluginOptions = (plugin, options, api) => {
|
|
97
|
-
if ((options === null || options === void 0 ? void 0 : options.menuDisabled) === true) {
|
|
98
|
-
return plugin;
|
|
99
|
-
}
|
|
100
|
-
plugin.pluginsOptions = {
|
|
101
|
-
quickInsert: ({
|
|
102
|
-
formatMessage
|
|
103
|
-
}) => [{
|
|
104
|
-
id: 'status',
|
|
105
|
-
title: formatMessage(messages.status),
|
|
106
|
-
description: formatMessage(messages.statusDescription),
|
|
107
|
-
priority: 700,
|
|
108
|
-
keywords: ['lozenge'],
|
|
109
|
-
icon: () => /*#__PURE__*/React.createElement(IconStatus, null),
|
|
110
|
-
action(insert, state) {
|
|
111
|
-
var _api$analytics2;
|
|
112
|
-
const tr = createStatus()(insert, state);
|
|
113
|
-
api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.attachAnalyticsEvent({
|
|
114
|
-
action: ACTION.INSERTED,
|
|
115
|
-
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
116
|
-
actionSubjectId: ACTION_SUBJECT_ID.STATUS,
|
|
117
|
-
attributes: {
|
|
118
|
-
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
119
|
-
},
|
|
120
|
-
eventType: EVENT_TYPE.TRACK
|
|
121
|
-
})(tr);
|
|
122
|
-
return tr;
|
|
123
|
-
}
|
|
124
|
-
}]
|
|
125
|
-
};
|
|
126
|
-
return plugin;
|
|
127
|
-
};
|
|
128
|
-
const statusPlugin = ({
|
|
129
|
-
config: options,
|
|
130
|
-
api
|
|
131
|
-
}) => decorateWithPluginOptions(baseStatusPlugin({
|
|
132
|
-
config: options,
|
|
133
|
-
api
|
|
134
|
-
}), options, api);
|
|
135
|
-
export default statusPlugin;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
2
|
-
import { bindKeymapWithCommand, enter, tab } from '@atlaskit/editor-common/keymaps';
|
|
3
|
-
import { mayGetStatusAtSelection } from './utils';
|
|
4
|
-
export function keymapPlugin() {
|
|
5
|
-
const list = {};
|
|
6
|
-
bindKeymapWithCommand(enter.common, consumeKeyEvent, list);
|
|
7
|
-
bindKeymapWithCommand(tab.common, consumeKeyEvent, list);
|
|
8
|
-
return keymap(list);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// consume event to prevent status node problems with positioning and selection
|
|
12
|
-
const consumeKeyEvent = (state, _dispatch) => !!mayGetStatusAtSelection(state.tr.selection);
|
|
13
|
-
export default keymapPlugin;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/** @jsx jsx */
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { css, jsx } from '@emotion/react';
|
|
4
|
-
import { injectIntl } from 'react-intl-next';
|
|
5
|
-
import { Status } from '@atlaskit/status/element';
|
|
6
|
-
import { statusMessages as messages } from '@atlaskit/editor-common/messages';
|
|
7
|
-
const styledStatus = css`
|
|
8
|
-
opacity: 1;
|
|
9
|
-
`;
|
|
10
|
-
const styledStatusPlaceholder = css`
|
|
11
|
-
opacity: 0.5;
|
|
12
|
-
`;
|
|
13
|
-
const StatusContainerView = props => {
|
|
14
|
-
const {
|
|
15
|
-
text,
|
|
16
|
-
color,
|
|
17
|
-
localId,
|
|
18
|
-
style,
|
|
19
|
-
intl: {
|
|
20
|
-
formatMessage
|
|
21
|
-
}
|
|
22
|
-
} = props;
|
|
23
|
-
const statusText = text ? text : formatMessage(messages.placeholder);
|
|
24
|
-
const handleClick = event => {
|
|
25
|
-
if (event.nativeEvent.stopImmediatePropagation) {
|
|
26
|
-
event.nativeEvent.stopImmediatePropagation();
|
|
27
|
-
}
|
|
28
|
-
// handling of popup is done in plugin.apply on selection change.
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
return jsx("span", {
|
|
32
|
-
css: text ? styledStatus : styledStatusPlaceholder,
|
|
33
|
-
"data-testid": "statusContainerView"
|
|
34
|
-
}, jsx(Status, {
|
|
35
|
-
text: statusText,
|
|
36
|
-
color: color,
|
|
37
|
-
localId: localId,
|
|
38
|
-
style: style,
|
|
39
|
-
onClick: handleClick
|
|
40
|
-
}));
|
|
41
|
-
};
|
|
42
|
-
export const IntlStatusContainerView = injectIntl(StatusContainerView);
|
|
43
|
-
export const StatusNodeView = props => {
|
|
44
|
-
const {
|
|
45
|
-
view
|
|
46
|
-
} = props;
|
|
47
|
-
const {
|
|
48
|
-
text,
|
|
49
|
-
color,
|
|
50
|
-
localId,
|
|
51
|
-
style
|
|
52
|
-
} = props.node.attrs;
|
|
53
|
-
return jsx(IntlStatusContainerView, {
|
|
54
|
-
view: view,
|
|
55
|
-
text: text,
|
|
56
|
-
color: color,
|
|
57
|
-
style: style,
|
|
58
|
-
localId: localId
|
|
59
|
-
});
|
|
60
|
-
};
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
-
import { pmHistoryPluginKey } from '@atlaskit/editor-common/utils';
|
|
4
|
-
import { getInlineNodeViewProducer } from '@atlaskit/editor-common/react-node-view';
|
|
5
|
-
import { StatusNodeView } from './nodeviews/status';
|
|
6
|
-
import { pluginKey } from './plugin-key';
|
|
7
|
-
import { isEmptyStatus, mayGetStatusAtSelection } from './utils';
|
|
8
|
-
export { pluginKey, pluginKeyName } from './plugin-key';
|
|
9
|
-
const createPlugin = (pmPluginFactoryParams, options) => new SafePlugin({
|
|
10
|
-
state: {
|
|
11
|
-
init: () => ({
|
|
12
|
-
isNew: false,
|
|
13
|
-
showStatusPickerAt: null
|
|
14
|
-
}),
|
|
15
|
-
apply(tr, state, oldEditorState) {
|
|
16
|
-
const meta = tr.getMeta(pluginKey);
|
|
17
|
-
if (meta) {
|
|
18
|
-
const newState = {
|
|
19
|
-
...state,
|
|
20
|
-
...meta
|
|
21
|
-
};
|
|
22
|
-
pmPluginFactoryParams.dispatch(pluginKey, newState);
|
|
23
|
-
return newState;
|
|
24
|
-
}
|
|
25
|
-
if (tr.docChanged && state.showStatusPickerAt) {
|
|
26
|
-
const {
|
|
27
|
-
pos,
|
|
28
|
-
deleted
|
|
29
|
-
} = tr.mapping.mapResult(state.showStatusPickerAt);
|
|
30
|
-
const showStatusPickerAt = deleted ? null : pos;
|
|
31
|
-
const newState = {
|
|
32
|
-
...state,
|
|
33
|
-
showStatusPickerAt
|
|
34
|
-
};
|
|
35
|
-
if (newState.showStatusPickerAt !== state.showStatusPickerAt) {
|
|
36
|
-
pmPluginFactoryParams.dispatch(pluginKey, newState);
|
|
37
|
-
return newState;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (tr.selectionSet) {
|
|
41
|
-
// Change in selection, while status picker was open, update state, if required.
|
|
42
|
-
const selectionFrom = tr.selection.from;
|
|
43
|
-
const nodeAtSelection = tr.doc.nodeAt(selectionFrom);
|
|
44
|
-
let showStatusPickerAt = null;
|
|
45
|
-
if (nodeAtSelection && nodeAtSelection.type === oldEditorState.schema.nodes.status && tr.selection instanceof NodeSelection) {
|
|
46
|
-
showStatusPickerAt = selectionFrom;
|
|
47
|
-
}
|
|
48
|
-
if (showStatusPickerAt !== state.showStatusPickerAt) {
|
|
49
|
-
const newState = {
|
|
50
|
-
...state,
|
|
51
|
-
isNew: false,
|
|
52
|
-
showStatusPickerAt
|
|
53
|
-
};
|
|
54
|
-
pmPluginFactoryParams.dispatch(pluginKey, newState);
|
|
55
|
-
return newState;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return state;
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
filterTransaction: (tr, state) => {
|
|
62
|
-
// if it is a selection change transaction, and selection changes from node to text
|
|
63
|
-
if (tr.selectionSet && !tr.steps.length && tr.isGeneric && tr.selection instanceof TextSelection && state.selection instanceof NodeSelection) {
|
|
64
|
-
const {
|
|
65
|
-
isNew,
|
|
66
|
-
showStatusPickerAt
|
|
67
|
-
} = pluginKey.getState(state) || {};
|
|
68
|
-
const nodeAtSelection = tr.doc.nodeAt(tr.selection.from);
|
|
69
|
-
// prevent changing node selection to text selection on dom change right after inserting status
|
|
70
|
-
// if newly selected status is selected with status picker opened
|
|
71
|
-
if (isNew && showStatusPickerAt && nodeAtSelection && nodeAtSelection.type === state.schema.nodes.status) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return true;
|
|
76
|
-
},
|
|
77
|
-
appendTransaction: (transactions, oldEditorState, newEditorState) => {
|
|
78
|
-
let changed = false;
|
|
79
|
-
let tr = newEditorState.tr;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* When user start creating status, and, when users navigates away
|
|
83
|
-
* while empty, then we want to remove empty ("set a status") status.
|
|
84
|
-
* But when transaction to add empty status happens from undo/redo
|
|
85
|
-
* we don't want to remove it.
|
|
86
|
-
*/
|
|
87
|
-
if (transactions.find(tr => tr.selectionSet && !tr.getMeta(pmHistoryPluginKey))) {
|
|
88
|
-
let oldStatus = mayGetStatusAtSelection(oldEditorState.selection);
|
|
89
|
-
let newStatus = mayGetStatusAtSelection(newEditorState.selection);
|
|
90
|
-
if (oldStatus && (newStatus && oldStatus.localId !== newStatus.localId || !newStatus)) {
|
|
91
|
-
if (isEmptyStatus(oldStatus)) {
|
|
92
|
-
const pos = oldEditorState.selection.from;
|
|
93
|
-
tr.delete(tr.mapping.map(pos), tr.mapping.map(pos + 1));
|
|
94
|
-
changed = true;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return changed ? tr : undefined;
|
|
99
|
-
},
|
|
100
|
-
key: pluginKey,
|
|
101
|
-
props: {
|
|
102
|
-
nodeViews: {
|
|
103
|
-
status: getInlineNodeViewProducer({
|
|
104
|
-
pmPluginFactoryParams,
|
|
105
|
-
Component: StatusNodeView,
|
|
106
|
-
extraComponentProps: {
|
|
107
|
-
options
|
|
108
|
-
}
|
|
109
|
-
})
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
export default createPlugin;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|