@@ -216,9 +209,7 @@ const Render = ({ editor, node, updateAttributes }) => {
{content}
) : (
-
- {content}
-
+
{content}
)}
diff --git a/packages/client/src/components/tiptap/extensions/mind/jsmind.jsx b/packages/client/src/components/tiptap/extensions/mind/jsmind.jsx
index 583d35b4..d218931d 100644
--- a/packages/client/src/components/tiptap/extensions/mind/jsmind.jsx
+++ b/packages/client/src/components/tiptap/extensions/mind/jsmind.jsx
@@ -1,9 +1,9 @@
-import ReactDOM from "react-dom";
-import { Space, Button, Tooltip } from "@douyinfe/semi-ui";
-import { IconPlus, IconDelete } from "@douyinfe/semi-icons";
-import { IconZoomOut, IconZoomIn } from "components/icons";
-import { Divider } from "../../components/divider";
-import styles from "./index.module.scss";
+import ReactDOM from 'react-dom';
+import { Space, Button, Tooltip } from '@douyinfe/semi-ui';
+import { IconPlus, IconDelete } from '@douyinfe/semi-icons';
+import { IconZoomOut, IconZoomIn } from 'components/icons';
+import { Divider } from '../../components/divider';
+import styles from './index.module.scss';
/*
* Released under BSD License
@@ -14,19 +14,19 @@ import styles from "./index.module.scss";
*/
(function ($w) {
- "use strict";
+ 'use strict';
// set 'jsMind' as the library name.
// __name__ should be a const value, Never try to change it easily.
- var __name__ = "jsMind";
+ var __name__ = 'jsMind';
// library version
- var __version__ = "0.4.6";
+ var __version__ = '0.4.6';
// author
- var __author__ = "hizzgdev@163.com";
+ var __author__ = 'hizzgdev@163.com';
// an noop function define
var _noop = function () {};
var logger =
- typeof console === "undefined"
+ typeof console === 'undefined'
? {
log: _noop,
debug: _noop,
@@ -37,9 +37,9 @@ import styles from "./index.module.scss";
: console;
// check global variables
- if (typeof module === "undefined" || !module.exports) {
- if (typeof $w[__name__] != "undefined") {
- logger.log(__name__ + " has been already exist.");
+ if (typeof module === 'undefined' || !module.exports) {
+ if (typeof $w[__name__] != 'undefined') {
+ logger.log(__name__ + ' has been already exist.');
return;
}
}
@@ -66,30 +66,30 @@ import styles from "./index.module.scss";
var $i = function (el) {
return (
!!el &&
- typeof el === "object" &&
+ typeof el === 'object' &&
el.nodeType === 1 &&
- typeof el.style === "object" &&
- typeof el.ownerDocument === "object"
+ typeof el.style === 'object' &&
+ typeof el.ownerDocument === 'object'
);
};
- if (typeof String.prototype.startsWith != "function") {
+ if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (p) {
return this.slice(0, p.length) === p;
};
}
var DEFAULT_OPTIONS = {
- container: "", // id of the container
+ container: '', // id of the container
editable: false, // you can change it in your options
theme: null,
- mode: "full", // full or side
+ mode: 'full', // full or side
support_html: true,
view: {
hmargin: 100,
vmargin: 50,
line_width: 2,
- line_color: "#555",
+ line_color: '#555',
},
layout: {
hspace: 30,
@@ -128,7 +128,7 @@ import styles from "./index.module.scss";
jm.util.json.merge(opts, options);
if (!opts.container) {
- logger.error("the options.container should not be null or empty.");
+ logger.error('the options.container should not be null or empty.');
return;
}
this.options = opts;
@@ -142,25 +142,16 @@ import styles from "./index.module.scss";
jm.direction = { left: -1, center: 0, right: 1 };
jm.event_type = { show: 1, resize: 2, edit: 3, select: 4 };
- jm.node = function (
- sId,
- iIndex,
- sTopic,
- oData,
- bIsRoot,
- oParent,
- eDirection,
- bExpanded
- ) {
+ jm.node = function (sId, iIndex, sTopic, oData, bIsRoot, oParent, eDirection, bExpanded) {
if (!sId) {
- logger.error("invalid nodeid");
+ logger.error('invalid nodeid');
return;
}
- if (typeof iIndex != "number") {
- logger.error("invalid node index");
+ if (typeof iIndex != 'number') {
+ logger.error('invalid node index');
return;
}
- if (typeof bExpanded === "undefined") {
+ if (typeof bExpanded === 'undefined') {
bExpanded = true;
}
this.id = sId;
@@ -246,7 +237,7 @@ import styles from "./index.module.scss";
if (nodeid in this.nodes) {
return this.nodes[nodeid];
} else {
- logger.warn("the node[id=" + nodeid + "] can not be found");
+ logger.warn('the node[id=' + nodeid + '] can not be found');
return null;
}
},
@@ -256,36 +247,18 @@ import styles from "./index.module.scss";
this.root = new jm.node(nodeid, 0, topic, data, true);
this._put_node(this.root);
} else {
- logger.error("root node is already exist");
+ logger.error('root node is already exist');
}
},
- add_node: function (
- parent_node,
- nodeid,
- topic,
- data,
- idx,
- direction,
- expanded
- ) {
+ add_node: function (parent_node, nodeid, topic, data, idx, direction, expanded) {
if (!jm.util.is_node(parent_node)) {
var the_parent_node = this.get_node(parent_node);
if (!the_parent_node) {
- logger.error(
- "the parent_node[id=" + parent_node + "] can not be found."
- );
+ logger.error('the parent_node[id=' + parent_node + '] can not be found.');
return null;
} else {
- return this.add_node(
- the_parent_node,
- nodeid,
- topic,
- data,
- idx,
- direction,
- expanded
- );
+ return this.add_node(the_parent_node, nodeid, topic, data, idx, direction, expanded);
}
}
var nodeindex = idx || -1;
@@ -303,24 +276,11 @@ import styles from "./index.module.scss";
r++;
}
}
- d =
- children_len > 1 && r > 0 ? jm.direction.left : jm.direction.right;
+ d = children_len > 1 && r > 0 ? jm.direction.left : jm.direction.right;
} else {
- d =
- direction != jm.direction.left
- ? jm.direction.right
- : jm.direction.left;
+ d = direction != jm.direction.left ? jm.direction.right : jm.direction.left;
}
- node = new jm.node(
- nodeid,
- nodeindex,
- topic,
- data,
- false,
- parent_node,
- d,
- expanded
- );
+ node = new jm.node(nodeid, nodeindex, topic, data, false, parent_node, d, expanded);
} else {
node = new jm.node(
nodeid,
@@ -337,9 +297,7 @@ import styles from "./index.module.scss";
parent_node.children.push(node);
this._reindex(parent_node);
} else {
- logger.error(
- "fail, the nodeid '" + node.id + "' has been already exist."
- );
+ logger.error("fail, the nodeid '" + node.id + "' has been already exist.");
node = null;
}
return node;
@@ -349,9 +307,7 @@ import styles from "./index.module.scss";
if (!jm.util.is_node(node_before)) {
var the_node_before = this.get_node(node_before);
if (!the_node_before) {
- logger.error(
- "the node_before[id=" + node_before + "] can not be found."
- );
+ logger.error('the node_before[id=' + node_before + '] can not be found.');
return null;
} else {
return this.insert_node_before(the_node_before, nodeid, topic, data);
@@ -365,7 +321,7 @@ import styles from "./index.module.scss";
if (!jm.util.is_node(node)) {
var the_node = this.get_node(node);
if (!the_node) {
- logger.error("the node[id=" + node + "] can not be found.");
+ logger.error('the node[id=' + node + '] can not be found.');
return null;
} else {
return this.get_node_before(the_node);
@@ -386,9 +342,7 @@ import styles from "./index.module.scss";
if (!jm.util.is_node(node_after)) {
var the_node_after = this.get_node(node_before);
if (!the_node_after) {
- logger.error(
- "the node_after[id=" + node_after + "] can not be found."
- );
+ logger.error('the node_after[id=' + node_after + '] can not be found.');
return null;
} else {
return this.insert_node_after(the_node_after, nodeid, topic, data);
@@ -402,7 +356,7 @@ import styles from "./index.module.scss";
if (!jm.util.is_node(node)) {
var the_node = this.get_node(node);
if (!the_node) {
- logger.error("the node[id=" + node + "] can not be found.");
+ logger.error('the node[id=' + node + '] can not be found.');
return null;
} else {
return this.get_node_after(the_node);
@@ -424,7 +378,7 @@ import styles from "./index.module.scss";
if (!jm.util.is_node(node)) {
var the_node = this.get_node(node);
if (!the_node) {
- logger.error("the node[id=" + node + "] can not be found.");
+ logger.error('the node[id=' + node + '] can not be found.');
return null;
} else {
return this.move_node(the_node, beforeid, parentid, direction);
@@ -437,7 +391,7 @@ import styles from "./index.module.scss";
},
_flow_node_direction: function (node, direction) {
- if (typeof direction === "undefined") {
+ if (typeof direction === 'undefined') {
direction = node.direction;
} else {
node.direction = direction;
@@ -450,14 +404,14 @@ import styles from "./index.module.scss";
_move_node_internal: function (node, beforeid) {
if (!!node && !!beforeid) {
- if (beforeid == "_last_") {
+ if (beforeid == '_last_') {
node.index = -1;
this._reindex(node.parent);
- } else if (beforeid == "_first_") {
+ } else if (beforeid == '_first_') {
node.index = 0;
this._reindex(node.parent);
} else {
- var node_before = !!beforeid ? this.get_node(beforeid) : null;
+ var node_before = beforeid ? this.get_node(beforeid) : null;
if (
node_before != null &&
node_before.parent != null &&
@@ -506,18 +460,18 @@ import styles from "./index.module.scss";
if (!jm.util.is_node(node)) {
var the_node = this.get_node(node);
if (!the_node) {
- logger.error("the node[id=" + node + "] can not be found.");
+ logger.error('the node[id=' + node + '] can not be found.');
return false;
} else {
return this.remove_node(the_node);
}
}
if (!node) {
- logger.error("fail, the node can not be found");
+ logger.error('fail, the node can not be found');
return false;
}
if (node.isroot) {
- logger.error("fail, can not remove root node");
+ logger.error('fail, can not remove root node');
return false;
}
if (this.selected != null && this.selected.id == node.id) {
@@ -580,8 +534,8 @@ import styles from "./index.module.scss";
author: __author__,
version: __version__,
},
- format: "node_tree",
- data: { id: "root", topic: "jsMind Example" },
+ format: 'node_tree',
+ data: { id: 'root', topic: 'jsMind Example' },
},
get_mind: function (source) {
var df = jm.format.node_tree;
@@ -600,7 +554,7 @@ import styles from "./index.module.scss";
author: mind.author,
version: mind.version,
};
- json.format = "node_tree";
+ json.format = 'node_tree';
json.data = df._buildnode(mind.root);
return json;
},
@@ -609,7 +563,7 @@ import styles from "./index.module.scss";
var df = jm.format.node_tree;
var data = df._extract_data(node_root);
mind.set_root(node_root.id, node_root.topic, data);
- if ("children" in node_root) {
+ if ('children' in node_root) {
var children = node_root.children;
for (var i = 0; i < children.length; i++) {
df._extract_subnode(mind, mind.root, children[i]);
@@ -620,13 +574,7 @@ import styles from "./index.module.scss";
_extract_data: function (node_json) {
var data = {};
for (var k in node_json) {
- if (
- k == "id" ||
- k == "topic" ||
- k == "children" ||
- k == "direction" ||
- k == "expanded"
- ) {
+ if (k == 'id' || k == 'topic' || k == 'children' || k == 'direction' || k == 'expanded') {
continue;
}
data[k] = node_json[k];
@@ -639,10 +587,7 @@ import styles from "./index.module.scss";
var data = df._extract_data(node_json);
var d = null;
if (node_parent.isroot) {
- d =
- node_json.direction == "left"
- ? jm.direction.left
- : jm.direction.right;
+ d = node_json.direction == 'left' ? jm.direction.left : jm.direction.right;
}
var node = mind.add_node(
node_parent,
@@ -653,7 +598,7 @@ import styles from "./index.module.scss";
d,
node_json.expanded
);
- if ("children" in node_json) {
+ if ('children' in node_json) {
var children = node_json.children;
for (var i = 0; i < children.length; i++) {
df._extract_subnode(mind, node, children[i]);
@@ -672,7 +617,7 @@ import styles from "./index.module.scss";
expanded: node.expanded,
};
if (!!node.parent && node.parent.isroot) {
- o.direction = node.direction == jm.direction.left ? "left" : "right";
+ o.direction = node.direction == jm.direction.left ? 'left' : 'right';
}
if (node.data != null) {
var node_data = node.data;
@@ -698,8 +643,8 @@ import styles from "./index.module.scss";
author: __author__,
version: __version__,
},
- format: "node_array",
- data: [{ id: "root", topic: "jsMind Example", isroot: true }],
+ format: 'node_array',
+ data: [{ id: 'root', topic: 'jsMind Example', isroot: true }],
},
get_mind: function (source) {
@@ -720,7 +665,7 @@ import styles from "./index.module.scss";
author: mind.author,
version: mind.version,
};
- json.format = "node_array";
+ json.format = 'node_array';
json.data = [];
df._array(mind, json.data);
return json;
@@ -732,10 +677,10 @@ import styles from "./index.module.scss";
// reverse array for improving looping performance
narray.reverse();
var root_id = df._extract_root(mind, narray);
- if (!!root_id) {
+ if (root_id) {
df._extract_subnode(mind, root_id, narray);
} else {
- logger.error("root node can not be found");
+ logger.error('root node can not be found');
}
},
@@ -743,7 +688,7 @@ import styles from "./index.module.scss";
var df = jm.format.node_array;
var i = node_array.length;
while (i--) {
- if ("isroot" in node_array[i] && node_array[i].isroot) {
+ if ('isroot' in node_array[i] && node_array[i].isroot) {
var root_json = node_array[i];
var data = df._extract_data(root_json);
mind.set_root(root_json.id, root_json.topic, data);
@@ -766,11 +711,8 @@ import styles from "./index.module.scss";
data = df._extract_data(node_json);
var d = null;
var node_direction = node_json.direction;
- if (!!node_direction) {
- d =
- node_direction == "left"
- ? jm.direction.left
- : jm.direction.right;
+ if (node_direction) {
+ d = node_direction == 'left' ? jm.direction.left : jm.direction.right;
}
mind.add_node(
parentid,
@@ -783,11 +725,7 @@ import styles from "./index.module.scss";
);
node_array.splice(i, 1);
extract_count++;
- var sub_extract_count = df._extract_subnode(
- mind,
- node_json.id,
- node_array
- );
+ var sub_extract_count = df._extract_subnode(mind, node_json.id, node_array);
if (sub_extract_count > 0) {
// reset loop index after extract subordinate node
i = node_array.length;
@@ -802,12 +740,12 @@ import styles from "./index.module.scss";
var data = {};
for (var k in node_json) {
if (
- k == "id" ||
- k == "topic" ||
- k == "parentid" ||
- k == "isroot" ||
- k == "direction" ||
- k == "expanded"
+ k == 'id' ||
+ k == 'topic' ||
+ k == 'parentid' ||
+ k == 'isroot' ||
+ k == 'direction' ||
+ k == 'expanded'
) {
continue;
}
@@ -831,14 +769,14 @@ import styles from "./index.module.scss";
topic: node.topic,
expanded: node.expanded,
};
- if (!!node.parent) {
+ if (node.parent) {
o.parentid = node.parent.id;
}
if (node.isroot) {
o.isroot = true;
}
if (!!node.parent && node.parent.isroot) {
- o.direction = node.direction == jm.direction.left ? "left" : "right";
+ o.direction = node.direction == jm.direction.left ? 'left' : 'right';
}
if (node.data != null) {
var node_data = node.data;
@@ -861,7 +799,7 @@ import styles from "./index.module.scss";
author: __author__,
version: __version__,
},
- format: "freemind",
+ format: 'freemind',
data: '
',
},
get_mind: function (source) {
@@ -885,12 +823,12 @@ import styles from "./index.module.scss";
author: mind.author,
version: mind.version,
};
- json.format = "freemind";
+ json.format = 'freemind';
var xmllines = [];
xmllines.push('
");
- json.data = xmllines.join(" ");
+ xmllines.push('');
+ json.data = xmllines.join(' ');
return json;
},
@@ -898,10 +836,10 @@ import styles from "./index.module.scss";
var xml_doc = null;
if (window.DOMParser) {
var parser = new DOMParser();
- xml_doc = parser.parseFromString(xml, "text/xml");
+ xml_doc = parser.parseFromString(xml, 'text/xml');
} else {
// Internet Explorer
- xml_doc = new ActiveXObject("Microsoft.XMLDOM");
+ xml_doc = new ActiveXObject('Microsoft.XMLDOM');
xml_doc.async = false;
xml_doc.loadXML(xml);
}
@@ -915,17 +853,17 @@ import styles from "./index.module.scss";
var n = null;
for (var i = 0; i < nodes.length; i++) {
n = nodes[i];
- if (n.nodeType == 1 && n.tagName == "map") {
+ if (n.nodeType == 1 && n.tagName == 'map') {
node = n;
break;
}
}
- if (!!node) {
+ if (node) {
var ns = node.childNodes;
node = null;
for (var i = 0; i < ns.length; i++) {
n = ns[i];
- if (n.nodeType == 1 && n.tagName == "node") {
+ if (n.nodeType == 1 && n.tagName == 'node') {
node = n;
break;
}
@@ -936,8 +874,8 @@ import styles from "./index.module.scss";
_load_node: function (mind, parent_id, xml_node) {
var df = jm.format.freemind;
- var node_id = xml_node.getAttribute("ID");
- var node_topic = xml_node.getAttribute("TEXT");
+ var node_id = xml_node.getAttribute('ID');
+ var node_topic = xml_node.getAttribute('TEXT');
// look for richcontent
if (node_topic == null) {
var topic_children = xml_node.childNodes;
@@ -945,28 +883,23 @@ import styles from "./index.module.scss";
for (var i = 0; i < topic_children.length; i++) {
topic_child = topic_children[i];
//logger.debug(topic_child.tagName);
- if (
- topic_child.nodeType == 1 &&
- topic_child.tagName === "richcontent"
- ) {
+ if (topic_child.nodeType == 1 && topic_child.tagName === 'richcontent') {
node_topic = topic_child.textContent;
break;
}
}
}
var node_data = df._load_attributes(xml_node);
- var node_expanded =
- "expanded" in node_data ? node_data.expanded == "true" : true;
+ var node_expanded = 'expanded' in node_data ? node_data.expanded == 'true' : true;
delete node_data.expanded;
- var node_position = xml_node.getAttribute("POSITION");
+ var node_position = xml_node.getAttribute('POSITION');
var node_direction = null;
- if (!!node_position) {
- node_direction =
- node_position == "left" ? jm.direction.left : jm.direction.right;
+ if (node_position) {
+ node_direction = node_position == 'left' ? jm.direction.left : jm.direction.right;
}
//logger.debug(node_position +':'+ node_direction);
- if (!!parent_id) {
+ if (parent_id) {
mind.add_node(
parent_id,
node_id,
@@ -983,7 +916,7 @@ import styles from "./index.module.scss";
var child = null;
for (var i = 0; i < children.length; i++) {
child = children[i];
- if (child.nodeType == 1 && child.tagName == "node") {
+ if (child.nodeType == 1 && child.tagName == 'node') {
df._load_node(mind, node_id, child);
}
}
@@ -995,8 +928,8 @@ import styles from "./index.module.scss";
var attr_data = {};
for (var i = 0; i < children.length; i++) {
attr = children[i];
- if (attr.nodeType == 1 && attr.tagName === "attribute") {
- attr_data[attr.getAttribute("NAME")] = attr.getAttribute("VALUE");
+ if (attr.nodeType == 1 && attr.tagName === 'attribute') {
+ attr_data[attr.getAttribute('NAME')] = attr.getAttribute('VALUE');
}
}
return attr_data;
@@ -1006,27 +939,23 @@ import styles from "./index.module.scss";
var df = jm.format.freemind;
var pos = null;
if (!!node.parent && node.parent.isroot) {
- pos = node.direction === jm.direction.left ? "left" : "right";
+ pos = node.direction === jm.direction.left ? 'left' : 'right';
}
- xmllines.push("
');
// store expanded status as an attribute
- xmllines.push(
- ''
- );
+ xmllines.push('');
// for attributes
var node_data = node.data;
if (node_data != null) {
for (var k in node_data) {
- xmllines.push(
- ''
- );
+ xmllines.push('');
}
}
@@ -1036,7 +965,7 @@ import styles from "./index.module.scss";
df._buildmap(children[i], xmllines);
}
- xmllines.push("");
+ xmllines.push('');
},
},
};
@@ -1054,7 +983,7 @@ import styles from "./index.module.scss";
xhr = new XMLHttpRequest();
} else {
try {
- xhr = new ActiveXObject("Microsoft.XMLHTTP");
+ xhr = new ActiveXObject('Microsoft.XMLHTTP');
} catch (e) {}
}
return xhr;
@@ -1067,10 +996,10 @@ import styles from "./index.module.scss";
var p = null;
var tmp_param = [];
for (var k in param) {
- tmp_param.push(a._eurl(k) + "=" + a._eurl(param[k]));
+ tmp_param.push(a._eurl(k) + '=' + a._eurl(param[k]));
}
if (tmp_param.length > 0) {
- p = tmp_param.join("&");
+ p = tmp_param.join('&');
}
var xhr = a._xhr();
if (!xhr) {
@@ -1079,7 +1008,7 @@ import styles from "./index.module.scss";
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200 || xhr.status == 0) {
- if (typeof callback === "function") {
+ if (typeof callback === 'function') {
var data = jm.util.json.string2json(xhr.responseText);
if (data != null) {
callback(data);
@@ -1088,42 +1017,39 @@ import styles from "./index.module.scss";
}
}
} else {
- if (typeof fail_callback === "function") {
+ if (typeof fail_callback === 'function') {
fail_callback(xhr);
} else {
- logger.error("xhr request failed.", xhr);
+ logger.error('xhr request failed.', xhr);
}
}
}
};
- method = method || "GET";
+ method = method || 'GET';
xhr.open(method, url, true);
- xhr.setRequestHeader("If-Modified-Since", "0");
- if (method == "POST") {
- xhr.setRequestHeader(
- "Content-Type",
- "application/x-www-form-urlencoded;charset=utf-8"
- );
+ xhr.setRequestHeader('If-Modified-Since', '0');
+ if (method == 'POST') {
+ xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
xhr.send(p);
} else {
xhr.send();
}
},
get: function (url, callback) {
- return jm.util.ajax.request(url, {}, "GET", callback);
+ return jm.util.ajax.request(url, {}, 'GET', callback);
},
post: function (url, param, callback) {
- return jm.util.ajax.request(url, param, "POST", callback);
+ return jm.util.ajax.request(url, param, 'POST', callback);
},
},
dom: {
//target,eventType,handler
add_event: function (t, e, h) {
- if (!!t.addEventListener) {
+ if (t.addEventListener) {
t.addEventListener(e, h, true);
} else {
- t.attachEvent("on" + e, h);
+ t.attachEvent('on' + e, h);
}
},
},
@@ -1150,7 +1076,7 @@ import styles from "./index.module.scss";
read: function (file_data, fn_callback) {
var reader = new FileReader();
reader.onload = function () {
- if (typeof fn_callback === "function") {
+ if (typeof fn_callback === 'function') {
fn_callback(this.result, file_data.name);
}
};
@@ -1159,14 +1085,11 @@ import styles from "./index.module.scss";
save: function (file_data, type, name) {
var blob;
- if (typeof $w.Blob === "function") {
+ if (typeof $w.Blob === 'function') {
blob = new Blob([file_data], { type: type });
} else {
var BlobBuilder =
- $w.BlobBuilder ||
- $w.MozBlobBuilder ||
- $w.WebKitBlobBuilder ||
- $w.MSBlobBuilder;
+ $w.BlobBuilder || $w.MozBlobBuilder || $w.WebKitBlobBuilder || $w.MSBlobBuilder;
var bb = new BlobBuilder();
bb.append(file_data);
blob = bb.getBlob(type);
@@ -1176,14 +1099,14 @@ import styles from "./index.module.scss";
} else {
var URL = $w.URL || $w.webkitURL;
var bloburl = URL.createObjectURL(blob);
- var anchor = $c("a");
- if ("download" in anchor) {
- anchor.style.visibility = "hidden";
+ var anchor = $c('a');
+ if ('download' in anchor) {
+ anchor.style.visibility = 'hidden';
anchor.href = bloburl;
anchor.download = name;
$d.body.appendChild(anchor);
- var evt = $d.createEvent("MouseEvents");
- evt.initEvent("click", true, true);
+ var evt = $d.createEvent('MouseEvents');
+ evt.initEvent('click', true, true);
anchor.dispatchEvent(evt);
$d.body.removeChild(anchor);
} else {
@@ -1195,25 +1118,25 @@ import styles from "./index.module.scss";
json: {
json2string: function (json) {
- if (!!JSON) {
+ if (JSON) {
try {
var json_str = JSON.stringify(json);
return json_str;
} catch (e) {
logger.warn(e);
- logger.warn("can not convert to string");
+ logger.warn('can not convert to string');
return null;
}
}
},
string2json: function (json_str) {
- if (!!JSON) {
+ if (JSON) {
try {
var json = JSON.parse(json_str);
return json;
} catch (e) {
logger.warn(e);
- logger.warn("can not parse to json");
+ logger.warn('can not parse to json');
return null;
}
}
@@ -1222,9 +1145,8 @@ import styles from "./index.module.scss";
for (var o in a) {
if (o in b) {
if (
- typeof b[o] === "object" &&
- Object.prototype.toString.call(b[o]).toLowerCase() ==
- "[object object]" &&
+ typeof b[o] === 'object' &&
+ Object.prototype.toString.call(b[o]).toLowerCase() == '[object object]' &&
!b[o].length
) {
jm.util.json.merge(b[o], a[o]);
@@ -1241,10 +1163,10 @@ import styles from "./index.module.scss";
uuid: {
newid: function () {
- return (
- new Date().getTime().toString(16) +
- Math.random().toString(16).substr(2)
- ).substr(2, 16);
+ return (new Date().getTime().toString(16) + Math.random().toString(16).substr(2)).substr(
+ 2,
+ 16
+ );
},
},
@@ -1253,7 +1175,7 @@ import styles from "./index.module.scss";
if (!s) {
return true;
}
- return s.replace(/\s*/, "").length == 0;
+ return s.replace(/\s*/, '').length == 0;
},
},
};
@@ -1308,17 +1230,13 @@ import styles from "./index.module.scss";
// call enable_event_handle('dblclick')
// options are 'mousedown', 'click', 'dblclick'
enable_event_handle: function (event_handle) {
- this.options.default_event_handle[
- "enable_" + event_handle + "_handle"
- ] = true;
+ this.options.default_event_handle['enable_' + event_handle + '_handle'] = true;
},
// call disable_event_handle('dblclick')
// options are 'mousedown', 'click', 'dblclick'
disable_event_handle: function (event_handle) {
- this.options.default_event_handle[
- "enable_" + event_handle + "_handle"
- ] = false;
+ this.options.default_event_handle['enable_' + event_handle + '_handle'] = false;
},
get_editable: function () {
@@ -1327,25 +1245,25 @@ import styles from "./index.module.scss";
set_theme: function (theme) {
var theme_old = this.options.theme;
- this.options.theme = !!theme ? theme : null;
+ this.options.theme = theme ? theme : null;
if (theme_old != this.options.theme) {
this.view.reset_theme();
this.view.reset_custom_style();
}
},
_event_bind: function () {
- this.view.add_event(this, "mousedown", this.mousedown_handle);
- this.view.add_event(this, "click", this.click_handle);
- this.view.add_event(this, "dblclick", this.dblclick_handle);
+ this.view.add_event(this, 'mousedown', this.mousedown_handle);
+ this.view.add_event(this, 'click', this.click_handle);
+ this.view.add_event(this, 'dblclick', this.dblclick_handle);
},
mousedown_handle: function (e) {
- if (!this.options.default_event_handle["enable_mousedown_handle"]) {
+ if (!this.options.default_event_handle['enable_mousedown_handle']) {
return;
}
var element = e.target || event.srcElement;
var nodeid = this.view.get_binded_nodeid(element);
- if (!!nodeid) {
+ if (nodeid) {
this.select_node(nodeid);
} else {
this.select_clear();
@@ -1353,27 +1271,27 @@ import styles from "./index.module.scss";
},
click_handle: function (e) {
- if (!this.options.default_event_handle["enable_click_handle"]) {
+ if (!this.options.default_event_handle['enable_click_handle']) {
return;
}
var element = e.target || event.srcElement;
var isexpander = this.view.is_expander(element);
if (isexpander) {
var nodeid = this.view.get_binded_nodeid(element);
- if (!!nodeid) {
+ if (nodeid) {
this.toggle_node(nodeid);
}
}
},
dblclick_handle: function (e) {
- if (!this.options.default_event_handle["enable_dblclick_handle"]) {
+ if (!this.options.default_event_handle['enable_dblclick_handle']) {
return;
}
if (this.get_editable()) {
var element = e.target || event.srcElement;
var nodeid = this.view.get_binded_nodeid(element);
- if (!!nodeid) {
+ if (nodeid) {
this.begin_edit(nodeid);
}
}
@@ -1383,7 +1301,7 @@ import styles from "./index.module.scss";
if (!jm.util.is_node(node)) {
var the_node = this.get_node(node);
if (!the_node) {
- logger.error("the node[id=" + node + "] can not be found.");
+ logger.error('the node[id=' + node + '] can not be found.');
return false;
} else {
return this.begin_edit(the_node);
@@ -1392,7 +1310,7 @@ import styles from "./index.module.scss";
if (this.get_editable()) {
this.view.edit_node_begin(node);
} else {
- logger.error("fail, this mind map is not editable.");
+ logger.error('fail, this mind map is not editable.');
return;
}
},
@@ -1405,7 +1323,7 @@ import styles from "./index.module.scss";
if (!jm.util.is_node(node)) {
var the_node = this.get_node(node);
if (!the_node) {
- logger.error("the node[id=" + node + "] can not be found.");
+ logger.error('the node[id=' + node + '] can not be found.');
return;
} else {
return this.toggle_node(the_node);
@@ -1424,7 +1342,7 @@ import styles from "./index.module.scss";
if (!jm.util.is_node(node)) {
var the_node = this.get_node(node);
if (!the_node) {
- logger.error("the node[id=" + node + "] can not be found.");
+ logger.error('the node[id=' + node + '] can not be found.');
return;
} else {
return this.expand_node(the_node);
@@ -1443,7 +1361,7 @@ import styles from "./index.module.scss";
if (!jm.util.is_node(node)) {
var the_node = this.get_node(node);
if (!the_node) {
- logger.error("the node[id=" + node + "] can not be found.");
+ logger.error('the node[id=' + node + '] can not be found.');
return;
} else {
return this.collapse_node(the_node);
@@ -1484,20 +1402,20 @@ import styles from "./index.module.scss";
this.mind = this.data.load(m);
if (!this.mind) {
- logger.error("data.load error");
+ logger.error('data.load error');
return;
} else {
- logger.debug("data.load ok");
+ logger.debug('data.load ok');
}
this.view.load();
- logger.debug("view.load ok");
+ logger.debug('view.load ok');
this.layout.layout();
- logger.debug("layout.layout ok");
+ logger.debug('layout.layout ok');
this.view.show(true);
- logger.debug("view.show ok");
+ logger.debug('view.show ok');
this.invoke_event_handle(jm.event_type.show, { data: [mind] });
},
@@ -1516,7 +1434,7 @@ import styles from "./index.module.scss";
},
get_data: function (data_format) {
- var df = data_format || "node_tree";
+ var df = data_format || 'node_tree';
return this.data.get_data(df);
},
@@ -1531,49 +1449,42 @@ import styles from "./index.module.scss";
add_node: function (parent_node, nodeid, topic, data) {
if (this.get_editable()) {
var node = this.mind.add_node(parent_node, nodeid, topic, data);
- if (!!node) {
+ if (node) {
this.view.add_node(node);
this.layout.layout();
this.view.show(false);
this.view.reset_node_custom_style(node);
this.expand_node(parent_node);
this.invoke_event_handle(jm.event_type.edit, {
- evt: "add_node",
+ evt: 'add_node',
data: [parent_node.id, nodeid, topic, data],
node: nodeid,
});
}
return node;
} else {
- logger.error("fail, this mind map is not editable");
+ logger.error('fail, this mind map is not editable');
return null;
}
},
insert_node_before: function (node_before, nodeid, topic, data) {
if (this.get_editable()) {
- var beforeid = jm.util.is_node(node_before)
- ? node_before.id
- : node_before;
- var node = this.mind.insert_node_before(
- node_before,
- nodeid,
- topic,
- data
- );
- if (!!node) {
+ var beforeid = jm.util.is_node(node_before) ? node_before.id : node_before;
+ var node = this.mind.insert_node_before(node_before, nodeid, topic, data);
+ if (node) {
this.view.add_node(node);
this.layout.layout();
this.view.show(false);
this.invoke_event_handle(jm.event_type.edit, {
- evt: "insert_node_before",
+ evt: 'insert_node_before',
data: [beforeid, nodeid, topic, data],
node: nodeid,
});
}
return node;
} else {
- logger.error("fail, this mind map is not editable");
+ logger.error('fail, this mind map is not editable');
return null;
}
},
@@ -1582,19 +1493,19 @@ import styles from "./index.module.scss";
if (this.get_editable()) {
var afterid = jm.util.is_node(node_after) ? node_after.id : node_after;
var node = this.mind.insert_node_after(node_after, nodeid, topic, data);
- if (!!node) {
+ if (node) {
this.view.add_node(node);
this.layout.layout();
this.view.show(false);
this.invoke_event_handle(jm.event_type.edit, {
- evt: "insert_node_after",
+ evt: 'insert_node_after',
data: [afterid, nodeid, topic, data],
node: nodeid,
});
}
return node;
} else {
- logger.error("fail, this mind map is not editable");
+ logger.error('fail, this mind map is not editable');
return null;
}
},
@@ -1603,7 +1514,7 @@ import styles from "./index.module.scss";
if (!jm.util.is_node(node)) {
var the_node = this.get_node(node);
if (!the_node) {
- logger.error("the node[id=" + node + "] can not be found.");
+ logger.error('the node[id=' + node + '] can not be found.');
return false;
} else {
return this.remove_node(the_node);
@@ -1611,7 +1522,7 @@ import styles from "./index.module.scss";
}
if (this.get_editable()) {
if (node.isroot) {
- logger.error("fail, can not remove root node");
+ logger.error('fail, can not remove root node');
return false;
}
var nodeid = node.id;
@@ -1624,13 +1535,13 @@ import styles from "./index.module.scss";
this.view.show(false);
this.view.restore_location(parent_node);
this.invoke_event_handle(jm.event_type.edit, {
- evt: "remove_node",
+ evt: 'remove_node',
data: [nodeid],
node: parentid,
});
return true;
} else {
- logger.error("fail, this mind map is not editable");
+ logger.error('fail, this mind map is not editable');
return false;
}
},
@@ -1638,13 +1549,13 @@ import styles from "./index.module.scss";
update_node: function (nodeid, topic) {
if (this.get_editable()) {
if (jm.util.text.is_empty(topic)) {
- logger.warn("fail, topic can not be empty");
+ logger.warn('fail, topic can not be empty');
return;
}
var node = this.get_node(nodeid);
- if (!!node) {
+ if (node) {
if (node.topic === topic) {
- logger.info("nothing changed");
+ logger.info('nothing changed');
this.view.update_node(node);
return;
}
@@ -1653,13 +1564,13 @@ import styles from "./index.module.scss";
this.layout.layout();
this.view.show(false);
this.invoke_event_handle(jm.event_type.edit, {
- evt: "update_node",
+ evt: 'update_node',
data: [nodeid, topic],
node: nodeid,
});
}
} else {
- logger.error("fail, this mind map is not editable");
+ logger.error('fail, this mind map is not editable');
return;
}
},
@@ -1667,18 +1578,18 @@ import styles from "./index.module.scss";
move_node: function (nodeid, beforeid, parentid, direction) {
if (this.get_editable()) {
var node = this.mind.move_node(nodeid, beforeid, parentid, direction);
- if (!!node) {
+ if (node) {
this.view.update_node(node);
this.layout.layout();
this.view.show(false);
this.invoke_event_handle(jm.event_type.edit, {
- evt: "move_node",
+ evt: 'move_node',
data: [nodeid, beforeid, parentid, direction],
node: nodeid,
});
}
} else {
- logger.error("fail, this mind map is not editable");
+ logger.error('fail, this mind map is not editable');
return;
}
},
@@ -1687,7 +1598,7 @@ import styles from "./index.module.scss";
if (!jm.util.is_node(node)) {
var the_node = this.get_node(node);
if (!the_node) {
- logger.error("the node[id=" + node + "] can not be found.");
+ logger.error('the node[id=' + node + '] can not be found.');
return;
} else {
return this.select_node(the_node);
@@ -1701,7 +1612,7 @@ import styles from "./index.module.scss";
},
get_selected_node: function () {
- if (!!this.mind) {
+ if (this.mind) {
return this.mind.selected;
} else {
return null;
@@ -1709,7 +1620,7 @@ import styles from "./index.module.scss";
},
select_clear: function () {
- if (!!this.mind) {
+ if (this.mind) {
this.mind.selected = null;
this.view.select_clear();
}
@@ -1723,7 +1634,7 @@ import styles from "./index.module.scss";
if (!jm.util.is_node(node)) {
var the_node = this.get_node(node);
if (!the_node) {
- logger.error("the node[id=" + node + "] can not be found.");
+ logger.error('the node[id=' + node + '] can not be found.');
return;
} else {
return this.find_node_before(the_node);
@@ -1756,7 +1667,7 @@ import styles from "./index.module.scss";
if (!jm.util.is_node(node)) {
var the_node = this.get_node(node);
if (!the_node) {
- logger.error("the node[id=" + node + "] can not be found.");
+ logger.error('the node[id=' + node + '] can not be found.');
return;
} else {
return this.find_node_after(the_node);
@@ -1791,17 +1702,17 @@ import styles from "./index.module.scss";
set_node_color: function (nodeid, bgcolor, fgcolor) {
if (this.get_editable()) {
var node = this.mind.get_node(nodeid);
- if (!!node) {
- if (!!bgcolor) {
- node.data["background-color"] = bgcolor;
+ if (node) {
+ if (bgcolor) {
+ node.data['background-color'] = bgcolor;
}
- if (!!fgcolor) {
- node.data["foreground-color"] = fgcolor;
+ if (fgcolor) {
+ node.data['foreground-color'] = fgcolor;
}
this.view.reset_node_custom_style(node);
}
} else {
- logger.error("fail, this mind map is not editable");
+ logger.error('fail, this mind map is not editable');
return null;
}
},
@@ -1809,15 +1720,15 @@ import styles from "./index.module.scss";
set_node_font_style: function (nodeid, size, weight, style) {
if (this.get_editable()) {
var node = this.mind.get_node(nodeid);
- if (!!node) {
- if (!!size) {
- node.data["font-size"] = size;
+ if (node) {
+ if (size) {
+ node.data['font-size'] = size;
}
- if (!!weight) {
- node.data["font-weight"] = weight;
+ if (weight) {
+ node.data['font-weight'] = weight;
}
- if (!!style) {
- node.data["font-style"] = style;
+ if (style) {
+ node.data['font-style'] = style;
}
this.view.reset_node_custom_style(node);
this.view.update_node(node);
@@ -1825,32 +1736,26 @@ import styles from "./index.module.scss";
this.view.show(false);
}
} else {
- logger.error("fail, this mind map is not editable");
+ logger.error('fail, this mind map is not editable');
return null;
}
},
- set_node_background_image: function (
- nodeid,
- image,
- width,
- height,
- rotation
- ) {
+ set_node_background_image: function (nodeid, image, width, height, rotation) {
if (this.get_editable()) {
var node = this.mind.get_node(nodeid);
- if (!!node) {
- if (!!image) {
- node.data["background-image"] = image;
+ if (node) {
+ if (image) {
+ node.data['background-image'] = image;
}
- if (!!width) {
- node.data["width"] = width;
+ if (width) {
+ node.data['width'] = width;
}
- if (!!height) {
- node.data["height"] = height;
+ if (height) {
+ node.data['height'] = height;
}
- if (!!rotation) {
- node.data["background-rotation"] = rotation;
+ if (rotation) {
+ node.data['background-rotation'] = rotation;
}
this.view.reset_node_custom_style(node);
this.view.update_node(node);
@@ -1858,7 +1763,7 @@ import styles from "./index.module.scss";
this.view.show(false);
}
} else {
- logger.error("fail, this mind map is not editable");
+ logger.error('fail, this mind map is not editable');
return null;
}
},
@@ -1866,21 +1771,19 @@ import styles from "./index.module.scss";
set_node_background_rotation: function (nodeid, rotation) {
if (this.get_editable()) {
var node = this.mind.get_node(nodeid);
- if (!!node) {
- if (!node.data["background-image"]) {
- logger.error(
- "fail, only can change rotation angle of node with background image"
- );
+ if (node) {
+ if (!node.data['background-image']) {
+ logger.error('fail, only can change rotation angle of node with background image');
return null;
}
- node.data["background-rotation"] = rotation;
+ node.data['background-rotation'] = rotation;
this.view.reset_node_custom_style(node);
this.view.update_node(node);
this.layout.layout();
this.view.show(false);
}
} else {
- logger.error("fail, this mind map is not editable");
+ logger.error('fail, this mind map is not editable');
return null;
}
},
@@ -1891,7 +1794,7 @@ import styles from "./index.module.scss";
// callback(type ,data)
add_event_listener: function (callback) {
- if (typeof callback === "function") {
+ if (typeof callback === 'function') {
this.event_handles.push(callback);
}
},
@@ -1919,48 +1822,48 @@ import styles from "./index.module.scss";
jm.data_provider.prototype = {
init: function () {
- logger.debug("data.init");
+ logger.debug('data.init');
},
reset: function () {
- logger.debug("data.reset");
+ logger.debug('data.reset');
},
load: function (mind_data) {
var df = null;
var mind = null;
- if (typeof mind_data === "object") {
- if (!!mind_data.format) {
+ if (typeof mind_data === 'object') {
+ if (mind_data.format) {
df = mind_data.format;
} else {
- df = "node_tree";
+ df = 'node_tree';
}
} else {
- df = "freemind";
+ df = 'freemind';
}
- if (df == "node_array") {
+ if (df == 'node_array') {
mind = jm.format.node_array.get_mind(mind_data);
- } else if (df == "node_tree") {
+ } else if (df == 'node_tree') {
mind = jm.format.node_tree.get_mind(mind_data);
- } else if (df == "freemind") {
+ } else if (df == 'freemind') {
mind = jm.format.freemind.get_mind(mind_data);
} else {
- logger.warn("unsupported format");
+ logger.warn('unsupported format');
}
return mind;
},
get_data: function (data_format) {
var data = null;
- if (data_format == "node_array") {
+ if (data_format == 'node_array') {
data = jm.format.node_array.get_data(this.jm.mind);
- } else if (data_format == "node_tree") {
+ } else if (data_format == 'node_tree') {
data = jm.format.node_tree.get_data(this.jm.mind);
- } else if (data_format == "freemind") {
+ } else if (data_format == 'freemind') {
data = jm.format.freemind.get_data(this.jm.mind);
} else {
- logger.error("unsupported " + data_format + " format");
+ logger.error('unsupported ' + data_format + ' format');
}
return data;
},
@@ -1971,7 +1874,7 @@ import styles from "./index.module.scss";
jm.layout_provider = function (jm, options) {
this.opts = options;
this.jm = jm;
- this.isside = this.opts.mode == "side";
+ this.isside = this.opts.mode == 'side';
this.bounds = null;
this.cache_valid = false;
@@ -1979,14 +1882,14 @@ import styles from "./index.module.scss";
jm.layout_provider.prototype = {
init: function () {
- logger.debug("layout.init");
+ logger.debug('layout.init');
},
reset: function () {
- logger.debug("layout.reset");
+ logger.debug('layout.reset');
this.bounds = { n: 0, s: 0, w: 0, e: 0 };
},
layout: function () {
- logger.debug("layout.layout");
+ logger.debug('layout.layout');
this.layout_direction();
this.layout_offset();
},
@@ -1999,7 +1902,7 @@ import styles from "./index.module.scss";
var node = this.jm.mind.root;
// logger.debug(node);
var layout_data = null;
- if ("layout" in node._data) {
+ if ('layout' in node._data) {
layout_data = node._data.layout;
} else {
layout_data = {};
@@ -2040,7 +1943,7 @@ import styles from "./index.module.scss";
_layout_direction_side: function (node, direction, side_index) {
var layout_data = null;
- if ("layout" in node._data) {
+ if ('layout' in node._data) {
layout_data = node._data.layout;
} else {
layout_data = {};
@@ -2079,16 +1982,12 @@ import styles from "./index.module.scss";
layout_data.left_nodes = left_nodes;
layout_data.right_nodes = right_nodes;
layout_data.outer_height_left = this._layout_offset_subnodes(left_nodes);
- layout_data.outer_height_right =
- this._layout_offset_subnodes(right_nodes);
+ layout_data.outer_height_right = this._layout_offset_subnodes(right_nodes);
this.bounds.e = node._data.view.width / 2;
this.bounds.w = 0 - this.bounds.e;
//logger.debug(this.bounds.w);
this.bounds.n = 0;
- this.bounds.s = Math.max(
- layout_data.outer_height_left,
- layout_data.outer_height_right
- );
+ this.bounds.s = Math.max(layout_data.outer_height_left, layout_data.outer_height_right);
},
// layout both the x and y axis
@@ -2184,7 +2083,7 @@ import styles from "./index.module.scss";
get_node_offset: function (node) {
var layout_data = node._data.layout;
var offset_cache = null;
- if ("_offset_" in layout_data && this.cache_valid) {
+ if ('_offset_' in layout_data && this.cache_valid) {
offset_cache = layout_data._offset_;
} else {
offset_cache = { x: -1, y: -1 };
@@ -2209,8 +2108,7 @@ import styles from "./index.module.scss";
var offset_p = this.get_node_offset(node);
//logger.debug(offset_p);
var p = {};
- p.x =
- offset_p.x + (view_data.width * (node._data.layout.direction - 1)) / 2;
+ p.x = offset_p.x + (view_data.width * (node._data.layout.direction - 1)) / 2;
p.y = offset_p.y - view_data.height / 2;
//logger.debug(p);
return p;
@@ -2224,7 +2122,7 @@ import styles from "./index.module.scss";
get_node_point_out: function (node) {
var layout_data = node._data.layout;
var pout_cache = null;
- if ("_pout_" in layout_data && this.cache_valid) {
+ if ('_pout_' in layout_data && this.cache_valid) {
pout_cache = layout_data._pout_;
} else {
pout_cache = { x: -1, y: -1 };
@@ -2238,8 +2136,7 @@ import styles from "./index.module.scss";
var view_data = node._data.view;
var offset_p = this.get_node_offset(node);
pout_cache.x =
- offset_p.x +
- (view_data.width + this.opts.pspace) * node._data.layout.direction;
+ offset_p.x + (view_data.width + this.opts.pspace) * node._data.layout.direction;
pout_cache.y = offset_p.y;
//logger.debug('pout');
//logger.debug(pout_cache);
@@ -2366,20 +2263,24 @@ import styles from "./index.module.scss";
part_layout: function (node) {
var root = this.jm.mind.root;
- if (!!root) {
+ if (root) {
var root_layout_data = root._data.layout;
if (node.isroot) {
- root_layout_data.outer_height_right =
- this._layout_offset_subnodes_height(root_layout_data.right_nodes);
- root_layout_data.outer_height_left =
- this._layout_offset_subnodes_height(root_layout_data.left_nodes);
+ root_layout_data.outer_height_right = this._layout_offset_subnodes_height(
+ root_layout_data.right_nodes
+ );
+ root_layout_data.outer_height_left = this._layout_offset_subnodes_height(
+ root_layout_data.left_nodes
+ );
} else {
if (node._data.layout.direction == jm.direction.right) {
- root_layout_data.outer_height_right =
- this._layout_offset_subnodes_height(root_layout_data.right_nodes);
+ root_layout_data.outer_height_right = this._layout_offset_subnodes_height(
+ root_layout_data.right_nodes
+ );
} else {
- root_layout_data.outer_height_left =
- this._layout_offset_subnodes_height(root_layout_data.left_nodes);
+ root_layout_data.outer_height_left = this._layout_offset_subnodes_height(
+ root_layout_data.left_nodes
+ );
}
}
this.bounds.s = Math.max(
@@ -2388,7 +2289,7 @@ import styles from "./index.module.scss";
);
this.cache_valid = false;
} else {
- logger.warn("can not found root node");
+ logger.warn('can not found root node');
}
},
@@ -2416,7 +2317,7 @@ import styles from "./index.module.scss";
is_visible: function (node) {
var layout_data = node._data.layout;
- if ("visible" in layout_data && !layout_data.visible) {
+ if ('visible' in layout_data && !layout_data.visible) {
return false;
} else {
return true;
@@ -2444,26 +2345,24 @@ import styles from "./index.module.scss";
jm.view_provider.prototype = {
init: function () {
- logger.debug("view.init");
+ logger.debug('view.init');
- this.container = $i(this.opts.container)
- ? this.opts.container
- : $g(this.opts.container);
+ this.container = $i(this.opts.container) ? this.opts.container : $g(this.opts.container);
if (!this.container) {
- logger.error("the options.view.container was not be found in dom");
+ logger.error('the options.view.container was not be found in dom');
return;
}
- this.e_panel = $c("div");
- this.e_canvas = $c("canvas");
- this.e_nodes = $c("jmnodes");
- this.e_editor = $c("input");
+ this.e_panel = $c('div');
+ this.e_canvas = $c('canvas');
+ this.e_nodes = $c('jmnodes');
+ this.e_editor = $c('input');
- this.e_panel.className = "jsmind-inner";
+ this.e_panel.className = 'jsmind-inner';
this.e_panel.appendChild(this.e_canvas);
this.e_panel.appendChild(this.e_nodes);
- this.e_editor.className = "jsmind-editor";
- this.e_editor.type = "text";
+ this.e_editor.className = 'jsmind-editor';
+ this.e_editor.type = 'text';
this.actualZoom = 1;
this.zoomStep = 0.1;
@@ -2471,14 +2370,14 @@ import styles from "./index.module.scss";
this.maxZoom = 2;
var v = this;
- jm.util.dom.add_event(this.e_editor, "keydown", function (e) {
+ jm.util.dom.add_event(this.e_editor, 'keydown', function (e) {
var evt = e || event;
if (evt.keyCode == 13) {
v.edit_node_end();
evt.stopPropagation();
}
});
- jm.util.dom.add_event(this.e_editor, "blur", function (e) {
+ jm.util.dom.add_event(this.e_editor, 'blur', function (e) {
v.edit_node_end();
});
@@ -2499,22 +2398,22 @@ import styles from "./index.module.scss";
return null;
}
var tagName = element.tagName.toLowerCase();
- if (tagName == "jmnodes" || tagName == "body" || tagName == "html") {
+ if (tagName == 'jmnodes' || tagName == 'body' || tagName == 'html') {
return null;
}
- if (tagName == "jmnode" || tagName == "jmexpander") {
- return element.getAttribute("nodeid");
+ if (tagName == 'jmnode' || tagName == 'jmexpander') {
+ return element.getAttribute('nodeid');
} else {
return this.get_binded_nodeid(element.parentElement);
}
},
is_expander: function (element) {
- return element.tagName.toLowerCase() == "jmexpander";
+ return element.tagName.toLowerCase() == 'jmexpander';
},
reset: function () {
- logger.debug("view.reset");
+ logger.debug('view.reset');
this.selected_node = null;
this.clear_lines();
this.clear_nodes();
@@ -2523,10 +2422,10 @@ import styles from "./index.module.scss";
reset_theme: function () {
var theme_name = this.jm.options.theme;
- if (!!theme_name) {
- this.e_nodes.className = "theme-" + theme_name;
+ if (theme_name) {
+ this.e_nodes.className = 'theme-' + theme_name;
} else {
- this.e_nodes.className = "";
+ this.e_nodes.className = '';
}
},
@@ -2538,7 +2437,7 @@ import styles from "./index.module.scss";
},
load: function () {
- logger.debug("view.load");
+ logger.debug('view.load');
this.init_nodes();
},
@@ -2559,7 +2458,7 @@ import styles from "./index.module.scss";
},
init_canvas: function () {
- var ctx = this.e_canvas.getContext("2d");
+ var ctx = this.e_canvas.getContext('2d');
this.canvas_ctx = ctx;
const self = this;
this.createToolsDOMNode();
@@ -2571,7 +2470,7 @@ import styles from "./index.module.scss";
return;
}
- const div = document.createElement("div");
+ const div = document.createElement('div');
div.className = styles.jsmindWrap;
ReactDOM.render(
@@ -2610,9 +2509,9 @@ import styles from "./index.module.scss";
const selectedNode = _jm.get_selected_node();
if (!selectedNode) return;
const nodeid = jm.util.uuid.newid();
- const topic = "输入文字";
+ const topic = '输入文字';
const node = _jm.add_node(selectedNode, nodeid, topic);
- if (!!node) {
+ if (node) {
_jm.select_node(nodeid);
_jm.begin_edit(nodeid);
}
@@ -2643,18 +2542,18 @@ import styles from "./index.module.scss";
},
createAddHandlerDOMNode: function () {
- const span = document.createElement("div");
- span.innerText = "+";
+ const span = document.createElement('div');
+ span.innerText = '+';
span.style.cssText = `position:absolute;display: none;`;
ReactDOM.render(} />, span);
- this.container.querySelector("jmnodes").appendChild(span);
+ this.container.querySelector('jmnodes').appendChild(span);
this._add_handler_dom_node = span;
span.onclick = () => {
var selected_node = this.selected_node || null;
- if (!!selected_node) {
+ if (selected_node) {
var nodeid = jm.util.uuid.newid();
- var node = this.jm.add_node(selected_node, nodeid, "输入文字");
- if (!!node) {
+ var node = this.jm.add_node(selected_node, nodeid, '输入文字');
+ if (node) {
this.jm.select_node(nodeid);
this.jm.begin_edit(nodeid);
}
@@ -2674,10 +2573,8 @@ import styles from "./index.module.scss";
if (!node) return;
const direction = node.direction;
- el.style.display = "block";
- el.style.top = `${
- node._data.view.abs_y + node._data.view.height / 2 - 12
- }px`;
+ el.style.display = 'block';
+ el.style.top = `${node._data.view.abs_y + node._data.view.height / 2 - 12}px`;
el.style.left =
direction === -1
? `${node._data.view.abs_x - 34}px`
@@ -2686,7 +2583,7 @@ import styles from "./index.module.scss";
hideAddHandlerDOMNode: function () {
const el = this._add_handler_dom_node;
- el.style.display = "none";
+ el.style.display = 'none';
},
init_nodes_size: function (node) {
@@ -2714,33 +2611,33 @@ import styles from "./index.module.scss";
create_node_element: function (node, parent_node) {
var view_data = null;
- if ("view" in node._data) {
+ if ('view' in node._data) {
view_data = node._data.view;
} else {
view_data = {};
node._data.view = view_data;
}
- var d = $c("jmnode");
+ var d = $c('jmnode');
if (node.isroot) {
- d.className = "root";
+ d.className = 'root';
} else {
- var d_e = $c("jmexpander");
- $t(d_e, "-");
- d_e.setAttribute("nodeid", node.id);
- d_e.style.visibility = "hidden";
+ var d_e = $c('jmexpander');
+ $t(d_e, '-');
+ d_e.setAttribute('nodeid', node.id);
+ d_e.style.visibility = 'hidden';
parent_node.appendChild(d_e);
view_data.expander = d_e;
}
- if (!!node.topic) {
+ if (node.topic) {
if (this.opts.support_html) {
$h(d, node.topic);
} else {
$t(d, node.topic);
}
}
- d.setAttribute("nodeid", node.id);
- d.style.visibility = "hidden";
+ d.setAttribute('nodeid', node.id);
+ d.style.visibility = 'hidden';
this._reset_node_custom_style(d, node.data);
parent_node.appendChild(d);
@@ -2773,7 +2670,7 @@ import styles from "./index.module.scss";
update_node: function (node) {
var view_data = node._data.view;
var element = view_data.element;
- if (!!node.topic) {
+ if (node.topic) {
if (this.opts.support_html) {
$h(element, node.topic);
} else {
@@ -2785,17 +2682,14 @@ import styles from "./index.module.scss";
},
select_node: function (node) {
- if (!!this.selected_node) {
+ if (this.selected_node) {
this.selected_node._data.view.element.className =
- this.selected_node._data.view.element.className.replace(
- /\s*selected\b/i,
- ""
- );
+ this.selected_node._data.view.element.className.replace(/\s*selected\b/i, '');
this.reset_node_custom_style(this.selected_node);
}
- if (!!node) {
+ if (node) {
this.selected_node = node;
- node._data.view.element.className += " selected";
+ node._data.view.element.className += ' selected';
this.clear_node_custom_style(node);
this.showAddHandlerDOMNode(node);
}
@@ -2829,10 +2723,10 @@ import styles from "./index.module.scss";
this.e_editor.value = topic;
this.e_editor.style.width =
element.clientWidth -
- parseInt(ncs.getPropertyValue("padding-left")) -
- parseInt(ncs.getPropertyValue("padding-right")) +
- "px";
- element.innerHTML = "";
+ parseInt(ncs.getPropertyValue('padding-left')) -
+ parseInt(ncs.getPropertyValue('padding-right')) +
+ 'px';
+ element.innerHTML = '';
element.appendChild(this.e_editor);
element.style.zIndex = 5;
this.e_editor.focus();
@@ -2846,7 +2740,7 @@ import styles from "./index.module.scss";
var view_data = node._data.view;
var element = view_data.element;
var topic = this.e_editor.value;
- element.style.zIndex = "auto";
+ element.style.zIndex = 'auto';
element.removeChild(this.e_editor);
if (jm.util.text.is_empty(topic) || node.topic === topic) {
if (this.opts.support_html) {
@@ -2871,8 +2765,8 @@ import styles from "./index.module.scss";
resize: function () {
this.e_canvas.width = 1;
this.e_canvas.height = 1;
- this.e_nodes.style.width = "1px";
- this.e_nodes.style.height = "1px";
+ this.e_nodes.style.width = '1px';
+ this.e_nodes.style.height = '1px';
this.expand_size();
this._show();
@@ -2881,8 +2775,8 @@ import styles from "./index.module.scss";
_show: function () {
this.e_canvas.width = this.size.w;
this.e_canvas.height = this.size.h;
- this.e_nodes.style.width = this.size.w + "px";
- this.e_nodes.style.height = this.size.h + "px";
+ this.e_nodes.style.width = this.size.w + 'px';
+ this.e_nodes.style.height = this.size.h + 'px';
this.show_nodes();
this.show_lines();
//this.layout.cache_valid = true;
@@ -2903,7 +2797,7 @@ import styles from "./index.module.scss";
}
this.actualZoom = zoom;
for (var i = 0; i < this.e_panel.children.length; i++) {
- this.e_panel.children[i].style.transform = "scale(" + zoom + ")";
+ this.e_panel.children[i].style.transform = 'scale(' + zoom + ')';
}
this.show(true);
return true;
@@ -2923,10 +2817,10 @@ import styles from "./index.module.scss";
},
show: function (keep_center) {
- logger.debug("view.show");
+ logger.debug('view.show');
this.expand_size();
this._show();
- if (!!keep_center) {
+ if (keep_center) {
this._center_root();
}
},
@@ -2946,10 +2840,8 @@ import styles from "./index.module.scss";
restore_location: function (node) {
var vd = node._data.view;
- this.e_panel.scrollLeft =
- parseInt(vd.element.style.left) - vd._saved_location.x;
- this.e_panel.scrollTop =
- parseInt(vd.element.style.top) - vd._saved_location.y;
+ this.e_panel.scrollLeft = parseInt(vd.element.style.left) - vd._saved_location.x;
+ this.e_panel.scrollTop = parseInt(vd.element.style.top) - vd._saved_location.y;
},
clear_nodes: function () {
@@ -2964,7 +2856,7 @@ import styles from "./index.module.scss";
node._data.view.element = null;
node._data.view.expander = null;
}
- this.e_nodes.innerHTML = "";
+ this.e_nodes.innerHTML = '';
},
show_nodes: function () {
@@ -2974,7 +2866,7 @@ import styles from "./index.module.scss";
var expander = null;
var p = null;
var p_expander = null;
- var expander_text = "-";
+ var expander_text = '-';
var view_data = null;
var _offset = this.get_view_offset();
for (var nodeid in nodes) {
@@ -2983,31 +2875,31 @@ import styles from "./index.module.scss";
node_element = view_data.element;
expander = view_data.expander;
if (!this.layout.is_visible(node)) {
- node_element.style.display = "none";
- expander.style.display = "none";
+ node_element.style.display = 'none';
+ expander.style.display = 'none';
continue;
}
this.reset_node_custom_style(node);
p = this.layout.get_node_point(node);
view_data.abs_x = _offset.x + p.x;
view_data.abs_y = _offset.y + p.y;
- node_element.style.left = _offset.x + p.x + "px";
- node_element.style.top = _offset.y + p.y + "px";
- node_element.style.display = "";
- node_element.style.visibility = "visible";
+ node_element.style.left = _offset.x + p.x + 'px';
+ node_element.style.top = _offset.y + p.y + 'px';
+ node_element.style.display = '';
+ node_element.style.visibility = 'visible';
if (!node.isroot && node.children.length > 0) {
- expander_text = node.expanded ? "-" : "+";
+ expander_text = node.expanded ? '-' : '+';
p_expander = this.layout.get_expander_point(node);
- expander.style.left = _offset.x + p_expander.x + "px";
- expander.style.top = _offset.y + p_expander.y + "px";
- expander.style.display = "";
- expander.style.visibility = "visible";
+ expander.style.left = _offset.x + p_expander.x + 'px';
+ expander.style.top = _offset.y + p_expander.y + 'px';
+ expander.style.display = '';
+ expander.style.visibility = 'visible';
$t(expander, expander_text);
}
// hide expander while all children have been removed
if (!node.isroot && node.children.length == 0) {
- expander.style.display = "none";
- expander.style.visibility = "hidden";
+ expander.style.display = 'none';
+ expander.style.visibility = 'hidden';
}
}
},
@@ -3017,72 +2909,60 @@ import styles from "./index.module.scss";
},
_reset_node_custom_style: function (node_element, node_data) {
- if ("background-color" in node_data) {
- node_element.style.backgroundColor = node_data["background-color"];
+ if ('background-color' in node_data) {
+ node_element.style.backgroundColor = node_data['background-color'];
}
- if ("foreground-color" in node_data) {
- node_element.style.color = node_data["foreground-color"];
+ if ('foreground-color' in node_data) {
+ node_element.style.color = node_data['foreground-color'];
}
- if ("width" in node_data) {
- node_element.style.width = node_data["width"] + "px";
+ if ('width' in node_data) {
+ node_element.style.width = node_data['width'] + 'px';
}
- if ("height" in node_data) {
- node_element.style.height = node_data["height"] + "px";
+ if ('height' in node_data) {
+ node_element.style.height = node_data['height'] + 'px';
}
- if ("font-size" in node_data) {
- node_element.style.fontSize = node_data["font-size"] + "px";
+ if ('font-size' in node_data) {
+ node_element.style.fontSize = node_data['font-size'] + 'px';
}
- if ("font-weight" in node_data) {
- node_element.style.fontWeight = node_data["font-weight"];
+ if ('font-weight' in node_data) {
+ node_element.style.fontWeight = node_data['font-weight'];
}
- if ("font-style" in node_data) {
- node_element.style.fontStyle = node_data["font-style"];
+ if ('font-style' in node_data) {
+ node_element.style.fontStyle = node_data['font-style'];
}
- if ("background-image" in node_data) {
- var backgroundImage = node_data["background-image"];
- if (
- backgroundImage.startsWith("data") &&
- node_data["width"] &&
- node_data["height"]
- ) {
+ if ('background-image' in node_data) {
+ var backgroundImage = node_data['background-image'];
+ if (backgroundImage.startsWith('data') && node_data['width'] && node_data['height']) {
var img = new Image();
img.onload = function () {
- var c = $c("canvas");
+ var c = $c('canvas');
c.width = node_element.clientWidth;
c.height = node_element.clientHeight;
var img = this;
if (c.getContext) {
- var ctx = c.getContext("2d");
- ctx.drawImage(
- img,
- 2,
- 2,
- node_element.clientWidth,
- node_element.clientHeight
- );
+ var ctx = c.getContext('2d');
+ ctx.drawImage(img, 2, 2, node_element.clientWidth, node_element.clientHeight);
var scaledImageData = c.toDataURL();
- node_element.style.backgroundImage =
- "url(" + scaledImageData + ")";
+ node_element.style.backgroundImage = 'url(' + scaledImageData + ')';
}
};
img.src = backgroundImage;
} else {
- node_element.style.backgroundImage = "url(" + backgroundImage + ")";
+ node_element.style.backgroundImage = 'url(' + backgroundImage + ')';
}
- node_element.style.backgroundSize = "99%";
+ node_element.style.backgroundSize = '99%';
- if ("background-rotation" in node_data) {
- node_element.style.transform =
- "rotate(" + node_data["background-rotation"] + "deg)";
+ if ('background-rotation' in node_data) {
+ node_element.style.transform = 'rotate(' + node_data['background-rotation'] + 'deg)';
}
}
},
clear_node_custom_style: function (node) {
var node_element = node._data.view.element;
- node_element.style.backgroundColor = "";
- node_element.style.color = "";
+ node_element.style.backgroundColor = '';
+ node_element.style.color = '';
},
clear_lines: function (canvas_ctx) {
@@ -3099,10 +2979,10 @@ import styles from "./index.module.scss";
var _offset = this.get_view_offset();
for (var nodeid in nodes) {
node = nodes[nodeid];
- if (!!node.isroot) {
+ if (node.isroot) {
continue;
}
- if ("visible" in node._data.layout && !node._data.layout.visible) {
+ if ('visible' in node._data.layout && !node._data.layout.visible) {
continue;
}
pin = this.layout.get_node_point_in(node);
@@ -3115,7 +2995,7 @@ import styles from "./index.module.scss";
var ctx = canvas_ctx || this.canvas_ctx;
ctx.strokeStyle = this.opts.line_color;
ctx.lineWidth = this.opts.line_width;
- ctx.lineCap = "round";
+ ctx.lineCap = 'round';
jm.util.canvas.bezierto(
ctx,
@@ -3138,17 +3018,17 @@ import styles from "./index.module.scss";
jm.shortcut_provider.prototype = {
init: function () {
- jm.util.dom.add_event($d, "keydown", this.handler.bind(this));
+ jm.util.dom.add_event($d, 'keydown', this.handler.bind(this));
- this.handles["addchild"] = this.handle_addchild;
- this.handles["addbrother"] = this.handle_addbrother;
- this.handles["editnode"] = this.handle_editnode;
- this.handles["delnode"] = this.handle_delnode;
- this.handles["toggle"] = this.handle_toggle;
- this.handles["up"] = this.handle_up;
- this.handles["down"] = this.handle_down;
- this.handles["left"] = this.handle_left;
- this.handles["right"] = this.handle_right;
+ this.handles['addchild'] = this.handle_addchild;
+ this.handles['addbrother'] = this.handle_addbrother;
+ this.handles['editnode'] = this.handle_editnode;
+ this.handles['delnode'] = this.handle_delnode;
+ this.handles['toggle'] = this.handle_toggle;
+ this.handles['up'] = this.handle_up;
+ this.handles['down'] = this.handle_down;
+ this.handles['left'] = this.handle_left;
+ this.handles['right'] = this.handle_right;
for (var handle in this.mapping) {
if (!!this.mapping[handle] && handle in this.handles) {
@@ -3187,10 +3067,10 @@ import styles from "./index.module.scss";
handle_addchild: function (_jm, e) {
var selected_node = _jm.get_selected_node();
- if (!!selected_node) {
+ if (selected_node) {
var nodeid = jm.util.uuid.newid();
- var node = _jm.add_node(selected_node, nodeid, "输入文字");
- if (!!node) {
+ var node = _jm.add_node(selected_node, nodeid, '输入文字');
+ if (node) {
_jm.select_node(nodeid);
_jm.begin_edit(nodeid);
}
@@ -3200,8 +3080,8 @@ import styles from "./index.module.scss";
var selected_node = _jm.get_selected_node();
if (!!selected_node && !selected_node.isroot) {
var nodeid = jm.util.uuid.newid();
- var node = _jm.insert_node_after(selected_node, nodeid, "输入文字");
- if (!!node) {
+ var node = _jm.insert_node_after(selected_node, nodeid, '输入文字');
+ if (node) {
_jm.select_node(nodeid);
_jm.begin_edit(nodeid);
}
@@ -3209,7 +3089,7 @@ import styles from "./index.module.scss";
},
handle_editnode: function (_jm, e) {
var selected_node = _jm.get_selected_node();
- if (!!selected_node) {
+ if (selected_node) {
_jm.begin_edit(selected_node);
}
},
@@ -3224,7 +3104,7 @@ import styles from "./index.module.scss";
handle_toggle: function (_jm, e) {
var evt = e || event;
var selected_node = _jm.get_selected_node();
- if (!!selected_node) {
+ if (selected_node) {
_jm.toggle_node(selected_node.id);
evt.stopPropagation();
evt.preventDefault();
@@ -3233,7 +3113,7 @@ import styles from "./index.module.scss";
handle_up: function (_jm, e) {
var evt = e || event;
var selected_node = _jm.get_selected_node();
- if (!!selected_node) {
+ if (selected_node) {
var up_node = _jm.find_node_before(selected_node);
if (!up_node) {
var np = _jm.find_node_before(selected_node.parent);
@@ -3241,7 +3121,7 @@ import styles from "./index.module.scss";
up_node = np.children[np.children.length - 1];
}
}
- if (!!up_node) {
+ if (up_node) {
_jm.select_node(up_node);
}
evt.stopPropagation();
@@ -3252,7 +3132,7 @@ import styles from "./index.module.scss";
handle_down: function (_jm, e) {
var evt = e || event;
var selected_node = _jm.get_selected_node();
- if (!!selected_node) {
+ if (selected_node) {
var down_node = _jm.find_node_after(selected_node);
if (!down_node) {
var np = _jm.find_node_after(selected_node.parent);
@@ -3260,7 +3140,7 @@ import styles from "./index.module.scss";
down_node = np.children[0];
}
}
- if (!!down_node) {
+ if (down_node) {
_jm.select_node(down_node);
}
evt.stopPropagation();
@@ -3278,7 +3158,7 @@ import styles from "./index.module.scss";
var evt = e || event;
var selected_node = _jm.get_selected_node();
var node = null;
- if (!!selected_node) {
+ if (selected_node) {
if (selected_node.isroot) {
var c = selected_node.children;
var children = [];
@@ -3297,7 +3177,7 @@ import styles from "./index.module.scss";
} else {
node = selected_node.parent;
}
- if (!!node) {
+ if (node) {
_jm.select_node(node);
}
evt.stopPropagation();
@@ -3331,7 +3211,7 @@ import styles from "./index.module.scss";
var fn_init = null;
for (var i = 0; i < l; i++) {
fn_init = jm.plugins[i].init;
- if (typeof fn_init === "function") {
+ if (typeof fn_init === 'function') {
fn_init(sender);
}
}
@@ -3345,13 +3225,13 @@ import styles from "./index.module.scss";
};
// export jsmind
- if (typeof module !== "undefined" && typeof exports === "object") {
+ if (typeof module !== 'undefined' && typeof exports === 'object') {
module.exports = jm;
- } else if (typeof define === "function" && (define.amd || define.cmd)) {
+ } else if (typeof define === 'function' && (define.amd || define.cmd)) {
define(function () {
return jm;
});
} else {
$w[__name__] = jm;
}
-})(typeof window !== "undefined" ? window : global);
+})(typeof window !== 'undefined' ? window : global);
diff --git a/packages/client/src/components/tiptap/extensions/paste.tsx b/packages/client/src/components/tiptap/extensions/paste.tsx
index 8f832da0..6b436b9e 100644
--- a/packages/client/src/components/tiptap/extensions/paste.tsx
+++ b/packages/client/src/components/tiptap/extensions/paste.tsx
@@ -1,11 +1,11 @@
-import { Plugin, EditorState } from "prosemirror-state";
-import { Extension } from "@tiptap/core";
+import { Plugin, EditorState } from 'prosemirror-state';
+import { Extension } from '@tiptap/core';
// @ts-ignore
-import { lowlight } from "lowlight";
-import { uploadFile } from "services/file";
-import { Attachment } from "./attachment";
-import { Image } from "./image";
-import { markdownSerializer } from "../markdown";
+import { lowlight } from 'lowlight';
+import { uploadFile } from 'services/file';
+import { Attachment } from './attachment';
+import { Image } from './image';
+import { markdownSerializer } from '../markdown';
const isMarkActive =
(type) =>
@@ -40,7 +40,7 @@ const LANGUAGES = lowlight.listLanguages().reduce((a, language) => {
}, {});
export const acceptedMimes = {
- image: ["image/jpeg", "image/png", "image/gif", "image/jpg"],
+ image: ['image/jpeg', 'image/png', 'image/gif', 'image/jpg'],
};
function isMarkdown(text: string): boolean {
@@ -85,9 +85,9 @@ export const Paste = Extension.create({
if (!event.clipboardData) return false;
const file = event.clipboardData.files[0];
- const text = event.clipboardData.getData("text/plain");
- const html = event.clipboardData.getData("text/html");
- const vscode = event.clipboardData.getData("vscode-editor-data");
+ const text = event.clipboardData.getData('text/plain');
+ const html = event.clipboardData.getData('text/html');
+ const vscode = event.clipboardData.getData('vscode-editor-data');
if (file) {
event.preventDefault();
@@ -134,11 +134,7 @@ export const Paste = Extension.create({
// }
// 处理 markdown
- if (
- isMarkdown(text) ||
- html.length === 0 ||
- pasteCodeLanguage === "markdown"
- ) {
+ if (isMarkdown(text) || html.length === 0 || pasteCodeLanguage === 'markdown') {
event.preventDefault();
const paste = markdownSerializer.deserialize({
schema: view.props.state.schema,
@@ -184,12 +180,9 @@ export const Paste = Extension.create({
});
},
clipboardTextSerializer: (slice) => {
- const doc = this.editor.schema.topNodeType.createAndFill(
- undefined,
- slice.content
- );
+ const doc = this.editor.schema.topNodeType.createAndFill(undefined, slice.content);
if (!doc) {
- return "";
+ return '';
}
const content = markdownSerializer.serialize({
schema: this.editor.schema,
diff --git a/packages/client/src/components/tiptap/extensions/status/index.tsx b/packages/client/src/components/tiptap/extensions/status/index.tsx
index a446741a..674defe9 100644
--- a/packages/client/src/components/tiptap/extensions/status/index.tsx
+++ b/packages/client/src/components/tiptap/extensions/status/index.tsx
@@ -1,13 +1,9 @@
-import { Node, Command, mergeAttributes } from "@tiptap/core";
-import {
- NodeViewWrapper,
- NodeViewContent,
- ReactNodeViewRenderer,
-} from "@tiptap/react";
-import { Space, Popover, Tag, Input } from "@douyinfe/semi-ui";
-import styles from "./index.module.scss";
+import { Node, Command, mergeAttributes } from '@tiptap/core';
+import { NodeViewWrapper, NodeViewContent, ReactNodeViewRenderer } from '@tiptap/react';
+import { Space, Popover, Tag, Input } from '@douyinfe/semi-ui';
+import styles from './index.module.scss';
-declare module "@tiptap/core" {
+declare module '@tiptap/core' {
interface Commands {
status: {
setStatus: () => Command;
@@ -16,33 +12,30 @@ declare module "@tiptap/core" {
}
const StatusExtension = Node.create({
- name: "status",
- content: "text*",
- group: "inline",
+ name: 'status',
+ content: 'text*',
+ group: 'inline',
inline: true,
addAttributes() {
return {
color: {
- default: "grey",
+ default: 'grey',
},
text: {
- default: "",
+ default: '',
},
};
},
parseHTML() {
- return [{ tag: "span[data-type=status]" }];
+ return [{ tag: 'span[data-type=status]' }];
},
renderHTML({ HTMLAttributes }) {
return [
- "span",
- mergeAttributes(
- (this.options && this.options.HTMLAttributes) || {},
- HTMLAttributes
- ),
+ 'span',
+ mergeAttributes((this.options && this.options.HTMLAttributes) || {}, HTMLAttributes),
];
},
@@ -64,7 +57,7 @@ const StatusExtension = Node.create({
const Render = ({ editor, node, updateAttributes }) => {
const isEditable = editor.isEditable;
const { color, text } = node.attrs;
- const content = {text || "设置状态"};
+ const content = {text || '设置状态'};
return (
@@ -81,20 +74,18 @@ const Render = ({ editor, node, updateAttributes }) => {
/>
- {["grey", "red", "green", "orange", "purple", "teal"].map(
- (color) => {
- return (
- updateAttributes({ color })}
- >
- );
- }
- )}
+ {['grey', 'red', 'green', 'orange', 'purple', 'teal'].map((color) => {
+ return (
+ updateAttributes({ color })}
+ >
+ );
+ })}
>
}
diff --git a/packages/client/src/components/tiptap/extensions/table.tsx b/packages/client/src/components/tiptap/extensions/table.tsx
index e020ec75..c49d4199 100644
--- a/packages/client/src/components/tiptap/extensions/table.tsx
+++ b/packages/client/src/components/tiptap/extensions/table.tsx
@@ -1,6 +1,6 @@
-import Table from "@tiptap/extension-table";
-import TableRow from "@tiptap/extension-table-row";
-import TableCell from "@tiptap/extension-table-cell";
-import TableHeader from "@tiptap/extension-table-header";
+import Table from '@tiptap/extension-table';
+import TableRow from '@tiptap/extension-table-row';
+import TableCell from '@tiptap/extension-table-cell';
+import TableHeader from '@tiptap/extension-table-header';
export { Table, TableRow, TableCell, TableHeader };
diff --git a/packages/client/src/components/tiptap/extensions/title.tsx b/packages/client/src/components/tiptap/extensions/title.tsx
index 80c8ae0f..4d915051 100644
--- a/packages/client/src/components/tiptap/extensions/title.tsx
+++ b/packages/client/src/components/tiptap/extensions/title.tsx
@@ -1,15 +1,15 @@
-import { Node, mergeAttributes } from "@tiptap/core";
-import Document from "@tiptap/extension-document";
+import { Node, mergeAttributes } from '@tiptap/core';
+import Document from '@tiptap/extension-document';
const Title = Node.create({
- name: "title",
- group: "block",
- content: "text*",
+ name: 'title',
+ group: 'block',
+ content: 'text*',
addOptions() {
return {
HTMLAttributes: {
- class: "title",
+ class: 'title',
},
};
},
@@ -17,22 +17,18 @@ const Title = Node.create({
parseHTML() {
return [
{
- tag: "h1[class=title]",
+ tag: 'h1[class=title]',
},
];
},
renderHTML({ HTMLAttributes }) {
- return [
- "h1",
- mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
- 0,
- ];
+ return ['h1', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
},
});
const TitledDocument = Document.extend({
- content: "title block+",
+ content: 'title block+',
});
export { Document, Title, TitledDocument };
diff --git a/packages/client/src/components/tiptap/extensions/toc/index.tsx b/packages/client/src/components/tiptap/extensions/toc/index.tsx
index ab3a0865..c7ee2619 100644
--- a/packages/client/src/components/tiptap/extensions/toc/index.tsx
+++ b/packages/client/src/components/tiptap/extensions/toc/index.tsx
@@ -1,8 +1,8 @@
-import { useState, useEffect, useCallback } from "react";
-import { Command, Node, mergeAttributes } from "@tiptap/core";
-import { ReactNodeViewRenderer } from "@tiptap/react";
+import { useState, useEffect, useCallback } from 'react';
+import { Command, Node, mergeAttributes } from '@tiptap/core';
+import { ReactNodeViewRenderer } from '@tiptap/react';
-declare module "@tiptap/core" {
+declare module '@tiptap/core' {
interface Commands {
tableOfContents: {
setToc: () => Command;
@@ -18,7 +18,7 @@ const Component = ({ editor }) => {
const transaction = editor.state.tr;
editor.state.doc.descendants((node, pos) => {
- if (node.type.name === "heading") {
+ if (node.type.name === 'heading') {
const id = `heading-${headings.length + 1}`;
if (node.attrs.id !== id) {
@@ -36,8 +36,8 @@ const Component = ({ editor }) => {
}
});
- transaction.setMeta("addToHistory", false);
- transaction.setMeta("preventUpdate", true);
+ transaction.setMeta('addToHistory', false);
+ transaction.setMeta('preventUpdate', true);
editor.view.dispatch(transaction);
@@ -51,10 +51,10 @@ const Component = ({ editor }) => {
return null;
}
- editor.on("update", handleUpdate);
+ editor.on('update', handleUpdate);
return () => {
- editor.off("update", handleUpdate);
+ editor.off('update', handleUpdate);
};
}, [editor]);
@@ -62,22 +62,22 @@ const Component = ({ editor }) => {
};
export const Toc = Node.create({
- name: "tableOfContents",
+ name: 'tableOfContents',
- group: "block",
+ group: 'block',
atom: true,
parseHTML() {
return [
{
- tag: "toc",
+ tag: 'toc',
},
];
},
renderHTML({ HTMLAttributes }) {
- return ["toc", mergeAttributes(HTMLAttributes)];
+ return ['toc', mergeAttributes(HTMLAttributes)];
},
addNodeView() {
@@ -87,7 +87,7 @@ export const Toc = Node.create({
addGlobalAttributes() {
return [
{
- types: ["heading"],
+ types: ['heading'],
attributes: {
id: {
default: null,
diff --git a/packages/client/src/components/tiptap/extensions/trailing-node.tsx b/packages/client/src/components/tiptap/extensions/trailing-node.tsx
index 17f7fc27..b6261958 100644
--- a/packages/client/src/components/tiptap/extensions/trailing-node.tsx
+++ b/packages/client/src/components/tiptap/extensions/trailing-node.tsx
@@ -1,15 +1,14 @@
-import { Extension } from '@tiptap/core'
-import { PluginKey, Plugin } from 'prosemirror-state'
+import { Extension } from '@tiptap/core';
+import { PluginKey, Plugin } from 'prosemirror-state';
// @ts-ignore
function nodeEqualsType({ types, node }) {
- return (Array.isArray(types) && types.includes(node.type)) || node.type === types
+ return (Array.isArray(types) && types.includes(node.type)) || node.type === types;
}
-
export interface TrailingNodeOptions {
- node: string,
- notAfter: string[],
+ node: string;
+ notAfter: string[];
}
export const TrailingNode = Extension.create
({
@@ -18,50 +17,48 @@ export const TrailingNode = Extension.create({
addOptions() {
return {
node: 'paragraph',
- notAfter: [
- 'paragraph',
- ],
- }
+ notAfter: ['paragraph'],
+ };
},
addProseMirrorPlugins() {
- const plugin = new PluginKey(this.name)
+ const plugin = new PluginKey(this.name);
const disabledNodes = Object.entries(this.editor.schema.nodes)
.map(([, value]) => value)
- .filter(node => this.options.notAfter.includes(node.name))
+ .filter((node) => this.options.notAfter.includes(node.name));
return [
new Plugin({
key: plugin,
appendTransaction: (_, __, state) => {
- const { doc, tr, schema } = state
- const shouldInsertNodeAtEnd = plugin.getState(state)
- const endPosition = doc.content.size
- const type = schema.nodes[this.options.node]
+ const { doc, tr, schema } = state;
+ const shouldInsertNodeAtEnd = plugin.getState(state);
+ const endPosition = doc.content.size;
+ const type = schema.nodes[this.options.node];
if (!shouldInsertNodeAtEnd) {
- return
+ return;
}
- return tr.insert(endPosition, type.create())
+ return tr.insert(endPosition, type.create());
},
state: {
init: (_, state) => {
- const lastNode = state.tr.doc.lastChild
+ const lastNode = state.tr.doc.lastChild;
- return !nodeEqualsType({ node: lastNode, types: disabledNodes })
+ return !nodeEqualsType({ node: lastNode, types: disabledNodes });
},
apply: (tr, value) => {
if (!tr.docChanged) {
- return value
+ return value;
}
- const lastNode = tr.doc.lastChild
+ const lastNode = tr.doc.lastChild;
- return !nodeEqualsType({ node: lastNode, types: disabledNodes })
+ return !nodeEqualsType({ node: lastNode, types: disabledNodes });
},
},
}),
- ]
+ ];
},
-})
\ No newline at end of file
+});
diff --git a/packages/client/src/components/tiptap/index.tsx b/packages/client/src/components/tiptap/index.tsx
index a6cc51ff..eed6cf9e 100644
--- a/packages/client/src/components/tiptap/index.tsx
+++ b/packages/client/src/components/tiptap/index.tsx
@@ -1,18 +1,14 @@
-import {
- BaseExtension,
- Document,
- TitledDocument as DocumentWithTitle,
-} from "./base-kit";
-import { HocuspocusProvider } from "@hocuspocus/provider";
-import Collaboration from "@tiptap/extension-collaboration";
-import CollaborationCursor from "@tiptap/extension-collaboration-cursor";
-import { getRandomColor } from "helpers/color";
+import { BaseExtension, Document, TitledDocument as DocumentWithTitle } from './base-kit';
+import { HocuspocusProvider } from '@hocuspocus/provider';
+import Collaboration from '@tiptap/extension-collaboration';
+import CollaborationCursor from '@tiptap/extension-collaboration-cursor';
+import { getRandomColor } from 'helpers/color';
-export { getSchema } from "@tiptap/core";
-export * from "./menubar";
-export * from "./provider";
-export * from "./skeleton";
-export * from "./toc";
+export { getSchema } from '@tiptap/core';
+export * from './menubar';
+export * from './provider';
+export * from './skeleton';
+export * from './toc';
export { Document, DocumentWithTitle };
export const DEFAULT_EXTENSION = [...BaseExtension];
@@ -21,10 +17,7 @@ export const getCollaborationExtension = (provider: HocuspocusProvider) => {
document: provider.document,
});
};
-export const getCollaborationCursorExtension = (
- provider: HocuspocusProvider,
- user
-) => {
+export const getCollaborationCursorExtension = (provider: HocuspocusProvider, user) => {
return CollaborationCursor.configure({
provider,
user: {
diff --git a/packages/client/src/components/tiptap/markdown/helpers.tsx b/packages/client/src/components/tiptap/markdown/helpers.tsx
index 0787f684..03facc55 100644
--- a/packages/client/src/components/tiptap/markdown/helpers.tsx
+++ b/packages/client/src/components/tiptap/markdown/helpers.tsx
@@ -4,11 +4,11 @@ const uniq = (arr: string[]) => [...new Set(arr)];
function isString(value) {
const type = typeof value;
return (
- type === "string" ||
- (type === "object" &&
+ type === 'string' ||
+ (type === 'object' &&
value != null &&
!Array.isArray(value) &&
- Object.prototype.toString.call(value) == "[object String]")
+ Object.prototype.toString.call(value) == '[object String]')
);
}
@@ -18,8 +18,8 @@ const defaultAttrs = {
};
const ignoreAttrs = {
- dd: ["isTerm"],
- dt: ["isTerm"],
+ dd: ['isTerm'],
+ dt: ['isTerm'],
};
const tableMap = new WeakMap();
@@ -52,7 +52,7 @@ function containsOnlyText(node) {
function containsParagraphWithOnlyText(cell) {
if (cell.childCount === 1) {
const child = cell.child(0);
- if (child.type.name === "paragraph") {
+ if (child.type.name === 'paragraph') {
return containsOnlyText(child);
}
}
@@ -64,12 +64,12 @@ function getRowsAndCells(table) {
const cells = [];
const rows = [];
table.descendants((n) => {
- if (n.type.name === "tableCell" || n.type.name === "tableHeader") {
+ if (n.type.name === 'tableCell' || n.type.name === 'tableHeader') {
cells.push(n);
return false;
}
- if (n.type.name === "tableRow") {
+ if (n.type.name === 'tableRow') {
rows.push(n);
}
@@ -93,9 +93,7 @@ export function shouldRenderHTMLTable(table) {
const maxColspan = Math.max(...cells.map((cell) => cell.attrs.colspan));
const maxRowspan = Math.max(...cells.map((cell) => cell.attrs.rowspan));
- const rowChildren = rows.map((row) =>
- uniq(getChildren(row).map((cell) => cell.type.name))
- );
+ const rowChildren = rows.map((row) => uniq(getChildren(row).map((cell) => cell.type.name)));
const cellTypeInFirstRow = rowChildren[0];
const cellTypesInOtherRows = uniq(rowChildren.slice(1).map(([type]) => type));
@@ -103,9 +101,9 @@ export function shouldRenderHTMLTable(table) {
if (
!(
cellTypeInFirstRow.length === 1 &&
- cellTypeInFirstRow[0] === "tableHeader" &&
+ cellTypeInFirstRow[0] === 'tableHeader' &&
cellTypesInOtherRows.length === 1 &&
- cellTypesInOtherRows[0] === "tableCell"
+ cellTypesInOtherRows[0] === 'tableCell'
)
) {
return true;
@@ -114,7 +112,7 @@ export function shouldRenderHTMLTable(table) {
if (cellChildCount === 1 && maxColspan === 1 && maxRowspan === 1) {
// if all rows contain only one paragraph each and no rowspan/colspan, render markdown table
const children = uniq(cells.map((cell) => cell.child(0).type.name));
- if (children.length === 1 && children[0] === "paragraph") {
+ if (children.length === 1 && children[0] === 'paragraph') {
return false;
}
}
@@ -122,13 +120,13 @@ export function shouldRenderHTMLTable(table) {
return true;
}
-function htmlEncode(str = "") {
+function htmlEncode(str = '') {
return str
- .replace(/&/g, "&")
- .replace(//g, ">")
- .replace(/'/g, "'")
- .replace(/"/g, """);
+ .replace(/&/g, '&')
+ .replace(//g, '>')
+ .replace(/'/g, ''')
+ .replace(/"/g, '"');
}
export function openTag(tagName, attrs) {
@@ -136,15 +134,12 @@ export function openTag(tagName, attrs) {
str += Object.entries(attrs || {})
.map(([key, value]) => {
- if (
- (ignoreAttrs[tagName] || []).includes(key) ||
- defaultAttrs[tagName]?.[key] === value
- )
- return "";
+ if ((ignoreAttrs[tagName] || []).includes(key) || defaultAttrs[tagName]?.[key] === value)
+ return '';
return ` ${key}="${htmlEncode(value?.toString())}"`;
})
- .join("");
+ .join('');
return `${str}>`;
}
@@ -168,7 +163,7 @@ function setIsInBlockTable(table, value) {
rows.forEach((row) => tableMap.set(row, value));
cells.forEach((cell) => {
tableMap.set(cell, value);
- if (cell.childCount && cell.child(0).type.name === "paragraph")
+ if (cell.childCount && cell.child(0).type.name === 'paragraph')
tableMap.set(cell.child(0), value);
});
}
@@ -197,17 +192,15 @@ function renderTagClose(state, tagName, insertNewline = true) {
function renderTableHeaderRowAsMarkdown(state, node, cellWidths) {
state.flushClose(1);
- state.write("|");
+ state.write('|');
node.forEach((cell, _, i) => {
- if (i) state.write("|");
+ if (i) state.write('|');
- state.write(cell.attrs.align === "center" ? ":" : "-");
- state.write(state.repeat("-", cellWidths[i]));
- state.write(
- cell.attrs.align === "center" || cell.attrs.align === "right" ? ":" : "-"
- );
+ state.write(cell.attrs.align === 'center' ? ':' : '-');
+ state.write(state.repeat('-', cellWidths[i]));
+ state.write(cell.attrs.align === 'center' || cell.attrs.align === 'right' ? ':' : '-');
});
- state.write("|");
+ state.write('|');
state.closeBlock(node);
}
@@ -217,15 +210,15 @@ function renderTableRowAsMarkdown(state, node, isHeaderRow = false) {
state.flushClose(1);
- state.write("| ");
+ state.write('| ');
node.forEach((cell, _, i) => {
- if (i) state.write(" | ");
+ if (i) state.write(' | ');
const { length } = state.out;
state.render(cell, node, i);
cellWidths.push(state.out.length - length);
});
- state.write(" |");
+ state.write(' |');
state.closeBlock(node);
@@ -233,10 +226,10 @@ function renderTableRowAsMarkdown(state, node, isHeaderRow = false) {
}
function renderTableRowAsHTML(state, node) {
- renderTagOpen(state, "tr");
+ renderTagOpen(state, 'tr');
node.forEach((cell, _, i) => {
- const tag = cell.type.name === "tableHeader" ? "th" : "td";
+ const tag = cell.type.name === 'tableHeader' ? 'th' : 'td';
renderTagOpen(state, tag, cell.attrs);
@@ -251,7 +244,7 @@ function renderTableRowAsHTML(state, node) {
renderTagClose(state, tag);
});
- renderTagClose(state, "tr");
+ renderTagClose(state, 'tr');
}
export function renderContent(state, node, forceRenderInline) {
@@ -266,8 +259,7 @@ export function renderContent(state, node, forceRenderInline) {
state.flushClose();
}
} else {
- const renderInline =
- forceRenderInline || containsParagraphWithOnlyText(node);
+ const renderInline = forceRenderInline || containsParagraphWithOnlyText(node);
if (!renderInline) {
state.closeBlock(node);
state.flushClose();
@@ -279,18 +271,14 @@ export function renderContent(state, node, forceRenderInline) {
}
}
-export function renderHTMLNode(
- tagName,
- forceRenderInline = false,
- needNewLine = false
-) {
+export function renderHTMLNode(tagName, forceRenderInline = false, needNewLine = false) {
return (state, node) => {
renderTagOpen(state, tagName, node.attrs);
renderContent(state, node, forceRenderInline);
renderTagClose(state, tagName, false);
if (needNewLine) {
state.ensureNewLine();
- state.write("
");
+ state.write('
');
state.ensureNewLine();
}
};
@@ -300,12 +288,12 @@ export function renderOrderedList(state, node) {
const { parens } = node.attrs;
const start = node.attrs.start || 1;
const maxW = String(start + node.childCount - 1).length;
- const space = state.repeat(" ", maxW + 2);
- const delimiter = parens ? ")" : ".";
+ const space = state.repeat(' ', maxW + 2);
+ const delimiter = parens ? ')' : '.';
state.renderList(node, space, (i) => {
const nStr = String(start + i);
- return `${state.repeat(" ", maxW - nStr.length) + nStr}${delimiter} `;
+ return `${state.repeat(' ', maxW - nStr.length) + nStr}${delimiter} `;
});
}
@@ -321,22 +309,18 @@ export function renderTableRow(state, node) {
if (isInBlockTable(node)) {
renderTableRowAsHTML(state, node);
} else {
- renderTableRowAsMarkdown(
- state,
- node,
- node.child(0).type.name === "tableHeader"
- );
+ renderTableRowAsMarkdown(state, node, node.child(0).type.name === 'tableHeader');
}
}
export function renderTable(state, node) {
setIsInBlockTable(node, shouldRenderHTMLTable(node));
- if (isInBlockTable(node)) renderTagOpen(state, "table");
+ if (isInBlockTable(node)) renderTagOpen(state, 'table');
state.renderContent(node);
- if (isInBlockTable(node)) renderTagClose(state, "table");
+ if (isInBlockTable(node)) renderTagClose(state, 'table');
// ensure at least one blank line after any table
state.closeBlock(node);
@@ -346,7 +330,7 @@ export function renderTable(state, node) {
}
export function renderHardBreak(state, node, parent, index) {
- const br = isInTable(parent) ? "
" : "\\\n";
+ const br = isInTable(parent) ? '
' : '\\\n';
for (let i = index + 1; i < parent.childCount; i += 1) {
if (parent.child(i).type !== node.type) {
@@ -360,13 +344,9 @@ export function renderImage(state, node) {
const { alt, canonicalSrc, src, title } = node.attrs;
if (isString(src) || isString(canonicalSrc)) {
- const quotedTitle = title ? ` ${state.quote(title)}` : "";
+ const quotedTitle = title ? ` ${state.quote(title)}` : '';
- state.write(
- `![${state.esc(alt || "")}](${state.esc(
- canonicalSrc || src
- )}${quotedTitle})`
- );
+ state.write(`![${state.esc(alt || '')}](${state.esc(canonicalSrc || src)}${quotedTitle})`);
}
}
diff --git a/packages/client/src/components/tiptap/markdown/index.tsx b/packages/client/src/components/tiptap/markdown/index.tsx
index 0bbbf110..6dfbdbf1 100644
--- a/packages/client/src/components/tiptap/markdown/index.tsx
+++ b/packages/client/src/components/tiptap/markdown/index.tsx
@@ -1 +1 @@
-export * from "./serializer";
+export * from './serializer';
diff --git a/packages/client/src/components/tiptap/markdown/serializer.tsx b/packages/client/src/components/tiptap/markdown/serializer.tsx
index ef70b78e..163deda0 100644
--- a/packages/client/src/components/tiptap/markdown/serializer.tsx
+++ b/packages/client/src/components/tiptap/markdown/serializer.tsx
@@ -1,48 +1,48 @@
-import { DOMParser as ProseMirrorDOMParser } from "prosemirror-model";
-import { marked } from "marked";
-import { sanitize } from "dompurify";
+import { DOMParser as ProseMirrorDOMParser } from 'prosemirror-model';
+import { marked } from 'marked';
+import { sanitize } from 'dompurify';
import {
MarkdownSerializer as ProseMirrorMarkdownSerializer,
defaultMarkdownSerializer,
-} from "prosemirror-markdown";
-import { Document, TitledDocument, Title } from "../extensions/title";
-import Placeholder from "@tiptap/extension-placeholder";
-import Paragraph from "@tiptap/extension-paragraph";
-import Text from "@tiptap/extension-text";
-import Strike from "@tiptap/extension-strike";
-import Underline from "@tiptap/extension-underline";
-import TextStyle from "@tiptap/extension-text-style";
-import { Color } from "@tiptap/extension-color";
-import Blockquote from "@tiptap/extension-blockquote";
-import Bold from "@tiptap/extension-bold";
-import Code from "@tiptap/extension-code";
-import Highlight from "@tiptap/extension-highlight";
-import TextAlign from "@tiptap/extension-text-align";
-import Dropcursor from "@tiptap/extension-dropcursor";
-import Gapcursor from "@tiptap/extension-gapcursor";
-import HardBreak from "@tiptap/extension-hard-break";
-import Heading from "@tiptap/extension-heading";
-import Italic from "@tiptap/extension-italic";
-import OrderedList from "@tiptap/extension-ordered-list";
-import BulletList from "@tiptap/extension-bullet-list";
-import ListItem from "@tiptap/extension-list-item";
-import TaskList from "@tiptap/extension-task-list";
-import TaskItem from "@tiptap/extension-task-item";
-import { BackgroundColor } from "../extensions/background-color";
-import { Link } from "../extensions/link";
-import { FontSize } from "../extensions/font-size";
-import { ColorHighlighter } from "../extensions/color-highlight";
-import { Indent } from "../extensions/indent";
-import { Div } from "../extensions/div";
-import { Banner } from "../extensions/banner";
-import { CodeBlock } from "../extensions/code-block";
-import { Iframe } from "../extensions/iframe";
-import { Mind } from "../extensions/mind";
-import { Katex } from "../extensions/katex";
-import { Image } from "../extensions/image";
-import { HorizontalRule } from "../extensions/horizontal-rule";
-import { Table, TableCell, TableHeader, TableRow } from "../extensions/table";
-import { DocumentChildren } from "../extensions/documents/children";
+} from 'prosemirror-markdown';
+import { Document, TitledDocument, Title } from '../extensions/title';
+import Placeholder from '@tiptap/extension-placeholder';
+import Paragraph from '@tiptap/extension-paragraph';
+import Text from '@tiptap/extension-text';
+import Strike from '@tiptap/extension-strike';
+import Underline from '@tiptap/extension-underline';
+import TextStyle from '@tiptap/extension-text-style';
+import { Color } from '@tiptap/extension-color';
+import Blockquote from '@tiptap/extension-blockquote';
+import Bold from '@tiptap/extension-bold';
+import Code from '@tiptap/extension-code';
+import Highlight from '@tiptap/extension-highlight';
+import TextAlign from '@tiptap/extension-text-align';
+import Dropcursor from '@tiptap/extension-dropcursor';
+import Gapcursor from '@tiptap/extension-gapcursor';
+import HardBreak from '@tiptap/extension-hard-break';
+import Heading from '@tiptap/extension-heading';
+import Italic from '@tiptap/extension-italic';
+import OrderedList from '@tiptap/extension-ordered-list';
+import BulletList from '@tiptap/extension-bullet-list';
+import ListItem from '@tiptap/extension-list-item';
+import TaskList from '@tiptap/extension-task-list';
+import TaskItem from '@tiptap/extension-task-item';
+import { BackgroundColor } from '../extensions/background-color';
+import { Link } from '../extensions/link';
+import { FontSize } from '../extensions/font-size';
+import { ColorHighlighter } from '../extensions/color-highlight';
+import { Indent } from '../extensions/indent';
+import { Div } from '../extensions/div';
+import { Banner } from '../extensions/banner';
+import { CodeBlock } from '../extensions/code-block';
+import { Iframe } from '../extensions/iframe';
+import { Mind } from '../extensions/mind';
+import { Katex } from '../extensions/katex';
+import { Image } from '../extensions/image';
+import { HorizontalRule } from '../extensions/horizontal-rule';
+import { Table, TableCell, TableHeader, TableRow } from '../extensions/table';
+import { DocumentChildren } from '../extensions/documents/children';
import {
isPlainURL,
@@ -57,14 +57,14 @@ import {
renderPlayable,
renderHTMLNode,
renderContent,
-} from "./helpers";
+} from './helpers';
const defaultSerializerConfig = {
marks: {
[Bold.name]: defaultMarkdownSerializer.marks.strong,
[Italic.name]: {
- open: "_",
- close: "_",
+ open: '_',
+ close: '_',
mixable: true,
expelEnclosingWhitespace: true,
},
@@ -82,21 +82,19 @@ const defaultSerializerConfig = {
// },
[Link.name]: {
open(state, mark, parent, index) {
- return isPlainURL(mark, parent, index, 1) ? "<" : "[";
+ return isPlainURL(mark, parent, index, 1) ? '<' : '[';
},
close(state, mark, parent, index) {
const href = mark.attrs.canonicalSrc || mark.attrs.href;
return isPlainURL(mark, parent, index, -1)
- ? ">"
- : `](${state.esc(href)}${
- mark.attrs.title ? ` ${state.quote(mark.attrs.title)}` : ""
- })`;
+ ? '>'
+ : `](${state.esc(href)}${mark.attrs.title ? ` ${state.quote(mark.attrs.title)}` : ''})`;
},
},
[Strike.name]: {
- open: "~~",
- close: "~~",
+ open: '~~',
+ close: '~~',
mixable: true,
expelEnclosingWhitespace: true,
},
@@ -106,27 +104,27 @@ const defaultSerializerConfig = {
// [Audio.name]: renderPlayable,
[Blockquote.name]: (state, node) => {
if (node.attrs.multiline) {
- state.write(">>>");
+ state.write('>>>');
state.ensureNewLine();
state.renderContent(node);
state.ensureNewLine();
- state.write(">>>");
+ state.write('>>>');
state.closeBlock(node);
} else {
- state.wrapBlock("> ", null, node, () => state.renderContent(node));
+ state.wrapBlock('> ', null, node, () => state.renderContent(node));
}
},
[BulletList.name]: defaultMarkdownSerializer.nodes.bullet_list,
[CodeBlock.name]: (state, node) => {
- state.write(`\`\`\`${node.attrs.language || ""}\n`);
+ state.write(`\`\`\`${node.attrs.language || ''}\n`);
state.text(node.textContent, false);
state.ensureNewLine();
- state.write("```");
+ state.write('```');
state.closeBlock(node);
},
[Katex.name]: (state, node) => {
state.ensureNewLine();
- state.write(`\$\$${node.attrs.text || ""}\$`);
+ state.write(`\$\$${node.attrs.text || ''}\$`);
state.closeBlock(node);
},
[DocumentChildren.name]: (state, node) => {
@@ -177,7 +175,7 @@ const defaultSerializerConfig = {
// state.write(syntax);
// state.closeBlock(node);
// },
- [Title.name]: renderHTMLNode("div", true, true),
+ [Title.name]: renderHTMLNode('div', true, true),
// [FigureCaption.name]: renderHTMLNode("figcaption"),
[HardBreak.name]: renderHardBreak,
[Heading.name]: defaultMarkdownSerializer.nodes.heading,
@@ -198,7 +196,7 @@ const defaultSerializerConfig = {
[TableHeader.name]: renderTableCell,
[TableRow.name]: renderTableRow,
[TaskItem.name]: (state, node) => {
- state.write(`[${node.attrs.checked ? "x" : " "}] `);
+ state.write(`[${node.attrs.checked ? 'x' : ' '}] `);
state.renderContent(node);
},
[TaskList.name]: (state, node) => {
@@ -218,7 +216,7 @@ const createMarkdownSerializer = () => ({
const html = renderMarkdown(content);
if (!html) return null;
const parser = new DOMParser();
- const { body } = parser.parseFromString(html, "text/html");
+ const { body } = parser.parseFromString(html, 'text/html');
body.append(document.createComment(content));
const state = ProseMirrorDOMParser.fromSchema(schema).parse(body);
return state;
diff --git a/packages/client/src/components/tiptap/menubar.tsx b/packages/client/src/components/tiptap/menubar.tsx
index 7b91d754..bc891764 100644
--- a/packages/client/src/components/tiptap/menubar.tsx
+++ b/packages/client/src/components/tiptap/menubar.tsx
@@ -1,20 +1,20 @@
-import React from "react";
-import { Space, Button, Tooltip } from "@douyinfe/semi-ui";
-import { IconUndo, IconRedo } from "@douyinfe/semi-icons";
-import { IconClear } from "components/icons";
-import { Divider } from "./components/divider";
-import { MediaInsertMenu } from "./menus/media-insert";
-import { Paragraph } from "./menus/components/paragraph";
-import { FontSize } from "./menus/components/font-size";
-import { BaseMenu } from "./menus/base-menu";
-import { AlignMenu } from "./menus/align";
-import { ListMenu } from "./menus/list";
-import { BaseInsertMenu } from "./menus/base-insert";
-import { BaseBubbleMenu } from "./menus/base-bubble-menu";
-import { ImageBubbleMenu } from "./menus/image";
-import { BannerBubbleMenu } from "./menus/banner";
-import { LinkBubbleMenu } from "./menus/link";
-import { TableBubbleMenu } from "./menus/table";
+import React from 'react';
+import { Space, Button, Tooltip } from '@douyinfe/semi-ui';
+import { IconUndo, IconRedo } from '@douyinfe/semi-icons';
+import { IconClear } from 'components/icons';
+import { Divider } from './components/divider';
+import { MediaInsertMenu } from './menus/media-insert';
+import { Paragraph } from './menus/components/paragraph';
+import { FontSize } from './menus/components/font-size';
+import { BaseMenu } from './menus/base-menu';
+import { AlignMenu } from './menus/align';
+import { ListMenu } from './menus/list';
+import { BaseInsertMenu } from './menus/base-insert';
+import { BaseBubbleMenu } from './menus/base-bubble-menu';
+import { ImageBubbleMenu } from './menus/image';
+import { BannerBubbleMenu } from './menus/banner';
+import { LinkBubbleMenu } from './menus/link';
+import { TableBubbleMenu } from './menus/table';
export const MenuBar: React.FC<{ editor: any }> = ({ editor }) => {
if (!editor) {
diff --git a/packages/client/src/components/tiptap/menus/align.tsx b/packages/client/src/components/tiptap/menus/align.tsx
index 245ebd85..e5956da1 100644
--- a/packages/client/src/components/tiptap/menus/align.tsx
+++ b/packages/client/src/components/tiptap/menus/align.tsx
@@ -1,22 +1,22 @@
-import React from "react";
-import { Button, Dropdown, Tooltip } from "@douyinfe/semi-ui";
+import React from 'react';
+import { Button, Dropdown, Tooltip } from '@douyinfe/semi-ui';
import {
IconAlignLeft,
IconAlignCenter,
IconAlignRight,
IconAlignJustify,
-} from "@douyinfe/semi-icons";
-import { isTitleActive } from "../utils/active";
+} from '@douyinfe/semi-icons';
+import { isTitleActive } from '../utils/active';
export const AlignMenu = ({ editor }) => {
const current = (() => {
- if (editor.isActive({ textAlign: "center" })) {
+ if (editor.isActive({ textAlign: 'center' })) {
return ;
}
- if (editor.isActive({ textAlign: "right" })) {
+ if (editor.isActive({ textAlign: 'right' })) {
return ;
}
- if (editor.isActive({ textAlign: "justify" })) {
+ if (editor.isActive({ textAlign: 'justify' })) {
return ;
}
return ;
@@ -33,7 +33,7 @@ export const AlignMenu = ({ editor }) => {
<>
}
type="tertiary"
theme="borderless"
@@ -41,7 +41,7 @@ export const AlignMenu = ({ editor }) => {
}
type="tertiary"
theme="borderless"
@@ -49,7 +49,7 @@ export const AlignMenu = ({ editor }) => {
}
type="tertiary"
theme="borderless"
@@ -57,7 +57,7 @@ export const AlignMenu = ({ editor }) => {
}
type="tertiary"
theme="borderless"
diff --git a/packages/client/src/components/tiptap/menus/banner.tsx b/packages/client/src/components/tiptap/menus/banner.tsx
index 047b81b4..c2c8c75b 100644
--- a/packages/client/src/components/tiptap/menus/banner.tsx
+++ b/packages/client/src/components/tiptap/menus/banner.tsx
@@ -1,26 +1,24 @@
-import { Space, Button, Tooltip } from "@douyinfe/semi-ui";
+import { Space, Button, Tooltip } from '@douyinfe/semi-ui';
import {
IconDelete,
IconTickCircle,
IconAlertTriangle,
IconClear,
IconInfoCircle,
-} from "@douyinfe/semi-icons";
-import { BubbleMenu } from "../components/bubble-menu";
-import { Divider } from "../components/divider";
-import { Banner } from "../extensions/banner";
-import { deleteNode } from "../utils/delete";
+} from '@douyinfe/semi-icons';
+import { BubbleMenu } from '../components/bubble-menu';
+import { Divider } from '../components/divider';
+import { Banner } from '../extensions/banner';
+import { deleteNode } from '../utils/delete';
export const BannerBubbleMenu = ({ editor }) => {
return (
editor.isActive(Banner.name)}
- matchRenderContainer={(node) =>
- node && node.id === "js-bannber-container"
- }
+ matchRenderContainer={(node) => node && node.id === 'js-bannber-container'}
>
@@ -28,14 +26,12 @@ export const BannerBubbleMenu = ({ editor }) => {
size="small"
type="tertiary"
theme="borderless"
- icon={
-
- }
+ icon={}
onClick={() => {
editor
.chain()
.updateAttributes(Banner.name, {
- type: "info",
+ type: 'info',
})
.focus()
.run();
@@ -49,16 +45,12 @@ export const BannerBubbleMenu = ({ editor }) => {
editor
.chain()
.updateAttributes(Banner.name, {
- type: "warning",
+ type: 'warning',
})
.focus()
.run();
}}
- icon={
-
- }
+ icon={}
type="tertiary"
theme="borderless"
size="small"
@@ -71,12 +63,12 @@ export const BannerBubbleMenu = ({ editor }) => {
editor
.chain()
.updateAttributes(Banner.name, {
- type: "danger",
+ type: 'danger',
})
.focus()
.run();
}}
- icon={}
+ icon={}
type="tertiary"
theme="borderless"
size="small"
@@ -89,14 +81,12 @@ export const BannerBubbleMenu = ({ editor }) => {
editor
.chain()
.updateAttributes(Banner.name, {
- type: "success",
+ type: 'success',
})
.focus()
.run();
}}
- icon={
-
- }
+ icon={}
type="tertiary"
theme="borderless"
size="small"
@@ -111,7 +101,7 @@ export const BannerBubbleMenu = ({ editor }) => {
type="tertiary"
theme="borderless"
icon={}
- onClick={() => deleteNode("banner", editor)}
+ onClick={() => deleteNode('banner', editor)}
/>
diff --git a/packages/client/src/components/tiptap/menus/base-bubble-menu.tsx b/packages/client/src/components/tiptap/menus/base-bubble-menu.tsx
index 4680d8a7..6a36811e 100644
--- a/packages/client/src/components/tiptap/menus/base-bubble-menu.tsx
+++ b/packages/client/src/components/tiptap/menus/base-bubble-menu.tsx
@@ -1,18 +1,18 @@
-import React from "react";
-import { BubbleMenu, Editor } from "@tiptap/react";
-import { Space } from "@douyinfe/semi-ui";
-import { Title } from "../extensions/title";
-import { Link } from "../extensions/link";
-import { Attachment } from "../extensions/attachment";
-import { Image } from "../extensions/image";
-import { Banner } from "../extensions/banner";
-import { Iframe } from "../extensions/iframe";
-import { Mind } from "../extensions/mind";
-import { Table } from "../extensions/table";
-import { Katex } from "../extensions/katex";
-import { DocumentReference } from "../extensions/documents/reference";
-import { DocumentChildren } from "../extensions/documents/children";
-import { BaseMenu } from "./base-menu";
+import React from 'react';
+import { BubbleMenu, Editor } from '@tiptap/react';
+import { Space } from '@douyinfe/semi-ui';
+import { Title } from '../extensions/title';
+import { Link } from '../extensions/link';
+import { Attachment } from '../extensions/attachment';
+import { Image } from '../extensions/image';
+import { Banner } from '../extensions/banner';
+import { Iframe } from '../extensions/iframe';
+import { Mind } from '../extensions/mind';
+import { Table } from '../extensions/table';
+import { Katex } from '../extensions/katex';
+import { DocumentReference } from '../extensions/documents/reference';
+import { DocumentChildren } from '../extensions/documents/children';
+import { BaseMenu } from './base-menu';
const OTHER_BUBBLE_MENU_TYPES = [
Title.name,
@@ -36,7 +36,7 @@ export const BaseBubbleMenu: React.FC<{ editor: Editor }> = ({ editor }) => {
return (
!editor.state.selection.empty &&
diff --git a/packages/client/src/components/tiptap/menus/base-insert.tsx b/packages/client/src/components/tiptap/menus/base-insert.tsx
index 714cb3e0..d49a4f83 100644
--- a/packages/client/src/components/tiptap/menus/base-insert.tsx
+++ b/packages/client/src/components/tiptap/menus/base-insert.tsx
@@ -1,12 +1,8 @@
-import React from "react";
-import { Button, Tooltip } from "@douyinfe/semi-ui";
-import {
- IconQuote,
- IconCheckboxIndeterminate,
- IconLink,
-} from "@douyinfe/semi-icons";
-import { isTitleActive } from "../utils/active";
-import { Emoji } from "./components/emoji";
+import React from 'react';
+import { Button, Tooltip } from '@douyinfe/semi-ui';
+import { IconQuote, IconCheckboxIndeterminate, IconLink } from '@douyinfe/semi-icons';
+import { isTitleActive } from '../utils/active';
+import { Emoji } from './components/emoji';
export const BaseInsertMenu: React.FC<{ editor: any }> = ({ editor }) => {
if (!editor) {
@@ -19,7 +15,7 @@ export const BaseInsertMenu: React.FC<{ editor: any }> = ({ editor }) => {
}
onClick={() => editor.chain().focus().toggleLink().run()}
@@ -29,18 +25,18 @@ export const BaseInsertMenu: React.FC<{ editor: any }> = ({ editor }) => {
}
onClick={() => editor.chain().focus().toggleBlockquote().run()}
- className={editor.isActive("blockquote") ? "is-active" : ""}
+ className={editor.isActive('blockquote') ? 'is-active' : ''}
disabled={isTitleActive(editor)}
/>
}
onClick={() => editor.chain().focus().setHorizontalRule().run()}
diff --git a/packages/client/src/components/tiptap/menus/base-menu.tsx b/packages/client/src/components/tiptap/menus/base-menu.tsx
index ea74c09e..ed35d9c4 100644
--- a/packages/client/src/components/tiptap/menus/base-menu.tsx
+++ b/packages/client/src/components/tiptap/menus/base-menu.tsx
@@ -1,14 +1,14 @@
-import React from "react";
-import { Button, Tooltip } from "@douyinfe/semi-ui";
+import React from 'react';
+import { Button, Tooltip } from '@douyinfe/semi-ui';
import {
IconBold,
IconItalic,
IconStrikeThrough,
IconUnderline,
IconCode,
-} from "@douyinfe/semi-icons";
-import { isTitleActive } from "../utils/active";
-import { ColorMenu } from "./color";
+} from '@douyinfe/semi-icons';
+import { isTitleActive } from '../utils/active';
+import { ColorMenu } from './color';
export const BaseMenu: React.FC<{ editor: any }> = ({ editor }) => {
if (!editor) {
@@ -19,7 +19,7 @@ export const BaseMenu: React.FC<{ editor: any }> = ({ editor }) => {
<>
}
onClick={() => editor.chain().focus().toggleBold().run()}
@@ -29,7 +29,7 @@ export const BaseMenu: React.FC<{ editor: any }> = ({ editor }) => {
}
onClick={() => editor.chain().focus().toggleItalic().run()}
@@ -39,7 +39,7 @@ export const BaseMenu: React.FC<{ editor: any }> = ({ editor }) => {
}
onClick={() => editor.chain().focus().toggleUnderline().run()}
@@ -49,7 +49,7 @@ export const BaseMenu: React.FC<{ editor: any }> = ({ editor }) => {
}
onClick={() => editor.chain().focus().toggleStrike().run()}
@@ -59,7 +59,7 @@ export const BaseMenu: React.FC<{ editor: any }> = ({ editor }) => {
}
onClick={() => editor.chain().focus().toggleCode().run()}
diff --git a/packages/client/src/components/tiptap/menus/color.tsx b/packages/client/src/components/tiptap/menus/color.tsx
index 42b050f8..7f983bd0 100644
--- a/packages/client/src/components/tiptap/menus/color.tsx
+++ b/packages/client/src/components/tiptap/menus/color.tsx
@@ -1,11 +1,11 @@
-import React from "react";
-import { Button, Tooltip } from "@douyinfe/semi-ui";
-import { IconFont, IconMark } from "@douyinfe/semi-icons";
-import { isTitleActive } from "../utils/active";
-import { Color } from "../components/color";
+import React from 'react';
+import { Button, Tooltip } from '@douyinfe/semi-ui';
+import { IconFont, IconMark } from '@douyinfe/semi-icons';
+import { isTitleActive } from '../utils/active';
+import { Color } from '../components/color';
export const ColorMenu: React.FC<{ editor: any }> = ({ editor }) => {
- const { color, backgroundColor } = editor.getAttributes("textStyle");
+ const { color, backgroundColor } = editor.getAttributes('textStyle');
if (!editor) {
return null;
@@ -21,17 +21,17 @@ export const ColorMenu: React.FC<{ editor: any }> = ({ editor }) => {
>