@scalar/use-codemirror 0.8.0 → 0.8.1
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/CHANGELOG.md +6 -0
- package/dist/hooks/useCodeMirror.d.ts +3 -1
- package/dist/hooks/useCodeMirror.d.ts.map +1 -1
- package/dist/index.js +11 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,8 @@ import type { CodeMirrorLanguage } from '../types';
|
|
|
4
4
|
type BaseParameters = {
|
|
5
5
|
/** Element Ref to mount codemirror to */
|
|
6
6
|
codeMirrorRef: Ref<HTMLDivElement | null>;
|
|
7
|
+
/** List of optional extensions for the instance */
|
|
8
|
+
extensions?: MaybeRefOrGetter<Extension[]>;
|
|
7
9
|
/** Whether to load a theme.*/
|
|
8
10
|
withoutTheme?: MaybeRefOrGetter<boolean | undefined>;
|
|
9
11
|
/** Languages to support for syntax highlighting */
|
|
@@ -22,7 +24,7 @@ export type UseCodeMirrorParameters = (BaseParameters & {
|
|
|
22
24
|
content: MaybeRefOrGetter<string | undefined>;
|
|
23
25
|
onChange: (v: string) => void;
|
|
24
26
|
}) | (BaseParameters & {
|
|
25
|
-
provider: Extension
|
|
27
|
+
provider: MaybeRefOrGetter<Extension | null>;
|
|
26
28
|
content?: MaybeRefOrGetter<string | undefined>;
|
|
27
29
|
onChange?: (v: string) => void;
|
|
28
30
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCodeMirror.d.ts","sourceRoot":"","sources":["../../src/hooks/useCodeMirror.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,KAAK,SAAS,EAAe,MAAM,mBAAmB,CAAA;AAO/D,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,GAAG,EAMT,MAAM,KAAK,CAAA;AAGZ,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAGlD,KAAK,cAAc,GAAG;IACpB,yCAAyC;IACz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AAI;CAsGjD,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -3972,7 +3972,7 @@ const variables = () => ViewPlugin.fromClass(
|
|
|
3972
3972
|
)
|
|
3973
3973
|
}
|
|
3974
3974
|
);
|
|
3975
|
-
const hasProvider = (params) => "provider" in params;
|
|
3975
|
+
const hasProvider = (params) => "provider" in params && !!toValue(params.provider);
|
|
3976
3976
|
const useCodeMirror = (params) => {
|
|
3977
3977
|
const codeMirror = ref(null);
|
|
3978
3978
|
watch(
|
|
@@ -3991,8 +3991,6 @@ const useCodeMirror = (params) => {
|
|
|
3991
3991
|
function mountCodeMirror() {
|
|
3992
3992
|
if (params.codeMirrorRef.value) {
|
|
3993
3993
|
const extensions = getCodeMirrorExtensions(extensionConfig.value);
|
|
3994
|
-
if (hasProvider(params))
|
|
3995
|
-
extensions.push(params.provider);
|
|
3996
3994
|
codeMirror.value = new EditorView({
|
|
3997
3995
|
parent: params.codeMirrorRef.value,
|
|
3998
3996
|
extensions
|
|
@@ -4009,7 +4007,9 @@ const useCodeMirror = (params) => {
|
|
|
4009
4007
|
lineNumbers: toValue(params.lineNumbers),
|
|
4010
4008
|
withVariables: toValue(params.withVariables),
|
|
4011
4009
|
disableEnter: toValue(params.withVariables),
|
|
4012
|
-
withoutTheme: toValue(params.withoutTheme)
|
|
4010
|
+
withoutTheme: toValue(params.withoutTheme),
|
|
4011
|
+
additionalExtensions: toValue(params.extensions),
|
|
4012
|
+
provider: hasProvider(params) ? toValue(params.provider) : null
|
|
4013
4013
|
}));
|
|
4014
4014
|
watch(
|
|
4015
4015
|
extensionConfig,
|
|
@@ -4017,8 +4017,6 @@ const useCodeMirror = (params) => {
|
|
|
4017
4017
|
if (!codeMirror.value)
|
|
4018
4018
|
return;
|
|
4019
4019
|
const extensions = getCodeMirrorExtensions(extensionConfig.value);
|
|
4020
|
-
if (hasProvider(params))
|
|
4021
|
-
extensions.push(params.provider);
|
|
4022
4020
|
codeMirror.value.dispatch({
|
|
4023
4021
|
effects: StateEffect.reconfigure.of(extensions)
|
|
4024
4022
|
});
|
|
@@ -4082,13 +4080,15 @@ const syntaxHighlighting = {
|
|
|
4082
4080
|
};
|
|
4083
4081
|
function getCodeMirrorExtensions({
|
|
4084
4082
|
onChange,
|
|
4083
|
+
provider,
|
|
4085
4084
|
languages = [],
|
|
4086
4085
|
classes = [],
|
|
4087
4086
|
readOnly = false,
|
|
4088
4087
|
lineNumbers: lineNumbers$1 = false,
|
|
4089
4088
|
withVariables = false,
|
|
4090
4089
|
disableEnter = false,
|
|
4091
|
-
withoutTheme = false
|
|
4090
|
+
withoutTheme = false,
|
|
4091
|
+
additionalExtensions = []
|
|
4092
4092
|
}) {
|
|
4093
4093
|
const extensions = [
|
|
4094
4094
|
EditorView.theme({
|
|
@@ -4106,8 +4106,11 @@ function getCodeMirrorExtensions({
|
|
|
4106
4106
|
onChange == null ? void 0 : onChange(v.state.doc.toString());
|
|
4107
4107
|
}),
|
|
4108
4108
|
// Add Classes
|
|
4109
|
-
EditorView.editorAttributes.of({ class: classes.join(" ") })
|
|
4109
|
+
EditorView.editorAttributes.of({ class: classes.join(" ") }),
|
|
4110
|
+
...additionalExtensions
|
|
4110
4111
|
];
|
|
4112
|
+
if (provider)
|
|
4113
|
+
extensions.push(provider);
|
|
4111
4114
|
if (!withoutTheme)
|
|
4112
4115
|
extensions.push(customTheme);
|
|
4113
4116
|
if (readOnly)
|