@xh/hoist 79.0.0-SNAPSHOT.1765831120891 → 79.0.0-SNAPSHOT.1765833120742

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.
@@ -11,6 +11,7 @@ import {
11
11
  foldGutter,
12
12
  foldKeymap,
13
13
  indentOnInput,
14
+ LanguageSupport,
14
15
  syntaxHighlighting
15
16
  } from '@codemirror/language';
16
17
  import {linter, lintGutter} from '@codemirror/lint';
@@ -53,9 +54,10 @@ import {compact, isEmpty, isFunction, isObject} from 'lodash';
53
54
  import {ReactElement} from 'react';
54
55
  import './CodeInput.scss';
55
56
  import {javascript} from '@codemirror/lang-javascript';
56
-
57
- // import {languages} from '@codemirror/language-data';
58
-
57
+ import {json} from '@codemirror/lang-json';
58
+ import {html} from '@codemirror/lang-html';
59
+ import {sql} from '@codemirror/lang-sql';
60
+ import {css} from '@codemirror/lang-css';
59
61
  export interface CodeInputProps extends HoistProps, HoistInputProps, LayoutProps {
60
62
  /** True to focus the control on render. */
61
63
  autoFocus?: boolean;
@@ -474,7 +476,7 @@ class CodeInputModel extends HoistInputModel {
474
476
  if (propsHighlightActiveLine)
475
477
  extensions.push(highlightActiveLine(), highlightActiveLineGutter());
476
478
  if (autoFocus) extensions.push(this.autofocusExtension);
477
- if (language) extensions.push(javascript());
479
+ if (language) extensions.push(await this.getLanguageExtensionAsync(language));
478
480
 
479
481
  return extensions.filter(it => !isEmpty(it));
480
482
  }
@@ -484,19 +486,31 @@ class CodeInputModel extends HoistInputModel {
484
486
  return XH.darkTheme ? oneDark : lightTheme;
485
487
  }
486
488
 
487
- // private async getLanguageExtensionAsync(lang: string): Promise<LanguageSupport> {
488
- // try {
489
- // const langDesc: LanguageDescription | undefined = find(
490
- // languages,
491
- // it => includes(it.alias, lang) || it.name.toLowerCase() === lang.toLowerCase()
492
- // );
493
- // if (!langDesc) return null;
494
- // return await langDesc.load();
495
- // } catch (err) {
496
- // console.error(`Failed to load language: ${lang}`, err);
497
- // return null;
498
- // }
499
- // }
489
+ private LANGUAGE_EXTENSIONS: Record<string, () => LanguageSupport> = {
490
+ js: javascript,
491
+ javascript: javascript,
492
+ html: html,
493
+ css: css,
494
+ json: json,
495
+ sql: sql
496
+ };
497
+
498
+ private async getLanguageExtensionAsync(lang: string): Promise<LanguageSupport> {
499
+ if (!lang) return null;
500
+ const extFactory = this.LANGUAGE_EXTENSIONS[lang.toLowerCase()];
501
+ if (!extFactory) {
502
+ console.warn(`Language not found: ${lang}`);
503
+ return null;
504
+ }
505
+ try {
506
+ // DEBUG
507
+ console.log(extFactory());
508
+ return extFactory(); // returns a LanguageSupport instance
509
+ } catch (err) {
510
+ console.error(`Failed to load language: ${lang}`, err);
511
+ return null;
512
+ }
513
+ }
500
514
 
501
515
  private autofocusExtension = ViewPlugin.fromClass(
502
516
  class {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "79.0.0-SNAPSHOT.1765831120891",
3
+ "version": "79.0.0-SNAPSHOT.1765833120742",
4
4
  "description": "Hoist add-on for building and deploying React Applications.",
5
5
  "repository": "github:xh/hoist-react",
6
6
  "homepage": "https://xh.io",
@@ -34,7 +34,11 @@
34
34
  "@blueprintjs/datetime": "^5.3.7",
35
35
  "@blueprintjs/datetime2": "^2.3.7",
36
36
  "@codemirror/commands": "6.9.0",
37
+ "@codemirror/lang-css": "^6.3.1",
38
+ "@codemirror/lang-html": "^6.4.11",
37
39
  "@codemirror/lang-javascript": "^6.2.4",
40
+ "@codemirror/lang-json": "^6.0.2",
41
+ "@codemirror/lang-sql": "^6.10.0",
38
42
  "@codemirror/language": "6.11.3",
39
43
  "@codemirror/lint": "6.9.0",
40
44
  "@codemirror/search": "6.5.11",