@atlaskit/adf-schema
Version:
Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs
94 lines (89 loc) • 3.16 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 { rule as ruleFactory } from '../../next-schema/generated/nodeTypes';
import { uuid } from '../../utils/uuid';
/**
* @name rule_node
*/
/**
* @name rule_root_only_node
*/
/**
* @name rule_with_attrs_node
*/
/**
* @name rule_with_attrs_root_only_node
*/
var hrDOM = ['hr'];
export var rule = ruleFactory({
parseDOM: [{
tag: 'hr'
}],
toDOM: function toDOM() {
return hrDOM;
}
});
export var ruleWithLocalId = ruleFactory({
parseDOM: [{
tag: 'hr',
getAttrs: function getAttrs() {
return {
localId: uuid.generate()
};
}
}],
toDOM: function toDOM(node) {
var _node$attrs;
return ['hr', {
'data-local-id': (node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId) || undefined
}];
}
});
var getAttrs = function getAttrs(domNode) {
// eslint-disable-next-line @atlaskit/editor/no-as-casting
var dom = domNode;
var weight = dom.getAttribute('data-weight');
return {
color: dom.getAttribute('data-color') || undefined,
localId: dom.getAttribute('data-local-id') || undefined,
style: dom.getAttribute('data-style') || undefined,
weight: weight === null || weight === '' ? undefined : Number(weight)
};
};
export var ruleWithAttrs = _objectSpread(_objectSpread({}, ruleWithLocalId), {}, {
attrs: _objectSpread(_objectSpread({}, ruleWithLocalId.attrs), {}, {
color: {
default: null
},
style: {
default: null
},
weight: {
default: null
}
}),
parseDOM: [{
tag: 'hr',
getAttrs: getAttrs
}],
toDOM: function toDOM(node) {
var _node$attrs2 = node.attrs,
color = _node$attrs2.color,
localId = _node$attrs2.localId,
style = _node$attrs2.style,
weight = _node$attrs2.weight;
return ['hr', {
'data-color': color || undefined,
'data-local-id': localId || undefined,
'data-style': style || undefined,
'data-weight': weight !== null && weight !== void 0 ? weight : undefined
}];
}
});
export var ruleRootOnlyStage0 = _objectSpread(_objectSpread({}, ruleWithLocalId), {}, {
marks: 'breakout unsupportedMark unsupportedNodeAttribute'
});
export var ruleWithAttrsRootOnlyStage0 = _objectSpread(_objectSpread({}, ruleWithAttrs), {}, {
marks: 'breakout unsupportedMark unsupportedNodeAttribute'
});