Comparing version 0.1.9 to 0.1.10
@@ -60,2 +60,41 @@ /** | ||
return false; | ||
} | ||
static convertDOM() { | ||
return { | ||
div: node => ({ | ||
conversion: convertDivElement, | ||
priority: 1 | ||
}), | ||
pre: node => ({ | ||
conversion: convertPreElement, | ||
priority: 0 | ||
}), | ||
table: node => { | ||
// $FlowFixMe[incompatible-type] domNode is a <table> since we matched it by nodeName | ||
const table = node; | ||
if (isGitHubCodeTable(table)) { | ||
return { | ||
conversion: convertTableElement, | ||
priority: 1 | ||
}; | ||
} | ||
return null; | ||
}, | ||
td: node => { | ||
// $FlowFixMe[incompatible-type] element is a <td> since we matched it by nodeName | ||
const td = node; | ||
if (isGitHubCodeCell(td)) { | ||
return { | ||
conversion: convertTableCellElement, | ||
priority: 1 | ||
}; | ||
} | ||
return null; | ||
} | ||
}; | ||
} // Mutation | ||
@@ -170,2 +209,59 @@ | ||
function convertPreElement(domNode) { | ||
return { | ||
node: $createCodeNode() | ||
}; | ||
} | ||
function convertDivElement(domNode) { | ||
// $FlowFixMe[incompatible-type] domNode is a <div> since we matched it by nodeName | ||
const div = domNode; | ||
return { | ||
after: childLexicalNodes => { | ||
const domParent = domNode.parentNode; | ||
if (domParent != null && domNode !== domParent.lastChild) { | ||
childLexicalNodes.push(lexical.$createLineBreakNode()); | ||
} | ||
return childLexicalNodes; | ||
}, | ||
node: isCodeElement(div) ? $createCodeNode() : null | ||
}; | ||
} | ||
function convertTableElement() { | ||
return { | ||
node: $createCodeNode() | ||
}; | ||
} | ||
function convertTableCellElement(domNode) { | ||
// $FlowFixMe[incompatible-type] domNode is a <td> since we matched it by nodeName | ||
const cell = domNode; | ||
return { | ||
after: childLexicalNodes => { | ||
if (cell.parentNode && cell.parentNode.nextSibling) { | ||
// Append newline between code lines | ||
childLexicalNodes.push(lexical.$createLineBreakNode()); | ||
} | ||
return childLexicalNodes; | ||
}, | ||
node: null | ||
}; | ||
} | ||
function isCodeElement(div) { | ||
return div.style.fontFamily.match('monospace') !== null; | ||
} | ||
function isGitHubCodeCell(cell) { | ||
return cell.classList.contains('js-file-line'); | ||
} | ||
function isGitHubCodeTable(table) { | ||
return table.classList.contains('js-file-line-container'); | ||
} | ||
exports.$createCodeNode = $createCodeNode; | ||
@@ -172,0 +268,0 @@ exports.$isCodeNode = $isCodeNode; |
@@ -8,5 +8,6 @@ /** | ||
var d=require("lexical"),f=require("lexical/CodeHighlightNode");function g(a,...c){c.forEach(b=>{null!=b&&"string"===typeof b&&a.classList.add(...b.split(" "))})} | ||
class h extends d.ElementNode{static getType(){return"code"}static clone(a){return new h(a.__language,a.__key)}constructor(a,c){super(c);this.__language=a}createDOM(a){const c=document.createElement("code");g(c,a.theme.code);c.setAttribute("spellcheck","false");return c}updateDOM(){return!1}insertNewAfter(a){var c=this.getChildren(),b=c.length;if(2<=b&&"\n"===c[b-1].getTextContent()&&"\n"===c[b-2].getTextContent()&&a.isCollapsed()&&a.anchor.key===this.__key&&a.anchor.offset===b)return c[b-1].remove(), | ||
c[b-2].remove(),a=d.$createParagraphNode(),this.insertAfter(a),a;c=a.anchor.getNode();var e=k(c);if(null!=e){b=0;for(e=e.getTextContent();b<e.length&&/[\t ]/.test(e[b]);)b+=1;if(0<b)return b=e.substring(0,b),b=f.$createCodeHighlightNode(b),c.insertAfter(b),a.insertNodes([d.$createLineBreakNode()]),b.select(),b}return null}canInsertTab(){return!0}collapseAtStart(){const a=d.$createParagraphNode();this.getChildren().forEach(c=>a.append(c));this.replace(a);return!0}setLanguage(a){this.getWritable().__language= | ||
a}getLanguage(){return this.getLatest().__language}}function k(a){let c=null;const b=a.getPreviousSiblings();for(b.push(a);0<b.length&&(a=b.pop(),f.$isCodeHighlightNode(a)&&(c=a),!d.$isLineBreakNode(a)););return c}exports.$createCodeNode=function(a){return new h(a)};exports.$isCodeNode=function(a){return a instanceof h};exports.CodeNode=h;exports.getFirstCodeHighlightNodeOfLine=k; | ||
exports.getLastCodeHighlightNodeOfLine=function(a){let c=null;const b=a.getNextSiblings();for(b.unshift(a);0<b.length&&(a=b.shift(),f.$isCodeHighlightNode(a)&&(c=a),!d.$isLineBreakNode(a)););return c}; | ||
class h extends d.ElementNode{static getType(){return"code"}static clone(a){return new h(a.__language,a.__key)}constructor(a,c){super(c);this.__language=a}createDOM(a){const c=document.createElement("code");g(c,a.theme.code);c.setAttribute("spellcheck","false");return c}updateDOM(){return!1}static convertDOM(){return{div:()=>({conversion:k,priority:1}),pre:()=>({conversion:l,priority:0}),table:a=>a.classList.contains("js-file-line-container")?{conversion:m,priority:1}:null,td:a=>a.classList.contains("js-file-line")? | ||
{conversion:n,priority:1}:null}}insertNewAfter(a){var c=this.getChildren(),b=c.length;if(2<=b&&"\n"===c[b-1].getTextContent()&&"\n"===c[b-2].getTextContent()&&a.isCollapsed()&&a.anchor.key===this.__key&&a.anchor.offset===b)return c[b-1].remove(),c[b-2].remove(),a=d.$createParagraphNode(),this.insertAfter(a),a;c=a.anchor.getNode();var e=p(c);if(null!=e){b=0;for(e=e.getTextContent();b<e.length&&/[\t ]/.test(e[b]);)b+=1;if(0<b)return b=e.substring(0,b),b=f.$createCodeHighlightNode(b),c.insertAfter(b), | ||
a.insertNodes([d.$createLineBreakNode()]),b.select(),b}return null}canInsertTab(){return!0}collapseAtStart(){const a=d.$createParagraphNode();this.getChildren().forEach(c=>a.append(c));this.replace(a);return!0}setLanguage(a){this.getWritable().__language=a}getLanguage(){return this.getLatest().__language}}function q(a){return new h(a)}function p(a){let c=null;const b=a.getPreviousSiblings();for(b.push(a);0<b.length&&(a=b.pop(),f.$isCodeHighlightNode(a)&&(c=a),!d.$isLineBreakNode(a)););return c} | ||
function l(){return{node:q()}}function k(a){return{after:c=>{const b=a.parentNode;null!=b&&a!==b.lastChild&&c.push(d.$createLineBreakNode());return c},node:null!==a.style.fontFamily.match("monospace")?q():null}}function m(){return{node:q()}}function n(a){return{after:c=>{a.parentNode&&a.parentNode.nextSibling&&c.push(d.$createLineBreakNode());return c},node:null}}exports.$createCodeNode=q;exports.$isCodeNode=function(a){return a instanceof h};exports.CodeNode=h; | ||
exports.getFirstCodeHighlightNodeOfLine=p;exports.getLastCodeHighlightNodeOfLine=function(a){let c=null;const b=a.getNextSiblings();for(b.unshift(a);0<b.length&&(a=b.shift(),f.$isCodeHighlightNode(a)&&(c=a),!d.$isLineBreakNode(a)););return c}; |
@@ -71,2 +71,27 @@ /** | ||
return false; | ||
} | ||
static convertDOM() { | ||
return { | ||
h1: node => ({ | ||
conversion: convertHeadingElement, | ||
priority: 0 | ||
}), | ||
h2: node => ({ | ||
conversion: convertHeadingElement, | ||
priority: 0 | ||
}), | ||
h3: node => ({ | ||
conversion: convertHeadingElement, | ||
priority: 0 | ||
}), | ||
h4: node => ({ | ||
conversion: convertHeadingElement, | ||
priority: 0 | ||
}), | ||
h5: node => ({ | ||
conversion: convertHeadingElement, | ||
priority: 0 | ||
}) | ||
}; | ||
} // Mutation | ||
@@ -92,2 +117,16 @@ | ||
} | ||
function convertHeadingElement(domNode) { | ||
const nodeName = domNode.nodeName.toLowerCase(); | ||
let node = null; | ||
if (nodeName === 'h1' || nodeName === 'h2' || nodeName === 'h3' || nodeName === 'h4' || nodeName === 'h5') { | ||
node = $createHeadingNode(nodeName); | ||
} | ||
return { | ||
node | ||
}; | ||
} | ||
function $createHeadingNode(headingTag) { | ||
@@ -94,0 +133,0 @@ return new HeadingNode(headingTag); |
@@ -8,3 +8,3 @@ /** | ||
var d=require("lexical");function e(a,...b){b.forEach(c=>{null!=c&&"string"===typeof c&&a.classList.add(...c.split(" "))})} | ||
class f extends d.ElementNode{static getType(){return"heading"}static clone(a){return new f(a.__tag,a.__key)}constructor(a,b){super(b);this.__tag=a}getTag(){return this.__tag}createDOM(a){const b=this.__tag,c=document.createElement(b);a=a.theme.heading;void 0!==a&&e(c,a[b]);return c}updateDOM(){return!1}insertNewAfter(){const a=d.$createParagraphNode(),b=this.getDirection();a.setDirection(b);this.insertAfter(a);return a}collapseAtStart(){const a=d.$createParagraphNode();this.getChildren().forEach(b=> | ||
a.append(b));this.replace(a);return!0}}exports.$createHeadingNode=function(a){return new f(a)};exports.$isHeadingNode=function(a){return a instanceof f};exports.HeadingNode=f; | ||
class f extends d.ElementNode{static getType(){return"heading"}static clone(a){return new f(a.__tag,a.__key)}constructor(a,b){super(b);this.__tag=a}getTag(){return this.__tag}createDOM(a){const b=this.__tag,c=document.createElement(b);a=a.theme.heading;void 0!==a&&e(c,a[b]);return c}updateDOM(){return!1}static convertDOM(){return{h1:()=>({conversion:g,priority:0}),h2:()=>({conversion:g,priority:0}),h3:()=>({conversion:g,priority:0}),h4:()=>({conversion:g,priority:0}),h5:()=>({conversion:g,priority:0})}}insertNewAfter(){const a= | ||
d.$createParagraphNode(),b=this.getDirection();a.setDirection(b);this.insertAfter(a);return a}collapseAtStart(){const a=d.$createParagraphNode();this.getChildren().forEach(b=>a.append(b));this.replace(a);return!0}}function g(a){a=a.nodeName.toLowerCase();let b=null;if("h1"===a||"h2"===a||"h3"===a||"h4"===a||"h5"===a)b=h(a);return{node:b}}function h(a){return new f(a)}exports.$createHeadingNode=h;exports.$isHeadingNode=function(a){return a instanceof f};exports.HeadingNode=f; |
@@ -68,2 +68,11 @@ /** | ||
static convertDOM() { | ||
return { | ||
a: node => ({ | ||
conversion: convertAnchorElement, | ||
priority: 1 | ||
}) | ||
}; | ||
} | ||
getURL() { | ||
@@ -107,2 +116,15 @@ return this.getLatest().__url; | ||
} | ||
function convertAnchorElement(domNode) { | ||
let node = null; | ||
if (domNode instanceof HTMLAnchorElement) { | ||
node = $createLinkNode(domNode.href); | ||
} | ||
return { | ||
node | ||
}; | ||
} | ||
function $createLinkNode(url) { | ||
@@ -109,0 +131,0 @@ return new LinkNode(url); |
@@ -8,3 +8,3 @@ /** | ||
var d=require("lexical");function e(a,...b){b.forEach(c=>{null!=c&&"string"===typeof c&&a.classList.add(...c.split(" "))})} | ||
class f extends d.ElementNode{static getType(){return"link"}static clone(a){return new f(a.__url,a.__key)}constructor(a,b){super(b);this.__url=a}createDOM(a){const b=document.createElement("a");b.href=this.__url;e(b,a.theme.link);return b}updateDOM(a,b){const c=this.__url;c!==a.__url&&(b.href=c);return!1}getURL(){return this.getLatest().__url}setURL(a){this.getWritable().__url=a}insertNewAfter(a){a=this.getParentOrThrow().insertNewAfter(a);if(d.$isElementNode(a)){const b=g(this.__url);a.append(b); | ||
return b}return null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}}function g(a){return new f(a)}exports.$createLinkNode=g;exports.$isLinkNode=function(a){return a instanceof f};exports.LinkNode=f; | ||
class f extends d.ElementNode{static getType(){return"link"}static clone(a){return new f(a.__url,a.__key)}constructor(a,b){super(b);this.__url=a}createDOM(a){const b=document.createElement("a");b.href=this.__url;e(b,a.theme.link);return b}updateDOM(a,b){const c=this.__url;c!==a.__url&&(b.href=c);return!1}static convertDOM(){return{a:()=>({conversion:g,priority:1})}}getURL(){return this.getLatest().__url}setURL(a){this.getWritable().__url=a}insertNewAfter(a){a=this.getParentOrThrow().insertNewAfter(a); | ||
if(d.$isElementNode(a)){const b=h(this.__url);a.append(b);return b}return null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}}function g(a){let b=null;a instanceof HTMLAnchorElement&&(b=h(a.href));return{node:b}}function h(a){return new f(a)}exports.$createLinkNode=h;exports.$isLinkNode=function(a){return a instanceof f};exports.LinkNode=f; |
@@ -16,3 +16,3 @@ { | ||
"license": "MIT", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"main": "Lexical.js", | ||
@@ -19,0 +19,0 @@ "repository": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
352863
7985