jtlt 0.12.0 → 0.13.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.
Files changed (57) hide show
  1. package/CHANGES.md +5 -0
  2. package/README.md +9 -5
  3. package/demo/calltemplate-params-demo.js +19 -15
  4. package/demo/codemirror.esm.js +140 -70
  5. package/demo/codemirror.js +9 -5
  6. package/demo/index.js +2 -1
  7. package/demo/vendor/fontoxpath/dist/fontoxpath.esm.js +508 -499
  8. package/demo/vendor/jamilih/dist/jml.mjs +516 -225
  9. package/demo/vendor/jsonpath-plus/dist/index-browser-esm.js +11 -5
  10. package/dist/AbstractJoiningTransformer.d.ts +12 -20
  11. package/dist/AbstractJoiningTransformer.d.ts.map +1 -1
  12. package/dist/DOMJoiningTransformer.d.ts +502 -19
  13. package/dist/DOMJoiningTransformer.d.ts.map +1 -1
  14. package/dist/JSONJoiningTransformer.d.ts +41 -25
  15. package/dist/JSONJoiningTransformer.d.ts.map +1 -1
  16. package/dist/JSONPathTransformer.d.ts +20 -20
  17. package/dist/JSONPathTransformer.d.ts.map +1 -1
  18. package/dist/JSONPathTransformerContext.d.ts +103 -80
  19. package/dist/JSONPathTransformerContext.d.ts.map +1 -1
  20. package/dist/StringJoiningTransformer.d.ts +42 -28
  21. package/dist/StringJoiningTransformer.d.ts.map +1 -1
  22. package/dist/XPathTransformer.d.ts +11 -11
  23. package/dist/XPathTransformer.d.ts.map +1 -1
  24. package/dist/XPathTransformerContext.d.ts +47 -45
  25. package/dist/XPathTransformerContext.d.ts.map +1 -1
  26. package/dist/XSLTStyleJSONPathResolver.d.ts +1 -1
  27. package/dist/XSLTStyleJSONPathResolver.d.ts.map +1 -1
  28. package/dist/index-browser.d.ts +2 -2
  29. package/dist/index-browser.d.ts.map +1 -1
  30. package/dist/index-node.d.ts +2 -2
  31. package/dist/index-node.d.ts.map +1 -1
  32. package/dist/index.d.ts +126 -167
  33. package/dist/index.d.ts.map +1 -1
  34. package/docs/API.expanded.md +6 -4
  35. package/docs/API.md +1 -1
  36. package/docs/TO-DO.md +4 -2
  37. package/eslint.config.js +17 -1
  38. package/package.json +23 -22
  39. package/pnpm-workspace.yaml +32 -4
  40. package/rollup.config.js +42 -0
  41. package/src/AbstractJoiningTransformer.js +8 -1
  42. package/src/DOMJoiningTransformer.js +56 -27
  43. package/src/JSONJoiningTransformer.js +64 -44
  44. package/src/JSONPathTransformer.js +86 -85
  45. package/src/JSONPathTransformerContext.js +95 -48
  46. package/src/StringJoiningTransformer.js +48 -23
  47. package/src/XPathTransformer.js +18 -14
  48. package/src/XPathTransformerContext.js +173 -123
  49. package/src/index-browser.js +1 -0
  50. package/src/index-node.js +2 -0
  51. package/src/index.js +125 -68
  52. package/test.html +17 -0
  53. package/test.js +45 -0
  54. package/tsconfig-prod.json +1 -0
  55. package/tsconfig.json +3 -2
  56. package/dist/types.d.ts +0 -204
  57. package/dist/types.d.ts.map +0 -1
package/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # jtlt CHANGES
2
2
 
3
+ ## 0.13.0
4
+
5
+ - fix(types): more precise typing
6
+ - chore: update deps and devDeps
7
+
3
8
  ## 0.12.0
4
9
 
5
10
  - feat: allow `sequence` for this.function
package/README.md CHANGED
@@ -198,7 +198,7 @@ const data = {
198
198
  ]
199
199
  };
200
200
 
201
- const jtlt = new JTLT({
201
+ const jtlt = JTLT.create({
202
202
  data,
203
203
  outputType: 'json', // Top-level result will be a JSON array
204
204
  // forQuery mirrors: this.forEach(select, cb)
@@ -274,7 +274,7 @@ const templates = [
274
274
  }}
275
275
  ];
276
276
 
277
- const out = new JTLT({data, templates, outputType: 'string'}).
277
+ const out = JTLT.create({data, templates, outputType: 'string'}).
278
278
  transform('html');
279
279
 
280
280
  // -> <ul><li>Brave New</li><li>Cobalt</li><li>Delta</li></ul>
@@ -333,7 +333,9 @@ const templates = [
333
333
  }}
334
334
  ];
335
335
 
336
- const out = new JTLT({data, templates, outputType: 'string'}).transform('html');
336
+ const out = JTLT.create({
337
+ data, templates, outputType: 'string'
338
+ }).transform('html');
337
339
  // -> <ul><li>Bob — Keyboard</li><li>Alice — Mouse</li></ul>
338
340
  console.log(out);
339
341
  ```
@@ -381,7 +383,9 @@ const templates = [
381
383
  }}
382
384
  ];
383
385
 
384
- const out = new JTLT({data, templates, outputType: 'string'}).transform('html');
386
+ const out = JTLT.create({
387
+ data, templates, outputType: 'string'
388
+ }).transform('html');
385
389
  // -> <ul><li>Bob: Keyboard</li></ul>
386
390
  console.log(out);
387
391
  ```
@@ -426,4 +430,4 @@ from XSLT):
426
430
 
427
431
  ## To-dos
428
432
 
429
- See [TO-DO](./docs/TO.DO.md).
433
+ See [TO-DO](./docs/TO-DO.md).
@@ -6,12 +6,12 @@
6
6
  * instead of having to receive them as function parameters.
7
7
  */
8
8
 
9
- /* eslint-disable no-console, no-new -- Demo file */
9
+ /* eslint-disable no-console -- Demo file */
10
10
 
11
11
  import JTLT from '../src/index-node.js';
12
12
 
13
13
  console.log('=== Demo 1: Named parameters ===');
14
- new JTLT({
14
+ JTLT.create({
15
15
  data: {
16
16
  users: [
17
17
  {name: 'Alice', role: 'Admin'},
@@ -23,16 +23,20 @@ new JTLT({
23
23
  {
24
24
  path: '$',
25
25
  template () {
26
- this.forEach('$.users[*]', function (user) {
27
- this.callTemplate({
28
- name: 'formatUser',
29
- withParam: [
30
- {name: 'userName', value: user.name},
31
- {name: 'userRole', value: user.role},
32
- {name: 'prefix', value: '> '}
33
- ]
34
- });
35
- });
26
+ this.forEach(
27
+ '$.users[*]',
28
+ function (usr) {
29
+ const user = /** @type {{name: string, role: string}} */ (usr);
30
+ this.callTemplate({
31
+ name: 'formatUser',
32
+ withParam: [
33
+ {name: 'userName', value: user.name},
34
+ {name: 'userRole', value: user.role},
35
+ {name: 'prefix', value: '> '}
36
+ ]
37
+ });
38
+ }
39
+ );
36
40
  }
37
41
  },
38
42
  {
@@ -54,7 +58,7 @@ new JTLT({
54
58
  });
55
59
 
56
60
  console.log('=== Demo 2: Indexed parameters (no names) ===');
57
- new JTLT({
61
+ JTLT.create({
58
62
  data: {value: 'Test'},
59
63
  outputType: 'string',
60
64
  templates: [
@@ -92,7 +96,7 @@ new JTLT({
92
96
  });
93
97
 
94
98
  console.log('=== Demo 3: Nested callTemplate ===');
95
- new JTLT({
99
+ JTLT.create({
96
100
  data: {company: 'ACME Corp'},
97
101
  outputType: 'string',
98
102
  templates: [
@@ -115,7 +119,7 @@ new JTLT({
115
119
  this.string('\n');
116
120
 
117
121
  // Call another template from within
118
- /** @type {any} */ (this).callTemplate({
122
+ this.callTemplate({
119
123
  name: 'inner',
120
124
  withParam: [
121
125
  {name: 'message', value: 'Nested template call'}
@@ -6063,10 +6063,18 @@ class SelectionRange {
6063
6063
  /**
6064
6064
  The upper boundary of the range.
6065
6065
  */
6066
- to, flags) {
6066
+ to, flags,
6067
+ /**
6068
+ The goal column (stored vertical offset) associated with a
6069
+ cursor. This is used to preserve the vertical position when
6070
+ [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
6071
+ lines of different length.
6072
+ */
6073
+ goalColumn) {
6067
6074
  this.from = from;
6068
6075
  this.to = to;
6069
6076
  this.flags = flags;
6077
+ this.goalColumn = goalColumn;
6070
6078
  }
6071
6079
  /**
6072
6080
  The anchor of the range—the side that doesn't move when you
@@ -6090,6 +6098,16 @@ class SelectionRange {
6090
6098
  */
6091
6099
  get assoc() { return this.flags & 8 /* RangeFlag.AssocBefore */ ? -1 : this.flags & 16 /* RangeFlag.AssocAfter */ ? 1 : 0; }
6092
6100
  /**
6101
+ A flag that, when set, makes some selection-extending commands
6102
+ treat the range's head and anchor as exchangeable, so that for
6103
+ example Shift-ArrowUp will make the lower side of the selection
6104
+ the anchor, even if that was the head before. Used to implement
6105
+ MacOS-style undirectional selections.
6106
+ */
6107
+ get undirectional() {
6108
+ return (this.flags & 64 /* RangeFlag.Undirectional */) > 0;
6109
+ }
6110
+ /**
6093
6111
  The bidirectional text level associated with this cursor, if
6094
6112
  any.
6095
6113
  */
@@ -6098,16 +6116,6 @@ class SelectionRange {
6098
6116
  return level == 7 ? null : level;
6099
6117
  }
6100
6118
  /**
6101
- The goal column (stored vertical offset) associated with a
6102
- cursor. This is used to preserve the vertical position when
6103
- [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
6104
- lines of different length.
6105
- */
6106
- get goalColumn() {
6107
- let value = this.flags >> 6 /* RangeFlag.GoalColumnOffset */;
6108
- return value == 16777215 /* RangeFlag.NoGoalColumn */ ? undefined : value;
6109
- }
6110
- /**
6111
6119
  Map this range through a change, producing a valid range in the
6112
6120
  updated document.
6113
6121
  */
@@ -6120,22 +6128,22 @@ class SelectionRange {
6120
6128
  from = change.mapPos(this.from, 1);
6121
6129
  to = change.mapPos(this.to, -1);
6122
6130
  }
6123
- return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags);
6131
+ return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags, this.goalColumn);
6124
6132
  }
6125
6133
  /**
6126
6134
  Extend this range to cover at least `from` to `to`.
6127
6135
  */
6128
- extend(from, to = from) {
6136
+ extend(from, to = from, assoc = 0) {
6129
6137
  if (from <= this.anchor && to >= this.anchor)
6130
- return EditorSelection.range(from, to);
6138
+ return EditorSelection.range(from, to, undefined, undefined, assoc);
6131
6139
  let head = Math.abs(from - this.anchor) > Math.abs(to - this.anchor) ? from : to;
6132
- return EditorSelection.range(this.anchor, head);
6140
+ return EditorSelection.range(this.anchor, head, undefined, undefined, assoc);
6133
6141
  }
6134
6142
  /**
6135
6143
  Compare this range to another range.
6136
6144
  */
6137
6145
  eq(other, includeAssoc = false) {
6138
- return this.anchor == other.anchor && this.head == other.head &&
6146
+ return this.anchor == other.anchor && this.head == other.head && this.goalColumn == other.goalColumn &&
6139
6147
  (!includeAssoc || !this.empty || this.assoc == other.assoc);
6140
6148
  }
6141
6149
  /**
@@ -6154,8 +6162,8 @@ class SelectionRange {
6154
6162
  /**
6155
6163
  @internal
6156
6164
  */
6157
- static create(from, to, flags) {
6158
- return new SelectionRange(from, to, flags);
6165
+ static create(from, to, flags, goalColumn) {
6166
+ return new SelectionRange(from, to, flags, goalColumn);
6159
6167
  }
6160
6168
  }
6161
6169
  /**
@@ -6270,17 +6278,26 @@ class EditorSelection {
6270
6278
  */
6271
6279
  static cursor(pos, assoc = 0, bidiLevel, goalColumn) {
6272
6280
  return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 8 /* RangeFlag.AssocBefore */ : 16 /* RangeFlag.AssocAfter */) |
6273
- (bidiLevel == null ? 7 : Math.min(6, bidiLevel)) |
6274
- ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215 /* RangeFlag.NoGoalColumn */) << 6 /* RangeFlag.GoalColumnOffset */));
6281
+ (bidiLevel == null ? 7 : Math.min(6, bidiLevel)), goalColumn);
6275
6282
  }
6276
6283
  /**
6277
6284
  Create a selection range.
6278
6285
  */
6279
- static range(anchor, head, goalColumn, bidiLevel) {
6280
- let flags = ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215 /* RangeFlag.NoGoalColumn */) << 6 /* RangeFlag.GoalColumnOffset */) |
6281
- (bidiLevel == null ? 7 : Math.min(6, bidiLevel));
6282
- return head < anchor ? SelectionRange.create(head, anchor, 32 /* RangeFlag.Inverted */ | 16 /* RangeFlag.AssocAfter */ | flags)
6283
- : SelectionRange.create(anchor, head, (head > anchor ? 8 /* RangeFlag.AssocBefore */ : 0) | flags);
6286
+ static range(anchor, head, goalColumn, bidiLevel, assoc) {
6287
+ let flags = bidiLevel == null ? 7 : Math.min(6, bidiLevel);
6288
+ if (!assoc && anchor != head)
6289
+ assoc = head < anchor ? 1 : -1;
6290
+ if (assoc)
6291
+ flags |= assoc < 0 ? 8 /* RangeFlag.AssocBefore */ : 16 /* RangeFlag.AssocAfter */;
6292
+ return head < anchor ? SelectionRange.create(head, anchor, flags | 32 /* RangeFlag.Inverted */, goalColumn)
6293
+ : SelectionRange.create(anchor, head, flags, goalColumn);
6294
+ }
6295
+ /**
6296
+ Create an [undirectional](https://codemirror.net/6/docs/ref/#state.SelectionRange.undirectional)
6297
+ selection range.
6298
+ */
6299
+ static undirectionalRange(from, to) {
6300
+ return SelectionRange.create(from, to, 64 /* RangeFlag.Undirectional */, undefined);
6284
6301
  }
6285
6302
  /**
6286
6303
  @internal
@@ -6452,6 +6469,7 @@ class FacetProvider {
6452
6469
  }
6453
6470
  };
6454
6471
  }
6472
+ get extension() { return this; }
6455
6473
  }
6456
6474
  function compareArray(a, b, compare) {
6457
6475
  if (a.length != b.length)
@@ -6649,6 +6667,7 @@ class PrecExtension {
6649
6667
  this.inner = inner;
6650
6668
  this.prec = prec;
6651
6669
  }
6670
+ get extension() { return this; }
6652
6671
  }
6653
6672
  /**
6654
6673
  Extension compartments can be used to make a configuration
@@ -6683,6 +6702,7 @@ class CompartmentInstance {
6683
6702
  this.compartment = compartment;
6684
6703
  this.inner = inner;
6685
6704
  }
6705
+ get extension() { return this; }
6686
6706
  }
6687
6707
  class Configuration {
6688
6708
  constructor(base, compartments, dynamicSlots, address, staticValues, facets) {
@@ -6792,6 +6812,8 @@ function flatten(extension, compartments, newCompartments) {
6792
6812
  else {
6793
6813
  let content = ext.extension;
6794
6814
  if (!content)
6815
+ throw new Error(`Unrecognized extension value in extension set (${ext}).`);
6816
+ if (content == ext)
6795
6817
  throw new Error(`Unrecognized extension value in extension set (${ext}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);
6796
6818
  inner(content, prec);
6797
6819
  }
@@ -7624,7 +7646,8 @@ class EditorState {
7624
7646
  - Other (anything else)
7625
7647
  */
7626
7648
  charCategorizer(at) {
7627
- return makeCategorizer(this.languageDataAt("wordChars", at).join(""));
7649
+ let chars = this.languageDataAt("wordChars", at);
7650
+ return makeCategorizer(chars.length ? chars[0] : "");
7628
7651
  }
7629
7652
  /**
7630
7653
  Find the word at the given position, meaning the range
@@ -7810,6 +7833,9 @@ class RangeValue {
7810
7833
  RangeValue.prototype.startSide = RangeValue.prototype.endSide = 0;
7811
7834
  RangeValue.prototype.point = false;
7812
7835
  RangeValue.prototype.mapMode = MapMode.TrackDel;
7836
+ function cmpVal(a, b) {
7837
+ return a == b || a.constructor == b.constructor && a.eq(b);
7838
+ }
7813
7839
  /**
7814
7840
  A range associates a value with a range of positions.
7815
7841
  */
@@ -8116,7 +8142,7 @@ class RangeSet {
8116
8142
  for (;;) {
8117
8143
  if (sideA.to != sideB.to ||
8118
8144
  !sameValues(sideA.active, sideB.active) ||
8119
- sideA.point && (!sideB.point || !sideA.point.eq(sideB.point)))
8145
+ sideA.point && (!sideB.point || !cmpVal(sideA.point, sideB.point)))
8120
8146
  return false;
8121
8147
  if (sideA.to > to)
8122
8148
  return true;
@@ -8591,22 +8617,27 @@ function compare(a, startA, b, startB, length, comparator) {
8591
8617
  b.goto(startB);
8592
8618
  let endB = startB + length;
8593
8619
  let pos = startB, dPos = startB - startA;
8594
- for (;;) {
8620
+ let bounds = !!comparator.boundChange;
8621
+ for (let boundChange = false;;) {
8595
8622
  let dEnd = (a.to + dPos) - b.to, diff = dEnd || a.endSide - b.endSide;
8596
8623
  let end = diff < 0 ? a.to + dPos : b.to, clipEnd = Math.min(end, endB);
8597
- if (a.point || b.point) {
8598
- if (!(a.point && b.point && (a.point == b.point || a.point.eq(b.point)) &&
8624
+ let point = a.point || b.point;
8625
+ if (point) {
8626
+ if (!(a.point && b.point && cmpVal(a.point, b.point) &&
8599
8627
  sameValues(a.activeForPoint(a.to), b.activeForPoint(b.to))))
8600
8628
  comparator.comparePoint(pos, clipEnd, a.point, b.point);
8629
+ boundChange = false;
8601
8630
  }
8602
8631
  else {
8632
+ if (boundChange)
8633
+ comparator.boundChange(pos);
8603
8634
  if (clipEnd > pos && !sameValues(a.active, b.active))
8604
8635
  comparator.compareRange(pos, clipEnd, a.active, b.active);
8636
+ if (bounds && clipEnd < endB && (dEnd || a.openEnd(end) != b.openEnd(end)))
8637
+ boundChange = true;
8605
8638
  }
8606
8639
  if (end > endB)
8607
8640
  break;
8608
- if ((dEnd || a.openEnd != b.openEnd) && comparator.boundChange)
8609
- comparator.boundChange(end);
8610
8641
  pos = end;
8611
8642
  if (diff <= 0)
8612
8643
  a.next();
@@ -8618,7 +8649,7 @@ function sameValues(a, b) {
8618
8649
  if (a.length != b.length)
8619
8650
  return false;
8620
8651
  for (let i = 0; i < a.length; i++)
8621
- if (a[i] != b[i] && !a[i].eq(b[i]))
8652
+ if (a[i] != b[i] && !cmpVal(a[i], b[i]))
8622
8653
  return false;
8623
8654
  return true;
8624
8655
  }
@@ -20315,7 +20346,7 @@ Language.setState = /*@__PURE__*/StateEffect.define();
20315
20346
  function topNodeAt(state, pos, side) {
20316
20347
  let topLang = state.facet(language), tree = syntaxTree(state).topNode;
20317
20348
  if (!topLang || topLang.allowsNesting) {
20318
- for (let node = tree; node; node = node.enter(pos, side, IterMode.ExcludeBuffers))
20349
+ for (let node = tree; node; node = node.enter(pos, side, IterMode.ExcludeBuffers | IterMode.EnterBracketed))
20319
20350
  if (node.type.isTop)
20320
20351
  tree = node;
20321
20352
  }
@@ -20323,8 +20354,7 @@ function topNodeAt(state, pos, side) {
20323
20354
  }
20324
20355
  /**
20325
20356
  A subclass of [`Language`](https://codemirror.net/6/docs/ref/#language.Language) for use with Lezer
20326
- [LR parsers](https://lezer.codemirror.net/docs/ref#lr.LRParser)
20327
- parsers.
20357
+ [LR parsers](https://lezer.codemirror.net/docs/ref#lr.LRParser).
20328
20358
  */
20329
20359
  class LRLanguage extends Language {
20330
20360
  constructor(data, parser, name) {
@@ -21316,18 +21346,25 @@ const foldState = /*@__PURE__*/StateField.define({
21316
21346
  if (tr.isUserEvent("delete"))
21317
21347
  tr.changes.iterChangedRanges((fromA, toA) => folded = clearTouchedFolds(folded, fromA, toA));
21318
21348
  folded = folded.map(tr.changes);
21349
+ let rangesToFold = [];
21319
21350
  for (let e of tr.effects) {
21320
21351
  if (e.is(foldEffect) && !foldExists(folded, e.value.from, e.value.to)) {
21321
- let { preparePlaceholder } = tr.state.facet(foldConfig);
21322
- let widget = !preparePlaceholder ? foldWidget :
21323
- Decoration.replace({ widget: new PreparedFoldWidget(preparePlaceholder(tr.state, e.value)) });
21324
- folded = folded.update({ add: [widget.range(e.value.from, e.value.to)] });
21352
+ rangesToFold.push(e.value);
21325
21353
  }
21326
21354
  else if (e.is(unfoldEffect)) {
21327
21355
  folded = folded.update({ filter: (from, to) => e.value.from != from || e.value.to != to,
21328
21356
  filterFrom: e.value.from, filterTo: e.value.to });
21329
21357
  }
21330
21358
  }
21359
+ if (rangesToFold.length) {
21360
+ let { preparePlaceholder } = tr.state.facet(foldConfig);
21361
+ let decorations = rangesToFold.map(value => {
21362
+ let widget = !preparePlaceholder ? foldWidget :
21363
+ Decoration.replace({ widget: new PreparedFoldWidget(preparePlaceholder(tr.state, value)) });
21364
+ return widget.range(value.from, value.to);
21365
+ });
21366
+ folded = folded.update({ add: decorations });
21367
+ }
21331
21368
  // Clear folded ranges that cover the selection head
21332
21369
  if (tr.selection)
21333
21370
  folded = clearTouchedFolds(folded, tr.selection.main.head);
@@ -21608,7 +21645,7 @@ const baseTheme$1$1 = /*@__PURE__*/EditorView.baseTheme({
21608
21645
  });
21609
21646
 
21610
21647
  /**
21611
- A highlight style associates CSS styles with higlighting
21648
+ A highlight style associates CSS styles with highlighting
21612
21649
  [tags](https://lezer.codemirror.net/docs/ref#highlight.Tag).
21613
21650
  */
21614
21651
  class HighlightStyle {
@@ -21643,7 +21680,7 @@ class HighlightStyle {
21643
21680
  or array of tags in their `tag` property, and either a single
21644
21681
  `class` property providing a static CSS class (for highlighter
21645
21682
  that rely on external styling), or a
21646
- [`style-mod`](https://github.com/marijnh/style-mod#documentation)-style
21683
+ [`style-mod`](https://code.haverbeke.berlin/marijn/style-mod#documentation)-style
21647
21684
  set of CSS properties (which define the styling for those tags).
21648
21685
 
21649
21686
  The CSS rules created for a highlighter will be emitted in the
@@ -21793,30 +21830,44 @@ function defaultRenderMatch(match) {
21793
21830
  decorations.push(mark.range(match.end.from, match.end.to));
21794
21831
  return decorations;
21795
21832
  }
21796
- const bracketMatchingState = /*@__PURE__*/StateField.define({
21797
- create() { return Decoration.none; },
21798
- update(deco, tr) {
21799
- if (!tr.docChanged && !tr.selection)
21800
- return deco;
21801
- let decorations = [];
21802
- let config = tr.state.facet(bracketMatchingConfig);
21803
- for (let range of tr.state.selection.ranges) {
21804
- if (!range.empty)
21805
- continue;
21806
- let match = matchBrackets(tr.state, range.head, -1, config)
21807
- || (range.head > 0 && matchBrackets(tr.state, range.head - 1, 1, config))
21808
- || (config.afterCursor &&
21809
- (matchBrackets(tr.state, range.head, 1, config) ||
21810
- (range.head < tr.state.doc.length && matchBrackets(tr.state, range.head + 1, -1, config))));
21811
- if (match)
21812
- decorations = decorations.concat(config.renderMatch(match, tr.state));
21813
- }
21814
- return Decoration.set(decorations, true);
21815
- },
21816
- provide: f => EditorView.decorations.from(f)
21833
+ function bracketDeco(state) {
21834
+ let decorations = [];
21835
+ let config = state.facet(bracketMatchingConfig);
21836
+ for (let range of state.selection.ranges) {
21837
+ if (!range.empty)
21838
+ continue;
21839
+ let match = matchBrackets(state, range.head, -1, config)
21840
+ || (range.head > 0 && matchBrackets(state, range.head - 1, 1, config))
21841
+ || (config.afterCursor &&
21842
+ (matchBrackets(state, range.head, 1, config) ||
21843
+ (range.head < state.doc.length && matchBrackets(state, range.head + 1, -1, config))));
21844
+ if (match)
21845
+ decorations = decorations.concat(config.renderMatch(match, state));
21846
+ }
21847
+ return Decoration.set(decorations, true);
21848
+ }
21849
+ const bracketMatcher = /*@__PURE__*/ViewPlugin.fromClass(class {
21850
+ constructor(view) {
21851
+ this.paused = false;
21852
+ this.decorations = bracketDeco(view.state);
21853
+ }
21854
+ update(update) {
21855
+ if (update.docChanged || update.selectionSet || this.paused) {
21856
+ if (update.view.composing) {
21857
+ this.decorations = this.decorations.map(update.changes);
21858
+ this.paused = true;
21859
+ }
21860
+ else {
21861
+ this.decorations = bracketDeco(update.state);
21862
+ this.paused = false;
21863
+ }
21864
+ }
21865
+ }
21866
+ }, {
21867
+ decorations: v => v.decorations
21817
21868
  });
21818
21869
  const bracketMatchingUnique = [
21819
- bracketMatchingState,
21870
+ bracketMatcher,
21820
21871
  baseTheme$4
21821
21872
  ];
21822
21873
  /**
@@ -21900,6 +21951,8 @@ function matchMarkedBrackets(_state, _pos, dir, token, handle, matching, bracket
21900
21951
  return { start: firstToken, matched: false };
21901
21952
  }
21902
21953
  function matchPlainBrackets(state, pos, dir, tree, tokenType, maxScanDistance, brackets) {
21954
+ if (dir < 0 ? !pos : pos == state.doc.length)
21955
+ return null;
21903
21956
  let startCh = dir < 0 ? state.sliceDoc(pos - 1, pos) : state.sliceDoc(pos, pos + 1);
21904
21957
  let bracket = brackets.indexOf(startCh);
21905
21958
  if (bracket < 0 || (bracket % 2 == 0) != (dir > 0))
@@ -24154,7 +24207,21 @@ const javascriptLanguage = /*@__PURE__*/LRLanguage.define({
24154
24207
  }),
24155
24208
  /*@__PURE__*/foldNodeProp.add({
24156
24209
  "Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType": foldInside,
24157
- BlockComment(tree) { return { from: tree.from + 2, to: tree.to - 2 }; }
24210
+ BlockComment(tree) { return { from: tree.from + 2, to: tree.to - 2 }; },
24211
+ JSXElement(tree) {
24212
+ let open = tree.firstChild;
24213
+ if (!open || open.name == "JSXSelfClosingTag")
24214
+ return null;
24215
+ let close = tree.lastChild;
24216
+ return { from: open.to, to: close.type.isError ? tree.to : close.from };
24217
+ },
24218
+ "JSXSelfClosingTag JSXOpenTag"(tree) {
24219
+ var _a;
24220
+ let name = (_a = tree.firstChild) === null || _a === void 0 ? void 0 : _a.nextSibling, close = tree.lastChild;
24221
+ if (!name || name.type.isError)
24222
+ return null;
24223
+ return { from: name.to, to: close.type.isError ? tree.to : close.from };
24224
+ }
24158
24225
  })
24159
24226
  ]
24160
24227
  }),
@@ -28177,13 +28244,16 @@ function editorFromTextArea (textarea, extensions, inputHandler) {
28177
28244
  doc: val ?? textarea.value,
28178
28245
  extensions: [
28179
28246
  basicSetup,
28247
+ syntaxHighlighting(defaultHighlightStyle, {fallback: true}),
28180
28248
  EditorView.updateListener.of((viewUpdate) => {
28181
28249
  // Check if the document content has changed
28182
- if (viewUpdate.docChanged) {
28183
- const newContent = viewUpdate.state.doc.toString();
28184
- inputHandler(newContent);
28185
- // You can perform actions here based on the new content
28250
+ if (!viewUpdate.docChanged) {
28251
+ return;
28186
28252
  }
28253
+
28254
+ const newContent = viewUpdate.state.doc.toString();
28255
+ inputHandler(newContent);
28256
+ // You can perform actions here based on the new content
28187
28257
  }),
28188
28258
  ...(extensions.javascript ? [javascript(extensions.javascript)] : []),
28189
28259
  ...(extensions.xml ? [xml(extensions.xml)] : []),
@@ -28200,7 +28270,7 @@ function editorFromTextArea (textarea, extensions, inputHandler) {
28200
28270
  const prevLang = /** @type {HTMLElement} */ (
28201
28271
  textarea.previousElementSibling.querySelector('.cm-content')
28202
28272
  ).dataset.language;
28203
- if (prevLang && prevLang in extensions) {
28273
+ if (prevLang && Object.hasOwn(extensions, prevLang)) {
28204
28274
  // console.log('same language');
28205
28275
  return view;
28206
28276
  }
@@ -1,5 +1,6 @@
1
1
  import {javascript} from '@codemirror/lang-javascript';
2
2
  import {EditorView, basicSetup} from 'codemirror';
3
+ import {syntaxHighlighting, defaultHighlightStyle} from '@codemirror/language';
3
4
  import {xml} from '@codemirror/lang-xml';
4
5
  import {json} from '@codemirror/lang-json';
5
6
 
@@ -31,13 +32,16 @@ export function editorFromTextArea (textarea, extensions, inputHandler) {
31
32
  doc: val ?? textarea.value,
32
33
  extensions: [
33
34
  basicSetup,
35
+ syntaxHighlighting(defaultHighlightStyle, {fallback: true}),
34
36
  EditorView.updateListener.of((viewUpdate) => {
35
37
  // Check if the document content has changed
36
- if (viewUpdate.docChanged) {
37
- const newContent = viewUpdate.state.doc.toString();
38
- inputHandler(newContent);
39
- // You can perform actions here based on the new content
38
+ if (!viewUpdate.docChanged) {
39
+ return;
40
40
  }
41
+
42
+ const newContent = viewUpdate.state.doc.toString();
43
+ inputHandler(newContent);
44
+ // You can perform actions here based on the new content
41
45
  }),
42
46
  ...(extensions.javascript ? [javascript(extensions.javascript)] : []),
43
47
  ...(extensions.xml ? [xml(extensions.xml)] : []),
@@ -54,7 +58,7 @@ export function editorFromTextArea (textarea, extensions, inputHandler) {
54
58
  const prevLang = /** @type {HTMLElement} */ (
55
59
  textarea.previousElementSibling.querySelector('.cm-content')
56
60
  ).dataset.language;
57
- if (prevLang && prevLang in extensions) {
61
+ if (prevLang && Object.hasOwn(extensions, prevLang)) {
58
62
  // console.log('same language');
59
63
  return view;
60
64
  }
package/demo/index.js CHANGED
@@ -40,7 +40,8 @@ async function processTemplates () {
40
40
  // Firefox
41
41
  (data.documentElement.localName === 'parsererror' &&
42
42
  data.documentElement.namespaceURI ===
43
- // eslint-disable-next-line sonarjs/no-clear-text-protocols -- Namespace
43
+ // eslint-disable-next-line @stylistic/max-len -- Long
44
+ // eslint-disable-next-line sonarjs/no-clear-text-protocols, unicorn/prefer-https -- Namespace
44
45
  'http://www.mozilla.org/newlayout/xml/parsererror.xml') ||
45
46
  // Chrome
46
47
  data.querySelector('parsererror')