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