dsh-sticky 0.2.0 → 0.3.0
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.
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
- 浮条的包含块是对话框。对话框带 `position: relative`,浮条以 `position: absolute` 挂在它下面,因此不在滚动容器的子元素之列。
|
|
19
19
|
- 位置基准是正文的可视区,也就是滚动容器的 border box 与视口的交集:上方放得下就放上方;放不下就翻到选区下方,挂在选区底边之下;上下都放不下时取空间大的一侧,再把结果夹进可视区。
|
|
20
|
-
-
|
|
20
|
+
- 锚点取选区里第一个从可视区内开始的行,不用整段选区的并集矩形。并集矩形的中心离读者正在看的那一行很远,浮条会挂到已经滚出去的字旁边;行按起点算,起点在可视区里的第一行才是读者松手时看着的那一行。
|
|
21
21
|
- 水平中心取锚点与可视区交集的中点,不是锚点自身的中点。一条比可视区还宽的行若按自身中点居中,中心落在可视区外,夹取之后浮条被推到边缘。
|
|
22
22
|
- 鼠标拖选与键盘选区同等对待:按 Shift 加方向键、Shift+Home/End、Shift+PageUp/Down,松开 Shift 时弹出浮条。单独按 Shift 不算选区手势,不弹;`Ctrl/Cmd+A` 全选也不弹。
|
|
23
23
|
- 选区滚出可视区时浮条隐藏(`visibility: hidden`),选区状态留着。滚出可视区只说明那段字现在看不见,不等于用户说不要了。滚回可视区后浮条自己恢复,位置按新位置重算。
|
package/docs/editor.md
CHANGED
|
@@ -34,9 +34,10 @@
|
|
|
34
34
|
- 浮条升起后跟随新选区:换一段就跟着换到那段的旁边(上方或下方),选区空了就关掉。关掉之后要重新松开鼠标或松开 Shift 才会再弹。
|
|
35
35
|
- 消失:点浮条外面、按 `Esc`、浏览器选区消失,这三种才清掉选区,滚回可视区也不会自己冒出来。`Esc` 先关浮条;浮条隐藏着的时候不吃 `Esc`,`Esc` 直接关对话框。
|
|
36
36
|
- 选区里一个字都没有(只选中一张图片、只选中空白)时不弹。
|
|
37
|
+
- 表格里跨单元格选中时,选区在编辑器里是多段的(每格一段),浏览器却只能把它折成一段,落在拖选结束的那一格上。所以复制和引用读编辑器自己的选区,不读浏览器选区;只读这段多段选区覆盖的范围,最前到最后一格。浮条也读这段范围,并且和选中普通文字用同一条规则:贴第一个从可视区内开始的格子。表格往下滚过、起点那格已经在可视区上方时,浮条跟着下一个格子,不会贴在表格底部,也不会消失。只选中一格时选区只有一段,仍读浏览器选区。
|
|
37
38
|
- 便签墙的卡片上不弹:卡片是「一瞥」,预览已被硬裁,而且卡片本身是铺满整张的按钮,选区会和点击打架。
|
|
38
39
|
- 浮条用便签自己的纸色铺底,文字与两个动作按钮用它的标记色,不用宿主的品牌色或灰色标签色。
|
|
39
|
-
- 位置相对对话框计算,基准是正文的可视区,也就是滚动容器的 border box
|
|
40
|
+
- 位置相对对话框计算,基准是正文的可视区,也就是滚动容器的 border box 与视口的交集:上方放得下就放上方,放不下翻到选区下方,上下都放不下时取空间大的一侧并夹进可视区。多行选区时贴着第一个从可视区内开始的行,不用整段选区的并集矩形;拖到正文边缘自动滚动时,浏览器会报一个横跨整段的矩形,它起点在可视区上方,不算行,不会把浮条带到可视区外。正文滚动和可视区的尺寸变化都重算,同一帧内的多次触发合并成一次。选区还有一行看得见就留着浮条,整段都滚出去才隐藏,选区本身留着;滚回来时浮条自己恢复,位置按新位置重算。看得见的内容不论多高都算一行:贴进来的图、高代码块、整格表格都在内,只有起点在可视区上方的矩形才算滚出去。
|
|
40
41
|
|
|
41
42
|
「复制」把选区复制成 Markdown:粗体带 `**`,链接带目标,行内代码带反引号,选一段标题就带 `#`,选一段代码块就连围栏和代码语言一起带走。选区里的便签自有图片按[复制品](../GLOSSARY.md)的规则改写成绝对路径。三态反馈与工具栏的复制按钮一致。
|
|
42
43
|
|
package/lib/client.js
CHANGED
|
@@ -2571,29 +2571,29 @@ if(o.errorRaised)throw Error("Could not highlight with `Highlight.js`",{cause:o.
|
|
|
2571
2571
|
`,()=>``).trim()!==``}function QT(e){if(e.type.name===`hardBreak`)return`
|
|
2572
2572
|
`;if(e.type.name!==`image`)return``;let t=e.attrs.src;return typeof t==`string`?t:``}function $T(e,t,n){return e.state.doc.textBetween(t,n,`
|
|
2573
2573
|
`,QT).replace(XT,`
|
|
2574
|
-
`)}function eE(e){return e.state.getSnapshot().phase===`plain`?`selectionQuoteBlocked`:`selectionQuoteBusy`}function tE(e){let t=
|
|
2574
|
+
`)}function eE(e){return e.state.getSnapshot().phase===`plain`?`selectionQuoteBlocked`:`selectionQuoteBusy`}function tE(e,t,n){let r;for(let i of e){if(!t(i.startContainer)||!t(i.endContainer))continue;let e=n(i.startContainer,i.startOffset),a=n(i.endContainer,i.endOffset);r=r===void 0?{from:Math.min(e,a),to:Math.max(e,a)}:{from:Math.min(r.from,e,a),to:Math.max(r.to,e,a)}}if(r!==void 0&&r.from!==r.to)return r}function nE(e){let t=[e.getRangeAt(0)];for(let n=1;n<e.rangeCount;n+=1)t.push(e.getRangeAt(n));return t}function rE(e){let t=e.state.selection.ranges;if(t.length<2)return;let n;for(let e of t){let t=Math.min(e.$from.pos,e.$to.pos),r=Math.max(e.$from.pos,e.$to.pos);n=n===void 0?{from:t,to:r}:{from:Math.min(n.from,t),to:Math.max(n.to,r)}}return n===void 0||n.from===n.to?void 0:n}function iE(e){let t=e.view.dom,n=window.getSelection();if(n===null||n.rangeCount===0)return;let r=rE(e);return r===void 0?tE(nE(n),e=>t.contains(e),(t,n)=>e.view.posAtDOM(t,n)):r}function aE(e,t){let n=t.map(e=>e.$from.pos).sort((e,t)=>e-t),r=[];for(let t of n){let n=e.view.nodeDOM(t);if(!(n instanceof Element))continue;let i=n.closest(`td, th`);i!==null&&r.push(i.getBoundingClientRect())}return r}function oE(e,t){let n=e.flatMap(e=>Array.from(e.getClientRects()));return n.length===0?e[0].getBoundingClientRect():sE(n,t)}function sE(e,t){let n=t.top+t.height;return e.filter(e=>e.top>=t.top&&e.top<n).reduce((e,t)=>e===void 0||t.top<e.top?t:e,void 0)}function cE(e,t){return e.length===0?void 0:sE(e,t)}function lE(e){let t=Math.max(e.left,0),n=Math.max(e.top,0),r=Math.min(e.left+e.width,window.innerWidth),i=Math.min(e.top+e.height,window.innerHeight);return{top:n,left:t,width:Math.max(r-t,0),height:Math.max(i-n,0)}}function uE({editor:e,t,color:n,dialog:r,scroll:i,dismissRef:a,composer:o}){let[s,c]=(0,f.useState)(void 0),l=(0,f.useRef)(null),[u,d]=(0,f.useState)(void 0),[p,m]=(0,f.useState)(!1),{state:g,settle:_}=DT(),v=(0,f.useRef)(!1),y=(0,f.useRef)(void 0),b=()=>{let t=iE(e);c(t!==void 0&&ZT(e,t.from,t.to)?t:void 0)},x=()=>{let t=iE(e);c(n=>{if(n!==void 0&&t!==void 0)return ZT(e,t.from,t.to)?t:void 0})};(0,f.useEffect)(()=>{let e=e=>{e.key!==`Shift`&&e.shiftKey&&(v.current=!0)},t=()=>{v.current&&(v.current=!1,b())};return document.addEventListener(`mouseup`,b),document.addEventListener(`selectionchange`,x),document.addEventListener(`keydown`,e),document.addEventListener(`keyup`,t),()=>{document.removeEventListener(`mouseup`,b),document.removeEventListener(`selectionchange`,x),document.removeEventListener(`keydown`,e),document.removeEventListener(`keyup`,t)}}),(0,f.useEffect)(()=>{if(s===void 0)return;let e=e=>{let t=e.target;t instanceof Node&&l.current?.contains(t)===!0||c(void 0)};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[s]),(0,f.useEffect)(()=>(a.current=()=>s===void 0||!p?!1:(c(void 0),!0),()=>{a.current=null}),[a,s,p]);let S=()=>{let t=l.current,n=r.current,a=i.current;if(t===null||n===null||a===null)return;let o=lE(a.getBoundingClientRect()),s=window.getSelection();if(s===null||s.rangeCount===0)return;let c=rE(e)===void 0?oE(nE(s),o):cE(aE(e,e.state.selection.ranges),o)??oE(nE(s),o);if(c===void 0){m(!1);return}let u=KT({selection:c,dialog:n.getBoundingClientRect(),visible:o,bar:t.getBoundingClientRect(),gap:8});u===void 0?m(!1):(d(u),m(!0))};(0,f.useLayoutEffect)(S,[r,i,s,g]);let C=()=>{y.current===void 0&&(y.current=requestAnimationFrame(()=>{y.current=void 0,S()}))};(0,f.useEffect)(()=>{let e=i.current;if(e===null)return;e.addEventListener(`scroll`,C);let t=new ResizeObserver(C);return t.observe(e),()=>{e.removeEventListener(`scroll`,C),t.disconnect(),y.current!==void 0&&cancelAnimationFrame(y.current),y.current=void 0}},[r,i]);let w=async t=>{let n=await jT(JT(e,t.from,t.to));_(await(0,h.writeClipboard)(n))},T=async n=>{
|
|
2575
2575
|
/* v8 ignore next -- the control is disabled without a composer, so no press
|
|
2576
2576
|
reaches this guard; it protects the window between the press and a
|
|
2577
2577
|
Session change. */
|
|
2578
|
-
if(o===void 0)return;let r=await MT($T(e,n.from,n.to));o.insertQuote(r)?c(void 0):o.notify(`error`,t(eE(o)))};if(s===void 0)return null;let E=t(g===`idle`?`selectionCopy`:g===`copied`?`copied`:`copyFailed`),D={...u===void 0?{}:{top:`${String(u.top)}px`,left:`${String(u.left)}px`},...p?{}:{visibility:`hidden`}};return(0,f.createElement)(`div`,{ref:l,className:F.selectionBar,"data-color":n,role:`group`,"aria-label":t(`selectionActions`),"aria-hidden":p?void 0:`true`,style:D},(0,f.createElement)(`button`,{type:`button`,className:F.selectionAction,"data-state":g,"aria-label":E,onMouseDown:e=>{e.preventDefault()},onClick:()=>{w(s)}},(0,f.createElement)(ET[g],{size:14}),(0,f.createElement)(`span`,{className:F.selectionActionLabel},E)),(0,f.createElement)(`button`,{type:`button`,className:F.selectionAction,"aria-label":t(`selectionQuoteLabel`),disabled:o===void 0,onMouseDown:e=>{e.preventDefault()},onClick:()=>{T(s)}},(0,f.createElement)(Ue,{size:14}),(0,f.createElement)(`span`,{className:F.selectionActionLabel},t(`selectionQuote`))))}let
|
|
2579
|
-
`).filter(e=>e.trim()!==``).length<=1&&!
|
|
2578
|
+
if(o===void 0)return;let r=await MT($T(e,n.from,n.to));o.insertQuote(r)?c(void 0):o.notify(`error`,t(eE(o)))};if(s===void 0)return null;let E=t(g===`idle`?`selectionCopy`:g===`copied`?`copied`:`copyFailed`),D={...u===void 0?{}:{top:`${String(u.top)}px`,left:`${String(u.left)}px`},...p?{}:{visibility:`hidden`}};return(0,f.createElement)(`div`,{ref:l,className:F.selectionBar,"data-color":n,role:`group`,"aria-label":t(`selectionActions`),"aria-hidden":p?void 0:`true`,style:D},(0,f.createElement)(`button`,{type:`button`,className:F.selectionAction,"data-state":g,"aria-label":E,onMouseDown:e=>{e.preventDefault()},onClick:()=>{w(s)}},(0,f.createElement)(ET[g],{size:14}),(0,f.createElement)(`span`,{className:F.selectionActionLabel},E)),(0,f.createElement)(`button`,{type:`button`,className:F.selectionAction,"aria-label":t(`selectionQuoteLabel`),disabled:o===void 0,onMouseDown:e=>{e.preventDefault()},onClick:()=>{T(s)}},(0,f.createElement)(Ue,{size:14}),(0,f.createElement)(`span`,{className:F.selectionActionLabel},t(`selectionQuote`))))}let dE=`dsh-sticky-dialog-heading`,fE=`dsh-sticky-confirm-heading`;function pE(e){return`color${e.charAt(0).toUpperCase()}${e.slice(1)}`}function mE(e){let t=Math.floor(e()*$g.length);return $g[Math.min(Math.max(t,0),$g.length-1)]??$g[0]}let hE=/* @__PURE__ */ new Map;function gE(e){let t=hE.get(e);return t===void 0&&(t=[tS.configure({heading:{levels:[1,2,3]},link:!1,underline:{},codeBlock:!1}),dS.configure({lowlight:bT}),tb.configure({openOnClick:!1,autolink:!0,protocols:[`http`,`https`,`mailto`],HTMLAttributes:{rel:`noreferrer noopener`,target:`_blank`}}),qx.configure({placeholder:e}),rS.configure({inline:!0,allowBase64:!1}).extend({addOptions(){return{...this.parent?.()??{},missingLabel:e}},addNodeView(){return({node:e,editor:t,getPos:n})=>new CT(e,t,e=>{let r=n();r!==void 0&&t.chain().setNodeSelection(r).updateAttributes(`image`,e).run()})}}),kw.configure({table:{resizable:!1}}),sx,ox.configure({nested:!0}),Xg.configure({indentation:{style:`space`,size:2}})],hE.set(e,t)),t}function _E(e){return/^(?:#{1,6}\s|>\s?|[-*+]\s|\d+[.)]\s|```|~~~)/.test(e)||/(?:\*\*|__|~~).+(?:\*\*|__|~~)/.test(e)||/`[^`]+`/.test(e)||/!?\[[^\]]*\]\([^)]+\)/.test(e)}function vE(e){return e.type===``||e.type.startsWith(`image/`)}function yE(e){let t=[];for(let n of e.items){if(n.kind!==`file`)continue;let e=n.getAsFile();e!==null&&t.push(e)}return t}async function bE(e){let t=new Uint8Array(await e.arrayBuffer()),n=32768,r=``;for(let e=0;e<t.length;e+=n)r+=String.fromCharCode(...t.subarray(e,e+n));return btoa(r)}let xE=0;function SE(e,t){let n;return e.state.doc.descendants((e,r)=>n===void 0?e.type.name===`image`&&e.attrs.alt===t?(n=r,!1):!0:!1),n}async function CE(e,t,n,r){let i=n.type===``?`image/png`:n.type;if(!i_(i)){e.chain().focus().insertContent({type:`text`,text:`${r(`imageUploadFailed`)}: ${i}`}).run();return}if(n.size>5242880){e.chain().focus().insertContent({type:`text`,text:`${r(`imageTooLarge`)} (5 MB)`}).run();return}xE+=1;let a=`paste-${String(xE)}`;e.chain().focus().insertContent({type:`image`,attrs:{src:``,alt:a}}).run();try{let r=await ut(t,i,await bE(n)),o=SE(e,a);if(o===void 0)return;e.chain().focus().setNodeSelection(o).setImage({src:r,alt:``}).run()}catch(t){let n=SE(e,a);if(n===void 0)return;let i=t instanceof Error?t.message:String(t);e.chain().focus().setNodeSelection(n).insertContent({type:`text`,text:`${r(`imageUploadFailed`)}: ${i}`}).run()}}function wE(e,t,n,r){return(i,a)=>{let o=a.clipboardData;if(o==null)return!1;let s=yE(o).filter(vE);if(s.length>0){a.preventDefault();let e=r();if(e===null)return!0;for(let r of s)CE(e,t,r,n);return!0}return TE(i,o.getData(`text/plain`),e,a)}}function TE(e,t,n,r){if(t.trim()===``||t.split(`
|
|
2579
|
+
`).filter(e=>e.trim()!==``).length<=1&&!_E(t.trim()))return!1;let i;try{i=T_(t,n)}catch{
|
|
2580
2580
|
/* v8 ignore next -- the manager's parser accepts every text input the
|
|
2581
2581
|
clipboard probe produced; the catch keeps a future grammar change from
|
|
2582
2582
|
taking the editor down instead of inserting literal text. */
|
|
2583
|
-
return!1}r.preventDefault();let a=Kt.fromJSON(e.state.schema,i);return e.dispatch(e.state.tr.replaceWith(e.state.selection.from,e.state.selection.to,a.content)),!0}function
|
|
2583
|
+
return!1}r.preventDefault();let a=Kt.fromJSON(e.state.schema,i);return e.dispatch(e.state.tr.replaceWith(e.state.selection.from,e.state.selection.to,a.content)),!0}function EE({note:e,mode:t,noteId:n,t:r,opener:i,composer:a,random:o=Math.random,onCancel:s,onSave:c}){let l=t===`view`,[u,d]=(0,f.useState)(e?.title??``),[p,m]=(0,f.useState)(()=>e?.color??mE(o)),[h,g]=(0,f.useState)(!1),[_,v]=(0,f.useState)(``),[y,b]=(0,f.useState)(!1),x=(0,f.useRef)(null),S=(0,f.useRef)(null),C=(0,f.useRef)(null),[w,T]=(0,f.useState)(!1),E=(0,f.useRef)(null),D=(0,f.useRef)(null),ee=(0,f.useRef)(null),O=(0,f.useMemo)(()=>gE(r(`bodyPlaceholder`)),[r]),k=(0,f.useRef)(null),te=(0,f.useMemo)(()=>wE(O,n,r,()=>k.current),[O,n,r]),A=qv({extensions:O,content:wT(T_(e?.markdown??``,O),e?.imageWidths??{}),immediatelyRender:!1,editable:!l,editorProps:{attributes:{class:`dsh-sticky-prose`,"aria-label":r(`bodyPlaceholder`)},handlePaste:te},...l?{}:{onUpdate:()=>{b(!0)}}});(0,f.useEffect)(()=>(k.current=A,()=>{k.current=null}),[A]),(0,f.useLayoutEffect)(()=>{let e=document.activeElement;return()=>{let t=i instanceof HTMLElement&&i.isConnected?i:e;t instanceof HTMLElement&&t.isConnected&&t.focus()}},[]),(0,f.useLayoutEffect)(()=>{l?ee.current?.focus():t===`create`?E.current?.focus():A?.commands.focus(`end`)},[A,t,l]);let j=(0,f.useCallback)(()=>{l?s():y||u.trim()!==(e?.title??``).trim()?T(!0):s()},[y,e,s,l,u]);(0,f.useLayoutEffect)(()=>{w&&D.current?.focus()},[w]),(0,f.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.isComposing||e.keyCode!==229&&(e.stopPropagation(),C.current?.()!==!0&&(w?T(!1):j())))};return document.addEventListener(`keydown`,e,!0),()=>{document.removeEventListener(`keydown`,e,!0)}},[w,j]);let M=async()=>{
|
|
2584
2584
|
/* v8 ignore next -- the save button is disabled while `saving` and while
|
|
2585
2585
|
the editor is absent, so no click reaches this guard; it protects the
|
|
2586
2586
|
window between the click and the re-render. */
|
|
2587
2587
|
if(!(A===null||h)){g(!0),v(``);try{await c({...e?.id===void 0?{}:{id:e.id},title:u,markdown:A.getMarkdown(),color:p,imageWidths:TT(A.getJSON())})||(v(r(`saveFailed`)),g(!1))}catch(e){v(e instanceof Error?e.message:String(e)),g(!1)}}};return(0,f.createElement)(`div`,{className:F.scrim,onMouseDown:e=>{
|
|
2588
2588
|
/* v8 ignore next -- the dialog stops mousedown propagation, so only a
|
|
2589
2589
|
direct scrim press ever arrives here. */
|
|
2590
|
-
e.target===e.currentTarget&&j()}},(0,f.createElement)(`div`,{className:F.dialog,ref:x,role:`dialog`,"aria-modal":`true`,"aria-labelledby":
|
|
2590
|
+
e.target===e.currentTarget&&j()}},(0,f.createElement)(`div`,{className:F.dialog,ref:x,role:`dialog`,"aria-modal":`true`,"aria-labelledby":dE,onMouseDown:e=>{e.stopPropagation()},onKeyDown:e=>{e.key!==`Tab`||e.isComposing||OE(e,e.currentTarget)}},(0,f.createElement)(`h2`,{id:dE,className:F.visuallyHidden},r(t===`create`?`headingCreate`:t===`view`?`headingView`:`headingEdit`)),(0,f.createElement)(`div`,l?{className:F.dialogHead,"data-readonly":``}:{className:F.dialogHead},l?(0,f.createElement)(`h2`,null,u.trim()===``?r(`untitled`):u):(0,f.createElement)(`input`,{ref:E,className:F.titleInput,value:u,placeholder:r(`titlePlaceholder`),"aria-label":r(`titlePlaceholder`),onChange:e=>{d(e.target.value),b(!0)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),A?.commands.focus(`end`))}}),l?(0,f.createElement)(`span`,{className:F.badge},r(`archivedBadge`)):null,l?null:(0,f.createElement)(`div`,{className:F.swatches,role:`radiogroup`,"aria-label":r(`colorLabel`)},$g.map(e=>(0,f.createElement)(`button`,{key:e,type:`button`,className:F.swatch,"data-color":e,role:`radio`,"aria-checked":p===e,"aria-label":r(pE(e)),title:r(pE(e)),onClick:()=>{m(e),b(!0)}}))),l?null:(0,f.createElement)(`button`,{type:`button`,className:F.iconButton,"aria-label":r(`close`),title:r(`close`),onClick:j},(0,f.createElement)(je,{size:16}))),l||A===null?null:(0,f.createElement)(HT,{editor:A,t:r,noteTitle:u,readMarkdown:()=>A.getMarkdown()}),(0,f.createElement)(`div`,{className:F.editorScroll,ref:S},(0,f.createElement)(`div`,l?{className:F.editor,"data-readonly":``}:{className:F.editor},(0,f.createElement)(Bv,{editor:A}))),A===null?null:(0,f.createElement)(uE,{editor:A,t:r,color:p,dialog:x,scroll:S,dismissRef:C,composer:a}),l?(0,f.createElement)(`div`,{className:F.dialogFoot},(0,f.createElement)(`button`,{ref:ee,type:`button`,className:F.secondary,onClick:j},r(`close`))):(0,f.createElement)(`div`,{className:F.dialogFoot},_===``?null:(0,f.createElement)(`span`,{className:F.error,role:`alert`},_),(0,f.createElement)(`button`,{type:`button`,className:F.secondary,onClick:j,disabled:h},r(`cancel`)),(0,f.createElement)(`button`,{type:`button`,className:F.primary,onClick:()=>{M()},disabled:h||A===null},r(h?`saving`:`save`)))),w?(0,f.createElement)(DE,{t:r,onKeep:()=>{T(!1)},onDiscard:s,keepRef:D}):null)}function DE({t:e,onKeep:t,onDiscard:n,keepRef:r}){return(0,f.createElement)(`div`,{className:F.confirmScrim,onMouseDown:e=>{
|
|
2591
2591
|
/* v8 ignore next -- the card stops mousedown propagation, so only a
|
|
2592
2592
|
press on the scrim itself arrives here. */
|
|
2593
|
-
e.target===e.currentTarget&&t()}},(0,f.createElement)(`div`,{className:F.confirmDialog,role:`alertdialog`,"aria-modal":`true`,"aria-labelledby":
|
|
2593
|
+
e.target===e.currentTarget&&t()}},(0,f.createElement)(`div`,{className:F.confirmDialog,role:`alertdialog`,"aria-modal":`true`,"aria-labelledby":fE,onMouseDown:e=>{e.stopPropagation()},onKeyDown:e=>{e.key!==`Tab`||e.isComposing||OE(e,e.currentTarget)}},(0,f.createElement)(`h2`,{id:fE,className:F.confirmTitle},e(`dirtyTitle`)),(0,f.createElement)(`p`,{className:F.confirmBody},e(`dirtyBody`)),(0,f.createElement)(`div`,{className:F.confirmActions},(0,f.createElement)(`button`,{ref:r,type:`button`,className:F.secondary,onClick:t},e(`dirtyKeep`)),(0,f.createElement)(`button`,{type:`button`,className:F.danger,onClick:n},e(`dirtyConfirm`)))))}function OE(e,t){let n=t.querySelectorAll(`button:not([disabled]), [href], input, textarea, [tabindex]:not([tabindex="-1"]), .ProseMirror`),r=n[0],i=n[n.length-1];
|
|
2594
2594
|
/* v8 ignore next 3 -- the dialog always renders enabled controls (save and
|
|
2595
2595
|
close), so the collection is never empty on a Tab that reaches here. */
|
|
2596
|
-
if(r===void 0||i===void 0)return;let a=document.activeElement;e.shiftKey&&a===r?(e.preventDefault(),i.focus()):!e.shiftKey&&a===i&&(e.preventDefault(),r.focus())}let
|
|
2596
|
+
if(r===void 0||i===void 0)return;let a=document.activeElement;e.shiftKey&&a===r?(e.preventDefault(),i.focus()):!e.shiftKey&&a===i&&(e.preventDefault(),r.focus())}let kE=[`all`,`archived`];function AE(){return crypto.randomUUID()}function jE(e){return e?.draftId??AE()}function ME(e){
|
|
2597
2597
|
/* v8 ignore next -- the api layer wraps every transport and protocol failure
|
|
2598
2598
|
in an ApiError, so the fallback below only guards a future refactor. */
|
|
2599
|
-
let t=e instanceof P?e.code:``;return t===`sticky/network`?`errorNetwork`:t===`sticky/not-found`?`errorNotFound`:t===`sticky/bad-request`?`errorRequest`:`errorIo`}function
|
|
2599
|
+
let t=e instanceof P?e.code:``;return t===`sticky/network`?`errorNetwork`:t===`sticky/not-found`?`errorNotFound`:t===`sticky/bad-request`?`errorRequest`:`errorIo`}function NE({t:e,composer:t}){let[n,r]=(0,f.useState)([]),[i,a]=(0,f.useState)(`loading`),[o,s]=(0,f.useState)(``),[c,l]=(0,f.useState)(``),[u,d]=(0,f.useState)(`all`),[p,m]=(0,f.useState)(!1),[h,g]=(0,f.useState)(!1),_=(0,f.useRef)(`all`),v=(0,f.useRef)(null),y=(0,f.useRef)(null),[b,x]=(0,f.useState)(null),[S,C]=(0,f.useState)(``),w=(0,f.useRef)(!0),T=(0,f.useRef)(null),E=(0,f.useMemo)(()=>gE(e(`bodyPlaceholder`)),[e]);(0,f.useEffect)(()=>{c===``&&(_.current=u)},[u,c]),(0,f.useEffect)(()=>{p&&v.current?.focus()},[p]);let D=(0,f.useCallback)(()=>{y.current!==null&&(y.current.scrollTop=0)},[]),ee=(0,f.useCallback)(()=>{m(!1),g(!0),D()},[D]),O=(0,f.useCallback)(async e=>{a(`loading`);try{let t=await st(e);if(!w.current)return;r(t),a(`ready`),s(``)}catch(e){if(!w.current||e instanceof Error&&e.name===`AbortError`)return;s(ME(e)),a(`failed`)}},[]);(0,f.useEffect)(()=>{w.current=!0;let e=new AbortController;return O(e.signal),()=>{w.current=!1,e.abort()}},[O]);let k=(0,f.useCallback)(async(e,t)=>{try{let n=await e();return w.current&&(r(n),s(``),a(`ready`),C(t)),!0}catch(e){return w.current&&(s(ME(e)),C(``)),!1}},[]),te=(e,t)=>{x({note:e,mode:t,draftId:e===void 0?AE():e.id,opener:T.current})},A=()=>{te(void 0,`create`)},j=async t=>{let n=t.id===void 0,r=await k(async()=>n?(await ct(jE(b),t)).notes:(await lt(t)).notes,e(n?`statusCreated`:`statusSaved`));return r&&x(null),r},M=(t,n)=>{k(()=>pt(t.id,n),e(n?`statusArchived`:`statusUnarchived`))},ne=(t,n)=>{k(()=>mt(t.id,n),e(n?`statusPinned`:`statusUnpinned`))},re=t=>{k(()=>ht(t.id),e(`statusDeleted`))},ie=(0,f.useMemo)(()=>{let e=c.trim().toLowerCase();return n.filter(t=>(u===`archived`?!t.archived:t.archived)?!1:e===``||t.title.toLowerCase().includes(e)||t.markdown.toLowerCase().includes(e))},[u,n,c]),ae=n.filter(e=>!e.archived),oe=n.length-ae.length,se={all:`${e(`filterAll`)} ${String(ae.length)}`,archived:`${e(`filterArchived`)} ${String(oe)}`},ce=e=>{let t=e.target;T.current=t instanceof Element?t.closest(`button`):null};return(0,f.createElement)(`div`,{className:F.root,onMouseDownCapture:ce,onClickCapture:ce},(0,f.createElement)(gt),(0,f.createElement)(`div`,{className:F.shell},(0,f.createElement)(`div`,{className:F.scroll,ref:y},(0,f.createElement)(PE,{t:e,countsFor:se,filter:u,query:c,searching:p,swapped:h,input:v,onQuery:l,onFilter:e=>{d(e),D()},onEnterSearch:()=>{m(!0),g(!0)},onLeaveSearch:ee,onCreate:A}),(0,f.createElement)(`div`,{className:F.stack},(0,f.createElement)(`p`,{className:F.live,role:`status`,"aria-live":`polite`},S),o===``||b!==null?null:(0,f.createElement)(`div`,{className:`${F.state} ${F.stateFailure}`,role:`alert`},(0,f.createElement)(`span`,{className:F.stateTitle},e(`failure`)),(0,f.createElement)(`span`,{className:F.stateBody},e(o)),(0,f.createElement)(`button`,{type:`button`,className:F.secondary,onClick:()=>{O()}},e(`retry`))),i===`loading`&&n.length===0?(0,f.createElement)(FE,{t:e}):ie.length===0&&o===``?(0,f.createElement)(LE,{t:e,kind:c.trim()===``?u===`archived`?`archived`:`board`:`search`,onReset:()=>{let e=c.trim()===``?`all`:_.current;l(``),d(e),m(!1),D()}}):(0,f.createElement)(f.Fragment,null,(0,f.createElement)(`div`,{className:F.grid,"aria-busy":i===`loading`},ie.map(t=>(0,f.createElement)(V_,{key:t.id,note:t,extensions:E,t:e,onOpen:e=>{te(e,e.archived?`view`:`edit`)},onArchive:M,onPin:ne,onDelete:re}))),c.trim()===``?null:(0,f.createElement)(`p`,{className:F.searchSummary,role:`status`},IE(e,ie.length,c.trim(),u)))))),b===null?null:(0,f.createElement)(EE,{key:b.draftId,note:b.note,mode:b.mode,noteId:b.draftId,t:e,opener:b.opener,composer:t,onCancel:()=>{x(null)},onSave:j}))}function PE({t:e,countsFor:t,filter:n,query:r,searching:i,swapped:a,input:o,onQuery:s,onFilter:c,onEnterSearch:l,onLeaveSearch:u,onCreate:d}){return(0,f.createElement)(`header`,{className:F.head},(0,f.createElement)(`h1`,{className:F.title},e(`heading`)),(0,f.createElement)(`div`,{className:F.tools,"data-searching":i,"data-swapped":a},(0,f.createElement)(`button`,{type:`button`,className:F.searchToggle,"aria-label":e(`search`),title:e(`search`),"aria-expanded":i,onClick:l},(0,f.createElement)(Ae,{size:16})),(0,f.createElement)(`div`,{className:F.search},(0,f.createElement)(`span`,{className:F.searchGlyph},(0,f.createElement)(Ae,{size:15})),(0,f.createElement)(`input`,{className:F.searchInput,ref:o,type:`text`,role:`searchbox`,value:r,placeholder:e(`search`),"aria-label":e(`search`),onChange:e=>{s(e.target.value)},onKeyDown:e=>{e.key===`Escape`&&(i?u():(s(``),e.currentTarget.blur()))}}),r===``?null:(0,f.createElement)(`button`,{type:`button`,className:F.searchClear,"aria-label":e(`clearSearch`),title:e(`clearSearch`),onClick:()=>{s(``)}},(0,f.createElement)(je,{size:14}))),(0,f.createElement)(`button`,{type:`button`,className:F.searchCancel,onClick:u},e(`cancel`)),(0,f.createElement)(`div`,{className:F.segments,role:`group`,"aria-label":e(`filterLabel`)},kE.map(e=>(0,f.createElement)(`button`,{key:e,type:`button`,className:F.segment,"aria-pressed":n===e,onClick:()=>{c(e)}},t[e]))),(0,f.createElement)(`button`,{type:`button`,className:`${F.primary} ${F.create}`,"aria-label":e(`newNote`),title:e(`newNote`),onClick:d},(0,f.createElement)(`span`,{className:F.createIcon},(0,f.createElement)(ke,{size:15})),(0,f.createElement)(`span`,{className:F.createLabel},e(`newNote`)))))}function FE({t:e}){return(0,f.createElement)(`div`,{className:F.skeletonRow,role:`status`,"aria-busy":`true`,"aria-label":e(`loading`)},[0,1,2].map(e=>(0,f.createElement)(`div`,{key:e,className:F.skeleton})))}function IE(e,t,n,r){let i=e(`searchMatches`,{count:t,query:n});return r===`all`?i:e(`searchScope`,{filter:e(`filterArchived`),matches:i})}function LE({t:e,kind:t,onReset:n}){let r=t===`board`?{title:e(`emptyTitle`),body:e(`emptyBody`)}:t===`search`?{title:e(`emptyFiltered`),body:e(`emptyFilteredBody`)}:{title:e(`emptyArchived`),body:e(`emptyArchivedBody`)};return(0,f.createElement)(`div`,{className:F.state},t===`board`?(0,f.createElement)(`span`,{className:F.stateArt,"aria-hidden":`true`},(0,f.createElement)(`span`,{className:`${F.stateSheet} ${F.stateSheetBack}`}),(0,f.createElement)(`span`,{className:`${F.stateSheet} ${F.stateSheetMid}`}),(0,f.createElement)(`span`,{className:`${F.stateSheet} ${F.stateSheetFront}`},(0,f.createElement)(`span`,{className:F.stateMarker}),(0,f.createElement)(Te,{size:18}))):(0,f.createElement)(`span`,{className:F.stateGlyph},(0,f.createElement)(Te,{size:28})),(0,f.createElement)(`span`,{className:F.stateTitle},r.title),(0,f.createElement)(`span`,{className:F.stateBody},r.body),t===`board`?null:(0,f.createElement)(`button`,{type:`button`,className:F.secondary,onClick:n},e(`filterAll`)))}let RE=`sticky`,zE=`dsh-sticky`,BE=`sticky`,VE=[`slots`,`locale`,`sidebarRightTabs`,`sessions`,`conversation`];function HE(e){e.effect(()=>e.locale.register(RE,{zh:y,en:b}),`dsh-sticky: dictionaries`);let t=e.locale.bind(RE);e.effect(()=>e.sidebarRightTabs.register({id:zE,kind:BE,priority:`extension`,keepMounted:!0,title:()=>t(`panel`),guide:[{id:BE,order:40,title:()=>t(`panel`),icon:Te}]}),`dsh-sticky: tab type`),e.effect(()=>e.slots.inject(`sidebar.right.pane.tab`,()=>e.slots.register({name:`sidebar.right.pane.tab`,key:zE,locale:RE,inject:t=>{let n=e.sessions.scope(t);return n===void 0?{}:{composer:e.conversation.input.for(n)}}},NE)),`dsh-sticky: board body`)}return n.NS=RE,n.TAB_ID=zE,n.TAB_KIND=BE,n.apply=HE,n.inject=VE,t.exports}});
|