@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.
- package/CHANGELOG.md +10 -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 +49 -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 +60 -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 +29 -4
- package/report.api.md +5 -2
- package/tmp/api-report-tmp.d.ts +5 -2
|
@@ -0,0 +1,253 @@
|
|
|
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 _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
11
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
12
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
16
|
+
var _react = _interopRequireDefault(require("react"));
|
|
17
|
+
var _react2 = require("@emotion/react");
|
|
18
|
+
var _reactIntlNext = require("react-intl-next");
|
|
19
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
20
|
+
var _form = require("@atlaskit/form");
|
|
21
|
+
var _textfield = _interopRequireDefault(require("@atlaskit/textfield"));
|
|
22
|
+
var _formatParse = require("../../utils/formatParse");
|
|
23
|
+
var _internal = require("../../utils/internal");
|
|
24
|
+
var _templateObject;
|
|
25
|
+
/** @jsx jsx */
|
|
26
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
27
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
28
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
29
|
+
var dateTextFieldWrapper = (0, _react2.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n padding: 22px;\n padding-bottom: ", ";\n"])), "var(--ds-space-150, 12px)");
|
|
30
|
+
var messages = (0, _reactIntlNext.defineMessages)({
|
|
31
|
+
invalidDateError: {
|
|
32
|
+
id: 'fabric.editor.invalidDateError',
|
|
33
|
+
defaultMessage: 'Enter a valid date',
|
|
34
|
+
description: 'Error message when the date typed in is invalid, requesting they inputs a new date'
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
39
|
+
var DatePickerInput = /*#__PURE__*/function (_React$Component) {
|
|
40
|
+
(0, _inherits2.default)(DatePickerInput, _React$Component);
|
|
41
|
+
var _super = _createSuper(DatePickerInput);
|
|
42
|
+
function DatePickerInput(props) {
|
|
43
|
+
var _this;
|
|
44
|
+
(0, _classCallCheck2.default)(this, DatePickerInput);
|
|
45
|
+
_this = _super.call(this, props);
|
|
46
|
+
/**
|
|
47
|
+
* Focus the input textfield
|
|
48
|
+
*/
|
|
49
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "focusInput", function () {
|
|
50
|
+
if (!_this.inputRef) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
// Defer to prevent editor scrolling to top (See FS-3227, also ED-2992)
|
|
54
|
+
_this.autofocusTimeout = setTimeout(function () {
|
|
55
|
+
var _this$inputRef;
|
|
56
|
+
(_this$inputRef = _this.inputRef) === null || _this$inputRef === void 0 || _this$inputRef.focus();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Select all the input text
|
|
61
|
+
*/
|
|
62
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "selectInput", function () {
|
|
63
|
+
if (!_this.inputRef) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// Defer to prevent editor scrolling to top (See FS-3227, also ED-2992)
|
|
67
|
+
_this.autoSelectAllTimeout = setTimeout(function () {
|
|
68
|
+
var _this$inputRef2;
|
|
69
|
+
(_this$inputRef2 = _this.inputRef) === null || _this$inputRef2 === void 0 || _this$inputRef2.select();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleInputRef", function (ref) {
|
|
73
|
+
var _this$props = _this.props,
|
|
74
|
+
autoFocus = _this$props.autoFocus,
|
|
75
|
+
autoSelectAll = _this$props.autoSelectAll;
|
|
76
|
+
if (ref) {
|
|
77
|
+
_this.inputRef = ref;
|
|
78
|
+
}
|
|
79
|
+
if (ref && autoFocus) {
|
|
80
|
+
_this.focusInput();
|
|
81
|
+
}
|
|
82
|
+
if (autoSelectAll) {
|
|
83
|
+
_this.selectInput();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleChange", function (evt) {
|
|
87
|
+
var textFieldValue = evt.target.value;
|
|
88
|
+
var _this$props2 = _this.props,
|
|
89
|
+
locale = _this$props2.locale,
|
|
90
|
+
dispatchAnalyticsEvent = _this$props2.dispatchAnalyticsEvent;
|
|
91
|
+
var newDate = (0, _formatParse.parseDateType)(textFieldValue, locale);
|
|
92
|
+
if (newDate !== undefined && newDate !== null) {
|
|
93
|
+
_this.setState({
|
|
94
|
+
inputText: textFieldValue
|
|
95
|
+
});
|
|
96
|
+
_this.props.onNewDate(newDate);
|
|
97
|
+
if (dispatchAnalyticsEvent) {
|
|
98
|
+
dispatchAnalyticsEvent({
|
|
99
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
100
|
+
action: _analytics.ACTION.TYPING_FINISHED,
|
|
101
|
+
actionSubject: _analytics.ACTION_SUBJECT.DATE
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
// if invalid, just update state text (to rerender textfield)
|
|
106
|
+
_this.setState({
|
|
107
|
+
inputText: textFieldValue
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleKeyPress", function (event) {
|
|
112
|
+
var _this$props3 = _this.props,
|
|
113
|
+
locale = _this$props3.locale,
|
|
114
|
+
dispatchAnalyticsEvent = _this$props3.dispatchAnalyticsEvent;
|
|
115
|
+
var textFieldValue = event.target.value;
|
|
116
|
+
|
|
117
|
+
// Fire event on every keypress (textfield not necessarily empty)
|
|
118
|
+
if (dispatchAnalyticsEvent && event.key !== 'Enter' && event.key !== 'Backspace') {
|
|
119
|
+
dispatchAnalyticsEvent({
|
|
120
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
121
|
+
action: _analytics.ACTION.TYPING_STARTED,
|
|
122
|
+
actionSubject: _analytics.ACTION_SUBJECT.DATE
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (event.key !== 'Enter') {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (textFieldValue === '') {
|
|
129
|
+
_this.props.onEmptySubmit();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
var newDate = (0, _formatParse.parseDateType)(textFieldValue, locale);
|
|
133
|
+
_this.props.onSubmitDate(newDate);
|
|
134
|
+
});
|
|
135
|
+
// arrow keys are only triggered by onKeyDown, not onKeyPress
|
|
136
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleKeyDown", function (event) {
|
|
137
|
+
var _this$inputRef3;
|
|
138
|
+
var dateString = event.target.value;
|
|
139
|
+
var locale = _this.props.locale;
|
|
140
|
+
var adjustment;
|
|
141
|
+
if (event.key === 'ArrowUp') {
|
|
142
|
+
adjustment = 1;
|
|
143
|
+
} else if (event.key === 'ArrowDown') {
|
|
144
|
+
adjustment = -1;
|
|
145
|
+
}
|
|
146
|
+
if (adjustment === undefined) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
var dispatchAnalyticsEvent = _this.props.dispatchAnalyticsEvent;
|
|
150
|
+
var cursorPos = (_this$inputRef3 = _this.inputRef) === null || _this$inputRef3 === void 0 ? void 0 : _this$inputRef3.selectionStart;
|
|
151
|
+
if (cursorPos === null || cursorPos === undefined) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
var activeSegment = (0, _internal.findDateSegmentByPosition)(cursorPos, dateString, locale);
|
|
155
|
+
if (activeSegment === undefined) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
var dateSegment;
|
|
159
|
+
switch (activeSegment) {
|
|
160
|
+
case 'day':
|
|
161
|
+
dateSegment = _analytics.ACTION_SUBJECT_ID.DATE_DAY;
|
|
162
|
+
break;
|
|
163
|
+
case 'month':
|
|
164
|
+
dateSegment = _analytics.ACTION_SUBJECT_ID.DATE_MONTH;
|
|
165
|
+
break;
|
|
166
|
+
default:
|
|
167
|
+
dateSegment = _analytics.ACTION_SUBJECT_ID.DATE_YEAR;
|
|
168
|
+
}
|
|
169
|
+
if (dispatchAnalyticsEvent) {
|
|
170
|
+
dispatchAnalyticsEvent({
|
|
171
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
172
|
+
action: adjustment > 0 ? _analytics.ACTION.INCREMENTED : _analytics.ACTION.DECREMENTED,
|
|
173
|
+
actionSubject: _analytics.ACTION_SUBJECT.DATE_SEGMENT,
|
|
174
|
+
attributes: {
|
|
175
|
+
dateSegment: dateSegment
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
var oldDateType = (0, _formatParse.parseDateType)(dateString, locale);
|
|
180
|
+
if (oldDateType === undefined || oldDateType === null) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
var newDateType = (0, _internal.adjustDate)(oldDateType, activeSegment, adjustment);
|
|
184
|
+
_this.setState({
|
|
185
|
+
inputText: (0, _formatParse.formatDateType)(newDateType, locale)
|
|
186
|
+
});
|
|
187
|
+
_this.props.onNewDate(newDateType);
|
|
188
|
+
_this.setInputSelectionPos = Math.min(cursorPos, dateString.length);
|
|
189
|
+
event.preventDefault();
|
|
190
|
+
});
|
|
191
|
+
var date = props.date;
|
|
192
|
+
_this.setInputSelectionPos = undefined;
|
|
193
|
+
var inputText = (0, _formatParse.formatDateType)(date, _this.props.locale);
|
|
194
|
+
_this.state = {
|
|
195
|
+
inputText: inputText
|
|
196
|
+
};
|
|
197
|
+
return _this;
|
|
198
|
+
}
|
|
199
|
+
(0, _createClass2.default)(DatePickerInput, [{
|
|
200
|
+
key: "render",
|
|
201
|
+
value: function render() {
|
|
202
|
+
var _this$props4 = this.props,
|
|
203
|
+
locale = _this$props4.locale,
|
|
204
|
+
formatMessage = _this$props4.intl.formatMessage;
|
|
205
|
+
var inputText = this.state.inputText;
|
|
206
|
+
var possiblyValid = (0, _internal.isDatePossiblyValid)(inputText);
|
|
207
|
+
var attemptedDateParse = (0, _formatParse.parseDateType)(inputText, locale);
|
|
208
|
+
|
|
209
|
+
// Don't display an error for an empty input.
|
|
210
|
+
var displayError = (attemptedDateParse === null || !possiblyValid) && inputText !== '';
|
|
211
|
+
return (0, _react2.jsx)("div", {
|
|
212
|
+
css: dateTextFieldWrapper
|
|
213
|
+
}, (0, _react2.jsx)(_textfield.default, {
|
|
214
|
+
name: "datetextfield",
|
|
215
|
+
value: inputText,
|
|
216
|
+
ref: this.handleInputRef,
|
|
217
|
+
onChange: this.handleChange,
|
|
218
|
+
onKeyPress: this.handleKeyPress,
|
|
219
|
+
onKeyDown: this.handleKeyDown,
|
|
220
|
+
spellCheck: false,
|
|
221
|
+
autoComplete: "off",
|
|
222
|
+
isInvalid: displayError
|
|
223
|
+
}), displayError && (0, _react2.jsx)(_form.ErrorMessage, null, formatMessage(messages.invalidDateError)));
|
|
224
|
+
}
|
|
225
|
+
}, {
|
|
226
|
+
key: "componentDidUpdate",
|
|
227
|
+
value: function componentDidUpdate() {
|
|
228
|
+
var setInputSelectionPos = this.setInputSelectionPos;
|
|
229
|
+
if (this.inputRef && setInputSelectionPos !== undefined) {
|
|
230
|
+
this.inputRef.setSelectionRange(setInputSelectionPos, setInputSelectionPos);
|
|
231
|
+
this.setInputSelectionPos = undefined;
|
|
232
|
+
}
|
|
233
|
+
if (this.inputRef && this.props.autoFocus) {
|
|
234
|
+
// TODO: Check if input already has focus
|
|
235
|
+
this.focusInput();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Don't select all text here - would seleect text on each keystroke
|
|
239
|
+
}
|
|
240
|
+
}, {
|
|
241
|
+
key: "componentWillUnmount",
|
|
242
|
+
value: function componentWillUnmount() {
|
|
243
|
+
if (this.autofocusTimeout !== undefined) {
|
|
244
|
+
clearTimeout(this.autofocusTimeout);
|
|
245
|
+
}
|
|
246
|
+
if (this.autoSelectAllTimeout !== undefined) {
|
|
247
|
+
clearTimeout(this.autoSelectAllTimeout);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}]);
|
|
251
|
+
return DatePickerInput;
|
|
252
|
+
}(_react.default.Component);
|
|
253
|
+
var _default = exports.default = (0, _reactIntlNext.injectIntl)(DatePickerInput);
|
|
@@ -0,0 +1,170 @@
|
|
|
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 _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
11
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
12
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
16
|
+
var _react = _interopRequireDefault(require("react"));
|
|
17
|
+
var _react2 = require("@emotion/react");
|
|
18
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
19
|
+
var _reactIntlNext = require("react-intl-next");
|
|
20
|
+
var _calendar = _interopRequireDefault(require("@atlaskit/calendar"));
|
|
21
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
22
|
+
var _ui = require("@atlaskit/editor-common/ui");
|
|
23
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
24
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
25
|
+
var _colors = require("@atlaskit/theme/colors");
|
|
26
|
+
var _constants = require("@atlaskit/theme/constants");
|
|
27
|
+
var _datePickerInput = _interopRequireDefault(require("./date-picker-input"));
|
|
28
|
+
var _templateObject;
|
|
29
|
+
/** @jsx jsx */
|
|
30
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
31
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
32
|
+
var PopupWithListeners = (0, _ui.withOuterListeners)(_ui.Popup);
|
|
33
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
34
|
+
var popupContentWrapper = (0, _react2.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n padding: ", ";\n border-radius: ", "px;\n box-shadow: ", ";\n background-color: ", ";\n"])), "var(--ds-space-025, 2px)", (0, _constants.borderRadius)(), "var(--ds-shadow-overlay, ".concat("0 4px 8px -2px ".concat(_colors.N60A, ", 0 0 1px ").concat(_colors.N60A), ")"), "var(--ds-surface-overlay, ".concat(_colors.N0, ")"));
|
|
35
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
36
|
+
var DatePicker = /*#__PURE__*/function (_React$Component) {
|
|
37
|
+
(0, _inherits2.default)(DatePicker, _React$Component);
|
|
38
|
+
var _super = _createSuper(DatePicker);
|
|
39
|
+
function DatePicker(props) {
|
|
40
|
+
var _this;
|
|
41
|
+
(0, _classCallCheck2.default)(this, DatePicker);
|
|
42
|
+
_this = _super.call(this, props);
|
|
43
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleNewDate", function (date) {
|
|
44
|
+
_this.props.onTextChanged(date);
|
|
45
|
+
_this.setState({
|
|
46
|
+
latestValidDate: date
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleKeyboardSubmitDate", function (date) {
|
|
50
|
+
_this.props.onSelect(date, _analytics.INPUT_METHOD.KEYBOARD);
|
|
51
|
+
});
|
|
52
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleEmptySubmitDate", function () {
|
|
53
|
+
_this.props.onDelete();
|
|
54
|
+
});
|
|
55
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleOnChange", function (_ref) {
|
|
56
|
+
var day = _ref.day,
|
|
57
|
+
month = _ref.month,
|
|
58
|
+
year = _ref.year;
|
|
59
|
+
var date = {
|
|
60
|
+
day: day,
|
|
61
|
+
month: month,
|
|
62
|
+
year: year
|
|
63
|
+
};
|
|
64
|
+
_this.setState({
|
|
65
|
+
latestValidDate: date
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "closeDatePickerWithAnalytics", function () {
|
|
69
|
+
_this.props.closeDatePickerWithAnalytics({
|
|
70
|
+
date: _this.state.latestValidDate
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleRef", function (ref) {
|
|
74
|
+
var elm = ref && _reactDom.default.findDOMNode(ref);
|
|
75
|
+
if (elm) {
|
|
76
|
+
elm.focus();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
var timestamp = props.element.getAttribute('timestamp');
|
|
80
|
+
if (timestamp) {
|
|
81
|
+
// Warning: The 'Date' return type of timestampToUTCDate() is not a JS date, it's more similar
|
|
82
|
+
// to the DateType type
|
|
83
|
+
var _timestampToUTCDate = (0, _utils.timestampToUTCDate)(timestamp),
|
|
84
|
+
day = _timestampToUTCDate.day,
|
|
85
|
+
month = _timestampToUTCDate.month,
|
|
86
|
+
year = _timestampToUTCDate.year;
|
|
87
|
+
var _date = {
|
|
88
|
+
day: day,
|
|
89
|
+
month: month,
|
|
90
|
+
year: year
|
|
91
|
+
};
|
|
92
|
+
_this.state = {
|
|
93
|
+
selected: [(0, _utils.timestampToIsoFormat)(timestamp)],
|
|
94
|
+
date: _date,
|
|
95
|
+
latestValidDate: _date
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return _this;
|
|
99
|
+
}
|
|
100
|
+
(0, _createClass2.default)(DatePicker, [{
|
|
101
|
+
key: "render",
|
|
102
|
+
value: function render() {
|
|
103
|
+
var _this$props = this.props,
|
|
104
|
+
element = _this$props.element,
|
|
105
|
+
_onSelect = _this$props.onSelect,
|
|
106
|
+
mountTo = _this$props.mountTo,
|
|
107
|
+
boundariesElement = _this$props.boundariesElement,
|
|
108
|
+
scrollableElement = _this$props.scrollableElement,
|
|
109
|
+
intl = _this$props.intl,
|
|
110
|
+
dispatchAnalyticsEvent = _this$props.dispatchAnalyticsEvent,
|
|
111
|
+
isNew = _this$props.isNew,
|
|
112
|
+
autoFocus = _this$props.autoFocus,
|
|
113
|
+
weekStartDay = _this$props.weekStartDay;
|
|
114
|
+
var timestamp = element.getAttribute('timestamp');
|
|
115
|
+
if (this.state === null) {
|
|
116
|
+
// Without this, you can blow up the page by slowing down cpu, opening date, typing after date
|
|
117
|
+
// then clicking on date lozenge and typing quickly before it opens
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
var _this$state = this.state,
|
|
121
|
+
date = _this$state.date,
|
|
122
|
+
selected = _this$state.selected,
|
|
123
|
+
latestValidDate = _this$state.latestValidDate;
|
|
124
|
+
var day = latestValidDate.day,
|
|
125
|
+
month = latestValidDate.month,
|
|
126
|
+
year = latestValidDate.year;
|
|
127
|
+
if (!timestamp) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
return (0, _react2.jsx)(PopupWithListeners, {
|
|
131
|
+
target: element,
|
|
132
|
+
offset: [0, 8],
|
|
133
|
+
fitHeight: 327,
|
|
134
|
+
fitWidth: 340,
|
|
135
|
+
handleClickOutside: this.closeDatePickerWithAnalytics,
|
|
136
|
+
handleEscapeKeydown: this.closeDatePickerWithAnalytics,
|
|
137
|
+
zIndex: _editorSharedStyles.akEditorFloatingDialogZIndex,
|
|
138
|
+
mountTo: mountTo,
|
|
139
|
+
boundariesElement: boundariesElement,
|
|
140
|
+
scrollableElement: scrollableElement,
|
|
141
|
+
ariaLabel: null
|
|
142
|
+
}, (0, _react2.jsx)("div", {
|
|
143
|
+
css: popupContentWrapper
|
|
144
|
+
}, (0, _react2.jsx)(_datePickerInput.default, {
|
|
145
|
+
date: date,
|
|
146
|
+
onNewDate: this.handleNewDate,
|
|
147
|
+
onSubmitDate: this.handleKeyboardSubmitDate,
|
|
148
|
+
onEmptySubmit: this.handleEmptySubmitDate,
|
|
149
|
+
locale: intl.locale,
|
|
150
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
151
|
+
autoFocus: autoFocus,
|
|
152
|
+
autoSelectAll: isNew
|
|
153
|
+
}), (0, _react2.jsx)(_calendar.default, {
|
|
154
|
+
onChange: this.handleOnChange,
|
|
155
|
+
onSelect: function onSelect(date) {
|
|
156
|
+
return _onSelect(date, _analytics.INPUT_METHOD.PICKER);
|
|
157
|
+
},
|
|
158
|
+
day: day,
|
|
159
|
+
month: month,
|
|
160
|
+
year: year,
|
|
161
|
+
selected: selected,
|
|
162
|
+
ref: this.handleRef,
|
|
163
|
+
weekStartDay: weekStartDay,
|
|
164
|
+
testId: 'datepicker'
|
|
165
|
+
})));
|
|
166
|
+
}
|
|
167
|
+
}]);
|
|
168
|
+
return DatePicker;
|
|
169
|
+
}(_react.default.Component);
|
|
170
|
+
var _default = exports.default = (0, _reactIntlNext.injectIntl)(DatePicker);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.dateToDateType = dateToDateType;
|
|
7
|
+
exports.dateTypeToDate = dateTypeToDate;
|
|
8
|
+
exports.formatDateType = formatDateType;
|
|
9
|
+
exports.parseDateType = parseDateType;
|
|
10
|
+
var _locale = require("@atlaskit/locale");
|
|
11
|
+
/**
|
|
12
|
+
* Attempt to parse a string representing a date in a particular locale to a date object
|
|
13
|
+
* @param dateString The string representing the date in the given locale, eg '02/12/2000'
|
|
14
|
+
* @param l10n The localisation provider created by createLocalizationProvider
|
|
15
|
+
* @returns Editor DateType when can parse, null when can't parse or invalid
|
|
16
|
+
*/
|
|
17
|
+
function parseDateType(dateString, locale) {
|
|
18
|
+
try {
|
|
19
|
+
var l10n = (0, _locale.createLocalizationProvider)(locale);
|
|
20
|
+
var date = l10n.parseDate(dateString);
|
|
21
|
+
|
|
22
|
+
// If date is invalid
|
|
23
|
+
if (isNaN(date.getTime())) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
var year = date.getFullYear();
|
|
27
|
+
if (year < 1000 || year > 9999) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
var dateObj = {
|
|
31
|
+
day: date.getDate(),
|
|
32
|
+
month: date.getMonth() + 1,
|
|
33
|
+
year: year
|
|
34
|
+
};
|
|
35
|
+
return dateObj;
|
|
36
|
+
} catch (e) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Convert an EditorDateType to a date string string formatted for a particular locale
|
|
43
|
+
* @param date The date object
|
|
44
|
+
* @param locale The locale code string (eg. "en-AU")
|
|
45
|
+
* @returns Date string, eg "25/5/20"
|
|
46
|
+
*/
|
|
47
|
+
function formatDateType(date, locale) {
|
|
48
|
+
var day = date.day,
|
|
49
|
+
month = date.month,
|
|
50
|
+
year = date.year;
|
|
51
|
+
var l10n = (0, _locale.createLocalizationProvider)(locale);
|
|
52
|
+
|
|
53
|
+
// The JS Date api represents month as a number between 0-11 :)
|
|
54
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
|
|
55
|
+
var dateObj = new Date(year, month - 1, day);
|
|
56
|
+
return l10n.formatDate(dateObj);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Convert an Editor DateType to a JavaScript Date object
|
|
61
|
+
* @param date Editor DateType
|
|
62
|
+
* @returns JavaScript Date object
|
|
63
|
+
*/
|
|
64
|
+
function dateTypeToDate(date) {
|
|
65
|
+
var day = date.day,
|
|
66
|
+
month = date.month,
|
|
67
|
+
year = date.year;
|
|
68
|
+
// The JS Date api represents month as a number between 0-11 :)
|
|
69
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
|
|
70
|
+
var dateObj = new Date(year, month - 1, day);
|
|
71
|
+
return dateObj;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Convert a JavaScript Date to an editor DateType
|
|
76
|
+
* @param date JavaScript Date object
|
|
77
|
+
* @returns Editor DateType
|
|
78
|
+
*/
|
|
79
|
+
function dateToDateType(date) {
|
|
80
|
+
var dateObj = {
|
|
81
|
+
day: date.getDate(),
|
|
82
|
+
// The JS Date api represents month as a number between 0-11 :)
|
|
83
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
|
|
84
|
+
month: date.getMonth() + 1,
|
|
85
|
+
year: date.getFullYear()
|
|
86
|
+
};
|
|
87
|
+
return dateObj;
|
|
88
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.adjustDate = adjustDate;
|
|
8
|
+
exports.findDateSegmentByPosition = findDateSegmentByPosition;
|
|
9
|
+
exports.getLocaleDatePlaceholder = getLocaleDatePlaceholder;
|
|
10
|
+
exports.isDatePossiblyValid = isDatePossiblyValid;
|
|
11
|
+
exports.isToday = isToday;
|
|
12
|
+
var _addDays = _interopRequireDefault(require("date-fns/addDays"));
|
|
13
|
+
var _addMonths = _interopRequireDefault(require("date-fns/addMonths"));
|
|
14
|
+
var _addYears = _interopRequireDefault(require("date-fns/addYears"));
|
|
15
|
+
var _formatParse = require("./formatParse");
|
|
16
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
17
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
18
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
19
|
+
function isDigit(c) {
|
|
20
|
+
if (c === undefined) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return c >= '0' && c <= '9';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check if cursor is in first segment of a date.
|
|
28
|
+
* @param cursorPos Cursor pos, with 0 referring to the left of first char
|
|
29
|
+
* @param date Date string in any locale
|
|
30
|
+
*/
|
|
31
|
+
function isCursorInFirstDateSegment(cursorPos, date) {
|
|
32
|
+
var posCounter = cursorPos - 1;
|
|
33
|
+
var isAdjacent = true;
|
|
34
|
+
// The date without any non-digit characters on the end
|
|
35
|
+
var strippedDate = date.replace(/[^0-9]+$/g, '');
|
|
36
|
+
while (posCounter >= 0 && isAdjacent) {
|
|
37
|
+
var c = strippedDate[posCounter];
|
|
38
|
+
if (!isDigit(c)) {
|
|
39
|
+
isAdjacent = false;
|
|
40
|
+
}
|
|
41
|
+
posCounter -= 1;
|
|
42
|
+
}
|
|
43
|
+
return isAdjacent;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Check if cursor is in last segment of a date.
|
|
48
|
+
* @param cursorPos Cursor pos, with 0 referring to the left of first char
|
|
49
|
+
* @param date Date string in any locale
|
|
50
|
+
*/
|
|
51
|
+
function isCursorInLastDateSegment(cursorPos, date) {
|
|
52
|
+
var posCounter = cursorPos;
|
|
53
|
+
var isAdjacent = true;
|
|
54
|
+
// The date without any non-digit characters on the end
|
|
55
|
+
var strippedDate = date.replace(/[^0-9]+$/g, '');
|
|
56
|
+
while (posCounter < strippedDate.length && isAdjacent) {
|
|
57
|
+
var c = strippedDate[posCounter];
|
|
58
|
+
if (!isDigit(c)) {
|
|
59
|
+
isAdjacent = false;
|
|
60
|
+
}
|
|
61
|
+
posCounter += 1;
|
|
62
|
+
}
|
|
63
|
+
return isAdjacent;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Inconclusively check if a date string is valid - a value of false means it is definitely
|
|
68
|
+
* invalid, a value of true means it might be valid.
|
|
69
|
+
* @param date Date string to be parsed
|
|
70
|
+
*/
|
|
71
|
+
function isDatePossiblyValid(date) {
|
|
72
|
+
var _iterator = _createForOfIteratorHelper(date),
|
|
73
|
+
_step;
|
|
74
|
+
try {
|
|
75
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
76
|
+
var c = _step.value;
|
|
77
|
+
var isNumber = c >= '0' && c <= '9';
|
|
78
|
+
var isValidPunctuation = '. ,/'.indexOf(c) !== -1;
|
|
79
|
+
if (!(isNumber || isValidPunctuation)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch (err) {
|
|
84
|
+
_iterator.e(err);
|
|
85
|
+
} finally {
|
|
86
|
+
_iterator.f();
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Find the segment of a date a position refers to. Eg: pos 2 in 29/03/2020 is in
|
|
93
|
+
* the day segment.
|
|
94
|
+
* @param position Cursor position, with 0 referring to the left of the first char
|
|
95
|
+
* @param date The localised date string
|
|
96
|
+
* @param locale The language to interpret the date string in
|
|
97
|
+
*/
|
|
98
|
+
function findDateSegmentByPosition(position, date, locale) {
|
|
99
|
+
if (position > date.length) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
var placeholder = getLocaleDatePlaceholder(locale);
|
|
103
|
+
if (!placeholder) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// The placeholder without any non-digit characters on the end
|
|
108
|
+
var strippedPlaceholder = placeholder.replace(/[^ymd]+$/g, '');
|
|
109
|
+
var keyToSegment = {
|
|
110
|
+
d: 'day',
|
|
111
|
+
m: 'month',
|
|
112
|
+
y: 'year'
|
|
113
|
+
};
|
|
114
|
+
var firstSegment = keyToSegment[strippedPlaceholder[0]];
|
|
115
|
+
var lastSegment = keyToSegment[strippedPlaceholder[strippedPlaceholder.length - 1]];
|
|
116
|
+
var allPossibleSegments = ['day', 'month', 'year'];
|
|
117
|
+
var middleSegment = allPossibleSegments.filter(function (s) {
|
|
118
|
+
return s !== firstSegment && s !== lastSegment;
|
|
119
|
+
})[0];
|
|
120
|
+
if (isCursorInFirstDateSegment(position, date)) {
|
|
121
|
+
return firstSegment;
|
|
122
|
+
}
|
|
123
|
+
if (isCursorInLastDateSegment(position, date)) {
|
|
124
|
+
return lastSegment;
|
|
125
|
+
}
|
|
126
|
+
return middleSegment;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Generate a placeholder date string for a given locale
|
|
131
|
+
* eg: locale 'hu-HU' -> 'yyyy. mm. dd.'
|
|
132
|
+
* @param locale A locale string supported by Intl.DateTimeFormat
|
|
133
|
+
* @returns A placeholder string. d=1 or 2 digit day, dd=zero padded
|
|
134
|
+
* day, same for month but letter m, yyyy=year
|
|
135
|
+
*/
|
|
136
|
+
function getLocaleDatePlaceholder(locale) {
|
|
137
|
+
var uniqueDateType = {
|
|
138
|
+
day: 7,
|
|
139
|
+
month: 1,
|
|
140
|
+
year: 1992
|
|
141
|
+
};
|
|
142
|
+
var localisedDateString = (0, _formatParse.formatDateType)(uniqueDateType, locale);
|
|
143
|
+
var shortDateFormat = localisedDateString.replace(/\d+/g, function (str) {
|
|
144
|
+
if (!str) {
|
|
145
|
+
return '';
|
|
146
|
+
}
|
|
147
|
+
var num = parseInt(str);
|
|
148
|
+
switch (num % 100) {
|
|
149
|
+
case 92:
|
|
150
|
+
return str.replace(/.{1}/g, 'y');
|
|
151
|
+
case 1:
|
|
152
|
+
return str.length === 1 ? 'm' : 'mm';
|
|
153
|
+
case 7:
|
|
154
|
+
return str.length === 1 ? 'd' : 'dd';
|
|
155
|
+
}
|
|
156
|
+
return '';
|
|
157
|
+
});
|
|
158
|
+
return shortDateFormat;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Adjust date segment up or down. Eg. If day is the active segment and adjustment is -1,
|
|
163
|
+
* reduce the day by one.
|
|
164
|
+
* @param date Valid datetype
|
|
165
|
+
* @param activeSegment which part of the date is selected/being adjusted
|
|
166
|
+
* @param adjustment how many units the segment is being adjusted (can be pos or neg, usually 1 or -1)
|
|
167
|
+
*/
|
|
168
|
+
function adjustDate(date, activeSegment, adjustment) {
|
|
169
|
+
var originalDate = (0, _formatParse.dateTypeToDate)(date);
|
|
170
|
+
var newDate = activeSegment === 'day' ? (0, _addDays.default)(originalDate, adjustment) : activeSegment === 'month' ? (0, _addMonths.default)(originalDate, adjustment) : (0, _addYears.default)(originalDate, adjustment);
|
|
171
|
+
return (0, _formatParse.dateToDateType)(newDate);
|
|
172
|
+
}
|
|
173
|
+
function isToday(date) {
|
|
174
|
+
var today = new Date();
|
|
175
|
+
return date !== undefined && today.getDate() === date.day && date.month === today.getMonth() + 1 && date.year === today.getFullYear();
|
|
176
|
+
}
|