@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
72 lines • 3.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var defaultAttrs = {
id: { default: '' },
type: { default: '' },
collection: { default: null },
occurrenceKey: { default: null },
__fileName: { default: null },
__fileSize: { default: null },
__fileMimeType: { default: null },
__displayType: { default: null },
};
exports.media = {
inline: false,
selectable: true,
attrs: defaultAttrs,
parseDOM: [{
tag: 'div[data-node-type="media"]',
getAttrs: function (dom) {
var _a = dom.dataset, id = _a.id, type = _a.type, collection = _a.collection, occurrenceKey = _a.occurrenceKey;
var attrs = { id: id, type: type, collection: collection, occurrenceKey: occurrenceKey };
Object.keys(dom.dataset).forEach(function (key) {
if (defaultAttrs["__" + key]) {
attrs["__" + key] = dom.dataset[key];
}
});
// Need to do validation & type conversion manually
if (attrs.__fileSize) {
attrs.__fileSize = +attrs.__fileSize;
}
return attrs;
}
}],
toDOM: function (node) {
var attrs = {
'data-id': node.attrs.id,
'data-node-type': 'media',
'data-type': node.attrs.type,
'data-collection': node.attrs.collection,
'data-occurrence-key': node.attrs.occurrenceKey,
// toDOM is used for static rendering as well as editor rendering. This comes into play for
// emails, copy/paste, etc, so the title and styling here *is* useful (despite a React-based
// node view being used for editing).
'title': 'Attachment',
// Manually kept in sync with the style of media cards. The goal is to render a plain grey
// rectangle that provides an affordance for media.
'style': 'display: inline-block; border-radius: 3px; background: #EBECF0; height: 104px; width: 156px; box-shadow: 0 1px 1px rgba(9, 30, 66, 0.2), 0 0 1px 0 rgba(9, 30, 66, 0.24);'
};
exports.copyOptionalAttrs(node.attrs, attrs, function (key) { return "data-" + camelCaseToKebabCase(key.slice(2)); });
return ['div', attrs];
}
};
var camelCaseToKebabCase = function (str) { return str.replace(/([^A-Z]+)([A-Z])/g, function (_, x, y) { return x + "-" + y.toLowerCase(); }); };
exports.copyOptionalAttrs = function (from, to, map) {
Object.keys(exports.media.attrs).forEach(function (key) {
if (key[0] === '_' && key[1] === '_' && from[key]) {
to[map ? map(key) : key] = from[key];
}
});
};
exports.toJSON = function (node) { return ({
attrs: Object.keys(node.attrs)
.filter(function (key) { return !(key[0] === '_' && key[1] === '_'); })
.reduce(function (obj, key) {
if (key === 'occurrenceKey' && !node.attrs[key]) {
return obj;
}
obj[key] = node.attrs[key];
return obj;
}, {})
}); };
//# sourceMappingURL=media.js.map