@atlaskit/editor-plugin-date
Version:
Date plugin for @atlaskit/editor-core
80 lines • 3.79 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import { createIntl } from 'react-intl';
import { getBrowserInfo } from '@atlaskit/editor-common/browser';
import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
import { timestampToString } from '@atlaskit/editor-common/utils';
import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
import { fg } from '@atlaskit/platform-feature-flags';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
import { getDateInformation } from './utils';
var intlRef;
export var dateNodeSpec = function dateNodeSpec(node) {
intlRef = intlRef || createIntl({
locale: document.documentElement.lang || 'en-US'
});
var timestamp = node.attrs.timestamp;
var displayString = timestampToString(timestamp, intlRef);
var wrapperAttrs = {
class: 'date-lozenger-container',
'data-node-type': 'date',
'data-timestamp': timestamp,
'aria-busy': 'true'
};
var attrs = {
style: convertToInlineCss({
// Taken from @atlaskit/date Component
backgroundColor: "var(--ds-background-neutral, #0515240F)",
color: "var(--ds-text, #292A2E)",
borderRadius: "var(--ds-radius-small, 4px)",
padding: "var(--ds-space-025, 2px)".concat(" ", "var(--ds-space-050, 4px)"),
margin: '0 1px'
})
};
return ['span', wrapperAttrs, ['span', attrs, displayString]];
};
export var dateToDOM = function dateToDOM(node, state, getPos, intl) {
var timestamp = node.attrs.timestamp;
var pos = getPos === null || getPos === void 0 ? void 0 : getPos();
var _getDateInformation = getDateInformation(timestamp, intl, state, pos),
displayString = _getDateInformation.displayString,
color = _getDateInformation.color;
var nodeWrapperAttrs = _objectSpread(_objectSpread({
contenteditable: 'false',
timestamp: timestamp,
class: 'dateView-content-wrap inlineNodeView',
'data-prosemirror-content-type': 'node',
'data-prosemirror-node-name': 'date',
'data-prosemirror-node-inline': 'true'
}, expValEquals('platform_editor_copy_paste_issue_fix', 'isEnabled', true) ? {
'data-node-type': 'date',
'data-timestamp': timestamp
} : {}), {}, {
draggable: 'true'
});
if (fg('platform_editor_adf_with_localid')) {
nodeWrapperAttrs['data-local-id'] = node.attrs.localId;
}
var wrapperAttrs = {
class: 'date-lozenger-container',
'data-node-type': 'date',
'data-timestamp': timestamp
};
var attrs = {
class: !color ? '' : "date-node-color-".concat(color),
style: "white-space: unset"
};
return ['span', nodeWrapperAttrs, ['span', {
class: 'zeroWidthSpaceContainer'
}, ['span', {
class: 'inlineNodeViewAddZeroWidthSpace'
}, ZERO_WIDTH_SPACE]], ['span', wrapperAttrs, ['span', attrs, displayString]], getBrowserInfo().android ? ['span', {
class: 'zeroWidthSpaceContainer',
contentEditable: 'false'
}, ['span', {
class: 'inlineNodeViewAddZeroWidthSpace'
}, ZERO_WIDTH_SPACE]] : ['span', {
class: 'inlineNodeViewAddZeroWidthSpace'
}, '']];
};