@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.
Files changed (45) hide show
  1. package/dist/components/features/blockEdit.d.ts +1 -1
  2. package/dist/components/features/blockEdit.d.ts.map +1 -1
  3. package/dist/components/features/blockEdit.js +128 -7
  4. package/dist/components/features/blockEditMenu.d.ts +1 -1
  5. package/dist/components/features/blockEditMenu.d.ts.map +1 -1
  6. package/dist/components/features/blockEditMenu.js +226 -5
  7. package/dist/components/features/codeBlock.js +132 -1
  8. package/dist/components/features/htmlBlock.d.ts +1 -1
  9. package/dist/components/features/htmlBlock.d.ts.map +1 -1
  10. package/dist/components/features/htmlBlock.js +132 -11
  11. package/dist/components/features/index.js +178 -1
  12. package/dist/components/features/linkEdit/component.d.ts +1 -1
  13. package/dist/components/features/linkEdit/component.d.ts.map +1 -1
  14. package/dist/components/features/linkEdit/component.js +42 -5
  15. package/dist/components/features/linkEdit/config.js +64 -1
  16. package/dist/components/features/linkEdit/index.js +14 -1
  17. package/dist/components/features/linkEdit/slices.js +23 -1
  18. package/dist/components/features/linkEdit/utils.js +33 -1
  19. package/dist/components/features/linkEdit/view.js +135 -1
  20. package/dist/components/features/placeholder.js +50 -1
  21. package/dist/components/features/toolbar.d.ts +1 -1
  22. package/dist/components/features/toolbar.d.ts.map +1 -1
  23. package/dist/components/features/toolbar.js +127 -13
  24. package/dist/components/features/utils.js +64 -1
  25. package/dist/components/index.js +4 -1
  26. package/dist/components/markdownEditor.d.ts +1 -1
  27. package/dist/components/markdownEditor.d.ts.map +1 -1
  28. package/dist/components/markdownEditor.js +138 -2
  29. package/dist/components/markdownEditor.style.js +22 -2
  30. package/dist/components/markdownView.js +19 -1
  31. package/dist/components/markdownView.style.js +4 -2
  32. package/dist/components/styles/block-edit.js +4 -2
  33. package/dist/components/styles/cursor.js +4 -2
  34. package/dist/components/styles/image-block.js +4 -2
  35. package/dist/components/styles/index.js +19 -1
  36. package/dist/components/styles/link-tooltip.js +4 -2
  37. package/dist/components/styles/list-item.js +4 -2
  38. package/dist/components/styles/placeholder.js +4 -2
  39. package/dist/components/styles/prosemirror.js +4 -2
  40. package/dist/components/styles/table.js +4 -2
  41. package/dist/constants.js +5 -1
  42. package/dist/index.js +4 -1
  43. package/dist/loader.js +46 -1
  44. package/dist/utils.js +62 -1
  45. package/package.json +6 -6
@@ -1,26 +1,76 @@
1
- var _HtmlBlockComponent_content,__decorate=this&&this.__decorate||function(t,e,o,i){var n,r=arguments.length,s=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,o,i);else for(var l=t.length-1;l>=0;l--)(n=t[l])&&(s=(r<3?n(s):r>3?n(e,o,s):n(e,o))||s);return r>3&&s&&Object.defineProperty(e,o,s),s},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(t,e,o,i){if("a"===o&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===o?i:"a"===o?i.call(t):i?i.value:e.get(t)},__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(t,e,o,i,n){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?n.call(t,o):n?n.value=o:e.set(t,o),o};import{dom,events}from"@omegagrid/core";import{LitElement,css,html}from"lit";import{customElement,property,query}from"lit/decorators.js";import{unsafeHTML}from"lit/directives/unsafe-html.js";import{msg}from"@omegagrid/localize";let HtmlBlockComponent=class extends LitElement{get content(){return __classPrivateFieldGet(this,_HtmlBlockComponent_content,"f")}set content(t){__classPrivateFieldSet(this,_HtmlBlockComponent_content,t,"f"),this.requestUpdate()}constructor(){super(),_HtmlBlockComponent_content.set(this,""),this.editable=!1,this.editing=!1,this.startEdit=()=>{this.editing=!0},this.render=()=>this.editable?html`
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="${{minimap:{enabled:!1},lineNumbers:{renderType:0}}}"
11
- @blur="${()=>this.commit()}"
12
- @code.ready="${()=>this.editor.focus()}">
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
- `:this.content?html`
54
+ ` : (this.content ? html `
15
55
  <og-code-view
16
56
  language="html"
17
57
  .content="${this.content}" >
18
58
  </og-code-view>
19
- `:html`
20
- <div class="placeholder">${msg("Insert HTML")}</div>
21
- `}
59
+ ` : html `
60
+ <div class="placeholder">${msg('Insert HTML')}</div>
61
+ `)}
22
62
  </div>
23
- `:unsafeHTML(this.content),this.addEventListener("click",(()=>this.startEdit()))}commit(){this.editing=!1,__classPrivateFieldSet(this,_HtmlBlockComponent_content,this.editor.model.getValue(),"f"),this.dispatchEvent(new events.ChangeEvent(__classPrivateFieldGet(this,_HtmlBlockComponent_content,"f")))}};_HtmlBlockComponent_content=new WeakMap,HtmlBlockComponent.styles=css`
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
- `,__decorate([property({type:String})],HtmlBlockComponent.prototype,"content",null),__decorate([property({type:Boolean})],HtmlBlockComponent.prototype,"editable",void 0),__decorate([property({type:Boolean})],HtmlBlockComponent.prototype,"editing",void 0),__decorate([query("og-code-block")],HtmlBlockComponent.prototype,"editor",void 0),HtmlBlockComponent=__decorate([customElement("og-markdown-html-block")],HtmlBlockComponent);export{HtmlBlockComponent};export class HtmlBlock{constructor(t,e,o,i){this.md=t,this.node=e,this.view=o,this.getPos=i,this.updating=!1,this._onChange=t=>{if(this.updating)return;const e=this.view.state.tr;this.view.dispatch(e.setNodeAttribute(this.getPos()??0,"value",t.value))},this.dom=dom.createElement("og-markdown-html-block"),this.dom.editable=this.view.editable,this.dom.content=this.node.attrs?.value,this.dom.addEventListener("change",this._onChange)}update(t){return t.type===this.node.type&&(this.updating||(this.node=t,this.dom.content=this.node.attrs?.value),!0)}selectNode(){this.view.editable&&this.dom.startEdit(),this.dom.focus()}deselectNode(){}stopEvent(){return!0}destroy(){}}export const defaultCodeEditorConfig={};export function createHtmlBlockConfig(t){return t.utils.$ctx(defaultCodeEditorConfig,"htmlEditorConfigCtx")}export function createHtmlBlockView(t){return t.utils.$view(t.presets.commonmark.htmlSchema.node,(e=>(e,o,i)=>new HtmlBlock(t,e,o,i)))}
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{BlockHandleView}from"./blockEdit";import{ToolbarView}from"./toolbar";import{createPlaceHolder}from"./placeholder";import{createCodeBlockConfig,createCodeBlockView}from"./codeBlock";import{createHtmlBlockConfig,createHtmlBlockView}from"./htmlBlock";import linkEdit from"./linkEdit";export*from"./blockEditMenu";export*from"./htmlBlock";export*from"./linkEdit";export function configureFeatures(e,o){return t=>{t.inject(o.ctx.createSlice([],"FeaturesCtx"),e)}}const createIcon=(e,o)=>e.atomico.html`<og-fa-icon icon=${o}></og-fa-icon>`;export var EditorFeature;!function(e){e.BlockEdit="block-edit",e.Cursor="cursor",e.CodeEditor="code-editor",e.LinkTooltip="link-tooltip",e.ImageBlock="image-block",e.Toolbar="toolbar",e.Placeholder="placeholder",e.Table="table",e.Html="html"}(EditorFeature||(EditorFeature={}));const createModifyImageUrl=e=>async o=>{if(!o)return null;const t=e(o);return"string"==typeof o?t:await t};export function getFeatures(e,o,t){const r=t.modifyImageUrl?createModifyImageUrl(t.modifyImageUrl):null;return new Map([[EditorFeature.BlockEdit,{default:!0,init:()=>{e.config((e=>{e.set(o.plugins.block.blockConfig.key,{filterNodes:e=>!o.prose.findParent((e=>["table","blockquote"].includes(e.type.name)))(e)}),e.set(o.plugins.block.block.key,{view:()=>new BlockHandleView(e,o)})})).use(o.plugins.block.block)}}],[EditorFeature.Cursor,{default:!0,init:()=>{e.config((e=>{e.update(o.plugins.cursor.dropCursorConfig.key,(()=>({class:"md-editor-drop-cursor",width:4})))})).use(o.plugins.cursor.cursor)}}],[EditorFeature.ImageBlock,{default:!0,init:()=>{e.config((e=>{e.update(o.components.imageInline.inlineImageConfig.key,(e=>({uploadButton:()=>createIcon(o,"upload"),imageIcon:()=>createIcon(o,"image"),confirmButton:()=>createIcon(o,"check"),uploadPlaceholderText:"or paste link",onUpload:t.onUpload,proxyDomURL:r}))),e.update(o.components.imageBlock.imageBlockConfig.key,(e=>({uploadButton:()=>"Upload file",imageIcon:()=>createIcon(o,"image"),captionIcon:()=>createIcon(o,"comment"),confirmButton:()=>"Confirm",captionPlaceholderText:"Write Image Caption",uploadPlaceholderText:"or paste link",onUpload:t.onUpload,proxyDomURL:r})))})).use(o.components.imageBlock.imageBlockComponent).use(o.components.imageInline.imageInlineComponent)}}],[EditorFeature.LinkTooltip,{default:!0,init:()=>{const o=linkEdit.getPlugin();console.log(o),e.config(linkEdit.configure).use(o)}}],[EditorFeature.Toolbar,{default:!0,init:()=>{const t=o.plugins.tooltip.tooltipFactory("MARKDOWN_TOOLBAR");e.config((e=>{e.set(t.key,{view:t=>new ToolbarView(e,t,o)})})).use(t)}}],[EditorFeature.Placeholder,{default:!0,init:()=>{const{config:t,plugin:r}=createPlaceHolder(o);e.config((e=>{e.update(t.key,(e=>({...e})))})).use(r).use(t)}}],[EditorFeature.Table,{default:!0,init:()=>{e.config((e=>{e.update(o.components.tableBlock.tableBlockConfig.key,(e=>({renderButton:e=>{switch(e){case"add_row":case"add_col":return createIcon(o,"plus");case"delete_row":case"delete_col":return createIcon(o,"trash");case"align_col_left":return createIcon(o,"align-left");case"align_col_center":return createIcon(o,"align-center");case"align_col_right":return createIcon(o,"align-right");case"col_drag_handle":return createIcon(o,"grip-lines-vertical");case"row_drag_handle":return createIcon(o,"grip-lines")}}})))})).use(o.components.tableBlock.tableBlock)}}],[EditorFeature.CodeEditor,{default:!0,init:()=>{const t=createCodeBlockConfig(o),r=createCodeBlockView(o);e.config((e=>{e.update(t.key,(e=>({})))})).use([r,t])}}],[EditorFeature.Html,{default:!0,init:()=>{const t=createHtmlBlockConfig(o),r=createHtmlBlockView(o);e.config((e=>{e.update(t.key,(e=>({})))})).use([r,t])}}]])}
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
@@ -7,6 +7,6 @@ export declare class LinkEdit extends LitElement {
7
7
  value: string;
8
8
  input: Input;
9
9
  constructor();
10
- render: () => import("lit").TemplateResult<1>;
10
+ render: () => import("lit-html").TemplateResult<1>;
11
11
  }
12
12
  //# sourceMappingURL=component.d.ts.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,wCAmBJ;CACF"}
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||function(t,e,o,n){var i,r=arguments.length,c=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(t,e,o,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(c=(r<3?i(c):r>3?i(e,o,c):i(e,o))||c);return r>3&&c&&Object.defineProperty(e,o,c),c};import{LitElement,css,html}from"lit";import{customElement,property,query}from"lit/decorators.js";import{events}from"@omegagrid/core";let LinkEdit=class extends LitElement{constructor(){super(),this.value="",this.render=()=>html`
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({value:this.input.value}))}">
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({value:null}))}">
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
- `,this.addEventListener("click",(t=>t.stopPropagation())),this.addEventListener("mousedown",(t=>t.stopPropagation())),this.addEventListener("mouseup",(t=>t.stopPropagation()))}};LinkEdit.styles=css`
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
- `,__decorate([property({type:String})],LinkEdit.prototype,"value",void 0),__decorate([query("og-input")],LinkEdit.prototype,"input",void 0),LinkEdit=__decorate([customElement("og-markdown-linkedit")],LinkEdit);export{LinkEdit};
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
- import{debounce}from"ts-debounce";import{LinkEditView}from"./view";import{md}from"../../../loader";import{findMarkPosition,shouldShowPreviewWhenHover}from"./utils";import{getLinkEditAPI,getLinkEditState}from"./slices";let tooltip;export function getTooltip(){return tooltip||(tooltip=md.plugins.tooltip.tooltipFactory("MARKDOWN_LINK_EDIT")),tooltip}export function configureLinkEdit(e){const t=getLinkEditState();let o;e.update(getLinkEditAPI().key,(e=>({...e,addLink:(e,t)=>{o?.addLink(e,t)},editLink:(e,t,i)=>{o?.editLink(e,t,i)},removeLink:(e,t)=>{o?.removeLink(e,t)}})));const i=debounce(((i,n)=>{if(!o)return;if(!i.hasFocus())return;if("edit"===e.get(t.key).mode)return;const r=shouldShowPreviewWhenHover(e,i,n);if(r){const e=i.state.doc.resolve(r.pos),t=findMarkPosition(r.mark,r.node,i.state.doc,e.before(),e.after()),n=t.start,d=t.end;o.show(r.mark,n,d,md.prose.posToDOMRect(i,n,d))}else o.hide()}),200);e.set(getTooltip().key,{props:{handleDOMEvents:{mousemove:i,mouseleave:()=>{setTimeout((()=>{o?.hide()}),200)}}},view:t=>(o=new LinkEditView(e,t),o)})}
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"./config";import{getLinkEditAPI,getLinkEditConfig,getLinkEditState}from"./slices";export*from"./component";export default{configure:configureLinkEdit,getState:getLinkEditState,getPlugin:()=>[getLinkEditState(),getLinkEditAPI(),getLinkEditConfig(),getTooltip()].flat()};
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
- import{md}from"../../../loader";const defaultState={mode:"preview"};let linkEditState;export const getLinkEditState=()=>(linkEditState||(linkEditState=md.utils.$ctx({...defaultState},"linkEditStateCtx")),linkEditState);const defaultAPI={addLink:()=>{},editLink:()=>{},removeLink:()=>{}};let api;export const getLinkEditAPI=()=>api??(api=md.utils.$ctx({...defaultAPI},"linkEditAPICtx"));const defaultConfig={onCopyLink:()=>{},inputPlaceholder:"Paste link..."};let config;export const getLinkEditConfig=()=>config??(config=md.utils.$ctx({...defaultConfig},"linkEditConfigCtx"));
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";export function findMarkPosition(t,e,n,o,r){let s={start:-1,end:-1};return n.nodesBetween(o,r,((n,o)=>{if(s.start>-1)return!1;-1===s.start&&t.isInSet(n.marks)&&e===n&&(s={start:o,end:o+Math.max(n.textContent.length,1)})})),s}export function shouldShowPreviewWhenHover(t,e,n){const o=e.posAtCoords({left:n.clientX,top:n.clientY});if(!o)return;const{pos:r}=o,s=e.state.doc.nodeAt(r);if(!s)return;const i=s.marks.find((e=>e.type===md.presets.commonmark.linkSchema.mark.type(t)));return i?{show:!0,pos:r,node:s,mark:i}:void 0}
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