@girder/components

中文文档
4.0.2发布于 2026/05/18Apache-2.0ESM + CJS近 30 天下载 3298

Try the demo app. It works with data.kitware.com.

原始使用文档
文档目录12 节
  1. Usage Quickstart
  2. Installation
  3. Initialization
  4. Using Components
  5. Advanced Usage
  6. Customizing Vuetify Configuration
  7. Other installation methods
  8. For developers
  9. Use an external Girder API
  10. Displaying private media from Girder on a page
  11. Deploy and Publish
  12. Type Definitions

Girder web component library

Try the demo app. It works with data.kitware.com.

Usage Quickstart

Latest version only support Vue3. For Vue2, @girder/components v3.3.0 should be used.

Installation

Vite is required for building applications with Girder web components.

# Install GWC
yarn add @girder/components
# or
npm install @girder/components

Initialization

The lib exports the components and a plugin that initializes a RestClient and a NotificationBus, provide them and register the vuetify configuration. It can optionally register all components.

Example of application initialization using the plugin (typically src/main.js):

/* src/main.js */
import { createApp } from 'vue'
import App from './App.vue'

import GirderPlugin from '@girder/components'

const app = createApp(App)

app.use(GirderPlugin, {
  girder: {apiRoot: import.meta.env.VITE_API_ROOT},
  notification: {useEventSource: true},
  components: true // register all components
})
app.mount('#app')

Using Components

All components are prefixed Girder.

In this case the plugin does not register all components, thus to use components individually, they should be imported by name from @girder/components/, as this location will be stable across releases. For instance:

import { GirderUpload } from '@girder/components/'; // Good
import { Upload } from '@girder/components/src/components/Upload/Upload.vue'; // Unsafe -- may move in the future

Since Girder web components uses Vuetify, your application must provide v-app and v-content containers at some ancestor level.

For example, to create a login / registration widget in src/App.vue:

<!-- src/App.vue -->
<template>
  <v-app>
    <v-content>
      <h1>Welcome {{ currentUserLogin }}</h1>
      <GirderAuthentication />
    </v-content>
  </v-app>
</template>

<script setup>
import { inject, computed } from 'vue';
import { GirderAuthentication } from '@girder/components/';

// Injecting 'rest' is not necessary to use the component,
// but is required to access the results of API calls
const { rest, user } = inject('girder');
const currentUserLogin = computed(() => user.value ? user.value.login : 'anonymous');
</script>

Global registration

In this case, the components are registered by the plugin, so they do not need to be imported. See the demo app for a more comprehensive example.

Advanced Usage

Customizing Vuetify Configuration

Custom additional vuetify configuration can be passed to the plugin through the vuetifyConfig option. If your downstream application is also using Vuetify and needs to pass additional configuration options, it must be careful to coordinate with Girder web components.

/* src/main.js */
import { createApp } from 'vue'
import App from './App.vue'

import GirderPlugin from '@girder/components'

const app = createApp(App)

app.use(GirderPlugin, {
  girder: {apiRoot: import.meta.env.VITE_API_ROOT},
  notification: {useEventSource: true},
  vuetifyConfig: {icons: {aliases: {login: 'mdi-circle' }}}
})
app.mount('#app')

Note: You must use the mdi icon pack. Icon packs cannot be mixed.

Other installation methods

It's not necessary to install Girder web components yourself, you can import the pre-built bundle.

Using CDN/UMD

<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<script src="https://unpkg.com/@girder/components"></script>
<link rel="stylesheet" href="https://unpkg.com/@girder/components/dist/style.css">
<script>
  const app = Vue.createApp({});
  app.use(girder);
  app.mount('#app');
</script>

This exposes the plugin under the global variable girder.

Using ESM

<script type="module">
import Gwc, { GirderUpload } from 'https://unpkg.com/@girder/components?module';

const app = Vue.createApp({});
app.use(Gwc);
app.component('GirderUpload', GirderUpload);
app.mount('#app');
</script>

For developers

# Project Setup
yarn

# Compile and hot-reload for development
yarn serve

# Build the library for production
yarn build

# Lint and fix source code
yarn lint
yarn lint:style

# Run unit tests
yarn test:unit

Use an external Girder API

To build the demo app against an external Girder API, set the VITE_API_ROOT environment variable. For example:

export VITE_API_ROOT=https://data.kitware.com/api/v1
yarn serve

This variable value defaults to http://localhost:8080/api/v1 for normal development (which assumes the developer has a local instance of the Girder API server running). When running against your own instance of the Girder API server, make sure to set CORS accordingly.

Displaying private media from Girder on a page

If your app injects media dynamically into the page using img or video elements that load from Girder, there are several requirements.

  • You must use the authenticateWithCredentials option in the GirderRest constructor.
  • You must modify Girder's CORS allowed origin settings to match your app's origin exactly. You can use a comma-separated list to match multiple origins, for example *, http://localhost:8080, https://myapp.domain.com
  • To interact with the loaded element data from a canvas or JS, you may need to add the crossOrigin attribute to the media element.

Deploy and Publish

The demo app is automatically deployed to gwc.girder.org.

Any contributor can request an update to the published npmjs version by changing the version string in package.json and opening a pull request. Our CI runner will detect the change and publish on merge. Version update PRs should generally happen independently of feature PRs.

Type Definitions

TypeScript type defs are maintained at index.d.ts. Please remember to update this file if your change impacts the public api.

版本与发布记录

@girder/components 共发布 39 个版本,首次发布于 2018/09/17;过去 12 个月发布了 4 个版本。

版本发布日期距今
4.0.2latest2026/05/185 个月前
4.0.12026/03/068 个月前
4.0.02026/02/099 个月前
3.3.02026/01/249 个月前
3.2.02022/03/164 年前
3.1.02021/09/295 年前

关于 @girder/components 的常见问题

@girder/components 是什么?

Try the demo app. It works with data.kitware.com.

如何安装 @girder/components?

在项目目录运行 npm install @girder/components,或使用 pnpm add / yarn add / bun add。

@girder/components 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/girder__components 是否存在。

@girder/components 支持 ESM 还是 CommonJS?

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

@girder/components 可以商用吗?

@girder/components 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@girder/components 的下载量有多少?

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

@girder/components 还在维护吗?

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