@atlaskit/editor-core 189.3.24 → 189.3.25
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 +7 -0
- package/dist/cjs/plugins/index.js +0 -7
- package/dist/cjs/plugins/toolbar-lists-indentation/index.js +2 -13
- package/dist/cjs/plugins/toolbar-lists-indentation/pm-plugins/indentation-buttons.js +0 -3
- package/dist/cjs/presets/universal.js +2 -1
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/plugins/toolbar-lists-indentation/index.js +2 -11
- package/dist/es2019/plugins/toolbar-lists-indentation/pm-plugins/indentation-buttons.js +0 -2
- package/dist/es2019/presets/universal.js +2 -1
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/plugins/toolbar-lists-indentation/index.js +2 -11
- package/dist/esm/plugins/toolbar-lists-indentation/pm-plugins/indentation-buttons.js +0 -2
- package/dist/esm/presets/universal.js +2 -1
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/plugins/index.d.ts +0 -1
- package/dist/types/plugins/toolbar-lists-indentation/index.d.ts +1 -3
- package/dist/types/plugins/toolbar-lists-indentation/pm-plugins/indentation-buttons.d.ts +0 -2
- package/dist/types-ts4.5/plugins/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/toolbar-lists-indentation/index.d.ts +1 -3
- package/dist/types-ts4.5/plugins/toolbar-lists-indentation/pm-plugins/indentation-buttons.d.ts +0 -2
- package/package.json +2 -1
- package/dist/cjs/plugins/indentation/commands/index.js +0 -140
- package/dist/cjs/plugins/indentation/commands/utils.js +0 -92
- package/dist/cjs/plugins/indentation/getAttrsWithChangesRecorder.js +0 -38
- package/dist/cjs/plugins/indentation/index.js +0 -54
- package/dist/cjs/plugins/indentation/pm-plugins/keymap.js +0 -26
- package/dist/es2019/plugins/indentation/commands/index.js +0 -130
- package/dist/es2019/plugins/indentation/commands/utils.js +0 -89
- package/dist/es2019/plugins/indentation/getAttrsWithChangesRecorder.js +0 -32
- package/dist/es2019/plugins/indentation/index.js +0 -55
- package/dist/es2019/plugins/indentation/pm-plugins/keymap.js +0 -21
- package/dist/esm/plugins/indentation/commands/index.js +0 -133
- package/dist/esm/plugins/indentation/commands/utils.js +0 -85
- package/dist/esm/plugins/indentation/getAttrsWithChangesRecorder.js +0 -32
- package/dist/esm/plugins/indentation/index.js +0 -48
- package/dist/esm/plugins/indentation/pm-plugins/keymap.js +0 -19
- package/dist/types/plugins/indentation/commands/index.d.ts +0 -8
- package/dist/types/plugins/indentation/commands/utils.d.ts +0 -37
- package/dist/types/plugins/indentation/getAttrsWithChangesRecorder.d.ts +0 -23
- package/dist/types/plugins/indentation/index.d.ts +0 -18
- package/dist/types/plugins/indentation/pm-plugins/keymap.d.ts +0 -4
- package/dist/types-ts4.5/plugins/indentation/commands/index.d.ts +0 -8
- package/dist/types-ts4.5/plugins/indentation/commands/utils.d.ts +0 -37
- package/dist/types-ts4.5/plugins/indentation/getAttrsWithChangesRecorder.d.ts +0 -23
- package/dist/types-ts4.5/plugins/indentation/index.d.ts +0 -20
- package/dist/types-ts4.5/plugins/indentation/pm-plugins/keymap.d.ts +0 -4
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _adfSchema = require("@atlaskit/adf-schema");
|
|
8
|
-
var _keymap = require("./pm-plugins/keymap");
|
|
9
|
-
var _commands = require("./commands");
|
|
10
|
-
var _indentation = require("@atlaskit/editor-common/indentation");
|
|
11
|
-
var indentationPlugin = function indentationPlugin(_ref) {
|
|
12
|
-
var _api$analytics, _api$analytics2;
|
|
13
|
-
var api = _ref.api;
|
|
14
|
-
return {
|
|
15
|
-
name: 'indentation',
|
|
16
|
-
marks: function marks() {
|
|
17
|
-
return [{
|
|
18
|
-
name: 'indentation',
|
|
19
|
-
mark: _adfSchema.indentation
|
|
20
|
-
}];
|
|
21
|
-
},
|
|
22
|
-
actions: {
|
|
23
|
-
indentParagraphOrHeading: (0, _commands.getIndentCommand)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
|
|
24
|
-
outdentParagraphOrHeading: (0, _commands.getOutdentCommand)(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
25
|
-
},
|
|
26
|
-
getSharedState: function getSharedState(editorState) {
|
|
27
|
-
var _ref2;
|
|
28
|
-
if (!editorState) {
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
var selection = editorState.tr.selection,
|
|
32
|
-
indentation = editorState.schema.marks.indentation;
|
|
33
|
-
var node = selection.$from.node();
|
|
34
|
-
var indentationMark = node.marks.find(function (mark) {
|
|
35
|
-
return mark.type === indentation;
|
|
36
|
-
});
|
|
37
|
-
return {
|
|
38
|
-
isIndentationAllowed: (0, _commands.isIndentationAllowed)(editorState.schema, node),
|
|
39
|
-
indentDisabled: (_ref2 = (indentationMark === null || indentationMark === void 0 ? void 0 : indentationMark.attrs.level) >= _indentation.MAX_INDENTATION_LEVEL) !== null && _ref2 !== void 0 ? _ref2 : false,
|
|
40
|
-
outdentDisabled: !indentationMark
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
pmPlugins: function pmPlugins() {
|
|
44
|
-
return [{
|
|
45
|
-
name: 'indentationKeymap',
|
|
46
|
-
plugin: function plugin() {
|
|
47
|
-
var _api$analytics3;
|
|
48
|
-
return (0, _keymap.keymapPlugin)(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
|
|
49
|
-
}
|
|
50
|
-
}];
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
var _default = exports.default = indentationPlugin;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
exports.keymapPlugin = keymapPlugin;
|
|
8
|
-
var _keymap = require("@atlaskit/editor-prosemirror/keymap");
|
|
9
|
-
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
10
|
-
var _utils = require("@atlaskit/editor-common/utils");
|
|
11
|
-
var _commands = require("../commands");
|
|
12
|
-
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
13
|
-
function keymapPlugin(editorAnalyticsAPI) {
|
|
14
|
-
var list = {};
|
|
15
|
-
(0, _keymaps.bindKeymapWithCommand)((0, _keymaps.findShortcutByKeymap)(_keymaps.indent), (0, _commands.getIndentCommand)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD), list);
|
|
16
|
-
(0, _keymaps.bindKeymapWithCommand)((0, _keymaps.findShortcutByKeymap)(_keymaps.outdent), (0, _commands.getOutdentCommand)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD), list);
|
|
17
|
-
(0, _keymaps.bindKeymapWithCommand)((0, _keymaps.findShortcutByKeymap)(_keymaps.backspace), function (state, dispatch) {
|
|
18
|
-
var selection = state.selection;
|
|
19
|
-
if ((0, _utils.isTextSelection)(selection) && selection.$cursor && selection.$cursor.parentOffset === 0) {
|
|
20
|
-
return dispatch ? (0, _commands.getOutdentCommand)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD)(state, dispatch) : false;
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
23
|
-
}, list);
|
|
24
|
-
return (0, _keymap.keymap)(list);
|
|
25
|
-
}
|
|
26
|
-
var _default = exports.default = keymapPlugin;
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { toggleBlockMark } from '@atlaskit/editor-common/commands';
|
|
2
|
-
import { createAnalyticsDispatch } from './utils';
|
|
3
|
-
import { INDENT_DIRECTION, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
|
-
import getAttrsWithChangesRecorder from '../getAttrsWithChangesRecorder';
|
|
5
|
-
import { MAX_INDENTATION_LEVEL } from '@atlaskit/editor-common/indentation';
|
|
6
|
-
export const isIndentationAllowed = (schema, node) => {
|
|
7
|
-
const {
|
|
8
|
-
nodes: {
|
|
9
|
-
paragraph,
|
|
10
|
-
heading
|
|
11
|
-
},
|
|
12
|
-
marks: {
|
|
13
|
-
alignment
|
|
14
|
-
}
|
|
15
|
-
} = schema;
|
|
16
|
-
if ([paragraph, heading].indexOf(node.type) > -1) {
|
|
17
|
-
if (alignment) {
|
|
18
|
-
const hasAlignment = node.marks.filter(mark => mark.type === alignment)[0];
|
|
19
|
-
return !hasAlignment;
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Create new indentation command (Either indent or outdent depend of getArgsFn)
|
|
28
|
-
* @param getNewIndentationAttrs Function to handle new indentation level
|
|
29
|
-
*/
|
|
30
|
-
function createIndentationCommand(getNewIndentationAttrs) {
|
|
31
|
-
return (state, dispatch) => {
|
|
32
|
-
const {
|
|
33
|
-
indentation
|
|
34
|
-
} = state.schema.marks;
|
|
35
|
-
return toggleBlockMark(indentation, getNewIndentationAttrs, isIndentationAllowed)(state, dispatch);
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function createIndentationCommandWithAnalytics({
|
|
39
|
-
getNewIndentationAttrs,
|
|
40
|
-
direction,
|
|
41
|
-
inputMethod,
|
|
42
|
-
editorAnalyticsAPI
|
|
43
|
-
}) {
|
|
44
|
-
// Create a new getAttrs function to record the changes
|
|
45
|
-
const {
|
|
46
|
-
getAttrs,
|
|
47
|
-
getAndResetAttrsChanges
|
|
48
|
-
} = getAttrsWithChangesRecorder(getNewIndentationAttrs, {
|
|
49
|
-
direction
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// Use new getAttrs wrapper
|
|
53
|
-
const indentationCommand = createIndentationCommand(getAttrs);
|
|
54
|
-
|
|
55
|
-
// Return a new command where we change dispatch for our analytics dispatch
|
|
56
|
-
return (state, dispatch) => {
|
|
57
|
-
return indentationCommand(state, createAnalyticsDispatch({
|
|
58
|
-
getAttrsChanges: getAndResetAttrsChanges,
|
|
59
|
-
inputMethod,
|
|
60
|
-
editorAnalyticsAPI,
|
|
61
|
-
state,
|
|
62
|
-
dispatch
|
|
63
|
-
}));
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Get new level for outdent
|
|
69
|
-
* @param oldAttr Old attributes for the mark, undefined if the mark doesn't exit
|
|
70
|
-
* @returns - undefined; No change required
|
|
71
|
-
* - false; Remove the mark
|
|
72
|
-
* - object; Update attributes
|
|
73
|
-
*/
|
|
74
|
-
const getIndentAttrs = oldAttr => {
|
|
75
|
-
if (!oldAttr) {
|
|
76
|
-
return {
|
|
77
|
-
level: 1
|
|
78
|
-
}; // No mark exist, create a new one with level 1
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const {
|
|
82
|
-
level
|
|
83
|
-
} = oldAttr;
|
|
84
|
-
if (level >= MAX_INDENTATION_LEVEL) {
|
|
85
|
-
return undefined; // Max indentation level reached, do nothing.
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
level: level + 1
|
|
90
|
-
}; // Otherwise, increase the level by one
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export const getIndentCommand = editorAnalyticsAPI => (inputMethod = INPUT_METHOD.KEYBOARD) => createIndentationCommandWithAnalytics({
|
|
94
|
-
getNewIndentationAttrs: getIndentAttrs,
|
|
95
|
-
direction: INDENT_DIRECTION.INDENT,
|
|
96
|
-
inputMethod,
|
|
97
|
-
editorAnalyticsAPI
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Get new level for outdent
|
|
102
|
-
* @param oldAttr Old attributes for the mark, undefined if the mark doesn't exit
|
|
103
|
-
* @returns - undefined; No change required
|
|
104
|
-
* - false; Remove the mark
|
|
105
|
-
* - object; Update attributes
|
|
106
|
-
*/
|
|
107
|
-
const getOutdentAttrs = oldAttr => {
|
|
108
|
-
if (!oldAttr) {
|
|
109
|
-
return undefined; // Do nothing;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const {
|
|
113
|
-
level
|
|
114
|
-
} = oldAttr;
|
|
115
|
-
if (level <= 1) {
|
|
116
|
-
return false; // Remove the mark
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
level: level - 1
|
|
121
|
-
}; // Decrease the level on other cases
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
export const getOutdentCommand = editorAnalyticsAPI => (inputMethod = INPUT_METHOD.KEYBOARD) => createIndentationCommandWithAnalytics({
|
|
125
|
-
getNewIndentationAttrs: getOutdentAttrs,
|
|
126
|
-
direction: INDENT_DIRECTION.OUTDENT,
|
|
127
|
-
inputMethod,
|
|
128
|
-
editorAnalyticsAPI
|
|
129
|
-
});
|
|
130
|
-
export const removeIndentation = (state, dispatch) => toggleBlockMark(state.schema.marks.indentation, () => false)(state, dispatch);
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { INDENT_TYPE, ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
|
|
3
|
-
// Analytics GAS v3 Utils
|
|
4
|
-
|
|
5
|
-
const indentTypes = {
|
|
6
|
-
paragraph: INDENT_TYPE.PARAGRAPH,
|
|
7
|
-
heading: INDENT_TYPE.HEADING
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Get the current indentation level given prev and new attributes
|
|
12
|
-
* @param prevAttrs - Previous attributes from indentation
|
|
13
|
-
* @param newAttrs - New attributes from indentation
|
|
14
|
-
*/
|
|
15
|
-
export function getNewIndentLevel(prevAttrs, newAttrs) {
|
|
16
|
-
if (newAttrs === undefined) {
|
|
17
|
-
return getPrevIndentLevel(prevAttrs);
|
|
18
|
-
} else if (newAttrs === false) {
|
|
19
|
-
return 0;
|
|
20
|
-
}
|
|
21
|
-
return newAttrs.level;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Get the previous indentation level prev attributes
|
|
26
|
-
* @param prevAttrs - Previous attributes from indentation
|
|
27
|
-
*/
|
|
28
|
-
export function getPrevIndentLevel(prevAttrs) {
|
|
29
|
-
if (prevAttrs === undefined) {
|
|
30
|
-
return 0;
|
|
31
|
-
}
|
|
32
|
-
return prevAttrs.level;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Create a new dispatch function who add analytics events given a list of attributes changes
|
|
37
|
-
*
|
|
38
|
-
* @export
|
|
39
|
-
* @param {*} getAttrsChanges
|
|
40
|
-
* @param {*} state
|
|
41
|
-
* @param dispatch
|
|
42
|
-
* @returns
|
|
43
|
-
*/
|
|
44
|
-
export function createAnalyticsDispatch({
|
|
45
|
-
getAttrsChanges,
|
|
46
|
-
inputMethod,
|
|
47
|
-
editorAnalyticsAPI,
|
|
48
|
-
state,
|
|
49
|
-
dispatch
|
|
50
|
-
}) {
|
|
51
|
-
return tr => {
|
|
52
|
-
let currentTr = tr;
|
|
53
|
-
const changes = getAttrsChanges(); // Get all attributes changes
|
|
54
|
-
|
|
55
|
-
// Add analytics event for each change stored.
|
|
56
|
-
changes.forEach(({
|
|
57
|
-
node,
|
|
58
|
-
prevAttrs,
|
|
59
|
-
newAttrs,
|
|
60
|
-
options: {
|
|
61
|
-
direction
|
|
62
|
-
}
|
|
63
|
-
}) => {
|
|
64
|
-
const indentType = indentTypes[node.type.name];
|
|
65
|
-
if (!indentType) {
|
|
66
|
-
return; // If no valid indent type continue
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
70
|
-
action: ACTION.FORMATTED,
|
|
71
|
-
actionSubject: ACTION_SUBJECT.TEXT,
|
|
72
|
-
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_INDENT,
|
|
73
|
-
eventType: EVENT_TYPE.TRACK,
|
|
74
|
-
attributes: {
|
|
75
|
-
inputMethod,
|
|
76
|
-
previousIndentationLevel: getPrevIndentLevel(prevAttrs),
|
|
77
|
-
newIndentLevel: getNewIndentLevel(prevAttrs, newAttrs),
|
|
78
|
-
direction,
|
|
79
|
-
indentType
|
|
80
|
-
}
|
|
81
|
-
})(currentTr);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Dispatch analytics if exist
|
|
85
|
-
if (dispatch) {
|
|
86
|
-
dispatch(tr);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create a new getAttrs handler who will wrap the original function,
|
|
3
|
-
* and store the changes internally to be used for other
|
|
4
|
-
* tools like Analytics later in the code.
|
|
5
|
-
*
|
|
6
|
-
* @param getAttrs - Function who gets the new attributes
|
|
7
|
-
* @return object
|
|
8
|
-
* @property handler - New handler to get indentation attributes (It wraps the original)
|
|
9
|
-
* @property getChanges - Return all the stored changes.
|
|
10
|
-
* @property clear - Clear the changes
|
|
11
|
-
*/
|
|
12
|
-
export default function getAttrsWithChangesRecorder(getAttrs, options) {
|
|
13
|
-
let changes = [];
|
|
14
|
-
function getAttrsWithChangesRecorder(prevAttrs, node) {
|
|
15
|
-
const newAttrs = getAttrs(prevAttrs, node);
|
|
16
|
-
changes.push({
|
|
17
|
-
node: node,
|
|
18
|
-
prevAttrs,
|
|
19
|
-
newAttrs,
|
|
20
|
-
options
|
|
21
|
-
});
|
|
22
|
-
return newAttrs;
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
getAttrs: getAttrsWithChangesRecorder,
|
|
26
|
-
getAndResetAttrsChanges() {
|
|
27
|
-
const oldChanges = changes;
|
|
28
|
-
changes = [];
|
|
29
|
-
return oldChanges;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { indentation } from '@atlaskit/adf-schema';
|
|
2
|
-
import { keymapPlugin } from './pm-plugins/keymap';
|
|
3
|
-
import { getOutdentCommand, getIndentCommand, isIndentationAllowed } from './commands';
|
|
4
|
-
import { MAX_INDENTATION_LEVEL } from '@atlaskit/editor-common/indentation';
|
|
5
|
-
const indentationPlugin = ({
|
|
6
|
-
api
|
|
7
|
-
}) => {
|
|
8
|
-
var _api$analytics, _api$analytics2;
|
|
9
|
-
return {
|
|
10
|
-
name: 'indentation',
|
|
11
|
-
marks() {
|
|
12
|
-
return [{
|
|
13
|
-
name: 'indentation',
|
|
14
|
-
mark: indentation
|
|
15
|
-
}];
|
|
16
|
-
},
|
|
17
|
-
actions: {
|
|
18
|
-
indentParagraphOrHeading: getIndentCommand(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
|
|
19
|
-
outdentParagraphOrHeading: getOutdentCommand(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
20
|
-
},
|
|
21
|
-
getSharedState(editorState) {
|
|
22
|
-
var _ref;
|
|
23
|
-
if (!editorState) {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
const {
|
|
27
|
-
tr: {
|
|
28
|
-
selection
|
|
29
|
-
},
|
|
30
|
-
schema: {
|
|
31
|
-
marks: {
|
|
32
|
-
indentation
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
} = editorState;
|
|
36
|
-
const node = selection.$from.node();
|
|
37
|
-
const indentationMark = node.marks.find(mark => mark.type === indentation);
|
|
38
|
-
return {
|
|
39
|
-
isIndentationAllowed: isIndentationAllowed(editorState.schema, node),
|
|
40
|
-
indentDisabled: (_ref = (indentationMark === null || indentationMark === void 0 ? void 0 : indentationMark.attrs.level) >= MAX_INDENTATION_LEVEL) !== null && _ref !== void 0 ? _ref : false,
|
|
41
|
-
outdentDisabled: !indentationMark
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
pmPlugins() {
|
|
45
|
-
return [{
|
|
46
|
-
name: 'indentationKeymap',
|
|
47
|
-
plugin: () => {
|
|
48
|
-
var _api$analytics3;
|
|
49
|
-
return keymapPlugin(api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
|
|
50
|
-
}
|
|
51
|
-
}];
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
export default indentationPlugin;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
2
|
-
import { bindKeymapWithCommand, findShortcutByKeymap, outdent, indent, backspace } from '@atlaskit/editor-common/keymaps';
|
|
3
|
-
import { isTextSelection } from '@atlaskit/editor-common/utils';
|
|
4
|
-
import { getIndentCommand, getOutdentCommand } from '../commands';
|
|
5
|
-
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
6
|
-
export function keymapPlugin(editorAnalyticsAPI) {
|
|
7
|
-
const list = {};
|
|
8
|
-
bindKeymapWithCommand(findShortcutByKeymap(indent), getIndentCommand(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD), list);
|
|
9
|
-
bindKeymapWithCommand(findShortcutByKeymap(outdent), getOutdentCommand(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD), list);
|
|
10
|
-
bindKeymapWithCommand(findShortcutByKeymap(backspace), (state, dispatch) => {
|
|
11
|
-
const {
|
|
12
|
-
selection
|
|
13
|
-
} = state;
|
|
14
|
-
if (isTextSelection(selection) && selection.$cursor && selection.$cursor.parentOffset === 0) {
|
|
15
|
-
return dispatch ? getOutdentCommand(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD)(state, dispatch) : false;
|
|
16
|
-
}
|
|
17
|
-
return false;
|
|
18
|
-
}, list);
|
|
19
|
-
return keymap(list);
|
|
20
|
-
}
|
|
21
|
-
export default keymapPlugin;
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { toggleBlockMark } from '@atlaskit/editor-common/commands';
|
|
2
|
-
import { createAnalyticsDispatch } from './utils';
|
|
3
|
-
import { INDENT_DIRECTION, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
|
-
import getAttrsWithChangesRecorder from '../getAttrsWithChangesRecorder';
|
|
5
|
-
import { MAX_INDENTATION_LEVEL } from '@atlaskit/editor-common/indentation';
|
|
6
|
-
export var isIndentationAllowed = function isIndentationAllowed(schema, node) {
|
|
7
|
-
var _schema$nodes = schema.nodes,
|
|
8
|
-
paragraph = _schema$nodes.paragraph,
|
|
9
|
-
heading = _schema$nodes.heading,
|
|
10
|
-
alignment = schema.marks.alignment;
|
|
11
|
-
if ([paragraph, heading].indexOf(node.type) > -1) {
|
|
12
|
-
if (alignment) {
|
|
13
|
-
var hasAlignment = node.marks.filter(function (mark) {
|
|
14
|
-
return mark.type === alignment;
|
|
15
|
-
})[0];
|
|
16
|
-
return !hasAlignment;
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
return false;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Create new indentation command (Either indent or outdent depend of getArgsFn)
|
|
25
|
-
* @param getNewIndentationAttrs Function to handle new indentation level
|
|
26
|
-
*/
|
|
27
|
-
function createIndentationCommand(getNewIndentationAttrs) {
|
|
28
|
-
return function (state, dispatch) {
|
|
29
|
-
var indentation = state.schema.marks.indentation;
|
|
30
|
-
return toggleBlockMark(indentation, getNewIndentationAttrs, isIndentationAllowed)(state, dispatch);
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function createIndentationCommandWithAnalytics(_ref) {
|
|
34
|
-
var getNewIndentationAttrs = _ref.getNewIndentationAttrs,
|
|
35
|
-
direction = _ref.direction,
|
|
36
|
-
inputMethod = _ref.inputMethod,
|
|
37
|
-
editorAnalyticsAPI = _ref.editorAnalyticsAPI;
|
|
38
|
-
// Create a new getAttrs function to record the changes
|
|
39
|
-
var _getAttrsWithChangesR = getAttrsWithChangesRecorder(getNewIndentationAttrs, {
|
|
40
|
-
direction: direction
|
|
41
|
-
}),
|
|
42
|
-
getAttrs = _getAttrsWithChangesR.getAttrs,
|
|
43
|
-
getAndResetAttrsChanges = _getAttrsWithChangesR.getAndResetAttrsChanges;
|
|
44
|
-
|
|
45
|
-
// Use new getAttrs wrapper
|
|
46
|
-
var indentationCommand = createIndentationCommand(getAttrs);
|
|
47
|
-
|
|
48
|
-
// Return a new command where we change dispatch for our analytics dispatch
|
|
49
|
-
return function (state, dispatch) {
|
|
50
|
-
return indentationCommand(state, createAnalyticsDispatch({
|
|
51
|
-
getAttrsChanges: getAndResetAttrsChanges,
|
|
52
|
-
inputMethod: inputMethod,
|
|
53
|
-
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
54
|
-
state: state,
|
|
55
|
-
dispatch: dispatch
|
|
56
|
-
}));
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Get new level for outdent
|
|
62
|
-
* @param oldAttr Old attributes for the mark, undefined if the mark doesn't exit
|
|
63
|
-
* @returns - undefined; No change required
|
|
64
|
-
* - false; Remove the mark
|
|
65
|
-
* - object; Update attributes
|
|
66
|
-
*/
|
|
67
|
-
var getIndentAttrs = function getIndentAttrs(oldAttr) {
|
|
68
|
-
if (!oldAttr) {
|
|
69
|
-
return {
|
|
70
|
-
level: 1
|
|
71
|
-
}; // No mark exist, create a new one with level 1
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
var level = oldAttr.level;
|
|
75
|
-
if (level >= MAX_INDENTATION_LEVEL) {
|
|
76
|
-
return undefined; // Max indentation level reached, do nothing.
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
level: level + 1
|
|
81
|
-
}; // Otherwise, increase the level by one
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export var getIndentCommand = function getIndentCommand(editorAnalyticsAPI) {
|
|
85
|
-
return function () {
|
|
86
|
-
var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INPUT_METHOD.KEYBOARD;
|
|
87
|
-
return createIndentationCommandWithAnalytics({
|
|
88
|
-
getNewIndentationAttrs: getIndentAttrs,
|
|
89
|
-
direction: INDENT_DIRECTION.INDENT,
|
|
90
|
-
inputMethod: inputMethod,
|
|
91
|
-
editorAnalyticsAPI: editorAnalyticsAPI
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Get new level for outdent
|
|
98
|
-
* @param oldAttr Old attributes for the mark, undefined if the mark doesn't exit
|
|
99
|
-
* @returns - undefined; No change required
|
|
100
|
-
* - false; Remove the mark
|
|
101
|
-
* - object; Update attributes
|
|
102
|
-
*/
|
|
103
|
-
var getOutdentAttrs = function getOutdentAttrs(oldAttr) {
|
|
104
|
-
if (!oldAttr) {
|
|
105
|
-
return undefined; // Do nothing;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
var level = oldAttr.level;
|
|
109
|
-
if (level <= 1) {
|
|
110
|
-
return false; // Remove the mark
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
level: level - 1
|
|
115
|
-
}; // Decrease the level on other cases
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
export var getOutdentCommand = function getOutdentCommand(editorAnalyticsAPI) {
|
|
119
|
-
return function () {
|
|
120
|
-
var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INPUT_METHOD.KEYBOARD;
|
|
121
|
-
return createIndentationCommandWithAnalytics({
|
|
122
|
-
getNewIndentationAttrs: getOutdentAttrs,
|
|
123
|
-
direction: INDENT_DIRECTION.OUTDENT,
|
|
124
|
-
inputMethod: inputMethod,
|
|
125
|
-
editorAnalyticsAPI: editorAnalyticsAPI
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
export var removeIndentation = function removeIndentation(state, dispatch) {
|
|
130
|
-
return toggleBlockMark(state.schema.marks.indentation, function () {
|
|
131
|
-
return false;
|
|
132
|
-
})(state, dispatch);
|
|
133
|
-
};
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { INDENT_TYPE, ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
|
|
3
|
-
// Analytics GAS v3 Utils
|
|
4
|
-
|
|
5
|
-
var indentTypes = {
|
|
6
|
-
paragraph: INDENT_TYPE.PARAGRAPH,
|
|
7
|
-
heading: INDENT_TYPE.HEADING
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Get the current indentation level given prev and new attributes
|
|
12
|
-
* @param prevAttrs - Previous attributes from indentation
|
|
13
|
-
* @param newAttrs - New attributes from indentation
|
|
14
|
-
*/
|
|
15
|
-
export function getNewIndentLevel(prevAttrs, newAttrs) {
|
|
16
|
-
if (newAttrs === undefined) {
|
|
17
|
-
return getPrevIndentLevel(prevAttrs);
|
|
18
|
-
} else if (newAttrs === false) {
|
|
19
|
-
return 0;
|
|
20
|
-
}
|
|
21
|
-
return newAttrs.level;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Get the previous indentation level prev attributes
|
|
26
|
-
* @param prevAttrs - Previous attributes from indentation
|
|
27
|
-
*/
|
|
28
|
-
export function getPrevIndentLevel(prevAttrs) {
|
|
29
|
-
if (prevAttrs === undefined) {
|
|
30
|
-
return 0;
|
|
31
|
-
}
|
|
32
|
-
return prevAttrs.level;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Create a new dispatch function who add analytics events given a list of attributes changes
|
|
37
|
-
*
|
|
38
|
-
* @export
|
|
39
|
-
* @param {*} getAttrsChanges
|
|
40
|
-
* @param {*} state
|
|
41
|
-
* @param dispatch
|
|
42
|
-
* @returns
|
|
43
|
-
*/
|
|
44
|
-
export function createAnalyticsDispatch(_ref) {
|
|
45
|
-
var getAttrsChanges = _ref.getAttrsChanges,
|
|
46
|
-
inputMethod = _ref.inputMethod,
|
|
47
|
-
editorAnalyticsAPI = _ref.editorAnalyticsAPI,
|
|
48
|
-
state = _ref.state,
|
|
49
|
-
dispatch = _ref.dispatch;
|
|
50
|
-
return function (tr) {
|
|
51
|
-
var currentTr = tr;
|
|
52
|
-
var changes = getAttrsChanges(); // Get all attributes changes
|
|
53
|
-
|
|
54
|
-
// Add analytics event for each change stored.
|
|
55
|
-
changes.forEach(function (_ref2) {
|
|
56
|
-
var node = _ref2.node,
|
|
57
|
-
prevAttrs = _ref2.prevAttrs,
|
|
58
|
-
newAttrs = _ref2.newAttrs,
|
|
59
|
-
direction = _ref2.options.direction;
|
|
60
|
-
var indentType = indentTypes[node.type.name];
|
|
61
|
-
if (!indentType) {
|
|
62
|
-
return; // If no valid indent type continue
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
66
|
-
action: ACTION.FORMATTED,
|
|
67
|
-
actionSubject: ACTION_SUBJECT.TEXT,
|
|
68
|
-
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_INDENT,
|
|
69
|
-
eventType: EVENT_TYPE.TRACK,
|
|
70
|
-
attributes: {
|
|
71
|
-
inputMethod: inputMethod,
|
|
72
|
-
previousIndentationLevel: getPrevIndentLevel(prevAttrs),
|
|
73
|
-
newIndentLevel: getNewIndentLevel(prevAttrs, newAttrs),
|
|
74
|
-
direction: direction,
|
|
75
|
-
indentType: indentType
|
|
76
|
-
}
|
|
77
|
-
})(currentTr);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// Dispatch analytics if exist
|
|
81
|
-
if (dispatch) {
|
|
82
|
-
dispatch(tr);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create a new getAttrs handler who will wrap the original function,
|
|
3
|
-
* and store the changes internally to be used for other
|
|
4
|
-
* tools like Analytics later in the code.
|
|
5
|
-
*
|
|
6
|
-
* @param getAttrs - Function who gets the new attributes
|
|
7
|
-
* @return object
|
|
8
|
-
* @property handler - New handler to get indentation attributes (It wraps the original)
|
|
9
|
-
* @property getChanges - Return all the stored changes.
|
|
10
|
-
* @property clear - Clear the changes
|
|
11
|
-
*/
|
|
12
|
-
export default function getAttrsWithChangesRecorder(getAttrs, options) {
|
|
13
|
-
var changes = [];
|
|
14
|
-
function getAttrsWithChangesRecorder(prevAttrs, node) {
|
|
15
|
-
var newAttrs = getAttrs(prevAttrs, node);
|
|
16
|
-
changes.push({
|
|
17
|
-
node: node,
|
|
18
|
-
prevAttrs: prevAttrs,
|
|
19
|
-
newAttrs: newAttrs,
|
|
20
|
-
options: options
|
|
21
|
-
});
|
|
22
|
-
return newAttrs;
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
getAttrs: getAttrsWithChangesRecorder,
|
|
26
|
-
getAndResetAttrsChanges: function getAndResetAttrsChanges() {
|
|
27
|
-
var oldChanges = changes;
|
|
28
|
-
changes = [];
|
|
29
|
-
return oldChanges;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|