@yltrcc/vditor 0.1.0 → 0.2.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/dist/index.css CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.1.0 - A markdown editor written in TypeScript.
2
+ * Vditor v0.2.0 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -25,7 +25,7 @@
25
25
  *
26
26
  */
27
27
  /*!
28
- * Vditor v0.1.0 - A markdown editor written in TypeScript.
28
+ * Vditor v0.2.0 - A markdown editor written in TypeScript.
29
29
  *
30
30
  * MIT License
31
31
  *
@@ -1400,19 +1400,57 @@
1400
1400
  position: relative;
1401
1401
  }
1402
1402
  .vditor-wysiwyg__block pre:first-child {
1403
- margin-bottom: -1em;
1404
1403
  display: none;
1404
+ position: relative;
1405
+ margin: 0;
1406
+ padding: 1em;
1407
+ background-color: rgba(0, 0, 0, 0.03);
1408
+ border-radius: 4px;
1409
+ overflow-x: auto;
1410
+ cursor: text;
1411
+ white-space: initial;
1412
+ min-height: 27px;
1413
+ background-size: 20px 20px;
1414
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8AgMAAABHkjHhAAAACVBMVEWAgIBaWlo+Pj7rTFvWAAAAA3RSTlMHCAw+VhR4AAAA+klEQVQoz4WSMW7EQAhFPxKWNh2FCx+HkaZI6RRb5DYbyVfIJXLKDCFoMbaTKSw/8ZnPAPjaH2xgZcUNUDADD7D9LtDBCLZ45fbkvo/30K8yeI64pPwl6znd/3n/Oe93P3ho9qeh72btTFzqkz0rsJle8Zr81OLEwZ1dv/713uWqvu2pl+k0fy7MWtj9r/tN5q/02z89qa/L4Dc2LvM93kezPfXlME/O86EbY/V9GB9ePX8G1/6W+/9h1dq/HGfTfzT3j/xNo7522Bfnqe5jO/fvhVthlfk434v3iO9zG/UOphyPeinPl1J8Gtaa7xPTa/Dk+RIs4deMvwGvcGsmsCvJ0AAAAABJRU5ErkJggg==);
1405
1415
  }
1406
1416
  .vditor-wysiwyg__block pre:first-child code {
1407
- color: var(--textarea-text-color);
1408
- height: auto;
1409
- text-align: left;
1417
+ margin: 0;
1418
+ font-family: var(--code-font-family);
1419
+ font-size: var(--code-font-size);
1420
+ line-height: var(--code-line-height);
1421
+ padding: 0;
1422
+ background-color: transparent !important;
1423
+ border-radius: 0;
1424
+ display: inline;
1425
+ overflow: visible;
1426
+ white-space: pre;
1427
+ word-break: initial;
1428
+ word-wrap: normal;
1429
+ }
1430
+ .vditor-wysiwyg__block pre:first-child::before {
1431
+ content: attr(data-language);
1432
+ position: absolute;
1433
+ top: 0;
1434
+ right: 0;
1435
+ padding: 2px 8px;
1436
+ font-size: 12px;
1437
+ color: var(--second-color);
1438
+ background-color: var(--panel-background-color);
1439
+ border-radius: 0 4px 0 4px;
1440
+ z-index: 1;
1441
+ }
1442
+ .vditor-wysiwyg__block pre:first-child:hover {
1443
+ box-shadow: 0 0 0 2px var(--blurColor);
1444
+ }
1445
+ .vditor-wysiwyg__block pre:first-child:focus {
1446
+ outline: none;
1410
1447
  }
1411
1448
  .vditor-wysiwyg__block pre:last-child {
1412
1449
  margin-bottom: 1em;
1413
1450
  }
1414
1451
  .vditor-wysiwyg__block--editing pre:first-child {
1415
1452
  display: block;
1453
+ margin: 0;
1416
1454
  }
1417
1455
  .vditor-wysiwyg__block--editing .vditor-wysiwyg__preview {
1418
1456
  display: none;
@@ -1434,6 +1472,7 @@
1434
1472
  font-family: var(--code-font-family);
1435
1473
  font-size: var(--code-font-size);
1436
1474
  line-height: var(--code-line-height);
1475
+ background-color: transparent !important;
1437
1476
  }
1438
1477
  .vditor-wysiwyg__preview::before {
1439
1478
  content: attr(data-language);
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.1.0 - A markdown editor written in TypeScript.
2
+ * Vditor v0.2.0 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -1267,7 +1267,7 @@ var looseJsonParse = function (text) {
1267
1267
  /* harmony export */ Y: () => (/* binding */ Constants),
1268
1268
  /* harmony export */ g: () => (/* binding */ _VDITOR_VERSION)
1269
1269
  /* harmony export */ });
1270
- var _VDITOR_VERSION = "0.1.0";
1270
+ var _VDITOR_VERSION = "0.2.0";
1271
1271
 
1272
1272
  var Constants = /** @class */ (function () {
1273
1273
  function Constants() {
@@ -1315,7 +1315,7 @@ var Constants = /** @class */ (function () {
1315
1315
  // 别名
1316
1316
  "js", "ts", "html", "toml", "c#", "bat"
1317
1317
  ];
1318
- Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.1.0");
1318
+ Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.2.0");
1319
1319
  Constants.MARKDOWN_OPTIONS = {
1320
1320
  autoSpace: false,
1321
1321
  gfmAutoLink: true,
@@ -7000,6 +7000,7 @@ var removeHeading = function (vditor) {
7000
7000
  ;// ./src/ts/wysiwyg/showCode.ts
7001
7001
 
7002
7002
 
7003
+
7003
7004
  /**
7004
7005
  * 显示代码编辑区域,隐藏预览区域
7005
7006
  * @param previewElement - 预览区域元素
@@ -7011,12 +7012,21 @@ var showCode = function (previewElement, vditor, first) {
7011
7012
  if (first === void 0) { first = true; }
7012
7013
  var blockElement = previewElement.parentElement;
7013
7014
  var codeElement = previewElement.previousElementSibling;
7014
- // 添加编辑状态类
7015
+ // 添加编辑状态类,通过 CSS 控制显示/隐藏
7015
7016
  blockElement.classList.add("vditor-wysiwyg__block--editing");
7017
+ // 移除内联样式,让 CSS 类控制显示
7018
+ codeElement.style.removeProperty("display");
7019
+ previewElement.style.removeProperty("display");
7020
+ // 将语言信息传递给编辑区域
7021
+ var language = previewElement.getAttribute("data-language") || "";
7022
+ codeElement.setAttribute("data-language", language);
7023
+ // 隐藏编辑时的多余工具栏
7024
+ if (vditor.wysiwyg.popover) {
7025
+ vditor.wysiwyg.popover.style.display = "none";
7026
+ }
7016
7027
  var range = codeElement.ownerDocument.createRange();
7017
7028
  if (codeElement.tagName === "CODE") {
7018
7029
  // 行内代码
7019
- codeElement.style.display = "inline-block";
7020
7030
  if (first) {
7021
7031
  range.setStart(codeElement.firstChild, 1);
7022
7032
  }
@@ -7026,7 +7036,6 @@ var showCode = function (previewElement, vditor, first) {
7026
7036
  }
7027
7037
  else {
7028
7038
  // 代码块
7029
- codeElement.style.display = "block";
7030
7039
  if (!codeElement.firstChild.firstChild) {
7031
7040
  codeElement.firstChild.appendChild(document.createTextNode(""));
7032
7041
  }
@@ -7050,17 +7059,36 @@ var showCode = function (previewElement, vditor, first) {
7050
7059
  * @param vditor - Vditor 实例
7051
7060
  */
7052
7061
  var hideCode = function (blockElement, vditor) {
7053
- // 移除编辑状态类
7062
+ // 移除编辑状态类,通过 CSS 控制显示/隐藏
7054
7063
  blockElement.classList.remove("vditor-wysiwyg__block--editing");
7055
7064
  var codeElement = blockElement.querySelector("pre:first-child");
7056
7065
  var previewElement = blockElement.querySelector(".vditor-wysiwyg__preview");
7066
+ // 移除内联样式,让 CSS 类控制显示
7057
7067
  if (codeElement) {
7058
- codeElement.style.display = "none";
7068
+ codeElement.style.removeProperty("display");
7059
7069
  }
7060
7070
  if (previewElement) {
7061
- previewElement.style.display = "block";
7071
+ previewElement.style.removeProperty("display");
7072
+ // 从编辑区域获取代码内容
7073
+ // 编辑区域结构: <pre><code class="language-xxx">代码内容</code></pre>
7074
+ var editCodeElement = codeElement === null || codeElement === void 0 ? void 0 : codeElement.querySelector("code");
7075
+ var codeText = (editCodeElement === null || editCodeElement === void 0 ? void 0 : editCodeElement.textContent) || "";
7076
+ var language = (editCodeElement === null || editCodeElement === void 0 ? void 0 : editCodeElement.className.replace("language-", "")) || "";
7077
+ // 预览区域结构: <div class="vditor-wysiwyg__preview"><pre><code class="language-xxx">代码内容</code></pre></div>
7078
+ // 找到预览区域内部的 code 元素
7079
+ var previewCodeElement = previewElement.querySelector("pre > code");
7080
+ if (previewCodeElement) {
7081
+ // 更新预览区域的代码内容
7082
+ previewCodeElement.textContent = codeText;
7083
+ // 更新语言类名
7084
+ if (language && language !== "hljs") {
7085
+ previewCodeElement.className = "language-".concat(language);
7086
+ previewElement.setAttribute("data-language", language);
7087
+ }
7088
+ }
7062
7089
  // 重新渲染预览
7063
7090
  previewElement.setAttribute("data-render", "2");
7091
+ processCodeRender(previewElement, vditor);
7064
7092
  }
7065
7093
  };
7066
7094
 
@@ -7933,6 +7961,12 @@ var highlightToolbarWYSIWYG = function (vditor) {
7933
7961
  }
7934
7962
  });
7935
7963
  if (blockRenderElement && isBlock) {
7964
+ // 如果代码块处于编辑状态,则不显示工具栏
7965
+ var isCodeBlockEditing = blockRenderElement.classList.contains("vditor-wysiwyg__block--editing");
7966
+ if (isCodeBlockEditing) {
7967
+ vditor.wysiwyg.popover.style.display = "none";
7968
+ return;
7969
+ }
7936
7970
  vditor.wysiwyg.popover.innerHTML = "";
7937
7971
  genUp(range, blockRenderElement, vditor);
7938
7972
  genDown(range, blockRenderElement, vditor);
@@ -11302,7 +11336,7 @@ var fixFirefoxArrowUpTable = function (event, blockElement, range) {
11302
11336
  return false;
11303
11337
  };
11304
11338
  var paste = function (vditor, event, callback) { return fixBrowserBehavior_awaiter(void 0, void 0, void 0, function () {
11305
- var textHTML, textPlain, files, renderers, renderLinkDest, doc, height, code, codeElement, position, tempElement, fileReader_1, file_1, range, blockElement, range;
11339
+ var textHTML, textPlain, files, renderers, renderLinkDest, doc, height, code, codeElement, position, nextSibling, tempElement, fileReader_1, file_1, range, blockElement, range;
11306
11340
  var _a;
11307
11341
  return fixBrowserBehavior_generator(this, function (_b) {
11308
11342
  switch (_b.label) {
@@ -11428,9 +11462,11 @@ var paste = function (vditor, event, callback) { return fixBrowserBehavior_await
11428
11462
  codeElement.textContent = codeElement.textContent.substring(0, position.start)
11429
11463
  + textPlain + codeElement.textContent.substring(position.end);
11430
11464
  (0,selection/* setSelectionByPosition */.Fm)(position.start + textPlain.length, position.start + textPlain.length, codeElement.parentElement);
11431
- if ((_a = codeElement.parentElement) === null || _a === void 0 ? void 0 : _a.nextElementSibling.classList.contains("vditor-".concat(vditor.currentMode, "__preview"))) {
11432
- codeElement.parentElement.nextElementSibling.innerHTML = codeElement.outerHTML;
11433
- processCodeRender(codeElement.parentElement.nextElementSibling, vditor);
11465
+ nextSibling = (_a = codeElement.parentElement) === null || _a === void 0 ? void 0 : _a.nextElementSibling;
11466
+ if (nextSibling && nextSibling.classList
11467
+ .contains("vditor-".concat(vditor.currentMode, "__preview"))) {
11468
+ nextSibling.innerHTML = codeElement.outerHTML;
11469
+ processCodeRender(nextSibling, vditor);
11434
11470
  }
11435
11471
  }
11436
11472
  return [3 /*break*/, 10];