{"version":3,"sources":["jsdelivr-header.js","/npm/quick-email-editor-v2@0.4.9/src/utils/customCSS.js","/npm/quick-email-editor-v2@0.4.9/src/utils/customJS.ts","/npm/quick-email-editor-v2@0.4.9/src/utils/html2Image.ts","/npm/quick-email-editor-v2@0.4.9/src/components/constants.ts","/npm/quick-email-editor-v2@0.4.9/src/components/EmailEditor.tsx"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,6XCNO,MAAM,UAAY,CACvB,qOACA,6EACA,iFACA,2EACA,8ECGI,OACJ,qEAEI,SAUA,CACE,GAAG,6BACH,GAAG,uBACH,GAAG,4BACH,GAAG,sBACH,GAAG,0BACH,GAAG,qBAGL,WAAa,CACjB,qFACA,0GACA,mFAGI,qBAAuB,CAAC,UAAW,YAAa,YAChD,WAAa,CAAC,EAAa,KAC/B,MAAM,EAAe,KAAK,MAAM,KAAK,UAAU,WAQ/C,OAPI,MAAA,OAAA,EAAA,EAAa,QAAS,EACX,EAAA,OAAO,EAAG,GACd,qBAAqB,SAAS,GAC1B,EAAA,OAAO,EAAG,GAEV,EAAA,OAAO,EAAG,GAElB,IAAI,KAAiB,WAAU,EC5C3B,WAAoB,GAAiB,aAAA,oBAChD,QAAQ,KAAK,cACP,MAAA,EAAY,SAAS,cAAc,OACzC,EAAU,UAAY,EACtB,EAAU,MAAM,SAAW,WAC3B,EAAU,MAAM,KAAO,IACtB,IAAG,EAAU,qBAAqB,QAAQ,SAAS,IAC9C,EAAA,aAAa,MAAO,EAAI,IAAM,KAAM,IAAI,MAAO,UAAS,IAErD,SAAA,KAAK,YAAY,GAE1B,MAAM,QAAa,MAAM,GAAW,MAAM,IACxC,QAAQ,QAAQ,cACT,KAGF,OADE,SAAA,KAAK,YAAY,GACnB,CACT,ICjBA,KAAK,UAAU,OAAS,SAAU,GAChC,IAAI,EAAI,CACN,KAAM,KAAK,WAAa,EACxB,KAAM,KAAK,UACX,KAAM,KAAK,WACX,KAAM,KAAK,aACX,KAAM,KAAK,a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Z,WAAY,CAEV,iBAAkB,CAChB,MAAO,OAGT,eAAgB,CACd,OAAQ,CACN,KAAM,CACJ,SAAU,GACV,qBAAsB,GACtB,QAAS,GACT,gBACA,sBACA,aACA,MAAO,GACP,UAAW,EACX,YAAa,OAMvB,iBAAkB,CAChB,KAAM,CACJ,YAAa,KAGjB,kBAAmB,CACjB,WAAY,EACZ,WAAY,mBACV,EACA,EACA,EACA,EACA,IAGJ,MAAO,CACL,WAAY,CACV,IAAK,CACH,MAAO,CACL,IAAK,yIACL,MAAO,IACP,OAAQ,WAMjB,CACD,EACA,EACA,EACA,EACA,EACA,EACA,IAGI,EAAiB,SAAQ,KACtB,CACL,aAAc,CACZ,KAAM,eACN,UAAW,GAEb,gBAAiB,CACf,KAAM,kBACN,MAAO,cACP,OAAQ,kBAGX,CAAC,IAEE,EAAe,SAAQ,KACpB,CAKL,gBAAiB,CACf,MAAM,GAER,MAAO,CACL,kBAAkB,EAClB,eAEF,YAEA,oBACA,SAAU,WAAW,EAAa,GAClC,SAAU,CAER,gBAAgB,EAChB,WAAY,CACV,QAAQ,EAER,cAAc,OAInB,IAwBI,OAtBQ,SACb,K,QACG,OAAA,MAAA,cAAA,SAAA,CACC,IAAK,EACL,UAAW,EACX,UAAW,MACX,WAAY,CACV,MAAO,OAAA,EAAA,MAAA,OAAA,EAAA,EAAc,OAAd,EAAuB,QAC9B,OAAQ,CACN,MAAO,CACL,KAAM,OAAA,EAAA,MAAA,OAAA,EAAA,EAAc,MAAd,EAAsB,WAIlC,QACA,UACA,SACA,WACF,GAEF,CAAC,GAEI,W","file":"/npm/quick-email-editor-v2@0.4.9/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/quick-email-editor-v2@0.4.9/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","export const customCSS = [\n  '::-webkit-scrollbar{width:8px;height:8px;}::-webkit-scrollbar-thumb{border-radius:5px;background:#bfbfbf;}::-webkit-scrollbar-track{background:transparent;}::-webkit-scrollbar-thumb:hover{border-radius:5px;background:#4a9cee;}',\n  'https://cdn.jsdelivr.net/npm/freemarker-web-editor@1.0.0/css/fm-editor.css',\n  'https://cdn.jsdelivr.net/npm/freemarker-web-editor@1.0.0/css/fm-codemirror.css',\n  'https://cdn.jsdelivr.net/npm/freemarker-web-editor@1.0.0/css/fm-hint.css',\n  'https://cdn.jsdelivr.net/npm/freemarker-web-editor@1.0.0/css/fm-syntax.css'\n];\n","/*\n * @Author: zhaoxuan (zhaoxuan@quickcep.com)\n * @LastEditors: zhaoxuan (zhaoxuan@quickcep.com)\n * @Date: 2023-08-31 17:40:43\n * @Description:\n * @LastEditDescription:\n * @LastEditTime: 2024-03-22 17:14:41\n */\nconst suffix =\n  'https://cdn.jsdelivr.net/npm/quick-email-editor-v2@0.4.9/uploadJS/';\n\nconst customJS =\n  import.meta.env.MODE === 'development'\n    ? [\n        new URL('../customTool/productProperties.js', import.meta.url).href,\n        new URL('../customTool/productTool.js', import.meta.url).href,\n        new URL('../customTool/couponProperties.js', import.meta.url).href,\n        new URL('../customTool/couponTool.js', import.meta.url).href,\n        new URL('../customTool/htmlProperties.js', import.meta.url).href,\n        new URL('../customTool/htmlTool.js', import.meta.url).href\n      ]\n    : [\n        `${suffix}productProperties.js`,\n        `${suffix}productTool.js`,\n        `${suffix}couponProperties.js`,\n        `${suffix}couponTool.js`,\n        `${suffix}htmlProperties.js`,\n        `${suffix}htmlTool.js`\n      ];\n\nconst codeMirror = [\n  'https://cdn.jsdelivr.net/npm/freemarker-web-editor@1.0.0/js/dojo-1.9.1-bin/dojo.js',\n  'https://cdn.jsdelivr.net/npm/freemarker-web-editor@1.0.0/js/codemirror-3.0-bin/codemirror-compressed.js',\n  'https://cdn.jsdelivr.net/npm/freemarker-web-editor@1.0.0/js/fm/fm-editor.min.js'\n];\n\nconst showDiscountPlatform = ['shopify', 'shoplazza', 'shopline'];\nconst generateJs = (customFonts, platform) => {\n  const tempCustomJS = JSON.parse(JSON.stringify(customJS));\n  if (customFonts?.length > 3) {\n    tempCustomJS.splice(2, 2);\n  } else if (showDiscountPlatform.includes(platform)) {\n    tempCustomJS.splice(4, 2);\n  } else {\n    tempCustomJS.splice(2, 4);\n  }\n  return [...tempCustomJS, ...codeMirror];\n};\n\nexport default generateJs;\n","import { toPng } from 'html-to-image';\n\nexport const html2Image = async (html: string) => {\n  console.time('html2Image');\n  const container = document.createElement('div');\n  container.innerHTML = html;\n  container.style.position = 'absolute';\n  container.style.left = '0';\n  [...container.getElementsByTagName('img')].forEach((img) => {\n    img.setAttribute('src', img.src + '?' + new Date().getTime());\n  });\n  document.body.appendChild(container);\n\n  const blob = await toPng(container).then((dataUrl) => {\n    console.timeEnd('html2Image');\n    return dataUrl;\n  });\n  document.body.removeChild(container);\n  return blob;\n};\n","// @ts-expect-error: Unreachable code error\r\n// eslint-disable-next-line\r\nDate.prototype.format = function (format) {\r\n  var o = {\r\n    'M+': this.getMonth() + 1, // month\r\n    'd+': this.getDate(), // day\r\n    'h+': this.getHours(), // hour\r\n    'm+': this.getMinutes(), // minute\r\n    's+': this.getSeconds(), // second\r\n    'q+': Math.floor((this.getMonth() + 3) / 3), // quarter\r\n    S: this.getMilliseconds() // millisecond\r\n  };\r\n  if (/(y+)/.test(format))\r\n    format = format.replace(\r\n      RegExp.$1,\r\n      (this.getFullYear() + '').substr(4 - RegExp.$1.length)\r\n    );\r\n  for (var k in o)\r\n    if (new RegExp('(' + k + ')').test(format))\r\n      format = format.replace(\r\n        RegExp.$1,\r\n        RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)\r\n      );\r\n  return format;\r\n};\r\nconst dateFormat = (format) => {\r\n  // @ts-expect-error: Unreachable code error\r\n  let formatDate = new Date().format(format);\r\n  if (format.startsWith('MM')) {\r\n    const month = new Date().toString().split(' ')[1];\r\n    formatDate = month + formatDate.slice(2);\r\n  }\r\n  return formatDate;\r\n};\r\nconst getOptions = (platform) => {\r\n  const options = [\r\n    { label: 'All order', value: 'ALL' },\r\n    { label: 'Minimum order price', value: 'MINIMUM' },\r\n    { label: 'Collection', value: 'PRODUCT_COLLECTION' }\r\n  ];\r\n  if (platform === 'shoplazza') {\r\n    options.splice(1, 1);\r\n  }\r\n  return options;\r\n};\r\n// 网址\r\nexport const urlReg =\r\n  /^((http|ftp|https):\\/\\/)(([a-zA-Z0-9._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(:[0-9]{1,4})*(\\/[a-zA-Z0-9&%_./-~-]*)?/;\r\nexport const discountProperties = (\r\n  quickToken,\r\n  platform,\r\n  storeLink,\r\n  getConnectionUrl,\r\n  timeZone\r\n) => {\r\n  return {\r\n    discountType: {\r\n      editor: {\r\n        data: {\r\n          options: [\r\n            { label: 'Cart discount', value: 'ORDER_DISCOUNT' },\r\n            { label: 'Free shipping', value: 'FREE_SHIP' }\r\n          ]\r\n        }\r\n      }\r\n    },\r\n    discountRange: {\r\n      editor: {\r\n        data: {\r\n          options: getOptions(platform)\r\n        }\r\n      }\r\n    },\r\n    expiresDays: {\r\n      editor: {\r\n        data: {\r\n          label: 'Expires in',\r\n          suffix: 'days',\r\n          timeZone,\r\n          quickToken\r\n        }\r\n      }\r\n    },\r\n    limitUsedValue: {\r\n      editor: {\r\n        data: {\r\n          label: 'No. of times the discount can be used intotal'\r\n        }\r\n      }\r\n    },\r\n    minimumOrderPrice: {\r\n      editor: {\r\n        data: {\r\n          label: 'Minimum order price',\r\n          // eslint-disable-next-line\r\n          desc: \"The amount will be set in your store's currency\"\r\n        }\r\n      }\r\n    },\r\n    reduceValue: {\r\n      editor: {\r\n        data: {\r\n          label: 'Discount value',\r\n          // eslint-disable-next-line\r\n          desc: \"The amount will be set in your store's currency\"\r\n        }\r\n      }\r\n    },\r\n    reduceValuePercent: {\r\n      editor: {\r\n        data: {\r\n          label: 'Discount value',\r\n          suffix: '%'\r\n        }\r\n      }\r\n    },\r\n    expireDateFormat: {\r\n      editor: {\r\n        data: {\r\n          options: [\r\n            { label: dateFormat('MM dd,yyyy'), value: 'MM dd,yyyy' },\r\n            { label: dateFormat('yyyy-MM-dd'), value: 'yyyy-MM-dd' },\r\n            { label: dateFormat('dd/MM/yyyy'), value: 'dd/MM/yyyy' }\r\n          ]\r\n        }\r\n      }\r\n    },\r\n    buttonType: {\r\n      editor: {\r\n        data: {\r\n          options: [\r\n            { label: 'Primary button', value: 'primary' },\r\n            { label: 'Secondary button', value: 'secondary' },\r\n            { label: 'Tertiary button', value: 'tertiary' }\r\n          ]\r\n        }\r\n      }\r\n    },\r\n    reduceType: {\r\n      editor: {\r\n        data: {\r\n          label: 'Value type',\r\n          options: [\r\n            { label: 'Percentage', value: 'PERCENTAGE' },\r\n            { label: 'Fixed amount', value: 'FIXED_AMOUNT' }\r\n          ]\r\n        }\r\n      }\r\n    },\r\n    limitUsedType: {\r\n      editor: {\r\n        data: {\r\n          label: 'A customer can use the discount',\r\n          options: [\r\n            { label: 'Unlimited times', value: 'LIMIT_TOTAL' },\r\n            { label: 'Only once', value: 'LIMIT_PER_CUSTOMER' }\r\n          ]\r\n        }\r\n      }\r\n    },\r\n    buttonLink: {\r\n      editor: {\r\n        data: {\r\n          label: 'Button link',\r\n          storeLink\r\n        }\r\n      }\r\n    },\r\n    autoDiscount: {\r\n      editor: {\r\n        data: {\r\n          label: 'Apply Shopify discount link',\r\n          platform,\r\n          // eslint-disable-next-line\r\n          desc: \"lf enabled, we'll automatically applythe discount once the customerreaches the checkout page.\",\r\n          storeLink\r\n        }\r\n      }\r\n    },\r\n    collectionList: {\r\n      editor: {\r\n        data: {\r\n          label: 'Connection name',\r\n          getConnectionUrl,\r\n          quickToken\r\n        }\r\n      }\r\n    }\r\n  };\r\n};\r\n","import { debounce } from 'lodash';\nimport React, {\n  forwardRef,\n  useCallback,\n  useImperativeHandle,\n  useMemo,\n  useRef\n} from 'react';\nimport EmailEditor, { FileInfo, HtmlExport } from 'react-email-editor';\nimport {\n  EditorConfigType,\n  EditorRef,\n  EmailEditorProps,\n  ParamType\n} from '../types/emailEditor';\nimport { customCSS } from '../utils/customCSS';\nimport generateJs from '../utils/customJS';\nimport { html2Image } from '../utils/html2Image';\nimport { discountProperties } from './constants';\n\nexport type { EmailEditorProps, EditorConfigType };\nexport type { EditorRef, ParamType };\n// eslint-disable-next-line\nexport const QuickEditor = forwardRef(\n  (\n    {\n      quickToken,\n      editorConfig,\n      height,\n      uploadImage,\n      updateDesign,\n      getProductUrl,\n      getProductByTypeUrl,\n      systemParam,\n      customFonts,\n      platform,\n      storeLink,\n      getConnectionUrl,\n      timeZone\n    }: EmailEditorProps,\n    ref\n  ) => {\n    const emailEditorRef = useRef<any>(null);\n    const prepareSaveDesign = (design) => {\n      const errors: Array<{ [props: string]: string }> = [];\n      const checkUrlByType = {\n        button: (values) => {\n          const {\n            name,\n            values: { href }\n          } = values.href;\n          if (name === 'web' && !href) {\n            const div = document.createElement('div');\n            div.innerHTML = values.text;\n            const text = div.innerText;\n            errors.push({\n              id: values._meta.htmlID,\n              content: `BUTTON-${text}`,\n              type: !href ? 'noneError' : 'typeError'\n            });\n          }\n        },\n        social: (values) => {\n          const { icons } = values.icons;\n          icons.forEach((icon) => {\n            const { name, url } = icon;\n            if (!url) {\n              errors.push({\n                id: values._meta.htmlID,\n                content: `SOCIAL-${name as string}`,\n                type: !url ? 'noneError' : 'typeError'\n              });\n            }\n          });\n        },\n        menu: (values) => {\n          const { items } = values.menu;\n          items.forEach((item) => {\n            const {\n              link: { name, values: linkValues },\n              text\n            } = item;\n            if (name === 'web' && !linkValues.href) {\n              errors.push({\n                id: values._meta.htmlID,\n                content: `MENU-${text as string}`,\n                type: !linkValues.href ? 'noneError' : 'typeError'\n              });\n            }\n          });\n        }\n      };\n      design.body.rows.forEach((row) => {\n        row.columns.forEach((column) => {\n          column.contents.forEach((content) => {\n            const { type, values } = content;\n            checkUrlByType[type]?.(values);\n          });\n        });\n      });\n      return errors;\n    };\n    useImperativeHandle(ref, () => ({\n      exportHtml: (func: any) =>\n        emailEditorRef.current?.editor?.exportHtml(func),\n      saveDesign: (func: any, errorFunc: any) => {\n        emailEditorRef.current?.editor?.exportHtml(async (data: HtmlExport) => {\n          let usefreemarker = false;\n          data.html.includes('data-useFreeMarker') && (usefreemarker = true);\n          emailEditorRef.current?.editor?.saveDesign((design) => {\n            const errors = prepareSaveDesign(design);\n            if (errors.length) {\n              errorFunc(errors);\n            } else {\n              // 使用product和freemarker组件时 需要向后端传递标志\n              design.usefreemarker = usefreemarker;\n              func(design);\n            }\n          });\n        });\n      },\n      exportImage: async (func: any) => {\n        // emailEditorRef.current?.editor?.saveDesign((design: SaveDesignCallback) => {\n        //   exportImage(generateAuth(APIKey), design, {})\n        // })\n        emailEditorRef.current?.editor?.exportHtml(async (data: HtmlExport) => {\n          const blob = await html2Image(data.html);\n          func(blob);\n        });\n      },\n      loadDesign: (data) => {\n        emailEditorRef.current?.editor\n          ? emailEditorRef.current?.editor?.loadDesign(data)\n          : setTimeout(\n              () => emailEditorRef.current?.editor?.loadDesign(data),\n              0\n            );\n      },\n      updateDesign: (func: any) =>\n        emailEditorRef.current?.editor?.saveDesign(func)\n    }));\n    const onDesignUpdate = useCallback(() => {\n      emailEditorRef.current?.editor?.exportHtml((data) => {\n        const json = data?.design;\n        const html = data?.html || '';\n        const errors = prepareSaveDesign(json);\n        updateDesign(json, html, errors);\n      });\n    }, [updateDesign]);\n\n    const onDesignLoad = () => {\n      // 注册回调事件 使用uploadImage\n      emailEditorRef.current?.registerCallback(\n        'image',\n        async (file: FileInfo, done: any) => {\n          await uploadImage(file.attachments?.[0], done);\n        }\n      );\n    };\n    const registerEvent = () => {\n      emailEditorRef.current?.editor?.addEventListener(\n        'design:loaded',\n        onDesignLoad\n      );\n      emailEditorRef.current?.editor?.addEventListener(\n        'design:updated',\n        onDesignUpdate\n      );\n    };\n\n    const onLoad = () => {\n      if (emailEditorRef.current?.editor) {\n        initEditor();\n      }\n    };\n    const onReady = () => {\n      if (emailEditorRef.current?.editor) {\n        initEditor();\n      }\n    };\n    const initEditor = () => {\n      registerEvent();\n      // link标签移除sms设置\n      emailEditorRef.current?.editor?.setLinkTypes([\n        {\n          name: 'sms',\n          enabled: false\n        }\n      ]);\n    };\n\n    // product配置\n    const tools: any = useMemo(() => {\n      return {\n        'custom#product_tool': {\n          // 数据传递给自定义组件\n          data: {\n            products: []\n          },\n          properties: {\n            // 默认属性设置\n            containerPadding: {\n              value: '0px'\n            },\n            // 数据传递给自定义属性\n            productLibrary: {\n              editor: {\n                data: {\n                  products: [],\n                  currentSelectProduct: [],\n                  keyword: '',\n                  getProductUrl,\n                  getProductByTypeUrl,\n                  quickToken,\n                  total: 10,\n                  totalPage: 1,\n                  currentPage: 1\n                }\n              }\n            }\n          }\n        },\n        'custom#my_tool': {\n          data: {\n            saveContent: ''\n          }\n        },\n        'custom#discount': {\n          usageLimit: 1,\n          properties: discountProperties(\n            quickToken,\n            platform,\n            storeLink,\n            getConnectionUrl,\n            timeZone\n          )\n        },\n        image: {\n          properties: {\n            src: {\n              value: {\n                url: 'https://quick-cep.oss-cn-shanghai.aliyuncs.com/446/ma/template/html2canvas/764158287988916224/ed294e6e-098d-463c-9618-30411c3794c9.png',\n                width: 600,\n                height: 200\n              }\n            }\n          }\n        }\n      };\n    }, [\n      quickToken,\n      getProductUrl,\n      getProductByTypeUrl,\n      platform,\n      storeLink,\n      getConnectionUrl,\n      timeZone\n    ]);\n    // tags\n    const mergeTags: any = useMemo(() => {\n      return {\n        system_param: {\n          name: 'System param',\n          mergeTags: systemParam\n        },\n        custom_variable: {\n          name: 'Custom variable',\n          value: '[custom.xx]',\n          sample: '[custom.xx]'\n        }\n      };\n    }, [systemParam]);\n\n    const options: any = useMemo(() => {\n      return {\n        // 只有添加了user 才会显示user uploads\n        // user: {\n        //   id: editorConfig?.userId || 123,\n        // },\n        mergeTagsConfig: {\n          sort: false\n        },\n        fonts: {\n          showDefaultFonts: true,\n          customFonts\n        },\n        mergeTags,\n        // 修改默认滚动条\n        customCSS,\n        customJS: generateJs(customFonts, platform),\n        features: {\n          // 去除mergeTags默认样式\n          smartMergeTags: false,\n          textEditor: {\n            emojis: true, // 表情编辑\n            // tables: true, // 文本编辑表格功能呢\n            spellChecker: true // 文字拼写检查\n          }\n        }\n      };\n    }, []);\n\n    const editor = useMemo(\n      () => (\n        <EmailEditor\n          ref={emailEditorRef}\n          minHeight={height}\n          projectId={88838}\n          appearance={{\n            theme: editorConfig?.theme ?? 'light',\n            panels: {\n              tools: {\n                dock: editorConfig?.dock ?? 'right'\n              }\n            }\n          }}\n          tools={tools}\n          options={options}\n          onLoad={onLoad}\n          onReady={onReady}\n        />\n      ),\n      [height]\n    );\n    return editor;\n  }\n);\n"]}