@omegagrid/markdown 0.6.26 → 0.6.28
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/components/features/blockEdit.d.ts +1 -1
- package/dist/components/features/blockEdit.d.ts.map +1 -1
- package/dist/components/features/blockEdit.js +128 -7
- package/dist/components/features/blockEditMenu.d.ts +1 -1
- package/dist/components/features/blockEditMenu.d.ts.map +1 -1
- package/dist/components/features/blockEditMenu.js +226 -5
- package/dist/components/features/codeBlock.js +132 -1
- package/dist/components/features/htmlBlock.d.ts +1 -1
- package/dist/components/features/htmlBlock.d.ts.map +1 -1
- package/dist/components/features/htmlBlock.js +132 -11
- package/dist/components/features/index.js +178 -1
- package/dist/components/features/linkEdit/component.d.ts +1 -1
- package/dist/components/features/linkEdit/component.d.ts.map +1 -1
- package/dist/components/features/linkEdit/component.js +42 -5
- package/dist/components/features/linkEdit/config.js +64 -1
- package/dist/components/features/linkEdit/index.js +14 -1
- package/dist/components/features/linkEdit/slices.js +23 -1
- package/dist/components/features/linkEdit/utils.js +33 -1
- package/dist/components/features/linkEdit/view.js +135 -1
- package/dist/components/features/placeholder.js +50 -1
- package/dist/components/features/toolbar.d.ts +1 -1
- package/dist/components/features/toolbar.d.ts.map +1 -1
- package/dist/components/features/toolbar.js +127 -13
- package/dist/components/features/utils.js +64 -1
- package/dist/components/index.js +4 -1
- package/dist/components/markdownEditor.d.ts +1 -1
- package/dist/components/markdownEditor.d.ts.map +1 -1
- package/dist/components/markdownEditor.js +138 -2
- package/dist/components/markdownEditor.style.js +22 -2
- package/dist/components/markdownView.js +19 -1
- package/dist/components/markdownView.style.js +4 -2
- package/dist/components/styles/block-edit.js +4 -2
- package/dist/components/styles/cursor.js +4 -2
- package/dist/components/styles/image-block.js +4 -2
- package/dist/components/styles/index.js +19 -1
- package/dist/components/styles/link-tooltip.js +4 -2
- package/dist/components/styles/list-item.js +4 -2
- package/dist/components/styles/placeholder.js +4 -2
- package/dist/components/styles/prosemirror.js +4 -2
- package/dist/components/styles/table.js +4 -2
- package/dist/constants.js +5 -1
- package/dist/index.js +4 -1
- package/dist/loader.js +46 -1
- package/dist/utils.js +62 -1
- package/package.json +6 -6
|
@@ -1 +1,135 @@
|
|
|
1
|
-
var
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _LinkEditView_provider, _LinkEditView_slice, _LinkEditView_content, _LinkEditView_hovering, _LinkEditView_data, _LinkEditView_hide, _LinkEditView_onMouseEnter, _LinkEditView_onMouseLeave, _LinkEditView_enterEditMode, _LinkEditView_reset;
|
|
13
|
+
import { dom } from "@omegagrid/core";
|
|
14
|
+
import { md } from "../../../loader";
|
|
15
|
+
import { getLinkEditAPI, getLinkEditState } from "./slices";
|
|
16
|
+
const defaultData = {
|
|
17
|
+
from: -1,
|
|
18
|
+
to: -1,
|
|
19
|
+
mark: null,
|
|
20
|
+
};
|
|
21
|
+
export class LinkEditView {
|
|
22
|
+
constructor(ctx, view) {
|
|
23
|
+
this.ctx = ctx;
|
|
24
|
+
_LinkEditView_provider.set(this, void 0);
|
|
25
|
+
_LinkEditView_slice.set(this, void 0);
|
|
26
|
+
_LinkEditView_content.set(this, void 0);
|
|
27
|
+
_LinkEditView_hovering.set(this, false);
|
|
28
|
+
_LinkEditView_data.set(this, { ...defaultData });
|
|
29
|
+
this._onChange = (e) => {
|
|
30
|
+
const { from, to, mark } = __classPrivateFieldGet(this, _LinkEditView_data, "f");
|
|
31
|
+
if (e.value == null || e.value === '') {
|
|
32
|
+
this.ctx.get(getLinkEditAPI().key).removeLink(from, to);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const view = this.ctx.get(md.core.editorViewCtx);
|
|
36
|
+
const type = md.presets.commonmark.linkSchema.type(this.ctx);
|
|
37
|
+
if (mark && mark.attrs.href === e.value) {
|
|
38
|
+
__classPrivateFieldGet(this, _LinkEditView_reset, "f").call(this);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const tr = view.state.tr;
|
|
42
|
+
if (mark)
|
|
43
|
+
tr.removeMark(from, to, mark);
|
|
44
|
+
tr.addMark(from, to, type.create({ href: e.value }));
|
|
45
|
+
view.dispatch(tr);
|
|
46
|
+
__classPrivateFieldGet(this, _LinkEditView_reset, "f").call(this);
|
|
47
|
+
}
|
|
48
|
+
__classPrivateFieldGet(this, _LinkEditView_hide, "f").call(this);
|
|
49
|
+
};
|
|
50
|
+
this.update = (view) => {
|
|
51
|
+
const { state } = view;
|
|
52
|
+
const { selection } = state;
|
|
53
|
+
if (!(selection instanceof md.prose.state.TextSelection))
|
|
54
|
+
return;
|
|
55
|
+
const { from, to } = selection;
|
|
56
|
+
if (from === __classPrivateFieldGet(this, _LinkEditView_data, "f").from && to === __classPrivateFieldGet(this, _LinkEditView_data, "f").to)
|
|
57
|
+
return;
|
|
58
|
+
__classPrivateFieldGet(this, _LinkEditView_reset, "f").call(this);
|
|
59
|
+
};
|
|
60
|
+
this.destroy = () => {
|
|
61
|
+
__classPrivateFieldGet(this, _LinkEditView_provider, "f").destroy();
|
|
62
|
+
__classPrivateFieldGet(this, _LinkEditView_content, "f").remove();
|
|
63
|
+
};
|
|
64
|
+
this.show = (mark, from, to, rect) => {
|
|
65
|
+
__classPrivateFieldSet(this, _LinkEditView_data, { from, to, mark }, "f");
|
|
66
|
+
rect.height = __classPrivateFieldGet(this, _LinkEditView_content, "f").offsetHeight || 20;
|
|
67
|
+
rect.width = __classPrivateFieldGet(this, _LinkEditView_content, "f").offsetWidth || 150;
|
|
68
|
+
__classPrivateFieldGet(this, _LinkEditView_provider, "f").show({
|
|
69
|
+
getBoundingClientRect: () => rect,
|
|
70
|
+
});
|
|
71
|
+
__classPrivateFieldGet(this, _LinkEditView_provider, "f").element.addEventListener('mouseenter', __classPrivateFieldGet(this, _LinkEditView_onMouseEnter, "f"));
|
|
72
|
+
__classPrivateFieldGet(this, _LinkEditView_provider, "f").element.addEventListener('mouseleave', __classPrivateFieldGet(this, _LinkEditView_onMouseLeave, "f"));
|
|
73
|
+
__classPrivateFieldGet(this, _LinkEditView_content, "f").value = mark?.attrs.href ?? '';
|
|
74
|
+
dom.showElement(__classPrivateFieldGet(this, _LinkEditView_content, "f"));
|
|
75
|
+
};
|
|
76
|
+
this.hide = () => {
|
|
77
|
+
if (__classPrivateFieldGet(this, _LinkEditView_hovering, "f"))
|
|
78
|
+
return;
|
|
79
|
+
__classPrivateFieldGet(this, _LinkEditView_hide, "f").call(this);
|
|
80
|
+
};
|
|
81
|
+
_LinkEditView_hide.set(this, () => {
|
|
82
|
+
dom.hideElement(__classPrivateFieldGet(this, _LinkEditView_content, "f"));
|
|
83
|
+
__classPrivateFieldGet(this, _LinkEditView_provider, "f").hide();
|
|
84
|
+
__classPrivateFieldGet(this, _LinkEditView_provider, "f").element.removeEventListener('mouseenter', __classPrivateFieldGet(this, _LinkEditView_onMouseEnter, "f"));
|
|
85
|
+
__classPrivateFieldGet(this, _LinkEditView_provider, "f").element.removeEventListener('mouseleave', __classPrivateFieldGet(this, _LinkEditView_onMouseLeave, "f"));
|
|
86
|
+
});
|
|
87
|
+
_LinkEditView_onMouseEnter.set(this, () => {
|
|
88
|
+
__classPrivateFieldSet(this, _LinkEditView_hovering, true, "f");
|
|
89
|
+
});
|
|
90
|
+
_LinkEditView_onMouseLeave.set(this, () => {
|
|
91
|
+
__classPrivateFieldSet(this, _LinkEditView_hovering, false, "f");
|
|
92
|
+
});
|
|
93
|
+
_LinkEditView_enterEditMode.set(this, (value, from, to) => {
|
|
94
|
+
__classPrivateFieldGet(this, _LinkEditView_content, "f").value = value;
|
|
95
|
+
const view = this.ctx.get(md.core.editorViewCtx);
|
|
96
|
+
this.show(null, from, to, md.prose.posToDOMRect(view, from, to));
|
|
97
|
+
const tr = view.state.tr;
|
|
98
|
+
view.dispatch(tr.setSelection(md.prose.state.TextSelection.create(view.state.doc, from, to)));
|
|
99
|
+
});
|
|
100
|
+
_LinkEditView_reset.set(this, () => {
|
|
101
|
+
__classPrivateFieldGet(this, _LinkEditView_provider, "f").hide();
|
|
102
|
+
__classPrivateFieldSet(this, _LinkEditView_data, { ...defaultData }, "f");
|
|
103
|
+
});
|
|
104
|
+
this.addLink = (from, to) => {
|
|
105
|
+
__classPrivateFieldSet(this, _LinkEditView_data, { from, to, mark: null }, "f");
|
|
106
|
+
console.log(this);
|
|
107
|
+
__classPrivateFieldGet(this, _LinkEditView_enterEditMode, "f").call(this, '', from, to);
|
|
108
|
+
};
|
|
109
|
+
this.editLink = (mark, from, to) => {
|
|
110
|
+
__classPrivateFieldSet(this, _LinkEditView_data, { from, to, mark }, "f");
|
|
111
|
+
__classPrivateFieldGet(this, _LinkEditView_enterEditMode, "f").call(this, mark.attrs.href, from, to);
|
|
112
|
+
};
|
|
113
|
+
this.removeLink = (from, to) => {
|
|
114
|
+
const view = this.ctx.get(md.core.editorViewCtx);
|
|
115
|
+
const tr = view.state.tr;
|
|
116
|
+
tr.removeMark(from, to, md.presets.commonmark.linkSchema.type(this.ctx));
|
|
117
|
+
view.dispatch(tr);
|
|
118
|
+
__classPrivateFieldGet(this, _LinkEditView_reset, "f").call(this);
|
|
119
|
+
};
|
|
120
|
+
const content = dom.createElement('og-markdown-linkedit');
|
|
121
|
+
content.addEventListener('change', this._onChange);
|
|
122
|
+
content.ctx = ctx;
|
|
123
|
+
__classPrivateFieldSet(this, _LinkEditView_content, content, "f");
|
|
124
|
+
__classPrivateFieldSet(this, _LinkEditView_provider, new md.plugins.tooltip.TooltipProvider({
|
|
125
|
+
content: __classPrivateFieldGet(this, _LinkEditView_content, "f"),
|
|
126
|
+
offset: 10,
|
|
127
|
+
debounce: 0,
|
|
128
|
+
shouldShow: () => false
|
|
129
|
+
}), "f");
|
|
130
|
+
__classPrivateFieldGet(this, _LinkEditView_provider, "f").update(view);
|
|
131
|
+
__classPrivateFieldSet(this, _LinkEditView_slice, ctx.use(getLinkEditState().key), "f");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
_LinkEditView_provider = new WeakMap(), _LinkEditView_slice = new WeakMap(), _LinkEditView_content = new WeakMap(), _LinkEditView_hovering = new WeakMap(), _LinkEditView_data = new WeakMap(), _LinkEditView_hide = new WeakMap(), _LinkEditView_onMouseEnter = new WeakMap(), _LinkEditView_onMouseLeave = new WeakMap(), _LinkEditView_enterEditMode = new WeakMap(), _LinkEditView_reset = new WeakMap();
|
|
135
|
+
//# sourceMappingURL=view.js.map
|
|
@@ -1 +1,50 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isInCodeBlock, isInList } from './utils';
|
|
2
|
+
function isDocEmpty(doc) {
|
|
3
|
+
return doc.childCount <= 1 && !doc.firstChild?.content.size;
|
|
4
|
+
}
|
|
5
|
+
function createPlaceholderDecoration(md, state, placeholderText) {
|
|
6
|
+
const { selection } = state;
|
|
7
|
+
if (!selection.empty)
|
|
8
|
+
return null;
|
|
9
|
+
const $pos = selection.$anchor;
|
|
10
|
+
const node = $pos.parent;
|
|
11
|
+
if (node.content.size > 0)
|
|
12
|
+
return null;
|
|
13
|
+
const inTable = md.prose.findParent((node) => node.type.name === 'table')($pos);
|
|
14
|
+
if (inTable)
|
|
15
|
+
return null;
|
|
16
|
+
const before = $pos.before();
|
|
17
|
+
return md.prose.view.Decoration.node(before, before + node.nodeSize, {
|
|
18
|
+
class: 'crepe-placeholder',
|
|
19
|
+
'data-placeholder': placeholderText,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export const defaultPlaceholderConfig = {
|
|
23
|
+
text: 'Please enter...',
|
|
24
|
+
mode: 'block',
|
|
25
|
+
};
|
|
26
|
+
export const createPlaceHolder = (md) => {
|
|
27
|
+
const placeholderConfig = md.utils.$ctx(defaultPlaceholderConfig, 'placeholderConfigCtx');
|
|
28
|
+
const placeholderPlugin = md.utils.$prose(ctx => new md.prose.state.Plugin({
|
|
29
|
+
key: new md.prose.state.PluginKey('MARKDOWN_PLACEHOLDER'),
|
|
30
|
+
props: {
|
|
31
|
+
decorations: (state) => {
|
|
32
|
+
const config = ctx.get(placeholderConfig.key);
|
|
33
|
+
if (config.mode === 'doc' && !isDocEmpty(state.doc))
|
|
34
|
+
return null;
|
|
35
|
+
if (isInCodeBlock(state.selection) || isInList(state.selection))
|
|
36
|
+
return null;
|
|
37
|
+
const placeholderText = config.text ?? 'Please enter...';
|
|
38
|
+
const deco = createPlaceholderDecoration(md, state, placeholderText);
|
|
39
|
+
if (!deco)
|
|
40
|
+
return null;
|
|
41
|
+
return md.prose.view.DecorationSet.create(state.doc, [deco]);
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
45
|
+
return {
|
|
46
|
+
plugin: placeholderPlugin,
|
|
47
|
+
config: placeholderConfig,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=placeholder.js.map
|
|
@@ -12,7 +12,7 @@ export declare class Toolbar extends LitElement {
|
|
|
12
12
|
isActive: (mark: MarkType) => boolean;
|
|
13
13
|
constructor();
|
|
14
14
|
command(key: milkdown.core.CmdKey<unknown>): void;
|
|
15
|
-
render: () => import("lit").TemplateResult<1>;
|
|
15
|
+
render: () => import("lit-html").TemplateResult<1>;
|
|
16
16
|
}
|
|
17
17
|
export declare class ToolbarView implements PluginView {
|
|
18
18
|
#private;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolbar.d.ts","sourceRoot":"","sources":["../../../src/components/features/toolbar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAG5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AACxF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0CAA0C,CAAC;AACzE,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAGzD,qBACa,OAAQ,SAAQ,UAAU;IAEtC,MAAM,CAAC,MAAM,0BA6BX;IAEF,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,EAAE,EAAE,OAAO,QAAQ,CAAC;IAEpB,IAAI,UAAU,iDAAwC;IACtD,IAAI,GAAG,0CAAiC;IAExC,QAAQ,SAAU,QAAQ,aAKzB;;IAkBD,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAI1C,MAAM,
|
|
1
|
+
{"version":3,"file":"toolbar.d.ts","sourceRoot":"","sources":["../../../src/components/features/toolbar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAG5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AACxF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0CAA0C,CAAC;AACzE,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAGzD,qBACa,OAAQ,SAAQ,UAAU;IAEtC,MAAM,CAAC,MAAM,0BA6BX;IAEF,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,EAAE,EAAE,OAAO,QAAQ,CAAC;IAEpB,IAAI,UAAU,iDAAwC;IACtD,IAAI,GAAG,0CAAiC;IAExC,QAAQ,SAAU,QAAQ,aAKzB;;IAkBD,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAI1C,MAAM,6CAiDJ;CACF;AAGD,qBAAa,WAAY,YAAW,UAAU;;gBAKjC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,QAAQ;IAgCxE,MAAM,SAAU,UAAU,cAAc,WAAW,UAElD;IAED,OAAO,aAGN;IAED,IAAI,aAEH;CAED"}
|
|
@@ -1,41 +1,102 @@
|
|
|
1
|
-
var
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
+
};
|
|
13
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
14
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
15
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
16
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
17
|
+
};
|
|
18
|
+
var _ToolbarView_provider, _ToolbarView_ctx, _ToolbarView_content;
|
|
19
|
+
import { LitElement, css, html } from "lit";
|
|
20
|
+
import { customElement } from "lit/decorators.js";
|
|
21
|
+
import { dom } from "@omegagrid/core";
|
|
22
|
+
import { getLinkEditAPI } from "./linkEdit/slices";
|
|
23
|
+
let Toolbar = class Toolbar extends LitElement {
|
|
24
|
+
get commonmark() { return this.md.presets.commonmark; }
|
|
25
|
+
get gfm() { return this.md.presets.gfm; }
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
28
|
+
this.isActive = (mark) => {
|
|
29
|
+
if (!this.ctx)
|
|
30
|
+
return false;
|
|
31
|
+
const view = this.ctx.get(this.md.core.editorViewCtx);
|
|
32
|
+
const { state: { doc, selection } } = view;
|
|
33
|
+
return doc.rangeHasMark(selection.from, selection.to, mark);
|
|
34
|
+
};
|
|
35
|
+
this.render = () => html `
|
|
2
36
|
<div>
|
|
3
37
|
<og-button
|
|
4
|
-
.state="${this.isActive(this.commonmark.strongSchema.type(this.ctx))?
|
|
38
|
+
.state="${this.isActive(this.commonmark.strongSchema.type(this.ctx)) ? 'checked' : 'unchecked'}"
|
|
5
39
|
type="toggle"
|
|
6
40
|
icon="bold"
|
|
7
|
-
@click="${()=>this.command(this.commonmark.toggleStrongCommand.key)}">
|
|
41
|
+
@click="${() => this.command(this.commonmark.toggleStrongCommand.key)}">
|
|
8
42
|
</og-button>
|
|
9
43
|
|
|
10
44
|
<og-button
|
|
11
|
-
.state="${this.isActive(this.commonmark.emphasisSchema.type(this.ctx))?
|
|
45
|
+
.state="${this.isActive(this.commonmark.emphasisSchema.type(this.ctx)) ? 'checked' : 'unchecked'}"
|
|
12
46
|
type="toggle"
|
|
13
47
|
icon="italic"
|
|
14
|
-
@click="${()=>this.command(this.commonmark.toggleEmphasisCommand.key)}">
|
|
48
|
+
@click="${() => this.command(this.commonmark.toggleEmphasisCommand.key)}">
|
|
15
49
|
</og-button>
|
|
16
50
|
|
|
17
51
|
<og-button
|
|
18
|
-
.state="${this.isActive(this.gfm.strikethroughSchema.type(this.ctx))?
|
|
52
|
+
.state="${this.isActive(this.gfm.strikethroughSchema.type(this.ctx)) ? 'checked' : 'unchecked'}"
|
|
19
53
|
type="toggle"
|
|
20
54
|
icon="strikethrough"
|
|
21
|
-
@click="${()=>this.command(this.gfm.toggleStrikethroughCommand.key)}">
|
|
55
|
+
@click="${() => this.command(this.gfm.toggleStrikethroughCommand.key)}">
|
|
22
56
|
</og-button>
|
|
23
57
|
|
|
24
58
|
<og-button
|
|
25
|
-
.state="${this.isActive(this.commonmark.inlineCodeSchema.type(this.ctx))?
|
|
59
|
+
.state="${this.isActive(this.commonmark.inlineCodeSchema.type(this.ctx)) ? 'checked' : 'unchecked'}"
|
|
26
60
|
type="toggle"
|
|
27
61
|
icon="code"
|
|
28
|
-
@click="${()=>this.command(this.commonmark.toggleInlineCodeCommand.key)}">
|
|
62
|
+
@click="${() => this.command(this.commonmark.toggleInlineCodeCommand.key)}">
|
|
29
63
|
</og-button>
|
|
30
64
|
|
|
31
65
|
<og-button
|
|
32
|
-
.state="${this.isActive(this.commonmark.linkSchema.type(this.ctx))?
|
|
66
|
+
.state="${this.isActive(this.commonmark.linkSchema.type(this.ctx)) ? 'checked' : 'unchecked'}"
|
|
33
67
|
type="toggle"
|
|
34
68
|
icon="link"
|
|
35
|
-
@click="${()=>
|
|
69
|
+
@click="${() => {
|
|
70
|
+
const view = this.ctx.get(this.md.core.editorViewCtx);
|
|
71
|
+
const { selection } = view.state;
|
|
72
|
+
if (this.isActive(this.commonmark.linkSchema.type(this.ctx))) {
|
|
73
|
+
this.ctx.get(getLinkEditAPI().key).removeLink(selection.from, selection.to);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this.ctx.get(getLinkEditAPI().key).addLink(selection.from, selection.to);
|
|
77
|
+
this.dispatchEvent(new Event('hide'));
|
|
78
|
+
}}">
|
|
36
79
|
</og-button>
|
|
37
80
|
</div>
|
|
38
|
-
|
|
81
|
+
`;
|
|
82
|
+
this.addEventListener('click', (e) => {
|
|
83
|
+
e.stopPropagation();
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
});
|
|
86
|
+
this.addEventListener('mousedown', (e) => {
|
|
87
|
+
e.stopPropagation();
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
});
|
|
90
|
+
this.addEventListener('mouseup', (e) => {
|
|
91
|
+
e.stopPropagation();
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
command(key) {
|
|
96
|
+
this.ctx.get(this.md.core.commandsCtx).call(key);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
Toolbar.styles = css `
|
|
39
100
|
* {
|
|
40
101
|
box-sizing: border-box;
|
|
41
102
|
}
|
|
@@ -64,4 +125,57 @@ var _ToolbarView_provider,_ToolbarView_ctx,_ToolbarView_content,__decorate=this&
|
|
|
64
125
|
flex: 0;
|
|
65
126
|
text-align: center;
|
|
66
127
|
}
|
|
67
|
-
|
|
128
|
+
`;
|
|
129
|
+
Toolbar = __decorate([
|
|
130
|
+
customElement('og-markdown-toolbar')
|
|
131
|
+
], Toolbar);
|
|
132
|
+
export { Toolbar };
|
|
133
|
+
export class ToolbarView {
|
|
134
|
+
constructor(ctx, view, md) {
|
|
135
|
+
_ToolbarView_provider.set(this, void 0);
|
|
136
|
+
_ToolbarView_ctx.set(this, void 0);
|
|
137
|
+
_ToolbarView_content.set(this, void 0);
|
|
138
|
+
this.update = (view, prevState) => {
|
|
139
|
+
__classPrivateFieldGet(this, _ToolbarView_provider, "f").update(view, prevState);
|
|
140
|
+
};
|
|
141
|
+
this.destroy = () => {
|
|
142
|
+
__classPrivateFieldGet(this, _ToolbarView_provider, "f").destroy();
|
|
143
|
+
__classPrivateFieldGet(this, _ToolbarView_content, "f").remove();
|
|
144
|
+
};
|
|
145
|
+
this.hide = () => {
|
|
146
|
+
__classPrivateFieldGet(this, _ToolbarView_provider, "f").hide();
|
|
147
|
+
};
|
|
148
|
+
__classPrivateFieldSet(this, _ToolbarView_ctx, ctx, "f");
|
|
149
|
+
const content = dom.createElement('og-markdown-toolbar');
|
|
150
|
+
content.addEventListener('hide', () => __classPrivateFieldGet(this, _ToolbarView_provider, "f").hide());
|
|
151
|
+
content.ctx = ctx;
|
|
152
|
+
content.md = md;
|
|
153
|
+
__classPrivateFieldSet(this, _ToolbarView_content, content, "f");
|
|
154
|
+
__classPrivateFieldSet(this, _ToolbarView_provider, new md.plugins.tooltip.TooltipProvider({
|
|
155
|
+
content: __classPrivateFieldGet(this, _ToolbarView_content, "f"),
|
|
156
|
+
offset: 10,
|
|
157
|
+
debounce: 20,
|
|
158
|
+
shouldShow(view) {
|
|
159
|
+
const { doc, selection } = view.state;
|
|
160
|
+
const { empty, from, to } = selection;
|
|
161
|
+
const isEmptyTextBlock = !doc.textBetween(from, to).length && selection instanceof md.prose.state.TextSelection;
|
|
162
|
+
const isNotTextBlock = !(selection instanceof md.prose.state.TextSelection);
|
|
163
|
+
const activeElement = view.dom.getRootNode().activeElement;
|
|
164
|
+
const isTooltipChildren = content.contains(activeElement);
|
|
165
|
+
const notHasFocus = !view.hasFocus() && !isTooltipChildren;
|
|
166
|
+
const isReadonly = !view.editable;
|
|
167
|
+
if (notHasFocus || isNotTextBlock || empty || isEmptyTextBlock || isReadonly)
|
|
168
|
+
return false;
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
}), "f");
|
|
172
|
+
__classPrivateFieldGet(this, _ToolbarView_provider, "f").onShow = () => {
|
|
173
|
+
dom.showElement(__classPrivateFieldGet(this, _ToolbarView_content, "f"));
|
|
174
|
+
__classPrivateFieldGet(this, _ToolbarView_content, "f").requestUpdate();
|
|
175
|
+
};
|
|
176
|
+
__classPrivateFieldGet(this, _ToolbarView_provider, "f").onHide = () => dom.hideElement(__classPrivateFieldGet(this, _ToolbarView_content, "f"));
|
|
177
|
+
this.update(view);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
_ToolbarView_provider = new WeakMap(), _ToolbarView_ctx = new WeakMap(), _ToolbarView_content = new WeakMap();
|
|
181
|
+
//# sourceMappingURL=toolbar.js.map
|
|
@@ -1 +1,64 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { MilkdownLoader } from "../../loader";
|
|
2
|
+
export function clearRange(tr) {
|
|
3
|
+
const { $from, $to } = tr.selection;
|
|
4
|
+
const from = $from.pos - $from.node().content.size;
|
|
5
|
+
if (from >= 0)
|
|
6
|
+
tr = tr.deleteRange(from, $to.pos);
|
|
7
|
+
return tr;
|
|
8
|
+
}
|
|
9
|
+
export function setBlockType(tr, nodeType, attrs = null) {
|
|
10
|
+
const { from, to } = tr.selection;
|
|
11
|
+
return tr.setBlockType(from, to, nodeType, attrs);
|
|
12
|
+
}
|
|
13
|
+
export function wrapInBlockType(tr, nodeType, attrs = null) {
|
|
14
|
+
const { $from, $to } = tr.selection;
|
|
15
|
+
const range = $from.blockRange($to);
|
|
16
|
+
const wrapping = range && (MilkdownLoader.getSync()).prose.transform.findWrapping(range, nodeType, attrs);
|
|
17
|
+
if (!wrapping)
|
|
18
|
+
return null;
|
|
19
|
+
return tr.wrap(range, wrapping);
|
|
20
|
+
}
|
|
21
|
+
export function addBlockType(tr, nodeType, attrs = null) {
|
|
22
|
+
const node = nodeType.createAndFill(attrs);
|
|
23
|
+
if (!node)
|
|
24
|
+
return null;
|
|
25
|
+
return tr.replaceSelectionWith(node);
|
|
26
|
+
}
|
|
27
|
+
export function clearContentAndSetBlockType(nodeType, attrs = null) {
|
|
28
|
+
return (state, dispatch) => {
|
|
29
|
+
if (dispatch) {
|
|
30
|
+
const tr = setBlockType(clearRange(state.tr), nodeType, attrs);
|
|
31
|
+
dispatch(tr.scrollIntoView());
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function clearContentAndWrapInBlockType(nodeType, attrs = null) {
|
|
37
|
+
return (state, dispatch) => {
|
|
38
|
+
const tr = wrapInBlockType(clearRange(state.tr), nodeType, attrs);
|
|
39
|
+
if (!tr)
|
|
40
|
+
return false;
|
|
41
|
+
if (dispatch)
|
|
42
|
+
dispatch(tr.scrollIntoView());
|
|
43
|
+
return true;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function clearContentAndAddBlockType(nodeType, attrs = null) {
|
|
47
|
+
return (state, dispatch) => {
|
|
48
|
+
const tr = addBlockType(clearRange(state.tr), nodeType, attrs);
|
|
49
|
+
if (!tr)
|
|
50
|
+
return false;
|
|
51
|
+
if (dispatch)
|
|
52
|
+
dispatch(tr.scrollIntoView());
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export function isInCodeBlock(selection) {
|
|
57
|
+
const type = selection.$from.parent.type;
|
|
58
|
+
return type.name === 'code_block';
|
|
59
|
+
}
|
|
60
|
+
export function isInList(selection) {
|
|
61
|
+
const type = selection.$from.node(selection.$from.depth - 1)?.type;
|
|
62
|
+
return type?.name === 'list_item';
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=utils.js.map
|
package/dist/components/index.js
CHANGED
|
@@ -28,7 +28,7 @@ export declare class MarkdownEditor extends LitElement implements Layout {
|
|
|
28
28
|
_onChange: (markdown: string, prevMarkdown: string) => void;
|
|
29
29
|
updated(): Promise<void>;
|
|
30
30
|
disconnectedCallback(): void;
|
|
31
|
-
render: () => import("lit").TemplateResult<1>;
|
|
31
|
+
render: () => import("lit-html").TemplateResult<1>;
|
|
32
32
|
layout(): void;
|
|
33
33
|
}
|
|
34
34
|
//# sourceMappingURL=markdownEditor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownEditor.d.ts","sourceRoot":"","sources":["../../src/components/markdownEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,kBAAkB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,UAAU,EAAQ,MAAM,KAAK,CAAC;AAKvC,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAEzD,qBAAa,iBAAkB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,CAAC,EAAE,iBAAiB,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;gBAErB,IAAI,EAAE,OAAO,CAAC,iBAAiB,CAAC;CAI5C;AAED,qBACa,cAAe,SAAQ,UAAW,YAAW,MAAM;;IAE/D,MAAM,CAAC,MAAM,4BAAsB;IAGnC,IACI,OAAO,IACM,MAAM,CADe;IACtC,IAAI,OAAO,CAAC,GAAG,EAAE,MAAM,EAKtB;IAGD,eAAe,SAAO;IAGtB,gBAAgB,EAAE,kBAAkB,CAAU;IAG9C,QAAQ,UAAS;IAGjB,SAAS,EAAE,cAAc,CAAC;IAG1B,MAAM,EAAE,MAAM,CAAC;IAGf,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAG1C,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAAC,MAAM,CAAC;IAIzD,IAAI,WAAW,IAAiD,WAAW,CAAE;IAC7E,IAAI,MAAM,yBAA0B;;IAwBpC,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IAOjC,iBAAiB;IAKjB,WAAW;IAKX,SAAS,aAAc,MAAM,gBAAgB,MAAM,UAGlD;IAEK,OAAO;IAab,oBAAoB;IAOpB,MAAM,
|
|
1
|
+
{"version":3,"file":"markdownEditor.d.ts","sourceRoot":"","sources":["../../src/components/markdownEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,kBAAkB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,UAAU,EAAQ,MAAM,KAAK,CAAC;AAKvC,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAEzD,qBAAa,iBAAkB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,CAAC,EAAE,iBAAiB,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;gBAErB,IAAI,EAAE,OAAO,CAAC,iBAAiB,CAAC;CAI5C;AAED,qBACa,cAAe,SAAQ,UAAW,YAAW,MAAM;;IAE/D,MAAM,CAAC,MAAM,4BAAsB;IAGnC,IACI,OAAO,IACM,MAAM,CADe;IACtC,IAAI,OAAO,CAAC,GAAG,EAAE,MAAM,EAKtB;IAGD,eAAe,SAAO;IAGtB,gBAAgB,EAAE,kBAAkB,CAAU;IAG9C,QAAQ,UAAS;IAGjB,SAAS,EAAE,cAAc,CAAC;IAG1B,MAAM,EAAE,MAAM,CAAC;IAGf,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAG1C,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAAC,MAAM,CAAC;IAIzD,IAAI,WAAW,IAAiD,WAAW,CAAE;IAC7E,IAAI,MAAM,yBAA0B;;IAwBpC,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IAOjC,iBAAiB;IAKjB,WAAW;IAKX,SAAS,aAAc,MAAM,gBAAgB,MAAM,UAGlD;IAEK,OAAO;IAab,oBAAoB;IAOpB,MAAM,6CAMJ;IAEF,MAAM;CAEN"}
|