@atlaskit/editor-plugin-media
Version:
Media plugin for @atlaskit/editor-core
80 lines (77 loc) • 4.18 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 { media } from '@atlaskit/adf-schema';
import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
import { fg } from '@atlaskit/platform-feature-flags';
import { getMediaAttrs } from './toDOMAttrs';
/**
* Duplicate consts from `media-card`.
* `packages/media/media-card/src/utils/cardDimensions.ts`
*
* WHY?
* This will eventually move to `@atlaskit/adf-schema` and we cannot reference
* `media-card` from here or it will cause dependency issues.
*
* In the long term likely `toDOM` will move back out of `adf-schema` in which
* case we can consolidate them.
*/
export var defaultImageCardDimensions = {
width: 156,
height: 125
};
// @nodeSpecException:toDOM patch
export var mediaSpecWithFixedToDOM = function mediaSpecWithFixedToDOM() {
return _objectSpread(_objectSpread({}, media), {}, {
toDOM: function toDOM(node) {
var attrs = getMediaAttrs('media', node);
if (node.attrs.type === 'external') {
return ['img', _objectSpread(_objectSpread({}, attrs), {}, {
src: node.attrs.url,
style: convertToInlineCss({
backgroundColor: "var(--ds-background-neutral, #0515240F)",
outline: 'none',
width: "var(--ak-editor-media-card-width, 100%)",
height: "var(--ak-editor-media-card-height, 100%)"
})
})];
}
if (node.attrs.type === 'file') {
var dataUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
var width = defaultImageCardDimensions.width;
var height = defaultImageCardDimensions.height;
var sharedAttrs = _objectSpread(_objectSpread({
width: width,
height: height
}, attrs), {}, {
// Manually kept in sync with the style of media cards. The goal is to render a plain gray
// rectangle that provides an affordance for media.
style: convertToInlineCss({
display: 'var(--ak-editor-media-card-display, inline-block)',
backgroundImage: "url(\"".concat(dataUrl, "\")"),
marginLeft: '0',
marginRight: 'var(--ak-editor-media-margin-right, 4px)',
// eslint-disable-next-line @atlaskit/design-system/no-unsafe-design-token-usage
borderRadius: "var(--ds-radius-small, 3px)",
outline: 'none',
flexBasis: "".concat(defaultImageCardDimensions.width, "px"),
backgroundColor: 'var(--ak-editor-media-card-background-color)',
width: "var(--ak-editor-media-card-width, 100%)",
height: "var(--ak-editor-media-card-height, 0)",
paddingBottom: "var(--ak-editor-media-padding-bottom, 0)"
})
});
// Safari is stripping the dom if a child does not exist for the media nodes on safari.
// Creating an empty child allows safari to pick up the media node within the clipboard.
// https://product-fabric.atlassian.net/browse/ED-25841
return fg('platform_editor_safari_media_clipboard_fix') ? ['div', sharedAttrs, ['div', {}]] : ['div', sharedAttrs];
}
return ['div', _objectSpread(_objectSpread({}, attrs), {}, {
styles: convertToInlineCss({
backgroundColor: "var(--ak-editor-media-card-background-color, ".concat("var(--ds-background-neutral, #0515240F)", ")"),
outline: 'none'
})
})];
}
});
};