@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,26 +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 _HtmlBlockComponent_content;
|
|
19
|
+
import { dom, events } from '@omegagrid/core';
|
|
20
|
+
import { LitElement, css, html } from 'lit';
|
|
21
|
+
import { customElement, property, query } from 'lit/decorators.js';
|
|
22
|
+
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
|
23
|
+
import { msg } from '@omegagrid/localize';
|
|
24
|
+
let HtmlBlockComponent = class HtmlBlockComponent extends LitElement {
|
|
25
|
+
get content() { return __classPrivateFieldGet(this, _HtmlBlockComponent_content, "f"); }
|
|
26
|
+
set content(val) {
|
|
27
|
+
__classPrivateFieldSet(this, _HtmlBlockComponent_content, val, "f");
|
|
28
|
+
this.requestUpdate();
|
|
29
|
+
}
|
|
30
|
+
constructor() {
|
|
31
|
+
super();
|
|
32
|
+
_HtmlBlockComponent_content.set(this, '');
|
|
33
|
+
this.editable = false;
|
|
34
|
+
this.editing = false;
|
|
35
|
+
this.startEdit = () => {
|
|
36
|
+
this.editing = true;
|
|
37
|
+
};
|
|
38
|
+
this.render = () => this.editable ? html `
|
|
2
39
|
<div class="title">Raw HTML</div>
|
|
3
40
|
<div class="body">
|
|
4
|
-
${this.editing?html`
|
|
41
|
+
${this.editing ? html `
|
|
5
42
|
<og-code-block
|
|
6
43
|
disableToolbar
|
|
7
44
|
dynamicHeight
|
|
8
45
|
language="html"
|
|
9
46
|
.content="${this.content}"
|
|
10
|
-
.editorOptions="${{
|
|
11
|
-
|
|
12
|
-
|
|
47
|
+
.editorOptions="${{
|
|
48
|
+
minimap: { enabled: false },
|
|
49
|
+
lineNumbers: { renderType: 0 }
|
|
50
|
+
}}"
|
|
51
|
+
@blur="${() => this.commit()}"
|
|
52
|
+
@code.ready="${() => this.editor.focus()}">
|
|
13
53
|
</og-code-block>
|
|
14
|
-
|
|
54
|
+
` : (this.content ? html `
|
|
15
55
|
<og-code-view
|
|
16
56
|
language="html"
|
|
17
57
|
.content="${this.content}" >
|
|
18
58
|
</og-code-view>
|
|
19
|
-
|
|
20
|
-
<div class="placeholder">${msg(
|
|
21
|
-
`}
|
|
59
|
+
` : html `
|
|
60
|
+
<div class="placeholder">${msg('Insert HTML')}</div>
|
|
61
|
+
`)}
|
|
22
62
|
</div>
|
|
23
|
-
|
|
63
|
+
` : unsafeHTML(this.content);
|
|
64
|
+
this.addEventListener('click', () => this.startEdit());
|
|
65
|
+
}
|
|
66
|
+
commit() {
|
|
67
|
+
this.editing = false;
|
|
68
|
+
__classPrivateFieldSet(this, _HtmlBlockComponent_content, this.editor.model.getValue(), "f");
|
|
69
|
+
this.dispatchEvent(new events.ChangeEvent(__classPrivateFieldGet(this, _HtmlBlockComponent_content, "f")));
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
_HtmlBlockComponent_content = new WeakMap();
|
|
73
|
+
HtmlBlockComponent.styles = css `
|
|
24
74
|
* {
|
|
25
75
|
box-sizing: border-box;
|
|
26
76
|
}
|
|
@@ -49,4 +99,75 @@ var _HtmlBlockComponent_content,__decorate=this&&this.__decorate||function(t,e,o
|
|
|
49
99
|
og-code-view, .placeholder {
|
|
50
100
|
cursor: pointer;
|
|
51
101
|
}
|
|
52
|
-
|
|
102
|
+
`;
|
|
103
|
+
__decorate([
|
|
104
|
+
property({ type: String })
|
|
105
|
+
], HtmlBlockComponent.prototype, "content", null);
|
|
106
|
+
__decorate([
|
|
107
|
+
property({ type: Boolean })
|
|
108
|
+
], HtmlBlockComponent.prototype, "editable", void 0);
|
|
109
|
+
__decorate([
|
|
110
|
+
property({ type: Boolean })
|
|
111
|
+
], HtmlBlockComponent.prototype, "editing", void 0);
|
|
112
|
+
__decorate([
|
|
113
|
+
query('og-code-block')
|
|
114
|
+
], HtmlBlockComponent.prototype, "editor", void 0);
|
|
115
|
+
HtmlBlockComponent = __decorate([
|
|
116
|
+
customElement('og-markdown-html-block')
|
|
117
|
+
], HtmlBlockComponent);
|
|
118
|
+
export { HtmlBlockComponent };
|
|
119
|
+
export class HtmlBlock {
|
|
120
|
+
// private get editor() { return (this.dom as CodeBlock)?.editor?.editor }
|
|
121
|
+
// get model() { return this.editor?.getModel() }
|
|
122
|
+
constructor(md, node, view, getPos) {
|
|
123
|
+
this.md = md;
|
|
124
|
+
this.node = node;
|
|
125
|
+
this.view = view;
|
|
126
|
+
this.getPos = getPos;
|
|
127
|
+
this.updating = false;
|
|
128
|
+
this._onChange = (e) => {
|
|
129
|
+
if (this.updating)
|
|
130
|
+
return;
|
|
131
|
+
const tr = this.view.state.tr;
|
|
132
|
+
this.view.dispatch(tr.setNodeAttribute(this.getPos() ?? 0, 'value', e.value));
|
|
133
|
+
};
|
|
134
|
+
this.dom = dom.createElement('og-markdown-html-block');
|
|
135
|
+
this.dom.editable = this.view.editable;
|
|
136
|
+
this.dom.content = this.node.attrs?.value;
|
|
137
|
+
this.dom.addEventListener('change', this._onChange);
|
|
138
|
+
}
|
|
139
|
+
update(node) {
|
|
140
|
+
if (node.type !== this.node.type)
|
|
141
|
+
return false;
|
|
142
|
+
if (this.updating)
|
|
143
|
+
return true;
|
|
144
|
+
this.node = node;
|
|
145
|
+
this.dom.content = this.node.attrs?.value;
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
selectNode() {
|
|
149
|
+
if (this.view.editable)
|
|
150
|
+
this.dom.startEdit();
|
|
151
|
+
this.dom.focus();
|
|
152
|
+
}
|
|
153
|
+
deselectNode() {
|
|
154
|
+
// this.component.selected = false
|
|
155
|
+
}
|
|
156
|
+
stopEvent() {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
destroy() {
|
|
160
|
+
// this.component.destroy()
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export const defaultCodeEditorConfig = {};
|
|
164
|
+
export function createHtmlBlockConfig(md) {
|
|
165
|
+
return md.utils.$ctx(defaultCodeEditorConfig, 'htmlEditorConfigCtx');
|
|
166
|
+
}
|
|
167
|
+
export function createHtmlBlockView(md) {
|
|
168
|
+
return md.utils.$view(md.presets.commonmark.htmlSchema.node, _ctx => {
|
|
169
|
+
// const config = ctx.get('codeBlockConfigCtx')
|
|
170
|
+
return (node, view, getPos) => new HtmlBlock(md, node, view, getPos);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=htmlBlock.js.map
|
|
@@ -1 +1,178 @@
|
|
|
1
|
-
import
|
|
1
|
+
// import { Editor } from '@milkdown/kit/core';
|
|
2
|
+
// import { createSlice } from '@milkdown/kit/ctx';
|
|
3
|
+
// import { BlockProvider, block, blockConfig } from '@milkdown/kit/plugin/block'
|
|
4
|
+
import { BlockHandleView } from './blockEdit';
|
|
5
|
+
import { ToolbarView } from './toolbar';
|
|
6
|
+
import { createPlaceHolder } from './placeholder';
|
|
7
|
+
import { createCodeBlockConfig, createCodeBlockView } from './codeBlock';
|
|
8
|
+
import { createHtmlBlockConfig, createHtmlBlockView } from './htmlBlock';
|
|
9
|
+
import linkEdit from './linkEdit';
|
|
10
|
+
export * from './blockEditMenu';
|
|
11
|
+
export * from './htmlBlock';
|
|
12
|
+
export * from './linkEdit';
|
|
13
|
+
export function configureFeatures(features, md) {
|
|
14
|
+
return (ctx) => {
|
|
15
|
+
ctx.inject(md.ctx.createSlice([], 'FeaturesCtx'), features);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const createIcon = (md, icon) => md.atomico.html `<og-fa-icon icon=${icon}></og-fa-icon>`;
|
|
19
|
+
export var EditorFeature;
|
|
20
|
+
(function (EditorFeature) {
|
|
21
|
+
EditorFeature["BlockEdit"] = "block-edit";
|
|
22
|
+
EditorFeature["Cursor"] = "cursor";
|
|
23
|
+
EditorFeature["CodeEditor"] = "code-editor";
|
|
24
|
+
// ListItem = 'list-item',
|
|
25
|
+
EditorFeature["LinkTooltip"] = "link-tooltip";
|
|
26
|
+
EditorFeature["ImageBlock"] = "image-block";
|
|
27
|
+
EditorFeature["Toolbar"] = "toolbar";
|
|
28
|
+
EditorFeature["Placeholder"] = "placeholder";
|
|
29
|
+
EditorFeature["Table"] = "table";
|
|
30
|
+
EditorFeature["Html"] = "html";
|
|
31
|
+
})(EditorFeature || (EditorFeature = {}));
|
|
32
|
+
const createModifyImageUrl = (fn) => {
|
|
33
|
+
return async (url) => {
|
|
34
|
+
if (!url)
|
|
35
|
+
return null;
|
|
36
|
+
const modUrl = fn(url);
|
|
37
|
+
return typeof url === 'string' ? modUrl : await modUrl;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export function getFeatures(editor, md, options) {
|
|
41
|
+
const modifyImageUrl = options.modifyImageUrl ? createModifyImageUrl(options.modifyImageUrl) : null;
|
|
42
|
+
return new Map([
|
|
43
|
+
[EditorFeature.BlockEdit, {
|
|
44
|
+
default: true,
|
|
45
|
+
init: () => {
|
|
46
|
+
editor.config((ctx) => {
|
|
47
|
+
ctx.set(md.plugins.block.blockConfig.key, {
|
|
48
|
+
filterNodes: (pos) => {
|
|
49
|
+
const filter = md.prose.findParent((node) => ['table', 'blockquote'].includes(node.type.name))(pos);
|
|
50
|
+
if (filter)
|
|
51
|
+
return false;
|
|
52
|
+
return true;
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
ctx.set(md.plugins.block.block.key, {
|
|
56
|
+
view: () => new BlockHandleView(ctx, md),
|
|
57
|
+
});
|
|
58
|
+
}).use(md.plugins.block.block);
|
|
59
|
+
// .config((ctx) => configureMenu(ctx, config))
|
|
60
|
+
// .use(menuAPI)
|
|
61
|
+
// .use(menu)
|
|
62
|
+
}
|
|
63
|
+
}], [EditorFeature.Cursor, {
|
|
64
|
+
default: true,
|
|
65
|
+
init: () => {
|
|
66
|
+
editor.config((ctx) => {
|
|
67
|
+
ctx.update(md.plugins.cursor.dropCursorConfig.key, () => ({
|
|
68
|
+
class: 'md-editor-drop-cursor',
|
|
69
|
+
width: 4,
|
|
70
|
+
// color: '#ff0000',
|
|
71
|
+
}));
|
|
72
|
+
}).use(md.plugins.cursor.cursor);
|
|
73
|
+
}
|
|
74
|
+
}], [EditorFeature.ImageBlock, {
|
|
75
|
+
default: true,
|
|
76
|
+
init: () => {
|
|
77
|
+
editor.config((ctx) => {
|
|
78
|
+
ctx.update(md.components.imageInline.inlineImageConfig.key, (_value) => ({
|
|
79
|
+
uploadButton: () => createIcon(md, 'upload'),
|
|
80
|
+
imageIcon: () => createIcon(md, 'image'),
|
|
81
|
+
confirmButton: () => createIcon(md, 'check'),
|
|
82
|
+
uploadPlaceholderText: 'or paste link',
|
|
83
|
+
onUpload: options.onUpload,
|
|
84
|
+
proxyDomURL: modifyImageUrl,
|
|
85
|
+
}));
|
|
86
|
+
ctx.update(md.components.imageBlock.imageBlockConfig.key, (_value) => ({
|
|
87
|
+
uploadButton: () => 'Upload file',
|
|
88
|
+
imageIcon: () => createIcon(md, 'image'),
|
|
89
|
+
captionIcon: () => createIcon(md, 'comment'),
|
|
90
|
+
confirmButton: () => 'Confirm',
|
|
91
|
+
captionPlaceholderText: 'Write Image Caption',
|
|
92
|
+
uploadPlaceholderText: 'or paste link',
|
|
93
|
+
onUpload: options.onUpload,
|
|
94
|
+
proxyDomURL: modifyImageUrl,
|
|
95
|
+
}));
|
|
96
|
+
})
|
|
97
|
+
.use(md.components.imageBlock.imageBlockComponent)
|
|
98
|
+
.use(md.components.imageInline.imageInlineComponent);
|
|
99
|
+
}
|
|
100
|
+
}], [EditorFeature.LinkTooltip, {
|
|
101
|
+
default: true,
|
|
102
|
+
init: () => {
|
|
103
|
+
// const toolbar = md.plugins.tooltip.tooltipFactory('MARKDOWN_LINK_EDIT_TOOLBAR');
|
|
104
|
+
const plugin = linkEdit.getPlugin();
|
|
105
|
+
console.log(plugin);
|
|
106
|
+
editor.config(linkEdit.configure)
|
|
107
|
+
/*.config((ctx) => {
|
|
108
|
+
ctx.update(linkEdit.getState().key, (prev) => ({...prev}));
|
|
109
|
+
})*/
|
|
110
|
+
.use(plugin);
|
|
111
|
+
}
|
|
112
|
+
}], [EditorFeature.Toolbar, {
|
|
113
|
+
default: true,
|
|
114
|
+
init: () => {
|
|
115
|
+
const toolbar = md.plugins.tooltip.tooltipFactory('MARKDOWN_TOOLBAR');
|
|
116
|
+
editor.config((ctx) => {
|
|
117
|
+
ctx.set(toolbar.key, {
|
|
118
|
+
view: (view) => new ToolbarView(ctx, view, md),
|
|
119
|
+
});
|
|
120
|
+
})
|
|
121
|
+
.use(toolbar);
|
|
122
|
+
}
|
|
123
|
+
}], [EditorFeature.Placeholder, {
|
|
124
|
+
default: true,
|
|
125
|
+
init: () => {
|
|
126
|
+
const { config, plugin } = createPlaceHolder(md);
|
|
127
|
+
editor.config((ctx) => {
|
|
128
|
+
ctx.update(config.key, (prev) => {
|
|
129
|
+
return { ...prev };
|
|
130
|
+
});
|
|
131
|
+
})
|
|
132
|
+
.use(plugin)
|
|
133
|
+
.use(config);
|
|
134
|
+
}
|
|
135
|
+
}], [EditorFeature.Table, {
|
|
136
|
+
default: true,
|
|
137
|
+
init: () => {
|
|
138
|
+
editor.config((ctx) => {
|
|
139
|
+
ctx.update(md.components.tableBlock.tableBlockConfig.key, (_prev) => ({
|
|
140
|
+
renderButton: (renderType) => {
|
|
141
|
+
switch (renderType) {
|
|
142
|
+
case 'add_row': return createIcon(md, 'plus');
|
|
143
|
+
case 'add_col': return createIcon(md, 'plus');
|
|
144
|
+
case 'delete_row': return createIcon(md, 'trash');
|
|
145
|
+
case 'delete_col': return createIcon(md, 'trash');
|
|
146
|
+
case 'align_col_left': return createIcon(md, 'align-left');
|
|
147
|
+
case 'align_col_center': return createIcon(md, 'align-center');
|
|
148
|
+
case 'align_col_right': return createIcon(md, 'align-right');
|
|
149
|
+
case 'col_drag_handle': return createIcon(md, 'grip-lines-vertical');
|
|
150
|
+
case 'row_drag_handle': return createIcon(md, 'grip-lines');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}));
|
|
154
|
+
})
|
|
155
|
+
.use(md.components.tableBlock.tableBlock);
|
|
156
|
+
}
|
|
157
|
+
}], [EditorFeature.CodeEditor, {
|
|
158
|
+
default: true,
|
|
159
|
+
init: () => {
|
|
160
|
+
const codeBlockConfig = createCodeBlockConfig(md);
|
|
161
|
+
const codeBlockView = createCodeBlockView(md);
|
|
162
|
+
editor.config((ctx) => {
|
|
163
|
+
ctx.update(codeBlockConfig.key, (_defaultConfig) => ({}));
|
|
164
|
+
}).use([codeBlockView, codeBlockConfig]);
|
|
165
|
+
}
|
|
166
|
+
}], [EditorFeature.Html, {
|
|
167
|
+
default: true,
|
|
168
|
+
init: () => {
|
|
169
|
+
const htmlBlockConfig = createHtmlBlockConfig(md);
|
|
170
|
+
const htmlBlockView = createHtmlBlockView(md);
|
|
171
|
+
editor.config((ctx) => {
|
|
172
|
+
ctx.update(htmlBlockConfig.key, (_defaultConfig) => ({}));
|
|
173
|
+
}).use([htmlBlockView, htmlBlockConfig]);
|
|
174
|
+
}
|
|
175
|
+
}]
|
|
176
|
+
]);
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../../src/components/features/linkEdit/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAE5C,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAU,MAAM,iBAAiB,CAAC;AAEhD,qBACa,QAAS,SAAQ,UAAU;IAEvC,MAAM,CAAC,MAAM,0BA8BX;IAEF,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;IAGtB,KAAK,SAAM;IAGX,KAAK,EAAE,KAAK,CAAC;;IAab,MAAM,
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../../src/components/features/linkEdit/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAE5C,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAU,MAAM,iBAAiB,CAAC;AAEhD,qBACa,QAAS,SAAQ,UAAU;IAEvC,MAAM,CAAC,MAAM,0BA8BX;IAEF,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;IAGtB,KAAK,SAAM;IAGX,KAAK,EAAE,KAAK,CAAC;;IAab,MAAM,6CAmBJ;CACF"}
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
var __decorate=this&&this.__decorate
|
|
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
|
+
import { LitElement, css, html } from "lit";
|
|
8
|
+
import { customElement, property, query } from "lit/decorators.js";
|
|
9
|
+
import { events } from "@omegagrid/core";
|
|
10
|
+
let LinkEdit = class LinkEdit extends LitElement {
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
this.value = '';
|
|
14
|
+
// command(key: milkdown.core.CmdKey<unknown>) {
|
|
15
|
+
// this.ctx.get(this.md.core.commandsCtx).call(key);
|
|
16
|
+
// }
|
|
17
|
+
this.render = () => html `
|
|
2
18
|
<div class="inner">
|
|
3
19
|
<og-icon icon="link"></og-icon>
|
|
4
20
|
|
|
@@ -7,13 +23,23 @@ var __decorate=this&&this.__decorate||function(t,e,o,n){var i,r=arguments.length
|
|
|
7
23
|
.value="${this.value}">
|
|
8
24
|
</og-input>
|
|
9
25
|
|
|
10
|
-
<og-button icon="check" @click="${()=>this.dispatchEvent(new events.ChangeEvent({
|
|
26
|
+
<og-button icon="check" @click="${() => this.dispatchEvent(new events.ChangeEvent({
|
|
27
|
+
value: this.input.value
|
|
28
|
+
}))}">
|
|
11
29
|
</og-button>
|
|
12
30
|
|
|
13
|
-
<og-button icon="trash" color="red" @click="${()=>this.dispatchEvent(new events.ChangeEvent({
|
|
31
|
+
<og-button icon="trash" color="red" @click="${() => this.dispatchEvent(new events.ChangeEvent({
|
|
32
|
+
value: null
|
|
33
|
+
}))}">
|
|
14
34
|
</og-button>
|
|
15
35
|
</div>
|
|
16
|
-
|
|
36
|
+
`;
|
|
37
|
+
this.addEventListener('click', (e) => e.stopPropagation());
|
|
38
|
+
this.addEventListener('mousedown', (e) => e.stopPropagation());
|
|
39
|
+
this.addEventListener('mouseup', (e) => e.stopPropagation());
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
LinkEdit.styles = css `
|
|
17
43
|
* {
|
|
18
44
|
box-sizing: border-box;
|
|
19
45
|
}
|
|
@@ -43,4 +69,15 @@ var __decorate=this&&this.__decorate||function(t,e,o,n){var i,r=arguments.length
|
|
|
43
69
|
.inner > og-button {
|
|
44
70
|
flex: 0 20px;
|
|
45
71
|
}
|
|
46
|
-
|
|
72
|
+
`;
|
|
73
|
+
__decorate([
|
|
74
|
+
property({ type: String })
|
|
75
|
+
], LinkEdit.prototype, "value", void 0);
|
|
76
|
+
__decorate([
|
|
77
|
+
query('og-input')
|
|
78
|
+
], LinkEdit.prototype, "input", void 0);
|
|
79
|
+
LinkEdit = __decorate([
|
|
80
|
+
customElement('og-markdown-linkedit')
|
|
81
|
+
], LinkEdit);
|
|
82
|
+
export { LinkEdit };
|
|
83
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -1 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { debounce } from "ts-debounce";
|
|
3
|
+
import { LinkEditView } from "./view";
|
|
4
|
+
import { md } from "../../../loader";
|
|
5
|
+
import { findMarkPosition, shouldShowPreviewWhenHover } from "./utils";
|
|
6
|
+
import { getLinkEditAPI, getLinkEditState } from "./slices";
|
|
7
|
+
let tooltip;
|
|
8
|
+
export function getTooltip() {
|
|
9
|
+
if (!tooltip)
|
|
10
|
+
tooltip = md.plugins.tooltip.tooltipFactory('MARKDOWN_LINK_EDIT');
|
|
11
|
+
return tooltip;
|
|
12
|
+
}
|
|
13
|
+
export function configureLinkEdit(ctx) {
|
|
14
|
+
const linkEditState = getLinkEditState();
|
|
15
|
+
let linkEditView;
|
|
16
|
+
ctx.update(getLinkEditAPI().key, (api) => ({
|
|
17
|
+
...api,
|
|
18
|
+
addLink: (from, to) => {
|
|
19
|
+
linkEditView?.addLink(from, to);
|
|
20
|
+
},
|
|
21
|
+
editLink: (mark, from, to) => {
|
|
22
|
+
linkEditView?.editLink(mark, from, to);
|
|
23
|
+
},
|
|
24
|
+
removeLink: (from, to) => {
|
|
25
|
+
linkEditView?.removeLink(from, to);
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
const DELAY = 200;
|
|
29
|
+
const onMouseMove = debounce((view, event) => {
|
|
30
|
+
if (!linkEditView)
|
|
31
|
+
return;
|
|
32
|
+
if (!view.hasFocus())
|
|
33
|
+
return;
|
|
34
|
+
const state = ctx.get(linkEditState.key);
|
|
35
|
+
if (state.mode === 'edit')
|
|
36
|
+
return;
|
|
37
|
+
const result = shouldShowPreviewWhenHover(ctx, view, event);
|
|
38
|
+
if (result) {
|
|
39
|
+
const position = view.state.doc.resolve(result.pos);
|
|
40
|
+
const markPosition = findMarkPosition(result.mark, result.node, view.state.doc, position.before(), position.after());
|
|
41
|
+
const from = markPosition.start;
|
|
42
|
+
const to = markPosition.end;
|
|
43
|
+
linkEditView.show(result.mark, from, to, md.prose.posToDOMRect(view, from, to));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
linkEditView.hide();
|
|
47
|
+
}, DELAY);
|
|
48
|
+
const onMouseLeave = () => {
|
|
49
|
+
setTimeout(() => { linkEditView?.hide(); }, DELAY);
|
|
50
|
+
};
|
|
51
|
+
ctx.set(getTooltip().key, {
|
|
52
|
+
props: {
|
|
53
|
+
handleDOMEvents: {
|
|
54
|
+
mousemove: onMouseMove,
|
|
55
|
+
mouseleave: onMouseLeave,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
view: (view) => {
|
|
59
|
+
linkEditView = new LinkEditView(ctx, view);
|
|
60
|
+
return linkEditView;
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
import{configureLinkEdit,getTooltip}from
|
|
1
|
+
import { configureLinkEdit, getTooltip } from './config';
|
|
2
|
+
import { getLinkEditAPI, getLinkEditConfig, getLinkEditState } from './slices';
|
|
3
|
+
export * from './component';
|
|
4
|
+
export default {
|
|
5
|
+
configure: configureLinkEdit,
|
|
6
|
+
getState: getLinkEditState,
|
|
7
|
+
getPlugin: () => ([
|
|
8
|
+
getLinkEditState(),
|
|
9
|
+
getLinkEditAPI(),
|
|
10
|
+
getLinkEditConfig(),
|
|
11
|
+
getTooltip()
|
|
12
|
+
].flat())
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { md } from "../../../loader";
|
|
3
|
+
const defaultState = { mode: 'preview' };
|
|
4
|
+
let linkEditState;
|
|
5
|
+
export const getLinkEditState = () => {
|
|
6
|
+
if (!linkEditState)
|
|
7
|
+
linkEditState = md.utils.$ctx({ ...defaultState }, 'linkEditStateCtx');
|
|
8
|
+
return linkEditState;
|
|
9
|
+
};
|
|
10
|
+
const defaultAPI = {
|
|
11
|
+
addLink: () => { },
|
|
12
|
+
editLink: () => { },
|
|
13
|
+
removeLink: () => { },
|
|
14
|
+
};
|
|
15
|
+
let api;
|
|
16
|
+
export const getLinkEditAPI = () => api ?? (api = md.utils.$ctx({ ...defaultAPI }, 'linkEditAPICtx'));
|
|
17
|
+
const defaultConfig = {
|
|
18
|
+
onCopyLink: () => { },
|
|
19
|
+
inputPlaceholder: 'Paste link...',
|
|
20
|
+
};
|
|
21
|
+
let config;
|
|
22
|
+
export const getLinkEditConfig = () => config ?? (config = md.utils.$ctx({ ...defaultConfig }, 'linkEditConfigCtx'));
|
|
23
|
+
//# sourceMappingURL=slices.js.map
|
|
@@ -1 +1,33 @@
|
|
|
1
|
-
import{md}from"../../../loader";
|
|
1
|
+
import { md } from "../../../loader";
|
|
2
|
+
export function findMarkPosition(mark, node, doc, from, to) {
|
|
3
|
+
let markPos = { start: -1, end: -1 };
|
|
4
|
+
doc.nodesBetween(from, to, (n, pos) => {
|
|
5
|
+
// stop recursive finding if result is found
|
|
6
|
+
if (markPos.start > -1)
|
|
7
|
+
return false;
|
|
8
|
+
if (markPos.start === -1 && mark.isInSet(n.marks) && node === n) {
|
|
9
|
+
markPos = {
|
|
10
|
+
start: pos,
|
|
11
|
+
end: pos + Math.max(n.textContent.length, 1),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
});
|
|
16
|
+
return markPos;
|
|
17
|
+
}
|
|
18
|
+
export function shouldShowPreviewWhenHover(ctx, view, event) {
|
|
19
|
+
const $pos = view.posAtCoords({ left: event.clientX, top: event.clientY });
|
|
20
|
+
if (!$pos)
|
|
21
|
+
return;
|
|
22
|
+
const { pos } = $pos;
|
|
23
|
+
const node = view.state.doc.nodeAt(pos);
|
|
24
|
+
if (!node)
|
|
25
|
+
return;
|
|
26
|
+
const mark = node.marks.find((mark) => {
|
|
27
|
+
return mark.type === md.presets.commonmark.linkSchema.mark.type(ctx);
|
|
28
|
+
});
|
|
29
|
+
if (!mark)
|
|
30
|
+
return;
|
|
31
|
+
return { show: true, pos, node, mark };
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=utils.js.map
|