@omegagrid/markdown 0.11.6 → 0.11.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"markdownEditor.d.ts","sourceRoot":"","sources":["../../src/components/markdownEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,kBAAkB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAElF,OAAO,EAAE,UAAU,EAAQ,MAAM,KAAK,CAAC;AAMvC,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAKzD,qBAAa,iBAAkB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,CAAC,EAAE,iBAAiB,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;gBAErB,IAAI,EAAE,OAAO,CAAC,iBAAiB,CAAC;CAI5C;AAED,qBACa,cAAe,SAAQ,UAAW,YAAW,MAAM;;IAE/D,MAAM,CAAC,MAAM,4BAAsB;IAGnC,IACI,OAAO,IACM,MAAM,CADe;IACtC,IAAI,OAAO,CAAC,GAAG,EAAE,MAAM,EAMtB;IAGD,eAAe,SAAO;IAGtB,gBAAgB,EAAE,kBAAkB,CAAU;IAG9C,QAAQ,UAAS;IAGjB,UAAU,UAAS;IAGnB,SAAS,EAAE,cAAc,CAAC;IAG1B,MAAM,EAAE,MAAM,CAAC;IAMf,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAG1C,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAAC,MAAM,CAAC;IAIzD,IAAI,WAAW,IAAiD,WAAW,CAAE;IAC7E,IAAI,MAAM,yBAA0B;;IAqFpC,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IAOjC,iBAAiB;IAKjB,WA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MAAM,yBAA0B;;IAqFpC,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IAOjC,iBAAiB;IAKjB,WAAW;IAKX,SAAS,GAAI,UAAU,MAAM,EAAE,cAAc,MAAM,UAGlD;IAED,YAAY;IAkBN,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC;IA0ChD,YAAY;IAUZ,oBAAoB;IAOpB,MAAM,wCAMJ;IAEF,MAAM;CAEN"}
@@ -1,7 +1,7 @@
1
- var _MarkdownEditor_instances,_MarkdownEditor_content,_MarkdownEditor_mouseIn,_MarkdownEditor_scrollTop,_MarkdownEditor_editor,_MarkdownEditor_onScroll,_MarkdownEditor_closeCodeEditing,_MarkdownEditor_restoreScroll,_MarkdownEditor_applySpellcheck,__decorate=this&&this.__decorate||function(t,e,o,r){var i,d=arguments.length,n=d<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,o,r);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(n=(d<3?i(n):d>3?i(e,o,n):i(e,o))||n);return d>3&&n&&Object.defineProperty(e,o,n),n},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(t,e,o,r){if("a"===o&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===o?r:"a"===o?r.call(t):r?r.value:e.get(t)},__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(t,e,o,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?i.call(t,o):i?i.value=o:e.set(t,o),o};import{dom,events}from"@omegagrid/core";import{LitElement,html}from"lit";import{customElement,query,property}from"lit/decorators.js";import{style}from"./markdownEditor.style";import styles from"./styles";import{createEditor}from"../utils";const SCROLL_SETTLE_TIMEOUT=2e3;export class MarkdownLinkEvent extends Event{constructor(t){super("markdown.link",{bubbles:!0,composed:!0,cancelable:!0}),Object.assign(this,t)}}let MarkdownEditor=class extends LitElement{get content(){return __classPrivateFieldGet(this,_MarkdownEditor_content,"f")}set content(t){t!==__classPrivateFieldGet(this,_MarkdownEditor_content,"f")&&__classPrivateFieldSet(this,_MarkdownEditor_scrollTop,0,"f"),__classPrivateFieldSet(this,_MarkdownEditor_content,t,"f"),__classPrivateFieldGet(this,_MarkdownEditor_editor,"f")?.destroy(),__classPrivateFieldSet(this,_MarkdownEditor_editor,null,"f"),this.requestUpdate()}get milkdownElm(){return this.container.firstElementChild}get editor(){return __classPrivateFieldGet(this,_MarkdownEditor_editor,"f")}constructor(){super(),_MarkdownEditor_instances.add(this),_MarkdownEditor_content.set(this,void 0),this.maxContentWidth=800,this.contentAlignment="left",this.readOnly=!1,this.spellcheck=!1,_MarkdownEditor_mouseIn.set(this,!1),_MarkdownEditor_scrollTop.set(this,0),_MarkdownEditor_editor.set(this,void 0),_MarkdownEditor_onScroll.set(this,(()=>{__classPrivateFieldSet(this,_MarkdownEditor_scrollTop,this.milkdownElm?.scrollTop??0,"f"),__classPrivateFieldGet(this,_MarkdownEditor_instances,"m",_MarkdownEditor_closeCodeEditing).call(this)})),this._onChange=(t,e)=>{__classPrivateFieldSet(this,_MarkdownEditor_content,t,"f"),this.dispatchEvent(new events.ChangeEvent({value:t,oldValue:e}))},this.render=()=>html`
1
+ var _MarkdownEditor_instances,_MarkdownEditor_content,_MarkdownEditor_mouseIn,_MarkdownEditor_scrollTop,_MarkdownEditor_editor,_MarkdownEditor_creating,_MarkdownEditor_onScroll,_MarkdownEditor_closeCodeEditing,_MarkdownEditor_restoreScroll,_MarkdownEditor_applySpellcheck,__decorate=this&&this.__decorate||function(t,e,o,r){var i,d=arguments.length,n=d<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,o,r);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(n=(d<3?i(n):d>3?i(e,o,n):i(e,o))||n);return d>3&&n&&Object.defineProperty(e,o,n),n},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(t,e,o,r){if("a"===o&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===o?r:"a"===o?r.call(t):r?r.value:e.get(t)},__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(t,e,o,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?i.call(t,o):i?i.value=o:e.set(t,o),o};import{dom,events}from"@omegagrid/core";import{LitElement,html}from"lit";import{customElement,query,property}from"lit/decorators.js";import{style}from"./markdownEditor.style";import styles from"./styles";import{createEditor}from"../utils";const SCROLL_SETTLE_TIMEOUT=2e3;export class MarkdownLinkEvent extends Event{constructor(t){super("markdown.link",{bubbles:!0,composed:!0,cancelable:!0}),Object.assign(this,t)}}let MarkdownEditor=class extends LitElement{get content(){return __classPrivateFieldGet(this,_MarkdownEditor_content,"f")}set content(t){t!==__classPrivateFieldGet(this,_MarkdownEditor_content,"f")&&__classPrivateFieldSet(this,_MarkdownEditor_scrollTop,0,"f"),__classPrivateFieldSet(this,_MarkdownEditor_content,t,"f"),__classPrivateFieldGet(this,_MarkdownEditor_editor,"f")?.destroy(),__classPrivateFieldSet(this,_MarkdownEditor_editor,null,"f"),this.requestUpdate()}get milkdownElm(){return this.container.firstElementChild}get editor(){return __classPrivateFieldGet(this,_MarkdownEditor_editor,"f")}constructor(){super(),_MarkdownEditor_instances.add(this),_MarkdownEditor_content.set(this,void 0),this.maxContentWidth=800,this.contentAlignment="left",this.readOnly=!1,this.spellcheck=!1,_MarkdownEditor_mouseIn.set(this,!1),_MarkdownEditor_scrollTop.set(this,0),_MarkdownEditor_editor.set(this,void 0),_MarkdownEditor_creating.set(this,!1),_MarkdownEditor_onScroll.set(this,(()=>{__classPrivateFieldSet(this,_MarkdownEditor_scrollTop,this.milkdownElm?.scrollTop??0,"f"),__classPrivateFieldGet(this,_MarkdownEditor_instances,"m",_MarkdownEditor_closeCodeEditing).call(this)})),this._onChange=(t,e)=>{__classPrivateFieldSet(this,_MarkdownEditor_content,t,"f"),this.dispatchEvent(new events.ChangeEvent({value:t,oldValue:e}))},this.render=()=>html`
2
2
  <style>
3
3
  .ProseMirror.editor { max-width: ${this.maxContentWidth}px; }
4
4
  </style>
5
5
  <div id="container" spellcheck="${this.spellcheck}"></div>
6
6
  <og-slider direction="vertical" hidden></og-slider>
7
- `,dom.on(this,"click","a",((t,e)=>{if(!this.dispatchEvent(new MarkdownLinkEvent({href:e.getAttribute("href"),a:e,origEvent:t})))return void t.preventDefault();const o=e.getAttribute("href");o&&o.startsWith("#")&&(t.preventDefault(),this.scrollToSelector(o))}))}scrollToSelector(t){const e=this.milkdownElm.querySelector(t);e&&(this.milkdownElm.scrollTop=e.offsetTop,this.slider.updatePosition())}connectedCallback(){super.connectedCallback(),this.requestUpdate()}updateWidth(){const t=Math.min(this.maxContentWidth,this.clientWidth);this.milkdownElm.style.width=`${t}px`}firstUpdated(){this.slider.hide(),this.addEventListener("mouseenter",(()=>{__classPrivateFieldSet(this,_MarkdownEditor_mouseIn,!0,"f"),this.updateSlider()})),this.addEventListener("mouseleave",(()=>{__classPrivateFieldSet(this,_MarkdownEditor_mouseIn,!1,"f"),this.updateSlider()})),this.slider.addEventListener("slideEnd",(()=>{this.updateSlider()}))}async updated(t){t.has("spellcheck")&&__classPrivateFieldGet(this,_MarkdownEditor_instances,"m",_MarkdownEditor_applySpellcheck).call(this),__classPrivateFieldGet(this,_MarkdownEditor_editor,"f")||(__classPrivateFieldSet(this,_MarkdownEditor_editor,await createEditor({container:this.container,content:this.content,readOnly:this.readOnly,onUpload:this.onUpload,onChange:this._onChange,modifyImageUrl:this.modifyImageUrl}),"f"),__classPrivateFieldGet(this,_MarkdownEditor_instances,"m",_MarkdownEditor_applySpellcheck).call(this),this.slider.attachElement(this.milkdownElm),this.milkdownElm.addEventListener("scroll",__classPrivateFieldGet(this,_MarkdownEditor_onScroll,"f")),__classPrivateFieldGet(this,_MarkdownEditor_instances,"m",_MarkdownEditor_restoreScroll).call(this))}updateSlider(){this.slider&&this.milkdownElm&&(this.milkdownElm.scrollHeight>this.milkdownElm.clientHeight&&(__classPrivateFieldGet(this,_MarkdownEditor_mouseIn,"f")||this.slider.sliding)?this.slider.show():this.slider.hide())}disconnectedCallback(){super.disconnectedCallback(),__classPrivateFieldGet(this,_MarkdownEditor_editor,"f")?.destroy(),__classPrivateFieldSet(this,_MarkdownEditor_editor,null,"f"),dom.empty(this.container)}layout(){}};_MarkdownEditor_content=new WeakMap,_MarkdownEditor_mouseIn=new WeakMap,_MarkdownEditor_scrollTop=new WeakMap,_MarkdownEditor_editor=new WeakMap,_MarkdownEditor_onScroll=new WeakMap,_MarkdownEditor_instances=new WeakSet,_MarkdownEditor_closeCodeEditing=function(){const t=this.milkdownElm;t&&(t.querySelectorAll("og-code-block").forEach((t=>t.endEdit())),t.querySelectorAll("og-markdown-html-block").forEach((t=>{t.editing&&(t.editor?.model&&t.commit(),t.editor?.endEdit())})))},_MarkdownEditor_restoreScroll=function(){const t=this.milkdownElm,e=t?.firstElementChild,o=__classPrivateFieldGet(this,_MarkdownEditor_scrollTop,"f");if(!e||!o)return;let r=-1;const i=()=>!(!e.isConnected||r>-1&&Math.abs(t.scrollTop-r)>1||(r=Math.max(0,Math.min(o,t.scrollHeight-t.clientHeight)),t.scrollTop=r,this.slider.value=r,this.slider.updatePosition(),0));t.style.overflowAnchor="none",e.style.overflowAnchor="none";const d=new ResizeObserver((()=>{i()||n()})),n=()=>{clearTimeout(s),d.disconnect(),t.style.overflowAnchor="",e.style.overflowAnchor=""},s=setTimeout(n,2e3);i(),d.observe(e)},_MarkdownEditor_applySpellcheck=function(){this.milkdownElm?.setAttribute("spellcheck",String(this.spellcheck))},MarkdownEditor.styles=[style,...styles],__decorate([property({type:String})],MarkdownEditor.prototype,"content",null),__decorate([property({type:Number})],MarkdownEditor.prototype,"maxContentWidth",void 0),__decorate([property({type:String,reflect:!0})],MarkdownEditor.prototype,"contentAlignment",void 0),__decorate([property({type:Boolean,reflect:!0})],MarkdownEditor.prototype,"readOnly",void 0),__decorate([property({type:Boolean})],MarkdownEditor.prototype,"spellcheck",void 0),__decorate([query("#container")],MarkdownEditor.prototype,"container",void 0),__decorate([query("og-slider")],MarkdownEditor.prototype,"slider",void 0),__decorate([property({type:Object})],MarkdownEditor.prototype,"onUpload",void 0),__decorate([property({type:Object})],MarkdownEditor.prototype,"modifyImageUrl",void 0),MarkdownEditor=__decorate([customElement("og-markdown-editor")],MarkdownEditor);export{MarkdownEditor};
7
+ `,dom.on(this,"click","a",((t,e)=>{if(!this.dispatchEvent(new MarkdownLinkEvent({href:e.getAttribute("href"),a:e,origEvent:t})))return void t.preventDefault();const o=e.getAttribute("href");o&&o.startsWith("#")&&(t.preventDefault(),this.scrollToSelector(o))}))}scrollToSelector(t){const e=this.milkdownElm.querySelector(t);e&&(this.milkdownElm.scrollTop=e.offsetTop,this.slider.updatePosition())}connectedCallback(){super.connectedCallback(),this.requestUpdate()}updateWidth(){const t=Math.min(this.maxContentWidth,this.clientWidth);this.milkdownElm.style.width=`${t}px`}firstUpdated(){this.slider.hide(),this.addEventListener("mouseenter",(()=>{__classPrivateFieldSet(this,_MarkdownEditor_mouseIn,!0,"f"),this.updateSlider()})),this.addEventListener("mouseleave",(()=>{__classPrivateFieldSet(this,_MarkdownEditor_mouseIn,!1,"f"),this.updateSlider()})),this.slider.addEventListener("slideEnd",(()=>{this.updateSlider()}))}async updated(t){if(t.has("spellcheck")&&__classPrivateFieldGet(this,_MarkdownEditor_instances,"m",_MarkdownEditor_applySpellcheck).call(this),__classPrivateFieldGet(this,_MarkdownEditor_editor,"f")||__classPrivateFieldGet(this,_MarkdownEditor_creating,"f"))return;__classPrivateFieldSet(this,_MarkdownEditor_creating,!0,"f");const e=this.content;let o;try{o=await createEditor({container:this.container,content:e,readOnly:this.readOnly,onUpload:this.onUpload,onChange:this._onChange,modifyImageUrl:this.modifyImageUrl})}finally{__classPrivateFieldSet(this,_MarkdownEditor_creating,!1,"f")}if(e!==this.content||!this.isConnected)return o.destroy(),dom.empty(this.container),void(this.isConnected&&this.requestUpdate());__classPrivateFieldSet(this,_MarkdownEditor_editor,o,"f"),__classPrivateFieldGet(this,_MarkdownEditor_instances,"m",_MarkdownEditor_applySpellcheck).call(this),this.slider.attachElement(this.milkdownElm),this.milkdownElm.addEventListener("scroll",__classPrivateFieldGet(this,_MarkdownEditor_onScroll,"f")),__classPrivateFieldGet(this,_MarkdownEditor_instances,"m",_MarkdownEditor_restoreScroll).call(this)}updateSlider(){this.slider&&this.milkdownElm&&(this.milkdownElm.scrollHeight>this.milkdownElm.clientHeight&&(__classPrivateFieldGet(this,_MarkdownEditor_mouseIn,"f")||this.slider.sliding)?this.slider.show():this.slider.hide())}disconnectedCallback(){super.disconnectedCallback(),__classPrivateFieldGet(this,_MarkdownEditor_editor,"f")?.destroy(),__classPrivateFieldSet(this,_MarkdownEditor_editor,null,"f"),dom.empty(this.container)}layout(){}};_MarkdownEditor_content=new WeakMap,_MarkdownEditor_mouseIn=new WeakMap,_MarkdownEditor_scrollTop=new WeakMap,_MarkdownEditor_editor=new WeakMap,_MarkdownEditor_creating=new WeakMap,_MarkdownEditor_onScroll=new WeakMap,_MarkdownEditor_instances=new WeakSet,_MarkdownEditor_closeCodeEditing=function(){const t=this.milkdownElm;t&&(t.querySelectorAll("og-code-block").forEach((t=>t.endEdit())),t.querySelectorAll("og-markdown-html-block").forEach((t=>{t.editing&&(t.editor?.model&&t.commit(),t.editor?.endEdit())})))},_MarkdownEditor_restoreScroll=function(){const t=this.milkdownElm,e=t?.firstElementChild,o=__classPrivateFieldGet(this,_MarkdownEditor_scrollTop,"f");if(!e||!o)return;let r=-1;const i=()=>!(!e.isConnected||r>-1&&Math.abs(t.scrollTop-r)>1||(r=Math.max(0,Math.min(o,t.scrollHeight-t.clientHeight)),t.scrollTop=r,this.slider.value=r,this.slider.updatePosition(),0));t.style.overflowAnchor="none",e.style.overflowAnchor="none";const d=new ResizeObserver((()=>{i()||n()})),n=()=>{clearTimeout(s),d.disconnect(),t.style.overflowAnchor="",e.style.overflowAnchor=""},s=setTimeout(n,2e3);i(),d.observe(e)},_MarkdownEditor_applySpellcheck=function(){this.milkdownElm?.setAttribute("spellcheck",String(this.spellcheck))},MarkdownEditor.styles=[style,...styles],__decorate([property({type:String})],MarkdownEditor.prototype,"content",null),__decorate([property({type:Number})],MarkdownEditor.prototype,"maxContentWidth",void 0),__decorate([property({type:String,reflect:!0})],MarkdownEditor.prototype,"contentAlignment",void 0),__decorate([property({type:Boolean,reflect:!0})],MarkdownEditor.prototype,"readOnly",void 0),__decorate([property({type:Boolean})],MarkdownEditor.prototype,"spellcheck",void 0),__decorate([query("#container")],MarkdownEditor.prototype,"container",void 0),__decorate([query("og-slider")],MarkdownEditor.prototype,"slider",void 0),__decorate([property({type:Object})],MarkdownEditor.prototype,"onUpload",void 0),__decorate([property({type:Object})],MarkdownEditor.prototype,"modifyImageUrl",void 0),MarkdownEditor=__decorate([customElement("og-markdown-editor")],MarkdownEditor);export{MarkdownEditor};
@@ -1 +1 @@
1
- {"version":3,"file":"markdownEditor.js","sourceRoot":"","sources":["../../src/components/markdownEditor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,EAAsC,MAAM,iBAAiB,CAAC;AAElF,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,EAAE,MAA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;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;6CACa;AAUtC;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;uDACH;AAGtB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;wDACM;AAG9C;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;gDACxB;AAGjB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC;kDACP;AAGnB;IADC,KAAK,CAAC,YAAY,CAAC;iDACM;AAG1B;IADC,KAAK,CAAC,WAAW,CAAC;8CACJ;AAMf;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;gDACiB;AAG1C;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;sDACgC;AAxC7C,cAAc;IAD1B,aAAa,CAAC,oBAAoB,CAAC;GACvB,cAAc,CA4N1B","sourcesContent":["import { dom, events, HorizontalPosition, Layout, Slider } from '@omegagrid/core';\nimport { CodeBlock } from '@omegagrid/code';\nimport { LitElement, html } from 'lit';\nimport { customElement, query, property } from 'lit/decorators.js';\nimport { style } from './markdownEditor.style';\nimport styles from './styles';\nimport { createEditor } from '../utils';\nimport { HtmlBlockComponent } from './features/htmlBlock';\nimport type * as milkdown from '@omegagrid/milkdown-kit';\n\n// how long the restored scroll offset is held while the content renders\nconst SCROLL_SETTLE_TIMEOUT = 2000;\n\nexport class MarkdownLinkEvent extends Event {\n\treadonly href: string;\n\treadonly a: HTMLAnchorElement;\n\treadonly origEvent: PointerEvent;\n\n\tconstructor(args: Partial<MarkdownLinkEvent>) {\n\t\tsuper(`markdown.link`, {bubbles: true, composed: true, cancelable: true});\n\t\tObject.assign(this, args);\n\t}\n}\n\n@customElement('og-markdown-editor')\nexport class MarkdownEditor extends LitElement implements Layout {\n\n\tstatic styles = [style, ...styles];\n\n\t#content: string\n\t@property({type: String})\n\tget content() { return this.#content }\n\tset content(val: string) {\n\t\tif (val !== this.#content) this.#scrollTop = 0; // another document starts at the top\n\t\tthis.#content = val;\n\t\tthis.#editor?.destroy();\n\t\tthis.#editor = null;\n\t\tthis.requestUpdate();\n\t}\n\n\t@property({type: Number})\n\tmaxContentWidth = 800;\n\n\t@property({type: String, reflect: true})\n\tcontentAlignment: HorizontalPosition = 'left';\n\n\t@property({type: Boolean, reflect: true})\n\treadOnly = false;\n\n\t@property({type: Boolean})\n\tspellcheck = false;\n\n\t@query('#container')\n\tcontainer: HTMLDivElement;\n\n\t@query('og-slider')\n\tslider: Slider;\n\n\t#mouseIn = false;\n\t#scrollTop = 0;\n\n\t@property({type: Object})\n\tonUpload: (file: File) => Promise<string>;\n\n\t@property({type: Object})\n\tmodifyImageUrl: (file: string) => Promise<string>|string;\n\n\t#editor: milkdown.core.Editor;\n\n\tget milkdownElm () { return this.container.firstElementChild as HTMLElement }\n\tget editor() { return this.#editor }\n\n\tconstructor() {\n\t\tsuper();\n\t\tdom.on(this, 'click', 'a', (e: PointerEvent, a) => {\n\t\t\tconst canceled = !this.dispatchEvent(new MarkdownLinkEvent({\n\t\t\t\thref: a.getAttribute('href'), \n\t\t\t\ta: a as HTMLAnchorElement,\n\t\t\t\torigEvent: e\n\t\t\t}));\n\n\t\t\tif (canceled) {\n\t\t\t\te.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst href = a.getAttribute('href');\n\t\t\tif (href && href.startsWith('#')) {\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.scrollToSelector(href);\n\t\t\t}\n\t\t});\n\t}\n\n\t#onScroll = () => {\n\t\tthis.#scrollTop = this.milkdownElm?.scrollTop ?? 0;\n\t\tthis.#closeCodeEditing();\n\t}\n\n\t// Monaco renders into an overlay pinned to the document, so an open code editor\n\t// cannot travel with the scrolled content - close it instead of leaving it\n\t// standing over the rest of the document.\n\t#closeCodeEditing() {\n\t\tconst elm = this.milkdownElm;\n\t\tif (!elm) return;\n\n\t\telm.querySelectorAll<CodeBlock>('og-code-block').forEach(block => block.endEdit());\n\n\t\telm.querySelectorAll<HtmlBlockComponent>('og-markdown-html-block').forEach(block => {\n\t\t\tif (!block.editing) return;\n\t\t\t// the html block keeps its value in the code editor, let it save first\n\t\t\tif (block.editor?.model) block.commit();\n\t\t\tblock.editor?.endEdit();\n\t\t});\n\t}\n\n\t// The editor is destroyed on disconnect and rebuilt on reconnect (switching\n\t// tabs takes the component out of the DOM), which puts the fresh content back\n\t// to the top - put it back where the user left off.\n\t#restoreScroll() {\n\t\tconst elm = this.milkdownElm;\n\t\tconst content = elm?.firstElementChild as HTMLElement;\n\t\tconst target = this.#scrollTop;\n\t\tif (!content || !target) return;\n\n\t\tlet applied = -1;\n\t\tconst apply = () => {\n\t\t\tif (!content.isConnected) return false; // the editor is gone\n\t\t\tif (applied > -1 && Math.abs(elm.scrollTop - applied) > 1) return false; // the user took over\n\t\t\tapplied = Math.max(0, Math.min(target, elm.scrollHeight - elm.clientHeight));\n\t\t\telm.scrollTop = applied;\n\t\t\tthis.slider.value = applied;\n\t\t\tthis.slider.updatePosition();\n\t\t\treturn true;\n\t\t};\n\n\t\t// Images, code blocks and the like render asynchronously and keep growing\n\t\t// the content, so hold the offset until it settles. Scroll anchoring would\n\t\t// shift it along with the growing content, so turn it off while we do.\n\t\telm.style.overflowAnchor = 'none';\n\t\tcontent.style.overflowAnchor = 'none';\n\n\t\tconst observer = new ResizeObserver(() => { if (!apply()) stop() });\n\t\tconst stop = () => {\n\t\t\tclearTimeout(timer);\n\t\t\tobserver.disconnect();\n\t\t\telm.style.overflowAnchor = '';\n\t\t\tcontent.style.overflowAnchor = '';\n\t\t};\n\t\tconst timer = setTimeout(stop, SCROLL_SETTLE_TIMEOUT);\n\n\t\tapply();\n\t\tobserver.observe(content);\n\t}\n\n\tscrollToSelector(selector: string) {\n\t\tconst elm = this.milkdownElm.querySelector(selector) as HTMLElement;\n\t\tif (!elm) return;\n\t\tthis.milkdownElm.scrollTop = elm.offsetTop;\n\t\tthis.slider.updatePosition();\n\t}\n\n\tconnectedCallback() {\n\t\tsuper.connectedCallback();\n\t\tthis.requestUpdate();\n\t}\n\n\tupdateWidth() {\n\t\tconst width = Math.min(this.maxContentWidth, this.clientWidth);\n\t\tthis.milkdownElm.style.width = `${width}px`;\n\t}\n\n\t_onChange = (markdown: string, prevMarkdown: string) => {\n\t\tthis.#content = markdown;\n\t\tthis.dispatchEvent(new events.ChangeEvent({value: markdown, oldValue: prevMarkdown}));\n\t}\n\n\tfirstUpdated() {\n\t\tthis.slider.hide();\n\n\t\tthis.addEventListener('mouseenter', () => {\n\t\t\tthis.#mouseIn = true;\n\t\t\tthis.updateSlider();\n\t\t});\n\n\t\tthis.addEventListener('mouseleave', () => {\n\t\t\tthis.#mouseIn = false;\n\t\t\tthis.updateSlider();\n\t\t});\n\n\t\tthis.slider.addEventListener('slideEnd', () => {\n\t\t\tthis.updateSlider();\n\t\t});\n\t}\n\n\tasync updated(changed: Map<PropertyKey, unknown>) {\n\t\tif (changed.has('spellcheck')) this.#applySpellcheck();\n\t\tif (this.#editor) return;\n\t\tthis.#editor = await createEditor({\n\t\t\tcontainer: this.container,\n\t\t\tcontent: this.content,\n\t\t\treadOnly: this.readOnly,\n\t\t\tonUpload: this.onUpload,\n\t\t\tonChange: this._onChange,\n\t\t\tmodifyImageUrl: this.modifyImageUrl\n\t\t});\n\t\tthis.#applySpellcheck();\n\t\tthis.slider.attachElement(this.milkdownElm);\n\t\tthis.milkdownElm.addEventListener('scroll', this.#onScroll);\n\t\tthis.#restoreScroll();\n\t}\n\n\t// The browser only re-checks spelling on the element it edits, so set the\n\t// attribute on the ProseMirror editable itself (not just the container).\n\t#applySpellcheck() {\n\t\tthis.milkdownElm?.setAttribute('spellcheck', String(this.spellcheck));\n\t}\n\n\tupdateSlider() {\n\t\tif (!this.slider || !this.milkdownElm) return;\n\t\tconst needsScroll = this.milkdownElm.scrollHeight > this.milkdownElm.clientHeight;\n\t\tif (needsScroll && (this.#mouseIn || this.slider.sliding)) {\n\t\t\tthis.slider.show();\n\t\t} else {\n\t\t\tthis.slider.hide();\n\t\t}\n\t}\n\n\tdisconnectedCallback() {\n\t\tsuper.disconnectedCallback();\n\t\tthis.#editor?.destroy();\n\t\tthis.#editor = null;\n\t\tdom.empty(this.container);\n\t}\n\n\trender = () => html`\n\t\t<style>\n\t\t\t.ProseMirror.editor { max-width: ${this.maxContentWidth}px; }\n\t\t</style>\n\t\t<div id=\"container\" spellcheck=\"${this.spellcheck}\"></div>\n\t\t<og-slider direction=\"vertical\" hidden></og-slider>\n\t`;\n\n\tlayout() { }\n\n}"]}
1
+ {"version":3,"file":"markdownEditor.js","sourceRoot":"","sources":["../../src/components/markdownEditor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,EAAsC,MAAM,iBAAiB,CAAC;AAElF,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAIxC,wEAAwE;AACxE,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAEnC,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAK3C,YAAY,IAAgC;QAC3C,KAAK,CAAC,eAAe,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAC,CAAC,CAAC;QAC1E,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3B,CAAC;CACD;AAGM,IAAM,cAAc,GAApB,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AE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;AACvE,CAAC;AAjNM,qBAAM,GAAG,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC,AAArB,CAAsB;AAInC;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;6CACa;AAUtC;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;uDACH;AAGtB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;wDACM;AAG9C;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;gDACxB;AAGjB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC;kDACP;AAGnB;IADC,KAAK,CAAC,YAAY,CAAC;iDACM;AAG1B;IADC,KAAK,CAAC,WAAW,CAAC;8CACJ;AAMf;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;gDACiB;AAG1C;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;sDACgC;AAxC7C,cAAc;IAD1B,aAAa,CAAC,oBAAoB,CAAC;GACvB,cAAc,CAgP1B","sourcesContent":["import { dom, events, HorizontalPosition, Layout, Slider } from '@omegagrid/core';\nimport { CodeBlock } from '@omegagrid/code';\nimport { LitElement, html } from 'lit';\nimport { customElement, query, property } from 'lit/decorators.js';\nimport { style } from './markdownEditor.style';\nimport styles from './styles';\nimport { createEditor } from '../utils';\nimport { HtmlBlockComponent } from './features/htmlBlock';\nimport type * as milkdown from '@omegagrid/milkdown-kit';\n\n// how long the restored scroll offset is held while the content renders\nconst SCROLL_SETTLE_TIMEOUT = 2000;\n\nexport class MarkdownLinkEvent extends Event {\n\treadonly href: string;\n\treadonly a: HTMLAnchorElement;\n\treadonly origEvent: PointerEvent;\n\n\tconstructor(args: Partial<MarkdownLinkEvent>) {\n\t\tsuper(`markdown.link`, {bubbles: true, composed: true, cancelable: true});\n\t\tObject.assign(this, args);\n\t}\n}\n\n@customElement('og-markdown-editor')\nexport class MarkdownEditor extends LitElement implements Layout {\n\n\tstatic styles = [style, ...styles];\n\n\t#content: string\n\t@property({type: String})\n\tget content() { return this.#content }\n\tset content(val: string) {\n\t\tif (val !== this.#content) this.#scrollTop = 0; // another document starts at the top\n\t\tthis.#content = val;\n\t\tthis.#editor?.destroy();\n\t\tthis.#editor = null;\n\t\tthis.requestUpdate();\n\t}\n\n\t@property({type: Number})\n\tmaxContentWidth = 800;\n\n\t@property({type: String, reflect: true})\n\tcontentAlignment: HorizontalPosition = 'left';\n\n\t@property({type: Boolean, reflect: true})\n\treadOnly = false;\n\n\t@property({type: Boolean})\n\tspellcheck = false;\n\n\t@query('#container')\n\tcontainer: HTMLDivElement;\n\n\t@query('og-slider')\n\tslider: Slider;\n\n\t#mouseIn = false;\n\t#scrollTop = 0;\n\n\t@property({type: Object})\n\tonUpload: (file: File) => Promise<string>;\n\n\t@property({type: Object})\n\tmodifyImageUrl: (file: string) => Promise<string>|string;\n\n\t#editor: milkdown.core.Editor;\n\t#creating = false;\n\n\tget milkdownElm () { return this.container.firstElementChild as HTMLElement }\n\tget editor() { return this.#editor }\n\n\tconstructor() {\n\t\tsuper();\n\t\tdom.on(this, 'click', 'a', (e: PointerEvent, a) => {\n\t\t\tconst canceled = !this.dispatchEvent(new MarkdownLinkEvent({\n\t\t\t\thref: a.getAttribute('href'), \n\t\t\t\ta: a as HTMLAnchorElement,\n\t\t\t\torigEvent: e\n\t\t\t}));\n\n\t\t\tif (canceled) {\n\t\t\t\te.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst href = a.getAttribute('href');\n\t\t\tif (href && href.startsWith('#')) {\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.scrollToSelector(href);\n\t\t\t}\n\t\t});\n\t}\n\n\t#onScroll = () => {\n\t\tthis.#scrollTop = this.milkdownElm?.scrollTop ?? 0;\n\t\tthis.#closeCodeEditing();\n\t}\n\n\t// Monaco renders into an overlay pinned to the document, so an open code editor\n\t// cannot travel with the scrolled content - close it instead of leaving it\n\t// standing over the rest of the document.\n\t#closeCodeEditing() {\n\t\tconst elm = this.milkdownElm;\n\t\tif (!elm) return;\n\n\t\telm.querySelectorAll<CodeBlock>('og-code-block').forEach(block => block.endEdit());\n\n\t\telm.querySelectorAll<HtmlBlockComponent>('og-markdown-html-block').forEach(block => {\n\t\t\tif (!block.editing) return;\n\t\t\t// the html block keeps its value in the code editor, let it save first\n\t\t\tif (block.editor?.model) block.commit();\n\t\t\tblock.editor?.endEdit();\n\t\t});\n\t}\n\n\t// The editor is destroyed on disconnect and rebuilt on reconnect (switching\n\t// tabs takes the component out of the DOM), which puts the fresh content back\n\t// to the top - put it back where the user left off.\n\t#restoreScroll() {\n\t\tconst elm = this.milkdownElm;\n\t\tconst content = elm?.firstElementChild as HTMLElement;\n\t\tconst target = this.#scrollTop;\n\t\tif (!content || !target) return;\n\n\t\tlet applied = -1;\n\t\tconst apply = () => {\n\t\t\tif (!content.isConnected) return false; // the editor is gone\n\t\t\tif (applied > -1 && Math.abs(elm.scrollTop - applied) > 1) return false; // the user took over\n\t\t\tapplied = Math.max(0, Math.min(target, elm.scrollHeight - elm.clientHeight));\n\t\t\telm.scrollTop = applied;\n\t\t\tthis.slider.value = applied;\n\t\t\tthis.slider.updatePosition();\n\t\t\treturn true;\n\t\t};\n\n\t\t// Images, code blocks and the like render asynchronously and keep growing\n\t\t// the content, so hold the offset until it settles. Scroll anchoring would\n\t\t// shift it along with the growing content, so turn it off while we do.\n\t\telm.style.overflowAnchor = 'none';\n\t\tcontent.style.overflowAnchor = 'none';\n\n\t\tconst observer = new ResizeObserver(() => { if (!apply()) stop() });\n\t\tconst stop = () => {\n\t\t\tclearTimeout(timer);\n\t\t\tobserver.disconnect();\n\t\t\telm.style.overflowAnchor = '';\n\t\t\tcontent.style.overflowAnchor = '';\n\t\t};\n\t\tconst timer = setTimeout(stop, SCROLL_SETTLE_TIMEOUT);\n\n\t\tapply();\n\t\tobserver.observe(content);\n\t}\n\n\tscrollToSelector(selector: string) {\n\t\tconst elm = this.milkdownElm.querySelector(selector) as HTMLElement;\n\t\tif (!elm) return;\n\t\tthis.milkdownElm.scrollTop = elm.offsetTop;\n\t\tthis.slider.updatePosition();\n\t}\n\n\tconnectedCallback() {\n\t\tsuper.connectedCallback();\n\t\tthis.requestUpdate();\n\t}\n\n\tupdateWidth() {\n\t\tconst width = Math.min(this.maxContentWidth, this.clientWidth);\n\t\tthis.milkdownElm.style.width = `${width}px`;\n\t}\n\n\t_onChange = (markdown: string, prevMarkdown: string) => {\n\t\tthis.#content = markdown;\n\t\tthis.dispatchEvent(new events.ChangeEvent({value: markdown, oldValue: prevMarkdown}));\n\t}\n\n\tfirstUpdated() {\n\t\tthis.slider.hide();\n\n\t\tthis.addEventListener('mouseenter', () => {\n\t\t\tthis.#mouseIn = true;\n\t\t\tthis.updateSlider();\n\t\t});\n\n\t\tthis.addEventListener('mouseleave', () => {\n\t\t\tthis.#mouseIn = false;\n\t\t\tthis.updateSlider();\n\t\t});\n\n\t\tthis.slider.addEventListener('slideEnd', () => {\n\t\t\tthis.updateSlider();\n\t\t});\n\t}\n\n\tasync updated(changed: Map<PropertyKey, unknown>) {\n\t\tif (changed.has('spellcheck')) this.#applySpellcheck();\n\t\t// Only one editor may be under construction at a time. createEditor() is async\n\t\t// (it may still be downloading Milkdown), so a content change arriving meanwhile\n\t\t// must not start a second instance in the same container.\n\t\tif (this.#editor || this.#creating) return;\n\t\tthis.#creating = true;\n\t\tconst content = this.content;\n\t\tlet editor: milkdown.core.Editor;\n\t\ttry {\n\t\t\teditor = await createEditor({\n\t\t\t\tcontainer: this.container,\n\t\t\t\tcontent,\n\t\t\t\treadOnly: this.readOnly,\n\t\t\t\tonUpload: this.onUpload,\n\t\t\t\tonChange: this._onChange,\n\t\t\t\tmodifyImageUrl: this.modifyImageUrl\n\t\t\t});\n\t\t} finally {\n\t\t\tthis.#creating = false;\n\t\t}\n\t\t// The content changed (or the element was detached) while the editor was being\n\t\t// created: this instance is stale. Drop it and let the next update build a fresh one.\n\t\tif (content !== this.content || !this.isConnected) {\n\t\t\teditor.destroy();\n\t\t\tdom.empty(this.container);\n\t\t\tif (this.isConnected) this.requestUpdate();\n\t\t\treturn;\n\t\t}\n\t\tthis.#editor = editor;\n\t\tthis.#applySpellcheck();\n\t\tthis.slider.attachElement(this.milkdownElm);\n\t\tthis.milkdownElm.addEventListener('scroll', this.#onScroll);\n\t\tthis.#restoreScroll();\n\t}\n\n\t// The browser only re-checks spelling on the element it edits, so set the\n\t// attribute on the ProseMirror editable itself (not just the container).\n\t#applySpellcheck() {\n\t\tthis.milkdownElm?.setAttribute('spellcheck', String(this.spellcheck));\n\t}\n\n\tupdateSlider() {\n\t\tif (!this.slider || !this.milkdownElm) return;\n\t\tconst needsScroll = this.milkdownElm.scrollHeight > this.milkdownElm.clientHeight;\n\t\tif (needsScroll && (this.#mouseIn || this.slider.sliding)) {\n\t\t\tthis.slider.show();\n\t\t} else {\n\t\t\tthis.slider.hide();\n\t\t}\n\t}\n\n\tdisconnectedCallback() {\n\t\tsuper.disconnectedCallback();\n\t\tthis.#editor?.destroy();\n\t\tthis.#editor = null;\n\t\tdom.empty(this.container);\n\t}\n\n\trender = () => html`\n\t\t<style>\n\t\t\t.ProseMirror.editor { max-width: ${this.maxContentWidth}px; }\n\t\t</style>\n\t\t<div id=\"container\" spellcheck=\"${this.spellcheck}\"></div>\n\t\t<og-slider direction=\"vertical\" hidden></og-slider>\n\t`;\n\n\tlayout() { }\n\n}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omegagrid/markdown",
3
- "version": "0.11.6",
3
+ "version": "0.11.7",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Markdown view webcomponent",
6
6
  "main": "./dist/index.js",
@@ -28,11 +28,11 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@fortawesome/fontawesome-svg-core": "^7.0.1",
31
- "@omegagrid/code": "^0.11.6",
32
- "@omegagrid/core": "^0.11.6",
33
- "@omegagrid/localize": "^0.11.6",
34
- "@omegagrid/milkdown-kit": "^0.11.6",
35
- "@omegagrid/tabs": "^0.11.6",
31
+ "@omegagrid/code": "^0.11.7",
32
+ "@omegagrid/core": "^0.11.7",
33
+ "@omegagrid/localize": "^0.11.7",
34
+ "@omegagrid/milkdown-kit": "^0.11.7",
35
+ "@omegagrid/tabs": "^0.11.7",
36
36
  "lit": "^3.1.1",
37
37
  "markdown-it": "^14.1.0",
38
38
  "ts-debounce": "^4.0.0"