Parcourir la source

@uppy/unsplash: refactor to ESM (#3728)

Antoine du Hamel il y a 2 ans
Parent
commit
3d67029a04

+ 1 - 0
.eslintrc.js

@@ -218,6 +218,7 @@ module.exports = {
         'packages/@uppy/svelte/src/**/*.js',
         'packages/@uppy/svelte/rollup.config.js',
         'packages/@uppy/tus/src/**/*.js',
+        'packages/@uppy/unsplash/src/**/*.js',
         'packages/@uppy/url/src/**/*.js',
         'packages/@uppy/vue/src/**/*.js',
         'packages/@uppy/webcam/src/**/*.js',

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

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

+ 69 - 0
packages/@uppy/unsplash/src/Unsplash.jsx

@@ -0,0 +1,69 @@
+import { h } from 'preact'
+import { UIPlugin } from '@uppy/core'
+import { SearchProvider, Provider } from '@uppy/companion-client'
+import { SearchProviderViews } from '@uppy/provider-views'
+
+import packageJson from '../package.json'
+
+/**
+ * Unsplash
+ *
+ */
+export default class Unsplash extends UIPlugin {
+  static VERSION = packageJson.version
+
+  constructor (uppy, opts) {
+    super(uppy, opts)
+    this.id = this.opts.id || 'Unsplash'
+    this.title = this.opts.title || 'Unsplash'
+
+    Provider.initPlugin(this, opts, {})
+
+    this.icon = () => (
+      <svg viewBox="0 0 32 32" height="32" width="32" aria-hidden="true">
+        <path d="M46.575 10.883v-9h12v9zm12 5h10v18h-32v-18h10v9h12z" fill="#fff" />
+        <rect className="uppy-ProviderIconBg" width="32" height="32" rx="16" />
+        <path d="M13 12.5V8h6v4.5zm6 2.5h5v9H8v-9h5v4.5h6z" fill="#fff" />
+      </svg>
+    )
+
+    if (!this.opts.companionUrl) {
+      throw new Error('Companion hostname is required, please consult https://uppy.io/docs/companion')
+    }
+
+    this.hostname = this.opts.companionUrl
+
+    this.provider = new SearchProvider(uppy, {
+      companionUrl: this.opts.companionUrl,
+      companionHeaders: this.opts.companionHeaders,
+      companionCookiesRule: this.opts.companionCookiesRule,
+      provider: 'unsplash',
+      pluginId: this.id,
+    })
+  }
+
+  install () {
+    this.view = new SearchProviderViews(this, {
+      provider: this.provider,
+      viewType: 'unsplash',
+    })
+
+    const { target } = this.opts
+    if (target) {
+      this.mount(target, this)
+    }
+  }
+
+  // eslint-disable-next-line class-methods-use-this
+  onFirstRender () {
+    // do nothing
+  }
+
+  render (state) {
+    return this.view.render(state)
+  }
+
+  uninstall () {
+    this.unmount()
+  }
+}

+ 1 - 66
packages/@uppy/unsplash/src/index.js

@@ -1,66 +1 @@
-const { UIPlugin } = require('@uppy/core')
-const { h } = require('preact')
-const { SearchProvider, Provider } = require('@uppy/companion-client')
-const { SearchProviderViews } = require('@uppy/provider-views')
-
-/**
- * Unsplash
- *
- */
-module.exports = class Unsplash extends UIPlugin {
-  static VERSION = require('../package.json').version
-
-  constructor (uppy, opts) {
-    super(uppy, opts)
-    this.id = this.opts.id || 'Unsplash'
-    this.title = this.opts.title || 'Unsplash'
-
-    Provider.initPlugin(this, opts, {})
-
-    this.icon = () => (
-      <svg viewBox="0 0 32 32" height="32" width="32" aria-hidden="true">
-        <path d="M46.575 10.883v-9h12v9zm12 5h10v18h-32v-18h10v9h12z" fill="#fff" />
-        <rect className="uppy-ProviderIconBg" width="32" height="32" rx="16" />
-        <path d="M13 12.5V8h6v4.5zm6 2.5h5v9H8v-9h5v4.5h6z" fill="#fff" />
-      </svg>
-    )
-
-    if (!this.opts.companionUrl) {
-      throw new Error('Companion hostname is required, please consult https://uppy.io/docs/companion')
-    }
-
-    this.hostname = this.opts.companionUrl
-
-    this.provider = new SearchProvider(uppy, {
-      companionUrl: this.opts.companionUrl,
-      companionHeaders: this.opts.companionHeaders,
-      companionCookiesRule: this.opts.companionCookiesRule,
-      provider: 'unsplash',
-      pluginId: this.id,
-    })
-  }
-
-  install () {
-    this.view = new SearchProviderViews(this, {
-      provider: this.provider,
-      viewType: 'unsplash',
-    })
-
-    const { target } = this.opts
-    if (target) {
-      this.mount(target, this)
-    }
-  }
-
-  onFirstRender () {
-    // do nothing
-  }
-
-  render (state) {
-    return this.view.render(state)
-  }
-
-  uninstall () {
-    this.unmount()
-  }
-}
+export { default } from './Unsplash.jsx'