@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
67 lines • 2.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var ReactDOM = require("react-dom");
var task_decision_1 = require("@atlaskit/task-decision");
var Task = (function () {
function Task(node, view, getPos) {
var _this = this;
this.showPlaceholder = false;
this.handleRef = function (node) {
_this.contentDOMRef = node;
};
this.handleOnChange = function (taskId, isChecked) {
var view = _this.view;
var state = view.state;
var doc = state.doc, schema = state.schema, tr = state.tr;
var nodePos = _this.getPos();
var node = doc.nodeAt(nodePos);
tr.replaceWith(nodePos, nodePos + node.nodeSize, schema.nodes.taskItem.create({ state: isChecked ? 'DONE' : 'TODO' }, node.content));
view.dispatch(tr);
};
this.node = node;
this.view = view;
this.getPos = getPos;
this.showPlaceholder = node.content.childCount === 0;
this.renderReactComponent();
}
Task.prototype.renderReactComponent = function () {
this.domRef = document.createElement('li');
this.domRef.style['list-style-type'] = 'none';
var node = this.node;
var localId = node.attrs.localId;
// tslint:disable-next-line:variable-name
ReactDOM.render(React.createElement(task_decision_1.TaskItem, { taskId: localId, contentRef: this.handleRef, isDone: node.attrs.state === 'DONE', onChange: this.handleOnChange, showPlaceholder: this.showPlaceholder }), this.domRef);
};
Object.defineProperty(Task.prototype, "dom", {
get: function () {
return this.domRef;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Task.prototype, "contentDOM", {
get: function () {
return this.contentDOMRef;
},
enumerable: true,
configurable: true
});
Task.prototype.update = function () {
/**
* Returning false here fixes an error where the editor fails to set selection
* inside the contentDOM after a transaction. See ED-2374.
*/
return false;
};
Task.prototype.destroy = function () {
ReactDOM.unmountComponentAtNode(this.domRef);
this.domRef = undefined;
this.contentDOMRef = undefined;
};
return Task;
}());
exports.taskItemNodeView = function (node, view, getPos) {
return new Task(node, view, getPos);
};
//# sourceMappingURL=taskItem.js.map