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