@fluid-app/dam-picker

中文文档
0.2.10发布于 2026/07/15MITTypeScriptESM + CJS零依赖近 30 天下载 2.4万

Embeddable DAM file picker for Fluid Commerce applications

原始使用文档
文档目录17 节
  1. Features
  2. Installation
  3. Quick Start
  4. Vanilla JavaScript
  5. React (Hook)
  6. React (Component)
  7. API Reference
  8. DamPicker
  9. SelectedAsset
  10. DamPickerError
  11. Filtering Asset Types
  12. Multi-Select
  13. Upload Behavior
  14. Vue.js Integration
  15. Angular Integration
  16. Local Development
  17. License

@fluid-app/dam-picker

Embeddable DAM (Digital Asset Management) file picker for Fluid Commerce applications.

Features

  • Browse DAM Library - Search and navigate your existing assets
  • Upload Files - Drag & drop or click to upload from computer
  • Import from URL - Import files directly from any public URL
  • Asset Type Filtering - Filter by images, videos, documents, or audio
  • Framework Agnostic - Works with React, Vue, Angular, or vanilla JavaScript

Installation

npm install @fluid-app/dam-picker
# or
pnpm add @fluid-app/dam-picker
# or
yarn add @fluid-app/dam-picker

Quick Start

Vanilla JavaScript

import { DamPicker } from '@fluid-app/dam-picker';

const picker = new DamPicker({
  token: 'your-fluid-api-token',
  onSelect: (assets) => {
    console.log('Selected asset:', assets[0].url);
    // Use the asset URL in your application
  },
  onCancel: () => {
    console.log('User cancelled');
  },
  onError: (error) => {
    console.error('Error:', error.message);
  },
});

// Open the picker
document.getElementById('choose-image').addEventListener('click', () => {
  picker.open();
});

React (Hook)

import { useDamPicker } from '@fluid-app/dam-picker/react';

function ImageSelector() {
  const [imageUrl, setImageUrl] = useState(null);
  const { open } = useDamPicker({ token: 'your-fluid-api-token' });

  const handleChooseImage = () => {
    open({
      onSelect: (assets) => setImageUrl(assets[0].url),
      onCancel: () => console.log('Cancelled'),
    });
  };

  return (
    <div>
      <button onClick={handleChooseImage}>Choose Image</button>
      {imageUrl && <img src={imageUrl} alt="Selected" />}
    </div>
  );
}

React (Component)

import { useState } from 'react';
import { DamPickerModal } from '@fluid-app/dam-picker/react';

function ImageSelector() {
  const [isOpen, setIsOpen] = useState(false);
  const [imageUrl, setImageUrl] = useState(null);

  return (
    <div>
      <button onClick={() => setIsOpen(true)}>Choose Image</button>
      {imageUrl && <img src={imageUrl} alt="Selected" />}

      <DamPickerModal
        isOpen={isOpen}
        token="your-fluid-api-token"
        onSelect={(assets) => {
          setImageUrl(assets[0].url);
          setIsOpen(false);
        }}
        onCancel={() => setIsOpen(false)}
      />
    </div>
  );
}

API Reference

DamPicker

The main class for vanilla JavaScript usage.

Constructor Options

OptionTypeRequiredDescription
tokenstringYesYour Fluid API token
onSelect(assets: SelectedAsset[]) => voidYesCalled when user selects asset(s)
onCancel() => voidNoCalled when user cancels
onError(error: DamPickerError) => voidNoCalled on errors
onReady() => voidNoCalled when picker is ready
baseUrlstringNoOverride the picker app URL (for local development)
zIndexnumberNoModal z-index (default: 10000)
maxSelectablenumberNoMaximum number of selectable assets (default: 1, minimum: 1)
filters.assetTypesstring[]NoFilter by asset types: 'images', 'videos', 'documents', 'audio'

Methods

  • open() - Opens the picker modal
  • close() - Closes the picker modal
  • destroy() - Cleans up the picker instance
  • isOpen() - Returns whether the picker is currently open

SelectedAsset

The asset object returned on selection (both from library selection and uploads).

interface SelectedAsset {
  url: string;           // Public URL to the asset
  assetCode: string;     // Unique asset identifier
  name: string;          // Display name
  mimeType: string;      // MIME type (e.g., "image/png")
  metadata?: {
    width?: number;      // Image/video width
    height?: number;     // Image/video height
    fileSize?: number;   // File size in bytes
  };
  variantId?: string;    // Selected variant ID (if applicable)
}

DamPickerError

Error object passed to onError callback.

interface DamPickerError {
  code: 'AUTHENTICATION_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT' | 'UNKNOWN';
  message: string;
}

Filtering Asset Types

You can restrict which asset types users can browse and upload:

const picker = new DamPicker({
  token: 'your-token',
  filters: {
    assetTypes: ['images', 'videos'], // Only show images and videos
  },
  onSelect: (assets) => console.log(assets),
});

Available asset types:

  • 'images' - Image files (jpg, png, gif, webp, svg, etc.)
  • 'videos' - Video files (mp4, webm, mov, etc.)
  • 'documents' - Documents (pdf, doc, docx, xls, xlsx, etc.)
  • 'audio' - Audio files (mp3, wav, ogg, etc.)

Multi-Select

By default, users can select one asset at a time. Use maxSelectable to allow multiple selections:

const picker = new DamPicker({
  token: 'your-token',
  maxSelectable: 5, // Allow up to 5 assets
  onSelect: (assets) => {
    assets.forEach((asset) => console.log(asset.url));
  },
});

Breaking change: onSelect now always receives an array of SelectedAsset[], even when maxSelectable is 1.

Upload Behavior

When users upload a file (either from computer or URL):

  1. The file is uploaded to Fluid's DAM via ImageKit
  2. Once complete, the onSelect callback is fired with the new asset
  3. The picker automatically closes after successful upload

This means you handle uploads the same way as library selections - just listen for onSelect.

Vue.js Integration

Use the vanilla JavaScript API in Vue:

<script setup>
import { ref, onMounted, onUnmounted } from 'vue';
import { DamPicker } from '@fluid-app/dam-picker';

const imageUrl = ref(null);
let picker = null;

onMounted(() => {
  picker = new DamPicker({
    token: 'your-fluid-api-token',
    onSelect: (assets) => {
      imageUrl.value = assets[0].url;
    },
  });
});

onUnmounted(() => {
  picker?.destroy();
});

const openPicker = () => picker?.open();
</script>

<template>
  <div>
    <button @click="openPicker">Choose Image</button>
    <img v-if="imageUrl" :src="imageUrl" alt="Selected" />
  </div>
</template>

Angular Integration

import { Component, OnDestroy } from '@angular/core';
import { DamPicker } from '@fluid-app/dam-picker';

@Component({
  selector: 'app-image-selector',
  template: `
    <button (click)="openPicker()">Choose Image</button>
    <img *ngIf="imageUrl" [src]="imageUrl" alt="Selected" />
  `,
})
export class ImageSelectorComponent implements OnDestroy {
  imageUrl: string | null = null;
  private picker: DamPicker;

  constructor() {
    this.picker = new DamPicker({
      token: 'your-fluid-api-token',
      onSelect: (assets) => {
        this.imageUrl = assets[0].url;
      },
    });
  }

  openPicker() {
    this.picker.open();
  }

  ngOnDestroy() {
    this.picker.destroy();
  }
}

Local Development

For local development, point the SDK to your local fluid-admin instance:

const picker = new DamPicker({
  token: 'your-token',
  baseUrl: 'http://localhost:3007/dam-picker',
  onSelect: (assets) => console.log(assets),
});

License

MIT

版本与发布记录

@fluid-app/dam-picker 共发布 10 个版本,首次发布于 2026/04/16;过去 12 个月发布了 10 个版本。

版本发布日期距今
0.2.10latest2026/07/154 个月前
0.2.92026/07/144 个月前
0.2.82026/06/214 个月前
0.2.72026/05/026 个月前
0.2.62026/05/016 个月前
0.2.52026/05/016 个月前

关于 @fluid-app/dam-picker 的常见问题

@fluid-app/dam-picker 是什么?

Embeddable DAM file picker for Fluid Commerce applications

如何安装 @fluid-app/dam-picker?

在项目目录运行 npm install @fluid-app/dam-picker,或使用 pnpm add / yarn add / bun add。

@fluid-app/dam-picker 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fluid-app/dam-picker 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@fluid-app/dam-picker 可以商用吗?

@fluid-app/dam-picker 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fluid-app/dam-picker 的下载量有多少?

根据 npm 官方下载统计,@fluid-app/dam-picker 在 2026/10/15 – 2026/11/13 这 30 天内被下载 23,529 次,日均约 784 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fluid-app/dam-picker 还在维护吗?

最新版本 0.2.10 发布于 2026/07/15(4 个月前);至今共发布 10 个版本,其中过去 12 个月发布了 10 个;首次发布于 2026/04/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。