@nocobase/plugin-field-markdown-vditor 2.1.0-beta.14 → 2.1.0-beta.16

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.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ "use strict";(self.webpackChunk_nocobase_plugin_field_markdown_vditor=self.webpackChunk_nocobase_plugin_field_markdown_vditor||[]).push([["715"],{590:function(e,t,r){r.r(t),r.d(t,{default:function(){return R},MarkdownVditor:function(){return O}});var n=r(230),o=r(342),l=r(59),a=r(155),i=r.n(a),u=r(597),c=r.n(u),s=r(303),d=function(){var e=(0,o.usePlugin)(s.PluginFieldMarkdownVditorClient);return e.dependencyLoaded||(e.initVditorDependency(),e.dependencyLoaded=!0),e.getCDN()},f=(0,o.genStyleHook)("nb-field-markdown-vditor",function(e){var t,r,n;return t={},r=e.componentCls,n={".vditor-reset":{fontSize:"".concat(e.fontSize,"px !important"),color:"unset",padding:"10px !important"},".vditor":{borderRadius:8},".vditor .vditor-content":{borderRadius:"0 0 8px 8px",overflow:"hidden"},".vditor .vditor-toolbar":{paddingLeft:" 16px !important",borderRadius:"8px 8px 0 0"},".vditor .vditor-content .vditor-ir .vditor-reset":{paddingLeft:" 16px !important"},".vditor-ir pre.vditor-reset":{backgroundColor:"".concat(e.colorBgContainer,"!important")}},r in t?Object.defineProperty(t,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[r]=n,t});function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(r=o.next()).done)&&(l.push(r.value),!t||l.length!==t);a=!0);}catch(e){i=!0,n=e}finally{try{a||null==o.return||o.return()}finally{if(i)throw n}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return v(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return v(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var m=function(e){if(e){var t=document.createRange();return t.selectNodeContents(e),t.getBoundingClientRect().width}};function y(e){var t,r=(0,a.useRef)(null),n=f(),o=n.wrapSSR,l=n.componentCls,u=n.hashId,s=d();return(0,a.useEffect)(function(){var t;c().preview(r.current,null!=(t=e.value)?t:"",{mode:"light",cdn:s}),setTimeout(function(){var e;null==(e=r.current)||e.querySelectorAll("img").forEach(function(e){e.style.cursor="zoom-in",e.addEventListener("click",function(){var t=e.src;if(!document.getElementById("custom-image-preview")){var r=document.createElement("span");r.id="custom-image-preview",Object.assign(r.style,{position:"fixed",inset:"0",backgroundColor:"rgba(0,0,0,0.85)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"9999",cursor:"zoom-out"});var n=document.createElement("img");n.src=t,Object.assign(n.style,{maxWidth:"90%",maxHeight:"90%",borderRadius:"8px",boxShadow:"0 0 20px rgba(0,0,0,0.5)",transition:"transform 0.2s",cursor:"zoom-out"}),r.addEventListener("click",function(){document.body.removeChild(r)}),r.appendChild(n),document.body.appendChild(r)}})})},0)},[e.value]),o(i().createElement("span",{className:"".concat(u," ").concat(l)},i().createElement("span",{ref:r,style:function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({border:"none"},null!=(t=null==e?void 0:e.style)?t:{})})))}var b=(0,o.withDynamicSchemaProps)(function(e){var t,r=(0,n.useField)(),o=null!=(t=e.value)?t:null==r?void 0:r.value,u=d(),s=(0,a.useRef)(),f=p((0,a.useState)(!1),2),v=f[0],b=f[1],h=p((0,a.useState)(!1),2),g=h[0],w=h[1],S=p((0,a.useState)(""),2),x=S[0],E=S[1],C=(0,a.useRef)();(0,a.useEffect)(function(){if(e.value&&(!r||(null==r?void 0:r.value)))if(e.ellipsis)c().md2html(e.value,{mode:"light",cdn:u}).then(function(e){var t,r;E(((t=document.createElement("div")).innerHTML=e,r=t.innerText,t=null,(null==r?void 0:r.replace(/[\n\r]/g,""))||""))}).catch(function(){return E("")});else{var t;c().preview(s.current,null!=(t=e.value)?t:null==r?void 0:r.value,{mode:"light",cdn:u})}},[e.value,e.ellipsis,null==r?void 0:r.value]);var O=(0,a.useCallback)(function(){var e;return!!C.current&&m(C.current)>(null==(e=C.current)?void 0:e.offsetWidth)},[C]);return e.ellipsis?i().createElement(l.Popover,{open:v,onOpenChange:function(e){b(g&&e)},content:i().createElement(y,{value:o,style:{maxWidth:500,maxHeight:400,overflowY:"auto"}})},i().createElement("div",{ref:C,style:{overflow:"hidden",overflowWrap:"break-word",textOverflow:"ellipsis",whiteSpace:"nowrap",wordBreak:"break-all"},onMouseEnter:function(e){var t=e.target;O()&&w(t.scrollWidth>=t.clientWidth)}},x)):i().createElement(y,{value:o})}),h=r(953),g=r(280),w=r(872);function S(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function x(e,t,r,n,o,l,a){try{var i=e[l](a),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}var E=["en_US","fr_FR","pt_BR","ja_JP","ko_KR","ru_RU","sv_SE","zh_CN","zh_TW"],C=(0,o.withDynamicSchemaProps)(function(e){var t,r=e.disabled,n=e.onChange,l=e.value,u=e.fileCollection,s=e.toolbar,v=e.editMode,p=void 0===v?"ir":v,m=function(e){if(Array.isArray(e))return e}(t=(0,a.useState)(!1))||function(e){var t,r,n=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o=[],l=!0,a=!1;try{for(n=n.call(e);!(l=(t=n.next()).done)&&(o.push(t.value),2!==o.length);l=!0);}catch(e){a=!0,r=e}finally{try{l||null==n.return||n.return()}finally{if(a)throw r}}return o}}(t)||function(e){if(e){if("string"==typeof e)return S(e,2);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return S(e,2)}}(t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),y=m[0],b=m[1],C=(0,a.useRef)(),O=(0,a.useRef)(!1),R=(0,a.useRef)(null),k=(0,a.useRef)(null),_=(0,o.useAPIClient)(),j=d(),A=f(),I=A.wrapSSR,P=A.hashId,T=A.componentCls,L=_.auth.locale||"en-US",M=(0,o.usePlugin)("@nocobase/plugin-file-manager"),N=(0,o.useCompile)(),z=(0,a.useRef)(N);z.current=N;var F=(0,h.useTranslation)().t,V=(0,o.useZIndexContext)(),W=(0,o.getZIndex)("drawer",V+1e3,0),q=(0,a.useMemo)(function(){var e=L.replace(/-/g,"_");return E.includes(e)?e:"en_US"},[L]);return(0,a.useEffect)(function(){if(R.current){var e=null!=s?s:g.r,t=new(c())(R.current,{value:null!=l?l:"",lang:q,cache:{enable:!1},undoDelay:0,preview:{math:{engine:"KaTeX"}},toolbar:e,fullscreen:{index:1200},cdn:j,minHeight:200,mode:p,after:function(){C.current=t,b(!0);var e=window.scrollX||window.pageXOffset,n=window.scrollY||window.pageYOffset;t.setValue(null!=l?l:""),requestAnimationFrame(function(){window.scrollTo(e,n)}),r?t.disabled():t.enable()},input:function(e){n(e)},upload:{multiple:!1,fieldName:"file",handler:function(e){var r;return(r=function(){var r,n,o,l,a,i,c,s,d,f,v,p,m,y,b;return function(e,t){var r,n,o,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(a,"next",{value:u(0)}),i(a,"throw",{value:u(1)}),i(a,"return",{value:u(2)}),"function"==typeof Symbol&&i(a,Symbol.iterator,{value:function(){return this}}),a;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(l=0)),l;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,n=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){l=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){l.label=c[1];break}if(6===c[0]&&l.label<o[1]){l.label=o[1],o=c;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(c);break}o[2]&&l.ops.pop(),l.trys.pop();continue}c=t.call(e,l)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(h){switch(h.label){case 0:return s=e[0],t.focus(),[4,_.resource("vditor").check({fileCollectionName:u})];case 1:if(!(null==(d=h.sent().data)||null==(r=d.data)?void 0:r.isSupportToUploadFiles))return t.tip(F("vditor.uploadError.message",{ns:w.C,storageTitle:null==(f=d.data.storage)?void 0:f.title}),0),[2];return t.tip(F("uploading"),0),[4,M.uploadFile({file:s,fileCollectionName:u,storageId:null==d||null==(o=d.data)||null==(n=o.storage)?void 0:n.id,storageType:null==d||null==(a=d.data)||null==(l=a.storage)?void 0:l.type,storageRules:null==d||null==(c=d.data)||null==(i=c.storage)?void 0:i.rules})];case 2:if(p=(v=h.sent()).data,m=v.errorMessage)return t.tip(z.current(m),3e3),[2];if(!p)return t.tip(F("Response data is empty",{ns:w.C}),3e3),[2];return y=p.filename,b=p.url,s.type.startsWith("image/")?t.insertValue("![".concat(y,"](").concat(b,")")):t.insertValue("[".concat(y,"](").concat(b,")")),t.tip(F(""),10),[2,null]}})},function(){var e=this,t=arguments;return new Promise(function(n,o){var l=r.apply(e,t);function a(e){x(l,n,o,a,i,"next",e)}function i(e){x(l,n,o,a,i,"throw",e)}a(void 0)})})()}}}),o=R.current;if(o){var a=new MutationObserver(function(){var e=o.classList.contains("vditor--fullscreen"),t=o.querySelectorAll(".vditor-reset"),r=o.querySelectorAll(".vditor-toolbar");t.forEach(function(t){t.style.padding=e?"10px 200px":""}),r.forEach(function(t){t.style.paddingLeft=e?"200px":""})});return a.observe(o,{attributes:!0,attributeFilter:["class"]}),function(){var e;null==(e=C.current)||e.destroy(),C.current=void 0,a.disconnect()}}}},[null==s?void 0:s.join(","),p]),(0,a.useEffect)(function(){if(y&&C.current){var e=C.current;if(l!==e.getValue()){var t,r,n,o,a=window.scrollX||window.pageXOffset,i=window.scrollY||window.pageYOffset;e.setValue(null!=l?l:"");var u=null==(t=R.current)?void 0:t.querySelector("div.vditor-content > div.vditor-ir > pre"),c=null==(r=R.current)?void 0:r.querySelector(".vditor-content"),s=u&&(document.activeElement===u||u.contains(document.activeElement)||(null==(o=document.activeElement)||null==(n=o.closest)?void 0:n.call(o,".vditor-content"))===c);if(u&&s){var d=document.createRange(),f=window.getSelection();f&&(d.selectNodeContents(u),d.collapse(!1),f.removeAllRanges(),f.addRange(d))}s||requestAnimationFrame(function(){window.scrollTo(a,i)})}}},[l,y]),(0,a.useEffect)(function(){y&&C.current&&(r?C.current.disabled():C.current.enable())},[r,y]),(0,a.useEffect)(function(){if(k.current){var e=new MutationObserver(function(e){var t=!0,r=!1,n=void 0;try{for(var o,l=e[Symbol.iterator]();!(t=(o=l.next()).done);t=!0){var a=o.value,i=!0,u=!1,c=void 0;try{for(var s,d=Array.from(a.addedNodes)[Symbol.iterator]();!(i=(s=d.next()).done);i=!0){var f,v=s.value;f=HTMLElement,(null!=f&&"u">typeof Symbol&&f[Symbol.hasInstance]?!!f[Symbol.hasInstance](v):v instanceof f)&&v.classList.contains("vditor-img")&&(k.current.appendChild(v),v.style.zIndex=String(W))}}catch(e){u=!0,c=e}finally{try{i||null==d.return||d.return()}finally{if(u)throw c}}}}catch(e){r=!0,n=e}finally{try{t||null==l.return||l.return()}finally{if(r)throw n}}});return e.observe(document.body,{childList:!0}),function(){e.disconnect()}}},[W]),(0,a.useLayoutEffect)(function(){if(R.current){var e=new ResizeObserver(function(e){var t=!0,r=!1,n=void 0;try{for(var o,l=e[Symbol.iterator]();!(t=(o=l.next()).done);t=!0){var a,i=o.value.target;i.className.includes("vditor--fullscreen")?(document.body.appendChild(i),O.current=!0):O.current&&(null==(a=k.current)||a.appendChild(i),O.current=!1)}}catch(e){r=!0,n=e}finally{try{t||null==l.return||l.return()}finally{if(r)throw n}}});return e.observe(R.current),function(){e.unobserve(R.current)}}},[]),I(i().createElement("div",{ref:k,className:"".concat(P," ").concat(T)},i().createElement("div",{ref:R})))}),O=(0,o.withDynamicSchemaProps)((0,n.connect)(C,(0,n.mapReadPretty)(b))),R=O}}]);