@atlaskit/editor-core 185.12.1 → 185.13.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 (34) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugins/block-type/commands/block-type.js +79 -44
  3. package/dist/cjs/plugins/block-type/ui/ToolbarBlockType/blocktype-button.js +2 -1
  4. package/dist/cjs/plugins/code-block/index.js +7 -3
  5. package/dist/cjs/plugins/expand/commands.js +6 -2
  6. package/dist/cjs/plugins/expand/index.js +5 -1
  7. package/dist/cjs/plugins/panel/index.js +81 -43
  8. package/dist/cjs/plugins/quick-insert/commands.js +2 -0
  9. package/dist/cjs/ui/ElementBrowser/InsertMenu.js +10 -0
  10. package/dist/cjs/version-wrapper.js +1 -1
  11. package/dist/cjs/version.json +1 -1
  12. package/dist/es2019/plugins/block-type/commands/block-type.js +86 -51
  13. package/dist/es2019/plugins/block-type/ui/ToolbarBlockType/blocktype-button.js +2 -1
  14. package/dist/es2019/plugins/code-block/index.js +7 -2
  15. package/dist/es2019/plugins/expand/commands.js +6 -2
  16. package/dist/es2019/plugins/expand/index.js +5 -1
  17. package/dist/es2019/plugins/panel/index.js +82 -41
  18. package/dist/es2019/plugins/quick-insert/commands.js +2 -0
  19. package/dist/es2019/ui/ElementBrowser/InsertMenu.js +10 -0
  20. package/dist/es2019/version-wrapper.js +1 -1
  21. package/dist/es2019/version.json +1 -1
  22. package/dist/esm/plugins/block-type/commands/block-type.js +76 -43
  23. package/dist/esm/plugins/block-type/ui/ToolbarBlockType/blocktype-button.js +2 -1
  24. package/dist/esm/plugins/code-block/index.js +7 -2
  25. package/dist/esm/plugins/expand/commands.js +6 -2
  26. package/dist/esm/plugins/expand/index.js +5 -1
  27. package/dist/esm/plugins/panel/index.js +81 -43
  28. package/dist/esm/plugins/quick-insert/commands.js +2 -0
  29. package/dist/esm/ui/ElementBrowser/InsertMenu.js +10 -0
  30. package/dist/esm/version-wrapper.js +1 -1
  31. package/dist/esm/version.json +1 -1
  32. package/dist/types/plugins/block-type/commands/block-type.d.ts +25 -0
  33. package/dist/types-ts4.5/plugins/block-type/commands/block-type.d.ts +25 -0
  34. package/package.json +3 -3
@@ -2,12 +2,12 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
4
  import { TextSelection } from 'prosemirror-state';
5
- import { safeInsert } from 'prosemirror-utils';
6
5
  import { findTable } from '@atlaskit/editor-tables/utils';
7
6
  import { addAnalytics, ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD, EVENT_TYPE, PLATFORMS, MODE } from '../analytics';
8
7
  import { GapCursorSelection, Side } from '../selection/gap-cursor-selection';
9
8
  import { findExpand } from './utils';
10
9
  import { createCommand } from './pm-plugins/plugin-factory';
10
+ import { createWrapSelectionTransaction } from '../block-type/commands/block-type';
11
11
  export var setExpandRef = function setExpandRef(ref) {
12
12
  return createCommand({
13
13
  type: 'SET_EXPAND_REF',
@@ -105,6 +105,10 @@ export var createExpandNode = function createExpandNode(state) {
105
105
  };
106
106
  export var insertExpand = function insertExpand(state, dispatch) {
107
107
  var expandNode = createExpandNode(state);
108
+ var tr = createWrapSelectionTransaction({
109
+ state: state,
110
+ type: state.schema.nodes.expand
111
+ });
108
112
  var payload = {
109
113
  action: ACTION.INSERTED,
110
114
  actionSubject: ACTION_SUBJECT.DOCUMENT,
@@ -115,7 +119,7 @@ export var insertExpand = function insertExpand(state, dispatch) {
115
119
  eventType: EVENT_TYPE.TRACK
116
120
  };
117
121
  if (dispatch && expandNode) {
118
- dispatch(addAnalytics(state, safeInsert(expandNode)(state.tr).scrollIntoView(), payload));
122
+ dispatch(addAnalytics(state, tr, payload));
119
123
  }
120
124
  return true;
121
125
  };
@@ -8,6 +8,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, addAnalytics, EVENT_TYPE, IN
8
8
  import { getToolbarConfig } from './toolbar';
9
9
  import { createExpandNode } from './commands';
10
10
  import { messages } from '../insert-block/ui/ToolbarInsertBlock/messages';
11
+ import { createWrapSelectionTransaction } from '../block-type/commands/block-type';
11
12
  var expandPlugin = function expandPlugin() {
12
13
  var _api$dependencies, _api$dependencies$fea;
13
14
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -58,7 +59,10 @@ var expandPlugin = function expandPlugin() {
58
59
  if (!node) {
59
60
  return false;
60
61
  }
61
- var tr = insert(node);
62
+ var tr = createWrapSelectionTransaction({
63
+ state: state,
64
+ type: state.schema.nodes.expand
65
+ });
62
66
  return addAnalytics(state, tr, {
63
67
  action: ACTION.INSERTED,
64
68
  actionSubject: ACTION_SUBJECT.DOCUMENT,
@@ -8,25 +8,10 @@ import { IconPanel, IconPanelNote, IconPanelSuccess, IconPanelWarning, IconPanel
8
8
  import { messages } from '../block-type/messages';
9
9
  import IconCustomPanel from '../quick-insert/assets/custom-panel';
10
10
  import { T50 } from '@atlaskit/theme/colors';
11
- var insertPanelTypeWithAnalytics = function insertPanelTypeWithAnalytics(panelAttributes, state, insert) {
12
- var tr = insert(insertPanelType(panelAttributes, state));
13
- if (tr) {
14
- addAnalytics(state, tr, {
15
- action: ACTION.INSERTED,
16
- actionSubject: ACTION_SUBJECT.DOCUMENT,
17
- actionSubjectId: ACTION_SUBJECT_ID.PANEL,
18
- attributes: {
19
- inputMethod: INPUT_METHOD.QUICK_INSERT,
20
- panelType: panelAttributes.panelType
21
- },
22
- eventType: EVENT_TYPE.TRACK
23
- });
24
- }
25
- return tr;
26
- };
27
- var insertPanelType = function insertPanelType(panelAttributes, state) {
28
- return state.schema.nodes.panel.createChecked(panelAttributes, state.schema.nodes.paragraph.createChecked());
29
- };
11
+ // Theres an existing interelationship between these files, where the imported function is being called for panel
12
+ // Insertions via the drop down menu
13
+ // tslint-ignore-next-line
14
+ import { createWrapSelectionTransaction } from '../block-type/commands/block-type';
30
15
  var panelPlugin = function panelPlugin() {
31
16
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
32
17
  var api = arguments.length > 1 ? arguments[1] : undefined;
@@ -67,9 +52,12 @@ var panelPlugin = function panelPlugin() {
67
52
  return /*#__PURE__*/React.createElement(IconPanel, null);
68
53
  },
69
54
  action: function action(insert, state) {
70
- return insertPanelTypeWithAnalytics({
71
- panelType: PanelType.INFO
72
- }, state, insert);
55
+ return createPanelAction({
56
+ state: state,
57
+ attributes: {
58
+ panelType: PanelType.INFO
59
+ }
60
+ });
73
61
  }
74
62
  }, {
75
63
  id: 'notepanel',
@@ -80,9 +68,12 @@ var panelPlugin = function panelPlugin() {
80
68
  return /*#__PURE__*/React.createElement(IconPanelNote, null);
81
69
  },
82
70
  action: function action(insert, state) {
83
- return insertPanelTypeWithAnalytics({
84
- panelType: PanelType.NOTE
85
- }, state, insert);
71
+ return createPanelAction({
72
+ state: state,
73
+ attributes: {
74
+ panelType: PanelType.NOTE
75
+ }
76
+ });
86
77
  }
87
78
  }, {
88
79
  id: 'successpanel',
@@ -94,9 +85,12 @@ var panelPlugin = function panelPlugin() {
94
85
  return /*#__PURE__*/React.createElement(IconPanelSuccess, null);
95
86
  },
96
87
  action: function action(insert, state) {
97
- return insertPanelTypeWithAnalytics({
98
- panelType: PanelType.SUCCESS
99
- }, state, insert);
88
+ return createPanelAction({
89
+ state: state,
90
+ attributes: {
91
+ panelType: PanelType.SUCCESS
92
+ }
93
+ });
100
94
  }
101
95
  }, {
102
96
  id: 'warningpanel',
@@ -107,9 +101,12 @@ var panelPlugin = function panelPlugin() {
107
101
  return /*#__PURE__*/React.createElement(IconPanelWarning, null);
108
102
  },
109
103
  action: function action(insert, state) {
110
- return insertPanelTypeWithAnalytics({
111
- panelType: PanelType.WARNING
112
- }, state, insert);
104
+ return createPanelAction({
105
+ state: state,
106
+ attributes: {
107
+ panelType: PanelType.WARNING
108
+ }
109
+ });
113
110
  }
114
111
  }, {
115
112
  id: 'errorpanel',
@@ -120,9 +117,12 @@ var panelPlugin = function panelPlugin() {
120
117
  return /*#__PURE__*/React.createElement(IconPanelError, null);
121
118
  },
122
119
  action: function action(insert, state) {
123
- return insertPanelTypeWithAnalytics({
124
- panelType: PanelType.ERROR
125
- }, state, insert);
120
+ return createPanelAction({
121
+ state: state,
122
+ attributes: {
123
+ panelType: PanelType.ERROR
124
+ }
125
+ });
126
126
  }
127
127
  }];
128
128
  if (options.allowCustomPanel && options.allowCustomPanelEdit) {
@@ -135,15 +135,18 @@ var panelPlugin = function panelPlugin() {
135
135
  return /*#__PURE__*/React.createElement(IconCustomPanel, null);
136
136
  },
137
137
  action: function action(insert, state) {
138
- return insertPanelTypeWithAnalytics({
139
- panelType: PanelType.CUSTOM,
140
- panelIcon: ':rainbow:',
141
- panelIconId: '1f308',
142
- panelIconText: '🌈',
143
- // TODO: https://product-fabric.atlassian.net/browse/DSP-7268
144
- // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
145
- panelColor: T50
146
- }, state, insert);
138
+ return createPanelAction({
139
+ state: state,
140
+ attributes: {
141
+ panelType: PanelType.CUSTOM,
142
+ panelIcon: ':rainbow:',
143
+ panelIconId: '1f308',
144
+ panelIconText: '🌈',
145
+ // TODO: https://product-fabric.atlassian.net/browse/DSP-7268
146
+ // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
147
+ panelColor: T50
148
+ }
149
+ });
147
150
  }
148
151
  });
149
152
  }
@@ -155,4 +158,39 @@ var panelPlugin = function panelPlugin() {
155
158
  }
156
159
  };
157
160
  };
161
+
162
+ /**
163
+ * Creates panel action and wrap selection transaction with analytics for the panel insertion.
164
+ *
165
+ * @example
166
+ * const tr = createPanelAction({
167
+ * state: editorState,
168
+ * attributes: { panelType: 'info' },
169
+ * });
170
+ * if (tr) {
171
+ * applyTransaction(tr);
172
+ * }
173
+ */
174
+ function createPanelAction(_ref3) {
175
+ var state = _ref3.state,
176
+ attributes = _ref3.attributes;
177
+ var tr = createWrapSelectionTransaction({
178
+ state: state,
179
+ type: state.schema.nodes.panel,
180
+ nodeAttributes: attributes
181
+ });
182
+ if (tr) {
183
+ addAnalytics(state, tr, {
184
+ action: ACTION.INSERTED,
185
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
186
+ actionSubjectId: ACTION_SUBJECT_ID.PANEL,
187
+ attributes: {
188
+ inputMethod: INPUT_METHOD.QUICK_INSERT,
189
+ panelType: attributes.panelType
190
+ },
191
+ eventType: EVENT_TYPE.TRACK
192
+ });
193
+ }
194
+ return tr;
195
+ }
158
196
  export default panelPlugin;
@@ -31,6 +31,8 @@ export var insertItem = function insertItem(item) {
31
31
  return insertSelectedItem(maybeNode, opts)(state, state.tr, state.selection.head);
32
32
  };
33
33
  var tr = item.action(insert, state);
34
+
35
+ /** @note There is no transaction when called without a search currently (different insert) */
34
36
  if (tr && dispatch) {
35
37
  dispatch(tr);
36
38
  }
@@ -40,6 +40,10 @@ var InsertMenu = function InsertMenu(_ref) {
40
40
  name: item.value.name
41
41
  }) || item.elemBefore;
42
42
  },
43
+ /**
44
+ * @note This transformed items action is only used when a quick insert item has been
45
+ * called from the quick insert menu and a search has not been performed.
46
+ */
43
47
  action: function action() {
44
48
  return onInsert({
45
49
  item: item
@@ -62,6 +66,12 @@ var InsertMenu = function InsertMenu(_ref) {
62
66
  var getItems = useCallback(function (quickInsertState) {
63
67
  return function (query, category) {
64
68
  var result;
69
+ /**
70
+ * @warning The results if there is a query are not the same as the results if there is no query.
71
+ * For example: If you have a typed panel and then select the panel item then it will call a different action
72
+ * than is specified on the editor plugins quick insert
73
+ * @see above transform function for more details.
74
+ */
65
75
  if (query) {
66
76
  result = searchQuickInsertItems(quickInsertState, {})(query, category);
67
77
  } else {
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "185.12.1";
2
+ export var version = "185.13.0";
3
3
  export var nextMajorVersion = function nextMajorVersion() {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "185.12.1",
3
+ "version": "185.13.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,3 +1,7 @@
1
+ /// <reference path="../../../../../../../../typings/prosemirror.d.ts" />
2
+ /// <reference path="../../../../../../../../typings/prosemirror-state.d.ts" />
3
+ import { EditorState } from 'prosemirror-state';
4
+ import { NodeType } from 'prosemirror-model';
1
5
  import { Command } from '../../../types';
2
6
  import { HeadingLevelsAndNormalText } from '../types';
3
7
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
@@ -19,4 +23,25 @@ export declare function insertBlockType(name: string): Command;
19
23
  * @returns - command that inserts block type
20
24
  */
21
25
  export declare const insertBlockTypesWithAnalytics: (name: string, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined) => import("@atlaskit/editor-common/types").Command;
26
+ /**
27
+ * This function creates a new transaction that wraps the current selection
28
+ * in the specified node type if it results in a valid transaction.
29
+ * If not valid, it performs a safe insert operation.
30
+ *
31
+ * Example of when wrapping might not be valid is when attempting to wrap
32
+ * content that is already inside a panel with another panel
33
+ */
34
+ export declare function createWrapSelectionTransaction({ state, type, nodeAttributes, }: {
35
+ state: EditorState;
36
+ type: NodeType;
37
+ nodeAttributes?: Record<string, any>;
38
+ }): import("prosemirror-state").Transaction;
39
+ /**
40
+ * This function creates a new transaction that inserts a code block,
41
+ * if there is text selected it will wrap the current selection if not it will
42
+ * append the codeblock to the end of the document.
43
+ */
44
+ export declare function createInsertCodeBlockTransaction({ state, }: {
45
+ state: EditorState;
46
+ }): import("prosemirror-state").Transaction;
22
47
  export declare const cleanUpAtTheStartOfDocument: Command;
@@ -1,3 +1,7 @@
1
+ /// <reference path="../../../../../../../../typings/prosemirror.d.ts" />
2
+ /// <reference path="../../../../../../../../typings/prosemirror-state.d.ts" />
3
+ import { EditorState } from 'prosemirror-state';
4
+ import { NodeType } from 'prosemirror-model';
1
5
  import { Command } from '../../../types';
2
6
  import { HeadingLevelsAndNormalText } from '../types';
3
7
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
@@ -19,4 +23,25 @@ export declare function insertBlockType(name: string): Command;
19
23
  * @returns - command that inserts block type
20
24
  */
21
25
  export declare const insertBlockTypesWithAnalytics: (name: string, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined) => import("@atlaskit/editor-common/types").Command;
26
+ /**
27
+ * This function creates a new transaction that wraps the current selection
28
+ * in the specified node type if it results in a valid transaction.
29
+ * If not valid, it performs a safe insert operation.
30
+ *
31
+ * Example of when wrapping might not be valid is when attempting to wrap
32
+ * content that is already inside a panel with another panel
33
+ */
34
+ export declare function createWrapSelectionTransaction({ state, type, nodeAttributes, }: {
35
+ state: EditorState;
36
+ type: NodeType;
37
+ nodeAttributes?: Record<string, any>;
38
+ }): import("prosemirror-state").Transaction;
39
+ /**
40
+ * This function creates a new transaction that inserts a code block,
41
+ * if there is text selected it will wrap the current selection if not it will
42
+ * append the codeblock to the end of the document.
43
+ */
44
+ export declare function createInsertCodeBlockTransaction({ state, }: {
45
+ state: EditorState;
46
+ }): import("prosemirror-state").Transaction;
22
47
  export declare const cleanUpAtTheStartOfDocument: Command;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "185.12.1",
3
+ "version": "185.13.0",
4
4
  "description": "A package contains Atlassian editor core functionality",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -77,7 +77,7 @@
77
77
  "@atlaskit/icon-object": "^6.3.0",
78
78
  "@atlaskit/link-analytics": "^8.2.0",
79
79
  "@atlaskit/link-datasource": "^0.28.0",
80
- "@atlaskit/link-picker": "^1.26.0",
80
+ "@atlaskit/link-picker": "^1.27.0",
81
81
  "@atlaskit/locale": "^2.5.0",
82
82
  "@atlaskit/logo": "^13.14.0",
83
83
  "@atlaskit/media-card": "^76.1.0",
@@ -148,7 +148,7 @@
148
148
  "@af/editor-libra": "*",
149
149
  "@af/integration-testing": "*",
150
150
  "@atlaskit/code": "^14.6.0",
151
- "@atlaskit/collab-provider": "9.6.1",
151
+ "@atlaskit/collab-provider": "9.6.2",
152
152
  "@atlaskit/dropdown-menu": "^11.10.0",
153
153
  "@atlaskit/editor-extension-dropbox": "^0.4.0",
154
154
  "@atlaskit/editor-plugin-table": "^2.0.0",