@haklex/cm-editor 0.0.82 → 0.0.83

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.
Files changed (2) hide show
  1. package/dist/index.mjs +67 -50
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,65 +1,82 @@
1
- import { LanguageDescription, defaultHighlightStyle, syntaxHighlighting } from "@codemirror/language";
1
+ import { LanguageDescription, syntaxHighlighting, defaultHighlightStyle } from "@codemirror/language";
2
2
  import { languages } from "@codemirror/language-data";
3
3
  import { oneDark } from "@codemirror/theme-one-dark";
4
4
  import { EditorView } from "@codemirror/view";
5
- //#region src/language.ts
6
- var languageAliases = {
7
- c: ["c"],
8
- cpp: ["c++", "cpp"],
9
- cs: ["c#", "csharp"],
10
- js: ["javascript"],
11
- jsx: ["javascript jsx", "jsx"],
12
- md: ["markdown"],
13
- py: ["python"],
14
- sh: ["shell", "bash"],
15
- ts: ["typescript"],
16
- tsx: ["typescript jsx", "tsx"],
17
- yml: ["yaml"],
18
- zsh: ["shell", "bash"]
5
+ const languageAliases = {
6
+ c: ["c"],
7
+ cpp: ["c++", "cpp"],
8
+ cs: ["c#", "csharp"],
9
+ js: ["javascript"],
10
+ jsx: ["javascript jsx", "jsx"],
11
+ md: ["markdown"],
12
+ py: ["python"],
13
+ sh: ["shell", "bash"],
14
+ ts: ["typescript"],
15
+ tsx: ["typescript jsx", "tsx"],
16
+ yml: ["yaml"],
17
+ zsh: ["shell", "bash"]
19
18
  };
20
19
  function getLanguageCandidates(language) {
21
- const normalized = language === "plaintext" ? "text" : language;
22
- return [normalized, ...languageAliases[normalized] ?? []];
20
+ const normalized = language === "plaintext" ? "text" : language;
21
+ return [normalized, ...languageAliases[normalized] ?? []];
23
22
  }
24
23
  async function loadLanguageExtension(language) {
25
- if (language === "text") return [];
26
- const candidates = getLanguageCandidates(language);
27
- for (const candidate of candidates) {
28
- const matched = LanguageDescription.matchLanguageName(languages, candidate, true);
29
- if (!matched) continue;
30
- try {
31
- return await matched.load();
32
- } catch {}
33
- }
34
- return [];
24
+ if (language === "text") return [];
25
+ const candidates = getLanguageCandidates(language);
26
+ for (const candidate of candidates) {
27
+ const matched = LanguageDescription.matchLanguageName(
28
+ languages,
29
+ candidate,
30
+ true
31
+ );
32
+ if (!matched) continue;
33
+ try {
34
+ return await matched.load();
35
+ } catch {
36
+ }
37
+ }
38
+ return [];
35
39
  }
36
- //#endregion
37
- //#region src/selection.ts
38
40
  function isOnFirstLine(view) {
39
- const { main } = view.state.selection;
40
- if (!main.empty) return false;
41
- return view.state.doc.lineAt(main.head).number === 1;
41
+ const { main } = view.state.selection;
42
+ if (!main.empty) return false;
43
+ return view.state.doc.lineAt(main.head).number === 1;
42
44
  }
43
45
  function isOnLastLine(view) {
44
- const { main } = view.state.selection;
45
- if (!main.empty) return false;
46
- return view.state.doc.lineAt(main.head).number === view.state.doc.lines;
46
+ const { main } = view.state.selection;
47
+ if (!main.empty) return false;
48
+ return view.state.doc.lineAt(main.head).number === view.state.doc.lines;
47
49
  }
48
- //#endregion
49
- //#region src/theme.ts
50
- var baseTheme = EditorView.theme({
51
- "&": { backgroundColor: "transparent" },
52
- "&.cm-editor": { outline: "none" },
53
- "&.cm-editor.cm-focused": { outline: "none" },
54
- ".cm-scroller": {
55
- overflow: "auto",
56
- fontFamily: "inherit"
57
- },
58
- ".cm-content": { minHeight: "1.5em" },
59
- ".cm-selectionBackground": { backgroundColor: "rgba(125, 125, 125, 0.26) !important" }
50
+ const baseTheme = EditorView.theme({
51
+ "&": {
52
+ backgroundColor: "transparent"
53
+ },
54
+ "&.cm-editor": {
55
+ outline: "none"
56
+ },
57
+ "&.cm-editor.cm-focused": {
58
+ outline: "none"
59
+ },
60
+ ".cm-scroller": {
61
+ overflow: "auto",
62
+ fontFamily: "inherit"
63
+ },
64
+ ".cm-content": {
65
+ minHeight: "1.5em"
66
+ },
67
+ ".cm-selectionBackground": {
68
+ backgroundColor: "rgba(125, 125, 125, 0.26) !important"
69
+ }
60
70
  });
61
71
  function getThemeExtensions(colorScheme) {
62
- return colorScheme === "dark" ? [oneDark, baseTheme] : [baseTheme, syntaxHighlighting(defaultHighlightStyle, { fallback: true })];
72
+ return colorScheme === "dark" ? [oneDark, baseTheme] : [baseTheme, syntaxHighlighting(defaultHighlightStyle, { fallback: true })];
63
73
  }
64
- //#endregion
65
- export { baseTheme, getLanguageCandidates, getThemeExtensions, isOnFirstLine, isOnLastLine, languageAliases, loadLanguageExtension };
74
+ export {
75
+ baseTheme,
76
+ getLanguageCandidates,
77
+ getThemeExtensions,
78
+ isOnFirstLine,
79
+ isOnLastLine,
80
+ languageAliases,
81
+ loadLanguageExtension
82
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/cm-editor",
3
- "version": "0.0.82",
3
+ "version": "0.0.83",
4
4
  "description": "Shared CodeMirror 6 editor utilities",
5
5
  "repository": {
6
6
  "type": "git",