@sanity/code-input 4.1.1 → 4.1.3
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.
- package/LICENSE +1 -1
- package/README.md +1 -0
- package/lib/_chunks/{CodeMirrorProxy-a4266d26.js → CodeMirrorProxy-6jTWWQ83.js} +2 -2
- package/lib/_chunks/CodeMirrorProxy-6jTWWQ83.js.map +1 -0
- package/lib/_chunks/{CodeMirrorProxy-3018512e.js → CodeMirrorProxy-UbGy745B.cjs} +2 -2
- package/lib/_chunks/CodeMirrorProxy-UbGy745B.cjs.map +1 -0
- package/lib/_chunks/index-KYa8fGra.js +4672 -0
- package/lib/_chunks/index-KYa8fGra.js.map +1 -0
- package/lib/_chunks/index-cttyJsiZ.cjs +4686 -0
- package/lib/_chunks/index-cttyJsiZ.cjs.map +1 -0
- package/lib/index.cjs +11 -0
- package/lib/index.cjs.js +7 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.ts +3 -4
- package/lib/index.js +1 -10
- package/lib/index.js.map +1 -1
- package/package.json +58 -54
- package/src/CodeInput.tsx +3 -3
- package/src/LanguageField.tsx +2 -2
- package/src/LanguageInput.tsx +1 -1
- package/src/codemirror/CodeMirrorProxy.tsx +91 -92
- package/src/codemirror/defaultCodeModes.ts +4 -4
- package/src/codemirror/useLanguageMode.tsx +2 -2
- package/src/useFieldMember.ts +3 -3
- package/lib/_chunks/CodeMirrorProxy-3018512e.js.map +0 -1
- package/lib/_chunks/CodeMirrorProxy-a4266d26.js.map +0 -1
- package/lib/_chunks/index-160c0f7b.js +0 -563
- package/lib/_chunks/index-160c0f7b.js.map +0 -1
- package/lib/_chunks/index-a3bcac3a.js +0 -549
- package/lib/_chunks/index-a3bcac3a.js.map +0 -1
- package/lib/index.esm.js +0 -2
- package/lib/index.esm.js.map +0 -1
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var index = require('./_chunks/index-cttyJsiZ.cjs');
|
|
7
|
+
exports.PreviewCode = index.PreviewCode;
|
|
8
|
+
exports.codeInput = index.codeInput;
|
|
9
|
+
exports.codeSchema = index.codeSchema;
|
|
10
|
+
exports.codeTypeName = index.codeTypeName;
|
|
11
|
+
//# sourceMappingURL=index.cjs.map
|
package/lib/index.cjs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
|
|
3
1
|
import {Extension} from '@codemirror/state'
|
|
2
|
+
import {JSX as JSX_2} from 'react/jsx-runtime'
|
|
4
3
|
import {ObjectDefinition} from 'sanity'
|
|
5
4
|
import {ObjectInputProps} from 'sanity'
|
|
6
5
|
import {ObjectSchemaType} from 'sanity'
|
|
@@ -18,7 +17,7 @@ export declare interface CodeDefinition
|
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
/** @public */
|
|
21
|
-
export declare function CodeInput(props: CodeInputProps):
|
|
20
|
+
export declare function CodeInput(props: CodeInputProps): JSX_2.Element
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
23
|
* @public
|
|
@@ -104,7 +103,7 @@ declare type ModeLoader = () => Promise<Extension | undefined> | Extension | und
|
|
|
104
103
|
/**
|
|
105
104
|
* @public
|
|
106
105
|
*/
|
|
107
|
-
export declare function PreviewCode(props: PreviewCodeProps):
|
|
106
|
+
export declare function PreviewCode(props: PreviewCodeProps): JSX_2.Element
|
|
108
107
|
|
|
109
108
|
/**
|
|
110
109
|
* @public
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var index = require('./_chunks/index-160c0f7b.js');
|
|
7
|
-
exports.PreviewCode = index.PreviewCode;
|
|
8
|
-
exports.codeInput = index.codeInput;
|
|
9
|
-
exports.codeSchema = index.codeSchema;
|
|
10
|
-
exports.codeTypeName = index.codeTypeName;
|
|
1
|
+
export { PreviewCode, codeInput, codeSchema, codeTypeName } from './_chunks/index-KYa8fGra.js';
|
|
11
2
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/code-input",
|
|
3
|
-
"version": "4.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "4.1.3",
|
|
4
|
+
"description": "Sanity input component for code, powered by CodeMirror",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
7
7
|
"cms",
|
|
@@ -22,18 +22,22 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"author": "Sanity.io <hello@sanity.io>",
|
|
25
|
+
"type": "module",
|
|
25
26
|
"exports": {
|
|
26
27
|
".": {
|
|
27
28
|
"types": "./lib/index.d.ts",
|
|
28
29
|
"source": "./src/index.ts",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
30
|
+
"require": "./lib/index.cjs",
|
|
31
|
+
"node": {
|
|
32
|
+
"import": "./lib/index.cjs.js"
|
|
33
|
+
},
|
|
34
|
+
"import": "./lib/index.js",
|
|
35
|
+
"default": "./lib/index.js"
|
|
32
36
|
},
|
|
33
37
|
"./package.json": "./package.json"
|
|
34
38
|
},
|
|
35
|
-
"main": "./lib/index.
|
|
36
|
-
"module": "./lib/index.
|
|
39
|
+
"main": "./lib/index.cjs",
|
|
40
|
+
"module": "./lib/index.js",
|
|
37
41
|
"source": "./src/index.ts",
|
|
38
42
|
"types": "./lib/index.d.ts",
|
|
39
43
|
"files": [
|
|
@@ -57,76 +61,76 @@
|
|
|
57
61
|
"watch": "pkg-utils watch --strict"
|
|
58
62
|
},
|
|
59
63
|
"dependencies": {
|
|
60
|
-
"@codemirror/autocomplete": "^6.1
|
|
61
|
-
"@codemirror/commands": "^6.
|
|
62
|
-
"@codemirror/lang-html": "^6.4.
|
|
64
|
+
"@codemirror/autocomplete": "^6.11.1",
|
|
65
|
+
"@codemirror/commands": "^6.3.2",
|
|
66
|
+
"@codemirror/lang-html": "^6.4.7",
|
|
63
67
|
"@codemirror/lang-java": "^6.0.1",
|
|
64
|
-
"@codemirror/lang-javascript": "^6.1
|
|
68
|
+
"@codemirror/lang-javascript": "^6.2.1",
|
|
65
69
|
"@codemirror/lang-json": "^6.0.1",
|
|
66
|
-
"@codemirror/lang-markdown": "^6.
|
|
70
|
+
"@codemirror/lang-markdown": "^6.2.3",
|
|
67
71
|
"@codemirror/lang-php": "^6.0.1",
|
|
68
|
-
"@codemirror/lang-sql": "^6.
|
|
69
|
-
"@codemirror/language": "^6.
|
|
70
|
-
"@codemirror/legacy-modes": "^6.3.
|
|
71
|
-
"@codemirror/search": "^6.
|
|
72
|
-
"@codemirror/state": "^6.
|
|
73
|
-
"@codemirror/view": "^6.
|
|
72
|
+
"@codemirror/lang-sql": "^6.5.4",
|
|
73
|
+
"@codemirror/language": "^6.9.3",
|
|
74
|
+
"@codemirror/legacy-modes": "^6.3.3",
|
|
75
|
+
"@codemirror/search": "^6.5.5",
|
|
76
|
+
"@codemirror/state": "^6.3.3",
|
|
77
|
+
"@codemirror/view": "^6.22.3",
|
|
74
78
|
"@juggle/resize-observer": "^3.3.1",
|
|
75
|
-
"@lezer/highlight": "^1.
|
|
76
|
-
"@sanity/icons": "^2.0.0",
|
|
79
|
+
"@lezer/highlight": "^1.2.0",
|
|
77
80
|
"@sanity/incompatible-plugin": "^1.0.4",
|
|
78
81
|
"@sanity/ui": "^1.0.0",
|
|
79
|
-
"@uiw/codemirror-themes": "^4.
|
|
80
|
-
"@uiw/react-codemirror": "^4.
|
|
82
|
+
"@uiw/codemirror-themes": "^4.21.21",
|
|
83
|
+
"@uiw/react-codemirror": "^4.21.21"
|
|
81
84
|
},
|
|
82
85
|
"devDependencies": {
|
|
83
|
-
"@babel/core": "^7.
|
|
84
|
-
"@babel/preset-env": "^7.
|
|
85
|
-
"@babel/preset-react": "^7.
|
|
86
|
-
"@commitlint/cli": "^
|
|
87
|
-
"@commitlint/config-conventional": "^
|
|
88
|
-
"@sanity/icons": "^2.
|
|
89
|
-
"@sanity/pkg-utils": "^
|
|
90
|
-
"@sanity/plugin-kit": "^3.1.
|
|
91
|
-
"@sanity/semantic-release-preset": "^
|
|
86
|
+
"@babel/core": "^7.23.6",
|
|
87
|
+
"@babel/preset-env": "^7.23.6",
|
|
88
|
+
"@babel/preset-react": "^7.23.3",
|
|
89
|
+
"@commitlint/cli": "^18.4.3",
|
|
90
|
+
"@commitlint/config-conventional": "^18.4.3",
|
|
91
|
+
"@sanity/icons": "^2.8.0",
|
|
92
|
+
"@sanity/pkg-utils": "^3.3.5",
|
|
93
|
+
"@sanity/plugin-kit": "^3.1.10",
|
|
94
|
+
"@sanity/semantic-release-preset": "^4.1.6",
|
|
92
95
|
"@sanity/ui-workshop": "^1.2.0",
|
|
93
96
|
"@sanity/ui-workshop-plugin-sanity": "^1.0.0",
|
|
94
|
-
"@testing-library/jest-dom": "^
|
|
95
|
-
"@testing-library/react": "^
|
|
96
|
-
"@types/jest": "^29.
|
|
97
|
-
"@types/react": "^18.
|
|
98
|
-
"@types/styled-components": "^5.1.
|
|
99
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
100
|
-
"@typescript-eslint/parser": "^
|
|
101
|
-
"eslint": "^8.
|
|
102
|
-
"eslint-config-prettier": "^
|
|
103
|
-
"eslint-config-sanity": "^
|
|
104
|
-
"eslint-plugin-prettier": "^
|
|
105
|
-
"eslint-plugin-react": "^7.
|
|
97
|
+
"@testing-library/jest-dom": "^6.1.5",
|
|
98
|
+
"@testing-library/react": "^14.1.2",
|
|
99
|
+
"@types/jest": "^29.5.11",
|
|
100
|
+
"@types/react": "^18.2.45",
|
|
101
|
+
"@types/styled-components": "^5.1.34",
|
|
102
|
+
"@typescript-eslint/eslint-plugin": "^6.14.0",
|
|
103
|
+
"@typescript-eslint/parser": "^6.14.0",
|
|
104
|
+
"eslint": "^8.55.0",
|
|
105
|
+
"eslint-config-prettier": "^9.1.0",
|
|
106
|
+
"eslint-config-sanity": "^7.0.1",
|
|
107
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
108
|
+
"eslint-plugin-react": "^7.33.2",
|
|
106
109
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
107
110
|
"husky": "^8.0.1",
|
|
108
|
-
"jest": "^
|
|
109
|
-
"jest-environment-jsdom": "^
|
|
110
|
-
"lint-staged": "^
|
|
111
|
+
"jest": "^29.7.0",
|
|
112
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
113
|
+
"lint-staged": "^15.2.0",
|
|
111
114
|
"npm-run-all": "^4.1.5",
|
|
112
|
-
"prettier": "^
|
|
113
|
-
"prettier-plugin-packagejson": "^2.
|
|
115
|
+
"prettier": "^3.1.1",
|
|
116
|
+
"prettier-plugin-packagejson": "^2.4.7",
|
|
114
117
|
"react": "^18.2.0",
|
|
115
118
|
"react-dom": "^18.2.0",
|
|
116
119
|
"react-is": "^18.2.0",
|
|
117
|
-
"rimraf": "^
|
|
118
|
-
"sanity": "^3.
|
|
120
|
+
"rimraf": "^5.0.5",
|
|
121
|
+
"sanity": "^3.21.3",
|
|
119
122
|
"sanity-extra": "^1.0.0",
|
|
120
123
|
"sanity-testing-library": "^1.0.0",
|
|
121
|
-
"
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
+
"semantic-release": "^22.0.0",
|
|
125
|
+
"styled-components": "^6.1.1",
|
|
126
|
+
"ts-jest": "^29.1.1",
|
|
127
|
+
"typescript": "^5.3.3"
|
|
124
128
|
},
|
|
125
129
|
"peerDependencies": {
|
|
126
130
|
"react": "^18",
|
|
127
131
|
"react-dom": "^18",
|
|
128
132
|
"sanity": "^3",
|
|
129
|
-
"styled-components": "^5.2"
|
|
133
|
+
"styled-components": "^5.2 || ^6"
|
|
130
134
|
},
|
|
131
135
|
"engines": {
|
|
132
136
|
"node": ">=14"
|
package/src/CodeInput.tsx
CHANGED
|
@@ -77,7 +77,7 @@ export function CodeInput(props: CodeInputProps) {
|
|
|
77
77
|
|
|
78
78
|
const onHighlightChange = useCallback(
|
|
79
79
|
(lines: number[]) => onChange(set(lines, ['highlightedLines'])),
|
|
80
|
-
[onChange]
|
|
80
|
+
[onChange],
|
|
81
81
|
)
|
|
82
82
|
|
|
83
83
|
const handleCodeChange = useCallback(
|
|
@@ -90,7 +90,7 @@ export function CodeInput(props: CodeInputProps) {
|
|
|
90
90
|
code ? set(code, path) : unset(path),
|
|
91
91
|
])
|
|
92
92
|
},
|
|
93
|
-
[onChange, type]
|
|
93
|
+
[onChange, type],
|
|
94
94
|
)
|
|
95
95
|
const {languages, language, languageMode} = useLanguageMode(props.schemaType, props.value)
|
|
96
96
|
|
|
@@ -132,7 +132,7 @@ export function CodeInput(props: CodeInputProps) {
|
|
|
132
132
|
elementProps.onBlur,
|
|
133
133
|
readOnly,
|
|
134
134
|
value,
|
|
135
|
-
]
|
|
135
|
+
],
|
|
136
136
|
)
|
|
137
137
|
|
|
138
138
|
return (
|
package/src/LanguageField.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import {CodeInputLanguage} from './types'
|
|
|
4
4
|
import {LanguageInput} from './LanguageInput'
|
|
5
5
|
|
|
6
6
|
export function LanguageField(
|
|
7
|
-
props: MemberFieldProps & {member: FieldMember; language: string; languages: CodeInputLanguage[]}
|
|
7
|
+
props: MemberFieldProps & {member: FieldMember; language: string; languages: CodeInputLanguage[]},
|
|
8
8
|
) {
|
|
9
9
|
const {member, languages, language, renderItem, renderField, renderPreview} = props
|
|
10
10
|
|
|
@@ -18,7 +18,7 @@ export function LanguageField(
|
|
|
18
18
|
/>
|
|
19
19
|
)
|
|
20
20
|
},
|
|
21
|
-
[languages, language]
|
|
21
|
+
[languages, language],
|
|
22
22
|
)
|
|
23
23
|
|
|
24
24
|
return (
|
package/src/LanguageInput.tsx
CHANGED
|
@@ -25,98 +25,97 @@ export interface CodeMirrorProps extends ReactCodeMirrorProps {
|
|
|
25
25
|
*
|
|
26
26
|
* It is also responsible for integrating any CodeMirror extensions.
|
|
27
27
|
*/
|
|
28
|
-
const CodeMirrorProxy = forwardRef<ReactCodeMirrorRef, CodeMirrorProps>(
|
|
29
|
-
props,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
28
|
+
const CodeMirrorProxy = forwardRef<ReactCodeMirrorRef, CodeMirrorProps>(
|
|
29
|
+
function CodeMirrorProxy(props, ref) {
|
|
30
|
+
const {
|
|
31
|
+
basicSetup: basicSetupProp,
|
|
32
|
+
highlightLines,
|
|
33
|
+
languageMode,
|
|
34
|
+
onHighlightChange,
|
|
35
|
+
readOnly,
|
|
36
|
+
value,
|
|
37
|
+
...codeMirrorProps
|
|
38
|
+
} = props
|
|
39
|
+
|
|
40
|
+
const themeCtx = useRootTheme()
|
|
41
|
+
const codeMirrorTheme = useCodeMirrorTheme()
|
|
42
|
+
const [editorView, setEditorView] = useState<EditorView | undefined>(undefined)
|
|
43
|
+
|
|
44
|
+
// Resolve extensions
|
|
45
|
+
const themeExtension = useThemeExtension()
|
|
46
|
+
const fontSizeExtension = useFontSizeExtension({fontSize: 1})
|
|
47
|
+
const languageExtension = useLanguageExtension(languageMode)
|
|
48
|
+
const highlightLineExtension = useMemo(
|
|
49
|
+
() =>
|
|
50
|
+
highlightLine({
|
|
51
|
+
onHighlightChange,
|
|
52
|
+
readOnly,
|
|
53
|
+
theme: themeCtx,
|
|
54
|
+
}),
|
|
55
|
+
[onHighlightChange, readOnly, themeCtx],
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
const extensions = useMemo(() => {
|
|
59
|
+
const baseExtensions = [
|
|
60
|
+
themeExtension,
|
|
61
|
+
fontSizeExtension,
|
|
62
|
+
highlightLineExtension,
|
|
63
|
+
EditorView.lineWrapping,
|
|
64
|
+
]
|
|
65
|
+
if (languageExtension) {
|
|
66
|
+
return [...baseExtensions, languageExtension]
|
|
67
|
+
}
|
|
68
|
+
return baseExtensions
|
|
69
|
+
}, [fontSizeExtension, highlightLineExtension, languageExtension, themeExtension])
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (editorView) {
|
|
73
|
+
setHighlightedLines(editorView, highlightLines ?? [])
|
|
74
|
+
}
|
|
75
|
+
}, [editorView, highlightLines, value])
|
|
76
|
+
|
|
77
|
+
const initialState = useMemo(() => {
|
|
78
|
+
return {
|
|
79
|
+
json: {
|
|
80
|
+
doc: value ?? '',
|
|
81
|
+
selection: {
|
|
82
|
+
main: 0,
|
|
83
|
+
ranges: [{anchor: 0, head: 0}],
|
|
84
|
+
},
|
|
85
|
+
highlight: highlightLines ?? [],
|
|
86
86
|
},
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
})
|
|
87
|
+
fields: highlightState,
|
|
88
|
+
}
|
|
89
|
+
// only need to calculate this on initial render
|
|
90
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
91
|
+
}, [])
|
|
92
|
+
|
|
93
|
+
const handleCreateEditor = useCallback((view: EditorView) => {
|
|
94
|
+
setEditorView(view)
|
|
95
|
+
}, [])
|
|
96
|
+
|
|
97
|
+
const basicSetup = useMemo(
|
|
98
|
+
() =>
|
|
99
|
+
basicSetupProp ?? {
|
|
100
|
+
highlightActiveLine: false,
|
|
101
|
+
},
|
|
102
|
+
[basicSetupProp],
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<CodeMirror
|
|
107
|
+
{...codeMirrorProps}
|
|
108
|
+
value={value}
|
|
109
|
+
ref={ref}
|
|
110
|
+
extensions={extensions}
|
|
111
|
+
theme={codeMirrorTheme}
|
|
112
|
+
onCreateEditor={handleCreateEditor}
|
|
113
|
+
initialState={initialState}
|
|
114
|
+
basicSetup={basicSetup}
|
|
115
|
+
/>
|
|
116
|
+
)
|
|
117
|
+
},
|
|
118
|
+
)
|
|
120
119
|
|
|
121
120
|
function useLanguageExtension(mode?: string) {
|
|
122
121
|
const codeConfig = useContext(CodeInputConfigContext)
|
|
@@ -130,7 +129,7 @@ function useLanguageExtension(mode?: string) {
|
|
|
130
129
|
const codeMode = modes.find((m) => m.name === mode)
|
|
131
130
|
if (!codeMode?.loader) {
|
|
132
131
|
console.warn(
|
|
133
|
-
`Found no codeMode for language mode ${mode}, syntax highlighting will be disabled
|
|
132
|
+
`Found no codeMode for language mode ${mode}, syntax highlighting will be disabled.`,
|
|
134
133
|
)
|
|
135
134
|
}
|
|
136
135
|
let active = true
|
|
@@ -27,14 +27,14 @@ export const defaultCodeModes: CodeMode[] = [
|
|
|
27
27
|
name: 'typescript',
|
|
28
28
|
loader: () =>
|
|
29
29
|
import('@codemirror/lang-javascript').then(({javascript}) =>
|
|
30
|
-
javascript({jsx: false, typescript: true})
|
|
30
|
+
javascript({jsx: false, typescript: true}),
|
|
31
31
|
),
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
34
|
name: 'tsx',
|
|
35
35
|
loader: () =>
|
|
36
36
|
import('@codemirror/lang-javascript').then(({javascript}) =>
|
|
37
|
-
javascript({jsx: true, typescript: true})
|
|
37
|
+
javascript({jsx: true, typescript: true}),
|
|
38
38
|
),
|
|
39
39
|
},
|
|
40
40
|
{name: 'php', loader: () => import('@codemirror/lang-php').then(({php}) => php())},
|
|
@@ -54,7 +54,7 @@ export const defaultCodeModes: CodeMode[] = [
|
|
|
54
54
|
name: 'csharp',
|
|
55
55
|
loader: () =>
|
|
56
56
|
import('@codemirror/legacy-modes/mode/clike').then(({csharp}) =>
|
|
57
|
-
StreamLanguage.define(csharp)
|
|
57
|
+
StreamLanguage.define(csharp),
|
|
58
58
|
),
|
|
59
59
|
},
|
|
60
60
|
{
|
|
@@ -86,7 +86,7 @@ export const defaultCodeModes: CodeMode[] = [
|
|
|
86
86
|
name: 'python',
|
|
87
87
|
loader: () =>
|
|
88
88
|
import('@codemirror/legacy-modes/mode/python').then(({python}) =>
|
|
89
|
-
StreamLanguage.define(python)
|
|
89
|
+
StreamLanguage.define(python),
|
|
90
90
|
),
|
|
91
91
|
},
|
|
92
92
|
{
|
|
@@ -29,7 +29,7 @@ function useLanguageAlternatives(type: CodeSchemaType) {
|
|
|
29
29
|
|
|
30
30
|
if (!Array.isArray(languageAlternatives)) {
|
|
31
31
|
throw new Error(
|
|
32
|
-
`'options.languageAlternatives' should be an array, got ${typeof languageAlternatives}
|
|
32
|
+
`'options.languageAlternatives' should be an array, got ${typeof languageAlternatives}`,
|
|
33
33
|
)
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -41,7 +41,7 @@ function useLanguageAlternatives(type: CodeSchemaType) {
|
|
|
41
41
|
`'options.languageAlternatives' lists a language with value "%s", which is an alias of "%s" - please replace the value to read "%s"`,
|
|
42
42
|
val,
|
|
43
43
|
alias,
|
|
44
|
-
alias
|
|
44
|
+
alias,
|
|
45
45
|
)
|
|
46
46
|
|
|
47
47
|
return acc.concat({title, value: alias, mode: mode})
|
package/src/useFieldMember.ts
CHANGED
|
@@ -4,13 +4,13 @@ import {FieldMember, ObjectMember} from 'sanity'
|
|
|
4
4
|
/** @internal */
|
|
5
5
|
export function useFieldMember(
|
|
6
6
|
members: ObjectMember[],
|
|
7
|
-
fieldName: string
|
|
7
|
+
fieldName: string,
|
|
8
8
|
): FieldMember | undefined {
|
|
9
9
|
return useMemo(
|
|
10
10
|
() =>
|
|
11
11
|
members.find(
|
|
12
|
-
(member): member is FieldMember => member.kind === 'field' && member.name === fieldName
|
|
12
|
+
(member): member is FieldMember => member.kind === 'field' && member.name === fieldName,
|
|
13
13
|
),
|
|
14
|
-
[members, fieldName]
|
|
14
|
+
[members, fieldName],
|
|
15
15
|
)
|
|
16
16
|
}
|