@atlaskit/editor-plugin-placeholder-text
Version:
placeholder text plugin for @atlaskit/editor-core
35 lines (34 loc) • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.showPlaceholderFloatingToolbar = exports.insertPlaceholderTextAtSelection = exports.hidePlaceholderFloatingToolbar = void 0;
var _pluginKey = require("../pm-plugins/plugin-key");
var showPlaceholderFloatingToolbar = exports.showPlaceholderFloatingToolbar = function showPlaceholderFloatingToolbar(state, dispatch) {
var tr = state.tr;
if (!state.selection.empty) {
tr.deleteSelection();
}
tr.setMeta(_pluginKey.pluginKey, {
showInsertPanelAt: tr.selection.anchor
});
tr.scrollIntoView();
dispatch(tr);
return true;
};
var insertPlaceholderTextAtSelection = exports.insertPlaceholderTextAtSelection = function insertPlaceholderTextAtSelection(value) {
return function (state, dispatch) {
dispatch(state.tr.replaceSelectionWith(state.schema.nodes.placeholder.createChecked({
text: value
})).setMeta(_pluginKey.pluginKey, {
showInsertPanelAt: null
}).scrollIntoView());
return true;
};
};
var hidePlaceholderFloatingToolbar = exports.hidePlaceholderFloatingToolbar = function hidePlaceholderFloatingToolbar(state, dispatch) {
dispatch(state.tr.setMeta(_pluginKey.pluginKey, {
showInsertPanelAt: null
}));
return true;
};