Преглед изворни кода

@uppy/zoom: refactor to ESM (#3699)

Antoine du Hamel пре 2 година
родитељ
комит
010a6b162f

+ 1 - 0
.eslintrc.js

@@ -216,6 +216,7 @@ module.exports = {
         'packages/@uppy/url/src/**/*.js',
         'packages/@uppy/vue/src/**/*.js',
         'packages/@uppy/webcam/src/**/*.js',
+        'packages/@uppy/zoom/src/**/*.js',
       ],
       parser: 'espree',
       parserOptions: {

+ 1 - 0
packages/@uppy/zoom/package.json

@@ -5,6 +5,7 @@
   "license": "MIT",
   "main": "lib/index.js",
   "types": "types/index.d.ts",
+  "type": "module",
   "keywords": [
     "file uploader",
     "uppy",

+ 72 - 0
packages/@uppy/zoom/src/Zoom.jsx

@@ -0,0 +1,72 @@
+import { h } from 'preact'
+
+import { UIPlugin } from '@uppy/core'
+import { Provider } from '@uppy/companion-client'
+import { ProviderViews } from '@uppy/provider-views'
+
+import packageJson from '../package.json'
+import locale from './locale.js'
+
+export default class Zoom extends UIPlugin {
+  static VERSION = packageJson.version
+
+  constructor (uppy, opts) {
+    super(uppy, opts)
+    this.id = this.opts.id || 'Zoom'
+    Provider.initPlugin(this, opts)
+    this.title = this.opts.title || 'Zoom'
+    this.icon = () => (
+      <svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
+        <rect className="uppy-ProviderIconBg" width="32" height="32" rx="16" fill="#0E71EB" />
+        <g fill="none" fillRule="evenodd">
+          <path fill="#fff" d="M29,31H14c-1.657,0-3-1.343-3-3V17h15c1.657,0,3,1.343,3,3V31z" style={{ transform: 'translate(-5px, -5px) scale(0.9)' }} />
+          <polygon fill="#fff" points="37,31 31,27 31,21 37,17" style={{ transform: 'translate(-5px, -5px) scale(0.9)' }} />
+        </g>
+      </svg>
+    )
+
+    this.provider = new Provider(uppy, {
+      companionUrl: this.opts.companionUrl,
+      companionHeaders: this.opts.companionHeaders,
+      companionKeysParams: this.opts.companionKeysParams,
+      companionCookiesRule: this.opts.companionCookiesRule,
+      provider: 'zoom',
+      pluginId: this.id,
+    })
+
+    this.defaultLocale = locale
+
+    this.i18nInit()
+    this.title = this.i18n('pluginNameZoom')
+
+    this.onFirstRender = this.onFirstRender.bind(this)
+    this.render = this.render.bind(this)
+  }
+
+  install () {
+    this.view = new ProviderViews(this, {
+      provider: this.provider,
+    })
+
+    const { target } = this.opts
+    if (target) {
+      this.mount(target, this)
+    }
+  }
+
+  uninstall () {
+    this.view.tearDown()
+    this.unmount()
+  }
+
+  onFirstRender () {
+    return Promise.all([
+      this.provider.fetchPreAuthToken(),
+      this.view.getFolder(),
+    ])
+  }
+
+  render (state) {
+    return this.view.render(state)
+  }
+}

+ 1 - 70
packages/@uppy/zoom/src/index.js

@@ -1,70 +1 @@
-const { UIPlugin } = require('@uppy/core')
-const { Provider } = require('@uppy/companion-client')
-const { ProviderViews } = require('@uppy/provider-views')
-const { h } = require('preact')
-
-const locale = require('./locale')
-
-module.exports = class Zoom extends UIPlugin {
-  static VERSION = require('../package.json').version
-
-  constructor (uppy, opts) {
-    super(uppy, opts)
-    this.id = this.opts.id || 'Zoom'
-    Provider.initPlugin(this, opts)
-    this.title = this.opts.title || 'Zoom'
-    this.icon = () => (
-      <svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
-        <rect className="uppy-ProviderIconBg" width="32" height="32" rx="16" fill="#0E71EB" />
-        <g fill="none" fillRule="evenodd">
-          <path fill="#fff" d="M29,31H14c-1.657,0-3-1.343-3-3V17h15c1.657,0,3,1.343,3,3V31z" style={{ transform: 'translate(-5px, -5px) scale(0.9)' }} />
-          <polygon fill="#fff" points="37,31 31,27 31,21 37,17" style={{ transform: 'translate(-5px, -5px) scale(0.9)' }} />
-        </g>
-      </svg>
-    )
-
-    this.provider = new Provider(uppy, {
-      companionUrl: this.opts.companionUrl,
-      companionHeaders: this.opts.companionHeaders,
-      companionKeysParams: this.opts.companionKeysParams,
-      companionCookiesRule: this.opts.companionCookiesRule,
-      provider: 'zoom',
-      pluginId: this.id,
-    })
-
-    this.defaultLocale = locale
-
-    this.i18nInit()
-    this.title = this.i18n('pluginNameZoom')
-
-    this.onFirstRender = this.onFirstRender.bind(this)
-    this.render = this.render.bind(this)
-  }
-
-  install () {
-    this.view = new ProviderViews(this, {
-      provider: this.provider,
-    })
-
-    const { target } = this.opts
-    if (target) {
-      this.mount(target, this)
-    }
-  }
-
-  uninstall () {
-    this.view.tearDown()
-    this.unmount()
-  }
-
-  onFirstRender () {
-    return Promise.all([
-      this.provider.fetchPreAuthToken(),
-      this.view.getFolder(),
-    ])
-  }
-
-  render (state) {
-    return this.view.render(state)
-  }
-}
+export { default } from './Zoom.jsx'

+ 1 - 1
packages/@uppy/zoom/src/locale.js

@@ -1,4 +1,4 @@
-module.exports = {
+export default {
   strings: {
     pluginNameZoom: 'Zoom',
   },

+ 1 - 1
website/src/docs/zoom.md

@@ -93,7 +93,7 @@ This option correlates to the [RequestCredentials value](https://developer.mozil
 <!-- eslint-disable no-restricted-globals, no-multiple-empty-lines -->
 
 ```js
-module.exports = {
+export default {
   strings: {
     pluginNameZoom: 'Zoom',
   },