wendang-react 0.6.4 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +1 -1
- package/README.md +28 -1
- package/dist/bindings/yjs.js +1 -1
- package/dist/chunks/{MindMapCanvas-CVXQXNOg.js → MindMapCanvas-BA3FYy8p.js} +1 -1
- package/dist/chunks/{MindMapViewer-BI8zbQM1.js → MindMapViewer-B1_uaMHB.js} +7 -7
- package/dist/chunks/{extensions-C1fCBnEs.js → extensions-D4JlN-IP.js} +16 -14
- package/dist/chunks/mind-map-defaults-B9SSENmK.js +1 -0
- package/dist/chunks/{mind-topic-text-Bn1waxff.js → mind-topic-text-C7pIS6L9.js} +14 -15
- package/dist/chunks/worksheet-engine-Dz6P8Kiq.js +1 -0
- package/dist/document/viewer.js +4 -4
- package/dist/document.js +67 -74
- package/dist/mindmap/viewer.js +1 -1
- package/dist/mindmap.js +3 -3
- package/dist/spreadsheet.js +1 -1
- package/dist/styles/tokens.css +1 -1
- package/dist/styles/video-embed.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/types/engine/editor/video-block-controls.d.ts +13 -0
- package/dist/types/engine/shared/color-preview.d.ts +1 -0
- package/dist/types/engine/shared/mind-map-defaults.d.ts +3 -0
- package/dist/types/renderer/media.d.ts +2 -1
- package/integrity.json +58 -43
- package/package.json +3 -3
- package/dist/chunks/mind-map-controller-Ce76mETT.js +0 -1
- package/dist/chunks/worksheet-engine-c84sdD4N.js +0 -1
- /package/third-party-notices/{wendang-export@0.6.3-LICENSE.txt → wendang-export@0.6.5-LICENSE.txt} +0 -0
- /package/third-party-notices/{wendang-export@0.6.3-NOTICE.md.txt → wendang-export@0.6.5-NOTICE.md.txt} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use client";import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{c as
|
|
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(${
|
|
1
|
+
"use client";import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{c as i,a as n,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 b}from"wendang/shared";import{normalizeVideoEmbed as w,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 P,MIND_TOPIC_FONT as T}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 i=Array.from(r.querySelectorAll("img")).filter(e=>e instanceof HTMLImageElement&&!!e.getAttribute("src"));if(0===i.length)return{items:[],index:0};const n=i.indexOf(e);return n<0?lonely():{items:i.map(e=>({src:e.getAttribute("src")??"",label:e.getAttribute("alt")||t})),index:n}}function stepPreviewIndex(e,t,r){if(!Number.isFinite(e)||t<=0)return 0;const i=e+(Number.isFinite(r)?r:0);return Math.max(0,Math.min(t-1,Math.round(i)))}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=i().text,p=a??s("图片预览"),{portal:h}=n(),[v,f]=d(o),[g,b]=d(1),[w,y]=d(0),[x,k]=d({x:0,y:0}),[N,P]=d(!1),T=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(){b(1),y(0),k({x:0,y:0})}function zoomBy(e){b(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,P(!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()):T.current&&E(T.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=T.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:T,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(${w}deg)`},onPointerDown:e=>{var t,r;0===e.button&&(L.current={x:e.clientX,y:e.clientY,ox:x.x,oy:x.y},P(!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
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
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
5
|
/* @__PURE__ */e("div",{className:"img-preview-toolbar",role:"toolbar","aria-label":s("图片预览操作"),children:[
|
|
@@ -11,21 +11,20 @@
|
|
|
11
11
|
/* @__PURE__ */t("button",{type:"button","aria-label":s("向右旋转"),title:s("向右旋转"),onClick:()=>y(e=>e+90),children:"↻"}),
|
|
12
12
|
/* @__PURE__ */t("span",{className:"img-preview-divider"}),
|
|
13
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:
|
|
14
|
+
/* @__PURE__ */t("button",{type:"button","aria-label":s("关闭预览"),title:s("关闭(Esc)"),onClick:c,children:s("关闭")})]})]}),h):null}function AttachmentImage({id:n,alt:l="",width:s,fetcher:p,src:v,align:f,aspectRatio:b,galleryScale:w,className:y=""}){var x;const k=i().text,N=a(),C=u(null),[I,E]=d({id:"",url:"",failed:!1}),[P,T]=d(null);m(()=>{E({id:n??"",url:"",failed:!1});const e=C.current;if(!n||!e)return;let t,r=!0;const i=h(e,()=>{var e;t=o(n,e=>{r&&E({id:n,url:e,failed:!1})},p??(null==(e=N.attachments)?void 0:e.fetch)??c,()=>{r&&E({id:n,url:"",failed:!0})},N.scope)});return()=>{r=!1,i(),null==t||t()}},[n,p,null==(x=N.attachments)?void 0:x.fetch,N.scope]);const A=n?I.id===n?I.url:"":g(v),L=I.id===(n??"")&&I.failed;function open(e){A&&!L&&T(previewItemsFrom(e,l||k("图片预览")))}/* @__PURE__ */
|
|
15
15
|
return e(r,{children:[
|
|
16
|
-
/* @__PURE__ */t("img",{ref:C,className:"doc-image"+(y?` ${y}`:""),"data-attachment-id":
|
|
17
|
-
return t("div",{ref:v,className:"doc-file-video",children:w
|
|
16
|
+
/* @__PURE__ */t("img",{ref:C,className:"doc-image"+(y?` ${y}`:""),"data-attachment-id":n,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":b&&b>0?b:void 0,"data-gallery-scale":w&&1!==w?w:void 0,"data-loading":A||L?void 0:"true","data-image-error":L?"true":void 0,style:{...s?{width:`${s}px`}:{},...b&&b>0?{"--doc-image-aspect-ratio":String(b)}:{},...w&&w>0&&1!==w?{"--doc-image-weight":String(w)}:{}},tabIndex:0,onError:()=>E(e=>({...e,failed:!0})),onClick:e=>open(e.currentTarget),onKeyDown:e=>{"Enter"===e.key&&open(e.currentTarget)}}),P&&/* @__PURE__ */t(ImagePreview,{src:A,label:l||k("图片预览"),items:P.items,index:P.index,onClose:()=>T(null)})]})}function MathView({latex:e,block:r=!1}){const n=i().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?n("公式错误:{0}",{0:e}):e})}function FileVideo({id:e,mimeType:r,fetcher:n}){var l;const s=i().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 i=h(v.current,()=>{var i;t=o(e,t=>{r&&g({id:e,url:t,failed:!1})},n??(null==(i=p.attachments)?void 0:i.fetch)??c,()=>{r&&g({id:e,url:"",failed:!0})},p.scope)});return()=>{r=!1,i(),null==t||t()}},[e,n,null==(l=p.attachments)?void 0:l.fetch,p.scope]);const b=f.id===e?f.url:"",w=f.id===e&&f.failed;/* @__PURE__ */
|
|
17
|
+
return t("div",{ref:v,className:"doc-file-video",children:b&&!w?/* @__PURE__ */t("video",{src:b,controls:!0,preload:"metadata",onError:()=>g(e=>({...e,failed:!0})),children:/* @__PURE__ */t("source",{src:b,type:r})}):/* @__PURE__ */t("p",{className:"doc-file-video-fallback",children:s(w?"视频加载失败。":"视频加载中…")})})}function FileView({id:r,filename:n,mimeType:o="",size:p=0,fetcher:h,allowExport:v=!1}){const f=i().text,g=a(),[b,w]=d(""),[y,x]=d(!1),k=u(v),N=u(!0);return k.current=v,m(()=>(N.current=!0,()=>{N.current=!1}),[]),m(()=>{w("")},[r]),r?/* @__PURE__ */e("div",{className:"doc-file",children:[
|
|
18
18
|
/* @__PURE__ */e("div",{className:"doc-file-head",children:[
|
|
19
19
|
/* @__PURE__ */t("span",{className:"doc-file-icon",children:o.startsWith("video/")?"▶":o.startsWith("image/")?"🖼":"📎"}),
|
|
20
|
-
/* @__PURE__ */t("span",{className:"doc-file-name",title:
|
|
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),
|
|
22
|
-
return t("section",{ref:A,className:"doc-video-embed",contentEditable:!1,"aria-label":c("{0} 视频",{0:h}),children:s?/* @__PURE__ */e(r,{children:[D&&I&&f?/* @__PURE__ */t("iframe",{src:N(s),title:c("{0} 视频 {1}",{0:h,1:s.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(L.current),T(!1)}}):/* @__PURE__ */e("div",{className:"video-placeholder",children:[
|
|
20
|
+
/* @__PURE__ */t("span",{className:"doc-file-name",title:n,children:n}),
|
|
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),w("");try{await s(r,n,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&&w(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:n,fetcher:h,className:"doc-file-image"}):null,b&&/* @__PURE__ */t("p",{role:"alert",className:"doc-file-video-fallback",children:b})]}):/* @__PURE__ */t("div",{className:"doc-file is-missing",children:f("[附件缺失]")})}function VideoView({attrs:a,reloadKey:l=0}){var o;const c=i(),s=c.text,p=w(a),h=p?y(p):"",v=s(p?x[p.provider]:"外部"),f=n().video,g=!!p&&((null==(o=null==f?void 0:f.providers)?void 0:o.includes(p.provider))??!0),b=k(p,f),[C,I]=d(""),[E,P]=d(!0),[T,A]=d(!1),L=u(null),D=u(void 0);m(()=>{if(!L.current||"undefined"==typeof ResizeObserver)return;const e=new ResizeObserver(([e])=>P(e.contentRect.width>=200));return e.observe(L.current),()=>e.disconnect()},[]),m(()=>(I(""),A(!1),clearTimeout(D.current),h&&E&&g&&b&&(I(h),D.current=setTimeout(()=>A(!0),12e3)),()=>clearTimeout(D.current)),[h,E,g,b]);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",referrerPolicy:"strict-origin-when-cross-origin",onLoad:()=>{clearTimeout(D.current),A(!1)}},l):/* @__PURE__ */e("div",{className:"video-placeholder",children:[
|
|
23
22
|
/* @__PURE__ */t("span",{className:"video-play-icon","aria-hidden":"true",children:"▶"}),
|
|
24
|
-
/* @__PURE__ */e("strong",{children:[
|
|
25
|
-
/* @__PURE__ */t("span",{className:"video-id",children:
|
|
26
|
-
/* @__PURE__ */t("span",{className:"small muted",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")})]}),
|
|
27
26
|
/* @__PURE__ */e("div",{className:"video-footer",children:[
|
|
28
|
-
/* @__PURE__ */t("span",{className:"small muted",children:
|
|
29
|
-
/* @__PURE__ */t("a",{href:
|
|
30
|
-
return t("span",{children:(e.runs??[{text:e.text||r("未命名主题")}]).map((e,r)=>{var n,
|
|
31
|
-
return t(p,{children:o},r)})})}let A;P((e,t)=>{if("undefined"==typeof document)return null;if(A??(A=document.createElement("canvas").getContext("2d")),!A)return null;const r=A,
|
|
27
|
+
/* @__PURE__ */t("span",{className:"small muted",children:F?T?s("加载较慢,可在原站观看"):"bilibili"===p.provider?c.t("video.bilibiliPlayHint"):s("无法播放时可在原站观看"):s("外部视频")}),
|
|
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=i().text;/* @__PURE__ */
|
|
29
|
+
return t("span",{children:(e.runs??[{text:e.text||r("未命名主题")}]).map((e,r)=>{var i,n,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==(i=r.attrs)?void 0:i.href),target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:o});else if("textStyle"===r.type||"highlight"===r.type){const e=b("highlight"===r.type?"highlight":"text",null==(n=r.attrs)?void 0:n.color),i="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:i,children:o})}/* @__PURE__ */
|
|
30
|
+
return t(p,{children:o},r)})})}let A;P((e,t)=>{if("undefined"==typeof document)return null;if(A??(A=document.createElement("canvas").getContext("2d")),!A)return null;const r=A,i=`${t} ${e}px ${T}`;return e=>(r.font=i,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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{createUniver as e,LocaleType as t,mergeLocales as s,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 n}from"@univerjs/preset-sheets-filter";import l 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:t,dropped:s}=p(e);if(s.length){const e=s.filter(e=>e.includes(".cellData."));console.warn(`[wendang] 工作表快照含 ${s.length} 处非有限数值,已清洗(内容字段 ${e.length} 处)`,s.slice(0,10))}return t}function editKey(e){return JSON.stringify(e,(e,t)=>"cellData"===e?Object.fromEntries(Object.entries(t??{}).map(([e,t])=>[e,Object.fromEntries(Object.entries(t).map(([e,t])=>{const s=t;if(!(null==s?void 0:s.f))return[e,s];const{v:r,t:o,...i}=s;return[e,i]}))])):t)}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":t.ZH_CN,"zh-TW":t.ZH_TW,"en-US":t.EN_US,"ja-JP":t.JA_JP,"ko-KR":t.KO_KR,"es-ES":t.ES_ES};function createWorksheetEngine(p,m,h,v={}){const{univer:k,univerAPI:f}=e({locale:t.ZH_CN,region:Object.values(t).includes(m.workbook.locale)?m.workbook.locale:t.ZH_CN,darkMode:"dark"===v.theme,locales:{[t.ZH_CN]:s(i,l,c)},presets:[o({container:p,header:!0,ribbonType:"collapsed",menu:{"ribbon.start.number":{order:1.5}},footer:{statisticBar:!1,zoomSlider:!1}}),n(),a()]});let j;try{j=f.createWorkbook(m.workbook)}catch(e){throw k.dispose(),e}let b=null,E=0,w=!1;const snapshot=()=>b??(b={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(b=null,g||e.id.startsWith("formula."))return;const t=editKey(snapshot());t!==S&&(S=t,h())});return{snapshot:snapshot,setEditable:e=>j.setEditable(e),setTheme:e=>f.toggleDarkMode("dark"===e),async setLocale(e){const r=++E,o=d[e]??t.ZH_CN;if(Object.hasOwn(u,e)){const t=await u[e]();if(w||r!==E)return;f.loadLocales(o,s(...t.map(e=>e.default)))}w||r!==E||f.setLocale(o)},isEditing:()=>y,async finishEditing(){await j.endEditingAsync(!0),await f.getFormula().onCalculationResultApplied(15e3),b=null},async settleCalculation(){await f.getFormula().onCalculationResultApplied(15e3),b=null},replace(e){g=!0;const t=snapshot();try{f.disposeUnit(j.getId()),j=f.createWorkbook(e.workbook),b=null,S=editKey(snapshot())}catch(e){throw j=f.createWorkbook(t.workbook),b=null,S=editKey(snapshot()),e}finally{g=!1}},dispose(){w=!0,E++,K.dispose(),W.dispose(),C.dispose(),k.dispose()}}}export{createWorksheetEngine};
|
package/dist/document/viewer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use client";import{jsx as e,jsxs as t}from"react/jsx-runtime";import{c as n,b as r}from"../chunks/i18n-B0kCsIjc.js";import{useEffect as a,createElement as i,Fragment as l,useState as c}from"react";import{resolveInlineComments as o,splitTextByMarks as s,safeHref as d,documentColorAttributes as m,effectiveCallout as h,calloutDOMAttributes as u,cellBackground as p,tableColumnWidths as g,tableMinWidth as f}from"wendang/shared";import{readMindMap as k}from"wendang/mindmap";import{isWorkbookDocument as y}from"wendang/spreadsheet";import{M as
|
|
1
|
+
"use client";import{jsx as e,jsxs as t}from"react/jsx-runtime";import{c as n,b as r}from"../chunks/i18n-B0kCsIjc.js";import{useEffect as a,createElement as i,Fragment as l,useState as c}from"react";import{resolveInlineComments as o,splitTextByMarks as s,safeHref as d,documentColorAttributes as m,effectiveCallout as h,calloutDOMAttributes as u,cellBackground as p,tableColumnWidths as g,tableMinWidth as f}from"wendang/shared";import{readMindMap as k}from"wendang/mindmap";import{isWorkbookDocument as y}from"wendang/spreadsheet";import{M as v,V as x,F as b,A as w}from"../chunks/mind-topic-text-C7pIS6L9.js";import{M as N}from"../chunks/MindMapViewer-B1_uaMHB.js";import{S as C}from"../chunks/SpreadsheetViewer-CoQ4VIgj.js";import{e as M,c as S}from"../chunks/code-highlight-BmaqTe1m.js";import{h as I,s as j,C as E}from"../chunks/comment-hint-BhUxKjKK.js";import{codeBlockDisplay as B,codeLineNumbers as T,codeBlockClass as V}from"wendang/internal/code-block";import{D as L}from"../chunks/DocumentExportMenu-CUMsgq3w.js";function CommentText({marks:t,activeId:r,onMarkClick:a,children:i}){return n().text,/* @__PURE__ */e("span",{className:["doc-inline-comment",t.some(e=>"shifted"===e.state)?"is-shifted":"",t.some(e=>e.hasReplies)?"has-replies":"",t.some(e=>e.commentId===r)?"is-active":""].filter(Boolean).join(" "),"data-comment-id":t[0].commentId,"data-comment-ids":t.map(e=>e.commentId).join(" "),"data-comment-hint":"点击查看该处讨论",onMouseEnter:e=>j(e.currentTarget,"点击查看该处讨论"),onMouseLeave:()=>I(),onClick:e=>{e.stopPropagation(),I(),null==a||a(t[0].commentId)},children:i})}function CodeView({text:r,language:i,allowExport:l,marks:o,activeId:d,onMarkClick:m}){const h=n().text,[,u]=c(0),[p,g]=c(B);a(()=>{let e=!0;return M().then(()=>{e&&u(e=>e+1)}),()=>{e=!1}},[r,i]);const f=S(r,i);let k=0;const y=s(r,o).map((t,n)=>{const a=k;k+=t.text.length;const i=function syntaxText(t,n){const a=[];let i=t;for(const l of f){const c=Math.max(t,l.from),o=Math.min(n,l.to);c>=o||(c>i&&a.push(r.slice(i,c)),a.push(/* @__PURE__ */e("span",{className:l.classes,children:r.slice(c,o)},c)),i=o)}return i<n&&a.push(r.slice(i,n)),a}(a,k);return t.marks.length?/* @__PURE__ */e(CommentText,{marks:t.marks,activeId:d,onMarkClick:m,children:i},n):/* @__PURE__ */e("span",{children:i},n)});/* @__PURE__ */
|
|
2
2
|
return t("div",{className:["doc-code-wrap",...V(p)].join(" "),children:[
|
|
3
3
|
/* @__PURE__ */e(E,{text:r,language:i,editable:!1,canCopy:!!l,display:p,onLanguage:()=>{},onDisplay:g}),
|
|
4
4
|
/* @__PURE__ */t("div",{className:"code-scroll",hidden:p.collapsed,tabIndex:0,"aria-label":h("代码内容"),children:[p.lineNumbers&&/* @__PURE__ */e("div",{className:"code-line-numbers","aria-hidden":"true",children:T(r)}),
|
|
@@ -20,11 +20,11 @@ return e("tr",{children:children(n)});case"tableCell":case"tableHeader":return i
|
|
|
20
20
|
/* @__PURE__ */e("figcaption",{className:"doc-image-caption",title:o,children:o})]}):l}case"imageGallery":/* @__PURE__ */
|
|
21
21
|
return e("div",{className:"doc-image-gallery","data-image-gallery":"true",style:{"--image-gallery-height":`${Math.min(480,Math.max(72,Number(M.height)||120))}px`},children:children(n,!0)});case"fileAttachment":/* @__PURE__ */
|
|
22
22
|
return e(b,{id:String(M.attachmentId??""),filename:String(M.filename??S("附件")),mimeType:String(M.mimeType??""),size:Number(M.size)||0,fetcher:c.attachmentFetcher,allowExport:c.allowExport});case"videoEmbed":/* @__PURE__ */
|
|
23
|
-
return e(
|
|
24
|
-
return e(
|
|
23
|
+
return e(x,{attrs:M});case"mathInline":case"mathBlock":/* @__PURE__ */
|
|
24
|
+
return e(v,{latex:String(M.latex??""),block:"mathBlock"===n.type});case"callout":{const{icon:r}=h(M),a=u(M);/* @__PURE__ */
|
|
25
25
|
return t("div",{...Object.fromEntries(Object.entries(a).filter(([e])=>"style"!==e)),className:"doc-callout",style:cssStyle(a.style??""),children:[r?/* @__PURE__ */e("span",{className:"callout-icon","aria-hidden":"true","data-callout-decoration":"true",children:r}):null,
|
|
26
26
|
/* @__PURE__ */e("div",{className:"doc-callout-content","data-callout-content":"true",children:children(n)})]})}case"columns":/* @__PURE__ */
|
|
27
27
|
return e("div",{className:"doc-columns",children:children(n)});case"column":/* @__PURE__ */
|
|
28
28
|
return e("div",{className:"doc-column",children:children(n)});case"pageLink":{const t=String(M.label??S("页面")),n=String(M.pageId??"");if(!n)/* @__PURE__ */return e("span",{children:t});const r=null==(o=c.resolvePageLink??(null==(l=j.references)?void 0:l.resolve))?void 0:o(n,t),a=d((null==r?void 0:r.href)??"");return a?/* @__PURE__ */e("a",{className:"doc-page-link",rel:"noopener noreferrer",href:a,onClick:e=>{var t;(null==r?void 0:r.external)||!(null==(t=j.references)?void 0:t.navigate)||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),j.references.navigate(a))},children:t}):/* @__PURE__ */e("span",{className:"doc-page-link-plain",children:t})}case"mention":{const e=String(M.label??S("用户"));return M.userId?/* @__PURE__ */t("span",{className:"doc-mention",title:`提及:${e}`,children:["@",e]}):/* @__PURE__ */t("span",{children:["@",e]})}case"mindMap":{const count=e=>("text"===e.type?1:0)+(e.content??[]).reduce((e,t)=>e+count(t),0);return T+=count(n),k(n)?/* @__PURE__ */e(N,{node:n,allowExport:c.allowExport,pageId:c.pageId,canComment:c.canComment,onCommentsChanged:c.onCommentsChanged,fetchAttachment:c.attachmentFetcher}):/* @__PURE__ */e("p",{role:"alert",children:S("思维导图格式无效")})}case"workbook":return y(n)?/* @__PURE__ */e(C,{value:n,allowExport:c.allowExport}):/* @__PURE__ */e("p",{role:"alert",children:S("工作表格式无效")});case"mindMapTopic":case"mindMapDescription":case"mindMapNote":case"mindMapRelation":return null;default:/* @__PURE__ */
|
|
29
29
|
return t("p",{role:"alert",children:[S("不支持的内容节点:"),n.type]})}}/* @__PURE__ */
|
|
30
|
-
return e("div",{className:"doc-renderer ywiki-prose ywiki-content",children:render(E)})}const
|
|
30
|
+
return e("div",{className:"doc-renderer ywiki-prose ywiki-content",children:render(E)})}const D=DocumentViewer;export{D as DocRenderer,L as DocumentExportMenu,DocumentViewer,N as MindMapBlock};
|