monza-editor 0.2.1 → 0.3.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/dist/index.css +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -11
- package/rslib.config.ts +0 -5
- package/src/index.module.css +4 -0
- package/src/index.test.ts +1 -1
- package/src/index.ts +28 -5
package/dist/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.main-TdgjvV{position:relative}.text-YtgeQ_{white-space:break-spaces;word-break:break-word}.editor-ore7X3{box-sizing:border-box;font-family:var(--font-family,monospace);font-size:inherit;line-height:inherit;padding:var(--padding,.1rem);text-align:left;border:none;width:100%;height:100%;margin:0}.textarea-ugnhty{field-sizing:content;resize:none}.pre-bJTdjq{pointer-events:none;position:absolute;top:0;left:0}
|
|
1
|
+
.main-TdgjvV{position:relative}.text-YtgeQ_{white-space:break-spaces;word-break:break-word}.editor-ore7X3{box-sizing:border-box;font-family:var(--font-family,monospace);font-size:inherit;line-height:inherit;padding:var(--padding,.1rem);text-align:left;overscroll-behavior:none;border:none;width:100%;height:100%;margin:0;overflow:scroll}.textarea-ugnhty{field-sizing:content;resize:none}.pre-bJTdjq{pointer-events:none;scrollbar-width:0;position:absolute;top:0;left:0}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
interface Options {
|
|
2
|
+
highlight: (text: string) => string;
|
|
3
|
+
onChange?: (event: Event) => void;
|
|
4
|
+
onInput?: (event: Event) => void;
|
|
5
|
+
value?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const initialize: (container: Element, { highlight, onChange, onInput, value }: Options) => void;
|
|
8
|
+
export {};
|
|
2
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,UAAU,OAAO;IACf,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,UAAU,GACrB,WAAW,OAAO,EAClB,yCAAyC,OAAO,KAC/C,IAuCF,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let e=(e,t)=>{e.className+=" main-TdgjvV";let
|
|
1
|
+
let e=(e,{highlight:t,onChange:l,onInput:a,value:n})=>{e.className+=" main-TdgjvV";let r=e.appendChild(document.createElement("textarea"));r.className+=" textarea-ugnhty editor-ore7X3 text-YtgeQ_",r.setAttribute("spellcheck","false"),r.value=n??"";let d=e.appendChild(document.createElement("pre"));d.className+=" pre-bJTdjq editor-ore7X3";let c=d.appendChild(document.createElement("code"));c.className+=" code-p0LDSQ text-YtgeQ_";let s=()=>{d.scrollTop=r.scrollTop,d.scrollLeft=r.scrollLeft},i=()=>window.requestAnimationFrame(()=>{let e=r.value;c.innerHTML=t("\n"===e.at(-1)?`${e} `:e),s()});r.addEventListener("input",e=>{i(),a?.(e)}),r.addEventListener("scroll",s),l&&r.addEventListener("change",l),i()};export{e as initialize};
|
package/package.json
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "monza-editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The minimal textarea with syntax highlight",
|
|
5
5
|
"repository": "https://github.com/raviqqe/monza-editor",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"provenance": true
|
|
9
9
|
},
|
|
10
|
-
"engines": {
|
|
11
|
-
"node": "^24.5.0"
|
|
12
|
-
},
|
|
13
|
-
"packageManager": "pnpm@10.14.0+sha512.ad27a79641b49c3e481a16a805baa71817a04bbe06a38d17e60e2eaee83f6a146c6a688125f5792e48dd5ba30e7da52a5cda4c3992b9ccf333f9ce223af84748",
|
|
14
10
|
"type": "module",
|
|
15
11
|
"exports": {
|
|
16
12
|
".": {
|
|
@@ -26,15 +22,10 @@
|
|
|
26
22
|
"lint": "biome ci",
|
|
27
23
|
"test": "vitest"
|
|
28
24
|
},
|
|
29
|
-
"dependencies": {
|
|
30
|
-
"shiki": "^3.9.2"
|
|
31
|
-
},
|
|
25
|
+
"dependencies": {},
|
|
32
26
|
"devDependencies": {
|
|
33
|
-
"@biomejs/biome": "^2.1.4",
|
|
34
|
-
"@raviqqe/biome-config": "^2.0.10",
|
|
35
27
|
"@raviqqe/tsconfig": "^2.0.1",
|
|
36
28
|
"@rslib/core": "^0.12.0",
|
|
37
|
-
"@vitest/coverage-v8": "^3.0.2",
|
|
38
29
|
"jsdom": "^26.1.0",
|
|
39
30
|
"typescript": "^5.9.2",
|
|
40
31
|
"typescript-plugin-css-modules": "^5.2.0",
|
package/rslib.config.ts
CHANGED
package/src/index.module.css
CHANGED
|
@@ -18,12 +18,15 @@
|
|
|
18
18
|
text-align: left;
|
|
19
19
|
width: 100%;
|
|
20
20
|
height: 100%;
|
|
21
|
+
overflow: scroll;
|
|
22
|
+
overscroll-behavior: none;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
.textarea {
|
|
24
26
|
composes: editor;
|
|
25
27
|
composes: text;
|
|
26
28
|
|
|
29
|
+
/* TODO Support auto height. */
|
|
27
30
|
field-sizing: content;
|
|
28
31
|
resize: none;
|
|
29
32
|
}
|
|
@@ -35,6 +38,7 @@
|
|
|
35
38
|
top: 0;
|
|
36
39
|
left: 0;
|
|
37
40
|
pointer-events: none;
|
|
41
|
+
scrollbar-width: 0;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
.code {
|
package/src/index.test.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import styles from "./index.module.css";
|
|
2
2
|
|
|
3
|
+
interface Options {
|
|
4
|
+
highlight: (text: string) => string;
|
|
5
|
+
onChange?: (event: Event) => void;
|
|
6
|
+
onInput?: (event: Event) => void;
|
|
7
|
+
value?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
export const initialize = (
|
|
4
11
|
container: Element,
|
|
5
|
-
highlight
|
|
12
|
+
{ highlight, onChange, onInput, value }: Options,
|
|
6
13
|
): void => {
|
|
7
14
|
container.className += ` ${styles.main}`;
|
|
8
15
|
|
|
9
16
|
const textarea = container.appendChild(document.createElement("textarea"));
|
|
10
17
|
textarea.className += ` ${styles.textarea}`;
|
|
18
|
+
textarea.setAttribute("spellcheck", "false");
|
|
19
|
+
textarea.value = value ?? "";
|
|
11
20
|
|
|
12
21
|
const pre = container.appendChild(document.createElement("pre"));
|
|
13
22
|
pre.className += ` ${styles.pre}`;
|
|
@@ -15,15 +24,29 @@ export const initialize = (
|
|
|
15
24
|
const code = pre.appendChild(document.createElement("code"));
|
|
16
25
|
code.className += ` ${styles.code}`;
|
|
17
26
|
|
|
27
|
+
const scroll = () => {
|
|
28
|
+
pre.scrollTop = textarea.scrollTop;
|
|
29
|
+
pre.scrollLeft = textarea.scrollLeft;
|
|
30
|
+
};
|
|
31
|
+
|
|
18
32
|
const update = () =>
|
|
19
33
|
window.requestAnimationFrame(() => {
|
|
20
|
-
|
|
34
|
+
const text = textarea.value;
|
|
21
35
|
|
|
22
|
-
|
|
23
|
-
|
|
36
|
+
code.innerHTML = highlight(text.at(-1) === "\n" ? `${text} ` : text);
|
|
37
|
+
|
|
38
|
+
scroll();
|
|
24
39
|
});
|
|
25
40
|
|
|
26
|
-
textarea.addEventListener("input",
|
|
41
|
+
textarea.addEventListener("input", (event) => {
|
|
42
|
+
update();
|
|
43
|
+
onInput?.(event);
|
|
44
|
+
});
|
|
45
|
+
textarea.addEventListener("scroll", scroll);
|
|
46
|
+
|
|
47
|
+
if (onChange) {
|
|
48
|
+
textarea.addEventListener("change", onChange);
|
|
49
|
+
}
|
|
27
50
|
|
|
28
51
|
update();
|
|
29
52
|
};
|