@atlaskit/editor-core 188.10.7 → 188.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/architecture/0003-explicit-plugin-dependencies.md +1 -1
  3. package/dist/cjs/i18n/cs.js +0 -60
  4. package/dist/cjs/i18n/da.js +0 -60
  5. package/dist/cjs/i18n/de.js +0 -60
  6. package/dist/cjs/i18n/en.js +0 -60
  7. package/dist/cjs/i18n/en_GB.js +0 -60
  8. package/dist/cjs/i18n/en_ZZ.js +0 -60
  9. package/dist/cjs/i18n/es.js +0 -60
  10. package/dist/cjs/i18n/fi.js +0 -60
  11. package/dist/cjs/i18n/fr.js +0 -60
  12. package/dist/cjs/i18n/hu.js +0 -60
  13. package/dist/cjs/i18n/it.js +0 -60
  14. package/dist/cjs/i18n/ja.js +0 -60
  15. package/dist/cjs/i18n/ko.js +0 -60
  16. package/dist/cjs/i18n/nb.js +0 -60
  17. package/dist/cjs/i18n/nl.js +0 -60
  18. package/dist/cjs/i18n/pl.js +0 -60
  19. package/dist/cjs/i18n/pt_BR.js +0 -60
  20. package/dist/cjs/i18n/ru.js +0 -60
  21. package/dist/cjs/i18n/sv.js +0 -60
  22. package/dist/cjs/i18n/th.js +0 -60
  23. package/dist/cjs/i18n/tr.js +0 -60
  24. package/dist/cjs/i18n/uk.js +0 -60
  25. package/dist/cjs/i18n/vi.js +0 -60
  26. package/dist/cjs/i18n/zh.js +0 -60
  27. package/dist/cjs/i18n/zh_TW.js +0 -60
  28. package/dist/cjs/labs/next/presets/universal.js +2 -2
  29. package/dist/cjs/messages.js +1 -2
  30. package/dist/cjs/plugins/index.js +0 -7
  31. package/dist/cjs/plugins/tasks-and-decisions/nodeviews/decisionItem.js +1 -1
  32. package/dist/cjs/plugins/tasks-and-decisions/nodeviews/taskItem.js +1 -1
  33. package/dist/cjs/version-wrapper.js +1 -1
  34. package/dist/es2019/i18n/cs.js +0 -60
  35. package/dist/es2019/i18n/da.js +0 -60
  36. package/dist/es2019/i18n/de.js +0 -60
  37. package/dist/es2019/i18n/en.js +0 -60
  38. package/dist/es2019/i18n/en_GB.js +0 -60
  39. package/dist/es2019/i18n/en_ZZ.js +0 -60
  40. package/dist/es2019/i18n/es.js +0 -60
  41. package/dist/es2019/i18n/fi.js +0 -60
  42. package/dist/es2019/i18n/fr.js +0 -60
  43. package/dist/es2019/i18n/hu.js +0 -60
  44. package/dist/es2019/i18n/it.js +0 -60
  45. package/dist/es2019/i18n/ja.js +0 -60
  46. package/dist/es2019/i18n/ko.js +0 -60
  47. package/dist/es2019/i18n/nb.js +0 -60
  48. package/dist/es2019/i18n/nl.js +0 -60
  49. package/dist/es2019/i18n/pl.js +0 -60
  50. package/dist/es2019/i18n/pt_BR.js +0 -60
  51. package/dist/es2019/i18n/ru.js +0 -60
  52. package/dist/es2019/i18n/sv.js +0 -60
  53. package/dist/es2019/i18n/th.js +0 -60
  54. package/dist/es2019/i18n/tr.js +0 -60
  55. package/dist/es2019/i18n/uk.js +0 -60
  56. package/dist/es2019/i18n/vi.js +0 -60
  57. package/dist/es2019/i18n/zh.js +0 -60
  58. package/dist/es2019/i18n/zh_TW.js +0 -60
  59. package/dist/es2019/labs/next/presets/universal.js +1 -1
  60. package/dist/es2019/messages.js +1 -2
  61. package/dist/es2019/plugins/index.js +0 -1
  62. package/dist/es2019/plugins/tasks-and-decisions/nodeviews/decisionItem.js +1 -1
  63. package/dist/es2019/plugins/tasks-and-decisions/nodeviews/taskItem.js +1 -1
  64. package/dist/es2019/version-wrapper.js +1 -1
  65. package/dist/esm/i18n/cs.js +0 -60
  66. package/dist/esm/i18n/da.js +0 -60
  67. package/dist/esm/i18n/de.js +0 -60
  68. package/dist/esm/i18n/en.js +0 -60
  69. package/dist/esm/i18n/en_GB.js +0 -60
  70. package/dist/esm/i18n/en_ZZ.js +0 -60
  71. package/dist/esm/i18n/es.js +0 -60
  72. package/dist/esm/i18n/fi.js +0 -60
  73. package/dist/esm/i18n/fr.js +0 -60
  74. package/dist/esm/i18n/hu.js +0 -60
  75. package/dist/esm/i18n/it.js +0 -60
  76. package/dist/esm/i18n/ja.js +0 -60
  77. package/dist/esm/i18n/ko.js +0 -60
  78. package/dist/esm/i18n/nb.js +0 -60
  79. package/dist/esm/i18n/nl.js +0 -60
  80. package/dist/esm/i18n/pl.js +0 -60
  81. package/dist/esm/i18n/pt_BR.js +0 -60
  82. package/dist/esm/i18n/ru.js +0 -60
  83. package/dist/esm/i18n/sv.js +0 -60
  84. package/dist/esm/i18n/th.js +0 -60
  85. package/dist/esm/i18n/tr.js +0 -60
  86. package/dist/esm/i18n/uk.js +0 -60
  87. package/dist/esm/i18n/vi.js +0 -60
  88. package/dist/esm/i18n/zh.js +0 -60
  89. package/dist/esm/i18n/zh_TW.js +0 -60
  90. package/dist/esm/labs/next/presets/universal.js +1 -1
  91. package/dist/esm/messages.js +1 -2
  92. package/dist/esm/plugins/index.js +0 -1
  93. package/dist/esm/plugins/tasks-and-decisions/nodeviews/decisionItem.js +1 -1
  94. package/dist/esm/plugins/tasks-and-decisions/nodeviews/taskItem.js +1 -1
  95. package/dist/esm/version-wrapper.js +1 -1
  96. package/dist/types/i18n/cs.d.ts +0 -60
  97. package/dist/types/i18n/da.d.ts +0 -60
  98. package/dist/types/i18n/de.d.ts +0 -60
  99. package/dist/types/i18n/en.d.ts +0 -60
  100. package/dist/types/i18n/en_GB.d.ts +0 -60
  101. package/dist/types/i18n/en_ZZ.d.ts +0 -60
  102. package/dist/types/i18n/es.d.ts +0 -60
  103. package/dist/types/i18n/fi.d.ts +0 -60
  104. package/dist/types/i18n/fr.d.ts +0 -60
  105. package/dist/types/i18n/hu.d.ts +0 -60
  106. package/dist/types/i18n/it.d.ts +0 -60
  107. package/dist/types/i18n/ja.d.ts +0 -60
  108. package/dist/types/i18n/ko.d.ts +0 -60
  109. package/dist/types/i18n/nb.d.ts +0 -60
  110. package/dist/types/i18n/nl.d.ts +0 -60
  111. package/dist/types/i18n/pl.d.ts +0 -60
  112. package/dist/types/i18n/pt_BR.d.ts +0 -60
  113. package/dist/types/i18n/ru.d.ts +0 -60
  114. package/dist/types/i18n/sv.d.ts +0 -60
  115. package/dist/types/i18n/th.d.ts +0 -60
  116. package/dist/types/i18n/tr.d.ts +0 -60
  117. package/dist/types/i18n/uk.d.ts +0 -60
  118. package/dist/types/i18n/vi.d.ts +0 -60
  119. package/dist/types/i18n/zh.d.ts +0 -60
  120. package/dist/types/i18n/zh_TW.d.ts +0 -60
  121. package/dist/types/messages.d.ts +1 -2
  122. package/dist/types/plugins/index.d.ts +0 -1
  123. package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
  124. package/dist/types/ui/ConfigPanel/FormErrorBoundary.d.ts +1 -1
  125. package/dist/types/ui/ContentStyles/index.d.ts +2 -2
  126. package/dist/types-ts4.5/i18n/cs.d.ts +0 -60
  127. package/dist/types-ts4.5/i18n/da.d.ts +0 -60
  128. package/dist/types-ts4.5/i18n/de.d.ts +0 -60
  129. package/dist/types-ts4.5/i18n/en.d.ts +0 -60
  130. package/dist/types-ts4.5/i18n/en_GB.d.ts +0 -60
  131. package/dist/types-ts4.5/i18n/en_ZZ.d.ts +0 -60
  132. package/dist/types-ts4.5/i18n/es.d.ts +0 -60
  133. package/dist/types-ts4.5/i18n/fi.d.ts +0 -60
  134. package/dist/types-ts4.5/i18n/fr.d.ts +0 -60
  135. package/dist/types-ts4.5/i18n/hu.d.ts +0 -60
  136. package/dist/types-ts4.5/i18n/it.d.ts +0 -60
  137. package/dist/types-ts4.5/i18n/ja.d.ts +0 -60
  138. package/dist/types-ts4.5/i18n/ko.d.ts +0 -60
  139. package/dist/types-ts4.5/i18n/nb.d.ts +0 -60
  140. package/dist/types-ts4.5/i18n/nl.d.ts +0 -60
  141. package/dist/types-ts4.5/i18n/pl.d.ts +0 -60
  142. package/dist/types-ts4.5/i18n/pt_BR.d.ts +0 -60
  143. package/dist/types-ts4.5/i18n/ru.d.ts +0 -60
  144. package/dist/types-ts4.5/i18n/sv.d.ts +0 -60
  145. package/dist/types-ts4.5/i18n/th.d.ts +0 -60
  146. package/dist/types-ts4.5/i18n/tr.d.ts +0 -60
  147. package/dist/types-ts4.5/i18n/uk.d.ts +0 -60
  148. package/dist/types-ts4.5/i18n/vi.d.ts +0 -60
  149. package/dist/types-ts4.5/i18n/zh.d.ts +0 -60
  150. package/dist/types-ts4.5/i18n/zh_TW.d.ts +0 -60
  151. package/dist/types-ts4.5/messages.d.ts +1 -2
  152. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  153. package/dist/types-ts4.5/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
  154. package/dist/types-ts4.5/ui/ConfigPanel/FormErrorBoundary.d.ts +1 -1
  155. package/dist/types-ts4.5/ui/ContentStyles/index.d.ts +2 -2
  156. package/package.json +6 -9
  157. package/dist/cjs/plugins/date/actions.js +0 -105
  158. package/dist/cjs/plugins/date/commands.js +0 -118
  159. package/dist/cjs/plugins/date/index.js +0 -13
  160. package/dist/cjs/plugins/date/nodeviews/date.js +0 -44
  161. package/dist/cjs/plugins/date/nodeviews/messages.js +0 -14
  162. package/dist/cjs/plugins/date/plugin.js +0 -197
  163. package/dist/cjs/plugins/date/pm-plugins/keymap.js +0 -41
  164. package/dist/cjs/plugins/date/pm-plugins/main.js +0 -39
  165. package/dist/cjs/plugins/date/pm-plugins/plugin-key.js +0 -8
  166. package/dist/cjs/plugins/date/pm-plugins/types.js +0 -5
  167. package/dist/cjs/plugins/date/pm-plugins/utils.js +0 -70
  168. package/dist/cjs/plugins/date/types.js +0 -5
  169. package/dist/cjs/plugins/date/ui/DatePicker/date-picker-input.js +0 -244
  170. package/dist/cjs/plugins/date/ui/DatePicker/index.js +0 -168
  171. package/dist/cjs/plugins/date/utils/formatParse.js +0 -88
  172. package/dist/cjs/plugins/date/utils/internal.js +0 -176
  173. package/dist/es2019/plugins/date/actions.js +0 -93
  174. package/dist/es2019/plugins/date/commands.js +0 -113
  175. package/dist/es2019/plugins/date/index.js +0 -1
  176. package/dist/es2019/plugins/date/nodeviews/date.js +0 -47
  177. package/dist/es2019/plugins/date/nodeviews/messages.js +0 -8
  178. package/dist/es2019/plugins/date/plugin.js +0 -183
  179. package/dist/es2019/plugins/date/pm-plugins/keymap.js +0 -34
  180. package/dist/es2019/plugins/date/pm-plugins/main.js +0 -35
  181. package/dist/es2019/plugins/date/pm-plugins/plugin-key.js +0 -2
  182. package/dist/es2019/plugins/date/pm-plugins/types.js +0 -1
  183. package/dist/es2019/plugins/date/pm-plugins/utils.js +0 -70
  184. package/dist/es2019/plugins/date/types.js +0 -1
  185. package/dist/es2019/plugins/date/ui/DatePicker/date-picker-input.js +0 -233
  186. package/dist/es2019/plugins/date/ui/DatePicker/index.js +0 -152
  187. package/dist/es2019/plugins/date/utils/formatParse.js +0 -83
  188. package/dist/es2019/plugins/date/utils/internal.js +0 -151
  189. package/dist/esm/plugins/date/actions.js +0 -99
  190. package/dist/esm/plugins/date/commands.js +0 -112
  191. package/dist/esm/plugins/date/index.js +0 -1
  192. package/dist/esm/plugins/date/nodeviews/date.js +0 -37
  193. package/dist/esm/plugins/date/nodeviews/messages.js +0 -8
  194. package/dist/esm/plugins/date/plugin.js +0 -185
  195. package/dist/esm/plugins/date/pm-plugins/keymap.js +0 -34
  196. package/dist/esm/plugins/date/pm-plugins/main.js +0 -34
  197. package/dist/esm/plugins/date/pm-plugins/plugin-key.js +0 -2
  198. package/dist/esm/plugins/date/pm-plugins/types.js +0 -1
  199. package/dist/esm/plugins/date/pm-plugins/utils.js +0 -61
  200. package/dist/esm/plugins/date/types.js +0 -1
  201. package/dist/esm/plugins/date/ui/DatePicker/date-picker-input.js +0 -238
  202. package/dist/esm/plugins/date/ui/DatePicker/index.js +0 -162
  203. package/dist/esm/plugins/date/utils/formatParse.js +0 -79
  204. package/dist/esm/plugins/date/utils/internal.js +0 -165
  205. package/dist/types/plugins/date/actions.d.ts +0 -47
  206. package/dist/types/plugins/date/commands.d.ts +0 -12
  207. package/dist/types/plugins/date/index.d.ts +0 -1
  208. package/dist/types/plugins/date/nodeviews/date.d.ts +0 -3
  209. package/dist/types/plugins/date/nodeviews/messages.d.ts +0 -7
  210. package/dist/types/plugins/date/plugin.d.ts +0 -3
  211. package/dist/types/plugins/date/pm-plugins/keymap.d.ts +0 -3
  212. package/dist/types/plugins/date/pm-plugins/main.d.ts +0 -6
  213. package/dist/types/plugins/date/pm-plugins/plugin-key.d.ts +0 -3
  214. package/dist/types/plugins/date/pm-plugins/types.d.ts +0 -12
  215. package/dist/types/plugins/date/pm-plugins/utils.d.ts +0 -5
  216. package/dist/types/plugins/date/types.d.ts +0 -1
  217. package/dist/types/plugins/date/ui/DatePicker/date-picker-input.d.ts +0 -24
  218. package/dist/types/plugins/date/ui/DatePicker/index.d.ts +0 -36
  219. package/dist/types/plugins/date/utils/formatParse.d.ts +0 -27
  220. package/dist/types/plugins/date/utils/internal.d.ts +0 -33
  221. package/dist/types-ts4.5/plugins/date/actions.d.ts +0 -58
  222. package/dist/types-ts4.5/plugins/date/commands.d.ts +0 -14
  223. package/dist/types-ts4.5/plugins/date/index.d.ts +0 -1
  224. package/dist/types-ts4.5/plugins/date/nodeviews/date.d.ts +0 -3
  225. package/dist/types-ts4.5/plugins/date/nodeviews/messages.d.ts +0 -7
  226. package/dist/types-ts4.5/plugins/date/plugin.d.ts +0 -3
  227. package/dist/types-ts4.5/plugins/date/pm-plugins/keymap.d.ts +0 -3
  228. package/dist/types-ts4.5/plugins/date/pm-plugins/main.d.ts +0 -6
  229. package/dist/types-ts4.5/plugins/date/pm-plugins/plugin-key.d.ts +0 -3
  230. package/dist/types-ts4.5/plugins/date/pm-plugins/types.d.ts +0 -12
  231. package/dist/types-ts4.5/plugins/date/pm-plugins/utils.d.ts +0 -5
  232. package/dist/types-ts4.5/plugins/date/types.d.ts +0 -1
  233. package/dist/types-ts4.5/plugins/date/ui/DatePicker/date-picker-input.d.ts +0 -24
  234. package/dist/types-ts4.5/plugins/date/ui/DatePicker/index.d.ts +0 -36
  235. package/dist/types-ts4.5/plugins/date/utils/formatParse.d.ts +0 -27
  236. package/dist/types-ts4.5/plugins/date/utils/internal.d.ts +0 -33
@@ -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
- }
@@ -1,99 +0,0 @@
1
- import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
2
- import { Fragment } from '@atlaskit/editor-prosemirror/model';
3
- import { todayTimestampInUTC } from '@atlaskit/editor-common/utils';
4
- import { pluginKey } from './pm-plugins/plugin-key';
5
- import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
- import { isToday } from './utils/internal';
7
- export var createDate = function createDate(isQuickInsertAction) {
8
- return function (insert, state) {
9
- var dateNode = state.schema.nodes.date.createChecked({
10
- timestamp: todayTimestampInUTC()
11
- });
12
- var space = state.schema.text(' ');
13
- var tr = insert(Fragment.from([dateNode, space]), {
14
- selectInlineNode: true
15
- });
16
- var newPluginState = {
17
- isQuickInsertAction: isQuickInsertAction,
18
- showDatePickerAt: tr.selection.from,
19
- isNew: true,
20
- isDateEmpty: false,
21
- focusDateInput: false
22
- };
23
- return tr.setMeta(pluginKey, newPluginState);
24
- };
25
- };
26
-
27
- /** Focus input */
28
- export var focusDateInput = function focusDateInput() {
29
- return function (state, dispatch) {
30
- var pluginState = pluginKey.getState(state);
31
- if (!pluginState || pluginState.showDatePickerAt === null) {
32
- return false;
33
- }
34
- if (!dispatch) {
35
- return false;
36
- }
37
- var tr = state.tr.setMeta(pluginKey, {
38
- focusDateInput: true
39
- });
40
- dispatch(tr);
41
- return true;
42
- };
43
- };
44
- export var setDatePickerAt = function setDatePickerAt(showDatePickerAt) {
45
- return function (state, dispatch) {
46
- dispatch(state.tr.setMeta(pluginKey, {
47
- showDatePickerAt: showDatePickerAt
48
- }));
49
- return true;
50
- };
51
- };
52
- export var closeDatePicker = function closeDatePicker() {
53
- return function (state, dispatch) {
54
- var _ref = pluginKey.getState(state) || {},
55
- showDatePickerAt = _ref.showDatePickerAt;
56
- if (!dispatch) {
57
- return false;
58
- }
59
- var tr = showDatePickerAt ? state.tr.setMeta(pluginKey, {
60
- showDatePickerAt: null,
61
- isNew: false
62
- }).setSelection(Selection.near(state.tr.doc.resolve(showDatePickerAt + 2))) : state.tr.setMeta(pluginKey, {
63
- isNew: false
64
- });
65
- dispatch(tr);
66
- return false;
67
- };
68
- };
69
- export var closeDatePickerWithAnalytics = function closeDatePickerWithAnalytics(_ref2) {
70
- var _pluginInjectionApi$a;
71
- var date = _ref2.date,
72
- pluginInjectionApi = _ref2.pluginInjectionApi;
73
- pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 || (_pluginInjectionApi$a = _pluginInjectionApi$a.actions) === null || _pluginInjectionApi$a === void 0 || _pluginInjectionApi$a.attachAnalyticsEvent({
74
- eventType: EVENT_TYPE.TRACK,
75
- action: ACTION.COMMITTED,
76
- actionSubject: ACTION_SUBJECT.DATE,
77
- attributes: {
78
- commitMethod: INPUT_METHOD.BLUR,
79
- isValid: date !== undefined,
80
- isToday: isToday(date)
81
- }
82
- });
83
- return closeDatePicker();
84
- };
85
- export var openDatePicker = function openDatePicker() {
86
- return function (state, dispatch) {
87
- var $from = state.selection.$from;
88
- var node = state.doc.nodeAt($from.pos);
89
- if (node && node.type.name === state.schema.nodes.date.name) {
90
- var showDatePickerAt = $from.pos;
91
- if (dispatch) {
92
- dispatch(state.tr.setMeta(pluginKey, {
93
- showDatePickerAt: showDatePickerAt
94
- }).setSelection(NodeSelection.create(state.doc, showDatePickerAt)));
95
- }
96
- }
97
- return false;
98
- };
99
- };
@@ -1,112 +0,0 @@
1
- import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
- import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
3
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
4
- import { canInsert } from '@atlaskit/editor-prosemirror/utils';
5
- import { todayTimestampInUTC } from '@atlaskit/editor-common/utils';
6
- import { pluginKey } from './pm-plugins/plugin-key';
7
- import { isToday } from './utils/internal';
8
- /** Delete the date and close the datepicker */
9
- export var deleteDateCommand = function deleteDateCommand(pluginInjectionApi) {
10
- return function (_ref) {
11
- var _pluginInjectionApi$d, _pluginInjectionApi$d2;
12
- var tr = _ref.tr;
13
- var _ref2 = (_pluginInjectionApi$d = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$d2 = pluginInjectionApi.date) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.sharedState.currentState()) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : {},
14
- showDatePickerAt = _ref2.showDatePickerAt;
15
- if (!showDatePickerAt) {
16
- return tr;
17
- }
18
- tr.delete(showDatePickerAt, showDatePickerAt + 1).setMeta(pluginKey, {
19
- showDatePickerAt: null,
20
- isNew: false
21
- });
22
- return tr;
23
- };
24
- };
25
- export var insertDateCommand = function insertDateCommand(pluginInjectionApi) {
26
- return function (_ref3) {
27
- var date = _ref3.date,
28
- inputMethod = _ref3.inputMethod,
29
- commitMethod = _ref3.commitMethod,
30
- _ref3$enterPressed = _ref3.enterPressed,
31
- enterPressed = _ref3$enterPressed === void 0 ? true : _ref3$enterPressed;
32
- return function (_ref4) {
33
- var _pluginInjectionApi$d3, _pluginInjectionApi$d4;
34
- var tr = _ref4.tr;
35
- var schema = tr.doc.type.schema;
36
- var timestamp;
37
- if (date) {
38
- timestamp = Date.UTC(date.year, date.month - 1, date.day).toString();
39
- } else {
40
- timestamp = todayTimestampInUTC();
41
- }
42
- if (inputMethod) {
43
- var _pluginInjectionApi$a;
44
- pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 || (_pluginInjectionApi$a = _pluginInjectionApi$a.actions) === null || _pluginInjectionApi$a === void 0 || _pluginInjectionApi$a.attachAnalyticsEvent({
45
- action: ACTION.INSERTED,
46
- actionSubject: ACTION_SUBJECT.DOCUMENT,
47
- actionSubjectId: ACTION_SUBJECT_ID.DATE,
48
- eventType: EVENT_TYPE.TRACK,
49
- attributes: {
50
- inputMethod: inputMethod
51
- }
52
- })(tr);
53
- }
54
- if (commitMethod) {
55
- var _pluginInjectionApi$a2;
56
- pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 || (_pluginInjectionApi$a2 = _pluginInjectionApi$a2.actions) === null || _pluginInjectionApi$a2 === void 0 || _pluginInjectionApi$a2.attachAnalyticsEvent({
57
- eventType: EVENT_TYPE.TRACK,
58
- action: ACTION.COMMITTED,
59
- actionSubject: ACTION_SUBJECT.DATE,
60
- attributes: {
61
- commitMethod: commitMethod,
62
- isValid: date !== undefined,
63
- isToday: isToday(date)
64
- }
65
- })(tr);
66
- }
67
- var _ref5 = (_pluginInjectionApi$d3 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$d4 = pluginInjectionApi.date) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.sharedState.currentState()) !== null && _pluginInjectionApi$d3 !== void 0 ? _pluginInjectionApi$d3 : {},
68
- showDatePickerAt = _ref5.showDatePickerAt;
69
- if (!showDatePickerAt) {
70
- var dateNode = schema.nodes.date.createChecked({
71
- timestamp: timestamp
72
- });
73
- var textNode = schema.text(' ');
74
- var fragment = Fragment.fromArray([dateNode, textNode]);
75
- var _tr$selection = tr.selection,
76
- from = _tr$selection.from,
77
- to = _tr$selection.to;
78
- var insertable = canInsert(tr.selection.$from, fragment);
79
- if (!insertable) {
80
- var parentSelection = NodeSelection.create(tr.doc, tr.selection.from - tr.selection.$anchor.parentOffset - 1);
81
- tr.insert(parentSelection.to, fragment).setSelection(NodeSelection.create(tr.doc, parentSelection.to + 1));
82
- } else {
83
- tr.replaceWith(from, to, fragment).setSelection(NodeSelection.create(tr.doc, from));
84
- }
85
- if (tr.docChanged) {
86
- tr.scrollIntoView().setMeta(pluginKey, {
87
- isNew: true
88
- });
89
- }
90
- return tr;
91
- }
92
- if (tr.doc.nodeAt(showDatePickerAt)) {
93
- if (enterPressed) {
94
- // Setting selection to outside the date node causes showDatePickerAt
95
- // to be set to null by the PM plugin (onSelectionChanged), which will
96
- // immediately close the datepicker once a valid date is typed in.
97
- // Adding this check forces it to stay open until the user presses Enter.
98
- tr = tr.setSelection(Selection.near(tr.doc.resolve(showDatePickerAt + 2)));
99
- }
100
- tr = tr.setNodeMarkup(showDatePickerAt, schema.nodes.date, {
101
- timestamp: timestamp
102
- }).setMeta(pluginKey, {
103
- isNew: false
104
- }).scrollIntoView();
105
- if (!enterPressed) {
106
- tr = tr.setSelection(NodeSelection.create(tr.doc, showDatePickerAt));
107
- }
108
- }
109
- return tr;
110
- };
111
- };
112
- };
@@ -1 +0,0 @@
1
- export { default as datePlugin } from './plugin';
@@ -1,37 +0,0 @@
1
- import React from 'react';
2
- import { DateSharedCssClassName } from '@atlaskit/editor-common/styles';
3
- import { useIntl } from 'react-intl-next';
4
- import { timestampToString, timestampToTaskContext, isPastDate } from '@atlaskit/editor-common/utils';
5
- import { Date } from '@atlaskit/date';
6
- import { setDatePickerAt } from '../actions';
7
- export function DateNodeView(props) {
8
- var timestamp = props.node.attrs.timestamp,
9
- _props$view$state = props.view.state,
10
- doc = _props$view$state.doc,
11
- schema = _props$view$state.schema,
12
- selection = _props$view$state.selection,
13
- getPos = props.getPos;
14
- var intl = useIntl();
15
- var pos = typeof getPos === 'function' ? getPos() : undefined;
16
-
17
- // We fall back to selection.$from even though it does not cover all use cases
18
- // eg. upon Editor init, selection is at the start, not at the Date node
19
- var $nodePos = typeof pos === 'number' ? doc.resolve(pos) : selection.$from;
20
- var parent = $nodePos.parent;
21
- var withinIncompleteTask = parent.type === schema.nodes.taskItem && parent.attrs.state !== 'DONE';
22
- var color = withinIncompleteTask && isPastDate(timestamp) ? 'red' : undefined;
23
- return /*#__PURE__*/React.createElement("span", {
24
- className: DateSharedCssClassName.DATE_WRAPPER,
25
- onClick: handleClick
26
- }, /*#__PURE__*/React.createElement(Date, {
27
- color: color,
28
- value: timestamp
29
- }, withinIncompleteTask ? timestampToTaskContext(timestamp, intl) : timestampToString(timestamp, intl)));
30
- function handleClick(event) {
31
- event.nativeEvent.stopImmediatePropagation();
32
- var _props$view = props.view,
33
- state = _props$view.state,
34
- dispatch = _props$view.dispatch;
35
- setDatePickerAt(state.selection.from)(state, dispatch);
36
- }
37
- }
@@ -1,8 +0,0 @@
1
- import { defineMessages } from 'react-intl-next';
2
- export var messages = defineMessages({
3
- editText: {
4
- id: 'fabric.editor.editDateText',
5
- defaultMessage: 'Edit Date',
6
- description: 'Title for the input that changes the date'
7
- }
8
- });