@monza-editor/astro 0.5.14 → 0.6.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/package.json +9 -9
- package/src/Editor.astro +33 -33
- package/CHANGELOG.md +0 -13
package/package.json
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monza-editor/astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Astro component of Monza editor",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "https://github.com/raviqqe/monza-editor"
|
|
8
9
|
},
|
|
9
|
-
"license": "MIT",
|
|
10
|
-
"publishConfig": {
|
|
11
|
-
"provenance": true
|
|
12
|
-
},
|
|
13
10
|
"type": "module",
|
|
14
11
|
"exports": {
|
|
15
12
|
".": {
|
|
@@ -17,13 +14,16 @@
|
|
|
17
14
|
"default": "./src/index.js"
|
|
18
15
|
}
|
|
19
16
|
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"provenance": true
|
|
19
|
+
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"monza-editor": "^0.
|
|
22
|
-
"picolight": "^0.
|
|
21
|
+
"monza-editor": "^0.6.1",
|
|
22
|
+
"picolight": "^0.3.4"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@raviqqe/tsconfig": "^3.0.
|
|
26
|
-
"astro": "^7.
|
|
25
|
+
"@raviqqe/tsconfig": "^3.0.5",
|
|
26
|
+
"astro": "^7.4.7",
|
|
27
27
|
"typescript": "^6.0.3"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
package/src/Editor.astro
CHANGED
|
@@ -16,53 +16,53 @@ const { id, language, theme, darkTheme, value, ...props } = Astro.props;
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
18
|
<monza-editor
|
|
19
|
+
data-dark-theme={JSON.stringify(darkTheme)}
|
|
19
20
|
data-language={serializeLanguage(language)}
|
|
20
21
|
data-theme={JSON.stringify(theme)}
|
|
21
|
-
data-dark-theme={JSON.stringify(darkTheme)}
|
|
22
22
|
>
|
|
23
|
-
<div class={`${styles.
|
|
23
|
+
<div class={`${styles.root} ${props.class}`} id={id}>
|
|
24
24
|
<textarea class={styles.textarea}>{value}</textarea>
|
|
25
25
|
<pre class={styles.pre}><code class={styles.code} /></pre>
|
|
26
26
|
</div>
|
|
27
27
|
</monza-editor>
|
|
28
28
|
<script>
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
import { initialize } from "monza-editor";
|
|
30
|
+
import { deserializeLanguage, highlight } from "picolight";
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
class Editor extends HTMLElement {
|
|
33
|
+
async connectedCallback(): Promise<void> {
|
|
34
|
+
const { language, theme, darkTheme } = this.dataset;
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
if (!language || !theme) {
|
|
37
|
+
throw new Error("Editor props missing");
|
|
38
|
+
}
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
const div = this.querySelector("div");
|
|
41
|
+
const textarea = this.querySelector("textarea");
|
|
42
|
+
const pre = this.querySelector("pre");
|
|
43
|
+
const code = this.querySelector("code");
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
if (!div || !textarea || !pre || !code) {
|
|
46
|
+
throw new Error("Editor elements missing");
|
|
47
|
+
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
50
|
+
let dark = mediaQuery.matches;
|
|
51
|
+
mediaQuery.addEventListener("change", (event) => (dark = event.matches));
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
53
|
+
initialize({
|
|
54
|
+
code,
|
|
55
|
+
highlight: (text) =>
|
|
56
|
+
highlight(
|
|
57
|
+
text,
|
|
58
|
+
deserializeLanguage(language),
|
|
59
|
+
JSON.parse((dark && darkTheme) || theme),
|
|
60
|
+
).outerHTML,
|
|
61
|
+
pre,
|
|
62
|
+
textarea,
|
|
63
|
+
});
|
|
65
64
|
}
|
|
65
|
+
}
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
customElements.define("monza-editor", Editor);
|
|
68
68
|
</script>
|