@desktalk/miniapp-note 0.1.0-alpha.2 → 0.1.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/frontend.js CHANGED
@@ -1,4 +1,4 @@
1
- var h=window.React,qe=h.Children,Be=h.Component,je=h.Fragment,Ue=h.Profiler,Ye=h.PureComponent,Xe=h.StrictMode,Ge=h.Suspense,Ke=h.cloneElement,Je=h.createContext,Qe=h.createElement,Ze=h.createRef,ft=h.forwardRef,tr=h.isValidElement,er=h.lazy,rr=h.memo,ir=h.startTransition,x=h.useCallback,nr=h.useContext,sr=h.useDebugValue,ar=h.useDeferredValue,q=h.useEffect,or=h.useId,_t=h.useImperativeHandle,dr=h.useInsertionEffect,lr=h.useLayoutEffect,cr=h.useMemo,hr=h.useReducer,H=h.useRef,I=h.useState,ur=h.useSyncExternalStore,pr=h.useTransition,mr=h.version,at=window.ReactDOM,xt=at.createRoot,gr=at.hydrateRoot;import{useCommand as B,MiniAppIdProvider as wt,WindowIdProvider as yt}from"@desktalk/sdk";var v={root:"NoteApp_root",rootCompact:"NoteApp_rootCompact",listPanel:"NoteApp_listPanel",listHeader:"NoteApp_listHeader",searchInput:"NoteApp_searchInput",newNoteBtn:"NoteApp_newNoteBtn",noteList:"NoteApp_noteList",noteItem:"NoteApp_noteItem",noteItemActive:"NoteApp_noteItem NoteApp_noteItemActive",emptyState:"NoteApp_emptyState",noteTitle:"NoteApp_noteTitle",notePreview:"NoteApp_notePreview",noteDate:"NoteApp_noteDate",editorPanel:"NoteApp_editorPanel",editorHeader:"NoteApp_editorHeader",editorTitle:"NoteApp_editorTitle",editorTags:"NoteApp_editorTags",editorTag:"NoteApp_editorTag",editorBody:"NoteApp_editorBody",editorPlaceholder:"NoteApp_editorPlaceholder",saveStatus:"NoteApp_saveStatus",saveStatusSaving:"NoteApp_saveStatus NoteApp_saveStatusSaving"},G=window.__desktalk_jsx_runtime,u=G.jsx,T=G.jsxs,vr=G.jsxDEV,fr=G.Fragment;function kt(t){try{const e=new Date(t),i=new Date().getTime()-e.getTime(),n=Math.floor(i/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const s=Math.floor(n/60);if(s<24)return`${s}h ago`;const a=Math.floor(s/24);return a<7?`${a}d ago`:e.toLocaleDateString(void 0,{month:"short",day:"numeric"})}catch{return""}}function Ct({notes:t,selectedId:e,onSelect:r,onCreate:i,searchQuery:n,onSearchChange:s}){const a=H(null);return T("div",{className:v.listPanel,children:[T("div",{className:v.listHeader,children:[u("input",{ref:a,type:"text",className:v.searchInput,placeholder:"Search notes...",value:n,onChange:o=>s(o.target.value)}),u("button",{className:v.newNoteBtn,onClick:i,title:"New note",children:"+"})]}),u("div",{className:v.noteList,children:t.length===0?u("div",{className:v.emptyState,children:n?"No notes match your search":"No notes yet"}):t.map(o=>T("div",{className:o.id===e?v.noteItemActive:v.noteItem,onClick:()=>r(o.id),children:[u("div",{className:v.noteTitle,children:o.title}),u("div",{className:v.notePreview,children:o.preview}),u("div",{className:v.noteDate,children:kt(o.updatedAt)})]},o.id))})]})}var Et=`.dt-tooltip-popup {
1
+ var h=window.React,We=h.Children,Be=h.Component,je=h.Fragment,Ue=h.Profiler,Ye=h.PureComponent,Xe=h.StrictMode,Ge=h.Suspense,Ke=h.cloneElement,Je=h.createContext,Qe=h.createElement,Ze=h.createRef,ft=h.forwardRef,tr=h.isValidElement,er=h.lazy,rr=h.memo,ir=h.startTransition,x=h.useCallback,nr=h.useContext,sr=h.useDebugValue,ar=h.useDeferredValue,W=h.useEffect,or=h.useId,_t=h.useImperativeHandle,dr=h.useInsertionEffect,lr=h.useLayoutEffect,cr=h.useMemo,hr=h.useReducer,H=h.useRef,I=h.useState,ur=h.useSyncExternalStore,pr=h.useTransition,mr=h.version,at=window.ReactDOM,xt=at.createRoot,gr=at.hydrateRoot;import{useCommand as B,MiniAppIdProvider as wt,WindowIdProvider as yt}from"@desktalk/sdk";var v={root:"NoteApp_root",rootCompact:"NoteApp_rootCompact",listPanel:"NoteApp_listPanel",listHeader:"NoteApp_listHeader",searchInput:"NoteApp_searchInput",newNoteBtn:"NoteApp_newNoteBtn",noteList:"NoteApp_noteList",noteItem:"NoteApp_noteItem",noteItemActive:"NoteApp_noteItem NoteApp_noteItemActive",emptyState:"NoteApp_emptyState",noteTitle:"NoteApp_noteTitle",notePreview:"NoteApp_notePreview",noteDate:"NoteApp_noteDate",editorPanel:"NoteApp_editorPanel",editorHeader:"NoteApp_editorHeader",editorTitle:"NoteApp_editorTitle",editorTags:"NoteApp_editorTags",editorTag:"NoteApp_editorTag",editorBody:"NoteApp_editorBody",editorPlaceholder:"NoteApp_editorPlaceholder",saveStatus:"NoteApp_saveStatus",saveStatusSaving:"NoteApp_saveStatus NoteApp_saveStatusSaving"},G=window.__desktalk_jsx_runtime,u=G.jsx,T=G.jsxs,vr=G.jsxDEV,fr=G.Fragment;function kt(t){try{const e=new Date(t),i=new Date().getTime()-e.getTime(),n=Math.floor(i/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const s=Math.floor(n/60);if(s<24)return`${s}h ago`;const a=Math.floor(s/24);return a<7?`${a}d ago`:e.toLocaleDateString(void 0,{month:"short",day:"numeric"})}catch{return""}}function Ct({notes:t,selectedId:e,onSelect:r,onCreate:i,searchQuery:n,onSearchChange:s}){const a=H(null);return T("div",{className:v.listPanel,children:[T("div",{className:v.listHeader,children:[u("input",{ref:a,type:"text",className:v.searchInput,placeholder:"Search notes...",value:n,onChange:o=>s(o.target.value)}),u("button",{className:v.newNoteBtn,onClick:i,title:"New note",children:"+"})]}),u("div",{className:v.noteList,children:t.length===0?u("div",{className:v.emptyState,children:n?"No notes match your search":"No notes yet"}):t.map(o=>T("div",{className:o.id===e?v.noteItemActive:v.noteItem,onClick:()=>r(o.id),children:[u("div",{className:v.noteTitle,children:o.title}),u("div",{className:v.notePreview,children:o.preview}),u("div",{className:v.noteDate,children:kt(o.updatedAt)})]},o.id))})]})}var Et=`.dt-tooltip-popup {
2
2
  position: fixed;
3
3
  z-index: 2147483647;
4
4
  padding: 6px 10px;
@@ -448,7 +448,7 @@ var h=window.React,qe=h.Children,Be=h.Component,je=h.Fragment,Ue=h.Profiler,Ye=h
448
448
  ::slotted(*) {
449
449
  min-width: 0;
450
450
  }
451
- `,Wt="dt-grid-inner",qt=class extends HTMLElement{static get observedAttributes(){return["cols","gap","min-width"]}get cols(){let t=this.getAttribute("cols");return t==="1"||t==="2"||t==="3"||t==="4"||t==="5"||t==="6"?t:null}set cols(t){t===null?this.removeAttribute("cols"):this.setAttribute("cols",t)}get gap(){let t=this.getAttribute("gap");return t==="0"||t==="4"||t==="8"||t==="12"||t==="20"||t==="24"||t==="32"?t:"16"}set gap(t){this.setAttribute("gap",t)}get minWidth(){let t=this.getAttribute("min-width");return t==="150"||t==="180"||t==="200"||t==="260"||t==="300"?t:"220"}set minWidth(t){this.setAttribute("min-width",t)}constructor(){super();let t=this.attachShadow({mode:"open"}),e=document.createElement("style");e.textContent=Ot,t.appendChild(e);let r=document.createElement("div");r.className=Wt,r.innerHTML="<slot></slot>",t.appendChild(r)}},Bt=`:host {
451
+ `,qt="dt-grid-inner",Wt=class extends HTMLElement{static get observedAttributes(){return["cols","gap","min-width"]}get cols(){let t=this.getAttribute("cols");return t==="1"||t==="2"||t==="3"||t==="4"||t==="5"||t==="6"?t:null}set cols(t){t===null?this.removeAttribute("cols"):this.setAttribute("cols",t)}get gap(){let t=this.getAttribute("gap");return t==="0"||t==="4"||t==="8"||t==="12"||t==="20"||t==="24"||t==="32"?t:"16"}set gap(t){this.setAttribute("gap",t)}get minWidth(){let t=this.getAttribute("min-width");return t==="150"||t==="180"||t==="200"||t==="260"||t==="300"?t:"220"}set minWidth(t){this.setAttribute("min-width",t)}constructor(){super();let t=this.attachShadow({mode:"open"}),e=document.createElement("style");e.textContent=Ot,t.appendChild(e);let r=document.createElement("div");r.className=qt,r.innerHTML="<slot></slot>",t.appendChild(r)}},Bt=`:host {
452
452
  display: block;
453
453
  margin-bottom: 12px;
454
454
  }
@@ -860,7 +860,7 @@ var h=window.React,qe=h.Children,Be=h.Component,je=h.Fragment,Ue=h.Profiler,Ye=h
860
860
  width: 1em;
861
861
  height: 1em;
862
862
  }
863
- `,te="dt-button-inner",ee=class extends HTMLElement{static get observedAttributes(){return["variant","size","disabled","fullwidth","type"]}_button;_slot;get variant(){let t=this.getAttribute("variant");return t==="secondary"||t==="ghost"||t==="danger"?t:"primary"}set variant(t){this.setAttribute("variant",t)}get size(){let t=this.getAttribute("size");return t==="sm"||t==="lg"?t:"md"}set size(t){this.setAttribute("size",t)}get disabled(){return this.hasAttribute("disabled")}set disabled(t){t?this.setAttribute("disabled",""):this.removeAttribute("disabled")}get fullwidth(){return this.hasAttribute("fullwidth")}set fullwidth(t){t?this.setAttribute("fullwidth",""):this.removeAttribute("fullwidth")}get type(){let t=this.getAttribute("type");return t==="submit"||t==="reset"?t:"button"}set type(t){this.setAttribute("type",t)}constructor(){super();let t=this.attachShadow({mode:"open"}),e=document.createElement("style");e.textContent=Zt,t.appendChild(e),this._button=document.createElement("button"),this._button.className=te,this._button.type=this.type,this._button.disabled=this.disabled,this._slot=document.createElement("slot"),this._button.appendChild(this._slot),t.appendChild(this._button)}attributeChangedCallback(t,e,r){switch(t){case"disabled":this._button.disabled=this.disabled;break;case"type":this._button.type=this.type;break}}},re=`:host {
863
+ `,te="dt-button-inner",ee=class extends HTMLElement{static get observedAttributes(){return["variant","size","disabled","fullwidth","type"]}_button;_slot;get variant(){let t=this.getAttribute("variant");return t==="secondary"||t==="ghost"||t==="danger"?t:"primary"}set variant(t){this.setAttribute("variant",t)}get size(){let t=this.getAttribute("size");return t==="sm"||t==="lg"?t:"md"}set size(t){this.setAttribute("size",t)}get disabled(){return this.hasAttribute("disabled")}set disabled(t){t?this.setAttribute("disabled",""):this.removeAttribute("disabled")}get fullwidth(){return this.hasAttribute("fullwidth")}set fullwidth(t){t?this.setAttribute("fullwidth",""):this.removeAttribute("fullwidth")}get type(){let t=this.getAttribute("type");return t==="submit"||t==="reset"?t:"button"}set type(t){this.setAttribute("type",t)}constructor(){super();let t=this.attachShadow({mode:"open"}),e=document.createElement("style");e.textContent=Zt,t.appendChild(e),this._button=document.createElement("button"),this._button.className=te,this._button.type=this.type,this._button.disabled=this.disabled,this._slot=document.createElement("slot"),this._button.appendChild(this._slot),this._button.addEventListener("click",()=>{if(this.type==="submit"&&!this.disabled){let r=this.closest("form");r&&r.requestSubmit()}}),t.appendChild(this._button)}attributeChangedCallback(t,e,r){switch(t){case"disabled":this._button.disabled=this.disabled;break;case"type":this._button.type=this.type;break}}},re=`:host {
864
864
  display: block;
865
865
  }
866
866
 
@@ -1677,7 +1677,7 @@ ${r}`}var ze=class extends HTMLElement{_body;_caret;_contentOverride=null;_runti
1677
1677
  .milkdown .editor td {
1678
1678
  border: 1px solid var(--dt-border);
1679
1679
  }
1680
- `,rt=null;function Ne(){return window.__DtMilkdown?Promise.resolve(window.__DtMilkdown):rt||(rt=new Promise((t,e)=>{let r=document.createElement("script");r.src="/api/ui/milkdown.umd.js",r.async=!0,r.dataset.dtMilkdown="true",r.onload=()=>{if(window.__DtMilkdown){t(window.__DtMilkdown);return}e(new Error("Milkdown runtime loaded without a __DtMilkdown export."))},r.onerror=()=>e(new Error("Failed to load the Milkdown runtime bundle.")),document.head.appendChild(r)}),rt)}var Te=class extends HTMLElement{_runtimeStyle;_surface;_content;_status;_runtime=null;_loadPromise=null;_editor=null;_pendingValue="";_changeTimer=null;_setupToken=0;_suppressNextChange=!1;static get observedAttributes(){return["placeholder","readonly"]}get placeholder(){return this.getAttribute("placeholder")??""}set placeholder(t){this.setAttribute("placeholder",t)}get readonly(){return this.hasAttribute("readonly")}set readonly(t){this.toggleAttribute("readonly",t)}get value(){return this._editor&&(this._pendingValue=this._editor.getMarkdown()),this._pendingValue}set value(t){let e=String(t??"");this._pendingValue=e,this._editor&&this._runtime&&this._editor.getMarkdown()!==e&&(this._suppressNextChange=!0,this._editor.editor.action(this._runtime.replaceAll(e)))}constructor(){super();let t=this.attachShadow({mode:"open"}),e=document.createElement("style");e.textContent=Me,t.appendChild(e),this._runtimeStyle=document.createElement("style"),t.appendChild(this._runtimeStyle),this._surface=document.createElement("div"),this._surface.className="dt-markdown-editor",this._content=document.createElement("div"),this._content.className="dt-markdown-editor__surface";let r=document.createElement("div");r.className="dt-markdown-editor__content",this._content.appendChild(r),this._status=document.createElement("div"),this._status.className="dt-markdown-editor__status",this._status.textContent="Loading editor",this._surface.append(this._content,this._status),t.appendChild(this._surface)}connectedCallback(){this._initializeEditor()}disconnectedCallback(){this._setupToken+=1,this._clearChangeTimer(),this._destroyEditor()}attributeChangedCallback(t){if(t==="readonly"){this._editor?.setReadonly(this.readonly);return}t==="placeholder"&&this.isConnected&&this._initializeEditor(!0)}async _ensureRuntime(){return this._runtime?this._runtime:(this._loadPromise||(this._loadPromise=Ne().then(t=>(this._runtime=t,this._runtimeStyle.textContent=t.cssText,t))),this._loadPromise)}async _initializeEditor(t=!1){let e=++this._setupToken;if(this._setStatus("Loading editor"),t)await this._destroyEditor();else if(this._editor){this._setStatus(null);return}try{let r=await this._ensureRuntime();if(!this.isConnected||e!==this._setupToken)return;this._content.replaceChildren();let i=document.createElement("div");i.className="dt-markdown-editor__content",this._content.appendChild(i);let n=new r.Crepe({root:i,defaultValue:this._pendingValue,features:{[r.Crepe.Feature.CodeMirror]:!1,[r.Crepe.Feature.ImageBlock]:!1,[r.Crepe.Feature.Latex]:!1},featureConfigs:{[r.Crepe.Feature.Placeholder]:{text:this.placeholder,mode:"doc"}}});if(n.on(s=>{s.markdownUpdated((a,o)=>{if(this._pendingValue=o,this._suppressNextChange){this._suppressNextChange=!1;return}this._queueChange(o)}),s.focus(()=>{this.dispatchEvent(new CustomEvent("dt-focus",{bubbles:!0,composed:!0}))}),s.blur(()=>{this.dispatchEvent(new CustomEvent("dt-blur",{bubbles:!0,composed:!0}))})}),await n.create(),!this.isConnected||e!==this._setupToken){await n.destroy();return}this._editor=n,this._editor.setReadonly(this.readonly),this._pendingValue=this._editor.getMarkdown(),this._setStatus(null)}catch{e===this._setupToken&&this._setStatus("Failed to load editor")}}async _destroyEditor(){let t=this._editor;if(this._editor=null,!!t)try{await t.destroy()}catch{}}_queueChange(t){this._clearChangeTimer(),this._changeTimer=setTimeout(()=>{this._changeTimer=null,this.dispatchEvent(new CustomEvent("dt-change",{bubbles:!0,composed:!0,detail:{value:t}}))},300)}_clearChangeTimer(){this._changeTimer&&(clearTimeout(this._changeTimer),this._changeTimer=null)}_setStatus(t){if(t){this._status.hidden=!1,this._status.textContent=t;return}this._status.hidden=!0}};customElements.get("dt-tooltip")||customElements.define("dt-tooltip",zt),customElements.get("dt-card")||customElements.define("dt-card",Tt),customElements.get("dt-select")||customElements.define("dt-select",Vt),customElements.get("dt-grid")||customElements.define("dt-grid",qt),customElements.get("dt-stack")||customElements.define("dt-stack",Ut),customElements.get("dt-stat")||customElements.define("dt-stat",Gt),customElements.get("dt-badge")||customElements.define("dt-badge",Qt),customElements.get("dt-button")||customElements.define("dt-button",ee),customElements.get("dt-divider")||customElements.define("dt-divider",ne),customElements.get("dt-list-view")||customElements.define("dt-list-view",pe),customElements.get("dt-table-view")||customElements.define("dt-table-view",ce),customElements.get("dt-column")||customElements.define("dt-column",ut),customElements.get("dt-chart")||customElements.define("dt-chart",ye),customElements.get("dt-markdown")||customElements.define("dt-markdown",ze),customElements.get("dt-markdown-editor")||customElements.define("dt-markdown-editor",Te);function Le(t){const e=t.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?([\s\S]*)$/);return e?e[1]:t}var He=ft(function({note:e,loading:r,onSave:i},n){const s=H(null),[a,o]=I("idle"),d=H(null),l=H(i);return l.current=i,q(()=>{if(s.current&&e){const g=Le(e.content);s.current.value=g}},[e?.id]),q(()=>{const g=s.current;if(!g)return;const _=b=>{const w=b.detail;w&&(d.current&&clearTimeout(d.current),o("saving"),d.current=setTimeout(()=>{l.current(w.value),o("saved")},500))};return g.addEventListener("dt-change",_),()=>g.removeEventListener("dt-change",_)},[]),q(()=>()=>{d.current&&clearTimeout(d.current)},[]),_t(n,()=>({getMarkdown(){return s.current?.value??null},setMarkdown(g){s.current&&(s.current.value=g)},getCursorLine(){return 1},getSelectedText(){return""}}),[]),e?T("div",{className:v.editorPanel,children:[T("div",{className:v.editorHeader,children:[T("div",{children:[u("div",{className:v.editorTitle,children:e.title}),e.tags.length>0&&u("div",{className:v.editorTags,children:e.tags.map(g=>u("span",{className:v.editorTag,children:g},g))})]}),u("span",{className:a==="saving"?v.saveStatusSaving:v.saveStatus,children:a==="saving"?"Saving...":a==="saved"?"Saved":""})]}),u("div",{className:v.editorBody,children:u("dt-markdown-editor",{ref:s,placeholder:"Start writing...",style:{height:"100%"}})})]}):u("div",{className:v.editorPanel,children:u("div",{className:v.editorPlaceholder,children:r?"Loading...":"Select a note or create a new one"})})});import{ActionsProvider as Ie,Action as R,useCommand as J}from"@desktalk/sdk";var Re=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;function Fe(t){const e=t.match(Re);if(!e){const d=t.match(/^#\s+(.+)$/m);return{title:d?d[1].trim():"Untitled",tags:[],created:null,body:t}}const r=e[1],i=e[2];let n="Untitled",s=[],a=null,o=!1;for(const d of r.split(`
1680
+ `,rt=null;function Ne(){return window.__DtMilkdown?Promise.resolve(window.__DtMilkdown):rt||(rt=new Promise((t,e)=>{let r=document.createElement("script");r.src="/api/ui/milkdown.umd.js",r.async=!0,r.dataset.dtMilkdown="true",r.onload=()=>{if(window.__DtMilkdown){t(window.__DtMilkdown);return}e(new Error("Milkdown runtime loaded without a __DtMilkdown export."))},r.onerror=()=>e(new Error("Failed to load the Milkdown runtime bundle.")),document.head.appendChild(r)}),rt)}var Te=class extends HTMLElement{_runtimeStyle;_surface;_content;_status;_runtime=null;_loadPromise=null;_editor=null;_pendingValue="";_changeTimer=null;_setupToken=0;_suppressNextChange=!1;static get observedAttributes(){return["placeholder","readonly"]}get placeholder(){return this.getAttribute("placeholder")??""}set placeholder(t){this.setAttribute("placeholder",t)}get readonly(){return this.hasAttribute("readonly")}set readonly(t){this.toggleAttribute("readonly",t)}get value(){return this._editor&&(this._pendingValue=this._editor.getMarkdown()),this._pendingValue}set value(t){let e=String(t??"");this._pendingValue=e,this._editor&&this._runtime&&this._editor.getMarkdown()!==e&&(this._suppressNextChange=!0,this._editor.editor.action(this._runtime.replaceAll(e)))}constructor(){super();let t=this.attachShadow({mode:"open"}),e=document.createElement("style");e.textContent=Me,t.appendChild(e),this._runtimeStyle=document.createElement("style"),t.appendChild(this._runtimeStyle),this._surface=document.createElement("div"),this._surface.className="dt-markdown-editor",this._content=document.createElement("div"),this._content.className="dt-markdown-editor__surface";let r=document.createElement("div");r.className="dt-markdown-editor__content",this._content.appendChild(r),this._status=document.createElement("div"),this._status.className="dt-markdown-editor__status",this._status.textContent="Loading editor",this._surface.append(this._content,this._status),t.appendChild(this._surface)}connectedCallback(){this._initializeEditor()}disconnectedCallback(){this._setupToken+=1,this._clearChangeTimer(),this._destroyEditor()}attributeChangedCallback(t){if(t==="readonly"){this._editor?.setReadonly(this.readonly);return}t==="placeholder"&&this.isConnected&&this._initializeEditor(!0)}async _ensureRuntime(){return this._runtime?this._runtime:(this._loadPromise||(this._loadPromise=Ne().then(t=>(this._runtime=t,this._runtimeStyle.textContent=t.cssText,t))),this._loadPromise)}async _initializeEditor(t=!1){let e=++this._setupToken;if(this._setStatus("Loading editor"),t)await this._destroyEditor();else if(this._editor){this._setStatus(null);return}try{let r=await this._ensureRuntime();if(!this.isConnected||e!==this._setupToken)return;this._content.replaceChildren();let i=document.createElement("div");i.className="dt-markdown-editor__content",this._content.appendChild(i);let n=new r.Crepe({root:i,defaultValue:this._pendingValue,features:{[r.Crepe.Feature.CodeMirror]:!1,[r.Crepe.Feature.ImageBlock]:!1,[r.Crepe.Feature.Latex]:!1},featureConfigs:{[r.Crepe.Feature.Placeholder]:{text:this.placeholder,mode:"doc"}}});if(n.on(s=>{s.markdownUpdated((a,o)=>{if(this._pendingValue=o,this._suppressNextChange){this._suppressNextChange=!1;return}this._queueChange(o)}),s.focus(()=>{this.dispatchEvent(new CustomEvent("dt-focus",{bubbles:!0,composed:!0}))}),s.blur(()=>{this.dispatchEvent(new CustomEvent("dt-blur",{bubbles:!0,composed:!0}))})}),await n.create(),!this.isConnected||e!==this._setupToken){await n.destroy();return}this._editor=n,this._editor.setReadonly(this.readonly),this._pendingValue=this._editor.getMarkdown(),this._setStatus(null)}catch{e===this._setupToken&&this._setStatus("Failed to load editor")}}async _destroyEditor(){let t=this._editor;if(this._editor=null,!!t)try{await t.destroy()}catch{}}_queueChange(t){this._clearChangeTimer(),this._changeTimer=setTimeout(()=>{this._changeTimer=null,this.dispatchEvent(new CustomEvent("dt-change",{bubbles:!0,composed:!0,detail:{value:t}}))},300)}_clearChangeTimer(){this._changeTimer&&(clearTimeout(this._changeTimer),this._changeTimer=null)}_setStatus(t){if(t){this._status.hidden=!1,this._status.textContent=t;return}this._status.hidden=!0}};customElements.get("dt-tooltip")||customElements.define("dt-tooltip",zt),customElements.get("dt-card")||customElements.define("dt-card",Tt),customElements.get("dt-select")||customElements.define("dt-select",Vt),customElements.get("dt-grid")||customElements.define("dt-grid",Wt),customElements.get("dt-stack")||customElements.define("dt-stack",Ut),customElements.get("dt-stat")||customElements.define("dt-stat",Gt),customElements.get("dt-badge")||customElements.define("dt-badge",Qt),customElements.get("dt-button")||customElements.define("dt-button",ee),customElements.get("dt-divider")||customElements.define("dt-divider",ne),customElements.get("dt-list-view")||customElements.define("dt-list-view",pe),customElements.get("dt-table-view")||customElements.define("dt-table-view",ce),customElements.get("dt-column")||customElements.define("dt-column",ut),customElements.get("dt-chart")||customElements.define("dt-chart",ye),customElements.get("dt-markdown")||customElements.define("dt-markdown",ze),customElements.get("dt-markdown-editor")||customElements.define("dt-markdown-editor",Te);function Le(t){const e=t.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?([\s\S]*)$/);return e?e[1]:t}var He=ft(function({note:e,loading:r,onSave:i},n){const s=H(null),[a,o]=I("idle"),d=H(null),l=H(i);return l.current=i,W(()=>{if(s.current&&e){const g=Le(e.content);s.current.value=g}},[e?.id]),W(()=>{const g=s.current;if(!g)return;const _=b=>{const w=b.detail;w&&(d.current&&clearTimeout(d.current),o("saving"),d.current=setTimeout(()=>{l.current(w.value),o("saved")},500))};return g.addEventListener("dt-change",_),()=>g.removeEventListener("dt-change",_)},[]),W(()=>()=>{d.current&&clearTimeout(d.current)},[]),_t(n,()=>({getMarkdown(){return s.current?.value??null},setMarkdown(g){s.current&&(s.current.value=g)},getCursorLine(){return 1},getSelectedText(){return""}}),[]),e?T("div",{className:v.editorPanel,children:[T("div",{className:v.editorHeader,children:[T("div",{children:[u("div",{className:v.editorTitle,children:e.title}),e.tags.length>0&&u("div",{className:v.editorTags,children:e.tags.map(g=>u("span",{className:v.editorTag,children:g},g))})]}),u("span",{className:a==="saving"?v.saveStatusSaving:v.saveStatus,children:a==="saving"?"Saving...":a==="saved"?"Saved":""})]}),u("div",{className:v.editorBody,children:u("dt-markdown-editor",{ref:s,placeholder:"Start writing...",style:{height:"100%"}})})]}):u("div",{className:v.editorPanel,children:u("div",{className:v.editorPlaceholder,children:r?"Loading...":"Select a note or create a new one"})})});import{ActionsProvider as Ie,Action as R,useCommand as J}from"@desktalk/sdk";var Re=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;function Fe(t){const e=t.match(Re);if(!e){const d=t.match(/^#\s+(.+)$/m);return{title:d?d[1].trim():"Untitled",tags:[],created:null,body:t}}const r=e[1],i=e[2];let n="Untitled",s=[],a=null,o=!1;for(const d of r.split(`
1681
1681
  `)){const l=d.trim();if(l.startsWith("title:"))n=l.slice(6).trim().replace(/^["']|["']$/g,""),o=!1;else if(l.startsWith("created:"))a=l.slice(8).trim(),o=!1;else if(l.startsWith("tags:")){o=!0;const g=l.slice(5).trim();g.startsWith("[")&&g.endsWith("]")&&(s=g.slice(1,-1).split(",").map(_=>_.trim().replace(/^["']|["']$/g,"")).filter(Boolean),o=!1)}else o&&l.startsWith("- ")?s.push(l.slice(2).trim().replace(/^["']|["']$/g,"")):o=!1}return{title:n,tags:s,created:a,body:i}}function $e(t,e,r,i){const n=["---",`title: "${t.replace(/"/g,'\\"')}"`];if(e.length>0){n.push("tags:");for(const s of e)n.push(` - ${s}`)}return n.push(`created: ${r}`,"---","",i),n.join(`
1682
1682
  `)}function De(t,e,r,i,n){const a=t.substring(0,n).split(`
1683
1683
  `).length,o=r.split(`
@@ -1685,7 +1685,7 @@ ${r}`}var ze=class extends HTMLElement{_body;_caret;_contentOverride=null;_runti
1685
1685
  `),l=Math.max(0,a-4),g=t.split(`
1686
1686
  `),_=e.split(`
1687
1687
  `),b=[];b.push(`@@ -${a},${o.length} +${a},${d.length} @@`);for(let m=l;m<a-1;m++)b.push(` ${g[m]}`);for(const m of o)b.push(`-${m}`);for(const m of d)b.push(`+${m}`);const w=a-1+o.length,C=Math.min(_.length,w+3);for(let m=w;m<C;m++)_[m]!==void 0&&b.push(` ${_[m]}`);return{diff:b.join(`
1688
- `),firstChangedLine:a}}function Pe({children:t,selectedNoteId:e,selectedNote:r,notes:i,editorRef:n,onNoteCreated:s,onNoteDeleted:a,onSearch:o,onNoteUpdated:d,onSelectNote:l,onRefresh:g}){const _=J("notes.create"),b=J("notes.delete"),w=J("notes.search"),C=J("notes.update"),m=x(async f=>{const p=await _({title:f?.title||void 0,content:f?.content||void 0,tags:f?.tags||void 0,path:f?.path||void 0});return s(p),p},[_,s]),M=x(async()=>{e&&(await b({id:e}),a(e))},[b,e,a]),F=x(async f=>{const p=f?.query||"";return o(p),await w({query:p})},[w,o]),E=x(()=>{if(!r)return null;const f=n.current;if(!f)return null;const p=f.getMarkdown();return p===null?null:$e(r.title,r.tags,r.createdAt,p)},[r,n]),$=x(async()=>({notes:i.slice(0,20).map(p=>({id:p.id,title:p.title,updatedAt:p.updatedAt,selected:p.id===e}))}),[i,e]),A=x(async f=>{const p=f?.id;return p?i.find(N=>N.id===p)?(await l(p),{success:!0}):{success:!1,error:`Note not found: ${p}`}:{success:!1,error:"id parameter is required"}},[i,l]),U=x(async()=>{if(!e||!r)return{error:"No note is currently open"};const f=n.current;if(!f)return{error:"Editor is not ready"};const p=E();return p===null?{error:"Editor is not ready"}:{id:r.id,title:r.title,content:p,cursorLine:f.getCursorLine(),selectedText:f.getSelectedText()}},[e,r,n,E]),V=x(async f=>{if(!e||!r)return{success:!1,error:"No note is currently open"};const p=n.current;if(!p)return{success:!1,error:"Editor is not ready"};const y=f?.old_text,N=f?.new_text;if(y===void 0||N===void 0)return{success:!1,error:"Both old_text and new_text are required"};const S=E();if(S===null)return{success:!1,error:"Editor is not ready"};let D,O;if(y==="")D=N+S,O=0;else{const z=S.indexOf(y);if(z===-1)return{success:!1,error:"Text not found in note"};const X=S.indexOf(y,z+1);if(X!==-1){let it=2,nt=X+1;for(;;){const st=S.indexOf(y,nt);if(st===-1)break;it++,nt=st+1}return{success:!1,error:`Text appears ${it} times; provide more surrounding context to make it unique`}}D=S.substring(0,z)+N+S.substring(z+y.length),O=z}const c=Fe(D);p.setMarkdown(c.body);const k=c.tags.length!==r.tags.length||c.tags.some((z,X)=>z!==r.tags[X]),W=c.title!==r.title;if(k||W){const z=await C({id:e,tags:c.tags,content:c.body});d(z)}const{diff:Y,firstChangedLine:vt}=De(S,D,y,N,O);return{success:!0,diff:Y,firstChangedLine:vt}},[e,r,n,E,C,d]);return T(Ie,{children:[u(R,{name:"Create Note",description:"Create a new note with optional title, content, and path",params:{title:{type:"string",description:"Note title",required:!1},content:{type:"string",description:"Note content in Markdown",required:!1},tags:{type:"string",description:"Comma-separated tags",required:!1},path:{type:"string",description:'Relative path for the note (e.g. "work/meeting-notes"). Becomes the note ID. Auto-generated if omitted.',required:!1}},handler:m}),u(R,{name:"Delete Note",description:"Delete the currently selected note",handler:M}),u(R,{name:"Search Notes",description:"Search notes by keyword",params:{query:{type:"string",description:"Search query",required:!0}},handler:F}),u(R,{name:"List Notes",description:"Return the 20 most recent notes with selection status",handler:$}),u(R,{name:"Select Note",description:"Select a note by ID and open it in the editor",params:{id:{type:"string",description:"Note ID (relative path without .md)",required:!0}},handler:A}),u(R,{name:"Get Editing Context",description:"Return the current editor state for the selected note including content, cursor position, and selected text",handler:U}),u(R,{name:"Edit Note",description:"Apply a text replacement to the current note content including front matter. Use old_text to find exact text and new_text to replace it. To edit tags or title, modify the YAML front matter directly.",params:{old_text:{type:"string",description:"Exact text to find in the note content (must appear exactly once). Searches the full content including YAML front matter. Use empty string to insert at beginning.",required:!0},new_text:{type:"string",description:"Replacement text",required:!0}},handler:V}),t]})}var Ve=720;function Oe(){const[t,e]=I([]),[r,i]=I(null),[n,s]=I(null),[a,o]=I(""),[d,l]=I(!1),[g,_]=I(!1),b=H(null),w=H(null),C=B("notes.list"),m=B("notes.get"),M=B("notes.update"),F=B("notes.search"),E=B("notes.create"),$=x(async()=>{try{let c;a?c=await F({query:a}):c=await C(),e(c)}catch(c){console.error("Failed to fetch notes:",c)}},[C,F,a]),A=x(()=>{$()},[$]);q(()=>{A()},[A]),q(()=>{if(!w.current)return;const c=W=>{_(W<=Ve)};c(w.current.clientWidth);const k=new ResizeObserver(W=>{const Y=W[0];Y&&c(Y.contentRect.width)});return k.observe(w.current),()=>k.disconnect()},[]);const U=x(async c=>{i(c),l(!0);try{const k=await m({id:c});s(k)}catch(k){console.error("Failed to load note:",k),s(null)}finally{l(!1)}},[m]),V=H(null),f=x(c=>{o(c),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{},300)},[]),p=x(async c=>{if(!(!r||!n))try{const k=await M({id:r,content:c});s(k),$()}catch(k){console.error("Failed to save note:",k)}},[r,n,M,$]),y=x(c=>{A(),i(c.id),s(c)},[A]),N=x(c=>{r===c&&(i(null),s(null)),A()},[r,A]),S=x(c=>{r===c.id&&s(c),A()},[r,A]),D=x(c=>{o(c)},[]),O=x(async()=>{try{const c=await E({});y(c)}catch(c){console.error("Failed to create note:",c)}},[E,y]);return u(Pe,{selectedNoteId:r,selectedNote:n,notes:t,editorRef:b,onNoteCreated:y,onNoteDeleted:N,onSearch:D,onNoteUpdated:S,onSelectNote:U,onRefresh:A,children:T("div",{ref:w,className:`${v.root}${g?` ${v.rootCompact}`:""}`,children:[u(Ct,{notes:t,selectedId:r,onSelect:U,onCreate:O,searchQuery:a,onSearchChange:f}),u(He,{ref:b,note:n,loading:d,onSave:p})]})})}function We(t){const e=xt(t.root);return e.render(u(yt,{windowId:t.windowId,children:u(wt,{miniAppId:t.miniAppId,children:u(Oe,{})})})),{deactivate(){e.unmount()}}}export{We as activate};
1688
+ `),firstChangedLine:a}}function Pe({children:t,selectedNoteId:e,selectedNote:r,notes:i,editorRef:n,onNoteCreated:s,onNoteDeleted:a,onSearch:o,onNoteUpdated:d,onSelectNote:l,onRefresh:g}){const _=J("notes.create"),b=J("notes.delete"),w=J("notes.search"),C=J("notes.update"),m=x(async f=>{const p=await _({title:f?.title||void 0,content:f?.content||void 0,tags:f?.tags||void 0,path:f?.path||void 0});return s(p),p},[_,s]),M=x(async()=>{e&&(await b({id:e}),a(e))},[b,e,a]),F=x(async f=>{const p=f?.query||"";return o(p),await w({query:p})},[w,o]),E=x(()=>{if(!r)return null;const f=n.current;if(!f)return null;const p=f.getMarkdown();return p===null?null:$e(r.title,r.tags,r.createdAt,p)},[r,n]),$=x(async()=>({notes:i.slice(0,20).map(p=>({id:p.id,title:p.title,updatedAt:p.updatedAt,selected:p.id===e}))}),[i,e]),A=x(async f=>{const p=f?.id;return p?i.find(N=>N.id===p)?(await l(p),{success:!0}):{success:!1,error:`Note not found: ${p}`}:{success:!1,error:"id parameter is required"}},[i,l]),U=x(async()=>{if(!e||!r)return{error:"No note is currently open"};const f=n.current;if(!f)return{error:"Editor is not ready"};const p=E();return p===null?{error:"Editor is not ready"}:{id:r.id,title:r.title,content:p,cursorLine:f.getCursorLine(),selectedText:f.getSelectedText()}},[e,r,n,E]),V=x(async f=>{if(!e||!r)return{success:!1,error:"No note is currently open"};const p=n.current;if(!p)return{success:!1,error:"Editor is not ready"};const y=f?.old_text,N=f?.new_text;if(y===void 0||N===void 0)return{success:!1,error:"Both old_text and new_text are required"};const S=E();if(S===null)return{success:!1,error:"Editor is not ready"};let D,O;if(y==="")D=N+S,O=0;else{const z=S.indexOf(y);if(z===-1)return{success:!1,error:"Text not found in note"};const X=S.indexOf(y,z+1);if(X!==-1){let it=2,nt=X+1;for(;;){const st=S.indexOf(y,nt);if(st===-1)break;it++,nt=st+1}return{success:!1,error:`Text appears ${it} times; provide more surrounding context to make it unique`}}D=S.substring(0,z)+N+S.substring(z+y.length),O=z}const c=Fe(D);p.setMarkdown(c.body);const k=c.tags.length!==r.tags.length||c.tags.some((z,X)=>z!==r.tags[X]),q=c.title!==r.title;if(k||q){const z=await C({id:e,tags:c.tags,content:c.body});d(z)}const{diff:Y,firstChangedLine:vt}=De(S,D,y,N,O);return{success:!0,diff:Y,firstChangedLine:vt}},[e,r,n,E,C,d]);return T(Ie,{children:[u(R,{name:"Create Note",description:"Create a new note with optional title, content, and path",params:{title:{type:"string",description:"Note title",required:!1},content:{type:"string",description:"Note content in Markdown",required:!1},tags:{type:"string",description:"Comma-separated tags",required:!1},path:{type:"string",description:'Relative path for the note (e.g. "work/meeting-notes"). Becomes the note ID. Auto-generated if omitted.',required:!1}},handler:m}),u(R,{name:"Delete Note",description:"Delete the currently selected note",handler:M}),u(R,{name:"Search Notes",description:"Search notes by keyword",params:{query:{type:"string",description:"Search query",required:!0}},handler:F}),u(R,{name:"List Notes",description:"Return the 20 most recent notes with selection status",handler:$}),u(R,{name:"Select Note",description:"Select a note by ID and open it in the editor",params:{id:{type:"string",description:"Note ID (relative path without .md)",required:!0}},handler:A}),u(R,{name:"Get Editing Context",description:"Return the current editor state for the selected note including content, cursor position, and selected text",handler:U}),u(R,{name:"Edit Note",description:"Apply a text replacement to the current note content including front matter. Use old_text to find exact text and new_text to replace it. To edit tags or title, modify the YAML front matter directly.",params:{old_text:{type:"string",description:"Exact text to find in the note content (must appear exactly once). Searches the full content including YAML front matter. Use empty string to insert at beginning.",required:!0},new_text:{type:"string",description:"Replacement text",required:!0}},handler:V}),t]})}var Ve=720;function Oe(){const[t,e]=I([]),[r,i]=I(null),[n,s]=I(null),[a,o]=I(""),[d,l]=I(!1),[g,_]=I(!1),b=H(null),w=H(null),C=B("notes.list"),m=B("notes.get"),M=B("notes.update"),F=B("notes.search"),E=B("notes.create"),$=x(async()=>{try{let c;a?c=await F({query:a}):c=await C(),e(c)}catch(c){console.error("Failed to fetch notes:",c)}},[C,F,a]),A=x(()=>{$()},[$]);W(()=>{A()},[A]),W(()=>{if(!w.current)return;const c=q=>{_(q<=Ve)};c(w.current.clientWidth);const k=new ResizeObserver(q=>{const Y=q[0];Y&&c(Y.contentRect.width)});return k.observe(w.current),()=>k.disconnect()},[]);const U=x(async c=>{i(c),l(!0);try{const k=await m({id:c});s(k)}catch(k){console.error("Failed to load note:",k),s(null)}finally{l(!1)}},[m]),V=H(null),f=x(c=>{o(c),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{},300)},[]),p=x(async c=>{if(!(!r||!n))try{const k=await M({id:r,content:c});s(k),$()}catch(k){console.error("Failed to save note:",k)}},[r,n,M,$]),y=x(c=>{A(),i(c.id),s(c)},[A]),N=x(c=>{r===c&&(i(null),s(null)),A()},[r,A]),S=x(c=>{r===c.id&&s(c),A()},[r,A]),D=x(c=>{o(c)},[]),O=x(async()=>{try{const c=await E({});y(c)}catch(c){console.error("Failed to create note:",c)}},[E,y]);return u(Pe,{selectedNoteId:r,selectedNote:n,notes:t,editorRef:b,onNoteCreated:y,onNoteDeleted:N,onSearch:D,onNoteUpdated:S,onSelectNote:U,onRefresh:A,children:T("div",{ref:w,className:`${v.root}${g?` ${v.rootCompact}`:""}`,children:[u(Ct,{notes:t,selectedId:r,onSelect:U,onCreate:O,searchQuery:a,onSearchChange:f}),u(He,{ref:b,note:n,loading:d,onSave:p})]})})}function qe(t){const e=xt(t.root);return e.render(u(yt,{windowId:t.windowId,children:u(wt,{miniAppId:t.miniAppId,children:u(Oe,{})})})),{deactivate(){e.unmount()}}}export{qe as activate};
1689
1689
  (() => {
1690
1690
  if (typeof document === 'undefined') return;
1691
1691
  const styleId = "desktalk-style-desktalk-miniapp-note-emi3yz";