@wordpress/media-editor 0.2.0

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 (51) hide show
  1. package/LICENSE.md +788 -0
  2. package/README.md +121 -0
  3. package/build/components/media-editor-provider/index.cjs +59 -0
  4. package/build/components/media-editor-provider/index.cjs.map +7 -0
  5. package/build/components/media-form/index.cjs +71 -0
  6. package/build/components/media-form/index.cjs.map +7 -0
  7. package/build/components/media-preview/index.cjs +119 -0
  8. package/build/components/media-preview/index.cjs.map +7 -0
  9. package/build/index.cjs +47 -0
  10. package/build/index.cjs.map +7 -0
  11. package/build/utils/get-media-type.cjs +45 -0
  12. package/build/utils/get-media-type.cjs.map +7 -0
  13. package/build/utils/index.cjs +31 -0
  14. package/build/utils/index.cjs.map +7 -0
  15. package/build-module/components/media-editor-provider/index.mjs +33 -0
  16. package/build-module/components/media-editor-provider/index.mjs.map +7 -0
  17. package/build-module/components/media-form/index.mjs +50 -0
  18. package/build-module/components/media-form/index.mjs.map +7 -0
  19. package/build-module/components/media-preview/index.mjs +98 -0
  20. package/build-module/components/media-preview/index.mjs.map +7 -0
  21. package/build-module/index.mjs +10 -0
  22. package/build-module/index.mjs.map +7 -0
  23. package/build-module/utils/get-media-type.mjs +20 -0
  24. package/build-module/utils/get-media-type.mjs.map +7 -0
  25. package/build-module/utils/index.mjs +6 -0
  26. package/build-module/utils/index.mjs.map +7 -0
  27. package/build-style/style-rtl.css +127 -0
  28. package/build-style/style.css +127 -0
  29. package/build-types/components/media-editor-provider/index.d.ts +62 -0
  30. package/build-types/components/media-editor-provider/index.d.ts.map +1 -0
  31. package/build-types/components/media-form/index.d.ts +22 -0
  32. package/build-types/components/media-form/index.d.ts.map +1 -0
  33. package/build-types/components/media-preview/index.d.ts +15 -0
  34. package/build-types/components/media-preview/index.d.ts.map +1 -0
  35. package/build-types/index.d.ts +8 -0
  36. package/build-types/index.d.ts.map +1 -0
  37. package/build-types/utils/get-media-type.d.ts +14 -0
  38. package/build-types/utils/get-media-type.d.ts.map +1 -0
  39. package/build-types/utils/index.d.ts +3 -0
  40. package/build-types/utils/index.d.ts.map +1 -0
  41. package/package.json +57 -0
  42. package/src/components/media-editor-provider/index.tsx +90 -0
  43. package/src/components/media-form/index.tsx +87 -0
  44. package/src/components/media-preview/index.tsx +154 -0
  45. package/src/components/media-preview/style.scss +89 -0
  46. package/src/index.ts +15 -0
  47. package/src/style.scss +2 -0
  48. package/src/utils/get-media-type.ts +29 -0
  49. package/src/utils/index.ts +2 -0
  50. package/tsconfig.json +13 -0
  51. package/tsconfig.tsbuildinfo +1 -0
package/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # Media Editor
2
+
3
+ Media editor components for WordPress.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @wordpress/media-editor --save
9
+ ```
10
+
11
+ _This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for such language features and APIs, you should include [the polyfill shipped in `@wordpress/babel-preset-default`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/babel-preset-default#polyfill) in your code._
12
+
13
+ ## Usage
14
+
15
+ ```jsx
16
+ import {
17
+ MediaEditorProvider,
18
+ MediaPreview,
19
+ MediaForm,
20
+ type Field,
21
+ } from '@wordpress/media-editor';
22
+ import { useSelect, useDispatch } from '@wordpress/data';
23
+ import { store as coreStore } from '@wordpress/core-data';
24
+
25
+ function MyMediaEditor( { mediaId } ) {
26
+ const media = useSelect(
27
+ ( select ) =>
28
+ select( coreStore ).getEditedEntityRecord(
29
+ 'postType',
30
+ 'attachment',
31
+ mediaId
32
+ ),
33
+ [ mediaId ]
34
+ );
35
+
36
+ const { editEntityRecord } = useDispatch( coreStore );
37
+
38
+ const handleChange = ( updates ) => {
39
+ editEntityRecord( 'postType', 'attachment', mediaId, updates );
40
+ };
41
+
42
+ // Define fields using the Field type from @wordpress/dataviews
43
+ const fields: Field[] = [
44
+ { id: 'title', label: 'Title', type: 'text' },
45
+ { id: 'alt_text', label: 'Alt Text', type: 'text' },
46
+ { id: 'caption', label: 'Caption', type: 'textarea' },
47
+ { id: 'description', label: 'Description', type: 'textarea' },
48
+ ];
49
+
50
+ return (
51
+ <MediaEditorProvider
52
+ value={ media }
53
+ onChange={ handleChange }
54
+ settings={ { fields } }
55
+ >
56
+ <div style={ { display: 'flex', gap: '24px' } }>
57
+ <div style={ { flex: 1 } }>
58
+ <MediaPreview />
59
+ </div>
60
+ <div style={ { width: '360px' } }>
61
+ <MediaForm />
62
+ </div>
63
+ </div>
64
+ </MediaEditorProvider>
65
+ );
66
+ }
67
+ ```
68
+
69
+ ## API
70
+
71
+ ### `<MediaEditorProvider>`
72
+
73
+ Context provider that supplies media data and actions to child components.
74
+
75
+ **Props:**
76
+
77
+ - `value`: (optional) Media object from the WordPress REST API
78
+ - `onChange`: (optional) Callback when media is updated `(updates: Partial<Media>) => void`. If not provided, the MediaEditor can be used in a read-only mode, which is useful for preview-only scenarios where editing is not needed.
79
+ - `settings`: (optional) Configuration object
80
+ - `settings.fields`: Array of field definitions (uses `Field` type from `@wordpress/dataviews`)
81
+ - `children`: Child components
82
+
83
+ ### `<MediaPreview>`
84
+
85
+ Displays a preview of the media file. Automatically detects and renders images, videos, audio, or generic files based on MIME type.
86
+
87
+ **Props:**
88
+
89
+ Accepts any props that will be spread onto the preview container element (useful for click handlers, accessibility attributes, etc.)
90
+
91
+ ### `<MediaForm>`
92
+
93
+ Form for editing media metadata using `DataForm` from `@wordpress/dataviews`.
94
+
95
+ **Props:**
96
+
97
+ - `form`: Optional form configuration (uses `Form` type from `@wordpress/dataviews`)
98
+ - `header`: Optional header content to display above the form
99
+
100
+ ## TypeScript
101
+
102
+ This package is written in TypeScript and exports all relevant types:
103
+
104
+ ```typescript
105
+ import type {
106
+ Media,
107
+ MediaEditorProviderProps,
108
+ MediaPreviewProps,
109
+ MediaFormProps,
110
+ Field,
111
+ Form,
112
+ } from '@wordpress/media-editor';
113
+ ```
114
+
115
+ ## Contributing to this package
116
+
117
+ This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.
118
+
119
+ To find out more about contributing to this package or Gutenberg as a whole, please read the project's main [contributor guide](https://github.com/WordPress/gutenberg/tree/HEAD/CONTRIBUTING.md).
120
+
121
+ <br /><br /><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/media-editor/src/components/media-editor-provider/index.tsx
21
+ var media_editor_provider_exports = {};
22
+ __export(media_editor_provider_exports, {
23
+ MediaEditorProvider: () => MediaEditorProvider,
24
+ useMediaEditorContext: () => useMediaEditorContext
25
+ });
26
+ module.exports = __toCommonJS(media_editor_provider_exports);
27
+ var import_element = require("@wordpress/element");
28
+ var import_jsx_runtime = require("react/jsx-runtime");
29
+ var MediaEditorContext = (0, import_element.createContext)(
30
+ void 0
31
+ );
32
+ function MediaEditorProvider({
33
+ value,
34
+ onChange,
35
+ settings = {},
36
+ children
37
+ }) {
38
+ const contextValue = {
39
+ media: value,
40
+ onChange,
41
+ fields: settings.fields || []
42
+ };
43
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MediaEditorContext.Provider, { value: contextValue, children });
44
+ }
45
+ function useMediaEditorContext() {
46
+ const context = (0, import_element.useContext)(MediaEditorContext);
47
+ if (!context) {
48
+ throw new Error(
49
+ "useMediaEditorContext must be used within MediaEditorProvider"
50
+ );
51
+ }
52
+ return context;
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ MediaEditorProvider,
57
+ useMediaEditorContext
58
+ });
59
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/media-editor-provider/index.tsx"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\nimport type { Field } from '@wordpress/dataviews';\nimport type { ReactNode } from 'react';\n\n/**\n * Media object from WordPress REST API.\n */\nexport interface Media {\n\tid?: number;\n\tsource_url?: string;\n\tmime_type?: string;\n\talt_text?: string;\n\ttitle?: string | { rendered?: string; raw?: string };\n\tcaption?: string | { rendered?: string; raw?: string };\n\tdescription?: string | { rendered?: string; raw?: string };\n\t[ key: string ]: any;\n}\n\n/**\n * Context value for MediaEditor.\n */\nexport interface MediaEditorContextValue {\n\tmedia?: Media;\n\tonChange?: ( updates: Partial< Media > ) => void;\n\tfields: Field< Media >[];\n}\n\n/**\n * Props for MediaEditorProvider.\n */\nexport interface MediaEditorProviderProps {\n\t/** The media object to edit. */\n\tvalue?: Media;\n\t/**\n\t * Callback when media is updated.\n\t *\n\t * Optional - if not provided, the MediaEditor can be used in a read-only mode,\n\t * useful for preview-only scenarios.\n\t */\n\tonChange?: ( updates: Partial< Media > ) => void;\n\t/** Configuration settings for the media editor. */\n\tsettings?: {\n\t\tfields?: Field< Media >[];\n\t};\n\t/** Child components. */\n\tchildren: ReactNode;\n}\n\nconst MediaEditorContext = createContext< MediaEditorContextValue | undefined >(\n\tundefined\n);\n\nexport function MediaEditorProvider( {\n\tvalue,\n\tonChange,\n\tsettings = {},\n\tchildren,\n}: MediaEditorProviderProps ) {\n\tconst contextValue: MediaEditorContextValue = {\n\t\tmedia: value,\n\t\tonChange,\n\t\tfields: settings.fields || [],\n\t};\n\n\treturn (\n\t\t<MediaEditorContext.Provider value={ contextValue }>\n\t\t\t{ children }\n\t\t</MediaEditorContext.Provider>\n\t);\n}\n\n/**\n * Hook to access the MediaEditor context.\n *\n * Must be used within a MediaEditorProvider component.\n *\n * @return MediaEditorContextValue value with media, onChange, and fields, etc.\n */\nexport function useMediaEditorContext(): MediaEditorContextValue {\n\tconst context = useContext( MediaEditorContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditorContext must be used within MediaEditorProvider'\n\t\t);\n\t}\n\treturn context;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA0C;AAiExC;AAjBF,IAAM,yBAAqB;AAAA,EAC1B;AACD;AAEO,SAAS,oBAAqB;AAAA,EACpC;AAAA,EACA;AAAA,EACA,WAAW,CAAC;AAAA,EACZ;AACD,GAA8B;AAC7B,QAAM,eAAwC;AAAA,IAC7C,OAAO;AAAA,IACP;AAAA,IACA,QAAQ,SAAS,UAAU,CAAC;AAAA,EAC7B;AAEA,SACC,4CAAC,mBAAmB,UAAnB,EAA4B,OAAQ,cAClC,UACH;AAEF;AASO,SAAS,wBAAiD;AAChE,QAAM,cAAU,2BAAY,kBAAmB;AAC/C,MAAK,CAAE,SAAU;AAChB,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;",
6
+ "names": []
7
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/media-editor/src/components/media-form/index.tsx
21
+ var media_form_exports = {};
22
+ __export(media_form_exports, {
23
+ default: () => MediaForm
24
+ });
25
+ module.exports = __toCommonJS(media_form_exports);
26
+ var import_dataviews = require("@wordpress/dataviews");
27
+ var import_components = require("@wordpress/components");
28
+ var import_media_editor_provider = require("../media-editor-provider/index.cjs");
29
+ var import_jsx_runtime = require("react/jsx-runtime");
30
+ function MediaForm({
31
+ form: formOverrides,
32
+ header
33
+ }) {
34
+ const { media, fields, onChange } = (0, import_media_editor_provider.useMediaEditorContext)();
35
+ if (!media || !onChange) {
36
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-form media-editor-form--loading", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Spinner, {}) });
37
+ }
38
+ const defaultForm = {
39
+ layout: {
40
+ type: "panel"
41
+ },
42
+ fields: fields.map((field) => {
43
+ if (["title", "alt_text", "caption", "description"].includes(
44
+ field.id
45
+ )) {
46
+ return {
47
+ id: field.id,
48
+ layout: {
49
+ type: "regular",
50
+ labelPosition: "top"
51
+ }
52
+ };
53
+ }
54
+ return field.id;
55
+ })
56
+ };
57
+ const form = formOverrides || defaultForm;
58
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-form", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: 4, children: [
59
+ header,
60
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
61
+ import_dataviews.DataForm,
62
+ {
63
+ data: media,
64
+ fields,
65
+ form,
66
+ onChange
67
+ }
68
+ )
69
+ ] }) });
70
+ }
71
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/media-form/index.tsx"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { DataForm } from '@wordpress/dataviews';\nimport type { Form, Field } from '@wordpress/dataviews';\nimport { Spinner, __experimentalVStack as VStack } from '@wordpress/components';\nimport type { ReactNode } from 'react';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\n\n/**\n * Props for MediaForm component.\n */\nexport interface MediaFormProps {\n\tform?: Form;\n\theader?: ReactNode;\n}\n\n/**\n * MediaForm component for editing media metadata.\n *\n * Renders a DataForm with fields for editing media properties like\n * title, alt text, caption, description, etc.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration.\n * @param props.header - Optional header content to display above the form.\n * @return The MediaForm component.\n */\nexport default function MediaForm( {\n\tform: formOverrides,\n\theader,\n}: MediaFormProps ) {\n\tconst { media, fields, onChange } = useMediaEditorContext();\n\n\tif ( ! media || ! onChange ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-form media-editor-form--loading\">\n\t\t\t\t<Spinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\t// Default form structure with panel layout\n\tconst defaultForm: Form = {\n\t\tlayout: {\n\t\t\ttype: 'panel',\n\t\t},\n\t\tfields: fields.map( ( field: Field< Media > ) => {\n\t\t\t// Use regular layout for main editable fields\n\t\t\tif (\n\t\t\t\t[ 'title', 'alt_text', 'caption', 'description' ].includes(\n\t\t\t\t\tfield.id\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\tid: field.id,\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\ttype: 'regular',\n\t\t\t\t\t\tlabelPosition: 'top',\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn field.id;\n\t\t} ),\n\t};\n\n\tconst form = formOverrides || defaultForm;\n\n\treturn (\n\t\t<div className=\"media-editor-form\">\n\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t{ header }\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ media }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ form }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAyB;AAEzB,wBAAwD;AAMxD,mCAAsC;AA+BlC;AATW,SAAR,UAA4B;AAAA,EAClC,MAAM;AAAA,EACN;AACD,GAAoB;AACnB,QAAM,EAAE,OAAO,QAAQ,SAAS,QAAI,oDAAsB;AAE1D,MAAK,CAAE,SAAS,CAAE,UAAW;AAC5B,WACC,4CAAC,SAAI,WAAU,gDACd,sDAAC,6BAAQ,GACV;AAAA,EAEF;AAGA,QAAM,cAAoB;AAAA,IACzB,QAAQ;AAAA,MACP,MAAM;AAAA,IACP;AAAA,IACA,QAAQ,OAAO,IAAK,CAAE,UAA2B;AAEhD,UACC,CAAE,SAAS,YAAY,WAAW,aAAc,EAAE;AAAA,QACjD,MAAM;AAAA,MACP,GACC;AACD,eAAO;AAAA,UACN,IAAI,MAAM;AAAA,UACV,QAAQ;AAAA,YACP,MAAM;AAAA,YACN,eAAe;AAAA,UAChB;AAAA,QACD;AAAA,MACD;AACA,aAAO,MAAM;AAAA,IACd,CAAE;AAAA,EACH;AAEA,QAAM,OAAO,iBAAiB;AAE9B,SACC,4CAAC,SAAI,WAAU,qBACd,uDAAC,kBAAAA,sBAAA,EAAO,SAAU,GACf;AAAA;AAAA,IACF;AAAA,MAAC;AAAA;AAAA,QACA,MAAO;AAAA,QACP;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KACD,GACD;AAEF;",
6
+ "names": ["VStack"]
7
+ }
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/media-editor/src/components/media-preview/index.tsx
21
+ var media_preview_exports = {};
22
+ __export(media_preview_exports, {
23
+ default: () => MediaPreview
24
+ });
25
+ module.exports = __toCommonJS(media_preview_exports);
26
+ var import_components = require("@wordpress/components");
27
+ var import_element = require("@wordpress/element");
28
+ var import_i18n = require("@wordpress/i18n");
29
+ var import_media_editor_provider = require("../media-editor-provider/index.cjs");
30
+ var import_utils = require("../../utils/index.cjs");
31
+ var import_jsx_runtime = require("react/jsx-runtime");
32
+ function MediaPreviewContent({
33
+ mediaType,
34
+ mediaUrl,
35
+ altText,
36
+ displayTitle,
37
+ mimeType,
38
+ onLoad,
39
+ onError,
40
+ loadingState
41
+ }) {
42
+ switch (mediaType.type) {
43
+ case "image":
44
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
45
+ "img",
46
+ {
47
+ className: loadingState === "loaded" ? "loaded" : "",
48
+ src: mediaUrl,
49
+ alt: altText || "",
50
+ onLoad,
51
+ onError
52
+ }
53
+ );
54
+ case "video":
55
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("video", { src: mediaUrl, controls: true, onError, children: displayTitle });
56
+ case "audio":
57
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("audio", { src: mediaUrl, controls: true, onError, children: displayTitle });
58
+ default:
59
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "media-editor-preview__file-info", children: [
60
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "media-editor-preview__file-name", children: displayTitle }),
61
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "media-editor-preview__mime-type", children: mimeType }),
62
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
63
+ "a",
64
+ {
65
+ href: mediaUrl,
66
+ target: "_blank",
67
+ rel: "noopener noreferrer",
68
+ className: "media-editor-preview__download-link",
69
+ children: (0, import_i18n.__)("View file")
70
+ }
71
+ )
72
+ ] });
73
+ }
74
+ }
75
+ function MediaPreview(props) {
76
+ const [loadingState, setLoadingState] = (0, import_element.useState)("loading");
77
+ const { media } = (0, import_media_editor_provider.useMediaEditorContext)();
78
+ const {
79
+ source_url: mediaUrl,
80
+ mime_type: mimeType,
81
+ alt_text: altText,
82
+ title
83
+ } = media || {};
84
+ const mediaType = (0, import_utils.getMediaTypeFromMimeType)(mimeType);
85
+ if (!mediaUrl) {
86
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-preview media-editor-preview--empty", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: (0, import_i18n.__)("No media file available.") }) });
87
+ }
88
+ if (loadingState === "error") {
89
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "media-editor-preview media-editor-preview--error", children: [
90
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: (0, import_i18n.__)("Failed to load media file.") }),
91
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "media-editor-preview__url", children: mediaUrl })
92
+ ] });
93
+ }
94
+ const displayTitle = typeof title === "string" ? title : title?.rendered || title?.raw;
95
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
96
+ "div",
97
+ {
98
+ ...props,
99
+ className: `media-editor-preview media-editor-preview--${mediaType.type}`,
100
+ children: [
101
+ mediaType.type === "image" && loadingState === "loading" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-preview__spinner", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Spinner, {}) }),
102
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
103
+ MediaPreviewContent,
104
+ {
105
+ mediaType,
106
+ mediaUrl,
107
+ altText,
108
+ displayTitle,
109
+ mimeType,
110
+ onLoad: () => setLoadingState("loaded"),
111
+ onError: () => setLoadingState("error"),
112
+ loadingState
113
+ }
114
+ )
115
+ ]
116
+ }
117
+ );
118
+ }
119
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/media-preview/index.tsx"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Spinner } from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\n\n/**\n * Props for MediaPreview component.\n */\nexport interface MediaPreviewProps {\n\t[ key: string ]: any; // TODO: Define specific props as needed, this will likely be for click handlers, accessibility attributes, etc.\n}\n\n/**\n * Props for MediaPreviewContent component.\n */\ninterface MediaPreviewContentProps {\n\tmediaType: { type: string };\n\tmediaUrl: string;\n\taltText?: string;\n\tdisplayTitle?: string;\n\tmimeType?: string;\n\tonLoad: () => void;\n\tonError: () => void;\n\tloadingState: 'loading' | 'loaded' | 'error';\n}\n\nfunction MediaPreviewContent( {\n\tmediaType,\n\tmediaUrl,\n\taltText,\n\tdisplayTitle,\n\tmimeType,\n\tonLoad,\n\tonError,\n\tloadingState,\n}: MediaPreviewContentProps ) {\n\tswitch ( mediaType.type ) {\n\t\tcase 'image':\n\t\t\treturn (\n\t\t\t\t<img\n\t\t\t\t\tclassName={ loadingState === 'loaded' ? 'loaded' : '' }\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\talt={ altText || '' }\n\t\t\t\t\tonLoad={ onLoad }\n\t\t\t\t\tonError={ onError }\n\t\t\t\t/>\n\t\t\t);\n\t\tcase 'video':\n\t\t\treturn (\n\t\t\t\t<video src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</video>\n\t\t\t);\n\t\tcase 'audio':\n\t\t\treturn (\n\t\t\t\t<audio src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</audio>\n\t\t\t);\n\t\tdefault:\n\t\t\treturn (\n\t\t\t\t<div className=\"media-editor-preview__file-info\">\n\t\t\t\t\t<p className=\"media-editor-preview__file-name\">\n\t\t\t\t\t\t{ displayTitle }\n\t\t\t\t\t</p>\n\t\t\t\t\t<p className=\"media-editor-preview__mime-type\">\n\t\t\t\t\t\t{ mimeType }\n\t\t\t\t\t</p>\n\t\t\t\t\t<a\n\t\t\t\t\t\thref={ mediaUrl }\n\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\trel=\"noopener noreferrer\"\n\t\t\t\t\t\tclassName=\"media-editor-preview__download-link\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'View file' ) }\n\t\t\t\t\t</a>\n\t\t\t\t</div>\n\t\t\t);\n\t}\n}\n\n/**\n * MediaPreview component displays the media file in the editor canvas.\n * Supports images, videos, audio files, and generic file displays.\n *\n * @param props - Component props including click handlers and accessibility attributes.\n * @return The MediaPreview component.\n */\nexport default function MediaPreview( props: MediaPreviewProps ) {\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'loading' | 'loaded' | 'error'\n\t>( 'loading' );\n\tconst { media } = useMediaEditorContext();\n\n\tconst {\n\t\tsource_url: mediaUrl,\n\t\tmime_type: mimeType,\n\t\talt_text: altText,\n\t\ttitle,\n\t} = media || {};\n\n\tconst mediaType = getMediaTypeFromMimeType( mimeType );\n\n\tif ( ! mediaUrl ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--empty\">\n\t\t\t\t<p>{ __( 'No media file available.' ) }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( loadingState === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--error\">\n\t\t\t\t<p>{ __( 'Failed to load media file.' ) }</p>\n\t\t\t\t<p className=\"media-editor-preview__url\">{ mediaUrl }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst displayTitle =\n\t\ttypeof title === 'string' ? title : title?.rendered || title?.raw;\n\n\treturn (\n\t\t<div\n\t\t\t{ ...props }\n\t\t\tclassName={ `media-editor-preview media-editor-preview--${ mediaType.type }` }\n\t\t>\n\t\t\t{ mediaType.type === 'image' && loadingState === 'loading' && (\n\t\t\t\t<div className=\"media-editor-preview__spinner\">\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<MediaPreviewContent\n\t\t\t\tmediaType={ mediaType }\n\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\taltText={ altText }\n\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\tmimeType={ mimeType }\n\t\t\t\tonLoad={ () => setLoadingState( 'loaded' ) }\n\t\t\t\tonError={ () => setLoadingState( 'error' ) }\n\t\t\t\tloadingState={ loadingState }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAwB;AACxB,qBAAyB;AACzB,kBAAmB;AAKnB,mCAAsC;AACtC,mBAAyC;AAoCrC;AAbJ,SAAS,oBAAqB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAA8B;AAC7B,UAAS,UAAU,MAAO;AAAA,IACzB,KAAK;AACJ,aACC;AAAA,QAAC;AAAA;AAAA,UACA,WAAY,iBAAiB,WAAW,WAAW;AAAA,UACnD,KAAM;AAAA,UACN,KAAM,WAAW;AAAA,UACjB;AAAA,UACA;AAAA;AAAA,MACD;AAAA,IAEF,KAAK;AACJ,aACC,4CAAC,WAAM,KAAM,UAAW,UAAQ,MAAC,SAC9B,wBACH;AAAA,IAEF,KAAK;AACJ,aACC,4CAAC,WAAM,KAAM,UAAW,UAAQ,MAAC,SAC9B,wBACH;AAAA,IAEF;AACC,aACC,6CAAC,SAAI,WAAU,mCACd;AAAA,oDAAC,OAAE,WAAU,mCACV,wBACH;AAAA,QACA,4CAAC,OAAE,WAAU,mCACV,oBACH;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,MAAO;AAAA,YACP,QAAO;AAAA,YACP,KAAI;AAAA,YACJ,WAAU;AAAA,YAER,8BAAI,WAAY;AAAA;AAAA,QACnB;AAAA,SACD;AAAA,EAEH;AACD;AASe,SAAR,aAA+B,OAA2B;AAChE,QAAM,CAAE,cAAc,eAAgB,QAAI,yBAEvC,SAAU;AACb,QAAM,EAAE,MAAM,QAAI,oDAAsB;AAExC,QAAM;AAAA,IACL,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,UAAU;AAAA,IACV;AAAA,EACD,IAAI,SAAS,CAAC;AAEd,QAAM,gBAAY,uCAA0B,QAAS;AAErD,MAAK,CAAE,UAAW;AACjB,WACC,4CAAC,SAAI,WAAU,oDACd,sDAAC,OAAI,8BAAI,0BAA2B,GAAG,GACxC;AAAA,EAEF;AAEA,MAAK,iBAAiB,SAAU;AAC/B,WACC,6CAAC,SAAI,WAAU,oDACd;AAAA,kDAAC,OAAI,8BAAI,4BAA6B,GAAG;AAAA,MACzC,4CAAC,OAAE,WAAU,6BAA8B,oBAAU;AAAA,OACtD;AAAA,EAEF;AAEA,QAAM,eACL,OAAO,UAAU,WAAW,QAAQ,OAAO,YAAY,OAAO;AAE/D,SACC;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACL,WAAY,8CAA+C,UAAU,IAAK;AAAA,MAExE;AAAA,kBAAU,SAAS,WAAW,iBAAiB,aAChD,4CAAC,SAAI,WAAU,iCACd,sDAAC,6BAAQ,GACV;AAAA,QAED;AAAA,UAAC;AAAA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA,QAAS,MAAM,gBAAiB,QAAS;AAAA,YACzC,SAAU,MAAM,gBAAiB,OAAQ;AAAA,YACzC;AAAA;AAAA,QACD;AAAA;AAAA;AAAA,EACD;AAEF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // packages/media-editor/src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ MediaEditorProvider: () => import_media_editor_provider.MediaEditorProvider,
34
+ MediaForm: () => import_media_form.default,
35
+ MediaPreview: () => import_media_preview.default
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+ var import_media_editor_provider = require("./components/media-editor-provider/index.cjs");
39
+ var import_media_preview = __toESM(require("./components/media-preview/index.cjs"));
40
+ var import_media_form = __toESM(require("./components/media-form/index.cjs"));
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ MediaEditorProvider,
44
+ MediaForm,
45
+ MediaPreview
46
+ });
47
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["// Components\nexport { MediaEditorProvider } from './components/media-editor-provider';\nexport { default as MediaPreview } from './components/media-preview';\nexport { default as MediaForm } from './components/media-form';\n\n// Types\nexport type {\n\tMedia,\n\tMediaEditorProviderProps,\n} from './components/media-editor-provider';\nexport type { MediaPreviewProps } from './components/media-preview';\nexport type { MediaFormProps } from './components/media-form';\n\n// Re-export commonly used dataviews types for convenience\nexport type { Field, Form } from '@wordpress/dataviews';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mCAAoC;AACpC,2BAAwC;AACxC,wBAAqC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/media-editor/src/utils/get-media-type.ts
21
+ var get_media_type_exports = {};
22
+ __export(get_media_type_exports, {
23
+ getMediaTypeFromMimeType: () => getMediaTypeFromMimeType
24
+ });
25
+ module.exports = __toCommonJS(get_media_type_exports);
26
+ function getMediaTypeFromMimeType(mimeType) {
27
+ if (!mimeType) {
28
+ return { type: "application" };
29
+ }
30
+ if (mimeType.startsWith("image/")) {
31
+ return { type: "image" };
32
+ }
33
+ if (mimeType.startsWith("video/")) {
34
+ return { type: "video" };
35
+ }
36
+ if (mimeType.startsWith("audio/")) {
37
+ return { type: "audio" };
38
+ }
39
+ return { type: "application" };
40
+ }
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ getMediaTypeFromMimeType
44
+ });
45
+ //# sourceMappingURL=get-media-type.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/get-media-type.ts"],
4
+ "sourcesContent": ["/**\n * Media type result.\n */\nexport interface MediaType {\n\ttype: 'image' | 'video' | 'audio' | 'application';\n}\n\n/**\n * Determines the media type from a MIME type string.\n *\n * @param mimeType - The MIME type to check.\n * @return Object with type property ('image', 'video', 'audio', or 'application').\n */\nexport function getMediaTypeFromMimeType( mimeType?: string ): MediaType {\n\tif ( ! mimeType ) {\n\t\treturn { type: 'application' };\n\t}\n\n\tif ( mimeType.startsWith( 'image/' ) ) {\n\t\treturn { type: 'image' };\n\t}\n\tif ( mimeType.startsWith( 'video/' ) ) {\n\t\treturn { type: 'video' };\n\t}\n\tif ( mimeType.startsWith( 'audio/' ) ) {\n\t\treturn { type: 'audio' };\n\t}\n\treturn { type: 'application' };\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,SAAS,yBAA0B,UAA+B;AACxE,MAAK,CAAE,UAAW;AACjB,WAAO,EAAE,MAAM,cAAc;AAAA,EAC9B;AAEA,MAAK,SAAS,WAAY,QAAS,GAAI;AACtC,WAAO,EAAE,MAAM,QAAQ;AAAA,EACxB;AACA,MAAK,SAAS,WAAY,QAAS,GAAI;AACtC,WAAO,EAAE,MAAM,QAAQ;AAAA,EACxB;AACA,MAAK,SAAS,WAAY,QAAS,GAAI;AACtC,WAAO,EAAE,MAAM,QAAQ;AAAA,EACxB;AACA,SAAO,EAAE,MAAM,cAAc;AAC9B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/media-editor/src/utils/index.ts
21
+ var utils_exports = {};
22
+ __export(utils_exports, {
23
+ getMediaTypeFromMimeType: () => import_get_media_type.getMediaTypeFromMimeType
24
+ });
25
+ module.exports = __toCommonJS(utils_exports);
26
+ var import_get_media_type = require("./get-media-type.cjs");
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ getMediaTypeFromMimeType
30
+ });
31
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/index.ts"],
4
+ "sourcesContent": ["export { getMediaTypeFromMimeType } from './get-media-type';\nexport type { MediaType } from './get-media-type';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAyC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,33 @@
1
+ // packages/media-editor/src/components/media-editor-provider/index.tsx
2
+ import { createContext, useContext } from "@wordpress/element";
3
+ import { jsx } from "react/jsx-runtime";
4
+ var MediaEditorContext = createContext(
5
+ void 0
6
+ );
7
+ function MediaEditorProvider({
8
+ value,
9
+ onChange,
10
+ settings = {},
11
+ children
12
+ }) {
13
+ const contextValue = {
14
+ media: value,
15
+ onChange,
16
+ fields: settings.fields || []
17
+ };
18
+ return /* @__PURE__ */ jsx(MediaEditorContext.Provider, { value: contextValue, children });
19
+ }
20
+ function useMediaEditorContext() {
21
+ const context = useContext(MediaEditorContext);
22
+ if (!context) {
23
+ throw new Error(
24
+ "useMediaEditorContext must be used within MediaEditorProvider"
25
+ );
26
+ }
27
+ return context;
28
+ }
29
+ export {
30
+ MediaEditorProvider,
31
+ useMediaEditorContext
32
+ };
33
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/media-editor-provider/index.tsx"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\nimport type { Field } from '@wordpress/dataviews';\nimport type { ReactNode } from 'react';\n\n/**\n * Media object from WordPress REST API.\n */\nexport interface Media {\n\tid?: number;\n\tsource_url?: string;\n\tmime_type?: string;\n\talt_text?: string;\n\ttitle?: string | { rendered?: string; raw?: string };\n\tcaption?: string | { rendered?: string; raw?: string };\n\tdescription?: string | { rendered?: string; raw?: string };\n\t[ key: string ]: any;\n}\n\n/**\n * Context value for MediaEditor.\n */\nexport interface MediaEditorContextValue {\n\tmedia?: Media;\n\tonChange?: ( updates: Partial< Media > ) => void;\n\tfields: Field< Media >[];\n}\n\n/**\n * Props for MediaEditorProvider.\n */\nexport interface MediaEditorProviderProps {\n\t/** The media object to edit. */\n\tvalue?: Media;\n\t/**\n\t * Callback when media is updated.\n\t *\n\t * Optional - if not provided, the MediaEditor can be used in a read-only mode,\n\t * useful for preview-only scenarios.\n\t */\n\tonChange?: ( updates: Partial< Media > ) => void;\n\t/** Configuration settings for the media editor. */\n\tsettings?: {\n\t\tfields?: Field< Media >[];\n\t};\n\t/** Child components. */\n\tchildren: ReactNode;\n}\n\nconst MediaEditorContext = createContext< MediaEditorContextValue | undefined >(\n\tundefined\n);\n\nexport function MediaEditorProvider( {\n\tvalue,\n\tonChange,\n\tsettings = {},\n\tchildren,\n}: MediaEditorProviderProps ) {\n\tconst contextValue: MediaEditorContextValue = {\n\t\tmedia: value,\n\t\tonChange,\n\t\tfields: settings.fields || [],\n\t};\n\n\treturn (\n\t\t<MediaEditorContext.Provider value={ contextValue }>\n\t\t\t{ children }\n\t\t</MediaEditorContext.Provider>\n\t);\n}\n\n/**\n * Hook to access the MediaEditor context.\n *\n * Must be used within a MediaEditorProvider component.\n *\n * @return MediaEditorContextValue value with media, onChange, and fields, etc.\n */\nexport function useMediaEditorContext(): MediaEditorContextValue {\n\tconst context = useContext( MediaEditorContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditorContext must be used within MediaEditorProvider'\n\t\t);\n\t}\n\treturn context;\n}\n"],
5
+ "mappings": ";AAGA,SAAS,eAAe,kBAAkB;AAiExC;AAjBF,IAAM,qBAAqB;AAAA,EAC1B;AACD;AAEO,SAAS,oBAAqB;AAAA,EACpC;AAAA,EACA;AAAA,EACA,WAAW,CAAC;AAAA,EACZ;AACD,GAA8B;AAC7B,QAAM,eAAwC;AAAA,IAC7C,OAAO;AAAA,IACP;AAAA,IACA,QAAQ,SAAS,UAAU,CAAC;AAAA,EAC7B;AAEA,SACC,oBAAC,mBAAmB,UAAnB,EAA4B,OAAQ,cAClC,UACH;AAEF;AASO,SAAS,wBAAiD;AAChE,QAAM,UAAU,WAAY,kBAAmB;AAC/C,MAAK,CAAE,SAAU;AAChB,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;",
6
+ "names": []
7
+ }