@xh/hoist 79.0.0-SNAPSHOT.1765845531181 → 79.0.0-SNAPSHOT.1765846827962

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,8 +11,11 @@ import {
11
11
  foldGutter,
12
12
  foldKeymap,
13
13
  indentOnInput,
14
+ LanguageDescription,
15
+ LanguageSupport,
14
16
  syntaxHighlighting
15
17
  } from '@codemirror/language';
18
+ import {languages} from '@codemirror/language-data';
16
19
  import {linter, lintGutter} from '@codemirror/lint';
17
20
  import {highlightSelectionMatches, search} from '@codemirror/search';
18
21
  import {
@@ -49,14 +52,14 @@ import {action, bindable, makeObservable, observable} from '@xh/hoist/mobx';
49
52
  import {withDefault} from '@xh/hoist/utils/js';
50
53
  import {getLayoutProps} from '@xh/hoist/utils/react';
51
54
  import classNames from 'classnames';
52
- import {compact, isEmpty, isFunction, isObject} from 'lodash';
55
+ import {compact, find, includes, isEmpty, isFunction, isObject} from 'lodash';
53
56
  import {ReactElement} from 'react';
54
57
  import './CodeInput.scss';
55
58
  import {javascript} from '@codemirror/lang-javascript';
56
- // import {json} from '@codemirror/lang-json';
57
- // import {html} from '@codemirror/lang-html';
58
- // import {sql} from '@codemirror/lang-sql';
59
- // import {css} from '@codemirror/lang-css';
59
+ import {json} from '@codemirror/lang-json';
60
+ import {html} from '@codemirror/lang-html';
61
+ import {sql} from '@codemirror/lang-sql';
62
+ import {css} from '@codemirror/lang-css';
60
63
  export interface CodeInputProps extends HoistProps, HoistInputProps, LayoutProps {
61
64
  /** True to focus the control on render. */
62
65
  autoFocus?: boolean;
@@ -418,6 +421,7 @@ class CodeInputModel extends HoistInputModel {
418
421
  const {
419
422
  autoFocus,
420
423
  readonly,
424
+ language,
421
425
  highlightActiveLine: propsHighlightActiveLine,
422
426
  linter: propsLinter,
423
427
  lineNumbers: propsLineNumbers = true,
@@ -442,7 +446,6 @@ class CodeInputModel extends HoistInputModel {
442
446
  indentOnInput(),
443
447
  autocompletion(),
444
448
  history(),
445
- javascript(),
446
449
  // Linter
447
450
  propsLinter
448
451
  ? linter(async view => {
@@ -475,14 +478,14 @@ class CodeInputModel extends HoistInputModel {
475
478
  if (propsHighlightActiveLine)
476
479
  extensions.push(highlightActiveLine(), highlightActiveLineGutter());
477
480
  if (autoFocus) extensions.push(this.autofocusExtension);
478
- // if (language) {
479
- // const langExt = this.getLanguageExtension(language);
480
- // if (langExt) {
481
- // extensions.push(langExt);
482
- // } else {
483
- // console.warn('Failed to load language:', language);
484
- // }
485
- // }
481
+ if (language) {
482
+ const langExt = this.getLanguageExtensionAsync(language);
483
+ if (langExt) {
484
+ extensions.push(await langExt);
485
+ } else {
486
+ console.warn('Failed to load language:', language);
487
+ }
488
+ }
486
489
  return extensions.filter(it => !isEmpty(it));
487
490
  }
488
491
 
@@ -491,29 +494,28 @@ class CodeInputModel extends HoistInputModel {
491
494
  return XH.darkTheme ? oneDark : lightTheme;
492
495
  }
493
496
 
494
- // private LANGUAGE_EXTENSIONS: Record<string, () => LanguageSupport> = {
495
- // js: javascript,
496
- // javascript: javascript,
497
- // html: html,
498
- // css: css,
499
- // json: json,
500
- // sql: sql
501
- // };
502
-
503
- // private getLanguageExtension(lang: string): LanguageSupport {
504
- // if (!lang) return null;
505
- // const extFactory = this.LANGUAGE_EXTENSIONS[lang.toLowerCase()];
506
- // if (!extFactory) {
507
- // console.warn(`Language not found: ${lang}`);
508
- // return null;
509
- // }
510
- // try {
511
- // return extFactory(); // returns a LanguageSupport instance
512
- // } catch (err) {
513
- // console.error(`Failed to load language: ${lang}`, err);
514
- // return null;
515
- // }
516
- // }
497
+ private LANGUAGE_EXTENSIONS: Record<string, () => LanguageSupport> = {
498
+ js: javascript,
499
+ javascript: javascript,
500
+ html: html,
501
+ css: css,
502
+ json: json,
503
+ sql: sql
504
+ };
505
+
506
+ private async getLanguageExtensionAsync(lang: string): Promise<LanguageSupport> {
507
+ try {
508
+ const langDesc: LanguageDescription | undefined = find(
509
+ languages,
510
+ it => includes(it.alias, lang) || it.name.toLowerCase() === lang.toLowerCase()
511
+ );
512
+ if (!langDesc) return null;
513
+ return await langDesc.load();
514
+ } catch (err) {
515
+ console.error(`Failed to load language: ${lang}`, err);
516
+ return null;
517
+ }
518
+ }
517
519
 
518
520
  private autofocusExtension = ViewPlugin.fromClass(
519
521
  class {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "79.0.0-SNAPSHOT.1765845531181",
3
+ "version": "79.0.0-SNAPSHOT.1765846827962",
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,12 +34,8 @@
34
34
  "@blueprintjs/datetime": "^5.3.7",
35
35
  "@blueprintjs/datetime2": "^2.3.7",
36
36
  "@codemirror/commands": "6.10.0",
37
- "@codemirror/lang-css": "6.3.1",
38
- "@codemirror/lang-html": "6.4.11",
39
- "@codemirror/lang-javascript": "6.2.4",
40
- "@codemirror/lang-json": "6.0.2",
41
- "@codemirror/lang-sql": "6.10.0",
42
37
  "@codemirror/language": "6.11.3",
38
+ "@codemirror/language-data": "6.5.2",
43
39
  "@codemirror/lint": "6.9.2",
44
40
  "@codemirror/search": "6.5.11",
45
41
  "@codemirror/view": "6.39.4",