@atlaskit/editor-core 188.7.5 → 188.8.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 (45) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/plugins/date/actions.js +8 -114
  3. package/dist/cjs/plugins/date/commands.js +118 -0
  4. package/dist/cjs/plugins/date/plugin.js +13 -7
  5. package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/index.js +34 -33
  6. package/dist/cjs/plugins/type-ahead/index.js +4 -372
  7. package/dist/cjs/plugins/type-ahead/plugin.js +382 -0
  8. package/dist/cjs/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.js +17 -8
  9. package/dist/cjs/version-wrapper.js +1 -1
  10. package/dist/es2019/plugins/date/actions.js +3 -109
  11. package/dist/es2019/plugins/date/commands.js +113 -0
  12. package/dist/es2019/plugins/date/plugin.js +14 -8
  13. package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/index.js +5 -3
  14. package/dist/es2019/plugins/type-ahead/index.js +2 -375
  15. package/dist/es2019/plugins/type-ahead/plugin.js +381 -0
  16. package/dist/es2019/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.js +17 -8
  17. package/dist/es2019/version-wrapper.js +1 -1
  18. package/dist/esm/plugins/date/actions.js +8 -114
  19. package/dist/esm/plugins/date/commands.js +112 -0
  20. package/dist/esm/plugins/date/plugin.js +14 -8
  21. package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/index.js +34 -33
  22. package/dist/esm/plugins/type-ahead/index.js +2 -368
  23. package/dist/esm/plugins/type-ahead/plugin.js +374 -0
  24. package/dist/esm/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.js +17 -8
  25. package/dist/esm/version-wrapper.js +1 -1
  26. package/dist/types/labs/next/presets/default.d.ts +30 -12
  27. package/dist/types/plugins/date/actions.d.ts +4 -10
  28. package/dist/types/plugins/date/commands.d.ts +20 -0
  29. package/dist/types/plugins/date/types.d.ts +4 -4
  30. package/dist/types/plugins/type-ahead/index.d.ts +3 -14
  31. package/dist/types/plugins/type-ahead/plugin.d.ts +10 -0
  32. package/dist/types/plugins/type-ahead/types.d.ts +51 -6
  33. package/dist/types-ts4.5/labs/next/presets/default.d.ts +30 -12
  34. package/dist/types-ts4.5/plugins/date/actions.d.ts +4 -10
  35. package/dist/types-ts4.5/plugins/date/commands.d.ts +22 -0
  36. package/dist/types-ts4.5/plugins/date/types.d.ts +4 -4
  37. package/dist/types-ts4.5/plugins/type-ahead/index.d.ts +3 -14
  38. package/dist/types-ts4.5/plugins/type-ahead/plugin.d.ts +10 -0
  39. package/dist/types-ts4.5/plugins/type-ahead/types.d.ts +53 -6
  40. package/package.json +2 -2
  41. package/dist/cjs/plugins/view-update-subscription/subscribe/type-ahead-updates.js +0 -33
  42. package/dist/es2019/plugins/view-update-subscription/subscribe/type-ahead-updates.js +0 -28
  43. package/dist/esm/plugins/view-update-subscription/subscribe/type-ahead-updates.js +0 -27
  44. package/dist/types/plugins/view-update-subscription/subscribe/type-ahead-updates.d.ts +0 -9
  45. package/dist/types-ts4.5/plugins/view-update-subscription/subscribe/type-ahead-updates.d.ts +0 -9
@@ -0,0 +1,382 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.typeAheadPlugin = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = _interopRequireDefault(require("react"));
10
+ var _adfSchema = require("@atlaskit/adf-schema");
11
+ var _analytics = require("@atlaskit/editor-common/analytics");
12
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
13
+ var _typeAhead = require("@atlaskit/editor-common/type-ahead");
14
+ var _withPluginState = require("@atlaskit/editor-common/with-plugin-state");
15
+ var _insertTypeAheadItem = require("./commands/insert-type-ahead-item");
16
+ var _updateSelectedIndex = require("./commands/update-selected-index");
17
+ var _inputRules = require("./pm-plugins/input-rules");
18
+ var _insertItemPlugin = require("./pm-plugins/insert-item-plugin");
19
+ var _key = require("./pm-plugins/key");
20
+ var _main = require("./pm-plugins/main");
21
+ var _statsModifier = require("./stats-modifier");
22
+ var _closeTypeAhead = require("./transforms/close-type-ahead");
23
+ var _openTypeaheadAtCursor = require("./transforms/open-typeahead-at-cursor");
24
+ var _useItemInsert3 = require("./ui/hooks/use-item-insert");
25
+ var _TypeAheadPopup = require("./ui/TypeAheadPopup");
26
+ var _utils = require("./utils");
27
+ /**
28
+ *
29
+ * Revamped typeahead using decorations instead of the `typeAheadQuery` mark
30
+ *
31
+ * https://product-fabric.atlassian.net/wiki/spaces/E/pages/2992177582/Technical+TypeAhead+Data+Flow
32
+ *
33
+ *
34
+ */
35
+
36
+ var TypeAheadMenu = /*#__PURE__*/_react.default.memo(function (_ref) {
37
+ var _popupMountRef$curren, _popupMountRef$curren2, _popupMountRef$curren3;
38
+ var editorView = _ref.editorView,
39
+ popupMountRef = _ref.popupMountRef,
40
+ typeAheadState = _ref.typeAheadState,
41
+ fireAnalyticsCallback = _ref.fireAnalyticsCallback;
42
+ var isOpen = typeAheadState.decorationSet.find().length > 0;
43
+ var triggerHandler = typeAheadState.triggerHandler,
44
+ items = typeAheadState.items,
45
+ selectedIndex = typeAheadState.selectedIndex,
46
+ decorationElement = typeAheadState.decorationElement,
47
+ decorationSet = typeAheadState.decorationSet,
48
+ query = typeAheadState.query;
49
+ var _useItemInsert = (0, _useItemInsert3.useItemInsert)(triggerHandler, editorView, items),
50
+ _useItemInsert2 = (0, _slicedToArray2.default)(_useItemInsert, 3),
51
+ onItemInsert = _useItemInsert2[0],
52
+ onTextInsert = _useItemInsert2[1],
53
+ onItemMatch = _useItemInsert2[2];
54
+ var setSelectedItem = _react.default.useCallback(function (_ref2) {
55
+ var nextIndex = _ref2.index;
56
+ queueMicrotask(function () {
57
+ (0, _updateSelectedIndex.updateSelectedIndex)(nextIndex)(editorView.state, editorView.dispatch);
58
+ });
59
+ }, [editorView]);
60
+ var insertItem = _react.default.useCallback(function () {
61
+ var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _typeAhead.SelectItemMode.SELECTED;
62
+ var index = arguments.length > 1 ? arguments[1] : undefined;
63
+ queueMicrotask(function () {
64
+ onItemInsert({
65
+ mode: mode,
66
+ index: index,
67
+ query: query
68
+ });
69
+ });
70
+ }, [onItemInsert, query]);
71
+ var cancel = _react.default.useCallback(function (_ref3) {
72
+ var setSelectionAt = _ref3.setSelectionAt,
73
+ addPrefixTrigger = _ref3.addPrefixTrigger,
74
+ forceFocusOnEditor = _ref3.forceFocusOnEditor;
75
+ var fullQuery = addPrefixTrigger ? "".concat(triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.trigger).concat(query) : query;
76
+ onTextInsert({
77
+ forceFocusOnEditor: forceFocusOnEditor,
78
+ setSelectionAt: setSelectionAt,
79
+ text: fullQuery
80
+ });
81
+ }, [triggerHandler, onTextInsert, query]);
82
+ _react.default.useEffect(function () {
83
+ if (!isOpen || !query) {
84
+ return;
85
+ }
86
+ var isLastCharSpace = query[query.length - 1] === ' ';
87
+ if (!isLastCharSpace) {
88
+ return;
89
+ }
90
+ var result = onItemMatch({
91
+ mode: _typeAhead.SelectItemMode.SPACE,
92
+ query: query.trim()
93
+ });
94
+ if (!result) {
95
+ return;
96
+ }
97
+ }, [isOpen, query, onItemMatch]);
98
+ if (!isOpen || !triggerHandler || !(decorationElement instanceof HTMLElement) || items.length === 0) {
99
+ return null;
100
+ }
101
+ return /*#__PURE__*/_react.default.createElement(_TypeAheadPopup.TypeAheadPopup, {
102
+ editorView: editorView,
103
+ popupsMountPoint: (_popupMountRef$curren = popupMountRef.current) === null || _popupMountRef$curren === void 0 ? void 0 : _popupMountRef$curren.popupsMountPoint,
104
+ popupsBoundariesElement: (_popupMountRef$curren2 = popupMountRef.current) === null || _popupMountRef$curren2 === void 0 ? void 0 : _popupMountRef$curren2.popupsBoundariesElement,
105
+ popupsScrollableElement: (_popupMountRef$curren3 = popupMountRef.current) === null || _popupMountRef$curren3 === void 0 ? void 0 : _popupMountRef$curren3.popupsScrollableElement,
106
+ anchorElement: decorationElement,
107
+ triggerHandler: triggerHandler,
108
+ fireAnalyticsCallback: fireAnalyticsCallback,
109
+ items: items,
110
+ selectedIndex: selectedIndex,
111
+ setSelectedItem: setSelectedItem,
112
+ onItemInsert: insertItem,
113
+ decorationSet: decorationSet,
114
+ isEmptyQuery: !query,
115
+ cancel: cancel
116
+ });
117
+ });
118
+ var createOpenAtTransaction = function createOpenAtTransaction(editorAnalyticsAPI) {
119
+ return function (props) {
120
+ return function (tr) {
121
+ var triggerHandler = props.triggerHandler,
122
+ inputMethod = props.inputMethod;
123
+ (0, _openTypeaheadAtCursor.openTypeAheadAtCursor)({
124
+ triggerHandler: triggerHandler,
125
+ inputMethod: inputMethod
126
+ })({
127
+ tr: tr
128
+ });
129
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
130
+ action: _analytics.ACTION.INVOKED,
131
+ actionSubject: _analytics.ACTION_SUBJECT.TYPEAHEAD,
132
+ actionSubjectId: triggerHandler.id,
133
+ attributes: {
134
+ inputMethod: inputMethod
135
+ },
136
+ eventType: _analytics.EVENT_TYPE.UI
137
+ })(tr);
138
+ return true;
139
+ };
140
+ };
141
+ };
142
+ var createOpenTypeAhead = function createOpenTypeAhead(editorViewRef, editorAnalyticsAPI) {
143
+ return function (props) {
144
+ if (!editorViewRef.current) {
145
+ return false;
146
+ }
147
+ var view = editorViewRef.current;
148
+ var tr = view.state.tr;
149
+ createOpenAtTransaction(editorAnalyticsAPI)(props)(tr);
150
+ view.dispatch(tr);
151
+ return true;
152
+ };
153
+ };
154
+ var createInsertTypeAheadItem = function createInsertTypeAheadItem(editorViewRef) {
155
+ return function (props) {
156
+ if (!editorViewRef.current) {
157
+ return false;
158
+ }
159
+ var view = editorViewRef.current;
160
+ var triggerHandler = props.triggerHandler,
161
+ contentItem = props.contentItem,
162
+ query = props.query,
163
+ sourceListItem = props.sourceListItem,
164
+ mode = props.mode;
165
+ (0, _insertTypeAheadItem.insertTypeAheadItem)(view)({
166
+ handler: triggerHandler,
167
+ item: contentItem,
168
+ mode: mode || _typeAhead.SelectItemMode.SELECTED,
169
+ query: query,
170
+ sourceListItem: sourceListItem
171
+ });
172
+ return true;
173
+ };
174
+ };
175
+ var createFindHandlerByTrigger = function createFindHandlerByTrigger(editorViewRef) {
176
+ return function (trigger) {
177
+ if (!editorViewRef.current) {
178
+ return null;
179
+ }
180
+ var view = editorViewRef.current;
181
+ return (0, _utils.findHandler)(trigger, view.state);
182
+ };
183
+ };
184
+ var createCloseTypeAhead = function createCloseTypeAhead(editorViewRef) {
185
+ return function (options) {
186
+ if (!editorViewRef.current) {
187
+ return false;
188
+ }
189
+ var view = editorViewRef.current;
190
+ var currentQuery = (0, _utils.getTypeAheadQuery)(view.state) || '';
191
+ var state = view.state;
192
+ var tr = state.tr;
193
+ if (options.attachCommand) {
194
+ var fakeDispatch = function fakeDispatch(customTr) {
195
+ tr = customTr;
196
+ };
197
+ options.attachCommand(state, fakeDispatch);
198
+ }
199
+ (0, _closeTypeAhead.closeTypeAhead)(tr);
200
+ if (options.insertCurrentQueryAsRawText && currentQuery && currentQuery.length > 0) {
201
+ var handler = (0, _utils.getTypeAheadHandler)(state);
202
+ if (!handler) {
203
+ return false;
204
+ }
205
+ var text = handler.trigger.concat(currentQuery);
206
+ tr.replaceSelectionWith(state.schema.text(text));
207
+ }
208
+ view.dispatch(tr);
209
+ if (!view.hasFocus()) {
210
+ view.focus();
211
+ }
212
+ return true;
213
+ };
214
+ };
215
+
216
+ /**
217
+ *
218
+ * Revamped typeahead using decorations instead of the `typeAheadQuery` mark
219
+ *
220
+ * https://product-fabric.atlassian.net/wiki/spaces/E/pages/2992177582/Technical+TypeAhead+Data+Flow
221
+ *
222
+ *
223
+ */
224
+ var typeAheadPlugin = exports.typeAheadPlugin = function typeAheadPlugin(_ref4) {
225
+ var _api$analytics, _api$analytics2;
226
+ var options = _ref4.config,
227
+ api = _ref4.api;
228
+ var fireAnalyticsCallback = (0, _analytics.fireAnalyticsEvent)(options === null || options === void 0 ? void 0 : options.createAnalyticsEvent);
229
+ var popupMountRef = {
230
+ current: null
231
+ };
232
+ var editorViewRef = {
233
+ current: null
234
+ };
235
+ return {
236
+ name: 'typeAhead',
237
+ marks: function marks() {
238
+ // We need to keep this to make sure
239
+ // All documents with typeahead marks will be loaded normally
240
+ return [{
241
+ name: 'typeAheadQuery',
242
+ mark: _adfSchema.typeAheadQuery
243
+ }];
244
+ },
245
+ pmPlugins: function pmPlugins() {
246
+ var typeAhead = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
247
+ return [{
248
+ name: 'typeAhead',
249
+ plugin: function plugin(_ref5) {
250
+ var dispatch = _ref5.dispatch,
251
+ getIntl = _ref5.getIntl;
252
+ return (0, _main.createPlugin)({
253
+ getIntl: getIntl,
254
+ popupMountRef: popupMountRef,
255
+ reactDispatch: dispatch,
256
+ typeAheadHandlers: typeAhead,
257
+ createAnalyticsEvent: options === null || options === void 0 ? void 0 : options.createAnalyticsEvent
258
+ });
259
+ }
260
+ }, {
261
+ name: 'typeAheadEditorViewRef',
262
+ plugin: function plugin() {
263
+ return new _safePlugin.SafePlugin({
264
+ view: function view(_view) {
265
+ editorViewRef.current = _view;
266
+ return {
267
+ destroy: function destroy() {
268
+ editorViewRef.current = null;
269
+ }
270
+ };
271
+ }
272
+ });
273
+ }
274
+ }, {
275
+ name: 'typeAheadInsertItem',
276
+ plugin: _insertItemPlugin.createPlugin
277
+ }, {
278
+ name: 'typeAheadInputRule',
279
+ plugin: function plugin(_ref6) {
280
+ var schema = _ref6.schema,
281
+ featureFlags = _ref6.featureFlags;
282
+ return (0, _inputRules.inputRulePlugin)(schema, typeAhead, featureFlags);
283
+ }
284
+ }];
285
+ },
286
+ getSharedState: function getSharedState(editorState) {
287
+ if (!editorState) {
288
+ return {
289
+ query: '',
290
+ isOpen: false,
291
+ isAllowed: false,
292
+ currentHandler: undefined
293
+ };
294
+ }
295
+ var isOpen = (0, _utils.isTypeAheadOpen)(editorState);
296
+ return {
297
+ query: (0, _utils.getTypeAheadQuery)(editorState) || '',
298
+ currentHandler: (0, _utils.getTypeAheadHandler)(editorState),
299
+ isOpen: isOpen,
300
+ isAllowed: !isOpen
301
+ };
302
+ },
303
+ actions: {
304
+ isOpen: _utils.isTypeAheadOpen,
305
+ isAllowed: _utils.isTypeAheadAllowed,
306
+ open: createOpenTypeAhead(editorViewRef, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
307
+ openAtTransaction: createOpenAtTransaction(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions),
308
+ findHandlerByTrigger: createFindHandlerByTrigger(editorViewRef),
309
+ insert: createInsertTypeAheadItem(editorViewRef),
310
+ close: createCloseTypeAhead(editorViewRef)
311
+ },
312
+ contentComponent: function contentComponent(_ref7) {
313
+ var editorView = _ref7.editorView,
314
+ containerElement = _ref7.containerElement,
315
+ popupsMountPoint = _ref7.popupsMountPoint,
316
+ popupsBoundariesElement = _ref7.popupsBoundariesElement,
317
+ popupsScrollableElement = _ref7.popupsScrollableElement,
318
+ wrapperElement = _ref7.wrapperElement;
319
+ popupMountRef.current = {
320
+ popupsMountPoint: popupsMountPoint || wrapperElement || undefined,
321
+ popupsBoundariesElement: popupsBoundariesElement,
322
+ popupsScrollableElement: popupsScrollableElement || containerElement || undefined
323
+ };
324
+ return /*#__PURE__*/_react.default.createElement(_withPluginState.WithPluginState, {
325
+ plugins: {
326
+ typeAheadState: _key.pluginKey
327
+ },
328
+ render: function render(_ref8) {
329
+ var typeAheadState = _ref8.typeAheadState;
330
+ if (!typeAheadState) {
331
+ return null;
332
+ }
333
+ return /*#__PURE__*/_react.default.createElement(TypeAheadMenu, {
334
+ editorView: editorView,
335
+ popupMountRef: popupMountRef,
336
+ typeAheadState: typeAheadState,
337
+ fireAnalyticsCallback: fireAnalyticsCallback
338
+ });
339
+ }
340
+ });
341
+ },
342
+ onEditorViewStateUpdated: function onEditorViewStateUpdated(_ref9) {
343
+ var originalTransaction = _ref9.originalTransaction,
344
+ oldEditorState = _ref9.oldEditorState,
345
+ newEditorState = _ref9.newEditorState;
346
+ var oldPluginState = (0, _utils.getPluginState)(oldEditorState);
347
+ var newPluginState = (0, _utils.getPluginState)(newEditorState);
348
+ if (!oldPluginState || !newPluginState) {
349
+ return;
350
+ }
351
+ var oldTriggerHandler = oldPluginState.triggerHandler;
352
+ var newTriggerHandler = newPluginState.triggerHandler;
353
+ var isANewHandler = oldTriggerHandler !== newTriggerHandler;
354
+ if (oldTriggerHandler !== null && oldTriggerHandler !== void 0 && oldTriggerHandler.dismiss && isANewHandler) {
355
+ var typeAheadMessage = originalTransaction.getMeta(_key.pluginKey);
356
+ var wasItemInserted = typeAheadMessage && typeAheadMessage.action === 'INSERT_RAW_QUERY';
357
+ oldTriggerHandler.dismiss({
358
+ editorState: newEditorState,
359
+ query: oldPluginState.query,
360
+ stats: (oldPluginState.stats || new _statsModifier.StatsModifier()).serialize(),
361
+ wasItemInserted: wasItemInserted
362
+ });
363
+ }
364
+ if (newTriggerHandler !== null && newTriggerHandler !== void 0 && newTriggerHandler.onOpen && isANewHandler) {
365
+ newTriggerHandler.onOpen(newEditorState);
366
+ }
367
+ if (newTriggerHandler && isANewHandler && options !== null && options !== void 0 && options.createAnalyticsEvent) {
368
+ fireAnalyticsCallback({
369
+ payload: {
370
+ action: _analytics.ACTION.INVOKED,
371
+ actionSubject: _analytics.ACTION_SUBJECT.TYPEAHEAD,
372
+ actionSubjectId: newTriggerHandler.id || 'not_set',
373
+ attributes: {
374
+ inputMethod: newPluginState.inputMethod || _analytics.INPUT_METHOD.KEYBOARD
375
+ },
376
+ eventType: _analytics.EVENT_TYPE.UI
377
+ }
378
+ });
379
+ }
380
+ }
381
+ };
382
+ };
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.subscribeToToolbarAndPickerUpdates = void 0;
7
7
  var _floatingToolbar = require("@atlaskit/editor-common/floating-toolbar");
8
- var _utils = require("../../type-ahead/utils");
9
8
  var _ = require("..");
10
9
  var areToolbarsSame = function areToolbarsSame(left, right) {
11
10
  if (!left && !right) {
@@ -30,14 +29,13 @@ var subscribeToToolbarAndPickerUpdates = exports.subscribeToToolbarAndPickerUpda
30
29
  var lastUpdatedState = null;
31
30
  var subscription = function subscription(_ref) {
32
31
  var newEditorState = _ref.newEditorState;
33
- // TypeAhead has priority in the mobile-bridge
34
- // In case it is open we don't need to send
35
- // any toolbar updates don't need to be send
36
- if ((0, _utils.isTypeAheadOpen)(newEditorState)) {
37
- return;
38
- }
39
-
40
32
  // Creating fake plugin keys for these plugins for the mean time until all these plugins are extracted.
33
+ var typeAheadPluginKey = {
34
+ key: 'typeAheadPlugin$',
35
+ getState: function getState(state) {
36
+ return state['typeAheadPlugin$'];
37
+ }
38
+ };
41
39
  var datePluginKey = {
42
40
  key: 'datePlugin$',
43
41
  getState: function getState(state) {
@@ -56,6 +54,17 @@ var subscribeToToolbarAndPickerUpdates = exports.subscribeToToolbarAndPickerUpda
56
54
  return state['floatingToolbarPluginKey$'];
57
55
  }
58
56
  };
57
+ var isTypeAheadOpen = function isTypeAheadOpen(editorState) {
58
+ var _typeAheadState$decor;
59
+ var typeAheadState = typeAheadPluginKey.getState(newEditorState);
60
+ return !!((_typeAheadState$decor = typeAheadState.decorationSet) !== null && _typeAheadState$decor !== void 0 && _typeAheadState$decor.find().length);
61
+ };
62
+ // TypeAhead has priority in the mobile-bridge
63
+ // In case it is open we don't need to send
64
+ // any toolbar updates don't need to be send
65
+ if (isTypeAheadOpen(newEditorState)) {
66
+ return;
67
+ }
59
68
  var dateState = datePluginKey.getState(newEditorState);
60
69
  var statusState = statusPluginKey.getState(newEditorState);
61
70
  var _ref2 = floatingToolbarPluginKey.getState(newEditorState),
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.version = exports.nextMajorVersion = exports.name = void 0;
7
7
  var name = exports.name = "@atlaskit/editor-core";
8
- var version = exports.version = "188.7.5";
8
+ var version = exports.version = "188.8.0";
9
9
  var nextMajorVersion = exports.nextMajorVersion = function nextMajorVersion() {
10
10
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
11
11
  };
@@ -2,9 +2,8 @@ import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
2
2
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
3
3
  import { todayTimestampInUTC } from '@atlaskit/editor-common/utils';
4
4
  import { pluginKey } from './pm-plugins/plugin-key';
5
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
+ import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
6
  import { isToday } from './utils/internal';
7
- import { canInsert } from '@atlaskit/editor-prosemirror/utils';
8
7
  export const createDate = isQuickInsertAction => (insert, state) => {
9
8
  const dateNode = state.schema.nodes.date.createChecked({
10
9
  timestamp: todayTimestampInUTC()
@@ -23,25 +22,6 @@ export const createDate = isQuickInsertAction => (insert, state) => {
23
22
  return tr.setMeta(pluginKey, newPluginState);
24
23
  };
25
24
 
26
- /** Delete the date and close the datepicker */
27
- export const deleteDate = () => (state, dispatch) => {
28
- const pluginState = pluginKey.getState(state);
29
- if (!pluginState || pluginState.showDatePickerAt === null) {
30
- return false;
31
- }
32
- const {
33
- showDatePickerAt
34
- } = pluginState;
35
- const tr = state.tr.delete(showDatePickerAt, showDatePickerAt + 1).setMeta(pluginKey, {
36
- showDatePickerAt: null,
37
- isNew: false
38
- });
39
- if (dispatch) {
40
- dispatch(tr);
41
- }
42
- return true;
43
- };
44
-
45
25
  /** Focus input */
46
26
  export const focusDateInput = () => (state, dispatch) => {
47
27
  const pluginState = pluginKey.getState(state);
@@ -57,92 +37,6 @@ export const focusDateInput = () => (state, dispatch) => {
57
37
  dispatch(tr);
58
38
  return true;
59
39
  };
60
- export const insertDate = (date, inputMethod, commitMethod, enterPressed = true, pluginInjectionApi) => (state, dispatch) => {
61
- const {
62
- schema
63
- } = state;
64
- let timestamp;
65
- if (date) {
66
- timestamp = Date.UTC(date.year, date.month - 1, date.day).toString();
67
- } else {
68
- timestamp = todayTimestampInUTC();
69
- }
70
- let tr = state.tr;
71
- if (inputMethod) {
72
- var _pluginInjectionApi$a, _pluginInjectionApi$a2;
73
- pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : (_pluginInjectionApi$a2 = _pluginInjectionApi$a.actions) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.attachAnalyticsEvent({
74
- action: ACTION.INSERTED,
75
- actionSubject: ACTION_SUBJECT.DOCUMENT,
76
- actionSubjectId: ACTION_SUBJECT_ID.DATE,
77
- eventType: EVENT_TYPE.TRACK,
78
- attributes: {
79
- inputMethod
80
- }
81
- })(tr);
82
- }
83
- if (commitMethod) {
84
- var _pluginInjectionApi$a3, _pluginInjectionApi$a4;
85
- pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a3 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a3 === void 0 ? void 0 : (_pluginInjectionApi$a4 = _pluginInjectionApi$a3.actions) === null || _pluginInjectionApi$a4 === void 0 ? void 0 : _pluginInjectionApi$a4.attachAnalyticsEvent({
86
- eventType: EVENT_TYPE.TRACK,
87
- action: ACTION.COMMITTED,
88
- actionSubject: ACTION_SUBJECT.DATE,
89
- attributes: {
90
- commitMethod,
91
- isValid: date !== undefined,
92
- isToday: isToday(date)
93
- }
94
- })(tr);
95
- }
96
- const {
97
- showDatePickerAt
98
- } = pluginKey.getState(state) || {};
99
- if (!showDatePickerAt) {
100
- const dateNode = schema.nodes.date.createChecked({
101
- timestamp
102
- });
103
- const textNode = state.schema.text(' ');
104
- const fragment = Fragment.fromArray([dateNode, textNode]);
105
- const {
106
- from,
107
- to
108
- } = state.selection;
109
- const insertable = canInsert(tr.selection.$from, fragment);
110
- if (!insertable) {
111
- const parentSelection = NodeSelection.create(tr.doc, tr.selection.from - tr.selection.$anchor.parentOffset - 1);
112
- tr.insert(parentSelection.to, fragment).setSelection(NodeSelection.create(tr.doc, parentSelection.to + 1));
113
- } else {
114
- tr.replaceWith(from, to, fragment).setSelection(NodeSelection.create(tr.doc, from));
115
- }
116
- if (dispatch) {
117
- dispatch(tr.scrollIntoView().setMeta(pluginKey, {
118
- isNew: true
119
- }));
120
- }
121
- return true;
122
- }
123
- if (state.doc.nodeAt(showDatePickerAt)) {
124
- if (enterPressed) {
125
- // Setting selection to outside the date node causes showDatePickerAt
126
- // to be set to null by the PM plugin (onSelectionChanged), which will
127
- // immediately close the datepicker once a valid date is typed in.
128
- // Adding this check forces it to stay open until the user presses Enter.
129
- tr = tr.setSelection(Selection.near(tr.doc.resolve(showDatePickerAt + 2)));
130
- }
131
- tr = tr.setNodeMarkup(showDatePickerAt, schema.nodes.date, {
132
- timestamp
133
- }).setMeta(pluginKey, {
134
- isNew: false
135
- }).scrollIntoView();
136
- if (!enterPressed) {
137
- tr = tr.setSelection(NodeSelection.create(tr.doc, showDatePickerAt));
138
- }
139
- if (dispatch) {
140
- dispatch(tr);
141
- }
142
- return true;
143
- }
144
- return false;
145
- };
146
40
  export const setDatePickerAt = showDatePickerAt => (state, dispatch) => {
147
41
  dispatch(state.tr.setMeta(pluginKey, {
148
42
  showDatePickerAt
@@ -169,8 +63,8 @@ export const closeDatePickerWithAnalytics = ({
169
63
  date,
170
64
  pluginInjectionApi
171
65
  }) => {
172
- var _pluginInjectionApi$a5, _pluginInjectionApi$a6;
173
- pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a5 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a5 === void 0 ? void 0 : (_pluginInjectionApi$a6 = _pluginInjectionApi$a5.actions) === null || _pluginInjectionApi$a6 === void 0 ? void 0 : _pluginInjectionApi$a6.attachAnalyticsEvent({
66
+ var _pluginInjectionApi$a, _pluginInjectionApi$a2;
67
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : (_pluginInjectionApi$a2 = _pluginInjectionApi$a.actions) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.attachAnalyticsEvent({
174
68
  eventType: EVENT_TYPE.TRACK,
175
69
  action: ACTION.COMMITTED,
176
70
  actionSubject: ACTION_SUBJECT.DATE,
@@ -0,0 +1,113 @@
1
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
+ import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
3
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
4
+ import { canInsert } from '@atlaskit/editor-prosemirror/utils';
5
+ import { todayTimestampInUTC } from '@atlaskit/editor-common/utils';
6
+ import { pluginKey } from './pm-plugins/plugin-key';
7
+ import { isToday } from './utils/internal';
8
+ /** Delete the date and close the datepicker */
9
+ export const deleteDateCommand = pluginInjectionApi => ({
10
+ tr
11
+ }) => {
12
+ var _pluginInjectionApi$d, _pluginInjectionApi$d2;
13
+ const {
14
+ showDatePickerAt
15
+ } = (_pluginInjectionApi$d = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d2 = pluginInjectionApi.date) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.sharedState.currentState()) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : {};
16
+ if (!showDatePickerAt) {
17
+ return tr;
18
+ }
19
+ tr.delete(showDatePickerAt, showDatePickerAt + 1).setMeta(pluginKey, {
20
+ showDatePickerAt: null,
21
+ isNew: false
22
+ });
23
+ return tr;
24
+ };
25
+ export const insertDateCommand = pluginInjectionApi => ({
26
+ date,
27
+ inputMethod,
28
+ commitMethod,
29
+ enterPressed = true
30
+ }) => ({
31
+ tr
32
+ }) => {
33
+ var _pluginInjectionApi$d3, _pluginInjectionApi$d4;
34
+ const {
35
+ schema
36
+ } = tr.doc.type;
37
+ let timestamp;
38
+ if (date) {
39
+ timestamp = Date.UTC(date.year, date.month - 1, date.day).toString();
40
+ } else {
41
+ timestamp = todayTimestampInUTC();
42
+ }
43
+ if (inputMethod) {
44
+ var _pluginInjectionApi$a, _pluginInjectionApi$a2;
45
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : (_pluginInjectionApi$a2 = _pluginInjectionApi$a.actions) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.attachAnalyticsEvent({
46
+ action: ACTION.INSERTED,
47
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
48
+ actionSubjectId: ACTION_SUBJECT_ID.DATE,
49
+ eventType: EVENT_TYPE.TRACK,
50
+ attributes: {
51
+ inputMethod
52
+ }
53
+ })(tr);
54
+ }
55
+ if (commitMethod) {
56
+ var _pluginInjectionApi$a3, _pluginInjectionApi$a4;
57
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a3 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a3 === void 0 ? void 0 : (_pluginInjectionApi$a4 = _pluginInjectionApi$a3.actions) === null || _pluginInjectionApi$a4 === void 0 ? void 0 : _pluginInjectionApi$a4.attachAnalyticsEvent({
58
+ eventType: EVENT_TYPE.TRACK,
59
+ action: ACTION.COMMITTED,
60
+ actionSubject: ACTION_SUBJECT.DATE,
61
+ attributes: {
62
+ commitMethod,
63
+ isValid: date !== undefined,
64
+ isToday: isToday(date)
65
+ }
66
+ })(tr);
67
+ }
68
+ const {
69
+ showDatePickerAt
70
+ } = (_pluginInjectionApi$d3 = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d4 = pluginInjectionApi.date) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.sharedState.currentState()) !== null && _pluginInjectionApi$d3 !== void 0 ? _pluginInjectionApi$d3 : {};
71
+ if (!showDatePickerAt) {
72
+ const dateNode = schema.nodes.date.createChecked({
73
+ timestamp
74
+ });
75
+ const textNode = schema.text(' ');
76
+ const fragment = Fragment.fromArray([dateNode, textNode]);
77
+ const {
78
+ from,
79
+ to
80
+ } = tr.selection;
81
+ const insertable = canInsert(tr.selection.$from, fragment);
82
+ if (!insertable) {
83
+ const parentSelection = NodeSelection.create(tr.doc, tr.selection.from - tr.selection.$anchor.parentOffset - 1);
84
+ tr.insert(parentSelection.to, fragment).setSelection(NodeSelection.create(tr.doc, parentSelection.to + 1));
85
+ } else {
86
+ tr.replaceWith(from, to, fragment).setSelection(NodeSelection.create(tr.doc, from));
87
+ }
88
+ if (tr.docChanged) {
89
+ tr.scrollIntoView().setMeta(pluginKey, {
90
+ isNew: true
91
+ });
92
+ }
93
+ return tr;
94
+ }
95
+ if (tr.doc.nodeAt(showDatePickerAt)) {
96
+ if (enterPressed) {
97
+ // Setting selection to outside the date node causes showDatePickerAt
98
+ // to be set to null by the PM plugin (onSelectionChanged), which will
99
+ // immediately close the datepicker once a valid date is typed in.
100
+ // Adding this check forces it to stay open until the user presses Enter.
101
+ tr = tr.setSelection(Selection.near(tr.doc.resolve(showDatePickerAt + 2)));
102
+ }
103
+ tr = tr.setNodeMarkup(showDatePickerAt, schema.nodes.date, {
104
+ timestamp
105
+ }).setMeta(pluginKey, {
106
+ isNew: false
107
+ }).scrollIntoView();
108
+ if (!enterPressed) {
109
+ tr = tr.setSelection(NodeSelection.create(tr.doc, showDatePickerAt));
110
+ }
111
+ }
112
+ return tr;
113
+ };