Skip to content

Commit

Permalink
docs(Code): improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonzalo Uceda committed Oct 27, 2023
1 parent 20ad079 commit c601f85
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
MultipleEds,
Programatic,
Actions,
MultipleLangs,
Shortcuts,
CustomThemed,
} from './cases';
Expand Down Expand Up @@ -54,10 +53,3 @@ export const MultipleDiffEditors: DiffEditorStory = {
<MultipleEds {...props} />
),
};

export const MultipleLanguages: DiffEditorStory = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
render: ({ originalValue, modifiedValue, ...props }) => (
<MultipleLangs {...props} />
),
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import type * as monaco from 'monaco-editor-core';
import { DiffEditor, type DiffEditorProps } from '../../';
import { rawLanguage } from '../../../Editor/__stories__/languages/rawConfig';
import { dedalLanguage } from '../../../Editor/__stories__/languages/dedal';
import {
registerCompletionProvider,
registerStyleTokenizer,
} from '../../../Editor';
import { registerLanguage } from '../../../Editor';

type Monaco = typeof monaco;

Expand Down Expand Up @@ -36,18 +33,11 @@ export const CustomLang = ({
const monacoRef = React.useRef<Monaco>();

const registerLanguageProviders = (monaco) => {
// Register highlighting
registerStyleTokenizer(
monaco,
languages[langId].id,
languages[langId].lang,
);
// Register autocompletion
registerCompletionProvider(
monaco,
languages[langId].id,
languages[langId].completionProvider,
);
registerLanguage(monaco, languages[langId].id)
// register highlighting
.registerStyleTokenizer(languages[langId].lang)
// register autocompletion
.registerCompletionProvider(languages[langId].completionProvider);
};

const handleEditorDidMount = (
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './Actions';
export * from './CustomLang';
export * from './MultipleEds';
export * from './MultipleLangs';
export * from './Programatic';
export * from './Shortcuts';
export * from './CustomThemed';
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ export const registerStyleTokenizer = (
| monaco.languages.IMonarchLanguage
| monaco.Thenable<monaco.languages.IMonarchLanguage>,
): void => {
if (languageID == '') return;

if (monaco.languages.getEncodedLanguageId(languageID) == 0) {
monaco.languages.register({ id: languageID });
}

monaco.languages.onLanguage(languageID, () => {
monaco.languages.setMonarchTokensProvider(languageID, tokenizer);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
MultipleEds,
Programatic,
Actions,
MultipleLangs,
Shortcuts,
CustomThemed,
} from './cases';
Expand All @@ -27,8 +26,8 @@ const meta: Meta<typeof Editor> = {
export default meta;
type EditorStory = StoryObj<typeof Editor>;

export const MultipleCustomLanguages: EditorStory = {
render: MultipleLangs,
export const CustomLanguageWithValidation: EditorStory = {
render: CustomLang,
};

export const WithActions: EditorStory = {
Expand All @@ -51,7 +50,3 @@ export const MultipleEditors: EditorStory = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
render: ({ value, ...props }) => <MultipleEds {...props} />,
};

export const CustomLanguageWithValidation: EditorStory = {
render: CustomLang,
};
5 changes: 5 additions & 0 deletions packages/code/src/components/Editor/stories/Editor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export const CustomThemed = () => {
`}
/>

## Setting a custom language

The Editor supports custom languages. To use a custom language, the language and its configuration must be registered with the editor.


## Hooks

### useEditor
Expand Down
24 changes: 6 additions & 18 deletions packages/code/src/components/Editor/stories/cases/CustomLang.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import * as React from 'react';
import type * as monaco from 'monaco-editor-core';

import {
Editor,
EditorProps,
registerStyleTokenizer,
registerCompletionProvider,
} from '../../';
import { Editor, EditorProps, registerLanguage } from '../../';
import { rawLanguage } from '../../__stories__/languages/rawConfig';
import { dedalLanguage } from '../../__stories__/languages/dedal';

Expand Down Expand Up @@ -37,18 +32,11 @@ export const CustomLang = ({
const monacoRef = React.useRef<Monaco>();

const registerLanguageProviders = (monaco) => {
// Register highlighting
registerStyleTokenizer(
monaco,
languages[langId].id,
languages[langId].lang,
);
// Register autocompletion
registerCompletionProvider(
monaco,
languages[langId].id,
languages[langId].completionProvider,
);
registerLanguage(monaco, languages[langId].id)
// register highlighting
.registerStyleTokenizer(languages[langId].lang)
// register autocompletion
.registerCompletionProvider(languages[langId].completionProvider);
};

const handleEditorDidMount = (
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion packages/code/src/components/Editor/stories/cases/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './Actions';
export * from './CustomLang';
export * from './MultipleEds';
export * from './MultipleLangs';
export * from './Programatic';
export * from './Shortcuts';
export * from './Diff';
Expand Down

0 comments on commit c601f85

Please sign in to comment.