@atlaskit/adf-schema
Version:
Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs
52 lines (50 loc) • 1.57 kB
JavaScript
import { placeholder as placeholderFactory } from '../../next-schema/generated/nodeTypes';
import { uuid } from '../../utils/uuid';
/**
* @name placeholder_node
*/
export const placeholder = placeholderFactory({
parseDOM: [{
tag: 'span[data-placeholder]',
getAttrs: dom => ({
text:
// eslint-disable-next-line @atlaskit/editor/no-as-casting, @typescript-eslint/no-non-null-assertion
dom.getAttribute('data-placeholder') || placeholder.attrs.text.default
})
}],
toDOM(node) {
const {
text
} = node.attrs;
const attrs = {
'data-placeholder': text,
// Needs to be edtiable for mobile to not close keyboard
contenteditable: 'true'
};
return ['span', attrs, text];
}
});
export const placeholderWithLocalId = placeholderFactory({
parseDOM: [{
tag: 'span[data-placeholder]',
getAttrs: dom => ({
text:
// eslint-disable-next-line @atlaskit/editor/no-as-casting, @typescript-eslint/no-non-null-assertion
dom.getAttribute('data-placeholder') || placeholder.attrs.text.default,
localId: uuid.generate()
})
}],
toDOM(node) {
var _node$attrs;
const {
text
} = node.attrs;
const attrs = {
'data-placeholder': text,
// Needs to be edtiable for mobile to not close keyboard
contenteditable: 'true',
'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
};
return ['span', attrs, text];
}
});