@omegagrid/markdown 0.9.38 → 0.9.39

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 (47) 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 +7 -128
  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 +5 -226
  7. package/dist/components/features/codeBlock.js +1 -135
  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 +11 -132
  11. package/dist/components/features/index.d.ts.map +1 -1
  12. package/dist/components/features/index.js +1 -178
  13. package/dist/components/features/index.js.map +1 -1
  14. package/dist/components/features/linkEdit/component.d.ts +1 -1
  15. package/dist/components/features/linkEdit/component.d.ts.map +1 -1
  16. package/dist/components/features/linkEdit/component.js +5 -42
  17. package/dist/components/features/linkEdit/config.js +1 -64
  18. package/dist/components/features/linkEdit/index.js +1 -14
  19. package/dist/components/features/linkEdit/slices.js +1 -23
  20. package/dist/components/features/linkEdit/utils.js +1 -33
  21. package/dist/components/features/linkEdit/view.js +1 -135
  22. package/dist/components/features/placeholder.js +1 -50
  23. package/dist/components/features/toolbar.d.ts +1 -1
  24. package/dist/components/features/toolbar.d.ts.map +1 -1
  25. package/dist/components/features/toolbar.js +13 -127
  26. package/dist/components/features/utils.js +1 -64
  27. package/dist/components/index.js +1 -4
  28. package/dist/components/markdownEditor.d.ts +1 -1
  29. package/dist/components/markdownEditor.d.ts.map +1 -1
  30. package/dist/components/markdownEditor.js +2 -138
  31. package/dist/components/markdownEditor.style.js +2 -22
  32. package/dist/components/markdownView.js +1 -19
  33. package/dist/components/markdownView.style.js +2 -4
  34. package/dist/components/styles/block-edit.js +2 -4
  35. package/dist/components/styles/cursor.js +2 -4
  36. package/dist/components/styles/image-block.js +2 -4
  37. package/dist/components/styles/index.js +1 -19
  38. package/dist/components/styles/link-tooltip.js +2 -4
  39. package/dist/components/styles/list-item.js +2 -4
  40. package/dist/components/styles/placeholder.js +2 -4
  41. package/dist/components/styles/prosemirror.js +2 -4
  42. package/dist/components/styles/table.js +2 -4
  43. package/dist/constants.js +1 -5
  44. package/dist/index.js +1 -4
  45. package/dist/loader.js +1 -46
  46. package/dist/utils.js +1 -62
  47. package/package.json +6 -6
@@ -1,76 +1,26 @@
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 `
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`
39
2
  <div class="title">Raw HTML</div>
40
3
  <div class="body">
41
- ${this.editing ? html `
4
+ ${this.editing?html`
42
5
  <og-code-block
43
6
  disableToolbar
44
7
  dynamicHeight
45
8
  language="html"
46
9
  .content="${this.content}"
47
- .editorOptions="${{
48
- minimap: { enabled: false },
49
- lineNumbers: { renderType: 0 }
50
- }}"
51
- @blur="${() => this.commit()}"
52
- @code.ready="${() => this.editor.focus()}">
10
+ .editorOptions="${{minimap:{enabled:!1},lineNumbers:{renderType:0}}}"
11
+ @blur="${()=>this.commit()}"
12
+ @code.ready="${()=>this.editor.focus()}">
53
13
  </og-code-block>
54
- ` : (this.content ? html `
14
+ `:this.content?html`
55
15
  <og-code-view
56
16
  language="html"
57
17
  .content="${this.content}" >
58
18
  </og-code-view>
59
- ` : html `
60
- <div class="placeholder">${msg('Insert HTML')}</div>
61
- `)}
19
+ `:html`
20
+ <div class="placeholder">${msg("Insert HTML")}</div>
21
+ `}
62
22
  </div>
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 `
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`
74
24
  * {
75
25
  box-sizing: border-box;
76
26
  }
@@ -99,75 +49,4 @@ HtmlBlockComponent.styles = css `
99
49
  og-code-view, .placeholder {
100
50
  cursor: pointer;
101
51
  }
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
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)))}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/features/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAOzD,cAAc,iBAAiB,CAAC;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AC,OAAO,GAAG,OAAO,IAAI,CAC9C,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,EAC5B,MAAM,CAAC,EAAE,OAAO,KACZ,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAEzB,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,EAAE,EAAE,OAAO,QAAQ,IACvE,KAAK,QAAQ,CAAC,GAAG,CAAC,GAAG,UAG7B;AAKD,oBAAY,aAAa;IACxB,SAAS,eAAe;IACxB,MAAM,WAAW;IACjB,UAAU,gBAAgB;IAE1B,WAAW,iBAAiB;IAC5B,UAAU,gBAAgB;IAC1B,OAAO,YAAY;IACnB,WAAW,gBAAgB;IAC3B,KAAK,UAAU;IACf,IAAI,SAAS;CACb;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,IAAI,CAAA;CAChB,CAAC;AAUF,wBAAgB,WAAW,CAC1B,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,EAC5B,EAAE,EAAE,OAAO,QAAQ,EACnB,OAAO,EAAE;IACR,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3C,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAAC,MAAM,CAAC;CAC1D,yCA4ID"}
@@ -1,178 +1 @@
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-icon icon=${icon}></og-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
+ 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-icon icon=${o}></og-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();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 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/features/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,mDAAmD;AACnD,iFAAiF;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,QAA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AC,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;oBAC3D,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC,CAAC;gBAC1C,CAAC;aACD,CAAC;KACF,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// import { Editor } from '@milkdown/kit/core';\n// import { createSlice } from '@milkdown/kit/ctx';\n// import { BlockProvider, block, blockConfig } from '@milkdown/kit/plugin/block'\nimport { BlockHandleView } from './blockEdit';\nimport type * as milkdown from '@omegagrid/milkdown-kit';\nimport { ToolbarView } from './toolbar';\nimport { createPlaceHolder } from './placeholder';\nimport { createCodeBlockConfig, createCodeBlockView } from './codeBlock';\nimport { createHtmlBlockConfig, createHtmlBlockView } from './htmlBlock';\nimport linkEdit from './linkEdit';\n\nexport * from './blockEditMenu';\nexport * from './htmlBlock';\nexport * from './linkEdit';\n\nexport type DefineFeature<TConfig = unknown> = (\n\teditor: milkdown.core.Editor,\n\tconfig?: TConfig\n) => void | Promise<void>\n\nexport function configureFeatures(features: EditorFeature[], md: typeof milkdown) {\n\treturn (ctx: milkdown.ctx.Ctx) => {\n\t\tctx.inject(md.ctx.createSlice([] as EditorFeature[], 'FeaturesCtx'), features)\n\t}\n}\n\nconst createIcon = (md: typeof milkdown, icon: string) => \n\tmd.atomico.html`<og-icon icon=${icon}></og-icon>`;\n\nexport enum EditorFeature {\n\tBlockEdit = 'block-edit',\n\tCursor = 'cursor',\n\tCodeEditor = 'code-editor',\n\t// ListItem = 'list-item',\n\tLinkTooltip = 'link-tooltip',\n\tImageBlock = 'image-block',\n\tToolbar = 'toolbar',\n\tPlaceholder = 'placeholder',\n\tTable = 'table',\n\tHtml = 'html',\n}\n\nexport type FeatureDefinition = {\n\tdefault: boolean,\n\tinit: () => void\n};\n\nconst createModifyImageUrl = (fn: (url: string) => Promise<string>|string) => {\n\treturn async (url: string) => {\n\t\tif (!url) return null;\n\t\tconst modUrl = fn(url);\n\t\treturn typeof url === 'string' ? modUrl : await modUrl;\n\t}\n};\n\nexport function getFeatures(\n\teditor: milkdown.core.Editor,\n\tmd: typeof milkdown,\n\toptions: {\n\t\tonUpload?: (file: File) => Promise<string>,\n\t\tmodifyImageUrl?: (file: string) => Promise<string>|string,\n\t}\n) {\n\tconst modifyImageUrl = options.modifyImageUrl ? createModifyImageUrl(options.modifyImageUrl) : null;\n\treturn new Map<EditorFeature, FeatureDefinition>([\n\t\t[EditorFeature.BlockEdit, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.set(md.plugins.block.blockConfig.key, {\n\t\t\t\t\t\tfilterNodes: (pos) => {\n\t\t\t\t\t\tconst filter = md.prose.findParent((node) =>\n\t\t\t\t\t\t\t['table', 'blockquote'].includes(node.type.name)\n\t\t\t\t\t\t)(pos)\n\t\t\t\t\t\tif (filter) return false\n\t\t\t\t\t\n\t\t\t\t\t\treturn true\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t\tctx.set(md.plugins.block.block.key, {\n\t\t\t\t\t\tview: () => new BlockHandleView(ctx, md),\n\t\t\t\t\t})\n\t\t\t\t}).use(md.plugins.block.block);\n\t\t\t\t// .config((ctx) => configureMenu(ctx, config))\n\t\t\t\t// .use(menuAPI)\n\t\t\t\t// .use(menu)\n\t\t\t}\n\t\t}], [EditorFeature.Cursor, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.update(md.plugins.cursor.dropCursorConfig.key, () => ({\n\t\t\t\t\t\tclass: 'md-editor-drop-cursor',\n\t\t\t\t\t\twidth: 4,\n\t\t\t\t\t\t// color: '#ff0000',\n\t\t\t\t\t}))\n\t\t\t\t}).use(md.plugins.cursor.cursor)\n\t\t\t}\n\t\t}], [EditorFeature.ImageBlock, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.update(md.components.imageInline.inlineImageConfig.key, (_value) => ({\n\t\t\t\t\t\tuploadButton: () => createIcon(md, 'upload'),\n\t\t\t\t\t\timageIcon: () => createIcon(md, 'image'),\n\t\t\t\t\t\tconfirmButton: () => createIcon(md, 'check'),\n\t\t\t\t\t\tuploadPlaceholderText: 'or paste link',\n\t\t\t\t\t\tonUpload: options.onUpload,\n\t\t\t\t\t\tproxyDomURL: modifyImageUrl,\n\t\t\t\t\t}))\n\t\t\t\t\tctx.update(md.components.imageBlock.imageBlockConfig.key, (_value) => ({\n\t\t\t\t\t\tuploadButton: () => 'Upload file',\n\t\t\t\t\t\timageIcon: () => createIcon(md, 'image'),\n\t\t\t\t\t\tcaptionIcon: () => createIcon(md, 'comment'),\n\t\t\t\t\t\tconfirmButton: () => 'Confirm',\n\t\t\t\t\t\tcaptionPlaceholderText: 'Write Image Caption',\n\t\t\t\t\t\tuploadPlaceholderText: 'or paste link',\n\t\t\t\t\t\tonUpload: options.onUpload,\n\t\t\t\t\t\tproxyDomURL: modifyImageUrl,\n\t\t\t\t\t}))\n\t\t\t\t})\n\t\t\t\t.use(md.components.imageBlock.imageBlockComponent)\n\t\t\t\t.use(md.components.imageInline.imageInlineComponent)\n\t\t\t}\n\t\t}], [EditorFeature.LinkTooltip, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\t// const toolbar = md.plugins.tooltip.tooltipFactory('MARKDOWN_LINK_EDIT_TOOLBAR');\n\t\t\t\tconst plugin = linkEdit.getPlugin();\n\t\t\t\tconsole.log(plugin);\n\t\t\t\teditor.config(linkEdit.configure)\n\t\t\t\t/*.config((ctx) => {\n\t\t\t\t\tctx.update(linkEdit.getState().key, (prev) => ({...prev}));\n\t\t\t\t})*/\n\t\t\t\t.use(plugin);\n\t\t\t}\n\t\t}], [EditorFeature.Toolbar, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\tconst toolbar = md.plugins.tooltip.tooltipFactory('MARKDOWN_TOOLBAR');\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.set(toolbar.key, {\n\t\t\t\t\t\tview: (view) => new ToolbarView(ctx, view, md),\n\t\t\t\t\t})\n\t\t\t\t})\n\t\t\t\t.use(toolbar)\n\t\t\t}\n\t\t}], [EditorFeature.Placeholder, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\tconst { config, plugin } = createPlaceHolder(md);\n\t\t\t\t\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.update(config.key, (prev) => {\n\t\t\t\t\t\treturn {...prev};\n\t\t\t\t\t});\n\t\t\t\t})\n\t\t\t\t.use(plugin)\n\t\t\t\t.use(config)\n\t\t\t}\n\t\t}], [EditorFeature.Table, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.update(md.components.tableBlock.tableBlockConfig.key, (_prev) => ({\n\t\t\t\t\t\trenderButton: (renderType) => {\n\t\t\t\t\t\t\tswitch (renderType) {\n\t\t\t\t\t\t\t\tcase 'add_row': return createIcon(md, 'plus');\n\t\t\t\t\t\t\t\tcase 'add_col': return createIcon(md, 'plus');\n\t\t\t\t\t\t\t\tcase 'delete_row': return createIcon(md, 'trash');\n\t\t\t\t\t\t\t\tcase 'delete_col': return createIcon(md, 'trash');\n\t\t\t\t\t\t\t\tcase 'align_col_left': return createIcon(md, 'align-left');\n\t\t\t\t\t\t\t\tcase 'align_col_center': return createIcon(md, 'align-center');\n\t\t\t\t\t\t\t\tcase 'align_col_right': return createIcon(md, 'align-right');\n\t\t\t\t\t\t\t\tcase 'col_drag_handle': return createIcon(md, 'grip-lines-vertical');\n\t\t\t\t\t\t\t\tcase 'row_drag_handle': return createIcon(md, 'grip-lines');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}));\n\t\t\t\t})\n\t\t\t\t.use(md.components.tableBlock.tableBlock)\n\t\t\t}\n\t\t}], [EditorFeature.CodeEditor, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\tconst codeBlockConfig = createCodeBlockConfig(md);\n\t\t\t\tconst codeBlockView = createCodeBlockView(md);\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.update(codeBlockConfig.key, (_defaultConfig) => ({}));\n\t\t\t\t}).use([codeBlockView, codeBlockConfig]);\n\t\t\t}\n\t\t}], [EditorFeature.Html, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\tconst htmlBlockConfig = createHtmlBlockConfig(md);\n\t\t\t\tconst htmlBlockView = createHtmlBlockView(md);\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.update(htmlBlockConfig.key, (_defaultConfig) => ({}));\n\t\t\t\t}).use([htmlBlockView, htmlBlockConfig]);\n\t\t\t}\n\t\t}]\n\t]);\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/features/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,mDAAmD;AACnD,iFAAiF;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,QAAQ,MAAM,YAAY,CAAC;AAElC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAO3B,MAAM,UAAU,iBAAiB,CAAC,QAAyB,EAAE,EAAmB;IAC/E,OAAO,CAAC,GAAqB,EAAE,EAAE;QAChC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,WAAW,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n// import { BlockProvider, block, blockConfig } from '@milkdown/kit/plugin/block'\nimport { BlockHandleView } from './blockEdit';\nimport type * as milkdown from '@omegagrid/milkdown-kit';\nimport { ToolbarView } from './toolbar';\nimport { createPlaceHolder } from './placeholder';\nimport { createCodeBlockConfig, createCodeBlockView } from './codeBlock';\nimport { createHtmlBlockConfig, createHtmlBlockView } from './htmlBlock';\nimport linkEdit from './linkEdit';\n\nexport * from './blockEditMenu';\nexport * from './htmlBlock';\nexport * from './linkEdit';\n\nexport type DefineFeature<TConfig = unknown> = (\n\teditor: milkdown.core.Editor,\n\tconfig?: TConfig\n) => void | Promise<void>\n\nexport function configureFeatures(features: EditorFeature[], md: typeof milkdown) {\n\treturn (ctx: milkdown.ctx.Ctx) => {\n\t\tctx.inject(md.ctx.createSlice([] as EditorFeature[], 'FeaturesCtx'), features)\n\t}\n}\n\nconst createIcon = (md: typeof milkdown, icon: string) => \n\tmd.atomico.html`<og-icon icon=${icon}></og-icon>`;\n\nexport enum EditorFeature {\n\tBlockEdit = 'block-edit',\n\tCursor = 'cursor',\n\tCodeEditor = 'code-editor',\n\t// ListItem = 'list-item',\n\tLinkTooltip = 'link-tooltip',\n\tImageBlock = 'image-block',\n\tToolbar = 'toolbar',\n\tPlaceholder = 'placeholder',\n\tTable = 'table',\n\tHtml = 'html',\n}\n\nexport type FeatureDefinition = {\n\tdefault: boolean,\n\tinit: () => void\n};\n\nconst createModifyImageUrl = (fn: (url: string) => Promise<string>|string) => {\n\treturn async (url: string) => {\n\t\tif (!url) return null;\n\t\tconst modUrl = fn(url);\n\t\treturn typeof url === 'string' ? modUrl : await modUrl;\n\t}\n};\n\nexport function getFeatures(\n\teditor: milkdown.core.Editor,\n\tmd: typeof milkdown,\n\toptions: {\n\t\tonUpload?: (file: File) => Promise<string>,\n\t\tmodifyImageUrl?: (file: string) => Promise<string>|string,\n\t}\n) {\n\tconst modifyImageUrl = options.modifyImageUrl ? createModifyImageUrl(options.modifyImageUrl) : null;\n\treturn new Map<EditorFeature, FeatureDefinition>([\n\t\t[EditorFeature.BlockEdit, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.set(md.plugins.block.blockConfig.key, {\n\t\t\t\t\t\tfilterNodes: (pos) => {\n\t\t\t\t\t\tconst filter = md.prose.findParent((node) =>\n\t\t\t\t\t\t\t['table', 'blockquote'].includes(node.type.name)\n\t\t\t\t\t\t)(pos)\n\t\t\t\t\t\tif (filter) return false\n\t\t\t\t\t\n\t\t\t\t\t\treturn true\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t\tctx.set(md.plugins.block.block.key, {\n\t\t\t\t\t\tview: () => new BlockHandleView(ctx, md),\n\t\t\t\t\t})\n\t\t\t\t}).use(md.plugins.block.block);\n\t\t\t\t// .config((ctx) => configureMenu(ctx, config))\n\t\t\t\t// .use(menuAPI)\n\t\t\t\t// .use(menu)\n\t\t\t}\n\t\t}], [EditorFeature.Cursor, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.update(md.plugins.cursor.dropCursorConfig.key, () => ({\n\t\t\t\t\t\tclass: 'md-editor-drop-cursor',\n\t\t\t\t\t\twidth: 4,\n\t\t\t\t\t\t// color: '#ff0000',\n\t\t\t\t\t}))\n\t\t\t\t}).use(md.plugins.cursor.cursor)\n\t\t\t}\n\t\t}], [EditorFeature.ImageBlock, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.update(md.components.imageInline.inlineImageConfig.key, (_value) => ({\n\t\t\t\t\t\tuploadButton: () => createIcon(md, 'upload'),\n\t\t\t\t\t\timageIcon: () => createIcon(md, 'image'),\n\t\t\t\t\t\tconfirmButton: () => createIcon(md, 'check'),\n\t\t\t\t\t\tuploadPlaceholderText: 'or paste link',\n\t\t\t\t\t\tonUpload: options.onUpload,\n\t\t\t\t\t\tproxyDomURL: modifyImageUrl,\n\t\t\t\t\t}))\n\t\t\t\t\tctx.update(md.components.imageBlock.imageBlockConfig.key, (_value) => ({\n\t\t\t\t\t\tuploadButton: () => 'Upload file',\n\t\t\t\t\t\timageIcon: () => createIcon(md, 'image'),\n\t\t\t\t\t\tcaptionIcon: () => createIcon(md, 'comment'),\n\t\t\t\t\t\tconfirmButton: () => 'Confirm',\n\t\t\t\t\t\tcaptionPlaceholderText: 'Write Image Caption',\n\t\t\t\t\t\tuploadPlaceholderText: 'or paste link',\n\t\t\t\t\t\tonUpload: options.onUpload,\n\t\t\t\t\t\tproxyDomURL: modifyImageUrl,\n\t\t\t\t\t}))\n\t\t\t\t})\n\t\t\t\t.use(md.components.imageBlock.imageBlockComponent)\n\t\t\t\t.use(md.components.imageInline.imageInlineComponent)\n\t\t\t}\n\t\t}], [EditorFeature.LinkTooltip, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\t// const toolbar = md.plugins.tooltip.tooltipFactory('MARKDOWN_LINK_EDIT_TOOLBAR');\n\t\t\t\tconst plugin = linkEdit.getPlugin();\n\t\t\t\teditor.config(linkEdit.configure)\n\t\t\t\t/*.config((ctx) => {\n\t\t\t\t\tctx.update(linkEdit.getState().key, (prev) => ({...prev}));\n\t\t\t\t})*/\n\t\t\t\t.use(plugin);\n\t\t\t}\n\t\t}], [EditorFeature.Toolbar, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\tconst toolbar = md.plugins.tooltip.tooltipFactory('MARKDOWN_TOOLBAR');\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.set(toolbar.key, {\n\t\t\t\t\t\tview: (view) => new ToolbarView(ctx, view, md),\n\t\t\t\t\t})\n\t\t\t\t})\n\t\t\t\t.use(toolbar)\n\t\t\t}\n\t\t}], [EditorFeature.Placeholder, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\tconst { config, plugin } = createPlaceHolder(md);\n\t\t\t\t\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.update(config.key, (prev) => {\n\t\t\t\t\t\treturn {...prev};\n\t\t\t\t\t});\n\t\t\t\t})\n\t\t\t\t.use(plugin)\n\t\t\t\t.use(config)\n\t\t\t}\n\t\t}], [EditorFeature.Table, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.update(md.components.tableBlock.tableBlockConfig.key, (_prev) => ({\n\t\t\t\t\t\trenderButton: (renderType) => {\n\t\t\t\t\t\t\tswitch (renderType) {\n\t\t\t\t\t\t\t\tcase 'add_row': return createIcon(md, 'plus');\n\t\t\t\t\t\t\t\tcase 'add_col': return createIcon(md, 'plus');\n\t\t\t\t\t\t\t\tcase 'delete_row': return createIcon(md, 'trash');\n\t\t\t\t\t\t\t\tcase 'delete_col': return createIcon(md, 'trash');\n\t\t\t\t\t\t\t\tcase 'align_col_left': return createIcon(md, 'align-left');\n\t\t\t\t\t\t\t\tcase 'align_col_center': return createIcon(md, 'align-center');\n\t\t\t\t\t\t\t\tcase 'align_col_right': return createIcon(md, 'align-right');\n\t\t\t\t\t\t\t\tcase 'col_drag_handle': return createIcon(md, 'grip-lines-vertical');\n\t\t\t\t\t\t\t\tcase 'row_drag_handle': return createIcon(md, 'grip-lines');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}));\n\t\t\t\t})\n\t\t\t\t.use(md.components.tableBlock.tableBlock)\n\t\t\t}\n\t\t}], [EditorFeature.CodeEditor, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\tconst codeBlockConfig = createCodeBlockConfig(md);\n\t\t\t\tconst codeBlockView = createCodeBlockView(md);\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.update(codeBlockConfig.key, (_defaultConfig) => ({}));\n\t\t\t\t}).use([codeBlockView, codeBlockConfig]);\n\t\t\t}\n\t\t}], [EditorFeature.Html, {\n\t\t\tdefault: true,\n\t\t\tinit: () => {\n\t\t\t\tconst htmlBlockConfig = createHtmlBlockConfig(md);\n\t\t\t\tconst htmlBlockView = createHtmlBlockView(md);\n\t\t\t\teditor.config((ctx) => {\n\t\t\t\t\tctx.update(htmlBlockConfig.key, (_defaultConfig) => ({}));\n\t\t\t\t}).use([htmlBlockView, htmlBlockConfig]);\n\t\t\t}\n\t\t}]\n\t]);\n}\n"]}
@@ -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-html").TemplateResult<1>;
10
+ render: () => import("lit").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,6CAmBJ;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,wCAmBJ;CACF"}
@@ -1,20 +1,4 @@
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 `
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`
18
2
  <div class="inner">
19
3
  <og-icon icon="link"></og-icon>
20
4
 
@@ -23,23 +7,13 @@ let LinkEdit = class LinkEdit extends LitElement {
23
7
  .value="${this.value}">
24
8
  </og-input>
25
9
 
26
- <og-button icon="check" @click="${() => this.dispatchEvent(new events.ChangeEvent({
27
- value: this.input.value
28
- }))}">
10
+ <og-button icon="check" @click="${()=>this.dispatchEvent(new events.ChangeEvent({value:this.input.value}))}">
29
11
  </og-button>
30
12
 
31
- <og-button icon="trash" color="red" @click="${() => this.dispatchEvent(new events.ChangeEvent({
32
- value: null
33
- }))}">
13
+ <og-button icon="trash" color="red" @click="${()=>this.dispatchEvent(new events.ChangeEvent({value:null}))}">
34
14
  </og-button>
35
15
  </div>
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 `
16
+ `,this.addEventListener("click",(t=>t.stopPropagation())),this.addEventListener("mousedown",(t=>t.stopPropagation())),this.addEventListener("mouseup",(t=>t.stopPropagation()))}};LinkEdit.styles=css`
43
17
  * {
44
18
  box-sizing: border-box;
45
19
  }
@@ -69,15 +43,4 @@ LinkEdit.styles = css `
69
43
  .inner > og-button {
70
44
  flex: 0 20px;
71
45
  }
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
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};
@@ -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
+ 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,14 +1 @@
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
+ 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,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
+ 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"));