Ai
2 Star 0 Fork 0

mirrors_bpmn-io/bpmn-js-embedded-comments

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
util.js 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
Nico Rehwaldt 提交于 2014-09-21 00:48 +08:00 . feat(comments): add initial implementation
module.exports._getCommentsElement = function(element, create) {
var bo = element.businessObject;
var docs = bo.get('documentation');
var comments;
// get comments node
docs.some(function(d) {
return d.textFormat === 'text/x-comments' && (comments = d);
});
// create if not existing
if (!comments && create) {
comments = bo.$model.create('bpmn:Documentation', { textFormat: 'text/x-comments' });
docs.push(comments);
}
return comments;
};
module.exports.getComments = function(element) {
var doc = this._getCommentsElement(element);
if (!doc || !doc.text) {
return [];
} else {
return doc.text.split(/;\r?\n;/).map(function(str) {
return str.split(/:/, 2);
});
}
};
module.exports.setComments = function(element, comments) {
var doc = this._getCommentsElement(element, true);
var str = comments.map(function(c) {
return c.join(':');
}).join(';\n;');
doc.text = str;
};
module.exports.addComment = function(element, author, str) {
var comments = this.getComments(element);
comments.push([ author, str ]);
this.setComments(element, comments);
};
module.exports.removeComment = function(element, comment) {
var comments = this.getComments(element);
var idx = -1;
comments.some(function(c, i) {
var matches = c[0] === comment[0] && c[1] === comment[1];
if (matches) {
idx = i;
}
return matches;
});
if (idx !== -1) {
comments.splice(idx, 1);
}
this.setComments(element, comments);
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_bpmn-io/bpmn-js-embedded-comments.git
git@gitee.com:mirrors_bpmn-io/bpmn-js-embedded-comments.git
mirrors_bpmn-io
bpmn-js-embedded-comments
bpmn-js-embedded-comments
v0.4.0

搜索帮助