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 +6 -0
- package/dist/index.cjs +93 -38
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +93 -38
- package/dist/index.js.map +3 -3
- package/package.json +9 -1
package/dist/index.js
CHANGED
|
@@ -39,6 +39,7 @@ function normalizePlugins(plugins) {
|
|
|
39
39
|
// src/editor/runtime/editor-runtime.ts
|
|
40
40
|
import { EditorState as EditorState12, Transaction as Transaction4 } from "@codemirror/state";
|
|
41
41
|
import { EditorView as EditorView30, placeholder as viewPlaceholder } from "@codemirror/view";
|
|
42
|
+
import { forceParsing } from "@codemirror/language";
|
|
42
43
|
|
|
43
44
|
// src/extensions/default-extensions.ts
|
|
44
45
|
import { Prec } from "@codemirror/state";
|
|
@@ -4421,7 +4422,7 @@ function buildEditorStyles(options) {
|
|
|
4421
4422
|
position: "absolute",
|
|
4422
4423
|
inset: 0,
|
|
4423
4424
|
backgroundColor: colors.codeBackground,
|
|
4424
|
-
borderRadius:
|
|
4425
|
+
borderRadius: 0,
|
|
4425
4426
|
zIndex: -1
|
|
4426
4427
|
},
|
|
4427
4428
|
".cm-fenced-code:has(.cm-mermaid-widget)::before, .cm-fenced-code:has(.cm-latex-widget)::before": {
|
|
@@ -6637,6 +6638,7 @@ function buildTableHelperStyles(edgeButtonSize) {
|
|
|
6637
6638
|
.table-helper-operate-button {
|
|
6638
6639
|
z-index: 3;
|
|
6639
6640
|
opacity: 0;
|
|
6641
|
+
pointer-events: none;
|
|
6640
6642
|
position: absolute;
|
|
6641
6643
|
display: flex;
|
|
6642
6644
|
align-items: center;
|
|
@@ -6654,9 +6656,9 @@ function buildTableHelperStyles(edgeButtonSize) {
|
|
|
6654
6656
|
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;
|
|
6655
6657
|
}
|
|
6656
6658
|
|
|
6657
|
-
|
|
6658
|
-
.table-helper-operate-button:hover {
|
|
6659
|
+
.table-helper-operate-button.is-visible {
|
|
6659
6660
|
opacity: 1;
|
|
6661
|
+
pointer-events: auto;
|
|
6660
6662
|
}
|
|
6661
6663
|
|
|
6662
6664
|
.table-helper-operate-button:hover {
|
|
@@ -6763,7 +6765,7 @@ function buildTableHelperStyles(edgeButtonSize) {
|
|
|
6763
6765
|
backdrop-filter: blur(40px) saturate(180%);
|
|
6764
6766
|
-webkit-backdrop-filter: blur(40px) saturate(180%);
|
|
6765
6767
|
font-size: 13px;
|
|
6766
|
-
padding:
|
|
6768
|
+
padding: 0;
|
|
6767
6769
|
}
|
|
6768
6770
|
|
|
6769
6771
|
.tippy-box[data-theme~='custom'][data-placement^='bottom'] > .tippy-arrow::before {
|
|
@@ -6783,7 +6785,13 @@ function buildTableHelperStyles(edgeButtonSize) {
|
|
|
6783
6785
|
}
|
|
6784
6786
|
|
|
6785
6787
|
.tippy-box[data-theme~='custom'] .tippy-content {
|
|
6786
|
-
padding:
|
|
6788
|
+
padding: 0;
|
|
6789
|
+
}
|
|
6790
|
+
|
|
6791
|
+
.table-action-popover {
|
|
6792
|
+
display: flex;
|
|
6793
|
+
gap: 2px;
|
|
6794
|
+
padding: 5px;
|
|
6787
6795
|
}
|
|
6788
6796
|
|
|
6789
6797
|
.tippy-button {
|
|
@@ -6791,14 +6799,16 @@ function buildTableHelperStyles(edgeButtonSize) {
|
|
|
6791
6799
|
display: flex;
|
|
6792
6800
|
align-items: center;
|
|
6793
6801
|
justify-content: center;
|
|
6794
|
-
|
|
6795
|
-
|
|
6802
|
+
width: 32px;
|
|
6803
|
+
height: 32px;
|
|
6804
|
+
min-width: 32px;
|
|
6805
|
+
min-height: 32px;
|
|
6796
6806
|
border: none;
|
|
6797
6807
|
border-radius: 8px;
|
|
6798
6808
|
background: transparent;
|
|
6799
6809
|
color: #6e6e73;
|
|
6800
6810
|
cursor: pointer;
|
|
6801
|
-
padding:
|
|
6811
|
+
padding: 6px;
|
|
6802
6812
|
font-size: 14px;
|
|
6803
6813
|
transition: background-color 0.14s ease, color 0.14s ease, transform 0.12s ease;
|
|
6804
6814
|
}
|
|
@@ -6819,10 +6829,7 @@ function buildTableHelperStyles(edgeButtonSize) {
|
|
|
6819
6829
|
}
|
|
6820
6830
|
|
|
6821
6831
|
.alignment-options {
|
|
6822
|
-
|
|
6823
|
-
grid-template-columns: repeat(3, 1fr);
|
|
6824
|
-
gap: 4px;
|
|
6825
|
-
padding: 4px;
|
|
6832
|
+
gap: 2px;
|
|
6826
6833
|
}
|
|
6827
6834
|
|
|
6828
6835
|
.alignment-options .tippy-button {
|
|
@@ -6878,19 +6885,38 @@ function genericTextNode(from, to, value, whitespaceBefore = "") {
|
|
|
6878
6885
|
}
|
|
6879
6886
|
|
|
6880
6887
|
// src/extensions/table/table-functions.ts
|
|
6881
|
-
function
|
|
6882
|
-
const ast =
|
|
6883
|
-
|
|
6884
|
-
|
|
6885
|
-
|
|
6886
|
-
|
|
6888
|
+
function parseMarkdownTable(markdown3) {
|
|
6889
|
+
const ast = markdownToAST(markdown3);
|
|
6890
|
+
const table = findTableAst(ast);
|
|
6891
|
+
if (!table) {
|
|
6892
|
+
return void 0;
|
|
6893
|
+
}
|
|
6894
|
+
return tableAstToParsedTable(table, markdown3);
|
|
6895
|
+
}
|
|
6896
|
+
function tableAstToParsedTable(ast, markdown3) {
|
|
6897
|
+
const tableEditorAst = ast.rows.map((row) => row.cells.map((cell) => markdown3.substring(cell.from, cell.to).trim()));
|
|
6898
|
+
if (tableEditorAst.length === 0) {
|
|
6899
|
+
throw new Error("Cannot instantiate TableEditor: Table had zero rows.");
|
|
6900
|
+
}
|
|
6901
|
+
return {
|
|
6902
|
+
ast: tableEditorAst,
|
|
6903
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6904
|
+
colAlignments: ast.alignment ?? tableEditorAst[0].map((_cell) => "left")
|
|
6905
|
+
};
|
|
6906
|
+
}
|
|
6907
|
+
function findTableAst(node) {
|
|
6908
|
+
if (node.type === "Table") {
|
|
6909
|
+
return node;
|
|
6910
|
+
}
|
|
6911
|
+
if ("children" in node) {
|
|
6912
|
+
for (const child of node.children) {
|
|
6913
|
+
const table = findTableAst(child);
|
|
6914
|
+
if (table) {
|
|
6915
|
+
return table;
|
|
6916
|
+
}
|
|
6887
6917
|
}
|
|
6888
|
-
return {
|
|
6889
|
-
ast: tableEditorAst,
|
|
6890
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6891
|
-
colAlignments: ast.alignment ?? tableEditorAst[0].map((_cell) => "left")
|
|
6892
|
-
};
|
|
6893
6918
|
}
|
|
6919
|
+
return void 0;
|
|
6894
6920
|
}
|
|
6895
6921
|
function getWhitespaceBeforeNode(node, markdown3) {
|
|
6896
6922
|
if (node.prevSibling !== null) {
|
|
@@ -6970,11 +6996,12 @@ function parseTableNode(node, markdown3) {
|
|
|
6970
6996
|
const header = node.getChildren("TableHeader");
|
|
6971
6997
|
const rows = node.getChildren("TableRow");
|
|
6972
6998
|
for (const line of markdown3.substring(node.from, node.to).split("\n")) {
|
|
6973
|
-
|
|
6999
|
+
const normalizedLine = line.trim().replace(/\s+/g, "");
|
|
7000
|
+
if (!/^[|+:-]+$/.test(normalizedLine)) {
|
|
6974
7001
|
continue;
|
|
6975
7002
|
}
|
|
6976
|
-
const splitter =
|
|
6977
|
-
astNode.alignment =
|
|
7003
|
+
const splitter = normalizedLine.includes("+") ? "+" : "|";
|
|
7004
|
+
astNode.alignment = normalizedLine.split(splitter).filter((c) => c.length > 0).map((c) => {
|
|
6978
7005
|
if (c.startsWith("|")) {
|
|
6979
7006
|
c = c.substring(1);
|
|
6980
7007
|
}
|
|
@@ -7243,9 +7270,7 @@ function createActionButton(action) {
|
|
|
7243
7270
|
}
|
|
7244
7271
|
function createPopoverContainer() {
|
|
7245
7272
|
const container = document.createElement("div");
|
|
7246
|
-
container.
|
|
7247
|
-
container.style.gap = "5px";
|
|
7248
|
-
container.style.padding = "5px";
|
|
7273
|
+
container.className = "table-action-popover";
|
|
7249
7274
|
return container;
|
|
7250
7275
|
}
|
|
7251
7276
|
function mountIcons2(iconSet) {
|
|
@@ -7372,7 +7397,7 @@ var TableEditorActionsPopover = class {
|
|
|
7372
7397
|
}
|
|
7373
7398
|
showAlignmentOptions(target) {
|
|
7374
7399
|
const alignmentContainer = createPopoverContainer();
|
|
7375
|
-
alignmentContainer.
|
|
7400
|
+
alignmentContainer.classList.add("alignment-options");
|
|
7376
7401
|
const alignments = [
|
|
7377
7402
|
{
|
|
7378
7403
|
icon: "align-left",
|
|
@@ -7420,6 +7445,7 @@ var OFFSCREEN_POSITION = "-1000px";
|
|
|
7420
7445
|
var BUTTON_OFFSET_SCALE = 0.6;
|
|
7421
7446
|
var CENTER_SCALE = 1.2;
|
|
7422
7447
|
var EDGE_BUTTON_SPACING = 5;
|
|
7448
|
+
var VISIBLE_CLASS = "is-visible";
|
|
7423
7449
|
function isPointInsideExpandedRect({ event, table, edgeButtonSize }) {
|
|
7424
7450
|
const rect = table.getBoundingClientRect();
|
|
7425
7451
|
const minX = rect.left - edgeButtonSize;
|
|
@@ -7447,16 +7473,24 @@ var TableEditorEdgeButtons = class {
|
|
|
7447
7473
|
}
|
|
7448
7474
|
show() {
|
|
7449
7475
|
if (this.visible) {
|
|
7476
|
+
this.addTopButton.classList.add(VISIBLE_CLASS);
|
|
7477
|
+
this.addLeftButton.classList.add(VISIBLE_CLASS);
|
|
7450
7478
|
return;
|
|
7451
7479
|
}
|
|
7452
7480
|
document.body.appendChild(this.addTopButton);
|
|
7453
7481
|
document.body.appendChild(this.addLeftButton);
|
|
7482
|
+
this.addTopButton.classList.add(VISIBLE_CLASS);
|
|
7483
|
+
this.addLeftButton.classList.add(VISIBLE_CLASS);
|
|
7454
7484
|
}
|
|
7455
7485
|
hide() {
|
|
7486
|
+
this.addTopButton.classList.remove(VISIBLE_CLASS);
|
|
7487
|
+
this.addLeftButton.classList.remove(VISIBLE_CLASS);
|
|
7456
7488
|
this.addTopButton.parentElement?.removeChild(this.addTopButton);
|
|
7457
7489
|
this.addLeftButton.parentElement?.removeChild(this.addLeftButton);
|
|
7458
7490
|
}
|
|
7459
7491
|
hideOffscreen() {
|
|
7492
|
+
this.addTopButton.classList.remove(VISIBLE_CLASS);
|
|
7493
|
+
this.addLeftButton.classList.remove(VISIBLE_CLASS);
|
|
7460
7494
|
this.addTopButton.style.top = OFFSCREEN_POSITION;
|
|
7461
7495
|
this.addLeftButton.style.top = OFFSCREEN_POSITION;
|
|
7462
7496
|
}
|
|
@@ -7799,6 +7833,10 @@ var TableEditor = class {
|
|
|
7799
7833
|
this._recalculateEdgeButtonPositions();
|
|
7800
7834
|
return;
|
|
7801
7835
|
}
|
|
7836
|
+
if (this._hasFocusedCell()) {
|
|
7837
|
+
this._showEdgeButtons();
|
|
7838
|
+
return;
|
|
7839
|
+
}
|
|
7802
7840
|
this._hideAllButtons();
|
|
7803
7841
|
}
|
|
7804
7842
|
_clickHelper(event) {
|
|
@@ -7847,6 +7885,9 @@ var TableEditor = class {
|
|
|
7847
7885
|
if (!isInCurrentTable && !this._isClean) {
|
|
7848
7886
|
this._options.onBlur?.(this);
|
|
7849
7887
|
}
|
|
7888
|
+
if (!isInCurrentTable) {
|
|
7889
|
+
this._hideAllButtons();
|
|
7890
|
+
}
|
|
7850
7891
|
}, BLUR_DELAY_MS);
|
|
7851
7892
|
}
|
|
7852
7893
|
_onCellFocus(cell) {
|
|
@@ -7862,7 +7903,7 @@ var TableEditor = class {
|
|
|
7862
7903
|
cell.innerHTML = this._model.getCell(row, col);
|
|
7863
7904
|
this._rowIndex = row;
|
|
7864
7905
|
this._cellIndex = col;
|
|
7865
|
-
this.
|
|
7906
|
+
this._showEdgeButtons();
|
|
7866
7907
|
}
|
|
7867
7908
|
_onCellKeyDown(event, cell) {
|
|
7868
7909
|
if (this._options.readOnly) {
|
|
@@ -7918,6 +7959,10 @@ var TableEditor = class {
|
|
|
7918
7959
|
this._actionsPopover.destroy();
|
|
7919
7960
|
this._edgeButtons.hide();
|
|
7920
7961
|
}
|
|
7962
|
+
_hasFocusedCell() {
|
|
7963
|
+
const activeElement = document.activeElement;
|
|
7964
|
+
return !!activeElement && this._elem.contains(activeElement);
|
|
7965
|
+
}
|
|
7921
7966
|
get _edgeButtonsVisible() {
|
|
7922
7967
|
return this._edgeButtons.visible;
|
|
7923
7968
|
}
|
|
@@ -8128,21 +8173,20 @@ var TableEditor = class {
|
|
|
8128
8173
|
};
|
|
8129
8174
|
|
|
8130
8175
|
// src/extensions/table/table-widget-editor-factory.ts
|
|
8131
|
-
function
|
|
8132
|
-
const parsed =
|
|
8176
|
+
function createTableEditorFromMarkdown(tableMarkdown, options = {}) {
|
|
8177
|
+
const parsed = parseMarkdownTable(tableMarkdown);
|
|
8133
8178
|
if (!parsed) {
|
|
8134
|
-
throw new Error("Could not parse table
|
|
8179
|
+
throw new Error("Could not parse table markdown");
|
|
8135
8180
|
}
|
|
8136
8181
|
return new TableEditor(parsed.ast, parsed.colAlignments, options);
|
|
8137
8182
|
}
|
|
8138
8183
|
|
|
8139
8184
|
// src/extensions/table/render-tables.ts
|
|
8140
8185
|
var _TableWidget = class _TableWidget extends WidgetType12 {
|
|
8141
|
-
constructor(table, readOnly,
|
|
8186
|
+
constructor(table, readOnly, originalFrom, originalTo) {
|
|
8142
8187
|
super();
|
|
8143
8188
|
this.table = table;
|
|
8144
8189
|
this.readOnly = readOnly;
|
|
8145
|
-
this.node = node;
|
|
8146
8190
|
this.originalFrom = originalFrom;
|
|
8147
8191
|
this.originalTo = originalTo;
|
|
8148
8192
|
__publicField(this, "widgetId");
|
|
@@ -8155,7 +8199,7 @@ var _TableWidget = class _TableWidget extends WidgetType12 {
|
|
|
8155
8199
|
}
|
|
8156
8200
|
toDOM(view) {
|
|
8157
8201
|
try {
|
|
8158
|
-
const editor =
|
|
8202
|
+
const editor = createTableEditorFromMarkdown(this.table, {
|
|
8159
8203
|
readOnly: this.readOnly,
|
|
8160
8204
|
onBlur: (instance) => {
|
|
8161
8205
|
this.saveContent(view, instance);
|
|
@@ -8215,7 +8259,7 @@ function getErrorMessage(error) {
|
|
|
8215
8259
|
function createWidget3(state, node) {
|
|
8216
8260
|
const table = state.sliceDoc(node.from, node.to);
|
|
8217
8261
|
try {
|
|
8218
|
-
return new TableWidget(table, state.facet(CodeMirrorState.readOnly), node.
|
|
8262
|
+
return new TableWidget(table, state.facet(CodeMirrorState.readOnly), node.from, node.to);
|
|
8219
8263
|
} catch (error) {
|
|
8220
8264
|
console.error(`Could not instantiate TableEditor widget: ${getErrorMessage(error)}`);
|
|
8221
8265
|
return void 0;
|
|
@@ -8533,6 +8577,7 @@ var EditorRuntime = class {
|
|
|
8533
8577
|
},
|
|
8534
8578
|
annotations: Transaction4.addToHistory.of(false)
|
|
8535
8579
|
});
|
|
8580
|
+
this.refreshWysiwygWidgets();
|
|
8536
8581
|
}
|
|
8537
8582
|
toggleSyntaxHiding(enabled) {
|
|
8538
8583
|
this.config.syntaxHiding = enabled;
|
|
@@ -8579,6 +8624,16 @@ var EditorRuntime = class {
|
|
|
8579
8624
|
this.pluginRuntime.destroy();
|
|
8580
8625
|
this.view.destroy();
|
|
8581
8626
|
}
|
|
8627
|
+
refreshWysiwygWidgets() {
|
|
8628
|
+
if (!this.config.syntaxHiding) {
|
|
8629
|
+
return;
|
|
8630
|
+
}
|
|
8631
|
+
forceParsing(this.view, this.view.state.doc.length, 500);
|
|
8632
|
+
this.view.dispatch({
|
|
8633
|
+
effects: wysiwygCompartment.reconfigure(resolveWysiwygExtensions(true)),
|
|
8634
|
+
annotations: Transaction4.addToHistory.of(false)
|
|
8635
|
+
});
|
|
8636
|
+
}
|
|
8582
8637
|
};
|
|
8583
8638
|
|
|
8584
8639
|
// src/editor/moondown-editor.ts
|