@panneau/media 5.0.0-alpha.7 → 5.0.0-alpha.9
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/dist/ImageItem.d.ts +1 -1
- package/dist/MediaField.d.ts +1 -1
- package/dist/editor/ImageEditor.d.ts +1 -1
- package/dist/editor/draw.d.ts +2 -2
- package/dist/editor/index.d.ts +4 -4
- package/dist/editor/tools.d.ts +1 -1
- package/dist/editor/types.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/picker/MediaDetails.d.ts +1 -1
- package/dist/picker/MediaGrid.d.ts +1 -1
- package/dist/picker/MediaPicker.d.ts +1 -1
- package/dist/picker/PickerToolbar.d.ts +2 -2
- package/dist/picker/format.d.ts +1 -1
- package/dist/picker/index.d.ts +2 -2
- package/dist/picker/useMediaBrowser.d.ts +1 -1
- package/dist/resourceSource.d.ts +1 -1
- package/dist/resourceSource.d.ts.map +1 -1
- package/dist/resourceSource.js +13 -4
- package/dist/resourceSource.js.map +1 -1
- package/package.json +9 -9
package/dist/ImageItem.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { MediaReference } from '@panneau/protocol';
|
|
3
|
-
import type { EditedImage } from './editor/types';
|
|
3
|
+
import type { EditedImage } from './editor/types.js';
|
|
4
4
|
/** The image of a reference, as the editor reads it, or null when its media can't be edited. */
|
|
5
5
|
export declare function editedImageOf(reference: MediaReference): EditedImage | null;
|
|
6
6
|
/**
|
package/dist/MediaField.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DataAdapter } from '@panneau/data';
|
|
2
2
|
import { type FieldEntryProps, type FieldProps, type UploadSource } from '@panneau/fields';
|
|
3
3
|
import type { Definition, Field, MediaReference } from '@panneau/protocol';
|
|
4
|
-
import type { MediaSource } from './picker/types';
|
|
4
|
+
import type { MediaSource } from './picker/types.js';
|
|
5
5
|
/** What the media field needs from an adapter: `@panneau/data`'s `DataAdapter` has it. */
|
|
6
6
|
export type MediaAdapter = Pick<DataAdapter, 'create' | 'get'>;
|
|
7
7
|
export interface MediaFieldBaseProps extends Omit<FieldProps<never>, 'value' | 'onChange'> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ImageEditorDialogProps, ImageEditorProps } from './types';
|
|
1
|
+
import type { ImageEditorDialogProps, ImageEditorProps } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* The image editor (decision 0031): the image as it will be rendered, with the overlay of a tool
|
|
4
4
|
* over it, the tool's options on the side, and the result. It edits a transform for one use, over
|
package/dist/editor/draw.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { MediaTransform } from '@panneau/protocol';
|
|
3
|
-
import { type Rect, type Size } from './geometry';
|
|
4
|
-
import type { EditedImage, TransformBase } from './types';
|
|
3
|
+
import { type Rect, type Size } from './geometry.js';
|
|
4
|
+
import type { EditedImage, TransformBase } from './types.js';
|
|
5
5
|
export declare const viewBox: (rect: Rect) => string;
|
|
6
6
|
/** The media's own transform, or null when it has no edits. */
|
|
7
7
|
export declare function ownTransform(image: EditedImage): MediaTransform | null;
|
package/dist/editor/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { ImageEditor, ImageEditorDialog } from './ImageEditor';
|
|
2
|
-
export { useImageEditorTools } from './tools';
|
|
3
|
-
export type { EditedImage, ImageEditorDialogProps, ImageEditorProps, ImageEditorTool, ImageEditorToolContext, TransformBase, } from './types';
|
|
4
|
-
export type { Point, Rect, Size } from './geometry';
|
|
1
|
+
export { ImageEditor, ImageEditorDialog } from './ImageEditor.js';
|
|
2
|
+
export { useImageEditorTools } from './tools.js';
|
|
3
|
+
export type { EditedImage, ImageEditorDialogProps, ImageEditorProps, ImageEditorTool, ImageEditorToolContext, TransformBase, } from './types.js';
|
|
4
|
+
export type { Point, Rect, Size } from './geometry.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/editor/tools.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ImageEditorTool } from './types';
|
|
1
|
+
import type { ImageEditorTool } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* The tools of the editor by default: crop, rotate (with flips) and focal point. A product passes
|
|
4
4
|
* them to `ImageEditor`'s `tools` with its own, or without the ones a field doesn't offer.
|
package/dist/editor/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { MediaTransform } from '@panneau/protocol';
|
|
3
3
|
import type { IconComponent } from '@panneau/ui';
|
|
4
|
-
import type { Point, Rect, Size } from './geometry';
|
|
4
|
+
import type { Point, Rect, Size } from './geometry.js';
|
|
5
5
|
/**
|
|
6
6
|
* What a transform for one use starts from (decision 0031): the media's own transform, or the
|
|
7
7
|
* original file.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { ImageField, type ImageFieldProps, type ImageOptions, MediaField, type MediaAdapter, type MediaFieldBaseProps, MediaFieldEntry, type MediaFieldProps, type MultipleMediaFieldProps, type SingleMediaFieldProps, getImageOptions, getLibrary, isProcessing, toMediaReference, toMediaReferences, } from './MediaField';
|
|
2
|
-
export { mediaPlugin } from './plugin';
|
|
3
|
-
export { type MediaLibrary, type MediaSourceAdapter, createResourceMediaSource, } from './resourceSource';
|
|
4
|
-
export type { MediaPage, MediaQuery, MediaRequestOptions, MediaSort, MediaSource, MediaType, PickerMedia, } from './picker/types';
|
|
1
|
+
export { ImageField, type ImageFieldProps, type ImageOptions, MediaField, type MediaAdapter, type MediaFieldBaseProps, MediaFieldEntry, type MediaFieldProps, type MultipleMediaFieldProps, type SingleMediaFieldProps, getImageOptions, getLibrary, isProcessing, toMediaReference, toMediaReferences, } from './MediaField.js';
|
|
2
|
+
export { mediaPlugin } from './plugin.js';
|
|
3
|
+
export { type MediaLibrary, type MediaSourceAdapter, createResourceMediaSource, } from './resourceSource.js';
|
|
4
|
+
export type { MediaPage, MediaQuery, MediaRequestOptions, MediaSort, MediaSource, MediaType, PickerMedia, } from './picker/types.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Field } from '@panneau/protocol';
|
|
2
|
-
import type { PickerMedia } from './types';
|
|
2
|
+
import type { PickerMedia } from './types.js';
|
|
3
3
|
export interface MediaDetailsProps {
|
|
4
4
|
item: PickerMedia | null;
|
|
5
5
|
/** The fields the details edit: empty when the source can't update its media. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MediaPickerProps } from './types';
|
|
1
|
+
import type { MediaPickerProps } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* The media picker (decision 0027): browse the libraries given as sources, upload to them, and
|
|
4
4
|
* pick one media, or several with `multiple`. It returns references with their library
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Filter, FilterValue } from '@panneau/protocol';
|
|
2
|
-
import type { MediaSort } from './types';
|
|
3
|
-
import type { BrowseQuery } from './useMediaBrowser';
|
|
2
|
+
import type { MediaSort } from './types.js';
|
|
3
|
+
import type { BrowseQuery } from './useMediaBrowser.js';
|
|
4
4
|
export interface PickerToolbarProps {
|
|
5
5
|
query: BrowseQuery;
|
|
6
6
|
onQueryChange: (query: BrowseQuery) => void;
|
package/dist/picker/format.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { usePanneauIntl } from '@panneau/ui';
|
|
2
|
-
import type { MediaSort, MediaType, PickerMedia } from './types';
|
|
2
|
+
import type { MediaSort, MediaType, PickerMedia } from './types.js';
|
|
3
3
|
type Intl = ReturnType<typeof usePanneauIntl>;
|
|
4
4
|
/** The extension of a media's file, in capitals (`JPG`), or its type. */
|
|
5
5
|
export declare function extensionOf(item: PickerMedia): string;
|
package/dist/picker/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { MediaPicker } from './MediaPicker';
|
|
2
|
-
export type { MediaPage, MediaPickerProps, MediaQuery, MediaRequestOptions, MediaSort, MediaSource, MediaType, PickerMedia, } from './types';
|
|
1
|
+
export { MediaPicker } from './MediaPicker.js';
|
|
2
|
+
export type { MediaPage, MediaPickerProps, MediaQuery, MediaRequestOptions, MediaSort, MediaSource, MediaType, PickerMedia, } from './types.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FilterValue } from '@panneau/protocol';
|
|
2
|
-
import type { MediaQuery, MediaSource, MediaType, PickerMedia } from './types';
|
|
2
|
+
import type { MediaQuery, MediaSource, MediaType, PickerMedia } from './types.js';
|
|
3
3
|
/** What the user chose to see in a source. */
|
|
4
4
|
export interface BrowseQuery {
|
|
5
5
|
q: string;
|
package/dist/resourceSource.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DataAdapter } from '@panneau/data';
|
|
2
2
|
import type { Resource } from '@panneau/protocol';
|
|
3
|
-
import type { MediaSource } from './picker/types';
|
|
3
|
+
import type { MediaSource } from './picker/types.js';
|
|
4
4
|
/** What a library source needs of an adapter: `@panneau/data`'s `DataAdapter` has it. */
|
|
5
5
|
export type MediaSourceAdapter = Pick<DataAdapter, 'list' | 'get' | 'create' | 'update'>;
|
|
6
6
|
/** The library resource a source reads: a resource of kind `media` of the definition. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resourceSource.d.ts","sourceRoot":"","sources":["../src/resourceSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,KAAK,EAA0B,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"resourceSource.d.ts","sourceRoot":"","sources":["../src/resourceSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,KAAK,EAA0B,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG1E,OAAO,KAAK,EAAa,WAAW,EAAe,MAAM,gBAAgB,CAAC;AAE1E,yFAAyF;AACzF,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC;AAEzF,yFAAyF;AACzF,MAAM,MAAM,YAAY,GAAG,IAAI,CAC3B,QAAQ,EACR,IAAI,GAAG,OAAO,GAAG,WAAW,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CACjE,CAAC;AA0CF;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CACrC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,YAAY,GACtB,WAAW,CAkEb"}
|
package/dist/resourceSource.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getAccept, getMaxSize } from "@panneau/fields";
|
|
2
|
+
import { isCursorPage } from "@panneau/protocol/runtime";
|
|
2
3
|
//#region src/resourceSource.ts
|
|
3
4
|
/** Fields a picker never edits: the original file, and what the backend computes. */
|
|
4
5
|
var READ_ONLY = /* @__PURE__ */ new Set(["file", "media"]);
|
|
@@ -63,17 +64,25 @@ function createResourceMediaSource(adapter, library) {
|
|
|
63
64
|
fields,
|
|
64
65
|
canCreate: library.abilities?.create !== false,
|
|
65
66
|
async list({ q, filter, sort, cursor }, options) {
|
|
66
|
-
const
|
|
67
|
+
const cursors = library.list?.pagination === "cursor";
|
|
68
|
+
const given = cursor !== null && cursor !== void 0 && cursor !== "";
|
|
69
|
+
const page = !cursors && given ? Number(cursor) : 1;
|
|
67
70
|
const response = await adapter.list(library.id, {
|
|
68
|
-
page,
|
|
71
|
+
...cursors ? given ? { cursor } : {} : { page },
|
|
69
72
|
...q !== void 0 && q !== "" ? { q } : {},
|
|
70
73
|
...filter !== void 0 ? { filter } : {},
|
|
71
74
|
...sort !== void 0 ? { sort: [sort] } : {}
|
|
72
75
|
}, options);
|
|
76
|
+
const { meta } = response;
|
|
73
77
|
return {
|
|
74
78
|
items: response.data.map(read),
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
...isCursorPage(meta) ? {
|
|
80
|
+
nextCursor: meta.nextCursor,
|
|
81
|
+
...typeof meta.total === "number" ? { total: meta.total } : {}
|
|
82
|
+
} : {
|
|
83
|
+
nextCursor: page < meta.lastPage ? String(page + 1) : null,
|
|
84
|
+
total: meta.total
|
|
85
|
+
}
|
|
77
86
|
};
|
|
78
87
|
},
|
|
79
88
|
async get(id, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resourceSource.js","names":["DataAdapter","getAccept","getMaxSize","Field","Item","MediaInfo","Resource","MediaSort","MediaSource","PickerMedia","MediaSourceAdapter","Pick","MediaLibrary","READ_ONLY","Set","DESCENDING","toPickerMedia","item","itemTitle","fields","file","media","createdAt","name","title","fileName","id","label","type","values","Object","fromEntries","map","field","sortsOf","library","sorts","list","key","find","has","undefined","preferred","defaultSort","split","first","sort","replace","filter","createResourceMediaSource","adapter","abilities","update","read","plural","accept","maxSize","filters","canCreate","create","q","cursor","options","page","Number","response","items","data","nextCursor","meta","lastPage","String","total","get","value","File","upload","mime","size"],"sources":["../src/resourceSource.ts"],"sourcesContent":["import type { DataAdapter } from '@panneau/data';\nimport { getAccept, getMaxSize } from '@panneau/fields';\nimport type { Field, Item, MediaInfo, Resource } from '@panneau/protocol';\n\nimport type { MediaSort, MediaSource, PickerMedia } from './picker/types';\n\n/** What a library source needs of an adapter: `@panneau/data`'s `DataAdapter` has it. */\nexport type MediaSourceAdapter = Pick<DataAdapter, 'list' | 'get' | 'create' | 'update'>;\n\n/** The library resource a source reads: a resource of kind `media` of the definition. */\nexport type MediaLibrary = Pick<\n Resource,\n 'id' | 'label' | 'itemTitle' | 'fields' | 'list' | 'abilities'\n>;\n\n/** Fields a picker never edits: the original file, and what the backend computes. */\nconst READ_ONLY = new Set(['file', 'media']);\n\n/** Sorts that make more sense from the largest or the latest. */\nconst DESCENDING = new Set(['createdAt', 'updatedAt', 'size', 'pixels', 'duration']);\n\nfunction toPickerMedia(item: Item, itemTitle: string, fields: readonly Field[]): PickerMedia {\n const { file, media, createdAt } = item as Item & {\n file?: { name?: unknown } | null;\n media?: MediaInfo;\n createdAt?: unknown;\n };\n const title = item[itemTitle];\n const fileName = typeof file?.name === 'string' ? file.name : null;\n return {\n id: item.id,\n label: typeof title === 'string' && title !== '' ? title : (fileName ?? item.id),\n fileName,\n createdAt: typeof createdAt === 'string' ? createdAt : null,\n media: media ?? { type: 'other' },\n values: Object.fromEntries(fields.map((field) => [field.name, item[field.name]])),\n };\n}\n\n/** The sorts of a library: those of its list, the default one first. */\nfunction sortsOf(library: MediaLibrary): MediaSort[] {\n const sorts = (library.list?.sorts ?? []).map((key): MediaSort => {\n const label = library.fields.find((field) => field.name === key)?.label;\n return {\n id: DESCENDING.has(key) ? `-${key}` : key,\n ...(label !== undefined ? { label } : {}),\n };\n });\n const preferred = library.list?.defaultSort?.split(',')[0];\n const first = sorts.find(\n (sort) => sort.id === preferred || sort.id.replace(/^-/, '') === preferred,\n );\n return first !== undefined ? [first, ...sorts.filter((sort) => sort !== first)] : sorts;\n}\n\n/**\n * The source of a library resource (`kind: \"media\"`, decision 0027), for the media picker:\n *\n * - `list()` sends `GET /resources/{library}` with `q`, `filter`, `sort`, and the page number as\n * the cursor;\n * - `create()` sends `POST /resources/{library}` with `{ file: { upload, name, mime, size } }`,\n * or the file itself;\n * - `update()` sends `PATCH /resources/{library}/{id}` with the values edited in the details.\n *\n * Its filters and sorts are those of the resource's list, its fields those of the resource except\n * `file` (none when the user can't update the library), and `canCreate` its `create` ability.\n */\nexport function createResourceMediaSource(\n adapter: MediaSourceAdapter,\n library: MediaLibrary,\n): MediaSource {\n const itemTitle = library.itemTitle ?? 'name';\n const file = library.fields.find((field) => field.name === 'file');\n const fields =\n library.abilities?.update === false\n ? []\n : library.fields.filter((field) => !READ_ONLY.has(field.name));\n const read = (item: Item) => toPickerMedia(item, itemTitle, fields);\n return {\n id: library.id,\n label: library.label.plural,\n accept: file !== undefined ? getAccept(file) : null,\n maxSize: file !== undefined ? getMaxSize(file) : null,\n filters: (library.list?.filters ?? []).filter((filter) => filter.id !== 'type'),\n sorts: sortsOf(library),\n fields,\n canCreate: library.abilities?.create !== false,\n async list({ q, filter, sort, cursor }, options) {\n const page = cursor === null || cursor === undefined ? 1 : Number(cursor);\n const response = await adapter.list(\n library.id,\n {\n page,\n ...(q !== undefined && q !== '' ? { q } : {}),\n ...(filter !== undefined ? { filter } : {}),\n ...(sort !== undefined ? { sort: [sort] } : {}),\n },\n options,\n );\n return {\n items: response.data.map(read),\n nextCursor: page < response.meta.lastPage ? String(page + 1) : null,\n total: response.meta.total,\n };\n },\n async get(id, options) {\n return read(await adapter.get(library.id, id, options));\n },\n async create(file, options) {\n // With what the browser knows of the file, which the backend may check first.\n const value =\n file instanceof File\n ? file\n : {\n upload: file.upload,\n name: file.name,\n ...(file.mime !== null ? { mime: file.mime } : {}),\n ...(file.size !== null ? { size: file.size } : {}),\n };\n return read(await adapter.create(library.id, { file: value }, options));\n },\n async update(id, values, options) {\n return read(await adapter.update(library.id, id, values, options));\n },\n };\n}\n"],"mappings":";;;AAgBA,IAAMa,4BAAY,IAAIC,IAAI,CAAC,QAAQ,OAAO,CAAC;;AAG3C,IAAMC,6BAAa,IAAID,IAAI;CAAC;CAAa;CAAa;CAAQ;CAAU;AAAU,CAAC;AAEnF,SAASE,cAAcC,MAAYC,WAAmBC,QAAuC;CACzF,MAAM,EAAEC,MAAMC,OAAOC,cAAcL;CAKnC,MAAMO,QAAQP,KAAKC;CACnB,MAAMO,WAAW,OAAOL,MAAMG,SAAS,WAAWH,KAAKG,OAAO;CAC9D,OAAO;EACHG,IAAIT,KAAKS;EACTC,OAAO,OAAOH,UAAU,YAAYA,UAAU,K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AIzD,KAAK0D,SAAS,OAAO,EAAEA,MAAM1D,KAAK0D,KAAK,IAAI,CAAC;GACpD;GACV,OAAOzB,KAAK,MAAMH,QAAQS,OAAOxB,QAAQT,IAAI,EAAEN,MAAMsD,MAAM,GAAGZ,OAAO,CAAC;EAC1E;EACA,MAAMV,OAAO1B,IAAIG,QAAQiC,SAAS;GAC9B,OAAOT,KAAK,MAAMH,QAAQE,OAAOjB,QAAQT,IAAIA,IAAIG,QAAQiC,OAAO,CAAC;EACrE;CACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"resourceSource.js","names":["DataAdapter","getAccept","getMaxSize","Field","Item","MediaInfo","Resource","isCursorPage","MediaSort","MediaSource","PickerMedia","MediaSourceAdapter","Pick","MediaLibrary","READ_ONLY","Set","DESCENDING","toPickerMedia","item","itemTitle","fields","file","media","createdAt","name","title","fileName","id","label","type","values","Object","fromEntries","map","field","sortsOf","library","sorts","list","key","find","has","undefined","preferred","defaultSort","split","first","sort","replace","filter","createResourceMediaSource","adapter","abilities","update","read","plural","accept","maxSize","filters","canCreate","create","q","cursor","options","cursors","pagination","given","page","Number","response","meta","items","data","nextCursor","total","lastPage","String","get","value","File","upload","mime","size"],"sources":["../src/resourceSource.ts"],"sourcesContent":["import type { DataAdapter } from '@panneau/data';\nimport { getAccept, getMaxSize } from '@panneau/fields';\nimport type { Field, Item, MediaInfo, Resource } from '@panneau/protocol';\nimport { isCursorPage } from '@panneau/protocol/runtime';\n\nimport type { MediaSort, MediaSource, PickerMedia } from './picker/types';\n\n/** What a library source needs of an adapter: `@panneau/data`'s `DataAdapter` has it. */\nexport type MediaSourceAdapter = Pick<DataAdapter, 'list' | 'get' | 'create' | 'update'>;\n\n/** The library resource a source reads: a resource of kind `media` of the definition. */\nexport type MediaLibrary = Pick<\n Resource,\n 'id' | 'label' | 'itemTitle' | 'fields' | 'list' | 'abilities'\n>;\n\n/** Fields a picker never edits: the original file, and what the backend computes. */\nconst READ_ONLY = new Set(['file', 'media']);\n\n/** Sorts that make more sense from the largest or the latest. */\nconst DESCENDING = new Set(['createdAt', 'updatedAt', 'size', 'pixels', 'duration']);\n\nfunction toPickerMedia(item: Item, itemTitle: string, fields: readonly Field[]): PickerMedia {\n const { file, media, createdAt } = item as Item & {\n file?: { name?: unknown } | null;\n media?: MediaInfo;\n createdAt?: unknown;\n };\n const title = item[itemTitle];\n const fileName = typeof file?.name === 'string' ? file.name : null;\n return {\n id: item.id,\n label: typeof title === 'string' && title !== '' ? title : (fileName ?? item.id),\n fileName,\n createdAt: typeof createdAt === 'string' ? createdAt : null,\n media: media ?? { type: 'other' },\n values: Object.fromEntries(fields.map((field) => [field.name, item[field.name]])),\n };\n}\n\n/** The sorts of a library: those of its list, the default one first. */\nfunction sortsOf(library: MediaLibrary): MediaSort[] {\n const sorts = (library.list?.sorts ?? []).map((key): MediaSort => {\n const label = library.fields.find((field) => field.name === key)?.label;\n return {\n id: DESCENDING.has(key) ? `-${key}` : key,\n ...(label !== undefined ? { label } : {}),\n };\n });\n const preferred = library.list?.defaultSort?.split(',')[0];\n const first = sorts.find(\n (sort) => sort.id === preferred || sort.id.replace(/^-/, '') === preferred,\n );\n return first !== undefined ? [first, ...sorts.filter((sort) => sort !== first)] : sorts;\n}\n\n/**\n * The source of a library resource (`kind: \"media\"`, decision 0027), for the media picker:\n *\n * - `list()` sends `GET /resources/{library}` with `q`, `filter`, `sort`, and the page number as\n * the cursor;\n * - `create()` sends `POST /resources/{library}` with `{ file: { upload, name, mime, size } }`,\n * or the file itself;\n * - `update()` sends `PATCH /resources/{library}/{id}` with the values edited in the details.\n *\n * Its filters and sorts are those of the resource's list, its fields those of the resource except\n * `file` (none when the user can't update the library), and `canCreate` its `create` ability.\n */\nexport function createResourceMediaSource(\n adapter: MediaSourceAdapter,\n library: MediaLibrary,\n): MediaSource {\n const itemTitle = library.itemTitle ?? 'name';\n const file = library.fields.find((field) => field.name === 'file');\n const fields =\n library.abilities?.update === false\n ? []\n : library.fields.filter((field) => !READ_ONLY.has(field.name));\n const read = (item: Item) => toPickerMedia(item, itemTitle, fields);\n return {\n id: library.id,\n label: library.label.plural,\n accept: file !== undefined ? getAccept(file) : null,\n maxSize: file !== undefined ? getMaxSize(file) : null,\n filters: (library.list?.filters ?? []).filter((filter) => filter.id !== 'type'),\n sorts: sortsOf(library),\n fields,\n canCreate: library.abilities?.create !== false,\n async list({ q, filter, sort, cursor }, options) {\n // The picker's cursor is the library's own, or the number of the next page.\n const cursors = library.list?.pagination === 'cursor';\n const given = cursor !== null && cursor !== undefined && cursor !== '';\n const page = !cursors && given ? Number(cursor) : 1;\n const response = await adapter.list(\n library.id,\n {\n ...(cursors ? (given ? { cursor } : {}) : { page }),\n ...(q !== undefined && q !== '' ? { q } : {}),\n ...(filter !== undefined ? { filter } : {}),\n ...(sort !== undefined ? { sort: [sort] } : {}),\n },\n options,\n );\n const { meta } = response;\n return {\n items: response.data.map(read),\n ...(isCursorPage(meta)\n ? {\n nextCursor: meta.nextCursor,\n ...(typeof meta.total === 'number' ? { total: meta.total } : {}),\n }\n : {\n nextCursor: page < meta.lastPage ? String(page + 1) : null,\n total: meta.total,\n }),\n };\n },\n async get(id, options) {\n return read(await adapter.get(library.id, id, options));\n },\n async create(file, options) {\n // With what the browser knows of the file, which the backend may check first.\n const value =\n file instanceof File\n ? file\n : {\n upload: file.upload,\n name: file.name,\n ...(file.mime !== null ? { mime: file.mime } : {}),\n ...(file.size !== null ? { size: file.size } : {}),\n };\n return read(await adapter.create(library.id, { file: value }, options));\n },\n async update(id, values, options) {\n return read(await adapter.update(library.id, id, values, options));\n },\n };\n}\n"],"mappings":";;;;AAiBA,IAAMc,4BAAY,IAAIC,IAAI,CAAC,QAAQ,OAAO,CAAC;;AAG3C,IAAMC,6BAAa,IAAID,IAAI;CAAC;CAAa;CAAa;CAAQ;CAAU;AAAU,CAAC;AAEnF,SAASE,cAAcC,MAAYC,WAAmBC,QAAuC;CACzF,MAAM,EAAEC,MAAMC,OAAOC,cAAcL;CAKnC,MAAM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OAAOJ,KAAKI,MAAM,IAAI,CAAC;IAClE,IACA;KACID,YAAYN,OAAOG,KAAKK,WAAWC,OAAOT,OAAO,CAAC,IAAI;KACtDO,OAAOJ,KAAKI;IAChB;GACV;EACJ;EACA,MAAMG,IAAIlD,IAAIoC,SAAS;GACnB,OAAOT,KAAK,MAAMH,QAAQ0B,IAAIzC,QAAQT,IAAIA,IAAIoC,OAAO,CAAC;EAC1D;EACA,MAAMH,OAAOvC,MAAM0C,SAAS;GAExB,MAAMe,QACFzD,gBAAgB0D,OACV1D,OACA;IACI2D,QAAQ3D,KAAK2D;IACbxD,MAAMH,KAAKG;IACX,GAAIH,KAAK4D,SAAS,OAAO,EAAEA,MAAM5D,KAAK4D,KAAK,IAAI,CAAC;IAChD,GAAI5D,KAAK6D,SAAS,OAAO,EAAEA,MAAM7D,KAAK6D,KAAK,IAAI,CAAC;GACpD;GACV,OAAO5B,KAAK,MAAMH,QAAQS,OAAOxB,QAAQT,IAAI,EAAEN,MAAMyD,MAAM,GAAGf,OAAO,CAAC;EAC1E;EACA,MAAMV,OAAO1B,IAAIG,QAAQiC,SAAS;GAC9B,OAAOT,KAAK,MAAMH,QAAQE,OAAOjB,QAAQT,IAAIA,IAAIG,QAAQiC,OAAO,CAAC;EACrE;CACJ;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panneau/media",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.9",
|
|
4
4
|
"description": "The media of Panneau: the media field, which makes media of uploads and follows their ingest.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"scripts": {
|
|
37
|
-
"build": "vite build &&
|
|
37
|
+
"build": "vite build && node ../../scripts/declarations.js",
|
|
38
38
|
"typecheck": "tsc --noEmit",
|
|
39
|
-
"api": "
|
|
39
|
+
"api": "node ../../scripts/declarations.js && node ../../scripts/api-report.js"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"react-intl": "^12.0.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@panneau/core": "5.0.0-alpha.
|
|
52
|
-
"@panneau/data": "5.0.0-alpha.
|
|
53
|
-
"@panneau/fields": "5.0.0-alpha.
|
|
54
|
-
"@panneau/intl": "5.0.0-alpha.
|
|
55
|
-
"@panneau/protocol": "5.0.0-alpha.
|
|
56
|
-
"@panneau/ui": "5.0.0-alpha.
|
|
51
|
+
"@panneau/core": "5.0.0-alpha.9",
|
|
52
|
+
"@panneau/data": "5.0.0-alpha.9",
|
|
53
|
+
"@panneau/fields": "5.0.0-alpha.9",
|
|
54
|
+
"@panneau/intl": "5.0.0-alpha.9",
|
|
55
|
+
"@panneau/protocol": "5.0.0-alpha.9",
|
|
56
|
+
"@panneau/ui": "5.0.0-alpha.9",
|
|
57
57
|
"lucide-react": "^1.57.0"
|
|
58
58
|
}
|
|
59
59
|
}
|