monza-editor 0.2.2 → 0.3.1
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 +1 -1
- package/rslib.config.ts +0 -5
- package/src/index.module.css +3 -4
- package/src/index.test.ts +1 -1
- package/src/index.ts +17 -2
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;overscroll-behavior:none;border:none;width:100%;height:100%;margin:0;overflow:scroll}.textarea-ugnhty{
|
|
1
|
+
.main-TdgjvV{position:relative}.text-YtgeQ_{white-space:break-spaces;word-break:break-word}.editor-ore7X3{box-sizing:border-box;font-family:var(--me-font-family,monospace);font-size:inherit;line-height:inherit;padding:var(--me-padding,.1rem);text-align:left;overscroll-behavior:none;border:none;width:100%;height:100%;margin:0;overflow:scroll}.textarea-ugnhty{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
package/rslib.config.ts
CHANGED
package/src/index.module.css
CHANGED
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
.editor {
|
|
11
11
|
border: none;
|
|
12
12
|
box-sizing: border-box;
|
|
13
|
-
font-family: var(--font-family, monospace);
|
|
13
|
+
font-family: var(--me-font-family, monospace);
|
|
14
14
|
font-size: inherit;
|
|
15
15
|
line-height: inherit;
|
|
16
16
|
margin: 0;
|
|
17
|
-
padding: var(--padding, 0.1rem);
|
|
17
|
+
padding: var(--me-padding, 0.1rem);
|
|
18
18
|
text-align: left;
|
|
19
19
|
width: 100%;
|
|
20
20
|
height: 100%;
|
|
@@ -26,9 +26,8 @@
|
|
|
26
26
|
composes: editor;
|
|
27
27
|
composes: text;
|
|
28
28
|
|
|
29
|
-
/* TODO Support auto height. */
|
|
30
|
-
field-sizing: content;
|
|
31
29
|
resize: none;
|
|
30
|
+
/* TODO field-sizing: content; */
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
.pre {
|
package/src/index.test.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,14 +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}`;
|
|
11
18
|
textarea.setAttribute("spellcheck", "false");
|
|
19
|
+
textarea.value = value ?? "";
|
|
12
20
|
|
|
13
21
|
const pre = container.appendChild(document.createElement("pre"));
|
|
14
22
|
pre.className += ` ${styles.pre}`;
|
|
@@ -30,8 +38,15 @@ export const initialize = (
|
|
|
30
38
|
scroll();
|
|
31
39
|
});
|
|
32
40
|
|
|
33
|
-
textarea.addEventListener("input",
|
|
41
|
+
textarea.addEventListener("input", (event) => {
|
|
42
|
+
update();
|
|
43
|
+
onInput?.(event);
|
|
44
|
+
});
|
|
34
45
|
textarea.addEventListener("scroll", scroll);
|
|
35
46
|
|
|
47
|
+
if (onChange) {
|
|
48
|
+
textarea.addEventListener("change", onChange);
|
|
49
|
+
}
|
|
50
|
+
|
|
36
51
|
update();
|
|
37
52
|
};
|