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 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{field-sizing:content;resize:none}.pre-bJTdjq{pointer-events:none;scrollbar-width:0;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(--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
- export declare const initialize: (container: Element, highlight: (text: string) => string) => void;
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,GACrB,WAAW,OAAO,EAClB,WAAW,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,KAClC,IA+BF,CAAC"}
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 l=e.appendChild(document.createElement("textarea"));l.className+=" textarea-ugnhty editor-ore7X3 text-YtgeQ_",l.setAttribute("spellcheck","false");let a=e.appendChild(document.createElement("pre"));a.className+=" pre-bJTdjq editor-ore7X3";let n=a.appendChild(document.createElement("code"));n.className+=" code-p0LDSQ text-YtgeQ_";let r=()=>{a.scrollTop=l.scrollTop,a.scrollLeft=l.scrollLeft},d=()=>window.requestAnimationFrame(()=>{let e=l.value;n.innerHTML=t("\n"===e.at(-1)?`${e} `:e),r()});l.addEventListener("input",d),l.addEventListener("scroll",r),d()};export{e as initialize};
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,6 +1,6 @@
1
1
  {
2
2
  "name": "monza-editor",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "The minimal textarea with syntax highlight",
5
5
  "repository": "https://github.com/raviqqe/monza-editor",
6
6
  "license": "MIT",
package/rslib.config.ts CHANGED
@@ -13,9 +13,4 @@ export default defineConfig({
13
13
  output: {
14
14
  target: "web",
15
15
  },
16
- source: {
17
- entry: {
18
- index: "./src/index.ts",
19
- },
20
- },
21
16
  });
@@ -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
@@ -4,5 +4,5 @@ import { initialize } from "./index.js";
4
4
  it("initializes an editor", () => {
5
5
  const editor = document.createElement("div");
6
6
 
7
- initialize(editor, (text) => text);
7
+ initialize(editor, { highlight: (text) => text });
8
8
  });
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: (text: string) => string,
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", update);
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
  };