UNPKG

@atlaskit/editor-plugin-date

Version:

Date plugin for @atlaskit/editor-core

184 lines (182 loc) 8.23 kB
/* index.tsx generated by @compiled/babel-plugin v0.39.1 */ import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/inherits"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import "./index.compiled.css"; import { ax, ix } from "@compiled/react/runtime"; function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } import React from 'react'; import { injectIntl } from 'react-intl'; import Calendar from '@atlaskit/calendar'; import { INPUT_METHOD } from '@atlaskit/editor-common/analytics'; import { dateMessages as messages } from '@atlaskit/editor-common/messages'; import { PlainOutsideClickTargetRefContext, Popup, withOuterListeners } from '@atlaskit/editor-common/ui'; import { timestampToIsoFormat, timestampToUTCDate } from '@atlaskit/editor-common/utils'; import { akEditorFloatingDialogZIndex } from '@atlaskit/editor-shared-styles'; import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals'; import VisuallyHidden from '@atlaskit/visually-hidden'; var PopupWithListeners = withOuterListeners(Popup); import DatePickerInput from './date-picker-input'; import { getDFLocale } from './utils/internal'; // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage var popupContentWrapper = null; // eslint-disable-next-line @repo/internal/react/no-class-components var DatePicker = /*#__PURE__*/function (_React$Component) { function DatePicker(props) { var _this; _classCallCheck(this, DatePicker); _this = _callSuper(this, DatePicker, [props]); // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _defineProperty(_this, "handleNewDate", function (date) { _this.props.onTextChanged(date); _this.setState({ latestValidDate: date }); }); _defineProperty(_this, "handleKeyboardSubmitDate", function (date) { _this.props.onSelect(date, INPUT_METHOD.KEYBOARD); }); _defineProperty(_this, "handleEmptySubmitDate", function () { _this.props.onDelete(); }); _defineProperty(_this, "handleOnChange", function (_ref) { var day = _ref.day, month = _ref.month, year = _ref.year; var date = { day: day, month: month, year: year }; _this.setState({ latestValidDate: date }); }); _defineProperty(_this, "closeDatePickerWithAnalytics", function () { _this.props.closeDatePickerWithAnalytics({ date: _this.state.latestValidDate }); }); _defineProperty(_this, "handleRef", function (ref) { var elm = ref; if (elm) { elm.focus(); } }); var timestamp = props.element.getAttribute('timestamp'); if (timestamp) { // Warning: The 'Date' return type of timestampToUTCDate() is not a JS date, it's more similar // to the DateType type var _timestampToUTCDate = timestampToUTCDate(timestamp), day = _timestampToUTCDate.day, month = _timestampToUTCDate.month, year = _timestampToUTCDate.year; var date = { day: day, month: month, year: year }; _this.state = { selected: [timestampToIsoFormat(timestamp)], date: date, latestValidDate: date }; } return _this; } _inherits(DatePicker, _React$Component); return _createClass(DatePicker, [{ key: "render", value: function render() { var _getDFLocale, _this2 = this; var _this$props = this.props, element = _this$props.element, _onSelect = _this$props.onSelect, mountTo = _this$props.mountTo, boundariesElement = _this$props.boundariesElement, scrollableElement = _this$props.scrollableElement, intl = _this$props.intl, dispatchAnalyticsEvent = _this$props.dispatchAnalyticsEvent, isNew = _this$props.isNew, autoFocus = _this$props.autoFocus, weekStartDay = _this$props.weekStartDay; // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion var timestamp = element.getAttribute('timestamp'); if (this.state === null) { // Without this, you can blow up the page by slowing down cpu, opening date, typing after date // then clicking on date lozenge and typing quickly before it opens return null; } var _this$state = this.state, date = _this$state.date, selected = _this$state.selected, latestValidDate = _this$state.latestValidDate; var day = latestValidDate.day, month = latestValidDate.month, year = latestValidDate.year; if (!timestamp) { return null; } var defaultWeekStartDay = expValEquals('platform_editor_locale_datepicker', 'isEnabled', true) ? (_getDFLocale = getDFLocale(intl.locale)) === null || _getDFLocale === void 0 || (_getDFLocale = _getDFLocale.options) === null || _getDFLocale === void 0 ? void 0 : _getDFLocale.weekStartsOn : undefined; return /*#__PURE__*/React.createElement(PopupWithListeners // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion , { target: element // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed) , offset: [0, 8], fitHeight: 370, fitWidth: 340, handleClickOutside: this.closeDatePickerWithAnalytics, handleEscapeKeydown: this.closeDatePickerWithAnalytics, zIndex: akEditorFloatingDialogZIndex, mountTo: mountTo, boundariesElement: boundariesElement, scrollableElement: scrollableElement, preventOverflow: true }, /*#__PURE__*/React.createElement(VisuallyHidden, { "aria-atomic": true, role: "alert" }, intl.formatMessage(messages.datePickerOpenedAlert)), /*#__PURE__*/React.createElement(PlainOutsideClickTargetRefContext.Consumer, null, function (setOutsideClickTargetRef) { return /*#__PURE__*/React.createElement("div", { ref: setOutsideClickTargetRef, className: ax(["_2rkofajl _ca0qv77o _n3tdv77o _19bvv77o _u5f3v77o _16qs130s _bfhk1bhr"]) }, /*#__PURE__*/React.createElement(DatePickerInput, { date: date, onNewDate: _this2.handleNewDate, onSubmitDate: _this2.handleKeyboardSubmitDate, onEmptySubmit: _this2.handleEmptySubmitDate, locale: intl.locale, dispatchAnalyticsEvent: dispatchAnalyticsEvent, autoFocus: autoFocus, autoSelectAll: isNew }), /*#__PURE__*/React.createElement(Calendar, { onChange: _this2.handleOnChange // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed) , onSelect: function onSelect(date) { return _onSelect(date, INPUT_METHOD.PICKER); }, day: day, month: month, year: year, selected: selected, ref: _this2.handleRef, weekStartDay: weekStartDay !== null && weekStartDay !== void 0 ? weekStartDay : defaultWeekStartDay, testId: 'datepicker', locale: expValEquals('platform_editor_locale_datepicker', 'isEnabled', true) ? intl.locale : undefined })); })); } }]); }(React.Component); // eslint-disable-next-line @typescript-eslint/ban-types var _default_1 = injectIntl(DatePicker); export default _default_1;