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