Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .eslintrc.cjs

This file was deleted.

7 changes: 7 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
singleQuote: true,
jsxSingleQuote: true,
trailingComma: 'none',
semi: false,
printWidth: 100
}
4 changes: 2 additions & 2 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default {
extends: ['@codingame/commitlint-config-codingame']
};
extends: ['@codingame/commitlint-config-codingame']
}
28 changes: 28 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import eslint from '@eslint/js'
import tsEslint from 'typescript-eslint'
import eslintPluginReact from 'eslint-plugin-react'
import eslintPluginReactHooks from 'eslint-plugin-react-hooks'
import globals from 'globals'

export default tsEslint.config(
eslint.configs.recommended,
tsEslint.configs.recommended,
eslintPluginReact.configs.flat.recommended,
eslintPluginReact.configs.flat?.['jsx-runtime'],
{
rules: { '@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }] },
languageOptions: {
globals: {
...globals.browser
}
}
},

// TODO: Simplify when https://github.com/facebook/react/issues/28313 is resolved
{
plugins: {
'react-hooks': eslintPluginReactHooks
},
rules: { ...eslintPluginReactHooks.configs.recommended.rules }
}
)
14,000 changes: 7,484 additions & 6,516 deletions package-lock.json

Large diffs are not rendered by default.

41 changes: 18 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"build": "npm run lint && npm run compile",
"compile": "tsc -p tsconfig.build.json",
"lint": "eslint --ext .ts,.tsx src/"
"lint": "eslint 'src/**/*.ts' && prettier --check '**/*.{js,ts}'"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -39,37 +39,32 @@
],
"types": "dist/index.d.ts",
"dependencies": {
"@codingame/monaco-editor-wrapper": "^9.0.1",
"@codingame/monaco-editor-wrapper": "^11.0.0",
"deep-equal": "^2.2.3",
"lodash.debounce": "^4.0.8",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@^8.0.3",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api@^13.1.3",
"react-dom": "^18.3.1",
"vscode": "npm:@codingame/monaco-vscode-api@^8.0.3"
"vscode": "npm:@codingame/monaco-vscode-extension-api@^13.1.3"
},
"devDependencies": {
"@codingame/commitlint-config-codingame": "^1.1.1",
"@codingame/eslint-config": "^1.1.10",
"@codingame/eslint-config-react": "^1.0.2",
"@codingame/semantic-release-config-github": "^1.0.0",
"@codingame/semantic-release-config-github": "^2.0.0",
"@codingame/tsconfig": "^1.1.1",
"@commitlint/cli": "^19.4.0",
"@commitlint/cli": "^19.7.1",
"@types/deep-equal": "^1.0.4",
"@types/lodash.debounce": "^4.0.9",
"@types/react": "18.3.4",
"@types/react-dom": "^18.3.0",
"@types/vscode": "^1.92.0",
"@typescript-eslint/eslint-plugin": "7.16.0",
"@typescript-eslint/parser": "7.16.0",
"conventional-changelog-conventionalcommits": "^7.0.2",
"eslint": "8.57.0",
"eslint-config-standard": "17.1.0",
"eslint-config-standard-jsx": "11.0.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-react": "7.34.3",
"eslint-plugin-react-hooks": "4.6.2",
"eslint-plugin-unused-imports": "3.2.0",
"typescript": "5.5.4"
"@types/react": "19.0.8",
"@types/react-dom": "^19.0.3",
"@types/vscode": "^1.96.0",
"@typescript-eslint/eslint-plugin": "8.23.0",
"@typescript-eslint/parser": "8.23.0",
"conventional-changelog-conventionalcommits": "^8.0.0",
"eslint": "9.19.0",
"eslint-plugin-react": "^7.37.4",
"eslint-plugin-react-hooks": "^5.1.0",
"prettier": "^3.4.2",
"typescript": "5.7.3",
"typescript-eslint": "^8.23.0"
},
"peerDependencies": {
"react": ">=16.0.0"
Expand Down
5 changes: 2 additions & 3 deletions src/MonacoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ function MonacoEditor ({
onEditorOpenRequest,
onDidSave = defaultOnDidSave
}: MonacoEditorProps, ref: ForwardedRef<monaco.editor.IStandaloneCodeEditor>): ReactElement {
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor>()
const modelRef = useRef<monaco.editor.ITextModel>()
const editorRef = useRef<monaco.editor.IStandaloneCodeEditor>(undefined)
const modelRef = useRef<monaco.editor.ITextModel>(undefined)
const [modelReady, setModelReady] = useState(false)
const preventTriggerChangeEventRef = useRef<boolean>(false)

Expand Down Expand Up @@ -193,7 +193,6 @@ function MonacoEditor ({
}
}
return undefined
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

// Create/Update model
Expand Down
25 changes: 15 additions & 10 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import deepEqual from 'deep-equal'
import { getConfiguration, onConfigurationChanged, monaco } from '@codingame/monaco-editor-wrapper'
import { StandaloneServices, IThemeService } from 'vscode/services'

function getCurrentThemeColor (color: string): string | undefined {
function getCurrentThemeColor(color: string): string | undefined {
const themeService = StandaloneServices.get(IThemeService)
return themeService.getColorTheme().getColor(color)?.toString()
}

export function useThemeColor (color: string): string | undefined {
export function useThemeColor(color: string): string | undefined {
const [colorValue, setColorValue] = useState(getCurrentThemeColor(color))
useEffect(() => {
const disposable = StandaloneServices.get(IThemeService).onDidColorThemeChange(() => {
Expand All @@ -25,7 +25,9 @@ export function useThemeColor (color: string): string | undefined {
return colorValue
}

export function useUserConfiguration (programmingLanguageId?: string): Partial<monaco.editor.IEditorOptions> {
export function useUserConfiguration(
programmingLanguageId?: string
): Partial<monaco.editor.IEditorOptions> {
const [userConfiguration, setUserConfiguration] = useState(() => getConfiguration()!)
useEffect(() => {
const updateOptions = () => {
Expand All @@ -39,33 +41,36 @@ export function useUserConfiguration (programmingLanguageId?: string): Partial<m
return userConfiguration
}

export function useLastValueRef<T> (value: T): MutableRefObject<T> {
export function useLastValueRef<T>(value: T): MutableRefObject<T> {
const ref = useRef<T>(value)
ref.current = value
return ref
}

export function useLastVersion<P extends unknown[], R> (func: (...args: P) => R): (...args: P) => R {
export function useLastVersion<P extends unknown[], R>(func: (...args: P) => R): (...args: P) => R {
const ref = useRef<(...args: P) => R>(func)
useEffect(() => {
ref.current = func
}, [func])
return useCallback((...args: P) => {
return ref.current(...args)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
}

export function usePrevious<T> (value: T): T | undefined {
const ref = useRef<T>()
export function usePrevious<T>(value: T): T | undefined {
const ref = useRef<T>(undefined)
useEffect(() => {
ref.current = value
}, [value])
return ref.current
}

export function useDeepMemo<T, D extends unknown[]> (memoFn: () => T, deps: D, isEqual: (a: D, b: D) => boolean = deepEqual): T {
const ref = useRef<{ deps: D, value: T }>()
export function useDeepMemo<T, D extends unknown[]>(
memoFn: () => T,
deps: D,
isEqual: (a: D, b: D) => boolean = deepEqual
): T {
const ref = useRef<{ deps: D; value: T }>(undefined)
if (ref.current == null || !isEqual(deps, ref.current.deps)) {
ref.current = { deps, value: memoFn() }
}
Expand Down
19 changes: 11 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { loadLanguage, monaco, updateKeybindings, updateUserConfiguration } from '@codingame/monaco-editor-wrapper'
import { IEditorOptions, IResolvedTextEditorModel } from '@codingame/monaco-vscode-editor-service-override'
import {
loadLanguage,
monaco,
updateKeybindings,
updateUserConfiguration
} from '@codingame/monaco-editor-wrapper'
import {
IEditorOptions,
IResolvedTextEditorModel
} from '@codingame/monaco-vscode-editor-service-override'
import type { IReference } from 'vscode/monaco'
import { useThemeColor, useUserConfiguration } from './hooks.js'
import MonacoEditor, { MonacoEditorProps } from './MonacoEditor.js'
Expand All @@ -13,9 +21,4 @@ export {
updateUserConfiguration,
loadLanguage
}
export type {
MonacoEditorProps,
IReference,
IEditorOptions,
IResolvedTextEditorModel
}
export type { MonacoEditorProps, IReference, IEditorOptions, IResolvedTextEditorModel }
2 changes: 1 addition & 1 deletion src/style.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function addStyle (styleString: string): void {
export function addStyle(styleString: string): void {
const style = document.createElement('style')
style.textContent = styleString
document.head.append(style)
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
},
"resolveJsonModule": true,
"sourceMap": true,
"target": "ES2022"
"target": "ES2022",
"skipLibCheck": true
},
"include": ["src"],
"exclude": [
Expand Down
Loading