hypermd-uplift 0.4.0 → 0.4.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.
@@ -1,11 +1,12 @@
1
1
  import { Decoration, DecorationSet, EditorView, ViewPlugin, ViewUpdate } from '@codemirror/view';
2
2
  import { Extension } from '@codemirror/state';
3
+ import { SyntaxNodeRef } from '@lezer/common';
3
4
 
4
5
  export type NodeDecorator = (node: {
5
6
  name: string;
6
7
  from: number;
7
8
  to: number;
8
- node: any;
9
+ node: SyntaxNodeRef;
9
10
  }, view: EditorView) => Decoration | null;
10
11
  export declare function createDecorationPlugin(decorators: NodeDecorator[]): ViewPlugin<{
11
12
  decorations: DecorationSet;
@@ -0,0 +1,4 @@
1
+ import { Extension } from '@codemirror/state';
2
+
3
+ export declare const hypermdBaseTheme: Extension;
4
+ export declare function hypermdStyling(): Extension;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Extension } from '@codemirror/state';
2
+ import { hypermdStyling } from './features/styling';
2
3
  import { hypermdFold } from './features/fold';
3
4
  import { hypermdMath } from './features/math';
4
5
  import { hypermdMedia } from './features/media';
@@ -8,4 +9,4 @@ import { hypermdTable } from './features/table';
8
9
  export interface HyperMDConfig {
9
10
  }
10
11
  export declare function hypermd(_config?: HyperMDConfig): Extension;
11
- export { hypermdFold, hypermdMath, hypermdMedia, hypermdInteraction, hypermdTable };
12
+ export { hypermdStyling, hypermdFold, hypermdMath, hypermdMedia, hypermdInteraction, hypermdTable };
package/dist/index.js CHANGED
@@ -1,42 +1,96 @@
1
- var y = Object.defineProperty;
2
- var D = (e, t, r) => t in e ? y(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var a = (e, t, r) => (D(e, typeof t != "symbol" ? t + "" : t, r), r);
1
+ var b = Object.defineProperty;
2
+ var x = (e, t, r) => t in e ? b(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var c = (e, t, r) => (x(e, typeof t != "symbol" ? t + "" : t, r), r);
4
4
  import { markdown as w } from "@codemirror/lang-markdown";
5
- import { EditorView as c, ViewPlugin as m, Decoration as i, MatchDecorator as b, WidgetType as d } from "@codemirror/view";
6
- import { syntaxTree as u } from "@codemirror/language";
7
- import x from "katex";
8
- const v = c.theme({
9
- "&": {
5
+ import { EditorView as d, ViewPlugin as l, Decoration as s, WidgetType as m, MatchDecorator as D } from "@codemirror/view";
6
+ import { syntaxTree as h } from "@codemirror/language";
7
+ import C from "katex";
8
+ const M = d.theme({
9
+ ".cm-content": {
10
10
  fontFamily: "var(--hypermd-font-family, system-ui, sans-serif)",
11
11
  lineHeight: "1.6"
12
- }
12
+ },
13
+ // Headings
14
+ ".cm-line .cm-header-1": { fontSize: "2em", fontWeight: "bold" },
15
+ ".cm-line .cm-header-2": { fontSize: "1.5em", fontWeight: "bold" },
16
+ ".cm-line .cm-header-3": { fontSize: "1.25em", fontWeight: "bold" },
17
+ ".cm-line .cm-header-4": { fontSize: "1.1em", fontWeight: "bold" },
18
+ // Lists (We will hide the marker and replace with a widget, but basic styling here)
19
+ ".cm-line .cm-list": { paddingLeft: "5px" },
20
+ ".cm-line .cm-quote": { borderLeft: "4px solid #ccc", paddingLeft: "10px", color: "#666" }
13
21
  });
14
- function f(e) {
15
- return m.fromClass(
22
+ class W extends m {
23
+ toDOM() {
24
+ const t = document.createElement("span");
25
+ return t.textContent = "•", t.style.fontWeight = "bold", t.style.marginRight = "5px", t;
26
+ }
27
+ }
28
+ class v extends m {
29
+ toDOM() {
30
+ return document.createElement("span");
31
+ }
32
+ // Empty span
33
+ }
34
+ function u(e) {
35
+ const t = [];
36
+ for (const { from: r, to: n } of e.visibleRanges)
37
+ h(e.state).iterate({
38
+ from: r,
39
+ to: n,
40
+ enter: (o) => {
41
+ const a = o.name;
42
+ if (a.startsWith("HeaderMark") && t.push(s.replace({
43
+ widget: new v()
44
+ }).range(o.from, o.to)), a === "ListMark") {
45
+ const i = e.state.sliceDoc(o.from, o.to);
46
+ ["-", "*", "+"].includes(i.trim()) && t.push(s.replace({
47
+ widget: new W()
48
+ }).range(o.from, o.to));
49
+ }
50
+ }
51
+ });
52
+ return s.set(t);
53
+ }
54
+ function E() {
55
+ return [
56
+ M,
57
+ l.fromClass(class {
58
+ constructor(e) {
59
+ c(this, "decorations");
60
+ this.decorations = u(e);
61
+ }
62
+ update(e) {
63
+ (e.docChanged || e.viewportChanged) && (this.decorations = u(e.view));
64
+ }
65
+ }, { decorations: (e) => e.decorations })
66
+ ];
67
+ }
68
+ function p(e) {
69
+ return l.fromClass(
16
70
  class {
17
71
  constructor(t) {
18
- a(this, "decorations");
72
+ c(this, "decorations");
19
73
  this.decorations = this.buildDecorations(t);
20
74
  }
21
75
  update(t) {
22
76
  (t.docChanged || t.viewportChanged || t.selectionSet) && (this.decorations = this.buildDecorations(t.view));
23
77
  }
24
78
  buildDecorations(t) {
25
- const r = [], o = t.state.selection.main;
26
- for (const { from: n, to: p } of t.visibleRanges)
27
- u(t.state).iterate({
28
- from: n,
29
- to: p,
30
- enter: (s) => {
31
- if (!(o.from >= s.from && o.to <= s.to))
32
- for (const g of e) {
33
- const l = g({ name: s.name, from: s.from, to: s.to, node: s }, t);
34
- if (l)
35
- return r.push(l.range(s.from, s.to)), !1;
79
+ const r = [], n = t.state.selection.main;
80
+ for (const { from: o, to: a } of t.visibleRanges)
81
+ h(t.state).iterate({
82
+ from: o,
83
+ to: a,
84
+ enter: (i) => {
85
+ if (!(n.from >= i.from && n.to <= i.to))
86
+ for (const y of e) {
87
+ const f = y({ name: i.name, from: i.from, to: i.to, node: i }, t);
88
+ if (f)
89
+ return r.push(f.range(i.from, i.to)), !1;
36
90
  }
37
91
  }
38
92
  });
39
- return i.set(r);
93
+ return s.set(r);
40
94
  }
41
95
  },
42
96
  {
@@ -44,10 +98,10 @@ function f(e) {
44
98
  }
45
99
  );
46
100
  }
47
- function C(e = []) {
48
- return e.length === 0 ? [] : f(e);
101
+ function $(e = []) {
102
+ return e.length === 0 ? [] : p(e);
49
103
  }
50
- class M extends d {
104
+ class k extends m {
51
105
  constructor(t, r) {
52
106
  super(), this.code = t, this.display = r;
53
107
  }
@@ -58,7 +112,7 @@ class M extends d {
58
112
  const t = document.createElement("span");
59
113
  t.className = "hypermd-math";
60
114
  try {
61
- x.render(this.code, t, { displayMode: this.display, throwOnError: !1 });
115
+ C.render(this.code, t, { displayMode: this.display, throwOnError: !1 });
62
116
  } catch {
63
117
  t.textContent = this.code;
64
118
  }
@@ -68,33 +122,33 @@ class M extends d {
68
122
  return !1;
69
123
  }
70
124
  }
71
- const h = new b({
125
+ const g = new D({
72
126
  regexp: /\$\$([\s\S]+?)\$\$|\$([^$\n]+)\$/g,
73
127
  decoration: (e) => {
74
128
  const t = !!e[1], r = t ? e[1] : e[2];
75
- return i.replace({
76
- widget: new M(r, t)
129
+ return s.replace({
130
+ widget: new k(r, t)
77
131
  });
78
132
  }
79
133
  });
80
- function $() {
81
- return m.fromClass(class {
134
+ function S() {
135
+ return l.fromClass(class {
82
136
  constructor(e) {
83
- a(this, "math");
84
- this.math = h.createDeco(e);
137
+ c(this, "math");
138
+ this.math = g.createDeco(e);
85
139
  }
86
140
  update(e) {
87
- this.math = h.updateDeco(e, this.math);
141
+ this.math = g.updateDeco(e, this.math);
88
142
  }
89
143
  }, {
90
144
  decorations: (e) => e.math,
91
- provide: (e) => c.atomicRanges.of((t) => {
145
+ provide: (e) => d.atomicRanges.of((t) => {
92
146
  var r;
93
- return ((r = t.plugin(e)) == null ? void 0 : r.math) || i.none;
147
+ return ((r = t.plugin(e)) == null ? void 0 : r.math) || s.none;
94
148
  })
95
149
  });
96
150
  }
97
- class E extends d {
151
+ class O extends m {
98
152
  constructor(t, r) {
99
153
  super(), this.url = t, this.title = r;
100
154
  }
@@ -106,14 +160,14 @@ class E extends d {
106
160
  return t.src = this.url, t.alt = this.title, t.title = this.title, t.className = "hypermd-image", t.style.maxWidth = "100%", t;
107
161
  }
108
162
  }
109
- function k() {
110
- return f([
163
+ function R() {
164
+ return p([
111
165
  (e, t) => {
112
166
  if (e.name === "Image") {
113
- const r = t.state.sliceDoc(e.from, e.to), o = /^!\[(.*?)\]\((.*?)\)$/.exec(r);
114
- if (o)
115
- return i.replace({
116
- widget: new E(o[2], o[1])
167
+ const r = t.state.sliceDoc(e.from, e.to), n = /^!\[(.*?)\]\((.*?)\)$/.exec(r);
168
+ if (n)
169
+ return s.replace({
170
+ widget: new O(n[2], n[1])
117
171
  });
118
172
  }
119
173
  return null;
@@ -121,15 +175,15 @@ function k() {
121
175
  ]);
122
176
  }
123
177
  function T() {
124
- return c.domEventHandlers({
178
+ return d.domEventHandlers({
125
179
  click: (e, t) => {
126
180
  }
127
181
  });
128
182
  }
129
- function W() {
130
- return m.fromClass(class {
183
+ function z() {
184
+ return l.fromClass(class {
131
185
  constructor(e) {
132
- a(this, "decorations");
186
+ c(this, "decorations");
133
187
  this.decorations = this.buildDecorations(e);
134
188
  }
135
189
  update(e) {
@@ -137,38 +191,39 @@ function W() {
137
191
  }
138
192
  buildDecorations(e) {
139
193
  const t = [];
140
- for (const { from: r, to: o } of e.visibleRanges)
141
- u(e.state).iterate({
194
+ for (const { from: r, to: n } of e.visibleRanges)
195
+ h(e.state).iterate({
142
196
  from: r,
143
- to: o,
144
- enter: (n) => {
145
- n.name === "Table" && t.push(i.mark({
197
+ to: n,
198
+ enter: (o) => {
199
+ o.name === "Table" && t.push(s.mark({
146
200
  class: "hypermd-table"
147
- }).range(n.from, n.to));
201
+ }).range(o.from, o.to));
148
202
  }
149
203
  });
150
- return i.set(t);
204
+ return s.set(t);
151
205
  }
152
206
  }, {
153
207
  decorations: (e) => e.decorations
154
208
  });
155
209
  }
156
- function F(e = {}) {
210
+ function P(e = {}) {
157
211
  return [
158
- v,
159
212
  w(),
160
- C(),
213
+ E(),
161
214
  $(),
162
- k(),
215
+ S(),
216
+ R(),
163
217
  T(),
164
- W()
218
+ z()
165
219
  ];
166
220
  }
167
221
  export {
168
- F as hypermd,
169
- C as hypermdFold,
222
+ P as hypermd,
223
+ $ as hypermdFold,
170
224
  T as hypermdInteraction,
171
- $ as hypermdMath,
172
- k as hypermdMedia,
173
- W as hypermdTable
225
+ S as hypermdMath,
226
+ R as hypermdMedia,
227
+ E as hypermdStyling,
228
+ z as hypermdTable
174
229
  };
@@ -1 +1 @@
1
- (function(r,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@codemirror/lang-markdown"),require("@codemirror/view"),require("@codemirror/language"),require("katex")):typeof define=="function"&&define.amd?define(["exports","@codemirror/lang-markdown","@codemirror/view","@codemirror/language","katex"],i):(r=typeof globalThis<"u"?globalThis:r||self,i(r["HyperMD-uplift"]={},r.CM.lang.markdown,r.CM.view,r.CM.language,r.katex))})(this,function(r,i,o,m,M){"use strict";var E=Object.defineProperty;var q=(r,i,o)=>i in r?E(r,i,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[i]=o;var d=(r,i,o)=>(q(r,typeof i!="symbol"?i+"":i,o),o);const b=o.EditorView.theme({"&":{fontFamily:"var(--hypermd-font-family, system-ui, sans-serif)",lineHeight:"1.6"}});function u(t){return o.ViewPlugin.fromClass(class{constructor(e){d(this,"decorations");this.decorations=this.buildDecorations(e)}update(e){(e.docChanged||e.viewportChanged||e.selectionSet)&&(this.decorations=this.buildDecorations(e.view))}buildDecorations(e){const n=[],s=e.state.selection.main;for(const{from:c,to:x}of e.visibleRanges)m.syntaxTree(e.state).iterate({from:c,to:x,enter:a=>{if(!(s.from>=a.from&&s.to<=a.to))for(const w of t){const D=w({name:a.name,from:a.from,to:a.to,node:a},e);if(D)return n.push(D.range(a.from,a.to)),!1}}});return o.Decoration.set(n)}},{decorations:e=>e.decorations})}function l(t=[]){return t.length===0?[]:u(t)}class C extends o.WidgetType{constructor(e,n){super(),this.code=e,this.display=n}eq(e){return e.code==this.code&&e.display==this.display}toDOM(){const e=document.createElement("span");e.className="hypermd-math";try{M.render(this.code,e,{displayMode:this.display,throwOnError:!1})}catch{e.textContent=this.code}return e}ignoreEvent(){return!1}}const h=new o.MatchDecorator({regexp:/\$\$([\s\S]+?)\$\$|\$([^$\n]+)\$/g,decoration:t=>{const e=!!t[1],n=e?t[1]:t[2];return o.Decoration.replace({widget:new C(n,e)})}});function f(){return o.ViewPlugin.fromClass(class{constructor(t){d(this,"math");this.math=h.createDeco(t)}update(t){this.math=h.updateDeco(t,this.math)}},{decorations:t=>t.math,provide:t=>o.EditorView.atomicRanges.of(e=>{var n;return((n=e.plugin(t))==null?void 0:n.math)||o.Decoration.none})})}class T extends o.WidgetType{constructor(e,n){super(),this.url=e,this.title=n}eq(e){return this.url===e.url&&this.title===e.title}toDOM(){const e=document.createElement("img");return e.src=this.url,e.alt=this.title,e.title=this.title,e.className="hypermd-image",e.style.maxWidth="100%",e}}function p(){return u([(t,e)=>{if(t.name==="Image"){const n=e.state.sliceDoc(t.from,t.to),s=/^!\[(.*?)\]\((.*?)\)$/.exec(n);if(s)return o.Decoration.replace({widget:new T(s[2],s[1])})}return null}])}function g(){return o.EditorView.domEventHandlers({click:(t,e)=>{}})}function y(){return o.ViewPlugin.fromClass(class{constructor(t){d(this,"decorations");this.decorations=this.buildDecorations(t)}update(t){(t.docChanged||t.viewportChanged)&&(this.decorations=this.buildDecorations(t.view))}buildDecorations(t){const e=[];for(const{from:n,to:s}of t.visibleRanges)m.syntaxTree(t.state).iterate({from:n,to:s,enter:c=>{c.name==="Table"&&e.push(o.Decoration.mark({class:"hypermd-table"}).range(c.from,c.to))}});return o.Decoration.set(e)}},{decorations:t=>t.decorations})}function k(t={}){return[b,i.markdown(),l(),f(),p(),g(),y()]}r.hypermd=k,r.hypermdFold=l,r.hypermdInteraction=g,r.hypermdMath=f,r.hypermdMedia=p,r.hypermdTable=y,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
1
+ (function(o,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@codemirror/lang-markdown"),require("@codemirror/view"),require("@codemirror/language"),require("katex")):typeof define=="function"&&define.amd?define(["exports","@codemirror/lang-markdown","@codemirror/view","@codemirror/language","katex"],i):(o=typeof globalThis<"u"?globalThis:o||self,i(o["HyperMD-uplift"]={},o.CM.lang.markdown,o.CM.view,o.CM.language,o.katex))})(this,function(o,i,r,l,C){"use strict";var P=Object.defineProperty;var V=(o,i,r)=>i in o?P(o,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):o[i]=r;var d=(o,i,r)=>(V(o,typeof i!="symbol"?i+"":i,r),r);const W=r.EditorView.theme({".cm-content":{fontFamily:"var(--hypermd-font-family, system-ui, sans-serif)",lineHeight:"1.6"},".cm-line .cm-header-1":{fontSize:"2em",fontWeight:"bold"},".cm-line .cm-header-2":{fontSize:"1.5em",fontWeight:"bold"},".cm-line .cm-header-3":{fontSize:"1.25em",fontWeight:"bold"},".cm-line .cm-header-4":{fontSize:"1.1em",fontWeight:"bold"},".cm-line .cm-list":{paddingLeft:"5px"},".cm-line .cm-quote":{borderLeft:"4px solid #ccc",paddingLeft:"10px",color:"#666"}});class T extends r.WidgetType{toDOM(){const e=document.createElement("span");return e.textContent="•",e.style.fontWeight="bold",e.style.marginRight="5px",e}}class k extends r.WidgetType{toDOM(){return document.createElement("span")}}function h(t){const e=[];for(const{from:n,to:c}of t.visibleRanges)l.syntaxTree(t.state).iterate({from:n,to:c,enter:s=>{const m=s.name;if(m.startsWith("HeaderMark")&&e.push(r.Decoration.replace({widget:new k}).range(s.from,s.to)),m==="ListMark"){const a=t.state.sliceDoc(s.from,s.to);["-","*","+"].includes(a.trim())&&e.push(r.Decoration.replace({widget:new T}).range(s.from,s.to))}}});return r.Decoration.set(e)}function u(){return[W,r.ViewPlugin.fromClass(class{constructor(t){d(this,"decorations");this.decorations=h(t)}update(t){(t.docChanged||t.viewportChanged)&&(this.decorations=h(t.view))}},{decorations:t=>t.decorations})]}function f(t){return r.ViewPlugin.fromClass(class{constructor(e){d(this,"decorations");this.decorations=this.buildDecorations(e)}update(e){(e.docChanged||e.viewportChanged||e.selectionSet)&&(this.decorations=this.buildDecorations(e.view))}buildDecorations(e){const n=[],c=e.state.selection.main;for(const{from:s,to:m}of e.visibleRanges)l.syntaxTree(e.state).iterate({from:s,to:m,enter:a=>{if(!(c.from>=a.from&&c.to<=a.to))for(const q of t){const x=q({name:a.name,from:a.from,to:a.to,node:a},e);if(x)return n.push(x.range(a.from,a.to)),!1}}});return r.Decoration.set(n)}},{decorations:e=>e.decorations})}function g(t=[]){return t.length===0?[]:f(t)}class E extends r.WidgetType{constructor(e,n){super(),this.code=e,this.display=n}eq(e){return e.code==this.code&&e.display==this.display}toDOM(){const e=document.createElement("span");e.className="hypermd-math";try{C.render(this.code,e,{displayMode:this.display,throwOnError:!1})}catch{e.textContent=this.code}return e}ignoreEvent(){return!1}}const p=new r.MatchDecorator({regexp:/\$\$([\s\S]+?)\$\$|\$([^$\n]+)\$/g,decoration:t=>{const e=!!t[1],n=e?t[1]:t[2];return r.Decoration.replace({widget:new E(n,e)})}});function y(){return r.ViewPlugin.fromClass(class{constructor(t){d(this,"math");this.math=p.createDeco(t)}update(t){this.math=p.updateDeco(t,this.math)}},{decorations:t=>t.math,provide:t=>r.EditorView.atomicRanges.of(e=>{var n;return((n=e.plugin(t))==null?void 0:n.math)||r.Decoration.none})})}class S extends r.WidgetType{constructor(e,n){super(),this.url=e,this.title=n}eq(e){return this.url===e.url&&this.title===e.title}toDOM(){const e=document.createElement("img");return e.src=this.url,e.alt=this.title,e.title=this.title,e.className="hypermd-image",e.style.maxWidth="100%",e}}function D(){return f([(t,e)=>{if(t.name==="Image"){const n=e.state.sliceDoc(t.from,t.to),c=/^!\[(.*?)\]\((.*?)\)$/.exec(n);if(c)return r.Decoration.replace({widget:new S(c[2],c[1])})}return null}])}function M(){return r.EditorView.domEventHandlers({click:(t,e)=>{}})}function b(){return r.ViewPlugin.fromClass(class{constructor(t){d(this,"decorations");this.decorations=this.buildDecorations(t)}update(t){(t.docChanged||t.viewportChanged)&&(this.decorations=this.buildDecorations(t.view))}buildDecorations(t){const e=[];for(const{from:n,to:c}of t.visibleRanges)l.syntaxTree(t.state).iterate({from:n,to:c,enter:s=>{s.name==="Table"&&e.push(r.Decoration.mark({class:"hypermd-table"}).range(s.from,s.to))}});return r.Decoration.set(e)}},{decorations:t=>t.decorations})}function w(t={}){return[i.markdown(),u(),g(),y(),D(),M(),b()]}o.hypermd=w,o.hypermdFold=g,o.hypermdInteraction=M,o.hypermdMath=y,o.hypermdMedia=D,o.hypermdStyling=u,o.hypermdTable=b,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "name": "hypermd-uplift",
3
- "version": "0.4.0",
2
+ "name": "hypermd-uplift",
3
+ "version": "0.4.2",
4
4
  "description": "A full-featured Markdown editor, breaks the wall between writing and preview.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.js",
@@ -39,13 +39,12 @@
39
39
  "url": "https://github.com/Keshav-writes-code/HyperMD-uplift.git"
40
40
  },
41
41
  "peerDependencies": {
42
+ "@codemirror/lang-markdown": "^6.0.0",
43
+ "@codemirror/language": "^6.0.0",
42
44
  "@codemirror/state": "^6.0.0",
43
45
  "@codemirror/view": "^6.0.0",
44
- "@codemirror/language": "^6.0.0",
45
- "@codemirror/lang-markdown": "^6.0.0",
46
46
  "katex": "^0.16.0"
47
47
  },
48
- "dependencies": {},
49
48
  "devDependencies": {
50
49
  "@codemirror/autocomplete": "^6.0.0",
51
50
  "@codemirror/commands": "^6.0.0",
@@ -55,6 +54,7 @@
55
54
  "@codemirror/search": "^6.0.0",
56
55
  "@codemirror/state": "^6.0.0",
57
56
  "@codemirror/view": "^6.0.0",
57
+ "@lezer/common": "^1.5.0",
58
58
  "@types/node": "^18.0.0",
59
59
  "@typescript-eslint/eslint-plugin": "^6.0.0",
60
60
  "@typescript-eslint/parser": "^6.0.0",