@scalar/use-codemirror 0.7.22 → 0.8.0

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @scalar/use-codemirror
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 612431b4: Migrate model logic from codemirror component to hook
8
+
3
9
  ## 0.7.22
4
10
 
5
11
  ### Patch Changes
@@ -1,9 +1,6 @@
1
- import { type Extension } from '@codemirror/state';
2
1
  import type { CodeMirrorLanguage } from '../../types';
3
2
  declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
4
- name?: string | undefined;
5
- extensions?: Extension[] | undefined;
6
- content?: string | undefined;
3
+ content: string | undefined;
7
4
  readOnly?: boolean | undefined;
8
5
  languages?: CodeMirrorLanguage[] | undefined;
9
6
  withVariables?: boolean | undefined;
@@ -12,14 +9,10 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
12
9
  disableEnter?: boolean | undefined;
13
10
  }>, {
14
11
  disableEnter: boolean;
15
- }>, {
16
- setCodeMirrorContent: (content?: string | undefined) => void;
17
- }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
12
+ }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
18
13
  change: (value: string) => void;
19
14
  }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
20
- name?: string | undefined;
21
- extensions?: Extension[] | undefined;
22
- content?: string | undefined;
15
+ content: string | undefined;
23
16
  readOnly?: boolean | undefined;
24
17
  languages?: CodeMirrorLanguage[] | undefined;
25
18
  withVariables?: boolean | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../../src/components/CodeMirror/CodeMirror.vue.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAUlD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA6PlC,OAAO;;AAV1B,wBAkBG;AAGH,KAAK,sBAAsB,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,CAAC,CAAC;AACjE,KAAK,6BAA6B,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;QAAE,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAAC,QAAQ,EAAE,IAAI,CAAA;KAAE;CAAE,CAAC;AAC9M,KAAK,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI;KAE1B,CAAC,IAAI,MAAM,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;QACxE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;KACb,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACT,CAAC;AACN,KAAK,cAAc,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG,EAAE,CAAC"}
1
+ {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../../src/components/CodeMirror/CodeMirror.vue.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;;aA2GxC,MAAM,GAAG,SAAS;;;;;;;;;;;;aAAlB,MAAM,GAAG,SAAS;;;;;;;;;;;;kBAMZ,OAAO;;AAR1B,wBAeG;AAGH,KAAK,sBAAsB,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,CAAC,CAAC;AACjE,KAAK,6BAA6B,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;QAAE,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAAC,QAAQ,EAAE,IAAI,CAAA;KAAE;CAAE,CAAC;AAC9M,KAAK,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI;KAE1B,CAAC,IAAI,MAAM,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;QACxE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;KACb,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACT,CAAC;AACN,KAAK,cAAc,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG,EAAE,CAAC"}
@@ -1,27 +1,34 @@
1
1
  import { type Extension } from '@codemirror/state';
2
- import { EditorView } from 'codemirror';
3
- import { type Ref } from 'vue';
4
- type UseCodeMirrorParameters = {
5
- /**
6
- * Some additional CodeMirror extensions.
7
- */
8
- extensions: Extension[];
9
- /**
10
- * Prefill the content. Will be ignored when a provider is given.
11
- */
12
- content?: string;
13
- /**
14
- * Whether to load a theme.
15
- */
16
- withoutTheme?: boolean;
17
- };
18
- export declare const useCodeMirror: (parameters: UseCodeMirrorParameters) => {
19
- value: Ref<string>;
2
+ import { type MaybeRefOrGetter, type Ref } from 'vue';
3
+ import type { CodeMirrorLanguage } from '../types';
4
+ type BaseParameters = {
5
+ /** Element Ref to mount codemirror to */
20
6
  codeMirrorRef: Ref<HTMLDivElement | null>;
21
- codeMirror: Ref<EditorView | null>;
7
+ /** Whether to load a theme.*/
8
+ withoutTheme?: MaybeRefOrGetter<boolean | undefined>;
9
+ /** Languages to support for syntax highlighting */
10
+ languages?: MaybeRefOrGetter<CodeMirrorLanguage[] | undefined>;
11
+ /** Class names to apply to the instance */
12
+ classes?: MaybeRefOrGetter<string[] | undefined>;
13
+ /** Put the editor into read-only mode */
14
+ readOnly?: MaybeRefOrGetter<boolean | undefined>;
15
+ /** Option to show line numbers in the editor */
16
+ lineNumbers?: MaybeRefOrGetter<boolean | undefined>;
17
+ withVariables?: MaybeRefOrGetter<boolean | undefined>;
18
+ disableEnter?: MaybeRefOrGetter<boolean | undefined>;
19
+ };
20
+ export type UseCodeMirrorParameters = (BaseParameters & {
21
+ /** Prefill the content. Will be ignored when a provider is given. */
22
+ content: MaybeRefOrGetter<string | undefined>;
23
+ onChange: (v: string) => void;
24
+ }) | (BaseParameters & {
25
+ provider: Extension;
26
+ content?: MaybeRefOrGetter<string | undefined>;
27
+ onChange?: (v: string) => void;
28
+ });
29
+ /** Reactive CodeMirror Integration */
30
+ export declare const useCodeMirror: (params: UseCodeMirrorParameters) => {
22
31
  setCodeMirrorContent: (content?: string) => void;
23
- reconfigureCodeMirror: (newExtensions: Extension[]) => void;
24
- restartCodeMirror: (newExtensions: Extension[]) => void;
25
32
  };
26
33
  export {};
27
34
  //# sourceMappingURL=useCodeMirror.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCodeMirror.d.ts","sourceRoot":"","sources":["../../src/hooks/useCodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAe,MAAM,mBAAmB,CAAA;AAE/D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,KAAK,GAAG,EAAc,MAAM,KAAK,CAAA;AAI1C,KAAK,uBAAuB,GAAG;IAC7B;;OAEG;IACH,UAAU,EAAE,SAAS,EAAE,CAAA;IACvB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,aAAa,eACZ,uBAAuB;WAE5B,IAAI,MAAM,CAAC;mBACH,IAAI,cAAc,GAAG,IAAI,CAAC;gBAC7B,IAAI,UAAU,GAAG,IAAI,CAAC;qCACD,MAAM,KAAK,IAAI;2CACT,SAAS,EAAE,KAAK,IAAI;uCACxB,SAAS,EAAE,KAAK,IAAI;CA+HxD,CAAA"}
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;IACzC,aAAa,EAAE,GAAG,CAAC,cAAc,GAAG,IAAI,CAAC,CAAA;IACzC,8BAA8B;IAC9B,YAAY,CAAC,EAAE,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;IACpD,mDAAmD;IACnD,SAAS,CAAC,EAAE,gBAAgB,CAAC,kBAAkB,EAAE,GAAG,SAAS,CAAC,CAAA;IAC9D,2CAA2C;IAC3C,OAAO,CAAC,EAAE,gBAAgB,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CAAA;IAChD,yCAAyC;IACzC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;IAChD,gDAAgD;IAChD,WAAW,CAAC,EAAE,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;IACnD,aAAa,CAAC,EAAE,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;IACrD,YAAY,CAAC,EAAE,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;CACrD,CAAA;AAED,MAAM,MAAM,uBAAuB,GAC/B,CAAC,cAAc,GAAG;IAChB,qEAAqE;IACrE,OAAO,EAAE,gBAAgB,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IAC7C,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CAC9B,CAAC,GACF,CAAC,cAAc,GAAG;IAChB,QAAQ,EAAE,SAAS,CAAA;IACnB,OAAO,CAAC,EAAE,gBAAgB,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IAC9C,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CAC/B,CAAC,CAAA;AAUN,sCAAsC;AACtC,eAAO,MAAM,aAAa,WAChB,uBAAuB;qCAEE,MAAM,KAAK,IAAI;CAsGjD,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../src/hooks/variables.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAGlB,UAAU,EACV,KAAK,UAAU,EAChB,MAAM,kBAAkB,CAAA;AAYzB,eAAO,MAAM,SAAS;;mBAOD,UAAU;EAc5B,CAAA"}
package/dist/index.js CHANGED
@@ -4,16 +4,15 @@ var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
6
6
  };
7
- import { ref, watch, defineComponent, openBlock, createElementBlock, toRaw } from "vue";
7
+ import { ref, watch, onBeforeUnmount, toValue, computed, defineComponent, toRef, openBlock, createElementBlock } from "vue";
8
8
  import { html } from "@codemirror/lang-html";
9
9
  import { java } from "@codemirror/lang-java";
10
10
  import { javascript } from "@codemirror/lang-javascript";
11
11
  import { json } from "@codemirror/lang-json";
12
12
  import { python } from "@codemirror/lang-python";
13
13
  import { StreamLanguage } from "@codemirror/language";
14
- import { MatchDecorator, Decoration, ViewPlugin, EditorView as EditorView$1, lineNumbers, keymap } from "@codemirror/view";
15
14
  import { StateEffect } from "@codemirror/state";
16
- import { EditorView } from "codemirror";
15
+ import { MatchDecorator, Decoration, ViewPlugin, EditorView, lineNumbers, keymap } from "@codemirror/view";
17
16
  import { tags } from "@lezer/highlight";
18
17
  import { createTheme } from "@uiw/codemirror-themes";
19
18
  function Context$2(indented, column, type, info, align, prev) {
@@ -3942,110 +3941,6 @@ const customTheme = createTheme({
3942
3941
  }
3943
3942
  ]
3944
3943
  });
3945
- const useCodeMirror = (parameters) => {
3946
- const { extensions, content, withoutTheme } = parameters;
3947
- const value = ref(content ?? "");
3948
- const codeMirrorRef = ref(null);
3949
- const codeMirror = ref(null);
3950
- watch(codeMirrorRef, () => {
3951
- destroyCodeMirror();
3952
- mountCodeMirror(extensions);
3953
- });
3954
- const mountCodeMirror = (withCustomExtensions) => {
3955
- if (codeMirrorRef.value) {
3956
- const configuration = {
3957
- parent: codeMirrorRef.value,
3958
- extensions: addDefaultExtensions(withCustomExtensions)
3959
- };
3960
- if (content) {
3961
- configuration.doc = content;
3962
- }
3963
- codeMirror.value = new EditorView(configuration);
3964
- }
3965
- };
3966
- const addDefaultExtensions = (newExtensions = []) => {
3967
- const defaultExtensions = [
3968
- withoutTheme ? null : customTheme,
3969
- EditorView.theme({
3970
- ".cm-line": {
3971
- lineHeight: "20px"
3972
- },
3973
- ".cm-gutterElement": {
3974
- lineHeight: "20px"
3975
- }
3976
- })
3977
- ].filter((extension) => extension !== null);
3978
- return [...defaultExtensions, newExtensions];
3979
- };
3980
- const destroyCodeMirror = () => {
3981
- var _a;
3982
- (_a = codeMirror.value) == null ? void 0 : _a.destroy();
3983
- };
3984
- const setCodeMirrorContent = (newValue) => {
3985
- if (!codeMirror.value) {
3986
- return;
3987
- }
3988
- if (value.value === newValue) {
3989
- return;
3990
- }
3991
- value.value = newValue ?? "";
3992
- if (codeMirror.value.state.doc.toString() === value.value) {
3993
- return;
3994
- }
3995
- codeMirror.value.dispatch({
3996
- changes: {
3997
- from: 0,
3998
- to: codeMirror.value.state.doc.length,
3999
- insert: newValue
4000
- },
4001
- selection: {
4002
- anchor: Math.min(
4003
- codeMirror.value.state.selection.main.anchor,
4004
- value.value.length
4005
- )
4006
- }
4007
- });
4008
- };
4009
- const reconfigureCodeMirror = (newExtensions) => {
4010
- if (!codeMirror.value) {
4011
- return;
4012
- }
4013
- codeMirror.value.dispatch({
4014
- effects: StateEffect.reconfigure.of(addDefaultExtensions(newExtensions))
4015
- });
4016
- };
4017
- const restartCodeMirror = (newExtensions) => {
4018
- destroyCodeMirror();
4019
- mountCodeMirror(newExtensions);
4020
- };
4021
- return {
4022
- /**
4023
- * The current value
4024
- */
4025
- value,
4026
- /**
4027
- * An empty reference used to mount CodeMirror when bound to the DOM.
4028
- */
4029
- codeMirrorRef,
4030
- /**
4031
- * The CodeMirror instance.
4032
- */
4033
- // @ts-ignore
4034
- codeMirror,
4035
- /**
4036
- * Replaces the current content with the given value.
4037
- */
4038
- setCodeMirrorContent,
4039
- /**
4040
- * Reconfigure the used extensions.
4041
- */
4042
- reconfigureCodeMirror,
4043
- /**
4044
- * Restarts CodeMirror (destroy + mount)
4045
- */
4046
- restartCodeMirror
4047
- };
4048
- };
4049
3944
  const variableHighlighterDecoration = new MatchDecorator({
4050
3945
  regexp: /(\{[^}]+\})/g,
4051
3946
  decoration: () => Decoration.mark({
@@ -4069,7 +3964,7 @@ const variables = () => ViewPlugin.fromClass(
4069
3964
  },
4070
3965
  {
4071
3966
  decorations: (instance) => instance.variables,
4072
- provide: (plugin) => EditorView$1.atomicRanges.of(
3967
+ provide: (plugin) => EditorView.atomicRanges.of(
4073
3968
  (view) => {
4074
3969
  var _a;
4075
3970
  return ((_a = view.plugin(plugin)) == null ? void 0 : _a.variables) || Decoration.none;
@@ -4077,11 +3972,185 @@ const variables = () => ViewPlugin.fromClass(
4077
3972
  )
4078
3973
  }
4079
3974
  );
3975
+ const hasProvider = (params) => "provider" in params;
3976
+ const useCodeMirror = (params) => {
3977
+ const codeMirror = ref(null);
3978
+ watch(
3979
+ params.codeMirrorRef,
3980
+ () => {
3981
+ var _a;
3982
+ (_a = codeMirror.value) == null ? void 0 : _a.destroy();
3983
+ mountCodeMirror();
3984
+ },
3985
+ { immediate: true }
3986
+ );
3987
+ onBeforeUnmount(() => {
3988
+ var _a;
3989
+ return (_a = codeMirror.value) == null ? void 0 : _a.destroy();
3990
+ });
3991
+ function mountCodeMirror() {
3992
+ if (params.codeMirrorRef.value) {
3993
+ const extensions = getCodeMirrorExtensions(extensionConfig.value);
3994
+ if (hasProvider(params))
3995
+ extensions.push(params.provider);
3996
+ codeMirror.value = new EditorView({
3997
+ parent: params.codeMirrorRef.value,
3998
+ extensions
3999
+ });
4000
+ if (!hasProvider(params))
4001
+ setCodeMirrorContent(toValue(params.content));
4002
+ }
4003
+ }
4004
+ const extensionConfig = computed(() => ({
4005
+ onChange: params.onChange,
4006
+ languages: toValue(params.languages),
4007
+ classes: toValue(params.classes),
4008
+ readOnly: toValue(params.readOnly),
4009
+ lineNumbers: toValue(params.lineNumbers),
4010
+ withVariables: toValue(params.withVariables),
4011
+ disableEnter: toValue(params.withVariables),
4012
+ withoutTheme: toValue(params.withoutTheme)
4013
+ }));
4014
+ watch(
4015
+ extensionConfig,
4016
+ () => {
4017
+ if (!codeMirror.value)
4018
+ return;
4019
+ const extensions = getCodeMirrorExtensions(extensionConfig.value);
4020
+ if (hasProvider(params))
4021
+ extensions.push(params.provider);
4022
+ codeMirror.value.dispatch({
4023
+ effects: StateEffect.reconfigure.of(extensions)
4024
+ });
4025
+ },
4026
+ { immediate: true }
4027
+ );
4028
+ const setCodeMirrorContent = (newValue = "") => {
4029
+ if (!codeMirror.value)
4030
+ return;
4031
+ if (codeMirror.value.state.doc.toString() === newValue)
4032
+ return;
4033
+ codeMirror.value.dispatch({
4034
+ changes: {
4035
+ from: 0,
4036
+ to: codeMirror.value.state.doc.length,
4037
+ insert: newValue
4038
+ },
4039
+ selection: {
4040
+ anchor: Math.min(
4041
+ codeMirror.value.state.selection.main.anchor,
4042
+ newValue.length
4043
+ )
4044
+ }
4045
+ });
4046
+ };
4047
+ watch(
4048
+ () => toValue(params.content),
4049
+ () => {
4050
+ if (hasProvider(params))
4051
+ return;
4052
+ setCodeMirrorContent(toValue(params.content));
4053
+ },
4054
+ { immediate: true }
4055
+ );
4056
+ return {
4057
+ /** Replaces the current content with the given value. */
4058
+ setCodeMirrorContent
4059
+ };
4060
+ };
4061
+ const syntaxHighlighting = {
4062
+ c: StreamLanguage.define(c),
4063
+ clojure: StreamLanguage.define(clojure),
4064
+ csharp: StreamLanguage.define(csharp),
4065
+ go: StreamLanguage.define(go),
4066
+ http: StreamLanguage.define(http),
4067
+ html: html(),
4068
+ java: java(),
4069
+ javascript: javascript(),
4070
+ json: json(),
4071
+ kotlin: StreamLanguage.define(kotlin),
4072
+ node: javascript(),
4073
+ objc: StreamLanguage.define(objectiveC),
4074
+ ocaml: StreamLanguage.define(oCaml),
4075
+ powershell: StreamLanguage.define(powerShell),
4076
+ python: python(),
4077
+ r: StreamLanguage.define(r),
4078
+ ruby: StreamLanguage.define(ruby),
4079
+ shell: StreamLanguage.define(shell),
4080
+ swift: StreamLanguage.define(swift),
4081
+ yaml: StreamLanguage.define(yaml)
4082
+ };
4083
+ function getCodeMirrorExtensions({
4084
+ onChange,
4085
+ languages = [],
4086
+ classes = [],
4087
+ readOnly = false,
4088
+ lineNumbers: lineNumbers$1 = false,
4089
+ withVariables = false,
4090
+ disableEnter = false,
4091
+ withoutTheme = false
4092
+ }) {
4093
+ const extensions = [
4094
+ EditorView.theme({
4095
+ ".cm-line": {
4096
+ lineHeight: "20px"
4097
+ },
4098
+ ".cm-gutterElement": {
4099
+ lineHeight: "20px"
4100
+ }
4101
+ }),
4102
+ // Listen to updates
4103
+ EditorView.updateListener.of((v) => {
4104
+ if (!v.docChanged)
4105
+ return;
4106
+ onChange == null ? void 0 : onChange(v.state.doc.toString());
4107
+ }),
4108
+ // Add Classes
4109
+ EditorView.editorAttributes.of({ class: classes.join(" ") })
4110
+ ];
4111
+ if (!withoutTheme)
4112
+ extensions.push(customTheme);
4113
+ if (readOnly)
4114
+ extensions.push(EditorView.editable.of(false));
4115
+ if (languages.length) {
4116
+ languages.filter((language) => typeof syntaxHighlighting[language] !== "undefined").forEach((language) => {
4117
+ extensions.push(syntaxHighlighting[language]);
4118
+ });
4119
+ }
4120
+ if (lineNumbers$1)
4121
+ extensions.push(lineNumbers());
4122
+ if (withVariables)
4123
+ extensions.push(variables());
4124
+ if (disableEnter) {
4125
+ extensions.push(
4126
+ keymap.of([
4127
+ {
4128
+ key: "Enter",
4129
+ run: () => {
4130
+ return true;
4131
+ }
4132
+ },
4133
+ {
4134
+ key: "Ctrl-Enter",
4135
+ mac: "Cmd-Enter",
4136
+ run: () => {
4137
+ return true;
4138
+ }
4139
+ },
4140
+ {
4141
+ key: "Shift-Enter",
4142
+ run: () => {
4143
+ return true;
4144
+ }
4145
+ }
4146
+ ])
4147
+ );
4148
+ }
4149
+ return extensions;
4150
+ }
4080
4151
  const _sfc_main = /* @__PURE__ */ defineComponent({
4081
4152
  __name: "CodeMirror",
4082
4153
  props: {
4083
- name: {},
4084
- extensions: {},
4085
4154
  content: {},
4086
4155
  readOnly: { type: Boolean },
4087
4156
  languages: {},
@@ -4091,128 +4160,26 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4091
4160
  disableEnter: { type: Boolean, default: false }
4092
4161
  },
4093
4162
  emits: ["change"],
4094
- setup(__props, { expose: __expose, emit }) {
4163
+ setup(__props, { emit }) {
4095
4164
  const props = __props;
4096
- const syntaxHighlighting = {
4097
- c: StreamLanguage.define(c),
4098
- clojure: StreamLanguage.define(clojure),
4099
- csharp: StreamLanguage.define(csharp),
4100
- go: StreamLanguage.define(go),
4101
- http: StreamLanguage.define(http),
4102
- html: html(),
4103
- java: java(),
4104
- javascript: javascript(),
4105
- json: json(),
4106
- kotlin: StreamLanguage.define(kotlin),
4107
- node: javascript(),
4108
- objc: StreamLanguage.define(objectiveC),
4109
- ocaml: StreamLanguage.define(oCaml),
4110
- powershell: StreamLanguage.define(powerShell),
4111
- python: python(),
4112
- r: StreamLanguage.define(r),
4113
- ruby: StreamLanguage.define(ruby),
4114
- shell: StreamLanguage.define(shell),
4115
- swift: StreamLanguage.define(swift),
4116
- yaml: StreamLanguage.define(yaml)
4117
- };
4118
- const classes = ["scalar-api-client__codemirror"];
4119
- if (props.readOnly) {
4120
- classes.push("scalar-api-client__codemirror--read-only");
4121
- }
4122
- const getCodeMirrorExtensions = () => {
4123
- const extensions = [];
4124
- extensions.push(EditorView$1.editorAttributes.of({ class: classes.join(" ") }));
4125
- if (props.extensions) {
4126
- props.extensions.forEach((extension) => {
4127
- extensions.push(toRaw(extension));
4128
- });
4129
- }
4130
- if (props.readOnly) {
4131
- extensions.push(EditorView$1.editable.of(false));
4132
- }
4133
- if (props.languages) {
4134
- props.languages.filter((language) => typeof syntaxHighlighting[language] !== "undefined").forEach((language) => {
4135
- extensions.push(syntaxHighlighting[language]);
4136
- });
4137
- }
4138
- if (props.lineNumbers) {
4139
- extensions.push(lineNumbers());
4140
- }
4141
- if (props.withVariables) {
4142
- extensions.push(variables());
4143
- }
4144
- if (props.disableEnter) {
4145
- extensions.push(
4146
- keymap.of([
4147
- {
4148
- key: "Enter",
4149
- run: () => {
4150
- return true;
4151
- }
4152
- },
4153
- {
4154
- key: "Ctrl-Enter",
4155
- mac: "Cmd-Enter",
4156
- run: () => {
4157
- return true;
4158
- }
4159
- },
4160
- {
4161
- key: "Shift-Enter",
4162
- run: () => {
4163
- return true;
4164
- }
4165
- }
4166
- ])
4167
- );
4168
- }
4169
- extensions.push(
4170
- EditorView$1.updateListener.of((v) => {
4171
- if (!v.docChanged) {
4172
- return;
4173
- }
4174
- emit("change", v.state.doc.toString());
4175
- })
4176
- );
4177
- return extensions;
4178
- };
4179
- const {
4180
- codeMirrorRef,
4181
- setCodeMirrorContent,
4182
- reconfigureCodeMirror,
4183
- restartCodeMirror
4184
- } = useCodeMirror({
4185
- content: props.content ?? "",
4186
- extensions: getCodeMirrorExtensions(),
4187
- withoutTheme: props.withoutTheme
4188
- });
4189
- watch(
4190
- () => props.content,
4191
- () => {
4192
- setCodeMirrorContent(props.content);
4193
- }
4194
- );
4195
- watch(
4196
- () => props.name,
4197
- () => {
4198
- restartCodeMirror(getCodeMirrorExtensions());
4199
- }
4165
+ const classes = computed(
4166
+ () => props.readOnly ? [
4167
+ "scalar-api-client__codemirror",
4168
+ "scalar-api-client__codemirror--read-only"
4169
+ ] : ["scalar-api-client__codemirror"]
4200
4170
  );
4201
- watch(
4202
- [
4203
- () => props.disableEnter,
4204
- () => props.languages,
4205
- () => props.lineNumbers,
4206
- () => props.readOnly,
4207
- () => props.withoutTheme,
4208
- () => props.withVariables
4209
- ],
4210
- () => {
4211
- reconfigureCodeMirror(getCodeMirrorExtensions());
4212
- }
4213
- );
4214
- __expose({
4215
- setCodeMirrorContent
4171
+ const codeMirrorRef = ref(null);
4172
+ useCodeMirror({
4173
+ content: toRef(() => props.content),
4174
+ readOnly: toRef(() => props.readOnly),
4175
+ languages: toRef(() => props.languages),
4176
+ withVariables: toRef(() => props.withVariables),
4177
+ lineNumbers: toRef(() => props.lineNumbers),
4178
+ withoutTheme: toRef(() => props.withoutTheme),
4179
+ disableEnter: toRef(() => props.disableEnter),
4180
+ onChange: (v) => emit("change", v || ""),
4181
+ codeMirrorRef,
4182
+ classes
4216
4183
  });
4217
4184
  return (_ctx, _cache) => {
4218
4185
  return openBlock(), createElementBlock("div", {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "vue",
12
12
  "vue3"
13
13
  ],
14
- "version": "0.7.22",
14
+ "version": "0.8.0",
15
15
  "engines": {
16
16
  "node": ">=18"
17
17
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../../../src/components/CodeMirror/extensions/variables.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAGlB,UAAU,EACV,KAAK,UAAU,EAChB,MAAM,kBAAkB,CAAA;AAYzB,eAAO,MAAM,SAAS;;mBAOD,UAAU;EAc5B,CAAA"}