wendang-react 0.6.3 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/NOTICE.md +1 -1
  2. package/README.md +133 -1
  3. package/dist/bindings/yjs.js +1 -5
  4. package/dist/chunks/AnchoredPanel-C7jMoPze.js +1 -0
  5. package/dist/chunks/DocumentExportMenu-CUMsgq3w.js +2 -0
  6. package/dist/chunks/Dropdown-D98tXfe0.js +3 -0
  7. package/dist/chunks/MindMapCanvas-C46Q5JBU.js +163 -0
  8. package/dist/chunks/MindMapViewer-C9zxZIW8.js +13 -0
  9. package/dist/chunks/SpreadsheetViewer-CoQ4VIgj.js +23 -0
  10. package/dist/chunks/code-highlight-BmaqTe1m.js +1 -30
  11. package/dist/chunks/code-highlight-engine-BFDzDPzy.js +1 -40
  12. package/dist/chunks/comment-hint-BhUxKjKK.js +14 -0
  13. package/dist/chunks/composition-state-Bl-U1R_2.js +1 -40
  14. package/dist/chunks/extensions-BefQ1tDm.js +14 -0
  15. package/dist/chunks/fuzzy-match-DYQR-4w2.js +1 -89
  16. package/dist/chunks/hooks-C53Dp0pr.js +1 -35
  17. package/dist/chunks/i18n-B0kCsIjc.js +2 -0
  18. package/dist/chunks/index-COeA2QcQ.js +15 -0
  19. package/dist/chunks/katex-WjrodtTU.js +1 -71
  20. package/dist/chunks/locale-DWpIJ_9X.js +1 -0
  21. package/dist/chunks/mind-map-controller-Ce76mETT.js +1 -0
  22. package/dist/chunks/mind-map-delete-CVsxdXfs.js +1 -31
  23. package/dist/chunks/mind-map-input-CEWRz_t6.js +1 -43
  24. package/dist/chunks/mind-topic-text-BHXkxexr.js +30 -0
  25. package/dist/chunks/popover-placement-D3xVYdkt.js +1 -47
  26. package/dist/chunks/worksheet-engine-c84sdD4N.js +1 -0
  27. package/dist/chunks/worksheet-preview-DsDVWxIM.js +1 -129
  28. package/dist/document/viewer.js +30 -289
  29. package/dist/document.js +120 -3811
  30. package/dist/export/json.js +1 -5
  31. package/dist/export/markdown.js +1 -2
  32. package/dist/export/mindmap.js +1 -2
  33. package/dist/export/pdf.js +1 -6
  34. package/dist/export/word.js +1 -2
  35. package/dist/export.js +1 -2
  36. package/dist/i18n.js +1 -0
  37. package/dist/index.js +1 -8
  38. package/dist/locales/en-US.js +1 -0
  39. package/dist/locales/es-ES.js +1 -0
  40. package/dist/locales/ja-JP.js +1 -0
  41. package/dist/locales/ko-KR.js +1 -0
  42. package/dist/locales/zh-CN.js +1 -0
  43. package/dist/locales/zh-TW.js +1 -0
  44. package/dist/mindmap/viewer.js +1 -6
  45. package/dist/mindmap.js +3 -123
  46. package/dist/shared.js +1 -52
  47. package/dist/spreadsheet/viewer.js +1 -5
  48. package/dist/spreadsheet/xlsx.js +1 -299
  49. package/dist/spreadsheet.js +2 -120
  50. package/dist/styles/callout.css +1 -34
  51. package/dist/styles/code-block.css +1 -58
  52. package/dist/styles/content-style.css +1 -619
  53. package/dist/styles/content-tokens.css +1 -29
  54. package/dist/styles/editor-interaction.css +1 -621
  55. package/dist/styles/file-video.css +1 -12
  56. package/dist/styles/image-preview.css +1 -103
  57. package/dist/styles/mind-map-block.css +1 -14
  58. package/dist/styles/mind-map-canvas.css +1 -80
  59. package/dist/styles/mind-map-comments.css +1 -93
  60. package/dist/styles/mind-map-details.css +1 -7
  61. package/dist/styles/mind-map-preview.css +1 -7
  62. package/dist/styles/mind-map-topic.css +1 -112
  63. package/dist/styles/page-picker.css +1 -47
  64. package/dist/styles/renderer.css +1 -45
  65. package/dist/styles/spreadsheet-editor.css +1 -3
  66. package/dist/styles/tokens.css +1 -142
  67. package/dist/styles/video-dialog.css +1 -41
  68. package/dist/styles/video-embed.css +1 -35
  69. package/dist/styles.css +1 -2655
  70. package/dist/types/editor/BlockAffordance.d.ts +5 -2
  71. package/dist/types/editor/CalloutView.d.ts +2 -1
  72. package/dist/types/editor/ImagePreview.d.ts +1 -1
  73. package/dist/types/editor/PagePicker.d.ts +1 -1
  74. package/dist/types/editor/extensions.d.ts +4 -1
  75. package/dist/types/engine/editor/block-commands.d.ts +1 -1
  76. package/dist/types/engine/editor/block-menu-hover.d.ts +16 -0
  77. package/dist/types/engine/editor/extensions/locale.d.ts +3 -0
  78. package/dist/types/engine/editor/nodes/image-nodeview.d.ts +1 -1
  79. package/dist/types/engine/editor/video-block-controls.d.ts +13 -0
  80. package/dist/types/engine/host.d.ts +60 -2
  81. package/dist/types/engine/renderer/attachments.d.ts +3 -3
  82. package/dist/types/engine/shared/video-feedback.d.ts +1 -1
  83. package/dist/types/engine/worksheets/worksheet-engine.d.ts +1 -0
  84. package/dist/types/engine/worksheets/worksheet-xlsx.d.ts +6 -1
  85. package/dist/types/host-types.d.ts +2 -60
  86. package/dist/types/host.d.ts +8 -1
  87. package/dist/types/i18n.d.ts +3 -0
  88. package/dist/types/index.d.ts +2 -0
  89. package/dist/types/locales/en-US.d.ts +1 -0
  90. package/dist/types/locales/es-ES.d.ts +1 -0
  91. package/dist/types/locales/ja-JP.d.ts +1 -0
  92. package/dist/types/locales/ko-KR.d.ts +1 -0
  93. package/dist/types/locales/zh-CN.d.ts +1 -0
  94. package/dist/types/locales/zh-TW.d.ts +1 -0
  95. package/dist/types/renderer/media.d.ts +2 -1
  96. package/dist/types/spreadsheet/xlsx.d.ts +1 -1
  97. package/dist/types/wui/Dropdown.d.ts +2 -1
  98. package/dist/types/wui/index.d.ts +2 -1
  99. package/integrity.json +3140 -0
  100. package/package.json +15 -5
  101. package/verify-integrity.mjs +138 -0
  102. package/dist/chunks/AnchoredPanel-Cv4RURwF.js +0 -68
  103. package/dist/chunks/DocumentExportMenu-BrGipZ59.js +0 -75
  104. package/dist/chunks/MindMapCanvas-tkFBBs4g.js +0 -2090
  105. package/dist/chunks/MindMapViewer-DJrryb2Y.js +0 -180
  106. package/dist/chunks/SpreadsheetViewer-DxCxIUx_.js +0 -163
  107. package/dist/chunks/comment-hint-B9qcrqvn.js +0 -296
  108. package/dist/chunks/extensions-ByORRoRa.js +0 -4210
  109. package/dist/chunks/host-C-V688Rq.js +0 -197
  110. package/dist/chunks/index-DdfMnva8.js +0 -726
  111. package/dist/chunks/mind-map-controller-B6SxK3GZ.js +0 -479
  112. package/dist/chunks/mind-topic-text-DSyb95vL.js +0 -446
  113. package/dist/chunks/nodes-iKqTGr_N.js +0 -291
  114. package/dist/chunks/worksheet-engine-TJ54m0KC.js +0 -125
  115. package/third-party-notices/wendang-export@0.6.0-NOTICE.md.txt +0 -51
  116. package/third-party-notices/wendang-export@0.6.1-LICENSE.txt +0 -21
  117. package/third-party-notices/wendang-export@0.6.2-LICENSE.txt +0 -21
  118. package/third-party-notices/wendang-export@0.6.2-NOTICE.md.txt +0 -70
  119. /package/third-party-notices/{wendang-export@0.6.0-LICENSE.txt → wendang-export@0.6.4-LICENSE.txt} +0 -0
  120. /package/third-party-notices/{wendang-export@0.6.1-NOTICE.md.txt → wendang-export@0.6.4-NOTICE.md.txt} +0 -0
@@ -0,0 +1,15 @@
1
+ "use client";import{jsxs as e,jsx as t}from"react/jsx-runtime";import{c as a,a as l}from"./i18n-B0kCsIjc.js";import{createPortal as n}from"react-dom";import{createElement as r,useState as i,useRef as o,useLayoutEffect as d,useEffect as h,forwardRef as c,useId as s,useContext as p,createContext as u}from"react";const M={top:"bottom",bottom:"top",left:"right",right:"left"};function placePanel(e){const t=e.gap??6,a=e.margin??8,{trigger:l,panel:n,viewport:r}=e,i=function resolvePlacement(e){const t={bottom:{side:"bottom",align:"center"},top:{side:"top",align:"center"},left:{side:"left",align:"center"},right:{side:"right",align:"center"},bl:{side:"bottom",align:"start"},br:{side:"bottom",align:"end"},tl:{side:"top",align:"start"},tr:{side:"top",align:"end"}};return t[e??"bottom"]??t.bottom}(e.position),o=e.point?{left:e.point.x,top:e.point.y,width:0,height:0}:l,fits=e=>"bottom"===e?o.top+o.height+t+n.height<=r.height-a:"top"===e?o.top-t-n.height>=a:"right"===e?o.left+o.width+t+n.width<=r.width-a:o.left-t-n.width>=a;let d,h,c=i.side;if(!fits(c)){const e=M[c];c=fits(e)?e:"top"===c||"bottom"===c?o.top+o.height/2>r.height/2?"top":"bottom":o.left+o.width/2>r.width/2?"left":"right"}"bottom"===c||"top"===c?(d="start"===i.align?o.left:"end"===i.align?o.left+o.width-n.width:o.left+o.width/2-n.width/2,h="bottom"===c?o.top+o.height+t:o.top-t-n.height):(h="start"===i.align?o.top:"end"===i.align?o.top+o.height-n.height:o.top+o.height/2-n.height/2,d="right"===c?o.left+o.width+t:o.left-t-n.width);const s=Math.max(a,r.width-a-n.width),p=Math.max(a,r.height-a-n.height);d=Math.min(Math.max(d,a),s),h=Math.min(Math.max(h,a),p);const u="top"===c||"bottom"===c,m=u?o.left+o.width/2:o.top+o.height/2,v=u?d:h,f=u?n.width:n.height,g=Math.min(Math.max(m-v,12),Math.max(12,f-12));return{left:d,top:h,side:c,arrow:g,arrowShift:g-f/2}}const m={x:{els:[["path",{d:"M18 6 6 18"}],["path",{d:"m6 6 12 12"}]]},text:{els:[["path",{d:"M12 4v16"}],["path",{d:"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2"}],["path",{d:"M9 20h6"}]]},"text-color":{els:[["path",{d:"m5 20 7-16 7 16M8 14h8"}]]},ellipsis:{els:[5,12,19].map(e=>["circle",{cx:e,cy:12,r:1.6,fill:"currentColor",stroke:"none"}])},bold:{els:[["path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"}]]},italic:{els:[["line",{x1:19,x2:10,y1:4,y2:4}],["line",{x1:14,x2:5,y1:20,y2:20}],["line",{x1:15,x2:9,y1:4,y2:20}]]},underline:{els:[["path",{d:"M6 4v6a6 6 0 0 0 12 0V4"}],["line",{x1:4,x2:20,y1:20,y2:20}]]},strike:{els:[["path",{d:"M16 4H9a3 3 0 0 0-2.83 4"}],["path",{d:"M14 12a4 4 0 0 1 0 8H6"}],["line",{x1:4,x2:20,y1:12,y2:12}]]},"inline-code":{els:[["path",{d:"m18 16 4-4-4-4"}],["path",{d:"m6 8-4 4 4 4"}],["path",{d:"m14.5 4-5 16"}]]},"format-link":{els:[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"}]]},unlink:{els:[["path",{d:"M9 17H7A5 5 0 0 1 7 7"}],["path",{d:"M15 7h2a5 5 0 0 1 4 8"}],["line",{x1:8,x2:12,y1:12,y2:12}],["line",{x1:2,x2:22,y1:2,y2:22}]]},edit:{els:[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"}],["path",{d:"m15 5 4 4"}]]},"zoom-in":{els:[["circle",{cx:11,cy:11,r:8}],["line",{x1:21,x2:16.65,y1:21,y2:16.65}],["line",{x1:11,x2:11,y1:8,y2:14}],["line",{x1:8,x2:14,y1:11,y2:11}]]},h1:{els:[["path",{d:"M4 12h8"}],["path",{d:"M4 18V6"}],["path",{d:"M12 18V6"}],["path",{d:"m17 12 3-2v8"}]]},h2:{els:[["path",{d:"M4 12h8"}],["path",{d:"M4 18V6"}],["path",{d:"M12 18V6"}],["path",{d:"M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"}]]},h3:{els:[["path",{d:"M4 12h8"}],["path",{d:"M4 18V6"}],["path",{d:"M12 18V6"}],["path",{d:"M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2"}],["path",{d:"M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2"}]]},h4:{els:[["path",{d:"M12 18V6"}],["path",{d:"M17 10v3a1 1 0 0 0 1 1h3"}],["path",{d:"M21 10v8"}],["path",{d:"M4 12h8"}],["path",{d:"M4 18V6"}]]},h5:{els:[["path",{d:"M4 12h8"}],["path",{d:"M4 18V6"}],["path",{d:"M12 18V6"}],["path",{d:"M17 13v-3h4"}],["path",{d:"M17 17.7c.4.2.8.3 1.3.3 1.5 0 2.7-1.1 2.7-2.5S19.8 13 18.3 13H17"}]]},h6:{els:[["path",{d:"M4 12h8"}],["path",{d:"M4 18V6"}],["path",{d:"M12 18V6"}],["circle",{cx:19,cy:16,r:2}],["path",{d:"M20 10c-2 2-3 3.5-3 6"}]]},"bullet-list":{els:[["path",{d:"M3 5h.01"}],["path",{d:"M3 12h.01"}],["path",{d:"M3 19h.01"}],["path",{d:"M8 5h13"}],["path",{d:"M8 12h13"}],["path",{d:"M8 19h13"}]]},"ordered-list":{els:[["path",{d:"M11 5h10"}],["path",{d:"M11 12h10"}],["path",{d:"M11 19h10"}],["path",{d:"M4 4h1v5"}],["path",{d:"M4 9h2"}],["path",{d:"M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02"}]]},task:{els:[["path",{d:"M13 5h8"}],["path",{d:"M13 12h8"}],["path",{d:"M13 19h8"}],["path",{d:"m3 17 2 2 4-4"}],["rect",{x:3,y:4,width:6,height:6,rx:1}]]},quote:{els:[["path",{d:"M17 5H3"}],["path",{d:"M21 12H8"}],["path",{d:"M21 19H8"}],["path",{d:"M3 12v7"}]]},code:{els:[["path",{d:"m10 9-3 3 3 3"}],["path",{d:"m14 15 3-3-3-3"}],["rect",{x:3,y:3,width:18,height:18,rx:2}]]},link:{els:[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2"}],["line",{x1:8,x2:16,y1:12,y2:12}]]},image:{els:[["rect",{x:3,y:3,width:18,height:18,rx:2}],["circle",{cx:9,cy:9,r:2}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"}]]},file:{els:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}]]},table:{els:[["path",{d:"M12 3v18"}],["rect",{x:3,y:3,width:18,height:18,rx:2}],["path",{d:"M3 9h18"}],["path",{d:"M3 15h18"}]]},"table-header-row":{els:[["path",{d:"M3 5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v4H3z",fill:"currentColor",stroke:"none"}],["rect",{x:3,y:3,width:18,height:18,rx:2}],["path",{d:"M3 9h18"}],["path",{d:"M9 9v12"}],["path",{d:"M15 9v12"}]]},"table-header-column":{els:[["path",{d:"M5 3h4v18H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",fill:"currentColor",stroke:"none"}],["rect",{x:3,y:3,width:18,height:18,rx:2}],["path",{d:"M9 3v18"}]]},callout:{els:[["path",{d:"M14 14a2 2 0 0 0 2-2V8h-2"}],["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z"}],["path",{d:"M8 14a2 2 0 0 0 2-2V8H8"}]]},math:{els:[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2"}]]},divider:{els:[["path",{d:"m16 16-4 4-4-4"}],["path",{d:"M3 12h18"}],["path",{d:"m8 8 4-4 4 4"}]]},page:{els:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5"}],["path",{d:"M9 15h6"}],["path",{d:"M12 18v-6"}]]},handle:{els:[["circle",{cx:9,cy:5,r:1}],["circle",{cx:9,cy:12,r:1}],["circle",{cx:9,cy:19,r:1}],["circle",{cx:15,cy:5,r:1}],["circle",{cx:15,cy:12,r:1}],["circle",{cx:15,cy:19,r:1}]]},plus:{els:[["path",{d:"M5 12h14"}],["path",{d:"M12 5v14"}]]},"chevron-down":{els:[["path",{d:"m6 9 6 6 6-6"}]]},chevron:{els:[["path",{d:"m9 18 6-6-6-6"}]]},check:{els:[["path",{d:"M20 6 9 17l-5-5"}]]},comment:{els:[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z"}]]},cut:{els:[["circle",{cx:6,cy:6,r:3}],["path",{d:"M8.12 8.12 12 12"}],["path",{d:"M20 4 8.12 15.88"}],["circle",{cx:6,cy:18,r:3}],["path",{d:"M14.8 14.8 20 20"}]]},copy:{els:[["rect",{x:8,y:8,width:14,height:14,rx:2,ry:2}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"}]]},trash:{els:[["path",{d:"M10 11v6"}],["path",{d:"M14 11v6"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"}],["path",{d:"M3 6h18"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}]]},"copy-link":{els:[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2"}],["line",{x1:8,x2:16,y1:12,y2:12}]]},share:{els:[["circle",{cx:18,cy:5,r:3}],["circle",{cx:6,cy:12,r:3}],["circle",{cx:18,cy:19,r:3}],["line",{x1:8.59,x2:15.42,y1:13.51,y2:17.49}],["line",{x1:15.41,x2:8.59,y1:6.51,y2:10.49}]]},"add-below":{els:[["path",{d:"M4 6h16"}],["path",{d:"M4 11h16"}],["path",{d:"M12 14.5v7"}],["path",{d:"M8.5 18h7"}]]},indent:{els:[["path",{d:"M21 5H11"}],["path",{d:"M21 12H11"}],["path",{d:"M21 19H11"}],["path",{d:"m3 8 4 4-4 4"}]]},outdent:{els:[["path",{d:"M21 5H11"}],["path",{d:"M21 12H11"}],["path",{d:"M21 19H11"}],["path",{d:"m7 8-4 4 4 4"}]]},"align-left":{els:[["path",{d:"M21 5H3"}],["path",{d:"M15 12H3"}],["path",{d:"M17 19H3"}]]},"align-center":{els:[["path",{d:"M21 5H3"}],["path",{d:"M17 12H7"}],["path",{d:"M19 19H5"}]]},"align-right":{els:[["path",{d:"M21 5H3"}],["path",{d:"M21 12H9"}],["path",{d:"M21 19H7"}]]},palette:{els:[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z"}],["circle",{cx:13.5,cy:6.5,r:.5,fill:"currentColor"}],["circle",{cx:17.5,cy:10.5,r:.5,fill:"currentColor"}],["circle",{cx:6.5,cy:12.5,r:.5,fill:"currentColor"}],["circle",{cx:8.5,cy:7.5,r:.5,fill:"currentColor"}]]},marker:{els:[["path",{d:"m9 11-6 6v3h9l3-3"}],["path",{d:"m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4"}]]},"cell-fill":{els:[["path",{d:"M4 11 11 4l8 8-7 7a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8Z"}],["path",{d:"m8 3 4 4"}],["path",{d:"M5 11h13"}],["path",{d:"M21 14s2 2.2 2 3.5a2 2 0 0 1-4 0C19 16.2 21 14 21 14Z"}]]},"table-row-plus":{els:[["rect",{x:3,y:3,width:18,height:9,rx:2}],["path",{d:"M3 7.5h18"}],["path",{d:"M12 14.5v7"}],["path",{d:"M8.5 18h7"}]]},"table-col-plus":{els:[["rect",{x:3,y:3,width:9,height:18,rx:2}],["path",{d:"M7.5 3v18"}],["path",{d:"M18 8.5v7"}],["path",{d:"M14.5 12h7"}]]},merge:{els:[["rect",{x:3,y:3,width:18,height:18,rx:2}],["path",{d:"M8.5 9.5 11 12l-2.5 2.5"}],["path",{d:"M15.5 9.5 13 12l2.5 2.5"}]]},split:{els:[["rect",{x:3,y:3,width:18,height:18,rx:2}],["path",{d:"M12 3v18"}],["path",{d:"M7.5 9.5 5 12l2.5 2.5"}],["path",{d:"M16.5 9.5 19 12l-2.5 2.5"}]]},columns:{els:[["rect",{x:3,y:3,width:18,height:18,rx:2}],["path",{d:"M9 3v18"}],["path",{d:"M15 3v18"}]]},"mind-map":{els:[["rect",{x:16,y:16,width:6,height:6,rx:1}],["rect",{x:2,y:16,width:6,height:6,rx:1}],["rect",{x:9,y:2,width:6,height:6,rx:1}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3"}],["path",{d:"M12 12V8"}]]}};function WIcon({name:e,size:t=18,className:a,style:l}){const n=m[e];return n?r("svg",{className:["wr-icon",a].filter(Boolean).join(" "),width:t,height:t,viewBox:"0 0 24 24",fill:n.filled?"currentColor":"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:l},n.els.map((e,t)=>r(e[0],{key:t,...e[1]}))):null}const v=["a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(",");function trapTab(e,t){if("Tab"!==t.key)return!1;const a=function focusableWithin(e){return Array.from(e.querySelectorAll(v)).filter(e=>null!==e.offsetParent||e===document.activeElement)}(e);if(!a.length)return!0;const l=a[0],n=a[a.length-1],r=document.activeElement;return r&&e.contains(r)?t.shiftKey&&r===l?(n.focus(),!0):!t.shiftKey&&r===n&&(l.focus(),!0):((t.shiftKey?n:l).focus(),!0)}const f=/* @__PURE__ */new WeakMap;function lockScroll(){const e=document.body;let t=f.get(e);if(!t){t={count:0,overflow:e.style.overflow,padding:e.style.paddingRight},f.set(e,t);const a=window.innerWidth-document.documentElement.clientWidth,l=parseFloat(getComputedStyle(e).paddingRight)||0;e.style.overflow="hidden",a>0&&(e.style.paddingRight=`${l+a}px`)}t.count++;let a=!1;return{release:()=>{a||(a=!0,--t.count>0||(e.style.overflow=t.overflow,e.style.paddingRight=t.padding,f.delete(e)))}}}function buttonClasses(e,t,a,l,n){return["w-button",`w-button--${e}`,`w-button--${t}`,a?"w-button--narrow":"",l?"w-button--block":"",n?"is-loading":""].filter(Boolean).join(" ")}const g=c(function WButton2(l,n){a().text;const{children:r,variant:i,size:o="small",narrow:d=!1,block:h=!1,loading:c=!1,htmlType:s,icon:p,className:u="",disabled:M,...m}=l;/* @__PURE__ */
2
+ return e("button",{...m,ref:n,type:s??"button",disabled:M||c,"aria-busy":c||void 0,"aria-disabled":M||void 0,className:buttonClasses(i??"default",o,d,h,c)+(u?` ${u}`:""),children:[c?/* @__PURE__ */t("span",{className:"w-button__spinner","aria-hidden":"true",children:/* @__PURE__ */e("svg",{viewBox:"0 0 16 16",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[
3
+ /* @__PURE__ */t("circle",{cx:"8",cy:"8",r:"6",opacity:"0.25"}),
4
+ /* @__PURE__ */t("path",{d:"M14 8a6 6 0 0 0-6-6",strokeLinecap:"round"})]})}):p?/* @__PURE__ */t("span",{className:"w-button__icon",children:p}):null,r?/* @__PURE__ */t("span",{className:"w-button__label",children:r}):null]})});function WAlert({children:l,closable:n=!1,closeLabel:r,onClose:o,tone:d="info",className:h=""}){const c=a().text,[s,p]=i(!0);return s?/* @__PURE__ */e("div",{role:"status","aria-label":c("提示"),className:`w-alert w-alert--${d}${h?` ${h}`:""}`,children:[
5
+ /* @__PURE__ */t("span",{className:"w-alert__icon","aria-hidden":"true",children:"warning"===d?"⚠":"danger"===d?"❗":"success"===d?"✓":"ⓘ"}),
6
+ /* @__PURE__ */t("span",{className:"w-alert__body",children:l}),n&&/* @__PURE__ */t(g,{variant:"text",size:"mini","aria-label":r??c("关闭提示"),onClick:()=>{p(!1),null==o||o()},children:/* @__PURE__ */t(WIcon,{name:"x",size:14})})]}):null}const y=u(null);function LayerProvider({layer:e,children:l}){return a().text,/* @__PURE__ */t(y.Provider,{value:e,children:l})}function useLayer(e,t,a,l){const n=p(y),r=o({children:/* @__PURE__ */new Set,contains:()=>!1});return r.current.contains=a=>{var l,n;return!!(null==(l=e.current)?void 0:l.contains(a))||!!(null==(n=t.current)?void 0:n.contains(a))||[...r.current.children].some(e=>e.contains(a))},h(()=>{if(a)return null==n||n.children.add(r.current),()=>{null==n||n.children.delete(r.current)}},[a,n]),h(()=>{if(!a)return;const outside=e=>{e.target instanceof Node&&!r.current.contains(e.target)&&l()},escape=t=>{var a;"Escape"!==t.key||t.isComposing||229===t.keyCode||t.defaultPrevented||r.current.children.size||(t.preventDefault(),t.stopPropagation(),l(),null==(a=e.current)||a.focus())};return document.addEventListener("pointerdown",outside,!0),document.addEventListener("keydown",escape),()=>{document.removeEventListener("pointerdown",outside,!0),document.removeEventListener("keydown",escape)}},[a,l,e]),r.current}function WSelect({label:r,ariaLabel:c,value:s,onChange:p,options:u,disabled:M,size:m="small",searchable:v,width:f,className:g="",prefix:y}){const w=a().text,{portal:x}=l(),[b,k]=i(!1),[C,H]=i(""),[L,N]=i(0),[_,V]=i({left:-9999,top:-9999}),S=o(null),$=o(null),E=o(null),W=c??r,z=u.find(e=>String(e.value)===String(s)),A=function filterOptions(e,t){const a=t.trim().toLowerCase();return a?e.filter(e=>e.label.toLowerCase().includes(a)):[...e]}(u,v?C:""),P=v&&u.length>6;function choose(e){e.disabled||(k(!1),String(e.value)!==String(s)&&p(String(e.value)))}function keydown(e){var t;if(!e.nativeEvent.isComposing&&229!==e.keyCode){if("Escape"===e.key&&b)return e.preventDefault(),e.stopPropagation(),k(!1),void(null==(t=S.current)||t.focus());if(!b&&("Enter"===e.key||" "===e.key||"ArrowDown"===e.key))return e.preventDefault(),void k(!0);if(b)if("ArrowDown"===e.key||"ArrowUp"===e.key)e.preventDefault(),N(t=>function moveActive(e,t,a,l=()=>!1){if(t<=0)return-1;let n=e;for(let e=0;e<t;e+=1)if(n=(n+a+t)%t,!l(n))return n;return-1}(t,A.length,"ArrowDown"===e.key?1:-1,e=>{var t;return!!(null==(t=A[e])?void 0:t.disabled)}));else if("Enter"===e.key){e.preventDefault();const t=A[L];t&&choose(t)}}}return function useWuiPanel(e,t,a,l){useLayer(e,t,a,l)}(S,$,b,()=>k(!1)),d(()=>{if(!b||!x)return;const measure=()=>{var e,t;const a=null==(e=S.current)?void 0:e.getBoundingClientRect(),l=null==(t=$.current)?void 0:t.getBoundingClientRect();if(!a||!l)return;const n=placePanel({trigger:a,panel:l,position:"bl",gap:4,viewport:{width:innerWidth,height:innerHeight}});V({left:n.left,top:n.top})};measure();const e=new ResizeObserver(measure);return $.current&&e.observe($.current),window.addEventListener("resize",measure),window.addEventListener("scroll",measure,!0),()=>{e.disconnect(),window.removeEventListener("resize",measure),window.removeEventListener("scroll",measure,!0)}},[b,x]),h(()=>{b&&(H(""),N(Math.max(0,u.findIndex(e=>String(e.value)===String(s)))),queueMicrotask(()=>{var e;return null==(e=E.current)?void 0:e.focus()}))},[b]),/* @__PURE__ */e("div",{className:`w-select w-select--${m}${g?` ${g}`:""}`,style:f?{width:f}:void 0,children:[
7
+ /* @__PURE__ */e("button",{ref:S,type:"button",className:"w-select__trigger","aria-label":W,"aria-expanded":b,"aria-haspopup":"listbox",disabled:M,onClick:()=>k(!b),onKeyDown:keydown,children:[y&&/* @__PURE__ */t("span",{className:"w-select__prefix","aria-hidden":"true",children:y}),
8
+ /* @__PURE__ */t("span",{className:"w-select__label"+(z?"":" is-placeholder"),children:(null==z?void 0:z.label)??r??w("请选择")}),
9
+ /* @__PURE__ */t("svg",{className:"w-select__caret",viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:/* @__PURE__ */t("path",{d:"m6 9 6 6 6-6"})})]}),b&&x&&n(/* @__PURE__ */t("div",{ref:$,className:"w-popover w-select-popup",role:"listbox","aria-label":W,style:{left:_.left,top:_.top},children:/* @__PURE__ */e("div",{className:"w-select-panel",onKeyDown:keydown,children:[P&&/* @__PURE__ */t("input",{ref:E,className:"w-select-search",type:"text","aria-label":w("{0}搜索",{0:W??w("选项")}),placeholder:w("搜索"),value:C,onChange:e=>{H(e.target.value),N(0)},autoComplete:"off"}),
10
+ /* @__PURE__ */e("div",{className:"w-select-list",role:"listbox",children:[A.map((e,a)=>/* @__PURE__ */t("button",{type:"button",role:"option","aria-selected":String(e.value)===String(s),"aria-disabled":e.disabled||void 0,disabled:e.disabled,className:`w-select-option${a===L?" is-active":""}${String(e.value)===String(s)?" is-selected":""}`,onMouseEnter:()=>N(a),onClick:()=>choose(e),children:e.label},String(e.value))),!A.length&&/* @__PURE__ */t("div",{className:"w-select-empty",children:w("无匹配选项")})]})]})}),x)]})}function WDialog({title:r,children:i,onClose:d,fullscreen:c=!1,hideFooter:p=!1,footer:u,workspace:M=!1,className:m="",ariaLabel:v,escToClose:f=!0}){const g=a().text,{portal:y}=l(),w=s(),x=o(null),b=o({children:/* @__PURE__ */new Set,contains:()=>!1});b.current.contains=e=>{var t;return!!(null==(t=x.current)?void 0:t.contains(e))||[...b.current.children].some(t=>t.contains(e))};const k=o(d);k.current=d;const C=o(f);if(C.current=f,h(()=>{const e=document.activeElement,t=x.current;null==t||t.focus();const a=lockScroll(),listener=e=>{t&&t.contains(document.activeElement)&&("Escape"!==e.key||!C.current||b.current.children.size||e.isComposing||e.defaultPrevented||(e.preventDefault(),e.stopPropagation(),k.current()),trapTab(t,e)&&e.preventDefault())};return null==t||t.addEventListener("keydown",listener),()=>{null==t||t.removeEventListener("keydown",listener),a.release(),(null==e?void 0:e.isConnected)&&e.focus()}},[y]),!y)return null;const H=M?"wd-dialog":"w-dialog";/* @__PURE__ */
11
+ return t(LayerProvider,{layer:b.current,children:n(/* @__PURE__ */t("div",{className:`${H}-mask${c?" is-fullscreen":""}`,onPointerDown:e=>{e.target===e.currentTarget&&d()},children:/* @__PURE__ */e("div",{ref:x,role:"dialog","aria-modal":"true","aria-labelledby":v?void 0:w,tabIndex:-1,"aria-label":v,className:`${H}${c?" is-fullscreen":""}${m?` ${m}`:""}`,children:[
12
+ /* @__PURE__ */e("header",{className:`${H}__header`,children:[
13
+ /* @__PURE__ */t("div",{id:w,className:`${H}__title`,children:r}),
14
+ /* @__PURE__ */t("button",{type:"button",className:`${H}__close`,"aria-label":g("关闭"),onClick:d,children:/* @__PURE__ */t("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:/* @__PURE__ */t("path",{d:"M6 6l12 12M18 6L6 18"})})})]}),
15
+ /* @__PURE__ */t("div",{className:`${H}__body`,children:i}),!p&&u&&/* @__PURE__ */t("footer",{className:`${H}__footer`,children:u})]})}),y)})}export{LayerProvider as L,WSelect as W,g as a,WIcon as b,WDialog as c,WAlert as d,lockScroll as l,placePanel as p,trapTab as t,useLayer as u};
@@ -1,71 +1 @@
1
- "use client";
2
- function whenNearViewport(target, onVisible, options = {}) {
3
- const factory = options.io ?? (typeof IntersectionObserver !== "undefined" ? (cb, opts) => new IntersectionObserver(cb, opts) : void 0);
4
- if (!factory) {
5
- onVisible();
6
- return () => void 0;
7
- }
8
- let done = false;
9
- const observer = factory(
10
- (entries) => {
11
- const hit = entries.some((e) => e.isIntersecting);
12
- if (!hit || done) return;
13
- done = true;
14
- observer.disconnect();
15
- onVisible();
16
- },
17
- { rootMargin: options.rootMargin ?? "200px" }
18
- );
19
- observer.observe(target);
20
- return () => {
21
- if (done) return;
22
- done = true;
23
- observer.disconnect();
24
- };
25
- }
26
- let katexPromise = null;
27
- async function loadKatex() {
28
- if (!katexPromise) {
29
- katexPromise = import("katex").then((m) => m.default ?? m);
30
- }
31
- return katexPromise;
32
- }
33
- const cache = /* @__PURE__ */ new Map();
34
- const CACHE_LIMIT = 500;
35
- async function renderMathAsync(latex, displayMode) {
36
- const key = `${displayMode ? "b" : "i"}:${latex}`;
37
- const hit = cache.get(key);
38
- if (hit) return { html: hit, error: null };
39
- try {
40
- const katex = await loadKatex();
41
- const html = katex.renderToString(latex, {
42
- displayMode,
43
- // 关键安全选项:不允许 \href / \url / \htmlClass 等产生链接或属性
44
- trust: false,
45
- // 捕获解析错误并交给两端的统一错误态,避免红色 KaTeX 输出被缓存为成功。
46
- throwOnError: true,
47
- // 严格模式降级为忽略:不因排版细节让整个公式渲染失败
48
- strict: "ignore",
49
- output: "html"
50
- });
51
- if (cache.size >= CACHE_LIMIT) cache.clear();
52
- cache.set(key, html);
53
- return { html, error: null };
54
- } catch (err) {
55
- return {
56
- html: "",
57
- error: err instanceof Error ? err.message : "公式渲染失败"
58
- };
59
- }
60
- }
61
- let cssInjected = false;
62
- async function ensureKatexCss() {
63
- if (cssInjected || typeof document === "undefined") return;
64
- cssInjected = true;
65
- await import("katex/dist/katex.min.css");
66
- }
67
- export {
68
- ensureKatexCss as e,
69
- renderMathAsync as r,
70
- whenNearViewport as w
71
- };
1
+ "use client";function whenNearViewport(e,t,r={}){const n=r.io??("undefined"!=typeof IntersectionObserver?(e,t)=>new IntersectionObserver(e,t):void 0);if(!n)return t(),()=>{};let o=!1;const s=n(e=>{e.some(e=>e.isIntersecting)&&!o&&(o=!0,s.disconnect(),t())},{rootMargin:r.rootMargin??"200px"});return s.observe(e),()=>{o||(o=!0,s.disconnect())}}let e=null;const t=/* @__PURE__ */new Map;async function renderMathAsync(r,n){const o=`${n?"b":"i"}:${r}`,s=t.get(o);if(s)return{html:s,error:null};try{const s=(await async function loadKatex(){return e||(e=import("katex").then(e=>e.default??e)),e}()).renderToString(r,{displayMode:n,trust:!1,throwOnError:!0,strict:"ignore",output:"html"});return t.size>=500&&t.clear(),t.set(o,s),{html:s,error:null}}catch(e){return{html:"",error:e instanceof Error?e.message:"公式渲染失败"}}}let r=!1;async function ensureKatexCss(){r||"undefined"==typeof document||(r=!0,await(import("katex/dist/katex.min.css")))}export{ensureKatexCss as e,renderMathAsync as r,whenNearViewport as w};
@@ -0,0 +1 @@
1
+ "use client";import{Node as t,mergeAttributes as e,Mark as a,Extension as r}from"@tiptap/core";import{documentColorAttributes as d,paletteColor as o,TEXT_COLORS as n,HIGHLIGHT_COLORS as i}from"wendang/internal/document-colors";import{Slice as s,Fragment as l}from"@tiptap/pm/model";import{Plugin as u}from"@tiptap/pm/state";import{MIND_MAP_VERSION as c,mindMapId as p}from"wendang/internal/mind-map";import{normalizeVideoEmbed as m,videoSourceUrl as g}from"wendang/internal/video-embed";import{effectiveCallout as b,calloutDOMAttributes as M,validCalloutAttrs as f,CALLOUT_TONES as h}from"wendang/shared";import{bindI18n as T}from"wendang/i18n";const L=t.create({name:"mindMapTopic",content:"text* mindMapDescription? mindMapNote?",marks:"bold italic strike textStyle highlight link",defining:!0,addAttributes:()=>({id:{default:"",parseHTML:t=>t.getAttribute("data-topic-id")},parentId:{default:"",parseHTML:t=>t.getAttribute("data-parent-id")},order:{default:0,parseHTML:t=>Number(t.getAttribute("data-order"))||0},...Object.fromEntries(["shape","color","background","fontSize","align","icon","done","attachmentId","side"].map(t=>[t,{default:null,parseHTML:e=>{try{return JSON.parse(e.getAttribute("data-topic-meta")||"{}")[t]??null}catch{return null}}}]))}),parseHTML:()=>[{tag:"div[data-mind-topic]"}],renderHTML:({node:t})=>["div",{"data-mind-topic":"","data-topic-id":t.attrs.id,"data-parent-id":t.attrs.parentId,"data-order":t.attrs.order,"data-topic-meta":JSON.stringify(t.attrs)},0]}),H=t.create({name:"mindMap",group:"block",content:"mindMapTopic+ mindMapRelation*",atom:!0,isolating:!0,defining:!0,addStorage:()=>({composing:0}),addAttributes:()=>({id:{default:"",parseHTML:t=>t.getAttribute("data-map-id")},rootId:{default:"",parseHTML:t=>t.getAttribute("data-root-id")},formatVersion:{default:c,parseHTML:t=>Number(t.getAttribute("data-format-version"))||1},branchStyle:{default:"curve",parseHTML:t=>t.getAttribute("data-branch-style")||"curve"},layout:{default:"right",parseHTML:t=>t.getAttribute("data-layout")||"right"},theme:{default:"blue",parseHTML:t=>t.getAttribute("data-theme")||"blue"},height:{default:380,parseHTML:t=>Number(t.getAttribute("data-height"))||380}}),parseHTML:()=>[{tag:"div[data-mind-map]"}],renderHTML:({node:t,HTMLAttributes:a})=>["div",e(a,{"data-block-chrome":"","data-mind-map":"","data-map-id":t.attrs.id,"data-root-id":t.attrs.rootId,"data-format-version":t.attrs.formatVersion,"data-layout":t.attrs.layout,"data-theme":t.attrs.theme,"data-height":t.attrs.height,"data-branch-style":t.attrs.branchStyle}),0],addProseMirrorPlugins:()=>[new u({props:{transformPasted(t){const clone=t=>{const e=[];return t.forEach(t=>{if("mindMap"===t.type.name){const a=/* @__PURE__ */new Map;t.forEach(t=>{"mindMapTopic"===t.type.name&&a.set(t.attrs.id,p())});const r=[];t.forEach(t=>r.push(t.type.create({...t.attrs,id:a.get(t.attrs.id)??p(),..."mindMapRelation"===t.type.name?{source:a.get(t.attrs.source),target:a.get(t.attrs.target)}:{parentId:a.get(t.attrs.parentId)??""}},t.content))),e.push(t.type.create({...t.attrs,id:p(),rootId:a.get(t.attrs.rootId)},r))}else e.push(t.copy(clone(t.content)))}),l.from(e)};return new s(clone(t.content),t.openStart,t.openEnd)}}})]}),v=t.create({name:"mindMapDescription",inline:!0,content:"text*",marks:"",selectable:!1,parseHTML:()=>[{tag:"span[data-mind-description]"}],renderHTML:()=>["span",{"data-mind-description":""},0]}),A=v.extend({name:"mindMapNote",parseHTML:()=>[{tag:"span[data-mind-note]"}],renderHTML:()=>["span",{"data-mind-note":""},0]}),y=t.create({name:"mindMapRelation",atom:!0,addAttributes:()=>Object.fromEntries(["id","source","target","kind","label"].map(t=>[t,{default:"",parseHTML:e=>e.getAttribute(`data-${t}`)||""}])),parseHTML:()=>[{tag:"span[data-mind-relation]"}],renderHTML:({node:t})=>["span",{"data-mind-relation":"",...Object.fromEntries(Object.entries(t.attrs).map(([t,e])=>[`data-${t}`,e]))}]}),w=t.create({name:"videoEmbed",group:"block",atom:!0,selectable:!0,draggable:!1,addAttributes:()=>({provider:{default:null,parseHTML:t=>t.getAttribute("data-provider")},videoId:{default:"",parseHTML:t=>t.getAttribute("data-video-id")},page:{default:1,parseHTML:t=>Number(t.getAttribute("data-page")??1)},startSeconds:{default:0,parseHTML:t=>Number(t.getAttribute("data-start-seconds")??0)},autoLoad:{default:null,parseHTML:t=>{const e=t.getAttribute("data-auto-load");return"true"===e||"false"!==e&&null}}}),parseHTML:()=>[{tag:"div[data-video-embed]"}],renderHTML({node:t}){const a=m(t.attrs);return["div",e({"data-video-embed":"true","data-block-chrome":"","data-provider":null==a?void 0:a.provider,"data-video-id":null==a?void 0:a.videoId,"data-page":null==a?void 0:a.page,"data-start-seconds":null==a?void 0:a.startSeconds,"data-auto-load":"boolean"==typeof(null==a?void 0:a.autoLoad)?String(a.autoLoad):void 0}),a?g(a):"视频地址无效"]},renderText({node:t}){const e=m(t.attrs);return e?g(e):"视频地址无效"}}),k=a.create({name:"textStyle",inclusive:!0,addAttributes:()=>({color:{default:null,parseHTML:t=>{const e=t.getAttribute("data-color")??t.style.color;return o(e,n)},renderHTML:t=>d("text",t.color)}}),parseHTML:()=>[{tag:"span[data-text-color]"}],renderHTML:({HTMLAttributes:t})=>["span",e(t,{"data-text-color":"true"}),0]}),x=a.create({name:"highlight",inclusive:!0,addAttributes:()=>({color:{default:null,parseHTML:t=>{const e=t.getAttribute("data-color")??t.style.backgroundColor;return o(e,i)},renderHTML:t=>d("highlight",t.color)}}),parseHTML:()=>[{tag:"mark[data-highlight]"}],renderHTML:({HTMLAttributes:t})=>["mark",e(t,{"data-highlight":"true"}),0]}),S=t.create({name:"callout",group:"block",content:"block+",defining:!0,addOptions:()=>({renderer:void 0}),addAttributes:()=>({tone:{default:"info",parseHTML:t=>{const e=t.getAttribute("data-tone");return h.includes(e)?e:"info"}},...Object.fromEntries(["icon","textColor","borderColor","backgroundColor"].map(t=>[t,{default:null,parseHTML:e=>{const a=e.getAttribute(`data-callout-${t.toLowerCase()}`);return null!==a&&f({[t]:a})?a:null}}]))}),parseHTML:()=>[{tag:"div[data-callout]",contentElement:t=>t.querySelector("[data-callout-content]")??t}],renderHTML:({node:t})=>{const{icon:e}=b(t.attrs);return["div",{...M(t.attrs),class:"doc-callout"},...e?[["span",{class:"callout-icon",contenteditable:"false","data-callout-decoration":"true"},e]]:[],["div",{class:"doc-callout-content","data-callout-content":"true"},0]]},addNodeView(){return this.options.renderer??null}}),E=H.extend({addOptions:()=>({renderer:void 0}),addNodeView(){return this.options.renderer??null}}),N=w.extend({addOptions:()=>({renderer:void 0}),addNodeView(){return this.options.renderer??null}});function localeExtension(t){let e,a;return r.create({name:"wendangLocale",onBeforeCreate(){e=T(this.editor,t)},onCreate(){const e=this.editor,refresh=()=>{e.isDestroyed||(e.view.dom.lang=t.locale,e.view.dom.setAttribute("aria-label",t.t("document.body")),e.view.dispatch(e.state.tr.setMeta("wendang-locale",t.version).setMeta("addToHistory",!1)))};a=t.subscribe(refresh),refresh()},onDestroy(){null==a||a(),null==e||e()}})}export{S as C,x as H,E as M,k as T,N as V,L as a,v as b,A as c,y as d,localeExtension as l};
@@ -0,0 +1 @@
1
+ "use client";import{closeHistory as t}from"@tiptap/pm/history";import{yUndoPluginKey as e}from"@tiptap/y-tiptap";import{p as n}from"./mind-map-delete-CVsxdXfs.js";import{readI18n as o}from"wendang/i18n";import{textDifference as r,MIND_MAP_MAX_TOPICS as i,mindMapId as a,mindMapTree as d,mindMapDescendants as s,mindMapOutline as l,projectMindSideMove as c,canMoveMindTopic as u,mindMapBranchSides as p,MIND_MAP_MAX_TEXT as f,readMindMap as m,MIND_MAP_VERSION as h}from"wendang/internal/mind-map";import{searchMindMap as g,topicTitle as v,topicField as M}from"wendang/internal/mind-map-phase2";function createMindMapController(y,I,x={}){var S;const b=/* @__PURE__ */new Set,A=/* @__PURE__ */new Map;let T=!1;const C=I(),N="number"==typeof C?null==(S=y.state.doc.nodeAt(C))?void 0:S.attrs.id:void 0;let k=!1;function composition(t){var e;if(t===k)return;k=t;const n=null==(e=y.storage)?void 0:e.mindMap;n&&(n.composing=Math.max(0,n.composing+(t?1:-1)))}function current(){if(T||y.isDestroyed)return null;const t=I();if("number"!=typeof t)return null;const e=y.state.doc.nodeAt(t);if("mindMap"!==(null==e?void 0:e.type.name)||e.attrs.id!==N)return null;const n=m(e.toJSON());return n?{node:e,pos:t,model:n}:null}function topicAt(t){const e=current();if(!e)return null;let n=null;return e.node.forEach((o,r)=>{o.attrs.id===t&&(n={node:o,pos:e.pos+r+1})}),n}function topicInsertPos(t){let e=t.pos+1;return t.node.forEach(t=>{"mindMapTopic"===t.type.name&&(e+=t.nodeSize)}),e}function fieldAt(t,e){const n=topicAt(t);if(!n)return null;if("title"===e)return{...n,text:v(n.node.toJSON())};let o=null;return n.node.forEach((t,r)=>{t.type.name===("description"===e?"mindMapDescription":"mindMapNote")&&(o={node:t,pos:n.pos+1+r,text:t.textContent})}),o}const editable=()=>!!current()&&y.isEditable;function structuralChange(n){var o;const r=current();if(r&&r.node.attrs.formatVersion<h){const t=n.doc.nodeAt(n.mapping.map(r.pos));"mindMap"===(null==t?void 0:t.type.name)&&n.setNodeMarkup(n.mapping.map(r.pos),void 0,{...t.attrs,formatVersion:h})}const i=null==(o=e.getState(y.state))?void 0:o.undoManager;null==i||i.stopCapturing(),y.view.dispatch(t(n)),null==i||i.stopCapturing()}function notify(){for(const t of b)t()}function onTransaction({transaction:t}){for(const[e,n]of A){const locate=t=>{let n=null;return t.descendants((t,o)=>"mindMapTopic"===t.type.name&&t.attrs.id===e.split("::")[0]?(n={node:t,pos:o},!1):!n),n},o=e.split("::")[1]||"title",i=locate(t.before),a=locate(t.doc);if(!i||!a){A.delete(e);continue}const getText=t=>"title"===o?v(t.toJSON()):M(t.toJSON(),o),d=r(getText(i.node),getText(a.node)),s=d.text.length-(d.to-d.from);n.boundaries=n.boundaries.map(t=>{const e=Math.max(0,Math.min(getText(i.node).length,t)),n=e<d.from?e:e>=d.to?e+s:d.from+d.text.length;return Math.max(0,Math.min(getText(a.node).length,n))})}notify()}function beginText(t,e="title"){var n,o,r;const i=fieldAt(t,e);if(!i)return;const a=i.text;A.set(`${t}::${e}`,{text:a,boundaries:Array.from({length:a.length+1},(t,e)=>e)});const d=null==(o=null==(n=x.awareness)?void 0:n.getLocalState())?void 0:o.mindMap;(null==d?void 0:d.blockId)===N&&(null==(r=x.awareness)||r.setLocalStateField("mindMap",{...d,topicId:t,editing:!0}))}function orderAt(t,e,n){var o,r,i;const a=(null==(o=e[n-1])?void 0:o.order)??((null==(r=e[n])?void 0:r.order)??0)-2048,d=(null==(i=e[n])?void 0:i.order)??a+2048,s=(a+d)/2;return s>a&&s<d&&Math.abs(s)<1e12&&d-a>Number.EPSILON*Math.max(1,Math.abs(a),Math.abs(d))*8?s:(e.forEach((e,n)=>{const o=topicAt(e.id);o&&t.setNodeMarkup(o.pos,void 0,{...o.node.attrs,order:1024*n})}),1024*n-512)}function freezeBranchSides(t,e){const n=p(e.model);for(const[e,o]of n){const n=topicAt(e);t.setNodeMarkup(n.pos,void 0,{...t.doc.nodeAt(n.pos).attrs,side:o})}return n}function insertTopic(t,e,n=o(y).t("mind.newTopic"),r="after",s){const l=current();if(!editable()||!l||l.model.topics.length>=i||!topicAt(t))return null;if(void 0!==s&&(t!==l.model.rootId||"down"===l.model.layout||-1!==s&&1!==s))return null;const c=d(l.model).filter(e=>e.parentId===t),u=c.findIndex(t=>t.id===e);if(e&&u<0)return null;const m=y.state.tr,h=orderAt(m,c,u>=0?u+("after"===r?1:0):c.length),g=a(),v=void 0!==s&&"both"!==l.model.layout&&s!==("left"===l.model.layout?-1:1),M="both"===l.model.layout||v?freezeBranchSides(m,l):p(l.model),I=s??(t===l.model.rootId?e?M.get(e):"left"===l.model.layout?-1:1:null),x=y.schema.nodes.mindMapTopic.create({id:g,parentId:t,order:h,side:I},n?y.schema.text(n.slice(0,f)):void 0);return v&&m.setNodeMarkup(l.pos,void 0,{...l.node.attrs,layout:"both"}),structuralChange(m.insert(topicInsertPos(l),x)),g}function move(t,e,n="child"){const o=current();if(!o||!editable())return!1;const r=d(o.model),i=r.find(t=>t.id===e);if(!i)return!1;const a="child"===n?e:i.parentId;if(!u(o.model,t,a)||t===e)return!1;const s=r.filter(e=>e.parentId===a&&e.id!==t),l=y.state.tr;let c;if("child"===n)c=s.length;else{const t=s.findIndex(t=>t.id===e);if(t<0)return!1;c="before"===n?t:t+1}const f=orderAt(l,s,c),m=topicAt(t),h=p(o.model);if(a===o.model.rootId)for(const e of r.filter(e=>e.parentId===a&&e.id!==t)){const t=topicAt(e.id);l.setNodeMarkup(t.pos,void 0,{...l.doc.nodeAt(t.pos).attrs,side:h.get(e.id)})}const g=a===o.model.rootId?h.get("child"===n?t:e)??("left"===o.model.layout?-1:1):null;return l.setNodeMarkup(m.pos,void 0,{...l.doc.nodeAt(m.pos).attrs,parentId:a,order:f,side:g}),structuralChange(l),!0}function removeMany(t){const e=current();if(!editable()||!e)return!1;const o=n(e.model,t);if(!o)return!1;const{ids:r}=o,i=[];e.node.forEach((t,n)=>{(r.has(t.attrs.id)||"mindMapRelation"===t.type.name&&(r.has(t.attrs.source)||r.has(t.attrs.target)))&&i.push({from:e.pos+1+n,to:e.pos+1+n+t.nodeSize})});const a=y.state.tr;"both"===e.model.layout&&freezeBranchSides(a,e);for(const t of i.reverse())a.delete(t.from,t.to);return structuralChange(a),!0}return y.on("transaction",onTransaction),y.on("update",notify),{context:x,snapshot:()=>{var t;return(null==(t=current())?void 0:t.model)??null},editable:editable,beginText:beginText,text:function text(t,e,n="title"){if(!editable()||e.length>("title"===n?f:4e3))return!1;let o=fieldAt(t,n);if(!o&&"title"!==n){const e=topicAt(t);if(!e)return!1;let r=e.pos+e.node.nodeSize-1;"description"===n&&e.node.forEach((t,n)=>{"mindMapNote"===t.type.name&&(r=e.pos+1+n)}),structuralChange(y.state.tr.insert(r,y.schema.nodes["description"===n?"mindMapDescription":"mindMapNote"].create())),o=fieldAt(t,n)}if(!o)return!1;const i=`${t}::${n}`;A.has(i)||beginText(t,n);const a=A.get(i),d=r(a.text,e);if(d.from===d.to&&!d.text)return!0;const s=o.pos+1+a.boundaries[d.from],l=o.pos+1+a.boundaries[d.to];if(s<o.pos+1||l>o.pos+1+o.text.length||s>l)return!1;const c=y.state.tr.insertText(d.text,s,l);y.view.dispatch(c);const u=A.get(i);return!!u&&(u.boundaries=[...u.boundaries.slice(0,d.from),...Array.from({length:d.text.length+1},(t,e)=>s-o.pos-1+e),...u.boundaries.slice(d.to+1)],u.text=e,!0)},composition:composition,patch:function patch(t,e){const n=topicAt(t);return!(!editable()||!n||(structuralChange(y.state.tr.setNodeMarkup(n.pos,void 0,{...n.node.attrs,...e})),0))},addParent:function addParent(t){const e=current(),n=topicAt(t);if(!e||!n||!editable()||t===e.model.rootId||e.model.topics.length>=500)return null;const o=d(e.model).find(e=>e.id===t),r=a(),i=y.state.tr;return"both"===e.model.layout&&freezeBranchSides(i,e),i.setNodeMarkup(n.pos,void 0,{...n.node.attrs,parentId:r,order:0}),i.insert(topicInsertPos(e),y.schema.nodes.mindMapTopic.create({id:r,parentId:o.parentId,order:o.order,side:p(e.model).get(t)??null},y.schema.text("父主题"))),structuralChange(i),r},indent:function indent(t,e=!1){const n=current();if(!n)return!1;const o=d(n.model),r=o.find(e=>e.id===t);if(!r||!r.parentId)return!1;if(e){const e=o.find(t=>t.id===r.parentId);return!!(null==e?void 0:e.parentId)&&move(t,e.id,"after")}const i=o.filter(t=>t.parentId===r.parentId),a=i.findIndex(e=>e.id===t);return a>0&&move(t,i[a-1].id)},format:function format(t,e,n,o,r){const i=fieldAt(t,"title"),a=y.schema.marks[o];if(!editable()||!i||!a||e<0||n>i.text.length||n<=e)return!1;const d=i.pos+1+e,s=i.pos+1+n,l=y.state.tr;return!r&&y.state.doc.rangeHasMark(d,s,a)?l.removeMark(d,s,a):l.addMark(d,s,a.create(r)),structuralChange(l),!0},clearFormat:function clearFormat(t,e,n,o){const r=fieldAt(t,"title");if(!editable()||!r||e<0||n>r.text.length||n<=e)return!1;const i=y.state.tr;if(o)for(const t of o){const o=y.schema.marks[t];o&&i.removeMark(r.pos+1+e,r.pos+1+n,o)}else i.removeMark(r.pos+1+e,r.pos+1+n);return structuralChange(i),!0},replace:function replace(t,e,n){const o=current();if(!o||!editable()||!t)return 0;const r=n?[n]:g(o.model,t),i=y.state.tr;if(r.length>5e3)return-1;const a=/* @__PURE__ */new Map;for(const t of r)a.set(`${t.id}::${t.field}`,(a.get(`${t.id}::${t.field}`)??0)+1);for(const[n,o]of a){const[r,i]=n.split("::"),a=fieldAt(r,i);if(a&&a.text.length+o*(e.length-t.length)>("title"===i?2e3:4e3))return-2}const d=r.flatMap(n=>{const o=fieldAt(n.id,n.field);return o&&o.text.slice(n.from,n.to).toLocaleLowerCase()===t.toLocaleLowerCase()?o.text.length+e.length-t.length>("title"===n.field?2e3:4e3)?[]:[{from:o.pos+1+n.from,to:o.pos+1+n.to}]:[]}).sort((t,e)=>e.from-t.from);for(const t of d)i.insertText(e,t.from,t.to);return d.length&&structuralChange(i),d.length},relation:function relation(t){const e=current();if(!(e&&editable()&&t.source!==t.target&&topicAt(t.source)&&topicAt(t.target)))return!1;let n=null;e.node.forEach((o,r)=>{"mindMapRelation"===o.type.name&&o.attrs.id===t.id&&(n={node:o,pos:e.pos+1+r})});const o=n,r={...t,id:t.id??a(),label:t.label.slice(0,200)};return structuralChange(o?y.state.tr.setNodeMarkup(o.pos,void 0,r):y.state.tr.insert(e.pos+e.node.nodeSize-1,y.schema.nodes.mindMapRelation.create(r))),!0},deleteRelation:function deleteRelation(t){const e=current();if(!e||!editable())return!1;const n=y.state.tr;let o=!1;return e.node.forEach((r,i)=>{"mindMapRelation"===r.type.name&&r.attrs.id===t&&(n.delete(e.pos+1+i,e.pos+1+i+r.nodeSize),o=!0)}),o&&structuralChange(n),o},hasActiveText:()=>A.size>0,endText:(t,e="title")=>{var n,o,r;A.delete(`${t}::${e}`);const i=null==(o=null==(n=x.awareness)?void 0:n.getLocalState())?void 0:o.mindMap;(null==i?void 0:i.blockId)===N&&(null==(r=x.awareness)||r.setLocalStateField("mindMap",{...i,editing:A.size>0}))},add:function add(t,e,n=o(y).t("mind.newTopic")){return insertTopic(t,e,n)},addRootChild:function addRootChild(t,e=o(y).t("mind.newTopic")){const n=current();return n?insertTopic(n.model.rootId,void 0,e,"after",t):null},addSibling:function addSibling(t,e,n=o(y).t("mind.newTopic")){const r=current();if(!r||t===r.model.rootId)return null;const i=d(r.model).find(e=>e.id===t);return(null==i?void 0:i.parentId)?insertTopic(i.parentId,t,n,e):null},move:move,moveToSide:function moveToSide(t,e,n){const o=current();if(!o||!editable())return!1;const r=c(o.model,t,e,n);if(!r)return!1;const i=y.state.tr;for(const t of r.topics){const e=o.model.topics.find(e=>e.id===t.id);if(e.parentId===t.parentId&&e.order===t.order&&e.side===t.side)continue;const n=topicAt(t.id);i.setNodeMarkup(n.pos,void 0,{...n.node.attrs,parentId:t.parentId,order:t.order,side:t.side??null})}return o.model.layout!==r.layout&&i.setNodeMarkup(o.pos,void 0,{...o.node.attrs,layout:r.layout}),i.docChanged&&structuralChange(i),!0},remove:function remove(t){return removeMany([t])},removeMany:removeMany,settings:function settings(t){const e=current();if(!editable()||!e)return!1;const n=y.state.tr;if(t.layout&&t.layout!==e.model.layout)for(const t of e.model.topics.filter(t=>t.parentId===e.model.rootId)){const e=topicAt(t.id);null!==e.node.attrs.side&&n.setNodeMarkup(e.pos,void 0,{...e.node.attrs,side:null})}return structuralChange(n.setNodeMarkup(e.pos,void 0,{...e.node.attrs,...t})),!0},copyBranch:function copyBranch(t){const e=current();if(!e)return[];const n=s(e.model,t),o=new Map((e.node.toJSON().content??[]).map(t=>{var e;return[String(null==(e=t.attrs)?void 0:e.id),t]}));return[...l(e.model).filter(t=>n.has(t.id)).map(t=>o.get(t.id)),...(e.node.toJSON().content??[]).filter(t=>{var e,o;return"mindMapRelation"===t.type&&n.has(String(null==(e=t.attrs)?void 0:e.source))&&n.has(String(null==(o=t.attrs)?void 0:o.target))})]},pasteBranch:function pasteBranch(t,e){var n,o,r,s;const l=current();if(!editable()||!l||!topicAt(t)||!e.length||e.filter(t=>"mindMapTopic"===t.type).length+l.model.topics.length>i)return null;const c=e.filter(t=>"mindMapTopic"===t.type);if(!c.length)return null;const u=new Map(c.map(t=>{var e;return[String(null==(e=t.attrs)?void 0:e.id),a()]})),p=d(l.model).filter(e=>e.parentId===t),f=c.map((e,n)=>{var o,r,i,a,d;return y.schema.nodeFromJSON({...e,attrs:{...e.attrs,id:u.get(String(null==(o=e.attrs)?void 0:o.id)),parentId:u.get(String(null==(r=e.attrs)?void 0:r.parentId))??t,order:u.has(String(null==(i=e.attrs)?void 0:i.parentId))?Number(null==(a=e.attrs)?void 0:a.order)||0:((null==(d=p.at(-1))?void 0:d.order)??-1)+1+n}})}),m=y.state.tr.insert(topicInsertPos(l),f);for(const t of e.filter(t=>"mindMapRelation"===t.type))u.has(String(null==(n=t.attrs)?void 0:n.source))&&u.has(String(null==(o=t.attrs)?void 0:o.target))&&m.insert(m.mapping.map(l.pos+l.node.nodeSize-1),y.schema.nodes.mindMapRelation.create({...t.attrs,id:a(),source:u.get(String(null==(r=t.attrs)?void 0:r.source)),target:u.get(String(null==(s=t.attrs)?void 0:s.target))}));return structuralChange(m),f[0].attrs.id},undo:()=>editable()&&y.commands.undo(),redo:()=>editable()&&y.commands.redo(),canUndo:()=>editable()&&y.can().undo(),canRedo:()=>editable()&&y.can().redo(),canExport:()=>{var t;return(null==(t=x.canExport)?void 0:t.call(x))??!1},status:()=>{var t;return(null==(t=x.status)?void 0:t.call(x))??""},subscribe:t=>(b.add(t),()=>b.delete(t)),dispose(){composition(!1),T=!0,y.off("transaction",onTransaction),y.off("update",notify),notify(),b.clear(),A.clear()}}}export{createMindMapController as c};
@@ -1,31 +1 @@
1
- "use client";
2
- import { mindMapTree } from "wendang/internal/mind-map";
3
- function planMindTopicDeletion(model, selection, activeId) {
4
- var _a, _b;
5
- const tree = mindMapTree(model), byId = new Map(tree.map((topic) => [topic.id, topic]));
6
- const selected = [...new Set(selection)];
7
- if (!selected.length || selected.some((id) => !byId.has(id))) return null;
8
- const targets = selected.filter((id) => id !== model.rootId);
9
- if (!targets.length) return null;
10
- const children = /* @__PURE__ */ new Map();
11
- for (const topic of tree) {
12
- const siblings = children.get(topic.parentId) ?? [];
13
- siblings.push(topic.id);
14
- children.set(topic.parentId, siblings);
15
- }
16
- const ids = /* @__PURE__ */ new Set();
17
- const pending = [...targets];
18
- while (pending.length) {
19
- const id = pending.pop();
20
- if (ids.has(id)) continue;
21
- ids.add(id);
22
- pending.push(...children.get(id) ?? []);
23
- }
24
- const roots = targets.filter((id) => !ids.has(byId.get(id).parentId));
25
- let nextId = ((_a = byId.get(activeId ?? targets.at(-1))) == null ? void 0 : _a.parentId) || model.rootId;
26
- while (ids.has(nextId)) nextId = ((_b = byId.get(nextId)) == null ? void 0 : _b.parentId) || model.rootId;
27
- return { ids, roots, nextId, keepsCenter: selected.includes(model.rootId) };
28
- }
29
- export {
30
- planMindTopicDeletion as p
31
- };
1
+ "use client";import{mindMapTree as t}from"wendang/internal/mind-map";function planMindTopicDeletion(n,e,o){var r,d;const s=t(n),a=new Map(s.map(t=>[t.id,t])),i=[...new Set(e)];if(!i.length||i.some(t=>!a.has(t)))return null;const l=i.filter(t=>t!==n.rootId);if(!l.length)return null;const p=/* @__PURE__ */new Map;for(const t of s){const n=p.get(t.parentId)??[];n.push(t.id),p.set(t.parentId,n)}const c=/* @__PURE__ */new Set,u=[...l];for(;u.length;){const t=u.pop();c.has(t)||(c.add(t),u.push(...p.get(t)??[]))}const f=l.filter(t=>!c.has(a.get(t).parentId));let I=(null==(r=a.get(o??l.at(-1)))?void 0:r.parentId)||n.rootId;for(;c.has(I);)I=(null==(d=a.get(I))?void 0:d.parentId)||n.rootId;return{ids:c,roots:f,nextId:I,keepsCenter:i.includes(n.rootId)}}export{planMindTopicDeletion as p};
@@ -1,43 +1 @@
1
- "use client";
2
- function selectMindTopic(current, id, additive = false) {
3
- if (!additive) return /* @__PURE__ */ new Set([id]);
4
- const next = new Set(current);
5
- if (next.has(id)) next.delete(id);
6
- else next.add(id);
7
- return next;
8
- }
9
- function resetMindZoom(viewport, width, height) {
10
- return {
11
- x: width / 2 - (width / 2 - viewport.x) / viewport.zoom,
12
- y: height / 2 - (height / 2 - viewport.y) / viewport.zoom,
13
- zoom: 1
14
- };
15
- }
16
- function mindCanvasShortcut(event) {
17
- if (event.isComposing || event.keyCode === 229 || event.altKey) return null;
18
- if (event.metaKey || event.ctrlKey) {
19
- if (event.key === "+" || event.key === "=") return "zoom-in";
20
- if (event.key === "-") return "zoom-out";
21
- if (!event.shiftKey && event.key === "0") return "reset-zoom";
22
- return null;
23
- }
24
- if (event.metaKey || event.ctrlKey || !event.shiftKey) return null;
25
- switch (event.key.toLowerCase()) {
26
- case "c":
27
- return "comments";
28
- case "q":
29
- return "quick";
30
- case "g":
31
- return "grid";
32
- case "1":
33
- case "!":
34
- return "fit";
35
- default:
36
- return null;
37
- }
38
- }
39
- export {
40
- mindCanvasShortcut as m,
41
- resetMindZoom as r,
42
- selectMindTopic as s
43
- };
1
+ "use client";function selectMindTopic(e,t,n=!1){if(!n)/* @__PURE__ */return new Set([t]);const r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r}function resetMindZoom(e,t,n){return{x:t/2-(t/2-e.x)/e.zoom,y:n/2-(n/2-e.y)/e.zoom,zoom:1}}function mindCanvasShortcut(e){if(e.isComposing||229===e.keyCode||e.altKey)return null;if(e.metaKey||e.ctrlKey)return"+"===e.key||"="===e.key?"zoom-in":"-"===e.key?"zoom-out":e.shiftKey||"0"!==e.key?null:"reset-zoom";if(e.metaKey||e.ctrlKey||!e.shiftKey)return null;switch(e.key.toLowerCase()){case"c":return"comments";case"q":return"quick";case"g":return"grid";case"1":case"!":return"fit";default:return null}}export{mindCanvasShortcut as m,resetMindZoom as r,selectMindTopic as s};
@@ -0,0 +1,30 @@
1
+ "use client";import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{c as n,a as i,b as a,f as l,d as o,u as c,e as s}from"./i18n-B0kCsIjc.js";import{useState as d,useRef as u,useEffect as m,Fragment as p}from"react";import{w as h,e as v,r as f}from"./katex-WjrodtTU.js";import{safeHref as g,documentColorAttributes as w}from"wendang/shared";import{normalizeVideoEmbed as b,videoSourceUrl as y,VIDEO_PROVIDER_LABELS as x,videoLoadsAutomatically as k,videoPlayerUrl as N}from"wendang/internal/video-embed";import{createPortal as C}from"react-dom";import{l as I,t as E}from"./index-COeA2QcQ.js";import{setMindTextMeasureFactory as T,MIND_TOPIC_FONT as P}from"wendang/internal/mind-topic-text";function previewItemsFrom(e,t="图片预览"){const lonely=()=>{if(!(e instanceof HTMLImageElement))return{items:[],index:0};const r=e.getAttribute("src");return r?{items:[{src:r,label:e.getAttribute("alt")||t}],index:0}:{items:[],index:0}};if(!e||"function"!=typeof e.closest)return{items:[],index:0};const r=e.closest(".ywiki-image-gallery, .doc-image-gallery");if(!r)return lonely();const n=Array.from(r.querySelectorAll("img")).filter(e=>e instanceof HTMLImageElement&&!!e.getAttribute("src"));if(0===n.length)return{items:[],index:0};const i=n.indexOf(e);return i<0?lonely():{items:n.map(e=>({src:e.getAttribute("src")??"",label:e.getAttribute("alt")||t})),index:i}}function stepPreviewIndex(e,t,r){if(!Number.isFinite(e)||t<=0)return 0;const n=e+(Number.isFinite(r)?r:0);return Math.max(0,Math.min(t-1,Math.round(n)))}function canStepPreview(e,t,r){return!(t<=1)&&stepPreviewIndex(e,t,r)!==stepPreviewIndex(e,t,0)}function ImagePreview({src:r,label:a,items:l,index:o=0,onClose:c}){const s=n().text,p=a??s("图片预览"),{portal:h}=i(),[v,f]=d(o),[g,w]=d(1),[b,y]=d(0),[x,k]=d({x:0,y:0}),[N,T]=d(!1),P=u(null),A=u(null),L=u(null),D=u(c);D.current=c;const F=(null==l?void 0:l.length)?l:[{src:r,label:p}],M=u(F);M.current=F;const z=u(v);z.current=v;const V=F[v]??F[0];function reset(){w(1),y(0),k({x:0,y:0})}function zoomBy(e){w(t=>Math.min(8,Math.max(.25,t*e)))}function step(e){const t=stepPreviewIndex(z.current,M.current.length,e);t!==z.current&&(z.current=t,f(t),reset())}function endDrag(){L.current=null,T(!1)}return m(()=>{z.current=o,f(o),reset()},[r,o]),m(()=>{if(!h)return;const e=document.activeElement,t=I(),keydown=e=>{e.isComposing||("Escape"===e.key?(e.preventDefault(),e.stopPropagation(),D.current()):"ArrowLeft"===e.key?(e.preventDefault(),step(-1)):"ArrowRight"===e.key?(e.preventDefault(),step(1)):"+"===e.key||"="===e.key?(e.preventDefault(),zoomBy(1.2)):"-"===e.key||"_"===e.key?(e.preventDefault(),zoomBy(1/1.2)):"0"===e.key?(e.preventDefault(),reset()):P.current&&E(P.current,e)&&e.preventDefault())};window.addEventListener("keydown",keydown,!0);const r=requestAnimationFrame(()=>{var e;return null==(e=A.current)?void 0:e.focus()});return()=>{cancelAnimationFrame(r),window.removeEventListener("keydown",keydown,!0),t.release(),(null==e?void 0:e.isConnected)&&e.focus()}},[h]),m(()=>{const e=P.current;if(!e)return;const wheel=e=>{e.preventDefault(),zoomBy(e.deltaY<0?1.12:1/1.12)};return e.addEventListener("wheel",wheel,{passive:!1}),()=>e.removeEventListener("wheel",wheel)},[h]),h?C(/* @__PURE__ */e("div",{ref:P,className:"img-preview-mask",onMouseDown:e=>{!L.current&&e.target instanceof Element&&!e.target.closest(".img-preview-image,.img-preview-toolbar,.img-preview-nav")&&D.current()},children:[
2
+ /* @__PURE__ */t("div",{ref:A,className:"img-preview-stage",role:"dialog","aria-modal":"true","aria-label":V.label,tabIndex:-1,children:/* @__PURE__ */t("img",{className:"img-preview-image"+(N?" is-dragging":""),src:V.src,alt:V.label,draggable:!1,style:{transform:`translate(${x.x}px, ${x.y}px) scale(${g}) rotate(${b}deg)`},onPointerDown:e=>{var t,r;0===e.button&&(L.current={x:e.clientX,y:e.clientY,ox:x.x,oy:x.y},T(!0),null==(r=(t=e.currentTarget).setPointerCapture)||r.call(t,e.pointerId))},onPointerMove:e=>{const t=L.current;t&&k({x:t.ox+e.clientX-t.x,y:t.oy+e.clientY-t.y})},onPointerUp:endDrag,onPointerCancel:endDrag,onLostPointerCapture:endDrag})}),F.length>1&&/* @__PURE__ */e("div",{className:"img-preview-nav",role:"group","aria-label":s("图片翻页"),children:[
3
+ /* @__PURE__ */t("button",{type:"button",className:"img-preview-nav-btn is-prev","aria-label":s("上一张"),title:s("上一张(←)"),disabled:!canStepPreview(v,F.length,-1),onClick:()=>step(-1),children:/* @__PURE__ */t("svg",{viewBox:"0 0 24 24",width:"22",height:"22",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:/* @__PURE__ */t("path",{d:"m15 18-6-6 6-6"})})}),
4
+ /* @__PURE__ */t("button",{type:"button",className:"img-preview-nav-btn is-next","aria-label":s("下一张"),title:s("下一张(→)"),disabled:!canStepPreview(v,F.length,1),onClick:()=>step(1),children:/* @__PURE__ */t("svg",{viewBox:"0 0 24 24",width:"22",height:"22",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:/* @__PURE__ */t("path",{d:"m9 18 6-6-6-6"})})})]}),
5
+ /* @__PURE__ */e("div",{className:"img-preview-toolbar",role:"toolbar","aria-label":s("图片预览操作"),children:[
6
+ /* @__PURE__ */t("button",{type:"button","aria-label":s("缩小"),title:s("缩小(-)"),onClick:()=>zoomBy(1/1.2),children:"−"}),
7
+ /* @__PURE__ */e("span",{className:"img-preview-scale","aria-live":"polite",children:[Math.round(100*g),"%"]}),
8
+ /* @__PURE__ */t("button",{type:"button","aria-label":s("放大"),title:s("放大(+)"),onClick:()=>zoomBy(1.2),children:"+"}),
9
+ /* @__PURE__ */t("span",{className:"img-preview-divider"}),
10
+ /* @__PURE__ */t("button",{type:"button","aria-label":s("向左旋转"),title:s("向左旋转"),onClick:()=>y(e=>e-90),children:"↺"}),
11
+ /* @__PURE__ */t("button",{type:"button","aria-label":s("向右旋转"),title:s("向右旋转"),onClick:()=>y(e=>e+90),children:"↻"}),
12
+ /* @__PURE__ */t("span",{className:"img-preview-divider"}),
13
+ /* @__PURE__ */t("button",{type:"button","aria-label":s("还原"),title:s("还原(0)"),onClick:reset,children:s("还原")}),F.length>1&&/* @__PURE__ */e("span",{className:"img-preview-count","aria-live":"polite",children:[v+1," / ",F.length]}),
14
+ /* @__PURE__ */t("button",{type:"button","aria-label":s("关闭预览"),title:s("关闭(Esc)"),onClick:c,children:s("关闭")})]})]}),h):null}function AttachmentImage({id:i,alt:l="",width:s,fetcher:p,src:v,align:f,aspectRatio:w,galleryScale:b,className:y=""}){var x;const k=n().text,N=a(),C=u(null),[I,E]=d({id:"",url:"",failed:!1}),[T,P]=d(null);m(()=>{E({id:i??"",url:"",failed:!1});const e=C.current;if(!i||!e)return;let t,r=!0;const n=h(e,()=>{var e;t=o(i,e=>{r&&E({id:i,url:e,failed:!1})},p??(null==(e=N.attachments)?void 0:e.fetch)??c,()=>{r&&E({id:i,url:"",failed:!0})},N.scope)});return()=>{r=!1,n(),null==t||t()}},[i,p,null==(x=N.attachments)?void 0:x.fetch,N.scope]);const A=i?I.id===i?I.url:"":g(v),L=I.id===(i??"")&&I.failed;function open(e){A&&!L&&P(previewItemsFrom(e,l||k("图片预览")))}/* @__PURE__ */
15
+ return e(r,{children:[
16
+ /* @__PURE__ */t("img",{ref:C,className:"doc-image"+(y?` ${y}`:""),"data-attachment-id":i,src:A||(L?"data:image/svg+xml;charset=utf-8,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%221%22 height=%221%22 preserveAspectRatio=%22none%22%3E%3C/svg%3E":void 0),alt:A?l:void 0,title:L?l:void 0,"data-sized":s?"true":void 0,"data-align":f??void 0,"data-aspect-ratio":w&&w>0?w:void 0,"data-gallery-scale":b&&1!==b?b:void 0,"data-loading":A||L?void 0:"true","data-image-error":L?"true":void 0,style:{...s?{width:`${s}px`}:{},...w&&w>0?{"--doc-image-aspect-ratio":String(w)}:{},...b&&b>0&&1!==b?{"--doc-image-weight":String(b)}:{}},tabIndex:0,onError:()=>E(e=>({...e,failed:!0})),onClick:e=>open(e.currentTarget),onKeyDown:e=>{"Enter"===e.key&&open(e.currentTarget)}}),T&&/* @__PURE__ */t(ImagePreview,{src:A,label:l||k("图片预览"),items:T.items,index:T.index,onClose:()=>P(null)})]})}function MathView({latex:e,block:r=!1}){const i=n().text,[a,l]=d({html:"",error:null});return m(()=>{let t=!0;return v(),f(e,r).then(e=>{t&&l(e)}),()=>{t=!1}},[e,r]),a.html?/* @__PURE__ */t("span",{className:r?"doc-math-block":"doc-math-inline",dangerouslySetInnerHTML:{__html:a.html}}):/* @__PURE__ */t("span",{role:a.error?"alert":void 0,children:a.error?i("公式错误:{0}",{0:e}):e})}function FileVideo({id:e,mimeType:r,fetcher:i}){var l;const s=n().text,p=a(),v=u(null),[f,g]=d({id:"",url:"",failed:!1});m(()=>{if(g({id:e,url:"",failed:!1}),!v.current||!e)return;let t,r=!0;const n=h(v.current,()=>{var n;t=o(e,t=>{r&&g({id:e,url:t,failed:!1})},i??(null==(n=p.attachments)?void 0:n.fetch)??c,()=>{r&&g({id:e,url:"",failed:!0})},p.scope)});return()=>{r=!1,n(),null==t||t()}},[e,i,null==(l=p.attachments)?void 0:l.fetch,p.scope]);const w=f.id===e?f.url:"",b=f.id===e&&f.failed;/* @__PURE__ */
17
+ return t("div",{ref:v,className:"doc-file-video",children:w&&!b?/* @__PURE__ */t("video",{src:w,controls:!0,preload:"metadata",onError:()=>g(e=>({...e,failed:!0})),children:/* @__PURE__ */t("source",{src:w,type:r})}):/* @__PURE__ */t("p",{className:"doc-file-video-fallback",children:s(b?"视频加载失败。":"视频加载中…")})})}function FileView({id:r,filename:i,mimeType:o="",size:p=0,fetcher:h,allowExport:v=!1}){const f=n().text,g=a(),[w,b]=d(""),[y,x]=d(!1),k=u(v),N=u(!0);return k.current=v,m(()=>(N.current=!0,()=>{N.current=!1}),[]),m(()=>{b("")},[r]),r?/* @__PURE__ */e("div",{className:"doc-file",children:[
18
+ /* @__PURE__ */e("div",{className:"doc-file-head",children:[
19
+ /* @__PURE__ */t("span",{className:"doc-file-icon",children:o.startsWith("video/")?"▶":o.startsWith("image/")?"🖼":"📎"}),
20
+ /* @__PURE__ */t("span",{className:"doc-file-name",title:i,children:i}),
21
+ /* @__PURE__ */t("span",{className:"doc-file-size",children:l(p)}),v&&/* @__PURE__ */t("button",{type:"button",className:"doc-file-action",disabled:y,onClick:()=>{!async function download(){if(!y&&k.current){x(!0),b("");try{await s(r,i,async e=>{var t;const r=await(h??(null==(t=g.attachments)?void 0:t.fetch)??c)(e);if(!N.current||!k.current)throw new Error(f("当前不允许导出附件"));return r})}catch(e){N.current&&b(e instanceof Error?e.message:f("附件下载失败"))}finally{N.current&&x(!1)}}}()},children:f(y?"下载中…":"下载")})]}),o.startsWith("video/")?/* @__PURE__ */t(FileVideo,{id:r,mimeType:o,fetcher:h}):o.startsWith("image/")?/* @__PURE__ */t(AttachmentImage,{id:r,alt:i,fetcher:h,className:"doc-file-image"}):null,w&&/* @__PURE__ */t("p",{role:"alert",className:"doc-file-video-fallback",children:w})]}):/* @__PURE__ */t("div",{className:"doc-file is-missing",children:f("[附件缺失]")})}function VideoView({attrs:a,reloadKey:l=0}){var o;const c=n(),s=c.text,p=b(a),h=p?y(p):"",v=s(p?x[p.provider]:"外部"),f=i().video,g=!!p&&((null==(o=null==f?void 0:f.providers)?void 0:o.includes(p.provider))??!0),w=k(p,f),[C,I]=d(""),[E,T]=d(!0),[P,A]=d(!1),L=u(null),D=u(void 0);m(()=>{if(!L.current||"undefined"==typeof ResizeObserver)return;const e=new ResizeObserver(([e])=>T(e.contentRect.width>=200));return e.observe(L.current),()=>e.disconnect()},[]),m(()=>(I(""),A(!1),clearTimeout(D.current),h&&E&&g&&w&&(I(h),D.current=setTimeout(()=>A(!0),12e3)),()=>clearTimeout(D.current)),[h,E,g,w]);const F=!!h&&C===h;return m(()=>{l&&h&&E&&g&&(clearTimeout(D.current),A(!1),I(h),D.current=setTimeout(()=>A(!0),12e3))},[l]),/* @__PURE__ */t("section",{ref:L,className:"doc-video-embed",contentEditable:!1,"aria-label":s("{0} 视频",{0:v}),children:p?/* @__PURE__ */e(r,{children:[F&&E&&g?/* @__PURE__ */t("iframe",{src:N(p),title:s("{0} 视频 {1}",{0:v,1:p.videoId}),loading:"lazy",allow:"fullscreen; picture-in-picture; encrypted-media",allowFullScreen:!0,sandbox:"allow-scripts allow-same-origin allow-presentation allow-popups",referrerPolicy:"strict-origin-when-cross-origin",onLoad:()=>{clearTimeout(D.current),A(!1)}},l):/* @__PURE__ */e("div",{className:"video-placeholder",children:[
22
+ /* @__PURE__ */t("span",{className:"video-play-icon","aria-hidden":"true",children:"▶"}),
23
+ /* @__PURE__ */e("strong",{children:[v," ",s("视频"),p.page>1?c.t("video.part",{0:p.page}):""]}),
24
+ /* @__PURE__ */t("span",{className:"video-id",children:p.videoId}),E&&g&&/* @__PURE__ */t("button",{type:"button",className:"video-load",onClick:()=>{I(h),D.current=setTimeout(()=>A(!0),12e3)},children:s("加载视频")}),
25
+ /* @__PURE__ */t("span",{className:"small muted",children:g?E?s("点击后连接 {0} 播放器",{0:v}):s("当前栏宽较窄,请在原站观看"):c.t("video.notEnabled")})]}),
26
+ /* @__PURE__ */e("div",{className:"video-footer",children:[
27
+ /* @__PURE__ */t("span",{className:"small muted",children:s(F?P?"加载较慢,可在原站观看":"无法播放时可在原站观看":"外部视频")}),
28
+ /* @__PURE__ */t("a",{href:h,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:s("在原站打开 ↗")})]})]}):/* @__PURE__ */t("p",{className:"muted",children:s("视频地址无效,请重新插入。")})})}function TopicLabel({topic:e}){const r=n().text;/* @__PURE__ */
29
+ return t("span",{children:(e.runs??[{text:e.text||r("未命名主题")}]).map((e,r)=>{var n,i,a,l;let o=e.text;for(const r of e.marks??[])if("bold"===r.type)o=/* @__PURE__ */t("strong",{children:o});else if("italic"===r.type)o=/* @__PURE__ */t("em",{children:o});else if("strike"===r.type)o=/* @__PURE__ */t("s",{children:o});else if("link"===r.type)o=/* @__PURE__ */t("a",{href:g(null==(n=r.attrs)?void 0:n.href),target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:o});else if("textStyle"===r.type||"highlight"===r.type){const e=w("highlight"===r.type?"highlight":"text",null==(i=r.attrs)?void 0:i.color),n="highlight"===r.type?{backgroundColor:null==(a=e.style)?void 0:a.slice(e.style.indexOf(":")+1).trim()}:{color:null==(l=e.style)?void 0:l.slice(e.style.indexOf(":")+1).trim()};o=/* @__PURE__ */t("span",{style:n,children:o})}/* @__PURE__ */
30
+ return t(p,{children:o},r)})})}let A;T((e,t)=>{if("undefined"==typeof document)return null;if(A??(A=document.createElement("canvas").getContext("2d")),!A)return null;const r=A,n=`${t} ${e}px ${P}`;return e=>(r.font=n,r.measureText(e).width)});export{AttachmentImage as A,FileView as F,ImagePreview as I,MathView as M,TopicLabel as T,VideoView as V,previewItemsFrom as p};
@@ -1,47 +1 @@
1
- "use client";
2
- const ANCHORED_POPOVER_GAP = 8;
3
- const ANCHORED_POPOVER_VIEW_MARGIN = 8;
4
- const ANCHORED_POPOVER_ARROW_INSET = 14;
5
- function placeAnchoredPopover(input) {
6
- const { align, prefer, anchor, host, card, bounds } = input;
7
- const gap = input.gap ?? ANCHORED_POPOVER_GAP;
8
- const margin = ANCHORED_POPOVER_VIEW_MARGIN;
9
- const anchorLeft = host.left + anchor.left;
10
- const anchorTop = host.top + anchor.top;
11
- const anchorBottom = anchorTop + anchor.height;
12
- const anchorCenter = anchorLeft + anchor.width / 2;
13
- const preferredLeft = align === "center" ? anchorCenter - card.width / 2 : anchorLeft;
14
- const minLeft = bounds.left + margin;
15
- const maxLeft = Math.max(minLeft, bounds.left + bounds.width - margin - card.width);
16
- const left = Math.min(Math.max(preferredLeft, minLeft), maxLeft);
17
- const minTop = bounds.top + margin;
18
- const maxTop = Math.max(minTop, bounds.top + bounds.height - margin - card.height);
19
- const above = anchorTop - gap - card.height;
20
- const below = anchorBottom + gap;
21
- const fitsAbove = above >= minTop;
22
- const fitsBelow = below + card.height <= bounds.top + bounds.height - margin;
23
- let side = prefer === "above" ? fitsAbove ? "above" : "below" : fitsBelow ? "below" : "above";
24
- if (side === "below" && !fitsBelow && fitsAbove) {
25
- side = "above";
26
- } else if (side === "above" && !fitsAbove && fitsBelow) {
27
- side = "below";
28
- }
29
- const top = Math.min(Math.max(side === "above" ? above : below, minTop), maxTop);
30
- const arrowLeft = Math.min(
31
- Math.max(anchorCenter - left, ANCHORED_POPOVER_ARROW_INSET),
32
- Math.max(ANCHORED_POPOVER_ARROW_INSET, card.width - ANCHORED_POPOVER_ARROW_INSET)
33
- );
34
- return {
35
- left: left - host.left,
36
- top: top - host.top,
37
- side,
38
- arrowLeft,
39
- arrowShift: arrowLeft - card.width / 2
40
- };
41
- }
42
- export {
43
- ANCHORED_POPOVER_ARROW_INSET as A,
44
- ANCHORED_POPOVER_GAP as a,
45
- ANCHORED_POPOVER_VIEW_MARGIN as b,
46
- placeAnchoredPopover as p
47
- };
1
+ "use client";const t=8,e=8,a=14;function placeAnchoredPopover(t){const{align:e,prefer:a,anchor:o,host:h,card:i,bounds:n}=t,r=t.gap??8,l=h.left+o.left,p=h.top+o.top,b=p+o.height,c=l+o.width/2,w="center"===e?c-i.width/2:l,d=n.left+8,s=Math.max(d,n.left+n.width-8-i.width),f=Math.min(Math.max(w,d),s),m=n.top+8,M=Math.max(m,n.top+n.height-8-i.height),g=p-r-i.height,v=b+r,x=g>=m,u=v+i.height<=n.top+n.height-8;let A="above"===a?x?"above":"below":u?"below":"above";"below"===A&&!u&&x?A="above":"above"===A&&!x&&u&&(A="below");const P=Math.min(Math.max("above"===A?g:v,m),M),L=Math.min(Math.max(c-f,14),Math.max(14,i.width-14));return{left:f-h.left,top:P-h.top,side:A,arrowLeft:L,arrowShift:L-i.width/2}}export{a as A,t as a,e as b,placeAnchoredPopover as p};
@@ -0,0 +1 @@
1
+ "use client";import{createUniver as e,LocaleType as s,mergeLocales as t,CommandType as r}from"@univerjs/presets";import{UniverSheetsCorePreset as o}from"@univerjs/preset-sheets-core";import i from"@univerjs/preset-sheets-core/locales/zh-CN";import{UniverSheetsFilterPreset as l}from"@univerjs/preset-sheets-filter";import n from"@univerjs/preset-sheets-filter/locales/zh-CN";import{UniverSheetsSortPreset as a}from"@univerjs/preset-sheets-sort";import c from"@univerjs/preset-sheets-sort/locales/zh-CN";import"@univerjs/preset-sheets-core/lib/index.css";import"@univerjs/preset-sheets-filter/lib/index.css";import"@univerjs/preset-sheets-sort/lib/index.css";import{sanitizeNonFiniteNumbers as p}from"wendang/internal/workbook";function snapshotWorkbook(e){const{value:s,dropped:t}=p(e);if(t.length){const e=t.filter(e=>e.includes(".cellData."));console.warn(`[wendang] 工作表快照含 ${t.length} 处非有限数值,已清洗(内容字段 ${e.length} 处)`,t.slice(0,10))}return s}function editKey(e){return JSON.stringify(e,(e,s)=>"cellData"===e?Object.fromEntries(Object.entries(s??{}).map(([e,s])=>[e,Object.fromEntries(Object.entries(s).map(([e,s])=>{const t=s;if(!(null==t?void 0:t.f))return[e,t];const{v:r,t:o,...i}=t;return[e,i]}))])):s)}const u={"zh-TW":()=>Promise.all([import("@univerjs/preset-sheets-core/locales/zh-TW"),import("@univerjs/preset-sheets-filter/locales/zh-TW"),import("@univerjs/preset-sheets-sort/locales/zh-TW")]),"en-US":()=>Promise.all([import("@univerjs/preset-sheets-core/locales/en-US"),import("@univerjs/preset-sheets-filter/locales/en-US"),import("@univerjs/preset-sheets-sort/locales/en-US")]),"ja-JP":()=>Promise.all([import("@univerjs/preset-sheets-core/locales/ja-JP"),import("@univerjs/preset-sheets-filter/locales/ja-JP"),import("@univerjs/preset-sheets-sort/locales/ja-JP")]),"ko-KR":()=>Promise.all([import("@univerjs/preset-sheets-core/locales/ko-KR"),import("@univerjs/preset-sheets-filter/locales/ko-KR"),import("@univerjs/preset-sheets-sort/locales/ko-KR")]),"es-ES":()=>Promise.all([import("@univerjs/preset-sheets-core/locales/es-ES"),import("@univerjs/preset-sheets-filter/locales/es-ES"),import("@univerjs/preset-sheets-sort/locales/es-ES")])},d={"zh-CN":s.ZH_CN,"zh-TW":s.ZH_TW,"en-US":s.EN_US,"ja-JP":s.JA_JP,"ko-KR":s.KO_KR,"es-ES":s.ES_ES};function createWorksheetEngine(p,h,m,v={}){const{univer:k,univerAPI:f}=e({locale:s.ZH_CN,region:Object.values(s).includes(h.workbook.locale)?h.workbook.locale:s.ZH_CN,darkMode:"dark"===v.theme,locales:{[s.ZH_CN]:t(i,n,c)},presets:[o({container:p,header:!0,ribbonType:"collapsed",footer:{statisticBar:!1,zoomSlider:!1}}),l(),a()]});let j;try{j=f.createWorkbook(h.workbook)}catch(e){throw k.dispose(),e}let E=null,b=0,w=!1;const snapshot=()=>E??(E={type:"workbook",formatVersion:1,workbook:snapshotWorkbook(j.save())});let S=editKey(snapshot()),g=!1,y=!1;const W=f.addEvent(f.Event.SheetEditStarted,()=>{y=!0}),C=f.addEvent(f.Event.SheetEditEnded,()=>{y=!1}),K=f.addEvent(f.Event.CommandExecuted,e=>{if(e.type!==r.MUTATION)return;if(E=null,g||e.id.startsWith("formula."))return;const s=editKey(snapshot());s!==S&&(S=s,m())});return{snapshot:snapshot,setEditable:e=>j.setEditable(e),setTheme:e=>f.toggleDarkMode("dark"===e),async setLocale(e){const r=++b,o=d[e]??s.ZH_CN;if(Object.hasOwn(u,e)){const s=await u[e]();if(w||r!==b)return;f.loadLocales(o,t(...s.map(e=>e.default)))}w||r!==b||f.setLocale(o)},isEditing:()=>y,async finishEditing(){await j.endEditingAsync(!0),await f.getFormula().onCalculationResultApplied(15e3),E=null},async settleCalculation(){await f.getFormula().onCalculationResultApplied(15e3),E=null},replace(e){g=!0;const s=snapshot();try{f.disposeUnit(j.getId()),j=f.createWorkbook(e.workbook),E=null,S=editKey(snapshot())}catch(e){throw j=f.createWorkbook(s.workbook),E=null,S=editKey(snapshot()),e}finally{g=!1}},dispose(){w=!0,b++,K.dispose(),W.dispose(),C.dispose(),k.dispose()}}}export{createWorksheetEngine};
@@ -1,129 +1 @@
1
- "use client";
2
- import { format } from "numfmt";
3
- function cellStyleData(doc, sheet, r, c) {
4
- var _a, _b, _c, _d, _e, _f, _g;
5
- const resolve = (raw) => {
6
- var _a2;
7
- const value = typeof raw === "string" ? (_a2 = doc.workbook.styles) == null ? void 0 : _a2[raw] : raw;
8
- return value && typeof value === "object" && !Array.isArray(value) ? value : {};
9
- };
10
- return {
11
- ...resolve(sheet.defaultStyle),
12
- ...resolve((_b = (_a = sheet.columnData) == null ? void 0 : _a[c]) == null ? void 0 : _b.s),
13
- ...resolve((_d = (_c = sheet.rowData) == null ? void 0 : _c[r]) == null ? void 0 : _d.s),
14
- ...resolve((_g = (_f = (_e = sheet.cellData) == null ? void 0 : _e[r]) == null ? void 0 : _f[c]) == null ? void 0 : _g.s)
15
- };
16
- }
17
- function cellDisplay(cell, style = {}) {
18
- var _a, _b, _c;
19
- if (!cell) return { text: "" };
20
- if (cell.f && (cell.v === void 0 || cell.v === null)) return { text: "待计算", note: `缺少已保存结果:${cell.f}` };
21
- if ((_b = (_a = cell.p) == null ? void 0 : _a.body) == null ? void 0 : _b.dataStream) return { text: cell.p.body.dataStream.replace(/[\r\n]+$/, "") };
22
- if (cell.v === void 0 || cell.v === null) return { text: "" };
23
- if (cell.t === 4) return { text: String(cell.v), note: "公式或单元格错误" };
24
- if (typeof cell.v === "boolean") return { text: cell.v ? "TRUE" : "FALSE" };
25
- const pattern = (_c = style.n) == null ? void 0 : _c.pattern;
26
- if (typeof pattern === "string" && pattern.length <= 1e3) {
27
- try {
28
- return { text: format(pattern, cell.v, { throws: true }) };
29
- } catch {
30
- return { text: String(cell.v), note: "此数字格式暂不支持,当前显示原始值" };
31
- }
32
- }
33
- return { text: String(cell.v) };
34
- }
35
- function safeColor(value) {
36
- const rgb = value && typeof value === "object" ? value.rgb : void 0;
37
- return typeof rgb === "string" && /^#[\da-f]{6}$/i.test(rgb) ? rgb : void 0;
38
- }
39
- const FILTER_RESOURCE = "SHEET_FILTER_PLUGIN";
40
- function workbookFilters(doc) {
41
- const resources = doc.workbook.resources;
42
- if (!Array.isArray(resources)) return {};
43
- const resource = resources.find((item) => (item == null ? void 0 : item.name) === FILTER_RESOURCE);
44
- try {
45
- const parsed = JSON.parse(typeof (resource == null ? void 0 : resource.data) === "string" ? resource.data : "{}");
46
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
47
- const valid = {};
48
- for (const id of doc.workbook.sheetOrder) {
49
- const raw = parsed[id], sheet = doc.workbook.sheets[id], ref = raw == null ? void 0 : raw.ref;
50
- if (!ref || ![ref.startRow, ref.endRow, ref.startColumn, ref.endColumn].every(Number.isInteger) || ref.startRow < 0 || ref.endRow < ref.startRow || ref.endRow >= sheet.rowCount || ref.startColumn < 0 || ref.endColumn < ref.startColumn || ref.endColumn >= sheet.columnCount) continue;
51
- valid[id] = {
52
- ref,
53
- cachedFilteredOut: Array.isArray(raw.cachedFilteredOut) ? raw.cachedFilteredOut.filter((r) => typeof r === "number" && Number.isInteger(r) && r >= 0 && r < sheet.rowCount) : [],
54
- filterColumns: Array.isArray(raw.filterColumns) ? raw.filterColumns : []
55
- };
56
- }
57
- return valid;
58
- } catch {
59
- return {};
60
- }
61
- }
62
- function dateSerial(value) {
63
- const days = (value.getTime() - Date.UTC(1899, 11, 31)) / 864e5;
64
- return days >= 60 ? days + 1 : days;
65
- }
66
- function columnName(index) {
67
- let name = "", n = index + 1;
68
- while (n > 0) {
69
- name = String.fromCharCode(65 + (n - 1) % 26) + name;
70
- n = Math.floor((n - 1) / 26);
71
- }
72
- return name;
73
- }
74
- function previewAxes(doc, sheet, showAll) {
75
- const filter = workbookFilters(doc)[sheet.id];
76
- const filtered = new Set(Array.isArray(filter == null ? void 0 : filter.cachedFilteredOut) ? filter.cachedFilteredOut : []);
77
- const populated = Object.keys(sheet.cellData ?? {}).map(Number);
78
- const used = Math.max(
79
- 20,
80
- ...populated.map((r) => r + 1),
81
- ...Object.keys(sheet.rowData ?? {}).map((r) => Number(r) + 1),
82
- ...(sheet.mergeData ?? []).map((m) => m.endRow + 1)
83
- );
84
- const rows = Array.from({ length: Math.min(sheet.rowCount, used) }, (_, r) => r).filter((r) => {
85
- var _a, _b;
86
- return showAll || ((_b = (_a = sheet.rowData) == null ? void 0 : _a[r]) == null ? void 0 : _b.hd) !== 1 && !filtered.has(r);
87
- });
88
- const columns = Array.from({ length: sheet.columnCount }, (_, c) => c).filter((c) => {
89
- var _a, _b;
90
- return showAll || ((_b = (_a = sheet.columnData) == null ? void 0 : _a[c]) == null ? void 0 : _b.hd) !== 1;
91
- });
92
- return {
93
- rows,
94
- columns,
95
- filtered: filtered.size,
96
- hasFilter: !!filter,
97
- hasHidden: sheet.hidden === 1 || sheet.hidden === 2 || Object.values(sheet.rowData ?? {}).some((d) => d.hd === 1) || Object.values(sheet.columnData ?? {}).some((d) => d.hd === 1)
98
- };
99
- }
100
- function previewMerges(sheet, rows, columns) {
101
- const result = /* @__PURE__ */ new Map();
102
- if (!rows.length || !columns.length) return result;
103
- for (const merge of sheet.mergeData ?? []) {
104
- if (merge.endRow < rows[0] || merge.startRow > rows[rows.length - 1] || merge.endColumn < columns[0] || merge.startColumn > columns[columns.length - 1]) continue;
105
- const rr = rows.filter((r) => r >= merge.startRow && r <= merge.endRow);
106
- const cc = columns.filter((c) => c >= merge.startColumn && c <= merge.endColumn);
107
- for (const r of rr) for (const c of cc) {
108
- result.set(`${r}:${c}`, {
109
- sourceRow: merge.startRow,
110
- sourceColumn: merge.startColumn,
111
- rowspan: rr.length,
112
- colspan: cc.length,
113
- hidden: r !== rr[0] || c !== cc[0]
114
- });
115
- }
116
- }
117
- return result;
118
- }
119
- export {
120
- FILTER_RESOURCE as F,
121
- previewMerges as a,
122
- cellStyleData as b,
123
- columnName as c,
124
- cellDisplay as d,
125
- dateSerial as e,
126
- previewAxes as p,
127
- safeColor as s,
128
- workbookFilters as w
129
- };
1
+ "use client";import{format as t}from"numfmt";function cellStyleData(t,e,r,o){var n,l,a,u,i,s,d;const resolve=e=>{var r;const o="string"==typeof e?null==(r=t.workbook.styles)?void 0:r[e]:e;return o&&"object"==typeof o&&!Array.isArray(o)?o:{}};return{...resolve(e.defaultStyle),...resolve(null==(l=null==(n=e.columnData)?void 0:n[o])?void 0:l.s),...resolve(null==(u=null==(a=e.rowData)?void 0:a[r])?void 0:u.s),...resolve(null==(d=null==(s=null==(i=e.cellData)?void 0:i[r])?void 0:s[o])?void 0:d.s)}}function cellDisplay(e,r={}){var o,n,l;if(!e)return{text:""};if(e.f&&(void 0===e.v||null===e.v))return{text:"待计算",note:`缺少已保存结果:${e.f}`};if(null==(n=null==(o=e.p)?void 0:o.body)?void 0:n.dataStream)return{text:e.p.body.dataStream.replace(/[\r\n]+$/,"")};if(void 0===e.v||null===e.v)return{text:""};if(4===e.t)return{text:String(e.v),note:"公式或单元格错误"};if("boolean"==typeof e.v)return{text:e.v?"TRUE":"FALSE"};const a=null==(l=r.n)?void 0:l.pattern;if("string"==typeof a&&a.length<=1e3)try{return{text:t(a,e.v,{throws:!0})}}catch{return{text:String(e.v),note:"此数字格式暂不支持,当前显示原始值"}}return{text:String(e.v)}}function safeColor(t){const e=t&&"object"==typeof t?t.rgb:void 0;return"string"==typeof e&&/^#[\da-f]{6}$/i.test(e)?e:void 0}const e="SHEET_FILTER_PLUGIN";function workbookFilters(t){const r=t.workbook.resources;if(!Array.isArray(r))return{};const o=r.find(t=>(null==t?void 0:t.name)===e);try{const e=JSON.parse("string"==typeof(null==o?void 0:o.data)?o.data:"{}");if(!e||"object"!=typeof e||Array.isArray(e))return{};const r={};for(const o of t.workbook.sheetOrder){const n=e[o],l=t.workbook.sheets[o],a=null==n?void 0:n.ref;!a||![a.startRow,a.endRow,a.startColumn,a.endColumn].every(Number.isInteger)||a.startRow<0||a.endRow<a.startRow||a.endRow>=l.rowCount||a.startColumn<0||a.endColumn<a.startColumn||a.endColumn>=l.columnCount||(r[o]={ref:a,cachedFilteredOut:Array.isArray(n.cachedFilteredOut)?n.cachedFilteredOut.filter(t=>"number"==typeof t&&Number.isInteger(t)&&t>=0&&t<l.rowCount):[],filterColumns:Array.isArray(n.filterColumns)?n.filterColumns:[]})}return r}catch{return{}}}function dateSerial(t){const e=(t.getTime()-Date.UTC(1899,11,31))/864e5;return e>=60?e+1:e}function columnName(t){let e="",r=t+1;for(;r>0;)e=String.fromCharCode(65+(r-1)%26)+e,r=Math.floor((r-1)/26);return e}function previewAxes(t,e,r){const o=workbookFilters(t)[e.id],n=new Set(Array.isArray(null==o?void 0:o.cachedFilteredOut)?o.cachedFilteredOut:[]),l=Object.keys(e.cellData??{}).map(Number),a=Math.max(20,...l.map(t=>t+1),...Object.keys(e.rowData??{}).map(t=>Number(t)+1),...(e.mergeData??[]).map(t=>t.endRow+1));return{rows:Array.from({length:Math.min(e.rowCount,a)},(t,e)=>e).filter(t=>{var o,l;return r||1!==(null==(l=null==(o=e.rowData)?void 0:o[t])?void 0:l.hd)&&!n.has(t)}),columns:Array.from({length:e.columnCount},(t,e)=>e).filter(t=>{var o,n;return r||1!==(null==(n=null==(o=e.columnData)?void 0:o[t])?void 0:n.hd)}),filtered:n.size,hasFilter:!!o,hasHidden:1===e.hidden||2===e.hidden||Object.values(e.rowData??{}).some(t=>1===t.hd)||Object.values(e.columnData??{}).some(t=>1===t.hd)}}function previewMerges(t,e,r){const o=/* @__PURE__ */new Map;if(!e.length||!r.length)return o;for(const n of t.mergeData??[]){if(n.endRow<e[0]||n.startRow>e[e.length-1]||n.endColumn<r[0]||n.startColumn>r[r.length-1])continue;const t=e.filter(t=>t>=n.startRow&&t<=n.endRow),l=r.filter(t=>t>=n.startColumn&&t<=n.endColumn);for(const e of t)for(const r of l)o.set(`${e}:${r}`,{sourceRow:n.startRow,sourceColumn:n.startColumn,rowspan:t.length,colspan:l.length,hidden:e!==t[0]||r!==l[0]})}return o}export{e as F,previewMerges as a,cellStyleData as b,columnName as c,cellDisplay as d,dateSerial as e,previewAxes as p,safeColor as s,workbookFilters as w};