@raster-app/react 0.1.0-rc.1 → 0.2.0-canary-846559b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,26 +1,28 @@
1
1
  # @raster-app/react
2
2
 
3
- React bindings for [`@raster-app/sdk`](https://www.npmjs.com/package/@raster-app/sdk): a drop-in
4
- Raster asset picker, and the provider and hooks it is built on (session, organizations,
5
- libraries, assets, search, uploads and the navigation model every Raster plugin shares). They
6
- cache in TanStack Query.
3
+ Raster's asset picker for React, and hooks to build your own Raster UI.
4
+
5
+ ## Documentation
6
+
7
+ [raster.app/docs/api/sdk](https://raster.app/docs/api/sdk)
8
+
9
+ ## Requirements
10
+
11
+ - React 18 or 19
12
+ - Node.js 22.12 or later
13
+
14
+ ## Installation
7
15
 
8
16
  ```sh
9
17
  npm install @raster-app/react
10
18
  ```
11
19
 
12
- It takes the host's React, 18 or 19, as a peer dependency. It re-exports all of
13
- `@raster-app/sdk`, so the client, `toUserMessage` and types such as `Asset` and `Library` come
14
- from `@raster-app/react` too.
20
+ It includes [`@raster-app/sdk`](https://www.npmjs.com/package/@raster-app/sdk) and re-exports all
21
+ of it, so import the client, `toUserMessage` and types such as `Asset` from `@raster-app/react`.
15
22
 
16
- ## The picker
23
+ ## Usage
17
24
 
18
- `RasterPicker` is Raster's asset picker, drawn in Raster's own design: sign-in with the device
19
- grant or an API key, Raster's organization switcher, the organization's libraries, search, and
20
- infinite scroll. A tile opens its asset large, with Pick asset and Open in Raster, which goes
21
- through the host's `openExternal`, over the asset's versions, where a variant is uploaded or set as
22
- the default. It uploads into a library from its menu or a drop. An organization or a library is
23
- read as the pointer reaches it, so it opens at once. It fills its container.
25
+ ### Add the picker
24
26
 
25
27
  ```tsx
26
28
  import {
@@ -31,11 +33,11 @@ import {
31
33
  } from '@raster-app/react'
32
34
  import '@raster-app/react/styles.css'
33
35
 
34
- function Picker({ onImage }: { onImage: (url: string) => void }) {
36
+ export function Picker({ onImage }: { onImage: (url: string) => void }) {
35
37
  return (
36
38
  <RasterProvider
37
39
  config={{
38
- host: { name: 'Sanity', openExternal: (url) => window.open(url, '_blank') },
40
+ host: { name: 'My App', openExternal: (url) => window.open(url, '_blank') },
39
41
  credentials: localStorageCredentialStore(),
40
42
  }}
41
43
  >
@@ -45,93 +47,106 @@ function Picker({ onImage }: { onImage: (url: string) => void }) {
45
47
  }
46
48
  ```
47
49
 
48
- | Prop | What it does |
49
- | ---------------- | --------------------------------------------------------------------------------------------------------------- |
50
- | `onPick` | Called with the picked `Asset`, from any view, and its organization's id. `getFullSizeUrl(asset)` is the image. |
51
- | `organizationId` | Binds the device sign-in to one organization: any other grant fails with `ORGANIZATION_MISMATCH`. |
52
- | `scope` | The consent the device sign-in asks for: `'org'` when `organizationId` is set, `'user'` otherwise. |
53
- | `onError` | Called once with each `RasterApiError` the picker shows, for the host to log. |
54
- | `theme` | `'light'` or `'dark'`. The system's color scheme when unset. |
50
+ `host.name` is the name Raster's sign-in page shows for your app, and `openExternal` opens that page
51
+ in the user's browser. `credentials` is where the sign-in is kept.
52
+
53
+ The picker signs the user in, browses their organizations and libraries, searches, uploads, and
54
+ lets them pick an asset or one of its versions. It fills its container.
55
55
 
56
- The styles are scoped under `.rs`, so they leave the host's own untouched.
56
+ | Prop | What it does |
57
+ | ------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
58
+ | `onPick(asset, organizationId)` | Called with the picked asset. `getFullSizeUrl(asset)` is its image. Leave it out for a picker that only browses. |
59
+ | `organizationId` | Limits sign-in to this organization. |
60
+ | `scope` | `'org'` to ask for one organization, `'user'` for the whole account. Defaults to `'org'` with an `organizationId`. |
61
+ | `onError(error)` | Called with each error the picker shows, for logging. |
62
+ | `theme` | `'light'` or `'dark'`. Follows the system when unset. |
57
63
 
58
- ## Your own UI
64
+ ### Build your own UI
59
65
 
60
- A host that draws its own UI uses the hooks under the same provider.
66
+ The same provider gives your components hooks.
61
67
 
62
68
  ```tsx
63
69
  import {
64
70
  RasterProvider,
65
71
  createRasterClient,
72
+ getThumbUrl,
66
73
  localStorageCredentialStore,
67
74
  useAssets,
68
- useLibraries,
69
75
  useSession,
76
+ useSignIn,
70
77
  } from '@raster-app/react'
71
78
 
72
- // Build the client once, outside render — a second one means a second session store.
79
+ // Create the client once, outside any component.
73
80
  const client = createRasterClient({
74
- host: { name: 'Sanity', openExternal: (url) => window.open(url, '_blank') },
81
+ host: { name: 'My App', openExternal: (url) => window.open(url, '_blank') },
75
82
  credentials: localStorageCredentialStore(),
76
83
  })
77
84
 
78
- function App() {
85
+ export function App() {
79
86
  return (
80
87
  <RasterProvider client={client}>
81
- <Browser />
88
+ <Library />
82
89
  </RasterProvider>
83
90
  )
84
91
  }
85
92
 
86
- function Browser() {
87
- const { isConfigured } = useSession()
88
- const libraries = useLibraries({ organizationId: 'acme' })
89
- const assets = useAssets({ organizationId: 'acme', libraryId: 'lib-1' })
93
+ function Library() {
94
+ const { credentials, isConfigured, signOut } = useSession()
95
+ const { state, signInWithDevice } = useSignIn()
96
+ // Your organization's and library's ids.
97
+ const { assets, hasMore, loadMore } = useAssets({ organizationId: 'acme', libraryId: 'lib-1' })
98
+
99
+ if (credentials === undefined) return null // still reading the saved sign-in
100
+
101
+ if (!isConfigured) {
102
+ if (state.status === 'awaitingApproval') {
103
+ return <p>Approve {state.device.userCode} in the Raster tab that just opened.</p>
104
+ }
105
+ return (
106
+ <button type="button" onClick={signInWithDevice}>
107
+ Sign in with Raster
108
+ </button>
109
+ )
110
+ }
90
111
 
91
- if (!isConfigured) return <SignIn />
92
- return <Grid assets={assets.assets ?? []} onLoadMore={assets.loadMore} />
112
+ return (
113
+ <>
114
+ {assets?.map((asset) => (
115
+ <img key={asset.id} src={getThumbUrl(asset)} alt={asset.name ?? ''} width={200} />
116
+ ))}
117
+ {hasMore && (
118
+ <button type="button" onClick={loadMore}>
119
+ Load more
120
+ </button>
121
+ )}
122
+ <button type="button" onClick={signOut}>
123
+ Sign out
124
+ </button>
125
+ </>
126
+ )
93
127
  }
94
128
  ```
95
129
 
96
- ## Provider
97
-
98
- | Prop | What it does |
99
- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
100
- | `client` or `config` | An existing `RasterClient`, or the config for one the provider creates. |
101
- | `queryClient` | The host's own TanStack `QueryClient`, from the same TanStack Query major as this package. Without one the provider creates its own, which shadows the host's for everything below. |
102
- | `state` | The `StateStore` where `useRasterNavigation` remembers the last organization and library: `memoryStateStore()` (the default), `localStorageStateStore()`, or the host's own. |
103
-
104
- ## Hooks
105
-
106
- | Hook | What it gives you |
107
- | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |
108
- | `useSession()` | The credential, `isConfigured` / `isSignedIn`, `userName`, `signOut`. |
109
- | `useSignIn()` | Device grant or API key. One state machine for both. Takes `scope` and `organizationId` for the device grant. |
110
- | `useOrganizations()` | Everything the credential reaches, from `/me`, as a TanStack query result. |
111
- | `useLibraries({ organizationId })` | The libraries in one organization, as a query result. Each carries `access`: `'write'`, `'read'` or `null` for none. |
112
- | `useAssets({ organizationId, libraryId })` | A library's assets, paged. |
113
- | `useAssetSearch(scope, query)` | Debounced, paged search that keeps the last results up while the next query runs. |
114
- | `useAssetUpload()` | Upload, then poll until Raster has finished processing. |
115
- | `usePromoteVariant()` | Promote a variant to its asset's default, then poll until Raster has swapped the files. Takes an optimistic update. |
116
- | `useRasterNavigation({ organizations })` | `organization → library → asset`, persisted; `refresh()` refetches every Raster query. |
117
-
118
- ## Things worth knowing
119
-
120
- - **The provider fixes its client on mount.** An inline `config` builds one client for the
121
- provider's life, and a later `client` prop is ignored: remount with a new `key` to switch.
122
- Two clients for one credential would each refresh it, spending each other's refresh token.
123
- - **`credentials` is `undefined` while the store is read.** Gate the sign-in screen on
124
- `isConfigured` once it has settled, or it flashes on every launch.
125
- - **Every fetch aborts when superseded**, which frees its connection for the requests that
126
- follow.
127
- - **The cache belongs to a sign-in.** Query keys carry the session's `credentialIdentity()`,
128
- and a sign-out or a different account drops the previous one's queries. For an API key that
129
- identity is a digest of the key, so the key itself stays out of the cache.
130
- - **Errors are `RasterApiError`s.** Branch on `code`, and show `toUserMessage(error)`.
131
- - **Raster finishes uploads and promotes after answering.** Both hooks poll until the work
132
- lands, and settle as `timed-out` when it outlasts the wait: the work is still running, and a
133
- later refetch shows it.
134
-
135
- ## Preact
136
-
137
- To use the hooks with Preact, alias `react` and `react-dom` to `preact/compat` in the bundler.
130
+ | Hook | What it gives you |
131
+ | ------------------------------------------ | ---------------------------------------------------------------------- |
132
+ | `useSession()` | `isConfigured`, `isSignedIn`, `userName` and `signOut()`. |
133
+ | `useSignIn()` | Sign-in with Raster's device flow or an API key. |
134
+ | `useOrganizations()` | The organizations the user can reach, in `data`. |
135
+ | `useLibraries({ organizationId })` | An organization's libraries, in `data`, each with the user's `access`. |
136
+ | `useAssets({ organizationId, libraryId })` | A library's `assets`, with `loadMore()`. |
137
+ | `useAssetSearch(scope, query)` | Search results, `hits` and `found`, as the user types. |
138
+ | `useAssetUpload()` | `upload()` a file, then wait for Raster to process it. |
139
+ | `usePromoteVariant()` | Make a variant its asset's default. |
140
+ | `useRasterNavigation({ organizations })` | The open organization, library and asset, remembered between visits. |
141
+
142
+ `RasterProvider` takes a `client`, or a `config` to create one, and `state`, where navigation is
143
+ remembered: `memoryStateStore()` by default, or `localStorageStateStore()`.
144
+
145
+ ### Errors
146
+
147
+ Every failure is a `RasterApiError`. Show the user `toUserMessage(error)`, and branch on
148
+ `error.code`.
149
+
150
+ ## License
151
+
152
+ MIT
package/dist/context.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
3
3
  import { createContext, useContext, useEffect, useState } from 'react';
4
- import { createRasterClient } from '@raster-app/sdk';
4
+ import { createRasterClient, getCredentialIdentity, onSessionChange, } from '@raster-app/sdk';
5
5
  import { rasterKeys } from './query-keys.js';
6
6
  import { memoryStateStore } from './state-store.js';
7
7
  const RasterContext = createContext(null);
@@ -23,9 +23,9 @@ export function RasterProvider({ children, client, config, state, queryClient, }
23
23
  }));
24
24
  // A sign-in's cache goes when it ends: a sign-out, or somebody else signing in.
25
25
  useEffect(() => {
26
- let identity = value.client.session.credentialIdentity();
27
- return value.client.session.subscribe(() => {
28
- const next = value.client.session.credentialIdentity();
26
+ let identity = getCredentialIdentity(value.client);
27
+ return onSessionChange(value.client, () => {
28
+ const next = getCredentialIdentity(value.client);
29
29
  if (identity !== null && next !== identity) {
30
30
  value.queryClient.removeQueries({ queryKey: rasterKeys.signIn(identity) });
31
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,EAAkB,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEtF,OAAO,EAA8C,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEhG,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAmB,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAEpE,MAAM,aAAa,GAAG,aAAa,CAAqD,IAAI,CAAC,CAAA;AAwB7F;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,EAC9B,QAAQ,EACR,MAAM,EACN,MAAM,EACN,KAAK,EACL,WAAW,GACU;IACrB,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;QAC/B,MAAM,EAAE,MAAM,IAAI,kBAAkB,CAAC,MAAM,CAAC;QAC5C,KAAK,EAAE,KAAK,IAAI,gBAAgB,EAAE;QAClC,WAAW,EACV,WAAW;YACX,yFAAyF;YACzF,kEAAkE;YAClE,IAAI,WAAW,CAAC;gBACf,cAAc,EAAE,EAAE,OAAO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CAAC","sourcesContent":["import { QueryClient, QueryClientProvider } from '@tanstack/react-query'\nimport { type ReactNode, createContext, useContext, useEffect, useState } from 'react'\n\nimport { type RasterClient, type RasterClientConfig, createRasterClient } from '@raster-app/sdk'\n\nimport { rasterKeys } from './query-keys.js'\nimport { type StateStore, memoryStateStore } from './state-store.js'\n\nconst RasterContext = createContext<{ client: RasterClient; state: StateStore } | null>(null)\n\nexport type RasterProviderProps = {\n\tchildren: ReactNode\n\t/** Where `useRasterNavigation` remembers the last organization and library. Defaults to memory. */\n\tstate?: StateStore\n\t/**\n\t * The host's own `QueryClient`, if it has one, from the same TanStack Query major as this\n\t * package. Without it the provider creates one, which shadows the host's for everything below.\n\t */\n\tqueryClient?: QueryClient\n} & (\n\t| {\n\t\t\t/** An existing client. Use this when the host builds one itself. */\n\t\t\tclient: RasterClient\n\t\t\tconfig?: never\n\t }\n\t| {\n\t\t\t/** Config for a client the provider creates and owns. */\n\t\t\tconfig: RasterClientConfig\n\t\t\tclient?: never\n\t }\n)\n\n/**\n * Provides one `RasterClient` to the tree, and the `QueryClient` its hooks cache in. Both are\n * fixed on mount: a second client means a second session store, and two stores refreshing one\n * credential spend each other's refresh token. Remount with a new `key` to switch.\n */\nexport function RasterProvider({\n\tchildren,\n\tclient,\n\tconfig,\n\tstate,\n\tqueryClient,\n}: RasterProviderProps) {\n\tconst [value] = useState(() => ({\n\t\tclient: client ?? createRasterClient(config),\n\t\tstate: state ?? memoryStateStore(),\n\t\tqueryClient:\n\t\t\tqueryClient ??\n\t\t\t// The Raster app's own defaults. Focus returns to a plugin frame on every click into it,\n\t\t\t// and a refetch each time would replay every page of a long grid.\n\t\t\tnew QueryClient({\n\t\t\t\tdefaultOptions: { queries: { staleTime: 60 * 1000, refetchOnWindowFocus: false } },\n\t\t\t}),\n\t}))\n\n\t// A sign-in's cache goes when it ends: a sign-out, or somebody else signing in.\n\tuseEffect(() => {\n\t\tlet identity = value.client.session.credentialIdentity()\n\t\treturn value.client.session.subscribe(() => {\n\t\t\tconst next = value.client.session.credentialIdentity()\n\t\t\tif (identity !== null && next !== identity) {\n\t\t\t\tvalue.queryClient.removeQueries({ queryKey: rasterKeys.signIn(identity) })\n\t\t\t}\n\t\t\tidentity = next\n\t\t})\n\t}, [value])\n\n\treturn (\n\t\t<QueryClientProvider client={value.queryClient}>\n\t\t\t<RasterContext.Provider value={value}>{children}</RasterContext.Provider>\n\t\t</QueryClientProvider>\n\t)\n}\n\nfunction useRaster() {\n\tconst value = useContext(RasterContext)\n\tif (value === null) {\n\t\tthrow new Error('Raster hooks must be used inside a <RasterProvider>.')\n\t}\n\treturn value\n}\n\nexport function useRasterClient(): RasterClient {\n\treturn useRaster().client\n}\n\nexport function useStateStore(): StateStore {\n\treturn useRaster().state\n}\n"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,EAAkB,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEtF,OAAO,EAGN,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,GACf,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAmB,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAEpE,MAAM,aAAa,GAAG,aAAa,CAAqD,IAAI,CAAC,CAAA;AAwB7F;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,EAC9B,QAAQ,EACR,MAAM,EACN,MAAM,EACN,KAAK,EACL,WAAW,GACU;IACrB,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;QAC/B,MAAM,EAAE,MAAM,IAAI,kBAAkB,CAAC,MAAM,CAAC;QAC5C,KAAK,EAAE,KAAK,IAAI,gBAAgB,EAAE;QAClC,WAAW,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AAa;IAC5B,OAAO,SAAS,EAAE,CAAC,KAAK,CAAA;AACzB,CAAC","sourcesContent":["import { QueryClient, QueryClientProvider } from '@tanstack/react-query'\nimport { type ReactNode, createContext, useContext, useEffect, useState } from 'react'\n\nimport {\n\ttype RasterClient,\n\ttype RasterClientConfig,\n\tcreateRasterClient,\n\tgetCredentialIdentity,\n\tonSessionChange,\n} from '@raster-app/sdk'\n\nimport { rasterKeys } from './query-keys.js'\nimport { type StateStore, memoryStateStore } from './state-store.js'\n\nconst RasterContext = createContext<{ client: RasterClient; state: StateStore } | null>(null)\n\nexport type RasterProviderProps = {\n\tchildren: ReactNode\n\t/** Where `useRasterNavigation` remembers the last organization and library. Defaults to memory. */\n\tstate?: StateStore\n\t/**\n\t * The host's own `QueryClient`, if it has one, from the same TanStack Query major as this\n\t * package. Without it the provider creates one, which shadows the host's for everything below.\n\t */\n\tqueryClient?: QueryClient\n} & (\n\t| {\n\t\t\t/** An existing client. Use this when the host builds one itself. */\n\t\t\tclient: RasterClient\n\t\t\tconfig?: never\n\t }\n\t| {\n\t\t\t/** Config for a client the provider creates and owns. */\n\t\t\tconfig: RasterClientConfig\n\t\t\tclient?: never\n\t }\n)\n\n/**\n * Provides one `RasterClient` to the tree, and the `QueryClient` its hooks cache in. Both are\n * fixed on mount: a second client means a second session store, and two stores refreshing one\n * credential spend each other's refresh token. Remount with a new `key` to switch.\n */\nexport function RasterProvider({\n\tchildren,\n\tclient,\n\tconfig,\n\tstate,\n\tqueryClient,\n}: RasterProviderProps) {\n\tconst [value] = useState(() => ({\n\t\tclient: client ?? createRasterClient(config),\n\t\tstate: state ?? memoryStateStore(),\n\t\tqueryClient:\n\t\t\tqueryClient ??\n\t\t\t// The Raster app's own defaults. Focus returns to a plugin frame on every click into it,\n\t\t\t// and a refetch each time would replay every page of a long grid.\n\t\t\tnew QueryClient({\n\t\t\t\tdefaultOptions: { queries: { staleTime: 60 * 1000, refetchOnWindowFocus: false } },\n\t\t\t}),\n\t}))\n\n\t// A sign-in's cache goes when it ends: a sign-out, or somebody else signing in.\n\tuseEffect(() => {\n\t\tlet identity = getCredentialIdentity(value.client)\n\t\treturn onSessionChange(value.client, () => {\n\t\t\tconst next = getCredentialIdentity(value.client)\n\t\t\tif (identity !== null && next !== identity) {\n\t\t\t\tvalue.queryClient.removeQueries({ queryKey: rasterKeys.signIn(identity) })\n\t\t\t}\n\t\t\tidentity = next\n\t\t})\n\t}, [value])\n\n\treturn (\n\t\t<QueryClientProvider client={value.queryClient}>\n\t\t\t<RasterContext.Provider value={value}>{children}</RasterContext.Provider>\n\t\t</QueryClientProvider>\n\t)\n}\n\nfunction useRaster() {\n\tconst value = useContext(RasterContext)\n\tif (value === null) {\n\t\tthrow new Error('Raster hooks must be used inside a <RasterProvider>.')\n\t}\n\treturn value\n}\n\nexport function useRasterClient(): RasterClient {\n\treturn useRaster().client\n}\n\nexport function useStateStore(): StateStore {\n\treturn useRaster().state\n}\n"]}
@@ -14,6 +14,15 @@ export declare function Empty({ glyph, title, text, children, }: {
14
14
  text: string;
15
15
  children?: ReactNode;
16
16
  }): import("react").JSX.Element;
17
+ /** Raster's columns for a grid this wide: its window holds a 266px sidebar and 30px padding too. */
18
+ export declare function gridColumns(width: number): number;
19
+ /**
20
+ * Tiles in Raster's grid, a row at a time as the Raster app draws them: only the rows in view,
21
+ * and five either side, are mounted, however many have loaded.
22
+ */
23
+ export declare function TileGrid({ children }: {
24
+ children: ReactNode;
25
+ }): import("react").JSX.Element;
17
26
  /**
18
27
  * Raster's grid tile: the picture over its blurred fill, or a checkerboard where it has alpha,
19
28
  * with a pill for a badge on the left and one for an action on the right.
@@ -32,9 +41,9 @@ export declare function Tile({ asset, onOpen, selected, badge, action, }: {
32
41
  */
33
42
  export declare function Detail({ item, busy, onPick, }: {
34
43
  item: Asset | SearchHit | AssetVariant;
35
- /** While the asset is read in full for the host. */
44
+ /** While the asset is read in full for the host, or a promote has yet to land. */
36
45
  busy: boolean;
37
- onPick: () => void;
46
+ onPick?: () => void;
38
47
  }): import("react").JSX.Element;
39
48
  /** A file on its way into Raster, as the grid shows it until Raster has processed it. */
40
49
  export declare function PendingTile({ name, preview, status, }: {
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useEffect, useRef, useState } from 'react';
2
+ import { useVirtualizer } from '@tanstack/react-virtual';
3
+ import { Children, useEffect, useLayoutEffect, useRef, useState } from 'react';
3
4
  import { formatDateLong, formatFileSize, formatRelativeTime, getBlurhashPlaceholder, getPreviewUrl, getThumbUrl, isReady, toUserMessage, } from '@raster-app/sdk';
4
5
  import { useRasterClient } from './context.js';
5
6
  import { Icon } from './icons.js';
@@ -20,6 +21,54 @@ export function ErrorCard({ error, onError }) {
20
21
  export function Empty({ glyph, title, text, children, }) {
21
22
  return (_jsxs("div", { className: "rs-empty", children: [_jsx("div", { className: "rs-empty-glyph", children: glyph === 'grid' ? _jsx(Icon, { shape: "grid" }) : glyph }), _jsx("h2", { className: "rs-heading", children: title }), _jsx("p", { className: "rs-muted rs-small", children: text }), children] }));
22
23
  }
24
+ /** Raster's tile height (`.rs-asset-thumb`) and the gap between its rows. */
25
+ const ROW_HEIGHT = 210 + 30;
26
+ /** The Raster app's columns from its window's width (`calculateGridColumns`). */
27
+ const BREAKPOINTS = [
28
+ [2180, 7],
29
+ [1920, 6],
30
+ [1536, 5],
31
+ [1280, 4],
32
+ [1024, 3],
33
+ [768, 2],
34
+ ];
35
+ /** Raster's columns for a grid this wide: its window holds a 266px sidebar and 30px padding too. */
36
+ export function gridColumns(width) {
37
+ const viewport = width + 266 + 2 * 30;
38
+ return BREAKPOINTS.find(([min]) => viewport >= min)?.[1] ?? 1;
39
+ }
40
+ /**
41
+ * Tiles in Raster's grid, a row at a time as the Raster app draws them: only the rows in view,
42
+ * and five either side, are mounted, however many have loaded.
43
+ */
44
+ export function TileGrid({ children }) {
45
+ const tiles = Children.toArray(children);
46
+ const grid = useRef(null);
47
+ const [width, setWidth] = useState(0);
48
+ useLayoutEffect(() => {
49
+ const node = grid.current;
50
+ if (node === null)
51
+ return;
52
+ setWidth(node.clientWidth);
53
+ if (typeof ResizeObserver === 'undefined')
54
+ return;
55
+ const observer = new ResizeObserver(() => setWidth(node.clientWidth));
56
+ observer.observe(node);
57
+ return () => observer.disconnect();
58
+ }, []);
59
+ const columns = gridColumns(width);
60
+ const rows = useVirtualizer({
61
+ count: Math.ceil(tiles.length / columns),
62
+ getScrollElement: () => grid.current?.closest('.rs-content') ?? null,
63
+ estimateSize: () => ROW_HEIGHT,
64
+ overscan: 5,
65
+ scrollMargin: grid.current?.offsetTop ?? 0,
66
+ });
67
+ return (_jsx("div", { ref: grid, className: "rs-tile-grid", style: { height: rows.getTotalSize() }, children: rows.getVirtualItems().map((row) => (_jsx("div", { className: "rs-grid", style: {
68
+ top: row.start - rows.options.scrollMargin,
69
+ gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
70
+ }, children: tiles.slice(row.index * columns, (row.index + 1) * columns) }, row.key))) }));
71
+ }
23
72
  /**
24
73
  * Raster's grid tile: the picture over its blurred fill, or a checkerboard where it has alpha,
25
74
  * with a pill for a badge on the left and one for an action on the right.
@@ -28,7 +77,7 @@ export function Tile({ asset, onOpen, selected, badge, action, }) {
28
77
  const [loaded, setLoaded] = useState(false);
29
78
  const ready = isReady(asset);
30
79
  const thumb = getThumbUrl(asset);
31
- const fill = ('blurhash' in asset ? getBlurhashPlaceholder(asset) : null) ?? thumb;
80
+ const fill = 'blurhash' in asset ? getBlurhashPlaceholder(asset) : null;
32
81
  const transparent = 'contentType' in asset && /png|svg|webp|gif/.test(asset.contentType ?? '');
33
82
  const size = 'size' in asset ? formatFileSize(asset.size) : '';
34
83
  const updated = 'updated' in asset ? formatRelativeTime(asset.updated) : '';
@@ -44,19 +93,47 @@ export function Detail({ item, busy, onPick, }) {
44
93
  const { host } = useRasterClient();
45
94
  const image = getPreviewUrl(item);
46
95
  const appUrl = item.appUrl;
96
+ const url = 'url' in item ? item.url : null;
47
97
  const facts = [
48
98
  item.width && item.height ? `${item.width} × ${item.height}` : '',
49
99
  'size' in item ? formatFileSize(item.size) : '',
50
100
  'created' in item && item.created ? `Created ${formatDateLong(item.created)}` : '',
51
101
  ].filter((fact) => fact !== '');
52
- return (_jsxs("div", { className: "rs-detail", children: [_jsx("div", { className: "rs-detail-image", children: image && _jsx("img", { src: image, alt: "" }, image) }), _jsxs("div", { className: "rs-detail-info", children: [_jsx("h2", { className: "rs-heading", children: item.name }), facts.length > 0 && _jsx("p", { className: "rs-muted rs-small", children: facts.join(' · ') }), _jsx("button", { type: "button", className: "rs-button rs-button-primary", disabled: !isReady(item) || busy, onClick: onPick, children: "Pick asset" }), appUrl && (_jsxs("a", { className: "rs-button rs-button-secondary", href: appUrl, target: "_blank", rel: "noreferrer", onClick: (event) => {
102
+ return (_jsxs("div", { className: "rs-detail", children: [_jsx("div", { className: "rs-detail-image", children: image && _jsx("img", { src: image, alt: "" }, image) }), _jsxs("div", { className: "rs-detail-info", children: [_jsx("h2", { className: "rs-heading", children: item.name }), facts.length > 0 && _jsx("p", { className: "rs-muted rs-small", children: facts.join(' · ') }), onPick && (_jsx("button", { type: "button", className: "rs-button rs-button-primary", disabled: !isReady(item) || busy, onClick: onPick, children: "Pick asset" })), appUrl && (_jsxs("a", { className: "rs-button rs-button-secondary", href: appUrl, target: "_blank", rel: "noreferrer", onClick: (event) => {
53
103
  event.preventDefault();
54
104
  host.openExternal(appUrl);
55
- }, children: [_jsx(Icon, { shape: "link", width: 12.25 }), "Open in Raster"] }))] })] }));
105
+ }, children: [_jsx(Icon, { shape: "link", width: 12.25 }), "Open in Raster"] })), url && _jsx(CopyUrl, { url: url })] })] }));
106
+ }
107
+ /** Copies the asset's CDN URL, and says so for 2 seconds, as Raster's Copy URL does. */
108
+ function CopyUrl({ url }) {
109
+ const [copied, setCopied] = useState(false);
110
+ useEffect(() => {
111
+ if (!copied)
112
+ return;
113
+ const timer = setTimeout(() => setCopied(false), 2000);
114
+ return () => clearTimeout(timer);
115
+ }, [copied]);
116
+ return (_jsxs("button", { type: "button", className: "rs-button rs-button-secondary", onClick: async () => setCopied(await copyText(url)), children: [_jsx(Icon, { shape: copied ? 'check' : 'link', width: 12.25 }), copied ? 'Copied' : 'Copy URL'] }));
117
+ }
118
+ /** The Clipboard API, or a selection copied, where a sandboxed iframe blocks that API. */
119
+ async function copyText(text) {
120
+ try {
121
+ await navigator.clipboard.writeText(text);
122
+ return true;
123
+ }
124
+ catch {
125
+ const field = document.createElement('textarea');
126
+ field.value = text;
127
+ document.body.append(field);
128
+ field.select();
129
+ const copied = document.execCommand('copy');
130
+ field.remove();
131
+ return copied;
132
+ }
56
133
  }
57
134
  /** A file on its way into Raster, as the grid shows it until Raster has processed it. */
58
135
  export function PendingTile({ name, preview, status, }) {
59
- return (_jsx("div", { className: "rs-tile", children: _jsxs("div", { className: "rs-asset-thumb", "data-loaded": true, "aria-busy": "true", children: [_jsx("img", { className: "rs-thumb-blur", src: preview, alt: "" }), _jsx("div", { className: "rs-thumb-preview", children: _jsx("img", { src: preview, alt: "" }) }), _jsxs("div", { className: "rs-thumb-meta", children: [_jsx("span", { className: "rs-thumb-title", children: name }), _jsxs("span", { className: "rs-thumb-subtitle", children: [_jsx("span", { className: "rs-spinner" }), status] })] })] }) }));
136
+ return (_jsx("div", { className: "rs-tile", children: _jsxs("div", { className: "rs-asset-thumb", "data-loaded": true, "aria-busy": "true", children: [_jsx("div", { className: "rs-thumb-preview", children: _jsx("img", { src: preview, alt: "" }) }), _jsxs("div", { className: "rs-thumb-meta", children: [_jsx("span", { className: "rs-thumb-title", children: name }), _jsxs("span", { className: "rs-thumb-subtitle", children: [_jsx("span", { className: "rs-spinner" }), status] })] })] }) }));
60
137
  }
61
138
  /** A control that opens the file chooser, drawn as whatever `className` makes it. */
62
139
  export function FilePicker({ className, disabled, focusable = true, onFile, children, }) {
@@ -100,8 +177,12 @@ export function OrganizationSwitcher({ organizations, current, onIntent, onSelec
100
177
  return;
101
178
  const close = (event) => {
102
179
  const outside = event.target instanceof Node && !root.current?.contains(event.target);
103
- if (event instanceof KeyboardEvent ? event.key === 'Escape' : outside)
104
- setOpen(false);
180
+ if (event instanceof KeyboardEvent ? event.key !== 'Escape' : !outside)
181
+ return;
182
+ // Stopped here, so a host dialog that closes on Escape stays open.
183
+ if (event instanceof KeyboardEvent)
184
+ event.stopPropagation();
185
+ setOpen(false);
105
186
  };
106
187
  document.addEventListener('mousedown', close);
107
188
  document.addEventListener('keydown', close);
@@ -1 +1 @@
1
- {"version":3,"file":"picker-parts.js","sourceRoot":"","sources":["../src/picker-parts.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAkB,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEnE,OAAO,EAMN,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,aAAa,EACb,WAAW,EACX,OAAO,EACP,aAAa,GACb,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAMjC,MAAM,UAAU,KAAK;IACpB,OAAO,CACN,eAAK,SAAS,EAAC,UAAU,aACxB,KAAC,IAAI,IAAC,KAAK,EAAC,QAAQ,EAAC,KAAK,QAAC,KAAK,EAAE,EAAE,GAAI,cAEnC,CACN,CAAA;AACF,CAAC;AAED,sFAAsF;AACtF,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAkB,CAAA;AAE9C,MAAM,UAAU,SAAS,CAAC,EAAE,KAAK,EAAE,OAAO,EAAmD;IAC5F,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,OAAM;QAC/B,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACnB,OAAO,EAAE,CAAC,KAAK,CAAC,CAAA;IACjB,CAAC,EAAE,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C,CAAA;IAE7C,SAAS,CAAC,GAAG,EAAE;QACd,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAA;QAC5B,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,oBAAoB,KAAK,WAAW;YAAE,OAAM;QACxE,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CACxC,CAAC,OAAO,EAAE,EAAE;YACX,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC;gBAAE,SAAS,EAAE,CAAA;QAC/D,CAAC,EACD,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,UAAU,EAAE,mBAAmB,EAAE,CACtE,CAAA;QACD,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACtB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAA;IACnC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IAEf,OAAO,eAAM,GAAG,EAAE,OAAO,EAAE,SAAS,EAAC,YAAY,GAAG,CAAA;AACrD,CAAC","sourcesContent":["import { type ReactNode, useEffect, useRef, useState } from 'react'\n\nimport {\n\ttype Asset,\n\ttype AssetVariant,\n\ttype Organization,\n\ttype RasterApiError,\n\ttype SearchHit,\n\tformatDateLong,\n\tformatFileSize,\n\tformatRelativeTime,\n\tgetBlurhashPlaceholder,\n\tgetPreviewUrl,\n\tgetThumbUrl,\n\tisReady,\n\ttoUserMessage,\n} from '@raster-app/sdk'\n\nimport { useRasterClient } from './context.js'\nimport { Icon } from './icons.js'\nimport type { PromoteState } from './use-promote-variant.js'\nimport type { UploadState } from './use-asset-upload.js'\n\nexport type ReportError = ((error: RasterApiError) => void) | undefined\n\nexport function Brand() {\n\treturn (\n\t\t<div className=\"rs-brand\">\n\t\t\t<Icon shape=\"raster\" solid width={18} />\n\t\t\tRaster\n\t\t</div>\n\t)\n}\n\n// Strict Mode runs an effect twice in development; the host hears of each error once.\nconst reported = new WeakSet<RasterApiError>()\n\nexport function ErrorCard({ error, onError }: { error: RasterApiError; onError: ReportError }) {\n\tuseEffect(() => {\n\t\tif (reported.has(error)) return\n\t\treported.add(error)\n\t\tonError?.(error)\n\t}, [error, onError])\n\treturn (\n\t\t<p role=\"alert\" className=\"rs-card\">\n\t\t\t{toUserMessage(error)}\n\t\t</p>\n\t)\n}\n\nexport function Empty({\n\tglyph,\n\ttitle,\n\ttext,\n\tchildren,\n}: {\n\tglyph: 'grid' | '∅'\n\ttitle: string\n\ttext: string\n\tchildren?: ReactNode\n}) {\n\treturn (\n\t\t<div className=\"rs-empty\">\n\t\t\t<div className=\"rs-empty-glyph\">{glyph === 'grid' ? <Icon shape=\"grid\" /> : glyph}</div>\n\t\t\t<h2 className=\"rs-heading\">{title}</h2>\n\t\t\t<p className=\"rs-muted rs-small\">{text}</p>\n\t\t\t{children}\n\t\t</div>\n\t)\n}\n\n/**\n * Raster's grid tile: the picture over its blurred fill, or a checkerboard where it has alpha,\n * with a pill for a badge on the left and one for an action on the right.\n */\nexport function Tile({\n\tasset,\n\tonOpen,\n\tselected,\n\tbadge,\n\taction,\n}: {\n\tasset: Asset | SearchHit | AssetVariant\n\tonOpen: () => void\n\t/** Whether this is the version shown large, among an asset's versions. */\n\tselected?: boolean\n\tbadge?: ReactNode\n\taction?: ReactNode\n}) {\n\tconst [loaded, setLoaded] = useState(false)\n\tconst ready = isReady(asset)\n\tconst thumb = getThumbUrl(asset)\n\tconst fill = ('blurhash' in asset ? getBlurhashPlaceholder(asset) : null) ?? thumb\n\tconst transparent = 'contentType' in asset && /png|svg|webp|gif/.test(asset.contentType ?? '')\n\tconst size = 'size' in asset ? formatFileSize(asset.size) : ''\n\tconst updated = 'updated' in asset ? formatRelativeTime(asset.updated) : ''\n\n\treturn (\n\t\t<div className=\"rs-tile\">\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tclassName=\"rs-asset-thumb\"\n\t\t\t\tdata-loaded={loaded || undefined}\n\t\t\t\tdisabled={!ready}\n\t\t\t\taria-pressed={selected}\n\t\t\t\ttitle={\n\t\t\t\t\t'created' in asset && asset.created\n\t\t\t\t\t\t? `Created ${formatDateLong(asset.created)}`\n\t\t\t\t\t\t: undefined\n\t\t\t\t}\n\t\t\t\tonClick={onOpen}\n\t\t\t>\n\t\t\t\t{transparent ? (\n\t\t\t\t\t<div className=\"rs-transparent\" />\n\t\t\t\t) : (\n\t\t\t\t\tfill && <img className=\"rs-thumb-blur\" src={fill} alt=\"\" />\n\t\t\t\t)}\n\t\t\t\t<div className=\"rs-thumb-preview\">\n\t\t\t\t\t{thumb && (\n\t\t\t\t\t\t<img\n\t\t\t\t\t\t\tkey={thumb}\n\t\t\t\t\t\t\tsrc={thumb}\n\t\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\t\tloading=\"lazy\"\n\t\t\t\t\t\t\tdecoding=\"async\"\n\t\t\t\t\t\t\tonLoad={() => setLoaded(true)}\n\t\t\t\t\t\t\tonError={() => setLoaded(true)}\n\t\t\t\t\t\t/>\n\t\t\t\t\t)}\n\t\t\t\t</div>\n\t\t\t\t<div className=\"rs-thumb-meta\">\n\t\t\t\t\t<span className=\"rs-thumb-title\">{asset.name}</span>\n\t\t\t\t\t<span className=\"rs-thumb-subtitle\">\n\t\t\t\t\t\t{!ready && <span>Not ready</span>}\n\t\t\t\t\t\t{ready && size && <span>{size}</span>}\n\t\t\t\t\t\t{ready && updated && <span>{updated}</span>}\n\t\t\t\t\t\t{ready && !size && !updated && asset.width && asset.height && (\n\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t{asset.width} × {asset.height}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t)}\n\t\t\t\t\t</span>\n\t\t\t\t</div>\n\t\t\t</button>\n\t\t\t{badge}\n\t\t\t{action}\n\t\t</div>\n\t)\n}\n\n/**\n * An opened asset or variant: the image large, its facts, and what the host can do with it.\n * Raster opens through the host, which reaches the browser from a Figma plugin too.\n */\nexport function Detail({\n\titem,\n\tbusy,\n\tonPick,\n}: {\n\titem: Asset | SearchHit | AssetVariant\n\t/** While the asset is read in full for the host. */\n\tbusy: boolean\n\tonPick: () => void\n}) {\n\tconst { host } = useRasterClient()\n\tconst image = getPreviewUrl(item)\n\tconst appUrl = item.appUrl\n\tconst facts = [\n\t\titem.width && item.height ? `${item.width} × ${item.height}` : '',\n\t\t'size' in item ? formatFileSize(item.size) : '',\n\t\t'created' in item && item.created ? `Created ${formatDateLong(item.created)}` : '',\n\t].filter((fact) => fact !== '')\n\n\treturn (\n\t\t<div className=\"rs-detail\">\n\t\t\t<div className=\"rs-detail-image\">{image && <img key={image} src={image} alt=\"\" />}</div>\n\t\t\t<div className=\"rs-detail-info\">\n\t\t\t\t<h2 className=\"rs-heading\">{item.name}</h2>\n\t\t\t\t{facts.length > 0 && <p className=\"rs-muted rs-small\">{facts.join(' · ')}</p>}\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tclassName=\"rs-button rs-button-primary\"\n\t\t\t\t\tdisabled={!isReady(item) || busy}\n\t\t\t\t\tonClick={onPick}\n\t\t\t\t>\n\t\t\t\t\tPick asset\n\t\t\t\t</button>\n\t\t\t\t{appUrl && (\n\t\t\t\t\t<a\n\t\t\t\t\t\tclassName=\"rs-button rs-button-secondary\"\n\t\t\t\t\t\thref={appUrl}\n\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\trel=\"noreferrer\"\n\t\t\t\t\t\tonClick={(event) => {\n\t\t\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\t\t\thost.openExternal(appUrl)\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon shape=\"link\" width={12.25} />\n\t\t\t\t\t\tOpen in Raster\n\t\t\t\t\t</a>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n\n/** A file on its way into Raster, as the grid shows it until Raster has processed it. */\nexport function PendingTile({\n\tname,\n\tpreview,\n\tstatus,\n}: {\n\tname: string\n\tpreview: string\n\tstatus: string\n}) {\n\treturn (\n\t\t<div className=\"rs-tile\">\n\t\t\t<div className=\"rs-asset-thumb\" data-loaded aria-busy=\"true\">\n\t\t\t\t<img className=\"rs-thumb-blur\" src={preview} alt=\"\" />\n\t\t\t\t<div className=\"rs-thumb-preview\">\n\t\t\t\t\t<img src={preview} alt=\"\" />\n\t\t\t\t</div>\n\t\t\t\t<div className=\"rs-thumb-meta\">\n\t\t\t\t\t<span className=\"rs-thumb-title\">{name}</span>\n\t\t\t\t\t<span className=\"rs-thumb-subtitle\">\n\t\t\t\t\t\t<span className=\"rs-spinner\" />\n\t\t\t\t\t\t{status}\n\t\t\t\t\t</span>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n\n/** A control that opens the file chooser, drawn as whatever `className` makes it. */\nexport function FilePicker({\n\tclassName,\n\tdisabled,\n\tfocusable = true,\n\tonFile,\n\tchildren,\n}: {\n\tclassName: string\n\tdisabled: boolean\n\tfocusable?: boolean\n\tonFile: (file: File) => void\n\tchildren: ReactNode\n}) {\n\treturn (\n\t\t<label className={className}>\n\t\t\t{children}\n\t\t\t<input\n\t\t\t\tclassName=\"rs-visually-hidden\"\n\t\t\t\ttype=\"file\"\n\t\t\t\tdisabled={disabled}\n\t\t\t\ttabIndex={focusable ? 0 : -1}\n\t\t\t\tonChange={(event) => {\n\t\t\t\t\tconst file = event.target.files?.[0]\n\t\t\t\t\t// Cleared, so picking the same file again uploads it again.\n\t\t\t\t\tevent.target.value = ''\n\t\t\t\t\tif (file) onFile(file)\n\t\t\t\t}}\n\t\t\t/>\n\t\t</label>\n\t)\n}\n\nconst UPLOADS = {\n\tuploading: 'Uploading',\n\tprocessing: 'Processing',\n\tdone: 'Uploaded',\n\t'timed-out': 'Still processing',\n} as const\nconst PROMOTES = {\n\tpromoting: 'Setting as default',\n\tdone: 'Default set',\n\t'timed-out': 'Still setting as default',\n} as const\n\n/** Where an upload and a promote stand, beside the header; each failure shows as an error. */\nexport function Progress({ upload, promote }: { upload: UploadState; promote: PromoteState }) {\n\treturn (\n\t\t<>\n\t\t\t{upload.status !== 'idle' && upload.status !== 'error' && (\n\t\t\t\t<Status status={upload.status} text={UPLOADS[upload.status]} />\n\t\t\t)}\n\t\t\t{promote.status !== 'idle' && promote.status !== 'error' && (\n\t\t\t\t<Status status={promote.status} text={PROMOTES[promote.status]} />\n\t\t\t)}\n\t\t</>\n\t)\n}\n\nfunction Status({ status, text }: { status: string; text: string }) {\n\tlet glyph = <span className=\"rs-spinner\" />\n\tif (status === 'done') glyph = <Icon shape=\"check\" />\n\tif (status === 'timed-out') glyph = <Icon shape=\"info-circle\" />\n\treturn (\n\t\t<span className=\"rs-status\" data-status={status}>\n\t\t\t{glyph}\n\t\t\t{text}\n\t\t</span>\n\t)\n}\n\n/** Raster's organization switcher: the current organization, over a menu of every one. */\nexport function OrganizationSwitcher({\n\torganizations,\n\tcurrent,\n\tonIntent,\n\tonSelect,\n}: {\n\torganizations: Array<Organization>\n\tcurrent: Organization | undefined\n\tonIntent: (organization: Organization) => void\n\tonSelect: (organizationId: string) => void\n}) {\n\tconst [open, setOpen] = useState(false)\n\tconst root = useRef<HTMLDivElement>(null)\n\n\tuseEffect(() => {\n\t\tif (!open) return\n\t\tconst close = (event: MouseEvent | KeyboardEvent) => {\n\t\t\tconst outside = event.target instanceof Node && !root.current?.contains(event.target)\n\t\t\tif (event instanceof KeyboardEvent ? event.key === 'Escape' : outside) setOpen(false)\n\t\t}\n\t\tdocument.addEventListener('mousedown', close)\n\t\tdocument.addEventListener('keydown', close)\n\t\treturn () => {\n\t\t\tdocument.removeEventListener('mousedown', close)\n\t\t\tdocument.removeEventListener('keydown', close)\n\t\t}\n\t}, [open])\n\n\treturn (\n\t\t<div className=\"rs-org\" ref={root}>\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tclassName=\"rs-sidebar-item rs-org-trigger\"\n\t\t\t\taria-expanded={open}\n\t\t\t\tonClick={() => setOpen(!open)}\n\t\t\t>\n\t\t\t\t<Avatar name={current?.name ?? current?.id ?? ''} />\n\t\t\t\t<span className=\"rs-library-name\">{current?.name ?? current?.id}</span>\n\t\t\t\t<Icon shape=\"chevron-up-down\" />\n\t\t\t</button>\n\t\t\t{open && (\n\t\t\t\t<div className=\"rs-menu\">\n\t\t\t\t\t<div className=\"rs-menu-heading\">Organizations</div>\n\t\t\t\t\t{organizations.map((organization) => (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tkey={organization.id}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\torganization.id === current?.id ? 'rs-sidebar-item is-active' : 'rs-sidebar-item'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonMouseEnter={() => onIntent(organization)}\n\t\t\t\t\t\t\tonFocus={() => onIntent(organization)}\n\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\tsetOpen(false)\n\t\t\t\t\t\t\t\tonSelect(organization.id)\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Avatar name={organization.name ?? organization.id} />\n\t\t\t\t\t\t\t<span className=\"rs-library-name\">{organization.name ?? organization.id}</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t))}\n\t\t\t\t</div>\n\t\t\t)}\n\t\t</div>\n\t)\n}\n\n/** Raster's letter avatar, on a gradient hued from the name as the app hues it. */\nfunction Avatar({ name }: { name: string }) {\n\tif (name === '') return null\n\tlet hex = ''\n\tfor (let index = 0; index < Math.min(name.length, 10); index++) {\n\t\thex += `000${name.charCodeAt(index).toString(16)}`.slice(-4)\n\t}\n\tconst hue = Number.parseInt(hex, 16) % 360\n\treturn (\n\t\t<span\n\t\t\tclassName=\"rs-avatar\"\n\t\t\tstyle={{\n\t\t\t\tbackgroundImage: `linear-gradient(45deg, hsl(${hue}, 70%, 50%), hsl(${(hue + 60) % 360}, 70%, 50%))`,\n\t\t\t}}\n\t\t>\n\t\t\t{name.charAt(0).toUpperCase()}\n\t\t</span>\n\t)\n}\n\n/**\n * The spinner at the end of the grid, which asks for the next page once it is within two rows\n * of view. Keyed by the item count, so it looks again after each page lands.\n */\nexport function Sentinel({ onVisible }: { onVisible: () => void }) {\n\tconst spinner = useRef<HTMLSpanElement>(null)\n\n\tuseEffect(() => {\n\t\tconst node = spinner.current\n\t\tif (node === null || typeof IntersectionObserver === 'undefined') return\n\t\tconst observer = new IntersectionObserver(\n\t\t\t(entries) => {\n\t\t\t\tif (entries.some((entry) => entry.isIntersecting)) onVisible()\n\t\t\t},\n\t\t\t{ root: node.closest('.rs-content'), rootMargin: '0px 0px 360px 0px' }\n\t\t)\n\t\tobserver.observe(node)\n\t\treturn () => observer.disconnect()\n\t}, [onVisible])\n\n\treturn <span ref={spinner} className=\"rs-spinner\" />\n}\n"]}
1
+ {"version":3,"file":"picker-parts.js","sourceRoot":"","sources":["../src/picker-parts.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAkB,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE9F,OAAO,EAMN,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,aAAa,EACb,WAAW,EACX,OAAO,EACP,aAAa,GACb,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAMjC,MAAM,UAAU,KAAK;IACpB,OAAO,CACN,eAAK,SAAS,EAAC,UAAU,aACxB,KAAC,IAAI,IAAC,KAAK,EAAC,QAAQ,EAAC,KAAK,QAAC,KAAK,EAAE,EAAE,GAAI,cAEnC,CACN,CAAA;AACF,CAAC;AAED,sFAAsF;AACtF,MAAM,Q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ayoutEffect, useRef, useState } from 'react'\n\nimport {\n\ttype Asset,\n\ttype AssetVariant,\n\ttype Organization,\n\ttype RasterApiError,\n\ttype SearchHit,\n\tformatDateLong,\n\tformatFileSize,\n\tformatRelativeTime,\n\tgetBlurhashPlaceholder,\n\tgetPreviewUrl,\n\tgetThumbUrl,\n\tisReady,\n\ttoUserMessage,\n} from '@raster-app/sdk'\n\nimport { useRasterClient } from './context.js'\nimport { Icon } from './icons.js'\nimport type { PromoteState } from './use-promote-variant.js'\nimport type { UploadState } from './use-asset-upload.js'\n\nexport type ReportError = ((error: RasterApiError) => void) | undefined\n\nexport function Brand() {\n\treturn (\n\t\t<div className=\"rs-brand\">\n\t\t\t<Icon shape=\"raster\" solid width={18} />\n\t\t\tRaster\n\t\t</div>\n\t)\n}\n\n// Strict Mode runs an effect twice in development; the host hears of each error once.\nconst reported = new WeakSet<RasterApiError>()\n\nexport function ErrorCard({ error, onError }: { error: RasterApiError; onError: ReportError }) {\n\tuseEffect(() => {\n\t\tif (reported.has(error)) return\n\t\treported.add(error)\n\t\tonError?.(error)\n\t}, [error, onError])\n\treturn (\n\t\t<p role=\"alert\" className=\"rs-card\">\n\t\t\t{toUserMessage(error)}\n\t\t</p>\n\t)\n}\n\nexport function Empty({\n\tglyph,\n\ttitle,\n\ttext,\n\tchildren,\n}: {\n\tglyph: 'grid' | '∅'\n\ttitle: string\n\ttext: string\n\tchildren?: ReactNode\n}) {\n\treturn (\n\t\t<div className=\"rs-empty\">\n\t\t\t<div className=\"rs-empty-glyph\">{glyph === 'grid' ? <Icon shape=\"grid\" /> : glyph}</div>\n\t\t\t<h2 className=\"rs-heading\">{title}</h2>\n\t\t\t<p className=\"rs-muted rs-small\">{text}</p>\n\t\t\t{children}\n\t\t</div>\n\t)\n}\n\n/** Raster's tile height (`.rs-asset-thumb`) and the gap between its rows. */\nconst ROW_HEIGHT = 210 + 30\n\n/** The Raster app's columns from its window's width (`calculateGridColumns`). */\nconst BREAKPOINTS: Array<[number, number]> = [\n\t[2180, 7],\n\t[1920, 6],\n\t[1536, 5],\n\t[1280, 4],\n\t[1024, 3],\n\t[768, 2],\n]\n\n/** Raster's columns for a grid this wide: its window holds a 266px sidebar and 30px padding too. */\nexport function gridColumns(width: number): number {\n\tconst viewport = width + 266 + 2 * 30\n\treturn BREAKPOINTS.find(([min]) => viewport >= min)?.[1] ?? 1\n}\n\n/**\n * Tiles in Raster's grid, a row at a time as the Raster app draws them: only the rows in view,\n * and five either side, are mounted, however many have loaded.\n */\nexport function TileGrid({ children }: { children: ReactNode }) {\n\tconst tiles = Children.toArray(children)\n\tconst grid = useRef<HTMLDivElement>(null)\n\tconst [width, setWidth] = useState(0)\n\n\tuseLayoutEffect(() => {\n\t\tconst node = grid.current\n\t\tif (node === null) return\n\t\tsetWidth(node.clientWidth)\n\t\tif (typeof ResizeObserver === 'undefined') return\n\t\tconst observer = new ResizeObserver(() => setWidth(node.clientWidth))\n\t\tobserver.observe(node)\n\t\treturn () => observer.disconnect()\n\t}, [])\n\n\tconst columns = gridColumns(width)\n\tconst rows = useVirtualizer({\n\t\tcount: Math.ceil(tiles.length / columns),\n\t\tgetScrollElement: () => grid.current?.closest('.rs-content') ?? null,\n\t\testimateSize: () => ROW_HEIGHT,\n\t\toverscan: 5,\n\t\tscrollMargin: grid.current?.offsetTop ?? 0,\n\t})\n\n\treturn (\n\t\t<div ref={grid} className=\"rs-tile-grid\" style={{ height: rows.getTotalSize() }}>\n\t\t\t{rows.getVirtualItems().map((row) => (\n\t\t\t\t<div\n\t\t\t\t\tkey={row.key}\n\t\t\t\t\tclassName=\"rs-grid\"\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\ttop: row.start - rows.options.scrollMargin,\n\t\t\t\t\t\tgridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t{tiles.slice(row.index * columns, (row.index + 1) * columns)}\n\t\t\t\t</div>\n\t\t\t))}\n\t\t</div>\n\t)\n}\n\n/**\n * Raster's grid tile: the picture over its blurred fill, or a checkerboard where it has alpha,\n * with a pill for a badge on the left and one for an action on the right.\n */\nexport function Tile({\n\tasset,\n\tonOpen,\n\tselected,\n\tbadge,\n\taction,\n}: {\n\tasset: Asset | SearchHit | AssetVariant\n\tonOpen: () => void\n\t/** Whether this is the version shown large, among an asset's versions. */\n\tselected?: boolean\n\tbadge?: ReactNode\n\taction?: ReactNode\n}) {\n\tconst [loaded, setLoaded] = useState(false)\n\tconst ready = isReady(asset)\n\tconst thumb = getThumbUrl(asset)\n\tconst fill = 'blurhash' in asset ? getBlurhashPlaceholder(asset) : null\n\tconst transparent = 'contentType' in asset && /png|svg|webp|gif/.test(asset.contentType ?? '')\n\tconst size = 'size' in asset ? formatFileSize(asset.size) : ''\n\tconst updated = 'updated' in asset ? formatRelativeTime(asset.updated) : ''\n\n\treturn (\n\t\t<div className=\"rs-tile\">\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tclassName=\"rs-asset-thumb\"\n\t\t\t\tdata-loaded={loaded || undefined}\n\t\t\t\tdisabled={!ready}\n\t\t\t\taria-pressed={selected}\n\t\t\t\ttitle={\n\t\t\t\t\t'created' in asset && asset.created\n\t\t\t\t\t\t? `Created ${formatDateLong(asset.created)}`\n\t\t\t\t\t\t: undefined\n\t\t\t\t}\n\t\t\t\tonClick={onOpen}\n\t\t\t>\n\t\t\t\t{transparent ? (\n\t\t\t\t\t<div className=\"rs-transparent\" />\n\t\t\t\t) : (\n\t\t\t\t\tfill && <img className=\"rs-thumb-blur\" src={fill} alt=\"\" />\n\t\t\t\t)}\n\t\t\t\t<div className=\"rs-thumb-preview\">\n\t\t\t\t\t{thumb && (\n\t\t\t\t\t\t<img\n\t\t\t\t\t\t\tkey={thumb}\n\t\t\t\t\t\t\tsrc={thumb}\n\t\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\t\tloading=\"lazy\"\n\t\t\t\t\t\t\tdecoding=\"async\"\n\t\t\t\t\t\t\tonLoad={() => setLoaded(true)}\n\t\t\t\t\t\t\tonError={() => setLoaded(true)}\n\t\t\t\t\t\t/>\n\t\t\t\t\t)}\n\t\t\t\t</div>\n\t\t\t\t<div className=\"rs-thumb-meta\">\n\t\t\t\t\t<span className=\"rs-thumb-title\">{asset.name}</span>\n\t\t\t\t\t<span className=\"rs-thumb-subtitle\">\n\t\t\t\t\t\t{!ready && <span>Not ready</span>}\n\t\t\t\t\t\t{ready && size && <span>{size}</span>}\n\t\t\t\t\t\t{ready && updated && <span>{updated}</span>}\n\t\t\t\t\t\t{ready && !size && !updated && asset.width && asset.height && (\n\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t{asset.width} × {asset.height}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t)}\n\t\t\t\t\t</span>\n\t\t\t\t</div>\n\t\t\t</button>\n\t\t\t{badge}\n\t\t\t{action}\n\t\t</div>\n\t)\n}\n\n/**\n * An opened asset or variant: the image large, its facts, and what the host can do with it.\n * Raster opens through the host, which reaches the browser from a Figma plugin too.\n */\nexport function Detail({\n\titem,\n\tbusy,\n\tonPick,\n}: {\n\titem: Asset | SearchHit | AssetVariant\n\t/** While the asset is read in full for the host, or a promote has yet to land. */\n\tbusy: boolean\n\tonPick?: () => void\n}) {\n\tconst { host } = useRasterClient()\n\tconst image = getPreviewUrl(item)\n\tconst appUrl = item.appUrl\n\tconst url = 'url' in item ? item.url : null\n\tconst facts = [\n\t\titem.width && item.height ? `${item.width} × ${item.height}` : '',\n\t\t'size' in item ? formatFileSize(item.size) : '',\n\t\t'created' in item && item.created ? `Created ${formatDateLong(item.created)}` : '',\n\t].filter((fact) => fact !== '')\n\n\treturn (\n\t\t<div className=\"rs-detail\">\n\t\t\t<div className=\"rs-detail-image\">{image && <img key={image} src={image} alt=\"\" />}</div>\n\t\t\t<div className=\"rs-detail-info\">\n\t\t\t\t<h2 className=\"rs-heading\">{item.name}</h2>\n\t\t\t\t{facts.length > 0 && <p className=\"rs-muted rs-small\">{facts.join(' · ')}</p>}\n\t\t\t\t{onPick && (\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tclassName=\"rs-button rs-button-primary\"\n\t\t\t\t\t\tdisabled={!isReady(item) || busy}\n\t\t\t\t\t\tonClick={onPick}\n\t\t\t\t\t>\n\t\t\t\t\t\tPick asset\n\t\t\t\t\t</button>\n\t\t\t\t)}\n\t\t\t\t{appUrl && (\n\t\t\t\t\t<a\n\t\t\t\t\t\tclassName=\"rs-button rs-button-secondary\"\n\t\t\t\t\t\thref={appUrl}\n\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\trel=\"noreferrer\"\n\t\t\t\t\t\tonClick={(event) => {\n\t\t\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\t\t\thost.openExternal(appUrl)\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon shape=\"link\" width={12.25} />\n\t\t\t\t\t\tOpen in Raster\n\t\t\t\t\t</a>\n\t\t\t\t)}\n\t\t\t\t{url && <CopyUrl url={url} />}\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n\n/** Copies the asset's CDN URL, and says so for 2 seconds, as Raster's Copy URL does. */\nfunction CopyUrl({ url }: { url: string }) {\n\tconst [copied, setCopied] = useState(false)\n\n\tuseEffect(() => {\n\t\tif (!copied) return\n\t\tconst timer = setTimeout(() => setCopied(false), 2000)\n\t\treturn () => clearTimeout(timer)\n\t}, [copied])\n\n\treturn (\n\t\t<button\n\t\t\ttype=\"button\"\n\t\t\tclassName=\"rs-button rs-button-secondary\"\n\t\t\tonClick={async () => setCopied(await copyText(url))}\n\t\t>\n\t\t\t<Icon shape={copied ? 'check' : 'link'} width={12.25} />\n\t\t\t{copied ? 'Copied' : 'Copy URL'}\n\t\t</button>\n\t)\n}\n\n/** The Clipboard API, or a selection copied, where a sandboxed iframe blocks that API. */\nasync function copyText(text: string): Promise<boolean> {\n\ttry {\n\t\tawait navigator.clipboard.writeText(text)\n\t\treturn true\n\t} catch {\n\t\tconst field = document.createElement('textarea')\n\t\tfield.value = text\n\t\tdocument.body.append(field)\n\t\tfield.select()\n\t\tconst copied = document.execCommand('copy')\n\t\tfield.remove()\n\t\treturn copied\n\t}\n}\n\n/** A file on its way into Raster, as the grid shows it until Raster has processed it. */\nexport function PendingTile({\n\tname,\n\tpreview,\n\tstatus,\n}: {\n\tname: string\n\tpreview: string\n\tstatus: string\n}) {\n\treturn (\n\t\t<div className=\"rs-tile\">\n\t\t\t<div className=\"rs-asset-thumb\" data-loaded aria-busy=\"true\">\n\t\t\t\t<div className=\"rs-thumb-preview\">\n\t\t\t\t\t<img src={preview} alt=\"\" />\n\t\t\t\t</div>\n\t\t\t\t<div className=\"rs-thumb-meta\">\n\t\t\t\t\t<span className=\"rs-thumb-title\">{name}</span>\n\t\t\t\t\t<span className=\"rs-thumb-subtitle\">\n\t\t\t\t\t\t<span className=\"rs-spinner\" />\n\t\t\t\t\t\t{status}\n\t\t\t\t\t</span>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n\n/** A control that opens the file chooser, drawn as whatever `className` makes it. */\nexport function FilePicker({\n\tclassName,\n\tdisabled,\n\tfocusable = true,\n\tonFile,\n\tchildren,\n}: {\n\tclassName: string\n\tdisabled: boolean\n\tfocusable?: boolean\n\tonFile: (file: File) => void\n\tchildren: ReactNode\n}) {\n\treturn (\n\t\t<label className={className}>\n\t\t\t{children}\n\t\t\t<input\n\t\t\t\tclassName=\"rs-visually-hidden\"\n\t\t\t\ttype=\"file\"\n\t\t\t\tdisabled={disabled}\n\t\t\t\ttabIndex={focusable ? 0 : -1}\n\t\t\t\tonChange={(event) => {\n\t\t\t\t\tconst file = event.target.files?.[0]\n\t\t\t\t\t// Cleared, so picking the same file again uploads it again.\n\t\t\t\t\tevent.target.value = ''\n\t\t\t\t\tif (file) onFile(file)\n\t\t\t\t}}\n\t\t\t/>\n\t\t</label>\n\t)\n}\n\nconst UPLOADS = {\n\tuploading: 'Uploading',\n\tprocessing: 'Processing',\n\tdone: 'Uploaded',\n\t'timed-out': 'Still processing',\n} as const\nconst PROMOTES = {\n\tpromoting: 'Setting as default',\n\tdone: 'Default set',\n\t'timed-out': 'Still setting as default',\n} as const\n\n/** Where an upload and a promote stand, beside the header; each failure shows as an error. */\nexport function Progress({ upload, promote }: { upload: UploadState; promote: PromoteState }) {\n\treturn (\n\t\t<>\n\t\t\t{upload.status !== 'idle' && upload.status !== 'error' && (\n\t\t\t\t<Status status={upload.status} text={UPLOADS[upload.status]} />\n\t\t\t)}\n\t\t\t{promote.status !== 'idle' && promote.status !== 'error' && (\n\t\t\t\t<Status status={promote.status} text={PROMOTES[promote.status]} />\n\t\t\t)}\n\t\t</>\n\t)\n}\n\nfunction Status({ status, text }: { status: string; text: string }) {\n\tlet glyph = <span className=\"rs-spinner\" />\n\tif (status === 'done') glyph = <Icon shape=\"check\" />\n\tif (status === 'timed-out') glyph = <Icon shape=\"info-circle\" />\n\treturn (\n\t\t<span className=\"rs-status\" data-status={status}>\n\t\t\t{glyph}\n\t\t\t{text}\n\t\t</span>\n\t)\n}\n\n/** Raster's organization switcher: the current organization, over a menu of every one. */\nexport function OrganizationSwitcher({\n\torganizations,\n\tcurrent,\n\tonIntent,\n\tonSelect,\n}: {\n\torganizations: Array<Organization>\n\tcurrent: Organization | undefined\n\tonIntent: (organization: Organization) => void\n\tonSelect: (organizationId: string) => void\n}) {\n\tconst [open, setOpen] = useState(false)\n\tconst root = useRef<HTMLDivElement>(null)\n\n\tuseEffect(() => {\n\t\tif (!open) return\n\t\tconst close = (event: MouseEvent | KeyboardEvent) => {\n\t\t\tconst outside = event.target instanceof Node && !root.current?.contains(event.target)\n\t\t\tif (event instanceof KeyboardEvent ? event.key !== 'Escape' : !outside) return\n\t\t\t// Stopped here, so a host dialog that closes on Escape stays open.\n\t\t\tif (event instanceof KeyboardEvent) event.stopPropagation()\n\t\t\tsetOpen(false)\n\t\t}\n\t\tdocument.addEventListener('mousedown', close)\n\t\tdocument.addEventListener('keydown', close)\n\t\treturn () => {\n\t\t\tdocument.removeEventListener('mousedown', close)\n\t\t\tdocument.removeEventListener('keydown', close)\n\t\t}\n\t}, [open])\n\n\treturn (\n\t\t<div className=\"rs-org\" ref={root}>\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tclassName=\"rs-sidebar-item rs-org-trigger\"\n\t\t\t\taria-expanded={open}\n\t\t\t\tonClick={() => setOpen(!open)}\n\t\t\t>\n\t\t\t\t<Avatar name={current?.name ?? current?.id ?? ''} />\n\t\t\t\t<span className=\"rs-library-name\">{current?.name ?? current?.id}</span>\n\t\t\t\t<Icon shape=\"chevron-up-down\" />\n\t\t\t</button>\n\t\t\t{open && (\n\t\t\t\t<div className=\"rs-menu\">\n\t\t\t\t\t<div className=\"rs-menu-heading\">Organizations</div>\n\t\t\t\t\t{organizations.map((organization) => (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tkey={organization.id}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\torganization.id === current?.id ? 'rs-sidebar-item is-active' : 'rs-sidebar-item'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonMouseEnter={() => onIntent(organization)}\n\t\t\t\t\t\t\tonFocus={() => onIntent(organization)}\n\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\tsetOpen(false)\n\t\t\t\t\t\t\t\tonSelect(organization.id)\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Avatar name={organization.name ?? organization.id} />\n\t\t\t\t\t\t\t<span className=\"rs-library-name\">{organization.name ?? organization.id}</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t))}\n\t\t\t\t</div>\n\t\t\t)}\n\t\t</div>\n\t)\n}\n\n/** Raster's letter avatar, on a gradient hued from the name as the app hues it. */\nfunction Avatar({ name }: { name: string }) {\n\tif (name === '') return null\n\tlet hex = ''\n\tfor (let index = 0; index < Math.min(name.length, 10); index++) {\n\t\thex += `000${name.charCodeAt(index).toString(16)}`.slice(-4)\n\t}\n\tconst hue = Number.parseInt(hex, 16) % 360\n\treturn (\n\t\t<span\n\t\t\tclassName=\"rs-avatar\"\n\t\t\tstyle={{\n\t\t\t\tbackgroundImage: `linear-gradient(45deg, hsl(${hue}, 70%, 50%), hsl(${(hue + 60) % 360}, 70%, 50%))`,\n\t\t\t}}\n\t\t>\n\t\t\t{name.charAt(0).toUpperCase()}\n\t\t</span>\n\t)\n}\n\n/**\n * The spinner at the end of the grid, which asks for the next page once it is within two rows\n * of view. Keyed by the item count, so it looks again after each page lands.\n */\nexport function Sentinel({ onVisible }: { onVisible: () => void }) {\n\tconst spinner = useRef<HTMLSpanElement>(null)\n\n\tuseEffect(() => {\n\t\tconst node = spinner.current\n\t\tif (node === null || typeof IntersectionObserver === 'undefined') return\n\t\tconst observer = new IntersectionObserver(\n\t\t\t(entries) => {\n\t\t\t\tif (entries.some((entry) => entry.isIntersecting)) onVisible()\n\t\t\t},\n\t\t\t{ root: node.closest('.rs-content'), rootMargin: '0px 0px 360px 0px' }\n\t\t)\n\t\tobserver.observe(node)\n\t\treturn () => observer.disconnect()\n\t}, [onVisible])\n\n\treturn <span ref={spinner} className=\"rs-spinner\" />\n}\n"]}
@@ -2,9 +2,10 @@ import { type Asset, type RasterApiError } from '@raster-app/sdk';
2
2
  export type RasterPickerProps = {
3
3
  /**
4
4
  * The picked asset, whole whether it came from a library, a search or an asset's versions, and
5
- * its organization. `getFullSizeUrl(asset)` is the image.
5
+ * its organization. `getFullSizeUrl(asset)` is the image. Without it, the picker only browses,
6
+ * with no Pick asset button.
6
7
  */
7
- onPick: (asset: Asset, organizationId: string) => void;
8
+ onPick?: (asset: Asset, organizationId: string) => void;
8
9
  /** Binds the device sign-in to this organization; any other grant fails. */
9
10
  organizationId?: string;
10
11
  /** The consent the device sign-in asks for: `org` when `organizationId` is set, else `user`. */