@nocobase/plugin-text-copy
Version:
Add copy button to text fields
10 lines (9 loc) • 8.75 kB
JavaScript
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("antd"),require("react"),require("@nocobase/client-v2"),require("@nocobase/flow-engine")):"function"==typeof define&&define.amd?define("@nocobase/plugin-text-copy/client-v2",["antd","react","@nocobase/client-v2","@nocobase/flow-engine"],e):"object"==typeof exports?exports["@nocobase/plugin-text-copy/client-v2"]=e(require("antd"),require("react"),require("@nocobase/client-v2"),require("@nocobase/flow-engine")):t["@nocobase/plugin-text-copy/client-v2"]=e(t.antd,t.react,t["@nocobase/client-v2"],t["@nocobase/flow-engine"])}(self,function(t,e,n,r){return function(){"use strict";var o={485:function(t){t.exports=n},694:function(t){t.exports=r},59:function(e){e.exports=t},155:function(t){t.exports=e}},i={};function c(t){var e=i[t];if(void 0!==e)return e.exports;var n=i[t]={exports:{}};return o[t](n,n.exports,c),n.exports}c.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return c.d(e,{a:e}),e},c.d=function(t,e){for(var n in e)c.o(e,n)&&!c.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},c.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(t){if("object"==typeof window)return window}}(),c.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},c.r=function(t){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},c.g.importScripts&&(u=c.g.location+"");var u,a=c.g.document;if(!u&&a&&(a.currentScript&&"SCRIPT"===a.currentScript.tagName.toUpperCase()&&(u=a.currentScript.src),!u)){var l=a.getElementsByTagName("script");if(l.length)for(var p=l.length-1;p>-1&&(!u||!/^http(s?):/.test(u));)u=l[p--].src}if(!u)throw Error("Automatic publicPath is not supported in this browser");c.p=u.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/");var s={};return!function(){var t="",e="u">typeof document?document.currentScript:null;if(e&&e.src){var n=e.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"");n.indexOf("/static/plugins/@nocobase/plugin-text-copy/dist/client-v2/")>=0&&(t=n.replace(/\/[^\/]+$/,"/"))}if(!t){var r=window.__webpack_public_path__||"";r&&("/"!==r.charAt(r.length-1)&&(r+="/"),t=r+"static/plugins/@nocobase/plugin-text-copy/dist/client-v2/")}if(!t){var o=window.__nocobase_modern_client_prefix__||"v",i="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(t=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var u=window.location.pathname||"/",a=u.indexOf(i);t=a>=0?u.slice(0,a+1):"/"}t&&(t=t.replace(RegExp("/"+o+"/?$"),"/")),t||(t="/"),"/"!==t.charAt(t.length-1)&&(t+="/"),t+="static/plugins/@nocobase/plugin-text-copy/dist/client-v2/"}c.p=t}(),!function(){c.r(s),c.d(s,{default:function(){return h}});var t=c(485),e=c(59),n=c(155),r=c.n(n),o=c(694);function i(t){return(0,o.tExpr)(t,{ns:["@nocobase/plugin-text-copy","text-copy","client"]})}function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}var a=Symbol.for("nocobase.plugin-text-copy.DisplayTextFieldModel.patched"),l=function(t){var n,o=t.children,i=t.copyText,c=function(t){if(Array.isArray(t))return t}(n=r().useState(!1))||function(t){var e,n,r=null==t?null:"u">typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var o=[],i=!0,c=!1;try{for(r=r.call(t);!(i=(e=r.next()).done)&&(o.push(e.value),2!==o.length);i=!0);}catch(t){c=!0,n=t}finally{try{i||null==r.return||r.return()}finally{if(c)throw n}}return o}}(n)||function(t){if(t){if("string"==typeof t)return u(t,2);var e=Object.prototype.toString.call(t).slice(8,-1);if("Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e)return Array.from(e);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return u(t,2)}}(n)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),a=c[0],l=c[1];return r().createElement("span",{onMouseEnter:function(){return l(!0)},onMouseLeave:function(){return l(!1)}},r().createElement(e.Space,{size:"small"},o,a?r().createElement(e.Typography.Text,{copyable:{text:i}}):null))};function p(t,e,n,r,o,i,c){try{var u=t[i](c),a=u.value}catch(t){n(t);return}u.done?e(a):Promise.resolve(a).then(r,o)}function f(t,e,n){return(f=v()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&b(o,n.prototype),o}).apply(null,arguments)}function y(t){return(y=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function b(t,e){return(b=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function d(t){var e="function"==typeof Map?new Map:void 0;return(d=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return f(t,arguments,y(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),b(n,t)})(t)}function v(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(v=function(){return!!t})()}var h=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function o(){var t,e;if(!(this instanceof o))throw TypeError("Cannot call a class as a function");return t=o,e=arguments,t=y(t),function(t,e){var n;if(e&&("object"==((n=e)&&"u">typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof e))return e;if(void 0===t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(this,v()?Reflect.construct(t,e||[],y(this).constructor):t.apply(this,e))}return o.prototype=Object.create(e&&e.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),e&&b(o,e),n=[{key:"load",value:function(){var e;return(e=function(){return function(t,e){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},c=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(c,"next",{value:a(0)}),u(c,"throw",{value:a(1)}),u(c,"return",{value:a(2)}),"function"==typeof Symbol&&u(c,Symbol.iterator,{value:function(){return this}}),c;function a(u){return function(a){var l=[u,a];if(n)throw TypeError("Generator is already executing.");for(;c&&(c=0,l[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=e.call(t,i)}catch(t){l=[6,t],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}(this,function(e){t.DisplayTextFieldModel.registerFlow({key:"textCopySettings",title:i("Display Field settings"),sort:210,steps:{displayCopyButton:{title:i("Display copy button"),uiMode:{type:"switch",key:"displayCopyButton"},defaultParams:{displayCopyButton:!1},handler:function(t,e){t.model.setProps({displayCopyButton:e.displayCopyButton})}}}});var n=t.DisplayTextFieldModel.prototype;if(!n[a]){var o=n.renderComponent;n.renderComponent=function(t,e){var n,i=o.call(this,t,e),c=this.t(t);return(null==(n=this.props)?void 0:n.displayCopyButton)&&null!=c&&""!==c?r().createElement(l,{copyText:String(c)},i):i},n[a]=!0}return[2]})},function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function c(t){p(i,r,o,c,u,"next",t)}function u(t){p(i,r,o,c,u,"throw",t)}c(void 0)})})()}}],function(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}(o.prototype,n),o}(d(t.Plugin))}(),s}()});