UNPKG

@atlaskit/editor-plugin-date

Version:

Date plugin for @atlaskit/editor-core

78 lines 2.9 kB
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'; let intlRef; export const dateNodeSpec = node => { intlRef = intlRef || createIntl({ locale: document.documentElement.lang || 'en-US' }); const timestamp = node.attrs.timestamp; const displayString = timestampToString(timestamp, intlRef); const wrapperAttrs = { class: 'date-lozenger-container', 'data-node-type': 'date', 'data-timestamp': timestamp, 'aria-busy': 'true' }; const 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)"} ${"var(--ds-space-050, 4px)"}`, margin: '0 1px' }) }; return ['span', wrapperAttrs, ['span', attrs, displayString]]; }; export const dateToDOM = (node, state, getPos, intl) => { const timestamp = node.attrs.timestamp; const pos = getPos === null || getPos === void 0 ? void 0 : getPos(); const { displayString, color } = getDateInformation(timestamp, intl, state, pos); const nodeWrapperAttrs = { 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; } const wrapperAttrs = { class: 'date-lozenger-container', 'data-node-type': 'date', 'data-timestamp': timestamp }; const attrs = { class: !color ? '' : `date-node-color-${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' }, '']]; };