@keshav-writes-code/hypermd-uplift 0.4.0

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.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (C) 2017-2018 by laobubu <laobubu@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # HyperMD
2
+
3
+ A full-featured Markdown editor, breaking the wall between writing and preview.
4
+ Built on **CodeMirror 6**.
5
+
6
+ ## Features
7
+
8
+ - **WYSIWYG-ish**: Renders Markdown syntax (Images, Math, etc.) in place.
9
+ - **Modern**: Built with TypeScript and Vite.
10
+ - **Modular**: Extensions for specific features.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install hypermd-uplift
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```typescript
21
+ import { EditorView } from '@codemirror/view'
22
+ import { EditorState } from '@codemirror/state'
23
+ import { hypermd } from 'hypermd-uplift'
24
+
25
+ new EditorView({
26
+ state: EditorState.create({
27
+ doc: "# Hello HyperMD",
28
+ extensions: [
29
+ hypermd()
30
+ ]
31
+ }),
32
+ parent: document.body
33
+ })
34
+ ```
35
+
36
+ ## Development
37
+
38
+ 1. Clone the repo.
39
+ 2. `npm install`
40
+ 3. `npm run dev` to start the playground.
41
+ 4. `npm run build` to build the library.
42
+
43
+ ## License
44
+
45
+ MIT
package/dist/core.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const hypermdTheme: import('@codemirror/state').Extension;
@@ -0,0 +1,15 @@
1
+ import { Decoration, DecorationSet, EditorView, ViewPlugin, ViewUpdate } from '@codemirror/view';
2
+ import { Extension } from '@codemirror/state';
3
+
4
+ export type NodeDecorator = (node: {
5
+ name: string;
6
+ from: number;
7
+ to: number;
8
+ node: any;
9
+ }, view: EditorView) => Decoration | null;
10
+ export declare function createDecorationPlugin(decorators: NodeDecorator[]): ViewPlugin<{
11
+ decorations: DecorationSet;
12
+ update(update: ViewUpdate): void;
13
+ buildDecorations(view: EditorView): DecorationSet;
14
+ }, undefined>;
15
+ export declare function hypermdFold(decorators?: NodeDecorator[]): Extension;
@@ -0,0 +1,3 @@
1
+ import { Extension } from '@codemirror/state';
2
+
3
+ export declare function hypermdInteraction(): Extension;
@@ -0,0 +1,3 @@
1
+ import { Extension } from '@codemirror/state';
2
+
3
+ export declare function hypermdMath(): Extension;
@@ -0,0 +1,3 @@
1
+ import { Extension } from '@codemirror/state';
2
+
3
+ export declare function hypermdMedia(): Extension;
@@ -0,0 +1,3 @@
1
+ import { Extension } from '@codemirror/state';
2
+
3
+ export declare function hypermdTable(): Extension;
@@ -0,0 +1,11 @@
1
+ import { Extension } from '@codemirror/state';
2
+ import { hypermdFold } from './features/fold';
3
+ import { hypermdMath } from './features/math';
4
+ import { hypermdMedia } from './features/media';
5
+ import { hypermdInteraction } from './features/interaction';
6
+ import { hypermdTable } from './features/table';
7
+
8
+ export interface HyperMDConfig {
9
+ }
10
+ export declare function hypermd(_config?: HyperMDConfig): Extension;
11
+ export { hypermdFold, hypermdMath, hypermdMedia, hypermdInteraction, hypermdTable };
package/dist/index.js ADDED
@@ -0,0 +1,174 @@
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);
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
+ "&": {
10
+ fontFamily: "var(--hypermd-font-family, system-ui, sans-serif)",
11
+ lineHeight: "1.6"
12
+ }
13
+ });
14
+ function f(e) {
15
+ return m.fromClass(
16
+ class {
17
+ constructor(t) {
18
+ a(this, "decorations");
19
+ this.decorations = this.buildDecorations(t);
20
+ }
21
+ update(t) {
22
+ (t.docChanged || t.viewportChanged || t.selectionSet) && (this.decorations = this.buildDecorations(t.view));
23
+ }
24
+ 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;
36
+ }
37
+ }
38
+ });
39
+ return i.set(r);
40
+ }
41
+ },
42
+ {
43
+ decorations: (t) => t.decorations
44
+ }
45
+ );
46
+ }
47
+ function C(e = []) {
48
+ return e.length === 0 ? [] : f(e);
49
+ }
50
+ class M extends d {
51
+ constructor(t, r) {
52
+ super(), this.code = t, this.display = r;
53
+ }
54
+ eq(t) {
55
+ return t.code == this.code && t.display == this.display;
56
+ }
57
+ toDOM() {
58
+ const t = document.createElement("span");
59
+ t.className = "hypermd-math";
60
+ try {
61
+ x.render(this.code, t, { displayMode: this.display, throwOnError: !1 });
62
+ } catch {
63
+ t.textContent = this.code;
64
+ }
65
+ return t;
66
+ }
67
+ ignoreEvent() {
68
+ return !1;
69
+ }
70
+ }
71
+ const h = new b({
72
+ regexp: /\$\$([\s\S]+?)\$\$|\$([^$\n]+)\$/g,
73
+ decoration: (e) => {
74
+ const t = !!e[1], r = t ? e[1] : e[2];
75
+ return i.replace({
76
+ widget: new M(r, t)
77
+ });
78
+ }
79
+ });
80
+ function $() {
81
+ return m.fromClass(class {
82
+ constructor(e) {
83
+ a(this, "math");
84
+ this.math = h.createDeco(e);
85
+ }
86
+ update(e) {
87
+ this.math = h.updateDeco(e, this.math);
88
+ }
89
+ }, {
90
+ decorations: (e) => e.math,
91
+ provide: (e) => c.atomicRanges.of((t) => {
92
+ var r;
93
+ return ((r = t.plugin(e)) == null ? void 0 : r.math) || i.none;
94
+ })
95
+ });
96
+ }
97
+ class E extends d {
98
+ constructor(t, r) {
99
+ super(), this.url = t, this.title = r;
100
+ }
101
+ eq(t) {
102
+ return this.url === t.url && this.title === t.title;
103
+ }
104
+ toDOM() {
105
+ const t = document.createElement("img");
106
+ return t.src = this.url, t.alt = this.title, t.title = this.title, t.className = "hypermd-image", t.style.maxWidth = "100%", t;
107
+ }
108
+ }
109
+ function k() {
110
+ return f([
111
+ (e, t) => {
112
+ 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])
117
+ });
118
+ }
119
+ return null;
120
+ }
121
+ ]);
122
+ }
123
+ function T() {
124
+ return c.domEventHandlers({
125
+ click: (e, t) => {
126
+ }
127
+ });
128
+ }
129
+ function W() {
130
+ return m.fromClass(class {
131
+ constructor(e) {
132
+ a(this, "decorations");
133
+ this.decorations = this.buildDecorations(e);
134
+ }
135
+ update(e) {
136
+ (e.docChanged || e.viewportChanged) && (this.decorations = this.buildDecorations(e.view));
137
+ }
138
+ buildDecorations(e) {
139
+ const t = [];
140
+ for (const { from: r, to: o } of e.visibleRanges)
141
+ u(e.state).iterate({
142
+ from: r,
143
+ to: o,
144
+ enter: (n) => {
145
+ n.name === "Table" && t.push(i.mark({
146
+ class: "hypermd-table"
147
+ }).range(n.from, n.to));
148
+ }
149
+ });
150
+ return i.set(t);
151
+ }
152
+ }, {
153
+ decorations: (e) => e.decorations
154
+ });
155
+ }
156
+ function F(e = {}) {
157
+ return [
158
+ v,
159
+ w(),
160
+ C(),
161
+ $(),
162
+ k(),
163
+ T(),
164
+ W()
165
+ ];
166
+ }
167
+ export {
168
+ F as hypermd,
169
+ C as hypermdFold,
170
+ T as hypermdInteraction,
171
+ $ as hypermdMath,
172
+ k as hypermdMedia,
173
+ W as hypermdTable
174
+ };
@@ -0,0 +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"})});
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@keshav-writes-code/hypermd-uplift",
3
+ "version": "0.4.0",
4
+ "description": "A full-featured Markdown editor, breaks the wall between writing and preview.",
5
+ "type": "module",
6
+ "main": "./dist/index.umd.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.umd.js",
13
+ "types": "./dist/index.d.ts"
14
+ },
15
+ "./style.css": "./dist/style.css"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "scripts": {
21
+ "dev": "vite",
22
+ "build": "tsc && vite build",
23
+ "preview": "vite preview",
24
+ "lint": "eslint . --ext .ts,.tsx",
25
+ "format": "prettier --write .",
26
+ "test": "npm run lint",
27
+ "prepublishOnly": "npm run build"
28
+ },
29
+ "keywords": [
30
+ "markdown",
31
+ "codemirror",
32
+ "wysiwyg",
33
+ "editor"
34
+ ],
35
+ "author": "laobubu <laobubu@gmail.com> (http://laobubu.net)",
36
+ "license": "MIT",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/Keshav-writes-code/HyperMD-uplift.git"
40
+ },
41
+ "peerDependencies": {
42
+ "@codemirror/state": "^6.0.0",
43
+ "@codemirror/view": "^6.0.0",
44
+ "@codemirror/language": "^6.0.0",
45
+ "@codemirror/lang-markdown": "^6.0.0",
46
+ "katex": "^0.16.0"
47
+ },
48
+ "dependencies": {},
49
+ "devDependencies": {
50
+ "@codemirror/autocomplete": "^6.0.0",
51
+ "@codemirror/commands": "^6.0.0",
52
+ "@codemirror/lang-markdown": "^6.0.0",
53
+ "@codemirror/language": "^6.0.0",
54
+ "@codemirror/lint": "^6.0.0",
55
+ "@codemirror/search": "^6.0.0",
56
+ "@codemirror/state": "^6.0.0",
57
+ "@codemirror/view": "^6.0.0",
58
+ "@types/node": "^18.0.0",
59
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
60
+ "@typescript-eslint/parser": "^6.0.0",
61
+ "eslint": "^8.0.0",
62
+ "katex": "^0.16.0",
63
+ "prettier": "^3.0.0",
64
+ "sass": "^1.63.0",
65
+ "typescript": "^5.0.0",
66
+ "vite": "^4.0.0",
67
+ "vite-plugin-dts": "^3.0.0"
68
+ }
69
+ }