@scalar/use-codemirror 0.7.10 → 0.7.12

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,18 @@
1
1
  # @scalar/use-codemirror
2
2
 
3
+ ## 0.7.12
4
+
5
+ ### Patch Changes
6
+
7
+ - f4681d5: feat: add yaml syntax highlighting
8
+
9
+ ## 0.7.11
10
+
11
+ ### Patch Changes
12
+
13
+ - 509db1e: refactor: move all api reference refs and watchers to hooks
14
+ - a4f1b08: fix: switching documents with collaborative editing mode enabled
15
+
3
16
  ## 0.7.10
4
17
 
5
18
  ### Patch Changes
@@ -17,6 +17,9 @@ declare const _default: import("vue").DefineComponent<{
17
17
  readOnly: {
18
18
  type: import("vue").PropType<boolean>;
19
19
  };
20
+ name: {
21
+ type: import("vue").PropType<string>;
22
+ };
20
23
  languages: {
21
24
  type: import("vue").PropType<CodeMirrorLanguage[]>;
22
25
  };
@@ -51,6 +54,9 @@ declare const _default: import("vue").DefineComponent<{
51
54
  readOnly: {
52
55
  type: import("vue").PropType<boolean>;
53
56
  };
57
+ name: {
58
+ type: import("vue").PropType<string>;
59
+ };
54
60
  languages: {
55
61
  type: import("vue").PropType<CodeMirrorLanguage[]>;
56
62
  };
@@ -1 +1 @@
1
- {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../../src/components/CodeMirror/CodeMirror.vue.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAUlD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8OrD,wBAAkD"}
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqQrD,wBAAkD"}
@@ -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;AAG/D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,KAAK,GAAG,EAAc,MAAM,KAAK,CAAA;AAO1C,KAAK,uBAAuB,GAAG;IAC7B;;OAEG;IACH,UAAU,EAAE,SAAS,EAAE,CAAA;IACvB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;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;oCACF,MAAM,KAAK,IAAI;2CACR,SAAS,EAAE,KAAK,IAAI;uCACxB,SAAS,EAAE,KAAK,IAAI;CAqKxD,CAAA"}
1
+ {"version":3,"file":"useCodeMirror.d.ts","sourceRoot":"","sources":["../../src/hooks/useCodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAe,MAAM,mBAAmB,CAAA;AAM/D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,KAAK,GAAG,EAAc,MAAM,KAAK,CAAA;AAO1C,KAAK,uBAAuB,GAAG;IAC7B;;OAEG;IACH,UAAU,EAAE,SAAS,EAAE,CAAA;IACvB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;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;oCACF,MAAM,KAAK,IAAI;2CACR,SAAS,EAAE,KAAK,IAAI;uCACxB,SAAS,EAAE,KAAK,IAAI;CAgLxD,CAAA"}
package/dist/index.js CHANGED
@@ -3753,6 +3753,109 @@ const swift = {
3753
3753
  closeBrackets: { brackets: ["(", "[", "{", "'", '"', "`"] }
3754
3754
  }
3755
3755
  };
3756
+ var cons = ["true", "false", "on", "off", "yes", "no"];
3757
+ var keywordRegex = new RegExp("\\b((" + cons.join(")|(") + "))$", "i");
3758
+ const yaml = {
3759
+ name: "yaml",
3760
+ token: function(stream, state) {
3761
+ var ch = stream.peek();
3762
+ var esc = state.escaped;
3763
+ state.escaped = false;
3764
+ if (ch == "#" && (stream.pos == 0 || /\s/.test(stream.string.charAt(stream.pos - 1)))) {
3765
+ stream.skipToEnd();
3766
+ return "comment";
3767
+ }
3768
+ if (stream.match(/^('([^']|\\.)*'?|"([^"]|\\.)*"?)/))
3769
+ return "string";
3770
+ if (state.literal && stream.indentation() > state.keyCol) {
3771
+ stream.skipToEnd();
3772
+ return "string";
3773
+ } else if (state.literal) {
3774
+ state.literal = false;
3775
+ }
3776
+ if (stream.sol()) {
3777
+ state.keyCol = 0;
3778
+ state.pair = false;
3779
+ state.pairStart = false;
3780
+ if (stream.match("---")) {
3781
+ return "def";
3782
+ }
3783
+ if (stream.match("...")) {
3784
+ return "def";
3785
+ }
3786
+ if (stream.match(/^\s*-\s+/)) {
3787
+ return "meta";
3788
+ }
3789
+ }
3790
+ if (stream.match(/^(\{|\}|\[|\])/)) {
3791
+ if (ch == "{")
3792
+ state.inlinePairs++;
3793
+ else if (ch == "}")
3794
+ state.inlinePairs--;
3795
+ else if (ch == "[")
3796
+ state.inlineList++;
3797
+ else
3798
+ state.inlineList--;
3799
+ return "meta";
3800
+ }
3801
+ if (state.inlineList > 0 && !esc && ch == ",") {
3802
+ stream.next();
3803
+ return "meta";
3804
+ }
3805
+ if (state.inlinePairs > 0 && !esc && ch == ",") {
3806
+ state.keyCol = 0;
3807
+ state.pair = false;
3808
+ state.pairStart = false;
3809
+ stream.next();
3810
+ return "meta";
3811
+ }
3812
+ if (state.pairStart) {
3813
+ if (stream.match(/^\s*(\||\>)\s*/)) {
3814
+ state.literal = true;
3815
+ return "meta";
3816
+ }
3817
+ if (stream.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i)) {
3818
+ return "variable";
3819
+ }
3820
+ if (state.inlinePairs == 0 && stream.match(/^\s*-?[0-9\.\,]+\s?$/)) {
3821
+ return "number";
3822
+ }
3823
+ if (state.inlinePairs > 0 && stream.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/)) {
3824
+ return "number";
3825
+ }
3826
+ if (stream.match(keywordRegex)) {
3827
+ return "keyword";
3828
+ }
3829
+ }
3830
+ if (!state.pair && stream.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^,\[\]{}#&*!|>'"%@`])[^#]*?(?=\s*:($|\s))/)) {
3831
+ state.pair = true;
3832
+ state.keyCol = stream.indentation();
3833
+ return "atom";
3834
+ }
3835
+ if (state.pair && stream.match(/^:\s*/)) {
3836
+ state.pairStart = true;
3837
+ return "meta";
3838
+ }
3839
+ state.pairStart = false;
3840
+ state.escaped = ch == "\\";
3841
+ stream.next();
3842
+ return null;
3843
+ },
3844
+ startState: function() {
3845
+ return {
3846
+ pair: false,
3847
+ pairStart: false,
3848
+ keyCol: 0,
3849
+ inlinePairs: 0,
3850
+ inlineList: 0,
3851
+ literal: false,
3852
+ escaped: false
3853
+ };
3854
+ },
3855
+ languageData: {
3856
+ commentTokens: { line: "#" }
3857
+ }
3858
+ };
3756
3859
  const lightTheme = createTheme({
3757
3860
  theme: "light",
3758
3861
  settings: {
@@ -4004,7 +4107,13 @@ const useCodeMirror = (parameters) => {
4004
4107
  if (!codeMirror.value) {
4005
4108
  return;
4006
4109
  }
4110
+ if (value.value === newValue) {
4111
+ return;
4112
+ }
4007
4113
  value.value = newValue;
4114
+ if (codeMirror.value.state.doc.toString() === newValue) {
4115
+ return;
4116
+ }
4008
4117
  codeMirror.value.dispatch({
4009
4118
  changes: {
4010
4119
  from: 0,
@@ -4093,6 +4202,7 @@ const variables = () => ViewPlugin.fromClass(
4093
4202
  const _sfc_main = /* @__PURE__ */ defineComponent({
4094
4203
  __name: "CodeMirror",
4095
4204
  props: {
4205
+ name: {},
4096
4206
  extensions: {},
4097
4207
  content: {},
4098
4208
  readOnly: { type: Boolean },
@@ -4107,7 +4217,6 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4107
4217
  setup(__props, { expose: __expose, emit }) {
4108
4218
  const props = __props;
4109
4219
  const syntaxHighlighting = {
4110
- axios: javascript(),
4111
4220
  c: StreamLanguage.define(c),
4112
4221
  clojure: StreamLanguage.define(clojure),
4113
4222
  csharp: StreamLanguage.define(csharp),
@@ -4126,7 +4235,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4126
4235
  r: StreamLanguage.define(r),
4127
4236
  ruby: StreamLanguage.define(ruby),
4128
4237
  shell: StreamLanguage.define(shell),
4129
- swift: StreamLanguage.define(swift)
4238
+ swift: StreamLanguage.define(swift),
4239
+ yaml: StreamLanguage.define(yaml)
4130
4240
  };
4131
4241
  const classes = ["scalar-api-client__codemirror"];
4132
4242
  if (props.readOnly) {
@@ -4200,16 +4310,35 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
4200
4310
  withoutTheme: props.withoutTheme,
4201
4311
  forceDarkMode: props.forceDarkMode
4202
4312
  });
4203
- watch(props, () => {
4204
- setCodeMirrorContent(props.content ?? "");
4205
- reconfigureCodeMirror(getCodeMirrorExtensions());
4206
- });
4207
4313
  watch(
4208
- () => props.extensions,
4314
+ () => props.content,
4315
+ () => {
4316
+ var _a;
4317
+ if ((_a = props.content) == null ? void 0 : _a.length) {
4318
+ setCodeMirrorContent(props.content);
4319
+ }
4320
+ }
4321
+ );
4322
+ watch(
4323
+ () => props.name,
4209
4324
  () => {
4210
4325
  restartCodeMirror(getCodeMirrorExtensions());
4211
4326
  }
4212
4327
  );
4328
+ watch(
4329
+ [
4330
+ () => props.disableEnter,
4331
+ () => props.forceDarkMode,
4332
+ () => props.languages,
4333
+ () => props.lineNumbers,
4334
+ () => props.readOnly,
4335
+ () => props.withoutTheme,
4336
+ () => props.withVariables
4337
+ ],
4338
+ () => {
4339
+ reconfigureCodeMirror(getCodeMirrorExtensions());
4340
+ }
4341
+ );
4213
4342
  __expose({
4214
4343
  setCodeMirrorContent
4215
4344
  });
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export type CodeMirrorLanguage = 'axios' | 'c' | 'clojure' | 'csharp' | 'go' | 'http' | 'html' | 'java' | 'javascript' | 'json' | 'kotlin' | 'node' | 'objc' | 'ocaml' | 'powershell' | 'python' | 'r' | 'ruby' | 'shell' | 'swift' | 'php';
1
+ export type CodeMirrorLanguage = 'c' | 'clojure' | 'csharp' | 'go' | 'html' | 'http' | 'java' | 'javascript' | 'json' | 'kotlin' | 'node' | 'objc' | 'ocaml' | 'php' | 'powershell' | 'python' | 'r' | 'ruby' | 'shell' | 'swift' | 'yaml';
2
2
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAC1B,OAAO,GACP,GAAG,GACH,SAAS,GACT,QAAQ,GACR,IAAI,GACJ,MAAM,GACN,MAAM,GACN,MAAM,GACN,YAAY,GACZ,MAAM,GACN,QAAQ,GACR,MAAM,GACN,MAAM,GACN,OAAO,GACP,YAAY,GACZ,QAAQ,GACR,GAAG,GACH,MAAM,GACN,OAAO,GACP,OAAO,GACP,KAAK,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAC1B,GAAG,GACH,SAAS,GACT,QAAQ,GACR,IAAI,GACJ,MAAM,GACN,MAAM,GACN,MAAM,GACN,YAAY,GACZ,MAAM,GACN,QAAQ,GACR,MAAM,GACN,MAAM,GACN,OAAO,GACP,KAAK,GACL,YAAY,GACZ,QAAQ,GACR,GAAG,GACH,MAAM,GACN,OAAO,GACP,OAAO,GACP,MAAM,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scalar/use-codemirror",
3
3
  "description": "CodeMirror for Vue",
4
- "version": "0.7.10",
4
+ "version": "0.7.12",
5
5
  "author": "Scalar (https://github.com/scalar)",
6
6
  "bugs": "https://github.com/scalar/scalar/issues/new",
7
7
  "dependencies": {