@lexical/markdown
Advanced tools
Comparing version 0.3.8 to 0.3.9
@@ -8,5 +8,5 @@ /** | ||
*/ | ||
import type { ElementTransformer, TextFormatTransformer, TextMatchTransformer, Transformer } from './v2/MarkdownTransformers'; | ||
import { registerMarkdownShortcuts } from './v2/MarkdownShortcuts'; | ||
import { BOLD_ITALIC_STAR, BOLD_ITALIC_UNDERSCORE, BOLD_STAR, BOLD_UNDERSCORE, CHECK_LIST, CODE, HEADING, INLINE_CODE, ITALIC_STAR, ITALIC_UNDERSCORE, LINK, ORDERED_LIST, QUOTE, STRIKETHROUGH, UNORDERED_LIST } from './v2/MarkdownTransformers'; | ||
import type { ElementTransformer, TextFormatTransformer, TextMatchTransformer, Transformer } from './MarkdownTransformers'; | ||
import { registerMarkdownShortcuts } from './MarkdownShortcuts'; | ||
import { BOLD_ITALIC_STAR, BOLD_ITALIC_UNDERSCORE, BOLD_STAR, BOLD_UNDERSCORE, CHECK_LIST, CODE, HEADING, INLINE_CODE, ITALIC_STAR, ITALIC_UNDERSCORE, LINK, ORDERED_LIST, QUOTE, STRIKETHROUGH, UNORDERED_LIST } from './MarkdownTransformers'; | ||
declare const ELEMENT_TRANSFORMERS: Array<ElementTransformer>; | ||
@@ -13,0 +13,0 @@ declare const TEXT_FORMAT_TRANSFORMERS: Array<TextFormatTransformer>; |
@@ -23,2 +23,3 @@ /** | ||
*/ | ||
function indexBy(list, callback) { | ||
@@ -557,3 +558,3 @@ const index = {}; | ||
replaceNode.selectNext(); | ||
replaceNode.selectNext(0, 0); | ||
transformer.replace(replaceNode, match); | ||
@@ -560,0 +561,0 @@ return true; |
@@ -26,4 +26,4 @@ /** | ||
{if(!q.hasFormat("code")){var l=q.getParent();if(null!==l&&!y.$isCodeNode(l)){var w=n.anchor.offset;b:{var g=c.element,m=l.getParent();if(h.$isRootNode(m)&&l.getFirstChild()===q&&(m=q.getTextContent()," "===m[w-1]))for(let {regExp:B,replace:C}of g)if((g=m.match(B))&&g[0].length===w){m=q.getNextSiblings();let [D,oa]=q.splitText(w);D.remove();m=oa?[oa,...m]:m;C(l,m,g,!1);l=!0;break b}l=!1}if(!l){b:{g=q.getTextContent();l=e[g[w-1]];if(null!=l){w<g.length&&(g=g.slice(0,w));for(x of l)if(l=g.match(x.regExp), | ||
null!==l){g=l.index||0;m=g+l[0].length;var v=void 0;0===g?[v]=q.splitText(m):[,v]=q.splitText(g,m);v.selectNext();x.replace(v,l);var x=!0;break b}}x=!1}if(!x)b:{m=q.getTextContent();--w;var u=m[w];if(x=d[u])for(let B of x){var {tag:A}=B;x=A.length;let C=w-x+1;if(!(1<x&&!R(m,C,A,0,x)||" "===m[C-1])&&(v=m[w+1],!1!==B.intraword||!v||J.test(v))){l=v=q;g=Q(m,C,A);for(var z=l;0>g&&(z=z.getPreviousSibling())&&!h.$isLineBreakNode(z);)h.$isTextNode(z)&&(g=z.getTextContent(),l=z,g=Q(g,g.length,A));if(!(0>g|| | ||
l===v&&g+x===C||(A=l.getTextContent(),0<g&&A[g-1]===u||(z=A[g-1],!1===B.intraword&&z&&!J.test(z))))){m=v.getTextContent();m=m.slice(0,C)+m.slice(w+1);v.setTextContent(m);m=l===v?m:A;l.setTextContent(m.slice(0,g)+m.slice(g+x));m=h.$getSelection();u=h.$createRangeSelection();h.$setSelection(u);w=w-x*(l===v?2:1)+1;u.anchor.set(l.__key,g,"text");u.focus.set(v.__key,w,"text");for(let D of B.format)u.hasFormat(D)||u.formatText(D);u.anchor.set(u.focus.key,u.focus.offset,u.focus.type);for(let D of B.format)u.hasFormat(D)&& | ||
null!==l){g=l.index||0;m=g+l[0].length;var v=void 0;0===g?[v]=q.splitText(m):[,v]=q.splitText(g,m);v.selectNext(0,0);x.replace(v,l);var x=!0;break b}}x=!1}if(!x)b:{m=q.getTextContent();--w;var u=m[w];if(x=d[u])for(let B of x){var {tag:A}=B;x=A.length;let C=w-x+1;if(!(1<x&&!R(m,C,A,0,x)||" "===m[C-1])&&(v=m[w+1],!1!==B.intraword||!v||J.test(v))){l=v=q;g=Q(m,C,A);for(var z=l;0>g&&(z=z.getPreviousSibling())&&!h.$isLineBreakNode(z);)h.$isTextNode(z)&&(g=z.getTextContent(),l=z,g=Q(g,g.length,A));if(!(0> | ||
g||l===v&&g+x===C||(A=l.getTextContent(),0<g&&A[g-1]===u||(z=A[g-1],!1===B.intraword&&z&&!J.test(z))))){m=v.getTextContent();m=m.slice(0,C)+m.slice(w+1);v.setTextContent(m);m=l===v?m:A;l.setTextContent(m.slice(0,g)+m.slice(g+x));m=h.$getSelection();u=h.$createRangeSelection();h.$setSelection(u);w=w-x*(l===v?2:1)+1;u.anchor.set(l.__key,g,"text");u.focus.set(v.__key,w,"text");for(let D of B.format)u.hasFormat(D)||u.formatText(D);u.anchor.set(u.focus.key,u.focus.offset,u.focus.type);for(let D of B.format)u.hasFormat(D)&& | ||
u.toggleFormat(D);h.$isRangeSelection(m)&&(u.format=m.format);break b}}}}}}}})}}})} |
@@ -11,14 +11,14 @@ { | ||
"license": "MIT", | ||
"version": "0.3.8", | ||
"version": "0.3.9", | ||
"main": "LexicalMarkdown.js", | ||
"peerDependencies": { | ||
"lexical": "0.3.8" | ||
"lexical": "0.3.9" | ||
}, | ||
"dependencies": { | ||
"@lexical/utils": "0.3.8", | ||
"@lexical/code": "0.3.8", | ||
"@lexical/text": "0.3.8", | ||
"@lexical/rich-text": "0.3.8", | ||
"@lexical/list": "0.3.8", | ||
"@lexical/link": "0.3.8" | ||
"@lexical/utils": "0.3.9", | ||
"@lexical/code": "0.3.9", | ||
"@lexical/text": "0.3.9", | ||
"@lexical/rich-text": "0.3.9", | ||
"@lexical/list": "0.3.9", | ||
"@lexical/link": "0.3.9" | ||
}, | ||
@@ -25,0 +25,0 @@ "repository": { |
@@ -8,28 +8,7 @@ /** | ||
*/ | ||
import type { TextNodeWithOffset } from '@lexical/text'; | ||
import type { DecoratorNode, ElementNode, LexicalEditor, LexicalNode, NodeKey, TextFormatType } from 'lexical'; | ||
export declare type AutoFormatTriggerState = Readonly<{ | ||
anchorOffset: number; | ||
hasParentNode: boolean; | ||
isCodeBlock: boolean; | ||
isParentAListItemNode: boolean; | ||
isSelectionCollapsed: boolean; | ||
isSimpleText: boolean; | ||
nodeKey: NodeKey; | ||
textContent: string; | ||
}>; | ||
export declare type MarkdownFormatKind = 'noTransformation' | 'paragraphH1' | 'paragraphH2' | 'paragraphH3' | 'paragraphH4' | 'paragraphH5' | 'paragraphH6' | 'paragraphBlockQuote' | 'paragraphUnorderedList' | 'paragraphOrderedList' | 'paragraphCodeBlock' | 'horizontalRule' | 'bold' | 'code' | 'italic' | 'underline' | 'strikethrough' | 'italic_bold' | 'strikethrough_italic' | 'strikethrough_bold' | 'strikethrough_italic_bold' | 'link'; | ||
export declare type ScanningContext = { | ||
currentElementNode: null | ElementNode; | ||
editor: LexicalEditor; | ||
isAutoFormatting: boolean; | ||
isWithinCodeBlock: boolean; | ||
joinedText: string | null | undefined; | ||
markdownCriteria: MarkdownCriteria; | ||
patternMatchResults: PatternMatchResults; | ||
textNodeWithOffset: TextNodeWithOffset | null | undefined; | ||
triggerState: AutoFormatTriggerState | null | undefined; | ||
}; | ||
export declare type MarkdownCriteria = Readonly<{ | ||
export?: (node: LexicalNode, traverseChildren: (node: ElementNode) => string) => string | null; | ||
import type { ElementTransformer, TextFormatTransformer, TextMatchTransformer, Transformer } from '@lexical/markdown'; | ||
import type { ElementNode, LexicalNode, TextFormatType } from 'lexical'; | ||
declare type MarkdownFormatKind = 'noTransformation' | 'paragraphH1' | 'paragraphH2' | 'paragraphH3' | 'paragraphH4' | 'paragraphH5' | 'paragraphH6' | 'paragraphBlockQuote' | 'paragraphUnorderedList' | 'paragraphOrderedList' | 'paragraphCodeBlock' | 'horizontalRule' | 'bold' | 'code' | 'italic' | 'underline' | 'strikethrough' | 'italic_bold' | 'strikethrough_italic' | 'strikethrough_bold' | 'strikethrough_italic_bold' | 'link'; | ||
declare type MarkdownCriteria = Readonly<{ | ||
export?: (node: LexicalNode, traverseChildren: (elementNode: ElementNode) => string) => string | null; | ||
exportFormat?: TextFormatType; | ||
@@ -43,34 +22,12 @@ exportTag?: string; | ||
}>; | ||
declare type CaptureGroupDetail = { | ||
offsetInParent: number; | ||
text: string; | ||
}; | ||
export declare type PatternMatchResults = { | ||
regExCaptureGroups: Array<CaptureGroupDetail>; | ||
}; | ||
export declare type MarkdownCriteriaWithPatternMatchResults = { | ||
markdownCriteria: null | MarkdownCriteria; | ||
patternMatchResults: null | PatternMatchResults; | ||
}; | ||
export declare type MarkdownCriteriaArray = Array<MarkdownCriteria>; | ||
export declare type AutoFormatTriggerKind = 'space_trigger' | 'codeBlock_trigger'; | ||
export declare type AutoFormatTrigger = { | ||
triggerKind: AutoFormatTriggerKind; | ||
triggerString: string; | ||
}; | ||
export declare const triggers: Array<AutoFormatTrigger>; | ||
export declare const allMarkdownCriteria: MarkdownCriteriaArray; | ||
export declare function getAllTriggers(): Array<AutoFormatTrigger>; | ||
declare type MarkdownCriteriaArray = Array<MarkdownCriteria>; | ||
export declare function getAllMarkdownCriteriaForParagraphs(): MarkdownCriteriaArray; | ||
export declare function getAllMarkdownCriteriaForTextNodes(): MarkdownCriteriaArray; | ||
export declare function getAllMarkdownCriteria(): MarkdownCriteriaArray; | ||
export declare function getInitialScanningContext(editor: LexicalEditor, isAutoFormatting: boolean, textNodeWithOffset: null | TextNodeWithOffset, triggerState: null | AutoFormatTriggerState): ScanningContext; | ||
export declare function resetScanningContext(scanningContext: ScanningContext): ScanningContext; | ||
export declare function getCodeBlockCriteria(): MarkdownCriteria; | ||
export declare function getPatternMatchResultsForCriteria(markdownCriteria: MarkdownCriteria, scanningContext: ScanningContext, parentElementNode: ElementNode): null | PatternMatchResults; | ||
export declare function getPatternMatchResultsForCodeBlock(scanningContext: ScanningContext, text: string): null | PatternMatchResults; | ||
export declare function hasPatternMatchResults(scanningContext: ScanningContext): boolean; | ||
export declare function getTextNodeWithOffsetOrThrow(scanningContext: ScanningContext): TextNodeWithOffset; | ||
export declare function transformTextNodeForMarkdownCriteria<T>(scanningContext: ScanningContext, elementNode: ElementNode, createHorizontalRuleNode: null | (() => DecoratorNode<T>)): void; | ||
export declare function getParentElementNodeOrThrow(scanningContext: ScanningContext): ElementNode; | ||
export declare function indexBy<T>(list: Array<T>, callback: (arg0: T) => string): Readonly<Record<string, Array<T>>>; | ||
export declare function transformersByType(transformers: Array<Transformer>): Readonly<{ | ||
element: Array<ElementTransformer>; | ||
textFormat: Array<TextFormatTransformer>; | ||
textMatch: Array<TextMatchTransformer>; | ||
}>; | ||
export declare const PUNCTUATION_OR_SPACE: RegExp; | ||
export {}; |
57924
14
1047
+ Added@lexical/clipboard@0.3.9(transitive)
+ Added@lexical/code@0.3.9(transitive)
+ Added@lexical/html@0.3.9(transitive)
+ Added@lexical/link@0.3.9(transitive)
+ Added@lexical/list@0.3.9(transitive)
+ Added@lexical/rich-text@0.3.9(transitive)
+ Added@lexical/selection@0.3.9(transitive)
+ Added@lexical/table@0.3.9(transitive)
+ Added@lexical/text@0.3.9(transitive)
+ Added@lexical/utils@0.3.9(transitive)
+ Addedlexical@0.3.9(transitive)
- Removed@lexical/clipboard@0.3.8(transitive)
- Removed@lexical/code@0.3.8(transitive)
- Removed@lexical/html@0.3.8(transitive)
- Removed@lexical/link@0.3.8(transitive)
- Removed@lexical/list@0.3.8(transitive)
- Removed@lexical/rich-text@0.3.8(transitive)
- Removed@lexical/selection@0.3.8(transitive)
- Removed@lexical/table@0.3.8(transitive)
- Removed@lexical/text@0.3.8(transitive)
- Removed@lexical/utils@0.3.8(transitive)
- Removedlexical@0.3.8(transitive)
Updated@lexical/code@0.3.9
Updated@lexical/link@0.3.9
Updated@lexical/list@0.3.9
Updated@lexical/rich-text@0.3.9
Updated@lexical/text@0.3.9
Updated@lexical/utils@0.3.9