-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to latest monaco-editor-wrapper and monaco-editor-react
- Extract/Add package langium-website-foundation
- Loading branch information
Showing
25 changed files
with
914 additions
and
687 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,4 @@ | ||
/public/ | ||
/hugo/resources/ | ||
/hugo/static/css/ | ||
hugo/static/libs | ||
hugo/static/showcase/ | ||
hugo/static/libs/ | ||
hugo/static/playground/ | ||
node_modules/ | ||
.DS_Store | ||
.hugo_build.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bundle/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"name": "langium-website-foundation", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"description": "Bundling complex sources for hugo", | ||
"author": "TypeFox", | ||
"license": "MIT", | ||
"private": true, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.js", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"./bundle": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./bundle/monaco-editor-wrapper-bundle/index.js" | ||
} | ||
}, | ||
"typesVersions": { | ||
"*": { | ||
".": [ | ||
"dist/index" | ||
], | ||
"bundle": [ | ||
"dist/index" | ||
] | ||
} | ||
}, | ||
"files": [ | ||
"dist", | ||
"bundle", | ||
"src", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"scripts": { | ||
"clean": "shx rm -rf ./bundle ./dist", | ||
"compile": "tsc", | ||
"build:bundle": "vite --config vite.bundle.ts build", | ||
"build": "npm run clean && npm run compile && npm run build:bundle" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "~18.2.28", | ||
"@types/react-dom": "~18.2.13", | ||
"@types/vscode": "~1.83.0", | ||
"typescript": "~5.2.2", | ||
"vite": "~4.4.11" | ||
}, | ||
"dependencies": { | ||
"@codingame/monaco-vscode-keybindings-service-override": "~1.83.2", | ||
"@typefox/monaco-editor-react": "2.3.0", | ||
"monaco-editor": "~0.44.0", | ||
"monaco-editor-workers": "~0.44.0", | ||
"monaco-editor-wrapper": "~3.3.0", | ||
"monaco-languageclient": "~6.6.0", | ||
"react": "~18.2.0", | ||
"react-dom": "~18.2.0", | ||
"vscode": "npm:@codingame/monaco-vscode-api@>=1.83.2 <1.84.0", | ||
"vscode-languageserver": "~8.0.2" | ||
}, | ||
"volta": { | ||
"node": "18.18.1", | ||
"npm": "9.9.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as monaco from "monaco-editor"; | ||
import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override'; | ||
import type { MonacoEditorProps } from "@typefox/monaco-editor-react"; | ||
import { MonacoEditorReactComp } from "@typefox/monaco-editor-react"; | ||
import { addMonacoStyles } from 'monaco-editor-wrapper/styles'; | ||
|
||
export * from "monaco-editor-wrapper"; | ||
export type * from "monaco-editor-wrapper"; | ||
export * from "./monaco-editor-wrapper-utils.js"; | ||
|
||
export { | ||
monaco, | ||
MonacoEditorProps, | ||
MonacoEditorReactComp, | ||
addMonacoStyles, | ||
getKeybindingsServiceOverride | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
import { languages } from "monaco-editor"; | ||
import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override'; | ||
import { EditorAppConfigClassic, EditorAppConfigExtended, LanguageClientConfig, UserConfig } from "monaco-editor-wrapper"; | ||
|
||
export type WorkerUrl = string; | ||
|
||
/** | ||
* Generalized configuration used with 'getMonacoEditorReactConfig' to generate a working configuration for monaco-editor-react | ||
*/ | ||
export interface MonacoReactConfig { | ||
code: string, | ||
languageId: string, | ||
worker: WorkerUrl | Worker, | ||
readonly?: boolean // whether to make the editor readonly or not (by default is false) | ||
} | ||
|
||
/** | ||
* Extended config, specifically for textmate usage | ||
*/ | ||
export interface MonacoExtendedReactConfig extends MonacoReactConfig { | ||
textmateGrammar: any; | ||
} | ||
|
||
/** | ||
* Editor config, specifically for monarch grammar usage | ||
*/ | ||
export interface MonacoEditorReactConfig extends MonacoReactConfig { | ||
monarchGrammar?: languages.IMonarchLanguage; | ||
} | ||
|
||
/** | ||
* Helper to identify a Extended config, for use with TextMate | ||
*/ | ||
function isMonacoExtendedReactConfig(config: unknown): config is MonacoExtendedReactConfig { | ||
return (config as MonacoExtendedReactConfig).textmateGrammar !== undefined; | ||
} | ||
|
||
|
||
/** | ||
* Default language configuration, common to most Langium DSLs | ||
*/ | ||
export const defaultLanguageConfig = { | ||
"comments": { | ||
"lineComment": "//", | ||
"blockComment": ["/*", "*/"] | ||
}, | ||
"brackets": [ | ||
["{", "}"], | ||
["[", "]"], | ||
["(", ")"] | ||
], | ||
"autoClosingPairs": [ | ||
["{", "}"], | ||
["[", "]"], | ||
["(", ")"], | ||
["\"", "\""], | ||
["'", "'"] | ||
], | ||
"surroundingPairs": [ | ||
["{", "}"], | ||
["[", "]"], | ||
["(", ")"], | ||
["\"", "\""], | ||
["'", "'"] | ||
] | ||
}; | ||
|
||
/** | ||
* Generates a UserConfig for a given Langium example, which is then passed to the monaco-editor-react component | ||
* | ||
* @param config A Extended or classic editor config to generate a UserConfig from | ||
* @returns A completed UserConfig | ||
*/ | ||
export function createUserConfig(config: MonacoExtendedReactConfig | MonacoEditorReactConfig): UserConfig { | ||
// setup urls for config & grammar | ||
const id = config.languageId; | ||
|
||
// check whether to use extended config (Textmate) or the classic editor config (Monarch) | ||
let editorAppConfig: EditorAppConfigClassic | EditorAppConfigExtended; | ||
const useExtendedConfig = isMonacoExtendedReactConfig(config); | ||
if (useExtendedConfig) { | ||
// setup extension contents | ||
const languageConfigUrl = `/${id}-configuration.json`; | ||
const languageGrammarUrl = `/${id}-grammar.json`; | ||
const extensionContents = new Map<string, string>(); | ||
extensionContents.set(languageConfigUrl, JSON.stringify(defaultLanguageConfig)); | ||
extensionContents.set(languageGrammarUrl, JSON.stringify(config.textmateGrammar)); | ||
|
||
editorAppConfig = { | ||
$type: 'extended', | ||
languageId: id, | ||
code: config.code, | ||
useDiffEditor: false, | ||
extensions: [{ | ||
config: { | ||
name: id, | ||
publisher: 'TypeFox', | ||
version: '1.0.0', | ||
engines: { | ||
vscode: '*' | ||
}, | ||
contributes: { | ||
languages: [{ | ||
id: id, | ||
extensions: [ `.${id}` ], | ||
configuration: languageConfigUrl | ||
}], | ||
grammars: [{ | ||
language: id, | ||
scopeName: `source.${id}`, | ||
path: languageGrammarUrl | ||
}] | ||
} | ||
}, | ||
filesOrContents: extensionContents, | ||
}], | ||
userConfiguration: { | ||
json: JSON.stringify({ | ||
'workbench.colorTheme': 'Default Dark Modern', | ||
'editor.semanticHighlighting.enabled': true, | ||
'editor.lightbulb.enabled': true, | ||
'editor.guides.bracketPairsHorizontal': 'active' | ||
}) | ||
} | ||
}; | ||
} else { | ||
editorAppConfig = { | ||
$type: 'classic', | ||
languageId: id, | ||
code: config.code, | ||
useDiffEditor: false, | ||
languageExtensionConfig: { id }, | ||
languageDef: config.monarchGrammar, | ||
editorOptions: { | ||
'semanticHighlighting.enabled': true, | ||
readOnly: config.readonly, | ||
theme: 'vs-dark' | ||
} | ||
}; | ||
} | ||
|
||
let languageClientConfig: LanguageClientConfig; | ||
if (typeof config.worker === 'string') { | ||
languageClientConfig = { | ||
options: { | ||
$type: 'WorkerConfig', | ||
url: new URL(config.worker, window.location.href), | ||
type: 'module', | ||
name: `${id}-language-server-worker`, | ||
} | ||
}; | ||
} else { | ||
languageClientConfig = { | ||
options: { | ||
$type: 'WorkerDirect', | ||
worker: config.worker | ||
} | ||
}; | ||
} | ||
|
||
// generate user config for langium based language | ||
const userConfig: UserConfig = { | ||
wrapperConfig: { | ||
serviceConfig: { | ||
// only use keyboard service in addition to the default services from monaco-editor-wrapper | ||
userServices: { | ||
...getKeybindingsServiceOverride() | ||
}, | ||
debugLogging: true | ||
}, | ||
editorAppConfig | ||
}, | ||
languageClientConfig | ||
} | ||
return userConfig; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"noImplicitAny": true, | ||
"target": "ES2022", | ||
"module": "Node16", | ||
"moduleResolution": "Node16", | ||
"rootDir": "src", | ||
"outDir": "dist", | ||
"declaration": true, | ||
"declarationDir": "dist" | ||
}, | ||
"include": [ | ||
"src/**/*.ts", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
resources/ | ||
static/css/ | ||
static/showcase/ | ||
static/libs/ | ||
static/playground/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.