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