{"version":3,"file":"index.mjs","names":["copy"],"sources":["../../../src/directives/click-copy/index.ts"],"sourcesContent":["/**\n * v-copy\n * 复制某个值至剪贴板\n * 接收参数：string类型/Ref<string>类型/Reactive<string>类型\n */\nimport { ElMessage } from \"element-plus\";\nimport { copy as copyToClipboard, withInstallDirective } from \"../../utils\";\nimport type { Directive, DirectiveBinding } from \"vue\";\n\ninterface CopyElement extends HTMLElement {\n\tcopyData: string | number;\n\t__handleClick__: () => void;\n}\n\nconst CopyDirective: Directive = {\n\tmounted(el: CopyElement, binding: DirectiveBinding<string | number>) {\n\t\tel.copyData = binding.value;\n\n\t\tconst copy = (): void => {\n\t\t\tif (!el.copyData) return;\n\t\t\tcopyToClipboard(String(el.copyData)).then(\n\t\t\t\t() => {\n\t\t\t\t\tElMessage({\n\t\t\t\t\t\ttype: \"success\",\n\t\t\t\t\t\tmessage: \"复制成功\",\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tElMessage({\n\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\tmessage: \"复制失败\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t);\n\t\t};\n\t\tel.__handleClick__ = copy;\n\t\tel.addEventListener(\"click\", el.__handleClick__);\n\t},\n\tupdated(el: CopyElement, binding: DirectiveBinding<string | number>) {\n\t\tel.copyData = binding.value;\n\t},\n\tbeforeUnmount(el: CopyElement) {\n\t\tel.removeEventListener(\"click\", el.__handleClick__);\n\t},\n};\n\n/** 将绑定值复制到剪贴板的 Vue 指令。 */\nexport const vCopy = withInstallDirective(CopyDirective, \"copy\");\nexport default vCopy;\n"],"mappings":";;;;AA+CA,MAAa,QAAQ,qBAAqB;CAhCzC,QAAQ,IAAiB,SAA4C;EACpE,GAAG,WAAW,QAAQ;EAEtB,MAAMA,eAAmB;GACxB,IAAI,CAAC,GAAG,UAAU;GAClB,KAAgB,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,WAC9B;IACL,UAAU;KACT,MAAM;KACN,SAAS;IACV,CAAC;GACF,SACM;IACL,UAAU;KACT,MAAM;KACN,SAAS;IACV,CAAC;GACF,CACD;EACD;EACA,GAAG,kBAAkBA;EACrB,GAAG,iBAAiB,SAAS,GAAG,eAAe;CAChD;CACA,QAAQ,IAAiB,SAA4C;EACpE,GAAG,WAAW,QAAQ;CACvB;CACA,cAAc,IAAiB;EAC9B,GAAG,oBAAoB,SAAS,GAAG,eAAe;CACnD;AAIyC,GAAe,MAAM"}