@nocobase/plugin-field-markdown-vditor 2.0.0-alpha.6 → 2.0.0-alpha.61

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([["189"],{563:function(e,t,n){n.r(t),n.d(t,{MarkdownVditor:function(){return R},default:function(){return k}});var r=n(505),o=n(772),l=n(721),a=n(156),i=n.n(a),u=n(825),c=n.n(u),s=n(718),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,n,r;return t={},n=e.componentCls,r={".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")}},n in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t});function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(l.push(n.value),!t||l.length!==t);a=!0);}catch(e){i=!0,r=e}finally{try{a||null==o.return||o.return()}finally{if(i)throw r}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return v(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))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,n=(0,a.useRef)(null),r=f(),o=r.wrapSSR,l=r.componentCls,u=r.hashId,s=d();return(0,a.useEffect)(function(){var t;c().preview(n.current,null!=(t=e.value)?t:"",{mode:"light",cdn:s}),setTimeout(function(){var e;null==(e=n.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 n=document.createElement("span");n.id="custom-image-preview",Object.assign(n.style,{position:"fixed",inset:"0",backgroundColor:"rgba(0,0,0,0.85)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"9999",cursor:"zoom-out"});var r=document.createElement("img");r.src=t,Object.assign(r.style,{maxWidth:"90%",maxHeight:"90%",borderRadius:"8px",boxShadow:"0 0 20px rgba(0,0,0,0.5)",transition:"transform 0.2s",cursor:"zoom-out"}),n.addEventListener("click",function(){document.body.removeChild(n)}),n.appendChild(r),document.body.appendChild(n)}})})},0)},[e.value]),o(i().createElement("span",{className:"".concat(u," ").concat(l)},i().createElement("span",{ref:n,style:function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({border:"none"},null!=(t=null==e?void 0:e.style)?t:{})})))}var b=(0,o.withDynamicSchemaProps)(function(e){var t,n=(0,r.useField)(),o=null!=(t=e.value)?t:null==n?void 0:n.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],C=S[1],E=(0,a.useRef)();(0,a.useEffect)(function(){if(e.value&&(!n||(null==n?void 0:n.value)))if(e.ellipsis)c().md2html(e.value,{mode:"light",cdn:u}).then(function(e){var t,n;C(((t=document.createElement("div")).innerHTML=e,n=t.innerText,t=null,(null==n?void 0:n.replace(/[\n\r]/g,""))||""))}).catch(function(){return C("")});else{var t;c().preview(s.current,null!=(t=e.value)?t:null==n?void 0:n.value,{mode:"light",cdn:u})}},[e.value,e.ellipsis,null==n?void 0:n.value]);var R=(0,a.useCallback)(function(){var e;return!!E.current&&m(E.current)>(null==(e=E.current)?void 0:e.offsetWidth)},[E]);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:E,style:{overflow:"hidden",overflowWrap:"break-word",textOverflow:"ellipsis",whiteSpace:"nowrap",wordBreak:"break-all"},onMouseEnter:function(e){var t=e.target;R()&&w(t.scrollWidth>=t.clientWidth)}},x)):i().createElement(y,{value:o})}),h=n(238),g=n(68),w=n(551);function S(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function x(e,t,n,r,o,l,a){try{var i=e[l](a),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,o)}var C=["en_US","fr_FR","pt_BR","ja_JP","ko_KR","ru_RU","sv_SE","zh_CN","zh_TW"],E=(0,o.withDynamicSchemaProps)(function(e){var t,n=e.disabled,r=e.onChange,l=e.value,u=e.fileCollection,s=e.toolbar,v=(t=(0,a.useState)(!1),function(e){if(Array.isArray(e))return e}(t)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],a=!0,i=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(l.push(n.value),l.length!==t);a=!0);}catch(e){i=!0,r=e}finally{try{a||null==o.return||o.return()}finally{if(i)throw r}}return l}}(t,2)||function(e,t){if(e){if("string"==typeof e)return S(e,2);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return S(e,t)}}(t,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),p=v[0],m=v[1],y=(0,a.useRef)(),b=(0,a.useRef)(!1),E=(0,a.useRef)(null),R=(0,a.useRef)(null),k=(0,o.useAPIClient)(),_=d(),A=f(),O=A.wrapSSR,I=A.hashId,j=A.componentCls,P=k.auth.locale||"en-US",L=(0,o.usePlugin)("@nocobase/plugin-file-manager"),T=(0,o.useCompile)(),M=(0,a.useRef)(T);M.current=T;var N=(0,h.useTranslation)().t,z=(0,o.useZIndexContext)(),V=(0,o.getZIndex)("drawer",z+1e3,0),W=(0,a.useMemo)(function(){var e=P.replace(/-/g,"_");return C.includes(e)?e:"en_US"},[P]);return(0,a.useEffect)(function(){if(E.current){var e=null!=s?s:g.K,t=new(c())(E.current,{value:null!=l?l:"",lang:W,cache:{enable:!1},undoDelay:0,preview:{math:{engine:"KaTeX"}},toolbar:e,fullscreen:{index:1200},cdn:_,minHeight:200,after:function(){y.current=t,m(!0),t.setValue(null!=l?l:""),n?t.disabled():t.enable()},input:function(e){r(e)},upload:{multiple:!1,fieldName:"file",handler:function(e){var n;return(n=function(){var n,r,o,l,a,i,c,s,d,f,v,p,m,y,b;return function(e,t){var n,r,o,l,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return l={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function i(l){return function(i){var u=[l,i];if(n)throw TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(this,function(h){switch(h.label){case 0:return s=e[0],t.focus(),[4,k.resource("vditor").check({fileCollectionName:u})];case 1:if(!(null==(d=h.sent().data)||null==(n=d.data)?void 0:n.isSupportToUploadFiles))return t.tip(N("vditor.uploadError.message",{ns:w.A,storageTitle:null==(f=d.data.storage)?void 0:f.title}),0),[2];return t.tip(N("uploading"),0),[4,L.uploadFile({file:s,fileCollectionName:u,storageId:null==d||null==(o=d.data)||null==(r=o.storage)?void 0:r.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(M.current(m),3e3),[2];if(!p)return t.tip(N("Response data is empty",{ns:w.A}),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(N(""),10),[2,null]}})},function(){var e=this,t=arguments;return new Promise(function(r,o){var l=n.apply(e,t);function a(e){x(l,r,o,a,i,"next",e)}function i(e){x(l,r,o,a,i,"throw",e)}a(void 0)})})()}}}),o=E.current;if(o){var a=new MutationObserver(function(){var e=o.classList.contains("vditor--fullscreen"),t=o.querySelectorAll(".vditor-reset"),n=o.querySelectorAll(".vditor-toolbar");t.forEach(function(t){t.style.padding=e?"10px 200px":""}),n.forEach(function(t){t.style.paddingLeft=e?"200px":""})});return a.observe(o,{attributes:!0,attributeFilter:["class"]}),function(){var e;null==(e=y.current)||e.destroy(),y.current=void 0,a.disconnect()}}}},[null==s?void 0:s.join(",")]),(0,a.useEffect)(function(){if(p&&y.current){var e=y.current;if(l!==e.getValue()){e.setValue(null!=l?l:"");var t,n=null==(t=E.current)?void 0:t.querySelector("div.vditor-content > div.vditor-ir > pre");if(n){var r=document.createRange(),o=window.getSelection();o&&(r.selectNodeContents(n),r.collapse(!1),o.removeAllRanges(),o.addRange(r))}}}},[l,p]),(0,a.useEffect)(function(){p&&y.current&&(n?y.current.disabled():y.current.enable())},[n,p]),(0,a.useEffect)(function(){if(R.current){var e=new MutationObserver(function(e){var t=!0,n=!1,r=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&&"undefined"!=typeof Symbol&&f[Symbol.hasInstance]?!!f[Symbol.hasInstance](v):v instanceof f)&&v.classList.contains("vditor-img")&&(R.current.appendChild(v),v.style.zIndex=String(V))}}catch(e){u=!0,c=e}finally{try{i||null==d.return||d.return()}finally{if(u)throw c}}}}catch(e){n=!0,r=e}finally{try{t||null==l.return||l.return()}finally{if(n)throw r}}});return e.observe(document.body,{childList:!0}),function(){e.disconnect()}}},[V]),(0,a.useLayoutEffect)(function(){if(E.current){var e=new ResizeObserver(function(e){var t=!0,n=!1,r=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),b.current=!0):b.current&&(null==(a=R.current)||a.appendChild(i),b.current=!1)}}catch(e){n=!0,r=e}finally{try{t||null==l.return||l.return()}finally{if(n)throw r}}});return e.observe(E.current),function(){e.unobserve(E.current)}}},[]),O(i().createElement("div",{ref:R,className:"".concat(I," ").concat(j)},i().createElement("div",{ref:E})))}),R=(0,o.withDynamicSchemaProps)((0,r.connect)(E,(0,r.mapReadPretty)(b))),k=R}}]);