moondown 0.1.0 → 1.0.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/README.md CHANGED
@@ -378,6 +378,12 @@ pnpm run test:e2e:real-ai
378
378
  }
379
379
  ```
380
380
 
381
+ ### GitHub Actions 自动发布
382
+
383
+ 仓库包含 `.github/workflows/publish.yml`。推送 `v1.0.0` tag 或手动触发 workflow 后,GitHub Actions 会依次执行依赖安装、类型检查、单元测试、构建、`npm pack --dry-run`,然后通过 `npm publish --access public --provenance` 发布到 npm。
384
+
385
+ npm 侧需要为该包配置 Trusted Publisher(推荐),或在 GitHub 仓库 secrets 中配置具备发布权限的 `NPM_TOKEN`。
386
+
381
387
  推荐发布流程:
382
388
 
383
389
  ```bash
package/dist/index.cjs CHANGED
@@ -113,6 +113,7 @@ function normalizePlugins(plugins) {
113
113
  // src/editor/runtime/editor-runtime.ts
114
114
  var import_state36 = require("@codemirror/state");
115
115
  var import_view36 = require("@codemirror/view");
116
+ var import_language15 = require("@codemirror/language");
116
117
 
117
118
  // src/extensions/default-extensions.ts
118
119
  var import_state35 = require("@codemirror/state");
@@ -4487,7 +4488,7 @@ function buildEditorStyles(options) {
4487
4488
  position: "absolute",
4488
4489
  inset: 0,
4489
4490
  backgroundColor: colors.codeBackground,
4490
- borderRadius: "8px",
4491
+ borderRadius: 0,
4491
4492
  zIndex: -1
4492
4493
  },
4493
4494
  ".cm-fenced-code:has(.cm-mermaid-widget)::before, .cm-fenced-code:has(.cm-latex-widget)::before": {
@@ -6697,6 +6698,7 @@ function buildTableHelperStyles(edgeButtonSize) {
6697
6698
  .table-helper-operate-button {
6698
6699
  z-index: 3;
6699
6700
  opacity: 0;
6701
+ pointer-events: none;
6700
6702
  position: absolute;
6701
6703
  display: flex;
6702
6704
  align-items: center;
@@ -6714,9 +6716,9 @@ function buildTableHelperStyles(edgeButtonSize) {
6714
6716
  transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.16, 1, 0.3, 1), color 0.14s ease, border-color 0.14s ease, background-color 0.14s ease;
6715
6717
  }
6716
6718
 
6717
- table.table-helper:hover .table-helper-operate-button,
6718
- .table-helper-operate-button:hover {
6719
+ .table-helper-operate-button.is-visible {
6719
6720
  opacity: 1;
6721
+ pointer-events: auto;
6720
6722
  }
6721
6723
 
6722
6724
  .table-helper-operate-button:hover {
@@ -6823,7 +6825,7 @@ function buildTableHelperStyles(edgeButtonSize) {
6823
6825
  backdrop-filter: blur(40px) saturate(180%);
6824
6826
  -webkit-backdrop-filter: blur(40px) saturate(180%);
6825
6827
  font-size: 13px;
6826
- padding: 4px;
6828
+ padding: 0;
6827
6829
  }
6828
6830
 
6829
6831
  .tippy-box[data-theme~='custom'][data-placement^='bottom'] > .tippy-arrow::before {
@@ -6843,7 +6845,13 @@ function buildTableHelperStyles(edgeButtonSize) {
6843
6845
  }
6844
6846
 
6845
6847
  .tippy-box[data-theme~='custom'] .tippy-content {
6846
- padding: 4px;
6848
+ padding: 0;
6849
+ }
6850
+
6851
+ .table-action-popover {
6852
+ display: flex;
6853
+ gap: 2px;
6854
+ padding: 5px;
6847
6855
  }
6848
6856
 
6849
6857
  .tippy-button {
@@ -6851,14 +6859,16 @@ function buildTableHelperStyles(edgeButtonSize) {
6851
6859
  display: flex;
6852
6860
  align-items: center;
6853
6861
  justify-content: center;
6854
- min-width: 34px;
6855
- min-height: 34px;
6862
+ width: 32px;
6863
+ height: 32px;
6864
+ min-width: 32px;
6865
+ min-height: 32px;
6856
6866
  border: none;
6857
6867
  border-radius: 8px;
6858
6868
  background: transparent;
6859
6869
  color: #6e6e73;
6860
6870
  cursor: pointer;
6861
- padding: 8px 10px;
6871
+ padding: 6px;
6862
6872
  font-size: 14px;
6863
6873
  transition: background-color 0.14s ease, color 0.14s ease, transform 0.12s ease;
6864
6874
  }
@@ -6879,10 +6889,7 @@ function buildTableHelperStyles(edgeButtonSize) {
6879
6889
  }
6880
6890
 
6881
6891
  .alignment-options {
6882
- display: grid;
6883
- grid-template-columns: repeat(3, 1fr);
6884
- gap: 4px;
6885
- padding: 4px;
6892
+ gap: 2px;
6886
6893
  }
6887
6894
 
6888
6895
  .alignment-options .tippy-button {
@@ -6938,19 +6945,38 @@ function genericTextNode(from, to, value, whitespaceBefore = "") {
6938
6945
  }
6939
6946
 
6940
6947
  // src/extensions/table/table-functions.ts
6941
- function parseNode2(tableNode, markdown3) {
6942
- const ast = parseNode(tableNode, markdown3);
6943
- if (ast.type === "Table") {
6944
- const tableEditorAst = ast.rows.map((row) => row.cells.map((cell) => markdown3.substring(cell.from, cell.to).trim()));
6945
- if (tableEditorAst.length === 0) {
6946
- throw new Error("Cannot instantiate TableEditor: Table had zero rows.");
6948
+ function parseMarkdownTable(markdown3) {
6949
+ const ast = markdownToAST(markdown3);
6950
+ const table = findTableAst(ast);
6951
+ if (!table) {
6952
+ return void 0;
6953
+ }
6954
+ return tableAstToParsedTable(table, markdown3);
6955
+ }
6956
+ function tableAstToParsedTable(ast, markdown3) {
6957
+ const tableEditorAst = ast.rows.map((row) => row.cells.map((cell) => markdown3.substring(cell.from, cell.to).trim()));
6958
+ if (tableEditorAst.length === 0) {
6959
+ throw new Error("Cannot instantiate TableEditor: Table had zero rows.");
6960
+ }
6961
+ return {
6962
+ ast: tableEditorAst,
6963
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
6964
+ colAlignments: ast.alignment ?? tableEditorAst[0].map((_cell) => "left")
6965
+ };
6966
+ }
6967
+ function findTableAst(node) {
6968
+ if (node.type === "Table") {
6969
+ return node;
6970
+ }
6971
+ if ("children" in node) {
6972
+ for (const child of node.children) {
6973
+ const table = findTableAst(child);
6974
+ if (table) {
6975
+ return table;
6976
+ }
6947
6977
  }
6948
- return {
6949
- ast: tableEditorAst,
6950
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
6951
- colAlignments: ast.alignment ?? tableEditorAst[0].map((_cell) => "left")
6952
- };
6953
6978
  }
6979
+ return void 0;
6954
6980
  }
6955
6981
  function getWhitespaceBeforeNode(node, markdown3) {
6956
6982
  if (node.prevSibling !== null) {
@@ -7030,11 +7056,12 @@ function parseTableNode(node, markdown3) {
7030
7056
  const header = node.getChildren("TableHeader");
7031
7057
  const rows = node.getChildren("TableRow");
7032
7058
  for (const line of markdown3.substring(node.from, node.to).split("\n")) {
7033
- if (!/^[|+:-]+$/.test(line)) {
7059
+ const normalizedLine = line.trim().replace(/\s+/g, "");
7060
+ if (!/^[|+:-]+$/.test(normalizedLine)) {
7034
7061
  continue;
7035
7062
  }
7036
- const splitter = line.includes("+") ? "+" : "|";
7037
- astNode.alignment = line.split(splitter).filter((c) => c.length > 0).map((c) => {
7063
+ const splitter = normalizedLine.includes("+") ? "+" : "|";
7064
+ astNode.alignment = normalizedLine.split(splitter).filter((c) => c.length > 0).map((c) => {
7038
7065
  if (c.startsWith("|")) {
7039
7066
  c = c.substring(1);
7040
7067
  }
@@ -7293,9 +7320,7 @@ function createActionButton(action) {
7293
7320
  }
7294
7321
  function createPopoverContainer() {
7295
7322
  const container = document.createElement("div");
7296
- container.style.display = "flex";
7297
- container.style.gap = "5px";
7298
- container.style.padding = "5px";
7323
+ container.className = "table-action-popover";
7299
7324
  return container;
7300
7325
  }
7301
7326
  function mountIcons2(iconSet) {
@@ -7422,7 +7447,7 @@ var TableEditorActionsPopover = class {
7422
7447
  }
7423
7448
  showAlignmentOptions(target) {
7424
7449
  const alignmentContainer = createPopoverContainer();
7425
- alignmentContainer.className = "alignment-options";
7450
+ alignmentContainer.classList.add("alignment-options");
7426
7451
  const alignments = [
7427
7452
  {
7428
7453
  icon: "align-left",
@@ -7470,6 +7495,7 @@ var OFFSCREEN_POSITION = "-1000px";
7470
7495
  var BUTTON_OFFSET_SCALE = 0.6;
7471
7496
  var CENTER_SCALE = 1.2;
7472
7497
  var EDGE_BUTTON_SPACING = 5;
7498
+ var VISIBLE_CLASS = "is-visible";
7473
7499
  function isPointInsideExpandedRect({ event, table, edgeButtonSize }) {
7474
7500
  const rect = table.getBoundingClientRect();
7475
7501
  const minX = rect.left - edgeButtonSize;
@@ -7497,16 +7523,24 @@ var TableEditorEdgeButtons = class {
7497
7523
  }
7498
7524
  show() {
7499
7525
  if (this.visible) {
7526
+ this.addTopButton.classList.add(VISIBLE_CLASS);
7527
+ this.addLeftButton.classList.add(VISIBLE_CLASS);
7500
7528
  return;
7501
7529
  }
7502
7530
  document.body.appendChild(this.addTopButton);
7503
7531
  document.body.appendChild(this.addLeftButton);
7532
+ this.addTopButton.classList.add(VISIBLE_CLASS);
7533
+ this.addLeftButton.classList.add(VISIBLE_CLASS);
7504
7534
  }
7505
7535
  hide() {
7536
+ this.addTopButton.classList.remove(VISIBLE_CLASS);
7537
+ this.addLeftButton.classList.remove(VISIBLE_CLASS);
7506
7538
  this.addTopButton.parentElement?.removeChild(this.addTopButton);
7507
7539
  this.addLeftButton.parentElement?.removeChild(this.addLeftButton);
7508
7540
  }
7509
7541
  hideOffscreen() {
7542
+ this.addTopButton.classList.remove(VISIBLE_CLASS);
7543
+ this.addLeftButton.classList.remove(VISIBLE_CLASS);
7510
7544
  this.addTopButton.style.top = OFFSCREEN_POSITION;
7511
7545
  this.addLeftButton.style.top = OFFSCREEN_POSITION;
7512
7546
  }
@@ -7849,6 +7883,10 @@ var TableEditor = class {
7849
7883
  this._recalculateEdgeButtonPositions();
7850
7884
  return;
7851
7885
  }
7886
+ if (this._hasFocusedCell()) {
7887
+ this._showEdgeButtons();
7888
+ return;
7889
+ }
7852
7890
  this._hideAllButtons();
7853
7891
  }
7854
7892
  _clickHelper(event) {
@@ -7897,6 +7935,9 @@ var TableEditor = class {
7897
7935
  if (!isInCurrentTable && !this._isClean) {
7898
7936
  this._options.onBlur?.(this);
7899
7937
  }
7938
+ if (!isInCurrentTable) {
7939
+ this._hideAllButtons();
7940
+ }
7900
7941
  }, BLUR_DELAY_MS);
7901
7942
  }
7902
7943
  _onCellFocus(cell) {
@@ -7912,7 +7953,7 @@ var TableEditor = class {
7912
7953
  cell.innerHTML = this._model.getCell(row, col);
7913
7954
  this._rowIndex = row;
7914
7955
  this._cellIndex = col;
7915
- this._recalculateEdgeButtonPositions();
7956
+ this._showEdgeButtons();
7916
7957
  }
7917
7958
  _onCellKeyDown(event, cell) {
7918
7959
  if (this._options.readOnly) {
@@ -7968,6 +8009,10 @@ var TableEditor = class {
7968
8009
  this._actionsPopover.destroy();
7969
8010
  this._edgeButtons.hide();
7970
8011
  }
8012
+ _hasFocusedCell() {
8013
+ const activeElement = document.activeElement;
8014
+ return !!activeElement && this._elem.contains(activeElement);
8015
+ }
7971
8016
  get _edgeButtonsVisible() {
7972
8017
  return this._edgeButtons.visible;
7973
8018
  }
@@ -8178,21 +8223,20 @@ var TableEditor = class {
8178
8223
  };
8179
8224
 
8180
8225
  // src/extensions/table/table-widget-editor-factory.ts
8181
- function createTableEditorFromSyntaxNode(tableNode, markdown3, options = {}) {
8182
- const parsed = parseNode2(tableNode, markdown3);
8226
+ function createTableEditorFromMarkdown(tableMarkdown, options = {}) {
8227
+ const parsed = parseMarkdownTable(tableMarkdown);
8183
8228
  if (!parsed) {
8184
- throw new Error("Could not parse table node");
8229
+ throw new Error("Could not parse table markdown");
8185
8230
  }
8186
8231
  return new TableEditor(parsed.ast, parsed.colAlignments, options);
8187
8232
  }
8188
8233
 
8189
8234
  // src/extensions/table/render-tables.ts
8190
8235
  var _TableWidget = class _TableWidget extends import_view32.WidgetType {
8191
- constructor(table, readOnly, node, originalFrom, originalTo) {
8236
+ constructor(table, readOnly, originalFrom, originalTo) {
8192
8237
  super();
8193
8238
  this.table = table;
8194
8239
  this.readOnly = readOnly;
8195
- this.node = node;
8196
8240
  this.originalFrom = originalFrom;
8197
8241
  this.originalTo = originalTo;
8198
8242
  __publicField(this, "widgetId");
@@ -8205,7 +8249,7 @@ var _TableWidget = class _TableWidget extends import_view32.WidgetType {
8205
8249
  }
8206
8250
  toDOM(view) {
8207
8251
  try {
8208
- const editor = createTableEditorFromSyntaxNode(this.node, view.state.sliceDoc(), {
8252
+ const editor = createTableEditorFromMarkdown(this.table, {
8209
8253
  readOnly: this.readOnly,
8210
8254
  onBlur: (instance) => {
8211
8255
  this.saveContent(view, instance);
@@ -8265,7 +8309,7 @@ function getErrorMessage(error) {
8265
8309
  function createWidget3(state, node) {
8266
8310
  const table = state.sliceDoc(node.from, node.to);
8267
8311
  try {
8268
- return new TableWidget(table, state.facet(import_state33.EditorState.readOnly), node.node, node.from, node.to);
8312
+ return new TableWidget(table, state.facet(import_state33.EditorState.readOnly), node.from, node.to);
8269
8313
  } catch (error) {
8270
8314
  console.error(`Could not instantiate TableEditor widget: ${getErrorMessage(error)}`);
8271
8315
  return void 0;
@@ -8583,6 +8627,7 @@ var EditorRuntime = class {
8583
8627
  },
8584
8628
  annotations: import_state36.Transaction.addToHistory.of(false)
8585
8629
  });
8630
+ this.refreshWysiwygWidgets();
8586
8631
  }
8587
8632
  toggleSyntaxHiding(enabled) {
8588
8633
  this.config.syntaxHiding = enabled;
@@ -8629,6 +8674,16 @@ var EditorRuntime = class {
8629
8674
  this.pluginRuntime.destroy();
8630
8675
  this.view.destroy();
8631
8676
  }
8677
+ refreshWysiwygWidgets() {
8678
+ if (!this.config.syntaxHiding) {
8679
+ return;
8680
+ }
8681
+ (0, import_language15.forceParsing)(this.view, this.view.state.doc.length, 500);
8682
+ this.view.dispatch({
8683
+ effects: wysiwygCompartment.reconfigure(resolveWysiwygExtensions(true)),
8684
+ annotations: import_state36.Transaction.addToHistory.of(false)
8685
+ });
8686
+ }
8632
8687
  };
8633
8688
 
8634
8689
  // src/editor/moondown-editor.ts