@omegagrid/markdown 0.9.37 → 0.9.38
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 +135 -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
|
@@ -9,7 +9,7 @@ export declare class BlockEdit extends LitElement {
|
|
|
9
9
|
get menu(): BlockEditMenu;
|
|
10
10
|
updated(): void;
|
|
11
11
|
disconnectedCallback(): void;
|
|
12
|
-
render: () => import("lit").TemplateResult<1>;
|
|
12
|
+
render: () => import("lit-html").TemplateResult<1>;
|
|
13
13
|
hideMenu: () => HTMLElement;
|
|
14
14
|
showMenu: (elm: HTMLElement) => void;
|
|
15
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blockEdit.d.ts","sourceRoot":"","sources":["../../../src/components/features/blockEdit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAG5C,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,CAAC;AAGlC,qBACa,SAAU,SAAQ,UAAU;;IAExC,MAAM,CAAC,MAAM,0BAqBX;IAGF,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;IAGtB,EAAE,EAAE,OAAO,QAAQ,CAAC;IAGpB,IAAI,IAAI,kBAA+B;IAEvC,OAAO;IAMP,oBAAoB;IAIpB,MAAM,
|
|
1
|
+
{"version":3,"file":"blockEdit.d.ts","sourceRoot":"","sources":["../../../src/components/features/blockEdit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAG5C,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,CAAC;AAGlC,qBACa,SAAU,SAAQ,UAAU;;IAExC,MAAM,CAAC,MAAM,0BAqBX;IAGF,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;IAGtB,EAAE,EAAE,OAAO,QAAQ,CAAC;IAGpB,IAAI,IAAI,kBAA+B;IAEvC,OAAO;IAMP,oBAAoB;IAIpB,MAAM,6CAkBJ;IAEF,QAAQ,oBAAoC;IAE5C,QAAQ,GAAI,KAAK,WAAW,UAW3B;CACD;AAED,qBAAa,eAAe;;IAG3B,EAAE,EAAE,OAAO,QAAQ,CAAC;gBAGR,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,EAAE,OAAO,QAAQ;IAqBtD,MAAM,aAEL;IAED,OAAO,aAEN;CAyBD"}
|
|
@@ -1,20 +1,76 @@
|
|
|
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 __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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
13
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
14
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
15
|
+
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");
|
|
16
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
17
|
+
};
|
|
18
|
+
var _BlockEdit_menu, _BlockHandleView_provider, _BlockHandleView_ctx, _BlockHandleView_content, _BlockHandleView_onAdd;
|
|
19
|
+
import { LitElement, css, html } from "lit";
|
|
20
|
+
import { customElement, property } from "lit/decorators.js";
|
|
21
|
+
import { dom } from "@omegagrid/core";
|
|
22
|
+
import { createRef, ref } from "lit/directives/ref.js";
|
|
23
|
+
let BlockEdit = class BlockEdit extends LitElement {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments);
|
|
26
|
+
_BlockEdit_menu.set(this, createRef());
|
|
27
|
+
this.render = () => html `
|
|
2
28
|
<og-button
|
|
3
29
|
icon="plus"
|
|
4
30
|
color="transparent"
|
|
5
|
-
@click=${()=>{
|
|
31
|
+
@click=${() => {
|
|
32
|
+
this.dispatchEvent(new Event('add'));
|
|
33
|
+
}}>
|
|
6
34
|
</og-button>
|
|
7
35
|
|
|
8
36
|
<og-button icon="grip-vertical" color="transparent"></og-button>
|
|
9
37
|
|
|
10
|
-
<og-markdown-block-edit-menu ${ref(__classPrivateFieldGet(this,_BlockEdit_menu,"f"))}
|
|
11
|
-
@mousedown=${e=>e.stopPropagation()}
|
|
38
|
+
<og-markdown-block-edit-menu ${ref(__classPrivateFieldGet(this, _BlockEdit_menu, "f"))}
|
|
39
|
+
@mousedown=${(e) => e.stopPropagation()}
|
|
12
40
|
style="display: none"
|
|
13
|
-
@run=${()=>this.hideMenu()}
|
|
41
|
+
@run=${() => this.hideMenu()}
|
|
14
42
|
.ctx="${this.ctx}"
|
|
15
43
|
.md="${this.md}">
|
|
16
44
|
</og-markdown-block-edit-menu>
|
|
17
|
-
|
|
45
|
+
`;
|
|
46
|
+
this.hideMenu = () => dom.hideElement(this.menu);
|
|
47
|
+
this.showMenu = (elm) => {
|
|
48
|
+
if (!this.menu)
|
|
49
|
+
return;
|
|
50
|
+
const container = this.menu.parentElement;
|
|
51
|
+
const offset = dom.getElementOffset(elm, container);
|
|
52
|
+
dom.showElement(this.menu);
|
|
53
|
+
let top = offset.top + elm.offsetHeight + 4;
|
|
54
|
+
if (top + this.menu.offsetHeight > container.clientHeight) {
|
|
55
|
+
top = offset.top - this.menu.offsetHeight - 4;
|
|
56
|
+
}
|
|
57
|
+
dom.setPosition(this.menu, { t: top, l: offset.left });
|
|
58
|
+
document.addEventListener('mousedown', () => dom.hideElement(this.menu), { once: true });
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
get menu() { return __classPrivateFieldGet(this, _BlockEdit_menu, "f")?.value; }
|
|
62
|
+
updated() {
|
|
63
|
+
if (this.menu.parentNode == this.shadowRoot) {
|
|
64
|
+
document.body.appendChild(this.menu);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
disconnectedCallback() {
|
|
68
|
+
if (this.menu)
|
|
69
|
+
this.shadowRoot.appendChild(this.menu);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
_BlockEdit_menu = new WeakMap();
|
|
73
|
+
BlockEdit.styles = css `
|
|
18
74
|
* {
|
|
19
75
|
box-sizing: border-box;
|
|
20
76
|
}
|
|
@@ -35,4 +91,69 @@ var _BlockEdit_menu,_BlockHandleView_provider,_BlockHandleView_ctx,_BlockHandleV
|
|
|
35
91
|
flex: 0;
|
|
36
92
|
text-align: center;
|
|
37
93
|
}
|
|
38
|
-
|
|
94
|
+
`;
|
|
95
|
+
__decorate([
|
|
96
|
+
property({ type: Object })
|
|
97
|
+
], BlockEdit.prototype, "ctx", void 0);
|
|
98
|
+
__decorate([
|
|
99
|
+
property({ type: Object })
|
|
100
|
+
], BlockEdit.prototype, "md", void 0);
|
|
101
|
+
BlockEdit = __decorate([
|
|
102
|
+
customElement('og-markdown-block-edit')
|
|
103
|
+
], BlockEdit);
|
|
104
|
+
export { BlockEdit };
|
|
105
|
+
export class BlockHandleView {
|
|
106
|
+
constructor(ctx, md) {
|
|
107
|
+
_BlockHandleView_provider.set(this, void 0);
|
|
108
|
+
_BlockHandleView_ctx.set(this, void 0);
|
|
109
|
+
_BlockHandleView_content.set(this, void 0);
|
|
110
|
+
this.update = () => {
|
|
111
|
+
__classPrivateFieldGet(this, _BlockHandleView_provider, "f").update();
|
|
112
|
+
};
|
|
113
|
+
this.destroy = () => {
|
|
114
|
+
__classPrivateFieldGet(this, _BlockHandleView_provider, "f").destroy();
|
|
115
|
+
};
|
|
116
|
+
_BlockHandleView_onAdd.set(this, () => {
|
|
117
|
+
const ctx = __classPrivateFieldGet(this, _BlockHandleView_ctx, "f");
|
|
118
|
+
const view = ctx.get(this.md.core.editorViewCtx);
|
|
119
|
+
if (!view.hasFocus())
|
|
120
|
+
view.focus();
|
|
121
|
+
const { state, dispatch } = view;
|
|
122
|
+
const active = __classPrivateFieldGet(this, _BlockHandleView_provider, "f").active;
|
|
123
|
+
if (!active)
|
|
124
|
+
return;
|
|
125
|
+
const $pos = active.$pos;
|
|
126
|
+
const pos = $pos.pos + active.node.nodeSize;
|
|
127
|
+
let tr = state.tr.insert(pos, this.md.presets.commonmark.paragraphSchema.type(ctx).create());
|
|
128
|
+
tr = tr.setSelection(this.md.prose.state.TextSelection.near(tr.doc.resolve(pos)));
|
|
129
|
+
dispatch(tr.scrollIntoView());
|
|
130
|
+
__classPrivateFieldGet(this, _BlockHandleView_provider, "f").hide();
|
|
131
|
+
if (__classPrivateFieldGet(this, _BlockHandleView_content, "f").menu) {
|
|
132
|
+
const el = active.el.nextElementSibling;
|
|
133
|
+
if (el)
|
|
134
|
+
__classPrivateFieldGet(this, _BlockHandleView_content, "f").showMenu(el);
|
|
135
|
+
}
|
|
136
|
+
// ctx.get(menuAPI.key).show(tr.selection.from);
|
|
137
|
+
});
|
|
138
|
+
this.md = md;
|
|
139
|
+
__classPrivateFieldSet(this, _BlockHandleView_ctx, ctx, "f");
|
|
140
|
+
const content = dom.createElement('og-markdown-block-edit');
|
|
141
|
+
content.ctx = ctx;
|
|
142
|
+
content.md = md;
|
|
143
|
+
content.addEventListener('add', __classPrivateFieldGet(this, _BlockHandleView_onAdd, "f"));
|
|
144
|
+
__classPrivateFieldSet(this, _BlockHandleView_content, content, "f");
|
|
145
|
+
__classPrivateFieldSet(this, _BlockHandleView_provider, new md.plugins.block.BlockProvider({
|
|
146
|
+
ctx,
|
|
147
|
+
content,
|
|
148
|
+
getOffset: () => 10,
|
|
149
|
+
getPlacement: ({ active, blockDom }) => {
|
|
150
|
+
dom.setPosition(blockDom, { l: 0 });
|
|
151
|
+
dom.setSize(blockDom, { h: active.el.offsetHeight, w: 40 });
|
|
152
|
+
return 'left';
|
|
153
|
+
}
|
|
154
|
+
}), "f");
|
|
155
|
+
this.update();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
_BlockHandleView_provider = new WeakMap(), _BlockHandleView_ctx = new WeakMap(), _BlockHandleView_content = new WeakMap(), _BlockHandleView_onAdd = new WeakMap();
|
|
159
|
+
//# sourceMappingURL=blockEdit.js.map
|
|
@@ -10,7 +10,7 @@ export declare class BlockEditMenu extends LitElement {
|
|
|
10
10
|
ctx: milkdown.ctx.Ctx;
|
|
11
11
|
md: typeof milkdown;
|
|
12
12
|
get menuItems(): BlockMenuItem[];
|
|
13
|
-
render: () => import("lit").TemplateResult<1>;
|
|
13
|
+
render: () => import("lit-html").TemplateResult<1>;
|
|
14
14
|
}
|
|
15
15
|
export {};
|
|
16
16
|
//# sourceMappingURL=blockEditMenu.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blockEditMenu.d.ts","sourceRoot":"","sources":["../../../src/components/features/blockEditMenu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAI5C,OAAO,EAAkD,QAAQ,EAAO,MAAM,iBAAiB,CAAC;AAChG,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAWzD,KAAK,aAAa,GAAG,QAAQ,GAAG;IAAC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,IAAI,CAAA;CAAC,CAAC;AA8I1E,qBACa,aAAc,SAAQ,UAAU;;IAE5C,MAAM,CAAC,MAAM,0BAkBX;IAKF,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;IAGtB,EAAE,EAAE,OAAO,QAAQ,CAAC;IAGpB,IAAI,SAAS,oBAA6E;IAmC1F,MAAM,
|
|
1
|
+
{"version":3,"file":"blockEditMenu.d.ts","sourceRoot":"","sources":["../../../src/components/features/blockEditMenu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAI5C,OAAO,EAAkD,QAAQ,EAAO,MAAM,iBAAiB,CAAC;AAChG,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAWzD,KAAK,aAAa,GAAG,QAAQ,GAAG;IAAC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,IAAI,CAAA;CAAC,CAAC;AA8I1E,qBACa,aAAc,SAAQ,UAAU;;IAE5C,MAAM,CAAC,MAAM,0BAkBX;IAKF,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;IAGtB,EAAE,EAAE,OAAO,QAAQ,CAAC;IAGpB,IAAI,SAAS,oBAA6E;IAmC1F,MAAM,6CAMJ;CACF"}
|
|
@@ -1,10 +1,220 @@
|
|
|
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 __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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
13
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
14
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
15
|
+
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");
|
|
16
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
17
|
+
};
|
|
18
|
+
var _BlockEditMenu_menu, _BlockEditMenu_menuItems, _BlockEditMenu_createComponent, _BlockEditMenu_onTabSelect;
|
|
19
|
+
import { LitElement, css, html } from "lit";
|
|
20
|
+
import { customElement, property } from "lit/decorators.js";
|
|
21
|
+
import { msg } from "@omegagrid/localize";
|
|
22
|
+
import { dom } from "@omegagrid/core";
|
|
23
|
+
import { addBlockType, clearContentAndAddBlockType, clearContentAndSetBlockType, clearContentAndWrapInBlockType, clearRange } from "./utils";
|
|
24
|
+
const items = [
|
|
25
|
+
{ id: 'sectionText', title: msg('Text') },
|
|
26
|
+
{ id: 'sectionList', title: msg('List') },
|
|
27
|
+
{ id: 'sectionAdvanced', title: msg('Advanced') },
|
|
28
|
+
];
|
|
29
|
+
const createMenuItems = (md) => [
|
|
30
|
+
{ key: 'sectionText', value: msg('Text'), divider: true, type: 'label' },
|
|
31
|
+
{
|
|
32
|
+
key: 'text',
|
|
33
|
+
value: msg('Text'),
|
|
34
|
+
icon: 'text', onRun: ctx => {
|
|
35
|
+
const view = ctx.get(md.core.editorViewCtx);
|
|
36
|
+
const { dispatch, state } = view;
|
|
37
|
+
const command = clearContentAndSetBlockType(md.presets.commonmark.paragraphSchema.type(ctx));
|
|
38
|
+
command(state, dispatch);
|
|
39
|
+
}
|
|
40
|
+
}, ...(new Array(6).fill(0).map((_, i) => ({
|
|
41
|
+
key: `square${i + 1}`,
|
|
42
|
+
value: msg('Heading') + (i + 1),
|
|
43
|
+
icon: `square-${i + 1}`,
|
|
44
|
+
onRun: (ctx) => {
|
|
45
|
+
const view = ctx.get(md.core.editorViewCtx);
|
|
46
|
+
const { dispatch, state } = view;
|
|
47
|
+
const command = clearContentAndSetBlockType(md.presets.commonmark.headingSchema.type(ctx), { level: i + 1 });
|
|
48
|
+
command(state, dispatch);
|
|
49
|
+
}
|
|
50
|
+
}))), {
|
|
51
|
+
key: 'quote',
|
|
52
|
+
value: msg('Quote'),
|
|
53
|
+
icon: 'quote-right',
|
|
54
|
+
onRun: ctx => {
|
|
55
|
+
const view = ctx.get(md.core.editorViewCtx);
|
|
56
|
+
const { dispatch, state } = view;
|
|
57
|
+
const command = clearContentAndWrapInBlockType(md.presets.commonmark.blockquoteSchema.type(ctx));
|
|
58
|
+
command(state, dispatch);
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
key: 'divider',
|
|
62
|
+
value: msg('Divider'),
|
|
63
|
+
icon: 'horizontal-rule',
|
|
64
|
+
onRun: (ctx) => {
|
|
65
|
+
const view = ctx.get(md.core.editorViewCtx);
|
|
66
|
+
const { dispatch, state } = view;
|
|
67
|
+
const command = clearContentAndAddBlockType(md.presets.commonmark.hrSchema.type(ctx));
|
|
68
|
+
command(state, dispatch);
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
key: 'sectionList',
|
|
72
|
+
value: msg('List'),
|
|
73
|
+
divider: true,
|
|
74
|
+
type: 'label'
|
|
75
|
+
}, {
|
|
76
|
+
key: 'bulletList',
|
|
77
|
+
value: msg('Bullet List'),
|
|
78
|
+
icon: 'list',
|
|
79
|
+
onRun: (ctx) => {
|
|
80
|
+
const view = ctx.get(md.core.editorViewCtx);
|
|
81
|
+
const { dispatch, state } = view;
|
|
82
|
+
const command = clearContentAndWrapInBlockType(md.presets.commonmark.bulletListSchema.type(ctx));
|
|
83
|
+
command(state, dispatch);
|
|
84
|
+
}
|
|
85
|
+
}, {
|
|
86
|
+
key: 'orderedList',
|
|
87
|
+
value: msg('Ordered List'),
|
|
88
|
+
icon: 'list-ol',
|
|
89
|
+
onRun: (ctx) => {
|
|
90
|
+
const view = ctx.get(md.core.editorViewCtx);
|
|
91
|
+
const { dispatch, state } = view;
|
|
92
|
+
const command = clearContentAndWrapInBlockType(md.presets.commonmark.orderedListSchema.type(ctx));
|
|
93
|
+
command(state, dispatch);
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
key: 'todoList',
|
|
97
|
+
value: msg('Todo List'),
|
|
98
|
+
icon: 'list-check',
|
|
99
|
+
onRun: (ctx) => {
|
|
100
|
+
const view = ctx.get(md.core.editorViewCtx);
|
|
101
|
+
const { dispatch, state } = view;
|
|
102
|
+
const command = clearContentAndWrapInBlockType(md.presets.commonmark.listItemSchema.type(ctx), { checked: false });
|
|
103
|
+
command(state, dispatch);
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
key: 'sectionAdvanced',
|
|
107
|
+
value: msg('Advanced'),
|
|
108
|
+
divider: true,
|
|
109
|
+
type: 'label'
|
|
110
|
+
}, {
|
|
111
|
+
key: 'image',
|
|
112
|
+
value: msg('Image'),
|
|
113
|
+
icon: 'image',
|
|
114
|
+
onRun: (ctx) => {
|
|
115
|
+
const view = ctx.get(md.core.editorViewCtx);
|
|
116
|
+
const { dispatch, state } = view;
|
|
117
|
+
const command = clearContentAndAddBlockType(md.components.imageBlock.imageBlockSchema.type(ctx));
|
|
118
|
+
command(state, dispatch);
|
|
119
|
+
}
|
|
120
|
+
}, {
|
|
121
|
+
key: 'html',
|
|
122
|
+
value: msg('Raw HTML'),
|
|
123
|
+
icon: 'code',
|
|
124
|
+
onRun: (ctx) => {
|
|
125
|
+
const view = ctx.get(md.core.editorViewCtx);
|
|
126
|
+
const { dispatch, state } = view;
|
|
127
|
+
const tr = addBlockType(clearRange(state.tr), md.presets.commonmark.htmlSchema.type(ctx), null);
|
|
128
|
+
dispatch(tr.scrollIntoView());
|
|
129
|
+
requestAnimationFrame(() => {
|
|
130
|
+
const node = view.domAtPos(tr.selection.$anchor.pos)?.node;
|
|
131
|
+
if (node) {
|
|
132
|
+
const block = node.querySelector('og-markdown-html-block');
|
|
133
|
+
block?.startEdit();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}, {
|
|
138
|
+
key: 'code',
|
|
139
|
+
value: msg('Code'),
|
|
140
|
+
icon: 'code',
|
|
141
|
+
onRun: (ctx) => {
|
|
142
|
+
const view = ctx.get(md.core.editorViewCtx);
|
|
143
|
+
const { dispatch, state } = view;
|
|
144
|
+
const command = clearContentAndAddBlockType(md.presets.commonmark.codeBlockSchema.type(ctx));
|
|
145
|
+
command(state, dispatch);
|
|
146
|
+
}
|
|
147
|
+
}, {
|
|
148
|
+
key: 'table',
|
|
149
|
+
value: msg('Table'),
|
|
150
|
+
icon: 'table',
|
|
151
|
+
onRun: (ctx) => {
|
|
152
|
+
const view = ctx.get(md.core.editorViewCtx);
|
|
153
|
+
const { dispatch, state } = view;
|
|
154
|
+
const tr = clearRange(state.tr);
|
|
155
|
+
const table = md.presets.gfm.createTable(ctx, 3, 3);
|
|
156
|
+
tr.replaceSelectionWith(table);
|
|
157
|
+
const { from } = tr.selection;
|
|
158
|
+
const pos = from - table.nodeSize + 2;
|
|
159
|
+
dispatch(tr);
|
|
160
|
+
requestAnimationFrame(() => {
|
|
161
|
+
const selection = md.prose.state.NodeSelection.create(view.state.tr.doc, pos);
|
|
162
|
+
dispatch(view.state.tr.setSelection(selection).scrollIntoView());
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
];
|
|
167
|
+
let BlockEditMenu = class BlockEditMenu extends LitElement {
|
|
168
|
+
constructor() {
|
|
169
|
+
super(...arguments);
|
|
170
|
+
_BlockEditMenu_menu.set(this, void 0);
|
|
171
|
+
_BlockEditMenu_menuItems.set(this, void 0);
|
|
172
|
+
_BlockEditMenu_createComponent.set(this, (_id) => {
|
|
173
|
+
if (!__classPrivateFieldGet(this, _BlockEditMenu_menu, "f")) {
|
|
174
|
+
const menuItems = this.menuItems;
|
|
175
|
+
__classPrivateFieldSet(this, _BlockEditMenu_menu, dom.createElement('og-menu'), "f");
|
|
176
|
+
__classPrivateFieldGet(this, _BlockEditMenu_menu, "f").dynamicWidth = false;
|
|
177
|
+
__classPrivateFieldGet(this, _BlockEditMenu_menu, "f").disabledFocus = true;
|
|
178
|
+
__classPrivateFieldGet(this, _BlockEditMenu_menu, "f").style.width = '100%';
|
|
179
|
+
__classPrivateFieldGet(this, _BlockEditMenu_menu, "f").style.height = '100%';
|
|
180
|
+
__classPrivateFieldGet(this, _BlockEditMenu_menu, "f").style.border = 'none';
|
|
181
|
+
__classPrivateFieldGet(this, _BlockEditMenu_menu, "f").items = menuItems;
|
|
182
|
+
__classPrivateFieldGet(this, _BlockEditMenu_menu, "f").addEventListener('menu.select', (e) => {
|
|
183
|
+
const item = menuItems.find(item => item.key === e.item.key);
|
|
184
|
+
if (item?.onRun) {
|
|
185
|
+
item.onRun(this.ctx);
|
|
186
|
+
this.dispatchEvent(new Event('run'));
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
__classPrivateFieldGet(this, _BlockEditMenu_menu, "f").addEventListener('mousedown', (e) => {
|
|
190
|
+
e.stopPropagation();
|
|
191
|
+
e.preventDefault();
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return __classPrivateFieldGet(this, _BlockEditMenu_menu, "f");
|
|
195
|
+
});
|
|
196
|
+
_BlockEditMenu_onTabSelect.set(this, (e) => {
|
|
197
|
+
if (__classPrivateFieldGet(this, _BlockEditMenu_menu, "f")?.list) {
|
|
198
|
+
const index = this.menuItems.findIndex(item => item.key === e.tab.id);
|
|
199
|
+
if (index > -1)
|
|
200
|
+
__classPrivateFieldGet(this, _BlockEditMenu_menu, "f").list.scrollToIndex(index);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
this.render = () => html `
|
|
2
204
|
<og-tabcontainer
|
|
3
|
-
.createComponent="${__classPrivateFieldGet(this,_BlockEditMenu_createComponent,"f")}"
|
|
205
|
+
.createComponent="${__classPrivateFieldGet(this, _BlockEditMenu_createComponent, "f")}"
|
|
4
206
|
.items="${items}"
|
|
5
|
-
@tab.select="${__classPrivateFieldGet(this,_BlockEditMenu_onTabSelect,"f")}">
|
|
207
|
+
@tab.select="${__classPrivateFieldGet(this, _BlockEditMenu_onTabSelect, "f")}">
|
|
6
208
|
</og-tabcontainer>
|
|
7
|
-
|
|
209
|
+
`;
|
|
210
|
+
}
|
|
211
|
+
get menuItems() { return __classPrivateFieldGet(this, _BlockEditMenu_menuItems, "f") ?? (__classPrivateFieldSet(this, _BlockEditMenu_menuItems, createMenuItems(this.md), "f")); }
|
|
212
|
+
};
|
|
213
|
+
_BlockEditMenu_menu = new WeakMap();
|
|
214
|
+
_BlockEditMenu_menuItems = new WeakMap();
|
|
215
|
+
_BlockEditMenu_createComponent = new WeakMap();
|
|
216
|
+
_BlockEditMenu_onTabSelect = new WeakMap();
|
|
217
|
+
BlockEditMenu.styles = css `
|
|
8
218
|
* {
|
|
9
219
|
box-sizing: border-box;
|
|
10
220
|
}
|
|
@@ -22,4 +232,15 @@ var _BlockEditMenu_menu,_BlockEditMenu_menuItems,_BlockEditMenu_createComponent,
|
|
|
22
232
|
width: 100%;
|
|
23
233
|
height: 100%;
|
|
24
234
|
}
|
|
25
|
-
|
|
235
|
+
`;
|
|
236
|
+
__decorate([
|
|
237
|
+
property({ type: Object })
|
|
238
|
+
], BlockEditMenu.prototype, "ctx", void 0);
|
|
239
|
+
__decorate([
|
|
240
|
+
property({ type: Object })
|
|
241
|
+
], BlockEditMenu.prototype, "md", void 0);
|
|
242
|
+
BlockEditMenu = __decorate([
|
|
243
|
+
customElement('og-markdown-block-edit-menu')
|
|
244
|
+
], BlockEditMenu);
|
|
245
|
+
export { BlockEditMenu };
|
|
246
|
+
//# sourceMappingURL=blockEditMenu.js.map
|
|
@@ -1 +1,135 @@
|
|
|
1
|
-
import{dom}from
|
|
1
|
+
import { dom } from '@omegagrid/core';
|
|
2
|
+
import { CodeBlock } from '@omegagrid/code';
|
|
3
|
+
const DEFAULT_LANGUAGE = 'plaintext';
|
|
4
|
+
export class CodeEditorBlock {
|
|
5
|
+
get editor() { return this.dom?.editor?.editor; }
|
|
6
|
+
get model() { return this.editor?.getModel(); }
|
|
7
|
+
constructor(md, node, view, getPos) {
|
|
8
|
+
this.md = md;
|
|
9
|
+
this.node = node;
|
|
10
|
+
this.view = view;
|
|
11
|
+
this.getPos = getPos;
|
|
12
|
+
this.updating = false;
|
|
13
|
+
this.languageName = 'plaintext';
|
|
14
|
+
this._onChange = (e) => {
|
|
15
|
+
if (this.updating)
|
|
16
|
+
return;
|
|
17
|
+
const model = e.editor.getModel();
|
|
18
|
+
const tr = this.view.state.tr;
|
|
19
|
+
this.view.dispatch(tr.setNodeAttribute(this.getPos() ?? 0, 'content', model.getValue()));
|
|
20
|
+
// const selection = e.editor.getSelection();
|
|
21
|
+
// const selFrom = offset + model.getOffsetAt(selection.getStartPosition());
|
|
22
|
+
// const selTo = offset + model.getOffsetAt(selection.getEndPosition());
|
|
23
|
+
// if (e.changes?.length) {
|
|
24
|
+
// const tr = this.view.state.tr;
|
|
25
|
+
// e.changes.forEach(change => {
|
|
26
|
+
// const { rangeOffset, rangeLength, text } = change;
|
|
27
|
+
// const from = offset + rangeOffset;
|
|
28
|
+
// const to = from + rangeLength;
|
|
29
|
+
// if (text.length) {
|
|
30
|
+
// tr.replaceWith(from, to, this.view.state.schema.text(text));
|
|
31
|
+
// } else {
|
|
32
|
+
// tr.delete(from, to);
|
|
33
|
+
// }
|
|
34
|
+
// offset += text.length - rangeLength;
|
|
35
|
+
// });
|
|
36
|
+
// tr.setSelection(this.md.prose.state.TextSelection.create(tr.doc, selFrom, selTo))
|
|
37
|
+
// this.view.dispatch(tr)
|
|
38
|
+
// }
|
|
39
|
+
};
|
|
40
|
+
this.setLanguage = (language) => {
|
|
41
|
+
this.view.dispatch(this.view.state.tr.setNodeAttribute(this.getPos() ?? 0, 'language', language));
|
|
42
|
+
};
|
|
43
|
+
this.dom = this.createComponent();
|
|
44
|
+
this.updateLanguage();
|
|
45
|
+
}
|
|
46
|
+
createComponent() {
|
|
47
|
+
const component = this.view.editable
|
|
48
|
+
? dom.createElement('og-code-block')
|
|
49
|
+
: dom.createElement('og-code-view');
|
|
50
|
+
component.content = this.node.textContent;
|
|
51
|
+
if (component instanceof CodeBlock) {
|
|
52
|
+
component.dynamicHeight = true;
|
|
53
|
+
component.editorOptions = {
|
|
54
|
+
minimap: { enabled: false },
|
|
55
|
+
stickyScroll: { enabled: false },
|
|
56
|
+
};
|
|
57
|
+
// dom.setSize(component, {h: 500});
|
|
58
|
+
component.addEventListener('code.change', this._onChange);
|
|
59
|
+
component.addEventListener('changeLanguage', (e) => this.setLanguage(e.value));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
component.copy = true;
|
|
63
|
+
}
|
|
64
|
+
return component;
|
|
65
|
+
}
|
|
66
|
+
setSelection(anchor, head) {
|
|
67
|
+
if (!this.dom?.isConnected)
|
|
68
|
+
return;
|
|
69
|
+
this.dom.focus();
|
|
70
|
+
this.updating = true;
|
|
71
|
+
const model = this.model;
|
|
72
|
+
if (model) {
|
|
73
|
+
const start = model.getPositionAt(anchor);
|
|
74
|
+
const end = model.getPositionAt(head);
|
|
75
|
+
this.editor.setSelection({
|
|
76
|
+
startLineNumber: start.lineNumber,
|
|
77
|
+
startColumn: start.column,
|
|
78
|
+
endLineNumber: end.lineNumber,
|
|
79
|
+
endColumn: end.column
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
this.updating = false;
|
|
83
|
+
}
|
|
84
|
+
update(node) {
|
|
85
|
+
if (node.type !== this.node.type)
|
|
86
|
+
return false;
|
|
87
|
+
if (this.updating)
|
|
88
|
+
return true;
|
|
89
|
+
this.node = node;
|
|
90
|
+
this.updateLanguage();
|
|
91
|
+
this.dom.content = node.textContent;
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
selectNode() {
|
|
95
|
+
// this.component.selected = true
|
|
96
|
+
this.dom.focus();
|
|
97
|
+
}
|
|
98
|
+
deselectNode() {
|
|
99
|
+
// this.component.selected = false
|
|
100
|
+
}
|
|
101
|
+
stopEvent() {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
destroy() {
|
|
105
|
+
// this.component.destroy()
|
|
106
|
+
}
|
|
107
|
+
updateLanguage() {
|
|
108
|
+
this.languageName = this.node.attrs.language || DEFAULT_LANGUAGE;
|
|
109
|
+
this.dom.language = this.languageName;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export const defaultCodeEditorConfig = {};
|
|
113
|
+
export function createCodeBlockConfig(md) {
|
|
114
|
+
return md.utils.$ctx(defaultCodeEditorConfig, 'codeEditorConfigCtx');
|
|
115
|
+
}
|
|
116
|
+
export function createCodeBlockView(md) {
|
|
117
|
+
return md.utils.$view(md.presets.commonmark.codeBlockSchema.node, _ctx => {
|
|
118
|
+
// const config = ctx.get('codeBlockConfigCtx')
|
|
119
|
+
// const languageLoader = new LanguageLoader(config.languages)
|
|
120
|
+
return (node, view, getPos) => new CodeEditorBlock(md, node, view, getPos);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// function computeChange(oldVal: string, newVal: string): { from: number; to: number; text: string } | null {
|
|
124
|
+
// if (oldVal === newVal) return null;
|
|
125
|
+
// let start = 0;
|
|
126
|
+
// let oldEnd = oldVal.length;
|
|
127
|
+
// let newEnd = newVal.length;
|
|
128
|
+
// while (start < oldEnd && oldVal.charCodeAt(start) === newVal.charCodeAt(start)) ++start;
|
|
129
|
+
// while (oldEnd > start && newEnd > start && oldVal.charCodeAt(oldEnd - 1) === newVal.charCodeAt(newEnd - 1)) {
|
|
130
|
+
// oldEnd--;
|
|
131
|
+
// newEnd--;
|
|
132
|
+
// }
|
|
133
|
+
// return {from: start, to: oldEnd, text: newVal.slice(start, newEnd)};
|
|
134
|
+
// }
|
|
135
|
+
//# sourceMappingURL=codeBlock.js.map
|
|
@@ -15,7 +15,7 @@ export declare class HtmlBlockComponent extends LitElement {
|
|
|
15
15
|
startEdit: () => void;
|
|
16
16
|
constructor();
|
|
17
17
|
commit(): void;
|
|
18
|
-
render: () => import("lit-html/
|
|
18
|
+
render: () => import("lit-html/directive").DirectiveResult<typeof import("lit-html/directives/unsafe-html").UnsafeHTMLDirective>;
|
|
19
19
|
}
|
|
20
20
|
export declare class HtmlBlock implements NodeView {
|
|
21
21
|
md: typeof milkdown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlBlock.d.ts","sourceRoot":"","sources":["../../../src/components/features/htmlBlock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC;AACrE,OAAO,EAAO,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAK5C,qBACa,kBAAmB,SAAQ,UAAU;;IAEjD,MAAM,CAAC,MAAM,0BA6BX;IAIF,IACI,OAAO,IACM,MAAM,CADe;IACtC,IAAI,OAAO,CAAC,GAAG,EAAE,MAAM,EAGtB;IAGD,QAAQ,UAAS;IAGjB,OAAO,UAAS;IAGhB,MAAM,EAAE,SAAS,CAAC;IAElB,SAAS,aAEP;;IAOF,MAAM;IAMN,MAAM,
|
|
1
|
+
{"version":3,"file":"htmlBlock.d.ts","sourceRoot":"","sources":["../../../src/components/features/htmlBlock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC;AACrE,OAAO,EAAO,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAK5C,qBACa,kBAAmB,SAAQ,UAAU;;IAEjD,MAAM,CAAC,MAAM,0BA6BX;IAIF,IACI,OAAO,IACM,MAAM,CADe;IACtC,IAAI,OAAO,CAAC,GAAG,EAAE,MAAM,EAGtB;IAGD,QAAQ,UAAS;IAGjB,OAAO,UAAS;IAGhB,MAAM,EAAE,SAAS,CAAC;IAElB,SAAS,aAEP;;IAOF,MAAM;IAMN,MAAM,2HAyBuB;CAE7B;AAGD,qBAAa,SAAU,YAAW,QAAQ;IAOjC,EAAE,EAAE,OAAO,QAAQ;IACnB,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,MAAM,MAAM,GAAG,SAAS;IATxC,GAAG,EAAE,kBAAkB,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAS;gBAKjB,EAAE,EAAE,OAAO,QAAQ,EACnB,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,MAAM,GAAG,SAAS;IAQxC,SAAS,GAAI,GAAG,MAAM,CAAC,WAAW,UAIjC;IAED,MAAM,CAAC,IAAI,EAAE,IAAI;IAQjB,UAAU;IAKV,YAAY;IAIZ,SAAS;IAIT,OAAO;CAyEP;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACrD,eAAO,MAAM,uBAAuB,EAAS,gBAAgB,CAAC;AAE9D,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,OAAO,QAAQ,gEAExD;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,OAAO,QAAQ,6HAQtD"}
|