@atlaskit/editor-core 187.35.7 → 187.37.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/index.js +10 -17
  3. package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/index.js +3 -3
  4. package/dist/cjs/plugins/rule/commands.js +11 -9
  5. package/dist/cjs/plugins/rule/index.js +17 -9
  6. package/dist/cjs/plugins/rule/pm-plugins/input-rule.js +10 -9
  7. package/dist/cjs/plugins/rule/pm-plugins/keymap.js +2 -2
  8. package/dist/cjs/plugins/tasks-and-decisions/commands.js +13 -6
  9. package/dist/cjs/plugins/tasks-and-decisions/pm-plugins/input-rules.js +15 -7
  10. package/dist/cjs/version-wrapper.js +1 -1
  11. package/dist/es2019/index.js +0 -1
  12. package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/index.js +3 -3
  13. package/dist/es2019/plugins/rule/commands.js +2 -2
  14. package/dist/es2019/plugins/rule/index.js +19 -7
  15. package/dist/es2019/plugins/rule/pm-plugins/input-rule.js +11 -11
  16. package/dist/es2019/plugins/rule/pm-plugins/keymap.js +2 -2
  17. package/dist/es2019/plugins/tasks-and-decisions/commands.js +9 -7
  18. package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/input-rules.js +11 -5
  19. package/dist/es2019/version-wrapper.js +1 -1
  20. package/dist/esm/index.js +0 -1
  21. package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/index.js +3 -3
  22. package/dist/esm/plugins/rule/commands.js +11 -9
  23. package/dist/esm/plugins/rule/index.js +15 -7
  24. package/dist/esm/plugins/rule/pm-plugins/input-rule.js +11 -11
  25. package/dist/esm/plugins/rule/pm-plugins/keymap.js +2 -2
  26. package/dist/esm/plugins/tasks-and-decisions/commands.js +12 -6
  27. package/dist/esm/plugins/tasks-and-decisions/pm-plugins/input-rules.js +14 -7
  28. package/dist/esm/version-wrapper.js +1 -1
  29. package/dist/types/index.d.ts +0 -1
  30. package/dist/types/plugins/insert-block/types.d.ts +2 -0
  31. package/dist/types/plugins/rule/commands.d.ts +3 -4
  32. package/dist/types/plugins/rule/index.d.ts +9 -3
  33. package/dist/types/plugins/rule/pm-plugins/input-rule.d.ts +5 -4
  34. package/dist/types/plugins/rule/pm-plugins/keymap.d.ts +2 -1
  35. package/dist/types/plugins/tasks-and-decisions/commands.d.ts +4 -4
  36. package/dist/types/plugins/tasks-and-decisions/types.d.ts +3 -0
  37. package/dist/types-ts4.5/index.d.ts +0 -1
  38. package/dist/types-ts4.5/plugins/insert-block/types.d.ts +2 -0
  39. package/dist/types-ts4.5/plugins/rule/commands.d.ts +3 -4
  40. package/dist/types-ts4.5/plugins/rule/index.d.ts +10 -3
  41. package/dist/types-ts4.5/plugins/rule/pm-plugins/input-rule.d.ts +5 -4
  42. package/dist/types-ts4.5/plugins/rule/pm-plugins/keymap.d.ts +2 -1
  43. package/dist/types-ts4.5/plugins/tasks-and-decisions/commands.d.ts +4 -4
  44. package/dist/types-ts4.5/plugins/tasks-and-decisions/types.d.ts +3 -0
  45. package/package.json +2 -2
  46. package/report.api.md +8 -11
  47. package/tmp/api-report-tmp.d.ts +6 -3
@@ -1,10 +1,9 @@
1
1
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
2
- import { createRule, createPlugin } from '@atlaskit/prosemirror-input-rules';
3
- import { leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
2
+ import { createRule, createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
4
3
  import { safeInsert } from '@atlaskit/editor-common/insert';
5
4
  import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
6
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, addAnalytics, EVENT_TYPE, INPUT_METHOD } from '../../analytics';
7
- export const createHorizontalRule = (state, featureFlags, start, end, inputMethod) => {
5
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
+ export const createHorizontalRule = (state, featureFlags, start, end, inputMethod, editorAnalyticsAPI) => {
8
7
  if (!state.selection.empty) {
9
8
  return null;
10
9
  }
@@ -27,7 +26,7 @@ export const createHorizontalRule = (state, featureFlags, start, end, inputMetho
27
26
  if (!tr) {
28
27
  tr = state.tr.replaceRange(start, end, new Slice(Fragment.from(state.schema.nodes.rule.createChecked()), 0, 0));
29
28
  }
30
- return addAnalytics(state, tr, {
29
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
31
30
  action: ACTION.INSERTED,
32
31
  actionSubject: ACTION_SUBJECT.DOCUMENT,
33
32
  actionSubjectId: ACTION_SUBJECT_ID.DIVIDER,
@@ -35,22 +34,23 @@ export const createHorizontalRule = (state, featureFlags, start, end, inputMetho
35
34
  inputMethod
36
35
  },
37
36
  eventType: EVENT_TYPE.TRACK
38
- });
37
+ })(tr);
38
+ return tr;
39
39
  };
40
- const createHorizontalRuleAutoformat = (state, featureFlags, start, end) => {
40
+ const createHorizontalRuleAutoformat = (state, featureFlags, start, end, editorAnalyticsAPI) => {
41
41
  const {
42
42
  listItem
43
43
  } = state.schema.nodes;
44
44
  if (hasParentNodeOfType(listItem)(state.selection)) {
45
45
  return null;
46
46
  }
47
- return createHorizontalRule(state, featureFlags, start, end, INPUT_METHOD.FORMATTING);
47
+ return createHorizontalRule(state, featureFlags, start, end, INPUT_METHOD.FORMATTING, editorAnalyticsAPI);
48
48
  };
49
- export function inputRulePlugin(schema, featureFlags) {
49
+ export function inputRulePlugin(schema, featureFlags, editorAnalyticsAPI) {
50
50
  const rules = [];
51
51
  if (schema.nodes.rule) {
52
52
  // '---' and '***' for hr
53
- rules.push(createRule(/^(\-\-\-|\*\*\*)$/, (state, _match, start, end) => createHorizontalRuleAutoformat(state, featureFlags, start, end)));
53
+ rules.push(createRule(/^(\-\-\-|\*\*\*)$/, (state, _match, start, end) => createHorizontalRuleAutoformat(state, featureFlags, start, end, editorAnalyticsAPI)));
54
54
 
55
55
  // '---' and '***' after shift+enter for hr
56
56
  rules.push(createRule(new RegExp(`${leafNodeReplacementCharacter}(\\-\\-\\-|\\*\\*\\*)`), (state, _match, start, end) => {
@@ -60,7 +60,7 @@ export function inputRulePlugin(schema, featureFlags) {
60
60
  if (state.doc.resolve(start).nodeAfter.type !== hardBreak) {
61
61
  return null;
62
62
  }
63
- return createHorizontalRuleAutoformat(state, featureFlags, start, end);
63
+ return createHorizontalRuleAutoformat(state, featureFlags, start, end, editorAnalyticsAPI);
64
64
  }));
65
65
  }
66
66
  if (rules.length !== 0) {
@@ -2,9 +2,9 @@ import { keymap } from '@atlaskit/editor-prosemirror/keymap';
2
2
  import { bindKeymapWithCommand, insertRule, escape } from '@atlaskit/editor-common/keymaps';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
4
  import { insertHorizontalRule } from '../commands';
5
- export function keymapPlugin(featureFlags) {
5
+ export function keymapPlugin(featureFlags, editorAnalyticsAPI) {
6
6
  const list = {};
7
- bindKeymapWithCommand(insertRule.common, insertHorizontalRule(INPUT_METHOD.SHORTCUT, featureFlags), list);
7
+ bindKeymapWithCommand(insertRule.common, insertHorizontalRule(featureFlags, editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
8
8
  bindKeymapWithCommand(escape.common, () => true, list);
9
9
  return keymap(list);
10
10
  }
@@ -65,7 +65,7 @@ export const getListTypes = (listType, schema) => {
65
65
  item: decisionItem
66
66
  };
67
67
  };
68
- export const insertTaskDecisionAction = (state, listType, inputMethod = INPUT_METHOD.TOOLBAR, addItem, listLocalId, itemLocalId) => {
68
+ export const insertTaskDecisionAction = (state, listType, inputMethod = INPUT_METHOD.TOOLBAR, addItem, listLocalId, itemLocalId, itemAttrs) => {
69
69
  const {
70
70
  schema
71
71
  } = state;
@@ -75,7 +75,7 @@ export const insertTaskDecisionAction = (state, listType, inputMethod = INPUT_ME
75
75
  item,
76
76
  listLocalId,
77
77
  itemLocalId
78
- }) => createListAtSelection(tr, list, item, schema, state, listLocalId, itemLocalId);
78
+ }) => createListAtSelection(tr, list, item, schema, state, listLocalId, itemLocalId, itemAttrs);
79
79
  const addToList = ({
80
80
  state,
81
81
  tr,
@@ -95,7 +95,7 @@ export const insertTaskDecisionAction = (state, listType, inputMethod = INPUT_ME
95
95
  }]).setSelection(new TextSelection(tr.doc.resolve(newItemParagraphPos)));
96
96
  };
97
97
  const addAndCreateListFn = addItem !== null && addItem !== void 0 ? addItem : addAndCreateList;
98
- const tr = insertTaskDecisionWithAnalytics(state, listType, inputMethod, addAndCreateListFn, addToList, listLocalId, itemLocalId);
98
+ const tr = insertTaskDecisionWithAnalytics(state, listType, inputMethod, addAndCreateListFn, addToList, listLocalId, itemLocalId, itemAttrs);
99
99
  if (!tr) {
100
100
  return state.tr;
101
101
  }
@@ -109,7 +109,7 @@ export const insertTaskDecisionCommand = (listType, inputMethod = INPUT_METHOD.T
109
109
  }
110
110
  return true;
111
111
  };
112
- export const insertTaskDecisionWithAnalytics = (state, listType, inputMethod, addAndCreateList, addToList, listLocalId, itemLocalId) => {
112
+ export const insertTaskDecisionWithAnalytics = (state, listType, inputMethod, addAndCreateList, addToList, listLocalId, itemLocalId, itemAttrs) => {
113
113
  const {
114
114
  schema
115
115
  } = state;
@@ -150,7 +150,8 @@ export const insertTaskDecisionWithAnalytics = (state, listType, inputMethod, ad
150
150
  list,
151
151
  item,
152
152
  listLocalId,
153
- itemLocalId
153
+ itemLocalId,
154
+ itemAttrs
154
155
  });
155
156
  if (insertTr) {
156
157
  insertTr = addAnalytics(state, insertTr, generateAnalyticsPayload(listType, contextData, inputMethod, itemLocalId, listLocalId, itemIdx || 0, listSize || 0));
@@ -169,7 +170,7 @@ export const isSupportedSourceNode = (schema, selection) => {
169
170
  return hasParentNodeOfType([blockquote, paragraph, decisionList, taskList])(selection);
170
171
  };
171
172
  export const changeInDepth = (before, after) => after.depth - before.depth;
172
- export const createListAtSelection = (tr, list, item, schema, state, listLocalId = uuid.generate(), itemLocalId = uuid.generate()) => {
173
+ export const createListAtSelection = (tr, list, item, schema, state, listLocalId = uuid.generate(), itemLocalId = uuid.generate(), itemAttrs) => {
173
174
  const {
174
175
  selection
175
176
  } = state;
@@ -196,7 +197,8 @@ export const createListAtSelection = (tr, list, item, schema, state, listLocalId
196
197
  const emptyList = list.create({
197
198
  localId: listLocalId
198
199
  }, [item.create({
199
- localId: itemLocalId
200
+ localId: itemLocalId,
201
+ ...itemAttrs
200
202
  })]);
201
203
 
202
204
  // we don't take the content of a block node next to the gap cursor and always create an empty task
@@ -4,7 +4,7 @@ import { createRule, createPlugin } from '@atlaskit/prosemirror-input-rules';
4
4
  import { leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
5
5
  import { INPUT_METHOD } from '../../analytics';
6
6
  import { changeInDepth, insertTaskDecisionAction, getListTypes } from '../commands';
7
- const createListRule = (regex, listType) => {
7
+ const createListRule = (regex, listType, itemAttrs) => {
8
8
  return createRule(regex, (state, _match, start, end) => {
9
9
  const {
10
10
  paragraph
@@ -19,7 +19,7 @@ const createListRule = (regex, listType) => {
19
19
  if ($end.parent.type !== paragraph || !canInsert($endOfParent, list.createAndFill())) {
20
20
  return null;
21
21
  }
22
- const insertTr = insertTaskDecisionAction(state, listType, INPUT_METHOD.FORMATTING, addItem(start, end));
22
+ const insertTr = insertTaskDecisionAction(state, listType, INPUT_METHOD.FORMATTING, addItem(start, end), undefined, undefined, itemAttrs);
23
23
  return insertTr;
24
24
  });
25
25
  };
@@ -29,7 +29,8 @@ const addItem = (start, end) => ({
29
29
  list,
30
30
  item,
31
31
  listLocalId,
32
- itemLocalId
32
+ itemLocalId,
33
+ itemAttrs
33
34
  }) => {
34
35
  const {
35
36
  selection: {
@@ -51,14 +52,16 @@ const addItem = (start, end) => ({
51
52
  tr.replaceRangeWith($from.before(), $from.after(), list.create({
52
53
  localId: listLocalId
53
54
  }, [item.create({
54
- localId: itemLocalId
55
+ localId: itemLocalId,
56
+ ...itemAttrs
55
57
  }, content)])).delete(start + 1, end + 1).setSelection(new TextSelection(tr.doc.resolve(start + 1)));
56
58
  } else {
57
59
  const depthAdjustment = changeInDepth($from, tr.selection.$from);
58
60
  tr.split($from.pos).setSelection(new NodeSelection(tr.doc.resolve($from.pos + 1))).replaceSelectionWith(list.create({
59
61
  localId: listLocalId
60
62
  }, [item.create({
61
- localId: itemLocalId
63
+ localId: itemLocalId,
64
+ ...itemAttrs
62
65
  },
63
66
  // TODO: [ts30] handle void and null properly
64
67
  tr.doc.nodeAt($from.pos + 1).content)])).setSelection(new TextSelection(tr.doc.resolve($from.pos + depthAdjustment))).delete(start, end + 1);
@@ -78,6 +81,9 @@ export function inputRulePlugin(schema, featureFlags) {
78
81
  }
79
82
  if (taskList && taskItem) {
80
83
  rules.push(createListRule(new RegExp(`(^|${leafNodeReplacementCharacter})\\[\\]\\s$`), 'taskList'));
84
+ rules.push(createListRule(new RegExp(`(^|${leafNodeReplacementCharacter})\\[x\\]\\s$`), 'taskList', {
85
+ state: 'DONE'
86
+ }));
81
87
  }
82
88
  return createPlugin('tasks-and-decisions', rules, {
83
89
  isBlockNodeRule: true
@@ -1,5 +1,5 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "187.35.7";
2
+ export const version = "187.37.0";
3
3
  export const nextMajorVersion = () => {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
package/dist/esm/index.js CHANGED
@@ -18,7 +18,6 @@ export { AnnotationUpdateEmitter } from './plugins/annotation';
18
18
  export { stateKey as mediaPluginKey } from './plugins/media/pm-plugins/main';
19
19
  export { textColorPluginKey } from './plugins/text-color';
20
20
  export { changeColor } from './plugins/text-color/commands/change-color';
21
- export { insertHorizontalRule } from './plugins/rule/commands';
22
21
 
23
22
  /**
24
23
  * @private
@@ -30,7 +30,6 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } f
30
30
  import { messages } from './messages';
31
31
  import { createItems } from './create-items';
32
32
  import { BlockInsertMenu } from './block-insert-menu';
33
- import { insertHorizontalRule } from '../../../rule/commands';
34
33
  import withOuterListeners from '../../../../ui/with-outer-listeners';
35
34
 
36
35
  /**
@@ -250,12 +249,13 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
250
249
  };
251
250
  });
252
251
  _defineProperty(_assertThisInitialized(_this), "insertHorizontalRule", function (inputMethod) {
252
+ var _pluginInjectionApi$r, _pluginInjectionApi$r2;
253
253
  var _this$props4 = _this.props,
254
254
  _this$props4$editorVi = _this$props4.editorView,
255
255
  state = _this$props4$editorVi.state,
256
256
  dispatch = _this$props4$editorVi.dispatch,
257
- featureFlags = _this$props4.featureFlags;
258
- return insertHorizontalRule(inputMethod, featureFlags)(state, dispatch);
257
+ pluginInjectionApi = _this$props4.pluginInjectionApi;
258
+ return (_pluginInjectionApi$r = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$r2 = pluginInjectionApi.rule) === null || _pluginInjectionApi$r2 === void 0 ? void 0 : _pluginInjectionApi$r2.actions.insertHorizontalRule(inputMethod)(state, dispatch)) !== null && _pluginInjectionApi$r !== void 0 ? _pluginInjectionApi$r : false;
259
259
  });
260
260
  _defineProperty(_assertThisInitialized(_this), "insertExpand", function () {
261
261
  var _this$props$editorVie2 = _this.props.editorView,
@@ -1,13 +1,15 @@
1
1
  import { createHorizontalRule } from './pm-plugins/input-rule';
2
- export var insertHorizontalRule = function insertHorizontalRule(inputMethod, featureFlags) {
3
- return function (state, dispatch) {
4
- var tr = createHorizontalRule(state, featureFlags, state.selection.from, state.selection.to, inputMethod);
5
- if (tr) {
6
- if (dispatch) {
7
- dispatch(tr);
2
+ export var insertHorizontalRule = function insertHorizontalRule(featureFlags, editorAnalyticsAPI) {
3
+ return function (inputMethod) {
4
+ return function (state, dispatch) {
5
+ var tr = createHorizontalRule(state, featureFlags, state.selection.from, state.selection.to, inputMethod, editorAnalyticsAPI);
6
+ if (tr) {
7
+ if (dispatch) {
8
+ dispatch(tr);
9
+ }
10
+ return true;
8
11
  }
9
- return true;
10
- }
11
- return false;
12
+ return false;
13
+ };
12
14
  };
13
15
  };
@@ -1,12 +1,13 @@
1
1
  import React from 'react';
2
2
  import { rule } from '@atlaskit/adf-schema';
3
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, addAnalytics, EVENT_TYPE, INPUT_METHOD } from '../analytics';
4
- import { messages } from '../insert-block/ui/ToolbarInsertBlock/messages';
3
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
5
5
  import { IconDivider } from '@atlaskit/editor-common/quick-insert';
6
6
  import inputRulePlugin from './pm-plugins/input-rule';
7
7
  import keymapPlugin from './pm-plugins/keymap';
8
+ import { insertHorizontalRule } from './commands';
8
9
  var rulePlugin = function rulePlugin(_ref) {
9
- var _api$featureFlags;
10
+ var _api$featureFlags, _api$analytics;
10
11
  var api = _ref.api;
11
12
  var featureFlags = (api === null || api === void 0 ? void 0 : (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
12
13
  return {
@@ -17,17 +18,22 @@ var rulePlugin = function rulePlugin(_ref) {
17
18
  node: rule
18
19
  }];
19
20
  },
21
+ actions: {
22
+ insertHorizontalRule: insertHorizontalRule(featureFlags, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
23
+ },
20
24
  pmPlugins: function pmPlugins() {
21
25
  return [{
22
26
  name: 'ruleInputRule',
23
27
  plugin: function plugin(_ref2) {
28
+ var _api$analytics2;
24
29
  var schema = _ref2.schema;
25
- return inputRulePlugin(schema, featureFlags);
30
+ return inputRulePlugin(schema, featureFlags, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
26
31
  }
27
32
  }, {
28
33
  name: 'ruleKeymap',
29
34
  plugin: function plugin() {
30
- return keymapPlugin(featureFlags);
35
+ var _api$analytics3;
36
+ return keymapPlugin(featureFlags, api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
31
37
  }
32
38
  }];
33
39
  },
@@ -45,8 +51,9 @@ var rulePlugin = function rulePlugin(_ref) {
45
51
  return /*#__PURE__*/React.createElement(IconDivider, null);
46
52
  },
47
53
  action: function action(insert, state) {
54
+ var _api$analytics4;
48
55
  var tr = insert(state.schema.nodes.rule.createChecked());
49
- return addAnalytics(state, tr, {
56
+ api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions.attachAnalyticsEvent({
50
57
  action: ACTION.INSERTED,
51
58
  actionSubject: ACTION_SUBJECT.DOCUMENT,
52
59
  actionSubjectId: ACTION_SUBJECT_ID.DIVIDER,
@@ -54,7 +61,8 @@ var rulePlugin = function rulePlugin(_ref) {
54
61
  inputMethod: INPUT_METHOD.QUICK_INSERT
55
62
  },
56
63
  eventType: EVENT_TYPE.TRACK
57
- });
64
+ })(tr);
65
+ return tr;
58
66
  }
59
67
  }];
60
68
  }
@@ -1,10 +1,9 @@
1
1
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
2
- import { createRule, createPlugin } from '@atlaskit/prosemirror-input-rules';
3
- import { leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
2
+ import { createRule, createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
4
3
  import { safeInsert } from '@atlaskit/editor-common/insert';
5
4
  import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
6
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, addAnalytics, EVENT_TYPE, INPUT_METHOD } from '../../analytics';
7
- export var createHorizontalRule = function createHorizontalRule(state, featureFlags, start, end, inputMethod) {
5
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
+ export var createHorizontalRule = function createHorizontalRule(state, featureFlags, start, end, inputMethod, editorAnalyticsAPI) {
8
7
  if (!state.selection.empty) {
9
8
  return null;
10
9
  }
@@ -23,7 +22,7 @@ export var createHorizontalRule = function createHorizontalRule(state, featureFl
23
22
  if (!tr) {
24
23
  tr = state.tr.replaceRange(start, end, new Slice(Fragment.from(state.schema.nodes.rule.createChecked()), 0, 0));
25
24
  }
26
- return addAnalytics(state, tr, {
25
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
27
26
  action: ACTION.INSERTED,
28
27
  actionSubject: ACTION_SUBJECT.DOCUMENT,
29
28
  actionSubjectId: ACTION_SUBJECT_ID.DIVIDER,
@@ -31,21 +30,22 @@ export var createHorizontalRule = function createHorizontalRule(state, featureFl
31
30
  inputMethod: inputMethod
32
31
  },
33
32
  eventType: EVENT_TYPE.TRACK
34
- });
33
+ })(tr);
34
+ return tr;
35
35
  };
36
- var createHorizontalRuleAutoformat = function createHorizontalRuleAutoformat(state, featureFlags, start, end) {
36
+ var createHorizontalRuleAutoformat = function createHorizontalRuleAutoformat(state, featureFlags, start, end, editorAnalyticsAPI) {
37
37
  var listItem = state.schema.nodes.listItem;
38
38
  if (hasParentNodeOfType(listItem)(state.selection)) {
39
39
  return null;
40
40
  }
41
- return createHorizontalRule(state, featureFlags, start, end, INPUT_METHOD.FORMATTING);
41
+ return createHorizontalRule(state, featureFlags, start, end, INPUT_METHOD.FORMATTING, editorAnalyticsAPI);
42
42
  };
43
- export function inputRulePlugin(schema, featureFlags) {
43
+ export function inputRulePlugin(schema, featureFlags, editorAnalyticsAPI) {
44
44
  var rules = [];
45
45
  if (schema.nodes.rule) {
46
46
  // '---' and '***' for hr
47
47
  rules.push(createRule(/^(\-\-\-|\*\*\*)$/, function (state, _match, start, end) {
48
- return createHorizontalRuleAutoformat(state, featureFlags, start, end);
48
+ return createHorizontalRuleAutoformat(state, featureFlags, start, end, editorAnalyticsAPI);
49
49
  }));
50
50
 
51
51
  // '---' and '***' after shift+enter for hr
@@ -54,7 +54,7 @@ export function inputRulePlugin(schema, featureFlags) {
54
54
  if (state.doc.resolve(start).nodeAfter.type !== hardBreak) {
55
55
  return null;
56
56
  }
57
- return createHorizontalRuleAutoformat(state, featureFlags, start, end);
57
+ return createHorizontalRuleAutoformat(state, featureFlags, start, end, editorAnalyticsAPI);
58
58
  }));
59
59
  }
60
60
  if (rules.length !== 0) {
@@ -2,9 +2,9 @@ import { keymap } from '@atlaskit/editor-prosemirror/keymap';
2
2
  import { bindKeymapWithCommand, insertRule, escape } from '@atlaskit/editor-common/keymaps';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
4
  import { insertHorizontalRule } from '../commands';
5
- export function keymapPlugin(featureFlags) {
5
+ export function keymapPlugin(featureFlags, editorAnalyticsAPI) {
6
6
  var list = {};
7
- bindKeymapWithCommand(insertRule.common, insertHorizontalRule(INPUT_METHOD.SHORTCUT, featureFlags), list);
7
+ bindKeymapWithCommand(insertRule.common, insertHorizontalRule(featureFlags, editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
8
8
  bindKeymapWithCommand(escape.common, function () {
9
9
  return true;
10
10
  }, list);
@@ -1,3 +1,6 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1
4
  import { NodeRange } from '@atlaskit/editor-prosemirror/model';
2
5
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
3
6
  import { findParentNodeOfType, hasParentNodeOfType, replaceParentNodeOfType, safeInsert, setTextSelection } from '@atlaskit/editor-prosemirror/utils';
@@ -66,6 +69,7 @@ export var insertTaskDecisionAction = function insertTaskDecisionAction(state, l
66
69
  var addItem = arguments.length > 3 ? arguments[3] : undefined;
67
70
  var listLocalId = arguments.length > 4 ? arguments[4] : undefined;
68
71
  var itemLocalId = arguments.length > 5 ? arguments[5] : undefined;
72
+ var itemAttrs = arguments.length > 6 ? arguments[6] : undefined;
69
73
  var schema = state.schema;
70
74
  var addAndCreateList = function addAndCreateList(_ref) {
71
75
  var tr = _ref.tr,
@@ -73,7 +77,7 @@ export var insertTaskDecisionAction = function insertTaskDecisionAction(state, l
73
77
  item = _ref.item,
74
78
  listLocalId = _ref.listLocalId,
75
79
  itemLocalId = _ref.itemLocalId;
76
- return createListAtSelection(tr, list, item, schema, state, listLocalId, itemLocalId);
80
+ return createListAtSelection(tr, list, item, schema, state, listLocalId, itemLocalId, itemAttrs);
77
81
  };
78
82
  var addToList = function addToList(_ref2) {
79
83
  var state = _ref2.state,
@@ -91,7 +95,7 @@ export var insertTaskDecisionAction = function insertTaskDecisionAction(state, l
91
95
  }]).setSelection(new TextSelection(tr.doc.resolve(newItemParagraphPos)));
92
96
  };
93
97
  var addAndCreateListFn = addItem !== null && addItem !== void 0 ? addItem : addAndCreateList;
94
- var tr = insertTaskDecisionWithAnalytics(state, listType, inputMethod, addAndCreateListFn, addToList, listLocalId, itemLocalId);
98
+ var tr = insertTaskDecisionWithAnalytics(state, listType, inputMethod, addAndCreateListFn, addToList, listLocalId, itemLocalId, itemAttrs);
95
99
  if (!tr) {
96
100
  return state.tr;
97
101
  }
@@ -111,7 +115,7 @@ export var insertTaskDecisionCommand = function insertTaskDecisionCommand(listTy
111
115
  return true;
112
116
  };
113
117
  };
114
- export var insertTaskDecisionWithAnalytics = function insertTaskDecisionWithAnalytics(state, listType, inputMethod, addAndCreateList, addToList, listLocalId, itemLocalId) {
118
+ export var insertTaskDecisionWithAnalytics = function insertTaskDecisionWithAnalytics(state, listType, inputMethod, addAndCreateList, addToList, listLocalId, itemLocalId, itemAttrs) {
115
119
  var schema = state.schema;
116
120
  var _getListTypes = getListTypes(listType, schema),
117
121
  list = _getListTypes.list,
@@ -145,7 +149,8 @@ export var insertTaskDecisionWithAnalytics = function insertTaskDecisionWithAnal
145
149
  list: list,
146
150
  item: item,
147
151
  listLocalId: listLocalId,
148
- itemLocalId: itemLocalId
152
+ itemLocalId: itemLocalId,
153
+ itemAttrs: itemAttrs
149
154
  });
150
155
  if (insertTr) {
151
156
  insertTr = addAnalytics(state, insertTr, generateAnalyticsPayload(listType, contextData, inputMethod, itemLocalId, listLocalId, itemIdx || 0, listSize || 0));
@@ -168,6 +173,7 @@ export var changeInDepth = function changeInDepth(before, after) {
168
173
  export var createListAtSelection = function createListAtSelection(tr, list, item, schema, state) {
169
174
  var listLocalId = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : uuid.generate();
170
175
  var itemLocalId = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : uuid.generate();
176
+ var itemAttrs = arguments.length > 7 ? arguments[7] : undefined;
171
177
  var selection = state.selection;
172
178
  var $from = selection.$from,
173
179
  $to = selection.$to;
@@ -188,9 +194,9 @@ export var createListAtSelection = function createListAtSelection(tr, list, item
188
194
  }
189
195
  var emptyList = list.create({
190
196
  localId: listLocalId
191
- }, [item.create({
197
+ }, [item.create(_objectSpread({
192
198
  localId: itemLocalId
193
- })]);
199
+ }, itemAttrs))]);
194
200
 
195
201
  // we don't take the content of a block node next to the gap cursor and always create an empty task
196
202
  if (selection instanceof GapCursorSelection) {
@@ -1,10 +1,13 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1
4
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
5
  import { canInsert } from '@atlaskit/editor-prosemirror/utils';
3
6
  import { createRule, createPlugin } from '@atlaskit/prosemirror-input-rules';
4
7
  import { leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
5
8
  import { INPUT_METHOD } from '../../analytics';
6
9
  import { changeInDepth, insertTaskDecisionAction, getListTypes } from '../commands';
7
- var createListRule = function createListRule(regex, listType) {
10
+ var createListRule = function createListRule(regex, listType, itemAttrs) {
8
11
  return createRule(regex, function (state, _match, start, end) {
9
12
  var paragraph = state.schema.nodes.paragraph;
10
13
  var _getListTypes = getListTypes(listType, state.schema),
@@ -16,7 +19,7 @@ var createListRule = function createListRule(regex, listType) {
16
19
  if ($end.parent.type !== paragraph || !canInsert($endOfParent, list.createAndFill())) {
17
20
  return null;
18
21
  }
19
- var insertTr = insertTaskDecisionAction(state, listType, INPUT_METHOD.FORMATTING, addItem(start, end));
22
+ var insertTr = insertTaskDecisionAction(state, listType, INPUT_METHOD.FORMATTING, addItem(start, end), undefined, undefined, itemAttrs);
20
23
  return insertTr;
21
24
  });
22
25
  };
@@ -27,7 +30,8 @@ var addItem = function addItem(start, end) {
27
30
  list = _ref.list,
28
31
  item = _ref.item,
29
32
  listLocalId = _ref.listLocalId,
30
- itemLocalId = _ref.itemLocalId;
33
+ itemLocalId = _ref.itemLocalId,
34
+ itemAttrs = _ref.itemAttrs;
31
35
  var $from = state.selection.$from,
32
36
  schema = state.schema;
33
37
  var hardBreak = schema.nodes.hardBreak;
@@ -41,16 +45,16 @@ var addItem = function addItem(start, end) {
41
45
  if (!shouldBreakNode) {
42
46
  tr.replaceRangeWith($from.before(), $from.after(), list.create({
43
47
  localId: listLocalId
44
- }, [item.create({
48
+ }, [item.create(_objectSpread({
45
49
  localId: itemLocalId
46
- }, content)])).delete(start + 1, end + 1).setSelection(new TextSelection(tr.doc.resolve(start + 1)));
50
+ }, itemAttrs), content)])).delete(start + 1, end + 1).setSelection(new TextSelection(tr.doc.resolve(start + 1)));
47
51
  } else {
48
52
  var depthAdjustment = changeInDepth($from, tr.selection.$from);
49
53
  tr.split($from.pos).setSelection(new NodeSelection(tr.doc.resolve($from.pos + 1))).replaceSelectionWith(list.create({
50
54
  localId: listLocalId
51
- }, [item.create({
55
+ }, [item.create(_objectSpread({
52
56
  localId: itemLocalId
53
- },
57
+ }, itemAttrs),
54
58
  // TODO: [ts30] handle void and null properly
55
59
  tr.doc.nodeAt($from.pos + 1).content)])).setSelection(new TextSelection(tr.doc.resolve($from.pos + depthAdjustment))).delete(start, end + 1);
56
60
  }
@@ -69,6 +73,9 @@ export function inputRulePlugin(schema, featureFlags) {
69
73
  }
70
74
  if (taskList && taskItem) {
71
75
  rules.push(createListRule(new RegExp("(^|".concat(leafNodeReplacementCharacter, ")\\[\\]\\s$")), 'taskList'));
76
+ rules.push(createListRule(new RegExp("(^|".concat(leafNodeReplacementCharacter, ")\\[x\\]\\s$")), 'taskList', {
77
+ state: 'DONE'
78
+ }));
72
79
  }
73
80
  return createPlugin('tasks-and-decisions', rules, {
74
81
  isBlockNodeRule: true
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "187.35.7";
2
+ export var version = "187.37.0";
3
3
  export var nextMajorVersion = function nextMajorVersion() {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -22,7 +22,6 @@ export { stateKey as mediaPluginKey } from './plugins/media/pm-plugins/main';
22
22
  export { textColorPluginKey } from './plugins/text-color';
23
23
  export type { TextColorPluginState } from './plugins/text-color';
24
24
  export { changeColor } from './plugins/text-color/commands/change-color';
25
- export { insertHorizontalRule } from './plugins/rule/commands';
26
25
  export type { BlockTypeState } from './plugins/block-type/pm-plugins/main';
27
26
  /**
28
27
  * @private
@@ -11,6 +11,7 @@ import type quickInsertPlugin from '../quick-insert';
11
11
  import type blockTypePlugin from '../block-type';
12
12
  import type codeBlockPlugin from '../code-block';
13
13
  import type panelPlugin from '../panel';
14
+ import type { RulePlugin } from '../rule';
14
15
  export type InsertBlockPluginDependencies = [
15
16
  FeatureFlagsPlugin,
16
17
  OptionalPlugin<typeof tablesPlugin>,
@@ -22,6 +23,7 @@ export type InsertBlockPluginDependencies = [
22
23
  OptionalPlugin<typeof mentionsPlugin>,
23
24
  OptionalPlugin<EmojiPlugin>,
24
25
  OptionalPlugin<typeof quickInsertPlugin>,
26
+ OptionalPlugin<RulePlugin>,
25
27
  OptionalPlugin<typeof codeBlockPlugin>,
26
28
  OptionalPlugin<typeof panelPlugin>
27
29
  ];
@@ -1,4 +1,3 @@
1
- import { FeatureFlags } from '@atlaskit/editor-common/types';
2
- import { Command } from '../../types';
3
- import { INPUT_METHOD } from '../analytics';
4
- export declare const insertHorizontalRule: (inputMethod: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT, featureFlags: FeatureFlags) => Command;
1
+ import type { FeatureFlags, Command } from '@atlaskit/editor-common/types';
2
+ import type { INPUT_METHOD, EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
+ export declare const insertHorizontalRule: (featureFlags: FeatureFlags, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT) => Command;
@@ -1,7 +1,13 @@
1
- import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
1
+ import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import { insertHorizontalRule } from './commands';
2
3
  import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
3
- declare const rulePlugin: NextEditorPlugin<'rule', {
4
+ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
5
+ export type RulePlugin = NextEditorPlugin<'rule', {
4
6
  pluginConfiguration: undefined;
5
- dependencies: [FeatureFlagsPlugin];
7
+ dependencies: [FeatureFlagsPlugin, OptionalPlugin<AnalyticsPlugin>];
8
+ actions: {
9
+ insertHorizontalRule: ReturnType<typeof insertHorizontalRule>;
10
+ };
6
11
  }>;
12
+ declare const rulePlugin: RulePlugin;
7
13
  export default rulePlugin;
@@ -1,8 +1,9 @@
1
1
  import type { Schema } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
- import type { FeatureFlags } from '../../../types/feature-flags';
5
- import { INPUT_METHOD } from '../../analytics';
6
- export declare const createHorizontalRule: (state: EditorState, featureFlags: FeatureFlags, start: number, end: number, inputMethod: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT) => Transaction | null;
7
- export declare function inputRulePlugin(schema: Schema, featureFlags: FeatureFlags): SafePlugin | undefined;
4
+ import type { FeatureFlags } from '@atlaskit/editor-common/types';
5
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
6
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
+ export declare const createHorizontalRule: (state: EditorState, featureFlags: FeatureFlags, start: number, end: number, inputMethod: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.FORMATTING | INPUT_METHOD.SHORTCUT, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Transaction | null;
8
+ export declare function inputRulePlugin(schema: Schema, featureFlags: FeatureFlags, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin | undefined;
8
9
  export default inputRulePlugin;
@@ -1,4 +1,5 @@
1
1
  import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
3
  import type { FeatureFlags } from '@atlaskit/editor-common/types';
3
- export declare function keymapPlugin(featureFlags: FeatureFlags): SafePlugin;
4
+ export declare function keymapPlugin(featureFlags: FeatureFlags, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin;
4
5
  export default keymapPlugin;