@lexical/markdown 0.11.1 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -773,9 +773,11 @@ function registerMarkdownShortcuts(editor, transformers = TRANSFORMERS) {
773
773
  if (type === 'element' || type === 'text-match') {
774
774
  const dependencies = transformer.dependencies;
775
775
 
776
- if (!editor.hasNodes(dependencies)) {
777
- {
778
- throw Error(`MarkdownShortcuts: missing dependency for transformer. Ensure node dependency is included in editor initial config.`);
776
+ for (const node of dependencies) {
777
+ if (!editor.hasNode(node)) {
778
+ {
779
+ throw Error(`MarkdownShortcuts: missing dependency ${node.getType()} for transformer. Ensure node dependency is included in editor initial config.`);
780
+ }
779
781
  }
780
782
  }
781
783
  }
@@ -802,6 +804,11 @@ function registerMarkdownShortcuts(editor, transformers = TRANSFORMERS) {
802
804
  // Ignore updates from undo/redo (as changes already calculated)
803
805
  if (tags.has('historic')) {
804
806
  return;
807
+ } // If editor is still composing (i.e. backticks) we must wait before the user confirms the key
808
+
809
+
810
+ if (editor.isComposing()) {
811
+ return;
805
812
  }
806
813
 
807
814
  const selection = editorState.read(lexical.$getSelection);
@@ -816,7 +823,7 @@ function registerMarkdownShortcuts(editor, transformers = TRANSFORMERS) {
816
823
 
817
824
  const anchorNode = editorState._nodeMap.get(anchorKey);
818
825
 
819
- if (!lexical.$isTextNode(anchorNode) || !dirtyLeaves.has(anchorKey) || anchorOffset !== 1 && anchorOffset !== prevSelection.anchor.offset + 1) {
826
+ if (!lexical.$isTextNode(anchorNode) || !dirtyLeaves.has(anchorKey) || anchorOffset !== 1 && anchorOffset > prevSelection.anchor.offset + 1) {
820
827
  return;
821
828
  }
822
829
 
@@ -28,8 +28,8 @@ type:"text-format"},xa={format:["bold"],intraword:!1,tag:"__",type:"text-format"
28
28
  c(d,b):b},importRegExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(a,b)=>{const [,c,d,e]=b;b=G.$createLinkNode(d,{title:e});const f=k.$createTextNode(c);f.setFormat(a.getFormat());b.append(f);a.replace(b)},trigger:")",type:"text-match"},Ca=[la,ma,na,oa,qa],Da=[ra,ta,va,wa,xa,sa,za,Aa,ya],Ea=[Ba],Z=[...Ca,...Da,...Ea];
29
29
  exports.$convertFromMarkdownString=function(a,b=Z,c){return ha(b)(a,c)};exports.$convertToMarkdownString=function(a=Z,b){return ba(a)(b)};exports.BOLD_ITALIC_STAR=ta;exports.BOLD_ITALIC_UNDERSCORE=va;exports.BOLD_STAR=wa;exports.BOLD_UNDERSCORE=xa;exports.CHECK_LIST=pa;exports.CODE=na;exports.ELEMENT_TRANSFORMERS=Ca;exports.HEADING=la;exports.HIGHLIGHT=sa;exports.INLINE_CODE=ra;exports.ITALIC_STAR=za;exports.ITALIC_UNDERSCORE=Aa;exports.LINK=Ba;exports.ORDERED_LIST=qa;exports.QUOTE=ma;
30
30
  exports.STRIKETHROUGH=ya;exports.TEXT_FORMAT_TRANSFORMERS=Da;exports.TEXT_MATCH_TRANSFORMERS=Ea;exports.TRANSFORMERS=Z;exports.UNORDERED_LIST=oa;
31
- exports.registerMarkdownShortcuts=function(a,b=Z){let c=I(b),d=H(c.textFormat,({tag:f})=>f[f.length-1]),e=H(c.textMatch,({trigger:f})=>f);for(let f of b)if(b=f.type,("element"===b||"text-match"===b)&&!a.hasNodes(f.dependencies))throw Error("Minified Lexical error #79; visit https://lexical.dev/docs/error?code=79 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return a.registerUpdateListener(({tags:f,dirtyLeaves:g,editorState:l,prevEditorState:p})=>
32
- {if(!f.has("historic")){var r=l.read(k.$getSelection);f=p.read(k.$getSelection);if(k.$isRangeSelection(f)&&k.$isRangeSelection(r)&&r.isCollapsed()){p=r.anchor.key;var y=r.anchor.offset,q=l._nodeMap.get(p);k.$isTextNode(q)&&g.has(p)&&(1===y||y===f.anchor.offset+1)&&a.update(()=>{if(!q.hasFormat("code")){var m=q.getParent();if(null!==m&&!t.$isCodeNode(m)){var w=r.anchor.offset;b:{var h=c.element,n=m.getParent();if(k.$isRootOrShadowRoot(n)&&m.getFirstChild()===q&&(n=q.getTextContent()," "===n[w-1]))for(let {regExp:D,
31
+ exports.registerMarkdownShortcuts=function(a,b=Z){let c=I(b),d=H(c.textFormat,({tag:f})=>f[f.length-1]),e=H(c.textMatch,({trigger:f})=>f);for(let f of b)if(b=f.type,"element"===b||"text-match"===b){b=f.dependencies;for(let g of b)if(!a.hasNode(g))throw Error(`MarkdownShortcuts: missing dependency ${g.getType()} for transformer. Ensure node dependency is included in editor initial config.`);}return a.registerUpdateListener(({tags:f,dirtyLeaves:g,editorState:l,prevEditorState:p})=>{if(!f.has("historic")&&
32
+ !a.isComposing()){var r=l.read(k.$getSelection);f=p.read(k.$getSelection);if(k.$isRangeSelection(f)&&k.$isRangeSelection(r)&&r.isCollapsed()){p=r.anchor.key;var y=r.anchor.offset,q=l._nodeMap.get(p);!k.$isTextNode(q)||!g.has(p)||1!==y&&y>f.anchor.offset+1||a.update(()=>{if(!q.hasFormat("code")){var m=q.getParent();if(null!==m&&!t.$isCodeNode(m)){var w=r.anchor.offset;b:{var h=c.element,n=m.getParent();if(k.$isRootOrShadowRoot(n)&&m.getFirstChild()===q&&(n=q.getTextContent()," "===n[w-1]))for(let {regExp:D,
33
33
  replace:E}of h)if((h=n.match(D))&&h[0].length===w){n=q.getNextSiblings();let [F,ua]=q.splitText(w);F.remove();n=ua?[ua,...n]:n;E(m,n,h,!1);m=!0;break b}m=!1}if(!m){b:{h=q.getTextContent();m=e[h[w-1]];if(null!=m){w<h.length&&(h=h.slice(0,w));for(x of m)if(m=h.match(x.regExp),null!==m){h=m.index||0;n=h+m[0].length;var v=void 0;0===h?[v]=q.splitText(n):[,v]=q.splitText(h,n);v.selectNext(0,0);x.replace(v,m);var x=!0;break b}}x=!1}if(!x)b:{n=q.getTextContent();--w;var u=n[w];if(x=d[u])for(let D of x){var {tag:C}=
34
34
  D;x=C.length;let E=w-x+1;if(!(1<x&&!W(n,E,C,0,x)||" "===n[E-1])&&(v=n[w+1],!1!==D.intraword||!v||J.test(v))){m=v=q;h=V(n,E,C);for(var z=m;0>h&&(z=z.getPreviousSibling())&&!k.$isLineBreakNode(z);)k.$isTextNode(z)&&(h=z.getTextContent(),m=z,h=V(h,h.length,C));if(!(0>h||m===v&&h+x===E||(C=m.getTextContent(),0<h&&C[h-1]===u||(z=C[h-1],!1===D.intraword&&z&&!J.test(z))))){n=v.getTextContent();n=n.slice(0,E)+n.slice(w+1);v.setTextContent(n);n=m===v?n:C;m.setTextContent(n.slice(0,h)+n.slice(h+x));n=k.$getSelection();
35
35
  u=k.$createRangeSelection();k.$setSelection(u);w=w-x*(m===v?2:1)+1;u.anchor.set(m.__key,h,"text");u.focus.set(v.__key,w,"text");for(let F of D.format)u.hasFormat(F)||u.formatText(F);u.anchor.set(u.focus.key,u.focus.offset,u.focus.type);for(let F of D.format)u.hasFormat(F)&&u.toggleFormat(F);k.$isRangeSelection(n)&&(u.format=n.format);break b}}}}}}}})}}})}
@@ -6,21 +6,21 @@
6
6
  *
7
7
  */
8
8
  import { ElementNode, Klass, LexicalNode, TextFormatType, TextNode } from 'lexical';
9
- export declare type Transformer = ElementTransformer | TextFormatTransformer | TextMatchTransformer;
10
- export declare type ElementTransformer = {
9
+ export type Transformer = ElementTransformer | TextFormatTransformer | TextMatchTransformer;
10
+ export type ElementTransformer = {
11
11
  dependencies: Array<Klass<LexicalNode>>;
12
12
  export: (node: LexicalNode, traverseChildren: (node: ElementNode) => string) => string | null;
13
13
  regExp: RegExp;
14
14
  replace: (parentNode: ElementNode, children: Array<LexicalNode>, match: Array<string>, isImport: boolean) => void;
15
15
  type: 'element';
16
16
  };
17
- export declare type TextFormatTransformer = Readonly<{
17
+ export type TextFormatTransformer = Readonly<{
18
18
  format: ReadonlyArray<TextFormatType>;
19
19
  tag: string;
20
20
  intraword?: boolean;
21
21
  type: 'text-format';
22
22
  }>;
23
- export declare type TextMatchTransformer = Readonly<{
23
+ export type TextMatchTransformer = Readonly<{
24
24
  dependencies: Array<Klass<LexicalNode>>;
25
25
  export: (node: LexicalNode, exportChildren: (node: ElementNode) => string, exportFormat: (node: TextNode, textContent: string) => string) => string | null;
26
26
  importRegExp: RegExp;
package/package.json CHANGED
@@ -8,18 +8,18 @@
8
8
  "markdown"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.11.1",
11
+ "version": "0.11.2",
12
12
  "main": "LexicalMarkdown.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.11.1"
14
+ "lexical": "0.11.2"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.11.1",
18
- "@lexical/code": "0.11.1",
19
- "@lexical/text": "0.11.1",
20
- "@lexical/rich-text": "0.11.1",
21
- "@lexical/list": "0.11.1",
22
- "@lexical/link": "0.11.1"
17
+ "@lexical/utils": "0.11.2",
18
+ "@lexical/code": "0.11.2",
19
+ "@lexical/text": "0.11.2",
20
+ "@lexical/rich-text": "0.11.2",
21
+ "@lexical/list": "0.11.2",
22
+ "@lexical/link": "0.11.2"
23
23
  },
24
24
  "repository": {
25
25
  "type": "git",
package/utils.d.ts CHANGED
@@ -7,8 +7,8 @@
7
7
  */
8
8
  import type { ElementTransformer, TextFormatTransformer, TextMatchTransformer, Transformer } from '@lexical/markdown';
9
9
  import type { ElementNode, LexicalNode, TextFormatType } from 'lexical';
10
- 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';
11
- declare type MarkdownCriteria = Readonly<{
10
+ 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';
11
+ type MarkdownCriteria = Readonly<{
12
12
  export?: (node: LexicalNode, traverseChildren: (elementNode: ElementNode) => string) => string | null;
13
13
  exportFormat?: TextFormatType;
14
14
  exportTag?: string;
@@ -18,7 +18,7 @@ declare type MarkdownCriteria = Readonly<{
18
18
  regExForAutoFormatting: RegExp;
19
19
  requiresParagraphStart: boolean | null | undefined;
20
20
  }>;
21
- declare type MarkdownCriteriaArray = Array<MarkdownCriteria>;
21
+ type MarkdownCriteriaArray = Array<MarkdownCriteria>;
22
22
  export declare function getAllMarkdownCriteriaForParagraphs(): MarkdownCriteriaArray;
23
23
  export declare function getAllMarkdownCriteriaForTextNodes(): MarkdownCriteriaArray;
24
24
  export declare function indexBy<T>(list: Array<T>, callback: (arg0: T) => string): Readonly<Record<string, Array<T>>>;