@panneau/media 5.0.0-alpha.4 → 5.0.0-alpha.6

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.
Files changed (83) hide show
  1. package/README.md +94 -7
  2. package/dist/ImageItem.d.ts +23 -0
  3. package/dist/ImageItem.d.ts.map +1 -0
  4. package/dist/ImageItem.js +292 -0
  5. package/dist/ImageItem.js.map +1 -0
  6. package/dist/MediaField.css +127 -0
  7. package/dist/MediaField.d.ts +67 -15
  8. package/dist/MediaField.d.ts.map +1 -1
  9. package/dist/MediaField.js +354 -148
  10. package/dist/MediaField.js.map +1 -1
  11. package/dist/MediaField.module.js +28 -2
  12. package/dist/MediaField.module.js.map +1 -1
  13. package/dist/editor/ImageEditor.css +369 -0
  14. package/dist/editor/ImageEditor.d.ts +13 -0
  15. package/dist/editor/ImageEditor.d.ts.map +1 -0
  16. package/dist/editor/ImageEditor.js +461 -0
  17. package/dist/editor/ImageEditor.js.map +1 -0
  18. package/dist/editor/ImageEditor.module.js +86 -0
  19. package/dist/editor/ImageEditor.module.js.map +1 -0
  20. package/dist/editor/draw.d.ts +37 -0
  21. package/dist/editor/draw.d.ts.map +1 -0
  22. package/dist/editor/draw.js +93 -0
  23. package/dist/editor/draw.js.map +1 -0
  24. package/dist/editor/geometry.d.ts +54 -0
  25. package/dist/editor/geometry.d.ts.map +1 -0
  26. package/dist/editor/geometry.js +227 -0
  27. package/dist/editor/geometry.js.map +1 -0
  28. package/dist/editor/index.d.ts +5 -0
  29. package/dist/editor/index.d.ts.map +1 -0
  30. package/dist/editor/index.js +3 -0
  31. package/dist/editor/tools.d.ts +11 -0
  32. package/dist/editor/tools.d.ts.map +1 -0
  33. package/dist/editor/tools.js +1199 -0
  34. package/dist/editor/tools.js.map +1 -0
  35. package/dist/editor/types.d.ts +111 -0
  36. package/dist/editor/types.d.ts.map +1 -0
  37. package/dist/index.d.ts +3 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +3 -2
  40. package/dist/picker/MediaDetails.d.ts +22 -0
  41. package/dist/picker/MediaDetails.d.ts.map +1 -0
  42. package/dist/picker/MediaDetails.js +368 -0
  43. package/dist/picker/MediaDetails.js.map +1 -0
  44. package/dist/picker/MediaGrid.d.ts +30 -0
  45. package/dist/picker/MediaGrid.d.ts.map +1 -0
  46. package/dist/picker/MediaGrid.js +260 -0
  47. package/dist/picker/MediaGrid.js.map +1 -0
  48. package/dist/picker/MediaPicker.css +642 -0
  49. package/dist/picker/MediaPicker.d.ts +9 -0
  50. package/dist/picker/MediaPicker.d.ts.map +1 -0
  51. package/dist/picker/MediaPicker.js +601 -0
  52. package/dist/picker/MediaPicker.js.map +1 -0
  53. package/dist/picker/MediaPicker.module.js +132 -0
  54. package/dist/picker/MediaPicker.module.js.map +1 -0
  55. package/dist/picker/PickerToolbar.d.ts +19 -0
  56. package/dist/picker/PickerToolbar.d.ts.map +1 -0
  57. package/dist/picker/PickerToolbar.js +266 -0
  58. package/dist/picker/PickerToolbar.js.map +1 -0
  59. package/dist/picker/UploadPanel.d.ts +22 -0
  60. package/dist/picker/UploadPanel.d.ts.map +1 -0
  61. package/dist/picker/UploadPanel.js +186 -0
  62. package/dist/picker/UploadPanel.js.map +1 -0
  63. package/dist/picker/format.d.ts +18 -0
  64. package/dist/picker/format.d.ts.map +1 -0
  65. package/dist/picker/format.js +64 -0
  66. package/dist/picker/format.js.map +1 -0
  67. package/dist/picker/index.d.ts +3 -0
  68. package/dist/picker/index.d.ts.map +1 -0
  69. package/dist/picker/index.js +1 -0
  70. package/dist/picker/types.d.ts +119 -0
  71. package/dist/picker/types.d.ts.map +1 -0
  72. package/dist/picker/useMediaBrowser.d.ts +50 -0
  73. package/dist/picker/useMediaBrowser.d.ts.map +1 -0
  74. package/dist/picker/useMediaBrowser.js +314 -0
  75. package/dist/picker/useMediaBrowser.js.map +1 -0
  76. package/dist/plugin.d.ts +1 -1
  77. package/dist/plugin.js +5 -2
  78. package/dist/plugin.js.map +1 -1
  79. package/dist/resourceSource.d.ts +21 -0
  80. package/dist/resourceSource.d.ts.map +1 -0
  81. package/dist/resourceSource.js +99 -0
  82. package/dist/resourceSource.js.map +1 -0
  83. package/package.json +18 -7
@@ -1,10 +1,14 @@
1
1
  import type { DataAdapter } from '@panneau/data';
2
2
  import { type FieldEntryProps, type FieldProps, type UploadSource } from '@panneau/fields';
3
- import type { Definition, MediaReference } from '@panneau/protocol';
3
+ import type { Definition, Field, MediaReference } from '@panneau/protocol';
4
+ import type { MediaSource } from './picker/types';
4
5
  /** What the media field needs from an adapter: `@panneau/data`'s `DataAdapter` has it. */
5
6
  export type MediaAdapter = Pick<DataAdapter, 'create' | 'get'>;
6
7
  export interface MediaFieldBaseProps extends Omit<FieldProps<never>, 'value' | 'onChange'> {
7
- /** The library: a resource of kind `media`, whose items the field references. */
8
+ /**
9
+ * The library the field uploads to: a resource of kind `media`. References without a
10
+ * `resource` are media of it.
11
+ */
8
12
  resource: string;
9
13
  /** The field that titles the media of the library, for the label of new references. Defaults to `name`. */
10
14
  itemTitle?: string;
@@ -23,6 +27,37 @@ export interface MediaFieldBaseProps extends Omit<FieldProps<never>, 'value' | '
23
27
  maxSize?: number | null;
24
28
  /** How often to read a media again until it is ready, in milliseconds. Defaults to 3 s. */
25
29
  refreshInterval?: number;
30
+ /**
31
+ * The libraries the media picker browses, in the order of its switcher ("Choose media",
32
+ * "Add media"). Without any, the field only uploads.
33
+ */
34
+ sources?: readonly MediaSource[];
35
+ /** Keeps what the user browsed in the picker between openings (see `MediaPicker`). */
36
+ stateKey?: string;
37
+ /**
38
+ * Makes it an `image` field (decision 0031): its images as they are rendered for this use,
39
+ * the image editor to edit their transform, and the editor as the step after a pick when a
40
+ * crop is required. `ImageField` sets it.
41
+ */
42
+ image?: ImageOptions | null;
43
+ }
44
+ /** The options of an `image` field (decision 0031). */
45
+ export interface ImageOptions {
46
+ /** The ratios the editor offers, as `width:height`. */
47
+ ratios?: readonly string[];
48
+ /** Whether a crop must have one of `ratios`: the `crop` rule. */
49
+ enforceRatios?: boolean;
50
+ /** Whether each image needs a crop for this use: the `crop` rule. */
51
+ cropRequired?: boolean;
52
+ /** Whether the editor offers rotation and flips. Defaults to true. */
53
+ rotate?: boolean;
54
+ /** Whether the editor offers the focal point. Defaults to true. */
55
+ focalPoint?: boolean;
56
+ /**
57
+ * What a transform for one use starts from: the media's own transform (the default), the
58
+ * original file, or the user's choice in the editor.
59
+ */
60
+ transformBase?: 'media' | 'original' | 'choose';
26
61
  }
27
62
  export interface SingleMediaFieldProps extends MediaFieldBaseProps {
28
63
  multiple?: false;
@@ -46,24 +81,41 @@ export declare function toMediaReferences(value: unknown, itemTitle?: string): M
46
81
  /** Whether the file of a media is still being processed. */
47
82
  export declare function isProcessing(reference: MediaReference): boolean;
48
83
  /**
49
- * The library of a `media` field: its `resource`, or the only resource of kind `media` of the
50
- * definition.
84
+ * The first library a `media` field allows (decision 0027): the one its `resource` names, the
85
+ * first one it lists, or the first resource of kind `media` of the definition when it names none.
86
+ * The field uploads to it.
51
87
  */
52
- export declare function getLibrary(definition: Pick<Definition, 'resources'> | null, resource: string | undefined): Definition['resources'][number] | null;
88
+ export declare function getLibrary(definition: Pick<Definition, 'resources'> | null, resource: string | readonly string[] | undefined): Definition['resources'][number] | null;
53
89
  /**
54
- * Media of a library (the `media` type, decision 0026): a file chosen or dropped becomes a media
55
- * of the library, an item of its resource (`create(resource, { file })`), sent directly to storage
56
- * first when there is an upload source. Values are references to the media, with their `media`
57
- * and their `transform` for this use. The field shows each media with its thumbnail and its
58
- * status, and reads it again until its file is processed. Picking media already in the library
59
- * comes with the media picker.
90
+ * Media of libraries (the `media` type, decisions 0026 and 0027). "Choose media" ("Add media"
91
+ * with `multiple`) opens the media picker on the `sources`, and a file chosen or dropped becomes
92
+ * a media of the library, an item of its resource (`create(resource, { file })`), sent directly
93
+ * to storage first when there is an upload source. Values are references to the media, with
94
+ * their library, their `media` and their `transform` for this use. The field shows each media
95
+ * with its thumbnail and its status, and reads it again until its file is processed.
60
96
  */
61
97
  export declare function MediaField(props: MediaFieldProps): import("react").JSX.Element;
98
+ /** The props of `ImageField`: those of `MediaField`, with the options of an `image` field. */
99
+ export type ImageFieldProps = MediaFieldProps & ImageOptions;
100
+ /**
101
+ * An `image` field (decision 0031): a `media` field for images, with the image editor. It accepts
102
+ * `image/*` by default. Each image shows as it is rendered for this use, with Edit, which opens
103
+ * the editor on its transform. When a crop is required, the editor is the step right after the
104
+ * pick of one image.
105
+ */
106
+ export declare function ImageField(props: ImageFieldProps): import("react").JSX.Element;
107
+ /**
108
+ * The options of an `image` field of a definition: its `crop` rule (enforced ratios, a required
109
+ * crop), its suggested `ratios`, and the tools and base of its editor.
110
+ */
111
+ export declare function getImageOptions(field: Field): ImageOptions;
62
112
  /**
63
- * The registry entry of the `media` type: the field's library (`resource`, or the only `media`
64
- * resource of the definition), `multiple`, `accept` (or its `accept` rule) and `maxSize` rule,
65
- * with the adapter of `@panneau/data` and the upload source of the fields context. Without a
66
- * library, the field shows its media and can't add any.
113
+ * The registry entry of the `media` and `image` types: the picker on the libraries the field allows
114
+ * (`getMediaLibraries()`), uploads to the first one (`getLibrary()`), `multiple`, `accept` (or
115
+ * its `accept` rule) and `maxSize` rule, with the adapter of `@panneau/data` and the upload source
116
+ * of the fields context. The picker opens again where the user left it in the same libraries.
117
+ * Without a library, the field shows its media and can't add any. An `image` field also gets its
118
+ * options (`getImageOptions()`), and accepts `image/*` by default.
67
119
  */
68
120
  export declare function MediaFieldEntry(props: FieldEntryProps): import("react").JSX.Element;
69
121
  //# sourceMappingURL=MediaField.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MediaField.d.ts","sourceRoot":"","sources":["../src/MediaField.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,EACH,KAAK,eAAe,EACpB,KAAK,UAAU,EAGf,KAAK,YAAY,EAQpB,MAAM,iBAAiB,CAAC;AAEz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