@douyinfe/semi-json-viewer-core 2.86.0-beta.0 → 2.87.0-alpha.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 (2) hide show
  1. package/lib/index.js +43 -44
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -24,17 +24,17 @@ function createTokenizationSupport(supportComments) {
24
24
  tokenize: (line, state) => tokenize(supportComments, line, state)
25
25
  };
26
26
  }
27
- var TOKEN_DELIM_OBJECT = "semi-json-viewer-delimiter-bracket";
28
- var TOKEN_DELIM_ARRAY = "semi-json-viewer-delimiter-array";
29
- var TOKEN_DELIM_COLON = "semi-json-viewer-delimiter-colon";
30
- var TOKEN_DELIM_COMMA = "semi-json-viewer-delimiter-comma";
31
- var TOKEN_VALUE_BOOLEAN = "semi-json-viewer-keyword";
32
- var TOKEN_VALUE_NULL = "semi-json-viewer-keyword";
33
- var TOKEN_VALUE_STRING = "semi-json-viewer-string-value";
34
- var TOKEN_VALUE_NUMBER = "semi-json-viewer-number";
35
- var TOKEN_PROPERTY_NAME = "semi-json-viewer-string-key";
36
- var TOKEN_COMMENT_BLOCK = "semi-json-viewer-comment-block";
37
- var TOKEN_COMMENT_LINE = "semi-json-viewer-comment-line";
27
+ var TOKEN_DELIM_OBJECT = "delimiter-bracket";
28
+ var TOKEN_DELIM_ARRAY = "delimiter-array";
29
+ var TOKEN_DELIM_COLON = "delimiter-colon";
30
+ var TOKEN_DELIM_COMMA = "delimiter-comma";
31
+ var TOKEN_VALUE_BOOLEAN = "keyword";
32
+ var TOKEN_VALUE_NULL = "keyword";
33
+ var TOKEN_VALUE_STRING = "string-value";
34
+ var TOKEN_VALUE_NUMBER = "number";
35
+ var TOKEN_PROPERTY_NAME = "string-key";
36
+ var TOKEN_COMMENT_BLOCK = "comment-block";
37
+ var TOKEN_COMMENT_LINE = "comment-line";
38
38
  var ParentsStack = class _ParentsStack {
39
39
  constructor(parent, type, depth) {
40
40
  this.parent = parent;
@@ -422,7 +422,7 @@ var SelectionModel = class {
422
422
  if (!node) return { row, col };
423
423
  let lineElement;
424
424
  if (node instanceof HTMLElement) {
425
- lineElement = node.closest(".semi-json-viewer-view-line");
425
+ lineElement = node.closest(`.${this._view.prefixCls}-view-line`);
426
426
  } else {
427
427
  lineElement = getLineElement(node);
428
428
  if (!lineElement) return { row, col };
@@ -1172,6 +1172,7 @@ var FoldingModel = class {
1172
1172
  return this._hiddenRangeModel.isHiddenLine(lineNumber);
1173
1173
  }
1174
1174
  isFoldable(lineNumber) {
1175
+ if (!this._regions) return false;
1175
1176
  const index = this._regions.findRange(lineNumber);
1176
1177
  const region = this._regions.toRegion(index);
1177
1178
  return region && region.startLineNumber === lineNumber;
@@ -1728,7 +1729,8 @@ var EditWidget = class {
1728
1729
  const startOffset = this._jsonModel.getOffsetAt(startRow, startCol);
1729
1730
  const endOffset = this._jsonModel.getOffsetAt(endRow, endCol);
1730
1731
  const op = this.buildBaseOperation();
1731
- switch (e.key) {
1732
+ const isCtrl = e.ctrlKey || e.metaKey;
1733
+ switch (e.code) {
1732
1734
  case "Tab":
1733
1735
  if (this._view.completeWidget.isVisible) {
1734
1736
  e.preventDefault();
@@ -1748,8 +1750,8 @@ var EditWidget = class {
1748
1750
  op.newText = insertText;
1749
1751
  this._jsonModel.applyOperation(op);
1750
1752
  break;
1751
- case "f":
1752
- if (e.shiftKey && e.metaKey) {
1753
+ case "KeyF":
1754
+ if (e.shiftKey && isCtrl) {
1753
1755
  e.preventDefault();
1754
1756
  this.format();
1755
1757
  }
@@ -1773,28 +1775,23 @@ var EditWidget = class {
1773
1775
  this._view.completeWidget._handleKeyDown(e);
1774
1776
  }
1775
1777
  break;
1776
- case "a":
1777
- if (e.metaKey) {
1778
- this._selectionModel.isSelectedAll = true;
1779
- }
1778
+ case "KeyA":
1779
+ isCtrl && (this._selectionModel.isSelectedAll = true);
1780
1780
  break;
1781
- case "x":
1782
- if (e.metaKey) {
1783
- e.preventDefault();
1784
- this._cutHandler();
1785
- }
1781
+ case "KeyX":
1782
+ isCtrl && (e.preventDefault(), this._cutHandler());
1786
1783
  break;
1787
- case "z":
1788
- if (e.metaKey && !e.shiftKey) {
1784
+ case "KeyZ":
1785
+ if (isCtrl && !e.shiftKey) {
1789
1786
  e.preventDefault();
1790
1787
  this._jsonModel.undo();
1791
- } else if (e.metaKey && e.shiftKey) {
1788
+ } else if (isCtrl && e.shiftKey) {
1792
1789
  e.preventDefault();
1793
1790
  this._jsonModel.redo();
1794
1791
  }
1795
1792
  break;
1796
- case "c":
1797
- if (e.metaKey) {
1793
+ case "KeyC":
1794
+ if (isCtrl) {
1798
1795
  e.preventDefault();
1799
1796
  this._copyHandler();
1800
1797
  }
@@ -1880,7 +1877,7 @@ var FoldWidget = class {
1880
1877
  return svg;
1881
1878
  }
1882
1879
  _createFoldingIcon(lineNumber) {
1883
- const foldingIconClass = "semi-json-viewer-folding-icon";
1880
+ const foldingIconClass = `${this._view.prefixCls}-folding-icon`;
1884
1881
  const foldingIcon = elt("span", foldingIconClass);
1885
1882
  const isCollapsed = this._foldingModel.isCollapsed(lineNumber);
1886
1883
  foldingIcon.appendChild(this._createFoldSvg(isCollapsed));
@@ -1908,7 +1905,7 @@ var FoldWidget = class {
1908
1905
  return foldingIcon;
1909
1906
  }
1910
1907
  removeAllFoldingIcons() {
1911
- const foldingIconClass = "semi-json-viewer-folding-icon";
1908
+ const foldingIconClass = `${this._view.prefixCls}-folding-icon`;
1912
1909
  const foldingIcons = this._view.lineScrollDom.querySelectorAll(`.${foldingIconClass}`);
1913
1910
  foldingIcons.forEach((icon) => icon.remove());
1914
1911
  }
@@ -3769,7 +3766,7 @@ var CompleteWidget = class {
3769
3766
  return { x, y };
3770
3767
  }
3771
3768
  createCompleteContainer() {
3772
- const className = "semi-json-viewer-complete-container";
3769
+ const className = `${this._view.prefixCls}-complete-container`;
3773
3770
  const container = elt("div", className);
3774
3771
  setStyles(container, {
3775
3772
  display: "none"
@@ -3777,7 +3774,7 @@ var CompleteWidget = class {
3777
3774
  return container;
3778
3775
  }
3779
3776
  createSuggestionsContainer() {
3780
- const className = "semi-json-viewer-complete-suggestions-container";
3777
+ const className = `${this._view.prefixCls}-complete-suggestions-container`;
3781
3778
  const container = elt("div", className);
3782
3779
  setStyles(container, {
3783
3780
  maxHeight: "200px",
@@ -3838,7 +3835,7 @@ var CompleteWidget = class {
3838
3835
  this.hide();
3839
3836
  }
3840
3837
  _renderCompletions() {
3841
- const className = "semi-json-viewer-complete-suggestions-item";
3838
+ const className = `${this._view.prefixCls}-complete-suggestions-item`;
3842
3839
  this._suggestionsContainer.innerHTML = this._suggestions.map(
3843
3840
  (item, index) => `
3844
3841
  <li class="${className}" style="background-color: ${index === this._selectedIndex ? "var(--semi-color-fill-0)" : "transparent"}" data-index="${index}">
@@ -3977,7 +3974,7 @@ var ErrorWidget = class {
3977
3974
  const child = line.children[i];
3978
3975
  offset += child.textContent?.length || 0;
3979
3976
  if (offset > start.column && offset <= end.column) {
3980
- const className = "semi-json-viewer-error";
3977
+ const className = `${this._view.prefixCls}-error`;
3981
3978
  child.classList.add(className);
3982
3979
  }
3983
3980
  }
@@ -3990,6 +3987,7 @@ var ViewDOMBuilder = class {
3990
3987
  this._lineHeight = lineHeight;
3991
3988
  this._totalLines = totalLines;
3992
3989
  this._options = options;
3990
+ this.prefixCls = options?.prefixCls || "semi-json-viewer";
3993
3991
  }
3994
3992
  createRenderContainer() {
3995
3993
  const renderContainer = elt("div", "json-viewer-container");
@@ -4002,7 +4000,7 @@ var ViewDOMBuilder = class {
4002
4000
  return renderContainer;
4003
4001
  }
4004
4002
  createLineNumberContainer() {
4005
- const lineNumberClass = "semi-json-viewer-line-number-container";
4003
+ const lineNumberClass = `${this._options?.prefixCls}-line-number-container`;
4006
4004
  const lineNumberContainer = elt("div", lineNumberClass);
4007
4005
  setStyles(lineNumberContainer, {
4008
4006
  position: "absolute",
@@ -4013,7 +4011,7 @@ var ViewDOMBuilder = class {
4013
4011
  return lineNumberContainer;
4014
4012
  }
4015
4013
  createContentContainer() {
4016
- const contentClass = "semi-json-viewer-content-container";
4014
+ const contentClass = `${this.prefixCls}-content-container`;
4017
4015
  const contentContainer = elt("div", contentClass);
4018
4016
  setStyles(contentContainer, {
4019
4017
  position: "absolute",
@@ -4078,6 +4076,7 @@ var View = class {
4078
4076
  this._lineHeight = options?.lineHeight || 20;
4079
4077
  this._options = options;
4080
4078
  this._customRenderRule = options?.customRenderRule || null;
4079
+ this.prefixCls = options?.prefixCls || "semi-json-viewer";
4081
4080
  this._domBuilder = new ViewDOMBuilder(this._lineHeight, model.getLineCount(), options);
4082
4081
  this._jsonViewerDom = this._domBuilder.createRenderContainer();
4083
4082
  this._lineNumberDom = this._domBuilder.createLineNumberContainer();
@@ -4190,7 +4189,7 @@ var View = class {
4190
4189
  this.onScroll(scrollTop);
4191
4190
  }
4192
4191
  createLineNumberElement(actualLineNumber, visibleLineNumber) {
4193
- const lineNumberClass = "semi-json-viewer-line-number";
4192
+ const lineNumberClass = `${this.prefixCls}-line-number`;
4194
4193
  const lineNumberElement = elt("div", lineNumberClass);
4195
4194
  const rowDatum = this._scalingCellSizeAndPositionManager.getSizeAndPositionOfCell(visibleLineNumber);
4196
4195
  setStyles(lineNumberElement, {
@@ -4214,7 +4213,7 @@ var View = class {
4214
4213
  return lineNumberElement;
4215
4214
  }
4216
4215
  createLineContentElement(actualLineNumber, visibleLineNumber) {
4217
- const lineElementClass = "semi-json-viewer-view-line";
4216
+ const lineElementClass = `${this.prefixCls}-view-line`;
4218
4217
  const lineElement = elt("div", lineElementClass);
4219
4218
  lineElement.setAttribute("data-line-element", "true");
4220
4219
  const rowDatum = this._scalingCellSizeAndPositionManager.getSizeAndPositionOfCell(visibleLineNumber);
@@ -4357,7 +4356,7 @@ var View = class {
4357
4356
  continue;
4358
4357
  } else if (customElement !== null) {
4359
4358
  const span2 = document.createElement("span");
4360
- span2.className = token.scopes;
4359
+ span2.className = `${this.prefixCls}-${token.scopes}`;
4361
4360
  span2.textContent = content;
4362
4361
  container.appendChild(span2);
4363
4362
  this._customRenderMap.set(span2, customElement);
@@ -4365,7 +4364,7 @@ var View = class {
4365
4364
  }
4366
4365
  }
4367
4366
  const span = document.createElement("span");
4368
- span.className = token.scopes;
4367
+ span.className = `${this.prefixCls}-${token.scopes}`;
4369
4368
  span.textContent = content;
4370
4369
  if (!this._options?.autoWrap) {
4371
4370
  span.style.whiteSpace = "pre";
@@ -4385,7 +4384,7 @@ var View = class {
4385
4384
  if (startIndex >= content.length || endIndex <= 0) continue;
4386
4385
  if (startIndex > lastIndex) {
4387
4386
  const normalSpan = document.createElement("span");
4388
- normalSpan.className = tokenClass;
4387
+ normalSpan.className = `${this.prefixCls}-${tokenClass}`;
4389
4388
  normalSpan.textContent = content.substring(lastIndex, startIndex);
4390
4389
  container.appendChild(normalSpan);
4391
4390
  }
@@ -4393,7 +4392,7 @@ var View = class {
4393
4392
  highlightSpan.textContent = content.substring(startIndex, endIndex);
4394
4393
  const currentMatch = this._searchWidget.searchResults?.[this._searchWidget._currentResultIndex];
4395
4394
  const isCurrentMatch = match.range.startLineNumber === currentMatch?.range.startLineNumber && match.range.endLineNumber === currentMatch?.range.endLineNumber && match.range.startColumn === currentMatch?.range.startColumn && match.range.endColumn === currentMatch?.range.endColumn;
4396
- highlightSpan.className = `${tokenClass} semi-json-viewer-search-result${isCurrentMatch ? " semi-json-viewer-current-search-result" : ""}`;
4395
+ highlightSpan.className = `${this.prefixCls}-${tokenClass} ${this.prefixCls}-search-result${isCurrentMatch ? ` ${this.prefixCls}-current-search-result` : ""}`;
4397
4396
  highlightSpan.dataset.startColumn = match.range.startColumn.toString();
4398
4397
  highlightSpan.dataset.endColumn = match.range.endColumn.toString();
4399
4398
  container.appendChild(highlightSpan);
@@ -4401,7 +4400,7 @@ var View = class {
4401
4400
  }
4402
4401
  if (lastIndex < content.length) {
4403
4402
  const remainingSpan = document.createElement("span");
4404
- remainingSpan.className = tokenClass;
4403
+ remainingSpan.className = `${this.prefixCls}-${tokenClass}`;
4405
4404
  remainingSpan.textContent = content.substring(lastIndex);
4406
4405
  container.appendChild(remainingSpan);
4407
4406
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-json-viewer-core",
3
- "version": "2.86.0-beta.0",
3
+ "version": "2.87.0-alpha.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.js",
@@ -53,5 +53,5 @@
53
53
  ],
54
54
  "author": "",
55
55
  "license": "MIT",
56
- "gitHead": "2ace7125fcf788875cb7aea7baebbaf2fb6fbab3"
56
+ "gitHead": "9e089cce3cd8aff4b4c73e2ea0346fde3b19e8b6"
57
57
  }