@atlaskit/editor-plugin-date 0.1.0 → 0.2.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 (76) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/actions.js +105 -0
  3. package/dist/cjs/commands.js +114 -1
  4. package/dist/cjs/index.js +9 -1
  5. package/dist/cjs/nodeviews/date.js +44 -0
  6. package/dist/cjs/plugin.js +197 -0
  7. package/dist/cjs/pm-plugins/keymap.js +41 -0
  8. package/dist/cjs/pm-plugins/main.js +39 -0
  9. package/dist/cjs/pm-plugins/plugin-key.js +8 -0
  10. package/dist/cjs/pm-plugins/types.js +5 -0
  11. package/dist/cjs/pm-plugins/utils.js +70 -0
  12. package/dist/cjs/ui/DatePicker/date-picker-input.js +253 -0
  13. package/dist/cjs/ui/DatePicker/index.js +170 -0
  14. package/dist/cjs/utils/formatParse.js +88 -0
  15. package/dist/cjs/utils/internal.js +176 -0
  16. package/dist/es2019/actions.js +93 -0
  17. package/dist/es2019/commands.js +113 -1
  18. package/dist/es2019/index.js +1 -1
  19. package/dist/es2019/nodeviews/date.js +47 -0
  20. package/dist/es2019/plugin.js +183 -0
  21. package/dist/es2019/pm-plugins/keymap.js +34 -0
  22. package/dist/es2019/pm-plugins/main.js +35 -0
  23. package/dist/es2019/pm-plugins/plugin-key.js +2 -0
  24. package/dist/es2019/pm-plugins/types.js +1 -0
  25. package/dist/es2019/pm-plugins/utils.js +70 -0
  26. package/dist/es2019/ui/DatePicker/date-picker-input.js +242 -0
  27. package/dist/es2019/ui/DatePicker/index.js +154 -0
  28. package/dist/es2019/utils/formatParse.js +83 -0
  29. package/dist/es2019/utils/internal.js +151 -0
  30. package/dist/esm/actions.js +99 -0
  31. package/dist/esm/commands.js +112 -1
  32. package/dist/esm/index.js +1 -1
  33. package/dist/esm/nodeviews/date.js +37 -0
  34. package/dist/esm/plugin.js +185 -0
  35. package/dist/esm/pm-plugins/keymap.js +34 -0
  36. package/dist/esm/pm-plugins/main.js +34 -0
  37. package/dist/esm/pm-plugins/plugin-key.js +2 -0
  38. package/dist/esm/pm-plugins/types.js +1 -0
  39. package/dist/esm/pm-plugins/utils.js +61 -0
  40. package/dist/esm/ui/DatePicker/date-picker-input.js +247 -0
  41. package/dist/esm/ui/DatePicker/index.js +164 -0
  42. package/dist/esm/utils/formatParse.js +79 -0
  43. package/dist/esm/utils/internal.js +165 -0
  44. package/dist/types/actions.d.ts +49 -0
  45. package/dist/types/commands.d.ts +12 -10
  46. package/dist/types/index.d.ts +1 -1
  47. package/dist/types/nodeviews/date.d.ts +3 -0
  48. package/dist/types/plugin.d.ts +3 -0
  49. package/dist/types/pm-plugins/keymap.d.ts +3 -0
  50. package/dist/types/pm-plugins/main.d.ts +6 -0
  51. package/dist/types/pm-plugins/plugin-key.d.ts +3 -0
  52. package/dist/types/pm-plugins/types.d.ts +12 -0
  53. package/dist/types/pm-plugins/utils.d.ts +5 -0
  54. package/dist/types/types.d.ts +10 -2
  55. package/dist/types/ui/DatePicker/date-picker-input.d.ts +25 -0
  56. package/dist/types/ui/DatePicker/index.d.ts +36 -0
  57. package/dist/types/utils/formatParse.d.ts +27 -0
  58. package/dist/types/utils/internal.d.ts +32 -0
  59. package/dist/types-ts4.5/actions.d.ts +60 -0
  60. package/dist/types-ts4.5/commands.d.ts +14 -10
  61. package/dist/types-ts4.5/index.d.ts +1 -1
  62. package/dist/types-ts4.5/nodeviews/date.d.ts +3 -0
  63. package/dist/types-ts4.5/plugin.d.ts +3 -0
  64. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +3 -0
  65. package/dist/types-ts4.5/pm-plugins/main.d.ts +6 -0
  66. package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +3 -0
  67. package/dist/types-ts4.5/pm-plugins/types.d.ts +12 -0
  68. package/dist/types-ts4.5/pm-plugins/utils.d.ts +5 -0
  69. package/dist/types-ts4.5/types.d.ts +10 -2
  70. package/dist/types-ts4.5/ui/DatePicker/date-picker-input.d.ts +25 -0
  71. package/dist/types-ts4.5/ui/DatePicker/index.d.ts +36 -0
  72. package/dist/types-ts4.5/utils/formatParse.d.ts +27 -0
  73. package/dist/types-ts4.5/utils/internal.d.ts +32 -0
  74. package/package.json +29 -4
  75. package/report.api.md +5 -2
  76. package/tmp/api-report-tmp.d.ts +5 -2
@@ -0,0 +1,99 @@
1
+ import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import { todayTimestampInUTC } from '@atlaskit/editor-common/utils';
3
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
4
+ import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
5
+ import { pluginKey } from './pm-plugins/plugin-key';
6
+ import { isToday } from './utils/internal';
7
+ export var createDate = function createDate(isQuickInsertAction) {
8
+ return function (insert, state) {
9
+ var dateNode = state.schema.nodes.date.createChecked({
10
+ timestamp: todayTimestampInUTC()
11
+ });
12
+ var space = state.schema.text(' ');
13
+ var tr = insert(Fragment.from([dateNode, space]), {
14
+ selectInlineNode: true
15
+ });
16
+ var newPluginState = {
17
+ isQuickInsertAction: isQuickInsertAction,
18
+ showDatePickerAt: tr.selection.from,
19
+ isNew: true,
20
+ isDateEmpty: false,
21
+ focusDateInput: false
22
+ };
23
+ return tr.setMeta(pluginKey, newPluginState);
24
+ };
25
+ };
26
+
27
+ /** Focus input */
28
+ export var focusDateInput = function focusDateInput() {
29
+ return function (state, dispatch) {
30
+ var pluginState = pluginKey.getState(state);
31
+ if (!pluginState || pluginState.showDatePickerAt === null) {
32
+ return false;
33
+ }
34
+ if (!dispatch) {
35
+ return false;
36
+ }
37
+ var tr = state.tr.setMeta(pluginKey, {
38
+ focusDateInput: true
39
+ });
40
+ dispatch(tr);
41
+ return true;
42
+ };
43
+ };
44
+ export var setDatePickerAt = function setDatePickerAt(showDatePickerAt) {
45
+ return function (state, dispatch) {
46
+ dispatch(state.tr.setMeta(pluginKey, {
47
+ showDatePickerAt: showDatePickerAt
48
+ }));
49
+ return true;
50
+ };
51
+ };
52
+ export var closeDatePicker = function closeDatePicker() {
53
+ return function (state, dispatch) {
54
+ var _ref = pluginKey.getState(state) || {},
55
+ showDatePickerAt = _ref.showDatePickerAt;
56
+ if (!dispatch) {
57
+ return false;
58
+ }
59
+ var tr = showDatePickerAt ? state.tr.setMeta(pluginKey, {
60
+ showDatePickerAt: null,
61
+ isNew: false
62
+ }).setSelection(Selection.near(state.tr.doc.resolve(showDatePickerAt + 2))) : state.tr.setMeta(pluginKey, {
63
+ isNew: false
64
+ });
65
+ dispatch(tr);
66
+ return false;
67
+ };
68
+ };
69
+ export var closeDatePickerWithAnalytics = function closeDatePickerWithAnalytics(_ref2) {
70
+ var _pluginInjectionApi$a;
71
+ var date = _ref2.date,
72
+ pluginInjectionApi = _ref2.pluginInjectionApi;
73
+ pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 || (_pluginInjectionApi$a = _pluginInjectionApi$a.actions) === null || _pluginInjectionApi$a === void 0 || _pluginInjectionApi$a.attachAnalyticsEvent({
74
+ eventType: EVENT_TYPE.TRACK,
75
+ action: ACTION.COMMITTED,
76
+ actionSubject: ACTION_SUBJECT.DATE,
77
+ attributes: {
78
+ commitMethod: INPUT_METHOD.BLUR,
79
+ isValid: date !== undefined,
80
+ isToday: isToday(date)
81
+ }
82
+ });
83
+ return closeDatePicker();
84
+ };
85
+ export var openDatePicker = function openDatePicker() {
86
+ return function (state, dispatch) {
87
+ var $from = state.selection.$from;
88
+ var node = state.doc.nodeAt($from.pos);
89
+ if (node && node.type.name === state.schema.nodes.date.name) {
90
+ var showDatePickerAt = $from.pos;
91
+ if (dispatch) {
92
+ dispatch(state.tr.setMeta(pluginKey, {
93
+ showDatePickerAt: showDatePickerAt
94
+ }).setSelection(NodeSelection.create(state.doc, showDatePickerAt)));
95
+ }
96
+ }
97
+ return false;
98
+ };
99
+ };
@@ -1 +1,112 @@
1
- export {};
1
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
+ import { todayTimestampInUTC } from '@atlaskit/editor-common/utils';
3
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
4
+ import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
5
+ import { canInsert } from '@atlaskit/editor-prosemirror/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 var deleteDateCommand = function deleteDateCommand(pluginInjectionApi) {
10
+ return function (_ref) {
11
+ var _pluginInjectionApi$d, _pluginInjectionApi$d2;
12
+ var tr = _ref.tr;
13
+ var _ref2 = (_pluginInjectionApi$d = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$d2 = pluginInjectionApi.date) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.sharedState.currentState()) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : {},
14
+ showDatePickerAt = _ref2.showDatePickerAt;
15
+ if (!showDatePickerAt) {
16
+ return tr;
17
+ }
18
+ tr.delete(showDatePickerAt, showDatePickerAt + 1).setMeta(pluginKey, {
19
+ showDatePickerAt: null,
20
+ isNew: false
21
+ });
22
+ return tr;
23
+ };
24
+ };
25
+ export var insertDateCommand = function insertDateCommand(pluginInjectionApi) {
26
+ return function (_ref3) {
27
+ var date = _ref3.date,
28
+ inputMethod = _ref3.inputMethod,
29
+ commitMethod = _ref3.commitMethod,
30
+ _ref3$enterPressed = _ref3.enterPressed,
31
+ enterPressed = _ref3$enterPressed === void 0 ? true : _ref3$enterPressed;
32
+ return function (_ref4) {
33
+ var _pluginInjectionApi$d3, _pluginInjectionApi$d4;
34
+ var tr = _ref4.tr;
35
+ var schema = tr.doc.type.schema;
36
+ var timestamp;
37
+ if (date) {
38
+ timestamp = Date.UTC(date.year, date.month - 1, date.day).toString();
39
+ } else {
40
+ timestamp = todayTimestampInUTC();
41
+ }
42
+ if (inputMethod) {
43
+ var _pluginInjectionApi$a;
44
+ pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 || (_pluginInjectionApi$a = _pluginInjectionApi$a.actions) === null || _pluginInjectionApi$a === void 0 || _pluginInjectionApi$a.attachAnalyticsEvent({
45
+ action: ACTION.INSERTED,
46
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
47
+ actionSubjectId: ACTION_SUBJECT_ID.DATE,
48
+ eventType: EVENT_TYPE.TRACK,
49
+ attributes: {
50
+ inputMethod: inputMethod
51
+ }
52
+ })(tr);
53
+ }
54
+ if (commitMethod) {
55
+ var _pluginInjectionApi$a2;
56
+ pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 || (_pluginInjectionApi$a2 = _pluginInjectionApi$a2.actions) === null || _pluginInjectionApi$a2 === void 0 || _pluginInjectionApi$a2.attachAnalyticsEvent({
57
+ eventType: EVENT_TYPE.TRACK,
58
+ action: ACTION.COMMITTED,
59
+ actionSubject: ACTION_SUBJECT.DATE,
60
+ attributes: {
61
+ commitMethod: commitMethod,
62
+ isValid: date !== undefined,
63
+ isToday: isToday(date)
64
+ }
65
+ })(tr);
66
+ }
67
+ var _ref5 = (_pluginInjectionApi$d3 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$d4 = pluginInjectionApi.date) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.sharedState.currentState()) !== null && _pluginInjectionApi$d3 !== void 0 ? _pluginInjectionApi$d3 : {},
68
+ showDatePickerAt = _ref5.showDatePickerAt;
69
+ if (!showDatePickerAt) {
70
+ var dateNode = schema.nodes.date.createChecked({
71
+ timestamp: timestamp
72
+ });
73
+ var textNode = schema.text(' ');
74
+ var fragment = Fragment.fromArray([dateNode, textNode]);
75
+ var _tr$selection = tr.selection,
76
+ from = _tr$selection.from,
77
+ to = _tr$selection.to;
78
+ var insertable = canInsert(tr.selection.$from, fragment);
79
+ if (!insertable) {
80
+ var parentSelection = NodeSelection.create(tr.doc, tr.selection.from - tr.selection.$anchor.parentOffset - 1);
81
+ tr.insert(parentSelection.to, fragment).setSelection(NodeSelection.create(tr.doc, parentSelection.to + 1));
82
+ } else {
83
+ tr.replaceWith(from, to, fragment).setSelection(NodeSelection.create(tr.doc, from));
84
+ }
85
+ if (tr.docChanged) {
86
+ tr.scrollIntoView().setMeta(pluginKey, {
87
+ isNew: true
88
+ });
89
+ }
90
+ return tr;
91
+ }
92
+ if (tr.doc.nodeAt(showDatePickerAt)) {
93
+ if (enterPressed) {
94
+ // Setting selection to outside the date node causes showDatePickerAt
95
+ // to be set to null by the PM plugin (onSelectionChanged), which will
96
+ // immediately close the datepicker once a valid date is typed in.
97
+ // Adding this check forces it to stay open until the user presses Enter.
98
+ tr = tr.setSelection(Selection.near(tr.doc.resolve(showDatePickerAt + 2)));
99
+ }
100
+ tr = tr.setNodeMarkup(showDatePickerAt, schema.nodes.date, {
101
+ timestamp: timestamp
102
+ }).setMeta(pluginKey, {
103
+ isNew: false
104
+ }).scrollIntoView();
105
+ if (!enterPressed) {
106
+ tr = tr.setSelection(NodeSelection.create(tr.doc, showDatePickerAt));
107
+ }
108
+ }
109
+ return tr;
110
+ };
111
+ };
112
+ };
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export { default as datePlugin } from './plugin';
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { Date } from '@atlaskit/date';
4
+ import { DateSharedCssClassName } from '@atlaskit/editor-common/styles';
5
+ import { isPastDate, timestampToString, timestampToTaskContext } from '@atlaskit/editor-common/utils';
6
+ import { setDatePickerAt } from '../actions';
7
+ export function DateNodeView(props) {
8
+ var timestamp = props.node.attrs.timestamp,
9
+ _props$view$state = props.view.state,
10
+ doc = _props$view$state.doc,
11
+ schema = _props$view$state.schema,
12
+ selection = _props$view$state.selection,
13
+ getPos = props.getPos;
14
+ var intl = useIntl();
15
+ var pos = typeof getPos === 'function' ? getPos() : undefined;
16
+
17
+ // We fall back to selection.$from even though it does not cover all use cases
18
+ // eg. upon Editor init, selection is at the start, not at the Date node
19
+ var $nodePos = typeof pos === 'number' ? doc.resolve(pos) : selection.$from;
20
+ var parent = $nodePos.parent;
21
+ var withinIncompleteTask = parent.type === schema.nodes.taskItem && parent.attrs.state !== 'DONE';
22
+ var color = withinIncompleteTask && isPastDate(timestamp) ? 'red' : undefined;
23
+ return /*#__PURE__*/React.createElement("span", {
24
+ className: DateSharedCssClassName.DATE_WRAPPER,
25
+ onClick: handleClick
26
+ }, /*#__PURE__*/React.createElement(Date, {
27
+ color: color,
28
+ value: timestamp
29
+ }, withinIncompleteTask ? timestampToTaskContext(timestamp, intl) : timestampToString(timestamp, intl)));
30
+ function handleClick(event) {
31
+ event.nativeEvent.stopImmediatePropagation();
32
+ var _props$view = props.view,
33
+ state = _props$view.state,
34
+ dispatch = _props$view.dispatch;
35
+ setDatePickerAt(state.selection.from)(state, dispatch);
36
+ }
37
+ }
@@ -0,0 +1,185 @@
1
+ import React from 'react';
2
+ import Loadable from 'react-loadable';
3
+ import { date } from '@atlaskit/adf-schema';
4
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
+ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
7
+ import { IconDate } from '@atlaskit/editor-common/quick-insert';
8
+ import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
9
+ import { closeDatePicker as _closeDatePicker, closeDatePickerWithAnalytics as _closeDatePickerWithAnalytics, createDate } from './actions';
10
+ import { deleteDateCommand, insertDateCommand } from './commands';
11
+ import keymap from './pm-plugins/keymap';
12
+ import createDatePlugin from './pm-plugins/main';
13
+ import { pluginKey as datePluginKey } from './pm-plugins/plugin-key';
14
+ var DatePicker = Loadable({
15
+ loader: function loader() {
16
+ return import( /* webpackChunkName: "@atlaskit-internal_editor-datepicker" */'./ui/DatePicker').then(function (mod) {
17
+ return mod.default;
18
+ });
19
+ },
20
+ loading: function loading() {
21
+ return null;
22
+ }
23
+ });
24
+ function ContentComponent(_ref) {
25
+ var editorView = _ref.editorView,
26
+ dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
27
+ popupsMountPoint = _ref.popupsMountPoint,
28
+ popupsBoundariesElement = _ref.popupsBoundariesElement,
29
+ popupsScrollableElement = _ref.popupsScrollableElement,
30
+ dependencyApi = _ref.dependencyApi,
31
+ weekStartDay = _ref.weekStartDay;
32
+ var dispatch = editorView.dispatch;
33
+ var domAtPos = editorView.domAtPos.bind(editorView);
34
+ var _useSharedPluginState = useSharedPluginState(dependencyApi, ['date', 'editorDisabled']),
35
+ editorDisabledState = _useSharedPluginState.editorDisabledState,
36
+ dateState = _useSharedPluginState.dateState;
37
+ if (!(dateState !== null && dateState !== void 0 && dateState.showDatePickerAt) || editorDisabledState !== null && editorDisabledState !== void 0 && editorDisabledState.editorDisabled) {
38
+ return null;
39
+ }
40
+ var showDatePickerAt = dateState.showDatePickerAt,
41
+ isNew = dateState.isNew,
42
+ focusDateInput = dateState.focusDateInput;
43
+ var element = findDomRefAtPos(showDatePickerAt, domAtPos);
44
+ return /*#__PURE__*/React.createElement(DatePicker, {
45
+ mountTo: popupsMountPoint,
46
+ boundariesElement: popupsBoundariesElement,
47
+ scrollableElement: popupsScrollableElement,
48
+ key: showDatePickerAt,
49
+ element: element,
50
+ isNew: isNew,
51
+ autoFocus: focusDateInput,
52
+ onDelete: function onDelete() {
53
+ dependencyApi === null || dependencyApi === void 0 || dependencyApi.core.actions.execute(deleteDateCommand(dependencyApi));
54
+ editorView.focus();
55
+ },
56
+ onSelect: function onSelect(date, commitMethod) {
57
+ // Undefined means couldn't parse date, null means invalid (out of bounds) date
58
+ if (date === undefined || date === null) {
59
+ return;
60
+ }
61
+ dependencyApi === null || dependencyApi === void 0 || dependencyApi.core.actions.execute(insertDateCommand(dependencyApi)({
62
+ date: date,
63
+ commitMethod: commitMethod
64
+ }));
65
+ editorView.focus();
66
+ },
67
+ onTextChanged: function onTextChanged(date) {
68
+ dependencyApi === null || dependencyApi === void 0 || dependencyApi.core.actions.execute(insertDateCommand(dependencyApi)({
69
+ date: date,
70
+ enterPressed: false
71
+ }));
72
+ },
73
+ closeDatePicker: function closeDatePicker() {
74
+ _closeDatePicker()(editorView.state, dispatch);
75
+ editorView.focus();
76
+ },
77
+ closeDatePickerWithAnalytics: function closeDatePickerWithAnalytics(_ref2) {
78
+ var date = _ref2.date;
79
+ _closeDatePickerWithAnalytics({
80
+ date: date
81
+ })(editorView.state, dispatch);
82
+ editorView.focus();
83
+ },
84
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
85
+ weekStartDay: weekStartDay
86
+ });
87
+ }
88
+ var datePlugin = function datePlugin(_ref3) {
89
+ var _ref3$config = _ref3.config,
90
+ options = _ref3$config === void 0 ? {} : _ref3$config,
91
+ api = _ref3.api;
92
+ return {
93
+ name: 'date',
94
+ getSharedState: function getSharedState(editorState) {
95
+ if (!editorState) {
96
+ return {
97
+ showDatePickerAt: null,
98
+ isNew: false,
99
+ focusDateInput: false
100
+ };
101
+ }
102
+ var _ref4 = datePluginKey.getState(editorState) || {},
103
+ showDatePickerAt = _ref4.showDatePickerAt,
104
+ isNew = _ref4.isNew,
105
+ focusDateInput = _ref4.focusDateInput;
106
+ return {
107
+ showDatePickerAt: showDatePickerAt,
108
+ isNew: !!isNew,
109
+ focusDateInput: !!focusDateInput
110
+ };
111
+ },
112
+ commands: {
113
+ insertDate: insertDateCommand(api),
114
+ deleteDate: deleteDateCommand(api)
115
+ },
116
+ nodes: function nodes() {
117
+ return [{
118
+ name: 'date',
119
+ node: date
120
+ }];
121
+ },
122
+ pmPlugins: function pmPlugins() {
123
+ return [{
124
+ name: 'date',
125
+ plugin: function plugin(options) {
126
+ DatePicker.preload();
127
+ return createDatePlugin(options);
128
+ }
129
+ }, {
130
+ name: 'dateKeymap',
131
+ plugin: function plugin() {
132
+ DatePicker.preload();
133
+ return keymap();
134
+ }
135
+ }];
136
+ },
137
+ contentComponent: function contentComponent(_ref5) {
138
+ var editorView = _ref5.editorView,
139
+ dispatchAnalyticsEvent = _ref5.dispatchAnalyticsEvent,
140
+ popupsMountPoint = _ref5.popupsMountPoint,
141
+ popupsBoundariesElement = _ref5.popupsBoundariesElement,
142
+ popupsScrollableElement = _ref5.popupsScrollableElement;
143
+ return /*#__PURE__*/React.createElement(ContentComponent, {
144
+ dependencyApi: api,
145
+ editorView: editorView,
146
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
147
+ popupsMountPoint: popupsMountPoint,
148
+ popupsBoundariesElement: popupsBoundariesElement,
149
+ popupsScrollableElement: popupsScrollableElement,
150
+ weekStartDay: options.weekStartDay
151
+ });
152
+ },
153
+ pluginsOptions: {
154
+ quickInsert: function quickInsert(_ref6) {
155
+ var formatMessage = _ref6.formatMessage;
156
+ return [{
157
+ id: 'date',
158
+ title: formatMessage(messages.date),
159
+ description: formatMessage(messages.dateDescription),
160
+ priority: 800,
161
+ keywords: ['calendar', 'day', 'time', 'today', '/'],
162
+ keyshortcut: '//',
163
+ icon: function icon() {
164
+ return /*#__PURE__*/React.createElement(IconDate, null);
165
+ },
166
+ action: function action(insert, state) {
167
+ var _api$analytics, _api$analytics$attach;
168
+ var tr = createDate(true)(insert, state);
169
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || (_api$analytics$attach = _api$analytics.attachAnalyticsEvent) === null || _api$analytics$attach === void 0 || _api$analytics$attach.call(_api$analytics, {
170
+ action: ACTION.INSERTED,
171
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
172
+ actionSubjectId: ACTION_SUBJECT_ID.DATE,
173
+ eventType: EVENT_TYPE.TRACK,
174
+ attributes: {
175
+ inputMethod: INPUT_METHOD.QUICK_INSERT
176
+ }
177
+ })(tr);
178
+ return tr;
179
+ }
180
+ }];
181
+ }
182
+ }
183
+ };
184
+ };
185
+ export default datePlugin;
@@ -0,0 +1,34 @@
1
+ import { bindKeymapWithCommand, enter, keymap, tab } from '@atlaskit/editor-common/keymaps';
2
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
+ import { closeDatePicker, focusDateInput, openDatePicker } from '../actions';
4
+ import { getPluginState } from './main';
5
+ export function keymapPlugin() {
6
+ var list = {};
7
+ bindKeymapWithCommand(enter.common, function (state, dispatch) {
8
+ var datePlugin = getPluginState(state);
9
+ var isDateNode = state.selection instanceof NodeSelection ? state.selection.node.type === state.schema.nodes.date : false;
10
+ if (!isDateNode) {
11
+ return false;
12
+ }
13
+ if (!datePlugin.showDatePickerAt) {
14
+ openDatePicker()(state, dispatch);
15
+ return true;
16
+ }
17
+ closeDatePicker()(state, dispatch);
18
+ return true;
19
+ }, list);
20
+ bindKeymapWithCommand(tab.common, function (state, dispatch) {
21
+ var datePlugin = getPluginState(state);
22
+ var isDateNode = state.selection instanceof NodeSelection ? state.selection.node.type === state.schema.nodes.date : false;
23
+ if (!isDateNode) {
24
+ return false;
25
+ }
26
+ if (datePlugin.showDatePickerAt) {
27
+ focusDateInput()(state, dispatch);
28
+ return true;
29
+ }
30
+ return false;
31
+ }, list);
32
+ return keymap(list);
33
+ }
34
+ export default keymapPlugin;
@@ -0,0 +1,34 @@
1
+ import { getInlineNodeViewProducer } from '@atlaskit/editor-common/react-node-view';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { pluginFactory } from '@atlaskit/editor-common/utils';
4
+ import { DateNodeView } from '../nodeviews/date';
5
+ import { pluginKey } from './plugin-key';
6
+ import { mapping, onSelectionChanged, reducer } from './utils';
7
+ var _pluginFactory = pluginFactory(pluginKey, reducer, {
8
+ mapping: mapping,
9
+ onSelectionChanged: onSelectionChanged
10
+ }),
11
+ createPluginState = _pluginFactory.createPluginState,
12
+ getPluginState = _pluginFactory.getPluginState;
13
+ var createPlugin = function createPlugin(pmPluginFactoryParams) {
14
+ var newPluginState = {
15
+ showDatePickerAt: null,
16
+ isNew: false,
17
+ isDateEmpty: false,
18
+ focusDateInput: false
19
+ };
20
+ return new SafePlugin({
21
+ state: createPluginState(pmPluginFactoryParams.dispatch, newPluginState),
22
+ key: pluginKey,
23
+ props: {
24
+ nodeViews: {
25
+ date: getInlineNodeViewProducer({
26
+ pmPluginFactoryParams: pmPluginFactoryParams,
27
+ Component: DateNodeView
28
+ })
29
+ }
30
+ }
31
+ });
32
+ };
33
+ export { getPluginState };
34
+ export default createPlugin;
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export var pluginKey = new PluginKey('datePlugin');
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,61 @@
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; }
4
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
5
+ export function reducer(pluginState, meta) {
6
+ // If the same nodeview is clicked twice, calendar should close
7
+ if (meta.showDatePickerAt === pluginState.showDatePickerAt) {
8
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
9
+ showDatePickerAt: null
10
+ });
11
+ }
12
+ var showDatePickerAt = pluginState.showDatePickerAt,
13
+ isNew = pluginState.isNew;
14
+ var showDatePickerAtMeta = meta.showDatePickerAt;
15
+ // If date picker position has changed, it is no longer new
16
+ if (showDatePickerAt && showDatePickerAtMeta && showDatePickerAt !== showDatePickerAtMeta && isNew) {
17
+ return _objectSpread(_objectSpread(_objectSpread({}, pluginState), meta), {}, {
18
+ isNew: false
19
+ });
20
+ }
21
+ return _objectSpread(_objectSpread({}, pluginState), meta);
22
+ }
23
+ export function mapping(tr, pluginState) {
24
+ if (!pluginState.showDatePickerAt) {
25
+ return pluginState;
26
+ }
27
+ var _tr$mapping$mapResult = tr.mapping.mapResult(pluginState.showDatePickerAt),
28
+ pos = _tr$mapping$mapResult.pos;
29
+ return {
30
+ showDatePickerAt: pos,
31
+ isNew: pluginState.isNew,
32
+ isDateEmpty: pluginState.isDateEmpty,
33
+ focusDateInput: pluginState.focusDateInput
34
+ };
35
+ }
36
+ export function onSelectionChanged(tr, pluginState) {
37
+ if (tr.docChanged && isDateNodeSelection(tr.selection)) {
38
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
39
+ isQuickInsertAction: false,
40
+ showDatePickerAt: tr.selection.from
41
+ });
42
+ } else if (!isDateNodeSelection(tr.selection) && !pluginState.isQuickInsertAction) {
43
+ if (pluginState.showDatePickerAt) {
44
+ return {
45
+ showDatePickerAt: null,
46
+ isNew: false,
47
+ isDateEmpty: false,
48
+ focusDateInput: false
49
+ };
50
+ }
51
+ return pluginState;
52
+ }
53
+ return pluginState;
54
+ }
55
+ var isDateNodeSelection = function isDateNodeSelection(selection) {
56
+ if (selection instanceof NodeSelection) {
57
+ var nodeTypeName = selection.node.type.name;
58
+ return nodeTypeName === 'date';
59
+ }
60
+ return false;
61
+ };