19 lines
8.5 KiB
JavaScript
19 lines
8.5 KiB
JavaScript
|
/*
|
||
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||
|
if you want to view the source, please visit the github repository of this plugin
|
||
|
*/
|
||
|
|
||
|
var V=Object.create;var w=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var b=n=>w(n,"__esModule",{value:!0});var _=(n,t)=>{b(n);for(var e in t)w(n,e,{get:t[e],enumerable:!0})},K=(n,t,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of z(t))!W.call(n,l)&&l!=="default"&&w(n,l,{get:()=>t[l],enumerable:!(e=q(t,l))||e.enumerable});return n},N=n=>K(b(w(n!=null?V(j(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var p=(n,t,e)=>new Promise((l,i)=>{var r=a=>{try{o(e.next(a))}catch(u){i(u)}},s=a=>{try{o(e.throw(a))}catch(u){i(u)}},o=a=>a.done?l(a.value):Promise.resolve(a.value).then(r,s);o((e=e.apply(n,t)).next())});_(exports,{ColumnInsertModal:()=>v,default:()=>x});var g=N(require("obsidian"));var L=N(require("obsidian")),J=n=>n=="yes"||n=="true",Q=(n,t)=>{if(t=="string")return n;if(t=="boolean")return J(n);if(t=="number")return parseFloat(n)};function E(n,t,e,l){let i=new L.Setting(n).setName(t[1].name).setDesc(t[1].desc);typeof t[1].value=="boolean"?i.addToggle(r=>r.setValue(e).onChange(s=>{l(s,t[0])})):i.addText(r=>r.setPlaceholder(String(t[1].value)).setValue(String(e)).onChange(s=>{l(Q(s,typeof t[1].value),t[0])}))}function I(n,t,e){let{containerEl:l}=n;l.empty(),l.createEl("h2",{text:"Settings for "+e});let i=Object.entries(t);for(let r of i)E(l,r,n.plugin.settings[r[0]].value,(s,o)=>{n.plugin.settings[o].value=s,n.plugin.saveSettings()})}function A(n,t){return p(this,null,function*(){return new Promise((e,l)=>{n.settings=t,n.loadData().then(i=>{i&&Object.entries(i).forEach(s=>{n.settings[s[0]].value=s[1]})}).then(e).catch(l)})})}function D(n,t){return p(this,null,function*(){let e={};Object.entries(n.settings).forEach(l=>{e[l[0]]=l[1].value,l[1].onChange(l[1].value)}),yield n.saveData(e)})}var X="Obsidian Columns",T="col",P=T+"-md",Y="!!!",O="===";var k="--obsidian-columns-min-width",G="--obsidian-columns-def-span",Z="`",M={wrapSize:{value:100,name:"Minimum width of column",desc:"Columns will have this minimum width before wrapping to a new row. 0 disables column wrapping. Useful for smaller devices",onChange:n=>{document.querySelector(":root").style.setProperty(k,n.toString()+"px")}},defaultSpan:{value:1,name:"The default span of an item",desc:"The default width of a column. If the minimum width is specified, the width of the column will be multiplied by this setting.",onChange:n=>{document.querySelector(":root").style.setProperty(G,n.toString())}}},H=(n,t=["`"],e=O)=>{let l=n.split(`
|
||
|
`),i=!1;e:for(let r of l)for(let s of t){if(r.contains(s))break e;if(r==e){let o=n.split(e+`
|
||
|
`);if(o.length>1)return{settings:o[0],source:o.slice(1).join(e+`
|
||
|
`)};break e}}return{settings:"",source:n}},B=n=>{let t={};return n.split(`
|
||
|
`).map(e=>e.split(";")).reduce((e,l)=>(e.push(...l),e)).map(e=>e.split("=").map(l=>l.trim()).slice(0,2)).forEach(e=>{t[e[0]]=e[1]}),t},$=n=>{let t=0,e=n.split("");for(let l of e)if(l==Z)t++;else break;return t},ee=n=>{let t=n.split(`
|
||
|
`),e=[],l=0,i=0,r=[];for(let s of t){let o=$(s);if(i=o<3?0:o,l==0&&i==0&&s.startsWith(O)){e.push(r.join(`
|
||
|
`)),r=[];continue}else l==0?l=i:l==i&&(l=0);r.push(s)}return e.push(r.join(`
|
||
|
`)),e},F=n=>parseFloat(n.split("").filter(t=>"0123456789.".contains(t)).join("")),x=class extends g.Plugin{constructor(){super(...arguments);this.generateCssString=t=>{let e={};return e.flexGrow=t.toString(),e.flexBasis=(this.settings.wrapSize.value*t).toString()+"px",e.width=(this.settings.wrapSize.value*t).toString()+"px",e};this.applyStyle=(t,e)=>{Object.assign(t.style,e)};this.processChild=t=>{t.firstChild!=null&&"tagName"in t.firstChild&&t.firstChild.tagName=="BR"&&t.removeChild(t.firstChild);let e=t;for(;e!=null;)"style"in e&&(e.style.marginTop="0px"),e=e.firstChild;let l=t;for(;l!=null;)"style"in l&&(l.style.marginBottom="0px"),l=l.lastChild}}onload(){return p(this,null,function*(){yield this.loadSettings(),this.addSettingTab(new R(this.app,this)),this.registerMarkdownCodeBlockProcessor(P,(e,l,i)=>{let r=H(e),s=B(r.settings);e=r.source;let o=i.sourcePath,a=l.createDiv(),u=new g.MarkdownRenderChild(a);if(i.addChild(u),g.MarkdownRenderer.renderMarkdown(e,a,o,u),s.flexGrow!=null){let d=parseFloat(s.flexGrow),f=this.generateCssString(d);delete f.width,this.applyStyle(a,f)}if(s.height!=null){let d={};d.height=s.height.toString(),d.overflow="scroll",this.applyStyle(a,d)}if(s.textAlign!=null){let d={};d.textAlign=s.textAlign,this.applyStyle(a,d)}}),this.registerMarkdownCodeBlockProcessor(T,(e,l,i)=>p(this,null,function*(){let r=H(e),s=B(r.settings),o=ee(r.source);console.log(o);for(let a of o){let u=i.sourcePath,d=createDiv(),f=new g.MarkdownRenderChild(d);i.addChild(f);let C=g.MarkdownRenderer.renderMarkdown(a,d,u,f),m=l.createEl("div",{cls:"columnParent"});if(Array.from(d.children).forEach(c=>{let h=m.createEl("div",{cls:"columnChild"}),y=new g.MarkdownRenderChild(h);i.addChild(y),this.applyStyle(h,this.generateCssString(this.settings.defaultSpan.value)),h.appendChild(c),c.classList.contains("block-language-"+P)&&c.childNodes[0].style.flexGrow!=""&&(h.style.flexGrow=c.childNodes[0].style.flexGrow,h.style.flexBasis=c.childNodes[0].style.flexBasis,h.style.width=c.childNodes[0].style.flexBasis),this.processChild(c)}),s.height!=null){let c=s.height;if(c=="shortest"){yield C;let h=Math.min(...Array.from(m.children).map(S=>S.childNodes[0]).map(S=>F(getComputedStyle(S).height)+F(getComputedStyle(S).lineHeight))),y={};y.height=h+"px",y.overflow="scroll",Array.from(m.children).map(S=>S.childNodes[0]).forEach(S=>{this.applyStyle(S,y)})}else{let h={};h.height=c,h.overflow="scroll",this.applyStyle(m,h)}}if(s.textAlign!=null){let c={};c.textAlign=s.textAlign,this.applyStyle(m,c)}}})),this.addCommand({id:"insert-column-wrapper",name:"Insert column wrapper",editorCallback:(e,l)=>{new v(this.app,i=>{let r=i.numberOfColumns.value,s="````col\n";for(let o=0;o<r;o++)s+="```col-md\nflexGrow=1\n===\n# Column "+o+"\n```\n";s+="````\n",e.replaceSelection(s)}).open()}}),this.addCommand({id:"insert-quick-column-wrapper",name:"Insert quick column wrapper",editorCallback:(e,l)=>{let i=e.getSelection(),r=e.getCursor(),s="````col\n```col-md\nflexGrow=1\n===\n"+i+"\n```\n````\n";if(e.replaceSelection(s),i==="")e.setCursor({line:r.line+4,ch:0});else{let o=i.split(`
|
||
|
`).length;e.setCursor({line:r.line+4+o-1,ch:i.length-i.lastIndexOf(`
|
||
|
`)-1})}}}),this.addCommand({id:"insert-column",name:"Insert column",editorCallback:(e,l)=>{let i=e.getSelection(),r=e.getCursor(),s;if(i==="")s="```col-md\nflexGrow=1\n===\n# New Column\n\n```",e.replaceSelection(s),e.setCursor({line:r.line+4,ch:0});else{s="```col-md\nflexGrow=1\n===\n"+i+"\n```",e.replaceSelection(s);let o=i.split(`
|
||
|
`).length;e.setCursor({line:r.line+o+2,ch:i.length-i.lastIndexOf(`
|
||
|
`)-1})}}});let t=(e,l)=>{for(let i of Array.from(e.children))if(i!=null&&!(i.nodeName!="UL"&&i.nodeName!="OL"))for(let r of Array.from(i.children)){if(r==null)continue;if(!r.textContent.trim().startsWith(Y+T)){t(r,l);continue}i.removeChild(r);let s=e.createEl("div",{cls:"columnParent"}),o=new g.MarkdownRenderChild(s);l.addChild(o);let a=r.querySelector("ul, ol");if(a!=null)for(let u of Array.from(a.children)){let d=s.createEl("div",{cls:"columnChild"}),f=new g.MarkdownRenderChild(d);l.addChild(f);let C=parseFloat(u.textContent.split(`
|
||
|
`)[0].split(" ")[0]);isNaN(C)&&(C=this.settings.defaultSpan.value),this.applyStyle(d,this.generateCssString(C));let m=!1;t(u,l);for(let c of Array.from(u.childNodes))m&&d.appendChild(c),c.nodeName=="#text"&&(m=!0);this.processChild(d)}}};this.registerMarkdownPostProcessor((e,l)=>{t(e,l)})})}onunload(){}loadSettings(){return p(this,null,function*(){yield A(this,M);let t=document.querySelector(":root");console.log(this.settings.wrapSize.value.toString()),t.style.setProperty(k,this.settings.wrapSize.value.toString()+"px"),t.style.setProperty(G,this.settings.defaultSpan.value.toString())})}saveSettings(){return p(this,null,function*(){yield D(this,M)})}},U={numberOfColumns:{value:2,name:"Number of Columns",desc:"Number of Columns to be made"}},v=class extends g.Modal{constructor(t,e){super(t);this.onSubmit=e}onOpen(){let{contentEl:t}=this;t.createEl("h1",{text:"Create a Column Wrapper"});let e=U,l=Object.entries(U);for(let i of l)E(t,i,"",(r,s)=>{e[s].value=r});new g.Setting(t).addButton(i=>i.setButtonText("Submit").setCta().onClick(()=>{this.close(),this.onSubmit(e)}))}onClose(){let{contentEl:t}=this;t.empty()}},R=class extends g.PluginSettingTab{constructor(t,e){super(t,e);this.plugin=e}display(){I(this,M,X)}};
|